}
DALI_TEST_EQUAL(ctx.loadResult.mAnimationDefinitions.size(), 1u);
- DALI_TEST_EQUAL(ctx.loadResult.mAnimationDefinitions[0].mProperties.size(), 57u);
+ DALI_TEST_EQUAL(ctx.loadResult.mAnimationDefinitions[0].GetPropertyCount(), 57u);
- uint32_t id = ctx.loadResult.mScene.GetNode(ctx.loadResult.mAnimationDefinitions[0].mProperties[0].mNodeIndex)->mNodeId;
+ uint32_t id = ctx.loadResult.mScene.GetNode(ctx.loadResult.mAnimationDefinitions[0].GetPropertyAt(0).mNodeIndex)->mNodeId;
DALI_TEST_EQUAL(id, root.FindChildByName("Skeleton_torso_joint_1").GetProperty<int32_t>(Dali::Actor::Property::ID));
END_TEST;
return actor.FindChildByName(property.mNodeName);
};
+ uint32_t animatedPropertyIndex = 0;
for (bool b: { false, true })
{
AnimationDefinition animDef;
- animDef.mName = "WalkRight";
- animDef.mDuration = 10.f;
- animDef.mLoopCount = 2;
- animDef.mEndAction = Animation::BAKE_FINAL;
- animDef.mSpeedFactor = .7f;
- animDef.mProperties.push_back(AnimatedProperty{
+ animDef.SetName("WalkRight");
+ animDef.SetDuration(10.f);
+ animDef.SetLoopCount(2);
+ animDef.SetEndAction(Animation::BAKE_FINAL);
+ animDef.SetSpeedFactor(.7f);
+ animDef.SetProperty(animatedPropertyIndex++,std::move(AnimatedProperty{
INVALID_INDEX,
"ChristopherPlummer",
"position",
b
} },
AlphaFunction::EASE_OUT,
- TimePeriod(animDef.mDuration)
- });
+ TimePeriod(animDef.GetDuration())
+ }));
auto anim = animDef.ReAnimate(getActor);
- DALI_TEST_EQUAL(anim.GetDuration(), animDef.mDuration);
- DALI_TEST_EQUAL(anim.GetEndAction(), animDef.mEndAction);
- DALI_TEST_EQUAL(anim.GetSpeedFactor(), animDef.mSpeedFactor);
- DALI_TEST_EQUAL(anim.GetLoopCount(), animDef.mLoopCount);
+ DALI_TEST_EQUAL(anim.GetDuration(), animDef.GetDuration());
+ DALI_TEST_EQUAL(anim.GetEndAction(), animDef.GetEndAction());
+ DALI_TEST_EQUAL(anim.GetSpeedFactor(), animDef.GetSpeedFactor());
+ DALI_TEST_EQUAL(anim.GetLoopCount(), animDef.GetLoopCount());
}
END_TEST;
kf.Add(0.f, Vector3::ZERO);
kf.Add(1.f, Vector3::XAXIS * 100.f);
+ uint32_t animatedPropertyIndex = 0;
AnimationDefinition animDef;
- animDef.mName = "WalkRight";
- animDef.mDuration = 10.f;
- animDef.mLoopCount = 2;
- animDef.mEndAction = Animation::BAKE_FINAL;
- animDef.mSpeedFactor = .7f;
- animDef.mProperties.push_back(AnimatedProperty{
+ animDef.SetName("WalkRight");
+ animDef.SetDuration(10.f);
+ animDef.SetLoopCount(2);
+ animDef.SetEndAction(Animation::BAKE_FINAL);
+ animDef.SetSpeedFactor(.7f);
+ animDef.SetProperty(animatedPropertyIndex++, std::move(AnimatedProperty{
INVALID_INDEX,
"ChristopherPlummer",
"position",
kf,
nullptr,
AlphaFunction::EASE_OUT,
- TimePeriod(animDef.mDuration)
- });
+ TimePeriod(animDef.GetDuration())
+ }));
auto anim = animDef.ReAnimate(getActor);
- DALI_TEST_EQUAL(anim.GetDuration(), animDef.mDuration);
- DALI_TEST_EQUAL(anim.GetEndAction(), animDef.mEndAction);
- DALI_TEST_EQUAL(anim.GetSpeedFactor(), animDef.mSpeedFactor);
- DALI_TEST_EQUAL(anim.GetLoopCount(), animDef.mLoopCount);
+ DALI_TEST_EQUAL(anim.GetDuration(), animDef.GetDuration());
+ DALI_TEST_EQUAL(anim.GetEndAction(), animDef.GetEndAction());
+ DALI_TEST_EQUAL(anim.GetSpeedFactor(), animDef.GetSpeedFactor());
+ DALI_TEST_EQUAL(anim.GetLoopCount(), animDef.GetLoopCount());
END_TEST;
}
AnimationDefinition animDef = LoadBvh(TEST_RESOURCE_DIR "/test.bvh", "testBvh");
- DALI_TEST_EQUAL(animDef.mName, "testBvh");
- DALI_TEST_EQUAL(animDef.mDuration, 0.3f);
+ DALI_TEST_EQUAL(animDef.GetName(), "testBvh");
+ DALI_TEST_EQUAL(animDef.GetDuration(), 0.3f);
- DALI_TEST_EQUAL(animDef.mProperties[0].mNodeName, "root");
- DALI_TEST_EQUAL(animDef.mProperties[0].mPropertyName, "position");
- DALI_TEST_EQUAL(animDef.mProperties[0].mKeyFrames.GetType(), Property::Type::VECTOR3);
- DALI_TEST_EQUAL(animDef.mProperties[0].mTimePeriod.durationSeconds, 0.3f);
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(0).mNodeName, "root");
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(0).mPropertyName, "position");
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(0).mKeyFrames.GetType(), Property::Type::VECTOR3);
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(0).mTimePeriod.durationSeconds, 0.3f);
- DALI_TEST_EQUAL(animDef.mProperties[1].mNodeName, "root");
- DALI_TEST_EQUAL(animDef.mProperties[1].mPropertyName, "orientation");
- DALI_TEST_EQUAL(animDef.mProperties[1].mKeyFrames.GetType(), Property::Type::ROTATION);
- DALI_TEST_EQUAL(animDef.mProperties[1].mTimePeriod.durationSeconds, 0.3f);
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(1).mNodeName, "root");
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(1).mPropertyName, "orientation");
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(1).mKeyFrames.GetType(), Property::Type::ROTATION);
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(1).mTimePeriod.durationSeconds, 0.3f);
- DALI_TEST_EQUAL(animDef.mProperties[2].mNodeName, "first");
- DALI_TEST_EQUAL(animDef.mProperties[2].mPropertyName, "position");
- DALI_TEST_EQUAL(animDef.mProperties[2].mKeyFrames.GetType(), Property::Type::VECTOR3);
- DALI_TEST_EQUAL(animDef.mProperties[2].mTimePeriod.durationSeconds, 0.3f);
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(2).mNodeName, "first");
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(2).mPropertyName, "position");
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(2).mKeyFrames.GetType(), Property::Type::VECTOR3);
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(2).mTimePeriod.durationSeconds, 0.3f);
- DALI_TEST_EQUAL(animDef.mProperties[3].mNodeName, "first");
- DALI_TEST_EQUAL(animDef.mProperties[3].mPropertyName, "orientation");
- DALI_TEST_EQUAL(animDef.mProperties[3].mKeyFrames.GetType(), Property::Type::ROTATION);
- DALI_TEST_EQUAL(animDef.mProperties[3].mTimePeriod.durationSeconds, 0.3f);
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(3).mNodeName, "first");
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(3).mPropertyName, "orientation");
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(3).mKeyFrames.GetType(), Property::Type::ROTATION);
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(3).mTimePeriod.durationSeconds, 0.3f);
Actor root = Actor::New();
root.SetProperty(Actor::Property::NAME, "root");
};
Animation animation = animDef.ReAnimate(getActor);
- DALI_TEST_EQUAL(animation.GetDuration(), animDef.mDuration);
+ DALI_TEST_EQUAL(animation.GetDuration(), animDef.GetDuration());
application.GetScene().Add(root);
TestApplication application;
AnimationDefinition animDef = LoadBvh("/nothing.bvh", "testBvh");
- DALI_TEST_EQUALS(0u, animDef.mProperties.size(), TEST_LOCATION);
+ DALI_TEST_EQUALS(0u, animDef.GetPropertyCount(), TEST_LOCATION);
END_TEST;
}
AnimationDefinition animDef = LoadFacialAnimation(TEST_RESOURCE_DIR "/facial-blendshape-animation.json");
- DALI_TEST_EQUAL(animDef.mName, "Facial_Blendshape_Animation");
- DALI_TEST_EQUAL(animDef.mDuration, 14.966001f);
- DALI_TEST_EQUAL(animDef.mEndAction, Animation::BAKE);
- DALI_TEST_EQUAL(animDef.mSpeedFactor, 1.0f);
- DALI_TEST_EQUAL(animDef.mLoopCount, 1);
- DALI_TEST_EQUAL(animDef.mProperties.size(), 122);
+ std::string name = animDef.GetName();
+ DALI_TEST_EQUAL(name, "Facial_Blendshape_Animation");
+ DALI_TEST_EQUAL(animDef.GetDuration(), 14.966001f);
+ DALI_TEST_EQUAL(animDef.GetEndAction(), Animation::BAKE);
+ DALI_TEST_EQUAL(animDef.GetSpeedFactor(), 1.0f);
+ DALI_TEST_EQUAL(animDef.GetLoopCount(), 1);
+ DALI_TEST_EQUAL(animDef.GetPropertyCount(), 122);
- DALI_TEST_EQUAL(animDef.mProperties[0].mNodeName, "GEO_1");
- DALI_TEST_EQUAL(animDef.mProperties[0].mPropertyName, "uBlendShapeWeight[0]");
- DALI_TEST_EQUAL(animDef.mProperties[0].mKeyFrames.GetType(), Property::Type::FLOAT);
- DALI_TEST_EQUAL(animDef.mProperties[0].mTimePeriod.delaySeconds, 0.0f);
- DALI_TEST_EQUAL(animDef.mProperties[0].mTimePeriod.durationSeconds, 14.966001f);
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(0).mNodeName, "GEO_1");
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(0).mPropertyName, "uBlendShapeWeight[0]");
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(0).mKeyFrames.GetType(), Property::Type::FLOAT);
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(0).mTimePeriod.delaySeconds, 0.0f);
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(0).mTimePeriod.durationSeconds, 14.966001f);
- DALI_TEST_EQUAL(animDef.mProperties[69].mNodeName, "GEO_2");
- DALI_TEST_EQUAL(animDef.mProperties[69].mPropertyName, "uBlendShapeWeight[1]");
- DALI_TEST_EQUAL(animDef.mProperties[69].mKeyFrames.GetType(), Property::Type::FLOAT);
- DALI_TEST_EQUAL(animDef.mProperties[69].mTimePeriod.delaySeconds, 0.0f);
- DALI_TEST_EQUAL(animDef.mProperties[69].mTimePeriod.durationSeconds, 14.966001f);
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(69).mNodeName, "GEO_2");
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(69).mPropertyName, "uBlendShapeWeight[1]");
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(69).mKeyFrames.GetType(), Property::Type::FLOAT);
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(69).mTimePeriod.delaySeconds, 0.0f);
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(69).mTimePeriod.durationSeconds, 14.966001f);
- DALI_TEST_EQUAL(animDef.mProperties[86].mNodeName, "GEO_3");
- DALI_TEST_EQUAL(animDef.mProperties[86].mPropertyName, "uBlendShapeWeight[2]");
- DALI_TEST_EQUAL(animDef.mProperties[86].mKeyFrames.GetType(), Property::Type::FLOAT);
- DALI_TEST_EQUAL(animDef.mProperties[86].mTimePeriod.delaySeconds, 0.0f);
- DALI_TEST_EQUAL(animDef.mProperties[86].mTimePeriod.durationSeconds, 14.966001f);
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(86).mNodeName, "GEO_3");
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(86).mPropertyName, "uBlendShapeWeight[2]");
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(86).mKeyFrames.GetType(), Property::Type::FLOAT);
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(86).mTimePeriod.delaySeconds, 0.0f);
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(86).mTimePeriod.durationSeconds, 14.966001f);
- DALI_TEST_EQUAL(animDef.mProperties[100].mNodeName, "GEO_4");
- DALI_TEST_EQUAL(animDef.mProperties[100].mPropertyName, "uBlendShapeWeight[7]");
- DALI_TEST_EQUAL(animDef.mProperties[100].mKeyFrames.GetType(), Property::Type::FLOAT);
- DALI_TEST_EQUAL(animDef.mProperties[100].mTimePeriod.delaySeconds, 0.0f);
- DALI_TEST_EQUAL(animDef.mProperties[100].mTimePeriod.durationSeconds, 14.966001f);
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(100).mNodeName, "GEO_4");
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(100).mPropertyName, "uBlendShapeWeight[7]");
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(100).mKeyFrames.GetType(), Property::Type::FLOAT);
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(100).mTimePeriod.delaySeconds, 0.0f);
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(100).mTimePeriod.durationSeconds, 14.966001f);
- DALI_TEST_EQUAL(animDef.mProperties[121].mNodeName, "GEO_5");
- DALI_TEST_EQUAL(animDef.mProperties[121].mPropertyName, "uBlendShapeWeight[19]");
- DALI_TEST_EQUAL(animDef.mProperties[121].mKeyFrames.GetType(), Property::Type::FLOAT);
- DALI_TEST_EQUAL(animDef.mProperties[121].mTimePeriod.delaySeconds, 0.0f);
- DALI_TEST_EQUAL(animDef.mProperties[121].mTimePeriod.durationSeconds, 14.966001f);
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(121).mNodeName, "GEO_5");
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(121).mPropertyName, "uBlendShapeWeight[19]");
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(121).mKeyFrames.GetType(), Property::Type::FLOAT);
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(121).mTimePeriod.delaySeconds, 0.0f);
+ DALI_TEST_EQUAL(animDef.GetPropertyAt(121).mTimePeriod.durationSeconds, 14.966001f);
auto actor = Actor::New();
actor.SetProperty(Actor::Property::NAME, "GEO_1");
};
auto anim = animDef.ReAnimate(getActor);
- DALI_TEST_EQUAL(anim.GetDuration(), animDef.mDuration);
- DALI_TEST_EQUAL(anim.GetEndAction(), animDef.mEndAction);
- DALI_TEST_EQUAL(anim.GetSpeedFactor(), animDef.mSpeedFactor);
- DALI_TEST_EQUAL(anim.GetLoopCount(), animDef.mLoopCount);
+ DALI_TEST_EQUAL(anim.GetDuration(), animDef.GetDuration());
+ DALI_TEST_EQUAL(anim.GetEndAction(), animDef.GetEndAction());
+ DALI_TEST_EQUAL(anim.GetSpeedFactor(), animDef.GetSpeedFactor());
+ DALI_TEST_EQUAL(anim.GetLoopCount(), animDef.GetLoopCount());
END_TEST;
}
for(auto&& animation : mModelLoadTask->GetAnimations())
{
Dali::Animation anim = animation.ReAnimate(getActor);
- mAnimations.push_back({animation.mName, anim});
+ mAnimations.push_back({animation.GetName(), anim});
}
}
}
++iAnim)
{
const TreeNode& tnAnim = (*iAnim).second;
+ uint32_t animationPropertyIndex = 0;
AnimationDefinition animDef;
- ReadString(tnAnim.GetChild(NAME), animDef.mName);
+ std::string animationName;
+ ReadString(tnAnim.GetChild(NAME), animationName);
+ animDef.SetName(animationName);
- auto iFind = std::lower_bound(definitions.begin(), definitions.end(), animDef, [](const AnimationDefinition& ad0, const AnimationDefinition& ad1) { return ad0.mName < ad1.mName; });
- const bool overwrite = iFind != definitions.end() && iFind->mName == animDef.mName;
+ auto iFind = std::lower_bound(definitions.begin(), definitions.end(), animDef, [](const AnimationDefinition& ad0, const AnimationDefinition& ad1) { return ad0.GetName() < ad1.GetName(); });
+ const bool overwrite = iFind != definitions.end() && iFind->GetName() == animDef.GetName();
if(overwrite)
{
- mOnError(FormatString("Pre-existing animation with name '%s' is being overwritten.", animDef.mName.c_str()));
+ mOnError(FormatString("Pre-existing animation with name '%s' is being overwritten.", animDef.GetName().c_str()));
}
// Duration -- We need something that animated properties' delay / duration can
// be expressed as a multiple of; 0 won't work. This is small enough (i.e. shorter
// than our frame delay) to not be restrictive WRT replaying. If anything needs
// to occur more frequently, then Animations are likely not your solution anyway.
- animDef.mDuration = AnimationDefinition::MIN_DURATION_SECONDS;
- if(!ReadFloat(tnAnim.GetChild("duration"), animDef.mDuration))
+ animDef.SetDuration(AnimationDefinition::MIN_DURATION_SECONDS);
+ float animationDuration;
+ if(!ReadFloat(tnAnim.GetChild("duration"), animationDuration))
{
+ animDef.SetDuration(animationDuration);
mOnError(FormatString("Animation '%s' fails to define '%s', defaulting to %f.",
- animDef.mName.c_str(),
+ animDef.GetName().c_str(),
"duration",
- animDef.mDuration));
+ animDef.GetDuration()));
}
// Get loop count - # of playbacks. Default is once. 0 means repeat indefinitely.
- animDef.mLoopCount = 1;
- if(ReadInt(tnAnim.GetChild("loopCount"), animDef.mLoopCount) &&
- animDef.mLoopCount < 0)
+ int32_t animationLoopCount = 1;
+ if(ReadInt(tnAnim.GetChild("loopCount"), animationLoopCount) && animationLoopCount < 0)
{
- animDef.mLoopCount = 0;
+ animationLoopCount = 0;
}
+ animDef.SetLoopCount(animationLoopCount);
std::string endAction;
if(ReadString(tnAnim.GetChild("endAction"), endAction))
{
if("BAKE" == endAction)
{
- animDef.mEndAction = Animation::BAKE;
+ animDef.SetEndAction(Animation::BAKE);
}
else if("DISCARD" == endAction)
{
- animDef.mEndAction = Animation::DISCARD;
+ animDef.SetEndAction(Animation::DISCARD);
}
else if("BAKE_FINAL" == endAction)
{
- animDef.mEndAction = Animation::BAKE_FINAL;
+ animDef.SetEndAction(Animation::BAKE_FINAL);
}
}
{
if("BAKE" == endAction)
{
- animDef.mDisconnectAction = Animation::BAKE;
+ animDef.SetDisconnectAction(Animation::BAKE);
}
else if("DISCARD" == endAction)
{
- animDef.mDisconnectAction = Animation::DISCARD;
+ animDef.SetDisconnectAction(Animation::DISCARD);
}
else if("BAKE_FINAL" == endAction)
{
- animDef.mDisconnectAction = Animation::BAKE_FINAL;
+ animDef.SetDisconnectAction(Animation::BAKE_FINAL);
}
}
if(const TreeNode* tnProperties = tnAnim.GetChild("properties"))
{
- animDef.mProperties.reserve(tnProperties->Size());
+ animDef.ReserveSize(tnProperties->Size());
for(TreeNode::ConstIterator iProperty = tnProperties->CBegin(), iPropertyEnd = tnProperties->CEnd();
iProperty != iPropertyEnd;
++iProperty)
AnimatedProperty animProp;
if(!ReadString(tnProperty.GetChild("node"), animProp.mNodeName))
{
- mOnError(FormatString("Animation '%s': Failed to read the 'node' tag.", animDef.mName.c_str()));
+ mOnError(FormatString("Animation '%s': Failed to read the 'node' tag.", animDef.GetName().c_str()));
continue;
}
if(!ReadString(tnProperty.GetChild("property"), animProp.mPropertyName))
{
- mOnError(FormatString("Animation '%s': Failed to read the 'property' tag", animDef.mName.c_str()));
+ mOnError(FormatString("Animation '%s': Failed to read the 'property' tag", animDef.GetName().c_str()));
continue;
}
// these are the defaults
animProp.mTimePeriod.delaySeconds = 0.f;
- animProp.mTimePeriod.durationSeconds = animDef.mDuration;
+ animProp.mTimePeriod.durationSeconds = animDef.GetDuration();
if(!ReadTimePeriod(tnProperty.GetChild("timePeriod"), animProp.mTimePeriod))
{
mOnError(FormatString("Animation '%s': timePeriod missing in Property #%d: defaulting to %f.",
- animDef.mName.c_str(),
- animDef.mProperties.size(),
+ animDef.GetName().c_str(),
+ animDef.GetPropertyCount(),
animProp.mTimePeriod.durationSeconds));
}
}
}
- animDef.mProperties.push_back(std::move(animProp));
+ animDef.SetProperty(animationPropertyIndex++, std::move(animProp));
}
}
return duration;
}
-float LoadBlendShapeKeyFrames(ConversionContext& context, const gltf2::Animation::Channel& channel, Index nodeIndex, uint32_t& propertyIndex, std::vector<Dali::Scene3D::Loader::AnimatedProperty>& properties)
+float LoadBlendShapeKeyFrames(ConversionContext& context, const gltf2::Animation::Channel& channel, Index nodeIndex, uint32_t& propertyIndex, AnimationDefinition& animationDefinition)
{
const gltf2::Accessor& input = *channel.mSampler->mInput;
const gltf2::Accessor& output = *channel.mSampler->mOutput;
const auto remainingSize = sizeof(weightNameBuffer) - prefixSize;
for(uint32_t weightIndex = 0u, endWeightIndex = channel.mSampler->mOutput->mCount / channel.mSampler->mInput->mCount; weightIndex < endWeightIndex; ++weightIndex)
{
- AnimatedProperty& animatedProperty = properties[propertyIndex++];
+ AnimatedProperty animatedProperty;
animatedProperty.mNodeIndex = nodeIndex;
snprintf(pWeightName, remainingSize, "%d]", weightIndex);
}
animatedProperty.mTimePeriod = {0.f, duration};
+
+ animationDefinition.SetProperty(propertyIndex++, std::move(animatedProperty));
}
return duration;
template<typename T>
float LoadAnimation(AnimationDefinition& animationDefinition, Index nodeIndex, Index propertyIndex, const std::string& propertyName, const gltf2::Animation::Channel& channel, ConversionContext& context)
{
- AnimatedProperty& animatedProperty = animationDefinition.mProperties[propertyIndex];
-
+ AnimatedProperty animatedProperty;
animatedProperty.mNodeIndex = nodeIndex;
animatedProperty.mPropertyName = propertyName;
float duration = LoadKeyFrames<T>(context, channel, animatedProperty.mKeyFrames, channel.mTarget.mPath);
animatedProperty.mTimePeriod = {0.f, duration};
+ animationDefinition.SetProperty(propertyIndex, std::move(animatedProperty));
return duration;
}
if(!animation.mName.empty())
{
- animationDefinition.mName = animation.mName;
+ animationDefinition.SetName(animation.mName.data());
}
uint32_t numberOfProperties = 0u;
numberOfProperties++;
}
}
- animationDefinition.mProperties.resize(numberOfProperties);
+ animationDefinition.ReserveSize(numberOfProperties);
Index propertyIndex = 0u;
for(const auto& channel : animation.mChannels)
}
case gltf2::Animation::Channel::Target::WEIGHTS:
{
- duration = LoadBlendShapeKeyFrames(context, channel, nodeIndex, propertyIndex, animationDefinition.mProperties);
+ duration = LoadBlendShapeKeyFrames(context, channel, nodeIndex, propertyIndex, animationDefinition);
break;
}
}
}
- animationDefinition.mDuration = std::max(duration, animationDefinition.mDuration);
+ animationDefinition.SetDuration(std::max(duration, animationDefinition.GetDuration()));
++propertyIndex;
}
{
}
+AnimationDefinition& AnimationDefinition::operator=(AnimationDefinition&& other)
+{
+ AnimationDefinition tmp(std::move(other));
+ mName = std::move(tmp.mName);
+ mDuration = tmp.mDuration;
+ mLoopCount = tmp.mLoopCount;
+ mDisconnectAction = tmp.mDisconnectAction;
+ mEndAction = tmp.mEndAction;
+ mSpeedFactor = tmp.mSpeedFactor;
+ mPlayRange = tmp.mPlayRange;
+ mProperties.swap(tmp.mProperties);
+ return *this;
+}
+
void AnimationDefinition::Animate(Animation& animation, AnimatedProperty::GetActor getActor)
{
DALI_ASSERT_ALWAYS(animation);
return animation;
}
-AnimationDefinition& AnimationDefinition::operator=(AnimationDefinition&& other)
+void AnimationDefinition::SetName(const std::string& name)
{
- AnimationDefinition tmp(std::move(other));
- mName = std::move(tmp.mName);
- mDuration = tmp.mDuration;
- mLoopCount = tmp.mLoopCount;
- mDisconnectAction = tmp.mDisconnectAction;
- mEndAction = tmp.mEndAction;
- mSpeedFactor = tmp.mSpeedFactor;
- mPlayRange = tmp.mPlayRange;
- mProperties.swap(tmp.mProperties);
- return *this;
+ mName = name;
+}
+
+const std::string& AnimationDefinition::GetName() const
+{
+ return mName;
+}
+
+void AnimationDefinition::SetDuration(float duration)
+{
+ mDuration = duration;
+}
+
+float AnimationDefinition::GetDuration() const
+{
+ return mDuration;
+}
+
+void AnimationDefinition::SetLoopCount(int32_t loopCount)
+{
+ mLoopCount = loopCount;
+}
+
+int AnimationDefinition::GetLoopCount() const
+{
+ return mLoopCount;
+}
+
+void AnimationDefinition::SetDisconnectAction(Animation::EndAction disconnectAction)
+{
+ mDisconnectAction = disconnectAction;
+}
+
+Animation::EndAction AnimationDefinition::GetDisconnectAction() const
+{
+ return mDisconnectAction;
+}
+
+void AnimationDefinition::SetEndAction(Animation::EndAction endAction)
+{
+ mEndAction = endAction;
+}
+
+Animation::EndAction AnimationDefinition::GetEndAction() const
+{
+ return mEndAction;
+}
+
+void AnimationDefinition::SetSpeedFactor(float speedFactor)
+{
+ mSpeedFactor = speedFactor;
+}
+
+float AnimationDefinition::GetSpeedFactor() const
+{
+ return mSpeedFactor;
+}
+
+void AnimationDefinition::SetPlayRange(const Vector2& playRange)
+{
+ mPlayRange = playRange;
+}
+
+Vector2 AnimationDefinition::GetPlayRange() const
+{
+ return mPlayRange;
+}
+
+void AnimationDefinition::ReserveSize(uint32_t size)
+{
+ mProperties.reserve(size);
+}
+
+uint32_t AnimationDefinition::GetPropertyCount()
+{
+ return mProperties.size();
+}
+
+void AnimationDefinition::SetProperty(uint32_t index, AnimatedProperty&& property)
+{
+ if(mProperties.size() <= index)
+ {
+ mProperties.resize(index + 1);
+ }
+ mProperties[index] = std::move(property);
+}
+
+const AnimatedProperty& AnimationDefinition::GetPropertyAt(uint32_t index)
+{
+ return mProperties[index];
}
} // namespace Dali::Scene3D::Loader
AnimationDefinition(AnimationDefinition&& other);
+ AnimationDefinition& operator=(AnimationDefinition&& other);
+
/**
* @brief Registers the properties against the given @a animation. @a getActor
* will be used to obtain the Actors for each AnimatedProperty.
*/
Animation ReAnimate(AnimatedProperty::GetActor getActor);
- AnimationDefinition& operator=(AnimationDefinition&& other);
+ /**
+ * @brief Set the name of the animation.
+ *
+ * @param[in] name The name of the animation.
+ */
+ void SetName(const std::string& name);
+
+ /**
+ * @brief Get the name of the animation.
+ *
+ * @return The name of the animation.
+ */
+ const std::string& GetName() const;
+
+ /**
+ * @brief Set the duration of the animation in seconds.
+ *
+ * @param[in] duration The duration of the animation in seconds.
+ */
+ void SetDuration(float duration);
+
+ /**
+ * @brief Get the duration of the animation in seconds.
+ *
+ * @return The duration of the animation in seconds.
+ */
+ float GetDuration() const;
+
+ /**
+ * @brief Set the number of times to loop the animation.
+ *
+ * @param[in] loopCount The number of times to loop the animation. Use -1 for infinite looping.
+ */
+ void SetLoopCount(int32_t loopCount);
+
+ /**
+ * @brief Get the number of times to loop the animation.
+ *
+ * @return The number of times to loop the animation. Use -1 for infinite looping.
+ */
+ int GetLoopCount() const;
+
+ /**
+ * @brief Set what should happen when an animation is disconnected from an object.
+ *
+ * @param[in] disconnectAction What should happen when an animation is disconnected from an object.
+ */
+ void SetDisconnectAction(Animation::EndAction disconnectAction);
+
+ /**
+ * @brief Get what should happen when an animation is disconnected from an object.
+ *
+ * @return What should happen when an animation is disconnected from an object.
+ */
+ Animation::EndAction GetDisconnectAction() const;
+
+ /**
+ * @brief Set what should happen when an animation reaches its end.
+ *
+ * @param[in] endAction What should happen when an animation reaches its end.
+ */
+ void SetEndAction(Animation::EndAction endAction);
+
+ /**
+ * @brief Get what should happen when an animation reaches its end.
+ *
+ * @return What should happen when an animation reaches its end.
+ */
+ Animation::EndAction GetEndAction() const;
+
+ /**
+ * @brief Set a speed factor for this animation. This can be used to speed up or slow down playback of this animation relative to other animations in a scene.
+ *
+ * @param[in] speedFactor The speed factor for this animation. 1.0 is normal speed, 2.0 is double speed, 0.5 is half speed, etc.
+ */
+ void SetSpeedFactor(float speedFactor);
+
+ /**
+ * @brief Get a speed factor for this animation. This can be used to speed up or slow down playback of this animation relative to other animations in a scene.
+ *
+ * @return The speed factor for this animation. 1.0 is normal speed, 2.0 is double speed, 0.5 is half speed, etc.
+ */
+ float GetSpeedFactor() const;
+
+ /**
+ * @brief Set a range within which to play this animation. This can be used to play only part of an animation or to play it backwards by setting playRange.y < playRange.x
+ *
+ * @param[in] playRange A range within which to play this animation. x = start time in seconds, y = end time in seconds
+ */
+ void SetPlayRange(const Vector2& playRange);
+
+ /**
+ * @brief Get a range within which to play this animation. This can be used to play only part of an animation or to play it backwards by setting playRange.y < playRange.x
+ *
+ * @return A range within which to play this animation. x = start time in seconds, y = end time in seconds
+ */
+ Vector2 GetPlayRange() const;
+
+ /**
+ * @brief Reserves Animated property vector's size
+ *
+ * @param[in] size The size to reserve property
+ */
+ void ReserveSize(uint32_t size);
+
+ /**
+ * @brief Retrieves the number of animated properties' count
+ *
+ * @return The count of animated properties.
+ */
+ uint32_t GetPropertyCount();
+
+ /**
+ * @brief Add a property that will be animated by this AnimationDefinition
+ *
+ * @param[in] index The index the property will be stored.
+ * @param[in] property The property that will be animated by this AnimationDefinition
+ */
+ void SetProperty(uint32_t index, AnimatedProperty&& property);
+
+ /**
+ * @brief Retrieves animated property at the index
+ *
+ * @param[in] index The index of property to be retrieved.
+ */
+ const AnimatedProperty& GetPropertyAt(uint32_t index);
-public: // DATA
+private: // DATA
std::string mName;
float mDuration = DEFAULT_DURATION_SECONDS;
- int mLoopCount = 1;
+ int32_t mLoopCount = 1;
Animation::EndAction mDisconnectAction = Animation::BAKE_FINAL;
Animation::EndAction mEndAction = Animation::BAKE;
float mSpeedFactor = 1.f;
} // namespace Dali::Scene3D::Loader
-#endif //DALI_SCENE3D_LOADER_ANIMATION_DEFINITION_H
+#endif // DALI_SCENE3D_LOADER_ANIMATION_DEFINITION_H
{
AnimationDefinition animationDefinition;
- animationDefinition.mName = animationName;
- animationDefinition.mDuration = frameTime * (frameCount - 1);
+ animationDefinition.SetName(animationName);
+ animationDefinition.SetDuration(frameTime * (frameCount - 1));
float keyFrameInterval = (frameCount > 1u) ? 1.0f / static_cast<float>(frameCount - 1u) : Dali::Math::MACHINE_EPSILON_10;
std::vector<std::shared_ptr<Joint>> jointList;
if(!jointList.empty())
{
- animationDefinition.mProperties.resize(jointList.size() * 2u); // translation and rotation
+ animationDefinition.ReserveSize(jointList.size() * 2u); // translation and rotation
for(uint32_t i = 0; i < jointList.size(); ++i)
{
- AnimatedProperty& translationProperty = animationDefinition.mProperties[i * 2u];
- translationProperty.mTimePeriod = Dali::TimePeriod(animationDefinition.mDuration);
+ AnimatedProperty translationProperty;
+ translationProperty.mTimePeriod = Dali::TimePeriod(animationDefinition.GetDuration());
translationProperty.mNodeName = jointList[i]->name;
translationProperty.mPropertyName = PROPERTY_NAME_POSITION.data();
- AnimatedProperty& rotationProperty = animationDefinition.mProperties[i * 2u + 1];
- rotationProperty.mTimePeriod = Dali::TimePeriod(animationDefinition.mDuration);
+ AnimatedProperty rotationProperty;
+ rotationProperty.mTimePeriod = Dali::TimePeriod(animationDefinition.GetDuration());
rotationProperty.mNodeName = jointList[i]->name;
rotationProperty.mPropertyName = PROPERTY_NAME_ORIENTATION.data();
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));
}
}
GetFacialAnimationReader().Read(rootObj, facialAnimation);\r
\r
AnimationDefinition animationDefinition;\r
- animationDefinition.mName = std::string(facialAnimation.mName.data());\r
- animationDefinition.mDuration = MILLISECONDS_TO_SECONDS * static_cast<float>(facialAnimation.mTime[facialAnimation.mNumberOfFrames - 1u]);\r
+ animationDefinition.SetName(facialAnimation.mName.data());\r
+ animationDefinition.SetDuration(MILLISECONDS_TO_SECONDS * static_cast<float>(facialAnimation.mTime[facialAnimation.mNumberOfFrames - 1u]));\r
\r
// Calculate the number of animated properties.\r
uint32_t numberOfAnimatedProperties = 0u;\r
{\r
numberOfAnimatedProperties += blendShape.mNumberOfMorphTarget;\r
}\r
- animationDefinition.mProperties.resize(numberOfAnimatedProperties);\r
+ animationDefinition.ReserveSize(numberOfAnimatedProperties);\r
\r
- // Create the key frame instances.\r
- for(auto& animatedProperty : animationDefinition.mProperties)\r
- {\r
- animatedProperty.mKeyFrames = Dali::KeyFrames::New();\r
- }\r
-\r
- // Set the property names\r
uint32_t targets = 0u;\r
for(const auto& blendShape : facialAnimation.mBlendShapes)\r
{\r
for(uint32_t morphTargetIndex = 0u; morphTargetIndex < blendShape.mNumberOfMorphTarget; ++morphTargetIndex)\r
{\r
- AnimatedProperty& animatedProperty = animationDefinition.mProperties[targets + morphTargetIndex];\r
- animatedProperty.mTimePeriod = Dali::TimePeriod(animationDefinition.mDuration);\r
-\r
+ AnimatedProperty animatedProperty;\r
+ animatedProperty.mTimePeriod = Dali::TimePeriod(animationDefinition.GetDuration());\r
animatedProperty.mNodeName = blendShape.mNodeName;\r
-\r
std::stringstream weightPropertyStream;\r
weightPropertyStream << BlendShapes::WEIGHTS_UNIFORM << "[" << morphTargetIndex << "]";\r
animatedProperty.mPropertyName = weightPropertyStream.str();\r
- }\r
- targets += blendShape.mNumberOfMorphTarget;\r
- }\r
\r
- targets = 0u;\r
- for(const auto& blendShape : facialAnimation.mBlendShapes)\r
- {\r
- for(uint32_t timeIndex = 0u; timeIndex < facialAnimation.mNumberOfFrames; ++timeIndex)\r
- {\r
- const float progress = MILLISECONDS_TO_SECONDS * static_cast<float>(facialAnimation.mTime[timeIndex]) / animationDefinition.mDuration;\r
-\r
- for(uint32_t morphTargetIndex = 0u; morphTargetIndex < blendShape.mNumberOfMorphTarget; ++morphTargetIndex)\r
+ animatedProperty.mKeyFrames = Dali::KeyFrames::New();\r
+ for(uint32_t timeIndex = 0u; timeIndex < facialAnimation.mNumberOfFrames; ++timeIndex)\r
{\r
- AnimatedProperty& animatedProperty = animationDefinition.mProperties[targets + morphTargetIndex];\r
-\r
+ const float progress = MILLISECONDS_TO_SECONDS * static_cast<float>(facialAnimation.mTime[timeIndex]) / animationDefinition.GetDuration();\r
animatedProperty.mKeyFrames.Add(progress, blendShape.mKeys[timeIndex][morphTargetIndex]);\r
}\r
+ animationDefinition.SetProperty(targets + morphTargetIndex, std::move(animatedProperty));\r
}\r
+\r
targets += blendShape.mNumberOfMorphTarget;\r
}\r
\r