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/public-api/controls/model/model.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 a Model.
100 * Some works like ibl setting should be applied on the only Model not the all child actors.
101 * SceneView contains child Model list to apply the works effectively.
103 * @param[in] model Model to be registered.
105 void RegisterModel(Scene3D::Model model);
108 * @brief Unregister a Model
110 * @param[in] model Model to be unregistered.
112 void UnregisterModel(Scene3D::Model model);
115 * @copydoc SceneView::SetImageBasedLightSource()
117 void SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor);
120 * @copydoc SceneView::SetImageBasedLightScaleFactor()
122 void SetImageBasedLightScaleFactor(float scaleFactor);
125 * @copydoc SceneView::GetImageBasedLightScaleFactor()
127 float GetImageBasedLightScaleFactor() const;
130 * @copydoc SceneView::UseFramebuffer()
132 void UseFramebuffer(bool useFramebuffer);
135 * @copydoc SceneView::IsUsingFramebuffer()
137 bool IsUsingFramebuffer() const;
141 * @brief Constructs a new SceneView.
146 * A reference counted object may only be deleted by calling Unreference()
148 virtual ~SceneView();
152 * @copydoc CustomActorImpl::OnSceneConnection()
154 void OnSceneConnection(int depth) override;
157 * @copydoc CustomActorImpl::OnSceneDisconnection()
159 void OnSceneDisconnection() override;
162 * @copydoc Toolkit::Control::OnInitialize()
164 void OnInitialize() override;
167 * @copydoc Toolkit::Control::OnChildAdd()
169 void OnChildAdd(Actor& child) override;
172 * @copydoc Toolkit::Control::OnChildRemove()
174 void OnChildRemove(Actor& child) override;
177 * @copydoc Toolkit::Control::GetHeightForWidth()
179 float GetHeightForWidth(float width) override;
182 * @copydoc Toolkit::Control::GetWidthForHeight()
184 float GetWidthForHeight(float height) override;
187 * @copydoc Toolkit::Control::OnRelayout()
189 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
192 * @copydoc Toolkit::Control::IsResourceReady()
194 bool IsResourceReady() const override;
197 * @brief Changes main camera as a input camera
199 * @param camera CameraActor that will be a main camera of the SceneView
201 void UpdateCamera(CameraActor camera);
204 * @brief Updates RenderTask to use selected camera and to make framebuffer
206 void UpdateRenderTask();
209 * @brief Loads image based light from file.
211 void LoadImageBasedLight();
214 * @brief Asynchronously loading finished.
216 void OnLoadComplete();
219 * @brief Callback that will be called when window is resized.
221 void OnWindowResized(Window window, Window::WindowSize size);
224 * @brief Update camera's projection orientation according to the screen orientation.
229 Toolkit::Visual::Base mVisual;
231 /////////////////////////////////////////////////////////////
232 // FrameBuffer and Rendertask to render child objects as a 3D Scene
233 CameraActor mDefaultCamera;
234 CameraActor mSelectedCamera;
235 std::vector<CameraActor> mCameras;
236 std::vector<Scene3D::Model> mModels;
237 Dali::FrameBuffer mRenderTarget;
238 Dali::Texture mTexture;
239 Dali::RenderTask mRenderTask;
241 CallbackBase* mIblLoadedCallback;
242 std::string mDiffuseIblUrl;
243 std::string mSpecularIblUrl;
244 int32_t mScreenOrientation;
247 Dali::Texture mSpecularTexture;
248 Dali::Texture mDiffuseTexture;
249 float mIblScaleFactor{1.0f};
250 bool mUseFrameBuffer{false};
251 bool mIBLResourceReady{true};
253 // TODO : Light Source
256 } // namespace Internal
258 // Helpers for public-api forwarding methods
259 inline Dali::Scene3D::Internal::SceneView& GetImpl(Dali::Scene3D::SceneView& obj)
261 DALI_ASSERT_ALWAYS(obj);
262 Dali::RefObject& handle = obj.GetImplementation();
263 return static_cast<Dali::Scene3D::Internal::SceneView&>(handle);
266 inline const Dali::Scene3D::Internal::SceneView& GetImpl(const Dali::Scene3D::SceneView& obj)
268 DALI_ASSERT_ALWAYS(obj);
269 const Dali::RefObject& handle = obj.GetImplementation();
270 return static_cast<const Dali::Scene3D::Internal::SceneView&>(handle);
273 } // namespace Scene3D
277 #endif // DALI_SCENE3D_INTERNAL_SCENE_VIEW_H