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/public-api/controls/scene-view/scene-view.h>
35 #include <dali-scene3d/internal/common/environment-map-load-task.h>
36 #include <dali-scene3d/internal/common/image-based-light-observer.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::SetSkybox()
144 void SetSkybox(const std::string& skyboxUrl);
147 * @copydoc SceneView::SetSkyboxEnvironmentMapType()
149 void SetSkyboxEnvironmentMapType(Scene3D::EnvironmentMapType skyboxEnvironmentMapType);
152 * @copydoc SceneView::SetSkyboxIntensity()
154 void SetSkyboxIntensity(float intensity);
157 * @copydoc SceneView::GetSkyboxIntensity()
159 float GetSkyboxIntensity() const;
162 * @copydoc SceneView::SetSkyboxOrientation()
164 void SetSkyboxOrientation(const Quaternion& orientation);
167 * @copydoc SceneView::GetSkyboxOrientation()
169 Quaternion GetSkyboxOrientation() const;
173 * @brief Constructs a new SceneView.
178 * A reference counted object may only be deleted by calling Unreference()
180 virtual ~SceneView();
184 * @copydoc CustomActorImpl::OnSceneConnection()
186 void OnSceneConnection(int depth) override;
189 * @copydoc CustomActorImpl::OnSceneDisconnection()
191 void OnSceneDisconnection() override;
194 * @copydoc Toolkit::Control::OnInitialize()
196 void OnInitialize() override;
199 * @copydoc Toolkit::Control::OnChildAdd()
201 void OnChildAdd(Actor& child) override;
204 * @copydoc Toolkit::Control::OnChildRemove()
206 void OnChildRemove(Actor& child) override;
209 * @copydoc Toolkit::Control::GetHeightForWidth()
211 float GetHeightForWidth(float width) override;
214 * @copydoc Toolkit::Control::GetWidthForHeight()
216 float GetWidthForHeight(float height) override;
219 * @copydoc Toolkit::Control::OnRelayout()
221 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
224 * @copydoc Toolkit::Control::IsResourceReady()
226 bool IsResourceReady() const override;
229 * @brief Changes main camera as a input camera
231 * @param camera CameraActor that will be a main camera of the SceneView
233 void UpdateCamera(CameraActor camera);
236 * @brief Updates RenderTask to use selected camera and to make framebuffer
238 void UpdateRenderTask();
241 * @brief Callback that will be called when window is resized.
243 void OnWindowResized(Window window, Window::WindowSize size);
246 * @brief Updates camera's projection orientation according to the screen orientation.
251 * @brief UpdateSkybox with skybox url and skybox environment map type.
253 * @param[in] skyboxUrl image url for skybox.
254 * @param[in] skyboxEnvironmentMapType The environment type of skybox.
256 void UpdateSkybox(const std::string& skyboxUrl, Scene3D::EnvironmentMapType skyboxEnvironmentMapType);
259 * @brief Asynchronously skybox loading finished.
261 void OnSkyboxLoadComplete();
264 * @brief Asynchronously ibl diffusel image loading finished.
266 void OnIblDiffuseLoadComplete();
269 * @brief Asynchronously ibl specular image loading finished.
271 void OnIblSpecularLoadComplete();
274 * @brief Asynchronously ibl loading finished.
276 void OnIblLoadComplete();
279 * @brief Notify the changes of Ibl textures to the child items.
281 void NotifyImageBasedLightTextureChange();
284 Toolkit::Visual::Base mVisual;
286 /////////////////////////////////////////////////////////////
287 // FrameBuffer and Rendertask to render child objects as a 3D Scene
288 Dali::WeakHandle<Dali::Window> mWindow;
289 CameraActor mDefaultCamera;
290 CameraActor mSelectedCamera;
291 std::vector<CameraActor> mCameras;
292 std::vector<Scene3D::Internal::ImageBasedLightObserver*> mItems;
293 Dali::FrameBuffer mFrameBuffer;
294 Dali::Texture mTexture;
295 Dali::RenderTask mRenderTask;
297 int32_t mWindowOrientation;
299 Quaternion mSkyboxOrientation;
300 float mSkyboxIntensity{1.0f};
302 // Asynchronous Loading.
303 EnvironmentMapLoadTaskPtr mSkyboxLoadTask;
304 EnvironmentMapLoadTaskPtr mIblDiffuseLoadTask;
305 EnvironmentMapLoadTaskPtr mIblSpecularLoadTask;
306 std::string mSkyboxUrl;
307 std::string mDiffuseIblUrl;
308 std::string mSpecularIblUrl;
310 Scene3D::EnvironmentMapType mSkyboxEnvironmentMapType{Scene3D::EnvironmentMapType::AUTO};
311 Dali::Texture mSkyboxTexture;
312 Dali::Texture mDiffuseTexture;
313 Dali::Texture mSpecularTexture;
314 float mIblScaleFactor{1.0f};
315 bool mUseFrameBuffer{false};
316 bool mSkyboxResourceReady{true};
317 bool mIblDiffuseResourceReady{true};
318 bool mIblSpecularResourceReady{true};
319 bool mSkyboxDirty{false};
320 bool mIblDiffuseDirty{false};
321 bool mIblSpecularDirty{false};
323 // TODO : Light Source
326 } // namespace Internal
328 // Helpers for public-api forwarding methods
329 inline Dali::Scene3D::Internal::SceneView& GetImpl(Dali::Scene3D::SceneView& obj)
331 DALI_ASSERT_ALWAYS(obj);
332 Dali::RefObject& handle = obj.GetImplementation();
333 return static_cast<Dali::Scene3D::Internal::SceneView&>(handle);
336 inline const Dali::Scene3D::Internal::SceneView& GetImpl(const Dali::Scene3D::SceneView& obj)
338 DALI_ASSERT_ALWAYS(obj);
339 const Dali::RefObject& handle = obj.GetImplementation();
340 return static_cast<const Dali::Scene3D::Internal::SceneView&>(handle);
343 } // namespace Scene3D
347 #endif // DALI_SCENE3D_INTERNAL_SCENE_VIEW_H