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

The SLScene class represents the top level instance holding the scene structure. More...

#include <SLScene.h>

Inherits SLObject.

Inherited by AppDemoScene2Dand3DText, AppDemoSceneAnimNode, AppDemoSceneAnimNodeMass, AppDemoSceneAnimNodeMass2, AppDemoSceneAnimSkinned, AppDemoSceneAnimSkinnedMass, AppDemoSceneAnimSkinnedMass2, AppDemoSceneEmpty, AppDemoSceneErlebARAugustaTmpTht, AppDemoSceneErlebARAventicumAmphitheater, AppDemoSceneErlebARAventicumCigognier, AppDemoSceneErlebARAventicumTheater, AppDemoSceneErlebARBernChristoffel, AppDemoSceneErlebARBielBFH, AppDemoSceneErlebARSutz, AppDemoSceneFigure, AppDemoSceneFrustum, AppDemoSceneGLTF, AppDemoSceneJansUniverse, AppDemoSceneLargeModel, AppDemoSceneLevelOfDetail, AppDemoSceneLotsOfNodes, AppDemoSceneMeshLoad, AppDemoSceneMinimal, AppDemoSceneParticleComplexFire, AppDemoSceneParticleDustStorm, AppDemoSceneParticleFountain, AppDemoSceneParticleMany, AppDemoSceneParticleRingOfFire, AppDemoSceneParticleSimple, AppDemoSceneParticleSun, AppDemoScenePointClouds, AppDemoSceneRTDoF, AppDemoSceneRTLens, AppDemoSceneRTMuttenzerBox, AppDemoSceneRTSpheres, AppDemoSceneRevolver, AppDemoSceneRobot, AppDemoSceneShaderBlinn, AppDemoSceneShaderBump, AppDemoSceneShaderCook, AppDemoSceneShaderEarth, AppDemoSceneShaderIBL, AppDemoSceneShaderParallax, AppDemoSceneShaderSkybox, AppDemoSceneShaderWave, AppDemoSceneShadowBasic, AppDemoSceneShadowCascaded, AppDemoSceneShadowLightPoint, AppDemoSceneShadowLightSpot, AppDemoSceneShadowLightTypes, AppDemoSceneSuzanne, AppDemoSceneTextureBlend, AppDemoSceneTextureCompression, AppDemoSceneTextureFilter, AppDemoSceneVideoSensorAR, AppDemoSceneVideoTexture, AppDemoSceneVideoTrackAruco, AppDemoSceneVideoTrackChessboard, AppDemoSceneVideoTrackFace, AppDemoSceneVideoTrackFeatures, AppDemoSceneVideoTrackMediapipe, AppDemoSceneVideoTrackWAI, AppDemoSceneVolumeRayCast, AppDemoSceneVolumeRayCastLighted, AppDemoSceneZFighting, AppMinimalScene, and AppNodeScene.

Public Member Functions

 SLScene (const SLstring &name)
 
 ~SLScene () override
 
void initOculus (SLstring shaderDir)
 
virtual void registerAssetsToLoad (SLAssetLoader &al)
 All assets the should be loaded in parallel must be registered in here. More...
 
virtual void assemble (SLAssetManager *am, SLSceneView *sv)
 After parallel loading of the assets the scene gets assembled in here. More...
 
void root3D (SLNode *root3D)
 
void root2D (SLNode *root2D)
 
void skybox (SLSkybox *skybox)
 
void stopAnimations (SLbool stop)
 
void info (SLstring i)
 
void loadTimeMS (SLfloat loadTimeMS)
 
SLAnimManageranimManager ()
 
SLAssetManagerassetManager ()
 
SLNoderoot3D ()
 
SLNoderoot2D ()
 
SLSkyboxskybox ()
 
SLstringinfo ()
 
SLfloat elapsedTimeMS () const
 
SLfloat elapsedTimeSec () const
 
SLVEventHandlereventHandlers ()
 
SLfloat loadTimeMS () const
 
SLVLightlights ()
 
SLfloat fps () const
 
AvgFloatframeTimesMS ()
 
AvgFloatupdateTimesMS ()
 
AvgFloatupdateAnimTimesMS ()
 
AvgFloatupdateAABBTimesMS ()
 
AvgFloatupdateDODTimesMS ()
 
SLNodesingleNodeSelected ()
 Returns the node if only one is selected. See also SLMesh::selectNodeMesh. More...
 
SLMeshsingleMeshFullSelected ()
 Returns the node if only one is selected. See also SLMesh::selectNodeMesh. More...
 
SLVNodeselectedNodes ()
 
SLVMeshselectedMeshes ()
 
SLbool stopAnimations () const
 
SLint numSceneCameras ()
 Returns the number of camera nodes in the scene. More...
 
SLCameranextCameraInScene (SLCamera *activeSVCam)
 Returns the next camera in the scene if there is one. More...
 
bool onUpdate (bool renderTypeIsRT, bool voxelsAreShown, bool forceCPUSkinning)
 Updates animations and AABBs. More...
 
void init (SLAssetManager *am)
 
virtual void unInit ()
 
void selectNodeMesh (SLNode *nodeToSelect, SLMesh *meshToSelect)
 Handles the full mesh selection from double-clicks. More...
 
void deselectAllNodesAndMeshes ()
 Deselects all nodes and its meshes. More...
 
SLGLOculusoculus ()
 
- 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
 

Protected Attributes

SLVLight _lights
 Vector of all lights. More...
 
SLVEventHandler _eventHandlers
 Vector of all event handler. More...
 
SLAnimManager _animManager
 Animation manager instance. More...
 
SLAssetManager_assetManager
 Pointer to the external assetManager. More...
 
SLNode_root3D
 Root node for 3D scene. More...
 
SLNode_root2D
 Root node for 2D scene displayed in ortho projection. More...
 
SLSkybox_skybox
 pointer to skybox More...
 
SLstring _info
 scene info string More...
 
SLVNode _selectedNodes
 Vector of selected nodes. See SLMesh::selectNodeMesh. More...
 
SLVMesh _selectedMeshes
 Vector of selected meshes. See SLMesh::selectNodeMesh. More...
 
SLfloat _loadTimeMS
 time to load scene in ms More...
 
SLfloat _frameTimeMS
 Last frame time in ms. More...
 
SLfloat _lastUpdateTimeMS
 Last time after update in ms. More...
 
SLfloat _fps
 Averaged no. of frames per second. More...
 
AvgFloat _frameTimesMS
 Averaged total time per frame in ms. More...
 
AvgFloat _updateTimesMS
 Averaged time for update in ms. More...
 
AvgFloat _updateAABBTimesMS
 Averaged time for update the nodes AABB in ms. More...
 
AvgFloat _updateAnimTimesMS
 Averaged time for update the animations in ms. More...
 
AvgFloat _updateDODTimesMS
 Averaged time for update the SLEntities graph. More...
 
SLbool _stopAnimations
 Global flag for stopping all animations. More...
 
std::unique_ptr< SLGLOculus_oculus
 Oculus Rift interface. More...
 
- Protected Attributes inherited from SLObject
SLstring _name
 name of an object More...
 
SLstring _url
 uniform resource locator More...
 

Friends

class SLNode
 

Detailed Description

The SLScene class represents the top level instance holding the scene structure.

The SLScene class holds everything that is common for all sceneviews such as the pointer (_root3D) to the root node of the scene. The scene loading happens in 3 steps:
1) Registering all expensive assets to load in registerAssetsToLoad.
2) Parallel loading of assets in threads with SLAssetLoader::loadAll.
3) Assembling the scene in assemble.
To load a scene you must therefore inherit from this class and override the methods registerAssetsToLoad and assemble.

Definition at line 46 of file SLScene.h.

Constructor & Destructor Documentation

◆ SLScene()

SLScene::SLScene ( const SLstring name)

The constructor of the scene. There will be only one scene for an application and it gets constructed in the C-interface function slCreateScene in SLInterface.cpp that is called by the platform and UI-toolkit dependent window initialization. As examples you can see it in:

  • app_demo_slproject/glfw: glfwMain.cpp in function main()
  • app-demo/android: Java_ch_fhnw_comgRT_glES2Lib_onInit()
  • app_demo_slproject/ios: ViewController.m in method viewDidLoad()
  • _old/app-Demo-Qt: qtGLWidget::initializeGL()
  • _old/app-Viewer-Qt: qtGLWidget::initializeGL()

Definition at line 39 of file SLScene.cpp.

40  : SLObject(name),
41  _loadTimeMS(0.0f),
42  _frameTimesMS(60, 0.0f),
43  _updateTimesMS(60, 0.0f),
44  _updateAABBTimesMS(60, 0.0f),
45  _updateAnimTimesMS(60, 0.0f),
46  _updateDODTimesMS(60, 0.0f)
47 {
48  _assetManager = nullptr;
49  _root3D = nullptr;
50  _root2D = nullptr;
51  _skybox = nullptr;
52  _info = "";
53  _stopAnimations = false;
54  _fps = 0;
55  _frameTimeMS = 0;
57 }
SLObject(const SLstring &Name="", const SLstring &url="")
Definition: SLObject.h:25
const SLstring & name() const
Definition: SLObject.h:38
SLbool _stopAnimations
Global flag for stopping all animations.
Definition: SLScene.h:171
SLSkybox * _skybox
pointer to skybox
Definition: SLScene.h:154
SLfloat _loadTimeMS
time to load scene in ms
Definition: SLScene.h:159
AvgFloat _frameTimesMS
Averaged total time per frame in ms.
Definition: SLScene.h:165
SLfloat _frameTimeMS
Last frame time in ms.
Definition: SLScene.h:160
AvgFloat _updateDODTimesMS
Averaged time for update the SLEntities graph.
Definition: SLScene.h:169
SLNode * _root3D
Root node for 3D scene.
Definition: SLScene.h:152
SLAssetManager * _assetManager
Pointer to the external assetManager.
Definition: SLScene.h:150
SLstring _info
scene info string
Definition: SLScene.h:155
SLfloat _fps
Averaged no. of frames per second.
Definition: SLScene.h:162
AvgFloat _updateAABBTimesMS
Averaged time for update the nodes AABB in ms.
Definition: SLScene.h:167
SLNode * _root2D
Root node for 2D scene displayed in ortho projection.
Definition: SLScene.h:153
SLfloat _lastUpdateTimeMS
Last time after update in ms.
Definition: SLScene.h:161
AvgFloat _updateAnimTimesMS
Averaged time for update the animations in ms.
Definition: SLScene.h:168
AvgFloat _updateTimesMS
Averaged time for update in ms.
Definition: SLScene.h:166

◆ ~SLScene()

SLScene::~SLScene ( )
override

The destructor does the final total deallocation of all global resources. The destructor is called in slTerminate.

Definition at line 62 of file SLScene.cpp.

63 {
64  unInit();
65 
66  SL_LOG_DEBUG("Destructor : ~SLScene");
67  SL_LOG_DEBUG("------------------------------------------------------------------");
68 }
#define SL_LOG_DEBUG(...)
Definition: SL.h:237
virtual void unInit()
Definition: SLScene.cpp:97

Member Function Documentation

◆ animManager()

SLAnimManager& SLScene::animManager ( )
inline

Definition at line 97 of file SLScene.h.

97 { return _animManager; }
SLAnimManager _animManager
Animation manager instance.
Definition: SLScene.h:149

◆ assemble()

virtual void SLScene::assemble ( SLAssetManager am,
SLSceneView sv 
)
inlinevirtual

After parallel loading of the assets the scene gets assembled in here.

Remarks
All scene-specific assets have to be loaded async by overriding SLScene::registerAssetsToLoad and SLScene::assemble. Async loading and assembling means that it happens in a parallel thread and that in there are no OpenGL calls allowed. OpenGL calls are only allowed in the main thread. It is important that all object instantiations within SLScene::assemble do NOT call any OpenGL functions (gl*) because they happen in a parallel thread. All objects that get rendered have to do their initialization when they are used the first time during rendering in the main thread.

Reimplemented in AppNodeScene, AppMinimalScene, AppDemoSceneZFighting, AppDemoSceneVolumeRayCastLighted, AppDemoSceneVolumeRayCast, AppDemoSceneVideoTrackWAI, AppDemoSceneVideoTrackMediapipe, AppDemoSceneVideoTrackFeatures, AppDemoSceneVideoTrackFace, AppDemoSceneVideoTrackChessboard, AppDemoSceneVideoTrackAruco, AppDemoSceneVideoTexture, AppDemoSceneVideoSensorAR, AppDemoSceneTextureFilter, AppDemoSceneTextureCompression, AppDemoSceneTextureBlend, AppDemoSceneSuzanne, AppDemoSceneShadowLightTypes, AppDemoSceneShadowLightSpot, AppDemoSceneShadowLightPoint, AppDemoSceneShadowCascaded, AppDemoSceneShadowBasic, AppDemoSceneShaderWave, AppDemoSceneShaderSkybox, AppDemoSceneShaderParallax, AppDemoSceneShaderIBL, AppDemoSceneShaderEarth, AppDemoSceneShaderCook, AppDemoSceneShaderBump, AppDemoSceneShaderBlinn, AppDemoSceneRTSpheres, AppDemoSceneRTMuttenzerBox, AppDemoSceneRTLens, AppDemoSceneRTDoF, AppDemoSceneRobot, AppDemoSceneRevolver, AppDemoScenePointClouds, AppDemoSceneParticleSun, AppDemoSceneParticleSimple, AppDemoSceneParticleRingOfFire, AppDemoSceneParticleMany, AppDemoSceneParticleFountain, AppDemoSceneParticleDustStorm, AppDemoSceneParticleComplexFire, AppDemoSceneMinimal, AppDemoSceneMeshLoad, AppDemoSceneLotsOfNodes, AppDemoSceneLevelOfDetail, AppDemoSceneLargeModel, AppDemoSceneJansUniverse, AppDemoSceneGLTF, AppDemoSceneFrustum, AppDemoSceneFigure, AppDemoSceneErlebARSutz, AppDemoSceneErlebARBielBFH, AppDemoSceneErlebARBernChristoffel, AppDemoSceneErlebARAventicumTheater, AppDemoSceneErlebARAventicumCigognier, AppDemoSceneErlebARAventicumAmphitheater, AppDemoSceneErlebARAugustaTmpTht, AppDemoSceneEmpty, AppDemoSceneAnimSkinnedMass2, AppDemoSceneAnimSkinnedMass, AppDemoSceneAnimSkinned, AppDemoSceneAnimNodeMass2, AppDemoSceneAnimNodeMass, AppDemoSceneAnimNode, and AppDemoScene2Dand3DText.

Definition at line 75 of file SLScene.h.

75 {}

◆ assetManager()

SLAssetManager* SLScene::assetManager ( )
inline

Definition at line 98 of file SLScene.h.

98 { return _assetManager; }

◆ deselectAllNodesAndMeshes()

void SLScene::deselectAllNodesAndMeshes ( )

Deselects all nodes and its meshes.

Definition at line 338 of file SLScene.cpp.

339 {
340  for (auto sn : _selectedNodes)
341  sn->isSelected(false);
342  _selectedNodes.clear();
343 
344  for (auto sm : _selectedMeshes)
345  {
346  sm->deselectPartialSelection();
347  sm->isSelected(false);
348  }
349  _selectedMeshes.clear();
350 }
SLVNode _selectedNodes
Vector of selected nodes. See SLMesh::selectNodeMesh.
Definition: SLScene.h:156
SLVMesh _selectedMeshes
Vector of selected meshes. See SLMesh::selectNodeMesh.
Definition: SLScene.h:157
Collection of classes for a state machine implementation used in the Erleb-AR app.
Definition: Event.h:25

◆ elapsedTimeMS()

SLfloat SLScene::elapsedTimeMS ( ) const
inline

Definition at line 103 of file SLScene.h.

103 { return _frameTimeMS; }

◆ elapsedTimeSec()

SLfloat SLScene::elapsedTimeSec ( ) const
inline

Definition at line 104 of file SLScene.h.

104 { return _frameTimeMS * 0.001f; }

◆ eventHandlers()

SLVEventHandler& SLScene::eventHandlers ( )
inline

Definition at line 105 of file SLScene.h.

105 { return _eventHandlers; }
SLVEventHandler _eventHandlers
Vector of all event handler.
Definition: SLScene.h:148

◆ fps()

SLfloat SLScene::fps ( ) const
inline

Definition at line 108 of file SLScene.h.

108 { return _fps; }

◆ frameTimesMS()

AvgFloat& SLScene::frameTimesMS ( )
inline

Definition at line 109 of file SLScene.h.

109 { return _frameTimesMS; }

◆ info() [1/2]

SLstring& SLScene::info ( )
inline

Definition at line 102 of file SLScene.h.

102 { return _info; }

◆ info() [2/2]

void SLScene::info ( SLstring  i)
inline

Definition at line 93 of file SLScene.h.

93 { _info = std::move(i); }

◆ init()

void SLScene::init ( SLAssetManager am)

The scene init is called before a new scene is assembled.

Definition at line 72 of file SLScene.cpp.

73 {
74  assert(am && "No asset manager passed to scene");
75 
76  unInit();
77 
78  _assetManager = am;
79 
80  // reset global light settings
81  SLLight::gamma = 1.0f;
82  SLLight::globalAmbient.set(0.15f, 0.15f, 0.15f, 1.0f);
83 
84  // Reset timing variables
85  _frameTimesMS.init(20, 0.0f);
86  _updateTimesMS.init(60, 0.0f);
87  _updateAnimTimesMS.init(60, 0.0f);
88  _updateAABBTimesMS.init(60, 0.0f);
89  _updateDODTimesMS.init(60, 0.0f);
90 }
static SLfloat gamma
final output gamma value
Definition: SLLight.h:204
static SLCol4f globalAmbient
static global ambient light intensity
Definition: SLLight.h:202
void set(const T X, const T Y, const T Z, const T W=1)
Definition: SLVec4.h:49
void init(int numValues, T initValue)
Initializes the average value array to a given value.
Definition: Averaged.h:41

◆ initOculus()

void SLScene::initOculus ( SLstring  shaderDir)

Definition at line 391 of file SLScene.cpp.

392 {
393  _oculus = std::make_unique<SLGLOculus>(shaderDir);
394  _oculus->init();
395 }
std::unique_ptr< SLGLOculus > _oculus
Oculus Rift interface.
Definition: SLScene.h:173

◆ lights()

SLVLight& SLScene::lights ( )
inline

Definition at line 107 of file SLScene.h.

107 { return _lights; }
SLVLight _lights
Vector of all lights.
Definition: SLScene.h:147

◆ loadTimeMS() [1/2]

SLfloat SLScene::loadTimeMS ( ) const
inline

Definition at line 106 of file SLScene.h.

106 { return _loadTimeMS; }

◆ loadTimeMS() [2/2]

void SLScene::loadTimeMS ( SLfloat  loadTimeMS)
inline

Definition at line 94 of file SLScene.h.

SLfloat loadTimeMS() const
Definition: SLScene.h:106

◆ nextCameraInScene()

SLCamera * SLScene::nextCameraInScene ( SLCamera activeSVCam)

Returns the next camera in the scene if there is one.

Definition at line 361 of file SLScene.cpp.

362 {
363  if (!_root3D) return nullptr;
364 
365  deque<SLCamera*> cams = _root3D->findChildren<SLCamera>();
366 
367  if (cams.empty()) return nullptr;
368  if (cams.size() == 1) return cams[0];
369 
370  SLint activeIndex = 0;
371  for (SLulong i = 0; i < cams.size(); ++i)
372  {
373  if (cams[i] == activeSVCam)
374  {
375  activeIndex = (SLint)i;
376  break;
377  }
378  }
379 
380  // find next camera, that is not of type SLKeyframeCamera
381  // and if allowAsActiveCam is deactivated
382  do
383  {
384  activeIndex = activeIndex > cams.size() - 2 ? 0 : ++activeIndex;
385  } while (dynamic_cast<SLKeyframeCamera*>(cams[(uint)activeIndex]) &&
386  !dynamic_cast<SLKeyframeCamera*>(cams[(uint)activeIndex])->allowAsActiveCam());
387 
388  return cams[(uint)activeIndex];
389 }
unsigned long SLulong
Definition: SL.h:165
int SLint
Definition: SL.h:170
Active or visible camera node class.
Definition: SLCamera.h:54
deque< T * > findChildren(const SLstring &name="", SLbool findRecursive=true, SLbool canContain=false)
Definition: SLNode.h:416

◆ numSceneCameras()

SLint SLScene::numSceneCameras ( )

Returns the number of camera nodes in the scene.

Definition at line 353 of file SLScene.cpp.

354 {
355  if (!_root3D) return 0;
356  deque<SLCamera*> cams = _root3D->findChildren<SLCamera>();
357  return (SLint)cams.size();
358 }

◆ oculus()

SLGLOculus* SLScene::oculus ( )
inline

Definition at line 140 of file SLScene.h.

140 { return _oculus.get(); }

◆ onUpdate()

bool SLScene::onUpdate ( bool  renderTypeIsRT,
bool  voxelsAreShown,
bool  forceCPUSkinning 
)

Updates animations and AABBs.

Updates different updatables in the scene after all views got painted:
1) Calculate frame time
2) Update all animations
3) Update AABBs

Returns
true if really something got updated

Definition at line 124 of file SLScene.cpp.

127 {
129 
130  /////////////////////////////
131  // 1) Calculate frame time //
132  /////////////////////////////
133 
134  // Calculate the elapsed time for the animation
135  // todo: If slowdown on idle is enabled the delta time will be wrong!
138 
139  // Calculate the frames per second metric
141  SLfloat averagedFrameTimeMS = _frameTimesMS.average();
142  if (averagedFrameTimeMS > 0.001f)
143  _fps = 1 / _frameTimesMS.average() * 1000.0f;
144  else
145  _fps = 0.0f;
146 
147  SLfloat startUpdateMS = GlobalTimer::timeMS();
148 
149  SLbool sceneHasChanged = false;
150 
151  //////////////////////////////
152  // 2) Update all animations //
153  //////////////////////////////
154 
155  SLfloat startAnimUpdateMS = GlobalTimer::timeMS();
156 
157  if (_root3D)
158  _root3D->updateRec();
159  if (_root2D)
160  _root2D->updateRec();
161 
162  // Update node animations
163  sceneHasChanged |= !_stopAnimations && _animManager.update(elapsedTimeSec());
164 
165  // Do software skinning on all changed skeletons. Update any out of date acceleration structure for RT or if they're being rendered.
166  if (_root3D)
167  {
168  if (renderTypeIsRT || voxelsAreShown)
169  forceCPUSkinning = true;
170 
171  // we use a lambda to inform nodes that share a mesh that the mesh got updated (so we don't have to transfer the root node)
172  sceneHasChanged |= _root3D->updateMeshSkins(forceCPUSkinning, [&](SLMesh* mesh)
173  {
174  SLVNode nodes = _root3D->findChildren(mesh, true);
175  for (auto* node : nodes)
176  node->needAABBUpdate(); });
177 
178  if (renderTypeIsRT || voxelsAreShown)
180  }
181 
182  _updateAnimTimesMS.set(GlobalTimer::timeMS() - startAnimUpdateMS);
183 
184  /////////////////////
185  // 3) Update AABBs //
186  /////////////////////
187 
188  // The updateAABBRec call won't generate any overhead if nothing changed
189  SLfloat startAAABBUpdateMS = GlobalTimer::timeMS();
191  if (_root3D)
192  _root3D->updateAABBRec(renderTypeIsRT);
193  if (_root2D)
194  _root2D->updateAABBRec(renderTypeIsRT);
195  _updateAABBTimesMS.set(GlobalTimer::timeMS() - startAAABBUpdateMS);
196 
197 #ifdef SL_USE_ENTITIES
198  SLfloat startDODUpdateMS = GlobalTimer::timeMS();
199  if (entities.size())
200  {
201  SLMat4f root;
202  entities.updateWMRec(0, root);
203  }
204  _updateDODTimesMS.set(GlobalTimer::timeMS() - startDODUpdateMS);
205 #endif
206 
207  // Finish total updateRec time
208  SLfloat updateTimeMS = GlobalTimer::timeMS() - startUpdateMS;
209  _updateTimesMS.set(updateTimeMS);
210 
211  // SL_LOG("SLScene::onUpdate");
212  return sceneHasChanged;
213 }
#define PROFILE_FUNCTION()
Definition: Instrumentor.h:41
float SLfloat
Definition: SL.h:173
bool SLbool
Definition: SL.h:175
deque< SLNode * > SLVNode
SLVNode typedef for a vector of SLNodes.
Definition: SLNode.h:26
static float timeMS()
Definition: GlobalTimer.cpp:25
SLbool update(SLfloat elapsedTimeSec)
Advances the time of all enabled animation plays.
An SLMesh object is a triangulated mesh, drawn with one draw call.
Definition: SLMesh.h:134
bool updateMeshSkins(bool forceCPUSkinning, const std::function< void(SLMesh *)> &cbInformNodes)
Update all skinned meshes recursively.
Definition: SLNode.cpp:1126
static SLuint numWMUpdates
NO. of calls to updateWMRec per frame.
Definition: SLNode.h:319
void updateRec()
Definition: SLNode.cpp:1107
void updateMeshAccelStructs()
Definition: SLNode.cpp:1149
virtual SLAABBox & updateAABBRec(SLbool updateAlsoAABBinOS)
Definition: SLNode.cpp:731
SLfloat elapsedTimeSec() const
Definition: SLScene.h:104
void set(T value)
Sets the current value in the value array and builds the average.
Definition: Averaged.h:53

◆ registerAssetsToLoad()

virtual void SLScene::registerAssetsToLoad ( SLAssetLoader al)
inlinevirtual

All assets the should be loaded in parallel must be registered in here.

All scene specific assets have to be registered for async loading in here.

Remarks
All scene sspecific assets have to be loaded async by overriding SLScene::registerAssetsToLoad and SLScene::assemble. Async loading and assembling means that it happens in a parallel thread and that in there are no OpenGL calls allowed. OpenGL calls are only allowed in the main thread.

Reimplemented in AppNodeScene, AppMinimalScene, AppDemoSceneZFighting, AppDemoSceneVolumeRayCastLighted, AppDemoSceneVolumeRayCast, AppDemoSceneVideoTrackWAI, AppDemoSceneVideoTrackMediapipe, AppDemoSceneVideoTrackFeatures, AppDemoSceneVideoTrackFace, AppDemoSceneVideoTrackChessboard, AppDemoSceneVideoTrackAruco, AppDemoSceneVideoTexture, AppDemoSceneVideoSensorAR, AppDemoSceneTextureFilter, AppDemoSceneTextureCompression, AppDemoSceneTextureBlend, AppDemoSceneSuzanne, AppDemoSceneShadowLightTypes, AppDemoSceneShadowLightSpot, AppDemoSceneShadowLightPoint, AppDemoSceneShadowCascaded, AppDemoSceneShadowBasic, AppDemoSceneShaderWave, AppDemoSceneShaderSkybox, AppDemoSceneShaderParallax, AppDemoSceneShaderIBL, AppDemoSceneShaderEarth, AppDemoSceneShaderCook, AppDemoSceneShaderBump, AppDemoSceneShaderBlinn, AppDemoSceneRTSpheres, AppDemoSceneRTMuttenzerBox, AppDemoSceneRTLens, AppDemoSceneRTDoF, AppDemoSceneRobot, AppDemoSceneRevolver, AppDemoScenePointClouds, AppDemoSceneParticleSun, AppDemoSceneParticleSimple, AppDemoSceneParticleRingOfFire, AppDemoSceneParticleMany, AppDemoSceneParticleFountain, AppDemoSceneParticleDustStorm, AppDemoSceneParticleComplexFire, AppDemoSceneMinimal, AppDemoSceneMeshLoad, AppDemoSceneLotsOfNodes, AppDemoSceneLevelOfDetail, AppDemoSceneLargeModel, AppDemoSceneJansUniverse, AppDemoSceneGLTF, AppDemoSceneFrustum, AppDemoSceneFigure, AppDemoSceneErlebARSutz, AppDemoSceneErlebARBielBFH, AppDemoSceneErlebARBernChristoffel, AppDemoSceneErlebARAventicumTheater, AppDemoSceneErlebARAventicumCigognier, AppDemoSceneErlebARAventicumAmphitheater, AppDemoSceneErlebARAugustaTmpTht, AppDemoSceneEmpty, AppDemoSceneAnimSkinnedMass2, AppDemoSceneAnimSkinnedMass, AppDemoSceneAnimSkinned, AppDemoSceneAnimNodeMass2, AppDemoSceneAnimNodeMass, AppDemoSceneAnimNode, and AppDemoScene2Dand3DText.

Definition at line 63 of file SLScene.h.

63 {}

◆ root2D() [1/2]

SLNode* SLScene::root2D ( )
inline

Definition at line 100 of file SLScene.h.

100 { return _root2D; }

◆ root2D() [2/2]

void SLScene::root2D ( SLNode root2D)
inline

Definition at line 90 of file SLScene.h.

90 { _root2D = root2D; }
SLNode * root2D()
Definition: SLScene.h:100

◆ root3D() [1/2]

SLNode* SLScene::root3D ( )
inline

Definition at line 99 of file SLScene.h.

99 { return _root3D; }

◆ root3D() [2/2]

void SLScene::root3D ( SLNode root3D)
inline

Definition at line 78 of file SLScene.h.

79  {
80  _root3D = root3D;
81 
82 #ifdef SL_USE_ENTITIES
83  SLint rootEntityID = SLScene::entities.getEntityID(root3D);
84  if (rootEntityID == INT32_MIN && root3D)
85  SLScene::entities.addChildEntity(-1, SLEntity(root3D));
86  else if (rootEntityID > -1)
87  SL_EXIT_MSG("Root node exists already with another ID among the entities");
88 #endif
89  }
#define SL_EXIT_MSG(message)
Definition: SL.h:240
SLNode * root3D()
Definition: SLScene.h:99
SLEntity is the Data Oriented Design version of a SLNode.
Definition: SLEntities.h:28

◆ selectedMeshes()

SLVMesh& SLScene::selectedMeshes ( )
inline

Definition at line 125 of file SLScene.h.

125 { return _selectedMeshes; }

◆ selectedNodes()

SLVNode& SLScene::selectedNodes ( )
inline

Definition at line 124 of file SLScene.h.

124 { return _selectedNodes; }

◆ selectNodeMesh()

void SLScene::selectNodeMesh ( SLNode nodeToSelect,
SLMesh meshToSelect 
)

Handles the full mesh selection from double-clicks.

There are two different selection modes: Full or partial mesh selection.
The full selection is done by double-clicking a mesh. Multiple meshes can be selected with SHIFT-double-clicking. The full selection is handled in SLScene::selectNodeMesh. The selected nodes are stored in SLScene::_selectedNodes and the fully or partially selected meshes are stored in SLScene::_selectedMeshes. The SLNode::isSelected and SLMesh::isSelected show if a node or mesh is selected. A node can be selected with or without a mesh. If a mesh is selected, its node is always also selected. A node without mesh can only be selected in the scenegraph window. To avoid a node from selection you can set its drawing bit SL_DB_NOTSELECTABLE. You should transform a node or mesh and show the properties of a node or mesh if only a single node and single full mesh is selected. To get them call SLScene::singleNodeSelected() or SLScene::singleMeshFullSelected().
For partial mesh selection see SLMesh::handleRectangleSelection.

Definition at line 234 of file SLScene.cpp.

235 {
236  // Case 1: Both are nullptr, so unselect all
237  if (!nodeToSelect && !meshToSelect)
238  {
240  return;
241  }
242 
243  if (nodeToSelect && nodeToSelect->drawBit(SL_DB_NOTSELECTABLE))
244  {
245  SL_LOG("Node is not selectable: %s", nodeToSelect->name().c_str());
246  return;
247  }
248 
249  // Case 2: mesh without node selected: This is not allowed
250  if (!nodeToSelect && meshToSelect)
251  SL_EXIT_MSG("SLScene::selectNodeMesh: No node or mesh to select.");
252 
253  // Search in _selectedNodes vector
254  auto foundNode = find(_selectedNodes.begin(),
255  _selectedNodes.end(),
256  nodeToSelect);
257 
258  // Case 3: Node without mesh selected
259  if (nodeToSelect && !meshToSelect)
260  {
261  if (foundNode == _selectedNodes.end())
262  {
263  nodeToSelect->isSelected(true);
264  _selectedNodes.push_back(nodeToSelect);
265  }
266  return;
267  }
268 
269  // Search in _selectedMeshes vector
270  auto foundMesh = find(_selectedMeshes.begin(),
271  _selectedMeshes.end(),
272  meshToSelect);
273 
274  // Case 4: nodeToSelect and meshToSelect are not yet selected: so we select them
275  if (foundNode == _selectedNodes.end() && foundMesh == _selectedMeshes.end())
276  {
277  nodeToSelect->isSelected(true);
278  _selectedNodes.push_back(nodeToSelect);
279  meshToSelect->isSelected(true);
280  meshToSelect->deselectPartialSelection();
281  _selectedMeshes.push_back(meshToSelect);
282  return;
283  }
284 
285  // Case 5: nodeToSelect is already selected but not the mesh: So select only the mesh
286  if (*foundNode == nodeToSelect && foundMesh == _selectedMeshes.end())
287  {
288  nodeToSelect->isSelected(true);
289  meshToSelect->isSelected(true);
290  meshToSelect->deselectPartialSelection();
291  _selectedMeshes.push_back(meshToSelect);
292  return;
293  }
294 
295  // Case 6: nodeToSelect is not selected but the mesh is selected (from another node)
296  if (foundNode == _selectedNodes.end() && *foundMesh == meshToSelect)
297  {
298  nodeToSelect->isSelected(true);
299  _selectedNodes.push_back(nodeToSelect);
300  meshToSelect->isSelected(true);
301  meshToSelect->deselectPartialSelection();
302  _selectedMeshes.push_back(meshToSelect);
303  return;
304  }
305 
306  // Case 7: Both are already selected, so we unselect them.
307  if (nodeToSelect && *foundNode == nodeToSelect && *foundMesh == meshToSelect)
308  {
309  // Check if other mesh from same node is selected
310  bool otherMeshIsSelected = false;
311 
312  SLMesh* nm = nodeToSelect->mesh();
313  for (auto sm : _selectedMeshes)
314  {
315  if (nm == sm && nm != meshToSelect)
316  {
317  otherMeshIsSelected = true;
318  goto endLoop;
319  }
320  }
321 
322  endLoop:
323  if (!otherMeshIsSelected)
324  {
325  nodeToSelect->isSelected(false);
326  _selectedNodes.erase(foundNode);
327  }
328  meshToSelect->deselectPartialSelection();
329  meshToSelect->isSelected(false);
330  _selectedMeshes.erase(foundMesh);
331  return;
332  }
333 
334  SL_EXIT_MSG("SLScene::selectNodeMesh: We should not get here.");
335 }
#define SL_LOG(...)
Definition: SL.h:233
#define SL_DB_NOTSELECTABLE
Flags an object as selected.
Definition: SLDrawBits.h:21
void deselectPartialSelection()
Definition: SLMesh.cpp:698
SLbool isSelected() const
Definition: SLMesh.h:183
SLbool drawBit(SLuint bit)
Definition: SLNode.h:300
SLMesh * mesh()
Definition: SLNode.h:304
void isSelected(bool isSelected)
Definition: SLNode.h:286
void name(const SLstring &Name)
Definition: SLObject.h:34
void deselectAllNodesAndMeshes()
Deselects all nodes and its meshes.
Definition: SLScene.cpp:338

◆ singleMeshFullSelected()

SLMesh* SLScene::singleMeshFullSelected ( )
inline

Returns the node if only one is selected. See also SLMesh::selectNodeMesh.

Definition at line 119 of file SLScene.h.

119  { return (_selectedNodes.size() == 1 &&
120  _selectedMeshes.size() == 1 &&
121  _selectedMeshes[0]->IS32.empty())
122  ? _selectedMeshes[0]
123  : nullptr; }

◆ singleNodeSelected()

SLNode* SLScene::singleNodeSelected ( )
inline

Returns the node if only one is selected. See also SLMesh::selectNodeMesh.

Definition at line 116 of file SLScene.h.

116 { return _selectedNodes.size() == 1 ? _selectedNodes[0] : nullptr; }

◆ skybox() [1/2]

SLSkybox* SLScene::skybox ( )
inline

Definition at line 101 of file SLScene.h.

101 { return _skybox; }

◆ skybox() [2/2]

void SLScene::skybox ( SLSkybox skybox)
inline

Definition at line 91 of file SLScene.h.

91 { _skybox = skybox; }
SLSkybox * skybox()
Definition: SLScene.h:101

◆ stopAnimations() [1/2]

SLbool SLScene::stopAnimations ( ) const
inline

Definition at line 127 of file SLScene.h.

127 { return _stopAnimations; }

◆ stopAnimations() [2/2]

void SLScene::stopAnimations ( SLbool  stop)
inline

Definition at line 92 of file SLScene.h.

92 { _stopAnimations = stop; }

◆ unInit()

void SLScene::unInit ( )
virtual

The scene uninitializing clears the scenegraph (_root3D) and all global global resources such as materials, textures & custom shaders loaded with the scene. The standard shaders, the fonts and the 2D-GUI elements remain. They are destructed at process end.

Definition at line 97 of file SLScene.cpp.

98 {
99  // delete entire scene graph
100  delete _root3D;
101  _root3D = nullptr;
102  delete _root2D;
103  _root2D = nullptr;
104  _skybox = nullptr;
105 
106  // clear light pointers
107  _lights.clear();
108 
109  _eventHandlers.clear();
111 
112  _selectedMeshes.clear();
113  _selectedNodes.clear();
114 }
void clear()
Clears and deletes all node animations and skeletons.

◆ updateAABBTimesMS()

AvgFloat& SLScene::updateAABBTimesMS ( )
inline

Definition at line 112 of file SLScene.h.

112 { return _updateAABBTimesMS; }

◆ updateAnimTimesMS()

AvgFloat& SLScene::updateAnimTimesMS ( )
inline

Definition at line 111 of file SLScene.h.

111 { return _updateAnimTimesMS; }

◆ updateDODTimesMS()

AvgFloat& SLScene::updateDODTimesMS ( )
inline

Definition at line 113 of file SLScene.h.

113 { return _updateDODTimesMS; }

◆ updateTimesMS()

AvgFloat& SLScene::updateTimesMS ( )
inline

Definition at line 110 of file SLScene.h.

110 { return _updateTimesMS; }

Friends And Related Function Documentation

◆ SLNode

friend class SLNode
friend

Definition at line 48 of file SLScene.h.

Member Data Documentation

◆ _animManager

SLAnimManager SLScene::_animManager
protected

Animation manager instance.

Definition at line 149 of file SLScene.h.

◆ _assetManager

SLAssetManager* SLScene::_assetManager
protected

Pointer to the external assetManager.

Definition at line 150 of file SLScene.h.

◆ _eventHandlers

SLVEventHandler SLScene::_eventHandlers
protected

Vector of all event handler.

Definition at line 148 of file SLScene.h.

◆ _fps

SLfloat SLScene::_fps
protected

Averaged no. of frames per second.

Definition at line 162 of file SLScene.h.

◆ _frameTimeMS

SLfloat SLScene::_frameTimeMS
protected

Last frame time in ms.

Definition at line 160 of file SLScene.h.

◆ _frameTimesMS

AvgFloat SLScene::_frameTimesMS
protected

Averaged total time per frame in ms.

Definition at line 165 of file SLScene.h.

◆ _info

SLstring SLScene::_info
protected

scene info string

Definition at line 155 of file SLScene.h.

◆ _lastUpdateTimeMS

SLfloat SLScene::_lastUpdateTimeMS
protected

Last time after update in ms.

Definition at line 161 of file SLScene.h.

◆ _lights

SLVLight SLScene::_lights
protected

Vector of all lights.

Definition at line 147 of file SLScene.h.

◆ _loadTimeMS

SLfloat SLScene::_loadTimeMS
protected

time to load scene in ms

Definition at line 159 of file SLScene.h.

◆ _oculus

std::unique_ptr<SLGLOculus> SLScene::_oculus
protected

Oculus Rift interface.

Definition at line 173 of file SLScene.h.

◆ _root2D

SLNode* SLScene::_root2D
protected

Root node for 2D scene displayed in ortho projection.

Definition at line 153 of file SLScene.h.

◆ _root3D

SLNode* SLScene::_root3D
protected

Root node for 3D scene.

Definition at line 152 of file SLScene.h.

◆ _selectedMeshes

SLVMesh SLScene::_selectedMeshes
protected

Vector of selected meshes. See SLMesh::selectNodeMesh.

Definition at line 157 of file SLScene.h.

◆ _selectedNodes

SLVNode SLScene::_selectedNodes
protected

Vector of selected nodes. See SLMesh::selectNodeMesh.

Definition at line 156 of file SLScene.h.

◆ _skybox

SLSkybox* SLScene::_skybox
protected

pointer to skybox

Definition at line 154 of file SLScene.h.

◆ _stopAnimations

SLbool SLScene::_stopAnimations
protected

Global flag for stopping all animations.

Definition at line 171 of file SLScene.h.

◆ _updateAABBTimesMS

AvgFloat SLScene::_updateAABBTimesMS
protected

Averaged time for update the nodes AABB in ms.

Definition at line 167 of file SLScene.h.

◆ _updateAnimTimesMS

AvgFloat SLScene::_updateAnimTimesMS
protected

Averaged time for update the animations in ms.

Definition at line 168 of file SLScene.h.

◆ _updateDODTimesMS

AvgFloat SLScene::_updateDODTimesMS
protected

Averaged time for update the SLEntities graph.

Definition at line 169 of file SLScene.h.

◆ _updateTimesMS

AvgFloat SLScene::_updateTimesMS
protected

Averaged time for update in ms.

Definition at line 166 of file SLScene.h.


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