Skip to content

Latest commit

 

History

History
365 lines (218 loc) · 24.3 KB

class_arraymesh.rst

File metadata and controls

365 lines (218 loc) · 24.3 KB
github_url:hide

ArrayMesh

Inherits: :ref:`Mesh<class_Mesh>` < :ref:`Resource<class_Resource>` < :ref:`Reference<class_Reference>` < :ref:`Object<class_Object>`

:ref:`Mesh<class_Mesh>` type that provides utility for constructing a surface from arrays.

Description

The ArrayMesh is used to construct a :ref:`Mesh<class_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(ArrayMesh.ARRAY_MAX)
arrays[ArrayMesh.ARRAY_VERTEX] = vertices
# Create the Mesh.
arr_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arrays)
var m = MeshInstance.new()
m.mesh = arr_mesh

The :ref:`MeshInstance<class_MeshInstance>` is ready to be added to the :ref:`SceneTree<class_SceneTree>` to be shown.

Tutorials

Properties

:ref:`BlendShapeMode<enum_Mesh_BlendShapeMode>` :ref:`blend_shape_mode<class_ArrayMesh_property_blend_shape_mode>` 1
:ref:`AABB<class_AABB>` :ref:`custom_aabb<class_ArrayMesh_property_custom_aabb>` AABB( 0, 0, 0, 0, 0, 0 )

Methods

void :ref:`add_blend_shape<class_ArrayMesh_method_add_blend_shape>` ( :ref:`StringName<class_StringName>` name )
void :ref:`add_surface_from_arrays<class_ArrayMesh_method_add_surface_from_arrays>` ( :ref:`PrimitiveType<enum_Mesh_PrimitiveType>` primitive, :ref:`Array<class_Array>` arrays, :ref:`Array<class_Array>` blend_shapes=[ ], :ref:`Dictionary<class_Dictionary>` lods={ }, :ref:`int<class_int>` compress_flags=31744 )
void :ref:`clear_blend_shapes<class_ArrayMesh_method_clear_blend_shapes>` ( )
void :ref:`clear_surfaces<class_ArrayMesh_method_clear_surfaces>` ( )
:ref:`int<class_int>` :ref:`get_blend_shape_count<class_ArrayMesh_method_get_blend_shape_count>` ( ) const
:ref:`StringName<class_StringName>` :ref:`get_blend_shape_name<class_ArrayMesh_method_get_blend_shape_name>` ( :ref:`int<class_int>` index ) const
:ref:`Error<enum_@GlobalScope_Error>` :ref:`lightmap_unwrap<class_ArrayMesh_method_lightmap_unwrap>` ( :ref:`Transform<class_Transform>` transform, :ref:`float<class_float>` texel_size )
void :ref:`regen_normalmaps<class_ArrayMesh_method_regen_normalmaps>` ( )
:ref:`int<class_int>` :ref:`surface_find_by_name<class_ArrayMesh_method_surface_find_by_name>` ( :ref:`String<class_String>` name ) const
:ref:`int<class_int>` :ref:`surface_get_array_index_len<class_ArrayMesh_method_surface_get_array_index_len>` ( :ref:`int<class_int>` surf_idx ) const
:ref:`int<class_int>` :ref:`surface_get_array_len<class_ArrayMesh_method_surface_get_array_len>` ( :ref:`int<class_int>` surf_idx ) const
:ref:`int<class_int>` :ref:`surface_get_format<class_ArrayMesh_method_surface_get_format>` ( :ref:`int<class_int>` surf_idx ) const
:ref:`String<class_String>` :ref:`surface_get_name<class_ArrayMesh_method_surface_get_name>` ( :ref:`int<class_int>` surf_idx ) const
:ref:`PrimitiveType<enum_Mesh_PrimitiveType>` :ref:`surface_get_primitive_type<class_ArrayMesh_method_surface_get_primitive_type>` ( :ref:`int<class_int>` surf_idx ) const
void :ref:`surface_set_name<class_ArrayMesh_method_surface_set_name>` ( :ref:`int<class_int>` surf_idx, :ref:`String<class_String>` name )
void :ref:`surface_update_region<class_ArrayMesh_method_surface_update_region>` ( :ref:`int<class_int>` surf_idx, :ref:`int<class_int>` offset, :ref:`PackedByteArray<class_PackedByteArray>` data )

Enumerations

enum ArrayType:

For triangles, the index array is interpreted as triples, referring to the vertices of each triangle. For lines, the index array is in pairs indicating the start and end of each line.


enum ArrayFormat:

  • ARRAY_FORMAT_VERTEX = 1 --- Array format will include vertices (mandatory).
  • ARRAY_FORMAT_NORMAL = 2 --- Array format will include normals.
  • ARRAY_FORMAT_TANGENT = 4 --- Array format will include tangents.
  • ARRAY_FORMAT_COLOR = 8 --- Array format will include a color array.
  • ARRAY_FORMAT_TEX_UV = 16 --- Array format will include UVs.
  • ARRAY_FORMAT_TEX_UV2 = 32 --- Array format will include another set of UVs.
  • ARRAY_FORMAT_BONES = 64 --- Array format will include bone indices.
  • ARRAY_FORMAT_WEIGHTS = 128 --- Array format will include bone weights.
  • ARRAY_FORMAT_INDEX = 256 --- Index array will be used.

Constants

  • NO_INDEX_ARRAY = -1 --- Default value used for index_array_len when no indices are present.
  • ARRAY_WEIGHTS_SIZE = 4 --- Amount of weights/bone indices per vertex (always 4).

Property Descriptions

Default 1
Setter set_blend_shape_mode(value)
Getter get_blend_shape_mode()

Sets the blend shape mode to one of :ref:`BlendShapeMode<enum_Mesh_BlendShapeMode>`.


Default AABB( 0, 0, 0, 0, 0, 0 )
Setter set_custom_aabb(value)
Getter get_custom_aabb()

Overrides the :ref:`AABB<class_AABB>` with one defined by user for use with frustum culling. Especially useful to avoid unexpected culling when using a shader to offset vertices.

Method Descriptions

Adds name for a blend shape that will be added with :ref:`add_surface_from_arrays<class_ArrayMesh_method_add_surface_from_arrays>`. Must be called before surface is added.


Creates a new surface.

Surfaces are created to be rendered using a primitive, which may be any of the types defined in :ref:`PrimitiveType<enum_Mesh_PrimitiveType>`. (As a note, when using indices, it is recommended to only use points, lines or triangles.) :ref:`Mesh.get_surface_count<class_Mesh_method_get_surface_count>` will become the surf_idx for this new surface.

The arrays argument is an array of arrays. See :ref:`ArrayType<enum_ArrayMesh_ArrayType>` for the values used in this array. 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 function 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 empty, except for :ref:`ARRAY_INDEX<class_ArrayMesh_constant_ARRAY_INDEX>` if it is used.

Adding an index array puts this function into "index mode" where the vertex and other arrays become the sources of data, and the index array defines the order of the vertices.

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


  • void clear_blend_shapes ( )

Removes all blend shapes from this ArrayMesh.


  • void clear_surfaces ( )

Removes all surfaces from this ArrayMesh.


Returns the number of blend shapes that the ArrayMesh holds.


Returns the name of the blend shape at this index.


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


  • void regen_normalmaps ( )

Will regenerate normal maps for the ArrayMesh.


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


Returns the length in indices of the index array in the requested surface (see :ref:`add_surface_from_arrays<class_ArrayMesh_method_add_surface_from_arrays>`).


Returns the length in vertices of the vertex array in the requested surface (see :ref:`add_surface_from_arrays<class_ArrayMesh_method_add_surface_from_arrays>`).


Returns the format mask of the requested surface (see :ref:`add_surface_from_arrays<class_ArrayMesh_method_add_surface_from_arrays>`).


Gets the name assigned to this surface.


Returns the primitive type of the requested surface (see :ref:`add_surface_from_arrays<class_ArrayMesh_method_add_surface_from_arrays>`).


Sets a name for a given surface.


Updates a specified region of mesh arrays on the GPU.

Warning: Only use if you know what you are doing. You can easily cause crashes by calling this function with improper arguments.