-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
DragControls: Add mouseButtons
#29072
Conversation
What I don't like about our control classes is the fact that stuff like this is implemented differently in each module. IMO, it's time to think about class Controls extends EventDispatcher {
constructor( object, domElement ) {
super();
this.object = object;
this.domElement = domElement;
this.enabled = true;
this.keys = {};
this.mouseButtons = { LEFT: null, MIDDLE: null, RIGHT: null };
this.touches = { ONE: null, TWO: null };
}
connect() {}
disconnect() {}
dispose() {}
update() {}
} I don't think getters and setters are required though. Controls can predefine |
I hope that day comes soon. I have revised this PR, I don't know if it meets your expectations. |
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
I have refactored |
Good job !!! |
This PR introduces a new property
mouseButtons
to DragControls.This enhancement allows users to customize which mouse button can trigger drag interactions.
This makes it easy to use DragControls with other controllers.
For example:
DragControls + OrbitControls
const myOrbitControls = new OrbitControls(...) const myDragControls = new DragControls(...) + myDragControls.mouseButtons = { LEFT: MOUSE.DRAG, MIDDLE: null, RIGHT: null } myDragControls.addEventListener('dragstart', () =>{ myOrbitControls.enabled = false }) myDragControls.addEventListener('dragend', () =>{ myOrbitControls.enabled = true })
I can achieve the following results:
MOUSE.LEFT (selected)
- drag meshMOUSE.LEFT (no selected)
- rotation of the cameraMOUSE.RIGH
- camera panningMOUSE.MIDDLE
- camera zooming