1 #ifndef DALI_SCENE3D_MODEL_MOTION_MOTION_DATA_H
2 #define DALI_SCENE3D_MODEL_MOTION_MOTION_DATA_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/public-api/common/dali-common.h>
23 #include <dali/public-api/object/base-handle.h>
26 #include <dali-scene3d/public-api/api.h>
27 #include <dali-scene3d/public-api/model-motion/motion-index/motion-index.h>
28 #include <dali-scene3d/public-api/model-motion/motion-value.h>
34 //Forward declarations.
38 } // namespace Internal
41 * @addtogroup dali_scene3d_model_motion_motion_data
46 * @brief List of model motion definitions.
47 * Each motion has pair of MotionIndex and MotionValue.
48 * MotionIndex is abstract class that specify the target of motion.
49 * MotionValue is target value of motion. It can be KeyFrames.
51 * We can generate list of motions by MotionIndex and MotionValue classes.
55 * MotionData motionData = MotionData::New(3.0f);
57 * // Make MotionIndex with MotionPropertyIndex
58 * // Make MotionValue with Dali::Property::Value
59 * motionData.Add(MotionPropertyIndex::New("nodeName", "color"), MotionValue::New(Color::RED));
61 * // Make MotionIndex with MotionTransformIndex
62 * // Make MotionValue with Dali::KeyFrames
63 * KeyFrames keyFrames = KeyFrames::New();
64 * keyFrames.Add(0.0f, 0.0f);
65 * keyFrames.Add(0.0f, 1.0f);
66 * motionData.Add(MotionTransformIndex::New("nodeName", MotionTransformIndex::TransformType::POSITION_X), MotionValue::New(keyFrames));
68 * // Make MotionIndex with BlendShapeIndex
69 * motionData.Add(BlendShapeIndex::New("nodeName", 0u), motionData.GetValue(1u));
73 * We can request to load MotionData from file or buffer asynchronously.
74 * If load completed, LoadCompletedSignal will be emitted.
75 * If we try to load before LoadCompletedSignal emitted, previous load request cancel and only latest request loaded.
79 * MotionData motionData = MotionData::New();
80 * motionData.LoadCompletedSignal().Connect(&OnLoadCompleted);
81 * motionData.LoadBvh("bvhFilename.bvh", Vector3::ONE);
85 * We can generate animation of Scene3D::Model from MotionData class.
86 * Or, just set values.
90 * // Generate animation from loaded Model
91 * Dali::Animation animation = model.GenerateMotionDataAnimation(motionData);
94 * // Set values from loaded Model.
95 * model2.SetMotionData(motionData);
98 * @note We don't check duplicated MotionIndex internally.
99 * @note We don't check MotionValue type is matched with MotionIndex.
102 class DALI_SCENE3D_API MotionData : public Dali::BaseHandle
105 /// @brief LoadCompleted signal type. @SINCE_2_2.34
106 typedef Signal<void(MotionData)> LoadCompletedSignalType;
108 public: // Creation & Destruction
110 * @brief Create an initialized MotionData.
113 * @return A handle to a newly allocated Dali resource
115 static MotionData New();
118 * @brief Create an initialized MotionData with duration.
121 * @param[in] durationSeconds Duration of animation as seconds.
122 * @return A handle to a newly allocated Dali resource
124 static MotionData New(float durationSeconds);
127 * @brief Creates an uninitialized MotionData.
129 * Only derived versions can be instantiated. Calling member
130 * functions with an uninitialized Dali::Object is not allowed.
139 * This is non-virtual since derived Handle types must not contain data or virtual methods.
146 * @brief Copy constructor.
149 * @param[in] motionData Handle to an object
151 MotionData(const MotionData& motionData);
154 * @brief Move constructor
157 * @param[in] rhs A reference to the moved handle
159 MotionData(MotionData&& rhs) noexcept;
162 * @brief Assignment operator.
165 * @param[in] motionData Handle to an object
166 * @return reference to this
168 MotionData& operator=(const MotionData& motionData);
171 * @brief Move assignment
174 * @param[in] rhs A reference to the moved handle
175 * @return A reference to this
177 MotionData& operator=(MotionData&& rhs) noexcept;
180 * @brief Downcasts an Object handle to MotionData.
182 * If handle points to a MotionData, the downcast produces valid handle.
183 * If not, the returned handle is left uninitialized.
186 * @param[in] handle Handle to an object
187 * @return Handle to a MotionData or an uninitialized handle
189 static MotionData DownCast(BaseHandle handle);
191 public: // Public Method
193 * @brief Get the number of motions what we added
196 * @return The number of motions
198 uint32_t GetMotionCount() const;
201 * @brief Get MotionIndex from given index'th.
204 * @param[in] index The index of motion list.
205 * @return Index of motion, or empty handle if invalid index inputed.
207 MotionIndex GetIndex(uint32_t index) const;
210 * @brief Get MotionValue from given index'th.
213 * @param[in] index The index of motion list.
214 * @return Value of motion, or empty handle if invalid index inputed.
216 MotionValue GetValue(uint32_t index) const;
219 * @brief Append new motion.
220 * @note We don't check duplicated MotionIndex internally.
223 * @param[in] index index of motion.
224 * @param[in] value value of motion.
226 void Add(MotionIndex index, MotionValue value);
229 * @brief Clear all stored motion data.
236 * @brief Set the duration of this motion data if it be generated as Dali::Animation.
239 * @param[in] durationSeconds Duration of animation as seconds.
241 void SetDuration(float durationSeconds);
244 * @brief Get the duration of this motion data if it be generated as Dali::Animation.
247 * @return The duration of this motion data seconds. Default is 0.0f
249 float GetDuration() const;
252 * @brief Load MotionData from bvh file.
253 * It will use Dali::Scene3D::Loader::LoadBvh() internally.
254 * LoadCompleteSignal() will be emitted after load completed.
257 * @param[in] path The file path.
258 * @param[in] scale The scale factor to set on the position property manually.
259 * @param[in] synchronousLoad True if we want to load result synchronously. Default is false.
261 void LoadBvh(const std::string& path, const Vector3& scale = Vector3::ONE, bool synchronousLoad = false);
264 * @brief Load MotionData from bvh file.
265 * It will use Dali::Scene3D::Loader::LoadBvh() internally.
266 * LoadCompleteSignal() will be emitted after load completed.
269 * @param[in] path The file path.
270 * @param[in] scale The scale factor to set on the position property manually.
271 * @param[in] useRootTranslationOnly True to use only root translation with rotation animation.
272 * @param[in] synchronousLoad True if we want to load result synchronously. Default is false.
274 void LoadBvh(const std::string& path, bool useRootTranslationOnly, const Vector3& scale = Vector3::ONE, bool synchronousLoad = false);
277 * @brief Load MotionData from bvh buffer.
278 * It will use Dali::Scene3D::Loader::LoadBvhFromBuffer() internally.
279 * LoadCompleteSignal() will be emitted after load completed.
282 * @param[in] rawBuffer The bvh buffer containing the facial animation as bvh format string.
283 * @param[in] rawBufferLength The length of buffer.
284 * @param[in] scale The scale factor to set on the position property manually.
285 * @param[in] synchronousLoad True if we want to load result synchronously. Default is false.
287 void LoadBvhFromBuffer(const uint8_t* rawBuffer, int rawBufferLength, const Vector3& scale = Vector3::ONE, bool synchronousLoad = false);
290 * @brief Load MotionData from bvh buffer.
291 * It will use Dali::Scene3D::Loader::LoadBvhFromBuffer() internally.
292 * LoadCompleteSignal() will be emitted after load completed.
295 * @param[in] rawBuffer The bvh buffer containing the facial animation as bvh format string.
296 * @param[in] rawBufferLength The length of buffer.
297 * @param[in] useRootTranslationOnly True to use only root translation with rotation animation.
298 * @param[in] scale The scale factor to set on the position property manually.
299 * @param[in] synchronousLoad True if we want to load result synchronously. Default is false.
301 void LoadBvhFromBuffer(const uint8_t* rawBuffer, int rawBufferLength, bool useRootTranslationOnly, const Vector3& scale = Vector3::ONE, bool synchronousLoad = false);
304 * @brief Load MotionData from facial defined json file.
305 * It will use Dali::Scene3D::Loader::LoadFacialAnimation() internally.
306 * LoadCompleteSignal() will be emitted after load completed.
309 * @param[in] url The file path.
310 * @param[in] synchronousLoad True if we want to load result synchronously. Default is false.
312 void LoadFacialAnimation(const std::string& url, bool synchronousLoad = false);
315 * @brief Load MotionData from facial defined json file.
316 * It will use Dali::Scene3D::Loader::LoadFacialAnimationFromBuffer() internally.
317 * LoadCompleteSignal() will be emitted after load completed.
320 * @param[in] rawBuffer The raw buffer containing the facial animation as json format string.
321 * @param[in] rawBufferLength The length of raw buffer.
322 * @param[in] synchronousLoad True if we want to load result synchronously. Default is false.
324 void LoadFacialAnimationFromBuffer(const uint8_t* rawBuffer, int rawBufferLength, bool synchronousLoad = false);
328 * @brief This signal is emitted after motion data are loaded completed.
329 * @note Signal will be emitted even if we request load synchronously.
331 * A callback of the following type may be connected:
333 * void YourCallbackName(MotionData motionData);
337 * @return The signal to connect to.
339 LoadCompletedSignalType& LoadCompletedSignal();
341 public: // Not intended for application developers
344 * @brief Creates a handle using the Scene3D::Internal implementation.
346 * @param[in] implementation The MotionData implementation
348 DALI_INTERNAL MotionData(Dali::Scene3D::Internal::MotionData* implementation);
356 } // namespace Scene3D
360 #endif // DALI_SCENE3D_MODEL_MOTION_MOTION_DATA_H