From 9855d7e245ef51d1c02359211302f0e60288deff Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Mon, 6 Mar 2023 19:42:40 +0800 Subject: [PATCH] Total time and tickers per second is now auto calculated in SHAnimationClip --- SHADE_Engine/src/Animation/SHAnimationClip.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/SHADE_Engine/src/Animation/SHAnimationClip.cpp b/SHADE_Engine/src/Animation/SHAnimationClip.cpp index b1745ed2..934290a0 100644 --- a/SHADE_Engine/src/Animation/SHAnimationClip.cpp +++ b/SHADE_Engine/src/Animation/SHAnimationClip.cpp @@ -20,11 +20,10 @@ namespace SHADE /* Constructors */ /*-----------------------------------------------------------------------------------*/ SHAnimationClip::SHAnimationClip(const SHAnimAsset& asset) - : ticksPerSecond { static_cast(asset.ticksPerSecond) } - , totalTime { static_cast(asset.duration) / static_cast(asset.ticksPerSecond) } { // Populate keyframes - int channelIdx = 0; + int maxFrames = 0; + totalTime = 0.0f; for (const auto& channel : asset.nodeChannels) { // Create a channel @@ -49,12 +48,18 @@ namespace SHADE newChannel.MaxFrames = std::max({ newChannel.PositionKeyFrames.size(), newChannel.RotationKeyFrames.size(), newChannel.ScaleKeyFrames.size() }); + // Compute max frames + maxFrames = std::max(maxFrames, newChannel.MaxFrames); + + // Compute total time + totalTime = std::max({ totalTime, newChannel.PositionKeyFrames.back().TimeStamp, newChannel.RotationKeyFrames.back().TimeStamp, newChannel.ScaleKeyFrames.back().TimeStamp }); + // Insert the channel channels.emplace_back(std::move(newChannel)); - - // Go to next channel - ++channelIdx; } + + // Compute fps + ticksPerSecond = static_cast(maxFrames / totalTime); } /*-----------------------------------------------------------------------------------*/