【发布时间】:2021-09-25 22:10:46
【问题描述】:
我正在尝试使用 Three.js 创建游戏,我想问是否有办法为 GLFT 模型设置动画,但我想使用随机间隔而不是动画循环。就我而言,游戏是关于照顾青蛙的(但我很酷,所以我把它拼成了 phrogs),作为一个空闲动画,我希望青蛙随机发出叫声。在进一步的开发中,我还想为运动、进食等添加随机播放动画,但现在我只需要呱呱叫的动画。 以下是加载模型并为其设置动画的代码:
const basePhrog = new GLTFLoader()
var obj
basePhrog.load('assets/models/Phrogs/base phrog/phrog.gltf', function (gltf) {
mixer = new THREE.AnimationMixer(gltf.scene)
obj = gltf.scene
var action = mixer.clipAction(gltf.animations[0])
scene.add(gltf.scene)
action.play()
})
我的动画循环如下所示:
function animate () {
requestAnimationFrame(animate)
var delta = clock.getDelta()
if (mixer) mixer.update(delta)
renderer.render(scene, camera)
}
animate()
希望您能提供帮助,感谢您的任何建议!
【问题讨论】:
标签: javascript animation three.js gltf