1 #ifndef DALI_TOOLKIT_INTERNAL_SCENE_H
\r
2 #define DALI_TOOLKIT_INTERNAL_SCENE_H
\r
5 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
\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
11 * http://www.apache.org/licenses/LICENSE-2.0
\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
21 // EXTERNAL INCLUDES
\r
23 #include <dali/public-api/object/base-object.h>
\r
24 #include <dali/devel-api/adaptor-framework/image-loading.h>
\r
25 #include <dali/devel-api/adaptor-framework/file-loader.h>
\r
27 // INTERNAL INCLUDES
\r
28 #include <dali-toolkit/devel-api/controls/scene/scene.h>
\r
29 #include <dali-toolkit/internal/controls/scene/gltf-loader.h>
\r
30 #include <dali-toolkit/public-api/controls/control-impl.h>
\r
48 // glTF file extension
\r
49 const std::string GLTF_EXT( ".gltf" );
\r
52 * cube map face index
\r
54 const int cubeMap_index_x[2][6] = { { 2, 0, 1, 1, 1, 3 },{ 0, 1, 2, 3, 4, 5 } };
\r
55 const int cubeMap_index_y[2][6] = { { 1, 1, 0, 2, 1, 1 },{ 0, 0, 0, 0, 0, 0 } };
\r
60 * Scene implementation class
\r
62 class Scene : public Control
\r
68 CROSS_HORIZENTAL = 0, // Cross horizental style cube map
\r
69 ARRAY_HORIZENTAL, // array horizental style cube map
\r
75 * @copydoc Dali::Toolkit::Scene::Scene
\r
80 * @copydoc Dali::Toolkit::Scene::~Scene
\r
85 * @copydoc Dali::Toolkit::Scene::New( const std::string& filePath )
\r
87 static Dali::Toolkit::Scene New( const std::string& filePath );
\r
90 * @copydoc Dali::Toolkit::Scene::New( const std::string& filePath, const std::string& diffuseTexturePath, const std::string& specularTexturePath, Vector4 ScaleFactor = Vector4( 1.0, 1.0, 1.0, 1.0 ) )
\r
92 static Dali::Toolkit::Scene New( const std::string& filePath, const std::string& diffuseTexturePath, const std::string& specularTexturePath, Vector4 ScaleFactor = Vector4( 1.0, 1.0, 1.0, 1.0 ) );
\r
95 * @copydoc Dali::Toolkit::Scene::CreateScene( const std::string& filePath )
\r
97 bool CreateScene( const std::string& filePath );
\r
100 * @copydoc Dali::Toolkit::Scene::CreateScene( const std::string& filePath )
\r
102 uint32_t GetAnimationCount();
\r
105 * @copydoc Dali::Toolkit::Scene::PlayAnimation()
\r
107 bool PlayAnimation( uint32_t index );
\r
110 * @copydoc Dali::Toolkit::Scene::PlayAnimations()
\r
112 bool PlayAnimations();
\r
115 * @copydoc Dali::Toolkit::Scene::SetLight( Toolkit::Scene::LightType type, Vector3 lightVector, Vector3 lightColor = Vector3( 1.0, 1.0, 1.0 ) )
\r
117 bool SetLight( Toolkit::Scene::LightType type, Vector3 lightVector, Vector3 lightColor = Vector3( 1.0, 1.0, 1.0 ) );
\r
120 * @brief Set default CameraActor.
\r
121 * with Dali::Camera::Type = Dali::Camera::LOOK_AT_TARGET,
\r
122 * near clipping plane = 0.1,
\r
123 * and camera position = Vector3( 0.0, 0.0, 0.0 ).
\r
125 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
128 * @brief Add CameraActor loaded from scene format file.
\r
130 void AddCamera( CameraActor& cameraActor );
\r
133 * @brief Add Animation loaded from scene format file.
\r
135 void AddAnimation( Animation& animation );
\r
138 * @brief Add new Shader.
\r
139 * Actors can share same Shader if they use same properties.
\r
140 * If a property changes in a shader, then the property of all actors that use the shader change.
\r
142 void AddShader( Shader shader );
\r
145 * @brief Get Root Actor.
\r
150 * @copydoc Dali::Toolkit::Scene::GetDefaultCamera()
\r
152 CameraActor GetDefaultCamera();
\r
155 * @copydoc Dali::Toolkit::Scene::GetCamera( int cameraIndex = -1 )
\r
157 CameraActor GetCamera( int cameraIndex = -1 );
\r
160 * @brief Get light type.
\r
162 Toolkit::Scene::LightType GetLightType();
\r
165 * @brief Get light vector.
\r
166 * Return light position when light type is LightType::POINT_LIGHT
\r
167 * Return light direction when light type is LightType::DIRECTIONAL_LIGHT
\r
169 Vector3 GetLightVector();
\r
172 * @brief Get light color.
\r
174 Vector3 GetLightColor();
\r
177 * @brief Get Scaling factor of IBL.
\r
179 Vector4 GetIBLScaleFactor();
\r
182 * @brief Get BRDF Texture.
\r
184 Texture GetBRDFTexture();
\r
187 * @brief Get diffuse cube map texture.
\r
189 Texture GetDiffuseTexture();
\r
192 * @brief Get specular cube map texture.
\r
194 Texture GetSpecularTexture();
\r
198 * @brief Crop image buffer.
\r
199 * For each direction, Offset + faceSize must be width or height or less then them.
\r
201 unsigned char* CropBuffer( unsigned char* sourceBuffer, unsigned int bytesPerPixel, unsigned int width, unsigned int height, unsigned int xOffset, unsigned int yOffset, unsigned int xFaceSize, unsigned int yFaceSize );
\r
204 * @brief Upload cube map texture.
\r
206 void UploadTextureFace( Texture& texture, Devel::PixelBuffer pixelBuffer, int faceIndex );
\r
209 * @brief Set diffuse and specular cube map textures.
\r
211 void SetCubeMap( const std::string& diffuseTexturePath, const std::string& specularTexturePath, Vector4 ScaleFactor = Vector4( 1.0, 1.0, 1.0, 1.0 ) );
\r
213 virtual void OnInitialize();
\r
217 * @brief Load 2D texture.
\r
218 * @param[in] imageUrl Image URL of the texture.
\r
219 * @param[in] generateMipmaps If generateMipmaps is true, then generate mipmap of this texture.
\r
220 * @return Texture loaded from imageUrl.
\r
222 Texture LoadTexture( const char *imageUrl, bool generateMipmaps );
\r
225 Actor mRoot; // Root actor that contains scene graph
\r
227 std::vector<Shader> mShaderArray; // Shader Array to change properties of scene such as lighting.
\r
229 std::vector<CameraActor> mCameraActorArray; // CameraActer array loaded from scene format file.
\r
230 CameraActor mDefaultCamera; // Default CameraActor for the empty mCameraActorArray.
\r
232 std::vector<Animation> mAnimationArray; // Animation array loaded from scene format file.
\r
234 Toolkit::Scene::LightType mLightType; // Light type
\r
235 Vector3 mLightVector; // Light position when mLightType is LightType::POINT_LIGHT
\r
236 // Light direction when mLightType is LightType::DIRECTIONAL_LIGHT
\r
237 Vector3 mLightColor; // Light color
\r
239 Vector4 mIBLScaleFactor; // IBL scaling factor for the IBL rendering
\r
240 Texture mBRDFTexture; // BRDF texture for the PBR rendering
\r
241 Texture mSpecularTexture; // Specular cube map texture
\r
242 Texture mDiffuseTexture; // Diffuse cube map texture
\r
246 // Undefined copy constructor.
\r
247 Scene( const Scene& );
\r
249 // Undefined assignment operator.
\r
250 Scene& operator=( const Scene& );
\r
253 } // namespace Internal
\r
255 // Helpers for public-api forwarding methods
\r
256 inline const Internal::Scene& GetImpl( const Toolkit::Scene& scene )
\r
258 DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
\r
259 const Dali::RefObject& handle = scene.GetImplementation();
\r
261 return static_cast<const Toolkit::Internal::Scene&>( handle );
\r
264 inline Internal::Scene& GetImpl( Toolkit::Scene& scene )
\r
266 DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
\r
268 Dali::RefObject& handle = scene.GetImplementation();
\r
270 return static_cast<Toolkit::Internal::Scene&>( handle );
\r
273 }//namespace Toolkit
\r
277 #endif // DALI_TOOLKIT_INTERNAL_SCENE_H
\r