Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cursor reports incorrect object when objects overlap #4978

Closed
diarmidmackenzie opened this issue Dec 9, 2021 · 2 comments
Closed

Cursor reports incorrect object when objects overlap #4978

diarmidmackenzie opened this issue Dec 9, 2021 · 2 comments

Comments

@diarmidmackenzie
Copy link
Contributor

Description:

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.
dmarcos added a commit to dmarcos/aframe that referenced this issue Dec 10, 2021
@dmarcos
Copy link
Member

dmarcos commented Dec 10, 2021

Thanks. Potential solution at #4979. I added your example in the hello world to the PR temporarily for convenience. Would you mind taking a quick look and let me know if it works? Thanks so much.

@diarmidmackenzie
Copy link
Contributor Author

Yes, that fix works perfectly. Thanks for jumping on this so quickly!

dmarcos added a commit to dmarcos/aframe that referenced this issue Dec 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants