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