Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trackball controls cannot customise user mouse buttons #26366

Closed
LinkunGao opened this issue Jul 3, 2023 · 2 comments · Fixed by #29442
Closed

Trackball controls cannot customise user mouse buttons #26366

LinkunGao opened this issue Jul 3, 2023 · 2 comments · Fixed by #29442
Labels
Milestone

Comments

@LinkunGao
Copy link
Contributor

Description

The default is:

    this.mouseButtons = {
      LEFT: MOUSE.ROTATE,
      MIDDLE: MOUSE.DOLLY,
      RIGHT: MOUSE.PAN,
    };

But if we change the buttons function like this will get a strange result which is not we expect:

 this.mouseButtons = {
      LEFT: MOUSE.PAN,
      MIDDLE: MOUSE.DOLLY,
      RIGHT: MOUSE.ROTATE,
    };

Then in the code we can find in line 537, when user mouse click down:

if ( _state === STATE.NONE ) {
  switch ( event.button ) {
          case scope.mouseButtons.LEFT:
                _state = STATE.ROTATE;
          break;
          case scope.mouseButtons.MIDDLE:
               _state = STATE.ZOOM;
          break;
          case scope.mouseButtons.RIGHT:
              _state = STATE.PAN;
          break;
  }
}

We can not just change the mouseButtons to change the controls behaviors.

Solution

Because the value of the MOUSE and controls STATE are similar:

MOUSE.PAN = STATE.PAN = 2
MOUSE.ROTATE = STATE.ROTATE = 0
MOUSE.DOLLY = STATE.ZOOM = 1

So what we can do is:

  • in .d.ts we limit the value sign in the mouseButtons:
 mouseButtons: {
    LEFT: MOUSE.ROTATE | MOUSE.PAN | -1;
    MIDDLE: MOUSE.DOLLY;
    RIGHT: MOUSE.ROTATE | MOUSE.PAN | -1;
  };
  • in js, we can change the mouse down like this:
if (_state === STATE.NONE) {
        switch (event.button) {
          case 0: //mouse left button click
            _state = scope.mouseButtons.LEFT;
            break;

          case 1: //mouse wheel
            _state = scope.mouseButtons.MIDDLE;
            break;

          case 2: //mouse right button click
            _state = scope.mouseButtons.RIGHT;
            break;
        }
      }
  • Then, after this we can customize the controls now when we use the trackball controls in our project.

Alternatives

no, haven't considered others.

Additional context

No response

@Mugen87 Mugen87 added the Addons label Jul 4, 2023
@LeviPesin
Copy link
Contributor

Couldn't we just do this?

if ( _state === STATE.NONE ) {

    _state = scope.mouseButtons[ event.button ];

}

@LeviPesin
Copy link
Contributor

Also, I think there is a logical error in the current code. event.button, being MOUSE.LEFT/MIDDLE/RIGHT is compared to scope.mouseButtons.LEFT/MIDDLE/RIGHT, which is MOUSE.ROTATE/DOLLY/PAN. This works only because they are equal.
I will file a PR with my solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants