Skip to content

Raycaster.setFromCamera: Position the ray origin at near plane rather than camera origin #28026

@gkjohnson

Description

@gkjohnson

Description

Currently when calling Raycaster.setFromCamera( mouse, camera ) the origin is currently set at the camera origin (perspective camera) or plane (orthographic camera) resulting in raycasts hitting objects that are being clipped by the camera plane (or not hitting object behind the camera if an ortho camera has a negative near clip value). Is there a reason for this?

When users set the raycaster from camera and mouse settings they are expecting to interact with objects that are rendered on the screen.

Solution

Place the raycaster origin on the camera near clip plane instead of the camera plane / origin.

See the following example showing that the box displays as intersected (red) even when hovering over the center of the object that is clipped by the camera. You can uncomment line 43 to see the suggested change:

https://jsfiddle.net/bjrog3Lw/1/

Alternatives

  • User must manually set the ray origin after calling setFromCamera.
  • Provide a setting to toggle the expected behavior.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions