SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLNode Class Reference

SLNode represents a node in a hierarchical scene graph. More...

#include <SLNode.h>

Inheritance diagram for SLNode:
[legend]

Public Member Functions

 SLNode (const SLstring &name="Node")
 Construct a new SLNode::SLNode object. More...
 
 SLNode (SLMesh *mesh, const SLstring &name="Node")
 
 SLNode (SLMesh *mesh, const SLVec3f &translation, const SLstring &name)
 
 ~SLNode () override
 
virtual void cull3DRec (SLSceneView *sv)
 
virtual void cullChildren3D (SLSceneView *sv)
 Initializer function to call SLNode::cull3DRec recursively. More...
 
virtual void cull2DRec (SLSceneView *sv)
 
virtual bool hitRec (SLRay *ray)
 
virtual void statsRec (SLNodeStats &stats)
 
virtual SLNodecopyRec ()
 
virtual SLAABBoxupdateAABBRec (SLbool updateAlsoAABBinOS)
 
virtual void dumpRec ()
 
void setDrawBitsRec (SLuint bit, SLbool state)
 
void setPrimitiveTypeRec (SLGLPrimitiveType primitiveType)
 
virtual void addMesh (SLMesh *mesh)
 
virtual void drawMesh (SLSceneView *sv)
 Draws the single mesh. More...
 
bool removeMesh ()
 Returns true if a mesh was assigned and set it to nullptr. More...
 
bool removeMesh (SLMesh *mesh)
 Returns true if the passed mesh was assigned and sets it to nullptr. More...
 
SLint numChildren ()
 
void addChild (SLNode *child)
 
bool insertChild (SLNode *insertC, SLNode *afterC)
 
void deleteChildren ()
 
bool deleteChild ()
 
bool deleteChild (SLNode *child)
 
bool deleteChild (const SLstring &name)
 
bool removeChild (SLNode *child)
 remove child from vector of children. Removes false if not found, else true. More...
 
template<typename T >
T * find (const SLstring &name="", SLbool findRecursive=true)
 
template<typename T >
T * findChild (const SLstring &name="", SLbool findRecursive=true)
 
template<typename T >
deque< T * > findChildren (const SLstring &name="", SLbool findRecursive=true, SLbool canContain=false)
 
deque< SLNode * > findChildren (const SLMesh *mesh, SLbool findRecursive=true)
 
deque< SLNode * > findChildren (SLuint drawbit, SLbool findRecursive=true)
 
SLVec3f translationOS () const
 
SLVec3f forwardOS () const
 
SLVec3f rightOS () const
 
SLVec3f upOS () const
 
SLVec3f axisXOS () const
 
SLVec3f axisYOS () const
 
SLVec3f axisZOS () const
 
SLVec3f translationWS () const
 
SLVec3f forwardWS () const
 
SLVec3f rightWS () const
 
SLVec3f upWS () const
 
SLVec3f axisXWS () const
 
SLVec3f axisYWS () const
 
SLVec3f axisZWS () const
 
void translation (const SLVec3f &pos, SLTransformSpace relativeTo=TS_parent)
 
void translation (SLfloat x, SLfloat y, SLfloat z, SLTransformSpace relativeTo=TS_parent)
 
void rotation (const SLQuat4f &rot, SLTransformSpace relativeTo=TS_parent)
 
void rotation (SLfloat angleDeg, const SLVec3f &axis, SLTransformSpace relativeTo=TS_parent)
 
void scaling (SLfloat s)
 
void scaling (SLfloat x, SLfloat y, SLfloat z)
 
void scaling (const SLVec3f &scaling)
 
void lookAt (SLfloat targetX, SLfloat targetY, SLfloat targetZ, SLfloat upX=0, SLfloat upY=1, SLfloat upZ=0, SLTransformSpace relativeTo=TS_world)
 
void lookAt (const SLVec3f &target, const SLVec3f &up=SLVec3f::AXISY, SLTransformSpace relativeTo=TS_world)
 
void translate (const SLVec3f &vec, SLTransformSpace relativeTo=TS_object)
 
void translate (SLfloat x, SLfloat y, SLfloat z, SLTransformSpace relativeTo=TS_object)
 
void rotate (const SLQuat4f &rot, SLTransformSpace relativeTo=TS_object)
 
void rotate (SLfloat angleDeg, const SLVec3f &axis, SLTransformSpace relativeTo=TS_object)
 
void rotate (SLfloat angleDeg, SLfloat x, SLfloat y, SLfloat z, SLTransformSpace relativeTo=TS_object)
 
void rotateAround (const SLVec3f &point, SLVec3f &axis, SLfloat angleDeg, SLTransformSpace relativeTo=TS_world)
 
void scale (SLfloat s)
 
void scale (SLfloat x, SLfloat y, SLfloat z)
 
void scale (const SLVec3f &scale)
 
void scaleToCenter (SLfloat maxDim)
 
void setInitialState ()
 
void resetToInitialState ()
 
void parent (SLNode *p)
 
void entityID (SLint entityID)
 
void om (const SLMat4f &mat)
 
void animation (SLAnimation *a)
 
void castsShadows (SLbool castsShadows)
 
virtual void needUpdate ()
 
void needWMUpdate ()
 
void needAABBUpdate ()
 
void isSelected (bool isSelected)
 
void minLodCoverage (SLfloat minLodCoverage)
 
void levelForSM (SLubyte lfsm)
 
void onUpdateCB (function< void()> callbackFunc)
 
SLNodeparent ()
 
SLint depth () const
 
SLint entityID () const
 
const SLMat4fom ()
 
const SLMat4finitialOM ()
 
const SLMat4fupdateAndGetWM () const
 
const SLMat4fupdateAndGetWMI () const
 
SLDrawBitsdrawBits ()
 
SLbool drawBit (SLuint bit)
 
SLAABBoxaabb ()
 
SLAnimationanimation ()
 
SLbool castsShadows ()
 
SLMeshmesh ()
 
SLVNodechildren ()
 
const SLAnimSkeletonskeleton ()
 Returns the first skeleton found in the meshes. More...
 
void updateRec ()
 
virtual void doUpdate ()
 
bool updateMeshSkins (bool forceCPUSkinning, const std::function< void(SLMesh *)> &cbInformNodes)
 Update all skinned meshes recursively. More...
 
void updateMeshAccelStructs ()
 
void updateMeshMat (std::function< void(SLMaterial *m)> setMat, bool recursive)
 Updates the mesh material recursively with a material lambda. More...
 
void setMeshMat (SLMaterial *mat, bool recursive)
 Set the mesh material recursively. More...
 
bool isSelected ()
 
SLfloat minLodCoverage ()
 
SLubyte levelForSM ()
 
- Public Member Functions inherited from SLObject
 SLObject (const SLstring &Name="", const SLstring &url="")
 
virtual ~SLObject ()
 
void name (const SLstring &Name)
 
void url (const SLstring &url)
 
const SLstringname () const
 
const SLstringurl () const
 
- Public Member Functions inherited from SLEventHandler
 SLEventHandler ()
 
virtual ~SLEventHandler ()
 
virtual SLbool onMouseDown (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod)
 
virtual SLbool onMouseUp (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod)
 
virtual SLbool onMouseMove (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod)
 
virtual SLbool onDoubleClick (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod)
 
virtual SLbool onMouseWheel (const SLint delta, const SLKey mod)
 
virtual SLbool onTouch2Down (const SLint x1, const SLint y1, const SLint x2, const SLint y2)
 
virtual SLbool onTouch2Move (const SLint x1, const SLint y1, const SLint x2, const SLint y2)
 
virtual SLbool onTouch2Up (const SLint x1, const SLint y1, const SLint x2, const SLint y2)
 
virtual SLbool onTouch3Down (const SLint x1, const SLint y1)
 
virtual SLbool onTouch3Move (const SLint x1, const SLint y1)
 
virtual SLbool onTouch3Up (const SLint x1, const SLint y1)
 
virtual SLbool onKeyPress (const SLKey key, const SLKey mod)
 
virtual SLbool onKeyRelease (const SLKey key, const SLKey mod)
 
virtual SLbool onRotationPYR (const SLfloat pitchRAD, const SLfloat yawRAD, const SLfloat rollRAD)
 
void mouseRotationFactor (SLfloat rf)
 
SLfloat mouseRotationFactor ()
 

Static Public Attributes

static SLuint numWMUpdates = 0
 NO. of calls to updateWMRec per frame. More...
 
static unsigned int instanceIndex = 0
 ??? More...
 

Protected Attributes

SLNode_parent
 pointer to the parent node More...
 
SLVNode _children
 vector of children nodes More...
 
SLMesh_mesh
 pointer to a single mesh More...
 
SLint _depth
 depth of the node in a scene tree More...
 
SLint _entityID
 ID in the SLVEntity graph for Data Oriented Design. More...
 
SLMat4f _om
 object matrix for local transforms More...
 
SLMat4f _initialOM
 the initial om state More...
 
SLMat4f _wm
 world matrix for world transform More...
 
SLMat4f _wmI
 inverse world matrix More...
 
SLbool _isWMUpToDate
 is the WM of this node still valid More...
 
SLbool _isWMIUpToDate
 is the inverse WM of this node still valid More...
 
SLbool _isAABBUpToDate
 is the saved aabb still valid More...
 
bool _castsShadows
 flag if meshes of node should cast shadows More...
 
bool _isSelected
 flag if node and one or more of its meshes are selected More...
 
SLDrawBits _drawBits
 node level drawing flags More...
 
SLAABBox _aabb
 axis aligned bounding box More...
 
SLAnimation_animation
 animation of the node More...
 
SLfloat _minLodCoverage
 Min. LOD coverage for visibility (0.0 < _minLodCoverage < 1.0) More...
 
SLubyte _levelForSM
 Level of LOD to use for shadow mapping (0 = the visible one will be drawn) More...
 
function< void()> _onUpdateCB
 Optional lambda callback once per update. More...
 
- Protected Attributes inherited from SLObject
SLstring _name
 name of an object More...
 
SLstring _url
 uniform resource locator More...
 
- Protected Attributes inherited from SLEventHandler
SLfloat _mouseRotationFactor
 Mouse rotation sensibility. More...
 
SLfloat _keyboardDeltaPos
 Delta dist. for keyboard translation. More...
 

Private Member Functions

void updateWM () const
 
template<typename T >
void findChildrenHelper (const SLstring &name, deque< T * > &list, SLbool findRecursive, SLbool canContain=false)
 
void findChildrenHelper (const SLMesh *mesh, deque< SLNode * > &list, SLbool findRecursive)
 
void findChildrenHelper (SLuint drawbit, deque< SLNode * > &list, SLbool findRecursive)
 

Friends

class SLSceneView
 

Detailed Description

SLNode represents a node in a hierarchical scene graph.

This is the most important building block of the scene graph. A node can have 0-N children nodes in the vector _children. With child nodes you can build hierarchical structures. A node without a mesh can act as parent node to group its children. A node without children only makes sense to hold a mesh for visualization. The pointer _parent points to the parent of a child node.

A node can point to a single SLMesh object for the rendering of triangles lines or points meshes. Meshes are stored in the SLAssetManager::_meshes vector. Multiple nodes can point to the same mesh object. The node is therefore not the owner of the meshes and does not delete them. The mesh is drawn by the methods SLNode::drawMesh and alternatively by SLNode::drawRec.

A node can be transformed and has therefore a object matrix (_om) for its local transform. All other matrices such as the world matrix (_wm), the inverse world matrix (_wmI) are derived from the object matrix and automatically generated and updated.

A node can be transformed by one of the various transform functions such as translate(). Many of these functions take an additional parameter 'relativeTo'. This parameter tells the transform function in what space the transformation should be applied in. The available transform spaces are:

  • TS_World: Space relative to the global world coordinate system.
  • TS_Parent: Space relative to our parent's transformation.
  • TS_Object: Space relative to our current node's origin.

A node can implement one of the event handlers defined in the inherited SLEventHandler interface. There is special node called SLTransformNode that acts as a visual gizmo for editing the transform. See the example in the menu Edit of the SLProject demo app.

The SLCamera is derived from the SLNode and implements a camera through which the scene can be viewed (see also SLSceneView). The SLLightSpot and SLLightRect are derived from SLNode and represent light sources in the scene. Cameras and lights can be placed in the scene because of their inheritance of SLNode.

Remarks
It is important that during instantiation NO OpenGL functions (gl*) get called because this constructor will be most probably called in a parallel thread from within an SLScene::registerAssetsToLoad or SLScene::assemble function. All objects that get rendered have to do their OpenGL initialization when they are used the first time during rendering in the main thread.

Definition at line 141 of file SLNode.h.

Constructor & Destructor Documentation

◆ SLNode() [1/3]

SLNode::SLNode ( const SLstring name = "Node")
explicit

Construct a new SLNode::SLNode object.

Remarks
It is important that during instantiation NO OpenGL functions (gl*) get called because this constructor will be most probably called in a parallel thread from within an SLScene::registerAssetsToLoad or SLScene::assemble function. All objects that get rendered have to do their OpenGL initialization when they are used the first time during rendering in the main thread.
Parameters
nameName of the node

Definition at line 40 of file SLNode.cpp.

40  : SLObject(name)
41 {
42  _parent = nullptr;
43  _depth = 1;
44  _entityID = INT32_MIN;
45  _om.identity();
46  _wm.identity();
47  _wmI.identity();
48  _drawBits.allOff();
49  _animation = nullptr;
50  _castsShadows = true;
51  _isWMUpToDate = false;
52  _isWMIUpToDate = false;
53  _isAABBUpToDate = false;
54  _isSelected = false;
55  _mesh = nullptr;
56  _minLodCoverage = 0.0f;
57  _levelForSM = 0;
58 }
void allOff()
Turns all bits off.
Definition: SLDrawBits.h:48
void identity()
Sets the identity matrix.
Definition: SLMat4.h:1333
SLubyte _levelForSM
Level of LOD to use for shadow mapping (0 = the visible one will be drawn)
Definition: SLNode.h:363
SLMat4f _wmI
inverse world matrix
Definition: SLNode.h:353
SLAnimation * _animation
animation of the node
Definition: SLNode.h:361
SLDrawBits _drawBits
node level drawing flags
Definition: SLNode.h:359
SLNode * _parent
pointer to the parent node
Definition: SLNode.h:344
SLMat4f _om
object matrix for local transforms
Definition: SLNode.h:350
SLbool _isAABBUpToDate
is the saved aabb still valid
Definition: SLNode.h:356
SLfloat _minLodCoverage
Min. LOD coverage for visibility (0.0 < _minLodCoverage < 1.0)
Definition: SLNode.h:362
bool _isSelected
flag if node and one or more of its meshes are selected
Definition: SLNode.h:358
bool _castsShadows
flag if meshes of node should cast shadows
Definition: SLNode.h:357
SLMesh * _mesh
pointer to a single mesh
Definition: SLNode.h:346
SLMat4f _wm
world matrix for world transform
Definition: SLNode.h:352
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
SLint _depth
depth of the node in a scene tree
Definition: SLNode.h:348
SLbool _isWMUpToDate
is the WM of this node still valid
Definition: SLNode.h:354
SLObject(const SLstring &Name="", const SLstring &url="")
Definition: SLObject.h:25
const SLstring & name() const
Definition: SLObject.h:38

◆ SLNode() [2/3]

SLNode::SLNode ( SLMesh mesh,
const SLstring name = "Node" 
)
explicit

Constructor with a mesh pointer and name. It is important that during instantiation NO OpenGL functions (gl*) get called because this constructor will be most probably called in a parallel thread from within a SLScene::assemble function. All objects that get rendered have to do their OpenGL initialization when they are used the first time during rendering in the main thread.

Definition at line 68 of file SLNode.cpp.

68  : SLObject(name)
69 {
70  assert(mesh && "No mesh passed");
71 
72  _parent = nullptr;
73  _depth = 1;
74  _entityID = INT32_MIN;
75  _om.identity();
76  _wm.identity();
77  _wmI.identity();
78  _drawBits.allOff();
79  _animation = nullptr;
80  _castsShadows = true;
81  _isWMUpToDate = false;
82  _isWMIUpToDate = false;
83  _isAABBUpToDate = false;
84  _isSelected = false;
85  _minLodCoverage = 0.0f;
86  _levelForSM = 0;
87  _mesh = nullptr;
88 
89  addMesh(mesh);
90 }
SLMesh * mesh()
Definition: SLNode.h:304
virtual void addMesh(SLMesh *mesh)
Definition: SLNode.cpp:157

◆ SLNode() [3/3]

SLNode::SLNode ( SLMesh mesh,
const SLVec3f translation,
const SLstring name 
)
explicit

Constructor with a mesh pointer, translation vector and name. It is important that during instantiation NO OpenGL functions (gl*) get called because this constructor will be most probably called in a parallel thread from within a SLScene::assemble function. All objects that get rendered have to do their OpenGL initialization when they are used the first time during rendering in the main thread.

Definition at line 100 of file SLNode.cpp.

102  : SLObject(name)
103 {
104  assert(mesh && "No mesh passed");
105 
106  _parent = nullptr;
107  _depth = 1;
108  _entityID = INT32_MIN;
109  _om.identity();
111  _wm.identity();
112  _wmI.identity();
113  _drawBits.allOff();
114  _animation = nullptr;
115  _castsShadows = true;
116  _isWMUpToDate = false;
117  _isWMIUpToDate = false;
118  _isAABBUpToDate = false;
119  _isSelected = false;
120  _minLodCoverage = 0.0f;
121  _levelForSM = 0;
122  _mesh = nullptr;
123 
124  addMesh(mesh);
125 }
void translate(T tx, T ty, T tz=0)
Definition: SLMat4.h:601
void translation(const SLVec3f &pos, SLTransformSpace relativeTo=TS_parent)
Definition: SLNode.cpp:828

◆ ~SLNode()

SLNode::~SLNode ( )
override

Destructor deletes all children recursively and the animation. The mesh is not deleted. Meshes get deleted at the end by the SLAssetManager vector. The entire scenegraph is deleted by deleting the SLScene::_root3D node. Nodes that are not in the scenegraph will not be deleted at scene destruction.

Definition at line 133 of file SLNode.cpp.

134 {
135 #ifdef SL_USE_ENTITIES
136  SLint entityID = SLScene::entities.getEntityID(this);
137  SLint parentID = SLScene::entities.getParentID(this);
138  if (entityID != INT32_MIN && parentID != INT32_MIN)
139  {
140  if (parentID == -1)
141  SLScene::entities.clear();
142  else
143  SLScene::entities.deleteEntity(entityID);
144  }
145 #endif
146 
147  for (auto* child : _children)
148  delete child;
149  _children.clear();
150 
151  delete _animation;
152 }
int SLint
Definition: SL.h:170
SLint entityID() const
Definition: SLNode.h:294
SLVNode _children
vector of children nodes
Definition: SLNode.h:345

Member Function Documentation

◆ aabb()

SLAABBox* SLNode::aabb ( )
inline

Definition at line 301 of file SLNode.h.

301 { return &_aabb; }
SLAABBox _aabb
axis aligned bounding box
Definition: SLNode.h:360

◆ addChild()

void SLNode::addChild ( SLNode child)

Adds a child node to the children vector

Definition at line 207 of file SLNode.cpp.

208 {
209  assert(child && "The child pointer is null.");
210  assert(this != child && "You can not add the node to itself.");
211  assert(!child->parent() && "The child has already a parent.");
212 
213  _children.push_back(child);
214  _isAABBUpToDate = false;
215  child->parent(this);
216 
217 #ifdef SL_USE_ENTITIES
218  // Only add child to existing parents in entities
219  if (_entityID != INT32_MIN)
220  {
221  SLScene::entities.addChildEntity(_entityID, SLEntity(child));
222  }
223 #endif
224 }
void parent(SLNode *p)
Definition: SLNode.cpp:600
SLEntity is the Data Oriented Design version of a SLNode.
Definition: SLEntities.h:28

◆ addMesh()

void SLNode::addMesh ( SLMesh mesh)
virtual

Simply adds a mesh to its mesh pointer vector of the node.

Definition at line 157 of file SLNode.cpp.

158 {
159  assert(mesh && "No mesh passed");
160 
161  // Take over mesh name if node name is default name
162  if (_name == "Node" && mesh->name() != "Mesh")
163  _name = mesh->name() + "-Node";
164 
165  _mesh = mesh;
166 
167  _isAABBUpToDate = false;
168  mesh->init(this);
169 }
virtual void init(SLNode *node)
SLMesh::shapeInit sets the transparency flag of the AABB.
Definition: SLMesh.cpp:296
void name(const SLstring &Name)
Definition: SLObject.h:34
SLstring _name
name of an object
Definition: SLObject.h:42

◆ animation() [1/2]

SLAnimation* SLNode::animation ( )
inline

Definition at line 302 of file SLNode.h.

302 { return _animation; }

◆ animation() [2/2]

void SLNode::animation ( SLAnimation a)
inline

Definition at line 281 of file SLNode.h.

281 { _animation = a; }

◆ axisXOS()

SLVec3f SLNode::axisXOS ( ) const
inline

Returns the x-axis in object space

Definition at line 504 of file SLNode.h.

505 {
506  return _om.axisX();
507 }
SLVec3< T > axisX() const
Definition: SLMat4.h:185

◆ axisXWS()

SLVec3f SLNode::axisXWS ( ) const
inline

Returns the x-axis in world space

Definition at line 571 of file SLNode.h.

572 {
573  updateAndGetWM();
574  return _wm.axisX();
575 }
const SLMat4f & updateAndGetWM() const
Definition: SLNode.cpp:703

◆ axisYOS()

SLVec3f SLNode::axisYOS ( ) const
inline

Returns the y-axis in object space

Definition at line 513 of file SLNode.h.

514 {
515  return _om.axisY();
516 }
SLVec3< T > axisY() const
Definition: SLMat4.h:186

◆ axisYWS()

SLVec3f SLNode::axisYWS ( ) const
inline

Returns the y-axis in world space

Definition at line 581 of file SLNode.h.

582 {
583  updateAndGetWM();
584  return _wm.axisY();
585 }

◆ axisZOS()

SLVec3f SLNode::axisZOS ( ) const
inline

Returns the z-axis in object space

Definition at line 522 of file SLNode.h.

523 {
524  return _om.axisZ();
525 }
SLVec3< T > axisZ() const
Definition: SLMat4.h:187

◆ axisZWS()

SLVec3f SLNode::axisZWS ( ) const
inline

Returns the z-axis in world space

Definition at line 591 of file SLNode.h.

592 {
593  updateAndGetWM();
594  return _wm.axisZ();
595 }

◆ castsShadows() [1/2]

SLbool SLNode::castsShadows ( )
inline

Definition at line 303 of file SLNode.h.

303 { return _castsShadows; }

◆ castsShadows() [2/2]

void SLNode::castsShadows ( SLbool  castsShadows)
inline

Definition at line 282 of file SLNode.h.

SLbool castsShadows()
Definition: SLNode.h:303

◆ children()

SLVNode& SLNode::children ( )
inline

Definition at line 305 of file SLNode.h.

305 { return _children; }

◆ copyRec()

SLNode * SLNode::copyRec ( )
virtual

Returns a deep copy of the node and its children recursively. The meshes do not get copied.

Definition at line 572 of file SLNode.cpp.

573 {
574  SLNode* copy = new SLNode(name());
575  copy->_om.setMatrix(_om);
576  copy->_depth = _depth;
579  copy->_drawBits = _drawBits;
580  copy->_aabb = _aabb;
582 
583  if (_animation)
584  copy->_animation = new SLAnimation(*_animation);
585  else
586  copy->_animation = nullptr;
587 
588  if (_mesh)
589  copy->addMesh(_mesh);
590 
591  for (auto* child : _children)
592  copy->addChild(child->copyRec());
593 
594  return copy;
595 }
SLAnimation is the base container for all animation data.
Definition: SLAnimation.h:33
void setMatrix(const SLMat4 &A)
Set matrix by other 4x4 matrix.
Definition: SLMat4.h:335
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:147
void addChild(SLNode *child)
Definition: SLNode.cpp:207
SLNode(const SLstring &name="Node")
Construct a new SLNode::SLNode object.
Definition: SLNode.cpp:40

◆ cull2DRec()

void SLNode::cull2DRec ( SLSceneView sv)
virtual

Does the 2D frustum culling. If a node is visible its mesh material is added to the SLSceneview::_visibleMaterials2D set and the node to the SLMaterials::nodesVisible2D vector. See also SLSceneView::draw3DGLAll for more details.

Definition at line 455 of file SLNode.cpp.

456 {
457  // PROFILE_FUNCTION();
458 
459  _aabb.isVisible(true);
460 
461  // Cull the group nodes recursively
462  for (auto* child : _children)
463  child->cull2DRec(sv);
464 
465  // Add all nodes to the opaque 2D vector
466  if (this->mesh())
467  {
468  sv->visibleMaterials2D().insert(this->mesh()->mat());
469  this->mesh()->mat()->nodesVisible2D().push_back(this);
470  }
471  else if (typeid(*this) == typeid(SLText))
472  sv->nodesBlended2D().push_back(this);
473 }
void isVisible(SLbool visible)
Definition: SLAABBox.h:44
SLVNode & nodesVisible2D()
Definition: SLMaterial.h:231
SLMaterial * mat() const
Definition: SLMesh.h:177
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
SLVNode & nodesBlended2D()
Definition: SLSceneView.h:192
std::unordered_set< SLMaterial * > & visibleMaterials2D()
Definition: SLSceneView.h:208
SLText creates a mesh using a textured font from SLTexFont.
Definition: SLText.h:30

◆ cull3DRec()

void SLNode::cull3DRec ( SLSceneView sv)
virtual

Does the view frustum culling by checking whether the AABB is inside the 3D cameras view frustum. The check is done in world space. If a AABB is visible the nodes children are checked recursively. If a node is visible its mesh material is added to the SLSceneview::_visibleMaterials3D set and the node to the SLMaterials::nodesVisible3D vector. See also SLSceneView::draw3DGLAll for more details.

Definition at line 397 of file SLNode.cpp.

398 {
399  if (!this->drawBit(SL_DB_HIDDEN))
400  {
401  // Do frustum culling for all shapes except cameras & lights
402  if (sv->doFrustumCulling() &&
403  _parent != nullptr && // hsm4: do not frustum check the root node
404  !dynamic_cast<SLCamera*>(this) && // Ghm1: Checking for typeid fails if someone adds a custom camera that inherits SLCamera
405  typeid(*this) != typeid(SLLightRect) &&
406  typeid(*this) != typeid(SLLightSpot) &&
407  typeid(*this) != typeid(SLLightDirect))
408  {
409  sv->camera()->isInFrustum(&_aabb);
410  }
411  else
412  _aabb.isVisible(true);
413 
414  // For particle system updating (Break, no update, setup to resume)
415  SLParticleSystem* tempPS = dynamic_cast<SLParticleSystem*>(this->mesh());
416  if (tempPS && !_aabb.isVisible())
417  tempPS->setNotVisibleInFrustum();
418 
419  // Cull the group nodes recursively
420  if (_aabb.isVisible())
421  {
423 
424  if (this->drawBit(SL_DB_OVERDRAW))
425  sv->nodesOverdrawn().push_back(this);
426  else
427  {
428  // All nodes with meshes get rendered sorted by their material
429  if (this->mesh())
430  {
431  sv->visibleMaterials3D().insert(this->mesh()->mat());
432  this->mesh()->mat()->nodesVisible3D().push_back(this);
433  }
434  else
435  {
436  // Add camera or selected node without mesh to opaque vector for line drawing
437  if (dynamic_cast<SLCamera*>(this) || this->_isSelected)
438  sv->nodesOpaque3D().push_back(this);
439 
440  // Add special text node to blended vector
441  else if (typeid(*this) == typeid(SLText))
442  sv->nodesBlended3D().push_back(this);
443  }
444  }
445  }
446  }
447 }
#define SL_DB_OVERDRAW
Draw node over all other nodes.
Definition: SLDrawBits.h:29
#define SL_DB_HIDDEN
Flags an object as hidden.
Definition: SLDrawBits.h:20
Active or visible camera node class.
Definition: SLCamera.h:54
SLLightDirect class for a directional light source.
Definition: SLLightDirect.h:40
Light node class for a rectangular light source.
Definition: SLLightRect.h:39
SLLightSpot class for a spot light source.
Definition: SLLightSpot.h:36
SLVNode & nodesVisible3D()
Definition: SLMaterial.h:232
SLbool drawBit(SLuint bit)
Definition: SLNode.h:300
virtual void cullChildren3D(SLSceneView *sv)
Initializer function to call SLNode::cull3DRec recursively.
Definition: SLNode.cpp:384
SLParticleSystem creates a particle meshes from a point primitive buffer.
SLVNode & nodesOpaque3D()
Definition: SLSceneView.h:189
std::unordered_set< SLMaterial * > & visibleMaterials3D()
Definition: SLSceneView.h:209
void camera(SLCamera *camera)
Definition: SLSceneView.h:145
SLVNode & nodesBlended3D()
Definition: SLSceneView.h:190
SLVNode & nodesOverdrawn()
Definition: SLSceneView.h:193
void doFrustumCulling(SLbool doFC)
Definition: SLSceneView.h:152

◆ cullChildren3D()

void SLNode::cullChildren3D ( SLSceneView sv)
virtual

Initializer function to call SLNode::cull3DRec recursively.

Reimplemented in SLNodeLOD.

Definition at line 384 of file SLNode.cpp.

385 {
386  for (auto* child : _children)
387  child->cull3DRec(sv);
388 }

◆ deleteChild() [1/3]

bool SLNode::deleteChild ( )

Deletes the last child in the child vector.

Definition at line 267 of file SLNode.cpp.

268 {
269  if (!_children.empty())
270  {
271  delete _children.back();
272  _children.pop_back();
273  _isAABBUpToDate = false;
274  return true;
275  }
276  return false;
277 }

◆ deleteChild() [2/3]

bool SLNode::deleteChild ( const SLstring name)

Searches for a child with the name 'name' and deletes it.

Definition at line 301 of file SLNode.cpp.

302 {
303  assert(!name.empty());
304  SLNode* found = findChild<SLNode>(name);
305  if (found) return deleteChild(found);
306  return false;
307 }
bool deleteChild()
Definition: SLNode.cpp:267

◆ deleteChild() [3/3]

bool SLNode::deleteChild ( SLNode child)

Deletes a child from the child vector.

Definition at line 282 of file SLNode.cpp.

283 {
284  assert(child);
285  for (SLulong i = 0; i < _children.size(); ++i)
286  {
287  if (_children[i] == child)
288  {
289  _children.erase(_children.begin() + (long)i);
290  delete child;
291  _isAABBUpToDate = false;
292  return true;
293  }
294  }
295  return false;
296 }
unsigned long SLulong
Definition: SL.h:165

◆ deleteChildren()

void SLNode::deleteChildren ( )

Deletes all child nodes.

Definition at line 248 of file SLNode.cpp.

249 {
250  for (auto& i : _children)
251  delete i;
252  _children.clear();
253 
254 #ifdef SL_USE_ENTITIES
255  SLint entityID = SLScene::entities.getEntityID(this);
256  SLint parentID = SLScene::entities.getParentID(this);
257  if (entityID != INT32_MIN && parentID != INT32_MIN)
258  {
259  SLScene::entities.deleteChildren(entityID);
260  }
261 #endif
262 }

◆ depth()

SLint SLNode::depth ( ) const
inline

Definition at line 293 of file SLNode.h.

293 { return _depth; }

◆ doUpdate()

virtual void SLNode::doUpdate ( )
inlinevirtual

Reimplemented in SLHorizonNode.

Definition at line 308 of file SLNode.h.

308 {}

◆ drawBit()

SLbool SLNode::drawBit ( SLuint  bit)
inline

Definition at line 300 of file SLNode.h.

300 { return _drawBits.get(bit); }
SLbool get(SLuint bit)
Returns the specified bit.
Definition: SLDrawBits.h:69

◆ drawBits()

SLDrawBits* SLNode::drawBits ( )
inline

Definition at line 299 of file SLNode.h.

299 { return &_drawBits; }

◆ drawMesh()

void SLNode::drawMesh ( SLSceneView sv)
virtual

Draws the single mesh.

Inserts a mesh pointer in the mesh pointer vector after the specified afterM pointer.

Reimplemented in SLText, SLLightSpot, SLLightRect, SLLightDirect, SLCamera, and SLKeyframeCamera.

Definition at line 176 of file SLNode.cpp.

177 {
178  if (_mesh)
179  _mesh->draw(sv, this);
180 }
virtual void draw(SLSceneView *sv, SLNode *node, SLuint intances=0)
Definition: SLMesh.cpp:389

◆ dumpRec()

void SLNode::dumpRec ( )
virtual

Prints the node name with the names of the meshes recursively

Definition at line 775 of file SLNode.cpp.

776 {
777  // dump node
778  for (SLint i = 0; i < _depth; ++i)
779  cout << " ";
780  cout << "Node: " << _name << endl;
781 
782  // dump meshes of node
783  for (SLint i = 0; i < _depth; ++i)
784  cout << " ";
785 
786  if (_mesh)
787  {
788  cout << "- Mesh: " << _mesh->name();
789  cout << ", " << _mesh->numI() * 3 << " tri";
790  if (_mesh->mat())
791  cout << ", Mat: " << _mesh->mat()->name();
792  }
793  else
794  cout << "- Mesh: none";
795  cout << endl;
796 
797  // dump children nodes
798  for (auto* child : _children)
799  child->dumpRec();
800 }
SLuint numI() const
Definition: SLMesh.h:181

◆ entityID() [1/2]

SLint SLNode::entityID ( ) const
inline

Definition at line 294 of file SLNode.h.

294 { return _entityID; }

◆ entityID() [2/2]

void SLNode::entityID ( SLint  entityID)
inline

Definition at line 275 of file SLNode.h.

275 { _entityID = entityID; }

◆ find()

template<typename T >
T * SLNode::find ( const SLstring name = "",
SLbool  findRecursive = true 
)

SLNode::findChild<T> searches a node tree including the node by a given name.

Definition at line 376 of file SLNode.h.

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 }

◆ findChild()

template<typename T >
T * SLNode::findChild ( const SLstring name = "",
SLbool  findRecursive = true 
)

SLNode::findChild<T> finds the first child that is of type T or a subclass of T.

Definition at line 388 of file SLNode.h.

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 }

◆ findChildren() [1/3]

std::deque< SLNode * > SLNode::findChildren ( const SLMesh mesh,
SLbool  findRecursive = true 
)

Searches for all nodes that contain the provided mesh

Definition at line 313 of file SLNode.cpp.

315 {
316  std::deque<SLNode*> list;
317  findChildrenHelper(mesh, list, findRecursive);
318 
319  return list;
320 }
void findChildrenHelper(const SLstring &name, deque< T * > &list, SLbool findRecursive, SLbool canContain=false)
Definition: SLNode.h:431

◆ findChildren() [2/3]

template<typename T >
deque< T * > SLNode::findChildren ( const SLstring name = "",
SLbool  findRecursive = true,
SLbool  canContain = false 
)

SLNode::findChildren<T> finds a list of all children that are of type T or subclasses of T. If a name is specified only nodes with that name are included.

Definition at line 416 of file SLNode.h.

419 {
420  deque<T*> list;
421  findChildrenHelper<T>(name, list, findRecursive);
422  return list;
423 }

◆ findChildren() [3/3]

deque< SLNode * > SLNode::findChildren ( SLuint  drawbit,
SLbool  findRecursive = true 
)

Searches for all nodes that contain the provided mesh

Definition at line 342 of file SLNode.cpp.

344 {
345  deque<SLNode*> list;
346  findChildrenHelper(drawbit, list, findRecursive);
347  return list;
348 }

◆ findChildrenHelper() [1/3]

void SLNode::findChildrenHelper ( const SLMesh mesh,
deque< SLNode * > &  list,
SLbool  findRecursive 
)
private

Helper function of findChildren for the passed mesh pointer

Definition at line 325 of file SLNode.cpp.

328 {
329  for (auto* child : _children)
330  {
331  if (child->_mesh == mesh)
332  list.push_back(child);
333  if (findRecursive)
334  child->findChildrenHelper(mesh, list, findRecursive);
335  }
336 }

◆ findChildrenHelper() [2/3]

template<typename T >
void SLNode::findChildrenHelper ( const SLstring name,
deque< T * > &  list,
SLbool  findRecursive,
SLbool  canContain = false 
)
private

SLNode::findChildrenHelper<T> is the helper function for findChildren<T>. It appends all newly found children to 'list'.

Definition at line 431 of file SLNode.h.

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 }
bool containsString(const string &container, const string &search)
Returns true if container contains the search string.
Definition: Utils.cpp:345

◆ findChildrenHelper() [3/3]

void SLNode::findChildrenHelper ( SLuint  drawbit,
deque< SLNode * > &  list,
SLbool  findRecursive 
)
private

Helper function of findChildren for passed drawing bit

Definition at line 353 of file SLNode.cpp.

356 {
357  for (auto* child : _children)
358  {
359  if (child->drawBits()->get(drawbit))
360  list.push_back(child);
361  if (findRecursive)
362  child->findChildrenHelper(drawbit, list, findRecursive);
363  }
364 }

◆ forwardOS()

SLVec3f SLNode::forwardOS ( ) const
inline

Returns the local forward vector (= -z-axis) in a right-hand y-up system

Definition at line 477 of file SLNode.h.

478 {
479  return SLVec3f(-_om.m(8), -_om.m(9), -_om.m(10));
480 }
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318
void m(int i, T val)
Definition: SLMat4.h:93

◆ forwardWS()

SLVec3f SLNode::forwardWS ( ) const
inline

SLNode::forward returns worlds forward vector

Definition at line 541 of file SLNode.h.

542 {
543  updateAndGetWM();
544  return -_wm.axisZ();
545 }

◆ hitRec()

bool SLNode::hitRec ( SLRay ray)
virtual

Intersects the nodes meshes with the given ray. The intersection test is only done if the AABB is intersected. The ray-mesh intersection is done in the nodes object space. The rays origin and direction is therefore transformed into the object space.

Reimplemented in SLText, SLLightSpot, SLLightRect, and SLLightDirect.

Definition at line 508 of file SLNode.cpp.

509 {
510  assert(ray != nullptr);
511 
512  // Do not test hidden nodes
514  return false;
515 
516  // Do not test origin node for shadow rays
517  // This restriction is not valid for objects that can shadow itself
518  // if (this == ray->srcNode && ray->type == SHADOW)
519  // return false;
520 
521  // Check first AABB for intersection
522  if (!_aabb.isHitInWS(ray))
523  return false;
524 
525  SLbool meshWasHit = false;
526 
527  // Transform ray to object space for non-groups
528  if (_mesh == nullptr)
529  {
530  // Special selection for cameras
531  if (dynamic_cast<SLCamera*>(this) && ray->sv->camera() != this)
532  {
533  ray->hitNode = this;
534  ray->hitMesh = nullptr;
535  SLVec3f OC = _aabb.centerWS() - ray->origin;
536  ray->length = OC.length();
537  return true;
538  }
539  }
540  else
541  {
542  // transform origin position to object space
543  ray->originOS.set(updateAndGetWMI().multVec(ray->origin));
544 
545  // transform the direction only with the linear sub matrix
546  ray->setDirOS(_wmI.mat3() * ray->dir);
547 
548  // test the mesh
549  if (_mesh->hit(ray, this) && !meshWasHit)
550  meshWasHit = true;
551 
552  if (ray->isShaded())
553  return true;
554  }
555 
556  // Test children nodes
557  for (auto* child : _children)
558  {
559  if (child->hitRec(ray) && !meshWasHit)
560  meshWasHit = true;
561  if (ray->isShaded())
562  return true;
563  }
564 
565  return meshWasHit;
566 }
bool SLbool
Definition: SL.h:175
SLVec3f centerWS()
Definition: SLAABBox.h:50
SLbool isHitInWS(SLRay *ray)
SLAABBox::isHitInWS: Ray - AABB Intersection Test in world space.
Definition: SLAABBox.cpp:361
SLMat3< T > mat3() const
Definition: SLMat4.h:98
SLbool hit(SLRay *ray, SLNode *node)
Definition: SLMesh.cpp:910
const SLMat4f & updateAndGetWMI() const
Definition: SLNode.cpp:714
SLVec3f origin
Vector to the origin of ray in WS.
Definition: SLRay.h:75
SLMesh * hitMesh
Points to the intersected mesh.
Definition: SLRay.h:106
SLVec3f dir
Direction vector of ray in WS.
Definition: SLRay.h:76
SLfloat length
length from origin to an intersection
Definition: SLRay.h:77
SLNode * hitNode
Points to the intersected node.
Definition: SLRay.h:105
void setDirOS(const SLVec3f &Dir)
Setter for the rays direction in object space also setting the inverse direction.
Definition: SLRay.h:159
SLVec3f originOS
Vector to the origin of ray in OS.
Definition: SLRay.h:80
SLSceneView * sv
Pointer to the sceneview.
Definition: SLRay.h:101
SLbool isShaded() const
Returns true if a shadow ray hits an object on the ray to the light.
Definition: SLRay.h:187
T length() const
Definition: SLVec3.h:122
void set(const T X, const T Y, const T Z)
Definition: SLVec3.h:59

◆ initialOM()

const SLMat4f& SLNode::initialOM ( )
inline

Definition at line 296 of file SLNode.h.

296 { return _initialOM; }
SLMat4f _initialOM
the initial om state
Definition: SLNode.h:351

◆ insertChild()

bool SLNode::insertChild ( SLNode insertC,
SLNode afterC 
)

Inserts a child node in the children vector after the afterC node.

Definition at line 229 of file SLNode.cpp.

230 {
231  assert(insertC && afterC);
232  assert(insertC != afterC);
233 
234  auto found = std::find(_children.begin(), _children.end(), afterC);
235  if (found != _children.end())
236  {
237  _children.insert(found, insertC);
238  insertC->parent(this);
239  _isAABBUpToDate = false;
240  return true;
241  }
242  return false;
243 }

◆ isSelected() [1/2]

bool SLNode::isSelected ( )
inline

Definition at line 315 of file SLNode.h.

315 { return _isSelected; }

◆ isSelected() [2/2]

void SLNode::isSelected ( bool  isSelected)
inline

Definition at line 286 of file SLNode.h.

286 { _isSelected = isSelected; }
bool isSelected()
Definition: SLNode.h:315

◆ levelForSM() [1/2]

SLubyte SLNode::levelForSM ( )
inline

Definition at line 317 of file SLNode.h.

317 { return _levelForSM; }

◆ levelForSM() [2/2]

void SLNode::levelForSM ( SLubyte  lfsm)
inline

Definition at line 288 of file SLNode.h.

288 { _levelForSM = lfsm; }

◆ lookAt() [1/2]

void SLNode::lookAt ( const SLVec3f target,
const SLVec3f up = SLVec3f::AXISY,
SLTransformSpace  relativeTo = TS_world 
)

Rotates the object so that it's forward vector is pointing towards the 'target' point. Default forward is -Z. The 'relativeTo' parameter defines in what space the 'target' parameter is to be interpreted in.

Definition at line 1023 of file SLNode.cpp.

1026 {
1027  SLVec3f pos = translationOS();
1028  SLVec3f dir;
1029  SLVec3f localUp = up;
1030 
1031  if (relativeTo == TS_world && _parent)
1032  {
1033  SLVec3f localTarget = _parent->updateAndGetWMI() * target;
1034  localUp = _parent->updateAndGetWMI().mat3() * up;
1035  dir = localTarget - translationOS();
1036  }
1037  else if (relativeTo == TS_object)
1038  dir = _om * target - translationOS();
1039  else
1040  dir = target - translationOS();
1041 
1042  dir.normalize();
1043 
1044  SLfloat cosAngle = localUp.dot(dir);
1045 
1046  // dir and up are parallel and facing in the same direction
1047  // or facing in opposite directions.
1048  // in this case we just rotate the up vector by 90� around
1049  // our current right vector
1050  // @todo This check might make more sense to be in Mat3.posAtUp
1051  if (fabs(cosAngle - 1.0) <= FLT_EPSILON || fabs(cosAngle + 1.0) <= FLT_EPSILON)
1052  {
1053  SLMat3f rot;
1054  rot.rotation(-90.0f, rightOS());
1055 
1056  localUp = rot * localUp;
1057  }
1058 
1059  _om.posAtUp(pos, pos + dir, localUp);
1060 
1061  needUpdate();
1062 }
float SLfloat
Definition: SL.h:173
@ TS_world
Definition: SLEnums.h:208
@ TS_object
Definition: SLEnums.h:210
void rotation(const T angleDEG, const SLVec3< T > &axis)
Sets the rotation components
Definition: SLMat3.h:392
void posAtUp(T PosX, T PosY, T PosZ, T dirAtX=0, T dirAtY=0, T dirAtZ=0, T dirUpX=0, T dirUpY=0, T dirUpZ=0)
Same as lightAt.
Definition: SLMat4.h:822
virtual void needUpdate()
Definition: SLNode.cpp:616
SLVec3f rightOS() const
Definition: SLNode.h:486
SLVec3f translationOS() const
Definition: SLNode.h:468
SLVec3 & normalize()
Definition: SLVec3.h:124
T dot(const SLVec3 &v) const
Definition: SLVec3.h:117

◆ lookAt() [2/2]

void SLNode::lookAt ( SLfloat  targetX,
SLfloat  targetY,
SLfloat  targetZ,
SLfloat  upX = 0,
SLfloat  upY = 1,
SLfloat  upZ = 0,
SLTransformSpace  relativeTo = TS_world 
)
inline

Definition at line 652 of file SLNode.h.

659 {
660  lookAt(SLVec3f(targetX,
661  targetY,
662  targetZ),
663  SLVec3f(upX, upY, upZ),
664  relativeTo);
665 }
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

◆ mesh()

SLMesh* SLNode::mesh ( )
inline

Definition at line 304 of file SLNode.h.

304 { return _mesh; }

◆ minLodCoverage() [1/2]

SLfloat SLNode::minLodCoverage ( )
inline

Definition at line 316 of file SLNode.h.

316 { return _minLodCoverage; }

◆ minLodCoverage() [2/2]

void SLNode::minLodCoverage ( SLfloat  minLodCoverage)
inline

Definition at line 287 of file SLNode.h.

SLfloat minLodCoverage()
Definition: SLNode.h:316

◆ needAABBUpdate()

void SLNode::needAABBUpdate ( )

Flags this node's AABB for an updateRec. If a node changed we need to updateRec it's world space AABB. This needs to also be propagated up the parent chain since the AABB of a node incorporates the AABB's of child nodes.

Definition at line 665 of file SLNode.cpp.

666 {
667  // stop if we reach a node that is already flagged.
668  if (!_isAABBUpToDate)
669  return;
670 
671  _isAABBUpToDate = false;
672 
673  // flag parent's for an AABB updateRec too since they need to
674  // merge the child AABBs
675  if (_parent)
677 }
void needAABBUpdate()
Definition: SLNode.cpp:665

◆ needUpdate()

void SLNode::needUpdate ( )
virtual

Flags this node for an updateRec. This function is called automatically if the local transform of the node or of its parent changed. Nodes that are flagged for updating will recalculate their world transform the next time it is requested by updateAndGetWM().

Reimplemented in SLJoint.

Definition at line 616 of file SLNode.cpp.

617 {
618 #ifdef SL_USE_ENTITIES
619  if (_entityID != INT32_MIN)
620  SLScene::entities.getEntity(_entityID)->om.setMatrix(_om);
621 #endif
622 
623  // stop if we reach a node that is already flagged.
624  if (!_isWMUpToDate)
625  return;
626 
627  _isWMUpToDate = false;
628  _isWMIUpToDate = false;
629 
630  // mark the WM of the children dirty since their parent just changed
631  for (auto* child : _children)
632  child->needUpdate();
633 
634  // flag AABB for an updateRec
635  needAABBUpdate();
636 }

◆ needWMUpdate()

void SLNode::needWMUpdate ( )

Flags this node for a wm updateRec. It is almost identical to the needUpdate function but it won't flag AABBs. This function is currently not in use but could give a slight performance boost if it was called instead of needUpdate for the children of a node that changed.

Definition at line 645 of file SLNode.cpp.

646 {
647  // stop if we reach a node that is already flagged.
648  if (!_isWMUpToDate)
649  return;
650 
651  _isWMUpToDate = false;
652  _isWMIUpToDate = false;
653 
654  // mark the WM of the children dirty since their parent just changed
655  for (auto* child : _children)
656  child->needWMUpdate();
657 }

◆ numChildren()

SLint SLNode::numChildren ( )
inline

Definition at line 175 of file SLNode.h.

175 { return (SLint)_children.size(); }

◆ om() [1/2]

const SLMat4f& SLNode::om ( )
inline

Definition at line 295 of file SLNode.h.

295 { return _om; }

◆ om() [2/2]

void SLNode::om ( const SLMat4f mat)
inline

Definition at line 276 of file SLNode.h.

277  {
278  _om.setMatrix(mat);
279  needUpdate();
280  }

◆ onUpdateCB()

void SLNode::onUpdateCB ( function< void()>  callbackFunc)
inline

Definition at line 289 of file SLNode.h.

289 { _onUpdateCB = callbackFunc; }
function< void()> _onUpdateCB
Optional lambda callback once per update.
Definition: SLNode.h:364

◆ parent() [1/2]

SLNode* SLNode::parent ( )
inline

Definition at line 292 of file SLNode.h.

292 { return _parent; }

◆ parent() [2/2]

void SLNode::parent ( SLNode p)

Sets the parent for this node and updates its depth

Definition at line 600 of file SLNode.cpp.

601 {
602  _parent = p;
603 
604  if (_parent)
605  _depth = _parent->depth() + 1;
606  else
607  _depth = 1;
608 }
SLint depth() const
Definition: SLNode.h:293

◆ removeChild()

bool SLNode::removeChild ( SLNode child)

remove child from vector of children. Removes false if not found, else true.

Definition at line 367 of file SLNode.cpp.

368 {
369  assert(child);
370  for (auto it = _children.begin(); it != _children.end(); ++it)
371  {
372  if (*it == child)
373  {
374  (*it)->parent(nullptr);
375  _children.erase(it);
376  return true;
377  }
378  }
379 
380  return false;
381 }

◆ removeMesh() [1/2]

bool SLNode::removeMesh ( )

Returns true if a mesh was assigned and set it to nullptr.

Definition at line 183 of file SLNode.cpp.

184 {
185  if (_mesh)
186  {
187  _mesh = nullptr;
188  return true;
189  }
190  return false;
191 }

◆ removeMesh() [2/2]

bool SLNode::removeMesh ( SLMesh mesh)

Returns true if the passed mesh was assigned and sets it to nullptr.

Definition at line 194 of file SLNode.cpp.

195 {
196  if (_mesh == mesh && mesh != nullptr)
197  {
198  _mesh = nullptr;
199  return true;
200  }
201  return false;
202 }

◆ resetToInitialState()

void SLNode::resetToInitialState ( )

Resets this object to its initial state

Definition at line 1092 of file SLNode.cpp.

1093 {
1095  needUpdate();
1096 }

◆ rightOS()

SLVec3f SLNode::rightOS ( ) const
inline

Returns the local right vector (= x-axis) in a right-hand y-up system

Definition at line 486 of file SLNode.h.

487 {
488  return SLVec3f(_om.m(0), _om.m(1), _om.m(2));
489 }

◆ rightWS()

SLVec3f SLNode::rightWS ( ) const
inline

SLNode::right returns worlds right vector

Definition at line 551 of file SLNode.h.

552 {
553  updateAndGetWM();
554  return _wm.axisX();
555 }

◆ rotate() [1/3]

void SLNode::rotate ( const SLQuat4f rot,
SLTransformSpace  relativeTo = TS_object 
)

Rotates the node around its local origin relative to the space expressed by 'relativeTo'.

Definition at line 945 of file SLNode.cpp.

946 {
947  SLMat4f rotation = rot.toMat4();
948 
949  if (relativeTo == TS_object)
950  {
952  }
953  else if (_parent && relativeTo == TS_world)
954  {
955  SLMat4f rotWS;
957  rotWS.multiply(rotation);
959 
961  }
962  else // relativeTo == TS_Parent || relativeTo == TS_World && !_parent
963  {
964  SLMat4f rotOS;
965  rotOS.translate(translationOS());
966  rotOS.multiply(rotation);
967  rotOS.translate(-translationOS());
968 
969  _om.setMatrix(rotOS * _om);
970  }
971 
972  needUpdate();
973 }
void multiply(const SLMat4 &A)
Definition: SLMat4.h:536
SLMat4< T > inverted() const
Computes the inverse of a 4x4 non-singular matrix.
Definition: SLMat4.h:1371
void rotation(const SLQuat4f &rot, SLTransformSpace relativeTo=TS_parent)
Definition: SLNode.cpp:846
SLMat4< T > toMat4() const
Definition: SLQuat4.h:337

◆ rotate() [2/3]

void SLNode::rotate ( SLfloat  angleDeg,
const SLVec3f axis,
SLTransformSpace  relativeTo = TS_object 
)

Rotates the node around its local origin relative to the space expressed by 'relativeTo'.

Definition at line 934 of file SLNode.cpp.

937 {
938  SLQuat4f rot(angleDeg, axis);
939  rotate(rot, relativeTo);
940 }
void rotate(const SLQuat4f &rot, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:945

◆ rotate() [3/3]

void SLNode::rotate ( SLfloat  angleDeg,
SLfloat  x,
SLfloat  y,
SLfloat  z,
SLTransformSpace  relativeTo = TS_object 
)
inline

Definition at line 630 of file SLNode.h.

635 {
636  rotate(angleDeg, SLVec3f(x, y, z), relativeTo);
637 }

◆ rotateAround()

void SLNode::rotateAround ( const SLVec3f point,
SLVec3f axis,
SLfloat  angleDeg,
SLTransformSpace  relativeTo = TS_world 
)

Rotates the node around an arbitrary point. The 'axis' and 'point' parameter are relative to the space described by 'relativeTo'.

Definition at line 979 of file SLNode.cpp.

983 {
984  SLVec3f localPoint = point;
985  SLVec3f localAxis = axis;
986 
987  if (relativeTo == TS_world && _parent)
988  {
989  localPoint = _parent->updateAndGetWMI() * point;
990  localAxis = _parent->updateAndGetWMI().mat3() * axis;
991  }
992 
993  SLMat4f rot;
994  rot.translate(localPoint);
995  rot.rotate(angleDeg, localAxis);
996  rot.translate(-localPoint);
997 
998  if (relativeTo == TS_object)
999  _om.setMatrix(_om * rot);
1000  else
1001  _om.setMatrix(rot * _om);
1002 
1003  needUpdate();
1004 }
void rotate(T degAng, T axisx, T axisy, T axisz)
Definition: SLMat4.h:656

◆ rotation() [1/2]

void SLNode::rotation ( const SLQuat4f rot,
SLTransformSpace  relativeTo = TS_parent 
)

sets the rotation of this node. The axis parameter will be transformed into 'relativeTo' space. So an passing in an axis of (0, 1, 0) with TS_Object will rotate the node around its own up axis.

Definition at line 846 of file SLNode.cpp.

848 {
849  SLMat4f rotation = rot.toMat4();
850 
851  if (_parent && relativeTo == TS_world)
852  {
853  // get the inverse parent rotation to remove it from our current rotation
854  // we want the input quaternion to absolutely set our new rotation relative
855  // to the world axes
856  SLMat4f parentRotInv = _parent->updateAndGetWMI();
857  parentRotInv.translation(0, 0, 0);
858 
859  // set the om rotation to the inverse of the parents rotation to achieve a
860  // 0, 0, 0 relative rotation in world space
861  _om.rotation(0, 0, 0, 0);
862  _om.setMatrix(_om * parentRotInv);
863  rotate(rot, relativeTo);
864  }
865  else if (relativeTo == TS_parent)
866  { // relative to parent, reset current rotation and just rotate again
867  _om.rotation(0, 0, 0, 0);
868  rotate(rot, relativeTo);
869  }
870  else
871  {
872  // in TS_Object everything is relative to our current orientation
873  _om.rotation(0, 0, 0, 0);
875  }
876  needUpdate();
877 }
@ TS_parent
Definition: SLEnums.h:209
SLVec3< T > translation() const
Definition: SLMat4.h:184
void rotation(T degAng, const SLVec3< T > &axis, SLbool keepTranslation=true)
Sets the rotation with or without overwriting the translation.
Definition: SLMat4.h:978

◆ rotation() [2/2]

void SLNode::rotation ( SLfloat  angleDeg,
const SLVec3f axis,
SLTransformSpace  relativeTo = TS_parent 
)

sets the rotation of this node. The axis parameter will be transformed into 'relativeTo' space. So a passing in an axis of (0, 1, 0) with TS_Object will rotate the node around its own up axis.

Definition at line 884 of file SLNode.cpp.

887 {
888  SLQuat4f rot(angleDeg, axis);
889  rotation(rot, relativeTo);
890 }

◆ scale() [1/3]

void SLNode::scale ( const SLVec3f scale)

Adds a scale transform to the current object matrix

Note
this is not a setter but a scale modifier.
this modifier doesn't allow for different transform spaces, so there isn't the possibility for shearing an object currently.

Definition at line 1012 of file SLNode.cpp.

1013 {
1014  _om.scale(scale);
1015  needUpdate();
1016 }
void scale(T sxyz)
Definition: SLMat4.h:667
void scale(SLfloat s)
Definition: SLNode.h:640

◆ scale() [2/3]

void SLNode::scale ( SLfloat  s)
inline

Definition at line 640 of file SLNode.h.

641 {
642  scale(SLVec3f(s, s, s));
643 }
The SLScene class represents the top level instance holding the scene structure.
Definition: SLScene.h:47

◆ scale() [3/3]

void SLNode::scale ( SLfloat  x,
SLfloat  y,
SLfloat  z 
)
inline

Definition at line 646 of file SLNode.h.

647 {
648  scale(SLVec3f(x, y, z));
649 }

◆ scaleToCenter()

void SLNode::scaleToCenter ( SLfloat  maxDim)

Scales and translates the node so that its largest dimension is maxDim and the center is in [0,0,0].

Definition at line 1068 of file SLNode.cpp.

1069 {
1070  _aabb = updateAABBRec(true);
1071  SLVec3f size(_aabb.maxWS() - _aabb.minWS());
1072  SLVec3f center((_aabb.maxWS() + _aabb.minWS()) * 0.5f);
1073  SLfloat scaleFactor = maxDim / size.maxXYZ();
1074  if (fabs(scaleFactor) > FLT_EPSILON)
1075  scale(scaleFactor);
1076  else
1077  cout << "Node can't be scaled: " << name().c_str() << endl;
1078  translate(-center);
1079 }
void minWS(const SLVec3f &minC)
Definition: SLAABBox.h:39
void maxWS(const SLVec3f &maxC)
Definition: SLAABBox.h:40
virtual SLAABBox & updateAABBRec(SLbool updateAlsoAABBinOS)
Definition: SLNode.cpp:731
void translate(const SLVec3f &vec, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:906

◆ scaling() [1/3]

void SLNode::scaling ( const SLVec3f scaling)

Sets the scaling of current object matrix

Note
this modifier doesn't allow for different transform spaces, so there isn't the possiblity for shearing an object currently.

Definition at line 897 of file SLNode.cpp.

898 {
900  needUpdate();
901 }
void scaling(T sxyz, SLbool keepTrans=true)
Sets the scaling with or without overwriting the translation.
Definition: SLMat4.h:1146
void scaling(SLfloat s)
Definition: SLNode.h:607

◆ scaling() [2/3]

void SLNode::scaling ( SLfloat  s)
inline

Definition at line 607 of file SLNode.h.

608 {
609  scaling(SLVec3f(s, s, s));
610 }

◆ scaling() [3/3]

void SLNode::scaling ( SLfloat  x,
SLfloat  y,
SLfloat  z 
)
inline

Definition at line 613 of file SLNode.h.

616 {
617  scaling(SLVec3f(x, y, z));
618 }

◆ setDrawBitsRec()

void SLNode::setDrawBitsRec ( SLuint  bit,
SLbool  state 
)

Recursively sets the specified drawbit on or off. See also SLDrawBits.

Definition at line 804 of file SLNode.cpp.

805 {
806  _drawBits.set(bit, state);
807  for (auto* child : _children)
808  child->setDrawBitsRec(bit, state);
809 }
void set(SLuint bit, SLbool state)
Sets the specified bit to the passed state.
Definition: SLDrawBits.h:57

◆ setInitialState()

void SLNode::setInitialState ( )

Saves the current position as the initial state

Definition at line 1084 of file SLNode.cpp.

1085 {
1086  _initialOM = _om;
1087 }

◆ setMeshMat()

void SLNode::setMeshMat ( SLMaterial mat,
bool  recursive 
)

Set the mesh material recursively.

Definition at line 1172 of file SLNode.cpp.

1173 {
1174  if (_mesh)
1175  _mesh->mat(mat);
1176 
1177  if (recursive)
1178  for (auto* child : _children)
1179  child->setMeshMat(mat, recursive);
1180 }

◆ setPrimitiveTypeRec()

void SLNode::setPrimitiveTypeRec ( SLGLPrimitiveType  primitiveType)

Recursively sets the specified OpenGL primitive type.

Definition at line 813 of file SLNode.cpp.

814 {
815  for (auto* child : _children)
816  child->setPrimitiveTypeRec(primitiveType);
817 
818  _mesh->primitive(primitiveType);
819 }
SLGLPrimitiveType primitive() const
Definition: SLMesh.h:179

◆ skeleton()

const SLAnimSkeleton * SLNode::skeleton ( )

Returns the first skeleton found in the meshes.

Definition at line 1100 of file SLNode.cpp.

1101 {
1102  if (_mesh && _mesh->skeleton())
1103  return _mesh->skeleton();
1104  return nullptr;
1105 }
const SLAnimSkeleton * skeleton() const
Definition: SLMesh.h:180

◆ statsRec()

void SLNode::statsRec ( SLNodeStats stats)
virtual

Updates the statistic numbers of the passed SLNodeStats struct and calls recursively the same method for all children.

Reimplemented in SLText, SLLightSpot, SLLightRect, SLLightDirect, and SLCamera.

Definition at line 479 of file SLNode.cpp.

480 {
481  // PROFILE_FUNCTION();
482 
483  stats.numBytes += sizeof(SLNode);
484  stats.numNodes++;
485 
486  if (_children.empty())
487  stats.numNodesLeaf++;
488  else
489  stats.numNodesGroup++;
490 
491  if (typeid(*this) == typeid(SLLightSpot)) stats.numLights++;
492  if (typeid(*this) == typeid(SLLightRect)) stats.numLights++;
493  if (typeid(*this) == typeid(SLLightDirect)) stats.numLights++;
494 
495  if (_mesh)
496  _mesh->addStats(stats);
497 
498  for (auto* child : _children)
499  child->statsRec(stats);
500 }
void addStats(SLNodeStats &stats)
Definition: SLMesh.cpp:950
SLuint numNodes
NO. of children nodes.
Definition: SLNode.h:38
SLuint numLights
NO. of lights in mesh.
Definition: SLNode.h:46
SLuint numNodesLeaf
NO. of leaf nodes.
Definition: SLNode.h:42
SLuint numNodesGroup
NO. of group nodes.
Definition: SLNode.h:41
SLuint numBytes
NO. of bytes allocated.
Definition: SLNode.h:39

◆ translate() [1/2]

void SLNode::translate ( const SLVec3f delta,
SLTransformSpace  relativeTo = TS_object 
)

Moves the node by the vector 'delta' relative to the space expressed by 'relativeTo'.

Definition at line 906 of file SLNode.cpp.

907 {
908  switch (relativeTo)
909  {
910  case TS_object:
911  _om.translate(delta);
912  break;
913 
914  case TS_world:
915  if (_parent)
916  {
917  SLVec3f localVec = _parent->updateAndGetWMI().mat3() * delta;
918  _om.translation(localVec + _om.translation());
919  }
920  else
921  _om.translation(delta + _om.translation());
922  break;
923 
924  case TS_parent:
925  _om.translation(delta + _om.translation());
926  break;
927  }
928  needUpdate();
929 }

◆ translate() [2/2]

void SLNode::translate ( SLfloat  x,
SLfloat  y,
SLfloat  z,
SLTransformSpace  relativeTo = TS_object 
)
inline

Definition at line 621 of file SLNode.h.

625 {
626  translate(SLVec3f(x, y, z), relativeTo);
627 }

◆ translation() [1/2]

void SLNode::translation ( const SLVec3f pos,
SLTransformSpace  relativeTo = TS_parent 
)

sets the position of this node to pos in 'relativeTo' space.

Note
using TS_Object for this function yields the same result as calling translate(pos, TS_Object)

Definition at line 828 of file SLNode.cpp.

829 {
830  if (relativeTo == TS_world && _parent)
831  { // transform position to local space
832  SLVec3f localPos = _parent->updateAndGetWMI() * pos;
833  _om.translation(localPos);
834  }
835  else
836  _om.translation(pos);
837 
838  needUpdate();
839 }

◆ translation() [2/2]

void SLNode::translation ( SLfloat  x,
SLfloat  y,
SLfloat  z,
SLTransformSpace  relativeTo = TS_parent 
)
inline

Definition at line 598 of file SLNode.h.

602 {
603  translation(SLVec3f(x, y, z), relativeTo);
604 }

◆ translationOS()

SLVec3f SLNode::translationOS ( ) const
inline

SLNode::position returns current local position

Definition at line 468 of file SLNode.h.

469 {
470  return _om.translation();
471 }

◆ translationWS()

SLVec3f SLNode::translationWS ( ) const
inline

SLNode::position returns current world position

Definition at line 531 of file SLNode.h.

532 {
533  updateAndGetWM();
534  return _wm.translation();
535 }

◆ updateAABBRec()

SLAABBox & SLNode::updateAABBRec ( SLbool  updateAlsoAABBinOS)
virtual

Updates the axis aligned bounding box in world space recursively.

Reimplemented in SLText.

Definition at line 731 of file SLNode.cpp.

732 {
733  if (_isAABBUpToDate)
734  return _aabb;
735 
736  // empty the AABB (= max negative AABB)
737  if (_mesh || !_children.empty())
738  {
739  _aabb.minWS(SLVec3f(FLT_MAX, FLT_MAX, FLT_MAX));
740  _aabb.maxWS(SLVec3f(-FLT_MAX, -FLT_MAX, -FLT_MAX));
741  }
742 
743  // Update special case of camera because it has no mesh
744  if (dynamic_cast<SLCamera*>(this))
745  ((SLCamera*)this)->buildAABB(_aabb, updateAndGetWM());
746 
747  // Build or updateRec AABB of meshes & merge them to the nodes aabb in WS
748  if (_mesh)
749  {
750  SLAABBox aabbMesh;
751  _mesh->buildAABB(aabbMesh, updateAndGetWM());
752  _aabb.mergeWS(aabbMesh);
753  }
754 
755  // Merge children in WS recursively
756  for (auto* child : _children)
757  _aabb.mergeWS(child->updateAABBRec(updateAlsoAABBinOS));
758 
759  // We need min & max also in OS for the uniform grid intersection in OS
760  // This is used for ray casts (picking) and raytracing.
761  if (updateAlsoAABBinOS)
763 
765 
766  // For visualizing the nodes' orientation we finally updateRec the axis in WS
768 
769  _isAABBUpToDate = true;
770  return _aabb;
771 }
Defines an axis aligned bounding box.
Definition: SLAABBox.h:34
void mergeWS(SLAABBox &bb)
Merges the bounding box bb to this one by extending this one axis aligned.
Definition: SLAABBox.cpp:390
void fromWStoOS(const SLVec3f &minWS, const SLVec3f &maxWS, const SLMat4f &wmI)
Recalculate min and max before transformation in object coords.
Definition: SLAABBox.cpp:96
void updateAxisWS(const SLMat4f &wm)
Updates the axis of the owning node.
Definition: SLAABBox.cpp:141
void setCenterAndRadiusWS()
Calculates center & radius of the bounding sphere around the AABB.
Definition: SLAABBox.cpp:204
virtual void buildAABB(SLAABBox &aabb, const SLMat4f &wmNode)
Definition: SLMesh.cpp:1111

◆ updateAndGetWM()

const SLMat4f & SLNode::updateAndGetWM ( ) const

Returns the current world matrix for this node. If the world matrix is out of date it will updateRec it and return a current result.

Definition at line 703 of file SLNode.cpp.

704 {
705  if (!_isWMUpToDate)
706  updateWM();
707 
708  return _wm;
709 }
void updateWM() const
Definition: SLNode.cpp:687

◆ updateAndGetWMI()

const SLMat4f & SLNode::updateAndGetWMI ( ) const

Returns the current world inverse matrix for this node. If the world matrix is out of date it will updateRec it and return a current result.

Definition at line 714 of file SLNode.cpp.

715 {
716  if (!_isWMUpToDate)
717  updateWM();
718 
719  if (!_isWMIUpToDate)
720  {
721  _wmI.setMatrix(_wm);
722  _wmI.invert();
723  _isWMIUpToDate = true;
724  }
725 
726  return _wmI;
727 }
void invert()
Inverts the matrix.
Definition: SLMat4.h:1364

◆ updateMeshAccelStructs()

void SLNode::updateMeshAccelStructs ( )

Definition at line 1149 of file SLNode.cpp.

1150 {
1151  PROFILE_FUNCTION();
1152 
1155 
1156  for (auto* child : _children)
1157  child->updateMeshAccelStructs();
1158 }
#define PROFILE_FUNCTION()
Definition: Instrumentor.h:41
void updateAccelStruct()
Definition: SLMesh.cpp:1133
SLbool accelStructIsOutOfDate()
Definition: SLMesh.h:189

◆ updateMeshMat()

void SLNode::updateMeshMat ( std::function< void(SLMaterial *m)>  setMat,
bool  recursive 
)

Updates the mesh material recursively with a material lambda.

Definition at line 1161 of file SLNode.cpp.

1162 {
1163  if (_mesh && _mesh->mat())
1164  setMat(_mesh->mat());
1165 
1166  if (recursive)
1167  for (auto* child : _children)
1168  child->updateMeshMat(setMat, recursive);
1169 }

◆ updateMeshSkins()

bool SLNode::updateMeshSkins ( bool  forceCPUSkinning,
const std::function< void(SLMesh *)> &  cbInformNodes 
)

Update all skinned meshes recursively.

Do software skinning on all changed skeletons && updateRec any out of date acceleration structure for RT or if they're being rendered.

Definition at line 1126 of file SLNode.cpp.

1128 {
1129  if (drawBit(SL_DB_WITHEDGES) ||
1132  forceCPUSkinning = true;
1133 
1134  bool hasChanges = false;
1135 
1136  // Do software skinning on changed skeleton
1137  if (_mesh && _mesh->skeleton() && _mesh->skeleton()->changed())
1138  {
1139  _mesh->transformSkin(forceCPUSkinning, cbInformNodes);
1140  hasChanges = true;
1141  }
1142 
1143  for (auto* child : _children)
1144  hasChanges |= child->updateMeshSkins(forceCPUSkinning, cbInformNodes);
1145 
1146  return hasChanges;
1147 }
#define SL_DB_ONLYEDGES
Draw only hard edges.
Definition: SLDrawBits.h:31
#define SL_DB_WITHEDGES
Draw faces with hard edges.
Definition: SLDrawBits.h:30
#define SL_DB_VOXELS
Draw the voxels of the uniform grid.
Definition: SLDrawBits.h:26
SLbool changed() const
void transformSkin(bool forceCPUSkinning, const std::function< void(SLMesh *)> &cbInformNodes)
Transforms the vertex positions and normals with by joint weights.
Definition: SLMesh.cpp:1573

◆ updateRec()

void SLNode::updateRec ( )

Definition at line 1107 of file SLNode.cpp.

1108 {
1109  // if (_parent == nullptr) PROFILE_FUNCTION();
1110 
1111  // Call optional update callback of attached
1112  if (_onUpdateCB)
1113  _onUpdateCB();
1114 
1115  // Call doUpdate for inherited classes if implemented
1116  doUpdate();
1117 
1118  for (auto* child : _children)
1119  child->updateRec();
1120 }
virtual void doUpdate()
Definition: SLNode.h:308

◆ updateWM()

void SLNode::updateWM ( ) const
private

A helper function that updates the current _wm to reflect the local matrix. recursively calls the updateAndGetWM of the node's parent.

Note
This function is const because it has to be called from inside the updateAndGetWM function which has to be const. Since we only updateRec the private cache of this class it is ok.

Definition at line 687 of file SLNode.cpp.

688 {
689  // PROFILE_FUNCTION();
690 
691  if (_parent)
693  else
694  _wm.setMatrix(_om);
695 
696  _isWMUpToDate = true;
697  numWMUpdates++;
698 }
static SLuint numWMUpdates
NO. of calls to updateWMRec per frame.
Definition: SLNode.h:319

◆ upOS()

SLVec3f SLNode::upOS ( ) const
inline

Returns the local up vector in a right-hand y-up system

Definition at line 495 of file SLNode.h.

496 {
497  return SLVec3f(_om.m(4), _om.m(5), _om.m(6));
498 }

◆ upWS()

SLVec3f SLNode::upWS ( ) const
inline

SLNode::up returns worlds up vector

Definition at line 561 of file SLNode.h.

562 {
563  updateAndGetWM();
564  return _wm.axisY();
565 }

Friends And Related Function Documentation

◆ SLSceneView

friend class SLSceneView
friend

Definition at line 148 of file SLNode.h.

Member Data Documentation

◆ _aabb

SLAABBox SLNode::_aabb
protected

axis aligned bounding box

Definition at line 360 of file SLNode.h.

◆ _animation

SLAnimation* SLNode::_animation
protected

animation of the node

Definition at line 361 of file SLNode.h.

◆ _castsShadows

bool SLNode::_castsShadows
protected

flag if meshes of node should cast shadows

Definition at line 357 of file SLNode.h.

◆ _children

SLVNode SLNode::_children
protected

vector of children nodes

Definition at line 345 of file SLNode.h.

◆ _depth

SLint SLNode::_depth
protected

depth of the node in a scene tree

Definition at line 348 of file SLNode.h.

◆ _drawBits

SLDrawBits SLNode::_drawBits
protected

node level drawing flags

Definition at line 359 of file SLNode.h.

◆ _entityID

SLint SLNode::_entityID
protected

ID in the SLVEntity graph for Data Oriented Design.

Definition at line 349 of file SLNode.h.

◆ _initialOM

SLMat4f SLNode::_initialOM
protected

the initial om state

Definition at line 351 of file SLNode.h.

◆ _isAABBUpToDate

SLbool SLNode::_isAABBUpToDate
mutableprotected

is the saved aabb still valid

Definition at line 356 of file SLNode.h.

◆ _isSelected

bool SLNode::_isSelected
protected

flag if node and one or more of its meshes are selected

Definition at line 358 of file SLNode.h.

◆ _isWMIUpToDate

SLbool SLNode::_isWMIUpToDate
mutableprotected

is the inverse WM of this node still valid

Definition at line 355 of file SLNode.h.

◆ _isWMUpToDate

SLbool SLNode::_isWMUpToDate
mutableprotected

is the WM of this node still valid

Definition at line 354 of file SLNode.h.

◆ _levelForSM

SLubyte SLNode::_levelForSM
protected

Level of LOD to use for shadow mapping (0 = the visible one will be drawn)

Definition at line 363 of file SLNode.h.

◆ _mesh

SLMesh* SLNode::_mesh
protected

pointer to a single mesh

Definition at line 346 of file SLNode.h.

◆ _minLodCoverage

SLfloat SLNode::_minLodCoverage
protected

Min. LOD coverage for visibility (0.0 < _minLodCoverage < 1.0)

Definition at line 362 of file SLNode.h.

◆ _om

SLMat4f SLNode::_om
protected

object matrix for local transforms

Definition at line 350 of file SLNode.h.

◆ _onUpdateCB

function<void()> SLNode::_onUpdateCB
protected

Optional lambda callback once per update.

Definition at line 364 of file SLNode.h.

◆ _parent

SLNode* SLNode::_parent
protected

pointer to the parent node

Definition at line 344 of file SLNode.h.

◆ _wm

SLMat4f SLNode::_wm
mutableprotected

world matrix for world transform

Definition at line 352 of file SLNode.h.

◆ _wmI

SLMat4f SLNode::_wmI
mutableprotected

inverse world matrix

Definition at line 353 of file SLNode.h.

◆ instanceIndex

unsigned int SLNode::instanceIndex = 0
static

???

Definition at line 321 of file SLNode.h.

◆ numWMUpdates

SLuint SLNode::numWMUpdates = 0
static

NO. of calls to updateWMRec per frame.

Definition at line 319 of file SLNode.h.


The documentation for this class was generated from the following files: