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

Level of detail (LOD) group node based on screen space coverage. More...

#include <SLNodeLOD.h>

Inheritance diagram for SLNodeLOD:
[legend]

Public Member Functions

 SLNodeLOD (const SLstring &name="NodeLOD")
 
void addChildLOD (SLNode *child, SLfloat minLodLimit, SLubyte levelForSM=0)
 Adds an LOD node with forced decreasing min LOD coverage. More...
 
virtual void cullChildren3D (SLSceneView *sv)
 Culls the LOD children by evaluating the the screen space coverage. More...
 
- Public Member Functions inherited from SLNode
 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 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 ()
 

Additional Inherited Members

- Static Public Attributes inherited from SLNode
static SLuint numWMUpdates = 0
 NO. of calls to updateWMRec per frame. More...
 
static unsigned int instanceIndex = 0
 ??? More...
 
- Protected Attributes inherited from SLNode
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...
 

Detailed Description

Level of detail (LOD) group node based on screen space coverage.

An LOD group node can be used to improve the rendering performance for a mesh is very detailed and has thousands for vertices and triangles. Such a details mesh doesn't need to be detailed in full resolution if the mesh is displayed far away from the camera because you can see all triangles anyway. We therefore need to create multiple levels of details with lower no. of triangles and vertices. You have to create these lower resolution version of an original mesh in an external program such as Blender that has multiple decimation algorithms for this purpose.
See the method addChildLOD for more information how to add the levels.

Definition at line 27 of file SLNodeLOD.h.

Constructor & Destructor Documentation

◆ SLNodeLOD()

SLNodeLOD::SLNodeLOD ( const SLstring name = "NodeLOD")
inlineexplicit

Definition at line 30 of file SLNodeLOD.h.

30 : SLNode(name) { ; }
SLNode(const SLstring &name="Node")
Construct a new SLNode::SLNode object.
Definition: SLNode.cpp:40
const SLstring & name() const
Definition: SLObject.h:38

Member Function Documentation

◆ addChildLOD()

void SLNodeLOD::addChildLOD ( SLNode childToAdd,
SLfloat  minLodCoverage,
SLubyte  levelForSM = 0 
)

Adds an LOD node with forced decreasing min LOD coverage.

The coverage value is the ratio of the nodes bounding rectangle in screen space to the full viewport. The minLodCoverage value must be > 0.0 and < 1.0 and < than the minLodCoverage of the last node in the LOD group. If the first child node has e.g. a minLodCoverage of 0.1 it means that it will be visible if its bounding rectangle covers more then 10% of the viewport. The first child node in the group must be the one with the highest resolution.

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
childToAddLOD child node pointer to add
minLodCoverageA value > 0 and < 1 and < than the minLodCoverage of the last node in the LOD group
levelForSMLevel to use for shadow mapping (0 uses the active level)

Definition at line 32 of file SLNodeLOD.cpp.

35 {
36  assert(minLodCoverage > 0.0f &&
37  minLodCoverage < 1.0f &&
38  "SLNodeLOD::addChildLOD min. LOD limit must be > 0 and < 1");
39 
40  if (!_children.empty() &&
41  _children[_children.size() - 1]->minLodCoverage() <= minLodCoverage)
42  SL_EXIT_MSG("SLNodeLOD::addChildLOD: A new child LOD node must have a smaller LOD limit than the last one.");
43 
44  childToAdd->minLodCoverage(minLodCoverage);
45  childToAdd->levelForSM(levelForSM);
46  addChild(childToAdd);
47 
48  /* Set new node hidden, so they won't be shadowed if they are outside
49  * the view frustum. Only the LOD algorithm in cullChildren3D can make
50  * them visible */
51  childToAdd->drawBits()->set(SL_DB_HIDDEN, true);
52 }
#define SL_EXIT_MSG(message)
Definition: SL.h:240
#define SL_DB_HIDDEN
Flags an object as hidden.
Definition: SLDrawBits.h:20
void set(SLuint bit, SLbool state)
Sets the specified bit to the passed state.
Definition: SLDrawBits.h:57
void addChild(SLNode *child)
Definition: SLNode.cpp:207
void minLodCoverage(SLfloat minLodCoverage)
Definition: SLNode.h:287
SLDrawBits * drawBits()
Definition: SLNode.h:299
SLVNode _children
vector of children nodes
Definition: SLNode.h:345
void levelForSM(SLubyte lfsm)
Definition: SLNode.h:288
SLubyte levelForSM()
Definition: SLNode.h:317
SLfloat minLodCoverage()
Definition: SLNode.h:316

◆ cullChildren3D()

void SLNodeLOD::cullChildren3D ( SLSceneView sv)
virtual

Culls the LOD children by evaluating the the screen space coverage.

Reimplemented from SLNode.

Definition at line 55 of file SLNodeLOD.cpp.

56 {
57  if (!_children.empty())
58  {
59  SLfloat rectCoverage = _aabb.rectCoverageInSS();
60 
61  // Set visibility (draw-bit SL_DB_HIDDEN) for each level
62  for (SLint i = 0; i < _children.size(); ++i)
63  {
64  bool isVisible;
65 
66  if (i == 0)
67  isVisible = rectCoverage >= _children[i]->minLodCoverage();
68  else
69  isVisible = rectCoverage < _children[i - 1]->minLodCoverage() &&
70  rectCoverage >= _children[i]->minLodCoverage();
71 
72  _children[i]->drawBits()->set(SL_DB_HIDDEN, !isVisible);
73  _aabb.isVisible(isVisible);
74 
75  // cull check only the visible level
76  if (isVisible)
77  _children[i]->cull3DRec(sv);
78  }
79  }
80 }
float SLfloat
Definition: SL.h:173
int SLint
Definition: SL.h:170
SLfloat rectCoverageInSS()
Calculates the bounding rectangle in screen space and returns coverage in SS.
Definition: SLAABBox.cpp:446
void isVisible(SLbool visible)
Definition: SLAABBox.h:44
SLAABBox _aabb
axis aligned bounding box
Definition: SLNode.h:360
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69

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