1 #ifndef DALI_SCENE3D_INTERNAL_MODEL_VIEW_H
2 #define DALI_SCENE3D_INTERNAL_MODEL_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/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/rendering/texture.h>
26 #include <dali/public-api/object/weak-handle.h>
29 #include <dali-scene3d/public-api/controls/model-view/model-view.h>
30 #include <dali-scene3d/public-api/controls/scene-view/scene-view.h>
41 * @brief Impl class for ModelView.
43 class ModelView : public Dali::Toolkit::Internal::Control
46 using AnimationData = std::pair<std::string, Dali::Animation>;
49 * @brief Creates a new ModelView.
51 * @return A public handle to the newly allocated ModelView.
53 static Dali::Scene3D::ModelView New(const std::string& modelPath, const std::string& resourcePath);
56 * @copydoc ModelView::GetModelRoot()
58 const Actor GetModelRoot();
61 * @copydoc ModelView::FitModel()
63 void FitSize(bool fit);
66 * @copydoc ModelView::FitCenter()
68 void FitCenter(bool fit);
71 * @copydoc ModelView::SetImageBasedLightSource()
73 void SetImageBasedLightSource(const std::string& diffuse, const std::string& specular, float scaleFactor);
76 * @copydoc ModelView::SetImageBasedLightTexture()
78 void SetImageBasedLightTexture(Dali::Texture diffuse, Dali::Texture specular, float scaleFactor);
81 * @copydoc ModelView::GetAnimationCount()
83 uint32_t GetAnimationCount();
86 * @copydoc ModelView::GetAnimation()
88 Dali::Animation GetAnimation(uint32_t index);
91 * @copydoc ModelView::GetAnimation()
93 Dali::Animation GetAnimation(const std::string& name);
97 * @brief Constructs a new ModelView.
99 ModelView(const std::string& modelPath, const std::string& resourcePath);
102 * A reference counted object may only be deleted by calling Unreference()
104 virtual ~ModelView();
108 * @copydoc CustomActorImpl::OnSceneConnection()
110 void OnSceneConnection(int depth) override;
113 * @copydoc CustomActorImpl::OnSceneDisconnection()
115 void OnSceneDisconnection() override;
118 * @copydoc Toolkit::Control::GetNaturalSize
120 Vector3 GetNaturalSize() override;
123 * @copydoc Toolkit::Control::GetHeightForWidth()
125 float GetHeightForWidth(float width) override;
128 * @copydoc Toolkit::Control::GetWidthForHeight()
130 float GetWidthForHeight(float height) override;
133 * @copydoc Toolkit::Control::OnRelayout()
135 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
138 * @copydoc Toolkit::Control::IsResourceReady()
140 bool IsResourceReady() const override;
143 * @brief Loads a model from file
148 * @brief Scales the model to fit the control or to return to original size.
153 * @brief Changes model anchor point to set the model at center or returns to the original model pivot.
155 void FitModelPosition();
158 * @brief Changes IBL information of the input node.
160 void CollectRenderableActor(Actor actor);
163 * @brief Changes IBL information of the input node.
165 void UpdateImageBasedLight();
168 std::string mModelPath;
169 std::string mResourcePath;
170 Dali::Actor mModelRoot;
171 std::vector<AnimationData> mAnimations;
172 std::vector<WeakHandle<Actor>> mRenderableActors;
173 WeakHandle<Scene3D::SceneView> mParentSceneView;
175 Dali::Texture mSpecularTexture;
176 Dali::Texture mDiffuseTexture;
177 Vector3 mNaturalSize;
179 float mIblScaleFactor;
182 bool mModelResourceReady;
183 bool mIBLResourceReady;
186 } // namespace Internal
188 // Helpers for public-api forwarding methods
189 inline Dali::Scene3D::Internal::ModelView& GetImpl(Dali::Scene3D::ModelView& obj)
191 DALI_ASSERT_ALWAYS(obj);
192 Dali::RefObject& handle = obj.GetImplementation();
193 return static_cast<Dali::Scene3D::Internal::ModelView&>(handle);
196 inline const Dali::Scene3D::Internal::ModelView& GetImpl(const Dali::Scene3D::ModelView& obj)
198 DALI_ASSERT_ALWAYS(obj);
199 const Dali::RefObject& handle = obj.GetImplementation();
200 return static_cast<const Dali::Scene3D::Internal::ModelView&>(handle);
203 } // namespace Scene3D
207 #endif // DALI_SCENE3D_INTERNAL_MODEL_VIEW_H