1 #ifndef DALI_SCENE3D_INTERNAL_SCENE_VIEW_H
2 #define DALI_SCENE3D_INTERNAL_SCENE_VIEW_H
5 * Copyright (c) 2022 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/image-based-light-observer.h>
35 #include <dali-scene3d/public-api/controls/scene-view/scene-view.h>
46 * @brief Impl class for SceneView.
48 class SceneView : public Dali::Toolkit::Internal::Control
52 * @brief Creates a new SceneView.
54 * @return A public handle to the newly allocated SceneView.
56 static Dali::Scene3D::SceneView New();
59 * @copydoc SceneView::AddCamera()
61 void AddCamera(Dali::CameraActor camera);
64 * @copydoc SceneView::RemoveCamera()
66 void RemoveCamera(CameraActor camera);
69 * @copydoc SceneView::GetCameraCount()
71 uint32_t GetCameraCount() const;
74 * @copydoc SceneView::GetSelectedCamera()
76 CameraActor GetSelectedCamera() const;
79 * @copydoc SceneView::GetCamera()
81 CameraActor GetCamera(uint32_t index) const;
84 * @copydoc SceneView::GetCamera()
86 CameraActor GetCamera(const std::string& name) const;
89 * @copydoc SceneView::SelectCamera()
91 void SelectCamera(uint32_t index);
94 * @copydoc SceneView::SelectCamera()
96 void SelectCamera(const std::string& name);
99 * @brief Register an item.
101 * Some works(e.g, lighting) of SceneView should be propagated to the child 3D items.
102 * SceneView can avoid unnecessary tree traversal to find 3D items by storing only 3D items as a list.
104 * @param[in] item scene observer to be registered.
106 void RegisterSceneItem(Scene3D::Internal::ImageBasedLightObserver* item);
109 * @brief Unregister an item
111 * @param[in] item scene observer to be unregistered.
113 void UnregisterSceneItem(Scene3D::Internal::ImageBasedLightObserver* item);
116 * @copydoc SceneView::SetImageBasedLightSource()
118 void SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor);
121 * @copydoc SceneView::SetImageBasedLightScaleFactor()
123 void SetImageBasedLightScaleFactor(float scaleFactor);
126 * @copydoc SceneView::GetImageBasedLightScaleFactor()
128 float GetImageBasedLightScaleFactor() const;
131 * @copydoc SceneView::UseFramebuffer()
133 void UseFramebuffer(bool useFramebuffer);
136 * @copydoc SceneView::IsUsingFramebuffer()
138 bool IsUsingFramebuffer() const;
141 * @copydoc SceneView::SetSkybox()
143 void SetSkybox(const std::string& skyboxUrl);
146 * @copydoc SceneView::SetSkyboxIntensity()
148 void SetSkyboxIntensity(float intensity);
151 * @copydoc SceneView::GetSkyboxIntensity()
153 float GetSkyboxIntensity() const;
156 * @copydoc SceneView::SetSkyboxOrientation()
158 void SetSkyboxOrientation(const Quaternion& orientation);
161 * @copydoc SceneView::GetSkyboxOrientation()
163 Quaternion GetSkyboxOrientation() const;
167 * @brief Constructs a new SceneView.
172 * A reference counted object may only be deleted by calling Unreference()
174 virtual ~SceneView();
178 * @copydoc CustomActorImpl::OnSceneConnection()
180 void OnSceneConnection(int depth) override;
183 * @copydoc CustomActorImpl::OnSceneDisconnection()
185 void OnSceneDisconnection() override;
188 * @copydoc Toolkit::Control::OnInitialize()
190 void OnInitialize() override;
193 * @copydoc Toolkit::Control::OnChildAdd()
195 void OnChildAdd(Actor& child) override;
198 * @copydoc Toolkit::Control::OnChildRemove()
200 void OnChildRemove(Actor& child) override;
203 * @copydoc Toolkit::Control::GetHeightForWidth()
205 float GetHeightForWidth(float width) override;
208 * @copydoc Toolkit::Control::GetWidthForHeight()
210 float GetWidthForHeight(float height) override;
213 * @copydoc Toolkit::Control::OnRelayout()
215 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
218 * @copydoc Toolkit::Control::IsResourceReady()
220 bool IsResourceReady() const override;
223 * @brief Changes main camera as a input camera
225 * @param camera CameraActor that will be a main camera of the SceneView
227 void UpdateCamera(CameraActor camera);
230 * @brief Updates RenderTask to use selected camera and to make framebuffer
232 void UpdateRenderTask();
235 * @brief Callback that will be called when window is resized.
237 void OnWindowResized(Window window, Window::WindowSize size);
240 * @brief Updates camera's projection orientation according to the screen orientation.
245 Toolkit::Visual::Base mVisual;
247 /////////////////////////////////////////////////////////////
248 // FrameBuffer and Rendertask to render child objects as a 3D Scene
249 Dali::WeakHandle<Dali::Window> mWindow;
250 CameraActor mDefaultCamera;
251 CameraActor mSelectedCamera;
252 std::vector<CameraActor> mCameras;
253 std::vector<Scene3D::Internal::ImageBasedLightObserver*> mItems;
254 Dali::FrameBuffer mFrameBuffer;
255 Dali::Texture mTexture;
256 Dali::RenderTask mRenderTask;
258 int32_t mWindowOrientation;
260 Quaternion mSkyboxOrientation;
261 float mSkyboxIntensity{1.0f};
263 Dali::Texture mSpecularTexture;
264 Dali::Texture mDiffuseTexture;
265 float mIblScaleFactor{1.0f};
266 bool mUseFrameBuffer{false};
267 bool mIBLResourceReady{true};
268 bool mSkyboxResourceReady{true};
270 // TODO : Light Source
273 } // namespace Internal
275 // Helpers for public-api forwarding methods
276 inline Dali::Scene3D::Internal::SceneView& GetImpl(Dali::Scene3D::SceneView& obj)
278 DALI_ASSERT_ALWAYS(obj);
279 Dali::RefObject& handle = obj.GetImplementation();
280 return static_cast<Dali::Scene3D::Internal::SceneView&>(handle);
283 inline const Dali::Scene3D::Internal::SceneView& GetImpl(const Dali::Scene3D::SceneView& obj)
285 DALI_ASSERT_ALWAYS(obj);
286 const Dali::RefObject& handle = obj.GetImplementation();
287 return static_cast<const Dali::Scene3D::Internal::SceneView&>(handle);
290 } // namespace Scene3D
294 #endif // DALI_SCENE3D_INTERNAL_SCENE_VIEW_H