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