three.js icon indicating copy to clipboard operation
three.js copied to clipboard

LineSegments2 raycast bug

Open rajsunku opened this issue 1 year ago • 2 comments

Description

When a LineSegments2 object is rendered off the screen, the LineMaterial.resolution variable doesn't get updated until the onBeforeRender function is run. This causes raycasters to intersect with the lines incorrectly even when they are not on the screen. It gets resolved once you pan to the line since the resolution gets updated.

Reproduction steps

  1. Render a line outside of camera view
  2. If your app has some picking logic that highlights a line that is selected, click anywhere on the screen.
  3. Once you pan to the line, you will see that it is highlighted.

Code

// code goes here

Live example

Screenshots

No response

Version

0.168.0

Device

No response

Browser

No response

OS

No response

rajsunku avatar Oct 15 '24 18:10 rajsunku

I think there's a bigger question of what these screenspace thickness lines should do for raycasting when they're off screen - if a line is off screen there's not a clear interpretation of what "screen space" means. And projecting into camera clip space to to perform the raycasting won't necessarily have sensible results.

cc @WestLangley

gkjohnson avatar Oct 16 '24 04:10 gkjohnson

@rajsunku Can you please provide a live example to demonstrate exactly what you are doing?

WestLangley avatar Oct 16 '24 13:10 WestLangley

I think there's a bigger question of what these screenspace thickness lines should do for raycasting when they're off screen - if a line is off screen there's not a clear interpretation of what "screen space" means. And projecting into camera clip space to to perform the raycasting won't necessarily have sensible results.

I'd agree with this. Anything that is screen-space must be culled if all points are completely offscreen. For speed, we can early out by checking resolution is non-zero.

CodyJasonBennett avatar Nov 05 '24 15:11 CodyJasonBennett

I'd agree with this. Anything that is screen-space must be culled if all points are completely offscreen.

From a practical perspective I can see needing to be able to interact / raycast with lines that are off screen but I'd be okay changing the function to just cull the lines off screen until there are requests to figure out another solution.

It gets resolved once you pan to the line since the resolution gets updated.

Disabling "frustumCulled" would be a workaround for now, I think.

gkjohnson avatar Nov 06 '24 02:11 gkjohnson