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

Container for mesh vertex attribute data. More...

#include <VertexBuffer.hpp>

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

Public Member Functions

 VertexBuffer ()
 Default constructor.
 
virtual ~VertexBuffer ()
 Destructor.
 
std::unique_ptr< Core::Baseclone () const override
 
const Infinity::Types::TypeIDtypeId () const override
 Gets the TypeID for VertexBuffer.
 
- 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

Containers::Array< Infinity::Types::Math::Vector3positions
 Vertex positions in object/local space.
 
Containers::Array< Infinity::Types::Math::Vector3normals
 Vertex normal vectors.
 
Containers::Array< Infinity::Types::Math::Vector2uvs
 Texture coordinates (UVs).
 
Containers::Array< Infinity::Types::Math::Vector4colors
 Per-vertex colors.
 
Containers::Array< Infinity::Types::Math::Vector4tangents
 Tangent vectors with handedness.
 
- Public Attributes inherited from Infinity::Types::Core::Data
std::unordered_map< std::string, PropertyValueproperties
 Property storage for arbitrary metadata.
 

Detailed Description

Container for mesh vertex attribute data.

VertexBuffer stores per-vertex attributes that define mesh geometry and appearance. It provides a structured representation of vertex data with separate arrays for each standard attribute type, enabling efficient mesh construction, manipulation, and rendering in the Infinity Engine.

The vertex buffer supports the following standard vertex attributes:

  • Positions: 3D vertex coordinates in object/local space (Vector3)
  • Normals: Surface normal vectors for lighting calculations (Vector3)
  • UVs: 2D texture coordinates for material mapping (Vector2)
  • Colors: Per-vertex color data (Vector4 RGBA)
  • Tangents: Tangent vectors for normal mapping (Vector4 with handedness in w)

Not all attributes are required - only the arrays that are populated will be used during rendering. This allows flexible mesh definitions from simple position-only geometry to fully-featured meshes with all attributes.

Common use cases:

  • Procedural mesh generation output
  • Mesh editing and manipulation
  • Vertex animation and deformation
  • Terrain mesh construction
  • Geometry streaming and LOD systems
  • Mesh simplification and optimization
Note
All attribute arrays should typically have the same length (vertex count).
Positions are usually required; other attributes are optional.
Tangents use Vector4 where w component stores handedness (+1 or -1) for bitangent calculation.
Empty arrays indicate attributes not used by the mesh.

Example usage:

// Create a simple quad mesh
// Define positions (CCW winding for front face)
verts.positions.push_back(Vector3{-1.0f, -1.0f, 0.0f}); // Bottom-left
verts.positions.push_back(Vector3{ 1.0f, -1.0f, 0.0f}); // Bottom-right
verts.positions.push_back(Vector3{ 1.0f, 1.0f, 0.0f}); // Top-right
verts.positions.push_back(Vector3{-1.0f, 1.0f, 0.0f}); // Top-left
// Define normals (facing +Z)
for (int i = 0; i < 4; ++i) {
verts.normals.push_back(Vector3{0.0f, 0.0f, 1.0f});
}
// Define UVs
verts.uvs.push_back(Vector2{0.0f, 0.0f}); // Bottom-left
verts.uvs.push_back(Vector2{1.0f, 0.0f}); // Bottom-right
verts.uvs.push_back(Vector2{1.0f, 1.0f}); // Top-right
verts.uvs.push_back(Vector2{0.0f, 1.0f}); // Top-left
// Procedural terrain mesh generation
VertexBuffer terrain;
Heightmap heightmap(256, 256);
// ... generate heightmap ...
for (size_t y = 0; y < 256; ++y) {
for (size_t x = 0; x < 256; ++x) {
float height = heightmap.at(x, y);
terrain.positions.push_back(Vector3{
static_cast<float>(x),
height,
static_cast<float>(y)
});
// Calculate normal from neighboring heights
Vector3 normal = calculateTerrainNormal(heightmap, x, y);
terrain.normals.push_back(normal);
// UV coordinates
terrain.uvs.push_back(Vector2{
x / 255.0f,
y / 255.0f
});
}
}
// Vertex color example (for debug visualization or paintable surfaces)
VertexBuffer coloredMesh;
for (const auto& pos : positions) {
coloredMesh.positions.push_back(pos);
// Color based on height
float height01 = (pos.y + 10.0f) / 20.0f;
coloredMesh.colors.push_back(Vector4{height01, 1.0f - height01, 0.0f, 1.0f});
}
// Use with ProceduralSystem
system->setIn("mesh_vertices", std::move(verts));
Container for mesh vertex attribute data.
Definition VertexBuffer.hpp:106
Containers::Array< Infinity::Types::Math::Vector3 > positions
Vertex positions in object/local space.
Definition VertexBuffer.hpp:117
Containers::Array< Infinity::Types::Math::Vector3 > normals
Vertex normal vectors.
Definition VertexBuffer.hpp:129
Containers::Array< Infinity::Types::Math::Vector2 > uvs
Texture coordinates (UVs).
Definition VertexBuffer.hpp:140
Array2D< float > Heightmap
Single-channel float heightmap for terrain generation.
Definition Array2D.hpp:336
t_Vector3< float > Vector3
Alias for t_Vector3<float>, the default 3D vector type.
Definition Vector3.hpp:580

Constructor & Destructor Documentation

◆ VertexBuffer()

Infinity::Types::Rendering::VertexBuffer::VertexBuffer ( )

Default constructor.

Creates an empty vertex buffer with no vertex data.

◆ ~VertexBuffer()

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

Destructor.

Member Function Documentation

◆ clone()

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

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

◆ typeId()

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

Gets the TypeID for VertexBuffer.

Returns
TypeID identifying this VertexBuffer type.

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

Member Data Documentation

◆ colors

Containers::Array<Infinity::Types::Math::Vector4> Infinity::Types::Rendering::VertexBuffer::colors

Per-vertex colors.

RGBA color values that can be used for vertex coloring, blending, or passed to shaders for custom effects. Values typically range [0, 1].

Note
Alpha (w component) can be used for transparency or custom data.
Optional - used when per-vertex color variation is needed.

◆ normals

Containers::Array<Infinity::Types::Math::Vector3> Infinity::Types::Rendering::VertexBuffer::normals

Vertex normal vectors.

3D unit vectors perpendicular to the surface at each vertex, used for lighting calculations. Normals should be normalized (length = 1) for correct lighting behavior.

Note
Normals are typically required for proper lighting.
Can be auto-generated from geometry if not provided.

◆ positions

Containers::Array<Infinity::Types::Math::Vector3> Infinity::Types::Rendering::VertexBuffer::positions

Vertex positions in object/local space.

3D coordinates defining vertex locations. This is typically the only required attribute - all other attributes are optional depending on the mesh's rendering requirements.

Note
Positions are in local/object space; world transform is applied separately.

◆ tangents

Containers::Array<Infinity::Types::Math::Vector4> Infinity::Types::Rendering::VertexBuffer::tangents

Tangent vectors with handedness.

4D vectors where xyz is the tangent direction and w is the handedness (+1 or -1) used to calculate the bitangent for normal mapping. Tangent vectors are perpendicular to normals and aligned with UV space.

Note
Required for normal mapping and detail surfaces.
The bitangent is calculated as: cross(normal, tangent.xyz) * tangent.w
Can be auto-generated using MikkTSpace or similar algorithms.

◆ uvs

Containers::Array<Infinity::Types::Math::Vector2> Infinity::Types::Rendering::VertexBuffer::uvs

Texture coordinates (UVs).

2D coordinates defining how textures map onto the mesh surface. Standard UV range is [0, 1] but can extend beyond for tiling effects.

Note
U = horizontal (x), V = vertical (y) texture coordinate.
Required for textured materials.