markuslerner / THREE.Interactive

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

interactionManager.update() event based #13

Closed simsuniy closed 1 year ago

simsuniy commented 2 years ago

Thanks for that great work!

One thing I wondered about was the "interactionManager.update();" I added it to the render function but didn't get any mousemove events, unless I clicked on one of my objects (then the "click" and the "enter/leave" events were triggerd). Then I found out you use the update() inside the animation but in my app I do not have any animation function as I use three event based. (In my opininion this is something like polling, and polling should be used only if there is no other way...)

For me I moved the update() to the onDocumentMouseMove(e) (just added this.update();) and removed the update on rendering. so, every time document triggers the mouseMove event, the interactionManager will be updated.

Do you see any problems on doing it that way?

markuslerner commented 2 years ago

Hi @simsuniy, thank you for pointing this out. The main reason why update() is called before render is that even if the pointer hasn't been moved or clicked, elements in the scene might have changed their position and not cause any intersection with the pointer any more. So if you have no animation, it should be sufficient to call update() in the onDocumentMouseMove() event.