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. (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 Changes Image Based Light as the input textures.
183 * @param[in] diffuseUrl cube map that can be used as a diffuse IBL source.
184 * @param[in] specularUrl cube map that can be used as a specular IBL source.
185 * @param[in] scaleFactor scale factor that controls light source intensity in [0.0f, 1.0f]. Default value is 1.0f.
187 void SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor = 1.0f);
190 * @brief Sets Image Based Light Texture.
193 * @param[in] diffuseTexture cube map texture that can be used as a diffuse IBL source.
194 * @param[in] specularTexture cube map texture that can be used as a specular IBL source.
195 * @param[in] scaleFactor scale factor that controls light source intensity in [0.0f, 1.0f]. Default value is 1.0f.
197 * @note Both of diffuse texture and specular texture should be available. If not, nothing applied.
199 void SetImageBasedLightTexture(Texture diffuseTexture, Texture specularTexture, float scaleFactor = 1.0f);
202 * @brief Sets Scale Factor of Image Based Light Source.
205 * @note If SetImageBasedLightSource() or SetImageBasedLightTexture() method is called after this method, scaleFactor is overrided.
207 * @param[in] scaleFactor scale factor that controls light source intensity in [0.0f, 1.0f].
209 void SetImageBasedLightScaleFactor(float scaleFactor);
212 * @brief Gets Scale Factor of Image Based Light Source.
213 * Default value is 1.0f.
216 * @return scale factor that controls light source intensity.
218 float GetImageBasedLightScaleFactor() const;
221 * @brief Gets number of animations those loaded from model file.
224 * @return The number of loaded animations.
225 * @note This method should be called after Model load finished.
227 uint32_t GetAnimationCount() const;
230 * @brief Gets animation at the index.
233 * @param[in] index Index of animation to be retrieved.
234 * @return Animation at the index.
235 * @note This method should be called after Model load finished.
237 Dali::Animation GetAnimation(uint32_t index) const;
240 * @brief Retrieves animation with the given name.
243 * @param[in] name string name of animation to be retrieved.
244 * @return Animation that has the given name.
245 * @note This method should be called after Model load finished.
247 Dali::Animation GetAnimation(const std::string& name) const;
249 public: // Not intended for application developers
252 * @brief Creates a handle using the Toolkit::Internal implementation.
254 * @param[in] implementation The Control implementation
256 DALI_INTERNAL Model(Internal::Model& implementation);
259 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
261 * @param[in] internal A pointer to the internal CustomActor
263 DALI_INTERNAL Model(Dali::Internal::CustomActor* internal);
270 } // namespace Scene3D
274 #endif // DALI_SCENE3D_MODEL_H