-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Examples: Add raycast support for LineSegments2 #17872
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
Conversation
examples/webgl_lines_fat.html
Outdated
|
|
||
| // perform raycast after the resolution has been updated for the camera | ||
| // view we care about | ||
| doRaycast(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be a similar case to what was discussed in #16423 where sprites needed more contextual about the camera being used in order to properly be raycast against. In this case the renderer canvas that is being clicked should dictate the resolution that is used when raycasting against the lines which means the renderer or the resolution should be available as context for the cast. Otherwise we have this scenario where the last call made to renderer.render will change the outcome of the raycast which would be confusing.
One solution is to add a raycaster.resolution or raycaster.renderer field which could be required when raycasting against these lines much like raycaster.camera but I'd be happy to hear other thoughts!
|
Regarding the questions I listed I think the current behavior of this PR is reasonable and we can update the raycast code in the future to respect the @mrdoob I know there has been some discussion about limiting the number of example pages in the repo -- would you prefer that a new fat lines raycasting example be created or include that code in the current fat lines example (as it is here)? |
|
@WestLangley I've gone ahead removed the example changes in this PR so it now just adds raycasting to |
My preference is to keep the examples focused, so I definitely agree with that. |
|
Thanks! |
This PR adds pixel-perfect raycast functionality to the LineSegments2 class and updates the
webgl_lines_fatexample to demonstrate the capability (and to test) with a red dot on hover.The intersection point result includes both
pointVector3 and apointOnLineVector3.pointis the line that lies on the ray being cast whilepointOnLineis the closest point on the line segment itself.Live Example Link
Here's a gif showing the raycast behavior. The red dot represents the resultant
pointvalue while the green shows thepointOnLinevalue:A few open questions I'd like some input on if anyone has any thoughts:
Raycaster.linePrecisionbe used here? It's not exactly clear how it should be used considering this value is in world units for THREE.Line, which doesn't make sense with these screen space lines.pointbe the point on the line as it with THREE.Line? It makes most sense to me to return the point along the ray being cast but this is an inconsistency at the moment. Maybe it makes more sense to use a point on the ray here because the lines actually have thickness that notionally defines a surface.And this is maybe a separate discussion but as you can see in the example the raycast result when using
THREE.Lineis not smooth -- the point jumps from line segment to line segment as you move the mouse around. I'm not sure if this is already known but it's leading me to believe that the THREE.Line raycast function isn't correct?@WestLangley
Fixes #15006