Three.js 仅在滚动或移动鼠标时渲染才起作用
我有一个大问题,让我的动画工作,没有任何动画在现场,除非我环顾四周与我的鼠标。我一停止环顾四周,动画就停止了。我尝试了很多事情,却不知道我做错了什么Three.js 仅在滚动或移动鼠标时渲染才起作用,three.js,Three.js,我有一个大问题,让我的动画工作,没有任何动画在现场,除非我环顾四周与我的鼠标。我一停止环顾四周,动画就停止了。我尝试了很多事情,却不知道我做错了什么 function onMouseMove(e) { mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1; mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1; } window.addEventLi
function onMouseMove(e) {
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
}
window.addEventListener( "mousemove", onMouseMove, false );
window.requestAnimationFrame(render);
function animate(){
controls.update();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
function render(){
sunArray[1].rotation.y += 0.01;
renderer.render(scene, camera);
};
您需要使其反复调用requestAnimation frame:
window.requestAnimationFrame(render);
应该可以我已经有了,如果你是说在动画功能中,它只会使整个浏览器冻结。在你发布的代码片段中,你没有这个功能。如果您仍然有问题,请尝试将其设置为JSFIDDLE。通过这样做,您现在有两个渲染器调用,这是不必要的。您只想添加到动画函数中的是sunArray[1]。rotation.y+=0.01;而不是渲染;改变了,谢谢,我不知道。更改为您的解决方案。
function animate(){
sunArray[1].rotation.y += 0.01;
controls.update();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
function render(){
renderer.render(scene, camera);
};