Skip to content

Commit 4fd6d06

Browse files
committed
support mousemove
1 parent 8c4fbd6 commit 4fd6d06

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

src/components/cursor.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ module.exports.Component = registerComponent('cursor', {
6363
this.fuseTimeout = undefined;
6464
this.cursorDownEl = null;
6565
this.intersectedEl = null;
66+
this.activeXRInputs = new Set();
6667
this.canvasBounds = document.body.getBoundingClientRect();
6768
this.isCursorDown = false;
6869

@@ -88,6 +89,19 @@ module.exports.Component = registerComponent('cursor', {
8889
this.updateMouseEventListeners();
8990
},
9091

92+
tick: function () {
93+
if (this.data.rayOrigin === 'xrselect' && this.el.sceneEl.frame) {
94+
var inputSource = Array.from(this.activeXRInputs).pop();
95+
if (inputSource) {
96+
this.onMouseMove({
97+
inputSource: inputSource,
98+
type: 'fakeselectmove',
99+
frame: this.el.sceneEl.frame
100+
});
101+
}
102+
}
103+
},
104+
91105
play: function () {
92106
this.addEventListeners();
93107
},
@@ -210,6 +224,12 @@ module.exports.Component = registerComponent('cursor', {
210224
var point;
211225
var top;
212226

227+
var frame;
228+
var inputSource;
229+
var referenceSpace;
230+
var pose;
231+
var transform;
232+
213233
camera.parent.updateMatrixWorld();
214234

215235
// Calculate mouse position based on the canvas element
@@ -225,12 +245,13 @@ module.exports.Component = registerComponent('cursor', {
225245
mouse.x = (left / bounds.width) * 2 - 1;
226246
mouse.y = -(top / bounds.height) * 2 + 1;
227247

228-
if (this.data.rayOrigin === 'xrselect' && evt.type === 'selectstart') {
229-
const frame = evt.frame;
230-
const inputSource = evt.inputSource;
231-
const referenceSpace = this.el.renderer.xr.getReferenceSpace();
232-
const pose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
233-
const transform = pose.transform;
248+
if (this.data.rayOrigin === 'xrselect' && (evt.type === 'selectstart' || evt.type === 'fakeselectmove')) {
249+
frame = evt.frame;
250+
inputSource = evt.inputSource;
251+
this.activeXRInputs.add(inputSource);
252+
referenceSpace = this.el.renderer.xr.getReferenceSpace();
253+
pose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
254+
transform = pose.transform;
234255
direction.set(0, 0, -1);
235256
direction.applyQuaternion(transform.orientation);
236257
origin.copy(transform.position);
@@ -310,6 +331,10 @@ module.exports.Component = registerComponent('cursor', {
310331
this.cursorDownEl.emit(EVENTS.MOUSEUP, this.intersectedEventDetail);
311332
}
312333

334+
if (data.rayOrigin === 'xrselect') {
335+
this.activeXRInputs.delete(evt.inputSource);
336+
}
337+
313338
if ((!data.fuse || data.rayOrigin === 'mouse' || data.rayOrigin === 'xrselect') &&
314339
this.intersectedEl && this.cursorDownEl === this.intersectedEl) {
315340
this.twoWayEmit(EVENTS.CLICK);

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ require('./core/a-mixin');
9090
require('./extras/components/');
9191
require('./extras/primitives/');
9292

93-
console.log('A-Frame Version: 1.3.0 (Date 2022-06-16, Commit #6da23e99)');
93+
console.log('A-Frame Version: 1.3.0 (Date 2022-07-07, Commit #8c4fbd63)');
9494
console.log('THREE Version (https://github.com/supermedium/three.js):',
9595
pkg.dependencies['super-three']);
9696
console.log('WebVR Polyfill Version:', pkg.dependencies['webvr-polyfill']);

0 commit comments

Comments
 (0)