Minor coverity issue fixes
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / controls / scene3d-view / scene3d-view.h
1 #ifndef DALI_TOOLKIT_SCENE3D_VIEW_H\r
2 #define DALI_TOOLKIT_SCENE3D_VIEW_H\r
3 \r
4 /*\r
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.\r
6  *\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  *\r
11  * http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  *\r
19  */\r
20 \r
21 // EXTERNAL INCLUDES\r
22 #include <dali/public-api/actors/camera-actor.h>\r
23 \r
24 // INTERNAL INCLUDES\r
25 #include <dali-toolkit/public-api/controls/control.h>\r
26 \r
27 namespace Dali\r
28 {\r
29 namespace Toolkit\r
30 {\r
31 namespace Internal DALI_INTERNAL\r
32 {\r
33 /**\r
34  * Scene3dView implementation class\r
35  */\r
36 class Scene3dView;\r
37 \r
38 } // namespace DALI_INTERNAL\r
39 \r
40 /**\r
41  *\r
42  * Scene3dView is a class for containing scene elements loaded from scene format file(e.g., glTF). Scene elements mean scene graph, cameras, and animations.\r
43  *\r
44  * Basic idea:-\r
45  *\r
46  * 1) The Scene3dView is initialized with diffuse and specular cube map for the Image Based Lighting.\n\r
47  *    If the Scene3dView initialized without cube map, the objects of the Scene3dView cannot be rendered with IBL.\n\r
48  * 2) The Scene3dView is loaded from each scene format file(e.g., glTF).\n\r
49  * 3) The Scene3dView can have a point light or a directional light.(optional)\n\r
50  * 4) The Scene3dView playes each actor's animation.\n\r
51  *\r
52  *\r
53  * Usage example: -\r
54  *\r
55  * @code\r
56  *\r
57  * void Scene3dViewExample::Create( Application& application )\r
58  * {\r
59  *   // Use 'Scene3dView::New( URL_SCENE_FILE )', if you don't want to render with IBL.\r
60  *   Scene3dView scene3dView = Scene3dView::New( URL_SCENE_FILE, URL_DIFFUSE_TEXTURE, URL_SPECULAR_TEXTURE );\r
61  *\r
62  *   Stage::GetCurrent().Add( scene3dView );\r
63  *   scene3dView.PlayAnimations();\r
64  *\r
65  *   scene3dView.SetLight( Scene3dView::LightType::DIRECTIONAL_LIGHT, Vector3( 1.0, 1.0, -1.0 ), Vector3( 0.3, 0.3, 0.3 ) );\r
66  * }\r
67  *\r
68  * @endcode\r
69  *\r
70  * @remarks This control makes 3D Layer internally. Therefore, if any 2D UI\r
71  * control is added as a child of this Scene3dView, the functionality of the 2D UI\r
72  * may not work well.\r
73  */\r
74 \r
75 class DALI_TOOLKIT_API Scene3dView : public Control\r
76 {\r
77 public:\r
78   enum LightType\r
79   {\r
80     // Scene doesn't use both of point and directional light\r
81     NONE = 0,\r
82     // Scene use point light\r
83     POINT_LIGHT = 1,\r
84     // Scene use directional light\r
85     DIRECTIONAL_LIGHT = 2\r
86   };\r
87 \r
88   /**\r
89    * @brief Create an uninitialized Scene3dView; this can be initialized with Scene3dView::New()\r
90    * Calling member functions with an uninitialized Dali::Object is not allowed.\r
91    */\r
92   Scene3dView();\r
93 \r
94   /**\r
95    * @brief Copy constructor. Creates another handle that points to the same real object\r
96    * @param[in] handle to copy from\r
97    */\r
98   Scene3dView(const Scene3dView& handle);\r
99 \r
100   /**\r
101    * @brief Assignment operator. Changes this handle to point to another real object\r
102    * @param[in] handle to copy from\r
103    * @return reference to this\r
104    */\r
105   Scene3dView& operator=(const Scene3dView& handle);\r
106 \r
107   /**\r
108    * @brief Move constructor. Creates another handle that points to the same real object\r
109    * @param[in] rhs to move from\r
110    */\r
111   Scene3dView(Scene3dView&& rhs);\r
112 \r
113   /**\r
114    * @brief Move assignment operator. Changes this handle to point to another real object\r
115    * @param[in] rhs to move from\r
116    * @return reference to this\r
117    */\r
118   Scene3dView& operator=(Scene3dView&& rhs);\r
119 \r
120   /**\r
121    * @brief Destructor\r
122    * This is non-virtual since derived Handle types must not contain data or virtual methods.\r
123    */\r
124   ~Scene3dView();\r
125 \r
126   /**\r
127    * @brief Downcast an Object handle to Scene3dView. If handle points to a Scene3dView the\r
128    * downcast produces valid handle. If not the returned handle is left uninitialized.\r
129    * @param[in] handle Handle to an object\r
130    * @return handle to a Scene3dView or an uninitialized handle\r
131    */\r
132   static Scene3dView DownCast(BaseHandle handle);\r
133 \r
134   /**\r
135    * @brief Create an initialized Scene3dView.\r
136    * @param[in] filePath File path of scene format file (e.g., glTF).\r
137    * @return A handle to a newly allocated Dali resource\r
138    */\r
139   static Scene3dView New(const std::string& filePath);\r
140 \r
141   /**\r
142    * @brief Create an initialized Scene3dView.\r
143    * @param[in] filePath File path of scene format file (e.g., glTF).\r
144    * @param[in] diffuseTexturePath The texture path of diffuse cube map that used to render with Image Based Lighting.\r
145    * @param[in] specularTexturePath The texture path of specular cube map that used to render with Image Based Lighting.\r
146    * @param[in] scaleFactor Scaling factor for the Image Based Lighting.\r
147    * @return A handle to a newly allocated Dali resource\r
148    */\r
149   static Scene3dView New(const std::string& filePath, const std::string& diffuseTexturePath, const std::string& specularTexturePath, Vector4 scaleFactor);\r
150 \r
151   /**\r
152    * @brief Get animation count.\r
153    * @return number of animations.\r
154    */\r
155   uint32_t GetAnimationCount();\r
156 \r
157   /**\r
158    * @brief Play an animation.\r
159    * @param[in] index Animation index\r
160    * @return true if animation is played.\r
161    */\r
162   bool PlayAnimation(uint32_t index);\r
163 \r
164   /**\r
165    * @brief Play all animations.\r
166    * @return true if animations are played.\r
167    */\r
168   bool PlayAnimations();\r
169 \r
170   /**\r
171    * @brief Set point light or directional light. If SetLight is not called, this scene doesn't use these kind of light.\r
172    * @param[in] type The light type. If the light is point light set this LightType::POINT_LIGHT,\r
173    * or if the light is directional light set this LightType::DIRECTIONAL_LIGHT.\r
174    * @param[in] lightVector The point light position when light type is LightType::POINT_LIGHT.\r
175    * The light direction when light type is LightType::DIRECTIONAL_LIGHT.\r
176    * @param[in] lightColor Vector3 value that denotes the light color of point light or directional light. Since this is the light color, we don't need to use alpha value.\r
177    * @return true if point light or directional light is set.\r
178    */\r
179   bool SetLight(LightType type, Vector3 lightVector, Vector3 lightColor);\r
180 \r
181   /**\r
182    * @brief Get default CameraActor. Dali::Camera::Type = Dali::Camera::LOOK_AT_TARGET , near clipping plane = 0.1, and camera position = Vector3( 0.0, 0.0, 0.0 ).\r
183    * @return CameraActor.\r
184    */\r
185   CameraActor GetDefaultCamera();\r
186 \r
187   /**\r
188    * @brief Get camera count.\r
189    * @return number of cameras.\r
190    */\r
191   uint32_t GetCameraCount();\r
192 \r
193   /**\r
194    * @brief Get CameraActor. If there is no CameraActor in the list, then returns default CameraActor.\r
195    * @param[in] cameraIndex Index of CameraActor list.\r
196    * @return CameraActor.\r
197    */\r
198   CameraActor GetCamera(uint32_t cameraIndex);\r
199 \r
200   // Not intended for developer use\r
201 public:\r
202   /**\r
203    * @brief Creates a handle using the Toolkit::Internal implementation.\r
204    * @param[in]  implementation  The UI Control implementation.\r
205    */\r
206   DALI_INTERNAL Scene3dView(Toolkit::Internal::Scene3dView& implementation);\r
207 \r
208   explicit DALI_INTERNAL Scene3dView(Dali::Internal::CustomActor* internal);\r
209 };\r
210 \r
211 } // namespace Toolkit\r
212 \r
213 } // namespace Dali\r
214 \r
215 #endif // DALI_TOOLKIT_SCENE3D_VIEW_H\r