我正在开发一个使用OrbitControls.js的简单Three.js演示。目前,鼠标左键旋转轨道,右键鼠标按钮,鼠标中键/滚轮推车(缩放)。但我想交换轨道和平移,以便分别用鼠标右键和鼠标左键控制它们。是否有配置设置来更改此功能?或者我是否需要深入研究代码来改变它?
答案 0 :(得分:3)
到现在为止,您可以非常轻松地配置鼠标控件。只需获取Control-Object,然后更改鼠标按钮配置,如下所示:
this._controls = new OrbitControls(world._engine._camera, world._container);
// Mouse buttons
this._controls.mouseButtons = { ORBIT: THREE.MOUSE.RIGHT, ZOOM: THREE.MOUSE.MIDDLE, PAN: THREE.MOUSE.LEFT };
答案 1 :(得分:1)
你需要深入研究代码;目前没有配置选项。令人高兴的是,这是一个非常容易的变化;您只需更新onMouseDown
函数并更改检查event.button
的条件:
// you could change this to `event.button == 1` if you wanted the
/// right mouse button to rotate, and so on...
if ( event.button === 0 ) {
if ( scope.noRotate === true ) return;
state = STATE.ROTATE;
rotateStart.set( event.clientX, event.clientY );
} else if ( event.button === 1 ) {
if ( scope.noZoom === true ) return;
state = STATE.DOLLY;
dollyStart.set( event.clientX, event.clientY );
} else if ( event.button === 2 ) {
if ( scope.noPan === true ) return;
state = STATE.PAN;
panStart.set( event.clientX, event.clientY );
}
https://github.com/mrdoob/three.js/blob/master/examples/js/controls/OrbitControls.js#L333-L352
这些控件放在示例中(而不是核心部分)的原因之一是人们的需求变化很大,因此鼓励您编辑控件以满足您的需求。
three.js r68
答案 2 :(得分:0)
从Three.js r99开始,您可以像这样切换轨道控件的鼠标按钮:
controls.mouseButtons = {
LEFT: THREE.MOUSE.RIGHT,
MIDDLE: THREE.MOUSE.MIDDLE,
RIGHT: THREE.MOUSE.LEFT
}
请参见https://threejs.org/docs/#examples/controls/OrbitControls