Raftel Engine
 
Loading...
Searching...
No Matches
Raftel::Mesh Class Reference

Represents a 3D mesh, including vertex data, indices, and materials. More...

#include <mesh.hpp>

Public Member Functions

 Mesh ()=default
 Default constructor for the Mesh class.
 
 ~Mesh ()
 Destructor for the Mesh class.
 
 Mesh (const std::string &filePath)
 Constructor that loads a mesh from a given file path.
 
 Mesh (std::vector< std::vector< Vertex > > verticesPerSubmesh, std::vector< std::vector< unsigned int > > indicesPerSubmesh, std::vector< std::shared_ptr< Material > > mats)
 Constructor that takes vertices, indices, and materials directly.
 
 Mesh (std::vector< std::vector< Vertex > > verticesPerSubmesh, std::vector< std::vector< unsigned int > > indicesPerSubmesh)
 Constructor that takes vertices and indices data without materials.
 
bool loadMesh (const std::string &filePath)
 Loads a mesh from a file.
 
void setMaterials (const std::vector< std::shared_ptr< Material > > &newMaterials)
 Sets the materials for the mesh.
 
void setMaterial (const std::shared_ptr< Material > &mat)
 Sets a single material for the mesh.
 
void addMaterial (const std::shared_ptr< Material > &mat)
 Adds a material to the mesh.
 
void setupMesh ()
 Initializes OpenGL buffers for the mesh (VAO, VBO, EBO).
 
void draw (ShaderProgram &shader)
 Renders the mesh using a specified shader.
 
void setUniforms (GLuint shaderProgramID)
 Sets the uniform variables for the shader program.
 
void renderMaterial (ShaderProgram &shader)
 Renders the material of the mesh.
 
std::string getName ()
 Retrieves the name of the mesh.
 
void setName (std::string n_)
 Sets the name of the mesh.
 
const std::string & getLastError () const
 Retrieves the last error encountered during mesh loading.
 
std::shared_ptr< MaterialGetMaterialByIndex (int index)
 Retrieves a material by its index.
 
std::vector< std::shared_ptr< Material > > & GetAllMaterials ()
 Retrieves all materials associated with the mesh.
 
std::vector< GLuint > GetVAOs ()
 Retrieves all VAOs associated with the mesh.
 
std::vector< std::vector< unsigned int > > GetSubMeshIndex ()
 Retrieves all submesh indices.
 

Static Public Member Functions

static std::shared_ptr< MeshCreate (const std::string &filePath, bool multithread)
 Move constructor for the Mesh class.
 

Detailed Description

Represents a 3D mesh, including vertex data, indices, and materials.

The Mesh class is responsible for storing, loading, and rendering 3D mesh data. It handles multiple submeshes, OpenGL buffers, and materials associated with the mesh.

The class supports the use of multiple materials and submeshes, where each submesh has its own vertex and index data.

Definition at line 89 of file mesh.hpp.

Constructor & Destructor Documentation

◆ Mesh() [1/3]

Raftel::Mesh::Mesh ( const std::string & filePath)

Constructor that loads a mesh from a given file path.

Parameters
filePathThe file path to the mesh file.

◆ Mesh() [2/3]

Raftel::Mesh::Mesh ( std::vector< std::vector< Vertex > > verticesPerSubmesh,
std::vector< std::vector< unsigned int > > indicesPerSubmesh,
std::vector< std::shared_ptr< Material > > mats )

Constructor that takes vertices, indices, and materials directly.

Parameters
verticesPerSubmeshA vector of vertex data for each submesh.
indicesPerSubmeshA vector of index data for each submesh.
matsA vector of materials for the mesh.

◆ Mesh() [3/3]

Raftel::Mesh::Mesh ( std::vector< std::vector< Vertex > > verticesPerSubmesh,
std::vector< std::vector< unsigned int > > indicesPerSubmesh )

Constructor that takes vertices and indices data without materials.

Parameters
verticesPerSubmeshA vector of vertex data for each submesh.
indicesPerSubmeshA vector of index data for each submesh.

Member Function Documentation

◆ addMaterial()

void Raftel::Mesh::addMaterial ( const std::shared_ptr< Material > & mat)
inline

Adds a material to the mesh.

Parameters
matThe material to add.

Definition at line 167 of file mesh.hpp.

◆ Create()

static std::shared_ptr< Mesh > Raftel::Mesh::Create ( const std::string & filePath,
bool multithread )
static

Move constructor for the Mesh class.

Static factory method to create a Mesh instance from a file.

Parameters
filePathThe file path to the mesh file.
multithreadFlag to enable multithreading while loading.
Returns
A shared pointer to the created Mesh instance.

◆ draw()

void Raftel::Mesh::draw ( ShaderProgram & shader)

Renders the mesh using a specified shader.

Parameters
shaderThe shader program to use for rendering.

◆ GetAllMaterials()

std::vector< std::shared_ptr< Material > > & Raftel::Mesh::GetAllMaterials ( )
inline

Retrieves all materials associated with the mesh.

Returns
A reference to the vector of materials.

Definition at line 223 of file mesh.hpp.

◆ getLastError()

const std::string & Raftel::Mesh::getLastError ( ) const
inline

Retrieves the last error encountered during mesh loading.

Returns
The last error message as a string.

Definition at line 210 of file mesh.hpp.

◆ GetMaterialByIndex()

std::shared_ptr< Material > Raftel::Mesh::GetMaterialByIndex ( int index)

Retrieves a material by its index.

Parameters
indexThe index of the material.
Returns
A shared pointer to the material at the given index.

◆ getName()

std::string Raftel::Mesh::getName ( )
inline

Retrieves the name of the mesh.

Returns
The name of the mesh.

Definition at line 198 of file mesh.hpp.

◆ GetSubMeshIndex()

std::vector< std::vector< unsigned int > > Raftel::Mesh::GetSubMeshIndex ( )
inline

Retrieves all submesh indices.

Returns
A vector of vectors of unsigned integers representing submesh indices.

Definition at line 235 of file mesh.hpp.

◆ GetVAOs()

std::vector< GLuint > Raftel::Mesh::GetVAOs ( )
inline

Retrieves all VAOs associated with the mesh.

Returns
A vector of GLuints representing the VAOs.

Definition at line 229 of file mesh.hpp.

◆ loadMesh()

bool Raftel::Mesh::loadMesh ( const std::string & filePath)

Loads a mesh from a file.

Parameters
filePathThe file path to the mesh file.
Returns
True if loading was successful, false otherwise.

◆ renderMaterial()

void Raftel::Mesh::renderMaterial ( ShaderProgram & shader)

Renders the material of the mesh.

Parameters
shaderThe shader program to use for rendering the material.

◆ setMaterial()

void Raftel::Mesh::setMaterial ( const std::shared_ptr< Material > & mat)
inline

Sets a single material for the mesh.

Parameters
matThe material to apply.

Definition at line 158 of file mesh.hpp.

◆ setMaterials()

void Raftel::Mesh::setMaterials ( const std::vector< std::shared_ptr< Material > > & newMaterials)
inline

Sets the materials for the mesh.

Parameters
newMaterialsA vector of materials to apply to the mesh.

Definition at line 150 of file mesh.hpp.

◆ setName()

void Raftel::Mesh::setName ( std::string n_)
inline

Sets the name of the mesh.

Parameters
n_The name to set for the mesh.

Definition at line 204 of file mesh.hpp.

◆ setUniforms()

void Raftel::Mesh::setUniforms ( GLuint shaderProgramID)

Sets the uniform variables for the shader program.

Parameters
shaderProgramIDThe ID of the shader program.

The documentation for this class was generated from the following file: