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/rendering/texture.h>
27 #include <dali/public-api/common/dali-common.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.
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);
61 * uint32_t animationCount = model.GetAnimationCount();
62 * Dali::Animation animation = model.GetAnimation(0);
67 class DALI_SCENE3D_API Model : public Dali::Toolkit::Control
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
77 static Model New(const std::string& modelUrl, const std::string& resourceDirectoryUrl = std::string());
80 * @brief Creates an uninitialized Model.
82 * Only derived versions can be instantiated. Calling member
83 * functions with an uninitialized Dali::Object is not allowed.
90 * This is non-virtual since derived Handle types must not contain data or virtual methods.
95 * @brief Copy constructor.
96 * @param[in] model Handle to an object
98 Model(const Model& model);
101 * @brief Move constructor
103 * @param[in] rhs A reference to the moved handle
108 * @brief Assignment operator.
109 * @param[in] model Handle to an object
110 * @return reference to this
112 Model& operator=(const Model& model);
115 * @brief Move assignment
117 * @param[in] rhs A reference to the moved handle
118 * @return A reference to this
120 Model& operator=(Model&& rhs);
123 * @brief Downcasts an Object handle to Model.
125 * If handle points to a Model, the downcast produces valid handle.
126 * If not, the returned handle is left uninitialized.
128 * @param[in] handle Handle to an object
129 * @return Handle to a Model or an uninitialized handle
131 static Model DownCast(BaseHandle handle);
134 * @brief Retrieves model root Actor.
135 * @return Root Actor of the model.
137 const Actor GetModelRoot() const;
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.
145 void SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor = 1.0f);
148 * @brief Sets Image Based Light Texture.
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.
154 * @note Both of diffuse texture and specular texture should be available. If not, nothing applied.
156 void SetImageBasedLightTexture(Texture diffuseTexture, Texture specularTexture, float scaleFactor = 1.0f);
159 * @brief Sets Scale Factor of Image Based Light Source.
161 * @note If SetImageBasedLightSource() or SetImageBasedLightTexture() method is called after this method, scaleFactor is overrided.
163 * @param[in] scaleFactor scale factor that controls light source intensity in [0.0f, 1.0f].
165 void SetImageBasedLightScaleFactor(float scaleFactor);
168 * @brief Gets Scale Factor of Image Based Light Source.
169 * Default value is 1.0f.
171 * @return scale factor that controls light source intensity.
173 float GetImageBasedLightScaleFactor() const;
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.
180 uint32_t GetAnimationCount() const;
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.
188 Dali::Animation GetAnimation(uint32_t index) const;
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.
196 Dali::Animation GetAnimation(const std::string& name) const;
198 public: // Not intended for application developers
201 * @brief Creates a handle using the Toolkit::Internal implementation.
203 * @param[in] implementation The Control implementation
205 DALI_INTERNAL Model(Internal::Model& implementation);
208 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
210 * @param[in] internal A pointer to the internal CustomActor
212 DALI_INTERNAL Model(Dali::Internal::CustomActor* internal);
219 } // namespace Scene3D
223 #endif // DALI_SCENE3D_MODEL_H