Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
Loading...
Searching...
No Matches
model.hpp
Go to the documentation of this file.
1// This file is part of the Rendering Engine project.
2// Author: Alexander Obzherin <alexanderobzherin@gmail.com>
3// Copyright (c) 2025 Alexander Obzherin
4// Distributed under the terms of the zlib License. See LICENSE.md for details.
5#pragma once
6
7#include "mesh.hpp"
8
9namespace rendering_engine
10{
11class ModelMaterial;
12
13/**
14 * @class Model
15 * @brief Represents a 3D model composed of multiple meshes and materials.
16 *
17 * The Model class serves as an intermediate container between the model-loading
18 * backend (e.g., Assimp) and GPU-side mesh upload (via MeshDataGpu). It holds
19 * all meshes and materials associated with a 3D model file, typically loaded
20 * from formats such as FBX, OBJ, or glTF.
21 *
22 * Each imported model can contain multiple meshes and materials, all of which
23 * are accessible through this class for further processing or rendering.
24 *
25 * @note This class does not perform rendering. It only stores CPU-side mesh
26 * and material data for later GPU upload.
27 * @see Mesh, ModelMaterial, MeshDataGpu
28 */
29class Model final
30{
31friend class Mesh;
32
33public:
34 /**
35 * @brief Constructs a model from a file.
36 *
37 * The model loader uses Assimp internally to parse the file and build
38 * Mesh and ModelMaterial instances. Optionally, UV coordinates can be
39 * flipped vertically during import.
40 *
41 * @param filename Path to the model file (e.g., `.obj`, `.fbx`, `.gltf`).
42 * @param flipUVs Whether to flip UV coordinates vertically (useful for texture alignment).
43 */
44 explicit Model(const std::string& filename, bool flipUVs = false);
45
46 /**
47 * @brief Constructs a model from an in-memory file buffer.
48 *
49 * This constructor allows importing a 3D model directly from raw file bytes
50 * stored in memory rather than from disk.
51 *
52 * The import process creates Mesh and ModelMaterial instances exactly the
53 * same way as the file-based constructor.
54 *
55 * @param fileBytes Raw contents of a model file (the full encoded file).
56 * @param flipUVs Whether to flip UV coordinates vertically during import.
57 * This matches the behavior of the file-based constructor.
58 *
59 * @throws std::runtime_error If Assimp fails to load the model.
60 */
61 explicit Model(std::vector<uint8_t> const& fileBytes, bool flipUVs = false);
62
63 Model(const Model&) = default;
64 Model& operator=(const Model&) = default;
65 Model(Model&&) = default;
66 Model& operator=(Model&&) = default;
67 ~Model() = default;
68
69 /**
70 * @brief Checks whether this model contains any meshes.
71 * @return True if at least one mesh was loaded; false otherwise.
72 */
73 bool HasMeshes() const;
74 /**
75 * @brief Checks whether this model contains any materials.
76 * @return True if at least one material was loaded; false otherwise.
77 */
78 bool HasMaterials() const;
79 /**
80 * @brief Returns the list of meshes belonging to this model.
81 * @return Vector of shared pointers to Mesh objects.
82 */
83 const std::vector<std::shared_ptr<Mesh>>& Meshes() const;
84 /**
85 * @brief Returns the list of materials belonging to this model.
86 * @return Vector of shared pointers to ModelMaterial objects.
87 */
88 const std::vector<std::shared_ptr<ModelMaterial>>& Materials() const;
89
90private:
91 std::vector<std::shared_ptr<Mesh>> mMeshes;
92 std::vector<std::shared_ptr<ModelMaterial>> mMaterials;
93};
94}// namespace rendering_engine
bool HasMeshes() const
Checks whether this model contains any meshes.
Definition model.cpp:76
Model & operator=(const Model &)=default
Model(Model &&)=default
bool HasMaterials() const
Checks whether this model contains any materials.
Definition model.cpp:80
Model(const std::string &filename, bool flipUVs=false)
Constructs a model from a file.
Definition model.cpp:10
friend class Mesh
Definition model.hpp:31
Model(const Model &)=default
const std::vector< std::shared_ptr< ModelMaterial > > & Materials() const
Returns the list of materials belonging to this model.
Definition model.cpp:88
const std::vector< std::shared_ptr< Mesh > > & Meshes() const
Returns the list of meshes belonging to this model.
Definition model.cpp:84
Model & operator=(Model &&)=default
Represents a single material imported from a 3D model file.