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

AnimationLoader.load()

函数描述

AnimationLoader.load()是three.js中用于加载动画数据的函数。该函数的作用是根据给定的URL加载动画数据,当加载成功后将其封装为AnimationClip对象返回。AnimationClip对象可以用于播放和控制动画。

语法

AnimationLoader.load(url: string, onLoad: function, onProgress?: function, onError?: function): void

参数

  • url: string - 用于加载动画数据的URL。
  • onLoad: function - 数据加载成功后要执行的回调函数。其中包含一个AnimationClip参数,表示加载成功后得到的动画数据。
  • onProgress: function, optional - 数据加载过程中要执行的回调函数。其中包含一个XMLHttpRequestProgressEvent参数,表示加载的进度。
  • onError: function, optional - 数据加载失败时要执行的回调函数。其中包含一个Error参数,表示加载失败的原因。

示例

import { AnimationLoader } from 'three';

const url = 'path/to/animation.json';

const onLoad = (animationClip) => {
    // 加载成功的回调函数,动画数据已经封装成AnimationClip对象
    console.log(animationClip);
};

const onProgress = (event) => {
    // 加载进度回调函数
    console.log(`已加载 ${event.loaded} / ${event.total} 字节`);
};

const onError = (error) => {
    // 加载失败回调函数
    console.error(`发生错误:${error}`);
};

AnimationLoader.load(url, onLoad, onProgress, onError);

返回值

AnimationLoader.load()函数没有返回值。AnimationClip对象通过onLoad回调函数传递。