keyframeTrack.interpolantFactoryMethodDiscrete()
该方法是THREE.KeyframeTrack
类的静态属性,用于创建“离散插值”的插值器工厂方法,可以用于所有不需要中间值(也就是没有过渡效果)的关键帧动画效果。
THREE.KeyframeTrack.interpolantFactoryMethodDiscrete(result: any) : Function
result
(任意类型):将在调用插值器前存放结果的变量返回一个接受两个参数的函数:(result: any, sampleValues: Array, sampleTimes: Array, frameRate: Number)
。
result
(任意类型):将在调用插值器后存放结果的变量sampleValues
(Array
) : 包含动画关键帧的值的数组sampleTimes
(Array
) : 包含动画关键帧的时间点的数组frameRate
(Number
):每秒渲染的帧数(如果未提供,则默认为60)const result = {
position: new THREE.Vector3(),
quaternion: new THREE.Quaternion()
}
const positionValues = [
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(50, 0, 0),
new THREE.Vector3(100, 0, 0)
]
const quaternionValues = [
new THREE.Quaternion(),
new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 1, 0), Math.PI / 2),
new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 1, 0), Math.PI)
]
const track = new THREE.KeyframeTrack('.position', [0, 1, 2], positionValues.flat(), THREE.InterpolateDiscrete)
const quatTrack = new THREE.QuaternionKeyframeTrack('.quaternion', [0, 1, 2], quaternionValues.flat(), THREE.InterpolateDiscrete)
const mixer = new THREE.AnimationMixer(mesh)
const clip = new THREE.AnimationClip('clip', -1, [track, quatTrack])
const action = mixer.clipAction(clip)
// 将使用离散插值器
track.createInterpolant = THREE.KeyframeTrack.interpolantFactoryMethodDiscrete(result)
quatTrack.createInterpolant = THREE.QuaternionKeyframeTrack.interpolateDiscrete