1 #ifndef DALI_SCENE_LOADER_MODEL_VIEW_H
2 #define DALI_SCENE_LOADER_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-scene-loader/public-api/api.h>
25 #include <dali-toolkit/public-api/controls/control.h>
26 #include <dali/public-api/common/dali-common.h>
32 namespace Internal DALI_INTERNAL
38 * @addtogroup dali_toolkit_controls_model_view
43 * @brief ModelView is a control to show 3D model objects.
44 * ModelView supports to load glTF 2.0 and DLI models for the input format
45 * and also supports Physically Based Rendering with Image Based Lighting.
47 * The Animations defined in the glTF or DLI models are also loaded and can be retrieved by using GetAnimation() method.
48 * The number of animation is also retrieved by GetAnimationCount() method.
50 * By default, The loaded model has it's own position and size which are defined in vertex buffer regardless of the Control size.
51 * The model can be resized and repositioned to fit to the ModelView Control with FitSize() and FitCenter() methods.
55 * ModelView modelView = ModelView::New(modelUrl);
56 * modelView.SetProperty(Dali::Actor::Property::SIZE, Vector2(width, height));
57 * modelView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
58 * modelView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
59 * modelView.SetImageBasedLightSource(diffuseUrl, specularUrl, scaleFactor);
60 * modelView.FitSize(true);
61 * modelView.FitCenter(true);
62 * window.Add(modelView);
63 * uint32_t animationCount = modelView.GetAnimationCount();
64 * Dali::Animation animation = modelView.GetAnimation(0);
69 class DALI_SCENE_LOADER_API ModelView : public Dali::Toolkit::Control
73 * @brief Create an initialized ModelView.
74 * @param[in] modelPath model file path.(e.g., glTF, and DLI).
75 * @param[in] resourcePath resource file path that includes binary, image etc.
76 * @note If resourcePath is empty, the parent directory path of modelPath is used for resource path.
77 * @return A handle to a newly allocated Dali resource
79 static ModelView New(const std::string& modelPath, const std::string& resourcePath = std::string());
82 * @brief Creates an uninitialized ModelView.
84 * Only derived versions can be instantiated. Calling member
85 * functions with an uninitialized Dali::Object is not allowed.
92 * This is non-virtual since derived Handle types must not contain data or virtual methods.
97 * @brief Copy constructor.
98 * @param[in] modelView Handle to an object
100 ModelView(const ModelView& modelView);
103 * @brief Move constructor
105 * @param[in] rhs A reference to the moved handle
107 ModelView(ModelView&& rhs);
110 * @brief Assignment operator.
111 * @param[in] modelView Handle to an object
112 * @return reference to this
114 ModelView& operator=(const ModelView& modelView);
117 * @brief Move assignment
119 * @param[in] rhs A reference to the moved handle
120 * @return A reference to this
122 ModelView& operator=(ModelView&& rhs);
125 * @brief Downcasts an Object handle to ModelView.
127 * If handle points to a ModelView, the downcast produces valid handle.
128 * If not, the returned handle is left uninitialized.
130 * @param[in] handle Handle to an object
131 * @return Handle to a ModelView or an uninitialized handle
133 static ModelView DownCast(BaseHandle handle);
136 * @brief Retrieves model root Actor.
137 * @return Root Actor of the model.
139 const Actor GetModelRoot();
142 * @brief Fits the model to the Control size.
143 * @param[in] fit true to fit model size to control.
144 * @note This method makes model fit to the Control size by keeping original model ratio.
145 * It means If model size is (2, 2, 2) and ModelView size is (10, 8), then the model become looks (8, 8, 8).
146 * If ModelView Size x or y is 0, this method don't work anything.
147 * If ModelView Size z is 0, this method considers only x and y values of ModelView Size.
149 void FitSize(bool fit);
152 * @brief Moves the model to the center of control.
153 * @param[in] fit true to fit model to center of control.
154 * @note This method doesn't changes size of model.
156 void FitCenter(bool fit);
159 * @brief Changes Image Based Light as the input textures.
160 * @param[in] diffuse cube map that can be used as a diffuse IBL source.
161 * @param[in] specular cube map that can be used as a specular IBL source.
162 * @param[in] scaleFactor scale factor that controls light source intensity in [0.0f, 1.0f]. Default value is 1.0f.
164 void SetImageBasedLightSource(const std::string& diffuse, const std::string& specular, float scaleFactor = 1.0f);
167 * @brief Gets number of animations those loaded from model file.
168 * @return The number of loaded animations.
169 * @note This method should be called after Model load finished.
171 uint32_t GetAnimationCount();
174 * @brief Gets animation at the index.
175 * @param[in] index Index of animation to be retrieved.
176 * @return Animation at the index.
177 * @note This method should be called after Model load finished.
179 Dali::Animation GetAnimation(uint32_t index);
182 * @brief Retrieves animation with the given name.
183 * @param[in] name string name of animation to be retrieved.
184 * @return Animation that has the given name.
185 * @note This method should be called after Model load finished.
187 Dali::Animation GetAnimation(const std::string& name);
189 public: // Not intended for application developers
192 * @brief Creates a handle using the Toolkit::Internal implementation.
194 * @param[in] implementation The Control implementation
196 DALI_INTERNAL ModelView(Internal::ModelView& implementation);
199 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
201 * @param[in] internal A pointer to the internal CustomActor
203 DALI_INTERNAL ModelView(Dali::Internal::CustomActor* internal);
210 } // namespace Scene3D
214 #endif // DALI_SCENE_LOADER_MODEL_VIEW_H