Add ResourceReady for Control
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / internal / controls / model-view / model-view-impl.cpp
index 61a5303..06ed187 100644 (file)
@@ -20,7 +20,6 @@
 
 // EXTERNAL INCLUDES
 #include <dali-toolkit/dali-toolkit.h>
-#include <dali-toolkit/devel-api/controls/control-devel.h>
 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
 #include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
 #include <dali/integration-api/debug.h>
@@ -29,8 +28,8 @@
 #include <filesystem>
 
 // INTERNAL INCLUDES
-#include <dali-scene3d/public-api/controls/model-view/model-view.h>
 #include <dali-scene3d/internal/controls/scene-view/scene-view-impl.h>
+#include <dali-scene3d/public-api/controls/model-view/model-view.h>
 #include <dali-scene3d/public-api/loader/animation-definition.h>
 #include <dali-scene3d/public-api/loader/camera-parameters.h>
 #include <dali-scene3d/public-api/loader/cube-map-loader.h>
@@ -173,7 +172,7 @@ void AddModelTreeToAABB(BoundingVolume& AABB, const Dali::Scene3D::Loader::Scene
 } // anonymous namespace
 
 ModelView::ModelView(const std::string& modelPath, const std::string& resourcePath)
-: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
+: Control(ControlBehaviour(DISABLE_SIZE_NEGOTIATION | DISABLE_STYLE_CHANGE_SIGNALS)),
   mModelPath(modelPath),
   mResourcePath(resourcePath),
   mModelRoot(),
@@ -181,7 +180,9 @@ ModelView::ModelView(const std::string& modelPath, const std::string& resourcePa
   mModelPivot(AnchorPoint::CENTER),
   mIblScaleFactor(1.0f),
   mFitSize(true),
-  mFitCenter(true)
+  mFitCenter(true),
+  mModelResourceReady(false),
+  mIBLResourceReady(true)
 {
 }
 
@@ -221,9 +222,18 @@ void ModelView::FitCenter(bool fit)
 
 void ModelView::SetImageBasedLightSource(const std::string& diffuse, const std::string& specular, float scaleFactor)
 {
+  mIBLResourceReady = false;
   Texture diffuseTexture  = Dali::Scene3D::Loader::LoadCubeMap(diffuse);
   Texture specularTexture = Dali::Scene3D::Loader::LoadCubeMap(specular);
   SetImageBasedLightTexture(diffuseTexture, specularTexture, scaleFactor);
+  mIBLResourceReady = true;
+
+  // If Model resource is already ready, then set resource ready.
+  // If Model resource is still not ready, wait for model resource ready.
+  if(IsResourceReady())
+  {
+    SetResourceReady(false);
+  }
 }
 
 void ModelView::SetImageBasedLightTexture(Dali::Texture diffuse, Dali::Texture specular, float scaleFactor)
@@ -339,6 +349,11 @@ void ModelView::OnRelayout(const Vector2& size, RelayoutContainer& container)
   ScaleModel();
 }
 
+bool ModelView::IsResourceReady() const
+{
+  return mModelResourceReady && mIBLResourceReady;
+}
+
 void ModelView::LoadModel()
 {
   std::filesystem::path modelPath(mModelPath);
@@ -464,6 +479,10 @@ void ModelView::LoadModel()
 
   Self().SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
   Self().SetProperty(Dali::Actor::Property::ANCHOR_POINT, Vector3(mModelPivot.x, 1.0f - mModelPivot.y, mModelPivot.z));
+
+  mModelResourceReady = true;
+
+  Control::SetResourceReady(false);
 }
 
 void ModelView::ScaleModel()