1 #ifndef DALI_SCENE3D_MODEL_VIEW_H
2 #define DALI_SCENE3D_MODEL_VIEW_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_view
44 * @brief ModelView is a control to show 3D model objects.
45 * ModelView 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 it's own position and size which are defined in vertex buffer regardless of the Control size.
52 * The model can be resized and repositioned to fit to the ModelView Control with FitSize() and FitCenter() methods.
56 * ModelView modelView = ModelView::New(modelUrl);
57 * modelView.SetProperty(Dali::Actor::Property::SIZE, Vector2(width, height));
58 * modelView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
59 * modelView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
60 * modelView.SetImageBasedLightSource(diffuseUrl, specularUrl, scaleFactor);
61 * modelView.FitSize(true);
62 * modelView.FitCenter(true);
63 * window.Add(modelView);
64 * uint32_t animationCount = modelView.GetAnimationCount();
65 * Dali::Animation animation = modelView.GetAnimation(0);
70 class DALI_SCENE3D_API ModelView : public Dali::Toolkit::Control
74 * @brief Create an initialized ModelView.
75 * @param[in] modelPath model file path.(e.g., glTF, and DLI).
76 * @param[in] resourcePath resource file path that includes binary, image etc.
77 * @note If resourcePath is empty, the parent directory path of modelPath is used for resource path.
78 * @return A handle to a newly allocated Dali resource
80 static ModelView New(const std::string& modelPath, const std::string& resourcePath = std::string());
83 * @brief Creates an uninitialized ModelView.
85 * Only derived versions can be instantiated. Calling member
86 * functions with an uninitialized Dali::Object is not allowed.
93 * This is non-virtual since derived Handle types must not contain data or virtual methods.
98 * @brief Copy constructor.
99 * @param[in] modelView Handle to an object
101 ModelView(const ModelView& modelView);
104 * @brief Move constructor
106 * @param[in] rhs A reference to the moved handle
108 ModelView(ModelView&& rhs);
111 * @brief Assignment operator.
112 * @param[in] modelView Handle to an object
113 * @return reference to this
115 ModelView& operator=(const ModelView& modelView);
118 * @brief Move assignment
120 * @param[in] rhs A reference to the moved handle
121 * @return A reference to this
123 ModelView& operator=(ModelView&& rhs);
126 * @brief Downcasts an Object handle to ModelView.
128 * If handle points to a ModelView, the downcast produces valid handle.
129 * If not, the returned handle is left uninitialized.
131 * @param[in] handle Handle to an object
132 * @return Handle to a ModelView or an uninitialized handle
134 static ModelView DownCast(BaseHandle handle);
137 * @brief Retrieves model root Actor.
138 * @return Root Actor of the model.
140 const Actor GetModelRoot() const;
143 * @brief Fits the model to the Control size.
144 * @param[in] fit true to fit model size to control.
145 * @note This method makes model fit to the Control size by keeping original model ratio.
146 * It means If model size is (2, 2, 2) and ModelView size is (10, 8), then the model become looks (8, 8, 8).
147 * If ModelView Size x or y is 0, this method don't work anything.
148 * If ModelView Size z is 0, this method considers only x and y values of ModelView Size.
150 void FitSize(bool fit);
153 * @brief Moves the model to the center of control.
154 * @param[in] fit true to fit model to center of control.
155 * @note This method doesn't changes size of model.
157 void FitCenter(bool fit);
160 * @brief Changes Image Based Light as the input textures.
161 * @param[in] diffuse cube map that can be used as a diffuse IBL source.
162 * @param[in] specular cube map that can be used as a specular IBL source.
163 * @param[in] scaleFactor scale factor that controls light source intensity in [0.0f, 1.0f]. Default value is 1.0f.
165 void SetImageBasedLightSource(const std::string& diffuse, const std::string& specular, float scaleFactor = 1.0f);
168 * @brief Sets Image Based Light Texture.
170 * @param[in] diffuse cube map texture that can be used as a diffuse IBL source.
171 * @param[in] specular cube map texture that can be used as a specular IBL source.
172 * @param[in] scaleFactor scale factor that controls light source intensity in [0.0f, 1.0f]. Default value is 1.0f.
174 * @note Both of diffuse and specular should be available. If not, nothing applied.
176 void SetImageBasedLightTexture(Texture diffuse, Texture specular, float scaleFactor = 1.0f);
179 * @brief Sets Scale Factor of Image Based Light Source.
181 * @note If SetImageBasedLightSource() or SetImageBasedLightTexture() method is called after this method, scaleFactor is overrided.
183 * @param[in] scaleFactor scale factor that controls light source intensity in [0.0f, 1.0f].
185 void SetImageBasedLightScaleFactor(float scaleFactor);
188 * @brief Gets Scale Factor of Image Based Light Source.
189 * Default value is 1.0f.
191 * @return scale factor that controls light source intensity.
193 float GetImageBasedLightScaleFactor() const;
196 * @brief Gets number of animations those loaded from model file.
197 * @return The number of loaded animations.
198 * @note This method should be called after Model load finished.
200 uint32_t GetAnimationCount() const;
203 * @brief Gets animation at the index.
204 * @param[in] index Index of animation to be retrieved.
205 * @return Animation at the index.
206 * @note This method should be called after Model load finished.
208 Dali::Animation GetAnimation(uint32_t index) const;
211 * @brief Retrieves animation with the given name.
212 * @param[in] name string name of animation to be retrieved.
213 * @return Animation that has the given name.
214 * @note This method should be called after Model load finished.
216 Dali::Animation GetAnimation(const std::string& name) const;
218 public: // Not intended for application developers
221 * @brief Creates a handle using the Toolkit::Internal implementation.
223 * @param[in] implementation The Control implementation
225 DALI_INTERNAL ModelView(Internal::ModelView& implementation);
228 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
230 * @param[in] internal A pointer to the internal CustomActor
232 DALI_INTERNAL ModelView(Dali::Internal::CustomActor* internal);
239 } // namespace Scene3D
243 #endif // DALI_SCENE3D_MODEL_VIEW_H