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

Please add a separate Line2 threshold for world / pixel based lines.

Open nzjony opened this issue 10 months ago • 4 comments

Description

We use Line2 for both screen space and world space lines.

Unfortunately, we need to have different thresholds for pixel / world units. Because for example, a threshold of 10 looks quite small, but 10 world units is quite big (of course depending on the camera distance).

Solution

Something like:

		const threshold = ( raycaster.params.Line2 !== undefined ) ?
			( worldUnits ? ( raycaster.params.Line2.thresholdWorld || 0 ) :
				( raycaster.params.Line2.thresholdPixel || 0 ) ) : 0;

In the raycast function of LineSegments2.js

I'm happy to make a PR, just want to get a thumbs up before I do it.

Alternatives

For now, I'll make a change to three.js locally and use patch-package to apply it.

Additional context

No response

nzjony avatar Feb 27 '25 12:02 nzjony

@gkjohnson I am curious as to how you feel about this. 😇

WestLangley avatar Feb 28 '25 23:02 WestLangley

These thresholds are used for making it easier to select items with a mouse so to me it's much more sensible to specify them in pixel units rather than providing a separate option for a world threshold. Ie we can change the Line2 world raycasting logic to allow for intersecting the line if the mouse is within the "threshold" amount of pixels around the projected shape. So:

  • Find the closest point to the ray on the line
  • Calculate the "world width" of a pixel at the distance of the point to the camera
  • Use that world width and threshold factor to determine whether the point is close enough

Alternatively the threshold could be used to specify the minimum screen width to use for the calculation instead of unnecessarily expanding an already large world-units line that is close to the camera.

gkjohnson avatar Mar 01 '25 08:03 gkjohnson

@WestLangley @gkjohnson , thanks for the comments.

@gkjohnson that sounds like a very clever approach. 👍

nzjony avatar Mar 05 '25 10:03 nzjony

@gkjohnson Please review PR#32416

yaxit24 avatar Nov 29 '25 17:11 yaxit24