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

Hardcoded maximum ray distance when Viewport processes 3d object picking #49735

Closed
Tracked by #39876
Flarkk opened this issue Jun 19, 2021 · 2 comments · Fixed by #54369
Closed
Tracked by #39876

Hardcoded maximum ray distance when Viewport processes 3d object picking #49735

Flarkk opened this issue Jun 19, 2021 · 2 comments · Fixed by #54369

Comments

@Flarkk
Copy link

Flarkk commented Jun 19, 2021

Godot version

4.0 dev 8b692e8 + all 3.x

System information

n/a

Issue description

When processing its physic 3d picking events, Viewports cast rays from camera's origin to 10000 units ahead from it.

The 10000 is harcoded in Viewport::_process_picking() when calling PhysicsDirectSpaceState3D::intersect_ray() as following :
intersect_ray(from, from + dir * 10000, [...] ); (see the actual code here)

This does not allow object picking in arbitrary large scenes using the built-in Viewport's event handling capabilities.
A possible workaround would be not to rely on the built-in Viewport's event handling capabilities but instead casting rays manually with a custom 'to' distance. This however makes user interaction handling much more cumbersome.

Here are the few possibles ways of fixing it that immediately come to my mind :

  • using camera's far clipping distance instead of harcoded 10000
  • adding a user defined property to Viewports allowing setting a custom maximum distance
  • providing PhysicsDirectSpaceState3D a method to check ray intersection without any maximum distance, and use it in Viewport's picking events processing

I think the point of view of experienced Godot contributors is required here to select the most suitable fix regarding Godot design philosophy.

Steps to reproduce

Obvious from code reading

Minimal reproduction project

No response

@Flarkk Flarkk changed the title Hardcoded maximum ray distance when viewport processes object picking Hardcoded maximum ray distance when viewport processes 3d object picking Jun 19, 2021
@Flarkk Flarkk changed the title Hardcoded maximum ray distance when viewport processes 3d object picking Hardcoded maximum ray distance when Viewport processes 3d object picking Jun 19, 2021
@Flarkk
Copy link
Author

Flarkk commented Jun 20, 2021

Realizing that some others arguments of PhysicsDirectSpaceState3D::intersect_ray(), namely the physics layer bitmask and the Bodies / Area toggles are hardcoded as well.

They probably need to be either turned into Viewport properties or taken back from the Camera settings depending on Godot design principles.

S0yKaf added a commit to S0yKaf/godot that referenced this issue Oct 29, 2021
having the raycast distance hardcoded to `10000` caused input events
to not be registered in very large 3D scenes.

This resolves the issue by using the cameras far distance instead.
Creating the more predictable behavior of if an object is visible,
it will be picked by the viewport.

resolves: godotengine#49735
S0yKaf added a commit to S0yKaf/godot that referenced this issue Oct 29, 2021
having the raycast distance hardcoded to `10000` caused input events
to not be registered in very large 3D scenes.

This resolves the issue by using the cameras far distance instead.
Creating the more predictable behavior of if an object is visible,
it will be picked by the viewport.

resolves: godotengine#49735
@S0yKaf
Copy link
Contributor

S0yKaf commented Oct 29, 2021

Here are some videos just to show the issue in action.

Current Behavior

old.mp4

Fix in #54369

fix.mp4

@akien-mga akien-mga added this to the 4.0 milestone Nov 1, 2021
akien-mga pushed a commit to akien-mga/godot that referenced this issue Nov 15, 2021
having the raycast distance hardcoded to `10000` caused input events
to not be registered in very large 3D scenes.

This resolves the issue by using the cameras far distance instead.
Creating the more predictable behavior of if an object is visible,
it will be picked by the viewport.

resolves: godotengine#49735
(cherry picked from commit 02b6bbc)
lekoder pushed a commit to KoderaSoftwareUnlimited/godot that referenced this issue Dec 18, 2021
having the raycast distance hardcoded to `10000` caused input events
to not be registered in very large 3D scenes.

This resolves the issue by using the cameras far distance instead.
Creating the more predictable behavior of if an object is visible,
it will be picked by the viewport.

resolves: godotengine#49735
(cherry picked from commit 02b6bbc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants