如何在三个js中获取动画的持续时间?

How do I get the duration of an animation in three js?

如何在 three.js 中获取动画的持续时间?

假设我们有这样一个样本,

var mixer = new THREE.AnimationMixer(gltf.scene)
gltf.animations.forEach((clip)) => {
 let animation = mixer.clipAction(clip)
animation.setLoop(THREE.LoopOnce)
animation.clampWhenFinished = true
animation.play()
}

动画的持续时间可以通过 clip.duration 在 forEach 循环内返回。您可以在 AnimationClip 的 three.js 文档中找到更多相关信息。请记住,这会在几秒钟内返回。 https://threejs.org/docs/#api/en/animation/AnimationClip.duration