/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// EXTERNAL INCLUDES
#include <dali/devel-api/adaptor-framework/file-stream.h>
+#include <dali/devel-api/animation/key-frames-devel.h>
#include <dali/integration-api/debug.h>
#include <fstream>
return parseHierarchy && parseMotion;
}
-AnimationDefinition GenerateAnimation(const std::string& animationName, std::shared_ptr<Joint>& hierarchy, uint32_t frameCount, float frameTime, const Vector3& scale)
+AnimationDefinition GenerateAnimation(const std::string& animationName, std::shared_ptr<Joint>& hierarchy, uint32_t frameCount, float frameTime, bool useRootTranslationOnly, const Vector3& scale)
{
AnimationDefinition animationDefinition;
if(!jointList.empty())
{
- animationDefinition.ReserveSize(jointList.size() * 2u); // translation and rotation
+ uint32_t animationSize = jointList.size();
+ animationSize = (useRootTranslationOnly) ? (animationSize + 1u) : (animationSize * 2u);
+ animationDefinition.ReserveSize(animationSize);
+ uint32_t animationIndex = 0u;
for(uint32_t i = 0; i < jointList.size(); ++i)
{
AnimatedProperty translationProperty;
- translationProperty.mTimePeriod = Dali::TimePeriod(animationDefinition.GetDuration());
- translationProperty.mNodeName = jointList[i]->name;
- translationProperty.mPropertyName = PROPERTY_NAME_POSITION.data();
+ if(!useRootTranslationOnly || i == 0)
+ {
+ translationProperty.mTimePeriod = Dali::TimePeriod(animationDefinition.GetDuration());
+ translationProperty.mNodeName = jointList[i]->name;
+ translationProperty.mPropertyName = PROPERTY_NAME_POSITION.data();
+ }
AnimatedProperty rotationProperty;
rotationProperty.mTimePeriod = Dali::TimePeriod(animationDefinition.GetDuration());
rotationProperty.mKeyFrames = Dali::KeyFrames::New();
for(uint32_t j = 0; j < frameCount; ++j)
{
- translationProperty.mKeyFrames.Add(static_cast<float>(j) * keyFrameInterval, (jointList[i]->translations[j] * scale));
+ if(!useRootTranslationOnly || i == 0)
+ {
+ translationProperty.mKeyFrames.Add(static_cast<float>(j) * keyFrameInterval, (jointList[i]->translations[j] * scale));
+ }
rotationProperty.mKeyFrames.Add(static_cast<float>(j) * keyFrameInterval, jointList[i]->rotations[j]);
}
- animationDefinition.SetProperty(i * 2u, std::move(translationProperty));
- animationDefinition.SetProperty(i * 2u + 1, std::move(rotationProperty));
+ if(!useRootTranslationOnly || i == 0)
+ {
+ // Optimize keyframes, for heuristic!
+ DevelKeyFrames::OptimizeKeyFramesLinear(translationProperty.mKeyFrames);
+ animationDefinition.SetProperty(animationIndex++, std::move(translationProperty));
+ }
+ // Optimize keyframes, for heuristic!
+ DevelKeyFrames::OptimizeKeyFramesLinear(rotationProperty.mKeyFrames);
+ animationDefinition.SetProperty(animationIndex++, std::move(rotationProperty));
}
}
return animationDefinition;
}
-AnimationDefinition LoadBvhInternal(std::istream& stream, const std::string& animationName, const Vector3& scale)
+AnimationDefinition LoadBvhInternal(std::istream& stream, const std::string& animationName, bool useRootTranslationOnly, const Vector3& scale)
{
uint32_t frameCount = 0;
float frameTime = 0.0f;
return animationDefinition;
}
- return GenerateAnimation(animationName, rootJoint, frameCount, frameTime, scale);
+ return GenerateAnimation(animationName, rootJoint, frameCount, frameTime, useRootTranslationOnly, scale);
}
} // namespace
-AnimationDefinition LoadBvh(const std::string& path, const std::string& animationName, const Vector3& scale)
+AnimationDefinition LoadBvh(const std::string& path, const std::string& animationName, bool useRootTranslationOnly, const Vector3& scale)
{
Dali::FileStream fileStream(path);
std::iostream& stream = fileStream.GetStream();
return animationDefinition;
}
- return LoadBvhInternal(stream, animationName, scale);
+ return LoadBvhInternal(stream, animationName, useRootTranslationOnly, scale);
}
-AnimationDefinition LoadBvhFromBuffer(const uint8_t* rawBuffer, int rawBufferLength, const std::string& animationName, const Vector3& scale)
+AnimationDefinition LoadBvhFromBuffer(const uint8_t* rawBuffer, int rawBufferLength, const std::string& animationName, bool useRootTranslationOnly, const Vector3& scale)
{
if(rawBuffer == nullptr || rawBufferLength == 0)
{
return animationDefinition;
}
- return LoadBvhInternal(stream, animationName, scale);
+ return LoadBvhInternal(stream, animationName, useRootTranslationOnly, scale);
}
} // namespace Dali::Scene3D::Loader
\ No newline at end of file