Asynchronous loading of Scene3D resources
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / controls / scene-view / scene-view.h
1 #ifndef DALI_SCENE3D_SCENE_VIEW_H
2 #define DALI_SCENE3D_SCENE_VIEW_H
3
4 /*
5  * Copyright (c) 2022 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 // INTERNAL INCLUDES
22 #include <dali-scene3d/public-api/api.h>
23
24 // EXTERNAL INCLUDES
25 #include <dali-toolkit/public-api/controls/control.h>
26 #include <dali/public-api/actors/camera-actor.h>
27 #include <dali/public-api/common/dali-common.h>
28
29 namespace Dali
30 {
31 namespace Scene3D
32 {
33 namespace Internal DALI_INTERNAL
34 {
35 class SceneView;
36 }
37
38 /**
39  * @addtogroup dali_toolkit_controls_scene_view
40  * @{
41  */
42
43 /**
44  * @brief SceneView is a Dali::Toolkit::Control to show multiple 3D objects in a single 3D scene.
45  * Each SceneView has its own 3D space, and 3D objects added to SceneView are positioned in the space.
46  * SceneView has a 3D root layer internally to trigger the depth test in the rendering process.
47  * When an Actor is added to the SceneView with Add() method,
48  * the Actor and its children are actually become child of the 3D layer automatically.
49  *
50  *  SceneView
51  *      |
52  * Dali::Layer(Layer::LAYER_3D)
53  *      |
54  *    Actor
55  *
56  * The children of the 3D root layer will be rendered with the SceneView's own CameraActor.
57  *
58  * SceneView can have multiple CameraActor and one of them is used to render the multiple objects as a Scene.
59  * AddCamera(), RemoveCamera(), GetCamera(), and SelectCamera() are methods to manage CameraActors of the SceneView.
60  * Users can place multiple cameras in a scene, either to show the entire scene or to show individual objects.
61  * And the user can select the currently needed camera by using the SelectCamera() method.
62  *
63  * SceneView makes one built-in CameraActor by default.
64  * The default CameraActor has index 0 and is not removed by using RemoveCamera() method.
65  * Therefore, the minimum value returned by GetCameraCount() method is 1.
66  *
67  * If the size of SceneView is changed, Some properties of CameraActor that depend on the size can be changed too.
68  * The changing properties are as follows: projectionMode, aspectRatio, leftPlaneDistance, rightPlaneDistance, topPlaneDistance, and bottomPlaneDistance.
69  * Position, near/farPlaneDistance, and FieldOfView are maintained even if the size of the SceneView is changed.
70  * The FieldOfView of Dali::CameraActor is for vertical fov. The horizontal fov is internally updated according to the SceneView size.
71  *
72  * The same light source is set for all Models added to SceneView, if SceneView has light source.
73  * The SetImageBasedLightSource() method sets the same IBL to all Models added to the SceneView.
74  * If any Model already has an IBL, it is replaced with the SceneView's IBL.
75  *
76  * SceneView provides an option to use FBO for rendering result with UseFramebuffer() method.
77  * If it is false, SceneView is always drawn in the form of a rectangle on the default window surface directly.
78  * It improves performance, but the SceneView is always drawn on top of other 2D objects regardless of Actor tree order.
79  * And it will show wrong result in case the window's default CameraActor is transformed.
80  * So, it is recommended not to change window's CameraActor.
81  *
82  * If FBO is used, the rendering result of SceneView is drawn on the FBO and it is mapped on the plane of the SceneView.
83  * It decreases performance, but it is useful to show SceneView according to the rendering order with other Actors.
84  * And it can be used in case window's CameraActor is transformed.
85  *
86  * And since SceneView is a Control, it can be placed together with other 2D UI components in the DALi window.
87  *
88  * @SINCE_2_1.38
89  * @code
90  *
91  * Dali::Scene3D::SceneView sceneView = Dali::Scene3D::SceneView::New();
92  * sceneView.SetProperty(Dali::Actor::Property::SIZE, Vector2(400, 400));
93  * mWindow.Add(sceneView);
94  *
95  * Dali::Scene3D::Model model = Dali::Scene3D::Model::New(...);
96  * sceneView.Add(model);
97  *
98  * CameraActor cameraActor = CameraActor::New();
99  * sceneView.AddCamera(cameraActor);
100  *
101  * @endcode
102  */
103 class DALI_SCENE3D_API SceneView : public Dali::Toolkit::Control
104 {
105 public:
106   /**
107    * @brief The skybox types
108    * @SINCE_2_2.6
109    */
110   enum class SkyboxType
111   {
112     CUBEMAP,        ///< Skybox in cubemap
113     EQUIRECTANGULAR ///< Skybox in equirectangular projection
114   };
115
116   /**
117    * @brief Create an initialized SceneView.
118    *
119    * @SINCE_2_1.38
120    * @return A handle to a newly allocated Dali resource
121    */
122   static SceneView New();
123
124   /**
125    * @brief Creates an uninitialized SceneView.
126    *
127    * Only derived versions can be instantiated. Calling member
128    * functions with an uninitialized Dali::Object is not allowed.
129    *
130    * @SINCE_2_1.38
131    */
132   SceneView();
133
134   /**
135    * @brief Destructor.
136    *
137    * This is non-virtual since derived Handle types must not contain data or virtual methods.
138    *
139    * @SINCE_2_1.38
140    */
141   ~SceneView();
142
143   /**
144    * @brief Copy constructor.
145    *
146    * @SINCE_2_1.38
147    * @param[in] sceneView Handle to an object
148    */
149   SceneView(const SceneView& sceneView);
150
151   /**
152    * @brief Move constructor
153    *
154    * @SINCE_2_1.38
155    * @param[in] rhs A reference to the moved handle
156    */
157   SceneView(SceneView&& rhs);
158
159   /**
160    * @brief Assignment operator.
161    *
162    * @SINCE_2_1.38
163    * @param[in] sceneView Handle to an object
164    * @return reference to this
165    */
166   SceneView& operator=(const SceneView& sceneView);
167
168   /**
169    * @brief Move assignment
170    *
171    * @SINCE_2_1.38
172    * @param[in] rhs A reference to the moved handle
173    * @return A reference to this
174    */
175   SceneView& operator=(SceneView&& rhs);
176
177   /**
178    * @brief Downcasts an Object handle to SceneView.
179    *
180    * If handle points to a SceneView, the downcast produces valid handle.
181    * If not, the returned handle is left uninitialized.
182    *
183    * @SINCE_2_1.38
184    * @param[in] handle Handle to an object
185    * @return Handle to a SceneView or an uninitialized handle
186    */
187   static SceneView DownCast(BaseHandle handle);
188
189   /**
190    * @brief Adds a CameraActor to the SceneView
191    * The CameraActor can be used as a selected camera to render the scene by using SelectCamera(uint32_t) or SelectCamera(std::string)
192    *
193    * @SINCE_2_1.38
194    * @note
195    * AspectRatio property of CameraActor will be changed depending on the Size of this SceneView.
196    *
197    * For Perspective camera
198    * The FieldOfView of Dali::CameraActor is for vertical fov.
199    * When the size of the SceneView is changed, the vertical fov is maintained
200    * and the horizontal fov is automatically calculated according to the SceneView's aspect ratio.
201    *
202    * For Orthographic camera
203    * leftPlaneDistance, rightPlaneDistance, and bottomPlaneDistance properties are defined according to the topPlaneDistance and aspectRatio.
204    *
205    * @param[in] camera CameraActor added on this scene view.
206    */
207   void AddCamera(Dali::CameraActor camera);
208
209   /**
210    * @brief Removes a CameraActor from this SceneView.
211    *
212    * @SINCE_2_1.38
213    * @note If removed CameraActor is selected CameraActor,
214    * first camera in the list is set to selected CameraActor.
215    *
216    * @param[in] camera CameraActor to be removed from this SceneView
217    */
218   void RemoveCamera(CameraActor camera);
219
220   /**
221    * @brief Retrieves the number of cameras.
222    *
223    * @SINCE_2_1.38
224    * @return Number of cameras those currently the SceneView contains.
225    */
226   uint32_t GetCameraCount() const;
227
228   /**
229    * @brief Retrieves selected CameraActor.
230    *
231    * @SINCE_2_1.38
232    * @return CameraActor currently used in SceneView as a selected CameraActor
233    */
234   CameraActor GetSelectedCamera() const;
235
236   /**
237    * @brief Retrieves a CameraActor of the index.
238    *
239    * @SINCE_2_1.38
240    * @param[in] index Index of CameraActor to be retrieved.
241    *
242    * @return CameraActor of the index
243    */
244   CameraActor GetCamera(uint32_t index) const;
245
246   /**
247    * @brief Retrieves a CameraActor of the name.
248    *
249    * @SINCE_2_1.38
250    * @param[in] name string keyword of CameraActor to be retrieved.
251    *
252    * @return CameraActor that has the name as a Dali::Actor::Property::NAME
253    */
254   CameraActor GetCamera(const std::string& name) const;
255
256   /**
257    * @brief Makes SceneView use a CameraActor of index as a selected camera.
258    *
259    * @SINCE_2_1.38
260    * @param[in] index Index of CameraActor to be used as a selected camera.
261    */
262   void SelectCamera(uint32_t index);
263
264   /**
265    * @brief Makes SceneView use a CameraActor of a name as a selected camera.
266    *
267    * @SINCE_2_1.38
268    * @param[in] name string keyword of CameraActor to be used as a selected camera.
269    */
270   void SelectCamera(const std::string& name);
271
272   /**
273    * @brief Sets Image Based Light Source to apply it on the all Models those added on this SceneView.
274    *
275    * @SINCE_2_1.38
276    * @note If any Models already have IBL, they are batch-overridden with the SceneView's IBL.
277    * If SceneView has IBL, IBL of newly added Model is also overridden.
278    * To set indivisual IBL for each Model, the Model's IBL should be set after the SceneView's IBL.
279    *
280    * @param[in] diffuseUrl cube map that can be used as a diffuse IBL source.
281    * @param[in] specularUrl cube map that can be used as a specular IBL source.
282    * @param[in] scaleFactor scale factor that controls light source intensity in [0.0f, 1.0f]. Default value is 1.0f.
283    */
284   void SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor = 1.0f);
285
286   /**
287    * @brief Sets Scale Factor of Image Based Light Source.
288    *
289    * @SINCE_2_1.41
290    * @note If SetImageBasedLightSource() or SetImageBasedLightTexture() method is called after this method, scaleFactor is overriden.
291    * @note Default value is 1.0f.
292    *
293    * @param[in] scaleFactor scale factor that controls light source intensity in [0.0f, 1.0f].
294    */
295   void SetImageBasedLightScaleFactor(float scaleFactor);
296
297   /**
298    * @brief Gets Scale Factor of Image Based Light Source.
299    * Default value is 1.0f.
300    *
301    * @SINCE_2_1.41
302    * @return scale factor that controls light source intensity.
303    */
304   float GetImageBasedLightScaleFactor() const;
305
306   /**
307    * @brief Sets whether to use FBO or not for the SceneView.
308    * If useFramebuffer is true, rendering result of SceneView is drawn on FBO and it is mapping on this SceneView plane.
309    * If useFramebuffer is false, each item in SceneView is rendered on window directly.
310    * Default is false.
311    *
312    * @SINCE_2_1.38
313    * @note If useFramebuffer is true, it could decrease performance but entire rendering order is satisfied.
314    * If useFramebuffer is false, performance is become better but SceneView is rendered on top of the other 2D Actors regardless tree order.
315    *
316    * @param[in] useFramebuffer True to use FBO for SceneView.
317    */
318   void UseFramebuffer(bool useFramebuffer);
319
320   /**
321    * @brief Gets whether this SceneView uses Framebuffer or not.
322    *
323    * @SINCE_2_1.38
324    * @return bool True if this SceneView uses Framebuffer.
325    */
326   bool IsUsingFramebuffer() const;
327
328   /**
329    * @brief Sets Skybox for this scene.
330    * Skybox texture is asynchronously loaded. When loading is finished, ResourceReady is emitted.
331    *
332    * @SINCE_2_2.0
333    * @param[in] skyboxUrl image url for skybox.
334    * @param[in] skyboxType The environment type of skymap (by default it is cubemap).
335    */
336   void SetSkybox(const std::string& skyboxUrl, SkyboxType skyboxType = SkyboxType::CUBEMAP);
337
338   /**
339    * @brief Sets Skybox intensity.
340    * The skybox intensity is multiplied to the color of skybox texture.
341    * Default value is 1.0f.
342    *
343    * @SINCE_2_2.0
344    * @note Intensity should be positive value.
345    * @param[in] intensity Intensity value to be multiplied to the cube map color
346    */
347   void SetSkyboxIntensity(float intensity);
348
349   /**
350    * @brief Gets Skybox intensity.
351    * Default value is 1.0f.
352    *
353    * @SINCE_2_2.0
354    * @return skybox intensity
355    */
356   float GetSkyboxIntensity() const;
357
358   /**
359    * @brief Sets Orientation of Skybox.
360    *
361    * @SINCE_2_2.0
362    * @param[in] orientation Quaternion for orientation of Skybox.
363    */
364   void SetSkyboxOrientation(const Quaternion& orientation);
365
366   /**
367    * @brief Gets Skybox orientation.
368    *
369    * @SINCE_2_2.0
370    * @return skybox orientation
371    */
372   Quaternion GetSkyboxOrientation() const;
373
374 public: // Not intended for application developers
375   /// @cond internal
376   /**
377    * @brief Creates a handle using the Toolkit::Internal implementation.
378    *
379    * @param[in] implementation The Control implementation
380    */
381   DALI_INTERNAL SceneView(Internal::SceneView& implementation);
382
383   /**
384    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
385    *
386    * @param[in] internal A pointer to the internal CustomActor
387    */
388   DALI_INTERNAL SceneView(Dali::Internal::CustomActor* internal);
389   /// @endcond
390 };
391
392 /**
393  * @}
394  */
395 } // namespace Scene3D
396
397 } // namespace Dali
398
399 #endif // DALI_SCENE3D_SCENE_VIEW_H