Fix wrong interpolation ratio in glTF TrackData.populateTransform()#2897
Fix wrong interpolation ratio in glTF TrackData.populateTransform()#2897DieterDePaepe wants to merge 1 commit into
Conversation
When a node's translation/rotation/scale channels carry different keyframe timestamps, update() merges them onto one shared time grid and gap-fills missing samples via populateTransform()/interpolate(). The blend ratio for that interpolation was computed as "currentKeyFrame.time / (nextKeyFrame.time - lastKeyFrame.time)", missing "- lastKeyFrame.time" in the numerator. Instead of the intended 0..1 blend position within [lastKeyFrame.time, nextKeyFrame.time], this passed the clip's absolute elapsed time into Quaternion.nlerp(), which doesn't clamp its blend parameter and so extrapolated wildly rather than interpolating.
There was a problem hiding this comment.
Code Review
This pull request corrects the interpolation ratio calculation in TrackData.java by subtracting the last keyframe's time from the current keyframe's time, ensuring proper interpolation between keyframes. There are no review comments, so I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
Fixes the interpolation blend ratio used when glTF animation channels (translation/rotation/scale) have non-identical keyframe timestamps and the loader must merge onto a shared time grid and gap-fill missing samples. The previous ratio calculation used absolute clip time in the numerator, causing extrapolation (not interpolation) in Quaternion.nlerp() and producing incorrect rotations.
Changes:
- Correct the interpolation ratio in
TrackData.populateTransform()to compute the normalized position within[lastKeyFrame.time, nextKeyFrame.time]. - Format the ratio calculation across two lines for clarity.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
When a node's translation/rotation/scale channels carry different keyframe timestamps, update() merges them onto one shared time grid and gap-fills missing samples via populateTransform()/interpolate(). The blend ratio for that interpolation was computed as
"currentKeyFrame.time / (nextKeyFrame.time - lastKeyFrame.time)", missing "- lastKeyFrame.time" in the numerator. Instead of the intended 0..1 blend position within [lastKeyFrame.time, nextKeyFrame.time], this passed the clip's absolute elapsed time into Quaternion.nlerp(), which doesn't clamp its blend parameter and so extrapolated wildly rather than interpolating.
Only triggers on the "channels don't share identical keyframe times" merge
path (
equalTimes(timeArrays)false) — simple clips where every channel issampled at the same rate never hit it.
Verified against a real affected clip: a bone was rotating >100° from bind
mid-clip in a stretch where the source data is smooth; after the fix,
motion is normal throughout.
Forum discussion: https://hub.jmonkeyengine.org/t/wrong-interpolation-in-gltf-loader/49640
(Created with help from AI)