Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

ArrayMesh

Inherits: Mesh < Resource < RefCounted < Object

Mesh type that provides utility for constructing a surface from arrays.

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:

var vertices = PackedVector3Array()
vertices.push_back(Vector3(0, 1, 0))
vertices.push_back(Vector3(1, 0, 0))
vertices.push_back(Vector3(0, 0, 1))

# Initialize the ArrayMesh.
var arr_mesh = ArrayMesh.new()
var arrays = []
arrays.resize(Mesh.ARRAY_MAX)
arrays[Mesh.ARRAY_VERTEX] = vertices

# Create the Mesh.
arr_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arrays)
var m = MeshInstance3D.new()
m.mesh = arr_mesh

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.

Tutorials

Properties

BlendShapeMode

blend_shape_mode

1

AABB

custom_aabb

AABB(0, 0, 0, 0, 0, 0)

ArrayMesh

shadow_mesh

Methods

void

add_blend_shape ( StringName name )

void

add_surface_from_arrays ( PrimitiveType primitive, Array arrays, Array[] blend_shapes=[], Dictionary lods={}, BitField<ArrayFormat> flags=0 )

void

clear_blend_shapes ( )

void

clear_surfaces ( )

int

get_blend_shape_count ( ) const

StringName

get_blend_shape_name ( int index ) const

Error

lightmap_unwrap ( Transform3D transform, float texel_size )

void

regen_normal_maps ( )

void

set_blend_shape_name ( int index, StringName name )

int

surface_find_by_name ( String name ) const

int

surface_get_array_index_len ( int surf_idx ) const

int

surface_get_array_len ( int surf_idx ) const

BitField<ArrayFormat>

surface_get_format ( int surf_idx ) const

String

surface_get_name ( int surf_idx ) const

PrimitiveType

surface_get_primitive_type ( int surf_idx ) const

void

surface_set_name ( int surf_idx, String name )

void

surface_update_attribute_region ( int surf_idx, int offset, PackedByteArray data )

void

surface_update_skin_region ( int surf_idx, int offset, PackedByteArray data )

void

surface_update_vertex_region ( int surf_idx, int offset, PackedByteArray data )


Property Descriptions

BlendShapeMode blend_shape_mode = 1

Sets the blend shape mode to one of BlendShapeMode.


AABB custom_aabb = AABB(0, 0, 0, 0, 0, 0)

  • void set_custom_aabb ( AABB value )

  • 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.


ArrayMesh shadow_mesh

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.).


Method Descriptions

void add_blend_shape ( StringName name )

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


void add_surface_from_arrays ( PrimitiveType primitive, Array arrays, Array[] blend_shapes=[], Dictionary lods={}, BitField&