Mesh¶
Description¶
Mesh is the base class for all renderable 3D objects. It exposes the material system (color, texture, PBR material), shadow casting and receiving, transparency control, face culling, and GPU instancing for drawing thousands of objects in a single draw call.
Inherits: Object → EntityHandle
Properties¶
| Type | Name | Default | Languages |
|---|---|---|---|
| Vector4 | color | (1,1,1,1) |
C++ | Lua |
| float | alpha | 1.0 |
C++ | Lua |
| Material | material | default | C++ | Lua |
| PrimitiveType | primitiveType | TRIANGLES |
C++ | Lua |
| bool | faceCulling | true |
C++ | Lua |
| CullingMode | cullingMode | BACK |
C++ | Lua |
| WindingOrder | windingOrder | CCW |
C++ | Lua |
| bool | receiveLights | true |
C++ | Lua |
| bool | castShadows | false |
C++ | Lua |
| bool | receiveShadows | false |
C++ | Lua |
| bool | shadowsBillboard | false |
C++ | Lua |
| bool | castShadowsWithTexture | false |
C++ | Lua |
| bool | transparent | false |
C++ | Lua |
| bool | autoTransparency | true |
C++ | Lua |
Methods¶
| Returns | Name | Languages |
|---|---|---|
| bool | load | C++ | Lua |
| void | setTexture | C++ | Lua |
| void | setColor | C++ | Lua |
| Vector4 | getColor | C++ | Lua |
| void | setAlpha | C++ | Lua |
| float | getAlpha | C++ | Lua |
| void | setMaterial | C++ | Lua |
| Material | getMaterial | C++ | Lua |
| void | setPrimitiveType | C++ | Lua |
| PrimitiveType | getPrimitiveType | C++ | Lua |
| void | setFaceCulling | C++ | Lua |
| bool | isFaceCulling | C++ | Lua |
| void | setCullingMode | C++ | Lua |
| CullingMode | getCullingMode | C++ | Lua |
| void | setWindingOrder | C++ | Lua |
| WindingOrder | getWindingOrder | C++ | Lua |
| AABB | getAABB | C++ | Lua |
| AABB | getVerticesAABB | C++ | Lua |
| AABB | getWorldAABB | C++ | Lua |
| unsigned int | getNumSubmeshes | C++ | Lua |
| void | setReceiveLights | C++ | Lua |
| bool | isReceiveLights | C++ | Lua |
| void | setCastShadows | C++ | Lua |
| bool | isCastShadows | C++ | Lua |
| void | setReceiveShadows | C++ | Lua |
| bool | isReceiveShadows | C++ | Lua |
| void | setShadowsBillboard | C++ | Lua |
| bool | isShadowsBillboard | C++ | Lua |
| void | setCastShadowsWithTexture | C++ | Lua |
| bool | isCastShadowsWithTexture | C++ | Lua |
| void | setTransparent | C++ | Lua |
| bool | isTransparent | C++ | Lua |
| void | setAutoTransparency | C++ | Lua |
| bool | isAutoTransparency | C++ | Lua |
| void | createInstancedMesh | C++ | Lua |
| void | removeInstancedMesh | C++ | Lua |
| bool | hasInstancedMesh | C++ | Lua |
| void | addInstance | C++ | Lua |
| InstanceData& | getInstance | C++ | Lua |
| void | updateInstance | C++ | Lua |
| void | removeInstance | C++ | Lua |
| bool | isInstanceVisible | C++ | Lua |
| void | setInstanceVisible | C++ | Lua |
| void | updateInstances | C++ | Lua |
| size_t | getNumInstances | C++ | Lua |
| void | clearInstances | C++ | Lua |
| void | setInstancedBillboard | C++ | Lua |
| bool | isInstancedBillboard | C++ | Lua |
| void | setInstancedCylindricalBillboard | C++ | Lua |
| bool | isInstancedCylindricalBillboard | C++ | Lua |
| void | setMaxInstances | C++ | Lua |
| unsigned int | getMaxInstances | C++ | Lua |
Enumerations¶
PrimitiveType¶
- TRIANGLES — Solid triangle meshes (default).
- TRIANGLE_STRIP — Triangle strip.
- POINTS — Renders each vertex as a point.
- LINES — Renders edges as lines.
CullingMode¶
- BACK — Culls back faces (default, outward-facing normals).
- FRONT — Culls front faces (useful for inside-out rendering).
WindingOrder¶
- CCW — Counter-clockwise winding defines the front face (OpenGL convention, default).
- CW — Clockwise winding defines the front face.
Property details¶
color¶
- Setter:
void setColor(Vector4 color) - Setter:
void setColor(float red, float green, float blue, float alpha) - Setter:
void setColor(float red, float green, float blue) - Getter:
Vector4 getColor() const
Tint color multiplied with the material texture. (1,1,1,1) means no tint.
alpha¶
- Setter:
void setAlpha(float alpha) - Getter:
float getAlpha() const
Shorthand for the alpha channel of color. Values below 1.0 require transparent to be enabled for correct rendering order.
material¶
- Setter:
void setMaterial(const Material& material)(all submeshes) - Setter:
void setMaterial(unsigned int submesh, const Material& material)(per submesh) - Getter:
Material getMaterial() const - Getter:
Material getMaterial(unsigned int submesh) const
PBR material descriptor. Contains base color, metallic/roughness factors, normal map, emissive settings, and shader overrides.
primitiveType¶
- Setter:
void setPrimitiveType(PrimitiveType primitiveType) - Getter:
PrimitiveType getPrimitiveType() const
GPU draw mode. Overloads are available per submesh.
faceCulling¶
- Setter:
void setFaceCulling(bool faceCulling) - Getter:
bool isFaceCulling() const
Enables or disables back-face culling globally for this mesh. Disable for double-sided geometry (e.g. leaves, cards).
castShadows / receiveShadows¶
- Setter:
void setCastShadows(bool castShadows)/void setReceiveShadows(bool receiveShadows) - Getter:
bool isCastShadows() const/bool isReceiveShadows() const
Shadow participation flags. Enabling both adds depth-map cost; disable on distant or small objects for performance.
transparent / autoTransparency¶
- transparent Setter:
void setTransparent(bool transparent) - autoTransparency Setter:
void setAutoTransparency(bool autoTransparency)
transparent marks the mesh for the transparent render pass (sorted back-to-front). autoTransparency detects transparency from the material and enables the transparent pass automatically.
Method details¶
load¶
bool load()
Uploads geometry and material resources to the GPU. Must be called after building or modifying geometry programmatically. Subclasses like Sprite call this internally when needed.
setTexture¶
void setTexture(const std::string& path)void setTexture(const std::string& id, TextureData data)void setTexture(Framebuffer* framebuffer)
Assigns the diffuse/base-color texture. Accepts a file path, raw TextureData, or a framebuffer render target.
getAABB / getVerticesAABB / getWorldAABB¶
AABB getAABB() const— Axis-aligned bounding box of the mesh in local space.AABB getVerticesAABB() const— AABB computed from raw vertex positions, ignoring the transform.AABB getWorldAABB() const— AABB in world space after applying the full transform chain.
Useful for frustum culling, click picking, and physics proxy fitting.
getNumSubmeshes¶
unsigned int getNumSubmeshes() const
Returns the number of submeshes. Each submesh can have its own material, primitive type, and culling settings.
createInstancedMesh¶
void createInstancedMesh()
Enables GPU instancing for this mesh. After calling this, use addInstance / updateInstance to populate the instance list, then updateInstances to flush changes to the GPU.
addInstance¶
void addInstance(InstanceData instance)void addInstance(Vector3 position)void addInstance(float x, float y, float z)void addInstance(Vector3 position, Quaternion rotation, Vector3 scale)void addInstance(Vector3 position, Quaternion rotation, Vector3 scale, Vector4 color)void addInstance(Vector3 position, Quaternion rotation, Vector3 scale, Vector4 color, Rect textureRect)
Appends a new instance with the specified transform. Requires createInstancedMesh to have been called first.
updateInstance¶
void updateInstance(size_t index, InstanceData instance)(and overloads)
Replaces the data for an existing instance at index. Call updateInstances afterwards to sync changes to the GPU.
updateInstances¶
void updateInstances()
Uploads all pending instance data changes to the GPU vertex buffer. Must be called after any addInstance or updateInstance calls.
clearInstances¶
void clearInstances()
Removes all instances from the instance list. The mesh geometry is preserved; call updateInstances afterwards.