From c9bc7eda384e108441e5a99dc54d7ef99f4fba90 Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Tue, 23 Nov 2021 09:27:43 +0100 Subject: AnimationClip: fix the way we compute the duration We wrongly assumed the start time of a clip was always 0. In practice this might not be the case. Therefore, we now compute duration as tEnd - tStart. Change-Id: I13ca860f3366c2aba5e978cb0c955e7bb2e7bc39 Reviewed-by: Sean Harmer (cherry picked from commit 7b23cb1ca5b32fcf24f889e79cec756786f86233) Reviewed-by: Qt Cherry-pick Bot --- src/animation/backend/animationclip.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/animation/backend/animationclip.cpp b/src/animation/backend/animationclip.cpp index d4a1f133a..24b41a50f 100644 --- a/src/animation/backend/animationclip.cpp +++ b/src/animation/backend/animationclip.cpp @@ -358,14 +358,17 @@ float AnimationClip::findDuration() { // Iterate over the contained fcurves and find the longest one float tMax = 0.f; + float tMin = 1.0f; for (const Channel &channel : qAsConst(m_channels)) { for (const ChannelComponent &channelComponent : qAsConst(channel.channelComponents)) { - const float t = channelComponent.fcurve.endTime(); - if (t > tMax) - tMax = t; + const float tStart = channelComponent.fcurve.startTime(); + const float tEnd = channelComponent.fcurve.endTime(); + tMax = std::max(tEnd, tMax); + tMin = std::min(tStart, tMin); } } - return tMax; + // We can't have a negative duration + return std::max(tMax - tMin, 0.0f); } int AnimationClip::findChannelComponentCount() -- cgit v1.2.3