ArrayMesh

package
v0.0.0-...-fa94a0d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

The ArrayMesh is used to construct a Mesh by specifying the attributes as arrays.

The most basic example is the creation of a single triangle:

package main

import (
	"graphics.gd/classdb/ArrayMesh"
	"graphics.gd/classdb/Mesh"
	"graphics.gd/classdb/MeshInstance3D"
	"graphics.gd/variant/Vector3"
)

func ExampleArrayMesh() {
	var vertices = []Vector3.XYZ{
		{0, 1, 0},
		{1, 0, 0},
		{0, 0, 1},
	}
	// Initialize the ArrayMesh.
	var arrMesh = ArrayMesh.New()
	var arrays = make([]any, Mesh.ArrayMax)
	arrays[Mesh.ArrayVertex] = vertices

	// Create the Mesh.
	arrMesh.AddSurfaceFromArrays(Mesh.PrimitiveTriangles, arrays)
	var m = MeshInstance3D.New()
	m.SetMesh(arrMesh.AsMesh())
}

The MeshInstance3D is ready to be added to the SceneTree to be shown.

See also ImmediateMesh, MeshDataTool and SurfaceTool for procedural geometry generation.

Note: Godot uses clockwise winding order for front faces of triangle primitive modes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsArrayMesh() Instance
}

type Expanded

type Expanded = MoreArgs

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsArrayMesh

func (self *Extension[T]) AsArrayMesh() Instance

func (*Extension[T]) AsMesh

func (self *Extension[T]) AsMesh() Mesh.Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

func (*Extension[T]) AsRefCounted

func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted

func (*Extension[T]) AsResource

func (self *Extension[T]) AsResource() Resource.Instance

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.ArrayMesh

Instance of the class with convieniently typed arguments and results.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func GetDebug

func GetDebug(peer Shape3D.Instance) Instance

Returns the [ArrayMesh] used to draw the debug collision for this [Shape3D].

func New

func New() Instance

func (Instance) AddBlendShape

func (self Instance) AddBlendShape(name string)

Adds name for a blend shape that will be added with AddSurfaceFromArrays. Must be called before surface is added.

func (Instance) AddSurfaceFromArrays

func (self Instance) AddSurfaceFromArrays(primitive Mesh.PrimitiveType, arrays []any)

Creates a new surface. Mesh.GetSurfaceCount will become the surf_idx for this new surface.

Surfaces are created to be rendered using a 'primitive', which may be any of the values defined in [Mesh.PrimitiveType].

The 'arrays' argument is an array of arrays. Each of the [Mesh.ArrayMax] elements contains an array with some of the mesh data for this surface as described by the corresponding member of [Mesh.ArrayType] or null if it is not used by the surface. For example, arrays[0] is the array of vertices. That first vertex sub-array is always required; the others are optional. Adding an index array puts this surface into "index mode" where the vertex and other arrays become the sources of data and the index array defines the vertex order. All sub-arrays must have the same length as the vertex array (or be an exact multiple of the vertex array's length, when multiple elements of a sub-array correspond to a single vertex) or be empty, except for [Mesh.ArrayIndex] if it is used.

The 'blend_shapes' argument is an array of vertex data for each blend shape. Each element is an array of the same structure as 'arrays', but [Mesh.ArrayVertex], [Mesh.ArrayNormal], and [Mesh.ArrayTangent] are set if and only if they are set in 'arrays' and all other entries are null.

The 'lods' argument is a dictionary with Float.X keys and []int32 values. Each entry in the dictionary represents an LOD level of the surface, where the value is the [Mesh.ArrayIndex] array to use for the LOD level and the key is roughly proportional to the distance at which the LOD stats being used. I.e., increasing the key of an LOD also increases the distance that the objects has to be from the camera before the LOD is used.

The 'flags' argument is the bitwise OR of, as required: One value of [Mesh.ArrayCustomFormat] left shifted by ARRAY_FORMAT_CUSTOMn_SHIFT for each custom channel in use, [Mesh.ArrayFlagUseDynamicUpdate], [Mesh.ArrayFlagUse8BoneWeights], or [Mesh.ArrayFlagUsesEmptyVertexArray].

Note: When using indices, it is recommended to only use points, lines, or triangles.

func (Instance) AsArrayMesh

func (self Instance) AsArrayMesh() Instance

func (Instance) AsMesh

func (self Instance) AsMesh() Mesh.Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsRefCounted

func (self Instance) AsRefCounted() [1]gd.RefCounted

func (Instance) AsResource

func (self Instance) AsResource() Resource.Instance

func (Instance) BlendShapeMode

func (self Instance) BlendShapeMode() Mesh.BlendShapeMode

func (Instance) ClearBlendShapes

func (self Instance) ClearBlendShapes()

Removes all blend shapes from this ArrayMesh.

func (Instance) ClearSurfaces

func (self Instance) ClearSurfaces()

Removes all surfaces from this ArrayMesh.

func (Instance) CustomAabb

func (self Instance) CustomAabb() AABB.PositionSize

func (Instance) GetBlendShapeCount

func (self Instance) GetBlendShapeCount() int

Returns the number of blend shapes that the ArrayMesh holds.

func (Instance) GetBlendShapeName

func (self Instance) GetBlendShapeName(index int) string

Returns the name of the blend shape at this index.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) LightmapUnwrap

func (self Instance) LightmapUnwrap(transform Transform3D.BasisOrigin, texel_size Float.X) error

Performs a UV unwrap on the ArrayMesh to prepare the mesh for lightmapping.

func (Instance) MoreArgs

func (self Instance) MoreArgs() MoreArgs

MoreArgs enables certain functions to be called with additional 'optional' arguments.

func (Instance) RegenNormalMaps

func (self Instance) RegenNormalMaps()

Regenerates tangents for each of the ArrayMesh's surfaces.

func (Instance) SetBlendShapeMode

func (self Instance) SetBlendShapeMode(value Mesh.BlendShapeMode)

func (Instance) SetBlendShapeName

func (self Instance) SetBlendShapeName(index int, name string)

Sets the name of the blend shape at this index.

func (Instance) SetCustomAabb

func (self Instance) SetCustomAabb(value AABB.PositionSize)

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) SetShadowMesh

func (self Instance) SetShadowMesh(value Instance)

func (Instance) ShadowMesh

func (self Instance) ShadowMesh() Instance

func (Instance) SurfaceFindByName

func (self Instance) SurfaceFindByName(name string) int

Returns the index of the first surface with this name held within this ArrayMesh. If none are found, -1 is returned.

func (Instance) SurfaceGetArrayIndexLen

func (self Instance) SurfaceGetArrayIndexLen(surf_idx int) int

Returns the length in indices of the index array in the requested surface (see AddSurfaceFromArrays).

func (Instance) SurfaceGetArrayLen

func (self Instance) SurfaceGetArrayLen(surf_idx int) int

Returns the length in vertices of the vertex array in the requested surface (see AddSurfaceFromArrays).

func (Instance) SurfaceGetFormat

func (self Instance) SurfaceGetFormat(surf_idx int) Mesh.ArrayFormat

Returns the format mask of the requested surface (see AddSurfaceFromArrays).

func (Instance) SurfaceGetName

func (self Instance) SurfaceGetName(surf_idx int) string

Gets the name assigned to this surface.

func (Instance) SurfaceGetPrimitiveType

func (self Instance) SurfaceGetPrimitiveType(surf_idx int) Mesh.PrimitiveType

Returns the primitive type of the requested surface (see AddSurfaceFromArrays).

func (Instance) SurfaceRemove

func (self Instance) SurfaceRemove(surf_idx int)

Removes the surface at the given index from the Mesh, shifting surfaces with higher index down by one.

func (Instance) SurfaceSetName

func (self Instance) SurfaceSetName(surf_idx int, name string)

Sets a name for a given surface.

func (Instance) SurfaceUpdateAttributeRegion

func (self Instance) SurfaceUpdateAttributeRegion(surf_idx int, offset int, data []byte)

func (Instance) SurfaceUpdateSkinRegion

func (self Instance) SurfaceUpdateSkinRegion(surf_idx int, offset int, data []byte)

func (Instance) SurfaceUpdateVertexRegion

func (self Instance) SurfaceUpdateVertexRegion(surf_idx int, offset int, data []byte)

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

type MoreArgs

type MoreArgs [1]gdclass.ArrayMesh

MoreArgs is a container for Instance functions with additional 'optional' arguments.

func (MoreArgs) AddSurfaceFromArrays

func (self MoreArgs) AddSurfaceFromArrays(primitive Mesh.PrimitiveType, arrays []any, blend_shapes [][][]interface{}, lods map[float32][]int32, flags Mesh.ArrayFormat)

Creates a new surface. Mesh.GetSurfaceCount will become the surf_idx for this new surface.

Surfaces are created to be rendered using a 'primitive', which may be any of the values defined in [Mesh.PrimitiveType].

The 'arrays' argument is an array of arrays. Each of the [Mesh.ArrayMax] elements contains an array with some of the mesh data for this surface as described by the corresponding member of [Mesh.ArrayType] or null if it is not used by the surface. For example, arrays[0] is the array of vertices. That first vertex sub-array is always required; the others are optional. Adding an index array puts this surface into "index mode" where the vertex and other arrays become the sources of data and the index array defines the vertex order. All sub-arrays must have the same length as the vertex array (or be an exact multiple of the vertex array's length, when multiple elements of a sub-array correspond to a single vertex) or be empty, except for [Mesh.ArrayIndex] if it is used.

The 'blend_shapes' argument is an array of vertex data for each blend shape. Each element is an array of the same structure as 'arrays', but [Mesh.ArrayVertex], [Mesh.ArrayNormal], and [Mesh.ArrayTangent] are set if and only if they are set in 'arrays' and all other entries are null.

The 'lods' argument is a dictionary with Float.X keys and []int32 values. Each entry in the dictionary represents an LOD level of the surface, where the value is the [Mesh.ArrayIndex] array to use for the LOD level and the key is roughly proportional to the distance at which the LOD stats being used. I.e., increasing the key of an LOD also increases the distance that the objects has to be from the camera before the LOD is used.

The 'flags' argument is the bitwise OR of, as required: One value of [Mesh.ArrayCustomFormat] left shifted by ARRAY_FORMAT_CUSTOMn_SHIFT for each custom channel in use, [Mesh.ArrayFlagUseDynamicUpdate], [Mesh.ArrayFlagUse8BoneWeights], or [Mesh.ArrayFlagUsesEmptyVertexArray].

Note: When using indices, it is recommended to only use points, lines, or triangles.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL