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/public-api/controls/model/model.h>
30 #include <dali-scene3d/public-api/controls/scene-view/scene-view.h>
31 #include <dali-scene3d/internal/common/image-based-light-observer.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::SetImageBasedLightSource()
74 void SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor);
77 * @copydoc Model::SetImageBasedLightTexture()
79 void SetImageBasedLightTexture(Dali::Texture diffuseTexture, Dali::Texture specularTexture, float scaleFactor);
82 * @copydoc Model::SetImageBasedLightScaleFactor()
84 void SetImageBasedLightScaleFactor(float scaleFactor);
87 * @copydoc Model::GetImageBasedLightScaleFactor()
89 float GetImageBasedLightScaleFactor() const;
92 * @copydoc Model::GetAnimationCount()
94 uint32_t GetAnimationCount() const;
97 * @copydoc Model::GetAnimation()
99 Dali::Animation GetAnimation(uint32_t index) const;
102 * @copydoc Model::GetAnimation()
104 Dali::Animation GetAnimation(const std::string& name) const;
108 * @brief Constructs a new Model.
110 Model(const std::string& modelUrl, const std::string& resourceDirectoryUrl);
113 * A reference counted object may only be deleted by calling Unreference()
119 * @copydoc CustomActorImpl::OnSceneConnection()
121 void OnSceneConnection(int depth) override;
124 * @copydoc CustomActorImpl::OnSceneDisconnection()
126 void OnSceneDisconnection() override;
129 * @copydoc Toolkit::Control::GetNaturalSize
131 Vector3 GetNaturalSize() override;
134 * @copydoc Toolkit::Control::GetHeightForWidth()
136 float GetHeightForWidth(float width) override;
139 * @copydoc Toolkit::Control::GetWidthForHeight()
141 float GetWidthForHeight(float height) override;
144 * @copydoc Toolkit::Control::OnRelayout()
146 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
149 * @copydoc Toolkit::Control::IsResourceReady()
151 bool IsResourceReady() const override;
154 * @brief Loads a model from file
159 * @brief Scales the model to fit the control or to return to original size.
164 * @brief Changes model anchor point to set the model at center or returns to the original model pivot.
166 void FitModelPosition();
169 * @brief Changes IBL information of the input node.
171 void CollectRenderableActor(Actor actor);
174 * @brief Changes IBL textures of the input node.
176 void UpdateImageBasedLightTexture();
179 * @brief Changes IBL scale factor of the input node.
181 void UpdateImageBasedLightScaleFactor();
183 public: // Overrides ImageBasedLightObserver Methods.
186 * @copydoc Dali::Scene3D::Internal::ImageBasedLightObserver::NotifyImageBasedLightTexture()
188 void NotifyImageBasedLightTexture(Dali::Texture diffuseTexture, Dali::Texture specularTexture, float scaleFactor) override;
191 * @copydoc Dali::Scene3D::Internal::ImageBasedLightObserver::NotifyImageBasedLightScaleFactor()
193 void NotifyImageBasedLightScaleFactor(float scaleFactor) override;
196 std::string mModelUrl;
197 std::string mResourceDirectoryUrl;
198 Dali::Actor mModelRoot;
199 std::vector<AnimationData> mAnimations;
200 std::vector<WeakHandle<Actor>> mRenderableActors;
201 WeakHandle<Scene3D::SceneView> mParentSceneView;
203 // TODO: This default texture can be removed after 3D Resource Cache is added.
204 Dali::Texture mDefaultSpecularTexture;
205 Dali::Texture mDefaultDiffuseTexture;
206 Dali::Texture mSceneSpecularTexture;
207 Dali::Texture mSceneDiffuseTexture;
208 Dali::Texture mSpecularTexture;
209 Dali::Texture mDiffuseTexture;
210 Vector3 mNaturalSize;
212 float mSceneIblScaleFactor;
213 float mIblScaleFactor;
214 bool mModelChildrenSensitive;
215 bool mModelResourceReady;
216 bool mIBLResourceReady;
219 } // namespace Internal
221 // Helpers for public-api forwarding methods
222 inline Dali::Scene3D::Internal::Model& GetImpl(Dali::Scene3D::Model& obj)
224 DALI_ASSERT_ALWAYS(obj);
225 Dali::RefObject& handle = obj.GetImplementation();
226 return static_cast<Dali::Scene3D::Internal::Model&>(handle);
229 inline const Dali::Scene3D::Internal::Model& GetImpl(const Dali::Scene3D::Model& obj)
231 DALI_ASSERT_ALWAYS(obj);
232 const Dali::RefObject& handle = obj.GetImplementation();
233 return static_cast<const Dali::Scene3D::Internal::Model&>(handle);
236 } // namespace Scene3D
240 #endif // DALI_SCENE3D_INTERNAL_MODEL_H