Class reference

Mesh

Inherits Resource

A Resource that contains vertex array-based geometry.

Description

Mesh is a type of Resource that contains vertex array-based geometry, divided in surfaces. Each surface contains a completely separate array and a material used to draw it. Design wise, a mesh with multiple surfaces is preferred to a single surface, because objects created in 3D editing software commonly contain multiple materials. The maximum number of surfaces per mesh is RenderingServer.MAX_MESH_SURFACES.

Properties

Vector2i lightmap_size_hint = Vector2i(0, 0)

Sets a hint to be used for lightmap resolution.

Methods

AABB _get_aabb() virtual required const

Virtual method to override the AABB for a custom class extending Mesh.

int _get_blend_shape_count() virtual required const

Virtual method to override the number of blend shapes for a custom class extending Mesh.

StringName _get_blend_shape_name(int index) virtual required const

Virtual method to override the retrieval of blend shape names for a custom class extending Mesh.

int _get_surface_count() virtual required const

Virtual method to override the surface count for a custom class extending Mesh.

void _set_blend_shape_name(int index, StringName name) virtual required

Virtual method to override the names of blend shapes for a custom class extending Mesh.

int _surface_get_array_index_len(int index) virtual required const

Virtual method to override the surface array index length for a custom class extending Mesh.

int _surface_get_array_len(int index) virtual required const

Virtual method to override the surface array length for a custom class extending Mesh.

Array _surface_get_arrays(int index) virtual required const

Virtual method to override the surface arrays for a custom class extending Mesh.

Array[] _surface_get_blend_shape_arrays(int index) virtual required const

Virtual method to override the blend shape arrays for a custom class extending Mesh.

int _surface_get_format(int index) virtual required const

Virtual method to override the surface format for a custom class extending Mesh.

Dictionary _surface_get_lods(int index) virtual required const

Virtual method to override the surface LODs for a custom class extending Mesh.

Material _surface_get_material(int index) virtual required const

Virtual method to override the surface material for a custom class extending Mesh.

int _surface_get_primitive_type(int index) virtual required const

Virtual method to override the surface primitive type for a custom class extending Mesh.

void _surface_set_material(int index, Material material) virtual required

Virtual method to override the setting of a material at the given index for a custom class extending Mesh.

ConvexPolygonShape3D create_convex_shape(bool clean = true, bool simplify = false) const

Calculate a ConvexPolygonShape3D from the mesh. If clean is true (default), duplicate and interior vertices are removed automatically. You can set it to false to make the process faster if not needed. If simplify is true, the geometry can be further simplified to reduce the number of vertices. Disabled by default.

Mesh create_outline(float margin) const

Calculate an outline mesh at a defined offset (margin) from the original mesh. Note: This method typically returns the vertices in reverse order (e.g. clockwise to counterclockwise).

AABB get_aabb() const

Returns the smallest AABB enclosing this mesh in local space. Not affected by custom_aabb. Note: This is only implemented for ArrayMesh and PrimitiveMesh.

PackedVector3Array get_faces() const

Returns all the vertices that make up the faces of the mesh. Each three vertices represent one triangle.

Array[] surface_get_blend_shape_arrays(int surf_idx) const

Returns the blend shape arrays for the requested surface.

Constants

PRIMITIVE_POINTS = 0

Enum: PrimitiveType

Render array as points (one vertex equals one point).

PRIMITIVE_LINES = 1

Enum: PrimitiveType

Render array as lines (every two vertices a line is created).

PRIMITIVE_LINE_STRIP = 2

Enum: PrimitiveType

Render array as line strip.

PRIMITIVE_TRIANGLES = 3

Enum: PrimitiveType

Render array as triangles (every three vertices a triangle is created).

PRIMITIVE_TRIANGLE_STRIP = 4

Enum: PrimitiveType

Render array as triangle strips.

ARRAY_NORMAL = 1

Enum: ArrayType

PackedVector3Array of vertex normals. Note: The array has to consist of normal vectors, otherwise they will be normalized by the engine, potentially causing visual discrepancies.

ARRAY_TANGENT = 2

Enum: ArrayType

PackedFloat32Array 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_INDEX = 12

Enum: ArrayType

PackedInt32Array 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 = 13

Enum: ArrayType

Represents the size of the ArrayType enum.

ARRAY_CUSTOM_RGBA8_UNORM = 0

Enum: ArrayCustomFormat

Indicates this custom channel contains unsigned normalized byte colors from 0 to 1, encoded as PackedByteArray.

ARRAY_CUSTOM_RGBA8_SNORM = 1

Enum: ArrayCustomFormat

Indicates this custom channel contains signed normalized byte colors from -1 to 1, encoded as PackedByteArray.

ARRAY_CUSTOM_RG_HALF = 2

Enum: ArrayCustomFormat

Indicates this custom channel contains half precision float colors, encoded as PackedByteArray. Only red and green channels are used.

ARRAY_CUSTOM_RGBA_HALF = 3

Enum: ArrayCustomFormat

Indicates this custom channel contains half precision float colors, encoded as PackedByteArray.

ARRAY_CUSTOM_R_FLOAT = 4

Enum: ArrayCustomFormat

Indicates this custom channel contains full float colors, in a PackedFloat32Array. Only the red channel is used.

ARRAY_CUSTOM_RG_FLOAT = 5

Enum: ArrayCustomFormat

Indicates this custom channel contains full float colors, in a PackedFloat32Array. Only red and green channels are used.

ARRAY_CUSTOM_RGB_FLOAT = 6

Enum: ArrayCustomFormat

Indicates this custom channel contains full float colors, in a PackedFloat32Array. Only red, green and blue channels are used.

ARRAY_CUSTOM_RGBA_FLOAT = 7

Enum: ArrayCustomFormat

Indicates this custom channel contains full float colors, in a PackedFloat32Array.

ARRAY_CUSTOM_MAX = 8

Enum: ArrayCustomFormat

Represents the size of the ArrayCustomFormat enum.

ARRAY_FORMAT_VERTEX = 1

Enum: ArrayFormat

Mesh array contains vertices. All meshes require a vertex array so this should always be present.

ARRAY_FORMAT_NORMAL = 2

Enum: ArrayFormat

Mesh array contains normals.

ARRAY_FORMAT_TANGENT = 4

Enum: ArrayFormat

Mesh array contains tangents.

ARRAY_FORMAT_COLOR = 8

Enum: ArrayFormat

Mesh array contains colors.

ARRAY_FORMAT_TEX_UV = 16

Enum: ArrayFormat

Mesh array contains UVs.

ARRAY_FORMAT_TEX_UV2 = 32

Enum: ArrayFormat

Mesh array contains second UV.

ARRAY_FORMAT_CUSTOM0 = 64

Enum: ArrayFormat

Mesh array contains custom channel index 0.

ARRAY_FORMAT_CUSTOM1 = 128

Enum: ArrayFormat

Mesh array contains custom channel index 1.

ARRAY_FORMAT_CUSTOM2 = 256

Enum: ArrayFormat

Mesh array contains custom channel index 2.

ARRAY_FORMAT_CUSTOM3 = 512

Enum: ArrayFormat

Mesh array contains custom channel index 3.

ARRAY_FORMAT_BONES = 1024

Enum: ArrayFormat

Mesh array contains bones.

ARRAY_FORMAT_WEIGHTS = 2048

Enum: ArrayFormat

Mesh array contains bone weights.

ARRAY_FORMAT_INDEX = 4096

Enum: ArrayFormat

Mesh array uses indices.

ARRAY_FORMAT_BLEND_SHAPE_MASK = 7

Enum: ArrayFormat

Mask of mesh channels permitted in blend shapes.

ARRAY_FORMAT_CUSTOM_BASE = 13

Enum: ArrayFormat

Shift of first custom channel.

ARRAY_FORMAT_CUSTOM_BITS = 3

Enum: ArrayFormat

Number of format bits per custom channel. See ArrayCustomFormat.

ARRAY_FORMAT_CUSTOM0_SHIFT = 13

Enum: ArrayFormat

Amount to shift ArrayCustomFormat for custom channel index 0.

ARRAY_FORMAT_CUSTOM1_SHIFT = 16

Enum: ArrayFormat

Amount to shift ArrayCustomFormat for custom channel index 1.

ARRAY_FORMAT_CUSTOM2_SHIFT = 19

Enum: ArrayFormat

Amount to shift ArrayCustomFormat for custom channel index 2.

ARRAY_FORMAT_CUSTOM3_SHIFT = 22

Enum: ArrayFormat

Amount to shift ArrayCustomFormat for custom channel index 3.

ARRAY_FORMAT_CUSTOM_MASK = 7

Enum: ArrayFormat

Mask of custom format bits per custom channel. Must be shifted by one of the SHIFT constants. See ArrayCustomFormat.

ARRAY_FLAG_USE_2D_VERTICES = 33554432

Enum: ArrayFormat

Flag used to mark that the array contains 2D vertices.

ARRAY_FLAG_USE_DYNAMIC_UPDATE = 67108864

Enum: ArrayFormat

Flag used to mark that the mesh data will use GL_DYNAMIC_DRAW on GLES. Unused on Vulkan.

ARRAY_FLAG_USE_8_BONE_WEIGHTS = 134217728

Enum: ArrayFormat

Flag used to mark that the mesh contains up to 8 bone influences per vertex. This flag indicates that ARRAY_BONES and ARRAY_WEIGHTS elements will have double length.

ARRAY_FLAG_USES_EMPTY_VERTEX_ARRAY = 268435456

Enum: ArrayFormat

Flag used to mark that the mesh intentionally contains no vertex array.

ARRAY_FLAG_COMPRESS_ATTRIBUTES = 536870912

Enum: ArrayFormat

Flag used to mark that a mesh is using compressed attributes (vertices, normals, tangents, UVs). When this form of compression is enabled, vertex positions will be packed into an RGBA16UNORM attribute and scaled in the vertex shader. The normal and tangent will be packed into an RG16UNORM representing an axis, and a 16-bit float stored in the A-channel of the vertex. UVs will use 16-bit normalized floats instead of full 32-bit signed floats. When using this compression mode you must use either vertices, normals, and tangents or only vertices. You cannot use normals without tangents. Importers will automatically enable this compression if they can.

BLEND_SHAPE_MODE_NORMALIZED = 0

Enum: BlendShapeMode

Blend shapes are normalized.

BLEND_SHAPE_MODE_RELATIVE = 1

Enum: BlendShapeMode

Blend shapes are relative to base weight.

Tutorials

Source revision 704b10a8e178
Connection interrupted. Reload×

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.