From 86feb3718ae5e94b3eacb5fa41511e07d66dacce Mon Sep 17 00:00:00 2001 From: seungho baek Date: Tue, 3 Jan 2023 16:58:47 +0900 Subject: [PATCH] Fix to use async resource load in scene3d-model example Change-Id: Ifddd21530c822731b18de25db6cd19aae4f10819 Signed-off-by: seungho baek --- examples/scene3d-model/scene3d-model-example.cpp | 17 ++++++++++++++++- examples/scene3d/scene3d-example.cpp | 19 +++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/examples/scene3d-model/scene3d-model-example.cpp b/examples/scene3d-model/scene3d-model-example.cpp index 1c0b8dd..43b6146 100644 --- a/examples/scene3d-model/scene3d-model-example.cpp +++ b/examples/scene3d-model/scene3d-model-example.cpp @@ -261,6 +261,7 @@ public: void CreateSceneFromGLTF(uint32_t index) { + mReadyToLoad = false; if(mModel) { mWindow.GetRootLayer().Remove(mModel); @@ -283,10 +284,17 @@ public: mModel.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); mModel.SetImageBasedLightSource(uri_diffuse_texture, uri_specular_texture, 0.6f); + mModel.ResourceReadySignal().Connect(this, &Scene3DModelExample::ResourceReady); + mWindow.Add(mModel); + } + + void ResourceReady(Control control) + { + mReadyToLoad = true; if(mModel.GetAnimationCount() > 0) { - Animation animation = (index == 0u) ? mModel.GetAnimation(0u) : mModel.GetAnimation("idleToSquatClip_0"); + Animation animation = (mCurrentGlTF == 0u) ? mModel.GetAnimation(0u) : mModel.GetAnimation("idleToSquatClip_0"); animation.Play(); animation.SetLoopCount(0); } @@ -466,6 +474,11 @@ public: void ChangeModel(int32_t direction) { + if(!mReadyToLoad) + { + return; + } + mCurrentGlTF += direction; if(mCurrentGlTF >= NUM_OF_GLTF_MODELS) { @@ -625,6 +638,8 @@ private: float mWheelDelta{1.0f}; int32_t mCurrentGlTF{0}; + + bool mReadyToLoad{true}; }; int32_t DALI_EXPORT_API main(int32_t argc, char** argv) diff --git a/examples/scene3d/scene3d-example.cpp b/examples/scene3d/scene3d-example.cpp index 13ea813..e2ba8bc 100644 --- a/examples/scene3d/scene3d-example.cpp +++ b/examples/scene3d/scene3d-example.cpp @@ -237,8 +237,22 @@ Actor LoadScene(std::string sceneName, CameraActor camera, std::vectorempty()) { - auto getActor = [&root](const Scene3D::Loader::AnimatedProperty& property) { - return root.FindChildByName(property.mNodeName); + auto getActor = [&](const Scene3D::Loader::AnimatedProperty& property) + { + Dali::Actor actor; + if(property.mNodeIndex != Scene3D::Loader::INVALID_INDEX) + { + auto* node = scene.GetNode(property.mNodeIndex); + if(node != nullptr) + { + actor = root.FindChildById(node->mNodeId); + } + } + else + { + actor = root.FindChildByName(property.mNodeName); + } + return actor; }; animation = (*animations)[0].ReAnimate(getActor); @@ -452,6 +466,7 @@ void Scene3DExample::OnTap(Dali::Actor actor, const Dali::TapGesture& tap) auto id = mItemView.GetItemId(actor); + Scene3D::Loader::InitializeGltfLoader(); try { auto window = mApp.GetWindow(); -- 2.7.4