Add signal for model loading completion for Scene3D::Model 71/319171/3
authorRichard Huang <r.huang@samsung.com>
Wed, 16 Oct 2024 14:16:20 +0000 (15:16 +0100)
committerRichard Huang <r.huang@samsung.com>
Thu, 17 Oct 2024 13:21:36 +0000 (14:21 +0100)
Change-Id: I63220da3858a4ca9bb934674bcd02f7154d0755d

automated-tests/src/dali-scene3d/utc-Dali-Model.cpp
dali-scene3d/internal/controls/model/model-impl.cpp
dali-scene3d/internal/controls/model/model-impl.h
dali-scene3d/public-api/controls/model/model.cpp
dali-scene3d/public-api/controls/model/model.h

index 6b6670cff7a56b6b532444b5d3d4c27962a72381..878e461f9f93cf719383782ad91bdfb055b1c63f 100644 (file)
@@ -124,6 +124,12 @@ void        OnResourceReady(Control control)
   gResourceReadyCalled = true;
 }
 
+static bool gLoadCompletedCalled = false;
+void        OnLoadCompleted(Scene3D::Model model, bool succeeded)
+{
+  gLoadCompletedCalled = true;
+}
+
 void ApplyAllMaterialPropertyRecursively(Scene3D::ModelNode modelNode, const std::vector<KeyValuePair>& materialPropertyValues)
 {
   if(!modelNode)
@@ -2090,4 +2096,27 @@ int UtcDaliModelReceiveShadow(void)
 
   DALI_TEST_EQUALS(modelNode2.GetProperty<int>(shadowReceivingIndex2), 0, TEST_LOCATION);
   END_TEST;
-}
\ No newline at end of file
+}
+
+int UtcDaliModelLoadComplete(void)
+{
+  ToolkitTestApplication application;
+
+  Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
+
+  gLoadCompletedCalled = false;
+  model.LoadCompletedSignal().Connect(&OnLoadCompleted);
+
+  application.GetScene().Add(model);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(gLoadCompletedCalled, true, TEST_LOCATION);
+
+  END_TEST;
+}
index bd911c5cbf9016024b816925373cb5cd560f7e33..13e0fe86e857fcabcb33bb0a02f662eb1997bb42 100644 (file)
@@ -1086,6 +1086,8 @@ void Model::OnModelLoadComplete()
       ModelCacheManager::Get().UnreferenceModelCache(mModelUrl);
     }
 
+    EmitLoadCompletedSignal(false);
+
     return;
   }
 
@@ -1122,6 +1124,8 @@ void Model::OnModelLoadComplete()
   mModelResourceReady = true;
   ResetResourceTask(mModelLoadTask);
   NotifyResourceReady();
+
+  EmitLoadCompletedSignal(true);
 }
 
 void Model::OnIblDiffuseLoadComplete()
index e174394afd0fa0bd31a1e97a79eab15283ff713a..eeba02cb4601603ce2ee90cc5b829e4b45ead368 100644 (file)
@@ -202,6 +202,27 @@ public:
     return mMeshHitSignal;
   }
 
+  /**
+   * @copydoc Scene3D::Model::LoadCompletedSignal()
+   */
+  Scene3D::Model::LoadCompletedSignalType& LoadCompletedSignal()
+  {
+    return mLoadCompletedSignal;
+  }
+
+  /**
+   * @brief Emits LoadCompletedSignal
+   * @param[in] succeeded Whether model loading has been successful
+   */
+  void EmitLoadCompletedSignal(bool succeeded)
+  {
+    if(!mLoadCompletedSignal.Empty())
+    {
+      Scene3D::Model handle(GetOwner());
+      mLoadCompletedSignal.Emit(handle, succeeded);
+    }
+  }
+
   /**
    * @brief Emits MeshHitSignal
    * @param[in] modelNode ModelNode that has been hit
@@ -416,7 +437,8 @@ private:
   Dali::PropertyNotification     mSizeNotification;
 
   // Signals
-  Scene3D::Model::MeshHitSignalType mMeshHitSignal;
+  Scene3D::Model::MeshHitSignalType       mMeshHitSignal;
+  Scene3D::Model::LoadCompletedSignalType mLoadCompletedSignal;
 
   Dali::Scene3D::Loader::ShaderManagerPtr mShaderManager;
 
index eda0041e70f2b9e8bd22b690c52f59420dc6d8b6..8eacbc1b13e85be0878da12576bf02ffe5cb92e4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -187,4 +187,9 @@ Model::MeshHitSignalType& Model::MeshHitSignal()
   return GetImpl(*this).MeshHitSignal();
 }
 
+Model::LoadCompletedSignalType& Model::LoadCompletedSignal()
+{
+  return GetImpl(*this).LoadCompletedSignal();
+}
+
 } // namespace Dali::Scene3D
index 58f7f68f7e079ded7d329bde5c3691d2be738058..1ba7107566f0fd7ad44be5f4da8bcbf2b1c0e8e2 100644 (file)
@@ -80,6 +80,8 @@ public:
   using MeshHitSignalType = Signal<bool(Model, Scene3D::ModelNode)>; ///< Mesh hit signal type @SINCE_2_2.53
   using ColliderMeshPtr   = std::unique_ptr<Algorithm::NavigationMesh>;
 
+  using LoadCompletedSignalType = Signal<void(Model, bool)>; ///< Model load completed signal type @SINCE_2_3.46
+
   /**
    * @brief Create an initialized Model.
    *
@@ -431,6 +433,23 @@ public:
    */
   MeshHitSignalType& MeshHitSignal();
 
+  /**
+   * @brief This signal is emitted when the model loading is completed.
+   *
+   * Two  parameters are sent as part of this signal, the first being the model that is loaded,
+   * the second being whether the loading has been successful.
+   *
+   * A callback of the following type may be connected:
+   * @code
+   *   void YourCallbackName(Model model, bool succeeded);
+   * @endcode
+   * Here the model is the one that has finifhed loading.
+   *
+   * @SINCE_2_3.46
+   * @return The signal to connect to
+   */
+  LoadCompletedSignalType& LoadCompletedSignal();
+
 public: // Not intended for application developers
   /// @cond internal
   /**