Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
SoMaterialElement.h
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2024 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Modified by : VSG (MMM YYYY)
22**=======================================================================*/
23
24
25#ifndef _SO_MATERIAL_ELEMENT
26#define _SO_MATERIAL_ELEMENT
27
28#include <Inventor/SbBasic.h>
29#include <Inventor/SbColor.h>
30#include <Inventor/elements/SoReplacedElement.h>
31#include <Inventor/elements/SoSubElement.h>
32#include <Inventor/devices/SoCpuBufferObject.h>
33#include <math.h>
34
35class SoMFFloat;
36class SoMFColor;
37class SbThreadMutex;
38
53SoEXTENDER_Documented class SoMaterialElement : public SoReplacedElement {
54 SO_ELEMENT_HEADER(SoMaterialElement);
55
56 public:
57
59 enum masks {
63 DIFFUSE_MASK = 1 << 2,
65 AMBIENT_MASK = 1 << 3,
67 EMISSIVE_MASK = 1 << 4,
69 SPECULAR_MASK = 1 << 5,
75 ALL_MASK = 0xFFFF,
76 };
77
84 static void setDiffuse(SoState *state,
85 SoNode *node,
86 int32_t numColors,
87 const SbColor *colors);
94 static void setTransparency(SoState *state,
95 SoNode *node,
96 int32_t numTransp,
97 const float *transp);
98
102 static void setPacked(SoState *state,
103 SoNode *node,
104 int32_t numColors,
105 const uint32_t *colors);
106
113 static void setColorIndices(SoState *state,
114 SoNode *node,
115 int32_t numIndices,
116 const int32_t *indices);
117
118 static void setAmbient(SoState *state, SoNode* node, const SbColor &color);
119 static void setEmissive(SoState *state, SoNode* node, const SbColor &color);
120 static void setSpecular(SoState *state, SoNode* node, const SbColor &color);
121
122 static void setShininess(SoState *state, SoNode* node, float value);
123 static void setColorMaterial(SoState *state, SoNode* node, SbBool value);
124
125 // Physically based parameters
126 static void setSpecularFactor(SoState* state, SoNode* node, float value);
127 static void setRoughness(SoState* state, SoNode* node, float value);
128 static void setMetallic(SoState* state, SoNode* node, float value);
129
134 static SbColor getDiffuse(SoState *state, int index);
140 static float getTransparency(SoState *, int index);
141
144
149 static const int32_t *getColorIndices(SoState *state);
150 static int32_t getColorIndex(SoState *, int num);
151 static const SbColor &getAmbient(SoState *);
152 static const SbColor &getEmissive(SoState *);
153 static const SbColor &getSpecular(SoState *);
154 static float getShininess(SoState *);
156
157 // Physically based parameters
158 static float getSpecularFactor(SoState* state);
159 static float getRoughness(SoState* state);
160 static float getMetallic(SoState* state);
161
165 static size_t getNumDiffuse(SoState* state);
166
170 static size_t getNumColorIndices(SoState* state);
171
175 int32_t getNumDiffuse() const {
176 return m_materialProperties.numDiffuseColors;
177 }
181 static int32_t getNumTransparencies( SoState* state );
182
186 int32_t getNumColorIndices() const {
187 return (m_materialProperties.colorIndices ? m_materialProperties.numDiffuseColors : 0);
188 }
189
193 static bool isTransparent( SoState* state );
194
199 return 0.2F;
200 }
201
206 return SbColor(0.8F, 0.8F, 0.8F);
207 }
212 return SbColor(0.2F, 0.2F, 0.2F);
213 }
218 return SbColor(0.0F, 0.0F, 0.0F);
219 }
224 return SbColor(0.0F, 0.0F, 0.0F);
225 }
229 static float getDefaultShininess() {
230 return 0.2F;
231 }
232
233 // Physically based parameters
234
236 {
237 return 0.0f;
238 }
239
240 static float getDefaultRoughness()
241 {
242 return 0.8f;
243 }
244
245 static float getDefaultMetallic()
246 {
247 return 0.0f;
248 }
249
253 static float getDefaultTransparency() {
254 return 0.0F;
255 }
259 static int32_t getDefaultColorIndex() {
260 return 1;
261 }
262
264 virtual void push(SoState *state);
266 virtual void pop( SoState* state, const SoElement* prevTopElement );
267
268private:
269
271 virtual void commonInit();
272
274 virtual void init(SoState *state);
275
282 virtual SbBool matches(const SoElement *) const;
283
289 virtual SoElement* copyMatchInfo() const;
290
291 private:
292
293 // set method for use in SoMaterial nodes:
294 static void setMaterials(SoState *state,
295 SoNode *node,
296 uint32_t bitmask,
297 const SoMFColor &diffuse,
298 const SoMFFloat &transp,
299 const SoMFColor &ambient,
300 const SoMFColor &emissive,
301 const SoMFColor &specular,
302 const SoMFFloat &shininess);
303
304 // Prints element (for debugging)
305 virtual void print(FILE *fp) const;
306
307 // Initializes the SoMaterialElement class
308 static void initClass();
309 static void exitClass();
310
311 static const SbColor* getDiffusePointer( SoState* state );
312 const SbColor* getDiffusePointer() const;
313
314 static const int32_t* getColorIndexPointer( SoState* state );
315 static const float* getTransparencyPointer( SoState* state );
316 const float* getTransparencyPointer() const;
317
318 static void setHasTransparency( SoState* state, SoNode* node, int hasTransparency );
319
320 static const SoMaterialElement* getInstance( SoState* state );
321
322 const SbColor& getAmbient() const;
323 const SbColor& getEmissive() const;
324 const SbColor& getSpecular() const;
325 float getShininess() const;
326
327 // Physically based parameters
328 float getSpecularFactor() const;
329 float getRoughness() const;
330 float getMetallic() const;
331
332 int32_t getNumTransparencies() const;
333 bool isTransparent() const;
335 bool isPacked() const
336 {
337 return m_materialProperties.packedColors.ptr() != nullptr;
338 }
339
340private:
341 //Struct to hold material parameters
342 struct Material
343 {
344 public:
345 Material()
346 {
347 //The memset ensure that we are also clearing the possible padding
348 //which is needed when doing memcmp in match method
349 memset(this, 0, sizeof(Material));
350 dirtyPackedColor = true;
351 packedColorExplicitelySet = false;
352 }
353 const SbColor *diffuseColors;
354 SoRef<SoCpuBufferObject> packedColors;
355 const float *transparencies;
356 const int32_t *colorIndices;
357
358 SbColor ambientColor;
359 SbColor emissiveColor;
360 SbColor specularColor;
361 float shininess;
362 int32_t colorMaterial;
363
364 // Physically based parameters
365 float specularFactor;
366 float roughness;
367 float metallic;
368
369 int32_t numDiffuseColors;
370 int32_t numTransparencies;
371
372 //True if we need to recreate the packed color buffer
373 bool dirtyPackedColor : 1;
374
375 bool packedColorExplicitelySet : 1;
376 };
377 Material m_materialProperties;
378
379 virtual ~SoMaterialElement();
380
381 // store the default color, transp so that we can set
382 // point to them if no other color or transp has been set.
383 static SbColor defaultDiffuseColor;
384 static float defaultTransparency;
385 static int32_t defaultColorIndices;
386 static SoCpuBufferObject* s_defaultPackedColorBuffer;
387
388 // -1 = don't know yet, 0 = no transp, 1 = has transp
389 int m_hasTransparency;
390
391 private:
396 static SoMaterialElement* getWInstance( SoState* state, SoNode* node = nullptr );
397
399 SoCpuBufferObject* packDiffuseColors();
400
401 void setDiffuseElt(int32_t numColors, const SbColor *colors);
402 void setColorIndexElt(int32_t numIndices, const int32_t *indices);
403 void setTranspElt(int32_t numTrans, const float *trans);
404 void setAmbientElt(const SbColor *color);
405 void setEmissiveElt(const SbColor *color);
406 void setSpecularElt(const SbColor *color);
407 void setShininessElt(float value);
408 void setColorMaterialElt(SbBool value);
409 void setMaterialElt(uint32_t bitmask, const SoMFColor &, const SoMFFloat &,
410 const SoMFColor &, const SoMFColor &, const SoMFColor &,
411 const SoMFFloat &);
412
413 // Physically based parameters
414 void setSpecularFactorElt(float value);
415 void setRoughnessElt(float value);
416 void setMetallicElt(float value);
417
418 static const float S_SHINY_THRESHOLD;
419};
420
421#endif /* _SO_MATERIAL_ELEMENT */
422
Color vector class.
Definition SbColor.h:82
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable mutex c...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> CPU buffer objec...
Abstract base class for all state elements.
Definition SoElement.h:102
Multiple-value field containing any number of RGB colors stored as three floats.
Definition SoMFColor.h:98
Multiple-value field containing any number of floating point values.
Definition SoMFFloat.h:90
Store in the state the material properties set by some property nodes.
static SbColor getDefaultEmissive()
Specify Open Inventor defaults for colors, etc.
static size_t getNumDiffuse(SoState *state)
Return number of diffuse colors.
static float getDefaultSpecularFactor()
static float getRoughness(SoState *state)
static float getDefaultRoughness()
static void setColorMaterial(SoState *state, SoNode *node, SbBool value)
static SbColor getDefaultDiffuse()
Specify Open Inventor defaults for colors, etc.
static void setAmbient(SoState *state, SoNode *node, const SbColor &color)
static size_t getNumColorIndices(SoState *state)
Method to inquire about current colors.
virtual void pop(SoState *state, const SoElement *prevTopElement)
Unref buffer object of the popped element.
static int32_t getColorIndex(SoState *, int num)
static bool isTransparent(SoState *state)
Method to inquire about current colors.
static void setSpecularFactor(SoState *state, SoNode *node, float value)
static SoCpuBufferObject * getPackedColors(SoState *state)
Return packed colors if any.
static SbColor getDefaultSpecular()
Specify Open Inventor defaults for colors, etc.
static const SbColor & getAmbient(SoState *)
static float getMetallic(SoState *state)
static float getDefaultMetallic()
static void setDiffuse(SoState *state, SoNode *node, int32_t numColors, const SbColor *colors)
Static set method.
static void setEmissive(SoState *state, SoNode *node, const SbColor &color)
static float getDefaultShininess()
Specify Open Inventor defaults for colors, etc.
static SbColor getDefaultAmbient()
Specify Open Inventor defaults for colors, etc.
static SbColor getDiffuse(SoState *state, int index)
get() methods get value from Inventor state.
static void setPacked(SoState *state, SoNode *node, int32_t numColors, const uint32_t *colors)
static void setTransparency(SoState *state, SoNode *node, int32_t numTransp, const float *transp)
Static set method.
int32_t getNumColorIndices() const
Method to inquire about current colors.
static float getDefaultTransparency()
Specify Open Inventor defaults for colors, etc.
@ DIFFUSE_MASK
Diffuse mask.
@ AMBIENT_MASK
Ambient mask.
@ EMISSIVE_MASK
Emissive mask.
@ SPECULAR_MASK
Specular mask.
@ TRANSPARENCY_MASK
Transparency mask.
@ COLOR_MATERIAL_MASK
Color mask.
@ SHININESS_MASK
Shininess mask.
static float getTransparency(SoState *, int index)
get() methods get value from Inventor state.
static SbBool getColorMaterial(SoState *)
static const int32_t * getColorIndices(SoState *state)
virtual void push(SoState *state)
Copy current material into the pushed element.
static const SbColor & getEmissive(SoState *)
static float getSpecularFactor(SoState *state)
static void setColorIndices(SoState *state, SoNode *node, int32_t numIndices, const int32_t *indices)
Static set method.
static void setShininess(SoState *state, SoNode *node, float value)
static int32_t getDefaultColorIndex()
Specify Open Inventor defaults for colors, etc.
int32_t getNumDiffuse() const
Method to inquire about current colors.
static const SbColor & getSpecular(SoState *)
static int32_t getNumTransparencies(SoState *state)
Method to inquire about current colors.
static void setRoughness(SoState *state, SoNode *node, float value)
static float getDefaultAmbientIntensity()
Specify Open Inventor defaults for colors, etc.
static void setSpecular(SoState *state, SoNode *node, const SbColor &color)
static void setMetallic(SoState *state, SoNode *node, float value)
static float getShininess(SoState *)
Abstract base class for all database nodes.
Definition SoNode.h:145
Smart pointer for any class inheriting SoRefCounter.
Definition SoRef.h:90
Abstract base class for each state element whose value is replaced whenever it is set.
Traversal state.
Definition SoState.h:74
int SbBool
Boolean type.
Definition SbBase.h:87