Total time and tickers per second is now auto calculated in SHAnimationClip

This commit is contained in:
Kah Wei 2023-03-06 19:42:40 +08:00
parent 43fd04dd5e
commit 9855d7e245
1 changed files with 11 additions and 6 deletions

View File

@ -20,11 +20,10 @@ namespace SHADE
/* Constructors */ /* Constructors */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
SHAnimationClip::SHAnimationClip(const SHAnimAsset& asset) SHAnimationClip::SHAnimationClip(const SHAnimAsset& asset)
: ticksPerSecond { static_cast<int>(asset.ticksPerSecond) }
, totalTime { static_cast<float>(asset.duration) / static_cast<int>(asset.ticksPerSecond) }
{ {
// Populate keyframes // Populate keyframes
int channelIdx = 0; int maxFrames = 0;
totalTime = 0.0f;
for (const auto& channel : asset.nodeChannels) for (const auto& channel : asset.nodeChannels)
{ {
// Create a channel // Create a channel
@ -49,12 +48,18 @@ namespace SHADE
newChannel.MaxFrames = std::max({ newChannel.PositionKeyFrames.size(), newChannel.RotationKeyFrames.size(), newChannel.ScaleKeyFrames.size() }); 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 // Insert the channel
channels.emplace_back(std::move(newChannel)); channels.emplace_back(std::move(newChannel));
// Go to next channel
++channelIdx;
} }
// Compute fps
ticksPerSecond = static_cast<int>(maxFrames / totalTime);
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/