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.
| 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
-
| fileBytes | Raw contents of a model file (the full encoded file). |
| flipUVs | Whether to flip UV coordinates vertically during import. This matches the behavior of the file-based constructor. |
- Exceptions
-
| std::runtime_error | If 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}