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

PropertyMixer.accumulateAdditive()

PropertyMixer.accumulateAdditive()PropertyMixer类中的一个方法,用于将累加器的值与动画帧的值相加,生成新的值。该方法用于动画的加法混合。

语法

PropertyMixer.accumulateAdditive( buffer, stride, offset )

参数

  • buffer:{Float32Array},长度为n的浮点数数组,表示混合数据。
  • stride:{number},表示混合数据的步长。
  • offset:{number},起始位置偏移。

返回值

  • 无返回值。

用法

// 创建属性混合器
let propertyMixer = new THREE.PropertyMixer( mesh.rotation, 1 );
propertyMixer.zeroQuaternion = new THREE.Quaternion();

// 动画初始化,假设有5帧
let times = [0, 1, 2, 3, 4];
let values = [
    new THREE.Quaternion(),
    new THREE.Quaternion(),
    new THREE.Quaternion(),
    new THREE.Quaternion(),
    new THREE.Quaternion()
];
let track = new THREE.QuaternionKeyframeTrack( ".quaternion", times, values );
let clip = new THREE.AnimationClip( "test", -1, [track] );
let mixer = new THREE.AnimationMixer( mesh );
let animationAction = mixer.clipAction( clip );
animationAction.play();

// 在动画循环中更新属性混合器的状态
function animate() {
    mixer.update( clock.getDelta() );
    propertyMixer.buffer = mesh.rotation.toArray();
    propertyMixer.cumulativeWeight = animationAction.weight;
    propertyMixer.update( frameTime );
}

在属性混合器的更新函数中,累加器应执行accumulateAdditive()方法:

PropertyMixer.prototype.accumulateAdditive = function( buffer, stride, offset ) {
    this.buffer[ offset ] += buffer[ 0 ] * this.weight;
    this.buffer[ offset + 1 ] += buffer[ 1 ] * this.weight;
    this.buffer[ offset + 2 ] += buffer[ 2 ] * this.weight;
    this.buffer[ offset + 3 ] += buffer[ 3 ] * this.weight;
};

该函数用于计算当前动画帧的值与累加器的值之和,并将结果设置为新的累加器值。

应用场景

PropertyMixer.accumulateAdditive()方法通常用于将多个动画的输出数据合并,生成可应用于对场景中对象进行控制的最终数据。它允许应用多个动画,并在应用时混合它们,从而创建复杂的动画交互,例如,同时控制多个对象的位置、旋转、缩放等属性。

参考文献