How glTF Handles Out-of-Bounds Animation Time

This article provides an overview of how glTF 2.0 handles animation time queries outside defined clip boundaries. In glTF, out-of-bounds animation evaluations are resolved via keyframe clamping at the sampler level, leaving playback behaviors like looping, wrapping, and ping-ponging entirely to the consuming runtime engine rather than the file format itself.

Keyframe Clamping in the glTF Specification

The glTF 2.0 specification defines animation data through channels and samplers. Each sampler references an input accessor containing monotonically increasing floating-point timestamps (\(t_0, t_1, \dots, t_n\)) and an output accessor containing the corresponding transform values (translation, rotation, scale, or morph target weights).

When a runtime queries an animation sampler at a time \(t\) that falls outside the defined range \([t_0, t_n]\), the specification mandates the following evaluation rules:

  • Before the First Keyframe (\(t < t_0\)): The output value is clamped to the value of the first keyframe at \(t_0\).
  • After the Last Keyframe (\(t > t_n\)): The output value is clamped to the value of the final keyframe at \(t_n\).

This behavior applies regardless of whether the chosen interpolation method is LINEAR, STEP, or CUBICSPLINE.

Implicit Durations and Multi-Channel Discrepancies

A glTF animation does not possess an explicit, global "duration" property. Instead, the duration of an animation clip is implicitly defined as the time span between the earliest \(t_0\) and the latest \(t_n\) among all samplers included in that animation.

Because each channel can have independent sampler timelines, channels within the same animation often have mismatched start or end times. For instance, a rotation channel might end at 2.0 seconds while a translation channel continues until 3.0 seconds. For any query where \(2.0 < t \le 3.0\), the rotation track evaluates out-of-bounds and clamps to its 2.0-second value, while the translation track continues interpolating keyframes normally.

Cubic Spline Handling at Boundaries

For CUBICSPLINE interpolation, each keyframe provides three components: an in-tangent, a value, and an out-tangent. When an out-of-bounds query occurs, the spline is not extrapolated along the boundary tangents. The query bypasses spline evaluation entirely and directly returns the raw keyframe value, preventing runaway polynomial curves beyond the clip bounds.

Application-Level Playback and Looping

Because glTF restricts sampler behavior to clamping, cyclic playback modes are not encoded in the standard asset data. Runtimes such as Three.js, Babylon.js, or game engines handle looping by wrapping the query time before passing it to the glTF sampler:

\[\text{query\_time} = t_0 + ((t - t_0) \pmod{(t_n - t_0)})\]

If an engine does not apply time-wrapping logic, querying past the end of the clip naturally freezes the animated node at its final pose due to glTF's underlying clamp-to-edge semantics.