Clamp glTF animation curves before first key#50
Open
Apidcloud wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
As discussed in atteneder#817, we found a visible transform flash with glTF animations whose sampler input accessors do not start at
0.In the attached sample model, one animation channel starts at
0.033333335and ends around60.When using Unity Legacy Animation and resetting the clip by setting
animation.time = 0, the generated Unity curve has no key at0, so sampling at0can briefly show an incorrect transform. In our case the scale difference is large, making the flash very visible:Screen.Recording.2026-05-20.at.17.27.13.compressed.mp4
Tree model in the video (initial keyframe is at time 0.033333335 instead of 0; see accessor 1659):
model-with-initial-0.033333335-keyframe.zip
Changes
glTF animation sampler inputs are relative to
t = 0, and the glTF 2.0 spec requires output before the first input timestamp to be clamped to the first available output value: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#animationsThis PR preserves that behaviour in Unity’s generated animation curves by inserting a synthetic key at
t = 0when the first sampler input time is greater than zero.The inserted key uses the first actual sampler value (copied) and is applied for:
CUBICSPLINEsamplers are handled using the glTF output layout[inTangent, value, outTangent], so the inserted key copies the first actual value, not the first tangent.Tests
Added runtime animation processor tests that cover non-zero first sampler input times for:
LINEARSTEPCUBICSPLINEThe tests fail before this change for the affected curve paths and pass after the synthetic
t = 0key insertion. We also tested it internally today and it seems to work properly.Before and After
Before (note no keyframe at 0)
After (note the keyframe at 0)
I've already signed the CLA, but let me know if you'd like to adjust the approach or so.