1 // Created by: NW,JPB,CAL
2 // Copyright (c) 1991-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _Graphic3d_MaterialAspect_HeaderFile
17 #define _Graphic3d_MaterialAspect_HeaderFile
19 #include <Standard.hxx>
20 #include <Standard_DefineAlloc.hxx>
21 #include <Standard_Handle.hxx>
23 #include <Standard_ShortReal.hxx>
24 #include <Quantity_Color.hxx>
25 #include <Standard_Boolean.hxx>
26 #include <Graphic3d_BSDF.hxx>
27 #include <Graphic3d_TypeOfMaterial.hxx>
28 #include <Graphic3d_NameOfMaterial.hxx>
29 #include <TCollection_AsciiString.hxx>
30 #include <Standard_Real.hxx>
31 #include <Graphic3d_TypeOfReflection.hxx>
32 #include <Standard_CString.hxx>
33 #include <Standard_Integer.hxx>
34 class Graphic3d_MaterialDefinitionError;
35 class Standard_OutOfRange;
39 //! This class allows the definition of the type of a surface.
40 //! Aspect attributes of a 3d face.
41 //! Keywords: Material, FillArea, Shininess, Ambient, Color, Diffuse,
42 //! Specular, Transparency, Emissive, ReflectionMode,
43 //! BackFace, FrontFace, Reflection, Absorbtion
44 class Graphic3d_MaterialAspect
51 //! Creates a material from default values.
52 Standard_EXPORT Graphic3d_MaterialAspect();
54 //! Creates a generic material calls <AName>
55 Standard_EXPORT Graphic3d_MaterialAspect(const Graphic3d_NameOfMaterial AName);
57 //! Increases or decreases the luminosity of <me>.
58 //! <ADelta> is a signed percentage.
59 Standard_EXPORT void IncreaseShine (const Standard_Real ADelta);
61 //! Modifies the reflection properties of the surface.
62 //! Category: Methods to modify the class definition
63 //! Warning: Raises MaterialDefinitionError if <AValue> is
64 //! a negative value or greater than 1.0.
65 Standard_EXPORT void SetAmbient (const Standard_Real AValue);
67 //! Modifies the reflection properties of the surface.
68 //! Category: Methods to modify the class definition
69 //! Warning: Raises MaterialDefinitionError if <AValue> is a
70 //! negative value or greater than 1.0.
71 Standard_EXPORT void SetDiffuse (const Standard_Real AValue);
73 //! Modifies the reflection properties of the surface.
74 //! Category: Methods to modify the class definition
75 //! Warning: Raises MaterialDefinitionError if <AValue> is a
76 //! negative value or greater than 1.0.
77 Standard_EXPORT void SetEmissive (const Standard_Real AValue);
79 //! Modifies the luminosity of the surface.
80 //! Category: Methods to modify the class definition
81 //! Warning: Raises MaterialDefinitionError if <AValue> is a
82 //! negative value or greater than 1.0.
83 Standard_EXPORT void SetShininess (const Standard_Real AValue);
85 //! Modifies the reflection properties of the surface.
86 //! Category: Methods to modify the class definition
87 //! Warning: Raises MaterialDefinitionError if <AValue> is a
88 //! negative value or greater than 1.0.
89 Standard_EXPORT void SetSpecular (const Standard_Real AValue);
91 //! Modifies the transparency coefficient of the surface.
92 //! <AValue> = 0. opaque. (default)
93 //! <AValue> = 1. transparent.
94 //! Transparency is applicable to materials that have at least
95 //! one of reflection modes (ambient, diffuse, specular or emissive)
96 //! enabled. See also SetReflectionModeOn() and SetReflectionModeOff() methods.
98 //! Category: Methods to modify the class definition
99 //! Warning: Raises MaterialDefinitionError if <AValue> is a
100 //! negative value or greater than 1.0.
101 Standard_EXPORT void SetTransparency (const Standard_Real AValue);
103 //! Modifies the refraction index of the material.
104 //! Category: Methods to modify the class definition
105 //! Warning: Raises MaterialDefinitionError if <theValue> is a
107 Standard_EXPORT void SetRefractionIndex (const Standard_Real theValue);
109 //! Modifies the BSDF (bidirectional scattering distribution function).
110 //! Category: Methods to modify the class definition
111 Standard_EXPORT void SetBSDF (const Graphic3d_BSDF& theBSDF);
113 //! Modifies the ambient and diffuse colour of the surface.
114 //! Category: Methods to modify the class definition
115 Standard_EXPORT void SetColor (const Quantity_Color& AColor);
117 //! Modifies the ambient colour of the surface.
118 Standard_EXPORT void SetAmbientColor (const Quantity_Color& AColor);
120 //! Modifies the difuse colour of the surface.
121 Standard_EXPORT void SetDiffuseColor (const Quantity_Color& AColor);
123 //! Modifies the specular colour of the surface.
124 Standard_EXPORT void SetSpecularColor (const Quantity_Color& AColor);
126 //! Modifies the emissive colour of the surface.
127 Standard_EXPORT void SetEmissiveColor (const Quantity_Color& AColor);
129 //! Activates the reflective properties of the surface <AType>.
131 //! TypeOfReflection : TOR_AMBIENT
135 //! 1, 2, 3 or 4 types of reflection can be set for a given surface.
136 Standard_EXPORT void SetReflectionModeOn (const Graphic3d_TypeOfReflection AType);
138 //! Deactivates the reflective properties of
139 //! the surface <AType>.
141 //! TypeOfReflection : TOR_AMBIENT
145 //! 1, 2, 3 or 4 types of reflection can be set off for a given surface.
146 //! Disabling diffuse and specular reflectance is useful for efficient visualization
147 //! of large amounts of data as definition of normals for graphic primitives is not needed
148 //! when only "all-directional" reflectance is active.
150 //! NOTE: Disabling all four reflection modes also turns off the following effects:
151 //! 1. Lighting. Colors of primitives are not affected by the material properties when lighting is off.
153 Standard_EXPORT void SetReflectionModeOff (const Graphic3d_TypeOfReflection AType);
155 //! Set MyMaterialType to the value of parameter <AType>
157 //! TypeOfMaterial : MATERIAL_ASPECT
159 Standard_EXPORT void SetMaterialType (const Graphic3d_TypeOfMaterial AType);
161 //! The current matarial become a "UserDefined" material.
162 //! Set the name of the "UserDefined" material.
163 Standard_EXPORT void SetMaterialName (const Standard_CString AName);
165 Standard_EXPORT void SetEnvReflexion (const Standard_ShortReal AValue);
167 //! Resets the material with the original values according to
168 //! the material name but leave the current color values untouched
169 //! for the material of type ASPECT.
170 Standard_EXPORT void Reset();
172 //! Returns the diffuse colour of the surface.
173 Standard_EXPORT const Quantity_Color& Color() const;
175 //! Returns the ambient colour of the surface.
176 Standard_EXPORT const Quantity_Color& AmbientColor() const;
178 //! Returns the diffuse colour of the surface.
179 Standard_EXPORT const Quantity_Color& DiffuseColor() const;
181 //! Returns the specular colour of the surface.
182 Standard_EXPORT const Quantity_Color& SpecularColor() const;
184 //! Returns the emissive colour of the surface.
185 Standard_EXPORT const Quantity_Color& EmissiveColor() const;
187 //! Returns the reflection properties of the surface.
188 Standard_EXPORT Standard_Real Ambient() const;
190 //! Returns the reflection properties of the surface.
191 Standard_EXPORT Standard_Real Diffuse() const;
193 //! Returns the reflection properties of the surface.
194 Standard_EXPORT Standard_Real Specular() const;
196 //! Returns the transparency coefficient of the surface.
197 Standard_EXPORT Standard_Real Transparency() const;
199 //! Returns the refraction index of the material
200 Standard_EXPORT Standard_Real RefractionIndex() const;
202 //! Returns BSDF (bidirectional scattering distribution function).
203 Standard_EXPORT const Graphic3d_BSDF& BSDF() const;
205 //! Returns the emissive coefficient of the surface.
206 Standard_EXPORT Standard_Real Emissive() const;
208 //! Returns the luminosity of the surface.
209 Standard_EXPORT Standard_Real Shininess() const;
211 //! Returns Standard_True if the reflection mode is active,
212 //! Standard_False otherwise.
213 Standard_EXPORT Standard_Boolean ReflectionMode (const Graphic3d_TypeOfReflection AType) const;
215 //! Returns Standard_True if MyMaterialType equal the parameter AType,
216 //! Standard_False otherwise.
217 Standard_EXPORT Standard_Boolean MaterialType (const Graphic3d_TypeOfMaterial AType) const;
219 Standard_EXPORT Standard_ShortReal EnvReflexion() const;
221 //! Returns the material name.
222 Standard_EXPORT Graphic3d_NameOfMaterial Name() const;
224 //! Returns Standard_True if the materials <me> and
225 //! <Other> are different.
226 Standard_EXPORT Standard_Boolean IsDifferent (const Graphic3d_MaterialAspect& Other) const;
227 Standard_Boolean operator != (const Graphic3d_MaterialAspect& Other) const
229 return IsDifferent(Other);
232 //! Returns Standard_True if the materials <me> and
233 //! <Other> are identical.
234 Standard_EXPORT Standard_Boolean IsEqual (const Graphic3d_MaterialAspect& Other) const;
235 Standard_Boolean operator == (const Graphic3d_MaterialAspect& Other) const
237 return IsEqual(Other);
241 //! Returns the number of predefined textures.
242 Standard_EXPORT static Standard_Integer NumberOfMaterials();
245 //! Returns the name of the predefined material of rank <aRank>
246 //! Trigger: when <aRank> is < 1 or > NumberOfMaterials.
247 Standard_EXPORT static Standard_CString MaterialName (const Standard_Integer aRank);
250 //! Returns the name of this material
251 Standard_EXPORT Standard_CString MaterialName() const;
254 //! Returns the type of the predefined material of rank <aRank>
255 //! Trigger: when <aRank> is < 1 or > NumberOfMaterials.
256 Standard_EXPORT static Graphic3d_TypeOfMaterial MaterialType (const Standard_Integer aRank);
259 //! Returns the material for specified name or Graphic3d_NOM_DEFAULT if name is unknown.
260 Standard_EXPORT static Graphic3d_NameOfMaterial MaterialFromName (const Standard_CString theName);
274 Standard_EXPORT void Init (const Graphic3d_NameOfMaterial AName);
277 Standard_ShortReal myDiffuseCoef;
278 Quantity_Color myDiffuseColor;
279 Standard_Boolean myDiffuseActivity;
280 Standard_ShortReal myAmbientCoef;
281 Quantity_Color myAmbientColor;
282 Standard_Boolean myAmbientActivity;
283 Standard_ShortReal mySpecularCoef;
284 Quantity_Color mySpecularColor;
285 Standard_Boolean mySpecularActivity;
286 Standard_ShortReal myEmissiveCoef;
287 Quantity_Color myEmissiveColor;
288 Standard_Boolean myEmissiveActivity;
289 Standard_ShortReal myTransparencyCoef;
290 Standard_ShortReal myRefractionIndex;
291 Graphic3d_BSDF myBSDF;
292 Standard_ShortReal myShininess;
293 Standard_ShortReal myEnvReflexion;
294 Graphic3d_TypeOfMaterial myMaterialType;
295 Graphic3d_NameOfMaterial myMaterialName;
296 Graphic3d_NameOfMaterial myRequestedMaterialName;
297 TCollection_AsciiString myStringName;
308 #endif // _Graphic3d_MaterialAspect_HeaderFile