[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / model-components / model-node.h
1 #ifndef DALI_SCENE3D_MODEL_COMPONENTS_MODEL_NODE_H
2 #define DALI_SCENE3D_MODEL_COMPONENTS_MODEL_NODE_H
3
4 /*
5  * Copyright (c) 2024 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-toolkit/public-api/controls/control.h>
23 #include <dali/public-api/common/dali-common.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-scene3d/public-api/algorithm/navigation-mesh.h>
27 #include <dali-scene3d/public-api/api.h>
28 #include <dali-scene3d/public-api/loader/blend-shape-details.h> ///< For Loader::BlendShapes::Index
29 #include <dali-scene3d/public-api/model-components/model-primitive.h>
30 namespace Dali
31 {
32 namespace Scene3D
33 {
34 // Forward declarations.
35
36 namespace Internal
37 {
38 class ModelNode;
39 }
40 /**
41  * @addtogroup dali_scene3d_model_components_model_node
42  * @{
43  */
44
45 /**
46  * @brief ModelNode is a class for representing the Node of Model in Scene3D.
47  * ModelNode contains multiple ModelPrimitives and allows easy access and modification of Material information that ModelPrimitive has.
48  * If a 3D format file is loaded by Model, ModelNode is created internally to construct the model.
49  * In addition, you can create a Custom ModelNode using ModelPrimitive and Material directly and add it to Model.
50  *
51  * @SINCE_2_2.22
52  *
53  * @code
54  * ModelNode modelNode = ModelNode::New();
55  * ModelPrimitive modelPrimitive = ModelPrimitive::New();
56  * modelNode.AddModelPrimitive(modelPrimitive);
57  *
58  * Material material = Material::New();
59  * modelPrimitive.SetMaterial(material);
60  * material.SetProperty(PropertyIndex, PropertyValue);
61  * @endcode
62  */
63 class DALI_SCENE3D_API ModelNode : public Dali::Toolkit::Control
64 {
65 public:
66   /**
67    * @brief Create an initialized ModelNode.
68    *
69    * @SINCE_2_2.22
70    * @return A handle to a newly allocated Dali resource
71    */
72   static ModelNode New();
73
74   /**
75    * @brief Creates an uninitialized ModelNode.
76    *
77    * Only derived versions can be instantiated. Calling member
78    * functions with an uninitialized Dali::Object is not allowed.
79    *
80    * @SINCE_2_2.22
81    */
82   ModelNode();
83
84   /**
85    * @brief Destructor.
86    *
87    * This is non-virtual since derived Handle types must not contain data or virtual methods.
88    *
89    * @SINCE_2_2.22
90    */
91   ~ModelNode();
92
93   /**
94    * @brief Copy constructor.
95    *
96    * @SINCE_2_2.22
97    * @param[in] modelNode Handle to an object
98    */
99   ModelNode(const ModelNode& modelNode);
100
101   /**
102    * @brief Move constructor
103    *
104    * @SINCE_2_2.22
105    * @param[in] rhs A reference to the moved handle
106    */
107   ModelNode(ModelNode&& rhs) noexcept;
108
109   /**
110    * @brief Assignment operator.
111    *
112    * @SINCE_2_2.22
113    * @param[in] modelNode Handle to an object
114    * @return reference to this
115    */
116   ModelNode& operator=(const ModelNode& modelNode);
117
118   /**
119    * @brief Move assignment
120    *
121    * @SINCE_2_2.22
122    * @param[in] rhs A reference to the moved handle
123    * @return A reference to this
124    */
125   ModelNode& operator=(ModelNode&& rhs) noexcept;
126
127   /**
128    * @brief Downcasts an Object handle to ModelNode.
129    *
130    * If handle points to a ModelNode, the downcast produces valid handle.
131    * If not, the returned handle is left uninitialized.
132    *
133    * @SINCE_2_2.22
134    * @param[in] handle Handle to an object
135    * @return Handle to a ModelNode or an uninitialized handle
136    */
137   static ModelNode DownCast(BaseHandle handle);
138
139 public: // Public Method
140   /**
141    * @brief Gets the number of ModelPrimitives this node has.
142    *
143    * @SINCE_2_2.22
144    * @return The number of ModelPrimitives this node has.
145    */
146   uint32_t GetModelPrimitiveCount() const;
147
148   /**
149    * @brief Appends a ModelPrimitive to this node.
150    *
151    * @SINCE_2_2.22
152    * @param[in] modelPrimitive The ModelPrimitive to append.
153    */
154   void AddModelPrimitive(ModelPrimitive modelPrimitive);
155
156   /**
157    * @brief Removes a ModelPrimitive from this node.
158    *
159    * @SINCE_2_2.22
160    * @param[in] modelPrimitive The ModelPrimitive to remove.
161    */
162   void RemoveModelPrimitive(ModelPrimitive modelPrimitive);
163
164   /**
165    * @brief Removes a ModelPrimitive from this node by index.
166    *
167    * @SINCE_2_2.22
168    * @param[in] index The index of the ModelPrimitive to remove.
169    */
170   void RemoveModelPrimitive(uint32_t index);
171
172   /**
173    * @brief Gets a ModelPrimitive by index.
174    *
175    * @SINCE_2_2.22
176    * @param[in] index The index of the ModelPrimitive to get.
177    * @return The ModelPrimitive at the given index, or an empty handle if the index is out of range.
178    */
179   ModelPrimitive GetModelPrimitive(uint32_t index) const;
180
181   /**
182    * @brief Returns a child ModelNode object with a name that matches nodeName.
183    *
184    * @SINCE_2_2.34
185    * @param[in] nodeName The name of the child ModelNode object you want to find.
186    * @return Returns a child ModelNode object with a name that matches nodeName. If there is no corresponding child ModelNode object, it returns an empty ModelNode object.
187    */
188   ModelNode FindChildModelNodeByName(std::string_view nodeName);
189
190   /**
191    * @brief Retrieve the list of blendshape name that current ModelNode hold.
192    * The name will be appended end of input list.
193    *
194    * @SINCE_2_2.34
195    * @param[in, out] blendShapeNames The name of blendShape list collected.
196    */
197   void RetrieveBlendShapeNames(std::vector<std::string>& blendShapeNames) const;
198
199   /**
200    * @brief Get the index of blend shape by given name.
201    *
202    * @SINCE_2_2.34
203    * @param[in] blendShapeName The name of blendshape that is not empty.
204    * @return Index of blendshape, or return invalid if there is no blendshape with given name.
205    */
206   Loader::BlendShapes::Index GetBlendShapeIndexByName(std::string_view blendShapeName) const;
207
208   /**
209    * @brief Sets collider mesh on the ModelNode
210    *
211    * The ownership of a collider mesh is taken over by the ModelNode.
212    *
213    * If there was a collider mesh set previously it will be erased.
214    *
215    * To remove collider mesh empty unique_ptr must be passed.
216    *
217    * @SINCE_2_2.53
218    * @param[in] colliderMesh r-value to unique pointer of ColliderMesh
219    */
220   void SetColliderMesh(std::unique_ptr<Algorithm::ColliderMesh>&& colliderMesh);
221
222   /**
223    * @brief Returns associated collider mesh
224    *
225    * HasColliderMesh() must be called to determine whether a valid
226    * collider mesh is associated. Calling GetColliderMesh() without
227    * previous check may produce undefined behaviour.
228    *
229    * @SINCE_2_2.53
230    * @return Associated collider mesh
231    */
232   const Algorithm::ColliderMesh& GetColliderMesh();
233
234   /**
235    * @brief Determines whether there is a valid collider mesh set
236    *
237    * @SINCE_2_2.53
238    * @return True if collider mesh is set, False otherwise
239    */
240   [[nodiscard]] bool HasColliderMesh() const;
241
242   /**
243    * @brief Sets whether this ModelNode casts shadow or not.
244    * If it is true, this ModelNode is drawn on Shadow Map.
245    *
246    * @SINCE_2_3.99
247    * @param[in] castShadow Whether this ModelNode casts shadow or not.
248    * @note This method affects only for this ModelNode.
249    */
250   void CastShadow(bool castShadow);
251
252   /**
253    * @brief Retrieves whether the ModelNode cast shadow or not for Light.
254    *
255    * @SINCE_2_3.99
256    * @return True if this ModelNode cast shadow.
257    * @note IBL does not cast any shadow.
258    */
259   bool IsShadowCasting() const;
260
261   /**
262    * @brief Sets whether this ModelNode receives shadow or not.
263    * If it is true, shadows are drawn on this ModelNode.
264    *
265    * @SINCE_2_3.99
266    * @param[in] receiveShadow Whether this ModelNode receives shadow or not.
267    * @note This method affects only for this ModelNode.
268    */
269   void ReceiveShadow(bool receiveShadow);
270
271   /**
272    * @brief Retrieves whether the ModelNode receives shadow or not for Light.
273    *
274    * @SINCE_2_3.99
275    * @return True if this ModelNode receives shadow.
276    */
277   bool IsShadowReceiving() const;
278
279 public: // Not intended for application developers
280   /// @cond internal
281   /**
282    * @brief Creates a handle using the Scene3D::Internal implementation.
283    *
284    * @param[in] implementation The ModelNodel implementation
285    */
286   DALI_INTERNAL ModelNode(Internal::ModelNode& implementation);
287
288   /**
289    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
290    *
291    * @param[in] internal A pointer to the internal CustomActor
292    */
293   DALI_INTERNAL ModelNode(Dali::Internal::CustomActor* internal);
294   /// @endcond
295 };
296
297 /**
298  * @}
299  */
300 } // namespace Scene3D
301
302 } // namespace Dali
303
304 #endif // DALI_SCENE3D_MODEL_COMPONENTS_MODEL_NODE_H