diff --git a/src/components/cursor.js b/src/components/cursor.js index 9e9c90fb899..11286bc0d97 100644 --- a/src/components/cursor.js +++ b/src/components/cursor.js @@ -66,6 +66,7 @@ module.exports.Component = registerComponent('cursor', { this.canvasBounds = document.body.getBoundingClientRect(); this.isCursorDown = false; this.activeXRInput = null; + this.mouseAvailable = true; // Debounce. this.updateCanvasBounds = utils.debounce(function updateCanvasBounds () { @@ -230,6 +231,7 @@ module.exports.Component = registerComponent('cursor', { var pose; var transform; + this.mouseAvailable = true; camera.parent.updateMatrixWorld(); // Calculate mouse position based on the canvas element @@ -276,6 +278,7 @@ module.exports.Component = registerComponent('cursor', { * Trigger mousedown and keep track of the mousedowned entity. */ onCursorDown: function (evt) { + this.mouseAvailable = true; this.isCursorDown = true; // Raycast again for touch. if (this.data.rayOrigin === 'mouse' && evt.type === 'touchstart') { @@ -313,6 +316,7 @@ module.exports.Component = registerComponent('cursor', { * in case user mousedowned one entity, dragged to another, and mouseupped. */ onCursorUp: function (evt) { + this.mouseAvailable = true; if (!this.isCursorDown) { return; } this.isCursorDown = false; @@ -393,6 +397,7 @@ module.exports.Component = registerComponent('cursor', { }, onEnterVR: function () { + this.mouseAvailable = false; this.clearCurrentIntersection(true); var xrSession = this.el.sceneEl.xrSession; var self = this; @@ -411,6 +416,9 @@ module.exports.Component = registerComponent('cursor', { var data = this.data; var self = this; + // mouse not available for use as rayOrigin (e.g. in VR w/o mouse) + if (this.data.rayOrigin === 'mouse' && !this.mouseAvailable) { return; } + // Already intersecting. if (this.intersectedEl === intersectedEl) { return; }