SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLNode.h
Go to the documentation of this file.
1 /**
2  * \file SLNode.h
3  * \date July 2014
4  * \authors Marc Wacker, Marcus Hudritsch, Jan Dellsperger
5  * \copyright http://opensource.org/licenses/GPL-3.0
6  * \remarks Please use clangformat to format the code. See more code style on
7  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
8 */
9 
10 #ifndef SLNODE_H
11 #define SLNODE_H
12 
13 #include "SL.h"
14 #include <SLDrawBits.h>
15 #include <SLEnums.h>
16 #include <SLEventHandler.h>
17 #include <SLMesh.h>
18 #include <SLQuat4.h>
19 #include <deque>
20 
21 using std::deque;
22 
23 class SLSceneView;
24 class SLRay;
25 class SLAABBox;
26 class SLNode;
27 class SLAnimation;
28 
29 //-----------------------------------------------------------------------------
30 //! SLVNode typedef for a vector of SLNodes
31 typedef deque<SLNode*> SLVNode;
32 //-----------------------------------------------------------------------------
33 //! Struct for scene graph statistics
34 /*! The SLNodeStats struct holds some statistics that are set in the recursive
35 SLNode::statsRec method.
36 */
38 {
39  SLuint numNodes; //!< NO. of children nodes
40  SLuint numBytes; //!< NO. of bytes allocated
41  SLuint numBytesAccel; //!< NO. of bytes in accel. structs
42  SLuint numNodesGroup; //!< NO. of group nodes
43  SLuint numNodesLeaf; //!< NO. of leaf nodes
44  SLuint numNodesOpaque; //!< NO. of visible opaque nodes
45  SLuint numNodesBlended; //!< NO. of visible blended nodes
46  SLuint numMeshes; //!< NO. of meshes in node
47  SLuint numLights; //!< NO. of lights in mesh
48  SLuint numTriangles; //!< NO. of triangles in mesh
49  SLuint numLines; //!< NO. of lines in mesh
50  SLuint numVoxels; //!< NO. of voxels
51  SLfloat numVoxEmpty; //!< NO. of empty voxels
52  SLuint numVoxMaxTria; //!< Max. no. of triangles per voxel
53  SLuint numAnimations; //!< NO. of animations
54 
55  //! Resets all counters to zero
56  void clear()
57  {
58  numNodes = 0;
59  numBytes = 0;
60  numBytesAccel = 0;
61  numNodesGroup = 0;
62  numNodesLeaf = 0;
63  numMeshes = 0;
64  numLights = 0;
65  numTriangles = 0;
66  numLines = 0;
67  numVoxels = 0;
68  numVoxEmpty = 0.0f;
69  numVoxMaxTria = 0;
70  numAnimations = 0;
71  }
72 
73  //! Prints all statistic informations on the std out stream.
74  void print() const
75  {
76  SLfloat voxelsEmpty = numVoxels ? (SLfloat)numVoxEmpty /
77  (SLfloat)numVoxels * 100.0f
78  : 0;
79  SLfloat avgTriPerVox = numVoxels ? (SLfloat)numTriangles /
81  : 0;
82  SL_LOG("Voxels : %d", numVoxels);
83  SL_LOG("Voxels empty : %4.1f%%", voxelsEmpty);
84  SL_LOG("Avg. Tria/Voxel: %4.1f", avgTriPerVox);
85  SL_LOG("Max. Tria/Voxel: %d", numVoxMaxTria);
86  SL_LOG("MB Meshes : %f", (SLfloat)numBytes / 1000000.0f);
87  SL_LOG("MB Accel. : %f", (SLfloat)numBytesAccel / 1000000.0f);
88  SL_LOG("Group Nodes : %d", numNodesGroup);
89  SL_LOG("Leaf Nodes : %d", numNodesLeaf);
90  SL_LOG("Meshes : %d", numMeshes);
91  SL_LOG("Triangles : %d", numTriangles);
92  SL_LOG("Lights : %d\n", numLights);
93  }
94 };
95 //-----------------------------------------------------------------------------
96 //! SLNode represents a node in a hierarchical scene graph.
97 /**
98  * @details This is the most important building block of the scene graph.
99  * A node can have 0-N children nodes in the vector _children. With child
100  * nodes you can build hierarchical structures. A node without a mesh can act
101  * as parent node to group its children. A node without children only makes
102  * sense to hold a mesh for visualization. The pointer _parent points to the
103  * parent of a child node.
104  * \n\n
105  * A node can point to a single SLMesh object for the rendering of triangles
106  * lines or points meshes. Meshes are stored in the SLAssetManager::_meshes
107  * vector. Multiple nodes can point to the same mesh object. The node is
108  * therefore not the owner of the meshes and does not delete them. The mesh
109  * is drawn by the methods SLNode::drawMesh and alternatively by
110  * SLNode::drawRec.
111  * \n\n
112  * A node can be transformed and has therefore a object matrix (_om) for its
113  * local transform. All other matrices such as the world matrix (_wm), the
114  * inverse world matrix (_wmI) are derived from the object matrix and
115  * automatically generated and updated.\n\n
116  *
117  * A node can be transformed by one of the various transform functions such
118  * as translate(). Many of these functions take an additional parameter
119  * 'relativeTo'. This parameter tells the transform function in what space
120  * the transformation should be applied in. The available transform spaces
121  * are:\n
122  * - TS_World: Space relative to the global world coordinate system.
123  * - TS_Parent: Space relative to our parent's transformation.
124  * - TS_Object: Space relative to our current node's origin.
125  *
126  * A node can implement one of the event handlers defined in the inherited
127  * SLEventHandler interface. There is special node called SLTransformNode
128  * that acts as a visual gizmo for editing the transform. See the example
129  * in the menu Edit of the SLProject demo app.\n\n
130  *
131  * The SLCamera is derived from the SLNode and implements a camera through
132  * which the scene can be viewed (see also SLSceneView). The SLLightSpot
133  * and SLLightRect are derived from SLNode and represent light sources in the
134  * scene. Cameras and lights can be placed in the scene because of their
135  * inheritance of SLNode.\n
136  * @remarks It is important that during instantiation NO OpenGL functions (gl*)
137  * get called because this constructor will be most probably called in a parallel
138  * thread from within an SLScene::registerAssetsToLoad or SLScene::assemble
139  * function. All objects that get rendered have to do their OpenGL initialization
140  * when they are used the first time during rendering in the main thread.
141  */
142 class SLNode
143  : public SLObject
144  , public SLEventHandler
145 #ifdef SL_HAS_OPTIX
146  , public SLOptixAccelStruct
147 #endif
148 {
149  friend class SLSceneView;
150 
151 public:
152  explicit SLNode(const SLstring& name = "Node");
153  explicit SLNode(SLMesh* mesh, const SLstring& name = "Node");
154  explicit SLNode(SLMesh* mesh, const SLVec3f& translation, const SLstring& name);
155  ~SLNode() override;
156 
157  // Recursive scene traversal methods (see impl. for details)
158  virtual void cull3DRec(SLSceneView* sv);
159  virtual void cullChildren3D(SLSceneView* sv);
160  virtual void cull2DRec(SLSceneView* sv);
161  virtual bool hitRec(SLRay* ray);
162  virtual void statsRec(SLNodeStats& stats);
163  virtual SLNode* copyRec();
164  virtual SLAABBox& updateAABBRec(SLbool updateAlsoAABBinOS);
165  virtual void dumpRec();
166  void setDrawBitsRec(SLuint bit, SLbool state);
167  void setPrimitiveTypeRec(SLGLPrimitiveType primitiveType);
168 
169  // Mesh methods (see impl. for details)
170  virtual void addMesh(SLMesh* mesh);
171  virtual void drawMesh(SLSceneView* sv);
172  bool removeMesh();
173  bool removeMesh(SLMesh* mesh);
174 
175  // Children methods (see impl. for details)
176  SLint numChildren() { return (SLint)_children.size(); }
177  void addChild(SLNode* child);
178  bool insertChild(SLNode* insertC, SLNode* afterC);
179  void deleteChildren();
180  bool deleteChild();
181  bool deleteChild(SLNode* child);
182  bool deleteChild(const SLstring& name);
183  bool removeChild(SLNode* child);
184 
185  template<typename T>
186  T* find(const SLstring& name = "",
187  SLbool findRecursive = true);
188  template<typename T>
189  T* findChild(const SLstring& name = "",
190  SLbool findRecursive = true);
191  template<typename T>
192  deque<T*> findChildren(const SLstring& name = "",
193  SLbool findRecursive = true,
194  SLbool canContain = false);
195  deque<SLNode*> findChildren(const SLMesh* mesh,
196  SLbool findRecursive = true);
197  deque<SLNode*> findChildren(SLuint drawbit,
198  SLbool findRecursive = true);
199 
200  // local direction getter functions
201  SLVec3f translationOS() const;
202  SLVec3f forwardOS() const;
203  SLVec3f rightOS() const;
204  SLVec3f upOS() const;
205  SLVec3f axisXOS() const;
206  SLVec3f axisYOS() const;
207  SLVec3f axisZOS() const;
208  SLVec3f translationWS() const;
209  SLVec3f forwardWS() const;
210  SLVec3f rightWS() const;
211  SLVec3f upWS() const;
212  SLVec3f axisXWS() const;
213  SLVec3f axisYWS() const;
214  SLVec3f axisZWS() const;
215 
216  // transform setter methods
217  void translation(const SLVec3f& pos,
218  SLTransformSpace relativeTo = TS_parent);
219  void translation(SLfloat x,
220  SLfloat y,
221  SLfloat z,
222  SLTransformSpace relativeTo = TS_parent);
223  void rotation(const SLQuat4f& rot,
224  SLTransformSpace relativeTo = TS_parent);
225  void rotation(SLfloat angleDeg,
226  const SLVec3f& axis,
227  SLTransformSpace relativeTo = TS_parent);
228  void scaling(SLfloat s);
229  void scaling(SLfloat x,
230  SLfloat y,
231  SLfloat z);
232  void scaling(const SLVec3f& scaling);
233  void lookAt(SLfloat targetX,
234  SLfloat targetY,
235  SLfloat targetZ,
236  SLfloat upX = 0,
237  SLfloat upY = 1,
238  SLfloat upZ = 0,
239  SLTransformSpace relativeTo = TS_world);
240  void lookAt(const SLVec3f& target,
241  const SLVec3f& up = SLVec3f::AXISY,
242  SLTransformSpace relativeTo = TS_world);
243 
244  // transform modifier methods
245  void translate(const SLVec3f& vec,
246  SLTransformSpace relativeTo = TS_object);
247  void translate(SLfloat x,
248  SLfloat y,
249  SLfloat z,
250  SLTransformSpace relativeTo = TS_object);
251  void rotate(const SLQuat4f& rot,
252  SLTransformSpace relativeTo = TS_object);
253  void rotate(SLfloat angleDeg,
254  const SLVec3f& axis,
255  SLTransformSpace relativeTo = TS_object);
256  void rotate(SLfloat angleDeg,
257  SLfloat x,
258  SLfloat y,
259  SLfloat z,
260  SLTransformSpace relativeTo = TS_object);
261  void rotateAround(const SLVec3f& point,
262  SLVec3f& axis,
263  SLfloat angleDeg,
264  SLTransformSpace relativeTo = TS_world);
265  void scale(SLfloat s);
266  void scale(SLfloat x, SLfloat y, SLfloat z);
267  void scale(const SLVec3f& scale);
268 
269  // Misc.
270  void scaleToCenter(SLfloat maxDim);
271  void setInitialState();
272  void resetToInitialState();
273 
274  // Setters (see also members)
275  void parent(SLNode* p);
277  void om(const SLMat4f& mat)
278  {
279  _om.setMatrix(mat);
280  needUpdate();
281  }
282  void animation(SLAnimation* a) { _animation = a; }
284  virtual void needUpdate();
285  void needWMUpdate();
286  void needAABBUpdate();
289  void levelForSM(SLubyte lfsm) { _levelForSM = lfsm; }
290  void onUpdateCB(function<void()> callbackFunc) { _onUpdateCB = callbackFunc; }
291 
292  // Getters (see also member)
293  SLNode* parent() { return _parent; }
294  SLint depth() const { return _depth; }
295  SLint entityID() const { return _entityID; }
296  const SLMat4f& om() { return _om; }
297  const SLMat4f& initialOM() { return _initialOM; }
298  const SLMat4f& updateAndGetWM() const;
299  const SLMat4f& updateAndGetWMI() const;
300  SLDrawBits* drawBits() { return &_drawBits; }
301  SLbool drawBit(SLuint bit) { return _drawBits.get(bit); }
302  SLAABBox* aabb() { return &_aabb; }
305  SLMesh* mesh() { return _mesh; }
306  SLVNode& children() { return _children; }
307  const SLAnimSkeleton* skeleton();
308  void updateRec();
309  virtual void doUpdate() {}
310  bool updateMeshSkins(bool forceCPUSkinning,
311  const std::function<void(SLMesh*)>& cbInformNodes);
312  void updateMeshAccelStructs();
313  void updateMeshMat(std::function<void(SLMaterial* m)> setMat,
314  bool recursive);
315  void setMeshMat(SLMaterial* mat, bool recursive);
316  bool isSelected() { return _isSelected; }
319 
320  static SLuint numWMUpdates; //!< NO. of calls to updateWMRec per frame
321 
322  static unsigned int instanceIndex; //!< ???
323 
324 #ifdef SL_HAS_OPTIX
325  void createInstanceAccelerationStructureTree();
326  void createInstanceAccelerationStructureFlat();
327  void createOptixInstances(vector<OptixInstance>&);
328 #endif
329 
330 private:
331  void updateWM() const;
332  template<typename T>
333  void findChildrenHelper(const SLstring& name,
334  deque<T*>& list,
335  SLbool findRecursive,
336  SLbool canContain = false);
337  void findChildrenHelper(const SLMesh* mesh,
338  deque<SLNode*>& list,
339  SLbool findRecursive);
340  void findChildrenHelper(SLuint drawbit,
341  deque<SLNode*>& list,
342  SLbool findRecursive);
343 
344 protected:
345  SLNode* _parent; //!< pointer to the parent node
346  SLVNode _children; //!< vector of children nodes
347  SLMesh* _mesh; //!< pointer to a single mesh
348 
349  SLint _depth; //!< depth of the node in a scene tree
350  SLint _entityID; //!< ID in the SLVEntity graph for Data Oriented Design
351  SLMat4f _om; //!< object matrix for local transforms
352  SLMat4f _initialOM; //!< the initial om state
353  mutable SLMat4f _wm; //!< world matrix for world transform
354  mutable SLMat4f _wmI; //!< inverse world matrix
355  mutable SLbool _isWMUpToDate; //!< is the WM of this node still valid
356  mutable SLbool _isWMIUpToDate; //!< is the inverse WM of this node still valid
357  mutable SLbool _isAABBUpToDate; //!< is the saved aabb still valid
358  bool _castsShadows; //!< flag if meshes of node should cast shadows
359  bool _isSelected; //!< flag if node and one or more of its meshes are selected
360  SLDrawBits _drawBits; //!< node level drawing flags
361  SLAABBox _aabb; //!< axis aligned bounding box
362  SLAnimation* _animation; //!< animation of the node
363  SLfloat _minLodCoverage; //!< Min. LOD coverage for visibility (0.0 < _minLodCoverage < 1.0)
364  SLubyte _levelForSM; //!< Level of LOD to use for shadow mapping (0 = the visible one will be drawn)
365  function<void()> _onUpdateCB; //!< Optional lambda callback once per update
366 };
367 
368 ////////////////////////
369 // TEMPLATE FUNCTIONS //
370 ////////////////////////
371 
372 //-----------------------------------------------------------------------------
373 /*!
374 SLNode::findChild<T> searches a node tree including the node by a given name.
375 */
376 template<typename T>
377 T* SLNode::find(const SLstring& name, SLbool findRecursive)
378 {
379  T* found = dynamic_cast<T*>(this);
380  if (found && (name.empty() || name == _name))
381  return found;
382  return findChild<T>(name, findRecursive);
383 }
384 //-----------------------------------------------------------------------------
385 /*!
386 SLNode::findChild<T> finds the first child that is of type T or a subclass of T.
387 */
388 template<typename T>
389 T* SLNode::findChild(const SLstring& name, SLbool findRecursive)
390 {
391  for (auto node : _children)
392  {
393  T* found = dynamic_cast<T*>(node);
394  if (found && (name.empty() || name == node->name()))
395  return found;
396  }
397  if (findRecursive)
398  {
399  for (auto& i : _children)
400  {
401  T* found = i->findChild<T>(name, findRecursive);
402  if (found)
403  return found;
404  }
405  }
406  //SL_LOG("SLNode::findChild: Nothing found for: %s\n", name.c_str());
407  return nullptr;
408 }
409 //-----------------------------------------------------------------------------
410 
411 /*!
412 SLNode::findChildren<T> finds a list of all children that are of type T or
413 subclasses of T. If a name is specified only nodes with that name are included.
414 */
415 template<typename T>
416 deque<T*>
418  SLbool findRecursive,
419  SLbool canContain)
420 {
421  deque<T*> list;
422  findChildrenHelper<T>(name, list, findRecursive);
423  return list;
424 }
425 //-----------------------------------------------------------------------------
426 
427 /*!
428 SLNode::findChildrenHelper<T> is the helper function for findChildren<T>.
429 It appends all newly found children to 'list'.
430 */
431 template<typename T>
433  deque<T*>& list,
434  SLbool findRecursive,
435  SLbool canContain)
436 {
437  for (auto& i : _children)
438  {
439  SLNode* node = i;
440  T* found = dynamic_cast<T*>(node);
441 
442  if (canContain)
443  {
444  if (found && (name.empty() ||
445  Utils::containsString(node->name(), name)))
446  list.push_back(found);
447  }
448  else
449  {
450  if (found && (name.empty() || name == node->name()))
451  list.push_back(found);
452  }
453 
454  if (findRecursive)
455  i->findChildrenHelper<T>(name, list, findRecursive);
456  }
457 }
458 //-----------------------------------------------------------------------------
459 
460 //////////////////////
461 // INLINE FUNCTIONS //
462 //////////////////////
463 
464 //-----------------------------------------------------------------------------
465 /*!
466 SLNode::position returns current local position
467 */
468 inline SLVec3f
470 {
471  return _om.translation();
472 }
473 //-----------------------------------------------------------------------------
474 /*!
475 Returns the local forward vector (= -z-axis) in a right-hand y-up system
476 */
477 inline SLVec3f
479 {
480  return SLVec3f(-_om.m(8), -_om.m(9), -_om.m(10));
481 }
482 //-----------------------------------------------------------------------------
483 /*!
484 Returns the local right vector (= x-axis) in a right-hand y-up system
485 */
486 inline SLVec3f
488 {
489  return SLVec3f(_om.m(0), _om.m(1), _om.m(2));
490 }
491 //-----------------------------------------------------------------------------
492 /*!
493 Returns the local up vector in a right-hand y-up system
494 */
495 inline SLVec3f
497 {
498  return SLVec3f(_om.m(4), _om.m(5), _om.m(6));
499 }
500 //-----------------------------------------------------------------------------
501 /*!
502 Returns the x-axis in object space
503 */
504 inline SLVec3f
506 {
507  return _om.axisX();
508 }
509 //-----------------------------------------------------------------------------
510 /*!
511 Returns the y-axis in object space
512 */
513 inline SLVec3f
515 {
516  return _om.axisY();
517 }
518 //-----------------------------------------------------------------------------
519 /*!
520 Returns the z-axis in object space
521 */
522 inline SLVec3f
524 {
525  return _om.axisZ();
526 }
527 //-----------------------------------------------------------------------------
528 /*!
529 SLNode::position returns current world position
530 */
531 inline SLVec3f
533 {
534  updateAndGetWM();
535  return _wm.translation();
536 }
537 //-----------------------------------------------------------------------------
538 /*!
539 SLNode::forward returns worlds forward vector
540 */
541 inline SLVec3f
543 {
544  updateAndGetWM();
545  return -_wm.axisZ();
546 }
547 //-----------------------------------------------------------------------------
548 /*!
549 SLNode::right returns worlds right vector
550 */
551 inline SLVec3f
553 {
554  updateAndGetWM();
555  return _wm.axisX();
556 }
557 //-----------------------------------------------------------------------------
558 /*!
559 SLNode::up returns worlds up vector
560 */
561 inline SLVec3f
563 {
564  updateAndGetWM();
565  return _wm.axisY();
566 }
567 //-----------------------------------------------------------------------------
568 /*!
569 Returns the x-axis in world space
570 */
571 inline SLVec3f
573 {
574  updateAndGetWM();
575  return _wm.axisX();
576 }
577 //-----------------------------------------------------------------------------
578 /*!
579 Returns the y-axis in world space
580 */
581 inline SLVec3f
583 {
584  updateAndGetWM();
585  return _wm.axisY();
586 }
587 //-----------------------------------------------------------------------------
588 /*!
589 Returns the z-axis in world space
590 */
591 inline SLVec3f
593 {
594  updateAndGetWM();
595  return _wm.axisZ();
596 }
597 //-----------------------------------------------------------------------------
598 inline void
600  SLfloat y,
601  SLfloat z,
602  SLTransformSpace relativeTo)
603 {
604  translation(SLVec3f(x, y, z), relativeTo);
605 }
606 //-----------------------------------------------------------------------------
607 inline void
609 {
610  scaling(SLVec3f(s, s, s));
611 }
612 //-----------------------------------------------------------------------------
613 inline void
615  SLfloat y,
616  SLfloat z)
617 {
618  scaling(SLVec3f(x, y, z));
619 }
620 //-----------------------------------------------------------------------------
621 inline void
623  SLfloat y,
624  SLfloat z,
625  SLTransformSpace relativeTo)
626 {
627  translate(SLVec3f(x, y, z), relativeTo);
628 }
629 //-----------------------------------------------------------------------------
630 inline void
632  SLfloat x,
633  SLfloat y,
634  SLfloat z,
635  SLTransformSpace relativeTo)
636 {
637  rotate(angleDeg, SLVec3f(x, y, z), relativeTo);
638 }
639 //-----------------------------------------------------------------------------
640 inline void
642 {
643  scale(SLVec3f(s, s, s));
644 }
645 //-----------------------------------------------------------------------------
646 inline void
648 {
649  scale(SLVec3f(x, y, z));
650 }
651 //-----------------------------------------------------------------------------
652 inline void
654  SLfloat targetY,
655  SLfloat targetZ,
656  SLfloat upX,
657  SLfloat upY,
658  SLfloat upZ,
659  SLTransformSpace relativeTo)
660 {
661  lookAt(SLVec3f(targetX,
662  targetY,
663  targetZ),
664  SLVec3f(upX, upY, upZ),
665  relativeTo);
666 }
667 //-----------------------------------------------------------------------------
668 
669 #endif
float SLfloat
Definition: SL.h:173
#define SL_LOG(...)
Definition: SL.h:233
unsigned int SLuint
Definition: SL.h:171
bool SLbool
Definition: SL.h:175
unsigned char SLubyte
Definition: SL.h:167
string SLstring
Definition: SL.h:158
int SLint
Definition: SL.h:170
SLTransformSpace
Describes the relative space a transformation is applied in.
Definition: SLEnums.h:206
@ TS_world
Definition: SLEnums.h:208
@ TS_parent
Definition: SLEnums.h:209
@ TS_object
Definition: SLEnums.h:210
SLGLPrimitiveType
Definition: SLGLEnums.h:30
typedef void(SL_STDCALL *cbOnImGuiBuild)(SLScene *s
Callback function typedef for ImGui build function.
deque< SLNode * > SLVNode
SLVNode typedef for a vector of SLNodes.
Definition: SLNode.h:27
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318
Defines an axis aligned bounding box.
Definition: SLAABBox.h:34
SLAnimSkeleton keeps track of a skeletons joints and animations.
SLAnimation is the base container for all animation data.
Definition: SLAnimation.h:33
Drawing states stored in the bits of an unsigned int.
Definition: SLDrawBits.h:42
SLbool get(SLuint bit)
Returns the specified bit.
Definition: SLDrawBits.h:69
Virtual Eventhandler class.
SLVec3< T > translation() const
Definition: SLMat4.h:184
void setMatrix(const SLMat4 &A)
Set matrix by other 4x4 matrix.
Definition: SLMat4.h:335
SLVec3< T > axisX() const
Definition: SLMat4.h:185
SLVec3< T > axisY() const
Definition: SLMat4.h:186
void m(int i, T val)
Definition: SLMat4.h:93
SLVec3< T > axisZ() const
Definition: SLMat4.h:187
Defines a standard CG material with textures and a shader program.
Definition: SLMaterial.h:56
An SLMesh object is a triangulated mesh, drawn with one draw call.
Definition: SLMesh.h:134
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:148
SLint numChildren()
Definition: SLNode.h:176
bool updateMeshSkins(bool forceCPUSkinning, const std::function< void(SLMesh *)> &cbInformNodes)
Update all skinned meshes recursively.
Definition: SLNode.cpp:1126
void resetToInitialState()
Definition: SLNode.cpp:1092
virtual void drawMesh(SLSceneView *sv)
Draws the single mesh.
Definition: SLNode.cpp:176
SLint entityID() const
Definition: SLNode.h:295
void rotation(const SLQuat4f &rot, SLTransformSpace relativeTo=TS_parent)
Definition: SLNode.cpp:846
T * find(const SLstring &name="", SLbool findRecursive=true)
Definition: SLNode.h:377
SLVec3f axisZWS() const
Definition: SLNode.h:592
function< void()> _onUpdateCB
Optional lambda callback once per update.
Definition: SLNode.h:365
~SLNode() override
Definition: SLNode.cpp:133
SLAABBox * aabb()
Definition: SLNode.h:302
void addChild(SLNode *child)
Definition: SLNode.cpp:207
SLubyte _levelForSM
Level of LOD to use for shadow mapping (0 = the visible one will be drawn)
Definition: SLNode.h:364
SLVec3f upWS() const
Definition: SLNode.h:562
SLVNode & children()
Definition: SLNode.h:306
SLMat4f _wmI
inverse world matrix
Definition: SLNode.h:354
SLbool drawBit(SLuint bit)
Definition: SLNode.h:301
void updateWM() const
Definition: SLNode.cpp:687
void translation(const SLVec3f &pos, SLTransformSpace relativeTo=TS_parent)
Definition: SLNode.cpp:828
bool removeMesh()
Returns true if a mesh was assigned and set it to nullptr.
Definition: SLNode.cpp:183
virtual void dumpRec()
Definition: SLNode.cpp:775
SLAnimation * _animation
animation of the node
Definition: SLNode.h:362
SLVec3f forwardOS() const
Definition: SLNode.h:478
const SLMat4f & om()
Definition: SLNode.h:296
void animation(SLAnimation *a)
Definition: SLNode.h:282
void needWMUpdate()
Definition: SLNode.cpp:645
virtual void needUpdate()
Definition: SLNode.cpp:616
SLNode * parent()
Definition: SLNode.h:293
void minLodCoverage(SLfloat minLodCoverage)
Definition: SLNode.h:288
SLDrawBits _drawBits
node level drawing flags
Definition: SLNode.h:360
void rotate(const SLQuat4f &rot, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:945
SLAnimation * animation()
Definition: SLNode.h:303
SLAABBox _aabb
axis aligned bounding box
Definition: SLNode.h:361
SLNode * _parent
pointer to the parent node
Definition: SLNode.h:345
SLVec3f rightWS() const
Definition: SLNode.h:552
const SLMat4f & updateAndGetWM() const
Definition: SLNode.cpp:703
void scale(SLfloat s)
Definition: SLNode.h:641
SLMesh * mesh()
Definition: SLNode.h:305
static SLuint numWMUpdates
NO. of calls to updateWMRec per frame.
Definition: SLNode.h:320
SLVec3f upOS() const
Definition: SLNode.h:496
void castsShadows(SLbool castsShadows)
Definition: SLNode.h:283
virtual SLNode * copyRec()
Definition: SLNode.cpp:572
void needAABBUpdate()
Definition: SLNode.cpp:665
SLMat4f _om
object matrix for local transforms
Definition: SLNode.h:351
static unsigned int instanceIndex
???
Definition: SLNode.h:322
bool insertChild(SLNode *insertC, SLNode *afterC)
Definition: SLNode.cpp:229
SLbool _isAABBUpToDate
is the saved aabb still valid
Definition: SLNode.h:357
SLVec3f translationWS() const
Definition: SLNode.h:532
const SLAnimSkeleton * skeleton()
Returns the first skeleton found in the meshes.
Definition: SLNode.cpp:1100
void setPrimitiveTypeRec(SLGLPrimitiveType primitiveType)
Definition: SLNode.cpp:813
SLVec3f axisXOS() const
Definition: SLNode.h:505
void deleteChildren()
Definition: SLNode.cpp:248
SLVec3f axisXWS() const
Definition: SLNode.h:572
SLVec3f rightOS() const
Definition: SLNode.h:487
T * findChild(const SLstring &name="", SLbool findRecursive=true)
Definition: SLNode.h:389
SLfloat _minLodCoverage
Min. LOD coverage for visibility (0.0 < _minLodCoverage < 1.0)
Definition: SLNode.h:363
SLVec3f translationOS() const
Definition: SLNode.h:469
void updateRec()
Definition: SLNode.cpp:1107
SLMat4f _initialOM
the initial om state
Definition: SLNode.h:352
bool _isSelected
flag if node and one or more of its meshes are selected
Definition: SLNode.h:359
void isSelected(bool isSelected)
Definition: SLNode.h:287
bool _castsShadows
flag if meshes of node should cast shadows
Definition: SLNode.h:358
SLVec3f axisZOS() const
Definition: SLNode.h:523
void setMeshMat(SLMaterial *mat, bool recursive)
Set the mesh material recursively.
Definition: SLNode.cpp:1172
virtual void cullChildren3D(SLSceneView *sv)
Initializer function to call SLNode::cull3DRec recursively.
Definition: SLNode.cpp:384
SLDrawBits * drawBits()
Definition: SLNode.h:300
virtual void addMesh(SLMesh *mesh)
Definition: SLNode.cpp:157
void entityID(SLint entityID)
Definition: SLNode.h:276
void updateMeshAccelStructs()
Definition: SLNode.cpp:1149
bool isSelected()
Definition: SLNode.h:316
void setInitialState()
Definition: SLNode.cpp:1084
SLVNode _children
vector of children nodes
Definition: SLNode.h:346
virtual void doUpdate()
Definition: SLNode.h:309
SLVec3f axisYWS() const
Definition: SLNode.h:582
void om(const SLMat4f &mat)
Definition: SLNode.h:277
virtual void statsRec(SLNodeStats &stats)
Definition: SLNode.cpp:479
void scaling(SLfloat s)
Definition: SLNode.h:608
const SLMat4f & updateAndGetWMI() const
Definition: SLNode.cpp:714
SLVec3f axisYOS() const
Definition: SLNode.h:514
void lookAt(SLfloat targetX, SLfloat targetY, SLfloat targetZ, SLfloat upX=0, SLfloat upY=1, SLfloat upZ=0, SLTransformSpace relativeTo=TS_world)
Definition: SLNode.h:653
SLMesh * _mesh
pointer to a single mesh
Definition: SLNode.h:347
void levelForSM(SLubyte lfsm)
Definition: SLNode.h:289
void updateMeshMat(std::function< void(SLMaterial *m)> setMat, bool recursive)
Updates the mesh material recursively with a material lambda.
Definition: SLNode.cpp:1161
SLNode(const SLstring &name="Node")
Construct a new SLNode::SLNode object.
Definition: SLNode.cpp:40
SLVec3f forwardWS() const
Definition: SLNode.h:542
virtual SLAABBox & updateAABBRec(SLbool updateAlsoAABBinOS)
Definition: SLNode.cpp:731
deque< T * > findChildren(const SLstring &name="", SLbool findRecursive=true, SLbool canContain=false)
Definition: SLNode.h:417
SLMat4f _wm
world matrix for world transform
Definition: SLNode.h:353
virtual void cull2DRec(SLSceneView *sv)
Definition: SLNode.cpp:455
SLubyte levelForSM()
Definition: SLNode.h:318
SLbool castsShadows()
Definition: SLNode.h:304
bool removeChild(SLNode *child)
remove child from vector of children. Removes false if not found, else true.
Definition: SLNode.cpp:367
void scaleToCenter(SLfloat maxDim)
Definition: SLNode.cpp:1068
SLbool _isWMIUpToDate
is the inverse WM of this node still valid
Definition: SLNode.h:356
SLint _entityID
ID in the SLVEntity graph for Data Oriented Design.
Definition: SLNode.h:350
SLfloat minLodCoverage()
Definition: SLNode.h:317
bool deleteChild()
Definition: SLNode.cpp:267
void onUpdateCB(function< void()> callbackFunc)
Definition: SLNode.h:290
SLint _depth
depth of the node in a scene tree
Definition: SLNode.h:349
const SLMat4f & initialOM()
Definition: SLNode.h:297
void findChildrenHelper(const SLstring &name, deque< T * > &list, SLbool findRecursive, SLbool canContain=false)
Definition: SLNode.h:432
virtual bool hitRec(SLRay *ray)
Definition: SLNode.cpp:508
SLbool _isWMUpToDate
is the WM of this node still valid
Definition: SLNode.h:355
void setDrawBitsRec(SLuint bit, SLbool state)
Definition: SLNode.cpp:804
virtual void cull3DRec(SLSceneView *sv)
Definition: SLNode.cpp:397
void rotateAround(const SLVec3f &point, SLVec3f &axis, SLfloat angleDeg, SLTransformSpace relativeTo=TS_world)
Definition: SLNode.cpp:979
SLint depth() const
Definition: SLNode.h:294
void translate(const SLVec3f &vec, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:906
Base class for all other classes.
Definition: SLObject.h:23
void name(const SLstring &Name)
Definition: SLObject.h:34
SLstring _name
name of an object
Definition: SLObject.h:42
const SLstring & name() const
Definition: SLObject.h:38
Ray class with ray and intersection properties.
Definition: SLRay.h:40
The SLScene class represents the top level instance holding the scene structure.
Definition: SLScene.h:47
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
static SLVec3 AXISY
Definition: SLVec3.h:298
bool containsString(const string &container, const string &search)
Returns true if container contains the search string.
Definition: Utils.cpp:345
Struct for scene graph statistics.
Definition: SLNode.h:38
SLuint numVoxMaxTria
Max. no. of triangles per voxel.
Definition: SLNode.h:52
void print() const
Prints all statistic informations on the std out stream.
Definition: SLNode.h:74
SLuint numBytesAccel
NO. of bytes in accel. structs.
Definition: SLNode.h:41
SLuint numNodesOpaque
NO. of visible opaque nodes.
Definition: SLNode.h:44
SLuint numMeshes
NO. of meshes in node.
Definition: SLNode.h:46
SLuint numNodes
NO. of children nodes.
Definition: SLNode.h:39
SLuint numLights
NO. of lights in mesh.
Definition: SLNode.h:47
void clear()
Resets all counters to zero.
Definition: SLNode.h:56
SLuint numTriangles
NO. of triangles in mesh.
Definition: SLNode.h:48
SLuint numAnimations
NO. of animations.
Definition: SLNode.h:53
SLuint numNodesBlended
NO. of visible blended nodes.
Definition: SLNode.h:45
SLuint numNodesLeaf
NO. of leaf nodes.
Definition: SLNode.h:43
SLuint numVoxels
NO. of voxels.
Definition: SLNode.h:50
SLuint numLines
NO. of lines in mesh.
Definition: SLNode.h:49
SLuint numNodesGroup
NO. of group nodes.
Definition: SLNode.h:42
SLuint numBytes
NO. of bytes allocated.
Definition: SLNode.h:40
SLfloat numVoxEmpty
NO. of empty voxels.
Definition: SLNode.h:51