-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
Description:
- A-Frame Version: 1.2.0
- Platform / Device: Desktop + mouse
- Reproducible Code Snippet or URL: https://problems-with-cursor-on-overlapping-objects.glitch.me/
Expected behaviour:
- when pointer is over the sphere, the sphere should be green.
- when pointer is over the torus, the torus should be green.
- same with click events - clicking sphere should indicate sphere clicked, and same with torus.
Observed behaviour:
- when moving from sphere to torus, or torus to sphere, the object that is green often doesn't update.
- click indications often indicate the wrong object (not the one that was clicked on).
Cause of problem.
Problems arise with cursor+raycaster solution when you move from one object to another, but both of them remain intersected by the mouse ray.
Cursor only updates state & emits events when it receives events from raycaster.
However raycaster only emits events when the set of intersected objects changes, not when their order changes.
In this case, the set of intersected objects remains constant, it's just their (distance-based) order that changes. Hence no events from raycaster, and no updates to cursor state.
The only ways I can see to fix this would be:
1 - Have cursor operate a tick, and proactively check raycaster object list.
2 - Have new event from the raycaster called something like intersectionOrderChanged, and update cursor to handle that.
2 seems like it would be a better solution, and presumably more performant.
- If cursor was going to run a tick, you may as well get rid of all the event listeners altogether & do everything on the tick...
- Applications that use raycaster might also want this event, to handle this exact same situation.
My view of this is that:
- handling this case is within the range of what I'd expect from cursor.
- therefore there is a case for fixing this within A-Frame.
- best fix would be with a new event on the raycaster, that fires whenever the order of raycasted objects changes.
- I'd be happy to contribute this fix, if there's agreement that it is the correct approach.