yomotsu / camera-controls

A camera control for three.js, similar to THREE.OrbitControls yet supports smooth transitions and more features.
https://yomotsu.github.io/camera-controls/
MIT License
1.99k stars 253 forks source link

Cannot dispatch custom event #503

Open vinkovsky opened 5 months ago

vinkovsky commented 5 months ago

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 commented 5 months ago

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?

https://github.com/yomotsu/camera-controls/assets/212837/c4de77ea-d1b8-4a5f-95b5-a967f4bca2da

vinkovsky commented 5 months ago

@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 commented 5 months ago

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 commented 5 months ago

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.