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

Complete 3D geometry definition with vertices, indices, and material partitioning. More...

#include <Mesh.hpp>

Inheritance diagram for Infinity::Types::Rendering::Mesh:
[legend]
Collaboration diagram for Infinity::Types::Rendering::Mesh:
[legend]

Public Member Functions

 Mesh ()
 Default constructor.
 
 Mesh (const VertexBuffer &vertexBuffer, const IndexBuffer &indexBuffer, const Containers::Array< SubMesh > &subMeshes)
 Constructs a mesh from pre-built buffers and submeshes.
 
 Mesh (const Containers::Array< Math::Vector3 > &vertices, const Containers::Array< uint16_t > &indices, const Containers::Array< Math::Vector2 > &uvs, const Containers::Array< Math::Vector3 > &normals)
 Constructs a simple mesh from vertex/index arrays (16-bit indices).
 
 Mesh (const Containers::Array< Math::Vector3 > &vertices, const Containers::Array< uint32_t > &indices, const Containers::Array< Math::Vector2 > &uvs, const Containers::Array< Math::Vector3 > &normals)
 Constructs a simple mesh from vertex/index arrays (32-bit indices).
 
 Mesh (size_t nVertices, size_t n16bitIndices, size_t nUVs, size_t nNormals)
 Constructs a mesh with pre-allocated buffers.
 
virtual ~Mesh ()
 Destructor.
 
std::unique_ptr< Core::Baseclone () const override
 
const Infinity::Types::TypeIDtypeId () const override
 Gets the TypeID for Mesh.
 
- Public Member Functions inherited from Infinity::Types::Core::Data
 Data ()
 
 Data (const Data &other)
 
 Data (Data &&other)
 
Dataoperator= (const Data &other)
 
Dataoperator= (Data &&other)
 
virtual ~Data ()
 Virtual destructor.
 
bool hasProperty (const std::string &key) const
 
template<typename T >
void setProperty (const std::string &key, T &&value)
 Sets a typed property value.
 
template<typename T >
void setProperty (const std::string &key, const T &value)
 Sets a typed property value.
 
void setProperty (const std::string &key, PropertyValue &&value)
 Sets a typed property value.
 
const PropertyValuegetProperty (const std::string &key) const
 Gets a property value without type checking.
 
template<typename T >
const T & getProperty (const std::string &key) const
 Gets a typed property value.
 
void removeProperty (const std::string &key)
 
- Public Member Functions inherited from Infinity::Types::Core::Base
virtual ~Base ()
 Virtual destructor.
 
virtual std::istream & legibleDataRead (std::istream &in) override
 Deserializes the object from a single-line text representation.
 
virtual std::ostream & legibleDataWrite (std::ostream &out) const override
 Serializes the object to a single-line text representation.
 

Public Attributes

VertexBuffer vertexBuffer
 Vertex attribute data for the mesh.
 
IndexBuffer indexBuffer
 Index data defining primitive connectivity.
 
Containers::Array< SubMeshsubMeshes
 Optional array of submeshes for multi-material rendering.
 
- Public Attributes inherited from Infinity::Types::Core::Data
std::unordered_map< std::string, PropertyValueproperties
 Property storage for arbitrary metadata.
 

Detailed Description

Complete 3D geometry definition with vertices, indices, and material partitioning.

Mesh combines a VertexBuffer, IndexBuffer, and optional SubMesh array to represent complete 3D geometry ready for rendering. It serves as the fundamental geometric primitive in the Infinity Engine, supporting both simple single-material meshes and complex multi-material objects.

The mesh structure consists of:

  • VertexBuffer: Vertex attribute data (positions, normals, UVs, colors, tangents)
  • IndexBuffer: Connectivity data defining how vertices form primitives
  • SubMeshes: Optional partitioning for multi-material rendering

Mesh provides several convenience constructors for common scenarios:

  • From pre-built VertexBuffer, IndexBuffer, and SubMesh arrays
  • From simple arrays of positions, indices, UVs, and normals
  • With pre-allocated sizes for procedural generation

If no submeshes are specified, the entire mesh is treated as a single submesh using material index 0.

Common use cases:

  • Procedural mesh generation (terrain, buildings, foliage)
  • Geometry import and conversion
  • Mesh manipulation and editing
  • LOD (Level of Detail) mesh construction
  • Runtime geometry creation
  • Mesh optimization and simplification
Note
Mesh owns its geometry data (vertices and indices).
SubMesh indices must be valid within the parent Renderable's materials array.
Empty submeshes array indicates single-material mesh using materialIndex 0.
All vertex attribute arrays in VertexBuffer should have matching lengths.

Example usage:

// Simple single-material quad
Mesh quad;
quad.vertexBuffer.positions.push_back(Vector3{-1, -1, 0});
quad.vertexBuffer.positions.push_back(Vector3{ 1, -1, 0});
quad.vertexBuffer.positions.push_back(Vector3{ 1, 1, 0});
quad.vertexBuffer.positions.push_back(Vector3{-1, 1, 0});
quad.vertexBuffer.uvs.push_back(Vector2{0, 0});
quad.vertexBuffer.uvs.push_back(Vector2{1, 0});
quad.vertexBuffer.uvs.push_back(Vector2{1, 1});
quad.vertexBuffer.uvs.push_back(Vector2{0, 1});
quad.indexBuffer.pushTriangle(0, 1, 2);
quad.indexBuffer.pushTriangle(0, 2, 3);
// Convenience constructor for simple meshes
Array<Vector3> positions = generatePositions();
Array<uint32_t> indices = generateIndices();
Array<Vector2> uvs = generateUVs();
Array<Vector3> normals = calculateNormals(positions, indices);
Mesh simple(positions, indices, uvs, normals);
// Procedural terrain mesh
size_t width = 256, height = 256;
Mesh terrain;
// Generate vertices
for (size_t z = 0; z < height; ++z) {
for (size_t x = 0; x < width; ++x) {
float heightValue = getHeight(x, z);
terrain.vertexBuffer.positions.push_back(Vector3{
static_cast<float>(x),
heightValue,
static_cast<float>(z)
});
Vector3 normal = calculateNormal(x, z);
terrain.vertexBuffer.normals.push_back(normal);
terrain.vertexBuffer.uvs.push_back(Vector2{
x / float(width - 1),
z / float(height - 1)
});
}
}
// Generate indices
for (size_t z = 0; z < height - 1; ++z) {
for (size_t x = 0; x < width - 1; ++x) {
uint32_t tl = z * width + x;
uint32_t tr = tl + 1;
uint32_t bl = (z + 1) * width + x;
uint32_t br = bl + 1;
terrain.indexBuffer.pushTriangle(tl, bl, tr);
terrain.indexBuffer.pushTriangle(tr, bl, br);
}
}
// Multi-material building mesh
Mesh building;
// ... generate combined geometry ...
SubMesh walls;
walls.indexOffset = 0;
walls.indexCount = wallTriangleCount * 3;
walls.materialIndex = 0; // Brick material
building.subMeshes.push_back(walls);
SubMesh windows;
windows.indexOffset = walls.indexCount;
windows.indexCount = windowTriangleCount * 3;
windows.materialIndex = 1; // Glass material
building.subMeshes.push_back(windows);
// Pre-allocated mesh for known size
size_t vertexCount = 10000;
size_t indexCount = 30000;
Mesh optimized(vertexCount, indexCount, vertexCount, vertexCount);
// Fill geometry arrays directly...
// Use with ProceduralSystem
system->setIn("generated_mesh", std::move(terrain));
void pushTriangle(uint16_t v0, uint16_t v1, uint16_t v2)
Appends three 16-bit indices forming a triangle.
Complete 3D geometry definition with vertices, indices, and material partitioning.
Definition Mesh.hpp:135
VertexBuffer vertexBuffer
Vertex attribute data for the mesh.
Definition Mesh.hpp:143
IndexBuffer indexBuffer
Index data defining primitive connectivity.
Definition Mesh.hpp:151
Mesh()
Default constructor.
Containers::Array< Infinity::Types::Math::Vector3 > positions
Vertex positions in object/local space.
Definition VertexBuffer.hpp:117
Containers::Array< Infinity::Types::Math::Vector2 > uvs
Texture coordinates (UVs).
Definition VertexBuffer.hpp:140
t_Vector3< float > Vector3
Alias for t_Vector3<float>, the default 3D vector type.
Definition Vector3.hpp:580

Constructor & Destructor Documentation

◆ Mesh() [1/5]

Infinity::Types::Rendering::Mesh::Mesh ( )

Default constructor.

Creates an empty mesh with no geometry.

◆ Mesh() [2/5]

Infinity::Types::Rendering::Mesh::Mesh ( const VertexBuffer vertexBuffer,
const IndexBuffer indexBuffer,
const Containers::Array< SubMesh > &  subMeshes 
)

Constructs a mesh from pre-built buffers and submeshes.

Parameters
vertexBufferVertex attribute data.
indexBufferIndex connectivity data.
subMeshesMaterial partitioning (can be empty for single-material).

◆ Mesh() [3/5]

Infinity::Types::Rendering::Mesh::Mesh ( const Containers::Array< Math::Vector3 > &  vertices,
const Containers::Array< uint16_t > &  indices,
const Containers::Array< Math::Vector2 > &  uvs,
const Containers::Array< Math::Vector3 > &  normals 
)

Constructs a simple mesh from vertex/index arrays (16-bit indices).

Convenience constructor for basic meshes. Creates a single-material mesh with positions, UVs, and normals.

Parameters
verticesVertex positions.
indices16-bit index array.
uvsTexture coordinates.
normalsNormal vectors.
Note
Arrays should have appropriate lengths (vertices/uvs/normals same, indices multiple of 3).

◆ Mesh() [4/5]

Infinity::Types::Rendering::Mesh::Mesh ( const Containers::Array< Math::Vector3 > &  vertices,
const Containers::Array< uint32_t > &  indices,
const Containers::Array< Math::Vector2 > &  uvs,
const Containers::Array< Math::Vector3 > &  normals 
)

Constructs a simple mesh from vertex/index arrays (32-bit indices).

Convenience constructor for basic meshes with more than 65,535 vertices.

Parameters
verticesVertex positions.
indices32-bit index array.
uvsTexture coordinates.
normalsNormal vectors.

◆ Mesh() [5/5]

Infinity::Types::Rendering::Mesh::Mesh ( size_t  nVertices,
size_t  n16bitIndices,
size_t  nUVs,
size_t  nNormals 
)

Constructs a mesh with pre-allocated buffers.

Pre-allocates memory for procedural generation without initializing data. Useful for avoiding reallocations during mesh construction.

Parameters
nVerticesNumber of vertices to allocate.
n16bitIndicesNumber of 16-bit indices to allocate.
nUVsNumber of UV coordinates to allocate.
nNormalsNumber of normals to allocate.

◆ ~Mesh()

virtual Infinity::Types::Rendering::Mesh::~Mesh ( )
virtual

Destructor.

Member Function Documentation

◆ clone()

std::unique_ptr< Core::Base > Infinity::Types::Rendering::Mesh::clone ( ) const
overridevirtual

Reimplemented from Infinity::Types::Core::Data.

◆ typeId()

const Infinity::Types::TypeID & Infinity::Types::Rendering::Mesh::typeId ( ) const
overridevirtual

Gets the TypeID for Mesh.

Returns
TypeID identifying this Mesh type.

Reimplemented from Infinity::Types::Core::Data.

Member Data Documentation

◆ indexBuffer

IndexBuffer Infinity::Types::Rendering::Mesh::indexBuffer

Index data defining primitive connectivity.

Defines how vertices are connected to form triangles, lines, or other primitives. Enables vertex sharing for memory efficiency.

◆ subMeshes

Containers::Array<SubMesh> Infinity::Types::Rendering::Mesh::subMeshes

Optional array of submeshes for multi-material rendering.

Partitions the mesh into material-specific sections. If empty, the entire mesh uses material index 0 from the parent Renderable.

◆ vertexBuffer

VertexBuffer Infinity::Types::Rendering::Mesh::vertexBuffer

Vertex attribute data for the mesh.

Contains positions, normals, UVs, colors, and tangents for all vertices. Not all attributes are required - populate only those needed for rendering.