Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
Infinity::Types::Rendering::SubMesh Struct Reference

Defines a subset of mesh geometry with an associated material. More...

#include <SubMesh.hpp>

Public Attributes

uint32_t indexOffset
 Starting index in the mesh's IndexBuffer.
 
uint32_t indexCount
 Number of indices used by this submesh.
 
uint32_t materialIndex
 Index into the parent Renderable's materials array.
 

Detailed Description

Defines a subset of mesh geometry with an associated material.

SubMesh represents a contiguous range of indices within a mesh's IndexBuffer, allowing a single mesh to use multiple materials by partitioning its geometry into material-specific sections. This enables efficient multi-material rendering without duplicating vertex data.

Each submesh specifies:

  • An index range (offset and count) into the mesh's IndexBuffer
  • A material index referencing the parent Renderable's material array

The submesh system allows:

  • Multi-material objects (e.g., character with different materials for skin, clothing, armor)
  • Efficient material switching during rendering
  • Culling and LOD at submesh granularity
  • Material variation without geometry duplication
  • Procedural assignment of materials to geometry sections

Common use cases:

  • Character meshes with separate materials for body parts
  • Buildings with different materials for walls, roof, windows
  • Terrain chunks with multiple texture layers
  • Vehicles with distinct materials for body, windows, wheels
  • Procedurally generated objects with material variation
Note
The index range [indexOffset, indexOffset + indexCount) must be valid in the IndexBuffer.
materialIndex must be a valid index into the parent Renderable's materials array.
All submeshes share the same VertexBuffer from the parent mesh.
Submeshes should not overlap in index ranges for correct rendering.

Example usage:

// Create a mesh with multiple materials
VertexBuffer vertices;
IndexBuffer indices;
// ... build combined geometry ...
// Define submeshes for different parts
Array<SubMesh> submeshes;
SubMesh bodySubmesh;
bodySubmesh.indexOffset = 0;
bodySubmesh.indexCount = 1800; // 600 triangles
bodySubmesh.materialIndex = 0; // Body material
submeshes.push_back(bodySubmesh);
SubMesh windowSubmesh;
windowSubmesh.indexOffset = 1800;
windowSubmesh.indexCount = 300; // 100 triangles
windowSubmesh.materialIndex = 1; // Glass material
submeshes.push_back(windowSubmesh);
SubMesh wheelSubmesh;
wheelSubmesh.indexOffset = 2100;
wheelSubmesh.indexCount = 600; // 200 triangles
wheelSubmesh.materialIndex = 2; // Rubber material
submeshes.push_back(wheelSubmesh);
// Procedural terrain with material zones
Array<SubMesh> terrainSubmeshes;
size_t currentOffset = 0;
for (const auto& zone : materialZones) {
SubMesh submesh;
submesh.indexOffset = currentOffset;
submesh.indexCount = zone.triangleCount * 3;
submesh.materialIndex = zone.materialType;
terrainSubmeshes.push_back(submesh);
currentOffset += zone.triangleCount * 3;
}
// Building with procedural material assignment
SubMesh walls;
walls.indexOffset = 0;
walls.indexCount = wallTriangleCount * 3;
walls.materialIndex = MATERIAL_BRICK;
SubMesh roof;
roof.indexOffset = walls.indexCount;
roof.indexCount = roofTriangleCount * 3;
roof.materialIndex = MATERIAL_SHINGLES;
SubMesh windows;
windows.indexOffset = roof.indexOffset + roof.indexCount;
windows.indexCount = windowTriangleCount * 3;
windows.materialIndex = MATERIAL_GLASS;
Container for mesh index data defining vertex connectivity and topology.
Definition IndexBuffer.hpp:89
Container for mesh vertex attribute data.
Definition VertexBuffer.hpp:106
Defines a subset of mesh geometry with an associated material.
Definition SubMesh.hpp:100
uint32_t indexOffset
Starting index in the mesh's IndexBuffer.
Definition SubMesh.hpp:107
uint32_t indexCount
Number of indices used by this submesh.
Definition SubMesh.hpp:118
uint32_t materialIndex
Index into the parent Renderable's materials array.
Definition SubMesh.hpp:128

Member Data Documentation

◆ indexCount

uint32_t Infinity::Types::Rendering::SubMesh::indexCount

Number of indices used by this submesh.

Count of indices to read from the IndexBuffer starting at indexOffset. For triangle topology, this should be a multiple of 3.

Note
For Triangles: indexCount / 3 = triangle count
For Lines: indexCount / 2 = line segment count

◆ indexOffset

uint32_t Infinity::Types::Rendering::SubMesh::indexOffset

Starting index in the mesh's IndexBuffer.

Zero-based offset to the first index used by this submesh. The submesh uses indices from [indexOffset, indexOffset + indexCount).

◆ materialIndex

uint32_t Infinity::Types::Rendering::SubMesh::materialIndex

Index into the parent Renderable's materials array.

References which material from the parent Renderable should be applied to this submesh's geometry during rendering.

Note
Must be a valid index (< materials.size()) in the parent Renderable.