b48a158f0ef54995a90b8c204b8c4df912d0532e
[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) 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.h>
23 #include <dali/public-api/common/dali-common.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-scene3d/public-api/api.h>
27 #include <dali-scene3d/public-api/model-components/model-primitive.h>
28
29 namespace Dali
30 {
31 namespace Scene3D
32 {
33 // Forward declarations.
34
35 namespace Internal
36 {
37 class ModelNode;
38 }
39 /**
40  * @addtogroup dali_scene3d_model_components_model_node
41  * @{
42  */
43
44 /**
45  * @brief ModelNode is a class for representing the Node of Model in Scene3D.
46  * ModelNode contains multiple ModelPrimitives and allows easy access and modification of Material information that ModelPrimitive has.
47  * If a 3D format file is loaded by Model, ModelNode is created internally to construct the model.
48  * In addition, you can create a Custom ModelNode using ModelPrimitive and Material directly and add it to Model.
49  *
50  * @SINCE_2_2.99
51  *
52  * @code
53  * ModelNode modelNode = ModelNode::New();
54  * ModelPrimitive modelPrimitive = ModelPrimitive::New();
55  * modelNode.AddModelPrimitive(modelPrimitive);
56  *
57  * Material material = Material::New();
58  * modelPrimitive.SetMaterial(material);
59  * material.SetProperty(PropertyIndex, PropertyValue);
60  * @endcode
61  */
62 class DALI_SCENE3D_API ModelNode : public Dali::CustomActor
63 {
64 public:
65   /**
66    * @brief Create an initialized ModelNode.
67    *
68    * @SINCE_2_2.99
69    * @return A handle to a newly allocated Dali resource
70    */
71   static ModelNode New();
72
73   /**
74    * @brief Creates an uninitialized ModelNode.
75    *
76    * Only derived versions can be instantiated. Calling member
77    * functions with an uninitialized Dali::Object is not allowed.
78    *
79    * @SINCE_2_2.99
80    */
81   ModelNode();
82
83   /**
84    * @brief Destructor.
85    *
86    * This is non-virtual since derived Handle types must not contain data or virtual methods.
87    *
88    * @SINCE_2_2.99
89    */
90   ~ModelNode();
91
92   /**
93    * @brief Copy constructor.
94    *
95    * @SINCE_2_2.99
96    * @param[in] modelNode Handle to an object
97    */
98   ModelNode(const ModelNode& modelNode);
99
100   /**
101    * @brief Move constructor
102    *
103    * @SINCE_2_2.99
104    * @param[in] rhs A reference to the moved handle
105    */
106   ModelNode(ModelNode&& rhs);
107
108   /**
109    * @brief Assignment operator.
110    *
111    * @SINCE_2_2.99
112    * @param[in] modelNode Handle to an object
113    * @return reference to this
114    */
115   ModelNode& operator=(const ModelNode& modelNode);
116
117   /**
118    * @brief Move assignment
119    *
120    * @SINCE_2_2.99
121    * @param[in] rhs A reference to the moved handle
122    * @return A reference to this
123    */
124   ModelNode& operator=(ModelNode&& rhs);
125
126   /**
127    * @brief Downcasts an Object handle to ModelNode.
128    *
129    * If handle points to a ModelNode, the downcast produces valid handle.
130    * If not, the returned handle is left uninitialized.
131    *
132    * @SINCE_2_2.99
133    * @param[in] handle Handle to an object
134    * @return Handle to a ModelNode or an uninitialized handle
135    */
136   static ModelNode DownCast(BaseHandle handle);
137
138 public: // Public Method
139
140   /**
141    * @brief Gets the number of ModelPrimitives this node has.
142    *
143    * @SINCE_2_2.99
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.99
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.99
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.99
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.99
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    * @param[in] nodeName The name of the child ModelNode object you want to find.
185    * @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.
186    */
187   ModelNode FindChildModelNodeByName(std::string_view nodeName);
188
189 public: // Not intended for application developers
190   /// @cond internal
191   /**
192    * @brief Creates a handle using the Scene3D::Internal implementation.
193    *
194    * @param[in] implementation The ModelNodel implementation
195    */
196   DALI_INTERNAL ModelNode(Internal::ModelNode& implementation);
197
198   /**
199    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
200    *
201    * @param[in] internal A pointer to the internal CustomActor
202    */
203   DALI_INTERNAL ModelNode(Dali::Internal::CustomActor* internal);
204   /// @endcond
205 };
206
207 /**
208  * @}
209  */
210 } // namespace Scene3D
211
212 } // namespace Dali
213
214 #endif // DALI_SCENE3D_MODEL_COMPONENTS_MODEL_NODE_H