1 #ifndef DALI_SCENE3D_INTERNAL_MODEL_H
2 #define DALI_SCENE3D_INTERNAL_MODEL_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/public-api/controls/control-impl.h>
23 #include <dali/public-api/actors/layer.h>
24 #include <dali/public-api/animation/animation.h>
25 #include <dali/public-api/object/weak-handle.h>
26 #include <dali/public-api/rendering/texture.h>
29 #include <dali-scene3d/internal/common/environment-map-load-task.h>
30 #include <dali-scene3d/internal/common/image-based-light-observer.h>
31 #include <dali-scene3d/internal/common/model-load-task.h>
32 #include <dali-scene3d/public-api/controls/model/model.h>
33 #include <dali-scene3d/public-api/controls/scene-view/scene-view.h>
44 * @brief Impl class for Model.
46 class Model : public Dali::Toolkit::Internal::Control, public ImageBasedLightObserver
49 using AnimationData = std::pair<std::string, Dali::Animation>;
52 * @brief Creates a new Model.
54 * @return A public handle to the newly allocated Model.
56 static Dali::Scene3D::Model New(const std::string& modelUrl, const std::string& resourceDirectoryUrl);
59 * @copydoc Model::GetModelRoot()
61 const Actor GetModelRoot() const;
64 * @copydoc Model::SetChildrenSensitive()
66 void SetChildrenSensitive(bool enable);
69 * @copydoc Model::GetChildrenSensitive()
71 bool GetChildrenSensitive() const;
74 * @copydoc Model::SetChildrenFocusable()
76 void SetChildrenFocusable(bool enable);
79 * @copydoc Model::GetChildrenFocusable()
81 bool GetChildrenFocusable() const;
84 * @copydoc Model::SetImageBasedLightSource()
86 void SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor);
89 * @copydoc Model::SetImageBasedLightTexture()
91 void SetImageBasedLightTexture(Dali::Texture diffuseTexture, Dali::Texture specularTexture, float scaleFactor);
94 * @copydoc Model::SetImageBasedLightScaleFactor()
96 void SetImageBasedLightScaleFactor(float scaleFactor);
99 * @copydoc Model::GetImageBasedLightScaleFactor()
101 float GetImageBasedLightScaleFactor() const;
104 * @copydoc Model::GetAnimationCount()
106 uint32_t GetAnimationCount() const;
109 * @copydoc Model::GetAnimation()
111 Dali::Animation GetAnimation(uint32_t index) const;
114 * @copydoc Model::GetAnimation()
116 Dali::Animation GetAnimation(const std::string& name) const;
120 * @brief Constructs a new Model.
122 Model(const std::string& modelUrl, const std::string& resourceDirectoryUrl);
125 * A reference counted object may only be deleted by calling Unreference()
131 * @copydoc Toolkit::Control::OnInitialize
136 * @copydoc CustomActorImpl::OnSceneConnection()
138 void OnSceneConnection(int depth) override;
141 * @copydoc CustomActorImpl::OnSceneDisconnection()
143 void OnSceneDisconnection() override;
146 * @copydoc Toolkit::Control::GetNaturalSize
148 Vector3 GetNaturalSize() override;
151 * @copydoc Toolkit::Control::GetHeightForWidth()
153 float GetHeightForWidth(float width) override;
156 * @copydoc Toolkit::Control::GetWidthForHeight()
158 float GetWidthForHeight(float height) override;
161 * @copydoc Toolkit::Control::OnRelayout()
163 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
166 * @copydoc Toolkit::Control::IsResourceReady()
168 bool IsResourceReady() const override;
171 * @brief Scales the model to fit the control or to return to original size.
176 * @brief Changes model anchor point to set the model at center or returns to the original model pivot.
178 void FitModelPosition();
181 * @brief Changes IBL information of the input node.
183 void CollectRenderableActor(Actor actor);
186 * @brief Changes IBL textures of the input node.
188 void UpdateImageBasedLightTexture();
191 * @brief Changes IBL scale factor of the input node.
193 void UpdateImageBasedLightScaleFactor();
195 public: // Overrides ImageBasedLightObserver Methods.
197 * @copydoc Dali::Scene3D::Internal::ImageBasedLightObserver::NotifyImageBasedLightTexture()
199 void NotifyImageBasedLightTexture(Dali::Texture diffuseTexture, Dali::Texture specularTexture, float scaleFactor) override;
202 * @copydoc Dali::Scene3D::Internal::ImageBasedLightObserver::NotifyImageBasedLightScaleFactor()
204 void NotifyImageBasedLightScaleFactor(float scaleFactor) override;
208 * @brief Asynchronously model loading finished.
210 void OnModelLoadComplete();
213 * @brief Asynchronously ibl diffusel image loading finished.
215 void OnIblDiffuseLoadComplete();
218 * @brief Asynchronously ibl specular image loading finished.
220 void OnIblSpecularLoadComplete();
223 * @brief Asynchronously ibl loading finished.
225 void OnIblLoadComplete();
228 * @brief Reset Resource loading tasks.
230 void ResetResourceTasks();
233 std::string mModelUrl;
234 std::string mResourceDirectoryUrl;
235 Dali::Actor mModelRoot;
236 std::vector<AnimationData> mAnimations;
237 std::vector<WeakHandle<Actor>> mRenderableActors;
238 WeakHandle<Scene3D::SceneView> mParentSceneView;
240 // Asynchronous loading variable
241 ModelLoadTaskPtr mModelLoadTask;
242 EnvironmentMapLoadTaskPtr mIblDiffuseLoadTask;
243 EnvironmentMapLoadTaskPtr mIblSpecularLoadTask;
245 std::string mDiffuseIblUrl;
246 std::string mSpecularIblUrl;
248 // TODO: This default texture can be removed after 3D Resource Cache is added.
249 Dali::Texture mDefaultSpecularTexture;
250 Dali::Texture mDefaultDiffuseTexture;
251 Dali::Texture mSceneSpecularTexture;
252 Dali::Texture mSceneDiffuseTexture;
253 Dali::Texture mSpecularTexture;
254 Dali::Texture mDiffuseTexture;
255 Vector3 mNaturalSize;
257 float mSceneIblScaleFactor;
258 float mIblScaleFactor;
259 bool mModelChildrenSensitive;
260 bool mModelChildrenFocusable;
261 bool mModelResourceReady;
262 bool mIblDiffuseResourceReady;
263 bool mIblSpecularResourceReady;
264 bool mIblDiffuseDirty;
265 bool mIblSpecularDirty;
268 } // namespace Internal
270 // Helpers for public-api forwarding methods
271 inline Dali::Scene3D::Internal::Model& GetImpl(Dali::Scene3D::Model& obj)
273 DALI_ASSERT_ALWAYS(obj);
274 Dali::RefObject& handle = obj.GetImplementation();
275 return static_cast<Dali::Scene3D::Internal::Model&>(handle);
278 inline const Dali::Scene3D::Internal::Model& GetImpl(const Dali::Scene3D::Model& obj)
280 DALI_ASSERT_ALWAYS(obj);
281 const Dali::RefObject& handle = obj.GetImplementation();
282 return static_cast<const Dali::Scene3D::Internal::Model&>(handle);
285 } // namespace Scene3D
289 #endif // DALI_SCENE3D_INTERNAL_MODEL_H