-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Fix last keyframe #10842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix last keyframe #10842
Conversation
| Ok(i) => i, | ||
| Err(0) => continue, // this curve isn't started yet | ||
| Err(n) if n > curve.keyframe_timestamps.len() - 1 => continue, // this curve is finished | ||
| Err(n) if n > curve.keyframe_timestamps.len() - 1 => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Err(n) is returned when no exact match was found this means that we sample after the last keyframe for n > len - 1. This curve should not contribute to the final pose by default in my opinion. The way most are familiar with this is probably an option "hold". I would continue here and special case it later when this option is implemented.
The rest looks fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should add curves not contributing anymore is essentially only relevant when blending
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave it another thought and my suggestion doesnt result in the last keyframe being applied when we sample with t > curve duration. Im going to give it some more thought for something bullet-proof.
My current stance is that the last keyframe should be sampled when t(i - 1) < curve duration and t(i) > curve duration, but not when t(i - 1) > curve duration and t(i) > curve duration (unless we are holding the animation).
This means we need to keep track of when an animation was last sampled and whether it was sampled the last time the player ran.
Where t(i - 1) is the last time we sampled and t(i) is the time we currently sample.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #10832 (comment)
|
What are your plans with this PR? This is a useful fix: should I put it up for adoption? |
|
Yeah put it up for adoption |
|
Closing as outdated/superseded by #15434 |
Objective
Fixes: #10832
Solution
If the time is past the final keyframe, just set the transform using final transform
How to test:
Run the
animated_foxexample and bump the speed up a bunch withup arrow, then hit1to run the animation once. On main it won't always stop in the same position, with this PR it always stops on exact value of last keyframeWith main (slightly different results everytime):

With this PR:

Changelog
Fixed bug where animation wouldn't stop at the value of exactly the last keyframe