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

Class for GLTF file loading demo scene. More...

#include <AppDemoSceneGLTF.h>

Inheritance diagram for AppDemoSceneGLTF:
[legend]

Public Member Functions

 AppDemoSceneGLTF (SLSceneID sceneID)
 
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
 

Private Attributes

SLSceneID _sceneID
 
SLstring _modelFile
 
SLSkybox_skybox
 
SLNode_modelGLTF
 

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 GLTF file loading demo scene.

Definition at line 20 of file AppDemoSceneGLTF.h.

Constructor & Destructor Documentation

◆ AppDemoSceneGLTF()

AppDemoSceneGLTF::AppDemoSceneGLTF ( SLSceneID  sceneID)

Definition at line 22 of file AppDemoSceneGLTF.cpp.

23  : SLScene("GLTF File Demo Scene"),
25 {
26  info("GLTF File Format Test Scene");
27 }
SLScene SLSceneView SLint sceneID
Definition: SLScene.h:33
SLScene(const SLstring &name)
Definition: SLScene.cpp:39
SLstring & info()
Definition: SLScene.h:102

Member Function Documentation

◆ assemble()

void AppDemoSceneGLTF::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 62 of file AppDemoSceneGLTF.cpp.

63 {
64  SLVec3f camPos, lookAt;
65  SLfloat camClipFar = 100;
66 
67  switch (_sceneID)
68  {
70  {
71  camPos.set(0, 0, 3);
72  lookAt.set(0, camPos.y, 0);
73  camClipFar = 20;
74  break;
75  }
77  {
78  camPos.set(0, 0.33f, 1.1f);
79  lookAt.set(0, camPos.y, 0);
80  camClipFar = 20;
81  break;
82  }
83  case SID_glTF_Sponza:
84  {
85  camPos.set(-8, 1.6f, 0);
86  lookAt.set(0, camPos.y, 0);
87  break;
88  }
90  {
91  camPos.set(0, 0, 0.5f);
92  lookAt.set(0, camPos.y, 0);
93  camClipFar = 20;
94  break;
95  }
96  }
97 
98  // Create a scene group node
99  SLNode* scene = new SLNode("scene node");
100  this->root3D(scene);
101 
102  // Create camera and initialize its parameters
103  SLCamera* cam1 = new SLCamera("Camera 1");
104  cam1->translation(camPos);
105  cam1->lookAt(lookAt);
106  cam1->background().colors(SLCol4f(0.2f, 0.2f, 0.2f));
107  cam1->focalDist(camPos.length());
108  cam1->clipFar(camClipFar);
109  cam1->setInitialState();
110  scene->addChild(cam1);
111 
112  // Add directional light with a position that corresponds roughly to the sun direction
113  SLLight::gamma = 2.2f;
114  SLLightDirect* light = new SLLightDirect(am,
115  this,
116  0.55f,
117  1.0f,
118  -0.2f,
119  0.2f,
120  0,
121  1,
122  1);
123  light->lookAt(0, 0, 0);
124  light->attenuation(1, 0, 0);
125  light->createsShadows(true);
126  light->createShadowMapAutoSize(cam1,
127  SLVec2i(2048, 2048),
128  4);
129  light->shadowMap()->cascadesFactor(1.0);
130  light->doSmoothShadows(true);
131  light->castsShadows(false);
132  light->shadowMinBias(0.001f);
133  light->shadowMaxBias(0.003f);
134  scene->addChild(light);
135 
136  // Update all materials and set their skybox to _skybox
138  { m->skybox(_skybox); },
139  true);
140 
141  scene->addChild(_modelGLTF);
142 
143  this->skybox(_skybox);
144  sv->camera(cam1);
145  sv->doWaitOnIdle(true); // Saves energy
146 }
@ SID_glTF_Sponza
@ SID_glTF_DamagedHelmet
@ SID_glTF_FlightHelmet
@ SID_glTF_WaterBottle
float SLfloat
Definition: SL.h:173
SLVec2< SLint > SLVec2i
Definition: SLVec2.h:140
SLVec4< SLfloat > SLCol4f
Definition: SLVec4.h:237
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 focalDist(const SLfloat f)
Definition: SLCamera.h:116
SLBackground & background()
Definition: SLCamera.h:165
SLLightDirect class for a directional light source.
Definition: SLLightDirect.h:40
void createShadowMapAutoSize(SLCamera *camera, SLVec2i texSize=SLVec2i(1024, 1024), int numCascades=4) override
static SLfloat gamma
final output gamma value
Definition: SLLight.h:204
void createsShadows(SLbool createsShadows)
Definition: SLLight.cpp:98
void shadowMaxBias(SLfloat maxBias)
Definition: SLLight.h:129
void shadowMap(SLShadowMap *shadowMap)
Definition: SLLight.h:125
void doSmoothShadows(SLbool doSS)
Definition: SLLight.h:126
void attenuation(const SLfloat kConstant, const SLfloat kLinear, const SLfloat kQuadratic)
Definition: SLLight.h:116
void shadowMinBias(SLfloat minBias)
Definition: SLLight.h:128
Defines a standard CG material with textures and a shader program.
Definition: SLMaterial.h:56
void skybox(SLSkybox *sb)
Definition: SLMaterial.h:207
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 castsShadows(SLbool castsShadows)
Definition: SLNode.h:282
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
void updateMeshMat(std::function< void(SLMaterial *m)> setMat, bool recursive)
Updates the mesh material recursively with a material lambda.
Definition: SLNode.cpp:1161
SLSkybox * skybox()
Definition: SLScene.h:101
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
T y
Definition: SLVec3.h:43
T length() const
Definition: SLVec3.h:122
void set(const T X, const T Y, const T Z)
Definition: SLVec3.h:59

◆ registerAssetsToLoad()

void AppDemoSceneGLTF::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 30 of file AppDemoSceneGLTF.cpp.

31 {
33  al.modelPath() +
34  "GLTF/glTF-Sample-Models/hdris/envmap_malibu.hdr",
35  SLVec2i(256, 256),
36  "HDR Skybox");
37  switch (_sceneID)
38  {
40  _modelFile = "GLTF/glTF-Sample-Models/2.0/DamagedHelmet/glTF/DamagedHelmet.gltf";
41  this->name("glTF-Sample-Model: Damaged Helmet");
42  break;
44  _modelFile = "GLTF/glTF-Sample-Models/2.0/FlightHelmet/glTF/FlightHelmet.gltf";
45  this->name("glTF-Sample-Model: Flight Helmet");
46  break;
47  case SID_glTF_Sponza:
48  _modelFile = "GLTF/glTF-Sample-Models/2.0/Sponza/glTF/Sponza.gltf";
49  this->name("glTF-Sample-Model: Sponza Palace in Dubrovnic");
50  break;
52  _modelFile = "GLTF/glTF-Sample-Models/2.0/WaterBottle/glTF/WaterBottle.gltf";
53  this->name("glTF-Sample-Model: WaterBottle");
54  break;
55  }
56 
59 }
static SLstring modelPath
Path to 3D models.
Definition: AppCommon.h:85
void addSkyboxToLoad(SLSkybox *&skybox, const SLstring &path, SLVec2i resolution, SLstring name)
Add skybox with HDR texture to load.
SLstring modelPath() const
Definition: SLAssetLoader.h:69
void addNodeToLoad(SLNode *&node, const SLstring &modelPath, SLSkybox *skybox=nullptr, SLbool deleteTexImgAfterBuild=false, SLbool loadMeshesOnly=true, SLMaterial *overrideMat=nullptr, float ambientFactor=0.5f, SLbool forceCookTorranceRM=false, SLuint flags=SLProcess_Triangulate|SLProcess_JoinIdenticalVertices|SLProcess_RemoveRedundantMaterials|SLProcess_FindDegenerates|SLProcess_FindInvalidData|SLProcess_SplitLargeMeshes)
Add mesh from file to load via assimp loader.
const SLstring & name() const
Definition: SLObject.h:38

Member Data Documentation

◆ _modelFile

SLstring AppDemoSceneGLTF::_modelFile
private

Definition at line 47 of file AppDemoSceneGLTF.h.

◆ _modelGLTF

SLNode* AppDemoSceneGLTF::_modelGLTF
private

Definition at line 49 of file AppDemoSceneGLTF.h.

◆ _sceneID

SLSceneID AppDemoSceneGLTF::_sceneID
private

Definition at line 46 of file AppDemoSceneGLTF.h.

◆ _skybox

SLSkybox* AppDemoSceneGLTF::_skybox
private

Definition at line 48 of file AppDemoSceneGLTF.h.


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