1 #ifndef DALI_SCENE3D_MODEL_H
2 #define DALI_SCENE3D_MODEL_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-scene3d/public-api/api.h>
25 #include <dali-toolkit/public-api/controls/control.h>
26 #include <dali/public-api/common/dali-common.h>
27 #include <dali/public-api/rendering/texture.h>
33 namespace Internal DALI_INTERNAL
39 * @addtogroup dali_toolkit_controls_model
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.
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.
51 * By default, The loaded model has its own position and size which are defined in vertex buffer regardless of the Control size.
56 * Model model = Model::New(modelUrl);
57 * model.SetProperty(Dali::Actor::Property::SIZE, Vector2(width, height));
58 * model.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
59 * model.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
60 * model.SetImageBasedLightSource(diffuseUrl, specularUrl, scaleFactor);
62 * uint32_t animationCount = model.GetAnimationCount();
63 * Dali::Animation animation = model.GetAnimation(0);
68 class DALI_SCENE3D_API Model : public Dali::Toolkit::Control
72 * @brief Create an initialized Model.
75 * @param[in] modelUrl model file path.(e.g., glTF, and DLI).
76 * @param[in] resourceDirectoryUrl resource file path that includes binary, image etc.
77 * @note If resourceDirectoryUrl is empty, the parent directory path of modelUrl is used for resource path.
78 * @return A handle to a newly allocated Dali resource
80 static Model New(const std::string& modelUrl, const std::string& resourceDirectoryUrl = std::string());
83 * @brief Creates an uninitialized Model.
85 * Only derived versions can be instantiated. Calling member
86 * functions with an uninitialized Dali::Object is not allowed.
95 * This is non-virtual since derived Handle types must not contain data or virtual methods.
102 * @brief Copy constructor.
105 * @param[in] model Handle to an object
107 Model(const Model& model);
110 * @brief Move constructor
113 * @param[in] rhs A reference to the moved handle
118 * @brief Assignment operator.
121 * @param[in] model Handle to an object
122 * @return reference to this
124 Model& operator=(const Model& model);
127 * @brief Move assignment
130 * @param[in] rhs A reference to the moved handle
131 * @return A reference to this
133 Model& operator=(Model&& rhs);
136 * @brief Downcasts an Object handle to Model.
138 * If handle points to a Model, the downcast produces valid handle.
139 * If not, the returned handle is left uninitialized.
142 * @param[in] handle Handle to an object
143 * @return Handle to a Model or an uninitialized handle
145 static Model DownCast(BaseHandle handle);
148 * @brief Retrieves model root Actor.
151 * @return Root Actor of the model.
153 const Actor GetModelRoot() const;
156 * @brief Whether allow this model's children actor to use events.
158 * Usually, 3D Model might have a lot of actors. And most of them don't need to check events.
159 * To optimize traversal, we need to setup some flag that this model don't allow (or allow) to traversal
160 * children so that child can use events.
163 * @note Even if we set children sensitive as false, model itself's sensitive
164 * is depend on it's property.
165 * @note If we don't call this API, default is false. (Don't allow to traversal model's children during hit-test)
167 * @param[in] enable True to enable model's children can use events.
169 void SetChildrenSensitive(bool enable);
172 * @brief Gets whether this Model allow model's children actor to use events or not.
175 * @return bool True if this Model allow model children sensitive.
177 bool GetChildrenSensitive() const;
180 * @brief Whether allow this model's children actor to be keyboard focusable.
182 * Usually, 3D Model might have a lot of actors. And most of them don't need to check focusable.
183 * To optimize traversal, we need to setup some flag that this model don't allow (or allow) to traversal
184 * children so that child can be keyboard focusable.
187 * @note Even if we set children focusable as false, model itself's focusable
188 * is depend on it's property.
189 * @note If we don't call this API, default is false. (Don't allow to traversal model's children during focusable test)
191 * @param[in] enable True to enable model's children can be focusable.
193 void SetChildrenFocusable(bool enable);
196 * @brief Gets whether this Model allow model's children actor to be keyboard focusable or not.
199 * @return bool True if this Model allow model children are focusable.
201 bool GetChildrenFocusable() const;
204 * @brief Changes Image Based Light as the input textures.
207 * @param[in] diffuseUrl cube map that can be used as a diffuse IBL source.
208 * @param[in] specularUrl cube map that can be used as a specular IBL source.
209 * @param[in] scaleFactor scale factor that controls light source intensity in [0.0f, 1.0f]. Default value is 1.0f.
211 void SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor = 1.0f);
214 * @brief Sets Image Based Light Texture.
217 * @param[in] diffuseTexture cube map texture that can be used as a diffuse IBL source.
218 * @param[in] specularTexture cube map texture that can be used as a specular IBL source.
219 * @param[in] scaleFactor scale factor that controls light source intensity in [0.0f, 1.0f]. Default value is 1.0f.
221 * @note Both of diffuse texture and specular texture should be available. If not, nothing applied.
223 void SetImageBasedLightTexture(Texture diffuseTexture, Texture specularTexture, float scaleFactor = 1.0f);
226 * @brief Sets Scale Factor of Image Based Light Source.
229 * @note If SetImageBasedLightSource() or SetImageBasedLightTexture() method is called after this method, scaleFactor is overrided.
231 * @param[in] scaleFactor scale factor that controls light source intensity in [0.0f, 1.0f].
233 void SetImageBasedLightScaleFactor(float scaleFactor);
236 * @brief Gets Scale Factor of Image Based Light Source.
237 * Default value is 1.0f.
240 * @return scale factor that controls light source intensity.
242 float GetImageBasedLightScaleFactor() const;
245 * @brief Gets number of animations those loaded from model file.
248 * @return The number of loaded animations.
249 * @note This method should be called after Model load finished.
251 uint32_t GetAnimationCount() const;
254 * @brief Gets animation at the index.
257 * @param[in] index Index of animation to be retrieved.
258 * @return Animation at the index.
259 * @note This method should be called after Model load finished.
261 Dali::Animation GetAnimation(uint32_t index) const;
264 * @brief Retrieves animation with the given name.
267 * @param[in] name string name of animation to be retrieved.
268 * @return Animation that has the given name.
269 * @note This method should be called after Model load finished.
271 Dali::Animation GetAnimation(const std::string& name) const;
273 public: // Not intended for application developers
276 * @brief Creates a handle using the Toolkit::Internal implementation.
278 * @param[in] implementation The Control implementation
280 DALI_INTERNAL Model(Internal::Model& implementation);
283 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
285 * @param[in] internal A pointer to the internal CustomActor
287 DALI_INTERNAL Model(Dali::Internal::CustomActor* internal);
294 } // namespace Scene3D
298 #endif // DALI_SCENE3D_MODEL_H