From 8e5d236f3f44d8a9404acee407eec26d9c3dc0e2 Mon Sep 17 00:00:00 2001
From: Garrett Johnson
Date: Fri, 29 Mar 2024 18:55:30 +0900
Subject: [PATCH 1/2] Position the ray origin such that it is on the camera
near plane
---
src/core/Raycaster.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/core/Raycaster.js b/src/core/Raycaster.js
index ef72c6b518a81d..dc107b91df6aa3 100644
--- a/src/core/Raycaster.js
+++ b/src/core/Raycaster.js
@@ -38,13 +38,13 @@ class Raycaster {
if ( camera.isPerspectiveCamera ) {
- this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
+ this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
this.camera = camera;
} else if ( camera.isOrthographicCamera ) {
- this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
+ this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
this.camera = camera;
From 308f744539916eac3359424c7aebf3383fcf2a58 Mon Sep 17 00:00:00 2001
From: Garrett Johnson
Date: Fri, 29 Mar 2024 19:10:57 +0900
Subject: [PATCH 2/2] Adjust tests
---
test/unit/src/core/Raycaster.tests.js | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/test/unit/src/core/Raycaster.tests.js b/test/unit/src/core/Raycaster.tests.js
index f71b2aa4671044..09999c138bc628 100644
--- a/test/unit/src/core/Raycaster.tests.js
+++ b/test/unit/src/core/Raycaster.tests.js
@@ -12,8 +12,12 @@ import { OrthographicCamera } from '../../../../src/cameras/OrthographicCamera.j
function checkRayDirectionAgainstReferenceVector( rayDirection, refVector, assert ) {
- assert.ok( refVector.x - rayDirection.x <= Number.EPSILON && refVector.y - rayDirection.y <= Number.EPSILON && refVector.z - rayDirection.z <= Number.EPSILON, 'camera is pointing to' +
- ' the same direction as expected' );
+ assert.ok(
+ refVector.x - rayDirection.x <= Number.EPSILON &&
+ refVector.y - rayDirection.y <= Number.EPSILON &&
+ refVector.z - rayDirection.z <= Number.EPSILON,
+ 'camera is pointing to the same direction as expected'
+ );
}
@@ -141,7 +145,7 @@ export default QUnit.module( 'Core', () => {
const raycaster = new Raycaster();
const rayDirection = raycaster.ray.direction;
- const camera = new PerspectiveCamera( 90, 1, 1, 1000 );
+ const camera = new PerspectiveCamera( 90, 1, 0.1, 1000 );
raycaster.setFromCamera( {
x: 0,