Commit 6ef0038f571e25d81a49f54ba09b7cbc59bfe080
1 parent
f7e4ed1a
Change to use ModelLoader instead of Gltf2Loader and DliLoader
Change-Id: Ib9a64eef388799d4534d86f95b20735bc03a7fdd
Showing
3 changed files
with
31 additions
and
57 deletions
examples/scene3d/scene3d-example.cpp
| @@ -19,8 +19,7 @@ | @@ -19,8 +19,7 @@ | ||
| 19 | #include <dirent.h> | 19 | #include <dirent.h> |
| 20 | #include <cstring> | 20 | #include <cstring> |
| 21 | #include <string_view> | 21 | #include <string_view> |
| 22 | -#include "dali-scene3d/public-api/loader/dli-loader.h" | ||
| 23 | -#include "dali-scene3d/public-api/loader/gltf2-loader.h" | 22 | +#include "dali-scene3d/public-api/loader/model-loader.h" |
| 24 | #include "dali-scene3d/public-api/loader/light-parameters.h" | 23 | #include "dali-scene3d/public-api/loader/light-parameters.h" |
| 25 | #include "dali-scene3d/public-api/loader/load-result.h" | 24 | #include "dali-scene3d/public-api/loader/load-result.h" |
| 26 | #include "dali-scene3d/public-api/loader/shader-definition-factory.h" | 25 | #include "dali-scene3d/public-api/loader/shader-definition-factory.h" |
| @@ -141,7 +140,7 @@ void ConfigureBlendShapeShaders(ResourceBundle& resources, const SceneDefinition | @@ -141,7 +140,7 @@ void ConfigureBlendShapeShaders(ResourceBundle& resources, const SceneDefinition | ||
| 141 | } | 140 | } |
| 142 | } | 141 | } |
| 143 | 142 | ||
| 144 | -Actor LoadScene(std::string sceneName, CameraActor camera, std::vector<AnimationDefinition>* animations, Animation& animation) | 143 | +Actor LoadScene(std::string sceneName, CameraActor camera, std::vector<Dali::Animation>& generatedAnimations, Animation& animation) |
| 145 | { | 144 | { |
| 146 | ResourceBundle::PathProvider pathProvider = [](ResourceType::Value type) { | 145 | ResourceBundle::PathProvider pathProvider = [](ResourceType::Value type) { |
| 147 | return Application::GetResourcePath() + RESOURCE_TYPE_DIRS[type]; | 146 | return Application::GetResourcePath() + RESOURCE_TYPE_DIRS[type]; |
| @@ -149,48 +148,27 @@ Actor LoadScene(std::string sceneName, CameraActor camera, std::vector<Animation | @@ -149,48 +148,27 @@ Actor LoadScene(std::string sceneName, CameraActor camera, std::vector<Animation | ||
| 149 | 148 | ||
| 150 | auto path = pathProvider(ResourceType::Mesh) + sceneName; | 149 | auto path = pathProvider(ResourceType::Mesh) + sceneName; |
| 151 | 150 | ||
| 152 | - ResourceBundle resources; | ||
| 153 | - SceneDefinition scene; | ||
| 154 | - SceneMetadata metaData; | ||
| 155 | - std::vector<AnimationGroupDefinition> animGroups; | ||
| 156 | - std::vector<CameraParameters> cameraParameters; | ||
| 157 | - std::vector<LightParameters> lights; | 151 | + ResourceBundle resources; |
| 152 | + SceneDefinition scene; | ||
| 153 | + SceneMetadata metaData; | ||
| 154 | + std::vector<Dali::Scene3D::Loader::AnimationDefinition> animations; | ||
| 155 | + std::vector<AnimationGroupDefinition> animGroups; | ||
| 156 | + std::vector<CameraParameters> cameraParameters; | ||
| 157 | + std::vector<LightParameters> lights; | ||
| 158 | 158 | ||
| 159 | - animations->clear(); | 159 | + animations.clear(); |
| 160 | 160 | ||
| 161 | LoadResult output{ | 161 | LoadResult output{ |
| 162 | resources, | 162 | resources, |
| 163 | scene, | 163 | scene, |
| 164 | metaData, | 164 | metaData, |
| 165 | - *animations, | 165 | + animations, |
| 166 | animGroups, | 166 | animGroups, |
| 167 | cameraParameters, | 167 | cameraParameters, |
| 168 | lights}; | 168 | lights}; |
| 169 | 169 | ||
| 170 | - if(sceneName.rfind(DLI_EXTENSION) == sceneName.size() - DLI_EXTENSION.size()) | ||
| 171 | - { | ||
| 172 | - DliLoader loader; | ||
| 173 | - DliLoader::InputParams input{ | ||
| 174 | - pathProvider(ResourceType::Mesh), | ||
| 175 | - nullptr, | ||
| 176 | - {}, | ||
| 177 | - {}, | ||
| 178 | - nullptr, | ||
| 179 | - {}}; | ||
| 180 | - DliLoader::LoadParams loadParams{input, output}; | ||
| 181 | - if(!loader.LoadScene(path, loadParams)) | ||
| 182 | - { | ||
| 183 | - ExceptionFlinger(ASSERT_LOCATION) << "Failed to load scene from '" << path << "': " << loader.GetParseError(); | ||
| 184 | - } | ||
| 185 | - } | ||
| 186 | - else | ||
| 187 | - { | ||
| 188 | - ShaderDefinitionFactory sdf; | ||
| 189 | - sdf.SetResources(resources); | ||
| 190 | - LoadGltfScene(path, sdf, output); | ||
| 191 | - | ||
| 192 | - resources.mEnvironmentMaps.push_back({}); | ||
| 193 | - } | 170 | + Dali::Scene3D::Loader::ModelLoader modelLoader(path, pathProvider(ResourceType::Mesh) + "/", output); |
| 171 | + modelLoader.LoadModel(pathProvider); | ||
| 194 | 172 | ||
| 195 | if(cameraParameters.empty()) | 173 | if(cameraParameters.empty()) |
| 196 | { | 174 | { |
| @@ -210,20 +188,14 @@ Actor LoadScene(std::string sceneName, CameraActor camera, std::vector<Animation | @@ -210,20 +188,14 @@ Actor LoadScene(std::string sceneName, CameraActor camera, std::vector<Animation | ||
| 210 | {}, | 188 | {}, |
| 211 | {}, | 189 | {}, |
| 212 | {}}; | 190 | {}}; |
| 213 | - Customization::Choices choices; | ||
| 214 | 191 | ||
| 215 | Actor root = Actor::New(); | 192 | Actor root = Actor::New(); |
| 216 | SetActorCentered(root); | 193 | SetActorCentered(root); |
| 217 | 194 | ||
| 195 | + auto& resourceChoices = modelLoader.GetResourceChoices(); | ||
| 218 | for(auto iRoot : scene.GetRoots()) | 196 | for(auto iRoot : scene.GetRoots()) |
| 219 | { | 197 | { |
| 220 | - auto resourceRefs = resources.CreateRefCounter(); | ||
| 221 | - scene.CountResourceRefs(iRoot, choices, resourceRefs); | ||
| 222 | - resources.CountEnvironmentReferences(resourceRefs); | ||
| 223 | - | ||
| 224 | - resources.LoadResources(resourceRefs, pathProvider); | ||
| 225 | - | ||
| 226 | - if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams)) | 198 | + if(auto actor = scene.CreateNodes(iRoot, resourceChoices, nodeParams)) |
| 227 | { | 199 | { |
| 228 | scene.ConfigureSkeletonJoints(iRoot, resources.mSkeletons, actor); | 200 | scene.ConfigureSkeletonJoints(iRoot, resources.mSkeletons, actor); |
| 229 | scene.ConfigureSkinningShaders(resources, actor, std::move(nodeParams.mSkinnables)); | 201 | scene.ConfigureSkinningShaders(resources, actor, std::move(nodeParams.mSkinnables)); |
| @@ -235,8 +207,10 @@ Actor LoadScene(std::string sceneName, CameraActor camera, std::vector<Animation | @@ -235,8 +207,10 @@ Actor LoadScene(std::string sceneName, CameraActor camera, std::vector<Animation | ||
| 235 | } | 207 | } |
| 236 | } | 208 | } |
| 237 | 209 | ||
| 238 | - if(!animations->empty()) | 210 | + generatedAnimations.clear(); |
| 211 | + if(!animations.empty()) | ||
| 239 | { | 212 | { |
| 213 | + generatedAnimations.reserve(animations.size()); | ||
| 240 | auto getActor = [&](const Scene3D::Loader::AnimatedProperty& property) | 214 | auto getActor = [&](const Scene3D::Loader::AnimatedProperty& property) |
| 241 | { | 215 | { |
| 242 | Dali::Actor actor; | 216 | Dali::Actor actor; |
| @@ -255,8 +229,11 @@ Actor LoadScene(std::string sceneName, CameraActor camera, std::vector<Animation | @@ -255,8 +229,11 @@ Actor LoadScene(std::string sceneName, CameraActor camera, std::vector<Animation | ||
| 255 | return actor; | 229 | return actor; |
| 256 | }; | 230 | }; |
| 257 | 231 | ||
| 258 | - animation = (*animations)[0].ReAnimate(getActor); | ||
| 259 | - animation.Play(); | 232 | + for(auto& animationDefinition : animations) |
| 233 | + { | ||
| 234 | + generatedAnimations.push_back(animationDefinition.ReAnimate(getActor)); | ||
| 235 | + } | ||
| 236 | + generatedAnimations[0].Play(); | ||
| 260 | } | 237 | } |
| 261 | 238 | ||
| 262 | return root; | 239 | return root; |
| @@ -466,7 +443,6 @@ void Scene3DExample::OnTap(Dali::Actor actor, const Dali::TapGesture& tap) | @@ -466,7 +443,6 @@ void Scene3DExample::OnTap(Dali::Actor actor, const Dali::TapGesture& tap) | ||
| 466 | 443 | ||
| 467 | auto id = mItemView.GetItemId(actor); | 444 | auto id = mItemView.GetItemId(actor); |
| 468 | 445 | ||
| 469 | - Scene3D::Loader::InitializeGltfLoader(); | ||
| 470 | try | 446 | try |
| 471 | { | 447 | { |
| 472 | auto window = mApp.GetWindow(); | 448 | auto window = mApp.GetWindow(); |
| @@ -474,7 +450,7 @@ void Scene3DExample::OnTap(Dali::Actor actor, const Dali::TapGesture& tap) | @@ -474,7 +450,7 @@ void Scene3DExample::OnTap(Dali::Actor actor, const Dali::TapGesture& tap) | ||
| 474 | auto renderTasks = window.GetRenderTaskList(); | 450 | auto renderTasks = window.GetRenderTaskList(); |
| 475 | renderTasks.RemoveTask(mSceneRender); | 451 | renderTasks.RemoveTask(mSceneRender); |
| 476 | 452 | ||
| 477 | - auto scene = LoadScene(mSceneNames[id], mSceneCamera, &mSceneAnimations, mCurrentAnimation); | 453 | + auto scene = LoadScene(mSceneNames[id], mSceneCamera, mSceneAnimations, mCurrentAnimation); |
| 478 | 454 | ||
| 479 | auto sceneRender = renderTasks.CreateTask(); | 455 | auto sceneRender = renderTasks.CreateTask(); |
| 480 | sceneRender.SetCameraActor(mSceneCamera); | 456 | sceneRender.SetCameraActor(mSceneCamera); |
examples/scene3d/scene3d-example.h
| @@ -65,8 +65,8 @@ private: // data | @@ -65,8 +65,8 @@ private: // data | ||
| 65 | public: | 65 | public: |
| 66 | Dali::Actor mScene; | 66 | Dali::Actor mScene; |
| 67 | 67 | ||
| 68 | - std::vector<Dali::Scene3D::Loader::AnimationDefinition> mSceneAnimations; | ||
| 69 | - Dali::Animation mCurrentAnimation; | 68 | + std::vector<Dali::Animation> mSceneAnimations; |
| 69 | + Dali::Animation mCurrentAnimation; | ||
| 70 | 70 | ||
| 71 | std::unique_ptr<Scene3DExtension> mScene3DExtension; | 71 | std::unique_ptr<Scene3DExtension> mScene3DExtension; |
| 72 | 72 |
examples/scene3d/scene3d-extension.h
| @@ -93,16 +93,14 @@ private: | @@ -93,16 +93,14 @@ private: | ||
| 93 | return false; | 93 | return false; |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | - auto root = mSceneLoader->mScene; | ||
| 97 | - auto getActor = [&root](const Dali::Scene3D::Loader::AnimatedProperty& property) { | ||
| 98 | - return root.FindChildByName(property.mNodeName); | ||
| 99 | - }; | ||
| 100 | - | ||
| 101 | if(mSceneLoader->mSceneAnimations.size() > animationIndex) | 96 | if(mSceneLoader->mSceneAnimations.size() > animationIndex) |
| 102 | { | 97 | { |
| 103 | mCurrentAnimationIndex = animationIndex; | 98 | mCurrentAnimationIndex = animationIndex; |
| 104 | - mSceneLoader->mCurrentAnimation = mSceneLoader->mSceneAnimations[animationIndex].ReAnimate(getActor); | ||
| 105 | - mSceneLoader->mCurrentAnimation.FinishedSignal().Connect(this, &Scene3DExtension::OnAnimationFinished); | 99 | + mSceneLoader->mCurrentAnimation = mSceneLoader->mSceneAnimations[animationIndex]; |
| 100 | + if(mSceneLoader->mCurrentAnimation.FinishedSignal().GetConnectionCount() == 0) | ||
| 101 | + { | ||
| 102 | + mSceneLoader->mCurrentAnimation.FinishedSignal().Connect(this, &Scene3DExtension::OnAnimationFinished); | ||
| 103 | + } | ||
| 106 | mSceneLoader->mCurrentAnimation.Play(); | 104 | mSceneLoader->mCurrentAnimation.Play(); |
| 107 | } | 105 | } |
| 108 | } | 106 | } |