ModelView using scene-loader
[platform/core/uifw/dali-toolkit.git] / dali-scene-loader / internal / controls / model-view / model-view-impl.h
1 #ifndef DALI_SCENE_LOADER_INTERNAL_MODEL_VIEW_H
2 #define DALI_SCENE_LOADER_INTERNAL_MODEL_VIEW_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/actors/layer.h>
23 #include <dali/public-api/animation/animation.h>
24 #include <dali/public-api/rendering/texture.h>
25 #include <dali-toolkit/public-api/controls/control-impl.h>
26
27 // INTERNAL INCLUDES
28 #include <dali-scene-loader/public-api/controls/model-view/model-view.h>
29
30 namespace Dali
31 {
32 namespace Scene3D
33 {
34 class ModelView;
35
36 namespace Internal
37 {
38 /**
39  * @brief Impl class for ModelView.
40  */
41 class ModelView : public Dali::Toolkit::Internal::Control
42 {
43 public:
44   using AnimationData = std::pair<std::string, Dali::Animation>;
45
46   /**
47    * @brief Creates a new ModelView.
48    *
49    * @return A public handle to the newly allocated ModelView.
50    */
51   static Dali::Scene3D::ModelView New(const std::string& modelPath, const std::string& resourcePath);
52
53   /**
54    * @copydoc ModelView::GetModelRoot()
55    */
56   const Actor GetModelRoot();
57
58   /**
59    * @copydoc ModelView::FitModel()
60    */
61   void FitSize(bool fit);
62
63   /**
64    * @copydoc ModelView::FitCenter()
65    */
66   void FitCenter(bool fit);
67
68   /**
69    * @copydoc ModelView::SetImageBasedLightSource()
70    */
71   void SetImageBasedLightSource(const std::string& diffuse, const std::string& specular, float scaleFactor);
72
73   /**
74    * @copydoc ModelView::GetAnimationCount()
75    */
76   uint32_t GetAnimationCount();
77
78   /**
79    * @copydoc ModelView::GetAnimation()
80    */
81   Dali::Animation GetAnimation(uint32_t index);
82
83   /**
84    * @copydoc ModelView::GetAnimation()
85    */
86   Dali::Animation GetAnimation(const std::string& name);
87
88 protected:
89   /**
90    * @brief Constructs a new ModelView.
91    */
92   ModelView(const std::string& modelPath, const std::string& resourcePath);
93
94   /**
95    * A reference counted object may only be deleted by calling Unreference()
96    */
97   virtual ~ModelView();
98
99 private:
100   /**
101    * @copydoc CustomActorImpl::OnSceneConnection()
102    */
103   void OnSceneConnection(int depth) override;
104
105   /**
106    * @copydoc Toolkit::Control::OnInitialize()
107    */
108   void OnInitialize() override;
109
110   /**
111    * @copydoc Toolkit::Control::GetNaturalSize
112    */
113   Vector3 GetNaturalSize() override;
114
115   /**
116    * @copydoc Toolkit::Control::GetHeightForWidth()
117    */
118   float GetHeightForWidth(float width) override;
119
120   /**
121    * @copydoc Toolkit::Control::GetWidthForHeight()
122    */
123   float GetWidthForHeight(float height) override;
124
125   /**
126    * @copydoc Toolkit::Control::OnRelayout()
127    */
128   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
129
130   /**
131    * @brief Loads a model from file
132    */
133   void LoadModel();
134
135   /**
136    * @brief Scales the model to fit the control or to return to original size.
137    */
138   void ScaleModel();
139
140   /**
141    * @brief Changes model anchor point to set the model at center or returns to the original model pivot.
142    */
143   void FitModelPosition();
144
145   /**
146    * @brief Changes IBL information of the input node.
147    */
148   void SetImageBasedLight(Actor node);
149
150 private:
151   std::string                  mModelPath;
152   std::string                  mResourcePath;
153   Dali::Layer                  mModelLayer;
154   Dali::Actor                  mModelRoot;
155   std::vector<AnimationData>   mAnimations;
156
157   Dali::Texture    mSpecularTexture;
158   Dali::Texture    mDiffuseTexture;
159   Vector3          mNaturalSize;
160   Vector3          mModelPivot;
161   float            mIblScaleFactor;
162   bool             mFitSize;
163   bool             mFitCenter;
164 };
165
166 } // namespace Internal
167
168 // Helpers for public-api forwarding methods
169 inline Dali::Scene3D::Internal::ModelView& GetImpl(Dali::Scene3D::ModelView& obj)
170 {
171   DALI_ASSERT_ALWAYS(obj);
172   Dali::RefObject& handle = obj.GetImplementation();
173   return static_cast<Dali::Scene3D::Internal::ModelView&>(handle);
174 }
175
176 inline const Dali::Scene3D::Internal::ModelView& GetImpl(const Dali::Scene3D::ModelView& obj)
177 {
178   DALI_ASSERT_ALWAYS(obj);
179   const Dali::RefObject& handle = obj.GetImplementation();
180   return static_cast<const Dali::Scene3D::Internal::ModelView&>(handle);
181 }
182
183 } // namespace Toolkit
184
185 } // namespace Dali
186
187 #endif // DALI_SCENE_LOADER_INTERNAL_MODEL_VIEW_H