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

Class for the benchmark scene for Jans Universe. More...

#include <AppDemoSceneJansUniverse.h>

Inheritance diagram for AppDemoSceneJansUniverse:
[legend]

Public Member Functions

 AppDemoSceneJansUniverse ()
 
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...
 
void addUniverseLevel (SLAssetManager *am, SLScene *s, SLNode *parent, SLint parentID, SLuint currentLevel, SLuint levels, SLuint childCount, SLVMaterial &materials, SLVMesh &meshes, SLuint &numNodes)
 Adds another level to Jan's Universe scene. More...
 
void generateUniverse (SLAssetManager *am, SLScene *s, SLNode *parent, SLint parentID, SLuint levels, SLuint childCount, SLVMaterial &materials, SLVMesh &meshes)
 Generates the Jan's Universe scene. 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
 

Private Attributes

SLGLTexture_textureC
 
SLGLTexture_textureM
 
SLGLTexture_textureR
 

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 the benchmark scene for Jans Universe.

Definition at line 21 of file AppDemoSceneJansUniverse.h.

Constructor & Destructor Documentation

◆ AppDemoSceneJansUniverse()

AppDemoSceneJansUniverse::AppDemoSceneJansUniverse ( )

Definition at line 31 of file AppDemoSceneJansUniverse.cpp.

32  : SLScene("Jan's Universe Test Scene")
33 {
34  info("Jan's Universe Test Scene");
35 }
SLScene(const SLstring &name)
Definition: SLScene.cpp:39
SLstring & info()
Definition: SLScene.h:102

Member Function Documentation

◆ addUniverseLevel()

void AppDemoSceneJansUniverse::addUniverseLevel ( SLAssetManager am,
SLScene s,
SLNode parent,
SLint  parentID,
SLuint  currentLevel,
SLuint  levels,
SLuint  childCount,
SLVMaterial materials,
SLVMesh meshes,
SLuint numNodes 
)

Adds another level to Jan's Universe scene.

Definition at line 110 of file AppDemoSceneJansUniverse.cpp.

120 {
121  if (currentLevel >= levels)
122  return;
123 
124  const float degPerChild = 360.0f / (float)childCount;
125  SLuint mod = currentLevel % 3;
126 
127  float scaleFactor = 0.25f;
128 
129  for (SLuint i = 0; i < childCount; i++)
130  {
131  numNodes++;
132  string childName = "Node" + std::to_string(numNodes) +
133  "-L" + std::to_string(currentLevel) +
134  "-C" + std::to_string(i);
135  SLNode* child = new SLNode(meshes[numNodes % meshes.size()], childName);
136 
137  child->rotate((float)i * degPerChild, 0, 0, 1);
138  child->translate(2, 0, 0);
139  child->scale(scaleFactor);
140 
141  // Node animation on child node
142  string animName = "Anim" + std::to_string(numNodes);
143  SLAnimation* childAnim = s->animManager().createNodeAnimation(animName.c_str(),
144  60,
145  true,
146  EC_linear,
147  AL_loop);
148  childAnim->createNodeAnimTrackForRotation360(child, {0, 0, 1});
149 
150  parent->addChild(child);
151 
152  addUniverseLevel(am,
153  s,
154  child,
155  parentID,
156  currentLevel + 1,
157  levels,
158  childCount,
159  materials,
160  meshes,
161  numNodes);
162  }
163 }
unsigned int SLuint
Definition: SL.h:171
@ EC_linear
linear easing with constant velocity
Definition: SLEnums.h:181
@ AL_loop
loop
Definition: SLEnums.h:169
void addUniverseLevel(SLAssetManager *am, SLScene *s, SLNode *parent, SLint parentID, SLuint currentLevel, SLuint levels, SLuint childCount, SLVMaterial &materials, SLVMesh &meshes, SLuint &numNodes)
Adds another level to Jan's Universe scene.
SLAnimation * createNodeAnimation(SLfloat duration)
SLAnimation is the base container for all animation data.
Definition: SLAnimation.h:33
SLNodeAnimTrack * createNodeAnimTrackForRotation360(SLNode *target, const SLVec3f &axis)
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:147
void addChild(SLNode *child)
Definition: SLNode.cpp:207
void rotate(const SLQuat4f &rot, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:945
void scale(SLfloat s)
Definition: SLNode.h:640
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
friend class SLNode
Definition: SLScene.h:48
SLAnimManager & animManager()
Definition: SLScene.h:97
T mod(T a, T b)
Definition: Utils.h:250

◆ assemble()

void AppDemoSceneJansUniverse::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 46 of file AppDemoSceneJansUniverse.cpp.

48 {
49  SLCamera* cam1 = new SLCamera("Camera 1");
50  cam1->clipNear(0.1f);
51  cam1->clipFar(1000);
52  cam1->translation(0, 0, 75);
53  cam1->focalDist(75);
54  cam1->lookAt(0, 0, 0);
55  cam1->background().colors(SLCol4f(0.3f, 0.3f, 0.3f));
56  cam1->setInitialState();
57 
58  // Root scene node
59  SLNode* scene = new SLNode;
60  root3D(scene);
61  scene->addChild(cam1);
62 
63  // Generate NUM_MAT cook-torrance materials
64  SLVMaterial materials(NUM_MAT_MESH);
65  for (int i = 0; i < NUM_MAT_MESH; ++i)
66  {
67  SLstring matName = "mat-" + std::to_string(i);
68  materials[i] = new SLMaterial(am,
69  matName.c_str(),
70  nullptr,
71  _textureC,
72  nullptr,
73  _textureM,
74  _textureR,
75  nullptr,
76  nullptr);
77  SLCol4f color;
78  color.hsva2rgba(SLVec4f(Utils::TWOPI * (float)i / (float)NUM_MAT_MESH, 1.0f, 1.0f));
79  materials[i]->diffuse(color);
80  }
81 
82  // Generate NUM_MESH sphere meshes
83  SLVMesh meshes(NUM_MAT_MESH);
84  for (int i = 0; i < NUM_MAT_MESH; ++i)
85  {
86  SLstring meshName = "mesh-" + std::to_string(i);
87  meshes[i] = new SLSphere(am,
88  1.0f,
89  32,
90  32,
91  meshName.c_str(),
92  materials[i % NUM_MAT_MESH]);
93  }
94 
95  // Create universe
97  this,
98  scene,
99  0,
100  NUM_LEVELS,
101  NUM_CHILDREN,
102  materials,
103  meshes);
104 
105  sv->camera(cam1);
106  sv->doWaitOnIdle(false);
107 }
const SLuint NUM_LEVELS
const SLuint NUM_CHILDREN
const SLuint NUM_MAT_MESH
string SLstring
Definition: SL.h:158
vector< SLMaterial * > SLVMaterial
STL vector of material pointers.
Definition: SLMaterial.h:274
vector< SLMesh * > SLVMesh
Definition: SLMesh.h:263
SLVec4< SLfloat > SLVec4f
Definition: SLVec4.h:235
SLVec4< SLfloat > SLCol4f
Definition: SLVec4.h:237
void generateUniverse(SLAssetManager *am, SLScene *s, SLNode *parent, SLint parentID, SLuint levels, SLuint childCount, SLVMaterial &materials, SLVMesh &meshes)
Generates the Jan's Universe scene.
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
Defines a standard CG material with textures and a shader program.
Definition: SLMaterial.h:56
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
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
SLSphere creates a sphere mesh based on SLSpheric w. 180 deg polar angle.
Definition: SLSphere.h:33
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

◆ generateUniverse()

void AppDemoSceneJansUniverse::generateUniverse ( SLAssetManager am,
SLScene s,
SLNode parent,
SLint  parentID,
SLuint  levels,
SLuint  childCount,
SLVMaterial materials,
SLVMesh meshes 
)

Generates the Jan's Universe scene.

Definition at line 166 of file AppDemoSceneJansUniverse.cpp.

174 {
175  // Point light without mesh
176  SLLightSpot* light = new SLLightSpot(am,
177  s,
178  0,
179  0,
180  0,
181  1.0f,
182  180,
183  0,
184  1000,
185  1000,
186  true);
187  light->attenuation(1, 0, 0);
188  light->scale(10, 10, 10);
189  light->diffuseColor({1.0f, 1.0f, 0.5f});
190 
191  // Node animation on light node
192  SLAnimation* lightAnim = s->animManager().createNodeAnimation("anim0",
193  60,
194  true,
195  EC_linear,
196  AL_loop);
197  lightAnim->createNodeAnimTrackForRotation360(light,
198  SLVec3f(0, 1, 0));
199 
200  parent->addChild(light);
201 
202  SLuint numNodes = 1;
203 
204  addUniverseLevel(am,
205  s,
206  light,
207  parentID,
208  1,
209  levels,
210  childCount,
211  materials,
212  meshes,
213  numNodes);
214 }
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318
void diffuseColor(const SLCol4f &diff)
Definition: SLLight.h:107
void attenuation(const SLfloat kConstant, const SLfloat kLinear, const SLfloat kQuadratic)
Definition: SLLight.h:116
SLLightSpot class for a spot light source.
Definition: SLLightSpot.h:36

◆ registerAssetsToLoad()

void AppDemoSceneJansUniverse::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 38 of file AppDemoSceneJansUniverse.cpp.

39 {
40  al.addTextureToLoad(_textureC, AppCommon::texturePath + "rusty-metal_2048_C.jpg");
41  al.addTextureToLoad(_textureM, AppCommon::texturePath + "rusty-metal_2048_M.jpg");
42  al.addTextureToLoad(_textureR, AppCommon::texturePath + "rusty-metal_2048_R.jpg");
43 }
static SLstring texturePath
Path to texture images.
Definition: AppCommon.h:86
void addTextureToLoad(SLGLTexture *&texture, const SLstring &path, SLint min_filter=GL_LINEAR_MIPMAP_LINEAR, SLint mag_filter=GL_LINEAR, SLTextureType type=TT_unknown, SLint wrapS=GL_REPEAT, SLint wrapT=GL_REPEAT)
Add 2D textures with internal image allocation.

Member Data Documentation

◆ _textureC

SLGLTexture* AppDemoSceneJansUniverse::_textureC
private

Definition at line 64 of file AppDemoSceneJansUniverse.h.

◆ _textureM

SLGLTexture* AppDemoSceneJansUniverse::_textureM
private

Definition at line 65 of file AppDemoSceneJansUniverse.h.

◆ _textureR

SLGLTexture* AppDemoSceneJansUniverse::_textureR
private

Definition at line 66 of file AppDemoSceneJansUniverse.h.


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