Rendering Engine 0.2.9
Modular Graphics Rendering Engine | v0.2.9
model_material.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) 2026 Alexander Obzherin
4// Distributed under the terms of the zlib License. See LICENSE.md for details.
5#pragma once
6
7#include <map>
8#include <vector>
9#include <string>
10#include <cstdint>
11#include <stdexcept>
12
13struct aiMaterial;
14
15namespace rendering_engine
16{
17/**
18 * @enum TextureType
19 * @brief Enumerates supported texture map types for imported materials.
20 *
21 * These correspond to common texture slots used in 3D rendering pipelines
22 * and align with Assimp's material texture types. The range [Begin, End]
23 * allows easy iteration through all supported types.
24 */
26{
36
39};
40
41class Model;
42/**
43 * @class ModelMaterial
44 * @brief Represents a single material imported from a 3D model file.
45 *
46 * A `ModelMaterial` acts as a lightweight wrapper around Assimp's `aiMaterial`,
47 * extracting and storing references to texture file paths per texture type.
48 *
49 * @note Multiple meshes within a model may reference the same `ModelMaterial`.
50 * @see Model, TextureType
51 */
53{
54 friend class Model;
55
56public:
57 /**
58 * @brief Constructs an empty material associated with a model.
59 * @param model Reference to the owning Model instance.
60 */
61 explicit ModelMaterial(Model& model);
62
63 ModelMaterial(const ModelMaterial&) = default;
67 ~ModelMaterial() = default;
68 /**
69 * @brief Returns a reference to the owning Model.
70 * @return Reference to the parent Model instance.
71 */
72 Model& GetModel();
73 /**
74 * @brief Gets the material name as defined in the source file.
75 * @return Material name string.
76 */
77 const std::string& Name() const;
78 /**
79 * @brief Retrieves the list of textures associated with each texture type.
80 *
81 * Each entry in the map corresponds to one TextureType key (e.g., Diffuse, NormalMap)
82 * and a list of texture file paths associated with that type.
83 *
84 * @return A map of texture types to vectors of texture file paths.
85 */
86 const std::map<TextureType, std::vector<std::string>> Textures() const;
87
88private:
89 static const std::map<TextureType, std::uint32_t> sTextureTypeMappings;
90
91 ModelMaterial(Model& model, aiMaterial& material);
92
93 Model* mModel;
94 std::string mName;
95 std::map<TextureType, std::vector<std::string>> mTextures;
96};
97
98template <typename T>
99class Enum final
100{
101public:
102 class Iterator final
103 {
104 public:
105 using size_type = std::size_t;
106 using difference_type = std::ptrdiff_t;
107 using value_type = T;
108 using reference = T;
109 using pointer = T*;
110 using iterator_category = std::forward_iterator_tag;
111
112 Iterator() = default;
113 explicit Iterator(T value);
114 Iterator(const Iterator&) = default;
115 Iterator(Iterator&&) = default;
116 Iterator& operator=(const Iterator&) = default;
118 ~Iterator() = default;
119
120 T operator*() const;
122 Iterator operator++(int);
123
124 bool operator==(const Iterator& rhs) const;
125 bool operator!=(const Iterator& rhs) const;
126
127 private:
128 T mValue;
129 };
130
131 Iterator begin() const;
132 Iterator end() const;
133};
134
135template <typename T>
137 mValue(value)
138{
139}
140
141template <typename T>
142inline bool Enum<T>::Iterator::operator==(const Iterator& rhs) const
143{
144 return mValue == rhs.mValue;
145}
146
147template <typename T>
148inline bool Enum<T>::Iterator::operator!=(const Iterator& rhs) const
149{
150 return mValue != rhs.mValue;
151}
152
153template <typename T>
155{
156 if (mValue > T::End)
157 {
158 throw std::runtime_error("Cannot dereference end().");
159 }
160
161 return mValue;
162}
163
164template <typename T>
166{
167 if (mValue <= T::End)
168 {
169 mValue = T(static_cast<int>(mValue) + 1);
170 }
171 return *this;
172}
173
174template <typename T>
176{
177 Iterator temp = *this;
178 operator++();
179 return temp;
180}
181
182template <typename T>
183inline typename Enum<T>::Iterator Enum<T>::begin() const
184{
185 return Iterator(T::Begin);
186}
187
188template <typename T>
189inline typename Enum<T>::Iterator Enum<T>::end() const
190{
191 return Iterator(T(static_cast<int>(T::End) + 1));
192}
193
194}// namespace rendering_engine
Iterator & operator=(const Iterator &)=default
Iterator(Iterator &&)=default
Iterator(const Iterator &)=default
bool operator==(const Iterator &rhs) const
Iterator & operator=(Iterator &&)=default
bool operator!=(const Iterator &rhs) const
std::forward_iterator_tag iterator_category
Iterator begin() const
Represents a single material imported from a 3D model file.
const std::string & Name() const
Gets the material name as defined in the source file.
const std::map< TextureType, std::vector< std::string > > Textures() const
Retrieves the list of textures associated with each texture type.
ModelMaterial(Model &model)
Constructs an empty material associated with a model.
ModelMaterial(ModelMaterial &&)=default
ModelMaterial(const ModelMaterial &)=default
Model & GetModel()
Returns a reference to the owning Model.
ModelMaterial & operator=(const ModelMaterial &)=default
ModelMaterial & operator=(ModelMaterial &&)=default
Represents a 3D model composed of multiple meshes and materials.
Definition: model.hpp:30
TextureType
Enumerates supported texture map types for imported materials.