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/public-api/actors/camera-actor.h>
25 #include <dali/public-api/actors/layer.h>
26 #include <dali/public-api/adaptor-framework/window.h>
27 #include <dali/public-api/animation/animation.h>
28 #include <dali/public-api/object/weak-handle.h>
29 #include <dali/public-api/render-tasks/render-task.h>
30 #include <dali/public-api/rendering/frame-buffer.h>
31 #include <dali/public-api/rendering/texture.h>
34 #include <dali-scene3d/internal/common/environment-map-load-task.h>
35 #include <dali-scene3d/internal/common/image-based-light-observer.h>
36 #include <dali-scene3d/public-api/controls/scene-view/scene-view.h>
47 * @brief Impl class for SceneView.
49 class SceneView : public Dali::Toolkit::Internal::Control
53 * @brief Creates a new SceneView.
55 * @return A public handle to the newly allocated SceneView.
57 static Dali::Scene3D::SceneView New();
60 * @copydoc SceneView::AddCamera()
62 void AddCamera(Dali::CameraActor camera);
65 * @copydoc SceneView::RemoveCamera()
67 void RemoveCamera(CameraActor camera);
70 * @copydoc SceneView::GetCameraCount()
72 uint32_t GetCameraCount() const;
75 * @copydoc SceneView::GetSelectedCamera()
77 CameraActor GetSelectedCamera() const;
80 * @copydoc SceneView::GetCamera()
82 CameraActor GetCamera(uint32_t index) const;
85 * @copydoc SceneView::GetCamera()
87 CameraActor GetCamera(const std::string& name) const;
90 * @copydoc SceneView::SelectCamera()
92 void SelectCamera(uint32_t index);
95 * @copydoc SceneView::SelectCamera()
97 void SelectCamera(const std::string& name);
100 * @brief Register an item.
102 * Some works(e.g, lighting) of SceneView should be propagated to the child 3D items.
103 * SceneView can avoid unnecessary tree traversal to find 3D items by storing only 3D items as a list.
105 * @param[in] item scene observer to be registered.
107 void RegisterSceneItem(Scene3D::Internal::ImageBasedLightObserver* item);
110 * @brief Unregister an item
112 * @param[in] item scene observer to be unregistered.
114 void UnregisterSceneItem(Scene3D::Internal::ImageBasedLightObserver* item);
117 * @copydoc SceneView::SetImageBasedLightSource()
119 void SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor);
122 * @copydoc SceneView::SetImageBasedLightScaleFactor()
124 void SetImageBasedLightScaleFactor(float scaleFactor);
127 * @copydoc SceneView::GetImageBasedLightScaleFactor()
129 float GetImageBasedLightScaleFactor() const;
132 * @copydoc SceneView::UseFramebuffer()
134 void UseFramebuffer(bool useFramebuffer);
137 * @copydoc SceneView::IsUsingFramebuffer()
139 bool IsUsingFramebuffer() const;
142 * @copydoc SceneView::SetFramebufferMultiSamplingLevel()
144 void SetFramebufferMultiSamplingLevel(uint8_t multiSamplingLevel);
147 * @copydoc SceneView::GetFramebufferMultiSamplingLevel()
149 uint8_t GetFramebufferMultiSamplingLevel() const;
152 * @copydoc SceneView::SetSkybox()
154 void SetSkybox(const std::string& skyboxUrl);
157 * @copydoc SceneView::SetSkyboxEnvironmentMapType()
159 void SetSkyboxEnvironmentMapType(Scene3D::EnvironmentMapType skyboxEnvironmentMapType);
162 * @copydoc SceneView::SetSkyboxIntensity()
164 void SetSkyboxIntensity(float intensity);
167 * @copydoc SceneView::GetSkyboxIntensity()
169 float GetSkyboxIntensity() const;
172 * @copydoc SceneView::SetSkyboxOrientation()
174 void SetSkyboxOrientation(const Quaternion& orientation);
177 * @copydoc SceneView::GetSkyboxOrientation()
179 Quaternion GetSkyboxOrientation() const;
183 * @brief Constructs a new SceneView.
188 * A reference counted object may only be deleted by calling Unreference()
190 virtual ~SceneView();
194 * @copydoc CustomActorImpl::OnSceneConnection()
196 void OnSceneConnection(int depth) override;
199 * @copydoc CustomActorImpl::OnSceneDisconnection()
201 void OnSceneDisconnection() override;
204 * @copydoc Toolkit::Control::OnInitialize()
206 void OnInitialize() override;
209 * @copydoc Toolkit::Control::OnChildAdd()
211 void OnChildAdd(Actor& child) override;
214 * @copydoc Toolkit::Control::OnChildRemove()
216 void OnChildRemove(Actor& child) override;
219 * @copydoc Toolkit::Control::GetHeightForWidth()
221 float GetHeightForWidth(float width) override;
224 * @copydoc Toolkit::Control::GetWidthForHeight()
226 float GetWidthForHeight(float height) override;
229 * @copydoc Toolkit::Control::OnRelayout()
231 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
234 * @copydoc Toolkit::Control::IsResourceReady()
236 bool IsResourceReady() const override;
239 * @brief Changes main camera as a input camera
241 * @param camera CameraActor that will be a main camera of the SceneView
243 void UpdateCamera(CameraActor camera);
246 * @brief Updates RenderTask to use selected camera and to make framebuffer
248 void UpdateRenderTask();
251 * @brief Callback that will be called when window is resized.
253 void OnWindowResized(Window window, Window::WindowSize size);
256 * @brief Updates camera's projection orientation according to the screen orientation.
261 * @brief UpdateSkybox with skybox url and skybox environment map type.
263 * @param[in] skyboxUrl image url for skybox.
264 * @param[in] skyboxEnvironmentMapType The environment type of skybox.
266 void UpdateSkybox(const std::string& skyboxUrl, Scene3D::EnvironmentMapType skyboxEnvironmentMapType);
269 * @brief Asynchronously skybox loading finished.
271 void OnSkyboxLoadComplete();
274 * @brief Asynchronously ibl diffusel image loading finished.
276 void OnIblDiffuseLoadComplete();
279 * @brief Asynchronously ibl specular image loading finished.
281 void OnIblSpecularLoadComplete();
284 * @brief Asynchronously ibl loading finished.
286 void OnIblLoadComplete();
289 * @brief Notify the changes of Ibl textures to the child items.
291 void NotifyImageBasedLightTextureChange();
294 Toolkit::Visual::Base mVisual;
296 /////////////////////////////////////////////////////////////
297 // FrameBuffer and Rendertask to render child objects as a 3D Scene
298 Dali::WeakHandle<Dali::Window> mWindow;
299 CameraActor mDefaultCamera;
300 CameraActor mSelectedCamera;
301 std::vector<CameraActor> mCameras;
302 std::vector<Scene3D::Internal::ImageBasedLightObserver*> mItems;
303 Dali::FrameBuffer mFrameBuffer;
304 Dali::Texture mTexture;
305 Dali::RenderTask mRenderTask;
307 int32_t mWindowOrientation;
309 Quaternion mSkyboxOrientation;
310 float mSkyboxIntensity{1.0f};
311 uint8_t mFrameBufferMultiSamplingLevel{0u};
313 // Asynchronous Loading.
314 EnvironmentMapLoadTaskPtr mSkyboxLoadTask;
315 EnvironmentMapLoadTaskPtr mIblDiffuseLoadTask;
316 EnvironmentMapLoadTaskPtr mIblSpecularLoadTask;
317 std::string mSkyboxUrl;
318 std::string mDiffuseIblUrl;
319 std::string mSpecularIblUrl;
321 Scene3D::EnvironmentMapType mSkyboxEnvironmentMapType{Scene3D::EnvironmentMapType::AUTO};
322 Dali::Texture mSkyboxTexture;
323 Dali::Texture mDiffuseTexture;
324 Dali::Texture mSpecularTexture;
325 float mIblScaleFactor{1.0f};
326 uint32_t mSpecularMipmapLevels{1u};
327 bool mUseFrameBuffer{false};
328 bool mSkyboxResourceReady{true};
329 bool mIblDiffuseResourceReady{true};
330 bool mIblSpecularResourceReady{true};
331 bool mSkyboxDirty{false};
332 bool mIblDiffuseDirty{false};
333 bool mIblSpecularDirty{false};
335 // TODO : Light Source
338 } // namespace Internal
340 // Helpers for public-api forwarding methods
341 inline Dali::Scene3D::Internal::SceneView& GetImpl(Dali::Scene3D::SceneView& obj)
343 DALI_ASSERT_ALWAYS(obj);
344 Dali::RefObject& handle = obj.GetImplementation();
345 return static_cast<Dali::Scene3D::Internal::SceneView&>(handle);
348 inline const Dali::Scene3D::Internal::SceneView& GetImpl(const Dali::Scene3D::SceneView& obj)
350 DALI_ASSERT_ALWAYS(obj);
351 const Dali::RefObject& handle = obj.GetImplementation();
352 return static_cast<const Dali::Scene3D::Internal::SceneView&>(handle);
355 } // namespace Scene3D
359 #endif // DALI_SCENE3D_INTERNAL_SCENE_VIEW_H