You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解析glTF的animations.samplers.input?对官方示例存疑

Understanding animations.samplers.input in glTF's "Animated Triangle" Example

Hey there, let's unpack this confusion around animations.samplers.input using the Animated Triangle example— I remember struggling with this exact link between the spec and raw binary data when I first started with glTF!

First, let's recap the spec requirement clearly:

规范中对animations.samplers.input属性的说明:包含关键帧输入值(如时间)的accessor的索引。该accessor的componentType必须为FLOAT,值以秒为单位表示时间,且满足time[0] ≥ 0.0、严格递增(即time[n+1] > time[n])。

Let's tie this to the Animated Triangle example

Here's how this translates to the actual files in that example:

  1. Find the sampler in the glTF JSON
    In the animation section of the JSON, you'll see a samplers array entry where the input field is an integer— that's the index of the accessor holding the time values.

  2. Look up the accessor
    The accessor with that index will have:

    • componentType: 5126 (this is the glTF code for 32-bit FLOAT)
    • type: "SCALAR" (since each input is a single time value, not a vector)
    • bufferView pointing to a specific range in the .bin file, plus details like count (how many keyframe times there are)
  3. Parse the binary data
    When you extract the bytes from the .bin file at the range specified by the buffer view, you'll need to read them as 32-bit little-endian floats (glTF uses little-endian for all binary data). For the Animated Triangle, this will be a short sequence like 0.0, 1.0, 2.0— notice how each value is strictly larger than the last, and the first is ≥ 0.0, which checks all the spec boxes.

What this actually does for the animation

These time values are the "timestamps" that tell the glTF runtime when to trigger each keyframe change. For example, if the first input value is 0.0 seconds, that's when the triangle starts at its initial position; at 1.0 seconds, it moves to the next keyframe position, and so on. The strictly increasing rule ensures the animation plays smoothly in order, no backward jumps or broken timing.

Quick troubleshooting tips

  • If you're parsing manually, don't mix up endianness— this is a super common mistake that leads to garbage time values.
  • Double-check the accessor's count matches the number of floats you extract from the binary. If they don't line up, you're looking at the wrong byte range.

内容的提问来源于stack exchange,提问作者davidkomer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 12:34:24