From 679f02413b55445b39148f4b102c153b1b5fae83 Mon Sep 17 00:00:00 2001 From: seungho baek Date: Sat, 1 Apr 2023 23:21:08 +0900 Subject: [PATCH] Change public member variable to private Change-Id: I8ba514c1dfcbd7e5f82aaa898b37d83e2ece890d Signed-off-by: seungho baek --- .../utc-Dali-Gltf2LoaderImpl.cpp | 4 +- .../dali-scene3d/utc-Dali-AnimationDefinition.cpp | 50 ++++---- .../src/dali-scene3d/utc-Dali-BvhLoader.cpp | 40 +++--- .../src/dali-scene3d/utc-Dali-FacialAnimation.cpp | 71 +++++------ .../internal/controls/model/model-impl.cpp | 2 +- dali-scene3d/internal/loader/dli-loader-impl.cpp | 55 +++++---- dali-scene3d/internal/loader/gltf2-util.cpp | 18 +-- .../public-api/loader/animation-definition.cpp | 116 ++++++++++++++++-- .../public-api/loader/animation-definition.h | 135 ++++++++++++++++++++- dali-scene3d/public-api/loader/bvh-loader.cpp | 16 +-- .../public-api/loader/facial-animation-loader.cpp | 37 ++---- 11 files changed, 380 insertions(+), 164 deletions(-) diff --git a/automated-tests/src/dali-scene3d-internal/utc-Dali-Gltf2LoaderImpl.cpp b/automated-tests/src/dali-scene3d-internal/utc-Dali-Gltf2LoaderImpl.cpp index 81c9d8c..a40ccac 100644 --- a/automated-tests/src/dali-scene3d-internal/utc-Dali-Gltf2LoaderImpl.cpp +++ b/automated-tests/src/dali-scene3d-internal/utc-Dali-Gltf2LoaderImpl.cpp @@ -680,9 +680,9 @@ int UtcDaliGltfLoaderAnimationLoadingTest(void) } 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(Dali::Actor::Property::ID)); END_TEST; diff --git a/automated-tests/src/dali-scene3d/utc-Dali-AnimationDefinition.cpp b/automated-tests/src/dali-scene3d/utc-Dali-AnimationDefinition.cpp index 99b0aaf..a2e052c 100644 --- a/automated-tests/src/dali-scene3d/utc-Dali-AnimationDefinition.cpp +++ b/automated-tests/src/dali-scene3d/utc-Dali-AnimationDefinition.cpp @@ -48,15 +48,16 @@ int UtcDaliAnimationDefinitionReAnimate(void) 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", @@ -66,14 +67,14 @@ int UtcDaliAnimationDefinitionReAnimate(void) 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; @@ -93,27 +94,28 @@ int UtcDaliAnimationDefinitionReAnimateKeyFrames(void) 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; } diff --git a/automated-tests/src/dali-scene3d/utc-Dali-BvhLoader.cpp b/automated-tests/src/dali-scene3d/utc-Dali-BvhLoader.cpp index db5f525..2315bfd 100644 --- a/automated-tests/src/dali-scene3d/utc-Dali-BvhLoader.cpp +++ b/automated-tests/src/dali-scene3d/utc-Dali-BvhLoader.cpp @@ -27,28 +27,28 @@ int UtcDaliLoadBvh(void) 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"); @@ -62,7 +62,7 @@ int UtcDaliLoadBvh(void) }; Animation animation = animDef.ReAnimate(getActor); - DALI_TEST_EQUAL(animation.GetDuration(), animDef.mDuration); + DALI_TEST_EQUAL(animation.GetDuration(), animDef.GetDuration()); application.GetScene().Add(root); @@ -98,6 +98,6 @@ int UtcDaliLoadBvhFailed(void) 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; } diff --git a/automated-tests/src/dali-scene3d/utc-Dali-FacialAnimation.cpp b/automated-tests/src/dali-scene3d/utc-Dali-FacialAnimation.cpp index 2e97dc9..100cd72 100644 --- a/automated-tests/src/dali-scene3d/utc-Dali-FacialAnimation.cpp +++ b/automated-tests/src/dali-scene3d/utc-Dali-FacialAnimation.cpp @@ -28,42 +28,43 @@ int UtcDaliLoadFacialAnimation(void) 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"); @@ -82,10 +83,10 @@ int UtcDaliLoadFacialAnimation(void) }; 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; } diff --git a/dali-scene3d/internal/controls/model/model-impl.cpp b/dali-scene3d/internal/controls/model/model-impl.cpp index 584c667..2f29b25 100644 --- a/dali-scene3d/internal/controls/model/model-impl.cpp +++ b/dali-scene3d/internal/controls/model/model-impl.cpp @@ -888,7 +888,7 @@ void Model::CreateAnimations(Dali::Scene3D::Loader::SceneDefinition& scene) for(auto&& animation : mModelLoadTask->GetAnimations()) { Dali::Animation anim = animation.ReAnimate(getActor); - mAnimations.push_back({animation.mName, anim}); + mAnimations.push_back({animation.GetName(), anim}); } } } diff --git a/dali-scene3d/internal/loader/dli-loader-impl.cpp b/dali-scene3d/internal/loader/dli-loader-impl.cpp index 3a08ea4..f111856 100644 --- a/dali-scene3d/internal/loader/dli-loader-impl.cpp +++ b/dali-scene3d/internal/loader/dli-loader-impl.cpp @@ -1439,51 +1439,56 @@ void DliLoaderImpl::Impl::ParseAnimations(const TreeNode* tnAnimations, LoadPara ++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); } } @@ -1491,21 +1496,21 @@ void DliLoaderImpl::Impl::ParseAnimations(const TreeNode* tnAnimations, LoadPara { 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) @@ -1515,24 +1520,24 @@ void DliLoaderImpl::Impl::ParseAnimations(const TreeNode* tnAnimations, LoadPara 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)); } @@ -1668,7 +1673,7 @@ void DliLoaderImpl::Impl::ParseAnimations(const TreeNode* tnAnimations, LoadPara } } - animDef.mProperties.push_back(std::move(animProp)); + animDef.SetProperty(animationPropertyIndex++, std::move(animProp)); } } diff --git a/dali-scene3d/internal/loader/gltf2-util.cpp b/dali-scene3d/internal/loader/gltf2-util.cpp index 06cac24..330a2c0 100644 --- a/dali-scene3d/internal/loader/gltf2-util.cpp +++ b/dali-scene3d/internal/loader/gltf2-util.cpp @@ -1079,7 +1079,7 @@ float LoadKeyFrames(ConversionContext& context, const gltf2::Animation::Channel& return duration; } -float LoadBlendShapeKeyFrames(ConversionContext& context, const gltf2::Animation::Channel& channel, Index nodeIndex, uint32_t& propertyIndex, std::vector& 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; @@ -1095,7 +1095,7 @@ float LoadBlendShapeKeyFrames(ConversionContext& context, const gltf2::Animation 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); @@ -1115,6 +1115,8 @@ float LoadBlendShapeKeyFrames(ConversionContext& context, const gltf2::Animation } animatedProperty.mTimePeriod = {0.f, duration}; + + animationDefinition.SetProperty(propertyIndex++, std::move(animatedProperty)); } return duration; @@ -1123,8 +1125,7 @@ float LoadBlendShapeKeyFrames(ConversionContext& context, const gltf2::Animation template 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; @@ -1132,6 +1133,7 @@ float LoadAnimation(AnimationDefinition& animationDefinition, Index nodeIndex, I float duration = LoadKeyFrames(context, channel, animatedProperty.mKeyFrames, channel.mTarget.mPath); animatedProperty.mTimePeriod = {0.f, duration}; + animationDefinition.SetProperty(propertyIndex, std::move(animatedProperty)); return duration; } @@ -1147,7 +1149,7 @@ void ConvertAnimations(const gltf2::Document& document, ConversionContext& conte if(!animation.mName.empty()) { - animationDefinition.mName = animation.mName; + animationDefinition.SetName(animation.mName.data()); } uint32_t numberOfProperties = 0u; @@ -1162,7 +1164,7 @@ void ConvertAnimations(const gltf2::Document& document, ConversionContext& conte numberOfProperties++; } } - animationDefinition.mProperties.resize(numberOfProperties); + animationDefinition.ReserveSize(numberOfProperties); Index propertyIndex = 0u; for(const auto& channel : animation.mChannels) @@ -1189,7 +1191,7 @@ void ConvertAnimations(const gltf2::Document& document, ConversionContext& conte } case gltf2::Animation::Channel::Target::WEIGHTS: { - duration = LoadBlendShapeKeyFrames(context, channel, nodeIndex, propertyIndex, animationDefinition.mProperties); + duration = LoadBlendShapeKeyFrames(context, channel, nodeIndex, propertyIndex, animationDefinition); break; } @@ -1200,7 +1202,7 @@ void ConvertAnimations(const gltf2::Document& document, ConversionContext& conte } } - animationDefinition.mDuration = std::max(duration, animationDefinition.mDuration); + animationDefinition.SetDuration(std::max(duration, animationDefinition.GetDuration())); ++propertyIndex; } diff --git a/dali-scene3d/public-api/loader/animation-definition.cpp b/dali-scene3d/public-api/loader/animation-definition.cpp index 31c5ed1..5d8d304 100644 --- a/dali-scene3d/public-api/loader/animation-definition.cpp +++ b/dali-scene3d/public-api/loader/animation-definition.cpp @@ -45,6 +45,20 @@ AnimationDefinition::AnimationDefinition(AnimationDefinition&& other) { } +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); @@ -69,18 +83,98 @@ Animation AnimationDefinition::ReAnimate(AnimatedProperty::GetActor getActor) 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 diff --git a/dali-scene3d/public-api/loader/animation-definition.h b/dali-scene3d/public-api/loader/animation-definition.h index 27fe2ac..ff72e3f 100644 --- a/dali-scene3d/public-api/loader/animation-definition.h +++ b/dali-scene3d/public-api/loader/animation-definition.h @@ -49,6 +49,8 @@ public: // METHODS 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. @@ -61,13 +63,138 @@ public: // METHODS */ 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; @@ -84,4 +211,4 @@ struct AnimationGroupDefinition } // namespace Dali::Scene3D::Loader -#endif //DALI_SCENE3D_LOADER_ANIMATION_DEFINITION_H +#endif // DALI_SCENE3D_LOADER_ANIMATION_DEFINITION_H diff --git a/dali-scene3d/public-api/loader/bvh-loader.cpp b/dali-scene3d/public-api/loader/bvh-loader.cpp index 93a826d..70cb297 100644 --- a/dali-scene3d/public-api/loader/bvh-loader.cpp +++ b/dali-scene3d/public-api/loader/bvh-loader.cpp @@ -287,8 +287,8 @@ AnimationDefinition GenerateAnimation(const std::string& animationName, std::sha { 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(frameCount - 1u) : Dali::Math::MACHINE_EPSILON_10; std::vector> jointList; @@ -296,16 +296,16 @@ AnimationDefinition GenerateAnimation(const std::string& animationName, std::sha 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(); @@ -316,6 +316,8 @@ AnimationDefinition GenerateAnimation(const std::string& animationName, std::sha translationProperty.mKeyFrames.Add(static_cast(j) * keyFrameInterval, (jointList[i]->translations[j] * scale)); rotationProperty.mKeyFrames.Add(static_cast(j) * keyFrameInterval, jointList[i]->rotations[j]); } + animationDefinition.SetProperty(i * 2u, std::move(translationProperty)); + animationDefinition.SetProperty(i * 2u + 1, std::move(rotationProperty)); } } diff --git a/dali-scene3d/public-api/loader/facial-animation-loader.cpp b/dali-scene3d/public-api/loader/facial-animation-loader.cpp index dfd9cc2..26afb29 100644 --- a/dali-scene3d/public-api/loader/facial-animation-loader.cpp +++ b/dali-scene3d/public-api/loader/facial-animation-loader.cpp @@ -130,8 +130,8 @@ AnimationDefinition LoadFacialAnimation(const std::string& url) GetFacialAnimationReader().Read(rootObj, facialAnimation); AnimationDefinition animationDefinition; - animationDefinition.mName = std::string(facialAnimation.mName.data()); - animationDefinition.mDuration = MILLISECONDS_TO_SECONDS * static_cast(facialAnimation.mTime[facialAnimation.mNumberOfFrames - 1u]); + animationDefinition.SetName(facialAnimation.mName.data()); + animationDefinition.SetDuration(MILLISECONDS_TO_SECONDS * static_cast(facialAnimation.mTime[facialAnimation.mNumberOfFrames - 1u])); // Calculate the number of animated properties. uint32_t numberOfAnimatedProperties = 0u; @@ -139,46 +139,29 @@ AnimationDefinition LoadFacialAnimation(const std::string& url) { numberOfAnimatedProperties += blendShape.mNumberOfMorphTarget; } - animationDefinition.mProperties.resize(numberOfAnimatedProperties); + animationDefinition.ReserveSize(numberOfAnimatedProperties); - // Create the key frame instances. - for(auto& animatedProperty : animationDefinition.mProperties) - { - animatedProperty.mKeyFrames = Dali::KeyFrames::New(); - } - - // Set the property names uint32_t targets = 0u; for(const auto& blendShape : facialAnimation.mBlendShapes) { for(uint32_t morphTargetIndex = 0u; morphTargetIndex < blendShape.mNumberOfMorphTarget; ++morphTargetIndex) { - AnimatedProperty& animatedProperty = animationDefinition.mProperties[targets + morphTargetIndex]; - animatedProperty.mTimePeriod = Dali::TimePeriod(animationDefinition.mDuration); - + AnimatedProperty animatedProperty; + animatedProperty.mTimePeriod = Dali::TimePeriod(animationDefinition.GetDuration()); animatedProperty.mNodeName = blendShape.mNodeName; - std::stringstream weightPropertyStream; weightPropertyStream << BlendShapes::WEIGHTS_UNIFORM << "[" << morphTargetIndex << "]"; animatedProperty.mPropertyName = weightPropertyStream.str(); - } - targets += blendShape.mNumberOfMorphTarget; - } - targets = 0u; - for(const auto& blendShape : facialAnimation.mBlendShapes) - { - for(uint32_t timeIndex = 0u; timeIndex < facialAnimation.mNumberOfFrames; ++timeIndex) - { - const float progress = MILLISECONDS_TO_SECONDS * static_cast(facialAnimation.mTime[timeIndex]) / animationDefinition.mDuration; - - for(uint32_t morphTargetIndex = 0u; morphTargetIndex < blendShape.mNumberOfMorphTarget; ++morphTargetIndex) + animatedProperty.mKeyFrames = Dali::KeyFrames::New(); + for(uint32_t timeIndex = 0u; timeIndex < facialAnimation.mNumberOfFrames; ++timeIndex) { - AnimatedProperty& animatedProperty = animationDefinition.mProperties[targets + morphTargetIndex]; - + const float progress = MILLISECONDS_TO_SECONDS * static_cast(facialAnimation.mTime[timeIndex]) / animationDefinition.GetDuration(); animatedProperty.mKeyFrames.Add(progress, blendShape.mKeys[timeIndex][morphTargetIndex]); } + animationDefinition.SetProperty(targets + morphTargetIndex, std::move(animatedProperty)); } + targets += blendShape.mNumberOfMorphTarget; } -- 2.7.4