9
9
Sphere ,
10
10
Vector3 ,
11
11
Vector4 ,
12
- Line2NodeMaterial
12
+ Line2NodeMaterial ,
13
+ Vector2
13
14
} from 'three/webgpu' ;
14
-
15
15
import { LineSegmentsGeometry } from '../../lines/LineSegmentsGeometry.js' ;
16
16
17
17
const _start = new Vector3 ( ) ;
@@ -29,6 +29,7 @@ const _closestPoint = new Vector3();
29
29
const _box = new Box3 ( ) ;
30
30
const _sphere = new Sphere ( ) ;
31
31
const _clipToWorldVector = new Vector4 ( ) ;
32
+ const _viewport = new Vector4 ( ) ;
32
33
33
34
let _ray , _lineWidth ;
34
35
@@ -93,8 +94,7 @@ function raycastWorldUnits( lineSegments, intersects ) {
93
94
function raycastScreenSpace ( lineSegments , camera , intersects ) {
94
95
95
96
const projectionMatrix = camera . projectionMatrix ;
96
- const material = lineSegments . material ;
97
- const resolution = material . resolution ;
97
+ const resolution = lineSegments . resolution ;
98
98
const matrixWorld = lineSegments . matrixWorld ;
99
99
100
100
const geometry = lineSegments . geometry ;
@@ -233,6 +233,8 @@ class LineSegments2 extends Mesh {
233
233
234
234
this . type = 'LineSegments2' ;
235
235
236
+ this . resolution = new Vector2 ( ) ;
237
+
236
238
}
237
239
238
240
// for backwards-compatibility, but could be a method of LineSegmentsGeometry...
@@ -264,6 +266,13 @@ class LineSegments2 extends Mesh {
264
266
265
267
}
266
268
269
+ onBeforeRender ( renderer ) {
270
+
271
+ renderer . getViewport ( _viewport ) ;
272
+ this . resolution . set ( _viewport . z , _viewport . w ) ;
273
+
274
+ }
275
+
267
276
raycast ( raycaster , intersects ) {
268
277
269
278
const worldUnits = this . material . worldUnits ;
@@ -303,7 +312,7 @@ class LineSegments2 extends Mesh {
303
312
} else {
304
313
305
314
const distanceToSphere = Math . max ( camera . near , _sphere . distanceToPoint ( _ray . origin ) ) ;
306
- sphereMargin = getWorldSpaceHalfWidth ( camera , distanceToSphere , material . resolution ) ;
315
+ sphereMargin = getWorldSpaceHalfWidth ( camera , distanceToSphere , this . resolution ) ;
307
316
308
317
}
309
318
@@ -333,7 +342,7 @@ class LineSegments2 extends Mesh {
333
342
} else {
334
343
335
344
const distanceToBox = Math . max ( camera . near , _box . distanceToPoint ( _ray . origin ) ) ;
336
- boxMargin = getWorldSpaceHalfWidth ( camera , distanceToBox , material . resolution ) ;
345
+ boxMargin = getWorldSpaceHalfWidth ( camera , distanceToBox , this . resolution ) ;
337
346
338
347
}
339
348
0 commit comments