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, bool useRootTranslationOnly, const Vector3& scale, CallbackBase* callback)
35 : AsyncTask(callback),
40 mUseRootTranslationOnly(useRootTranslationOnly),
41 mAnimationDefinition{},
42 mLoadMethod(MotionDataLoadTask::LoadMethod::BVH_FILE)
46 MotionDataLoadTask::MotionDataLoadTask(const uint8_t* rawBuffer, int rawBufferLength, bool useRootTranslationOnly, const Vector3& scale, CallbackBase* callback)
47 : AsyncTask(callback),
50 mRawBufferLength(rawBufferLength),
52 mUseRootTranslationOnly(useRootTranslationOnly),
53 mAnimationDefinition{},
54 mLoadMethod(MotionDataLoadTask::LoadMethod::BVH_BUFFER)
56 // To keep life of raw buffer, let us copy data now.
57 mRawBuffer = new uint8_t[mRawBufferLength];
58 memcpy(mRawBuffer, rawBuffer, sizeof(uint8_t) * mRawBufferLength);
61 MotionDataLoadTask::MotionDataLoadTask(const std::string& url, CallbackBase* callback)
62 : AsyncTask(callback),
67 mUseRootTranslationOnly(false),
68 mAnimationDefinition{},
69 mLoadMethod(MotionDataLoadTask::LoadMethod::FACIAL_FILE)
73 MotionDataLoadTask::MotionDataLoadTask(const uint8_t* rawBuffer, int rawBufferLength, CallbackBase* callback)
74 : AsyncTask(callback),
77 mRawBufferLength(rawBufferLength),
79 mUseRootTranslationOnly(false),
80 mAnimationDefinition{},
81 mLoadMethod(MotionDataLoadTask::LoadMethod::FACIAL_BUFFER)
83 // To keep life of raw buffer, let us copy data now.
84 mRawBuffer = new uint8_t[mRawBufferLength];
85 memcpy(mRawBuffer, rawBuffer, sizeof(uint8_t) * mRawBufferLength);
88 MotionDataLoadTask::~MotionDataLoadTask()
96 void MotionDataLoadTask::Process()
100 case LoadMethod::BVH_FILE:
102 mAnimationDefinition = std::move(Loader::LoadBvh(mFileUrl, "LoadedBvhMotionData", mUseRootTranslationOnly, mScale));
105 case LoadMethod::BVH_BUFFER:
107 mAnimationDefinition = std::move(Loader::LoadBvhFromBuffer(mRawBuffer, mRawBufferLength, "LoadedBvhMotionData", mUseRootTranslationOnly, mScale));
110 case LoadMethod::FACIAL_FILE:
112 mAnimationDefinition = std::move(Loader::LoadFacialAnimation(mFileUrl));
115 case LoadMethod::FACIAL_BUFFER:
117 mAnimationDefinition = std::move(Loader::LoadFacialAnimationFromBuffer(mRawBuffer, mRawBufferLength));
123 bool MotionDataLoadTask::IsReady()
128 const Scene3D::Loader::AnimationDefinition& MotionDataLoadTask::GetAnimationDefinition() const
130 return mAnimationDefinition;
133 } // namespace Internal
135 } // namespace Scene3D