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