Merge "Add log for font load validation" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / controls / model-view / model-view.h
1 #ifndef DALI_SCENE3D_MODEL_VIEW_H
2 #define DALI_SCENE3D_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 // INTERNAL INCLUDES
22 #include <dali-scene3d/public-api/api.h>
23
24 // EXTERNAL INCLUDES
25 #include <dali-toolkit/public-api/controls/control.h>
26 #include <dali/public-api/common/dali-common.h>
27
28 namespace Dali
29 {
30 namespace Scene3D
31 {
32 namespace Internal DALI_INTERNAL
33 {
34 class ModelView;
35 }
36
37 /**
38  * @addtogroup dali_toolkit_controls_model_view
39  * @{
40  */
41
42 /**
43  * @brief ModelView is a control to show 3D model objects.
44  * ModelView supports to load glTF 2.0 and DLI models for the input format
45  * and also supports Physically Based Rendering with Image Based Lighting.
46  *
47  * The Animations defined in the glTF or DLI models are also loaded and can be retrieved by using GetAnimation() method.
48  * The number of animation is also retrieved by GetAnimationCount() method.
49  *
50  * By default, The loaded model has it's own position and size which are defined in vertex buffer regardless of the Control size.
51  * The model can be resized and repositioned to fit to the ModelView Control with FitSize() and FitCenter() methods.
52  *
53  * @code
54  *
55  * ModelView modelView = ModelView::New(modelUrl);
56  * modelView.SetProperty(Dali::Actor::Property::SIZE, Vector2(width, height));
57  * modelView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
58  * modelView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
59  * modelView.SetImageBasedLightSource(diffuseUrl, specularUrl, scaleFactor);
60  * modelView.FitSize(true);
61  * modelView.FitCenter(true);
62  * window.Add(modelView);
63  * uint32_t animationCount = modelView.GetAnimationCount();
64  * Dali::Animation animation = modelView.GetAnimation(0);
65  * animation.Play();
66  *
67  * @endcode
68  */
69 class DALI_SCENE3D_API ModelView : public Dali::Toolkit::Control
70 {
71 public:
72   /**
73    * @brief Create an initialized ModelView.
74    * @param[in] modelPath model file path.(e.g., glTF, and DLI).
75    * @param[in] resourcePath resource file path that includes binary, image etc.
76    * @note If resourcePath is empty, the parent directory path of modelPath is used for resource path.
77    * @return A handle to a newly allocated Dali resource
78    */
79   static ModelView New(const std::string& modelPath, const std::string& resourcePath = std::string());
80
81   /**
82    * @brief Creates an uninitialized ModelView.
83    *
84    * Only derived versions can be instantiated. Calling member
85    * functions with an uninitialized Dali::Object is not allowed.
86    */
87   ModelView();
88
89   /**
90    * @brief Destructor.
91    *
92    * This is non-virtual since derived Handle types must not contain data or virtual methods.
93    */
94   ~ModelView();
95
96   /**
97    * @brief Copy constructor.
98    * @param[in] modelView Handle to an object
99    */
100   ModelView(const ModelView& modelView);
101
102   /**
103    * @brief Move constructor
104    *
105    * @param[in] rhs A reference to the moved handle
106    */
107   ModelView(ModelView&& rhs);
108
109   /**
110    * @brief Assignment operator.
111    * @param[in] modelView Handle to an object
112    * @return reference to this
113    */
114   ModelView& operator=(const ModelView& modelView);
115
116   /**
117    * @brief Move assignment
118    *
119    * @param[in] rhs A reference to the moved handle
120    * @return A reference to this
121    */
122   ModelView& operator=(ModelView&& rhs);
123
124   /**
125    * @brief Downcasts an Object handle to ModelView.
126    *
127    * If handle points to a ModelView, the downcast produces valid handle.
128    * If not, the returned handle is left uninitialized.
129    *
130    * @param[in] handle Handle to an object
131    * @return Handle to a ModelView or an uninitialized handle
132    */
133   static ModelView DownCast(BaseHandle handle);
134
135   /**
136    * @brief Retrieves model root Actor.
137    * @return Root Actor of the model.
138    */
139   const Actor GetModelRoot();
140
141   /**
142    * @brief Fits the model to the Control size.
143    * @param[in] fit true to fit model size to control.
144    * @note This method makes model fit to the Control size by keeping original model ratio.
145    * It means If model size is (2, 2, 2) and ModelView size is (10, 8), then the model become looks (8, 8, 8).
146    * If ModelView Size x or y is 0, this method don't work anything.
147    * If ModelView Size z is 0, this method considers only x and y values of ModelView Size.
148    */
149   void FitSize(bool fit);
150
151   /**
152    * @brief Moves the model to the center of control.
153    * @param[in] fit true to fit model to center of control.
154    * @note This method doesn't changes size of model.
155    */
156   void FitCenter(bool fit);
157
158   /**
159    * @brief Changes Image Based Light as the input textures.
160    * @param[in] diffuse cube map that can be used as a diffuse IBL source.
161    * @param[in] specular cube map that can be used as a specular IBL source.
162    * @param[in] scaleFactor scale factor that controls light source intensity in [0.0f, 1.0f]. Default value is 1.0f.
163    */
164   void SetImageBasedLightSource(const std::string& diffuse, const std::string& specular, float scaleFactor = 1.0f);
165
166   /**
167    * @brief Gets number of animations those loaded from model file.
168    * @return The number of loaded animations.
169    * @note This method should be called after Model load finished.
170    */
171   uint32_t GetAnimationCount();
172
173   /**
174    * @brief Gets animation at the index.
175    * @param[in] index Index of animation to be retrieved.
176    * @return Animation at the index.
177    * @note This method should be called after Model load finished.
178    */
179   Dali::Animation GetAnimation(uint32_t index);
180
181   /**
182    * @brief Retrieves animation with the given name.
183    * @param[in] name string name of animation to be retrieved.
184    * @return Animation that has the given name.
185    * @note This method should be called after Model load finished.
186    */
187   Dali::Animation GetAnimation(const std::string& name);
188
189 public: // Not intended for application developers
190   /// @cond internal
191   /**
192    * @brief Creates a handle using the Toolkit::Internal implementation.
193    *
194    * @param[in] implementation The Control implementation
195    */
196   DALI_INTERNAL ModelView(Internal::ModelView& implementation);
197
198   /**
199    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
200    *
201    * @param[in] internal A pointer to the internal CustomActor
202    */
203   DALI_INTERNAL ModelView(Dali::Internal::CustomActor* internal);
204   /// @endcond
205 };
206
207 /**
208  * @}
209  */
210 } // namespace Scene3D
211
212 } // namespace Dali
213
214 #endif // DALI_SCENE3D_MODEL_VIEW_H