2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-scene3d/internal/model-motion/motion-data-load-task.h>
22 #include <dali/integration-api/debug.h>
25 #include <dali-scene3d/public-api/loader/bvh-loader.h>
26 #include <dali-scene3d/public-api/loader/facial-animation-loader.h>
34 MotionDataLoadTask::MotionDataLoadTask(const std::string& path, const Vector3& scale, CallbackBase* callback)
35 : AsyncTask(callback),
40 mAnimationDefinition{},
41 mLoadMethod(MotionDataLoadTask::LoadMethod::BVH_FILE)
45 MotionDataLoadTask::MotionDataLoadTask(const uint8_t* rawBuffer, int rawBufferLength, const Vector3& scale, CallbackBase* callback)
46 : AsyncTask(callback),
49 mRawBufferLength(rawBufferLength),
51 mAnimationDefinition{},
52 mLoadMethod(MotionDataLoadTask::LoadMethod::BVH_BUFFER)
54 // To keep life of raw buffer, let we copy data now.
55 mRawBuffer = new uint8_t[mRawBufferLength];
56 memcpy(mRawBuffer, rawBuffer, sizeof(uint8_t) * mRawBufferLength);
59 MotionDataLoadTask::MotionDataLoadTask(const std::string& url, CallbackBase* callback)
60 : AsyncTask(callback),
65 mAnimationDefinition{},
66 mLoadMethod(MotionDataLoadTask::LoadMethod::FACIAL_FILE)
70 MotionDataLoadTask::MotionDataLoadTask(const uint8_t* rawBuffer, int rawBufferLength, CallbackBase* callback)
71 : AsyncTask(callback),
74 mRawBufferLength(rawBufferLength),
76 mAnimationDefinition{},
77 mLoadMethod(MotionDataLoadTask::LoadMethod::FACIAL_BUFFER)
79 // To keep life of raw buffer, let we copy data now.
80 mRawBuffer = new uint8_t[mRawBufferLength];
81 memcpy(mRawBuffer, rawBuffer, sizeof(uint8_t) * mRawBufferLength);
84 MotionDataLoadTask::~MotionDataLoadTask()
92 void MotionDataLoadTask::Process()
96 case LoadMethod::BVH_FILE:
98 mAnimationDefinition = std::move(Loader::LoadBvh(mFileUrl, "LoadedBvhMotionData", mScale));
101 case LoadMethod::BVH_BUFFER:
103 mAnimationDefinition = std::move(Loader::LoadBvhFromBuffer(mRawBuffer, mRawBufferLength, "LoadedBvhMotionData", mScale));
106 case LoadMethod::FACIAL_FILE:
108 mAnimationDefinition = std::move(Loader::LoadFacialAnimation(mFileUrl));
111 case LoadMethod::FACIAL_BUFFER:
113 mAnimationDefinition = std::move(Loader::LoadFacialAnimationFromBuffer(mRawBuffer, mRawBufferLength));
119 bool MotionDataLoadTask::IsReady()
124 const Scene3D::Loader::AnimationDefinition& MotionDataLoadTask::GetAnimationDefinition() const
126 return mAnimationDefinition;
129 } // namespace Internal
131 } // namespace Scene3D