Open Inventor Release 2023.2.3
 
Loading...
Searching...
No Matches
SoMaterialElement.h
Go to the documentation of this file.
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-2020 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>
33#include <math.h>
34
35class SoMFFloat;
36class SoMFColor;
37class SbThreadMutex;
38
65
66 public:
67
69 enum masks {
73 DIFFUSE_MASK = 1 << 2,
75 AMBIENT_MASK = 1 << 3,
77 EMISSIVE_MASK = 1 << 4,
79 SPECULAR_MASK = 1 << 5,
85 ALL_MASK = 0xFFFF,
86 };
87
94 static void setDiffuse(SoState *state,
95 SoNode *node,
96 int32_t numColors,
97 const SbColor *colors);
104 static void setTransparency(SoState *state,
105 SoNode *node,
106 int32_t numTransp,
107 const float *transp);
108
112 static void setPacked(SoState *state,
113 SoNode *node,
114 int32_t numColors,
115 const uint32_t *colors);
116
123 static void setColorIndices(SoState *state,
124 SoNode *node,
125 int32_t numIndices,
126 const int32_t *indices);
127
128 static void setAmbient(SoState *state, SoNode* node, const SbColor &color);
129 static void setEmissive(SoState *state, SoNode* node, const SbColor &color);
130 static void setSpecular(SoState *state, SoNode* node, const SbColor &color);
131
132 static void setShininess(SoState *state, SoNode* node, float value);
133 static void setColorMaterial(SoState *state, SoNode* node, SbBool value);
138 static SbColor getDiffuse(SoState *state, int index);
144 static float getTransparency(SoState *, int index);
145
148
153 static const int32_t *getColorIndices(SoState *state);
154 static int32_t getColorIndex(SoState *, int num);
155 static const SbColor &getAmbient(SoState *);
156 static const SbColor &getEmissive(SoState *);
157 static const SbColor &getSpecular(SoState *);
158 static float getShininess(SoState *);
160
164 static size_t getNumDiffuse(SoState* state);
165
169 static size_t getNumColorIndices(SoState* state);
170
174 int32_t getNumDiffuse() const {
175 return m_materialProperties.numDiffuseColors;
176 }
180 static int32_t getNumTransparencies( SoState* state );
181
185 int32_t getNumColorIndices() const {
186 return (m_materialProperties.colorIndices ? m_materialProperties.numDiffuseColors : 0);
187 }
188
192 static bool isTransparent( SoState* state );
193
198 return 0.2F;
199 }
200
205 return SbColor(0.8F, 0.8F, 0.8F);
206 }
211 return SbColor(0.2F, 0.2F, 0.2F);
212 }
217 return SbColor(0.0F, 0.0F, 0.0F);
218 }
223 return SbColor(0.0F, 0.0F, 0.0F);
224 }
228 static float getDefaultShininess() {
229 return 0.2F;
230 }
234 static float getDefaultTransparency() {
235 return 0.0F;
236 }
240 static int32_t getDefaultColorIndex() {
241 return 1;
242 }
243
245 virtual void push(SoState *state);
247 virtual void pop( SoState* state, const SoElement* prevTopElement );
248
249private:
250
252 virtual void commonInit();
253
255 virtual void init(SoState *state);
256
263 virtual SbBool matches(const SoElement *) const;
264
270 virtual SoElement* copyMatchInfo() const;
271
272 private:
273
274 // set method for use in SoMaterial nodes:
275 static void setMaterials(SoState *state,
276 SoNode *node,
277 uint32_t bitmask,
278 const SoMFColor &diffuse,
279 const SoMFFloat &transp,
280 const SoMFColor &ambient,
281 const SoMFColor &emissive,
282 const SoMFColor &specular,
283 const SoMFFloat &shininess);
284
285 // Prints element (for debugging)
286 virtual void print(FILE *fp) const;
287
288 // Initializes the SoMaterialElement class
289 static void initClass();
290 static void exitClass();
291
292 static const SbColor* getDiffusePointer( SoState* state );
293 const SbColor* getDiffusePointer() const;
294
295 static const int32_t* getColorIndexPointer( SoState* state );
296 static const float* getTransparencyPointer( SoState* state );
297 const float* getTransparencyPointer() const;
298
299 static void setHasTransparency( SoState* state, SoNode* node, int hasTransparency );
300
301 static const SoMaterialElement* getInstance( SoState* state );
302
303 const SbColor& getAmbient() const;
304 const SbColor& getEmissive() const;
305 const SbColor& getSpecular() const;
306 float getShininess() const;
307 int32_t getNumTransparencies() const;
308 bool isTransparent() const;
310 bool isPacked() const
311 {
312 return m_materialProperties.packedColors.ptr() != nullptr;
313 }
314
315private:
316 //Struct to hold material parameters
317 struct Material
318 {
319 public:
320 Material()
321 {
322 //The memset ensure that we are also clearing the possible padding
323 //which is needed when doing memcmp in match method
324 memset(this, 0, sizeof(Material));
325 dirtyPackedColor = true;
326 packedColorExplicitelySet = false;
327 }
328 const SbColor *diffuseColors;
329 SoRef<SoCpuBufferObject> packedColors;
330 const float *transparencies;
331 const int32_t *colorIndices;
332
333 SbColor ambientColor;
334 SbColor emissiveColor;
335 SbColor specularColor;
336 float shininess;
337 int32_t colorMaterial;
338
339 int32_t numDiffuseColors;
340 int32_t numTransparencies;
341
342 //True if we need to recreate the packed color buffer
343 bool dirtyPackedColor : 1;
344
345 bool packedColorExplicitelySet : 1;
346 };
347 Material m_materialProperties;
348
349 virtual ~SoMaterialElement();
350
351 // store the default color, transp so that we can set
352 // point to them if no other color or transp has been set.
353 static SbColor defaultDiffuseColor;
354 static float defaultTransparency;
355 static int32_t defaultColorIndices;
356 static SoCpuBufferObject* s_defaultPackedColorBuffer;
357
358 // -1 = don't know yet, 0 = no transp, 1 = has transp
359 int m_hasTransparency;
360
361 private:
366 static SoMaterialElement* getWInstance( SoState* state, SoNode* node = nullptr );
367
369 SoCpuBufferObject* packDiffuseColors();
370
371 void setDiffuseElt(int32_t numColors, const SbColor *colors);
372 void setColorIndexElt(int32_t numIndices, const int32_t *indices);
373 void setTranspElt(int32_t numTrans, const float *trans);
374 void setAmbientElt(const SbColor *color);
375 void setEmissiveElt(const SbColor *color);
376 void setSpecularElt(const SbColor *color);
377 void setShininessElt(float value);
378 void setColorMaterialElt(SbBool value);
379 void setMaterialElt(uint32_t bitmask, const SoMFColor &, const SoMFFloat &,
380 const SoMFColor &, const SoMFColor &, const SoMFColor &,
381 const SoMFFloat &);
382
383 static const float S_SHINY_THRESHOLD;
384};
385
386#endif /* _SO_MATERIAL_ELEMENT */
387
#define SoEXTENDER_Documented
static void init()
#define SO_ELEMENT_HEADER(className)
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
Manages several properties that need to be lazily tracked for rendering.
static SbColor getDefaultEmissive()
Specify Open Inventor defaults for colors, etc.
static size_t getNumDiffuse(SoState *state)
Return number of diffuse colors.
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 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 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 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 float getDefaultAmbientIntensity()
Specify Open Inventor defaults for colors, etc.
static void setSpecular(SoState *state, SoNode *node, const SbColor &color)
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