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

Class for level of detail test scene. More...

#include <AppDemoSceneLevelOfDetail.h>

Inheritance diagram for AppDemoSceneLevelOfDetail:
[legend]

Public Member Functions

 AppDemoSceneLevelOfDetail (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
 
SLGLTexture_texFloorDif
 
SLGLTexture_texFloorNrm
 
SLNode_columnLOD
 

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 level of detail test scene.

Definition at line 20 of file AppDemoSceneLevelOfDetail.h.

Constructor & Destructor Documentation

◆ AppDemoSceneLevelOfDetail()

AppDemoSceneLevelOfDetail::AppDemoSceneLevelOfDetail ( SLSceneID  sceneID)

Definition at line 21 of file AppDemoSceneLevelOfDetail.cpp.

22  : SLScene("Level of Detail Test"),
24 {
25 }
SLScene SLSceneView SLint sceneID
Definition: SLScene.h:33
SLScene(const SLstring &name)
Definition: SLScene.cpp:39

Member Function Documentation

◆ assemble()

void AppDemoSceneLevelOfDetail::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 44 of file AppDemoSceneLevelOfDetail.cpp.

45 {
46  SLchar name[512];
47  SLint size;
49  {
50  size = 25;
51  snprintf(name,
52  sizeof(name),
53  "%d corinthian columns without LOD",
54  size * size);
55  this->name(name);
56  }
57  else
58  {
59  size = 50;
60  snprintf(name,
61  sizeof(name),
62  "%d corinthian columns with LOD",
63  size * size);
64  this->name(name);
65  }
66  info(this->name() + " with cascaded shadow mapping. In the Day-Time dialogue you can change the sun angle.");
67 
68  // Create ground material
69  SLMaterial* matFloor = new SLMaterial(am,
70  "matFloor",
72  _texFloorNrm);
73 
74  // Define camera
75  SLCamera* cam1 = new SLCamera;
76  cam1->translation(0, 1.7f, 20);
77  cam1->lookAt(0, 1.7f, 0);
78  cam1->focalDist(cam1->translationOS().length());
79  cam1->clipFar(600);
80  cam1->background().colors(SLCol4f(0.1f, 0.4f, 0.8f));
81  cam1->setInitialState();
82 
83  // Create directional light for the sunlight
84  SLLightDirect* sunLight = new SLLightDirect(am, this, 1.0f);
85  sunLight->powers(0.25f, 1.0f, 1.0f);
86  sunLight->attenuation(1, 0, 0);
87  sunLight->translation(0, 1.7f, 0);
88  sunLight->lookAt(-1, 0, -1);
89  sunLight->doSunPowerAdaptation(true);
90 
91  // Add cascaded shadow mapping
92  sunLight->createsShadows(true);
93  sunLight->createShadowMapAutoSize(cam1);
94  sunLight->doSmoothShadows(true);
95  sunLight->castsShadows(false);
96  sunLight->shadowMinBias(0.003f);
97  sunLight->shadowMaxBias(0.012f);
98 
99  // Let the sun be rotated by time and location
102  7.24337,
103  488.2); // Ecke Giosa
105  7.24310,
106  488.7 + 1.7); // auf Parkplatz
107 
108  // Floor rectangle
109  SLNode* rect = new SLNode(new SLRectangle(am,
110  SLVec2f(-200, -200),
111  SLVec2f(200, 200),
112  SLVec2f(0, 0),
113  SLVec2f(50, 50),
114  50,
115  50,
116  "Floor",
117  matFloor));
118  rect->rotate(90, -1, 0, 0);
119  rect->castsShadows(false);
120 
121  // Configure the corinthian column
122  SLNode* columnL0 = _columnLOD->findChild<SLNode>("Corinthian-Column-Round-L0");
123  SLNode* columnL1 = _columnLOD->findChild<SLNode>("Corinthian-Column-Round-L1");
124  SLNode* columnL2 = _columnLOD->findChild<SLNode>("Corinthian-Column-Round-L2");
125  SLNode* columnL3 = _columnLOD->findChild<SLNode>("Corinthian-Column-Round-L3");
126 
127  // Assemble scene
128  SLNode* scene = new SLNode("Scene");
129  root3D(scene);
130  scene->addChild(sunLight);
131  scene->addChild(rect);
132  scene->addChild(cam1);
133 
134  // create loads of pillars
135  SLint numColumns = size * size;
136  SLfloat offset = 5.0f;
137  SLfloat z = (float)(size - 1) * offset * 0.5f;
138 
139  for (SLint iZ = 0; iZ < size; ++iZ)
140  {
141  SLfloat x = -(float)(size - 1) * offset * 0.5f;
142 
143  for (SLint iX = 0; iX < size; ++iX)
144  {
145  SLint iZX = iZ * size + iX;
146 
148  {
149  // Without just the level 0 node
150  string strNode = "Node" + std::to_string(iZX);
151  SLNode* column = new SLNode(columnL1->mesh(),
152  strNode + "-L0");
153  column->translate(x, 0, z, TS_object);
154  scene->addChild(column);
155  }
156  else
157  {
158  // With LOD parent node and 3 levels
159  string strLOD = "LOD" + std::to_string(iZX);
160  SLNodeLOD* lod_group = new SLNodeLOD(strLOD);
161  lod_group->translate(x, 0, z, TS_object);
162  lod_group->addChildLOD(new SLNode(columnL1->mesh(),
163  strLOD + "-L0"),
164  0.1f,
165  3);
166  lod_group->addChildLOD(new SLNode(columnL2->mesh(),
167  strLOD + "-L1"),
168  0.01f,
169  3);
170  lod_group->addChildLOD(new SLNode(columnL3->mesh(),
171  strLOD + "-L2"),
172  0.0001f,
173  3);
174  scene->addChild(lod_group);
175  }
176  x += offset;
177  }
178  z -= offset;
179  }
180 
181  // Set active camera & the root pointer
182  sv->camera(cam1);
183  sv->doWaitOnIdle(false);
184 }
@ SID_Benchmark_ColumnsNoLOD
float SLfloat
Definition: SL.h:173
char SLchar
Definition: SL.h:162
int SLint
Definition: SL.h:170
@ TS_object
Definition: SLEnums.h:210
SLVec2< SLfloat > SLVec2f
Definition: SLVec2.h:141
SLVec4< SLfloat > SLCol4f
Definition: SLVec4.h:237
static SLDeviceLocation devLoc
Mobile device location from GPS.
Definition: AppCommon.h:65
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
void defaultLatLonAlt(int degreesLat, int minutesLat, double secondsLat, int degreesLon, int minutesLon, double secondsLon, double altitudeM)
Default coordinate setter in WGS84 Lat-Lon in degrees, minutes and seconds.
void originLatLonAlt(int degreesLat, int minutesLat, double secondsLat, int degreesLon, int minutesLon, double secondsLon, double altitudeM)
Origin coordinate setter in WGS84 Lat-Lon in degrees, minutes and seconds.
void sunLightNode(SLLightDirect *sln)
SLLightDirect class for a directional light source.
Definition: SLLightDirect.h:40
void doSunPowerAdaptation(SLbool enabled)
Definition: SLLightDirect.h:82
void createShadowMapAutoSize(SLCamera *camera, SLVec2i texSize=SLVec2i(1024, 1024), int numCascades=4) override
void createsShadows(SLbool createsShadows)
Definition: SLLight.cpp:98
void shadowMaxBias(SLfloat maxBias)
Definition: SLLight.h:129
void doSmoothShadows(SLbool doSS)
Definition: SLLight.h:126
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
void shadowMinBias(SLfloat minBias)
Definition: SLLight.h:128
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 translation(const SLVec3f &pos, SLTransformSpace relativeTo=TS_parent)
Definition: SLNode.cpp:828
void rotate(const SLQuat4f &rot, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:945
void castsShadows(SLbool castsShadows)
Definition: SLNode.h:282
T * findChild(const SLstring &name="", SLbool findRecursive=true)
Definition: SLNode.h:388
SLVec3f translationOS() const
Definition: SLNode.h:468
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 translate(const SLVec3f &vec, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:906
Level of detail (LOD) group node based on screen space coverage.
Definition: SLNodeLOD.h:28
void addChildLOD(SLNode *child, SLfloat minLodLimit, SLubyte levelForSM=0)
Adds an LOD node with forced decreasing min LOD coverage.
Definition: SLNodeLOD.cpp:32
const SLstring & name() const
Definition: SLObject.h:38
SLRectangle creates a rectangular mesh with a certain resolution.
Definition: SLRectangle.h:29
SLNode * root3D()
Definition: SLScene.h:99
friend class SLNode
Definition: SLScene.h:48
SLstring & info()
Definition: SLScene.h:102
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 length() const
Definition: SLVec3.h:122

◆ registerAssetsToLoad()

void AppDemoSceneLevelOfDetail::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 28 of file AppDemoSceneLevelOfDetail.cpp.

29 {
32  "GLTF/CorinthianColumn/PavementSlateSquare2_2K_DIF.jpg",
36  "GLTF/CorinthianColumn/PavementSlateSquare2_2K_NRM.jpg",
40  "GLTF/CorinthianColumn/Corinthian-Column-Round-LOD.gltf");
41 }
#define SL_ANISOTROPY_MAX
Definition: SLGLTexture.h:34
static SLstring modelPath
Path to 3D models.
Definition: AppCommon.h:85
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.
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.

Member Data Documentation

◆ _columnLOD

SLNode* AppDemoSceneLevelOfDetail::_columnLOD
private

Definition at line 48 of file AppDemoSceneLevelOfDetail.h.

◆ _sceneID

SLSceneID AppDemoSceneLevelOfDetail::_sceneID
private

Definition at line 45 of file AppDemoSceneLevelOfDetail.h.

◆ _texFloorDif

SLGLTexture* AppDemoSceneLevelOfDetail::_texFloorDif
private

Definition at line 46 of file AppDemoSceneLevelOfDetail.h.

◆ _texFloorNrm

SLGLTexture* AppDemoSceneLevelOfDetail::_texFloorNrm
private

Definition at line 47 of file AppDemoSceneLevelOfDetail.h.


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