AnimationClip.parseAnimation()
是three.js中的一个静态方法,用于将动画数据解析并创建 AnimationClip
对象。
AnimationClip.parseAnimation(animationData, bones)
animationData
:一个JavaScript对象,包含动画数据。具体格式见下面的"动画数据格式"一节。bones
:一个可选的骨骼骨架数组。如果提供,将使用它来创建 AnimationClip
对象时的骨骼顺序。如果不提供,则将使用动画数据中骨骼动画的顺序。返回创建的 AnimationClip
对象。
三维动画通常由键帧动画序列组成。AnimationClip.parseAnimation()
所需的数据格式如下:
{
"name": "动画名称",
"tracks": [
{
"name": "骨骼名称",
"type": "骨骼动画类型(可能是旋转、位移或缩放)",
"times": [0.0, 1.0, 2.0, ..., n-1],
"values": [
[x1, y1, z1], [x2, y2, z2], ..., [xn, yn, zn]
]
},
...
]
}
其中,name
指动画名称, tracks
是一个数组,每个元素表示一个骨骼的动画。name
指骨骼名称,type
是骨骼动画的类型, times
指每一帧的时间, value
则是各帧的骨骼关键帧值。
var animationData = {
"name": "walking",
"tracks": [
{
"name": "root",
"type": "vector3",
"times": [ 0, 1, 2, 3, 4 ],
"values": [
[ 5, 3, 0 ],
[ 10, 5, 2 ],
[ 15, 7, 5 ],
[ 20, 5, 6 ],
[ 25, 3, 0 ]
]
},
{
"name": "torso",
"type": "quaternion",
"times": [ 0, 1, 2, 3, 4 ],
"values": [
[ 0, 0, 0, 1 ],
[ 0, -0.3827, 0, 0.9239 ],
[ 0, -0.9239, 0, 0.3827 ],
[ 0, -0.9239, 0, 0.3827 ],
[ 0, 0, 0, 1 ]
]
},
{
"name": "leftFoot",
"type": "quaternion",
"times": [ 0, 1, 2, 3, 4 ],
"values": [
[ 0, 0, 0, 1 ],
[ 0.3827, 0, 0, 0.9239 ],
[ 0, 0, 0, 1 ],
[ 0, 0, 0, 1 ],
[ 0, 0, 0, 1 ]
]
},
{
"name": "rightFoot",
"type": "quaternion",
"times": [ 0, 1, 2, 3, 4 ],
"values": [
[ 0, 0, 0, 1 ],
[ 0, 0, 0, 1 ],
[ 0.3827, 0, 0, 0.9239 ],
[ 0, 0, 0, 1 ],
[ 0, 0, 0, 1 ]
]
}
]
};
var clip = THREE.AnimationClip.parseAnimation(animationData);