99 Sphere ,
1010 Vector3 ,
1111 Vector4 ,
12- Line2NodeMaterial
12+ Line2NodeMaterial ,
13+ Vector2
1314} from 'three/webgpu' ;
14-
1515import { LineSegmentsGeometry } from '../../lines/LineSegmentsGeometry.js' ;
1616
1717const _start = new Vector3 ( ) ;
@@ -29,6 +29,7 @@ const _closestPoint = new Vector3();
2929const _box = new Box3 ( ) ;
3030const _sphere = new Sphere ( ) ;
3131const _clipToWorldVector = new Vector4 ( ) ;
32+ const _viewport = new Vector4 ( ) ;
3233
3334let _ray , _lineWidth ;
3435
@@ -93,8 +94,7 @@ function raycastWorldUnits( lineSegments, intersects ) {
9394function raycastScreenSpace ( lineSegments , camera , intersects ) {
9495
9596 const projectionMatrix = camera . projectionMatrix ;
96- const material = lineSegments . material ;
97- const resolution = material . resolution ;
97+ const resolution = lineSegments . resolution ;
9898 const matrixWorld = lineSegments . matrixWorld ;
9999
100100 const geometry = lineSegments . geometry ;
@@ -233,6 +233,8 @@ class LineSegments2 extends Mesh {
233233
234234 this . type = 'LineSegments2' ;
235235
236+ this . resolution = new Vector2 ( ) ;
237+
236238 }
237239
238240 // for backwards-compatibility, but could be a method of LineSegmentsGeometry...
@@ -264,6 +266,13 @@ class LineSegments2 extends Mesh {
264266
265267 }
266268
269+ onBeforeRender ( renderer ) {
270+
271+ renderer . getViewport ( _viewport ) ;
272+ this . resolution . set ( _viewport . z , _viewport . w ) ;
273+
274+ }
275+
267276 raycast ( raycaster , intersects ) {
268277
269278 const worldUnits = this . material . worldUnits ;
@@ -303,7 +312,7 @@ class LineSegments2 extends Mesh {
303312 } else {
304313
305314 const distanceToSphere = Math . max ( camera . near , _sphere . distanceToPoint ( _ray . origin ) ) ;
306- sphereMargin = getWorldSpaceHalfWidth ( camera , distanceToSphere , material . resolution ) ;
315+ sphereMargin = getWorldSpaceHalfWidth ( camera , distanceToSphere , this . resolution ) ;
307316
308317 }
309318
@@ -333,7 +342,7 @@ class LineSegments2 extends Mesh {
333342 } else {
334343
335344 const distanceToBox = Math . max ( camera . near , _box . distanceToPoint ( _ray . origin ) ) ;
336- boxMargin = getWorldSpaceHalfWidth ( camera , distanceToBox , material . resolution ) ;
345+ boxMargin = getWorldSpaceHalfWidth ( camera , distanceToBox , this . resolution ) ;
337346
338347 }
339348
0 commit comments