ArrayMesh
Inherits: Mesh < Resource < Shared < Object
Mesh type that provides utility for constructing a surface from arrays.
Description
Section titled “Description”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:
mut vertices : []Vector3 = []vertices.push_back(Vector3(0, 1, 0))vertices.push_back(Vector3(1, 0, 0))vertices.push_back(Vector3(0, 0, 1))
# Initialize the ArrayMesh.arr_mesh : ArrayMesh = ArrayMesh.new()mut arrays : Array = []arrays.resize(Mesh.ARRAY_MAX)arrays[Mesh.ARRAY_VERTEX] = vertices
# Create the Mesh.arr_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arrays)m : MeshInstance3D = MeshInstance3D.new()m.mesh = arr_meshThe MeshInstance3D is ready to be added to the SceneTree to be shown.
See also ImmediateMesh, MeshDataTool and SurfaceTool for procedural geometry generation.
Note: Gobu uses clockwise winding order for front faces of triangle primitive modes.
Properties
Section titled “Properties”| Type | Name | Default |
|---|---|---|
| Mesh.BlendShapeMode | blend_shape_mode | 1 |
| AABB | custom_aabb | AABB(0, 0, 0, 0, 0, 0) |
| ArrayMesh | shadow_mesh |
Methods
Section titled “Methods”| Returns | Method |
|---|---|
| void | add_blend_shape(name) |
| void | add_surface_from_arrays(primitive, arrays, blend_shapes, lods, flags) |
| void | clear_blend_shapes() |
| void | clear_surfaces() |
| int | get_blend_shape_count() |
| StringName | get_blend_shape_name(index) |
| Error | lightmap_unwrap(transform, texel_size) |
| void | regen_normal_maps() |
| void | set_blend_shape_name(index, name) |
| int | surface_find_by_name(name) |
| int | surface_get_array_index_len(surf_idx) |
| int | surface_get_array_len(surf_idx) |
| Mesh.ArrayFormat | surface_get_format(surf_idx) |
| String | surface_get_name(surf_idx) |
| Mesh.PrimitiveType | surface_get_primitive_type(surf_idx) |
| void | surface_remove(surf_idx) |
| void | surface_set_name(surf_idx, name) |
| void | surface_update_attribute_region(surf_idx, offset, data) |
| void | surface_update_skin_region(surf_idx, offset, data) |
| void | surface_update_vertex_region(surf_idx, offset, data) |
Property descriptions
Section titled “Property descriptions”blend_shape_mode
Section titled “blend_shape_mode”Mesh.BlendShapeMode blend_shape_mode = 1
Setter/getter: set_blend_shape_mode(), get_blend_shape_mode()
The blend shape mode.
custom_aabb
Section titled “custom_aabb”AABB custom_aabb = AABB(0, 0, 0, 0, 0, 0)
Setter/getter: set_custom_aabb(), get_custom_aabb()
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.
shadow_mesh
Section titled “shadow_mesh”ArrayMesh shadow_mesh
Setter/getter: set_shadow_mesh(), get_shadow_mesh()
An optional mesh which can be used for rendering shadows and the depth prepass. Can be used to increase performance by supplying a mesh with fused vertices and only vertex position data (without normals, UVs, colors, etc.).
Note: This mesh must have exactly the same vertex positions as the source mesh (including the source mesh’s LODs, if present). If vertex positions differ, then the mesh will not draw correctly.
Method descriptions
Section titled “Method descriptions”add_blend_shape
Section titled “add_blend_shape”void add_blend_shape(name: StringName)
Adds name for a blend shape that will be added with add_surface_from_arrays(). Must be called before surface is added.
add_surface_from_arrays
Section titled “add_surface_from_arrays”void add_surface_from_arrays(primitive: Mesh.PrimitiveType, arrays: Array, blend_shapes: []Array = [], lods: Dictionary = {}, flags: Mesh.ArrayFormat = 0)
Creates a new surface. Mesh.get_surface_count() 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.ARRAY_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 Mesh.ARRAY_INDEX 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.ARRAY_VERTEX, Mesh.ARRAY_NORMAL, and Mesh.ARRAY_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 []i32 values. Each entry in the dictionary represents an LOD level of the surface, where the value is the Mesh.ARRAY_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 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.ARRAY_FLAG_USE_DYNAMIC_UPDATE, Mesh.ARRAY_FLAG_USE_8_BONE_WEIGHTS, or Mesh.ARRAY_FLAG_USES_EMPTY_VERTEX_ARRAY.
Note: When using indices, it is recommended to only use points, lines, or triangles.
clear_blend_shapes
Section titled “clear_blend_shapes”void clear_blend_shapes()
Removes all blend shapes from this ArrayMesh.
clear_surfaces
Section titled “clear_surfaces”void clear_surfaces()
Removes all surfaces from this ArrayMesh.
get_blend_shape_count
Section titled “get_blend_shape_count”int get_blend_shape_count() const
Returns the number of blend shapes that the ArrayMesh holds.
get_blend_shape_name
Section titled “get_blend_shape_name”StringName get_blend_shape_name(index: int) const
Returns the name of the blend shape at this index.
lightmap_unwrap
Section titled “lightmap_unwrap”Error lightmap_unwrap(transform: Transform3D, texel_size: float)
Performs a UV unwrap on the ArrayMesh to prepare the mesh for lightmapping.
regen_normal_maps
Section titled “regen_normal_maps”void regen_normal_maps()
Regenerates tangents for each of the ArrayMesh’s surfaces.
set_blend_shape_name
Section titled “set_blend_shape_name”void set_blend_shape_name(index: int, name: StringName)
Sets the name of the blend shape at this index.
surface_find_by_name
Section titled “surface_find_by_name”int surface_find_by_name(name: String) const
Returns the index of the first surface with this name held within this ArrayMesh. If none are found, -1 is returned.
surface_get_array_index_len
Section titled “surface_get_array_index_len”int surface_get_array_index_len(surf_idx: int) const
Returns the length in indices of the index array in the requested surface (see add_surface_from_arrays()).
surface_get_array_len
Section titled “surface_get_array_len”int surface_get_array_len(surf_idx: int) const
Returns the length in vertices of the vertex array in the requested surface (see add_surface_from_arrays()).
surface_get_format
Section titled “surface_get_format”Mesh.ArrayFormat surface_get_format(surf_idx: int) const
Returns the format mask of the requested surface (see add_surface_from_arrays()).
surface_get_name
Section titled “surface_get_name”String surface_get_name(surf_idx: int) const
Gets the name assigned to this surface.
surface_get_primitive_type
Section titled “surface_get_primitive_type”Mesh.PrimitiveType surface_get_primitive_type(surf_idx: int) const
Returns the primitive type of the requested surface (see add_surface_from_arrays()).
surface_remove
Section titled “surface_remove”void surface_remove(surf_idx: int)
Removes the surface at the given index from the Mesh, shifting surfaces with higher index down by one.
surface_set_name
Section titled “surface_set_name”void surface_set_name(surf_idx: int, name: String)
Sets a name for a given surface.
surface_update_attribute_region
Section titled “surface_update_attribute_region”void surface_update_attribute_region(surf_idx: int, offset: int, data: []u8)
Updates the attribute buffer of this mesh’s surface with the given data. The expected data per attribute is 12 or 8 bytes (4 bytes per float, 2 floats per Vector2, and 3 floats per Vector3) depending on if the mesh is using Vector3 or Vector2 vertices. This value can be determined with Render.mesh_surface_get_format_attribute_stride().
The starting point of the updates can be changed with offset. The value of offset should be a multiple of 12 bytes in most cases to align to each attribute.
A []Vector3 of attribute locations can be converted into a []u8 using PackedVector3Array.to_byte_array() for use in data.
surface_update_skin_region
Section titled “surface_update_skin_region”void surface_update_skin_region(surf_idx: int, offset: int, data: []u8)
Updates the skin buffer of this mesh’s surface with the given data. The expected data per skin is 12 or 8 bytes (4 bytes per float, 2 floats per Vector2, and 3 floats per Vector3) depending on if the mesh is using Vector3 or Vector2 vertices. This value can be determined with Render.mesh_surface_get_format_skin_stride().
The starting point of the updates can be changed with offset. The value of offset should be a multiple of 12 bytes in most cases to align to each skin.
A []Vector3 of skin locations can be converted into a []u8 using PackedVector3Array.to_byte_array() for use in data.
surface_update_vertex_region
Section titled “surface_update_vertex_region”void surface_update_vertex_region(surf_idx: int, offset: int, data: []u8)
Updates the vertex buffer of this mesh’s surface with the given data. The expected data per vertex is 12 or 8 bytes (4 bytes per float, 2 floats per Vector2, and 3 floats per Vector3) depending on if the mesh is using Vector3 or Vector2 vertices. This value can be determined with Render.mesh_surface_get_format_vertex_stride().
The starting point of the updates can be changed with offset. The value of offset should be a multiple of 12 bytes in most cases to align to each vertex.
A []Vector3 of vertex locations can be converted into a []u8 using PackedVector3Array.to_byte_array() for use in data.