BufferGeometry
Object3D
Raycaster
Camera
CubeCamera
PerspectiveCamera
OrthographicCamera
StereoCamera
Clock
Curve
CurvePath
Path
Shape
ShapePath
ArrowHelper
AxesHelper
BoxHelper
Box3Helper
CameraHelper
DirectionalLightHelper
GridHelper
PolarGridHelper
HemisphereLightHelper
PlaneHelper
PointLightHelper
SkeletonHelper
SpotLightHelper
Light
PointLight
RectAreaLight
SpotLight
DirectionalLight
HemisphereLight
LightShadow
PointLightShadow
AnimationLoader
AudioLoader
BufferGeometryLoader
CompressedTextureLoader
CubeTextureLoader
DataTextureLoader
FileLoader
ImageBitmapLoader
ImageLoader
Loader
LoaderUtils
MaterialLoader
ObjectLoader
TextureLoader
LoadingManager
Material
Box2
Box3
Color
Cylindrical
Euler
Frustum
Interpolant
Line3
MathUtils
Matrix3
Matrix4
Plane
Quaternion
AnimationAction
AnimationClip
AnimationMixer
AnimationObjectGroup
AnimationUtils
keyframeTrack
PropertyBinding
PropertyMixer
BooleanKeyframeTrack
QuaternionKeyframeTrack
StringKeyframeTrack
Audio
AudioAnalyser
AudioContext
AudioListener
PositionalAudio

AnimationClip.parseAnimation()

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);