[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / internal / model-motion / motion-data-impl.h
1 #ifndef DALI_SCENE3D_MODEL_MOTION_MOTION_DATA_IMPL_H
2 #define DALI_SCENE3D_MODEL_MOTION_MOTION_DATA_IMPL_H
3
4 /*
5  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/public-api/common/intrusive-ptr.h>
24 #include <dali/public-api/object/base-object.h>
25
26 #include <dali/public-api/common/vector-wrapper.h>
27 #include <utility> ///< for std::pair
28
29 // INTERNAL INCLUDES
30 #include <dali-scene3d/internal/model-motion/motion-data-load-task.h>
31 #include <dali-scene3d/public-api/loader/animation-definition.h>
32 #include <dali-scene3d/public-api/model-motion/motion-data.h>
33
34 namespace Dali
35 {
36 namespace Scene3D
37 {
38 namespace Internal
39 {
40 using MotionDataPtr = IntrusivePtr<MotionData>;
41
42 /**
43  * @brief Internal data for Scene3D::MotionData.
44  */
45 class MotionData : public BaseObject
46 {
47 public: // Creation & Destruction
48   /**
49    * @brief Create a new MotionData object.
50    * @return A smart-pointer to the newly allocated MotionData.
51    */
52   static MotionDataPtr New();
53
54 protected:
55   /**
56    * @brief Construct a new MotionData.
57    */
58   MotionData();
59
60   /**
61    * @brief Second-phase constructor.
62    */
63   void Initialize();
64
65   /**
66    * @brief Virtual destructor.
67    */
68   virtual ~MotionData();
69
70 public: // Public Method
71   /**
72    * @copydoc Dali::Scene3D::MotionData::GetMotionCount()
73    */
74   uint32_t GetMotionCount() const;
75
76   /**
77    * @copydoc Dali::Scene3D::MotionData::GetIndex()
78    */
79   Scene3D::MotionIndex GetIndex(uint32_t index) const;
80
81   /**
82    * @copydoc Dali::Scene3D::MotionData::GetValue()
83    */
84   Scene3D::MotionValue GetValue(uint32_t index) const;
85
86   /**
87    * @copydoc Dali::Scene3D::MotionData::Add()
88    */
89   void Add(Scene3D::MotionIndex index, Scene3D::MotionValue value);
90
91   /**
92    * @copydoc Dali::Scene3D::MotionData::Clear()
93    */
94   void Clear();
95
96   /**
97    * @copydoc Dali::Scene3D::MotionData::SetDuration()
98    */
99   void SetDuration(float durationSeconds);
100
101   /**
102    * @copydoc Dali::Scene3D::MotionData::GetDuration()
103    */
104   float GetDuration() const;
105
106   /**
107    * @copydoc Dali::Scene3D::MotionData::LoadBvh()
108    */
109   void LoadBvh(const std::string& path, bool useRootTranslationOnly, const Vector3& scale = Vector3::ONE, bool synchronousLoad = false);
110
111   /**
112    * @copydoc Dali::Scene3D::MotionData::LoadBvhFromBuffer()
113    */
114   void LoadBvhFromBuffer(const uint8_t* rawBuffer, int rawBufferLength, bool useRootTranslationOnly, const Vector3& scale = Vector3::ONE, bool synchronousLoad = false);
115
116   /**
117    * @copydoc Dali::Scene3D::MotionData::LoadFacialAnimation()
118    */
119   void LoadFacialAnimation(const std::string& url, bool synchronousLoad = false);
120
121   /**
122    * @copydoc Dali::Scene3D::MotionData::LoadFacialAnimationFromBuffer()
123    */
124   void LoadFacialAnimationFromBuffer(const uint8_t* rawBuffer, int rawBufferLength, bool synchronousLoad = false);
125
126 public:
127   /**
128    * @copydoc Dali::Scene3D::MotionData::LoadCompletedSignal()
129    */
130   Scene3D::MotionData::LoadCompletedSignalType& LoadCompletedSignal()
131   {
132     return mLoadCompletedSignal;
133   }
134
135 private:
136   /**
137    * @brief Request motion data load task process.
138    *
139    * @param[in] synchronousLoad True if we want to load result synchronously.
140    */
141   void RequestMotionDataLoad(bool synchronousLoad);
142
143   /**
144    * @brief Cancel requested motion data load task process.
145    */
146   void CancelMotionDataLoad();
147
148 private:
149   /**
150    * @brief Called when async load task completed.
151    *
152    * @param[in] task Completed tasks
153    */
154   void OnLoadCompleted(MotionDataLoadTaskPtr task);
155
156 private:
157   // Asynchronous loading variable
158   MotionDataLoadTaskPtr                        mMotionDataLoadTask{nullptr};
159   Scene3D::MotionData::LoadCompletedSignalType mLoadCompletedSignal;
160
161   std::vector<std::pair<Scene3D::MotionIndex, Scene3D::MotionValue>> mMotions{};
162
163   float mDurationSeconds{0.0f}; ///< Duration of animation if we generate this motion data as Dali::Animation.
164 };
165
166 } // namespace Internal
167
168 // Helpers for public-api forwarding methods
169
170 inline Internal::MotionData& GetImplementation(Dali::Scene3D::MotionData& motionData)
171 {
172   DALI_ASSERT_ALWAYS(motionData && "MotionData handle is empty");
173
174   BaseObject& handle = motionData.GetBaseObject();
175
176   return static_cast<Internal::MotionData&>(handle);
177 }
178
179 inline const Internal::MotionData& GetImplementation(const Dali::Scene3D::MotionData& motionData)
180 {
181   DALI_ASSERT_ALWAYS(motionData && "MotionData handle is empty");
182
183   const BaseObject& handle = motionData.GetBaseObject();
184
185   return static_cast<const Internal::MotionData&>(handle);
186 }
187
188 } // namespace Scene3D
189
190 } // namespace Dali
191
192 #endif // DALI_SCENE3D_MODEL_MOTION_MOTION_DATA_IMPL_H