Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
Loading...
Searching...
No Matches
rendering_engine::Model Class Referencefinal

Represents a 3D model composed of multiple meshes and materials. More...

#include <model.hpp>

Public Member Functions

 Model (const std::string &filename, bool flipUVs=false)
 Constructs a model from a file.
 Model (std::vector< uint8_t > const &fileBytes, bool flipUVs=false)
 Constructs a model from an in-memory file buffer.
 Model (const Model &)=default
Modeloperator= (const Model &)=default
 Model (Model &&)=default
Modeloperator= (Model &&)=default
 ~Model ()=default
bool HasMeshes () const
 Checks whether this model contains any meshes.
bool HasMaterials () const
 Checks whether this model contains any materials.
const std::vector< std::shared_ptr< Mesh > > & Meshes () const
 Returns the list of meshes belonging to this model.
const std::vector< std::shared_ptr< ModelMaterial > > & Materials () const
 Returns the list of materials belonging to this model.

Friends

class Mesh

Detailed Description

Represents a 3D model composed of multiple meshes and materials.

The Model class serves as an intermediate container between the model-loading backend (e.g., Assimp) and GPU-side mesh upload (via MeshDataGpu). It holds all meshes and materials associated with a 3D model file, typically loaded from formats such as FBX, OBJ, or glTF.

Each imported model can contain multiple meshes and materials, all of which are accessible through this class for further processing or rendering.

Note
This class does not perform rendering. It only stores CPU-side mesh and material data for later GPU upload.
See also
Mesh, ModelMaterial, MeshDataGpu

Definition at line 29 of file model.hpp.

Constructor & Destructor Documentation

◆ Model() [1/4]

rendering_engine::Model::Model ( const std::string & filename,
bool flipUVs = false )
explicit

Constructs a model from a file.

The model loader uses Assimp internally to parse the file and build Mesh and ModelMaterial instances. Optionally, UV coordinates can be flipped vertically during import.

Parameters
filenamePath to the model file (e.g., .obj, .fbx, .gltf).
flipUVsWhether to flip UV coordinates vertically (useful for texture alignment).

Definition at line 10 of file model.cpp.

11{
12 Assimp::Importer importer;
13
14 uint32_t flags = aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType;
15 if( flipUVs )
16 {
17 flags |= aiProcess_FlipUVs;
18 }
19
20 const aiScene* scene = importer.ReadFile(filename, flags);
21
22 if( scene == nullptr )
23 {
24 throw std::runtime_error(importer.GetErrorString());
25 }
26
27 if( scene->HasMaterials() )
28 {
29 for( uint32_t i = 0; i < scene->mNumMaterials; i++ )
30 {
31 mMaterials.push_back(std::shared_ptr<ModelMaterial>(new ModelMaterial(*this, *scene->mMaterials[i])));
32 }
33 }
34
35 if( scene->HasMeshes() )
36 {
37 for( uint32_t i = 0; i < scene->mNumMeshes; i++ )
38 {
39 mMeshes.push_back(std::shared_ptr<Mesh>(new Mesh(*this, *(scene->mMeshes[i]))));
40 }
41 }
42}
friend class Mesh
Definition model.hpp:31

◆ Model() [2/4]

rendering_engine::Model::Model ( std::vector< uint8_t > const & fileBytes,
bool flipUVs = false )
explicit

Constructs a model from an in-memory file buffer.

This constructor allows importing a 3D model directly from raw file bytes stored in memory rather than from disk.

The import process creates Mesh and ModelMaterial instances exactly the same way as the file-based constructor.

Parameters
fileBytesRaw contents of a model file (the full encoded file).
flipUVsWhether to flip UV coordinates vertically during import. This matches the behavior of the file-based constructor.
Exceptions
std::runtime_errorIf Assimp fails to load the model.

Definition at line 43 of file model.cpp.

44{
45 Assimp::Importer importer;
46
47 uint32_t flags = aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType;
48 if (flipUVs)
49 {
50 flags |= aiProcess_FlipUVs;
51 }
52
53 const aiScene* scene = importer.ReadFileFromMemory(fileBytes.data(), fileBytes.size(), flags, "fbx");
54
55 if (scene == nullptr)
56 {
57 throw std::runtime_error(importer.GetErrorString());
58 }
59
60 if (scene->HasMaterials())
61 {
62 for (uint32_t i = 0; i < scene->mNumMaterials; i++)
63 {
64 mMaterials.push_back(std::shared_ptr<ModelMaterial>(new ModelMaterial(*this, *scene->mMaterials[i])));
65 }
66 }
67
68 if (scene->HasMeshes())
69 {
70 for (uint32_t i = 0; i < scene->mNumMeshes; i++)
71 {
72 mMeshes.push_back(std::shared_ptr<Mesh>(new Mesh(*this, *(scene->mMeshes[i]))));
73 }
74 }
75}

◆ Model() [3/4]

rendering_engine::Model::Model ( const Model & )
default

◆ Model() [4/4]

rendering_engine::Model::Model ( Model && )
default

◆ ~Model()

rendering_engine::Model::~Model ( )
default

Member Function Documentation

◆ HasMaterials()

bool rendering_engine::Model::HasMaterials ( ) const

Checks whether this model contains any materials.

Returns
True if at least one material was loaded; false otherwise.

Definition at line 80 of file model.cpp.

81{
82 return !mMaterials.empty();
83}

◆ HasMeshes()

bool rendering_engine::Model::HasMeshes ( ) const

Checks whether this model contains any meshes.

Returns
True if at least one mesh was loaded; false otherwise.

Definition at line 76 of file model.cpp.

77{
78 return !mMeshes.empty();
79}

◆ Materials()

const std::vector< std::shared_ptr< ModelMaterial > > & rendering_engine::Model::Materials ( ) const

Returns the list of materials belonging to this model.

Returns
Vector of shared pointers to ModelMaterial objects.

Definition at line 88 of file model.cpp.

89{
90 return mMaterials;
91}

◆ Meshes()

const std::vector< std::shared_ptr< Mesh > > & rendering_engine::Model::Meshes ( ) const

Returns the list of meshes belonging to this model.

Returns
Vector of shared pointers to Mesh objects.

Definition at line 84 of file model.cpp.

85{
86 return mMeshes;
87}

◆ operator=() [1/2]

Model & rendering_engine::Model::operator= ( const Model & )
default

◆ operator=() [2/2]

Model & rendering_engine::Model::operator= ( Model && )
default

◆ Mesh

friend class Mesh
friend

Definition at line 31 of file model.hpp.


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