1 #ifndef DALI_SCENE3D_MODEL_H
2 #define DALI_SCENE3D_MODEL_H
5 * Copyright (c) 2023 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/actors/camera-actor.h>
27 #include <dali/public-api/common/dali-common.h>
28 #include <dali/public-api/rendering/texture.h>
34 namespace Internal DALI_INTERNAL
40 * @addtogroup dali_toolkit_controls_model
45 * @brief Model is a control to show 3D model objects.
46 * Model supports to load glTF 2.0 and DLI models for the input format
47 * and also supports Physically Based Rendering with Image Based Lighting.
49 * The Animations defined in the glTF or DLI models are also loaded and can be retrieved by using GetAnimation() method.
50 * The number of animation is also retrieved by GetAnimationCount() method.
52 * By default, The loaded model has its own position and size which are defined in vertex buffer regardless of the Control size.
57 * Model model = Model::New(modelUrl);
58 * model.SetProperty(Dali::Actor::Property::SIZE, Vector2(width, height));
59 * model.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
60 * model.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
61 * model.SetImageBasedLightSource(diffuseUrl, specularUrl, scaleFactor);
63 * uint32_t animationCount = model.GetAnimationCount();
64 * Dali::Animation animation = model.GetAnimation(0);
69 class DALI_SCENE3D_API Model : public Dali::Toolkit::Control
73 * @brief Create an initialized Model.
76 * @param[in] modelUrl model file path.(e.g., glTF, and DLI).
77 * @param[in] resourceDirectoryUrl resource file path that includes binary, image etc.
78 * @note If resourceDirectoryUrl is empty, the parent directory path of modelUrl is used for resource path.
79 * @return A handle to a newly allocated Dali resource
81 static Model New(const std::string& modelUrl, const std::string& resourceDirectoryUrl = std::string());
84 * @brief Creates an uninitialized Model.
86 * Only derived versions can be instantiated. Calling member
87 * functions with an uninitialized Dali::Object is not allowed.
96 * This is non-virtual since derived Handle types must not contain data or virtual methods.
103 * @brief Copy constructor.
106 * @param[in] model Handle to an object
108 Model(const Model& model);
111 * @brief Move constructor
114 * @param[in] rhs A reference to the moved handle
119 * @brief Assignment operator.
122 * @param[in] model Handle to an object
123 * @return reference to this
125 Model& operator=(const Model& model);
128 * @brief Move assignment
131 * @param[in] rhs A reference to the moved handle
132 * @return A reference to this
134 Model& operator=(Model&& rhs);
137 * @brief Downcasts an Object handle to Model.
139 * If handle points to a Model, the downcast produces valid handle.
140 * If not, the returned handle is left uninitialized.
143 * @param[in] handle Handle to an object
144 * @return Handle to a Model or an uninitialized handle
146 static Model DownCast(BaseHandle handle);
149 * @brief Retrieves model root Actor.
152 * @return Root Actor of the model.
154 const Actor GetModelRoot() const;
157 * @brief Whether allow this model's children actor to use events.
159 * Usually, 3D Model might have a lot of actors. And most of them don't need to check events.
160 * To optimize traversal, we need to setup some flag that this model don't allow (or allow) to traversal
161 * children so that child can use events.
164 * @note Even if we set children sensitive as false, model itself's sensitive
165 * is depend on it's property.
166 * @note If we don't call this API, default is false. (Don't allow to traversal model's children during hit-test)
168 * @param[in] enable True to enable model's children can use events.
170 void SetChildrenSensitive(bool enable);
173 * @brief Gets whether this Model allow model's children actor to use events or not.
176 * @return bool True if this Model allow model children sensitive.
178 bool GetChildrenSensitive() const;
181 * @brief Whether allow this model's children actor to be keyboard focusable.
183 * Usually, 3D Model might have a lot of actors. And most of them don't need to check focusable.
184 * To optimize traversal, we need to setup some flag that this model don't allow (or allow) to traversal
185 * children so that child can be keyboard focusable.
188 * @note Even if we set children focusable as false, model itself's focusable
189 * is depend on it's property.
190 * @note If we don't call this API, default is false. (Don't allow to traversal model's children during focusable test)
192 * @param[in] enable True to enable model's children can be focusable.
194 void SetChildrenFocusable(bool enable);
197 * @brief Gets whether this Model allow model's children actor to be keyboard focusable or not.
200 * @return bool True if this Model allow model children are focusable.
202 bool GetChildrenFocusable() const;
205 * @brief Changes Image Based Light as the input textures.
208 * @param[in] diffuseUrl cube map that can be used as a diffuse IBL source.
209 * @param[in] specularUrl cube map that can be used as a specular IBL source.
210 * @param[in] scaleFactor scale factor that controls light source intensity in [0.0f, 1.0f]. Default value is 1.0f.
212 void SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor = 1.0f);
215 * @brief Sets Image Based Light Texture.
218 * @param[in] diffuseTexture cube map texture that can be used as a diffuse IBL source.
219 * @param[in] specularTexture cube map texture that can be used as a specular IBL source.
220 * @param[in] scaleFactor scale factor that controls light source intensity in [0.0f, 1.0f]. Default value is 1.0f.
222 * @note Both of diffuse texture and specular texture should be available. If not, nothing applied.
224 void SetImageBasedLightTexture(Texture diffuseTexture, Texture specularTexture, float scaleFactor = 1.0f);
227 * @brief Sets Scale Factor of Image Based Light Source.
230 * @note If SetImageBasedLightSource() or SetImageBasedLightTexture() method is called after this method, scaleFactor is overrided.
232 * @param[in] scaleFactor scale factor that controls light source intensity in [0.0f, 1.0f].
234 void SetImageBasedLightScaleFactor(float scaleFactor);
237 * @brief Gets Scale Factor of Image Based Light Source.
238 * Default value is 1.0f.
241 * @return scale factor that controls light source intensity.
243 float GetImageBasedLightScaleFactor() const;
246 * @brief Gets number of animations those loaded from model file.
249 * @return The number of loaded animations.
250 * @note This method should be called after Model load finished.
252 uint32_t GetAnimationCount() const;
255 * @brief Gets animation at the index.
258 * @param[in] index Index of animation to be retrieved.
259 * @return Animation at the index.
260 * @note This method should be called after Model load finished.
262 Dali::Animation GetAnimation(uint32_t index) const;
265 * @brief Retrieves animation with the given name.
268 * @param[in] name string name of animation to be retrieved.
269 * @return Animation that has the given name.
270 * @note This method should be called after Model load finished.
272 Dali::Animation GetAnimation(const std::string& name) const;
275 * @brief Gets number of camera parameters those loaded from model file.
278 * @return The number of loaded camera parameters.
279 * @note This method should be called after Model load finished.
281 uint32_t GetCameraCount() const;
284 * @brief Generate camera actor using camera parameters at the index.
285 * If camera parameter is valid, create new CameraActor.
286 * Camera parameter decide at initialized time and
287 * didn't apply model node's current position (like Animation).
290 * @param[in] index Index of camera to be used for generation camera.
291 * @return Generated CameraActor by the index, or empty Handle if generation failed.
292 * @note This method should be called after Model load finished.
294 Dali::CameraActor GenerateCamera(uint32_t index) const;
297 * @brief Apply camera parameters at the index to inputed camera actor.
298 * If camera parameter is valid and camera actor is not empty, apply parameters.
299 * It will change camera's transform and near / far / fov or orthographic size / aspect ratio (if defined)
300 * Camera parameter decide at initialized time and
301 * didn't apply model node's current position (like Animation).
304 * @param[in] index Index of camera to be used for generation camera.
305 * @param[in,out] camera Index of camera to be used for generation camera.
306 * @return True if apply successed. False otherwise.
307 * @note This method should be called after Model load finished.
309 bool ApplyCamera(uint32_t index, Dali::CameraActor camera) const;
311 public: // Not intended for application developers
314 * @brief Creates a handle using the Toolkit::Internal implementation.
316 * @param[in] implementation The Control implementation
318 DALI_INTERNAL Model(Internal::Model& implementation);
321 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
323 * @param[in] internal A pointer to the internal CustomActor
325 DALI_INTERNAL Model(Dali::Internal::CustomActor* internal);
332 } // namespace Scene3D
336 #endif // DALI_SCENE3D_MODEL_H