Commit b1ac2185448980b7428508a82b13c1e09d744c22
1 parent
6eeaff16
Added SceneView Example
Change-Id: I4aa9061ee5b4c64e2c8660935132fa9d6eaf593e
Showing
10 changed files
with
312 additions
and
0 deletions
com.samsung.dali-demo.xml
| ... | ... | @@ -286,6 +286,9 @@ |
| 286 | 286 | <ui-application appid="rendering-triangle.example" exec="/usr/apps/com.samsung.dali-demo/bin/rendering-triangle.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> |
| 287 | 287 | <label>Rendering Triangle</label> |
| 288 | 288 | </ui-application> |
| 289 | + <ui-application appid="scene-view.example" exec="/usr/apps/com.samsung.dali-demo/bin/scene-view.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> | |
| 290 | + <label>Scene View</label> | |
| 291 | + </ui-application> | |
| 289 | 292 | <ui-application appid="scene3d.example" exec="/usr/apps/com.samsung.dali-demo/bin/scene3d.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> |
| 290 | 293 | <label>Scene3D</label> |
| 291 | 294 | </ui-application> | ... | ... |
demo/dali-demo.cpp
| ... | ... | @@ -60,6 +60,7 @@ int DALI_EXPORT_API main(int argc, char** argv) |
| 60 | 60 | demo.AddExample(Example("rendering-skybox.example", DALI_DEMO_STR_TITLE_SKYBOX)); |
| 61 | 61 | demo.AddExample(Example("rendering-basic-pbr.example", DALI_DEMO_STR_TITLE_PBR)); |
| 62 | 62 | #ifdef DALI_SCENE3D_AVAILABLE |
| 63 | + demo.AddExample(Example("scene-view.example", DALI_DEMO_STR_TITLE_SCENE_VIEW)); | |
| 63 | 64 | demo.AddExample(Example("scene3d-model.example", DALI_DEMO_STR_TITLE_SCENE3D_MODEL)); |
| 64 | 65 | demo.AddExample(Example("scene3d.example", DALI_DEMO_STR_TITLE_SCENE3D)); |
| 65 | 66 | #endif //DALI_SCENE3D_AVAILABLE | ... | ... |
examples/scene-view/README.md
0 → 100644
| 1 | +# Scene View Example | |
| 2 | + | |
| 3 | +This is a basic example showing how to use a SceneView and a Model in the Scene3D library. | |
| 4 | +It also shows how an enviroment map can be loaded into the scene view and how to set the image-based-light source on the model. | |
| 5 | + | |
| 6 | +The setup also shows how to do a rotation animation around the model. | |
| 7 | + | |
| 8 | + | ... | ... |
examples/scene-view/scene-view-example.cpp
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2023 Samsung Electronics Co., Ltd. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + * | |
| 16 | + */ | |
| 17 | + | |
| 18 | +// EXTERNAL INCLUDES | |
| 19 | +#include <dali-scene3d/dali-scene3d.h> | |
| 20 | +#include <dali-toolkit/dali-toolkit.h> | |
| 21 | + | |
| 22 | +// INTERNAL INCLUDES | |
| 23 | +#include <dali/devel-api/adaptor-framework/file-stream.h> | |
| 24 | + | |
| 25 | +using namespace Dali; | |
| 26 | +using namespace Toolkit; | |
| 27 | +using namespace Scene3D; | |
| 28 | + | |
| 29 | +namespace | |
| 30 | +{ | |
| 31 | +const char* CUBEMAP_SKY_BOX_URL = DEMO_IMAGE_DIR "veste_oberhaus_cubemap.png"; | |
| 32 | +const char* CAMERA_NAME("MyCamera"); | |
| 33 | + | |
| 34 | +const char* MODEL_URL = DEMO_MODEL_DIR "SphereMetallic.gltf"; | |
| 35 | +constexpr Vector2 MODEL_SIZE(300.0f, 300.0f); | |
| 36 | + | |
| 37 | +const Quaternion MODEL_ROTATION(Degree(360.f), Vector3(0.1f, 1.0f, -0.1f)); | |
| 38 | +} // namespace | |
| 39 | + | |
| 40 | +class SceneViewExample : public ConnectionTracker | |
| 41 | +{ | |
| 42 | +public: | |
| 43 | + SceneViewExample(Application& application) | |
| 44 | + : mApplication(application) | |
| 45 | + { | |
| 46 | + // Connect to the Application's Init signal | |
| 47 | + mApplication.InitSignal().Connect(this, &SceneViewExample::Create); | |
| 48 | + } | |
| 49 | + | |
| 50 | + ~SceneViewExample() = default; | |
| 51 | + | |
| 52 | +private: | |
| 53 | + // The Init signal is received once (only) during the Application lifetime | |
| 54 | + void Create(Application& application) | |
| 55 | + { | |
| 56 | + // Get a handle to the window | |
| 57 | + Window window = application.GetWindow(); | |
| 58 | + const Vector2 windowSize = window.GetSize(); | |
| 59 | + | |
| 60 | + // Create a SceneView and set the Skybox | |
| 61 | + SceneView sceneView = Handle::New<SceneView>({{Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER}, | |
| 62 | + {Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER}, | |
| 63 | + {Actor::Property::SIZE, windowSize}}); | |
| 64 | + sceneView.SetSkybox(CUBEMAP_SKY_BOX_URL); | |
| 65 | + window.Add(sceneView); | |
| 66 | + | |
| 67 | + // Load the model and set IBL | |
| 68 | + Model model = Model::New(MODEL_URL); | |
| 69 | + model.SetProperties({ | |
| 70 | + {Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER}, | |
| 71 | + {Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER}, | |
| 72 | + {Actor::Property::SIZE, MODEL_SIZE}, | |
| 73 | + }); | |
| 74 | + model.SetImageBasedLightSource(CUBEMAP_SKY_BOX_URL, CUBEMAP_SKY_BOX_URL); | |
| 75 | + sceneView.Add(model); | |
| 76 | + | |
| 77 | + // Create a new camera and reparent as we want to rotate the camera around the origin | |
| 78 | + CameraActor cameraActor = Handle::New<CameraActor>({{Actor::Property::NAME, CAMERA_NAME}}); | |
| 79 | + sceneView.AddCamera(cameraActor); | |
| 80 | + sceneView.SelectCamera(CAMERA_NAME); | |
| 81 | + cameraActor.SetType(Camera::LOOK_AT_TARGET); | |
| 82 | + cameraActor.SetTargetPosition(Vector3::ZERO); | |
| 83 | + cameraActor.Unparent(); | |
| 84 | + Actor rotatingActor = Handle::New<Actor>({{Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER}, | |
| 85 | + {Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER}}); | |
| 86 | + rotatingActor.Add(cameraActor); | |
| 87 | + sceneView.Add(rotatingActor); | |
| 88 | + | |
| 89 | + Animation animation = Animation::New(10.0f); | |
| 90 | + animation.SetLooping(true); | |
| 91 | + animation.AnimateBy(Property(rotatingActor, Actor::Property::ORIENTATION), MODEL_ROTATION); | |
| 92 | + animation.Play(); | |
| 93 | + | |
| 94 | + // Respond to key events | |
| 95 | + window.KeyEventSignal().Connect(this, &SceneViewExample::OnKeyEvent); | |
| 96 | + } | |
| 97 | + | |
| 98 | + /** | |
| 99 | + * @brief Called when any key event is received | |
| 100 | + * | |
| 101 | + * Will use this to quit the application if Back or the Escape key is received | |
| 102 | + * @param[in] event The key event information | |
| 103 | + */ | |
| 104 | + void OnKeyEvent(const KeyEvent& event) | |
| 105 | + { | |
| 106 | + if(event.GetState() == KeyEvent::DOWN) | |
| 107 | + { | |
| 108 | + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) | |
| 109 | + { | |
| 110 | + mApplication.Quit(); | |
| 111 | + } | |
| 112 | + } | |
| 113 | + } | |
| 114 | + | |
| 115 | +private: | |
| 116 | + Application& mApplication; | |
| 117 | +}; | |
| 118 | + | |
| 119 | +int DALI_EXPORT_API main(int argc, char** argv) | |
| 120 | +{ | |
| 121 | + Application application = Application::New(&argc, &argv); | |
| 122 | + SceneViewExample test(application); | |
| 123 | + application.MainLoop(); | |
| 124 | + return 0; | |
| 125 | +} | ... | ... |
examples/scene-view/scene-view.png
0 → 100644
1000 KB
resources/images/veste_oberhaus_cubemap.png
0 → 100644