Mhd
Mhd

Reputation: 811

How to do PerspectiveCamera panning with Left mouse button in Trackball controls (r87)?

By default, Camera panning is with right mouse button

 Control.panSpeed = 1.5;

but I want it to work in left mouse button. How to set this?

Upvotes: 1

Views: 979

Answers (1)

AquaVitae
AquaVitae

Reputation: 177

This requires an easy modification to the trackball code.

If you look at TrackballControls.js, the very beginning details the keycode-correlated state machine (source code):

THREE.TrackballControls = function ( object, domElement ) {

    var _this = this;
    var STATE = {NONE: -1, ROTATE: 0, ZOOM: 1, PN: 2, TOUCH_ROTATE: 3, TOUCH_ZOOM_PANE: 4};

    this.object = object;
    this.domElement = ( domElement !== undefined ) ? domElement : document;

    // API

    this.enabled = true;
    this.screen  = { left: 0, top: 0, width: 0, height: 0 };

Which is related to the keydown() function further down (source code):

function keydown( event ) {

    if ( _this.enabled === false ) return;

    window.removeEventListener( 'keydown', keydown );

    _prevState = _state;

    if ( _state !== STATE.NONE ) {

        return;

    } else if ( event.keyCode === _this.keys[ STATE.ROTATE ] && ! _this.noRotate ){

        _state = STATE.ROTATE;

    } else if ( event.keyCode === _this.keys[ STATE.ROTATE ] && ! _this.noZoom ){

        _state = STATE.ZOOM;

    } else if ( event.keyCode === _this.keys[ STATE.ROTATE ] && ! _this.noPan ){

        _state = STATE.PAN;

    }        

So, I haven't had a chance to test this, but you should be able to change PAN in line 11 from 2 (the keycode for Right Click) to 0 (Left Click) or any other keycode you want. Remember to change ROTATE as well to avoid the bug-prone directive of rotating and panning at the same time.


EDIT: per @TheJim01's helpful correction, the actual click event triggering actually happens in function mousedown( event ) on line 393 of the script. event.button corresponds to the respective number in the state machine. Sorry about the confusion.

Upvotes: 1

Related Questions