Skip to content

Commit ad0ff80

Browse files
SamsyMugen87RenaudRohlinger
authored
LineSegments2: Fix raycast() . (#30016)
* updated linesegments2 webgpu * Update LineSegments2.js FIx codescan issue. * use of vec4 to transfer viewport to this.resolution --------- Co-authored-by: Michael Herzog <[email protected]> Co-authored-by: Renaud Rohlinger <[email protected]>
1 parent ae2791a commit ad0ff80

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

examples/jsm/lines/webgpu/LineSegments2.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import {
99
Sphere,
1010
Vector3,
1111
Vector4,
12-
Line2NodeMaterial
12+
Line2NodeMaterial,
13+
Vector2
1314
} from 'three/webgpu';
14-
1515
import { LineSegmentsGeometry } from '../../lines/LineSegmentsGeometry.js';
1616

1717
const _start = new Vector3();
@@ -29,6 +29,7 @@ const _closestPoint = new Vector3();
2929
const _box = new Box3();
3030
const _sphere = new Sphere();
3131
const _clipToWorldVector = new Vector4();
32+
const _viewport = new Vector4();
3233

3334
let _ray, _lineWidth;
3435

@@ -93,8 +94,7 @@ function raycastWorldUnits( lineSegments, intersects ) {
9394
function 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

Comments
 (0)