Skip to content

Commit

Permalink
Disable hand raycast by default, enable in xr
Browse files Browse the repository at this point in the history
Partially addresses issues in #618
  • Loading branch information
hi-liang committed Feb 28, 2024
1 parent a5ce833 commit 8c8d1b4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
arena-hand="hand:left"
laser-controls="hand:left"
blink-controls="cameraRig: #cameraRig; collisionEntities: [nav-mesh]; teleportOrigin: #my-camera"
raycaster="objects: [click-listener],[click-listener-local]"
raycaster="objects: [click-listener],[click-listener-local]; enabled: false"
></a-entity>
<a-entity
id="rightHand"
Expand All @@ -109,7 +109,7 @@
visible="false"
arena-hand="hand:right"
laser-controls="hand:right"
raycaster="objects: [click-listener],[click-listener-local]"
raycaster="objects: [click-listener],[click-listener-local]; enabled: false"
></a-entity>
</a-entity>
</a-entity>
Expand Down
19 changes: 16 additions & 3 deletions src/systems/webxr/webxr-device-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ AFRAME.registerComponent('webxr-device-manager', {
this.isMobile = ARENAUtils.isMobile();
this.mouseCursor = document.getElementById('mouse-cursor');
this.cameraSpinner = document.getElementById('cameraSpinner');
this.lHand = document.getElementById('leftHand');
this.rHand = document.getElementById('rightHand');
},

onWebXREnterVR() {
const { el, mouseCursor, cameraSpinner, isMobile, isWebXRViewer } = this;
const { sceneEl } = el;
const { el: sceneEl, mouseCursor, cameraSpinner, lHand, rHand, isMobile, isWebXRViewer } = this;
if (sceneEl.is('ar-mode')) {
if (isMobile && !isWebXRViewer) {
mouseCursor.removeAttribute('cursor');
Expand All @@ -40,6 +41,12 @@ AFRAME.registerComponent('webxr-device-manager', {
cameraSpinner.setAttribute('raycaster', { objects: '[click-listener],[click-listener-local]' });
cameraSpinner.setAttribute('cursor', { rayOrigin: 'xrselect', fuse: false });
cameraSpinner.components.cursor.onEnterVR(); // Manually trigger cursor callback for xr event binds
} else if (!isWebXRViewer) {
// non-mobile, non-WebXR browser, maybe headset? Enable hands, disable mouse raycaster
mouseCursor.removeAttribute('cursor');
mouseCursor.removeAttribute('raycaster');
lHand.setAttribute('raycaster', 'enabled', true);
rHand.setAttribute('raycaster', 'enabled', true);
}
document.getElementById('env').setAttribute('visible', false);
const arMarkerSys = sceneEl.systems.armarker;
Expand All @@ -48,13 +55,19 @@ AFRAME.registerComponent('webxr-device-manager', {
},

onWebXRRExitVR() {
const { el: sceneEl, mouseCursor, cameraSpinner, isMobile, isWebXRViewer } = this;
const { el: sceneEl, mouseCursor, cameraSpinner, lHand, rHand, isMobile, isWebXRViewer } = this;
if (sceneEl.is('ar-mode')) {
if (isMobile && !isWebXRViewer) {
cameraSpinner.removeAttribute('cursor');
cameraSpinner.removeAttribute('raycaster');
mouseCursor.setAttribute('raycaster', { objects: '[click-listener],[click-listener-local]' });
mouseCursor.setAttribute('cursor', { rayOrigin: 'mouse' });
} else if (!isWebXRViewer) {
// non-mobile, non-WebXR browser, maybe headset?
mouseCursor.setAttribute('raycaster', { objects: '[click-listener],[click-listener-local]' });
mouseCursor.setAttribute('cursor', { rayOrigin: 'mouse' });
lHand.setAttribute('raycaster', 'enabled', false);
rHand.setAttribute('raycaster', 'enabled', false);
}
document.getElementById('env').setAttribute('visible', true);
}
Expand Down

0 comments on commit 8c8d1b4

Please sign in to comment.