1 #ifndef DALI_SCENE3D_INTERNAL_SCENE_VIEW_H
2 #define DALI_SCENE3D_INTERNAL_SCENE_VIEW_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali-toolkit/internal/visuals/image/image-visual.h>
23 #include <dali-toolkit/public-api/controls/control-impl.h>
24 #include <dali/integration-api/adaptor-framework/scene-holder.h>
25 #include <dali/public-api/actors/camera-actor.h>
26 #include <dali/public-api/actors/layer.h>
27 #include <dali/public-api/adaptor-framework/window.h>
28 #include <dali/public-api/animation/animation.h>
29 #include <dali/public-api/object/weak-handle.h>
30 #include <dali/public-api/render-tasks/render-task.h>
31 #include <dali/public-api/rendering/frame-buffer.h>
32 #include <dali/public-api/rendering/texture.h>
35 #include <dali-scene3d/internal/common/environment-map-load-task.h>
36 #include <dali-scene3d/internal/common/image-based-light-observer.h>
37 #include <dali-scene3d/public-api/controls/scene-view/scene-view.h>
48 * @brief Impl class for SceneView.
50 class SceneView : public Dali::Toolkit::Internal::Control
54 * @brief Creates a new SceneView.
56 * @return A public handle to the newly allocated SceneView.
58 static Dali::Scene3D::SceneView New();
61 * @copydoc SceneView::AddCamera()
63 void AddCamera(Dali::CameraActor camera);
66 * @copydoc SceneView::RemoveCamera()
68 void RemoveCamera(CameraActor camera);
71 * @copydoc SceneView::GetCameraCount()
73 uint32_t GetCameraCount() const;
76 * @copydoc SceneView::GetSelectedCamera()
78 CameraActor GetSelectedCamera() const;
81 * @copydoc SceneView::GetCamera()
83 CameraActor GetCamera(uint32_t index) const;
86 * @copydoc SceneView::GetCamera()
88 CameraActor GetCamera(const std::string& name) const;
91 * @copydoc SceneView::SelectCamera()
93 void SelectCamera(uint32_t index);
96 * @copydoc SceneView::SelectCamera()
98 void SelectCamera(const std::string& name);
101 * @brief Register an item.
103 * Some works(e.g, lighting) of SceneView should be propagated to the child 3D items.
104 * SceneView can avoid unnecessary tree traversal to find 3D items by storing only 3D items as a list.
106 * @param[in] item scene observer to be registered.
108 void RegisterSceneItem(Scene3D::Internal::ImageBasedLightObserver* item);
111 * @brief Unregister an item
113 * @param[in] item scene observer to be unregistered.
115 void UnregisterSceneItem(Scene3D::Internal::ImageBasedLightObserver* item);
118 * @copydoc SceneView::SetImageBasedLightSource()
120 void SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor);
123 * @copydoc SceneView::SetImageBasedLightScaleFactor()
125 void SetImageBasedLightScaleFactor(float scaleFactor);
128 * @copydoc SceneView::GetImageBasedLightScaleFactor()
130 float GetImageBasedLightScaleFactor() const;
133 * @copydoc SceneView::UseFramebuffer()
135 void UseFramebuffer(bool useFramebuffer);
138 * @copydoc SceneView::IsUsingFramebuffer()
140 bool IsUsingFramebuffer() const;
143 * @copydoc SceneView::SetFramebufferMultiSamplingLevel()
145 void SetFramebufferMultiSamplingLevel(uint8_t multiSamplingLevel);
148 * @copydoc SceneView::GetFramebufferMultiSamplingLevel()
150 uint8_t GetFramebufferMultiSamplingLevel() const;
153 * @copydoc SceneView::SetSkybox()
155 void SetSkybox(const std::string& skyboxUrl);
158 * @copydoc SceneView::SetSkyboxEnvironmentMapType()
160 void SetSkyboxEnvironmentMapType(Scene3D::EnvironmentMapType skyboxEnvironmentMapType);
163 * @copydoc SceneView::SetSkyboxIntensity()
165 void SetSkyboxIntensity(float intensity);
168 * @copydoc SceneView::GetSkyboxIntensity()
170 float GetSkyboxIntensity() const;
173 * @copydoc SceneView::SetSkyboxOrientation()
175 void SetSkyboxOrientation(const Quaternion& orientation);
178 * @copydoc SceneView::GetSkyboxOrientation()
180 Quaternion GetSkyboxOrientation() const;
184 * @brief Constructs a new SceneView.
189 * A reference counted object may only be deleted by calling Unreference()
191 virtual ~SceneView();
195 * @copydoc CustomActorImpl::OnSceneConnection()
197 void OnSceneConnection(int depth) override;
200 * @copydoc CustomActorImpl::OnSceneDisconnection()
202 void OnSceneDisconnection() override;
205 * @copydoc Toolkit::Control::OnInitialize()
207 void OnInitialize() override;
210 * @copydoc Toolkit::Control::OnChildAdd()
212 void OnChildAdd(Actor& child) override;
215 * @copydoc Toolkit::Control::OnChildRemove()
217 void OnChildRemove(Actor& child) override;
220 * @copydoc Toolkit::Control::GetHeightForWidth()
222 float GetHeightForWidth(float width) override;
225 * @copydoc Toolkit::Control::GetWidthForHeight()
227 float GetWidthForHeight(float height) override;
230 * @copydoc Toolkit::Control::OnRelayout()
232 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
235 * @copydoc Toolkit::Control::IsResourceReady()
237 bool IsResourceReady() const override;
240 * @brief Changes main camera as a input camera
242 * @param camera CameraActor that will be a main camera of the SceneView
244 void UpdateCamera(CameraActor camera);
247 * @brief Updates RenderTask to use selected camera and to make framebuffer
249 void UpdateRenderTask();
252 * @brief Callback that will be called when window is resized.
254 void OnWindowResized(Window window, Window::WindowSize size);
257 * @brief Updates camera's projection orientation according to the screen orientation.
262 * @brief UpdateSkybox with skybox url and skybox environment map type.
264 * @param[in] skyboxUrl image url for skybox.
265 * @param[in] skyboxEnvironmentMapType The environment type of skybox.
267 void UpdateSkybox(const std::string& skyboxUrl, Scene3D::EnvironmentMapType skyboxEnvironmentMapType);
270 * @brief Asynchronously skybox loading finished.
272 void OnSkyboxLoadComplete();
275 * @brief Asynchronously ibl diffusel image loading finished.
277 void OnIblDiffuseLoadComplete();
280 * @brief Asynchronously ibl specular image loading finished.
282 void OnIblSpecularLoadComplete();
285 * @brief Asynchronously ibl loading finished.
287 void OnIblLoadComplete();
290 * @brief Notify the changes of Ibl textures to the child items.
292 void NotifyImageBasedLightTextureChange();
295 Toolkit::Visual::Base mVisual;
297 /////////////////////////////////////////////////////////////
298 // FrameBuffer and Rendertask to render child objects as a 3D Scene
299 Dali::WeakHandle<Dali::Window> mWindow;
300 Integration::SceneHolder mSceneHolder;
301 CameraActor mDefaultCamera;
302 CameraActor mSelectedCamera;
303 std::vector<CameraActor> mCameras;
304 std::vector<Scene3D::Internal::ImageBasedLightObserver*> mItems;
305 Dali::FrameBuffer mFrameBuffer;
306 Dali::Texture mTexture;
307 Dali::RenderTask mRenderTask;
309 int32_t mWindowOrientation;
311 Quaternion mSkyboxOrientation;
312 float mSkyboxIntensity{1.0f};
313 uint8_t mFrameBufferMultiSamplingLevel{0u};
315 // Asynchronous Loading.
316 EnvironmentMapLoadTaskPtr mSkyboxLoadTask;
317 EnvironmentMapLoadTaskPtr mIblDiffuseLoadTask;
318 EnvironmentMapLoadTaskPtr mIblSpecularLoadTask;
319 std::string mSkyboxUrl;
320 std::string mDiffuseIblUrl;
321 std::string mSpecularIblUrl;
323 Scene3D::EnvironmentMapType mSkyboxEnvironmentMapType{Scene3D::EnvironmentMapType::AUTO};
324 Dali::Texture mSkyboxTexture;
325 Dali::Texture mDiffuseTexture;
326 Dali::Texture mSpecularTexture;
327 float mIblScaleFactor{1.0f};
328 uint32_t mSpecularMipmapLevels{1u};
329 bool mUseFrameBuffer{false};
330 bool mSkyboxResourceReady{true};
331 bool mIblDiffuseResourceReady{true};
332 bool mIblSpecularResourceReady{true};
333 bool mSkyboxDirty{false};
334 bool mIblDiffuseDirty{false};
335 bool mIblSpecularDirty{false};
337 // TODO : Light Source
340 } // namespace Internal
342 // Helpers for public-api forwarding methods
343 inline Dali::Scene3D::Internal::SceneView& GetImpl(Dali::Scene3D::SceneView& obj)
345 DALI_ASSERT_ALWAYS(obj);
346 Dali::RefObject& handle = obj.GetImplementation();
347 return static_cast<Dali::Scene3D::Internal::SceneView&>(handle);
350 inline const Dali::Scene3D::Internal::SceneView& GetImpl(const Dali::Scene3D::SceneView& obj)
352 DALI_ASSERT_ALWAYS(obj);
353 const Dali::RefObject& handle = obj.GetImplementation();
354 return static_cast<const Dali::Scene3D::Internal::SceneView&>(handle);
357 } // namespace Scene3D
361 #endif // DALI_SCENE3D_INTERNAL_SCENE_VIEW_H