Closed tommie closed 1 week ago
PoC for OrthographicCamera
which does roughly what I suggest, but with a separate params boolean: https://gist.github.com/tommie/1a4b485d9f34ed9ca7cb78d4ae78310b
The actual implementation could come from LineSegments2
in the examples.
Normal lines primitives can't have a width greater than 1 pixel. This is a restriction of WebGL (and WebGPU). The existing linewidth
of LineBasicMaterial
is not WebGL related since lines can also be rendered with SVGRenderer
(an previously CanvasRenderer
).
So you have to use the wide line implementation from the addons.
Thanks for the reply.
My WebGLRenderer seems to be able to render wider lines than 1px using Line(LineBasicMaterial)
, so I assumed it worked in general. Looks like up to 8px works. (This is on Chrome.)
Though, reading https://stackoverflow.com/a/47445400, it seems this is not something to rely on. I guess I was lucky.
https://github.com/mrdoob/three.js/issues/27034 suggests contributions for add-on documentation are welcome, so I might have a look at that, for discoverability.
I would just add – if you want to do selection in screen space, with support for all of the effects that materials might have, then it might be better to use gpu picking rather than the raycaster.
Description
Since
Line
commonly usesLineBasicMaterial
, I would have expectedRaycaster
to honor theLineBasicMaterial.lineWidth
. It also seems the threshold is interpreted in world units, not screen space, going against the general intuition ofLineBasicMaterial
.Solution
threshold
withmaterial.lineWidth
inLine.raycast
.Raycaster.params.Line.threshold === 0
to mean thatlineWidth
and screen space distance is used.Points
.Line
andPoints
compatible withMesh
by handling undefined material to mean it's invisible.Alternatives
There have been a few additions to the Line2 and LineSegments2 examples in recent years, but I'm wondering why that hasn't reached core.
Additional context
The
Raycaster
does not look much at materials when determining intersections, with few exceptions:Mesh
et al. will make no intersection if the material is undefined.Sprite
looks atsizeAttenuation
androtation
(i.e. it assumes aSpriteMaterial
is being used.)Both
Line
andPoints
use thresholds that are static for theRaycaster
, and don't care about materials. As withlineWidth
, thePointMaterial.size
would be useful to honor, though it would also have to takesizeAttenuation
into account.