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

DragControls: Add mouseButtons #29072

Closed
wants to merge 7 commits into from
Closed

DragControls: Add mouseButtons #29072

wants to merge 7 commits into from

Conversation

puxiao
Copy link
Contributor

@puxiao puxiao commented Aug 6, 2024

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 mesh
  • MOUSE.LEFT (no selected) - rotation of the camera
  • MOUSE.RIGH - camera panning
  • MOUSE.MIDDLE - camera zooming

@Mugen87
Copy link
Collaborator

Mugen87 commented Aug 6, 2024

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 THREE.Controls which acts as an abstract upper class for all concrete controls. Mouse and keyboard configuration could be part of THREE.Controls. E.g.

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 keys, mouseButtons and touches and the developer can overwrite these properties if required.

@puxiao
Copy link
Contributor Author

puxiao commented Aug 6, 2024

IMO, it's time to think about THREE.Controls which acts as an abstract upper class for all concrete controls. Mouse and keyboard configuration could be part of THREE.Controls. E.g.

I hope that day comes soon.


I have revised this PR, I don't know if it meets your expectations.

Copy link

github-actions bot commented Aug 7, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Filesize dev Filesize PR Diff
685.1 kB (169.6 kB) 685.1 kB (169.6 kB) +7 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Filesize dev Filesize PR Diff
462 kB (111.5 kB) 462 kB (111.5 kB) +0 B

@Mugen87
Copy link
Collaborator

Mugen87 commented Aug 7, 2024

I have refactored DragControls based on your PR. Would these changes work for you as well?

#29079

@puxiao
Copy link
Contributor Author

puxiao commented Aug 8, 2024

Good job !!!

@puxiao puxiao closed this Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants