SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
AppDemoSceneAnimSkinned.cpp
Go to the documentation of this file.
1 /**
2  * \file AppDemoSceneAnimSkinned.cpp
3  * \brief Implementation for an SLScene inherited class
4  * \details For more info about App framework and the scene assembly see:
5  * https://cpvrlab.github.io/SLProject4/app-framework.html
6  * \date May 2024
7  * \authors Marcus Hudritsch, Marino von Wattenwyl
8  * \copyright http://opensource.org/licenses/GPL-3.0
9  * \remarks Please use clangformat to format the code. See more code style on
10  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
11 */
12 
14 #include <AppCommon.h>
15 #include <SLAssetLoader.h>
16 #include <SLLightSpot.h>
17 #include <SLGrid.h>
18 
19 //-----------------------------------------------------------------------------
21  : SLScene("Skeletal Animation Test Scene")
22 {
23  info("Skeletal Animation Test Scene");
24 }
25 //-----------------------------------------------------------------------------
26 //! All assets the should be loaded in parallel must be registered in here.
28 {
31  "DAE/AstroBoy/AstroBoy.dae");
34  "GLTF/Sintel/Sintel_LowRes-Rigged.gltf");
37  "DAE/SkinnedCube/skinnedcube2.dae");
40  "DAE/SkinnedCube/skinnedcube4.dae");
43  "DAE/SkinnedCube/skinnedcube5.dae");
44 }
45 //-----------------------------------------------------------------------------
46 //! After parallel loading of the assets the scene gets assembled in here.
48 {
49  // Root scene node
50  SLNode* scene = new SLNode("scene group");
51  root3D(scene);
52 
53  // camera
54  SLCamera* cam1 = new SLCamera("Camera 1");
55  cam1->translation(0, 2, 10);
56  cam1->lookAt(0, 2, 0);
57  cam1->focalDist(10);
58  cam1->setInitialState();
59  cam1->background().colors(SLCol4f(0.1f, 0.4f, 0.8f));
60  cam1->setInitialState();
62  scene->addChild(cam1);
63 
64  // light
65  SLLightSpot* light1 = new SLLightSpot(am,
66  this,
67  10,
68  10,
69  5,
70  0.5f);
71  light1->powers(0.2f, 1.0f, 1.0f);
72  light1->attenuation(1, 0, 0);
73  scene->addChild(light1);
74 
75  // Floor grid
76  SLMaterial* m2 = new SLMaterial(am, "m2", SLCol4f::WHITE);
77  SLGrid* grid = new SLGrid(am,
78  SLVec3f(-5, 0, -5),
79  SLVec3f(5, 0, 5),
80  20,
81  20,
82  "Grid",
83  m2);
84  scene->addChild(new SLNode(grid, "grid"));
85 
86  // Astro boy character
87  _char1->translate(-1, 0, 0);
88  SLAnimPlayback* char1Anim = animManager().animPlaybackByName("unnamed_anim_0");
89  char1Anim->playForward();
90  scene->addChild(_char1);
91 
92  // Sintel character
93  _char2->translate(1, 0, 0);
94  SLAnimPlayback* char2Anim = animManager().animPlaybackByName("Wave");
95  char2Anim->playForward();
96  char2Anim->playbackRate(30);
97  scene->addChild(_char2);
98 
99  // Skinned cube 1
100  _cube1->translate(3, 0, 0);
101  SLAnimPlayback* cube1Anim = animManager().animPlaybackByName("unnamed_anim_2");
102  cube1Anim->easing(EC_inOutSine);
103  cube1Anim->playForward();
104  scene->addChild(_cube1);
105 
106  // Skinned cube 2
107  _cube2->translate(-3, 0, 0);
108  SLAnimPlayback* cube2Anim = animManager().animPlaybackByName("unnamed_anim_3");
109  cube2Anim->easing(EC_inOutSine);
110  cube2Anim->playForward();
111  scene->addChild(_cube2);
112 
113  // Skinned cube 3
114  _cube3->translate(0, 3, 0);
115  SLAnimPlayback* cube3Anim = animManager().animPlaybackByName("unnamed_anim_4");
116  cube3Anim->loop(AL_pingPongLoop);
117  cube3Anim->easing(EC_inOutCubic);
118  cube3Anim->playForward();
119  scene->addChild(_cube3);
120 
121  sv->camera(cam1);
122 }
123 //-----------------------------------------------------------------------------
The AppCommon class holds the top-level instances of the app-demo.
Class declaration for an SLScene inherited class.
@ EC_inOutCubic
cubic easing in and then out
Definition: SLEnums.h:188
@ EC_inOutSine
sine easing in and then out
Definition: SLEnums.h:200
@ AL_pingPongLoop
loop forward and backwards
Definition: SLEnums.h:171
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
static SLstring modelPath
Path to 3D models.
Definition: AppCommon.h:85
void assemble(SLAssetManager *am, SLSceneView *sv) override
After parallel loading of the assets the scene gets assembled in here.
void registerAssetsToLoad(SLAssetLoader &al) override
All scene specific assets have to be registered for async loading in here.
SLAnimPlayback * animPlaybackByName(const SLstring &name)
Returns the playback of a node animation or skeleton by name if it exists.
Manages the playback of an SLAnimation.
SLAnimLooping loop() const
SLEasingCurve easing() const
SLfloat playbackRate() const
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.
Toplevel holder of the assets meshes, materials, textures and shaders.
void colors(const SLCol4f &uniformColor)
Sets a uniform background color.
Active or visible camera node class.
Definition: SLCamera.h:54
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
SLGrid creates a rectangular grid with lines with a certain resolution.
Definition: SLGrid.h:29
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
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 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
SLNode * root3D()
Definition: SLScene.h:99
friend class SLNode
Definition: SLScene.h:48
SLAnimManager & animManager()
Definition: SLScene.h:97
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
static SLVec4 WHITE
Definition: SLVec4.h:215