Skip to content

Commit a692ce7

Browse files
committed
Update ground plane collider transform & spatial cursor raycast logic
1 parent 35d8d71 commit a692ce7

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/gui/threejsScene.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ import { ViewFrustum, frustumVertexShader, frustumFragmentShader, MAX_VIEW_FRUST
149149
function addGroundPlaneCollider() {
150150
const sceneSizeInMeters = 100; // not actually infinite, but relative to any area target this should cover it
151151
const geometry = new THREE.PlaneGeometry( 1000 * sceneSizeInMeters, 1000 * sceneSizeInMeters);
152+
geometry.rotateX(Math.PI/2); // directly set the geometry's rotation to get the desired visual rotation & raycast direction. Otherwise setting mesh's rotation & run updateWorldMatrix(true, false) looks correct, but has wrong raycast direction
152153
const material = new THREE.MeshBasicMaterial( {color: 0x88ffff, side: THREE.DoubleSide} );
153154
const plane = new THREE.Mesh( geometry, material );
154-
plane.rotateX(Math.PI/2);
155155
plane.visible = false;
156156
addToScene(plane, {occluded: true});
157157
plane.name = 'groundPlaneCollider';

src/spatialCursor/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -651,15 +651,17 @@ import * as THREE from '../../thirdPartyCode/three/three.module.js';
651651
}
652652
}
653653

654-
function getRaycastCoordinates(screenX, screenY) {
654+
function getRaycastCoordinates(screenX, screenY, includeGroundPlane = false) {
655655
let worldIntersectPoint = null;
656656
let objectsToCheck = [];
657657
if (cachedOcclusionObject) {
658658
objectsToCheck.push(cachedOcclusionObject);
659659
}
660-
// if (realityEditor.gui.threejsScene.getGroundPlaneCollider()) {
661-
// objectsToCheck.push(realityEditor.gui.threejsScene.getGroundPlaneCollider());
662-
// }
660+
if (includeGroundPlane) {
661+
let groundPlane = realityEditor.gui.threejsScene.getGroundPlaneCollider();
662+
groundPlane.updateWorldMatrix(true, false);
663+
objectsToCheck.push(groundPlane);
664+
}
663665
if (cachedWorldObject && objectsToCheck.length > 0) {
664666
// by default, three.js raycast returns coordinates in the top-level scene coordinate system
665667
let raycastIntersects = realityEditor.gui.threejsScene.getRaycastIntersects(screenX, screenY, objectsToCheck);

0 commit comments

Comments
 (0)