Three.js AnimationMixer仅在打印返回值时才更新的异常问题求助
Three.js AnimationMixer仅在打印返回值时才更新的异常问题求助
各位大佬,遇到一个特别诡异的Three.js问题,想请教下大家:
我发现AnimationMixer.update(delta)方法居然只有在我打印它的返回值时才会生效,不打印的话动画根本动不起来,这实在太奇怪了!
能正常触发动画的代码:
function animate() { requestAnimationFrame(animate); renderer.render(scene, camera); // 更新动画混合器... Object.values(sandbox.models).forEach(x => (x.mixer && console.log(x.mixer.update(clock.getDelta())))); }
完全无效的两种写法:
第一种:
function animate() { requestAnimationFrame(animate); renderer.render(scene, camera); // 更新动画混合器... Object.values(sandbox.models).forEach(x => (x.mixer && (x.mixer.update(clock.getDelta())))); }
第二种:
function animate() { requestAnimationFrame(animate); renderer.render(scene, camera); // 更新动画混合器... Object.values(sandbox.models).forEach(x => (x.mixer && void(x.mixer.update(clock.getDelta())))); }
我通过AnimationMixer.clipAction(animation).play()启动动画后,只有第一种带console.log的写法能让动画正常播放,另外两种写法完全没反应。
这真的太匪夷所思了——为什么混合器的更新操作必须依赖打印返回值才能生效?
因为项目代码量很大,还有很多关联的外部文件,没法贴出完整代码。而且总不能每秒打印几千次吧,这不仅不合理,还会严重拖慢游戏的运行速度,实在不是长久之计。
备注:内容来源于stack exchange,提问作者Parking Master
相关产品推荐
相关产品推荐

