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