Revert "[Tizen] Add MotionData class and generate Animation by this"
[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/public-api/actors/custom-actor-impl.h>
23 #include <dali/public-api/common/dali-common.h>
24 #include <memory> // for std::unique_ptr
25
26 // INTERNAL INCLUDES
27 #include <dali-scene3d/internal/model-components/model-primitive-modify-observer.h>
28 #include <dali-scene3d/public-api/light/light.h>
29 #include <dali-scene3d/public-api/loader/mesh-definition.h>
30 #include <dali-scene3d/public-api/loader/skinning-details.h>
31 #include <dali-scene3d/public-api/model-components/model-node.h>
32 #include <dali-scene3d/public-api/model-components/model-primitive.h>
33
34 namespace Dali
35 {
36 namespace Scene3D
37 {
38 /**
39  * @addtogroup dali_toolkit_controls_model
40  * @{
41  */
42
43 namespace Internal
44 {
45 /**
46  * @brief This is the internal base class for custom node of model.
47  *
48  * @SINCE_2_2.99
49  */
50 class DALI_SCENE3D_API ModelNode : public CustomActorImpl, public ModelPrimitiveModifyObserver
51 {
52 public:
53   using ModelPrimitiveContainer = std::vector<Scene3D::ModelPrimitive>;
54   using BoneDataContainer       = std::vector<Dali::Scene3D::Loader::Skinning::BoneData>;
55
56   // Creation & Destruction
57   /**
58    * @brief Creates a new ModelNodeImpl instance that does not require touch by default.
59    *
60    * If touch is required, then the user can connect to this class' touch signal.
61    * @SINCE_2_2.99
62    * @return A handle to the ModelNode instance
63    */
64   static Scene3D::ModelNode New();
65
66 protected:
67   /**
68    * @brief Virtual destructor.
69    * @SINCE_2_2.99
70    */
71   virtual ~ModelNode();
72
73 protected: // From CustomActorImpl
74   /**
75    * @copydoc CustomActorImpl::OnSceneConnection()
76    * @note If overridden, then an up-call to ModelNode::OnSceneConnection MUST be made at the end.
77    */
78   void OnSceneConnection(int depth) override;
79
80   /**
81    * @copydoc CustomActorImpl::OnSceneDisconnection()
82    * @note If overridden, then an up-call to ModelNode::OnSceneDisconnection MUST be made at the end.
83    */
84   void OnSceneDisconnection() override;
85
86   /**
87    * @copydoc CustomActorImpl::OnChildAdd()
88    * @note If overridden, then an up-call to ModelNode::OnChildAdd MUST be made at the end.
89    */
90   void OnChildAdd(Actor& child) override;
91
92   /**
93    * @copydoc CustomActorImpl::OnChildRemove()
94    * @note If overridden, then an up-call to ModelNode::OnChildRemove MUST be made at the end.
95    */
96   void OnChildRemove(Actor& child) override;
97
98   /**
99    * @copydoc CustomActorImpl::OnPropertySet()
100    * @note If overridden, then an up-call to ModelNode::OnChildRemove MUST be made at the end.
101    */
102   void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
103
104   /**
105    * @copydoc CustomActorImpl::OnSizeSet()
106    * @note If overridden, then an up-call to ModelNode::OnSizeSet MUST be made at the end.
107    */
108   void OnSizeSet(const Vector3& targetSize) override;
109
110   /**
111    * @copydoc CustomActorImpl::OnSizeAnimation()
112    * @note If overridden, then an up-call to ModelNode::OnSizeAnimation MUST be made at the end.
113    */
114   void OnSizeAnimation(Animation& animation, const Vector3& targetSize) override;
115
116   /**
117    * @copydoc CustomActorImpl::OnRelayout()
118    */
119   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
120
121   /**
122    * @copydoc CustomActorImpl::OnSetResizePolicy()
123    */
124   void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension) override;
125
126   /**
127    * @copydoc CustomActorImpl::GetNaturalSize()
128    */
129   Vector3 GetNaturalSize() override;
130
131   /**
132    * @copydoc CustomActorImpl::CalculateChildSize()
133    */
134   float CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension) override;
135
136   /**
137    * @copydoc CustomActorImpl::GetHeightForWidth()
138    */
139   float GetHeightForWidth(float width) override;
140
141   /**
142    * @copydoc CustomActorImpl::GetWidthForHeight()
143    */
144   float GetWidthForHeight(float height) override;
145
146   /**
147    * @copydoc CustomActorImpl::RelayoutDependentOnChildren()
148    */
149   bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS) override;
150
151   /**
152    * @copydoc CustomActorImpl::OnCalculateRelayoutSize()
153    */
154   void OnCalculateRelayoutSize(Dimension::Type dimension) override;
155
156   /**
157    * @copydoc CustomActorImpl::OnLayoutNegotiated()
158    */
159   void OnLayoutNegotiated(float size, Dimension::Type dimension) override;
160
161 protected:
162   // Construction
163
164   /**
165    * @brief ModelNode constructor.
166    *
167    * @SINCE_2_2.99
168    */
169   ModelNode();
170
171   /**
172    * @brief Second phase initialization.
173    * @SINCE_2_2.99
174    */
175   void Initialize();
176
177 public: // API for derived classes to override
178   // Lifecycle
179
180   /**
181    * @brief This method is called after the Node has been initialized.
182    *
183    * Derived classes should do any second phase initialization by overriding this method.
184    * @SINCE_2_2.99
185    */
186   virtual void OnInitialize();
187
188 public: // Public Method
189   /**
190    * @copydoc Dali::Scene3D::ModelNode::GetModelPrimitiveCount()
191    */
192   uint32_t GetModelPrimitiveCount() const;
193
194   /**
195    * @copydoc Dali::Scene3D::ModelNode::AddModelPrimitive()
196    */
197   void AddModelPrimitive(Dali::Scene3D::ModelPrimitive modelPrimitive);
198
199   /**
200    * @copydoc Dali::Scene3D::ModelNode::RemoveModelPrimitive(Dali::Scene3D::ModelPrimitive modelPrimitive)
201    */
202   void RemoveModelPrimitive(Dali::Scene3D::ModelPrimitive modelPrimitive);
203
204   /**
205    * @copydoc Dali::Scene3D::ModelNode::RemoveModelPrimitive(uint32_t index)
206    */
207   void RemoveModelPrimitive(uint32_t index);
208
209   /**
210    * @copydoc Dali::Scene3D::ModelNode::GetModelPrimitive()
211    */
212   Dali::Scene3D::ModelPrimitive GetModelPrimitive(uint32_t index) const;
213
214   /**
215    * @copydoc Dali::Scene3D::ModelNode::FindChildModelNodeByName()
216    */
217   Scene3D::ModelNode FindChildModelNodeByName(std::string_view nodeName);
218
219   /**
220    * @brief Sets the diffuse and specular image-based lighting textures for a ModelPrimitive.
221    *
222    * @param[in] diffuseTexture The diffuse texture.
223    * @param[in] specularTexture The specular texture.
224    * @param[in] iblScaleFactor The scale factor for the image-based lighting.
225    * @param[in] specularMipmapLevels The number of mipmap levels for the specular texture.
226    */
227   void SetImageBasedLightTexture(Dali::Texture diffuseTexture, Dali::Texture specularTexture, float iblScaleFactor, uint32_t specularMipmapLevels);
228
229   /**
230    * @brief Sets the scale factor for image-based lighting.
231    *
232    * @param[in] iblScaleFactor The scale factor for image-based lighting.
233    */
234   void SetImageBasedLightScaleFactor(float iblScaleFactor);
235
236   void AddLight(Scene3D::Light light, uint32_t lightIndex);
237   void RemoveLight(uint32_t lightIndex);
238
239   /**
240    * @brief Sets the blend shape data for a ModelPrimitive.
241    *
242    * @param[in] data The blend shape data.
243    * @param[in] primitive The ModelPrimitive to set the blend shape data for.
244    */
245   void SetBlendShapeData(Scene3D::Loader::BlendShapes::BlendShapeData& data, Scene3D::ModelPrimitive primitive);
246
247   /**
248    * @brief Sets the bone matrix for a ModelPrimitive and bone index.
249    *
250    * @param[in] inverseMatrix The inverse matrix of the bone.
251    * @param[in] primitive The ModelPrimitive to set the bone matrix for.
252    * @param[in] boneIndex The index of the bone to set the matrix for.
253    */
254   void SetBoneMatrix(const Matrix& inverseMatrix, Scene3D::ModelPrimitive primitive, Scene3D::Loader::Index& boneIndex);
255
256   /**
257    * @brief Called when a Renderer of ModelPrimitive is created.
258    *
259    * @param[in] renderer The Renderer that is created.
260    */
261   void OnRendererCreated(Renderer renderer) override;
262
263 private:
264   /**
265    * @brief Updates the bone matrix for a ModelPrimitive.
266    *
267    * @param[in] primitive The ModelPrimitive to set the bone matrix for.
268    */
269   void UpdateBoneMatrix(Scene3D::ModelPrimitive primitive);
270
271 private:
272   /// @cond internal
273
274   // Not copyable or movable
275   DALI_INTERNAL            ModelNode(const ModelNode&) = delete; ///< Deleted copy constructor.
276   DALI_INTERNAL            ModelNode(ModelNode&&)      = delete; ///< Deleted move constructor.
277   DALI_INTERNAL ModelNode& operator=(const ModelNode&) = delete; ///< Deleted copy assignment operator.
278   DALI_INTERNAL ModelNode& operator=(ModelNode&&)      = delete; ///< Deleted move assignment operator.
279
280 private:
281   ModelPrimitiveContainer mModelPrimitiveContainer; ///< List of model primitives
282   BoneDataContainer       mBoneDataContainer;
283   Dali::Texture           mSpecularTexture;
284   Dali::Texture           mDiffuseTexture;
285   float                   mIblScaleFactor{1.0f};
286   uint32_t                mSpecularMipmapLevels{1u};
287
288   // Light
289   std::vector<Scene3D::Light> mLights;
290   /// @endcond
291 };
292
293 /**
294  * @brief Gets implementation from the handle.
295  *
296  * @SINCE_2_2.99
297  * @param handle
298  * @return Implementation
299  * @pre handle is initialized and points to a node
300  */
301 DALI_SCENE3D_API Internal::ModelNode& GetImplementation(Dali::Scene3D::ModelNode& handle);
302
303 /**
304  * @brief Gets implementation from the handle.
305  *
306  * @SINCE_2_2.99
307  * @param handle
308  * @return Implementation
309  * @pre Handle is initialized and points to a node.
310  */
311 DALI_SCENE3D_API const Internal::ModelNode& GetImplementation(const Dali::Scene3D::ModelNode& handle);
312
313 } // namespace Internal
314
315 /**
316  * @}
317  */
318 } // namespace Scene3D
319
320 } // namespace Dali
321
322 #endif // DALI_SCENE3D_MODEL_COMPONENTS_MODEL_NODE_IMPL_H