markuslerner / THREE.Interactive

Fast and simple interaction manager for three.js for enabling mouse and touch events on 3D objects
MIT License
178 stars 26 forks source link

The `type` property is a little bit confusing #16

Closed LancerComet closed 1 year ago

LancerComet commented 2 years ago

The document says

type (string) – event type: 'click', 'mouseover', 'mouseout', 'mouseenter', 'mouseleave', 'mousedown', 'mousemove', 'mouseup', 'touchstart', 'touchmove', 'touchend', 'pointerdown', 'pointerup'

So it seems like it is possible to have a type to be a pointerdown or a pointerup. But after reading the codes I have found that it is impossible to be like that, because the pointer events use the mouse events' handlers (code is here), and the mouse events just fire mouseup and mousedown.

So it is a little bit confusing, this is what you think:

// A cube can have a "pointerdown" event because the document says so.
cube.addEventListener('pointerdown', (event) => {
  // ...
});

but this is what you actually have to do:

// Well I just have to use "mousedown" event.
// But this handler has been registered as "pointerdown" actually.
cube.addEventListener('mousedown', (event) => {
  // ...
});

So this is my suggestion:

  1. Get rid of the pointerdown and pointerup from the document.
  2. Fire pointerdown and pointerup when PointerEvent is supported.

Best wishes

markuslerner commented 1 year ago

@LancerComet, thank you for pointing this out! Sorry for my late reply. I was pretty busy in the past few weeks. I will look into it, hopefully in the next few days, and get back here.

markuslerner commented 1 year ago

@LancerComet, now I'm firing pointer events additionally when they are supported: Release 1.5.0 Thanks again. Let me know, if there are any bugs.