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
2.05k stars 256 forks source link

Cannot dispatch custom event #503

Open vinkovsky opened 7 months ago

vinkovsky commented 7 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 6 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 6 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 6 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 6 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.