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

Class for all variants of generated shaders on the Suzanne head. More...

#include <AppDemoSceneSuzanne.h>

Inheritance diagram for AppDemoSceneSuzanne:
[legend]

Public Member Functions

 AppDemoSceneSuzanne (SLstring name, bool textureMapping, bool normalMapping, bool occlusionMapping, bool shadowMapping, bool environmentMapping)
 
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

SLNode_suzanneInCube
 
SLSkybox_skybox
 
bool _textureMapping
 
bool _normalMapping
 
bool _occlusionMapping
 
bool _shadowMapping
 
bool _environmentMapping
 

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 all variants of generated shaders on the Suzanne head.

Definition at line 20 of file AppDemoSceneSuzanne.h.

Constructor & Destructor Documentation

◆ AppDemoSceneSuzanne()

AppDemoSceneSuzanne::AppDemoSceneSuzanne ( SLstring  name,
bool  textureMapping,
bool  normalMapping,
bool  occlusionMapping,
bool  shadowMapping,
bool  environmentMapping 
)

Definition at line 20 of file AppDemoSceneSuzanne.cpp.

26  : SLScene(name),
27  _textureMapping(textureMapping),
28  _normalMapping(normalMapping),
29  _occlusionMapping(occlusionMapping),
30  _shadowMapping(shadowMapping),
31  _environmentMapping(environmentMapping)
32 {
33  info(name);
34  _skybox = nullptr;
35 }
const SLstring & name() const
Definition: SLObject.h:38
SLScene(const SLstring &name)
Definition: SLScene.cpp:39
SLstring & info()
Definition: SLScene.h:102

Member Function Documentation

◆ assemble()

void AppDemoSceneSuzanne::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 58 of file AppDemoSceneSuzanne.cpp.

59 {
60  // Create a scene group node
61  SLNode* scene = new SLNode("scene node");
62  root3D(scene);
63 
64  // Create camera in the center
65  SLCamera* cam1 = new SLCamera("Camera 1");
66  cam1->translation(0, 0.5f, 2);
67  cam1->lookAt(0, 0.5f, 0);
68  cam1->setInitialState();
69  cam1->focalDist(2);
70  scene->addChild(cam1);
71 
72  // Create directional light for the sunlight
73  SLLightDirect* light;
74 
76  {
77  SLLight::gamma = 2.0f;
78  light = new SLLightDirect(am, this, 0.1f);
79  light->ambientPower(0.0f);
80  light->diffusePower(3.0f);
81  }
82  else
83  {
84  SLLight::gamma = 1.0f;
85  light = new SLLightDirect(am, this, 0.1f);
86  light->ambientPower(0.6f);
87  light->diffusePower(0.6f);
88  }
89 
90  light->attenuation(1, 0, 0);
91  light->translate(0, 0, 0.5);
92  light->lookAt(1, -1, 0.5);
93  SLAnimation* lightAnim = animManager().createNodeAnimation("LightAnim",
94  4.0f,
95  true,
98  lightAnim->createNodeAnimTrackForRotation(light,
99  -180,
100  SLVec3f(0, 1, 0));
101 
102  scene->addChild(light);
103 
104  // Add shadow mapping
105  if (_shadowMapping)
106  {
107  light->createsShadows(true);
108  light->createShadowMap(-3,
109  3,
110  SLVec2f(5, 5),
111  SLVec2i(2048, 2048));
112  light->doSmoothShadows(true);
113  }
114 
115  SLCol4f stoneColor(0.56f, 0.50f, 0.44f);
116 
117  // Remove unwanted textures
118  auto materialUpdater = [=](SLMaterial* mat)
119  {
120  if (!_textureMapping)
121  {
122  mat->removeTextureType(TT_diffuse);
123  mat->ambientDiffuse(stoneColor);
124  }
125 
126  if (!_normalMapping)
127  mat->removeTextureType(TT_normal);
128 
129  if (!_occlusionMapping)
130  mat->removeTextureType(TT_occlusion);
131 
133  {
134  mat->skybox(_skybox);
135  mat->reflectionModel(RM_CookTorrance);
136  this->skybox(_skybox);
137  }
138  };
139  _suzanneInCube->updateMeshMat(materialUpdater,
140  true);
141 
142  scene->addChild(_suzanneInCube);
143 
144  sv->camera(cam1);
145 
146  // Save energy
147  sv->doWaitOnIdle(true);
148 }
@ EC_inOutSine
sine easing in and then out
Definition: SLEnums.h:200
@ RM_CookTorrance
Definition: SLEnums.h:290
@ AL_pingPongLoop
loop forward and backwards
Definition: SLEnums.h:171
@ TT_normal
Definition: SLGLTexture.h:79
@ TT_diffuse
Definition: SLGLTexture.h:78
@ TT_occlusion
Definition: SLGLTexture.h:83
SLVec2< SLint > SLVec2i
Definition: SLVec2.h:140
SLVec2< SLfloat > SLVec2f
Definition: SLVec2.h:141
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 * createNodeAnimTrackForRotation(SLNode *target, SLfloat angleDeg1, const SLVec3f &axis)
Active or visible camera node class.
Definition: SLCamera.h:54
void focalDist(const SLfloat f)
Definition: SLCamera.h:116
SLLightDirect class for a directional light source.
Definition: SLLightDirect.h:40
void createShadowMap(float clipNear=0.1f, float clipFar=20.0f, SLVec2f size=SLVec2f(8, 8), SLVec2i texSize=SLVec2i(1024, 1024)) override
static SLfloat gamma
final output gamma value
Definition: SLLight.h:204
void createsShadows(SLbool createsShadows)
Definition: SLLight.cpp:98
void ambientPower(const SLfloat ambPow)
Definition: SLLight.h:106
void doSmoothShadows(SLbool doSS)
Definition: SLLight.h:126
void diffusePower(const SLfloat diffPow)
Definition: SLLight.h:108
void attenuation(const SLfloat kConstant, const SLfloat kLinear, const SLfloat kQuadratic)
Definition: SLLight.h:116
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
void updateMeshMat(std::function< void(SLMaterial *m)> setMat, bool recursive)
Updates the mesh material recursively with a material lambda.
Definition: SLNode.cpp:1161
void translate(const SLVec3f &vec, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:906
SLSkybox * skybox()
Definition: SLScene.h:101
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
void doWaitOnIdle(SLbool doWI)
Definition: SLSceneView.h:149

◆ registerAssetsToLoad()

void AppDemoSceneSuzanne::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 AppDemoSceneSuzanne.cpp.

39 {
42  "GLTF/AO-Baked-Test/AO-Baked-Test.gltf",
43  nullptr,
44  false, // delete tex images after build
45  true, // load meshes only
46  nullptr, // override material
47  0.5f);
48 
51  al.modelPath() +
52  "GLTF/glTF-Sample-Models/hdris/envmap_malibu.hdr",
53  SLVec2i(256, 256),
54  "HDR Skybox");
55 }
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.

Member Data Documentation

◆ _environmentMapping

bool AppDemoSceneSuzanne::_environmentMapping
private

Definition at line 57 of file AppDemoSceneSuzanne.h.

◆ _normalMapping

bool AppDemoSceneSuzanne::_normalMapping
private

Definition at line 54 of file AppDemoSceneSuzanne.h.

◆ _occlusionMapping

bool AppDemoSceneSuzanne::_occlusionMapping
private

Definition at line 55 of file AppDemoSceneSuzanne.h.

◆ _shadowMapping

bool AppDemoSceneSuzanne::_shadowMapping
private

Definition at line 56 of file AppDemoSceneSuzanne.h.

◆ _skybox

SLSkybox* AppDemoSceneSuzanne::_skybox
private

Definition at line 52 of file AppDemoSceneSuzanne.h.

◆ _suzanneInCube

SLNode* AppDemoSceneSuzanne::_suzanneInCube
private

Definition at line 51 of file AppDemoSceneSuzanne.h.

◆ _textureMapping

bool AppDemoSceneSuzanne::_textureMapping
private

Definition at line 53 of file AppDemoSceneSuzanne.h.


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