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

Class for mass animation test scene. More...

#include <AppDemoSceneAnimNodeMass.h>

Inheritance diagram for AppDemoSceneAnimNodeMass:
[legend]

Public Member Functions

 AppDemoSceneAnimNodeMass ()
 
void registerAssetsToLoad (SLAssetLoader &al) override
 All scene specific assets have to be registered for async loading in here. More...
 
void assemble (SLAssetManager *am, SLSceneView *sv) override
 After parallel loading of the assets the scene gets assembled in here. More...
 
- Public Member Functions inherited from SLScene
 SLScene (const SLstring &name)
 
 ~SLScene () override
 
void initOculus (SLstring shaderDir)
 
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
 

Additional Inherited Members

- Protected Attributes inherited from SLScene
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...
 

Detailed Description

Class for mass animation test scene.

Definition at line 20 of file AppDemoSceneAnimNodeMass.h.

Constructor & Destructor Documentation

◆ AppDemoSceneAnimNodeMass()

AppDemoSceneAnimNodeMass::AppDemoSceneAnimNodeMass ( )

Definition at line 20 of file AppDemoSceneAnimNodeMass.cpp.

21  : SLScene("Mass Animation Test Scene")
22 {
23  info("Performance test for transform updates from many animations.");
24 }
SLScene(const SLstring &name)
Definition: SLScene.cpp:39
SLstring & info()
Definition: SLScene.h:102

Member Function Documentation

◆ assemble()

void AppDemoSceneAnimNodeMass::assemble ( SLAssetManager am,
SLSceneView sv 
)
overridevirtual

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 from SLScene.

Definition at line 32 of file AppDemoSceneAnimNodeMass.cpp.

33 {
34  // Create a scene group node
35  SLNode* scene = new SLNode("scene node");
36  root3D(scene);
37 
38  // Create and add camera
39  SLCamera* cam1 = new SLCamera("Camera 1");
40  cam1->translation(0, 20, 40);
41  cam1->lookAt(0, 0, 0);
42  cam1->focalDist(42);
43  scene->addChild(cam1);
44  sv->camera(cam1);
45 
46  // Add spotlight
47  SLLightSpot* light1 = new SLLightSpot(am, this, 0.1f);
48  light1->translate(0, 10, 0);
49  scene->addChild(light1);
50 
51  // build a basic scene to have a reference for the occurring rotations
52  SLMaterial* genericMat = new SLMaterial(am, "some material");
53 
54  // we use the same mesh to visualize all the nodes
55  SLBox* box = new SLBox(am,
56  -0.5f,
57  -0.5f,
58  -0.5f,
59  0.5f,
60  0.5f,
61  0.5f,
62  "box",
63  genericMat);
64 
65  // We build a stack of levels, each level has a grid of boxes on it
66  // each box on this grid has another grid above it with child nodes.
67  // Best results are achieved if gridSize is an uneven number.
68  // (gridSize^2)^levels = num nodes. handle with care.
69  const SLint levels = 3;
70  const SLint gridSize = 3;
71  const SLint gridHalf = gridSize / 2;
72  const SLint nodesPerLvl = gridSize * gridSize;
73 
74  // node spacing per level
75  // nodes are 1^3 in size, we want to space the levels so that the densest levels meet
76  // (so exactly 1 unit spacing between blocks)
77  SLfloat nodeSpacing[levels];
78  for (SLint i = 0; i < levels; ++i)
79  nodeSpacing[(levels - 1) - i] = (SLfloat)pow((SLfloat)gridSize, (SLfloat)i);
80 
81  // lists to keep track of previous grid level to set parents correctly
82  vector<SLNode*> parents;
83  vector<SLNode*> curParentsVector;
84 
85  // first parent is the scene root
86  parents.push_back(scene);
87 
88  SLint nodeIndex = 0;
89  for (float lvl : nodeSpacing)
90  {
91  curParentsVector = parents;
92  parents.clear();
93 
94  // for each parent in the previous level, add a completely new grid
95  for (auto parent : curParentsVector)
96  {
97  for (SLint i = 0; i < nodesPerLvl; ++i)
98  {
99  SLNode* node = new SLNode("MassAnimNode");
100  node->addMesh(box);
101  parent->addChild(node);
102  parents.push_back(node);
103 
104  // position
105  SLfloat x = (SLfloat)(i % gridSize - gridHalf);
106  SLfloat z = (SLfloat)((i > 0) ? i / gridSize - gridHalf : -gridHalf);
107  SLVec3f pos(x * lvl * 1.1f, 1.5f, z * lvl * 1.1f);
108 
109  node->translate(pos, TS_object);
110  // node->scale(1.1f);
111 
112  SLfloat duration = 1.0f + 5.0f * ((SLfloat)i / (SLfloat)nodesPerLvl);
113  ostringstream oss;
114 
115  oss << "random anim " << nodeIndex++;
116  SLAnimation* anim = animManager().createNodeAnimation(oss.str(),
117  duration,
118  true,
119  EC_inOutSine,
122  SLVec3f(0.0f, 1.0f, 0.0f));
123  }
124  }
125  }
126 }
float SLfloat
Definition: SL.h:173
int SLint
Definition: SL.h:170
@ EC_inOutSine
sine easing in and then out
Definition: SLEnums.h:200
@ TS_object
Definition: SLEnums.h:210
@ AL_pingPongLoop
loop forward and backwards
Definition: SLEnums.h:171
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318
SLAnimation * createNodeAnimation(SLfloat duration)
SLAnimation is the base container for all animation data.
Definition: SLAnimation.h:33
SLNodeAnimTrack * createNodeAnimTrackForTranslation(SLNode *target, const SLVec3f &endPos)
Axis aligned box mesh.
Definition: SLBox.h:31
Active or visible camera node class.
Definition: SLCamera.h:54
void focalDist(const SLfloat f)
Definition: SLCamera.h:116
SLLightSpot class for a spot light source.
Definition: SLLightSpot.h:36
Defines a standard CG material with textures and a shader program.
Definition: SLMaterial.h:56
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:147
void addChild(SLNode *child)
Definition: SLNode.cpp:207
void translation(const SLVec3f &pos, SLTransformSpace relativeTo=TS_parent)
Definition: SLNode.cpp:828
virtual void addMesh(SLMesh *mesh)
Definition: SLNode.cpp:157
void lookAt(SLfloat targetX, SLfloat targetY, SLfloat targetZ, SLfloat upX=0, SLfloat upY=1, SLfloat upZ=0, SLTransformSpace relativeTo=TS_world)
Definition: SLNode.h:652
void translate(const SLVec3f &vec, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:906
SLNode * root3D()
Definition: SLScene.h:99
friend class SLNode
Definition: SLScene.h:48
SLAnimManager & animManager()
Definition: SLScene.h:97
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
void camera(SLCamera *camera)
Definition: SLSceneView.h:145

◆ registerAssetsToLoad()

void AppDemoSceneAnimNodeMass::registerAssetsToLoad ( SLAssetLoader al)
overridevirtual

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

All assets the should be loaded in parallel must be registered 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 from SLScene.

Definition at line 27 of file AppDemoSceneAnimNodeMass.cpp.

28 {
29 }

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