SLProject 4.0.000
|
SLNode represents a node in a hierarchical scene graph. More...
#include <SLNode.h>
Public Member Functions | |
SLNode (const SLstring &name="Node") | |
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) |
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 (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.
SLNode 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 |
Default constructor just setting the name.
Constructor with a mesh pointer and name.
Constructor with a mesh pointer, translation vector and name.
|
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.
|
inline |
void SLNode::addChild | ( | SLNode * | child | ) |
Adds a child node to the children vector
|
virtual |
Simply adds a mesh to its mesh pointer vector of the node.
|
inline |
|
inline |
|
inline |
Returns the x-axis in object space
|
inline |
Returns the x-axis in world space
|
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 |
|
inline |
|
inline |
|
virtual |
Returns a deep copy of the node and its children recursively. The meshes do not get copied.
|
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.
|
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.
|
virtual |
Reimplemented in SLNodeLOD.
bool SLNode::deleteChild | ( | ) |
Deletes the last child in the child vector.
bool SLNode::deleteChild | ( | const SLstring & | name | ) |
Searches for a child with the name 'name' and deletes it.
bool SLNode::deleteChild | ( | SLNode * | child | ) |
Deletes a child from the child vector.
void SLNode::deleteChildren | ( | ) |
Deletes all child nodes.
|
inline |
|
inlinevirtual |
Reimplemented in SLHorizonNode.
|
inline |
|
virtual |
Draws the single mesh.
Inserts a mesh pointer in the mesh pointer vector after the specified afterM pointer.
Reimplemented in SLKeyframeCamera, SLCamera, SLLightDirect, SLLightRect, SLLightSpot, and SLText.
|
virtual |
Prints the node name with the names of the meshes recursively
|
inline |
|
inline |
SLNode::findChild<T> searches a node tree including the node by a given name.
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.
Searches for all nodes that contain the provided mesh
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.
Searches for all nodes that contain the provided mesh
|
private |
Helper function of findChildren for the passed mesh pointer
|
private |
SLNode::findChildrenHelper<T> is the helper function for findChildren<T>. It appends all newly found children to 'list'.
|
private |
Helper function of findChildren for passed drawing bit
|
inline |
Returns the local forward vector (= -z-axis) in a right-hand y-up system
|
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 SLLightDirect, SLLightRect, SLLightSpot, and SLText.
|
inline |
Inserts a child node in the children vector after the afterC node.
|
inline |
|
inline |
|
inline |
|
inline |
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.
|
inline |
|
inline |
|
inline |
|
inline |
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.
|
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.
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.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void SLNode::parent | ( | SLNode * | p | ) |
Sets the parent for this node and updates its depth
bool SLNode::removeChild | ( | SLNode * | child | ) |
remove child from vector of children. Removes false if not found, else true.
bool SLNode::removeMesh | ( | ) |
Returns true if a mesh was assigned and set it to nullptr.
bool SLNode::removeMesh | ( | SLMesh * | mesh | ) |
Returns true if the passed mesh was assigned and sets it to nullptr.
void SLNode::resetToInitialState | ( | ) |
Resets this object to its initial state
|
inline |
Returns the local right vector (= x-axis) in a right-hand y-up system
|
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'.
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'.
|
inline |
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'.
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.
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.
void SLNode::scale | ( | const SLVec3f & | scale | ) |
Adds a scale transform to the current object matrix
|
inline |
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].
void SLNode::scaling | ( | const SLVec3f & | scaling | ) |
Sets the scaling of current object matrix
|
inline |
Recursively sets the specified drawbit on or off. See also SLDrawBits.
void SLNode::setInitialState | ( | ) |
Saves the current position as the initial state
void SLNode::setMeshMat | ( | SLMaterial * | mat, |
bool | recursive | ||
) |
Set the mesh material recursively.
void SLNode::setPrimitiveTypeRec | ( | SLGLPrimitiveType | primitiveType | ) |
Recursively sets the specified OpenGL primitive type.
const SLAnimSkeleton * SLNode::skeleton | ( | ) |
Returns the first skeleton found in the meshes.
|
virtual |
Updates the statistic numbers of the passed SLNodeStats struct and calls recursively the same method for all children.
Reimplemented in SLCamera, SLLightDirect, SLLightRect, SLLightSpot, and SLText.
void SLNode::translate | ( | const SLVec3f & | delta, |
SLTransformSpace | relativeTo = TS_object |
||
) |
Moves the node by the vector 'delta' relative to the space expressed by 'relativeTo'.
|
inline |
void SLNode::translation | ( | const SLVec3f & | pos, |
SLTransformSpace | relativeTo = TS_parent |
||
) |
sets the position of this node to pos in 'relativeTo' space.
|
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.
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.
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.
void SLNode::updateMeshAccelStructs | ( | ) |
void SLNode::updateMeshMat | ( | std::function< void(SLMaterial *m)> | setMat, |
bool | recursive | ||
) |
Updates the mesh material recursively with a material lambda.
bool SLNode::updateMeshSkins | ( | 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.
void SLNode::updateRec | ( | ) |
|
private |
A helper function that updates the current _wm to reflect the local matrix. recursively calls the updateAndGetWM of the node's parent.
|
inline |
Returns the local up vector in a right-hand y-up system
|
inline |
SLNode::up returns worlds up vector
|
friend |
|
protected |
axis aligned bounding box
|
protected |
animation of the node
|
protected |
flag if meshes of node should cast shadows
|
protected |
vector of children nodes
|
protected |
depth of the node in a scene tree
|
protected |
node level drawing flags
|
protected |
ID in the SLVEntity graph for Data Oriented Design.
|
protected |
the initial om state
|
mutableprotected |
is the saved aabb still valid
|
protected |
flag if node and one or more of its meshes are selected
|
mutableprotected |
is the inverse WM of this node still valid
|
mutableprotected |
is the WM of this node still valid
|
protected |
Level of LOD to use for shadow mapping (0 = the visible one will be drawn)
|
protected |
pointer to a single mesh
|
protected |
Min. LOD coverage for visibility (0.0 < _minLodCoverage < 1.0)
|
protected |
object matrix for local transforms
|
protected |
Optional lambda callback once per update.
|
protected |
pointer to the parent node
|
mutableprotected |
world matrix for world transform
|
mutableprotected |
inverse world matrix
|
static |
???
|
static |
NO. of calls to updateWMRec per frame.