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, LoadCompetedSignal will be emmited.
78 * MotionData motionData = MotionData::New();
79 * motionData.LoadCompletedSignal().Connect(&OnLoadCompleted);
80 * motionData.LoadBvh("bvhFilename.bvh", Vector3::ONE);
84 * We can generate animation of Scene3D::Model from MotionData class.
85 * Or, just set values.
89 * // Generate animation from loaded Model
90 * Dali::Animation animation = model.GenerateMotionDataAnimation(motionData);
93 * // Set values from loaded Model.
94 * model2.SetMotionData(motionData);
97 * @note We don't check duplicated MotionIndex internally.
100 class DALI_SCENE3D_API MotionData : public Dali::BaseHandle
103 /// @brief LoadCompleted signal type. @SINCE_2_2.99
104 typedef Signal<void(MotionData)> LoadCompletedSignalType;
106 public: // Creation & Destruction
108 * @brief Create an initialized MotionData.
111 * @return A handle to a newly allocated Dali resource
113 static MotionData New();
116 * @brief Create an initialized MotionData with duration.
119 * @param[in] durationSeconds Duration of animation as seconds.
120 * @return A handle to a newly allocated Dali resource
122 static MotionData New(float durationSeconds);
125 * @brief Creates an uninitialized MotionData.
127 * Only derived versions can be instantiated. Calling member
128 * functions with an uninitialized Dali::Object is not allowed.
137 * This is non-virtual since derived Handle types must not contain data or virtual methods.
144 * @brief Copy constructor.
147 * @param[in] motionData Handle to an object
149 MotionData(const MotionData& motionData);
152 * @brief Move constructor
155 * @param[in] rhs A reference to the moved handle
157 MotionData(MotionData&& rhs) noexcept;
160 * @brief Assignment operator.
163 * @param[in] motionData Handle to an object
164 * @return reference to this
166 MotionData& operator=(const MotionData& motionData);
169 * @brief Move assignment
172 * @param[in] rhs A reference to the moved handle
173 * @return A reference to this
175 MotionData& operator=(MotionData&& rhs) noexcept;
178 * @brief Downcasts an Object handle to MotionData.
180 * If handle points to a MotionData, the downcast produces valid handle.
181 * If not, the returned handle is left uninitialized.
184 * @param[in] handle Handle to an object
185 * @return Handle to a MotionData or an uninitialized handle
187 static MotionData DownCast(BaseHandle handle);
189 public: // Public Method
191 * @brief Get the number of motions what we added
194 * @return The number of motions
196 uint32_t GetMotionCount() const;
199 * @brief Get MotionIndex from given index'th.
202 * @param[in] index The index of motion list.
203 * @return Index of motion, or empty handle if invalid index inputed.
205 MotionIndex GetIndex(uint32_t index) const;
208 * @brief Get MotionValue from given index'th.
211 * @param[in] index The index of motion list.
212 * @return Value of motion, or empty handle if invalid index inputed.
214 MotionValue GetValue(uint32_t index) const;
217 * @brief Append new motion.
218 * @note We don't check duplicated MotionIndex internally.
221 * @param[in] index index of motion.
222 * @param[in] value value of motion.
224 void Add(MotionIndex index, MotionValue value);
227 * @brief Clear all stored motion data.
234 * @brief Set the duration of this motion data if it be generated as Dali::Animation.
237 * @param[in] durationSeconds Duration of animation as seconds.
239 void SetDuration(float durationSeconds);
242 * @brief Get the duration of this motion data if it be generated as Dali::Animation.
245 * @return The duration of this motion data seconds. Default is 0.0f
247 float GetDuration() const;
250 * @brief Load MotionData from bvh file.
251 * It will use Dali::Scene3D::Loader::LoadBvh() internally.
252 * LoadCompleteSignal() will be emitted after load completed.
255 * @param[in] path The file path.
256 * @param[in] scale The scale factor to set on the position property manually.
257 * @param[in] synchronousLoad True if we want to load result synchronously. Default is false.
259 void LoadBvh(const std::string& path, const Vector3& scale = Vector3::ONE, bool synchronousLoad = false);
262 * @brief Load MotionData from bvh buffer.
263 * It will use Dali::Scene3D::Loader::LoadBvhFromBuffer() internally.
264 * LoadCompleteSignal() will be emitted after load completed.
267 * @param[in] rawBuffer The bvh buffer.
268 * @param[in] rawBufferLength The length of buffer.
269 * @param[in] scale The scale factor to set on the position property manually.
270 * @param[in] synchronousLoad True if we want to load result synchronously. Default is false.
272 void LoadBvhFromBuffer(const uint8_t* rawBuffer, int rawBufferLength, const Vector3& scale = Vector3::ONE, bool synchronousLoad = false);
275 * @brief Load MotionData from facail defined json file.
276 * It will use Dali::Scene3D::Loader::LoadFacialAnimation() internally.
277 * LoadCompleteSignal() will be emitted after load completed.
280 * @param[in] url The file path.
281 * @param[in] synchronousLoad True if we want to load result synchronously. Default is false.
283 void LoadFacialAnimation(const std::string& url, bool synchronousLoad = false);
286 * @brief Load MotionData from facail defined json file.
287 * It will use Dali::Scene3D::Loader::LoadFacialAnimationFromBuffer() internally.
288 * LoadCompleteSignal() will be emitted after load completed.
291 * @param[in] rawBuffer The raw buffer containing the facial animation.
292 * @param[in] rawBufferLength The length of raw buffer.
293 * @param[in] synchronousLoad True if we want to load result synchronously. Default is false.
295 void LoadFacialAnimationFromBuffer(const uint8_t* rawBuffer, int rawBufferLength, bool synchronousLoad = false);
299 * @brief This signal is emitted after motion data are loaded completed.
300 * @note Signal will be emitted even if we request load synchronously.
302 * A callback of the following type may be connected:
304 * void YourCallbackName(MotionData motionData);
308 * @return The signal to connect to.
310 LoadCompletedSignalType& LoadCompletedSignal();
312 public: // Not intended for application developers
315 * @brief Creates a handle using the Scene3D::Internal implementation.
317 * @param[in] implementation The MotionData implementation
319 DALI_INTERNAL MotionData(Dali::Scene3D::Internal::MotionData* implementation);
327 } // namespace Scene3D
331 #endif // DALI_SCENE3D_MODEL_MOTION_MOTION_DATA_H