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

Class for benchmark mass animation test scene. More...

#include <AppDemoSceneAnimNodeMass2.h>

Inheritance diagram for AppDemoSceneAnimNodeMass2:
[legend]

Public Member Functions

 AppDemoSceneAnimNodeMass2 ()
 
void registerAssetsToLoad (SLAssetLoader &al) override
 All assets the should be loaded in parallel must be registered in here. More...
 
void assemble (SLAssetManager *am, SLSceneView *sv) override
 After parallel loading of the assets the scene gets assembled in here. More...
 
SLNodeRotatingSpheres (SLAssetManager *am, SLScene *s, SLint depth, SLfloat x, SLfloat y, SLfloat z, SLfloat scale, SLuint resolution, SLVMaterial &mat)
 Creates a recursive rotating sphere group used for performance test. 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 benchmark mass animation test scene.

Definition at line 20 of file AppDemoSceneAnimNodeMass2.h.

Constructor & Destructor Documentation

◆ AppDemoSceneAnimNodeMass2()

AppDemoSceneAnimNodeMass2::AppDemoSceneAnimNodeMass2 ( )

Definition at line 20 of file AppDemoSceneAnimNodeMass2.cpp.

21  : SLScene("Benchmark Node 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 AppDemoSceneAnimNodeMass2::assemble ( SLAssetManager am,
SLSceneView sv 
)
overridevirtual

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

Reimplemented from SLScene.

Definition at line 32 of file AppDemoSceneAnimNodeMass2.cpp.

34 {
35  SLCamera* cam1 = new SLCamera("Camera 1");
36  cam1->clipNear(0.1f);
37  cam1->clipFar(100);
38  cam1->translation(0, 2.5f, 20);
39  cam1->focalDist(20);
40  cam1->lookAt(0, 2.5f, 0);
41  cam1->background().colors(SLCol4f(0.1f, 0.1f, 0.1f));
42  cam1->setInitialState();
43 
44  SLLightSpot* light1 = new SLLightSpot(am,
45  this,
46  15,
47  15,
48  15,
49  0.3f);
50  light1->powers(0.2f, 0.8f, 1.0f);
51  light1->attenuation(1, 0, 0);
52 
53  SLNode* scene = new SLNode;
54  root3D(scene);
55  scene->addChild(cam1);
56  scene->addChild(light1);
57 
58  // Generate NUM_MAT materials
59  const int NUM_MAT = 20;
60  SLVMaterial mat;
61  for (int i = 0; i < NUM_MAT; ++i)
62  {
63  SLGLTexture* texC = new SLGLTexture(am,
64  AppCommon::texturePath + "earth2048_C_Q95.jpg"); // color map
65 
66  SLstring matName = "mat-" + std::to_string(i);
67  mat.push_back(new SLMaterial(am,
68  matName.c_str(),
69  texC));
70  SLCol4f color;
71  color.hsva2rgba(SLVec4f(Utils::TWOPI * (float)i / (float)NUM_MAT,
72  1.0f,
73  1.0f));
74  mat[i]->diffuse(color);
75  }
76 
77  // create rotating sphere group
78  SLint maxDepth = 5;
79 
80  SLint resolution = 18;
81  scene->addChild(RotatingSpheres(am,
82  this,
83  maxDepth,
84  0,
85  0,
86  0,
87  1,
88  resolution,
89  mat));
90 
91  sv->camera(cam1);
92  sv->doWaitOnIdle(false);
93 }
string SLstring
Definition: SL.h:158
int SLint
Definition: SL.h:170
vector< SLMaterial * > SLVMaterial
STL vector of material pointers.
Definition: SLMaterial.h:274
SLVec4< SLfloat > SLVec4f
Definition: SLVec4.h:235
SLVec4< SLfloat > SLCol4f
Definition: SLVec4.h:237
static SLstring texturePath
Path to texture images.
Definition: AppCommon.h:86
SLNode * RotatingSpheres(SLAssetManager *am, SLScene *s, SLint depth, SLfloat x, SLfloat y, SLfloat z, SLfloat scale, SLuint resolution, SLVMaterial &mat)
Creates a recursive rotating sphere group used for performance test.
void colors(const SLCol4f &uniformColor)
Sets a uniform background color.
Active or visible camera node class.
Definition: SLCamera.h:54
void clipFar(const SLfloat cFar)
Definition: SLCamera.h:109
void clipNear(const SLfloat cNear)
Definition: SLCamera.h:108
void focalDist(const SLfloat f)
Definition: SLCamera.h:116
SLBackground & background()
Definition: SLCamera.h:165
Texture object for OpenGL texturing.
Definition: SLGLTexture.h:110
void attenuation(const SLfloat kConstant, const SLfloat kLinear, const SLfloat kQuadratic)
Definition: SLLight.h:116
void powers(SLfloat ambiPow, SLfloat diffPow, SLfloat specPow, const SLCol4f &ambiDiffSpecCol=SLCol4f::WHITE)
Sets the ambient, diffuse and specular powers all with the same color.
Definition: SLLight.h:74
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
void setInitialState()
Definition: SLNode.cpp:1084
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
SLNode * root3D()
Definition: SLScene.h:99
friend class SLNode
Definition: SLScene.h:48
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
void camera(SLCamera *camera)
Definition: SLSceneView.h:145
void doWaitOnIdle(SLbool doWI)
Definition: SLSceneView.h:149
void hsva2rgba(const SLVec4 &hsva)
HSVA to RGBA color conversion (http://www.rapidtables.com/convert/color/hsv-to-rgb....
Definition: SLVec4.h:191
static const float TWOPI
Definition: Utils.h:240

◆ registerAssetsToLoad()

void AppDemoSceneAnimNodeMass2::registerAssetsToLoad ( SLAssetLoader al)
overridevirtual

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

Reimplemented from SLScene.

Definition at line 27 of file AppDemoSceneAnimNodeMass2.cpp.

28 {
29 }

◆ RotatingSpheres()

SLNode * AppDemoSceneAnimNodeMass2::RotatingSpheres ( SLAssetManager am,
SLScene s,
SLint  depth,
SLfloat  x,
SLfloat  y,
SLfloat  z,
SLfloat  scale,
SLuint  resolution,
SLVMaterial mat 
)

Creates a recursive rotating sphere group used for performance test.

This performance benchmark is expensive in terms of world matrix updates because all sphere groups rotate. Therefore all children need to update their wm every frame.

Parameters
amPointer to the asset manager
sPointer to project scene aka asset manager
depthMax. allowed recursion depth
xPosition in x direction
yPosition in y direction
zPosition in z direction
scaleScale factor > 0 and < 1 for the children spheres
resolutionNO. of stack and slices of the spheres
matReference to an vector of materials
Returns
Group node of spheres

Definition at line 111 of file AppDemoSceneAnimNodeMass2.cpp.

120 {
121  assert(depth >= 0);
122  assert(scale >= 0.0f && scale <= 1.0f);
123  assert(resolution > 0 && resolution < 64);
124 
125  // Choose the material index randomly
126  SLint iMat = Utils::random(0, (int)mat.size() - 1);
127 
128  // Generate unique names for meshes, nodes and animations
129  static int sphereNum = 0;
130  string meshName = "Mesh" + std::to_string(sphereNum);
131  string animName = "Anim" + std::to_string(sphereNum);
132  string nodeName = "Node" + std::to_string(sphereNum);
133  sphereNum++;
134 
135  SLAnimation* nodeAnim = s->animManager().createNodeAnimation(animName,
136  60,
137  true,
138  EC_linear,
139  AL_loop);
140  if (depth == 0)
141  {
142  SLSphere* sphere = new SLSphere(am,
143  5.0f * scale,
144  resolution,
145  resolution,
146  meshName,
147  mat[iMat]);
148  SLNode* sphNode = new SLNode(sphere, nodeName);
149  sphNode->translate(x, y, z, TS_object);
150  nodeAnim->createNodeAnimTrackForRotation360(sphNode,
151  SLVec3f(0, 1, 0));
152  return sphNode;
153  }
154  else
155  {
156  depth--;
157 
158  // decrease resolution to reduce memory consumption
159  if (resolution > 8)
160  resolution -= 2;
161 
162  SLNode* sGroup = new SLNode(new SLSphere(am,
163  5.0f * scale,
164  resolution,
165  resolution,
166  meshName,
167  mat[iMat]),
168  nodeName);
169  sGroup->translate(x, y, z, TS_object);
170  nodeAnim->createNodeAnimTrackForRotation360(sGroup, SLVec3f(0, 1, 0));
171  sGroup->addChild(RotatingSpheres(am, s, depth, 6.43951f * scale, 0, 1.72546f * scale, scale / 3.0f, resolution, mat));
172  sGroup->addChild(RotatingSpheres(am, s, depth, 1.72546f * scale, 0, 6.43951f * scale, scale / 3.0f, resolution, mat));
173  sGroup->addChild(RotatingSpheres(am, s, depth, -4.71405f * scale, 0, 4.71405f * scale, scale / 3.0f, resolution, mat));
174  sGroup->addChild(RotatingSpheres(am, s, depth, -6.43951f * scale, 0, -1.72546f * scale, scale / 3.0f, resolution, mat));
175  sGroup->addChild(RotatingSpheres(am, s, depth, -1.72546f * scale, 0, -6.43951f * scale, scale / 3.0f, resolution, mat));
176  sGroup->addChild(RotatingSpheres(am, s, depth, 4.71405f * scale, 0, -4.71405f * scale, scale / 3.0f, resolution, mat));
177  sGroup->addChild(RotatingSpheres(am, s, depth, 2.72166f * scale, 5.44331f * scale, 2.72166f * scale, scale / 3.0f, resolution, mat));
178  sGroup->addChild(RotatingSpheres(am, s, depth, -3.71785f * scale, 5.44331f * scale, 0.99619f * scale, scale / 3.0f, resolution, mat));
179  sGroup->addChild(RotatingSpheres(am, s, depth, 0.99619f * scale, 5.44331f * scale, -3.71785f * scale, scale / 3.0f, resolution, mat));
180  return sGroup;
181  }
182 }
@ EC_linear
linear easing with constant velocity
Definition: SLEnums.h:181
@ TS_object
Definition: SLEnums.h:210
@ AL_loop
loop
Definition: SLEnums.h:169
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 * createNodeAnimTrackForRotation360(SLNode *target, const SLVec3f &axis)
void translate(const SLVec3f &vec, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:906
The SLScene class represents the top level instance holding the scene structure.
Definition: SLScene.h:47
SLAnimManager & animManager()
Definition: SLScene.h:97
SLSphere creates a sphere mesh based on SLSpheric w. 180 deg polar angle.
Definition: SLSphere.h:33
float random(float min, float max)
Returns a uniform distributed random float number between min and max.
Definition: Utils.h:265

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