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

Cannot dispatch custom event #503

Open
vinkovsky opened this issue Apr 22, 2024 · 4 comments
Open

Cannot dispatch custom event #503

vinkovsky opened this issue Apr 22, 2024 · 4 comments

Comments

@vinkovsky
Copy link

vinkovsky commented Apr 22, 2024

Describe the bug

For some reasons i need to dispatch custom events. For example i use pointerdown.

canvas.dispatchEvent(
  new PointerEvent('pointerdown', {
    button: 1,
    pointerType: 'mouse',
    clientX,
    clientY
  })
)

To Reproduce

Steps to reproduce the behavior:

  1. Go to the demo
  2. Try to move mouse on the canvas
  3. Your mouse should emit pointerdown event, but it doesnt

Code

const handleMouseMove = ({ clientX, clientY }) => {
  const dispatched = gl.domElement.dispatchEvent(
    new PointerEvent('pointerdown', {
      button: 1,
      pointerType: 'mouse',
      clientX,
      clientY
    })
  )
  console.log(dispatched)
}
window.addEventListener('mousemove', handleMouseMove)

Live example

https://codesandbox.io/p/sandbox/cameracontrols-basic-forked-gjdc8g?file=%2Fsrc%2FApp.js%3A29%2C4-40%2C60

Expected behavior

Custom events must fire

Screenshots or Video

No response

Device

Desktop

OS

iOS

Browser

Chrome

@yomotsu
Copy link
Owner

yomotsu commented May 2, 2024

I checked your demo and followed the provided reproduction steps.
I observed true being output in the console when moving the mouse pointer.
Could you please double-check the demo?

Untitled.mp4

@vinkovsky
Copy link
Author

@yomotsu Thanks for your reply! Yes, this event is dispatched successfully, but there is no visual behavior. should work exactly the same as clicking the left mouse button, but programmatically

@vinkovsky
Copy link
Author

that is, when you move the mouse across the screen, you should see the camera fly around the object, but this does not happen

@yomotsu
Copy link
Owner

yomotsu commented May 4, 2024

this does not happen

Are you looking to enable orbit rotation without needing to press a mouse button?
If so, that is intended. Dragging in camera-controls is a little complex, and unfortunately, you cannot modify this behavior using just a 'pointerdown' event.

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