Fix to use async resource load in scene3d-model example 97/286297/8
authorseungho baek <sbsh.baek@samsung.com>
Tue, 3 Jan 2023 07:58:47 +0000 (16:58 +0900)
committerseungho baek <sbsh.baek@samsung.com>
Mon, 9 Jan 2023 05:46:37 +0000 (14:46 +0900)
Change-Id: Ifddd21530c822731b18de25db6cd19aae4f10819
Signed-off-by: seungho baek <sbsh.baek@samsung.com>
examples/scene3d-model/scene3d-model-example.cpp
examples/scene3d/scene3d-example.cpp

index 1c0b8ddbc31546dc603273a80356c2e73f2dcf6e..43b6146c7f5a21dbef4adeae7c8d2da655a357fc 100644 (file)
@@ -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)
index 13ea813eb307c50c7626d814c910e5b61ddbb3eb..e2ba8bc7804f2942174995589ae39957220513eb 100644 (file)
@@ -237,8 +237,22 @@ Actor LoadScene(std::string sceneName, CameraActor camera, std::vector<Animation
 \r
   if(!animations->empty())\r
   {\r
-    auto getActor = [&root](const Scene3D::Loader::AnimatedProperty& property) {\r
-      return root.FindChildByName(property.mNodeName);\r
+    auto getActor = [&](const Scene3D::Loader::AnimatedProperty& property)\r
+    {\r
+      Dali::Actor actor;\r
+      if(property.mNodeIndex != Scene3D::Loader::INVALID_INDEX)\r
+      {\r
+        auto* node = scene.GetNode(property.mNodeIndex);\r
+        if(node != nullptr)\r
+        {\r
+          actor = root.FindChildById(node->mNodeId);\r
+        }\r
+      }\r
+      else\r
+      {\r
+        actor = root.FindChildByName(property.mNodeName);\r
+      }\r
+      return actor;\r
     };\r
 \r
     animation = (*animations)[0].ReAnimate(getActor);\r
@@ -452,6 +466,7 @@ void Scene3DExample::OnTap(Dali::Actor actor, const Dali::TapGesture& tap)
 \r
   auto id = mItemView.GetItemId(actor);\r
 \r
+  Scene3D::Loader::InitializeGltfLoader();\r
   try\r
   {\r
     auto window = mApp.GetWindow();\r