Skip to content
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

A-Frame - Exokit Web bindings prototype v0.1 #127

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions aframe.exokit.scene.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE html>
<html>
<head>
<script src="https://aframe.io/releases/0.9.2/aframe.min.js"></script>
<script type=module src="http://localhost:6969/local-exokit-web/exokit-web/ew.js"></script>
<script defer src="./aframe-exokit-v2.js"></script>

<script>
var kalilaContexts = [];
HTMLCanvasElement.prototype.getContext = (function(originalGetContext) {
return myCustomGetContext;
function myCustomGetContext(a,b) {
console.info('getContext intercepted - - - ',a,b);
b = b || {};
b.xrCompatible = true;
b.alpha = true;
b.antialias = true;
b.depth = true;
b.powerPreference = "default";
b.premultipliedAlpha = true;
b.preserveDrawingBuffer = false;
b.stencil = true;

if(a === "webgl") {
a = "webgl2";
}
if (this['$'+a]) return this['$'+a];
var context = originalGetContext.apply(this, arguments);
kalilaContexts.push({ canvas: this, arguments: [a,b], context: context });
this['$'+a] = context;
return context;
}
})(HTMLCanvasElement.prototype.getContext);
</script>

</head>
<body>

<a-scene>
<a-box rotation="45 45 45" position="0 0 -2" color="tomato" depth="2" height="4" width="0.5"></a-box>
<a-box rotation="45 -45 45" position="0 0 -16" color="tomato" depth="2" height="4" width="0.5"></a-box>
<a-box rotation="45 -45 45" position="0 0 -32" color="tomato" depth="2" height="4" width="0.5"></a-box>

<a-xr-engine xr-engine wireframe scale="2 2 2" material="color: gray" geometry="primitive: box; width: 1; height: 1; depth: 1" position="0 3 -5">
<!-- <a-xr-site wireframe scale=".95 .95 .95" material="color: magenta" geometry="primitive: box; width: 1; height: 1; depth: 1" position="0 0 0">
<a-xr-iframe position="0 0 0" gltf-model="#a-xr-iframe"></a-xr-iframe>
</a-xr-site> -->
</a-xr-engine>

<a-box a-xr-test="asdfsdf" rotation="45 -45 45" position="0 0 -20" color="blue" depth="2" height="10" width="0.25"></a-box>

<a-sphere position="0 1.25 -1" radius="1.25" color="#EF2D5E"></a-sphere>
<a-cube position="-1 0.5 1" rotation="0 45 0" width="1" height="1" depth="1" color="#4CC3D9"></a-cube>
<a-cylinder position="1 0.75 1" radius="0.5" height="1.5" color="#FFC65D"></a-cylinder>
<a-plane rotation="-90 0 0" width="4" height="4" color="#7BC8A4"></a-plane>
<!-- <a-sky color="#333333"></a-sky> -->
</a-scene>
</body>

</html>
67 changes: 67 additions & 0 deletions src/aframe-exokit-v2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
var axrengine = document.createElement("script"); // create a script DOM node
axrengine.src = "http://localhost:6969/local-exokit-web/exokit-web/src/a-xr-engine.js"; // set its src to the provided URL

document.head.appendChild(axrengine);

window.mainCanvas = null;

AFRAME.registerSystem('bind-exokit-aframe-canvas', {
init: function() {
console.info('AFRAME.system.init')
var sceneEl = this.sceneEl;

console.info(document.getElementsByClassName("a-canvas")[0]);
window.mainCanvas = document.getElementsByClassName("a-canvas")[0];
// if(0) setTimeout(function() {
try {
navigator.xr.requestSession('immersive-vr').then((session)=> {
console.info('got session', session)
console.info('exiting VR')
sceneEl.exitVR();
}).catch((err)=>console.error('crashless-vrless error:' + err));
} catch(e) { console.warn('navigator.xr error:'+e); }
// }, 500);
},
tick: function() {
// this.sceneEl.camera.rotation.y+=.01;
},
});

AFRAME.registerComponent('wireframe', {
dependencies: ['material'],
init: function () {
this.el.components.material.material.wireframe = true;
}
});

function generateXREngine(context) {

const xrEngine = new XREngine();
top.xrEngine = xrEngine;
xrEngine.canvas = window.mainCanvas;
xrEngine.context = window.mainCanvas.$webgl;
// alert(xrEngine.canvas);
xrEngine.innerHTML = '<xr-site><xr-iframe src="https://webvr.info/samples/04b-simple-mirroring-2.html?polyfill=1"></xr-iframe></xr-site>';
context.appendChild(xrEngine);
xrEngine.addEventListener('load', function() { console.log("XR ENGINE LOADED : : : ---")});
xrEngine.enterXr();

}

AFRAME.registerComponent('xr-engine', {
init: function() {
var context = this.el;
console.info('a-xr-engine', this.data)

setTimeout(function() {
generateXREngine(context);
}, 1000);
},
tick: function() {
//this.el.object3D.rotation.y+=.05;
},
});

AFRAME.registerElement("a-xr-engine", { prototype: AFRAME.AEntity.prototype });
AFRAME.registerElement("a-xr-site", { prototype: AFRAME.AEntity.prototype });
AFRAME.registerElement("a-xr-iframe", { prototype: AFRAME.AEntity.prototype });
32 changes: 20 additions & 12 deletions src/xr-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,34 @@ const XREngineProto = {
win.baseLayer = null;
win.install = () => {
if (!win.canvas) {
win.canvas = document.createElement('canvas');
win.canvas.width = GlobalContext.xrState.renderWidth[0] * 2;
win.canvas.height = GlobalContext.xrState.renderHeight[0];
win.canvas.style.width = '100%';
win.canvas.style.height = '100%';
win.canvas.addEventListener('mousedown', e => {
e.preventDefault();
});
// win.canvas = document.createElement('canvas');
if(document.getElementsByClassName("a-canvas")[0]) {
win.canvas = document.getElementsByClassName("a-canvas")[0];
} else {
win.canvas = document.createElement('canvas');
alert("Made new one.");
}
// win.canvas.width = GlobalContext.xrState.renderWidth[0] * 2;
// win.canvas.height = GlobalContext.xrState.renderHeight[0];
// win.canvas.style.width = '100%';
// win.canvas.style.height = '100%';
// win.canvas.addEventListener('mousedown', e => {
// e.preventDefault();
// });
win.canvas.addEventListener('mouseenter', e => {
const {x, y, width, height} = win.canvas.getBoundingClientRect();
GlobalContext.xrState.canvasViewport[0] = x;
GlobalContext.xrState.canvasViewport[1] = y;
GlobalContext.xrState.canvasViewport[2] = width;
GlobalContext.xrState.canvasViewport[3] = height;
});
win.ctx = win.canvas.getContext(window.WebGL2RenderingContext ? 'webgl2' : 'webgl', {
win.ctx = win.canvas.$webgl2; if(0) getContext(window.WebGL2RenderingContext ? 'webgl2' : 'webgl', {
antialias: true,
alpha: true,
xrCompatible: true,
});
console.info("win.ctx: ", win.ctx);

win.ctx.bindFramebuffer = (_bindFramebuffer => function bindFramebuffer(target, fbo) { // XXX return the correct undone binding in gl.getParameter
if (!fbo) {
fbo = win.ctx.xrFramebuffer;
Expand All @@ -108,11 +116,11 @@ const XREngineProto = {

if (this._canShadow) {
if (!this.shadow) {
this.shadow = this.attachShadow({mode: 'closed'});
// this.shadow = this.attachShadow({mode: 'closed'});
}
this.shadow.appendChild(win.canvas);
// this.shadow.appendChild(win.canvas);
} else {
this.insertAdjacentElement('afterend', win.canvas);
// this.insertAdjacentElement('afterend', win.canvas);
}

this.dispatchEvent(new MessageEvent('canvas', {
Expand Down