Ocean
scenedescription/sdl/obj/Material.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_SCENEDESCRIPTION_SDL_OBJ_MATERIAL_H
9 #define META_OCEAN_SCENEDESCRIPTION_SDL_OBJ_MATERIAL_H
10 
12 
14 #include "ocean/rendering/Engine.h"
15 
16 #include "ocean/math/RGBAColor.h"
17 
18 namespace Ocean
19 {
20 
21 namespace SceneDescription
22 {
23 
24 // Forward declaration
25 class SDLScene;
26 
27 namespace SDL
28 {
29 
30 namespace OBJ
31 {
32 
33 /**
34  * This class hold a material defined in a mtl obj material file.
35  * @ingroup scenedescriptionsdlobj
36  */
37 class OCEAN_SCENEDESCRIPTION_SDL_OBJ_EXPORT Material
38 {
39  public:
40 
41  /**
42  * Definition of illumination models.
43  */
44  typedef unsigned int IlluminationModel;
45 
46  public:
47 
48  /**
49  * Creates a new material object with default values.
50  */
51  Material() = default;
52 
53  /**
54  * Returns the name of this material.
55  * @return Material name
56  */
57  inline const std::string& name() const;
58 
59  /**
60  * Returns the ambient color of this material.
61  * @return Ambient color
62  */
63  inline const RGBAColor& ambientColor() const;
64 
65  /**
66  * Returns the diffuse color of this material.
67  * @return Diffuse color
68  */
69  inline const RGBAColor& diffuseColor() const;
70 
71  /**
72  * Returns the emissive color of this material.
73  * @return Emissive color
74  */
75  inline const RGBAColor& emissiveColor() const;
76 
77  /**
78  * Returns the specular color of this material.
79  * @return Specular color
80  */
81  inline const RGBAColor& specularColor() const;
82 
83  /**
84  * Returns the transparency of this material with range [0.0, 1.0]
85  * 0 means fully opaque, 1 means fully transparent.
86  * @return Material transparency
87  */
88  inline float transparency() const;
89 
90  /**
91  * Returns the transmission filter of this material.
92  * @return Transmission filter
93  */
94  inline const RGBAColor& transmissionFilter() const;
95 
96  /**
97  * Returns the illumination model of this material.
98  * @return Illumination model
99  */
100  inline IlluminationModel illuminationModel() const;
101 
102  /**
103  * Returns the specular exponent of this material.
104  * @return Specular exponent
105  */
106  inline Scalar specularExponent() const;
107 
108  /**
109  * Returns the texture name of this material.
110  * @return Texture name
111  */
112  inline const std::string& textureName() const;
113 
114  /**
115  * Returns the attribute set of this material.
116  * @param engine The rendering engine to use
117  * @param scene The scene object for which the attribute set will be created
118  * @return The resulting attribute set
119  */
121 
122  /**
123  * Sets the name of this material.
124  * @param name Name to set
125  */
126  inline void setName(const std::string& name);
127 
128  /**
129  * Sets the ambient color of this material.
130  * @param color Ambient color to set
131  */
132  inline void setAmbientColor(const RGBAColor& color);
133 
134  /**
135  * Sets the diffuse color of this material.
136  * @param color Diffuse color to set
137  */
138  inline void setDiffuseColor(const RGBAColor& color);
139 
140  /**
141  * Sets the emissive color of this material.
142  * @param color Emissive color to set
143  */
144  inline void setEmissiveColor(const RGBAColor& color);
145 
146  /**
147  * Sets the specular color of this material.
148  * @param color Specular color to set
149  */
150  inline void setSpecularColor(const RGBAColor& color);
151 
152  /**
153  * Sets the transparency value of this material with range [0.0, 1.0].
154  * 0 means fully opaque, 1 means fully transparent.
155  * @param transparency Transparency value to set
156  */
157  inline void setTransparency(const float transparency);
158 
159  /**
160  * Sets the transmission filter of this material.
161  * @param filter Filter to set
162  */
163  inline void setTransmissionFilter(const RGBAColor& filter);
164 
165  /**
166  * Sets the illumination model of this material.
167  * @param model Illumination model to set
168  */
169  inline void setIlluminationModel(const IlluminationModel model);
170 
171  /**
172  * Sets the specular exponent of this material.
173  * @param exponent Specular exponent to set
174  */
175  inline void setSpecularExponent(const Scalar exponent);
176 
177  /**
178  * Sets the texture name of this material.
179  * @param name Texture name to set
180  */
181  inline void setTextureName(const std::string& name);
182 
183  protected:
184 
185  /// Holds the name of this material.
186  std::string name_;
187 
188  /// Holds the ambient color of this material.
189  RGBAColor ambientColor_ = RGBAColor(0.2f, 0.2f, 0.2f);
190 
191  /// Holds the diffuse color of this material.
192  RGBAColor diffuseColor_ = RGBAColor(0.8f, 0.8f, 0.8f);
193 
194  /// Holds the emissive color of this material.
195  RGBAColor emissiveColor_ = RGBAColor(0, 0, 0);
196 
197  /// Holds the specular color of this material.
198  RGBAColor specularColor_ = RGBAColor(1, 1, 1);
199 
200  /// Holds the transparency value of this material with range [0 (opaque), 1 (transparent)].
201  float transparency_ = 0.0f;
202 
203  /// Holds the transmission filter of this material.
205 
206  /// Holds the illumination model of this material, a diffuse illumination model by default.
207  IlluminationModel iIlluminationModel_ = IlluminationModel(1);
208 
209  /// Holds the specular exponent of this material.
210  Scalar specularExponent_ = Scalar(0);
211 
212  /// Holds the texture name of this material.
213  std::string textureName_;
214 
215  /// Rendering attribute set.
217 };
218 
219 inline const std::string& Material::name() const
220 {
221  return name_;
222 }
223 
224 inline const RGBAColor& Material::ambientColor() const
225 {
226  return ambientColor_;
227 }
228 
229 inline const RGBAColor& Material::diffuseColor() const
230 {
231  return diffuseColor_;
232 }
233 
234 inline const RGBAColor& Material::emissiveColor() const
235 {
236  return emissiveColor_;
237 }
238 
239 inline const RGBAColor& Material::specularColor() const
240 {
241  return specularColor_;
242 }
243 
244 inline float Material::transparency() const
245 {
246  return transparency_;
247 }
248 
250 {
251  return transmissionFilter_;
252 }
253 
255 {
256  return iIlluminationModel_;
257 }
258 
260 {
261  return specularExponent_;
262 }
263 
264 const std::string& Material::textureName() const
265 {
266  return textureName_;
267 }
268 
269 inline void Material::setName(const std::string& name)
270 {
271  name_ = name;
272 }
273 
274 inline void Material::setAmbientColor(const RGBAColor& color)
275 {
276  ambientColor_ = color;
277 }
278 
279 inline void Material::setDiffuseColor(const RGBAColor& color)
280 {
281  diffuseColor_ = color;
282 }
283 
284 inline void Material::setEmissiveColor(const RGBAColor& color)
285 {
286  emissiveColor_ = color;
287 }
288 
289 inline void Material::setSpecularColor(const RGBAColor& color)
290 {
291  specularColor_ = color;
292 }
293 
294 inline void Material::setTransparency(const float transparency)
295 {
297 }
298 
299 inline void Material::setTransmissionFilter(const RGBAColor& filter)
300 {
301  transmissionFilter_ = filter;
302 }
303 
305 {
306  iIlluminationModel_ = model;
307 }
308 
309 inline void Material::setSpecularExponent(const Scalar exponent)
310 {
311  specularExponent_ = exponent;
312 }
313 
314 inline void Material::setTextureName(const std::string& name)
315 {
316  textureName_ = name;
317 }
318 
319 }
320 
321 }
322 
323 }
324 
325 }
326 
327 #endif // META_OCEAN_SCENEDESCRIPTION_SDL_OBJ_MATERIAL_H
This class implements a color defined by red, green, blue and alpha parameters.
Definition: RGBAColor.h:41
This class hold a material defined in a mtl obj material file.
Definition: scenedescription/sdl/obj/Material.h:38
void setEmissiveColor(const RGBAColor &color)
Sets the emissive color of this material.
Definition: scenedescription/sdl/obj/Material.h:284
void setSpecularColor(const RGBAColor &color)
Sets the specular color of this material.
Definition: scenedescription/sdl/obj/Material.h:289
RGBAColor emissiveColor_
Holds the emissive color of this material.
Definition: scenedescription/sdl/obj/Material.h:195
void setTransmissionFilter(const RGBAColor &filter)
Sets the transmission filter of this material.
Definition: scenedescription/sdl/obj/Material.h:299
RGBAColor diffuseColor_
Holds the diffuse color of this material.
Definition: scenedescription/sdl/obj/Material.h:192
void setTransparency(const float transparency)
Sets the transparency value of this material with range [0.0, 1.0].
Definition: scenedescription/sdl/obj/Material.h:294
void setDiffuseColor(const RGBAColor &color)
Sets the diffuse color of this material.
Definition: scenedescription/sdl/obj/Material.h:279
const RGBAColor & emissiveColor() const
Returns the emissive color of this material.
Definition: scenedescription/sdl/obj/Material.h:234
std::string name_
Holds the name of this material.
Definition: scenedescription/sdl/obj/Material.h:186
Rendering::AttributeSetRef attributeSet(const Rendering::EngineRef &engine, const SDLScene &scene)
Returns the attribute set of this material.
const RGBAColor & ambientColor() const
Returns the ambient color of this material.
Definition: scenedescription/sdl/obj/Material.h:224
float transparency() const
Returns the transparency of this material with range [0.0, 1.0] 0 means fully opaque,...
Definition: scenedescription/sdl/obj/Material.h:244
unsigned int IlluminationModel
Definition of illumination models.
Definition: scenedescription/sdl/obj/Material.h:44
void setSpecularExponent(const Scalar exponent)
Sets the specular exponent of this material.
Definition: scenedescription/sdl/obj/Material.h:309
IlluminationModel illuminationModel() const
Returns the illumination model of this material.
Definition: scenedescription/sdl/obj/Material.h:254
const std::string & textureName() const
Returns the texture name of this material.
Definition: scenedescription/sdl/obj/Material.h:264
Scalar specularExponent_
Holds the specular exponent of this material.
Definition: scenedescription/sdl/obj/Material.h:210
Material()=default
Creates a new material object with default values.
float transparency_
Holds the transparency value of this material with range [0 (opaque), 1 (transparent)].
Definition: scenedescription/sdl/obj/Material.h:201
std::string textureName_
Holds the texture name of this material.
Definition: scenedescription/sdl/obj/Material.h:213
void setAmbientColor(const RGBAColor &color)
Sets the ambient color of this material.
Definition: scenedescription/sdl/obj/Material.h:274
const RGBAColor & specularColor() const
Returns the specular color of this material.
Definition: scenedescription/sdl/obj/Material.h:239
void setIlluminationModel(const IlluminationModel model)
Sets the illumination model of this material.
Definition: scenedescription/sdl/obj/Material.h:304
RGBAColor transmissionFilter_
Holds the transmission filter of this material.
Definition: scenedescription/sdl/obj/Material.h:204
void setTextureName(const std::string &name)
Sets the texture name of this material.
Definition: scenedescription/sdl/obj/Material.h:314
Scalar specularExponent() const
Returns the specular exponent of this material.
Definition: scenedescription/sdl/obj/Material.h:259
const RGBAColor & transmissionFilter() const
Returns the transmission filter of this material.
Definition: scenedescription/sdl/obj/Material.h:249
RGBAColor specularColor_
Holds the specular color of this material.
Definition: scenedescription/sdl/obj/Material.h:198
RGBAColor ambientColor_
Holds the ambient color of this material.
Definition: scenedescription/sdl/obj/Material.h:189
void setName(const std::string &name)
Sets the name of this material.
Definition: scenedescription/sdl/obj/Material.h:269
IlluminationModel iIlluminationModel_
Holds the illumination model of this material, a diffuse illumination model by default.
Definition: scenedescription/sdl/obj/Material.h:207
const std::string & name() const
Returns the name of this material.
Definition: scenedescription/sdl/obj/Material.h:219
const RGBAColor & diffuseColor() const
Returns the diffuse color of this material.
Definition: scenedescription/sdl/obj/Material.h:229
Rendering::AttributeSetRef attributeSet_
Rendering attribute set.
Definition: scenedescription/sdl/obj/Material.h:216
This class implements the base class for all sdl scene object providing access to all elements of a s...
Definition: SDLScene.h:39
float Scalar
Definition of a scalar type.
Definition: Math.h:128
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15