Merge "Use Mipmap level to sample specular texture" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / controls / model / model.h
1 #ifndef DALI_SCENE3D_MODEL_H
2 #define DALI_SCENE3D_MODEL_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-toolkit/public-api/controls/control.h>
23 #include <dali/public-api/actors/camera-actor.h>
24 #include <dali/public-api/common/dali-common.h>
25 #include <dali/public-api/rendering/texture.h>
26
27 // INTERNAL INCLUDES
28 #include <dali-scene3d/public-api/api.h>
29
30 namespace Dali
31 {
32 namespace Scene3D
33 {
34 namespace Internal DALI_INTERNAL
35 {
36 class Model;
37 }
38
39 /**
40  * @addtogroup dali_toolkit_controls_model
41  * @{
42  */
43
44 /**
45  * @brief Model is a control to show 3D model objects.
46  * Model supports to load glTF 2.0 and DLI models for the input format
47  * and also supports Physically Based Rendering with Image Based Lighting.
48  *
49  * The Animations defined in the glTF or DLI models are also loaded and can be retrieved by using GetAnimation() method.
50  * The number of animation is also retrieved by GetAnimationCount() method.
51  *
52  * By default, The loaded model has its own position and size which are defined in vertex buffer regardless of the Control size.
53  *
54  * @SINCE_2_1.41
55  * @code
56  *
57  * Model model = Model::New(modelUrl);
58  * model.SetProperty(Dali::Actor::Property::SIZE, Vector2(width, height));
59  * model.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
60  * model.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
61  * model.SetImageBasedLightSource(diffuseUrl, specularUrl, scaleFactor);
62  * window.Add(model);
63  * uint32_t animationCount = model.GetAnimationCount();
64  * Dali::Animation animation = model.GetAnimation(0);
65  * animation.Play();
66  *
67  * @endcode
68  */
69 class DALI_SCENE3D_API Model : public Dali::Toolkit::Control
70 {
71 public:
72   /**
73    * @brief Create an initialized Model.
74    *
75    * @SINCE_2_1.41
76    * @param[in] modelUrl model file path.(e.g., glTF, and DLI).
77    * @param[in] resourceDirectoryUrl resource file path that includes binary, image etc.
78    * @note If resourceDirectoryUrl is empty, the parent directory path of modelUrl is used for resource path.
79    * @return A handle to a newly allocated Dali resource
80    */
81   static Model New(const std::string& modelUrl, const std::string& resourceDirectoryUrl = std::string());
82
83   /**
84    * @brief Creates an uninitialized Model.
85    *
86    * Only derived versions can be instantiated. Calling member
87    * functions with an uninitialized Dali::Object is not allowed.
88    *
89    * @SINCE_2_1.41
90    */
91   Model();
92
93   /**
94    * @brief Destructor.
95    *
96    * This is non-virtual since derived Handle types must not contain data or virtual methods.
97    *
98    * @SINCE_2_1.41
99    */
100   ~Model();
101
102   /**
103    * @brief Copy constructor.
104    *
105    * @SINCE_2_1.41
106    * @param[in] model Handle to an object
107    */
108   Model(const Model& model);
109
110   /**
111    * @brief Move constructor
112    *
113    * @SINCE_2_1.41
114    * @param[in] rhs A reference to the moved handle
115    */
116   Model(Model&& rhs);
117
118   /**
119    * @brief Assignment operator.
120    *
121    * @SINCE_2_1.41
122    * @param[in] model Handle to an object
123    * @return reference to this
124    */
125   Model& operator=(const Model& model);
126
127   /**
128    * @brief Move assignment
129    *
130    * @SINCE_2_1.41
131    * @param[in] rhs A reference to the moved handle
132    * @return A reference to this
133    */
134   Model& operator=(Model&& rhs);
135
136   /**
137    * @brief Downcasts an Object handle to Model.
138    *
139    * If handle points to a Model, the downcast produces valid handle.
140    * If not, the returned handle is left uninitialized.
141    *
142    * @SINCE_2_1.41
143    * @param[in] handle Handle to an object
144    * @return Handle to a Model or an uninitialized handle
145    */
146   static Model DownCast(BaseHandle handle);
147
148   /**
149    * @brief Retrieves model root Actor.
150    *
151    * @SINCE_2_1.41
152    * @return Root Actor of the model.
153    */
154   const Actor GetModelRoot() const;
155
156   /**
157    * @brief Whether allow this model's children actor to use events.
158    *
159    * Usually, 3D Model might have a lot of actors. And most of them don't need to check events.
160    * To optimize traversal, we need to setup some flag that this model don't allow (or allow) to traversal
161    * children so that child can use events.
162    *
163    * @SINCE_2_1.43
164    * @note Even if we set children sensitive as false, model itself's sensitive
165    * is depend on it's property.
166    * @note If we don't call this API, default is false. (Don't allow to traversal model's children during hit-test)
167    *
168    * @param[in] enable True to enable model's children can use events.
169    */
170   void SetChildrenSensitive(bool enable);
171
172   /**
173    * @brief Gets whether this Model allow model's children actor to use events or not.
174    *
175    * @SINCE_2_1.43
176    * @return bool True if this Model allow model children sensitive.
177    */
178   bool GetChildrenSensitive() const;
179
180   /**
181    * @brief Whether allow this model's children actor to be keyboard focusable.
182    *
183    * Usually, 3D Model might have a lot of actors. And most of them don't need to check focusable.
184    * To optimize traversal, we need to setup some flag that this model don't allow (or allow) to traversal
185    * children so that child can be keyboard focusable.
186    *
187    * @SINCE_2_2.2
188    * @note Even if we set children focusable as false, model itself's focusable
189    * is depend on it's property.
190    * @note If we don't call this API, default is false. (Don't allow to traversal model's children during focusable test)
191    *
192    * @param[in] enable True to enable model's children can be focusable.
193    */
194   void SetChildrenFocusable(bool enable);
195
196   /**
197    * @brief Gets whether this Model allow model's children actor to be keyboard focusable or not.
198    *
199    * @SINCE_2_2.2
200    * @return bool True if this Model allow model children are focusable.
201    */
202   bool GetChildrenFocusable() const;
203
204   /**
205    * @brief Changes Image Based Light as the input textures.
206    *
207    * @SINCE_2_1.41
208    * @param[in] diffuseUrl cube map that can be used as a diffuse IBL source.
209    * @param[in] specularUrl cube map that can be used as a specular IBL source.
210    * @param[in] scaleFactor scale factor that controls light source intensity in [0.0f, 1.0f]. Default value is 1.0f.
211    */
212   void SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor = 1.0f);
213
214   /**
215    * @brief Sets Scale Factor of Image Based Light Source.
216    *
217    * @SINCE_2_1.41
218    * @note If SetImageBasedLightSource() method is called after this method, scaleFactor is overrided.
219    *
220    * @param[in] scaleFactor scale factor that controls light source intensity in [0.0f, 1.0f].
221    */
222   void SetImageBasedLightScaleFactor(float scaleFactor);
223
224   /**
225    * @brief Gets Scale Factor of Image Based Light Source.
226    * Default value is 1.0f.
227    *
228    * @SINCE_2_1.41
229    * @return scale factor that controls light source intensity.
230    */
231   float GetImageBasedLightScaleFactor() const;
232
233   /**
234    * @brief Gets number of animations those loaded from model file.
235    *
236    * @SINCE_2_1.41
237    * @return The number of loaded animations.
238    * @note This method should be called after Model load finished.
239    */
240   uint32_t GetAnimationCount() const;
241
242   /**
243    * @brief Gets animation at the index.
244    *
245    * @SINCE_2_1.41
246    * @param[in] index Index of animation to be retrieved.
247    * @return Animation at the index.
248    * @note This method should be called after Model load finished.
249    */
250   Dali::Animation GetAnimation(uint32_t index) const;
251
252   /**
253    * @brief Retrieves animation with the given name.
254    *
255    * @SINCE_2_1.41
256    * @param[in] name string name of animation to be retrieved.
257    * @return Animation that has the given name.
258    * @note This method should be called after Model load finished.
259    */
260   Dali::Animation GetAnimation(const std::string& name) const;
261
262   /**
263    * @brief Gets number of camera parameters those loaded from model file.
264    *
265    * @SINCE_2_2.15
266    * @return The number of loaded camera parameters.
267    * @note This method should be called after Model load finished.
268    */
269   uint32_t GetCameraCount() const;
270
271   /**
272    * @brief Generate camera actor using camera parameters at the index.
273    * If camera parameter is valid, create new CameraActor.
274    * Camera parameter decide at initialized time and
275    * didn't apply model node's current position (like Animation).
276    *
277    * @SINCE_2_2.15
278    * @param[in] index Index of camera to be used for generation camera.
279    * @return Generated CameraActor by the index, or empty Handle if generation failed.
280    * @note This method should be called after Model load finished.
281    */
282   Dali::CameraActor GenerateCamera(uint32_t index) const;
283
284   /**
285    * @brief Apply camera parameters at the index to inputed camera actor.
286    * If camera parameter is valid and camera actor is not empty, apply parameters.
287    * It will change camera's transform and near / far / fov or orthographic size / aspect ratio (if defined)
288    * Camera parameter decide at initialized time and
289    * didn't apply model node's current position (like Animation).
290    *
291    * @SINCE_2_2.15
292    * @param[in] index Index of camera to be used for generation camera.
293    * @param[in,out] camera Index of camera to be used for generation camera.
294    * @return True if apply successed. False otherwise.
295    * @note This method should be called after Model load finished.
296    */
297   bool ApplyCamera(uint32_t index, Dali::CameraActor camera) const;
298
299 public: // Not intended for application developers
300   /// @cond internal
301   /**
302    * @brief Creates a handle using the Toolkit::Internal implementation.
303    *
304    * @param[in] implementation The Control implementation
305    */
306   DALI_INTERNAL Model(Internal::Model& implementation);
307
308   /**
309    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
310    *
311    * @param[in] internal A pointer to the internal CustomActor
312    */
313   DALI_INTERNAL Model(Dali::Internal::CustomActor* internal);
314   /// @endcond
315 };
316
317 /**
318  * @}
319  */
320 } // namespace Scene3D
321
322 } // namespace Dali
323
324 #endif // DALI_SCENE3D_MODEL_H