Skip to content

Commit

Permalink
LineSegments2: Fix raycast() . (mrdoob#30016)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Dec 4, 2024
1 parent ae2791a commit ad0ff80
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions examples/jsm/lines/webgpu/LineSegments2.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
Sphere,
Vector3,
Vector4,
Line2NodeMaterial
Line2NodeMaterial,
Vector2
} from 'three/webgpu';

import { LineSegmentsGeometry } from '../../lines/LineSegmentsGeometry.js';

const _start = new Vector3();
Expand All @@ -29,6 +29,7 @@ const _closestPoint = new Vector3();
const _box = new Box3();
const _sphere = new Sphere();
const _clipToWorldVector = new Vector4();
const _viewport = new Vector4();

let _ray, _lineWidth;

Expand Down Expand Up @@ -93,8 +94,7 @@ function raycastWorldUnits( lineSegments, intersects ) {
function raycastScreenSpace( lineSegments, camera, intersects ) {

const projectionMatrix = camera.projectionMatrix;
const material = lineSegments.material;
const resolution = material.resolution;
const resolution = lineSegments.resolution;
const matrixWorld = lineSegments.matrixWorld;

const geometry = lineSegments.geometry;
Expand Down Expand Up @@ -233,6 +233,8 @@ class LineSegments2 extends Mesh {

this.type = 'LineSegments2';

this.resolution = new Vector2();

}

// for backwards-compatibility, but could be a method of LineSegmentsGeometry...
Expand Down Expand Up @@ -264,6 +266,13 @@ class LineSegments2 extends Mesh {

}

onBeforeRender( renderer ) {

renderer.getViewport( _viewport );
this.resolution.set( _viewport.z, _viewport.w );

}

raycast( raycaster, intersects ) {

const worldUnits = this.material.worldUnits;
Expand Down Expand Up @@ -303,7 +312,7 @@ class LineSegments2 extends Mesh {
} else {

const distanceToSphere = Math.max( camera.near, _sphere.distanceToPoint( _ray.origin ) );
sphereMargin = getWorldSpaceHalfWidth( camera, distanceToSphere, material.resolution );
sphereMargin = getWorldSpaceHalfWidth( camera, distanceToSphere, this.resolution );

}

Expand Down Expand Up @@ -333,7 +342,7 @@ class LineSegments2 extends Mesh {
} else {

const distanceToBox = Math.max( camera.near, _box.distanceToPoint( _ray.origin ) );
boxMargin = getWorldSpaceHalfWidth( camera, distanceToBox, material.resolution );
boxMargin = getWorldSpaceHalfWidth( camera, distanceToBox, this.resolution );

}

Expand Down

0 comments on commit ad0ff80

Please sign in to comment.