Skip to content

Commit

Permalink
gltfpack: Fix output animation start time
Browse files Browse the repository at this point in the history
Due to a bug in resampling logic, minimum time value was always 0 - this
could result in animations that were too long, potentially causing
issues for the client side playback.

Note that if there are no tracks, mint stays at FLT_MAX and we correct
it by clamping it to max (so both end up 0) - this shouldn't happen
normally, and animations without tracks shouldn't be output, but it can
happen in rare edge cases and it's better to fix this up early instead
of triggering issues with timing logic later.

Reported in zeux#185.
  • Loading branch information
zeux committed Oct 14, 2020
1 parent afc1ea4 commit efa10d8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion gltf/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <algorithm>

#include <float.h>
#include <math.h>
#include <string.h>

Expand Down Expand Up @@ -262,7 +263,7 @@ static void getBaseTransform(Attr* result, size_t components, cgltf_animation_pa

void processAnimation(Animation& animation, const Settings& settings)
{
float mint = 0, maxt = 0;
float mint = FLT_MAX, maxt = 0;

for (size_t i = 0; i < animation.tracks.size(); ++i)
{
Expand All @@ -273,6 +274,8 @@ void processAnimation(Animation& animation, const Settings& settings)
maxt = std::max(maxt, track.time.back());
}

mint = std::min(mint, maxt);

// round the number of frames to nearest but favor the "up" direction
// this means that at 10 Hz resampling, we will try to preserve the last frame <10ms
// but if the last frame is <2ms we favor just removing this data
Expand Down

0 comments on commit efa10d8

Please sign in to comment.