ArrayMesh¶
Inherits:Mesh<Resource<Reference<Object
Mesh type that provides utility for constructing a surface from arrays.
Description¶
TheArrayMesh is used to construct aMesh by specifying the attributes as arrays.
The most basic example is the creation of a single triangle:
varvertices=PoolVector3Array()vertices.push_back(Vector3(0,1,0))vertices.push_back(Vector3(1,0,0))vertices.push_back(Vector3(0,0,1))# Initialize the ArrayMesh.vararr_mesh=ArrayMesh.new()vararrays=[]arrays.resize(ArrayMesh.ARRAY_MAX)arrays[ArrayMesh.ARRAY_VERTEX]=vertices# Create the Mesh.arr_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES,arrays)varm=MeshInstance.new()m.mesh=arr_mesh
TheMeshInstance is ready to be added to theSceneTree to be shown.
See alsoImmediateGeometry,MeshDataTool andSurfaceTool for procedural geometry generation.
Note: Godot uses clockwisewinding order for front faces of triangle primitive modes.
Tutorials¶
Properties¶
| ||
|
Methods¶
void | add_blend_shape(String name) |
void | add_surface_from_arrays(PrimitiveType primitive,Array arrays,Array blend_shapes=[ ],int compress_flags=2194432) |
void | |
void | |
get_blend_shape_name(int index)const | |
lightmap_unwrap(Transform transform,float texel_size) | |
void | |
void | set_blend_shape_name(int index,String name) |
surface_get_array_index_len(int surf_idx)const | |
surface_get_array_len(int surf_idx)const | |
surface_get_format(int surf_idx)const | |
surface_get_name(int surf_idx)const | |
surface_get_primitive_type(int surf_idx)const | |
void | surface_remove(int surf_idx) |
void | surface_set_name(int surf_idx,String name) |
void | surface_update_region(int surf_idx,int offset,PoolByteArray data) |
Enumerations¶
enumArrayType:
ARRAY_VERTEX =0 ---PoolVector3Array,PoolVector2Array, orArray of vertex positions.
ARRAY_NORMAL =1 ---PoolVector3Array of vertex normals.
ARRAY_TANGENT =2 ---PoolRealArray of vertex tangents. Each element in groups of 4 floats, first 3 floats determine the tangent, and the last the binormal direction as -1 or 1.
ARRAY_COLOR =3 ---PoolColorArray of vertex colors.
ARRAY_TEX_UV =4 ---PoolVector2Array for UV coordinates.
ARRAY_TEX_UV2 =5 ---PoolVector2Array for second UV coordinates.
ARRAY_BONES =6 ---PoolRealArray orPoolIntArray of bone indices. Each element in groups of 4 floats.
ARRAY_WEIGHTS =7 ---PoolRealArray of bone weights. Each element in groups of 4 floats.
ARRAY_INDEX =8 ---PoolIntArray of integers used as indices referencing vertices, colors, normals, tangents, and textures. All of those arrays must have the same number of elements as the vertex array. No index can be beyond the vertex array size. When this index array is present, it puts the function into "index mode," where the index selects the *i*'th vertex, normal, tangent, color, UV, etc. This means if you want to have different normals or colors along an edge, you have to duplicate the vertices.
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.
ARRAY_MAX =9 --- Represents the size of theArrayType enum.
enumArrayFormat:
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¶
BlendShapeModeblend_shape_mode
Default |
|
Setter | set_blend_shape_mode(value) |
Getter | get_blend_shape_mode() |
Sets the blend shape mode to one ofBlendShapeMode.
AABBcustom_aabb
Default |
|
Setter | set_custom_aabb(value) |
Getter | get_custom_aabb() |
Overrides theAABB 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¶
voidadd_blend_shape(String name)
Adds name for a blend shape that will be added withadd_surface_from_arrays. Must be called before surface is added.
voidadd_surface_from_arrays(PrimitiveType primitive,Array arrays,Array blend_shapes=[ ],int compress_flags=2194432)
Creates a new surface.
Surfaces are created to be rendered using aprimitive, which may be any of the types defined inPrimitiveType. (As a note, when using indices, it is recommended to only use points, lines, or triangles.)Mesh.get_surface_count will become thesurf_idx for this new surface.
Thearrays argument is an array of arrays. SeeArrayType 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 forARRAY_INDEX if it is used.
voidclear_blend_shapes()
Removes all blend shapes from thisArrayMesh.
voidclear_surfaces()
Removes all surfaces from thisArrayMesh.
Returns the number of blend shapes that theArrayMesh holds.
Returns the name of the blend shape at this index.
Will perform a UV unwrap on theArrayMesh to prepare the mesh for lightmapping.
voidregen_normalmaps()
Will regenerate normal maps for theArrayMesh.
Returns the index of the first surface with this name held within thisArrayMesh. If none are found, -1 is returned.
Returns the length in indices of the index array in the requested surface (seeadd_surface_from_arrays).
Returns the length in vertices of the vertex array in the requested surface (seeadd_surface_from_arrays).
Returns the format mask of the requested surface (seeadd_surface_from_arrays).
Gets the name assigned to this surface.
PrimitiveTypesurface_get_primitive_type(int surf_idx)const
Returns the primitive type of the requested surface (seeadd_surface_from_arrays).
voidsurface_remove(int surf_idx)
Removes a surface at positionsurf_idx, shifting greater surfaces onesurf_idx slot down.
Sets a name for a given surface.
voidsurface_update_region(int surf_idx,int offset,PoolByteArray data)
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.