Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #61 from chenzlabs/more-webxrviewer-work
Browse files Browse the repository at this point in the history
Exit AR on WebXRViewer
  • Loading branch information
machenmusik authored Apr 13, 2020
2 parents 8a7ee3b + d1c5c30 commit a2af6aa
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 7 deletions.
18 changes: 17 additions & 1 deletion dist/aframe-ar.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/aframe-ar.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/aframe-ar.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/aframe-ar.min.js.map

Large diffs are not rendered by default.

24 changes: 23 additions & 1 deletion examples/hello-world.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>Hello, World! • A-Frame ar</title>
<meta name="description" content="Hello, World! • A-Frame three.ar.js">
<script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/chenzlabs/aframe@handle-missing-rotationrate-dist/dist/aframe-master.min.js"></script>
<script src="main.js"></script>
</head>
<body>
Expand All @@ -14,5 +14,27 @@
<a-cylinder scale="0.25 0.25 0.25" position="0.25 0.1875 -0.75" radius="0.5" height="1.5" color="#FFC65D" shadow></a-cylinder>
<a-plane scale="0.25 0.25 0.25" position="0 0 -1" rotation="-90 0 0" width="4" height="4" color="#7BC8A4" shadow></a-plane>
</a-scene>

<script>

window.tenSecondTouch = function () {
AFRAME.scenes[0].exitVR();
};

window.addEventListener('touchend'/*'click'*/, function() {
if (window.lastTouchStartTimer != undefined) {
clearTimeout(window.lastTouchStartTimer);
}
window.lastTouchStartTimer = undefined
});

window.addEventListener('touchstart'/*'click'*/, function() {
if (window.lastTouchStartTimer != undefined) {
clearTimeout(window.lastTouchStartTimer);
}
window.lastTouchStartTimer = setTimeout(window.tenSecondTouch, 10*1000);
});

</script>
</body>
</html>
2 changes: 1 addition & 1 deletion examples/raycaster.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.jsdelivr.net/gh/aframevr/aframe@e47f441/dist/aframe-master.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/chenzlabs/aframe@handle-missing-rotationrate-dist/dist/aframe-master.min.js"></script>
<script src="main.js"></script>
<script>
AFRAME.registerComponent('samsung-logo', {
Expand Down
18 changes: 17 additions & 1 deletion src/mozilla-xr-ar.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,29 @@ AFRAME.registerComponent('mozilla-xr-ar', {
};
});

var self = this;

self.el.addEventListener('exit-vr', function (data) {
// tell WebXR Viewer to stop
// FIXME: well, no, that's too much, camera tracking stops.
window.webkit.messageHandlers.stopAR.postMessage({});
// release ar-camera
if (self.data.takeOverCamera && self.arCamera) {
self.arCamera.el.setAttribute('ar-camera', 'enabled', false);
}
// turn AR button back on
setTimeout(function () {
var vrmodeui = self.el.sceneEl.components['vr-mode-ui'];
vrmodeui.enterAREl.classList.remove('a-hidden');
});
});

// act like Chrome WebXR by forcibly showing AR button and making it work
var vrmodeui = this.el.sceneEl.components['vr-mode-ui'];
var newarbutton = vrmodeui.enterAREl.cloneNode(true);
vrmodeui.enterAREl.parentNode.replaceChild(newarbutton, vrmodeui.enterAREl);
vrmodeui.enterAREl = newarbutton;
vrmodeui.enterAREl.classList.remove('a-hidden');
var self = this;
vrmodeui.enterAREl.onclick = function() {
var scene = AFRAME.scenes[0];

Expand Down

0 comments on commit a2af6aa

Please sign in to comment.