DALi Version 2.2.11
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / internal / controls / model / model-impl.h
index 3db9c57..e4f1f08 100644 (file)
@@ -26,6 +26,9 @@
 #include <dali/public-api/rendering/texture.h>
 
 // INTERNAL INCLUDES
+#include <dali-scene3d/internal/common/environment-map-load-task.h>
+#include <dali-scene3d/internal/common/image-based-light-observer.h>
+#include <dali-scene3d/internal/common/model-load-task.h>
 #include <dali-scene3d/public-api/controls/model/model.h>
 #include <dali-scene3d/public-api/controls/scene-view/scene-view.h>
 
@@ -40,7 +43,7 @@ namespace Internal
 /**
  * @brief Impl class for Model.
  */
-class Model : public Dali::Toolkit::Internal::Control
+class Model : public Dali::Toolkit::Internal::Control, public ImageBasedLightObserver
 {
 public:
   using AnimationData = std::pair<std::string, Dali::Animation>;
@@ -68,6 +71,16 @@ public:
   bool GetChildrenSensitive() const;
 
   /**
+   * @copydoc Model::SetChildrenFocusable()
+   */
+  void SetChildrenFocusable(bool enable);
+
+  /**
+   * @copydoc Model::GetChildrenFocusable()
+   */
+  bool GetChildrenFocusable() const;
+
+  /**
    * @copydoc Model::SetImageBasedLightSource()
    */
   void SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor);
@@ -115,6 +128,11 @@ protected:
 
 private:
   /**
+   * @copydoc Toolkit::Control::OnInitialize
+   */
+  void OnInitialize();
+
+  /**
    * @copydoc CustomActorImpl::OnSceneConnection()
    */
   void OnSceneConnection(int depth) override;
@@ -150,11 +168,6 @@ private:
   bool IsResourceReady() const override;
 
   /**
-   * @brief Loads a model from file
-   */
-  void LoadModel();
-
-  /**
    * @brief Scales the model to fit the control or to return to original size.
    */
   void ScaleModel();
@@ -179,6 +192,43 @@ private:
    */
   void UpdateImageBasedLightScaleFactor();
 
+public: // Overrides ImageBasedLightObserver Methods.
+  /**
+   * @copydoc Dali::Scene3D::Internal::ImageBasedLightObserver::NotifyImageBasedLightTexture()
+   */
+  void NotifyImageBasedLightTexture(Dali::Texture diffuseTexture, Dali::Texture specularTexture, float scaleFactor) override;
+
+  /**
+   * @copydoc Dali::Scene3D::Internal::ImageBasedLightObserver::NotifyImageBasedLightScaleFactor()
+   */
+  void NotifyImageBasedLightScaleFactor(float scaleFactor) override;
+
+private:
+  /**
+   * @brief Asynchronously model loading finished.
+   */
+  void OnModelLoadComplete();
+
+  /**
+   * @brief Asynchronously ibl diffusel image loading finished.
+   */
+  void OnIblDiffuseLoadComplete();
+
+  /**
+   * @brief Asynchronously ibl specular image loading finished.
+   */
+  void OnIblSpecularLoadComplete();
+
+  /**
+   * @brief Asynchronously ibl loading finished.
+   */
+  void OnIblLoadComplete();
+
+  /**
+   * @brief Reset Resource loading tasks.
+   */
+  void ResetResourceTasks();
+
 private:
   std::string                    mModelUrl;
   std::string                    mResourceDirectoryUrl;
@@ -187,14 +237,32 @@ private:
   std::vector<WeakHandle<Actor>> mRenderableActors;
   WeakHandle<Scene3D::SceneView> mParentSceneView;
 
+  // Asynchronous loading variable
+  ModelLoadTaskPtr          mModelLoadTask;
+  EnvironmentMapLoadTaskPtr mIblDiffuseLoadTask;
+  EnvironmentMapLoadTaskPtr mIblSpecularLoadTask;
+
+  std::string mDiffuseIblUrl;
+  std::string mSpecularIblUrl;
+
+  // TODO: This default texture can be removed after 3D Resource Cache is added.
+  Dali::Texture mDefaultSpecularTexture;
+  Dali::Texture mDefaultDiffuseTexture;
+  Dali::Texture mSceneSpecularTexture;
+  Dali::Texture mSceneDiffuseTexture;
   Dali::Texture mSpecularTexture;
   Dali::Texture mDiffuseTexture;
   Vector3       mNaturalSize;
   Vector3       mModelPivot;
+  float         mSceneIblScaleFactor;
   float         mIblScaleFactor;
   bool          mModelChildrenSensitive;
+  bool          mModelChildrenFocusable;
   bool          mModelResourceReady;
-  bool          mIBLResourceReady;
+  bool          mIblDiffuseResourceReady;
+  bool          mIblSpecularResourceReady;
+  bool          mIblDiffuseDirty;
+  bool          mIblSpecularDirty;
 };
 
 } // namespace Internal