From dded296cde37d3815688eea7a3ccd9942048c9fb Mon Sep 17 00:00:00 2001 From: viktorljung Date: Wed, 10 Feb 2016 23:19:44 +0100 Subject: [PATCH 1/2] Animation looping fix --- assets | 2 +- resources/Schema/Entities/AnimationTests2.xml | 505 +----------------- src/Engine/Rendering/AnimationSystem.cpp | 2 - src/Engine/Rendering/Skeleton.cpp | 4 + 4 files changed, 20 insertions(+), 493 deletions(-) diff --git a/assets b/assets index 45cbc3ab..172b3ad5 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 45cbc3abaebe5f815e2c1b58bcf884d4953a4c52 +Subproject commit 172b3ad527fc14aa6175fa72580a66a00f04e0ba diff --git a/resources/Schema/Entities/AnimationTests2.xml b/resources/Schema/Entities/AnimationTests2.xml index 09573ac7..6536a839 100644 --- a/resources/Schema/Entities/AnimationTests2.xml +++ b/resources/Schema/Entities/AnimationTests2.xml @@ -55,498 +55,23 @@ - + - + + R_Arm_Weapon_Joint + + + + Models/Weapons/Blue/AssaultWeapon.mesh + + true + + + + + - - - - - R_Arm_Weapon_Joint - - - - Models/Weapons/Blue/AssaultWeapon.mesh - - true - - - - - - - - - - - - R_Hand - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - R_Arm - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - R_Shoulder - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - Neck - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - Spine_3 - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - Spine_2 - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - Spine_1 - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - Hip - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - L_Leg_Top - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - L_Leg_Bottom - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - L_Foot - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - L_Toe - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - L_Shoulder - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - L_Arm - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - L_Hand - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - L_Shoulder_Armor_Joint - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - Chin - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - Head - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - Perietal - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - L_Elbow - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - R_Leg_Bottom - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - R_Elbow - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - R_Leg_Top - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - R_Foot - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - R_Toe - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - R_Shoulder_Armor_Joint - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - + diff --git a/src/Engine/Rendering/AnimationSystem.cpp b/src/Engine/Rendering/AnimationSystem.cpp index 25813a63..3df502c4 100644 --- a/src/Engine/Rendering/AnimationSystem.cpp +++ b/src/Engine/Rendering/AnimationSystem.cpp @@ -13,9 +13,7 @@ void AnimationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& a return; } - Skeleton* skeleton = model->m_RawModel->m_Skeleton; - if(skeleton == nullptr) { return; } diff --git a/src/Engine/Rendering/Skeleton.cpp b/src/Engine/Rendering/Skeleton.cpp index 1aabd84c..5da95558 100644 --- a/src/Engine/Rendering/Skeleton.cpp +++ b/src/Engine/Rendering/Skeleton.cpp @@ -96,6 +96,7 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vectorDuration - currentFrame.Time); } else { progress = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time); @@ -227,6 +228,7 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vectorDuration - currentFrame.Time); } else { progress = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time); @@ -347,6 +349,7 @@ glm::mat4 Skeleton::GetOffsetTransform(const Bone* bone, AnimationOffset animati float progress; if (nextFrame.Index == 0) { + nextFrame = currentFrame; progress = (time - currentFrame.Time) / (animation->Duration - currentFrame.Time); } else { progress = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time); @@ -400,6 +403,7 @@ glm::mat4 Skeleton::GetBoneTransform(const Bone* bone, const Animation* animatio float progress; if (nextFrame.Index == 0) { + nextFrame = currentFrame; progress = (time - currentFrame.Time) / (animation->Duration - currentFrame.Time); } else { progress = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time); From 9c08c351b80197fd485e438b175a8293e681686d Mon Sep 17 00:00:00 2001 From: viktorljung Date: Wed, 10 Feb 2016 23:33:23 +0100 Subject: [PATCH 2/2] fixed reverse Animation looping --- src/Engine/Rendering/AnimationSystem.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Engine/Rendering/AnimationSystem.cpp b/src/Engine/Rendering/AnimationSystem.cpp index 3df502c4..48681e6e 100644 --- a/src/Engine/Rendering/AnimationSystem.cpp +++ b/src/Engine/Rendering/AnimationSystem.cpp @@ -31,20 +31,27 @@ void AnimationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& a double nextTime = (double)animationComponent["Time" + std::to_string(i)] + animationSpeed * dt; - if (!(bool)animationComponent["Loop" + std::to_string(i)] && glm::abs(nextTime) > animation->Duration) { - (double&)animationComponent["Time" + std::to_string(i)] = glm::sign(nextTime) * animation->Duration; + if (!(bool)animationComponent["Loop" + std::to_string(i)]) { + if (nextTime > animation->Duration) { + nextTime = animation->Duration; + } else if (nextTime < 0) { + nextTime = 0; + } + (double&)animationComponent["Speed" + std::to_string(i)] = 0.0; Events::AnimationComplete e; e.Entity = entity; e.Name = (std::string)animationComponent["AnimationName" + std::to_string(i)]; m_EventBroker->Publish(e); } else { - if (glm::abs(nextTime) > animation->Duration) { - (double&)animationComponent["Time" + std::to_string(i)] = glm::abs(nextTime) - animation->Duration; - } else { - (double&)animationComponent["Time" + std::to_string(i)] = nextTime; + if (nextTime > animation->Duration) { + nextTime -= animation->Duration; + } else if (nextTime < 0) { + nextTime += animation->Duration; } } + + (double&)animationComponent["Time" + std::to_string(i)] = nextTime; } }