[dali_2.3.24] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / internal / controls / model / model-impl.h
index d7924bf..d82fa8f 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_SCENE3D_INTERNAL_MODEL_H
 
 /*
- * 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.
 
 // EXTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/control-impl.h>
+#include <dali/devel-api/common/map-wrapper.h>
 #include <dali/public-api/actors/camera-actor.h>
 #include <dali/public-api/actors/layer.h>
 #include <dali/public-api/animation/animation.h>
 #include <dali/public-api/object/property-notification.h>
 #include <dali/public-api/object/weak-handle.h>
 #include <dali/public-api/rendering/texture.h>
+#include <unordered_map>
 
 // 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/light-observer.h>
 #include <dali-scene3d/internal/common/model-load-task.h>
+#include <dali-scene3d/internal/model-components/model-node-impl.h>
 #include <dali-scene3d/public-api/controls/model/model.h>
 #include <dali-scene3d/public-api/controls/scene-view/scene-view.h>
+#include <dali-scene3d/public-api/light/light.h>
 #include <dali-scene3d/public-api/loader/load-result.h>
 #include <dali-scene3d/public-api/model-components/model-node.h>
 
@@ -47,11 +51,17 @@ namespace Internal
 /**
  * @brief Impl class for Model.
  */
-class Model : public Dali::Toolkit::Internal::Control, public ImageBasedLightObserver
+class Model : public Dali::Toolkit::Internal::Control, public LightObserver
 {
 public:
-  using AnimationData = std::pair<std::string, Dali::Animation>;
-  using CameraData    = Loader::CameraParameters;
+  using AnimationData          = std::pair<std::string, Dali::Animation>;
+  using CameraData             = Loader::CameraParameters;
+  using BlendShapeModelNodeMap = std::map<std::string, std::vector<Scene3D::ModelNode>>;
+
+  // ColliderMeshContainer doesn't hold actual collider meshes
+  // but pairs unique ModelNode id with ModelNode for lookup purposes.
+  // All model nodes in the container have collider mesh attached.
+  using ColliderMeshContainer = std::unordered_map<int, Scene3D::ModelNode>;
 
   /**
    * @copydoc Model::New()
@@ -143,6 +153,92 @@ public:
    */
   Scene3D::ModelNode FindChildModelNodeByName(std::string_view nodeName);
 
+  /**
+   * @copydoc Model::RetrieveBlendShapeNames()
+   */
+  void RetrieveBlendShapeNames(std::vector<std::string>& blendShapeNames) const;
+
+  /**
+   * @copydoc Model::RetrieveModelNodesByBlendShapeName()
+   */
+  void RetrieveModelNodesByBlendShapeName(std::string_view blendShapeName, std::vector<Scene3D::ModelNode>& modelNodes) const;
+
+  /**
+   * @copydoc Model::GenerateMotionDataAnimation()
+   */
+  Dali::Animation GenerateMotionDataAnimation(Scene3D::MotionData motionData);
+
+  /**
+   * @copydoc Model::SetMotionData()
+   */
+  void SetMotionData(Scene3D::MotionData motionData);
+
+  /**
+   * @copydoc Model::CastShadow()
+   */
+  void CastShadow(bool castShadow);
+
+  /**
+   * @copydoc Model::IsShadowCasting()
+   */
+  bool IsShadowCasting() const;
+
+  /**
+   * @copydoc Model::ReceiveShadow()
+   */
+  void ReceiveShadow(bool receiveShadow);
+
+  /**
+   * @copydoc Model::IsShadowReceiving()
+   */
+  bool IsShadowReceiving() const;
+
+  /**
+   * @copydoc Scene3D::Model::MeshHitSignal()
+   */
+  Scene3D::Model::MeshHitSignalType& MeshHitSignal()
+  {
+    return mMeshHitSignal;
+  }
+
+  /**
+   * @brief Emits MeshHitSignal
+   * @param[in] modelNode ModelNode that has been hit
+   * @return Result of hit handling.
+   */
+  bool EmitMeshHitSignal(Scene3D::ModelNode modelNode)
+  {
+    bool retVal = false;
+    if(!mMeshHitSignal.Empty())
+    {
+      Scene3D::Model handle(GetOwner());
+      retVal = mMeshHitSignal.Emit(handle, modelNode);
+    }
+    return retVal;
+  }
+
+  /**
+   * @brief Returns collider mesh container
+   * @return Returns valid container
+   */
+  const ColliderMeshContainer& GetNodeColliderMeshContainer() const
+  {
+    return mColliderMeshes;
+  }
+
+  /**
+   * @brief Registers child node with collidier mesh
+   *
+   * @param[in] node ModelNode to register
+   */
+  void RegisterColliderMesh(Scene3D::ModelNode& node);
+
+  /**
+   * @brief Removes node/collider mesh from the register
+   * @param[in] node Child node to remove from the register
+   */
+  void RemoveColliderMesh(Scene3D::ModelNode& node);
+
 protected:
   /**
    * @brief Constructs a new Model.
@@ -219,6 +315,16 @@ private:
   void FitModelPosition();
 
   /**
+   * @brief Makes the input node cast shadow or not.
+   */
+  void UpdateCastShadowRecursively(Scene3D::ModelNode node, bool castShadow);
+
+  /**
+   * @brief Makes the input node receive shadow or not.
+   */
+  void UpdateReceiveShadowRecursively(Scene3D::ModelNode node, bool receiveShadow);
+
+  /**
    * @brief Changes IBL information of the input node.
    */
   void UpdateImageBasedLightTextureRecursively(Scene3D::ModelNode node, Dali::Texture diffuseTexture, Dali::Texture specularTexture, float iblScaleFactor, uint32_t specularMipmapLevels);
@@ -247,14 +353,19 @@ private:
    */
   void ApplyCameraTransform(Dali::CameraActor camera) const;
 
-public: // Overrides ImageBasedLightObserver Methods.
+public: // Overrides LightObserver Methods.
+  /**
+   * @copydoc Dali::Scene3D::Internal::LightObserver::NotifyShadowMapTexture()
+   */
+  void NotifyShadowMapTexture(Dali::Texture shadowMapTexture) override;
+
   /**
-   * @copydoc Dali::Scene3D::Internal::ImageBasedLightObserver::NotifyImageBasedLightTexture()
+   * @copydoc Dali::Scene3D::Internal::LightObserver::NotifyImageBasedLightTexture()
    */
   void NotifyImageBasedLightTexture(Dali::Texture diffuseTexture, Dali::Texture specularTexture, float scaleFactor, uint32_t specularMipmapLevels) override;
 
   /**
-   * @copydoc Dali::Scene3D::Internal::ImageBasedLightObserver::NotifyImageBasedLightScaleFactor()
+   * @copydoc Dali::Scene3D::Internal::LightObserver::NotifyImageBasedLightScaleFactor()
    */
   void NotifyImageBasedLightScaleFactor(float scaleFactor) override;
 
@@ -290,11 +401,6 @@ private:
   void ResetResourceTasks();
 
   /**
-   * @brief Reset a Resource loading task.
-   */
-  void ResetResourceTask(IntrusivePtr<AsyncTask> asyncTask);
-
-  /**
    * @brief Notify Resource Ready signal.
    */
   void NotifyResourceReady();
@@ -314,6 +420,11 @@ private:
    */
   void ResetCameraParameters();
 
+  /**
+   * @brief Collect ModelNode list by blendshape name
+   */
+  void UpdateBlendShapeNodeMap();
+
 private:
   std::string                    mModelUrl;
   std::string                    mResourceDirectoryUrl;
@@ -323,11 +434,24 @@ private:
   WeakHandle<Scene3D::SceneView> mParentSceneView;
   Dali::PropertyNotification     mSizeNotification;
 
+  // Signals
+  Scene3D::Model::MeshHitSignalType mMeshHitSignal;
+
+  Dali::Scene3D::Loader::ShaderManagerPtr mShaderManager;
+
+  ColliderMeshContainer mColliderMeshes;
+
+  // List of ModelNode for name of blend shape.
+  BlendShapeModelNodeMap mBlendShapeModelNodeMap;
+
   // Asynchronous loading variable
   ModelLoadTaskPtr          mModelLoadTask;
   EnvironmentMapLoadTaskPtr mIblDiffuseLoadTask;
   EnvironmentMapLoadTaskPtr mIblSpecularLoadTask;
 
+  // Shadow
+  Dali::Texture mShadowMapTexture;
+
   std::string mDiffuseIblUrl;
   std::string mSpecularIblUrl;
 
@@ -350,6 +474,8 @@ private:
   bool          mIblSpecularResourceReady;
   bool          mIblDiffuseDirty;
   bool          mIblSpecularDirty;
+  bool          mIsShadowCasting;
+  bool          mIsShadowReceiving;
 };
 
 } // namespace Internal