-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
XR Cursor #5065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XR Cursor #5065
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…ents
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,9 +52,11 @@ module.exports.Component = registerComponent('cursor', { | |
| fuseTimeout: {default: 1500, min: 0}, | ||
| mouseCursorStylesEnabled: {default: true}, | ||
| upEvents: {default: []}, | ||
| rayOrigin: {default: 'entity', oneOf: ['mouse', 'entity']} | ||
| rayOrigin: {default: 'entity', oneOf: ['mouse', 'entity', 'xrselect']} | ||
| }, | ||
|
|
||
| multiple: true, | ||
|
|
||
| init: function () { | ||
| var self = this; | ||
|
|
||
|
|
@@ -223,7 +225,16 @@ module.exports.Component = registerComponent('cursor', { | |
| mouse.x = (left / bounds.width) * 2 - 1; | ||
| mouse.y = -(top / bounds.height) * 2 + 1; | ||
|
|
||
| if (camera && camera.isPerspectiveCamera) { | ||
| if (this.data.rayOrigin === 'xrselect' && evt.type === 'selectstart') { | ||
| const frame = evt.frame; | ||
AdaRoseCannon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const inputSource = evt.inputSource; | ||
| const referenceSpace = this.el.renderer.xr.getReferenceSpace(); | ||
| const pose = frame.getPose(inputSource.targetRaySpace, referenceSpace); | ||
| const transform = pose.transform; | ||
| direction.set(0, 0, -1); | ||
| direction.applyQuaternion(transform.orientation); | ||
| origin.copy(transform.position); | ||
| } else if (camera && camera.isPerspectiveCamera) { | ||
| origin.setFromMatrixPosition(camera.matrixWorld); | ||
| direction.set(mouse.x, mouse.y, 0.5).unproject(camera).sub(origin).normalize(); | ||
| } else if (camera && camera.isOrthographicCamera) { | ||
|
|
@@ -250,6 +261,24 @@ module.exports.Component = registerComponent('cursor', { | |
| evt.preventDefault(); | ||
| } | ||
|
|
||
| if (this.data.rayOrigin === 'xrselect' && evt.type === 'selectstart') { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. disregard. github was not displaying enough context. sorry |
||
| this.onMouseMove(evt); | ||
| this.el.components.raycaster.checkIntersections(); | ||
|
|
||
| // if something was tapped on don't do ar-hit-test things | ||
| if ( | ||
| this.el.components.raycaster.intersectedEls.length && | ||
| this.el.sceneEl.components['ar-hit-test'] !== undefined && | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the component There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's not so much a dependency just that things can get messy if both are being used so if the user is tapping on a 3d object then it shouldn't also interact with the real world behind it |
||
| this.el.sceneEl.components['ar-hit-test'].data.enabled | ||
| ) { | ||
| // Cancel the ar-hit-test behaviours and disable the ar-hit-test | ||
| this.el.sceneEl.components['ar-hit-test'].data.enabled = false; | ||
AdaRoseCannon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.el.sceneEl.components['ar-hit-test'].hitTest = null; | ||
AdaRoseCannon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.el.sceneEl.components['ar-hit-test'].bboxMesh.visible = false; | ||
| this.reenableARHitTest = true; | ||
| } | ||
| } | ||
|
|
||
| this.twoWayEmit(EVENTS.MOUSEDOWN); | ||
| this.cursorDownEl = this.intersectedEl; | ||
| }, | ||
|
|
@@ -269,14 +298,19 @@ module.exports.Component = registerComponent('cursor', { | |
| var data = this.data; | ||
| this.twoWayEmit(EVENTS.MOUSEUP); | ||
|
|
||
| if (this.reenableARHitTest === true) { | ||
| this.el.sceneEl.components['ar-hit-test'].data.enabled = true; | ||
AdaRoseCannon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.reenableARHitTest = undefined; | ||
| } | ||
|
|
||
| // If intersected entity has changed since the cursorDown, still emit mouseUp on the | ||
| // previously cursorUp entity. | ||
| if (this.cursorDownEl && this.cursorDownEl !== this.intersectedEl) { | ||
| this.intersectedEventDetail.intersection = null; | ||
| this.cursorDownEl.emit(EVENTS.MOUSEUP, this.intersectedEventDetail); | ||
| } | ||
|
|
||
| if ((!data.fuse || data.rayOrigin === 'mouse') && | ||
| if ((!data.fuse || data.rayOrigin === 'mouse' || data.rayOrigin === 'xrselect') && | ||
| this.intersectedEl && this.cursorDownEl === this.intersectedEl) { | ||
| this.twoWayEmit(EVENTS.CLICK); | ||
| } | ||
|
|
@@ -363,7 +397,7 @@ module.exports.Component = registerComponent('cursor', { | |
| } | ||
|
|
||
| // Begin fuse if necessary. | ||
| if (data.fuseTimeout === 0 || !data.fuse) { return; } | ||
| if (data.fuseTimeout === 0 || !data.fuse || data.rayOrigin === 'xrselect') { return; } | ||
| cursorEl.addState(STATES.FUSING); | ||
| this.twoWayEmit(EVENTS.FUSING); | ||
| this.fuseTimeout = setTimeout(function fuse () { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multiple components for this might feel like an overkill. wondering if we can simplify somehow. maybe
rayOrigin: mousealso considers selectstart? Not a fan either because makesrayOrigin: mousea bit deceiving (not really only about mouse anymore)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can think of a few situations in which a developer may prefer to handle all of their own XR select behaviours but still take advantage of the mouse cursor.
My XR Input Handling library in particular makes it really simple to start building your x-platform own XR cursor using the
entitymethod of the cursor component component.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any other ideas to avoid the multiple component approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have rayOrigin be an array of strings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
array would weird too I think. probably even weirder. Let's go with the multiple components for now but I don't feel super comfortable. Thanks for the patience