Blue Brain BioExplorer
Material.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2024, EPFL/Blue Brain Project
3  *
4  * The Blue Brain BioExplorer is a tool for scientists to extract and analyse
5  * scientific data from visualization
6  *
7  * This file is part of Blue Brain BioExplorer <https://github.com/BlueBrain/BioExplorer>
8  *
9  * This library is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU Lesser General Public License version 3.0 as published
11  * by the Free Software Foundation.
12  *
13  * This library is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #pragma once
24 
31 
32 SERIALIZATION_ACCESS(Material)
33 
34 namespace core
35 {
36 typedef std::map<TextureType, Texture2DPtr> TextureDescriptors;
37 
46 class Material : public PropertyObject
47 {
48 public:
52  PLATFORM_API virtual void commit() = 0;
53 
58  PLATFORM_API Material(const PropertyMap& properties = {});
59 
63  PLATFORM_API const std::string& getName() const { return _name; }
64 
69  PLATFORM_API void setName(const std::string& value) { _updateValue(_name, value); }
70 
80 
86 
91 
95  PLATFORM_API void setSpecularExponent(const double value) { _updateValue(_specularExponent, value); }
101 
106  PLATFORM_API void setReflectionIndex(const double value) { _updateValue(_reflectionIndex, value); }
111 
116  PLATFORM_API void setOpacity(const double value) { _updateValue(_opacity, value); }
120  PLATFORM_API double getOpacity() const { return _opacity; }
121 
126  PLATFORM_API void setRefractionIndex(const double value) { _updateValue(_refractionIndex, value); }
131 
136  PLATFORM_API void setEmission(double value) { _updateValue(_emission, value); }
140  PLATFORM_API double getEmission() const { return _emission; }
141 
146  PLATFORM_API void setGlossiness(const double value) { _updateValue(_glossiness, value); }
150  PLATFORM_API double getGlossiness() const { return _glossiness; }
151 
161 
166  PLATFORM_API void setUserParameter(const double value) { _updateValue(_userParameter, value); }
170  PLATFORM_API double getUserParameter() const { return _userParameter; }
171 
176  PLATFORM_API void setCastUserData(const bool value) { _updateValue(_castUserData, value); }
180  PLATFORM_API double getCastUserData() const { return _castUserData; }
181 
191 
201 
206  PLATFORM_API void setNodeId(const int32_t value) { _updateValue(_nodeId, value); }
210  PLATFORM_API int32_t getNodeId() const { return _nodeId; }
211 
216 
220  PLATFORM_API void setTexture(const std::string& fileName, const TextureType type);
221 
225  PLATFORM_API void removeTexture(const TextureType type);
226 
233 
239  PLATFORM_API bool hasTexture(const TextureType type) const { return _textureDescriptors.count(type) > 0; }
240 
245 
246 protected:
253  bool _loadTexture(const std::string& fileName, const TextureType type);
254 
255  std::string _name{"undefined"}; // The name of the material.
256  Vector3d _diffuseColor{1., 1., 1.}; // The color of the diffuse component of the material.
257  Vector3d _specularColor{1., 1., 1.}; // The color of the specular component of the material.
258  double _specularExponent{10.}; // The specular exponent of the material.
259  double _reflectionIndex{0.}; // The reflection index of the material.
260  double _opacity{1.}; // The opacity of the material.
261  double _refractionIndex{1.}; // The refraction index of the material.
262  double _emission{0.}; // The emission of the material.
263  double _glossiness{1.}; // The glossiness of the material.
264  TexturesMap _textures; // The textures of the material.
265  TextureDescriptors _textureDescriptors; // The texture descriptors of the material.
266  double _userParameter{1.}; // The user parameter of the material.
268  bool _castUserData{false}; // The cast user data of the material
270  int32_t _nodeId; // ID attached to the material
272  // material
273 
275 };
276 } // namespace core
#define PLATFORM_API
Definition: Api.h:37
#define SERIALIZATION_FRIEND(type)
Definition: Macros.h:32
#define SERIALIZATION_ACCESS(type)
Definition: Macros.h:25
void _updateValue(T &member, const T &newValue, const bool triggerCallback=true)
Definition: BaseObject.h:87
The class that represents the material object. This class is derived from PropertyObject and provides...
Definition: Material.h:47
PLATFORM_API void setChameleonMode(const MaterialChameleonMode value)
Sets the chameleon mode of the material.
Definition: Material.h:196
TextureDescriptors _textureDescriptors
Definition: Material.h:265
MaterialClippingMode _clippingMode
Definition: Material.h:269
PLATFORM_API void setRefractionIndex(const double value)
Sets the refraction index of the material.
Definition: Material.h:126
Vector3d _diffuseColor
Definition: Material.h:256
virtual PLATFORM_API void commit()=0
Called after material change.
PLATFORM_API MaterialClippingMode getClippingMode() const
Returns the clipping mode of the material.
Definition: Material.h:190
MaterialShadingMode _shadingMode
Definition: Material.h:267
PLATFORM_API void setNodeId(const int32_t value)
Sets the cast user data of the material.
Definition: Material.h:206
PLATFORM_API const Vector3d & getDiffuseColor() const
Returns the color of the diffuse component of the material.
Definition: Material.h:79
PLATFORM_API double getCastUserData() const
Returns the cast user data of the material.
Definition: Material.h:180
PLATFORM_API double getEmission() const
Returns the emission of the material.
Definition: Material.h:140
PLATFORM_API double getSpecularExponent() const
Returns the specular exponent of the material.
Definition: Material.h:100
PLATFORM_API double getReflectionIndex() const
Returns the reflection index of the material.
Definition: Material.h:110
PLATFORM_API void removeTexture(const TextureType type)
Removes the texture of the material for the specified texture type.
Definition: Material.cpp:79
bool _castUserData
Definition: Material.h:268
PLATFORM_API void setOpacity(const double value)
Sets the opacity of the material.
Definition: Material.h:116
PLATFORM_API bool hasTexture(const TextureType type) const
Checks if the material has a texture for the specified texture type.
Definition: Material.h:239
bool _loadTexture(const std::string &fileName, const TextureType type)
Loads the texture for the specified texture type.
Definition: Material.cpp:51
PLATFORM_API void setEmission(double value)
Sets the emission of the material.
Definition: Material.h:136
PLATFORM_API MaterialChameleonMode getChameleonMode() const
Returns the chameleon mode of the material.
Definition: Material.h:200
PLATFORM_API void setCastUserData(const bool value)
Sets the cast user data of the material.
Definition: Material.h:176
PLATFORM_API const Vector3d & getSpecularColor() const
Returns the color of the specular component of the material.
Definition: Material.h:90
MaterialChameleonMode _chameleonMode
Definition: Material.h:271
PLATFORM_API double getOpacity() const
Returns the opacity of the material.
Definition: Material.h:120
PLATFORM_API void setClippingMode(const MaterialClippingMode value)
Sets the clipping mode of the material.
Definition: Material.h:186
PLATFORM_API void setGlossiness(const double value)
Sets the glossiness of the material.
Definition: Material.h:146
PLATFORM_API int32_t getNodeId() const
Returns the cast user data of the material.
Definition: Material.h:210
PLATFORM_API void setTexture(const std::string &fileName, const TextureType type)
Sets the texture of the material for the specified texture type.
Definition: Material.cpp:66
double _userParameter
Definition: Material.h:266
PLATFORM_API Texture2DPtr getTexture(const TextureType type) const
Returns the texture of the material for the specified texture type.
Definition: Material.cpp:37
PLATFORM_API void setUserParameter(const double value)
Sets the user parameter of the material.
Definition: Material.h:166
double _refractionIndex
Definition: Material.h:261
double _opacity
Definition: Material.h:260
PLATFORM_API const TextureDescriptors & getTextureDescriptors() const
Returns the texture descriptors of the material.
Definition: Material.h:215
double _specularExponent
Definition: Material.h:258
PLATFORM_API void setReflectionIndex(const double value)
Sets the reflection index of the material.
Definition: Material.h:106
double _glossiness
Definition: Material.h:263
PLATFORM_API void clearTextures()
Clears all textures from the material object.
Definition: Material.cpp:45
PLATFORM_API double getRefractionIndex() const
Returns the refraction index of the material.
Definition: Material.h:130
double _emission
Definition: Material.h:262
PLATFORM_API void setSpecularExponent(const double value)
Sets the specular exponent of the material.
Definition: Material.h:95
TexturesMap _textures
Definition: Material.h:264
PLATFORM_API void setName(const std::string &value)
Sets the name of the material.
Definition: Material.h:69
int32_t _nodeId
Definition: Material.h:270
PLATFORM_API void setShadingMode(const MaterialShadingMode value)
Sets the shading mode of the material.
Definition: Material.h:156
PLATFORM_API void setSpecularColor(const Vector3d &value)
Sets the color of the specular component of the material.
Definition: Material.h:85
std::string _name
Definition: Material.h:255
Vector3d _specularColor
Definition: Material.h:257
PLATFORM_API MaterialShadingMode getShadingMode() const
Returns the shading mode of the material.
Definition: Material.h:160
PLATFORM_API Material(const PropertyMap &properties={})
Constructs a Material object.
Definition: Material.cpp:31
PLATFORM_API const std::string & getName() const
Returns the name of the material.
Definition: Material.h:63
PLATFORM_API double getUserParameter() const
Returns the user parameter of the material.
Definition: Material.h:170
PLATFORM_API double getGlossiness() const
Returns the glossiness of the material.
Definition: Material.h:150
double _reflectionIndex
Definition: Material.h:259
PLATFORM_API void setDiffuseColor(const Vector3d &value)
Sets the color of the diffuse component of the material.
Definition: Material.h:75
std::map< std::string, Texture2DPtr > TexturesMap
Definition: Types.h:160
std::map< TextureType, Texture2DPtr > TextureDescriptors
Definition: Material.h:36
std::shared_ptr< Texture2D > Texture2DPtr
Definition: Types.h:159
glm::vec< 3, double > Vector3d
Definition: MathTypes.h:143
TextureType
Definition: Types.h:244
MaterialChameleonMode
Definition: CommonTypes.h:59
@ undefined_chameleon_mode
Definition: CommonTypes.h:60
MaterialShadingMode
Definition: CommonTypes.h:44
@ undefined_shading_mode
Definition: CommonTypes.h:45
MaterialClippingMode
Definition: CommonTypes.h:37
@ no_clipping
Definition: CommonTypes.h:38