Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
Object::Utils Namespace Reference

Functions

Component::Mesh GenerateBoxMesh (float width, float height, float depth)
 Generate a box mesh with specified dimensions.
Component::Mesh GenerateCapsuleMesh (float radius=0.5f, float height=1.0f, uint32_t segments=32u, uint32_t heightSegments=4u)
 Generate a capsule mesh with given radius and cylinder height.
Component::Mesh GenerateClothMesh (uint32_t width, uint32_t height, float spacing)
Component::Mesh GenerateCubeMesh (float size=1.0f)
 Generate a cube mesh with specified size.
Component::Mesh GenerateCylinderMesh (float radiusTop=0.5f, float radiusBottom=0.5f, float height=1.0f, uint32_t segments=32u, uint32_t heightSegments=1u)
 Generate a cylinder mesh with specified dimensions.
Component::Mesh GenerateJellyCubeMesh (uint32_t gridSize, float spacing)
static void NormalizeVector (glm::vec3 &normal, float epsilon)
void RecalculateNormals (Component::Mesh &mesh)
 Recalculate normals for a mesh based on face geometry.
bool ValidateMeshArraySizes (const Component::Mesh &mesh)
 Validate mesh data integrity.
Component::Mesh GeneratePlaneMesh (float width=1.0f, float depth=1.0f, uint32_t subdivisionsX=1u, uint32_t subdivisionsZ=1u)
 Generate a plane mesh with specified width and depth.
Component::Mesh GenerateRopeMesh (uint32_t segmentCount, float segmentLength)
Component::Mesh GenerateSphereMesh (float radius=0.5f, uint32_t segments=32u, uint32_t rings=16u)
 Generate a sphere mesh with specified radius and subdivisions.
Component::Mesh GenerateWheelMesh (float radius=0.3f, float width=0.2f, uint32_t segments=24u)
 Generate a wheel mesh (cylinder oriented along the X axis).

Function Documentation

◆ GenerateBoxMesh()

Component::Mesh Object::Utils::GenerateBoxMesh ( float width,
float height,
float depth )

Generate a box mesh with specified dimensions.

Parameters
widthWidth of the box
heightHeight of the box
depthDepth of the box
Returns
Component::Mesh The generated box mesh with vertices, normals, UVs, and indices

◆ GenerateCapsuleMesh()

Component::Mesh Object::Utils::GenerateCapsuleMesh ( float radius = 0.5f,
float height = 1.0f,
uint32_t segments = 32u,
uint32_t heightSegments = 4u )

Generate a capsule mesh with given radius and cylinder height.

Parameters
radiusRadius of the capsule
heightHeight of the cylindrical middle section
segmentsRadial segments
heightSegmentsNumber of subdivisions along the cylinder height
Returns
Component::Mesh The generated capsule mesh

◆ GenerateClothMesh()

Component::Mesh Object::Utils::GenerateClothMesh ( uint32_t width,
uint32_t height,
float spacing )

◆ GenerateCubeMesh()

Component::Mesh Object::Utils::GenerateCubeMesh ( float size = 1.0f)

Generate a cube mesh with specified size.

Parameters
sizeSide length of the cube (default: 1.0)
Returns
Component::Mesh The generated cube mesh with vertices, normals, UVs, and indices

◆ GenerateCylinderMesh()

Component::Mesh Object::Utils::GenerateCylinderMesh ( float radiusTop = 0.5f,
float radiusBottom = 0.5f,
float height = 1.0f,
uint32_t segments = 32u,
uint32_t heightSegments = 1u )

Generate a cylinder mesh with specified dimensions.

Parameters
radiusTopRadius at the top (default: 0.5)
radiusBottomRadius at the bottom (default: 0.5)
heightHeight of the cylinder (default: 1.0)
segmentsNumber of radial segments (default: 32)
heightSegmentsNumber of height segments (default: 1)
Returns
Component::Mesh The generated cylinder mesh

◆ GenerateJellyCubeMesh()

Component::Mesh Object::Utils::GenerateJellyCubeMesh ( uint32_t gridSize,
float spacing )

◆ GeneratePlaneMesh()

Component::Mesh Object::Utils::GeneratePlaneMesh ( float width = 1.0f,
float depth = 1.0f,
uint32_t subdivisionsX = 1u,
uint32_t subdivisionsZ = 1u )

Generate a plane mesh with specified width and depth.

Parameters
widthWidth of the plane (X axis, default: 1.0)
depthDepth of the plane (Z axis, default: 1.0)
subdivisionsXNumber of subdivisions along X (default: 1)
subdivisionsZNumber of subdivisions along Z (default: 1)
Returns
Component::Mesh The generated plane mesh

◆ GenerateRopeMesh()

Component::Mesh Object::Utils::GenerateRopeMesh ( uint32_t segmentCount,
float segmentLength )

◆ GenerateSphereMesh()

Component::Mesh Object::Utils::GenerateSphereMesh ( float radius = 0.5f,
uint32_t segments = 32u,
uint32_t rings = 16u )

Generate a sphere mesh with specified radius and subdivisions.

Uses UV sphere generation (latitude/longitude grid)

Parameters
radiusRadius of the sphere (default: 0.5)
segmentsNumber of horizontal segments (default: 32)
ringsNumber of vertical rings (default: 16)
Returns
Component::Mesh The generated sphere mesh

◆ GenerateWheelMesh()

Component::Mesh Object::Utils::GenerateWheelMesh ( float radius = 0.3f,
float width = 0.2f,
uint32_t segments = 24u )

Generate a wheel mesh (cylinder oriented along the X axis).

Creates a cylinder mesh rotated 90 degrees so the wheel's axis of rotation is along the X axis (left-right), suitable for vehicle wheels.

Parameters
radiusRadius of the wheel (default: 0.3)
widthWidth of the wheel (default: 0.2)
segmentsNumber of radial segments (default: 24)
Returns
Component::Mesh The generated wheel mesh

◆ NormalizeVector()

void Object::Utils::NormalizeVector ( glm::vec3 & normal,
float epsilon )
static

◆ RecalculateNormals()

void Object::Utils::RecalculateNormals ( Component::Mesh & mesh)

Recalculate normals for a mesh based on face geometry.

This function computes smooth normals by averaging the face normals of all triangles that share each vertex. This is essential for correct lighting on deformable meshes like soft bodies.

Algorithm:

  1. Initialize all normals to zero
  2. For each triangle face, compute face normal using cross product
  3. Add face normal to each vertex's accumulated normal
  4. Normalize all vertex normals
Parameters
meshThe mesh to recalculate normals for. Must have:
  • Non-empty vertices array
  • Non-empty indices array (multiple of 3 for triangles)
  • Normals array same size as vertices (will be overwritten)
Note
The mesh's dirty flag is NOT modified by this function. The caller is responsible for managing the dirty state.
For "flat" meshes where each face has unique vertices (like OBJ imports), this will still work correctly as each vertex only belongs to one face.

◆ ValidateMeshArraySizes()

bool Object::Utils::ValidateMeshArraySizes ( const Component::Mesh & mesh)
nodiscard

Validate mesh data integrity.

Checks that vertices, normals, and texCoords arrays have matching sizes. This is a debug utility to catch malformed meshes early.

Parameters
meshThe mesh to validate.
Returns
true if mesh arrays have consistent sizes.
false if there's a size mismatch.