Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LineSegments2: Fix raycast() . #30016

Merged
merged 3 commits into from
Dec 4, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 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 Down Expand Up @@ -93,8 +93,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 +232,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 +265,11 @@ class LineSegments2 extends Mesh {

}

onBeforeRender( renderer ) {

renderer.getViewport( this.resolution );
}

raycast( raycaster, intersects ) {

const worldUnits = this.material.worldUnits;
Expand Down Expand Up @@ -303,7 +309,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 +339,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
Loading