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

mouseup vs. mousedown selectivity #27

Open
psytron opened this issue Jul 11, 2024 · 4 comments
Open

mouseup vs. mousedown selectivity #27

psytron opened this issue Jul 11, 2024 · 4 comments

Comments

@psytron
Copy link

psytron commented Jul 11, 2024

I'm adding listeners to objects in a loop like this:

ref.addEventListener('mousedown', this.fireClickStarting );
ref.addEventListener('mouseup', this.fireClickEnding );

interactionManager.add( ref )

'mousedown' activates correctly only when clicked object ref
but 'mouseup' activates everywhere to all clicks in whole scene

This worked correctly in previous THREE REV, so perhaps it is a THREE.js R165 interaction

@markuslerner
Copy link
Owner

Hi @psytron, please check, if the 'click' event fires only on that object and let me know. It should actually rather be browser-related than three.js related. Which browser are you using? Do you have your code online?

@psytron
Copy link
Author

psytron commented Jul 19, 2024

the 'click' event ( subscribed as 'mouseup' ) fires anywhere on the whole screen. 'mousedown' fires correctly when clicking on the object but 'mouseup' fires everywhere. Using Chrome Version 126.0.6479.126 (Official Build) (arm64)

The code is pretty simple pretty much like the code above:

ref.addEventListener('mousedown', this.fireClickStarting );
ref.addEventListener('mouseup', this.fireClickEnding );

interactionManager.add( ref )

The two functions are subscribed to mouseup and mousedown in exactly the same way, but one behaves differently

@psytron
Copy link
Author

psytron commented Jul 25, 2024

'mousemove' is also same issue ( firing everywhere on whole screen )
'mousedown' works correctly , only on object

@markuslerner
Copy link
Owner

Hi @psytron, sorry for my late reply. I was on holiday. "mouseup" will of course fire everywhere on the screen. "click" should fire only on the object.
Nevertheless I added the property "wasIntersectedOnMouseDown" to InteractiveEvent in Version 1.8.0, so you can determine, whether an event was started (mouse down, touch down) on that particular object like this:

cube.addEventListener('mouseup', (event) => {
   if (event.wasIntersectedOnMouseDown) {
      // Object was intersected when mouse down fired, so this is essentially a click event
   } else {
      // Object was not intersected when mouse down fired
   }
});

You can also use the properties intersected, to check if the object is currently intersected and wasIntersected to check, if the object was intersected during the last event or render.

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

No branches or pull requests

2 participants