The spec explains the animations.samplers.input
property as:
The index of an accessor containing keyframe input values, e.g., time. That accessor must have componentType FLOAT. The values represent time in seconds with time[0] >= 0.0, and strictly increasing values, i.e., time[n + 1] > time[n].
However, I'm having a bit of trouble understanding this from the first basic example on the demo repo, Animated Triangle
Specifically, if we bring the relevant binary data for the animation from animation.bin and decode it into a Float32Array
, we get the following list of values:
[0, 0.25, 0.5, 0.75, 1, 0, 0, 0, 1, 0, 0, 0.7070000171661377, 0.7070000171661377, 0, 0, 1, 0, 0, 0, 0.7070000171661377, -0.7070000171661377, 0, 0, 0, 1]
This of course does not make sense in light of "strictly increasing values".
What am I misunderstanding here? How are these values meant to be used (in combination with output
) in order to update the rotation over time?
Note that animation.bin is the view referenced from the input
sampler. In other words, from the gltf
答案 0 :(得分:1)
你的解码太过分了。尽管bufferView 2是字节0到100,但访问器2不会调用所有这些字节。这是访问者2:
{
"bufferView" : 2,
"byteOffset" : 0,
"componentType" : 5126,
"count" : 5,
"type" : "SCALAR",
"max" : [ 1.0 ],
"min" : [ 0.0 ]
},
注意那里的count: 5
。计数定义为:
此访问器引用的属性数,不要与字节数或组件数混淆。
因此,accesessor 2是bufferView 2中偏移0的前五个SCALAR
值,即上面解码输出的前五个数字:
[0, 0.25, 0.5, 0.75, 1]
FWIW,有一些工具可以帮助调查glTF二进制文件。这是VSCode的glTF扩展中的“Peek Definition”函数:
(免责声明,我是此扩展程序的作者之一,虽然我自己没有编写此解码功能)。