ModelViewer 0.1
Template for CPP projects
Loading...
Searching...
No Matches
Material.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2026
3** Material.hpp
4** File description:
5** Material.hpp
6*/
7
8#ifndef MODELVIEWER_MATERIAL_HPP
9#define MODELVIEWER_MATERIAL_HPP
10
11#include <QColor>
12#include <QObject>
13#include <QUrl>
14#include <algorithm>
15#include <filesystem>
16#include <fstream>
17#include <iostream>
18#include <string>
19
22
23namespace model_viewer::material {
24
29class MTLMaterial final : public QObject {
30 Q_OBJECT
31
32 Q_PROPERTY(QColor diffuseColor MEMBER _Kd NOTIFY KdChanged)
33 Q_PROPERTY(
35 Q_PROPERTY(qreal metalness MEMBER _metalness NOTIFY metalnessChanged)
36 Q_PROPERTY(qreal roughness MEMBER _roughness NOTIFY roughnessChanged)
37 Q_PROPERTY(
39 Q_PROPERTY(qreal opacity MEMBER _d NOTIFY dChanged)
40 Q_PROPERTY(qreal indexOfRefraction MEMBER _Ni NOTIFY NiChanged)
41
42 Q_PROPERTY(QUrl diffuseMap READ getDiffuseMap NOTIFY diffuseMapChanged)
45 Q_PROPERTY(QUrl specularMap READ getSpecularMap NOTIFY specularMapChanged)
46 Q_PROPERTY(QUrl emissiveMap READ getEmissiveMap NOTIFY emissiveMapChanged)
47 Q_PROPERTY(QUrl dissolveMap READ getDissolveMap NOTIFY dissolveMapChanged)
48 Q_PROPERTY(QUrl bumpMap READ getBumpMap NOTIFY bumpMapChanged)
49 public:
50 private:
52 std::filesystem::path _parentPath;
53
55 QColor _Ka;
56
58 QColor _Kd;
59
61 QColor _Ks;
62
64 QColor _Ke;
65
67 QColor _Tf;
68
71
73 qreal _d;
74
76 qreal _Ns;
77
80
82 qreal _Ni;
83
85 qreal _metalness = 0.0;
86
88 qreal _roughness = 0.0;
89
91 qreal _bumpStrength = 0.0;
92
95
98
101
104
107
110
113
116
119
121 std::unordered_map<std::string, qreal> _scalars;
122
124 std::unordered_map<std::string, QColor> _colors;
125
127 std::unordered_map<std::string, QUrl> _maps;
128
130 std::unordered_map<std::string, std::function<void(const std::string &,
131 const std::string &)>>
133
134 public:
139 explicit MTLMaterial(QObject *parent = nullptr);
140
142 ~MTLMaterial() override = default;
143
148 void parseMTL(const std::string &filepath);
149
151 void resetMaterial();
152
157 const QUrl &getAmbientMap() const { return _ambientMap; };
158
163 const QUrl &getDiffuseMap() const { return _diffuseMap; };
164
169 const QUrl &getSpecularReflectionMap() const {
171 };
172
177 const QUrl &getSpecularMap() const { return _specularMap; };
178
183 const QUrl &getEmissiveMap() const { return _emissiveMap; };
184
189 const QUrl &getDissolveMap() const { return _dissolveMap; };
190
195 const QUrl &getBumpMap() const { return _bumpMap; };
196
201 const QUrl &getDecalMap() const { return _decalMap; };
202
207 const QUrl &getDispersionMap() const { return _dispersionMap; };
208 signals:
210 void KdChanged();
211
214
216 void dChanged();
217
219 void NsChanged();
220
223
225 void NiChanged();
226
229
232
235
238
241
244
247
250
253
254 private:
260 void parseMaterial(std::ifstream &file);
261
263 void setMaterialValues();
264
270 void parseScalar(const std::string &line, const std::string &key);
271
277 void parseColor(const std::string &line, const std::string &key);
278
284 void parseMap(const std::string &line, const std::string &key);
285};
286
287} // namespace model_viewer::material
288
289#endif // MODELVIEWER_MATERIAL_HPP
Class representing a material parsed from an MTL file.
Definition Material.hpp:29
QColor _Kd
Diffuse Color.
Definition Material.hpp:58
qreal _d
Opacity.
Definition Material.hpp:73
QUrl _ambientMap
Path to the Ambient Map.
Definition Material.hpp:94
QUrl _specularMap
Path to the Specular Map.
Definition Material.hpp:103
QUrl _dispersionMap
Path to the Dispersion Map.
Definition Material.hpp:118
qreal _bumpStrength
Bump/Normal Strength.
Definition Material.hpp:91
std::unordered_map< std::string, std::function< void(const std::string &, const std::string &)> > _parseFunctions
Map of parsing functions for different MTL line prefixes.
Definition Material.hpp:132
const QUrl & getDispersionMap() const
Get the Dispersion Map URL.
Definition Material.hpp:207
std::unordered_map< std::string, QUrl > _maps
Maps to store parsed texture maps before applying them.
Definition Material.hpp:127
const QUrl & getAmbientMap() const
Get the Ambient Map URL.
Definition Material.hpp:157
qreal illumination
Definition Material.hpp:34
void dChanged()
Signal emitted when the opacity changes.
const QUrl & getBumpMap() const
Get the Bump/Normal Map URL.
Definition Material.hpp:195
QUrl _decalMap
Path to the Decal Map.
Definition Material.hpp:115
const QUrl & getDiffuseMap() const
Get the Diffuse Map URL.
Definition Material.hpp:163
const QUrl & getDissolveMap() const
Get the Dissolve Map URL.
Definition Material.hpp:189
QUrl dissolveMap
Definition Material.hpp:47
void NsChanged()
Signal emitted when the specular roughness changes.
QUrl diffuseMap
Definition Material.hpp:42
qreal indexOfRefraction
Definition Material.hpp:40
qreal bumpStrength
Definition Material.hpp:38
qreal _sharpness
Sharpness.
Definition Material.hpp:79
qreal roughness
Definition Material.hpp:36
void KdChanged()
Signal emitted when the diffuse color changes.
QUrl specularReflectionMap
Definition Material.hpp:44
void metalnessChanged()
Signal emitted when the metalness changes.
qreal opacity
Definition Material.hpp:39
QColor _Ke
Emissive Color.
Definition Material.hpp:64
void bumpStrengthChanged()
Signal emitted when the bump strength changes.
std::unordered_map< std::string, qreal > _scalars
Maps to store parsed values before applying them.
Definition Material.hpp:121
void dissolveMapChanged()
Signal emitted when the dissolve map changes.
QUrl _emissiveMap
Path to the Emissive Map.
Definition Material.hpp:106
const QUrl & getEmissiveMap() const
Get the Emissive Map URL.
Definition Material.hpp:183
void parseMaterial(std::ifstream &file)
Parse the MTL file line by line.
Definition Material.cpp:63
QUrl _specularReflectionMap
Path to the Specular Reflection Map.
Definition Material.hpp:100
QUrl emissiveMap
Definition Material.hpp:46
QUrl _bumpMap
Path to the Bump/Normal Map.
Definition Material.hpp:112
QUrl _dissolveMap
Path to the Dissolve Map.
Definition Material.hpp:109
void parseMap(const std::string &line, const std::string &key)
Parse a texture map from an MTL line.
Definition Material.cpp:133
QColor _Tf
Transmission Filter.
Definition Material.hpp:67
std::filesystem::path _parentPath
Parent path of the MTL file.
Definition Material.hpp:52
std::unordered_map< std::string, QColor > _colors
Maps to store parsed colors before applying them.
Definition Material.hpp:124
qreal _illumination
Illumination Model.
Definition Material.hpp:70
qreal _roughness
Roughness.
Definition Material.hpp:88
QColor _Ks
Specular Color.
Definition Material.hpp:61
void diffuseMapChanged()
Signal emitted when the diffuse map changes.
void emissiveMapChanged()
Signal emitted when the emissive map changes.
void specularReflectionMapChanged()
Signal emitted when the specular reflection map changes.
void parseMTL(const std::string &filepath)
Parse an MTL file and set the material properties.
Definition Material.cpp:51
void specularMapChanged()
Signal emitted when the specular map changes.
const QUrl & getSpecularMap() const
Get the Specular Map URL.
Definition Material.hpp:177
void parseColor(const std::string &line, const std::string &key)
Parse a color value from an MTL line.
Definition Material.cpp:122
void parseScalar(const std::string &line, const std::string &key)
Parse a scalar value from an MTL line.
Definition Material.cpp:112
const QUrl & getDecalMap() const
Get the Decal Map URL.
Definition Material.hpp:201
void bumpMapChanged()
Signal emitted when the bump map changes.
const QUrl & getSpecularReflectionMap() const
Get the Specular Reflection Map URL.
Definition Material.hpp:169
QUrl _diffuseMap
Path to the Diffuse Map.
Definition Material.hpp:97
void NiChanged()
Signal emitted when the index of refraction changes.
QUrl bumpMap
Definition Material.hpp:48
void setMaterialValues()
Apply parsed values to the material properties.
Definition Material.cpp:84
qreal _Ni
Index of Refraction.
Definition Material.hpp:82
QColor diffuseColor
Definition Material.hpp:32
QColor _Ka
Ambient Color.
Definition Material.hpp:55
qreal _Ns
Specular Roughness.
Definition Material.hpp:76
void roughnessChanged()
Signal emitted when the roughness changes.
void resetMaterial()
Reset the material to default values.
Definition Material.cpp:74
qreal _metalness
Metalness.
Definition Material.hpp:85
qreal metalness
Definition Material.hpp:35
void sharpnessChanged()
Signal emitted when the sharpness changes.
void illuminationChanged()
Signal emitted when the illumination model changes.
QUrl specularMap
Definition Material.hpp:45
Definition Material.cpp:10