Bones now still affects skinned mesh when animation is stopped

This commit is contained in:
Antoine Pilote
2023-09-17 20:25:59 -04:00
parent c0f1178e7d
commit 33963c7b2e
2 changed files with 8 additions and 18 deletions

View File

@@ -36,29 +36,24 @@ namespace Nuake
{
float newAnimationTime = animation->GetCurrentTime() + (ts * animation->GetTicksPerSecond());
animation->SetCurrentTime(newAnimationTime);
auto& rootBone = model->GetSkeletonRootNode();
UpdateBonePositionTraversal(rootBone, animation, animation->GetCurrentTime());
}
auto& rootBone = model->GetSkeletonRootNode();
UpdateBonePositionTraversal(rootBone, animation, animation->GetCurrentTime(), model->IsPlaying);
}
}
void AnimationSystem::UpdateBonePositionTraversal(SkeletonNode& bone, Ref<SkeletalAnimation> animation, float time)
void AnimationSystem::UpdateBonePositionTraversal(SkeletonNode& bone, Ref<SkeletalAnimation> animation, float time, bool isPlaying)
{
const std::string& boneName = bone.Name;
auto animationTrack = animation->GetTrack(boneName);
auto& animationTrack = animation->GetTrack(bone.Name);
Entity& boneEntity = m_Scene->GetEntity(boneName);
Entity& boneEnt = m_Scene->GetEntityByID(bone.EntityHandle);
///assert(boneEnt.GetHandle() == boneEntity.GetHandle());
if (boneEnt.IsValid())
{
auto& transformComponent = boneEnt.GetComponent<TransformComponent>();
bone.FinalTransform = transformComponent.GetGlobalTransform() * bone.Offset;
if (!animationTrack.IsEmpty())
if (!animationTrack.IsEmpty() && isPlaying)
{
// Get Update transform
animationTrack.Update(time);
@@ -77,15 +72,10 @@ namespace Nuake
transformComponent.Dirty = false;
}
}
else
{
// Find bone
}
for (auto& childBone : bone.Children)
{
UpdateBonePositionTraversal(childBone, animation, time);
UpdateBonePositionTraversal(childBone, animation, time, isPlaying);
}
}