Revert "[Tizen] Add log if destroyed visual get some signal"
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / internal / model-components / model-node-impl.h
1 #ifndef DALI_SCENE3D_MODEL_COMPONENTS_MODEL_NODE_IMPL_H
2 #define DALI_SCENE3D_MODEL_COMPONENTS_MODEL_NODE_IMPL_H
3
4 /*
5  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/common/map-wrapper.h>
23 #include <dali/public-api/actors/custom-actor-impl.h>
24 #include <dali/public-api/common/dali-common.h>
25 #include <memory> // for std::unique_ptr
26 #include <string>
27
28 // INTERNAL INCLUDES
29 #include <dali-scene3d/internal/model-components/model-primitive-modify-observer.h>
30 #include <dali-scene3d/public-api/light/light.h>
31 #include <dali-scene3d/public-api/loader/mesh-definition.h>
32 #include <dali-scene3d/public-api/loader/shader-manager.h>
33 #include <dali-scene3d/public-api/loader/shader-option.h>
34 #include <dali-scene3d/public-api/loader/skinning-details.h>
35 #include <dali-scene3d/public-api/model-components/model-node.h>
36 #include <dali-scene3d/public-api/model-components/model-primitive.h>
37
38 namespace Dali
39 {
40 namespace Scene3D
41 {
42 /**
43  * @addtogroup dali_toolkit_controls_model
44  * @{
45  */
46
47 namespace Internal
48 {
49 /**
50  * @brief This is the internal base class for custom node of model.
51  *
52  * @SINCE_2_2.99
53  */
54 class DALI_SCENE3D_API ModelNode : public CustomActorImpl, public ModelPrimitiveModifyObserver
55 {
56 public:
57   using ModelPrimitiveContainer = std::vector<Scene3D::ModelPrimitive>;
58   using BoneDataContainer       = std::vector<Dali::Scene3D::Loader::Skinning::BoneData>;
59   using BlendShapeIndexMap      = std::map<std::string, Loader::BlendShapes::Index>;
60
61   // Creation & Destruction
62   /**
63    * @brief Creates a new ModelNodeImpl instance that does not require touch by default.
64    *
65    * If touch is required, then the user can connect to this class' touch signal.
66    * @SINCE_2_2.99
67    * @return A handle to the ModelNode instance
68    */
69   static Scene3D::ModelNode New();
70
71 protected:
72   /**
73    * @brief Virtual destructor.
74    * @SINCE_2_2.99
75    */
76   virtual ~ModelNode();
77
78 protected: // From CustomActorImpl
79   /**
80    * @copydoc CustomActorImpl::OnSceneConnection()
81    * @note If overridden, then an up-call to ModelNode::OnSceneConnection MUST be made at the end.
82    */
83   void OnSceneConnection(int depth) override;
84
85   /**
86    * @copydoc CustomActorImpl::OnSceneDisconnection()
87    * @note If overridden, then an up-call to ModelNode::OnSceneDisconnection MUST be made at the end.
88    */
89   void OnSceneDisconnection() override;
90
91   /**
92    * @copydoc CustomActorImpl::OnChildAdd()
93    * @note If overridden, then an up-call to ModelNode::OnChildAdd MUST be made at the end.
94    */
95   void OnChildAdd(Actor& child) override;
96
97   /**
98    * @copydoc CustomActorImpl::OnChildRemove()
99    * @note If overridden, then an up-call to ModelNode::OnChildRemove MUST be made at the end.
100    */
101   void OnChildRemove(Actor& child) override;
102
103   /**
104    * @copydoc CustomActorImpl::OnPropertySet()
105    * @note If overridden, then an up-call to ModelNode::OnChildRemove MUST be made at the end.
106    */
107   void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
108
109   /**
110    * @copydoc CustomActorImpl::OnSizeSet()
111    * @note If overridden, then an up-call to ModelNode::OnSizeSet MUST be made at the end.
112    */
113   void OnSizeSet(const Vector3& targetSize) override;
114
115   /**
116    * @copydoc CustomActorImpl::OnSizeAnimation()
117    * @note If overridden, then an up-call to ModelNode::OnSizeAnimation MUST be made at the end.
118    */
119   void OnSizeAnimation(Animation& animation, const Vector3& targetSize) override;
120
121   /**
122    * @copydoc CustomActorImpl::OnRelayout()
123    */
124   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
125
126   /**
127    * @copydoc CustomActorImpl::OnSetResizePolicy()
128    */
129   void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension) override;
130
131   /**
132    * @copydoc CustomActorImpl::GetNaturalSize()
133    */
134   Vector3 GetNaturalSize() override;
135
136   /**
137    * @copydoc CustomActorImpl::CalculateChildSize()
138    */
139   float CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension) override;
140
141   /**
142    * @copydoc CustomActorImpl::GetHeightForWidth()
143    */
144   float GetHeightForWidth(float width) override;
145
146   /**
147    * @copydoc CustomActorImpl::GetWidthForHeight()
148    */
149   float GetWidthForHeight(float height) override;
150
151   /**
152    * @copydoc CustomActorImpl::RelayoutDependentOnChildren()
153    */
154   bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS) override;
155
156   /**
157    * @copydoc CustomActorImpl::OnCalculateRelayoutSize()
158    */
159   void OnCalculateRelayoutSize(Dimension::Type dimension) override;
160
161   /**
162    * @copydoc CustomActorImpl::OnLayoutNegotiated()
163    */
164   void OnLayoutNegotiated(float size, Dimension::Type dimension) override;
165
166 protected:
167   // Construction
168
169   /**
170    * @brief ModelNode constructor.
171    *
172    * @SINCE_2_2.99
173    */
174   ModelNode();
175
176   /**
177    * @brief Second phase initialization.
178    * @SINCE_2_2.99
179    */
180   void Initialize();
181
182 public: // API for derived classes to override
183   // Lifecycle
184
185   /**
186    * @brief This method is called after the Node has been initialized.
187    *
188    * Derived classes should do any second phase initialization by overriding this method.
189    * @SINCE_2_2.99
190    */
191   virtual void OnInitialize();
192
193 public: // Public Method
194   /**
195    * @copydoc Dali::Scene3D::ModelNode::GetModelPrimitiveCount()
196    */
197   uint32_t GetModelPrimitiveCount() const;
198
199   /**
200    * @copydoc Dali::Scene3D::ModelNode::AddModelPrimitive()
201    */
202   void AddModelPrimitive(Dali::Scene3D::ModelPrimitive modelPrimitive, Loader::ShaderOption::HashType hash);
203
204   /**
205    * @copydoc Dali::Scene3D::ModelNode::RemoveModelPrimitive(Dali::Scene3D::ModelPrimitive modelPrimitive)
206    */
207   void RemoveModelPrimitive(Dali::Scene3D::ModelPrimitive modelPrimitive);
208
209   /**
210    * @copydoc Dali::Scene3D::ModelNode::RemoveModelPrimitive(uint32_t index)
211    */
212   void RemoveModelPrimitive(uint32_t index);
213
214   /**
215    * @copydoc Dali::Scene3D::ModelNode::GetModelPrimitive()
216    */
217   Dali::Scene3D::ModelPrimitive GetModelPrimitive(uint32_t index) const;
218
219   /**
220    * @copydoc Dali::Scene3D::ModelNode::FindChildModelNodeByName()
221    */
222   Scene3D::ModelNode FindChildModelNodeByName(std::string_view nodeName);
223
224   /**
225    * @copydoc Dali::Scene3D::ModelNode::RetrieveBlendShapeNames()
226    */
227   void RetrieveBlendShapeNames(std::vector<std::string>& blendShapeNames) const;
228
229   /**
230    * @copydoc Dali::Scene3D::ModelNode::GetBlendShapeIndexByName()
231    */
232   Loader::BlendShapes::Index GetBlendShapeIndexByName(std::string_view blendShapeName) const;
233
234   /**
235    * @brief Sets the shadow map textures for a ModelNode.
236    *
237    * @param[in] shadowMapTexture The shadow map texture.
238    */
239   void SetShadowMapTexture(Dali::Texture shadowMapTexture);
240
241   /**
242    * @brief Sets the diffuse and specular image-based lighting textures for a ModelNode.
243    *
244    * @param[in] diffuseTexture The diffuse texture.
245    * @param[in] specularTexture The specular texture.
246    * @param[in] iblScaleFactor The scale factor for the image-based lighting.
247    * @param[in] specularMipmapLevels The number of mipmap levels for the specular texture.
248    */
249   void SetImageBasedLightTexture(Dali::Texture diffuseTexture, Dali::Texture specularTexture, float iblScaleFactor, uint32_t specularMipmapLevels);
250
251   /**
252    * @brief Sets the scale factor for image-based lighting.
253    *
254    * @param[in] iblScaleFactor The scale factor for image-based lighting.
255    */
256   void SetImageBasedLightScaleFactor(float iblScaleFactor);
257
258   /**
259    * @brief Updates shaders by using current material
260    *
261    * @param[in] shaderManager Shader manager to create shader.
262    */
263   void UpdateShader(Scene3D::Loader::ShaderManagerPtr shaderManager);
264
265   /**
266    * @brief Sets the blend shape data for a ModelPrimitive.
267    *
268    * @param[in] data The blend shape data.
269    * @param[in] primitive The ModelPrimitive to set the blend shape data for.
270    */
271   void SetBlendShapeData(Scene3D::Loader::BlendShapes::BlendShapeData& data, Scene3D::ModelPrimitive primitive);
272
273   /**
274    * @brief Sets the bone matrix for a ModelPrimitive and bone index.
275    *
276    * @param[in] inverseMatrix The inverse matrix of the bone.
277    * @param[in] primitive The ModelPrimitive to set the bone matrix for.
278    * @param[in] boneIndex The index of the bone to set the matrix for.
279    */
280   void SetBoneMatrix(const Matrix& inverseMatrix, Scene3D::ModelPrimitive primitive, Scene3D::Loader::Index& boneIndex);
281
282   /**
283    * @brief Called when a Renderer of ModelPrimitive is created.
284    *
285    * @param[in] renderer The Renderer that is created.
286    */
287   void OnRendererCreated(Renderer renderer) override;
288
289 private:
290   /**
291    * @brief Updates the bone matrix for a ModelPrimitive.
292    *
293    * @param[in] primitive The ModelPrimitive to set the bone matrix for.
294    */
295   void UpdateBoneMatrix(Scene3D::ModelPrimitive primitive);
296
297 private:
298   /// @cond internal
299
300   // Not copyable or movable
301   DALI_INTERNAL ModelNode(const ModelNode&) = delete;            ///< Deleted copy constructor.
302   DALI_INTERNAL ModelNode(ModelNode&&)      = delete;            ///< Deleted move constructor.
303   DALI_INTERNAL ModelNode& operator=(const ModelNode&) = delete; ///< Deleted copy assignment operator.
304   DALI_INTERNAL ModelNode& operator=(ModelNode&&) = delete;      ///< Deleted move assignment operator.
305
306 private:
307   Scene3D::Loader::ShaderManagerPtr mShaderManager;
308   ModelPrimitiveContainer           mModelPrimitiveContainer; ///< List of model primitives
309   BoneDataContainer                 mBoneDataContainer;
310   BlendShapeIndexMap                mBlendShapeIndexMap; ///< Index of blend shape by name
311   Dali::Texture                     mShadowMapTexture;
312   Dali::Texture                     mSpecularTexture;
313   Dali::Texture                     mDiffuseTexture;
314   float                             mIblScaleFactor{1.0f};
315   uint32_t                          mSpecularMipmapLevels{1u};
316   /// @endcond
317 };
318
319 /**
320  * @brief Gets implementation from the handle.
321  *
322  * @SINCE_2_2.99
323  * @param handle
324  * @return Implementation
325  * @pre handle is initialized and points to a node
326  */
327 DALI_SCENE3D_API Internal::ModelNode& GetImplementation(Dali::Scene3D::ModelNode& handle);
328
329 /**
330  * @brief Gets implementation from the handle.
331  *
332  * @SINCE_2_2.99
333  * @param handle
334  * @return Implementation
335  * @pre Handle is initialized and points to a node.
336  */
337 DALI_SCENE3D_API const Internal::ModelNode& GetImplementation(const Dali::Scene3D::ModelNode& handle);
338
339 } // namespace Internal
340
341 /**
342  * @}
343  */
344 } // namespace Scene3D
345
346 } // namespace Dali
347
348 #endif // DALI_SCENE3D_MODEL_COMPONENTS_MODEL_NODE_IMPL_H