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/image-based-light-observer.h>
30 #include <dali-scene3d/public-api/controls/model/model.h>
31 #include <dali-scene3d/public-api/controls/scene-view/scene-view.h>
42 * @brief Impl class for Model.
44 class Model : public Dali::Toolkit::Internal::Control, public ImageBasedLightObserver
47 using AnimationData = std::pair<std::string, Dali::Animation>;
50 * @brief Creates a new Model.
52 * @return A public handle to the newly allocated Model.
54 static Dali::Scene3D::Model New(const std::string& modelUrl, const std::string& resourceDirectoryUrl);
57 * @copydoc Model::GetModelRoot()
59 const Actor GetModelRoot() const;
62 * @copydoc Model::SetChildrenSensitive()
64 void SetChildrenSensitive(bool enable);
67 * @copydoc Model::GetChildrenSensitive()
69 bool GetChildrenSensitive() const;
72 * @copydoc Model::SetChildrenFocusable()
74 void SetChildrenFocusable(bool enable);
77 * @copydoc Model::GetChildrenFocusable()
79 bool GetChildrenFocusable() const;
82 * @copydoc Model::SetImageBasedLightSource()
84 void SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor);
87 * @copydoc Model::SetImageBasedLightTexture()
89 void SetImageBasedLightTexture(Dali::Texture diffuseTexture, Dali::Texture specularTexture, float scaleFactor);
92 * @copydoc Model::SetImageBasedLightScaleFactor()
94 void SetImageBasedLightScaleFactor(float scaleFactor);
97 * @copydoc Model::GetImageBasedLightScaleFactor()
99 float GetImageBasedLightScaleFactor() const;
102 * @copydoc Model::GetAnimationCount()
104 uint32_t GetAnimationCount() const;
107 * @copydoc Model::GetAnimation()
109 Dali::Animation GetAnimation(uint32_t index) const;
112 * @copydoc Model::GetAnimation()
114 Dali::Animation GetAnimation(const std::string& name) const;
118 * @brief Constructs a new Model.
120 Model(const std::string& modelUrl, const std::string& resourceDirectoryUrl);
123 * A reference counted object may only be deleted by calling Unreference()
129 * @copydoc Toolkit::Control::OnInitialize
134 * @copydoc CustomActorImpl::OnSceneConnection()
136 void OnSceneConnection(int depth) override;
139 * @copydoc CustomActorImpl::OnSceneDisconnection()
141 void OnSceneDisconnection() override;
144 * @copydoc Toolkit::Control::GetNaturalSize
146 Vector3 GetNaturalSize() override;
149 * @copydoc Toolkit::Control::GetHeightForWidth()
151 float GetHeightForWidth(float width) override;
154 * @copydoc Toolkit::Control::GetWidthForHeight()
156 float GetWidthForHeight(float height) override;
159 * @copydoc Toolkit::Control::OnRelayout()
161 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
164 * @copydoc Toolkit::Control::IsResourceReady()
166 bool IsResourceReady() const override;
169 * @brief Loads a model from file
174 * @brief Scales the model to fit the control or to return to original size.
179 * @brief Changes model anchor point to set the model at center or returns to the original model pivot.
181 void FitModelPosition();
184 * @brief Changes IBL information of the input node.
186 void CollectRenderableActor(Actor actor);
189 * @brief Changes IBL textures of the input node.
191 void UpdateImageBasedLightTexture();
194 * @brief Changes IBL scale factor of the input node.
196 void UpdateImageBasedLightScaleFactor();
198 public: // Overrides ImageBasedLightObserver Methods.
200 * @copydoc Dali::Scene3D::Internal::ImageBasedLightObserver::NotifyImageBasedLightTexture()
202 void NotifyImageBasedLightTexture(Dali::Texture diffuseTexture, Dali::Texture specularTexture, float scaleFactor) override;
205 * @copydoc Dali::Scene3D::Internal::ImageBasedLightObserver::NotifyImageBasedLightScaleFactor()
207 void NotifyImageBasedLightScaleFactor(float scaleFactor) override;
210 std::string mModelUrl;
211 std::string mResourceDirectoryUrl;
212 Dali::Actor mModelRoot;
213 std::vector<AnimationData> mAnimations;
214 std::vector<WeakHandle<Actor>> mRenderableActors;
215 WeakHandle<Scene3D::SceneView> mParentSceneView;
217 // TODO: This default texture can be removed after 3D Resource Cache is added.
218 Dali::Texture mDefaultSpecularTexture;
219 Dali::Texture mDefaultDiffuseTexture;
220 Dali::Texture mSceneSpecularTexture;
221 Dali::Texture mSceneDiffuseTexture;
222 Dali::Texture mSpecularTexture;
223 Dali::Texture mDiffuseTexture;
224 Vector3 mNaturalSize;
226 float mSceneIblScaleFactor;
227 float mIblScaleFactor;
228 bool mModelChildrenSensitive;
229 bool mModelChildrenFocusable;
230 bool mModelResourceReady;
231 bool mIBLResourceReady;
234 } // namespace Internal
236 // Helpers for public-api forwarding methods
237 inline Dali::Scene3D::Internal::Model& GetImpl(Dali::Scene3D::Model& obj)
239 DALI_ASSERT_ALWAYS(obj);
240 Dali::RefObject& handle = obj.GetImplementation();
241 return static_cast<Dali::Scene3D::Internal::Model&>(handle);
244 inline const Dali::Scene3D::Internal::Model& GetImpl(const Dali::Scene3D::Model& obj)
246 DALI_ASSERT_ALWAYS(obj);
247 const Dali::RefObject& handle = obj.GetImplementation();
248 return static_cast<const Dali::Scene3D::Internal::Model&>(handle);
251 } // namespace Scene3D
255 #endif // DALI_SCENE3D_INTERNAL_MODEL_H