Globally available world coordinates relative to pointer position #3321
pedroalmeida415
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The current project I'm working on has multiple components that require the world coordinates represented by the intersection of a ray on a plane that is at origin and is normal to the camera (which is stationary), with current pointer position as direction.
However, none of these components has a full-screen PlaneGeometry for me to
state.raycaster.intersectObject()
to, thus I needed a way in which I could get said world coordinates without relying on any object.This is possible by using a Plane along with
state.raycaster.ray.intersectPlane
, but it still bothered me that I had to do the same setup multiple times on each component.The solution I came up with uses an Object3D and its position as a proxy to provide the coordinates to any component just by retrieving it from the scene:
This implementation can be further improved to support camera movement and rotation with OrbitControls by dynamically updating the plane relative to the camera, here is an example codesandbox by @mattrossman
References
Beta Was this translation helpful? Give feedback.
All reactions