Class Mesh
3D mesh object representing renderable geometry with material and transform. More...
#include <Mesh.h>
Inherits the following classes: ObjectID, Transform3D
Public Types inherited from ObjectID
See ObjectID
| Type | Name |
|---|---|
| enum | GOType Enumeration of scene object types. |
Public Types inherited from Transform
See Transform
| Type | Name |
|---|---|
| enum | TransType Flags for enabling/disabling transform components. |
Public Attributes
| Type | Name |
|---|---|
| bool | is_closure = { true }Mesh is closed/watertight (affects SDF and culling) |
| std::shared_ptr< Material > | o_material Material defining surface properties (albedo, metallic, roughness, etc.) |
| std::shared_ptr< MeshData > | o_mesh High-resolution geometry (vertex/index buffers) |
| std::shared_ptr< MeshData > | o_mesh_low = { nullptr }Optional low-poly proxy for LOD rendering. |
| std::shared_ptr< RenderShader > | o_shader Shader program for rendering this mesh. |
| bool | using_material = { true }Enable material shading (if false, use flat shading) |
| bool | using_sdf = { true }Include this mesh in SDF field generation. |
| bool | using_shadow = { true }Enable shadow casting for this mesh. |
Public Attributes inherited from ObjectID
See ObjectID
| Type | Name |
|---|---|
| bool | is_rendered = trueIncluded in rendering pipeline. |
| bool | is_viewport = trueVisible in viewport (editor-only) |
| std::string | o_name Display name in editor UI . |
| GOType | o_type = NONE\_GORuntime type identifier. |
Public Attributes inherited from Transform3D
See Transform3D
| Type | Name |
|---|---|
| glm::mat4 | o_InvTransform = { 1.0f }Cached inverse world transform matrix. |
| glm::mat4 | o_Transform = { 1.0f }Cached world transform matrix. |
| glm::vec3 | o_dir_right = { 1.0f, 0.0f, 0.0f }Right direction vector (X+) |
| glm::vec3 | o_dir_up = { 0.0f, 1.0f, 0.0f }Up direction vector (Y+) |
| glm::vec3 | o_position = { 0.0f }World position. |
| glm::vec3 | o_rot = { 0.0f }Euler rotation angles (radians): pitch, yaw, roll. |
| glm::vec3 | o_scale = { 1.0f }Local scale (non-uniform allowed) |
Public Attributes inherited from Transform
See Transform
| Type | Name |
|---|---|
| bool | is_TransF_changed = trueTransform matrix needs recomputation. |
| bool | is_Uniform_changed = trueUniform (non-scaled) transform needs recomputation. |
| bool | is_invTransF_changed = trueInverse transform needs recomputation. |
| bool | is_invUniform_changed = trueInverse uniform transform needs recomputation. |
| bool | use_position = { true }Enable position component in transform computation. |
| bool | use_rotation = { true }Enable rotation component in transform computation. |
| bool | use_scale = { true }Enable scale component in transform computation. |
Public Functions
| Type | Name |
|---|---|
| void | EnableMaterial (bool _enable) Enables or disables material shading. |
| void | EnableSDF (bool _enable) Enables or disables SDF contribution. |
| void | EnableShadow (bool _enable) Enables or disables shadow casting. |
| virtual void * | GetMaterial () override Returns pointer to material. |
| virtual void * | GetShader () override Returns pointer to shader. |
| virtual void * | GetTransform () override Returns pointer to transform. |
| Mesh () Constructs a default empty mesh. |
|
| Mesh (const std::string & path) Constructs a mesh from OBJ file. |
|
| void | RenderMesh (const Context & ctx) Renders the mesh to active framebuffer. |
| void | RenderObjProxy (bool using_original=true) const Renders low-poly proxy or original mesh. |
| void | SetCenter () Centers mesh pivot at geometry centroid. |
| void | SetLowPoly (const std::string & path="") Assigns low-poly proxy mesh for LOD. |
| void | SetMatColor (Material::MatParaType _type, float _val) Sets scalar material property. |
| void | SetMatColor (Material::MatParaType _type, glm::vec3 _col) Sets vector material property. |
| void | SetObjShader (std::string vert, std::string frag="") Sets custom shader for this mesh. |
| void | SetShaderValue (std::string _name, T ... _v) Sets shader uniform value. |
| void | SetTex (Material::MatParaType _type, std::string _name) Assigns texture to material parameter. |
Public Functions inherited from ObjectID
See ObjectID
| Type | Name |
|---|---|
| virtual void * | GetMaterial () Returns pointer to object's material, if applicable. |
| virtual void * | GetShader () Returns pointer to object's shader, if applicable. |
| virtual void * | GetTransform () Returns pointer to object's transform, if applicable. |
| ObjectID () Constructs an ObjectID with default values. |
|
| void | SetVisible (bool v, bool r) Sets visibility flags for viewport and rendering. |
| ~ObjectID () Destroys the ObjectID . |
Public Functions inherited from UID
See UID
| Type | Name |
|---|---|
| int | GetObjectID () const Returns the unique ID of this object. |
| UID () Constructs a UID and assigns a unique ID. |
|
| virtual | ~UID () = default Virtual destructor for polymorphic use. |
Public Functions inherited from Transform3D
See Transform3D
| Type | Name |
|---|---|
| virtual bool | ApplyAllTransform () override Recomputes transform and all parent transforms. |
| virtual bool | ApplyTransform (bool _forced=false) override Recomputes transform matrix if dirty. |
| Transform3D * | GetChildTransPtr () Returns pointer to first child transform. |
| virtual bool | GetInvTransform () override const Computes inverse transform matrix. |
| Transform3D * | GetParentTransPtr () Returns pointer to parent transform. |
| Transform3D * | GetTransformPtr () Returns pointer to this transform. |
| void | LookAt (const glm::vec3 & tar, const glm::vec3 & up={0, 0, 1}) Orients transform to look at target position. |
| void | Move (const glm::vec3 & d_pos) Translates position by offset. |
| void | SetParent (Transform3D * _p_trans, bool _keep_offset=true) Sets parent transform for hierarchy. |
| bool | SetPos (const glm::vec3 & pos) Sets world position. |
| bool | SetPos1D (float _1d, GLuint _dim) Sets single axis of position. |
| bool | SetRot (const glm::vec3 & rot) Sets rotation via Euler angles. |
| bool | SetRot1D (float _1d, GLuint _dim) Sets single axis of rotation. |
| bool | SetScale (const glm::vec3 & scale) Sets local scale. |
| bool | SetScale1D (float _1d, GLuint _dim) Sets single axis of scale. |
| bool | SetTrans (const glm::mat4 & _trans, bool pos=true, bool rot=true, bool scl=true) Sets transform from 4x4 matrix. |
| void | Spin (const glm::vec3 & anch, const glm::vec3 & axis, const float & angle) Rotates around arbitrary axis through anchor point. |
| void | Spin (const glm::vec3 & anch, const glm::vec2 & angle, bool global_up=true) Rotates around anchor with pitch/yaw. |
| void | Trans (const glm::mat4 & _trans) Applies transformation matrix to current transform. |
| Transform3D () Constructs a Transform3D with identity values. |
|
| virtual void | UnsetParent (bool _keep_offset=true) override Removes parent transform relationship. |
| virtual int | _debug () override const Debug utility for transform state inspection. |
| ~Transform3D () Destroys the Transform3D . |
Public Functions inherited from Transform
See Transform
| Type | Name |
|---|---|
| virtual bool | ApplyAllTransform () = 0 Recomputes transform and all parent transforms. |
| virtual bool | ApplyTransform (bool _forced=false) = 0 Recomputes transform matrix if dirty. |
| virtual bool | GetInvTransform () const = 0 Computes inverse transform matrix. |
| virtual void | UnsetParent (bool _keep_offset=true) = 0 Removes parent transform relationship. |
| void | UseTranformComp (bool _enable, TransType _type) Enables or disables specific transform components. |
| virtual int | _debug () const = 0 Debug utility for transform state inspection. |
Public Static Functions inherited from UID
See UID
| Type | Name |
|---|---|
| int | GetTotalAllocated () Returns total number of UIDs allocated. |
Detailed Description
Mesh combines MeshData (vertex/index buffers), Material (textures and properties), RenderShader (GPU program), and Transform3D (position/rotation/scale) to form a complete renderable object. It supports shadow casting, material shading, and SDF (Signed Distance Field) generation for soft shadows.
Resource Ownership: * MeshData: Shared ownership (multiple meshes can reference same geometry) * Material: Shared ownership (multiple meshes can share materials) * RenderShader: Shared ownership (shaders are reused across meshes) * Transform: Owned directly (each mesh has unique transform)
Rendering Pipeline Integration: * Geometry pass: Uploads mesh data and material to G-Buffer * Shadow pass: Optionally rendered into shadow maps (if using_shadow == true) * SDF pass: Optionally contributes to SDF field (if using_sdf == true) * Proxy rendering: Low-poly mesh can be used for distant objects (LOD)
Note:
Inheritance: ObjectID for scene identity, Transform3D for spatial transform.
Note:
Thread-safety: Not thread-safe. Access from main thread only.
Note:
LOD: Use SetLowPoly() to provide simplified geometry for distance culling.
Public Attributes Documentation
variable is_closure
Mesh is closed/watertight (affects SDF and culling)
bool Mesh::is_closure;
variable o_material
Material defining surface properties (albedo, metallic, roughness, etc.)
std::shared_ptr<Material> Mesh::o_material;
variable o_mesh
High-resolution geometry (vertex/index buffers)
std::shared_ptr<MeshData> Mesh::o_mesh;
variable o_mesh_low
Optional low-poly proxy for LOD rendering.
std::shared_ptr<MeshData> Mesh::o_mesh_low;
variable o_shader
Shader program for rendering this mesh.
std::shared_ptr<RenderShader> Mesh::o_shader;
variable using_material
Enable material shading (if false, use flat shading)
bool Mesh::using_material;
variable using_sdf
Include this mesh in SDF field generation.
bool Mesh::using_sdf;
variable using_shadow
Enable shadow casting for this mesh.
bool Mesh::using_shadow;
Public Functions Documentation
function EnableMaterial
Enables or disables material shading.
inline void Mesh::EnableMaterial (
bool _enable
)
Parameters:
_enableTrue for full PBR, false for flat/debug shading
function EnableSDF
Enables or disables SDF contribution.
inline void Mesh::EnableSDF (
bool _enable
)
Parameters:
_enableTrue to include in SDF field, false to exclude
Note:
SDF is used for soft shadow approximation.
function EnableShadow
Enables or disables shadow casting.
inline void Mesh::EnableShadow (
bool _enable
)
Parameters:
_enableTrue to cast shadows, false to skip shadow pass
function GetMaterial
Returns pointer to material.
inline virtual void * Mesh::GetMaterial () override
Returns:
Pointer to Material as void* (cast required)
Note:
Overrides ObjectID::GetMaterial() for polymorphic access.
Implements ObjectID::GetMaterial
function GetShader
Returns pointer to shader.
inline virtual void * Mesh::GetShader () override
Returns:
Pointer to RenderShader as void* (cast required)
Note:
Overrides ObjectID::GetShader() for polymorphic access.
Implements ObjectID::GetShader
function GetTransform
Returns pointer to transform.
inline virtual void * Mesh::GetTransform () override
Returns:
Pointer to Transform3D as void* (cast required)
Note:
Overrides ObjectID::GetTransform() for polymorphic access.
Implements ObjectID::GetTransform
function Mesh [1/2]
Constructs a default empty mesh.
Mesh::Mesh ()
Note:
Mesh has no geometry until o_mesh is assigned.
function Mesh [2/2]
Constructs a mesh from OBJ file.
Mesh::Mesh (
const std::string & path
)
Parameters:
pathPath to OBJ file on disk
Note:
Automatically loads MeshData from file via MeshData constructor.
function RenderMesh
Renders the mesh to active framebuffer.
void Mesh::RenderMesh (
const Context & ctx
)
Parameters:
ctxContext providing camera, lighting, and render state
Note:
Binds shader, material, and transform, then issues draw call.
Note:
Called by Renderer during geometry pass.
function RenderObjProxy
Renders low-poly proxy or original mesh.
void Mesh::RenderObjProxy (
bool using_original=true
) const
Parameters:
using_originalIf true, render high-res mesh; if false, render low-poly proxy
Note:
Used for LOD rendering or preview modes.
function SetCenter
Centers mesh pivot at geometry centroid.
void Mesh::SetCenter ()
Note:
Recomputes bounding box and shifts vertices to center.
function SetLowPoly
Assigns low-poly proxy mesh for LOD.
void Mesh::SetLowPoly (
const std::string & path=""
)
Parameters:
pathPath to low-poly OBJ file (default: empty, generates automatic simplification)
Note:
If path is empty, may auto-generate simplified mesh (implementation-dependent).
function SetMatColor [1/2]
Sets scalar material property.
void Mesh::SetMatColor (
Material::MatParaType _type,
float _val
)
Parameters:
_typeMaterial parameter type (METALLIC, ROUGHNESS, etc.)_valScalar value (typically 0.0 to 1.0)
Note:
Updates material's float properties.
function SetMatColor [2/2]
Sets vector material property.
void Mesh::SetMatColor (
Material::MatParaType _type,
glm::vec3 _col
)
Parameters:
_typeMaterial parameter type (ALBEDO, EMISSION, etc.)_colRGB color vector
Note:
Updates material's vec3 properties.
function SetObjShader
Sets custom shader for this mesh.
void Mesh::SetObjShader (
std::string vert,
std::string frag=""
)
Parameters:
vertVertex shader filename (without extension)fragFragment shader filename (without extension, default: same as vert)
Note:
Replaces o_shader with newly compiled shader from shader library.
function SetShaderValue
Sets shader uniform value.
template<typename... T>
void Mesh::SetShaderValue (
std::string _name,
T ... _v
)
Template parameters:
TVariadic parameter pack for uniform types
Parameters:
_nameUniform name in shader_vUniform value(s)
Note:
Automatically binds/unbinds shader for uniform upload.
function SetTex
Assigns texture to material parameter.
void Mesh::SetTex (
Material::MatParaType _type,
std::string _name
)
Parameters:
_typeMaterial parameter type (ALBEDO, METALLIC, ROUGHNESS, NORMAL, etc.)_nameTexture filename or path
Note:
Loads texture and updates material's texture slot.
The documentation for this class was generated from the following file src/scene/Mesh.h