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

Complete renderable object combining geometry, materials, and instancing. More...

#include <Renderable.hpp>

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

Public Member Functions

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

Mesh mesh
 Mesh geometry for this renderable.
 
Containers::Array< Materialmaterials
 Array of materials applied to the mesh.
 
Containers::Array< Spatial::Transforminstances
 Array of transform instances for instanced rendering.
 
- Public Attributes inherited from Infinity::Types::Core::Data
std::unordered_map< std::string, PropertyValueproperties
 Property storage for arbitrary metadata.
 

Detailed Description

Complete renderable object combining geometry, materials, and instancing.

Renderable represents a complete, self-contained object ready for rendering in the Infinity Engine. It combines a Mesh (geometry), an array of Materials (appearance), and an array of Transform instances (placement), providing everything needed to render one or more instances of an object in the scene.

The renderable structure enables:

  • Single geometry, multiple materials: SubMeshes reference materials array
  • Instanced rendering: Single mesh rendered at multiple transforms efficiently
  • Self-contained rendering: All rendering data in one object
  • Procedural object generation: Complete output from procedural systems
  • Scene composition: Building blocks for complex scenes

Key relationships:

  • Mesh.subMeshes[i].materialIndex references materials[materialIndex]
  • Each Transform in instances array creates one instance of the mesh
  • Empty instances array renders single instance at origin with identity transform

Common use cases:

  • Procedurally generated objects (trees, rocks, buildings)
  • Scatter/distribution systems (foliage, debris, props)
  • Terrain chunks with material blending
  • Character meshes with multi-material setup
  • LOD (Level of Detail) object variants
  • Instanced rendering of repeated geometry
Note
SubMesh.materialIndex must be valid (< materials.size()).
Empty materials array requires mesh to have no submeshes or use default material.
Empty instances array indicates single instance at identity transform.
Materials array length should match maximum materialIndex used in submeshes + 1.

Example usage:

// Simple single-material renderable
rock.mesh = generateRockMesh(seed);
Material rockMat;
rockMat.shaderName = "pbr_standard";
rockMat.setTexture2DRGBA("albedo", rockAlbedoTexture);
rockMat.setFloat("roughness", 0.9f);
rock.materials.push_back(std::move(rockMat));
// Single instance at specific location
transform.position = Vector3{10.0f, 0.0f, 5.0f};
transform.rotation = randomRotation();
transform.scale = Vector3{1.2f, 1.2f, 1.2f};
rock.instances.push_back(transform);
// Multi-material building
Renderable building;
building.mesh = generateBuildingMesh();
Material brickMat;
brickMat.shaderName = "pbr_standard";
brickMat.setTexture2DRGBA("albedo", brickTexture);
building.materials.push_back(std::move(brickMat));
Material glassMat;
glassMat.shaderName = "glass_transparent";
glassMat.setFloat("transparency", 0.9f);
building.materials.push_back(std::move(glassMat));
Material roofMat;
roofMat.shaderName = "pbr_standard";
roofMat.setTexture2DRGBA("albedo", shingleTexture);
building.materials.push_back(std::move(roofMat));
// Mesh submeshes reference these materials by index
// building.mesh.subMeshes[0].materialIndex = 0 (brick)
// building.mesh.subMeshes[1].materialIndex = 1 (glass)
// building.mesh.subMeshes[2].materialIndex = 2 (roof)
// Instanced foliage rendering
Renderable trees;
trees.mesh = generateTreeMesh();
Material treeMat;
treeMat.shaderName = "foliage";
treeMat.setTexture2DRGBA("albedo", treeTexture);
trees.materials.push_back(std::move(treeMat));
// Generate many instances
for (int i = 0; i < 1000; ++i) {
instance.position = Vector3{
randomFloat(-100.0f, 100.0f),
0.0f,
randomFloat(-100.0f, 100.0f)
};
instance.rotation = quaternionFromEuler(0.0f, randomFloat(0, 360), 0.0f);
instance.scale = Vector3{1.0f, randomFloat(0.8f, 1.2f), 1.0f};
trees.instances.push_back(instance);
}
// Procedural terrain chunk
Renderable terrainChunk;
terrainChunk.mesh = generateTerrainMesh(chunkX, chunkZ);
// Multiple materials for terrain layers
Material grass, rock, snow;
// ... configure materials ...
terrainChunk.materials.push_back(std::move(grass));
terrainChunk.materials.push_back(std::move(rock));
terrainChunk.materials.push_back(std::move(snow));
// Use with ProceduralSystem
system->setIn("scene_object", std::move(building));
Shader configuration with parameters and textures for surface appearance.
Definition Material.hpp:96
void setFloat(const std::string &key, float value)
Sets a float parameter.
std::string shaderName
Name of the shader to use for rendering.
Definition Material.hpp:119
void setTexture2DRGBA(const std::string &key, const Containers::Array2D< Math::Vector4ub > &texture)
Sets a four-channel 8-bit texture (RGBA format).
Complete renderable object combining geometry, materials, and instancing.
Definition Renderable.hpp:127
Mesh mesh
Mesh geometry for this renderable.
Definition Renderable.hpp:135
Containers::Array< Material > materials
Array of materials applied to the mesh.
Definition Renderable.hpp:146
Containers::Array< Spatial::Transform > instances
Array of transform instances for instanced rendering.
Definition Renderable.hpp:162
Complete 3D spatial transformation combining position, rotation, and scale.
Definition Transform.hpp:84
Infinity::Types::Math::Vector4 rotation
Orientation as a quaternion.
Definition Transform.hpp:104
Infinity::Types::Math::Vector3 scale
Non-uniform scale factors along each axis.
Definition Transform.hpp:116
Infinity::Types::Math::Vector3 position
World-space position (translation).
Definition Transform.hpp:91

Constructor & Destructor Documentation

◆ Renderable()

Infinity::Types::Rendering::Renderable::Renderable ( )

Default constructor.

Creates an empty renderable with no geometry, materials, or instances.

◆ ~Renderable()

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

Destructor.

Member Function Documentation

◆ clone()

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

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

◆ typeId()

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

Gets the TypeID for Renderable.

Returns
TypeID identifying this Renderable type.

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

Member Data Documentation

◆ instances

Containers::Array<Spatial::Transform> Infinity::Types::Rendering::Renderable::instances

Array of transform instances for instanced rendering.

Each Transform defines position, rotation, and scale for one instance of the mesh. Empty array indicates single instance at identity transform (origin, no rotation, unit scale).

Instancing allows efficient rendering of the same geometry at multiple locations with different transforms, ideal for foliage, rocks, props, and other repeated elements.

Note
Empty array = single instance at identity transform.
Large instance counts enable GPU instanced rendering optimizations.

◆ materials

Containers::Array<Material> Infinity::Types::Rendering::Renderable::materials

Array of materials applied to the mesh.

Materials are referenced by index from SubMesh.materialIndex. The array must contain at least as many materials as the highest materialIndex used in the mesh's submeshes plus one.

Note
Empty array requires mesh to have no submeshes or use external materials.

◆ mesh

Mesh Infinity::Types::Rendering::Renderable::mesh

Mesh geometry for this renderable.

Contains vertex data, index data, and optional submesh partitioning for multi-material rendering. The mesh is shared across all instances.