Skip to content

Conversation

@gkjohnson
Copy link
Collaborator

@gkjohnson gkjohnson commented Nov 5, 2019

This PR adds pixel-perfect raycast functionality to the LineSegments2 class and updates the webgl_lines_fat example to demonstrate the capability (and to test) with a red dot on hover.

The intersection point result includes both point Vector3 and a pointOnLine Vector3. point is the line that lies on the ray being cast while pointOnLine is 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 point value while the green shows the pointOnLine value:

line-raycast

A few open questions I'd like some input on if anyone has any thoughts:

  • Should Raycaster.linePrecision be 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.
  • Should the return value of point be 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.Line is 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


// perform raycast after the resolution has been updated for the camera
// view we care about
doRaycast();
Copy link
Collaborator Author

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!

@gkjohnson
Copy link
Collaborator Author

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 linePrecision field and or include the relevant resolution on the raycaster object.

@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)?

@gkjohnson gkjohnson marked this pull request as ready for review November 8, 2019 19:27
@Mugen87 Mugen87 added this to the r112 milestone Dec 7, 2019
@gkjohnson
Copy link
Collaborator Author

@WestLangley I've gone ahead removed the example changes in this PR so it now just adds raycasting to Line2. I think we can look into adding a standalone raycast example for fat lines in another PR.

@WestLangley
Copy link
Collaborator

I think we can look into adding a standalone raycast example for fat lines in another PR.

My preference is to keep the examples focused, so I definitely agree with that.

@mrdoob mrdoob merged commit 6a21666 into mrdoob:dev Dec 17, 2019
@mrdoob
Copy link
Owner

mrdoob commented Dec 17, 2019

Thanks!

@gkjohnson gkjohnson deleted the linesegments2-raycast branch December 17, 2019 22:47
@Mugen87 Mugen87 mentioned this pull request Dec 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Raycasting support for Line2Segments

4 participants