![](/img/trans.png)
[英]Three.JS Orbit Controls - enabling and disabling without position jumping
[英]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.