Class ArrayMesh
- Namespace
- Godot
- Assembly
- GodotSharp.dll
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:
var vertices = new Vector3[]
{
new Vector3(0, 1, 0),
new Vector3(1, 0, 0),
new Vector3(0, 0, 1),
};
// Initialize the ArrayMesh.
var arrMesh = new ArrayMesh();
var arrays = new Godot.Collections.Array();
arrays.Resize((int)Mesh.ArrayType.Max);
arrays[(int)Mesh.ArrayType.Vertex] = vertices;
// Create the Mesh.
arrMesh.AddSurfaceFromArrays(Mesh.PrimitiveType.Triangles, arrays);
var m = new MeshInstance3D();
m.Mesh = arrMesh;
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.
public class ArrayMesh : Mesh, IDisposable
- Inheritance
-
ArrayMesh
- Implements
- Inherited Members
Constructors
ArrayMesh()
public ArrayMesh()
Properties
BlendShapeMode
Sets the blend shape mode to one of Mesh.BlendShapeMode.
public Mesh.BlendShapeMode BlendShapeMode { get; set; }
Property Value
CustomAabb
Overrides the Aabb with one defined by user for use with frustum culling. Especially useful to avoid unexpected culling when using a shader to offset vertices.
public Aabb CustomAabb { get; set; }
Property Value
ShadowMesh
An optional mesh which is used for rendering shadows and can be used for the depth prepass. Can be used to increase performance of shadow rendering by using a mesh that only contains vertex position data (without normals, UVs, colors, etc.).
public ArrayMesh ShadowMesh { get; set; }
Property Value
_BlendShapeNames
public string[] _BlendShapeNames { get; set; }
Property Value
- string[]
_Surfaces
public Array _Surfaces { get; set; }
Property Value
Methods
AddBlendShape(StringName)
Adds name for a blend shape that will be added with AddSurfaceFromArrays(PrimitiveType, Array, Array<Array>, Dictionary, ArrayFormat). Must be called before surface is added.
public void AddBlendShape(StringName name)
Parameters
name
StringName
AddSurfaceFromArrays(PrimitiveType, Array, Array<Array>, Dictionary, ArrayFormat)
Creates a new surface. 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 Max 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 Index if it is used.
The blendShapes
argument is an array of vertex data for each blend shape. Each element is an array of the same structure as arrays
, but Vertex, Normal, and Tangent 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 keys and int[] values. Each entry in the dictionary represents a LOD level of the surface, where the value is the Index 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 a 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, FlagUseDynamicUpdate, FlagUse8BoneWeights, or FlagUsesEmptyVertexArray.
Note: When using indices, it is recommended to only use points, lines, or triangles.
public void AddSurfaceFromArrays(Mesh.PrimitiveType primitive, Array arrays, Array<Array> blendShapes = null, Dictionary lods = null, Mesh.ArrayFormat flags = (Mesh.ArrayFormat)0)
Parameters
primitive
Mesh.PrimitiveTypearrays
ArrayblendShapes
Array<Array>lods
Dictionaryflags
Mesh.ArrayFormat
ClearBlendShapes()
Removes all blend shapes from this ArrayMesh.
public void ClearBlendShapes()
ClearSurfaces()
Removes all surfaces from this ArrayMesh.
public void ClearSurfaces()
GetBlendShapeCount()
Returns the number of blend shapes that the ArrayMesh holds.
public int GetBlendShapeCount()
Returns
GetBlendShapeName(int)
Returns the name of the blend shape at this index.
public StringName GetBlendShapeName(int index)
Parameters
index
int
Returns
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
LightmapUnwrap(Transform3D, float)
Performs a UV unwrap on the ArrayMesh to prepare the mesh for lightmapping.
public Error LightmapUnwrap(Transform3D transform, float texelSize)
Parameters
transform
Transform3DtexelSize
float
Returns
RegenNormalMaps()
Regenerates tangents for each of the ArrayMesh's surfaces.
public void RegenNormalMaps()
SetBlendShapeName(int, StringName)
Sets the name of the blend shape at this index.
public void SetBlendShapeName(int index, StringName name)
Parameters
index
intname
StringName
SurfaceFindByName(string)
Returns the index of the first surface with this name held within this ArrayMesh. If none are found, -1 is returned.
public int SurfaceFindByName(string name)
Parameters
name
string
Returns
SurfaceGetArrayIndexLen(int)
Returns the length in indices of the index array in the requested surface (see AddSurfaceFromArrays(PrimitiveType, Array, Array<Array>, Dictionary, ArrayFormat)).
public int SurfaceGetArrayIndexLen(int surfIdx)
Parameters
surfIdx
int
Returns
SurfaceGetArrayLen(int)
Returns the length in vertices of the vertex array in the requested surface (see AddSurfaceFromArrays(PrimitiveType, Array, Array<Array>, Dictionary, ArrayFormat)).
public int SurfaceGetArrayLen(int surfIdx)
Parameters
surfIdx
int
Returns
SurfaceGetFormat(int)
Returns the format mask of the requested surface (see AddSurfaceFromArrays(PrimitiveType, Array, Array<Array>, Dictionary, ArrayFormat)).
public Mesh.ArrayFormat SurfaceGetFormat(int surfIdx)
Parameters
surfIdx
int
Returns
SurfaceGetName(int)
Gets the name assigned to this surface.
public string SurfaceGetName(int surfIdx)
Parameters
surfIdx
int
Returns
SurfaceGetPrimitiveType(int)
Returns the primitive type of the requested surface (see AddSurfaceFromArrays(PrimitiveType, Array, Array<Array>, Dictionary, ArrayFormat)).
public Mesh.PrimitiveType SurfaceGetPrimitiveType(int surfIdx)
Parameters
surfIdx
int
Returns
SurfaceSetName(int, string)
Sets a name for a given surface.
public void SurfaceSetName(int surfIdx, string name)
Parameters
SurfaceUpdateAttributeRegion(int, int, byte[])
public void SurfaceUpdateAttributeRegion(int surfIdx, int offset, byte[] data)
Parameters
SurfaceUpdateSkinRegion(int, int, byte[])
public void SurfaceUpdateSkinRegion(int surfIdx, int offset, byte[] data)
Parameters
SurfaceUpdateVertexRegion(int, int, byte[])
public void SurfaceUpdateVertexRegion(int surfIdx, int offset, byte[] data)