Skip to content

Commit

Permalink
Be more explicit checking for xrselect or entity
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentfretin committed Jan 10, 2025
1 parent e941fac commit 6a679e8
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/components/cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,17 @@ module.exports.Component = registerComponent('cursor', {
},

update: function (oldData) {
if (this.data.rayOrigin === oldData.rayOrigin) { return; }
if (this.data.rayOrigin === 'entity') { this.resetRaycaster(); }
var rayOrigin = this.data.rayOrigin;
if (rayOrigin === oldData.rayOrigin) { return; }
if (rayOrigin === 'entity') { this.resetRaycaster(); }
this.updateMouseEventListeners();
// Update the WebXR event listeners if needed
if (this.data.rayOrigin !== 'mouse') {
// Update the WebXR event listeners if needed.
// This handles the cases a cursor is created or has its rayOrigin changed during an XR session.
// In the case the cursor is created before we have an active XR session, it does not add the WebXR event listeners here (addWebXREventListeners is a no-op without xrSession), upon onEnterVR they are added.
if (rayOrigin === 'xrselect' || rayOrigin === 'entity') {
this.addWebXREventListeners();
}
if (oldData.rayOrigin !== 'mouse') {
if (oldData.rayOrigin === 'xrselect' || oldData.rayOrigin === 'entity') {
this.removeWebXREventListeners();
}
},
Expand Down Expand Up @@ -445,8 +448,9 @@ module.exports.Component = registerComponent('cursor', {
},

onEnterVR: function () {
var rayOrigin = this.data.rayOrigin;
this.clearCurrentIntersection(true);
if (this.data.rayOrigin !== 'mouse') {
if (rayOrigin === 'xrselect' || rayOrigin === 'entity') {
this.addWebXREventListeners();
}
},
Expand Down

0 comments on commit 6a679e8

Please sign in to comment.