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

Class for mesh loading demo scene. More...

#include <AppDemoSceneMeshLoad.h>

Inheritance diagram for AppDemoSceneMeshLoad:
[legend]

Public Member Functions

 AppDemoSceneMeshLoad ()
 
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_meshGLTF
 
SLNode_meshFBX
 
SLNode_meshDAE
 
SLSkybox_skybox
 

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

Definition at line 20 of file AppDemoSceneMeshLoad.h.

Constructor & Destructor Documentation

◆ AppDemoSceneMeshLoad()

AppDemoSceneMeshLoad::AppDemoSceneMeshLoad ( )

Definition at line 21 of file AppDemoSceneMeshLoad.cpp.

21  : SLScene("Mesh 3D Loader Test")
22 {
23  info("We use the assimp library to load 3D file formats including materials, skeletons and animations. "
24  "You can view the skeleton with key K. You can stop all animations with SPACE key.\n"
25  "Switch between perspective and orthographic projection with key 5. "
26  "Switch to front view with key 1, to side view with key 3 and to top view with key 7.\n"
27  "Try the different stereo rendering modes in the menu Camera.");
28 }
SLScene(const SLstring &name)
Definition: SLScene.cpp:39
SLstring & info()
Definition: SLScene.h:102

Member Function Documentation

◆ assemble()

void AppDemoSceneMeshLoad::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 51 of file AppDemoSceneMeshLoad.cpp.

52 {
53  SLMaterial* matBlu = new SLMaterial(am, "Blue", SLCol4f(0, 0, 0.2f), SLCol4f(1, 1, 1), 100, 0.8f, 0);
54  SLMaterial* matRed = new SLMaterial(am, "Red", SLCol4f(0.2f, 0, 0), SLCol4f(1, 1, 1), 100, 0.8f, 0);
55  SLMaterial* matGre = new SLMaterial(am, "Green", SLCol4f(0, 0.2f, 0), SLCol4f(1, 1, 1), 100, 0.8f, 0);
56  SLMaterial* matGra = new SLMaterial(am, "Gray", SLCol4f(0.3f, 0.3f, 0.3f), SLCol4f(1, 1, 1), 100, 0, 0);
57 
58  SLCamera* cam1 = new SLCamera("Camera 1");
59  cam1->clipNear(.1f);
60  cam1->clipFar(30);
61  cam1->translation(0, 0, 12);
62  cam1->lookAt(0, 0, 0);
63  cam1->focalDist(12);
64  cam1->stereoEyeSeparation(cam1->focalDist() / 30.0f);
65  cam1->background().colors(SLCol4f(0.6f, 0.6f, 0.6f), SLCol4f(0.3f, 0.3f, 0.3f));
66  cam1->setInitialState();
68 
69  SLLightSpot* light1 = new SLLightSpot(am, this, 2.5f, 2.5f, 2.5f, 0.2f);
70  light1->powers(0.1f, 1.0f, 1.0f);
71  light1->attenuation(1, 0, 0);
72  SLAnimation* anim = this->animManager().createNodeAnimation("anim_light1_backforth", 2.0f, true, EC_inOutQuad, AL_pingPongLoop);
73  anim->createNodeAnimTrackForTranslation(light1, SLVec3f(0.0f, 0.0f, -5.0f));
74 
75  SLLightSpot* light2 = new SLLightSpot(am, this, -2.5f, -2.5f, 2.5f, 0.2f);
76  light2->powers(0.1f, 1.0f, 1.0f);
77  light2->attenuation(1, 0, 0);
78  anim = this->animManager().createNodeAnimation("anim_light2_updown", 2.0f, true, EC_inOutQuint, AL_pingPongLoop);
79  anim->createNodeAnimTrackForTranslation(light2, SLVec3f(0.0f, 5.0f, 0.0f));
80 
81  // Start animation
82  SLAnimPlayback* charAnim = this->animManager().animPlaybacksBack();
83  charAnim->playForward();
84  charAnim->playbackRate(0.8f);
85 
86  // Scale to so that the AstroBoy is about 2 (meters) high.
87  if (_meshGLTF)
88  {
89  _meshGLTF->scale(0.8f);
90  _meshGLTF->translate(-2.4f, 0, -1.5f, TS_object);
91 
92  // Update all materials and set their skybox to _skybox
94  { m->skybox(_skybox); },
95  true);
96  _skybox->exposure(4.0f);
97  }
98  if (_meshDAE)
99  {
100  _meshDAE->translate(0, -3, 0, TS_object);
101  _meshDAE->scale(2.7f);
102  }
103  if (_meshFBX)
104  {
105  _meshFBX->scale(0.1f);
106  _meshFBX->scale(0.1f);
107  _meshFBX->translate(200, 30, -30, TS_object);
108  _meshFBX->rotate(-90, 0, 1, 0);
109  }
110 
111  // define rectangles for the surrounding box
112  SLfloat b = 3; // edge size of rectangles
113  SLNode *rb, *rl, *rr, *rf, *rt;
114  SLuint res = 20;
115  rb = new SLNode(new SLRectangle(am, SLVec2f(-b, -b), SLVec2f(b, b), res, res, "rectB", matBlu), "rectBNode");
116  rb->translate(0, 0, -b, TS_object);
117  rl = new SLNode(new SLRectangle(am, SLVec2f(-b, -b), SLVec2f(b, b), res, res, "rectL", matRed), "rectLNode");
118  rl->rotate(90, 0, 1, 0);
119  rl->translate(0, 0, -b, TS_object);
120  rr = new SLNode(new SLRectangle(am, SLVec2f(-b, -b), SLVec2f(b, b), res, res, "rectR", matGre), "rectRNode");
121  rr->rotate(-90, 0, 1, 0);
122  rr->translate(0, 0, -b, TS_object);
123  rf = new SLNode(new SLRectangle(am, SLVec2f(-b, -b), SLVec2f(b, b), res, res, "rectF", matGra), "rectFNode");
124  rf->rotate(-90, 1, 0, 0);
125  rf->translate(0, 0, -b, TS_object);
126  rt = new SLNode(new SLRectangle(am, SLVec2f(-b, -b), SLVec2f(b, b), res, res, "rectT", matGra), "rectTNode");
127  rt->rotate(90, 1, 0, 0);
128  rt->translate(0, 0, -b, TS_object);
129 
130  SLNode* scene = new SLNode("Scene");
131  this->root3D(scene);
132  this->skybox(_skybox);
133  scene->addChild(light1);
134  scene->addChild(light2);
135  scene->addChild(rb);
136  scene->addChild(rl);
137  scene->addChild(rr);
138  scene->addChild(rf);
139  scene->addChild(rt);
140  if (_meshGLTF) scene->addChild(_meshGLTF);
141  if (_meshFBX) scene->addChild(_meshFBX);
142  if (_meshDAE) scene->addChild(_meshDAE);
143  scene->addChild(cam1);
144 
145  sv->camera(cam1);
146 }
float SLfloat
Definition: SL.h:173
unsigned int SLuint
Definition: SL.h:171
@ EC_inOutQuad
quadratic easing in and then out
Definition: SLEnums.h:184
@ EC_inOutQuint
quintic easing in and then out
Definition: SLEnums.h:196
@ TS_object
Definition: SLEnums.h:210
@ AL_pingPongLoop
loop forward and backwards
Definition: SLEnums.h:171
SLVec2< SLfloat > SLVec2f
Definition: SLVec2.h:141
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318
SLVec4< SLfloat > SLCol4f
Definition: SLVec4.h:237
static SLDeviceRotation devRot
Mobile device rotation from IMU.
Definition: AppCommon.h:64
static SLDeviceLocation devLoc
Mobile device location from GPS.
Definition: AppCommon.h:65
SLAnimation * createNodeAnimation(SLfloat duration)
SLAnimPlayback * animPlaybacksBack()
Definition: SLAnimManager.h:50
Manages the playback of an SLAnimation.
SLfloat playbackRate() const
SLAnimation is the base container for all animation data.
Definition: SLAnimation.h:33
SLNodeAnimTrack * createNodeAnimTrackForTranslation(SLNode *target, const SLVec3f &endPos)
void colors(const SLCol4f &uniformColor)
Sets a uniform background color.
Active or visible camera node class.
Definition: SLCamera.h:54
void stereoEyeSeparation(const SLfloat es)
Definition: SLCamera.h:119
void clipFar(const SLfloat cFar)
Definition: SLCamera.h:109
void clipNear(const SLfloat cNear)
Definition: SLCamera.h:108
void devRotLoc(SLDeviceRotation *devRot, SLDeviceLocation *devLoc)
Definition: SLCamera.h:120
void focalDist(const SLfloat f)
Definition: SLCamera.h:116
SLBackground & background()
Definition: SLCamera.h:165
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
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 rotate(const SLQuat4f &rot, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:945
void scale(SLfloat s)
Definition: SLNode.h:640
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
SLRectangle creates a rectangular mesh with a certain resolution.
Definition: SLRectangle.h:29
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
SLfloat exposure()
Definition: SLSkybox.h:54

◆ registerAssetsToLoad()

void AppDemoSceneMeshLoad::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 31 of file AppDemoSceneMeshLoad.cpp.

32 {
34  al.modelPath() +
35  "GLTF/glTF-Sample-Models/hdris/approaching_storm_4k.hdr",
36  SLVec2i(512, 512),
37  "HDR Skybox");
38 
41  "GLTF/glTF-Sample-Models/2.0/DamagedHelmet/glTF/DamagedHelmet.gltf");
44  "FBX/Duck/duck.fbx");
47  "DAE/AstroBoy/AstroBoy.dae");
48 }
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

◆ _meshDAE

SLNode* AppDemoSceneMeshLoad::_meshDAE
private

Definition at line 47 of file AppDemoSceneMeshLoad.h.

◆ _meshFBX

SLNode* AppDemoSceneMeshLoad::_meshFBX
private

Definition at line 46 of file AppDemoSceneMeshLoad.h.

◆ _meshGLTF

SLNode* AppDemoSceneMeshLoad::_meshGLTF
private

Definition at line 45 of file AppDemoSceneMeshLoad.h.

◆ _skybox

SLSkybox* AppDemoSceneMeshLoad::_skybox
private

Definition at line 48 of file AppDemoSceneMeshLoad.h.


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