Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
Loading...
Searching...
No Matches
mesh.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#define GLM_ENABLE_EXPERIMENTAL
8#include <glm/glm.hpp>
9#include <cstdint>
10#include <string>
11#include <vector>
12#include <memory>
13
14struct aiMesh;
15
16namespace rendering_engine
17{
18class ModelMaterial;
19class Model;
20/**
21 * @class Mesh
22 * @brief Represents a single geometric mesh imported from a model file.
23 *
24 * The Mesh class stores all CPU-side vertex attributes and index data for one
25 * mesh, as imported from an Assimp `aiMesh`. It acts as an intermediate
26 * container before the data is transferred to GPU buffers (via MeshDataGpu).
27 *
28 * Each Mesh instance is associated with:
29 * - One parent `Model`
30 * - One `ModelMaterial` describing surface properties
31 * - One or more vertex attribute streams (positions, normals, tangents, etc.)
32 *
33 * @note This class does not handle GPU resource management.
34 * @see Model, ModelMaterial, MeshDataGpu
35 */
36class Mesh
37{
38 friend class Model;
39
40public:
41 Mesh(const Mesh&) = default;
42 Mesh& operator=(const Mesh&) = default;
43 Mesh(Mesh&&) = default;
44 Mesh& operator=(Mesh&&) = default;
45 ~Mesh() = default;
46 /**
47 * @brief Returns the parent model that owns this mesh.
48 * @return Reference to the parent Model.
49 */
50 Model& GetModel();
51 /**
52 * @brief Returns the material associated with this mesh.
53 * @return Shared pointer to ModelMaterial.
54 */
55 std::shared_ptr<ModelMaterial> GetMaterial() const;
56 /**
57 * @brief Returns the mesh name as imported from the source file.
58 * @return Mesh name string.
59 */
60 const std::string& Name() const;
61 /**
62 * @brief Returns the vertex position array.
63 * @return Vector of vertex positions (glm::vec3).
64 */
65 const std::vector<glm::vec3>& Vertices() const;
66 /**
67 * @brief Returns the vertex normal array.
68 * @return Vector of normal vectors (glm::vec3).
69 */
70 const std::vector<glm::vec3>& Normals() const;
71 /**
72 * @brief Returns the vertex tangent array.
73 * @return Vector of tangent vectors (glm::vec3).
74 */
75 const std::vector<glm::vec3>& Tangents() const;
76 /**
77 * @brief Returns the vertex binormal array.
78 * @return Vector of binormal vectors (glm::vec3).
79 */
80 const std::vector<glm::vec3>& BiNormals() const;
81 /**
82 * @brief Returns texture coordinate sets.
83 *
84 * Each inner vector represents one texture coordinate channel.
85 * Assimp supports up to 8 UV sets per mesh.
86 *
87 * @return Vector of texture coordinate arrays.
88 */
89 const std::vector<std::vector<glm::vec3>>& TextureCoordinates() const;
90 /**
91 * @brief Returns per-vertex color sets.
92 *
93 * Each inner vector corresponds to one color channel.
94 *
95 * @return Vector of vertex color arrays (each color is a vec4).
96 */
97 const std::vector<std::vector<glm::vec4>>& VertexColors() const;
98 /**
99 * @brief Returns the number of faces in the mesh.
100 * @return Face count.
101 */
102 std::uint32_t FaceCount() const;
103 /**
104 * @brief Returns the vertex index buffer.
105 * @return Vector of vertex indices.
106 */
107 const std::vector<std::uint32_t>& Indices() const;
108
109private:
110 Mesh(Model& model, aiMesh& mesh);
111
112private:
113 Model* mModel;
114 std::shared_ptr<ModelMaterial> mMaterial;
115 std::string mName;
116 std::vector<glm::vec3> mVertices;
117 std::vector<glm::vec3> mNormals;
118 std::vector<glm::vec3> mTangents;
119 std::vector<glm::vec3> mBiNormals;
120 std::vector<std::vector<glm::vec3>> mTextureCoordinates;
121 std::vector<std::vector<glm::vec4>> mVertexColors;
122 std::uint32_t mFaceCount;
123 std::vector<std::uint32_t> mIndices;
124};
125
126} // namespace rendering_engine
friend class Model
Definition mesh.hpp:38
const std::vector< std::vector< glm::vec3 > > & TextureCoordinates() const
Returns texture coordinate sets.
Definition mesh.cpp:138
std::shared_ptr< ModelMaterial > GetMaterial() const
Returns the material associated with this mesh.
Definition mesh.cpp:108
Mesh & operator=(const Mesh &)=default
const std::vector< std::uint32_t > & Indices() const
Returns the vertex index buffer.
Definition mesh.cpp:153
const std::vector< glm::vec3 > & Vertices() const
Returns the vertex position array.
Definition mesh.cpp:118
Mesh & operator=(Mesh &&)=default
const std::vector< glm::vec3 > & BiNormals() const
Returns the vertex binormal array.
Definition mesh.cpp:133
Model & GetModel()
Returns the parent model that owns this mesh.
Definition mesh.cpp:103
const std::vector< glm::vec3 > & Tangents() const
Returns the vertex tangent array.
Definition mesh.cpp:128
const std::vector< std::vector< glm::vec4 > > & VertexColors() const
Returns per-vertex color sets.
Definition mesh.cpp:143
Mesh(const Mesh &)=default
std::uint32_t FaceCount() const
Returns the number of faces in the mesh.
Definition mesh.cpp:148
const std::vector< glm::vec3 > & Normals() const
Returns the vertex normal array.
Definition mesh.cpp:123
const std::string & Name() const
Returns the mesh name as imported from the source file.
Definition mesh.cpp:113
Mesh(Mesh &&)=default