Skip to content

Raycaster.intersectObjects returns wrong order #16031

@drcmda

Description

@drcmda
Description of the problem

ezgif com-optimize (6)

intersectObjects does not seem to take actual render order into account, the docs say:

Checks all intersection between the ray and the object with or without the descendants. Intersections are returned sorted by distance, closest first. An array of intersections is returned...

but that will lead to a false order when multiple objects are positioned in the same place. They're rendered correctly, since Three knows internally which object is on top of the other due to opaque ordering, renderOrder and perhaps other indications. But the Raytracer seems to be disconnected from that knowledge as it merely sorts distance, which is random.

I am specifically bumping into this now because i am trying to implement event.stopPropagation for events: codesandbox The first object that should receive the event is the green one, when it calls stopPropagation, the blue image shouldn't fire. But since order isn't deterministic the object that's visually behind gets to stop propagation first.

Three.js version
  • r102
Browser
  • All of them
OS
  • All of them

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions