SLProject
4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
|
SLNode represents a node in a hierarchical scene graph. More...
#include <SLNode.h>
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 SLNode * | copyRec () |
virtual SLAABBox & | updateAABBRec (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) |
SLNode * | parent () |
SLint | depth () const |
SLint | entityID () const |
const SLMat4f & | om () |
const SLMat4f & | initialOM () |
const SLMat4f & | updateAndGetWM () const |
const SLMat4f & | updateAndGetWMI () const |
SLDrawBits * | drawBits () |
SLbool | drawBit (SLuint bit) |
SLAABBox * | aabb () |
SLAnimation * | animation () |
SLbool | castsShadows () |
SLMesh * | mesh () |
SLVNode & | children () |
const SLAnimSkeleton * | skeleton () |
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 SLstring & | name () const |
const SLstring & | url () 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 |
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:
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.
|
explicit |
Construct a new SLNode::SLNode object.
name | Name of the node |
Definition at line 40 of file SLNode.cpp.
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.
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.
|
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.
Simply adds a mesh to its mesh pointer vector of the node.
Definition at line 157 of file SLNode.cpp.
|
inline |
|
inline |
|
inline |
Returns the x-axis in object space
|
inline |
|
inline |
Returns the y-axis in object space
|
inline |
Returns the y-axis in world space
|
inline |
Returns the z-axis in object space
|
inline |
Returns the z-axis in world space
|
inline |
|
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.
|
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.
|
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.
|
virtual |
Initializer function to call SLNode::cull3DRec recursively.
Reimplemented in SLNodeLOD.
Definition at line 384 of file SLNode.cpp.
bool SLNode::deleteChild | ( | ) |
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.
bool SLNode::deleteChild | ( | SLNode * | child | ) |
void SLNode::deleteChildren | ( | ) |
|
inline |
|
inlinevirtual |
|
inline |
|
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.
|
virtual |
Prints the node name with the names of the meshes recursively
Definition at line 775 of file SLNode.cpp.
|
inline |
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.
Searches for all nodes that contain the provided mesh
Definition at line 313 of file SLNode.cpp.
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.
|
private |
Helper function of findChildren for the passed mesh pointer
Definition at line 325 of file SLNode.cpp.
|
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.
|
private |
|
inline |
|
inline |
SLNode::forward returns worlds forward vector
|
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.
Inserts a child node in the children vector after the afterC node.
Definition at line 229 of file SLNode.cpp.
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.
|
inline |
Definition at line 652 of file SLNode.h.
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.
|
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.
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.
|
inline |
Definition at line 289 of file SLNode.h.
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.
bool SLNode::removeMesh | ( | ) |
Returns true if a mesh was assigned and set it to nullptr.
Definition at line 183 of file SLNode.cpp.
bool SLNode::removeMesh | ( | SLMesh * | mesh | ) |
void SLNode::resetToInitialState | ( | ) |
Resets this object to its initial state
Definition at line 1092 of file SLNode.cpp.
|
inline |
|
inline |
SLNode::right returns worlds right vector
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.
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.
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.
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.
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.
Adds a scale transform to the current object matrix
Definition at line 1012 of file SLNode.cpp.
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.
Sets the scaling of current object matrix
Definition at line 897 of file SLNode.cpp.
Recursively sets the specified drawbit on or off. See also SLDrawBits.
Definition at line 804 of file SLNode.cpp.
void SLNode::setInitialState | ( | ) |
Saves the current position as the initial state
Definition at line 1084 of file SLNode.cpp.
void SLNode::setMeshMat | ( | SLMaterial * | mat, |
bool | recursive | ||
) |
void SLNode::setPrimitiveTypeRec | ( | SLGLPrimitiveType | primitiveType | ) |
const SLAnimSkeleton * SLNode::skeleton | ( | ) |
|
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.
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.
void SLNode::translation | ( | const SLVec3f & | pos, |
SLTransformSpace | relativeTo = TS_parent |
||
) |
sets the position of this node to pos in 'relativeTo' space.
Definition at line 828 of file SLNode.cpp.
|
inline |
|
inline |
SLNode::position returns current local position
|
inline |
SLNode::position returns current world position
Updates the axis aligned bounding box in world space recursively.
Reimplemented in SLText.
Definition at line 731 of file SLNode.cpp.
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.
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.
void SLNode::updateMeshAccelStructs | ( | ) |
Definition at line 1149 of file SLNode.cpp.
void SLNode::updateMeshMat | ( | std::function< void(SLMaterial *m)> | setMat, |
bool | recursive | ||
) |
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.
void SLNode::updateRec | ( | ) |
Definition at line 1107 of file SLNode.cpp.
|
private |
A helper function that updates the current _wm to reflect the local matrix. recursively calls the updateAndGetWM of the node's parent.
Definition at line 687 of file SLNode.cpp.
|
inline |
|
inline |
SLNode::up returns worlds up vector
|
friend |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
mutableprotected |
|
protected |
|
mutableprotected |
|
mutableprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
mutableprotected |
|
static |