繁体   English   中英

Orbit Controls 跟随鼠标不点击three.js

[英]Orbit Controls follow the mouse without clicking three.js

有没有人有代码可以强制three.js 中的轨道控件在mousemove 上移动场景而不是click + mousemove 我试过使用这个线程中的答案: 如何在鼠标移动时重新创建Three.js OrbitControl 移动? 但遗憾的是它抛出一个错误“最大调用堆栈大小超出错误”,我只得到一个黑色画布,里面什么都没有......

我也试过改变

scope.domElement.addEventListener( 'mousedown', onMouseDown, false );

scope.domElement.addEventListener( 'mousemove', onMouseDown, false );

在 OrbitControls.js 文件中,但它似乎在移动和时不时停止时冻结......

有没有人设法解决这个问题? 提前致谢!

这个怎么样; https://jsfiddle.net/EthanHermsey/e3b501cw/51/

document.addEventListener('mousemove', function(e){
    let scale = -0.01;
    orbit.rotateY( e.movementX * scale );
    orbit.rotateX( e.movementY * scale ); 
    orbit.rotation.z = 0; //this is important to keep the camera level..
})

//the camera rotation pivot
orbit = new THREE.Object3D();
orbit.rotation.order = "YXZ"; //this is important to keep level, so Z should be the last axis to rotate in order...
orbit.position.copy( mesh.position );
scene.add(orbit );

//offset the camera and add it to the pivot
//you could adapt the code so that you can 'zoom' by changing the z value in camera.position in a mousewheel event..
let cameraDistance = 1;
camera.position.z = cameraDistance;
orbit.add( camera );

使用一个 Object3D 作为相机的枢轴。 它随着鼠标移动而旋转。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM