6dbe8594b1b39674bb5ecda2ef76c4688782da91
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scene3d-view / scene3d-view-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_SCENE3D_VIEW_H\r
2 #define DALI_TOOLKIT_INTERNAL_SCENE3D_VIEW_H\r
3 \r
4 /*\r
5  * Copyright (c) 2021 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/devel-api/adaptor-framework/file-loader.h>\r
23 #include <dali/devel-api/adaptor-framework/image-loading.h>\r
24 #include <dali/public-api/object/base-object.h>\r
25 #include <dali/public-api/rendering/shader.h>\r
26 #include <cstring>\r
27 \r
28 // INTERNAL INCLUDES\r
29 #include <dali-toolkit/devel-api/controls/scene3d-view/scene3d-view.h>\r
30 #include <dali-toolkit/internal/controls/scene3d-view/gltf-loader.h>\r
31 #include <dali-toolkit/public-api/controls/control-impl.h>\r
32 \r
33 namespace Dali\r
34 {\r
35 namespace Toolkit\r
36 {\r
37 class Scene3dView;\r
38 \r
39 namespace Internal\r
40 {\r
41 namespace Gltf\r
42 {\r
43 class Loader;\r
44 \r
45 }\r
46 \r
47 /**\r
48  * Scene3dView implementation class\r
49  */\r
50 class Scene3dView : public Control\r
51 {\r
52 public:\r
53   enum CubeType\r
54   {\r
55     CROSS_HORIZONTAL = 0, // Cross horizontal style cube map\r
56     ARRAY_HORIZONTAL,     // array horizontal style cube map\r
57     NONE\r
58   };\r
59 \r
60   /**\r
61    * @copydoc Dali::Toolkit::Scene3dView::Scene3dView\r
62    */\r
63   Scene3dView();\r
64 \r
65   /**\r
66    * @copydoc Dali::Toolkit::Scene3dView::~Scene3dView\r
67    */\r
68   virtual ~Scene3dView();\r
69 \r
70   /**\r
71    * @copydoc Dali::Toolkit::Scene3dView::New( const std::string& filePath )\r
72    */\r
73   static Dali::Toolkit::Scene3dView New(const std::string& filePath);\r
74 \r
75   /**\r
76    * @copydoc Dali::Toolkit::Scene3dView::New( const std::string& filePath, const std::string& diffuseTexturePath, const std::string& specularTexturePath, Vector4 scaleFactor )\r
77    */\r
78   static Dali::Toolkit::Scene3dView New(const std::string& filePath, const std::string& diffuseTexturePath, const std::string& specularTexturePath, Vector4 scaleFactor);\r
79 \r
80   /**\r
81    * @copydoc Dali::Toolkit::Scene3dView::CreateScene()\r
82    */\r
83   bool CreateScene();\r
84 \r
85   /**\r
86    * @copydoc Dali::Toolkit::Scene3dView::GetAnimationCount()\r
87    */\r
88   uint32_t GetAnimationCount();\r
89 \r
90   /**\r
91    * @copydoc Dali::Toolkit::Scene3dView::PlayAnimation()\r
92    */\r
93   bool PlayAnimation(uint32_t index);\r
94 \r
95   /**\r
96    * @copydoc Dali::Toolkit::Scene3dView::PlayAnimations()\r
97    */\r
98   bool PlayAnimations();\r
99 \r
100   /**\r
101    * @copydoc Dali::Toolkit::Scene3dView::SetLight( Toolkit::Scene3dView::LightType type, Vector3 lightVector, Vector3 lightColor )\r
102    */\r
103   bool SetLight(Toolkit::Scene3dView::LightType type, Vector3 lightVector, Vector3 lightColor);\r
104 \r
105   /**\r
106    * @brief Set default CameraActor specified in the each scene format specification.\r
107    * Default input values are derived from glTF default camera format.\r
108    * with Dali::Camera::Type = Dali::Camera::LOOK_AT_TARGET,\r
109    * near clipping plane = 0.1,\r
110    * and camera position = Vector3( 0.0, 0.0, 0.0 ).\r
111    */\r
112   bool SetDefaultCamera(const Dali::Camera::Type type = Dali::Camera::LOOK_AT_TARGET, const float nearPlane = 0.1, const Vector3 cameraPosition = Vector3(0.0, 0.0, 0.0));\r
113 \r
114   /**\r
115    * @brief Add CameraActor loaded from scene format file.\r
116    */\r
117   void AddCamera(CameraActor cameraActor);\r
118 \r
119   /**\r
120    * @brief Add Animation loaded from scene format file.\r
121    */\r
122   void AddAnimation(Animation animation);\r
123 \r
124   /**\r
125    * @brief Add new Shader.\r
126    * Actors can share same Shader if they use same properties.\r
127    * If a property changes in a shader, then the property of all actors that use the shader change.\r
128    */\r
129   void AddShader(Shader shader);\r
130 \r
131   /**\r
132    * @brief Get Root Actor.\r
133    */\r
134   Actor GetRoot();\r
135 \r
136   /**\r
137    * @copydoc Dali::Toolkit::Scene3dView::GetDefaultCamera()\r
138    */\r
139   CameraActor GetDefaultCamera();\r
140 \r
141   /**\r
142    * @copydoc Dali::Toolkit::Scene3dView::GetCameraCount()\r
143    */\r
144   uint32_t GetCameraCount();\r
145 \r
146   /**\r
147    * @copydoc Dali::Toolkit::Scene3dView::GetCamera( uint32_t cameraIndex )\r
148    */\r
149   CameraActor GetCamera(uint32_t cameraIndex);\r
150 \r
151   /**\r
152    * @brief Get light type.\r
153    */\r
154   Toolkit::Scene3dView::LightType GetLightType();\r
155 \r
156   /**\r
157    * @brief Get light vector.\r
158    * Return light position when light type is LightType::POINT_LIGHT\r
159    * Return light direction when light type is LightType::DIRECTIONAL_LIGHT\r
160    */\r
161   Vector3 GetLightVector();\r
162 \r
163   /**\r
164    * @brief Get light color.\r
165    */\r
166   Vector3 GetLightColor();\r
167 \r
168   /**\r
169    * @brief Get Scaling factor of IBL.\r
170    */\r
171   Vector4 GetIBLScaleFactor();\r
172 \r
173   /**\r
174    * @brief Get BRDF Texture.\r
175    */\r
176   Texture GetBRDFTexture();\r
177 \r
178   /**\r
179    * @brief Get diffuse cube map texture.\r
180    */\r
181   Texture GetDiffuseTexture();\r
182 \r
183   /**\r
184    * @brief Get specular cube map texture.\r
185    */\r
186   Texture GetSpecularTexture();\r
187 \r
188 private:\r
189   /**\r
190    * @brief Get Cropped image buffer.\r
191    * For each direction, Offset + faceSize must be width or height or less then them.\r
192    */\r
193   uint8_t* GetCroppedBuffer(uint8_t* sourceBuffer, uint32_t bytesPerPixel, uint32_t width, uint32_t height, uint32_t xOffset, uint32_t yOffset, uint32_t xFaceSize, uint32_t yFaceSize);\r
194 \r
195   /**\r
196    * @brief Upload cube map texture.\r
197    */\r
198   void UploadTextureFace(Texture& texture, Devel::PixelBuffer pixelBuffer, uint32_t faceIndex);\r
199 \r
200   /**\r
201    * @brief Set diffuse and specular cube map textures.\r
202    */\r
203   void SetCubeMap(const std::string& diffuseTexturePath, const std::string& specularTexturePath, Vector4 scaleFactor = Vector4(1.0, 1.0, 1.0, 1.0));\r
204 \r
205   virtual void OnInitialize();\r
206 \r
207   /**\r
208    * @brief Load 2D texture.\r
209    * @param[in] imageUrl Image URL of the texture.\r
210    * @param[in] generateMipmaps If generateMipmaps is true, then generate mipmap of this texture.\r
211    * @return Texture loaded from imageUrl.\r
212    */\r
213   Texture LoadTexture(const char* imageUrl, bool generateMipmaps);\r
214 \r
215 private:\r
216   Actor       mRoot;     // Root actor that contains scene graph\r
217   std::string mFilePath; // Full file path of scene file\r
218 \r
219   std::vector<Shader> mShaderArray; // Shader Array to change properties of scene such as lighting.\r
220 \r
221   std::vector<CameraActor> mCameraActorArray; // CameraActer array loaded from scene format file.\r
222   CameraActor              mDefaultCamera;    // Default CameraActor for the empty mCameraActorArray.\r
223 \r
224   std::vector<Animation> mAnimationArray; // Animation array loaded from scene format file.\r
225 \r
226   Toolkit::Scene3dView::LightType mLightType;   // Light type\r
227   Vector3                         mLightVector; // Light position when mLightType is LightType::POINT_LIGHT\r
228                                                 // Light direction when mLightType is LightType::DIRECTIONAL_LIGHT\r
229   Vector3 mLightColor;                          // Light color\r
230 \r
231   Vector4 mIBLScaleFactor;  // IBL scaling factor for the IBL rendering\r
232   Texture mBRDFTexture;     // BRDF texture for the PBR rendering\r
233   Texture mSpecularTexture; // Specular cube map texture\r
234   Texture mDiffuseTexture;  // Diffuse cube map texture\r
235 \r
236 private:\r
237   // Undefined copy constructor.\r
238   Scene3dView(const Scene3dView&);\r
239 \r
240   // Undefined assignment operator.\r
241   Scene3dView& operator=(const Scene3dView&);\r
242 };\r
243 \r
244 } // namespace Internal\r
245 \r
246 // Helpers for public-api forwarding methods\r
247 inline const Internal::Scene3dView& GetImpl(const Toolkit::Scene3dView& scene3dView)\r
248 {\r
249   DALI_ASSERT_ALWAYS(scene3dView && "Scene3dView handle is empty");\r
250   const Dali::RefObject& handle = scene3dView.GetImplementation();\r
251 \r
252   return static_cast<const Toolkit::Internal::Scene3dView&>(handle);\r
253 }\r
254 \r
255 inline Internal::Scene3dView& GetImpl(Toolkit::Scene3dView& scene3dView)\r
256 {\r
257   DALI_ASSERT_ALWAYS(scene3dView && "Scene3dView handle is empty");\r
258 \r
259   Dali::RefObject& handle = scene3dView.GetImplementation();\r
260 \r
261   return static_cast<Toolkit::Internal::Scene3dView&>(handle);\r
262 }\r
263 \r
264 } //namespace Toolkit\r
265 \r
266 } //namespace Dali\r
267 \r
268 #endif // DALI_TOOLKIT_INTERNAL_SCENE3D_VIEW_H\r