Skip to content
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
Binary file added Build/ASIL_hub_V1.data.unityweb
Binary file not shown.
16 changes: 16 additions & 0 deletions Build/ASIL_hub_V1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"companyName": "DefaultCompany",
"productName": "ASIL_hubs_V1",
"productVersion": "0.1",
"dataUrl": "ASIL_hub_V1.data.unityweb",
"wasmCodeUrl": "ASIL_hub_V1.wasm.code.unityweb",
"wasmFrameworkUrl": "ASIL_hub_V1.wasm.framework.unityweb",
"graphicsAPI": ["WebGL 2.0","WebGL 1.0"],
"webglContextAttributes": {"preserveDrawingBuffer": false},
"splashScreenStyle": "Dark",
"backgroundColor": "#231F20",
"cacheControl": {"default": "must-revalidate"},
"developmentBuild": false,
"multithreading": false,
"unityVersion": "2019.3.5f1"
}
Binary file added Build/ASIL_hub_V1.wasm.code.unityweb
Binary file not shown.
Binary file added Build/ASIL_hub_V1.wasm.framework.unityweb
Binary file not shown.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta http-equiv="origin-trial" data-feature="Generic Sensors" data-expires="2018-04-10" content="Aokv0ODVMUPIswIBi6DnpAIjhWefEd8gD8GpVgdYgETj0C5+/3kKMzZE/FOrBwHcpBO6LHuVRrIw3yOT8EMmJAYAAABQeyJvcmlnaW4iOiJodHRwczovL2dpdGh1Yi5pbzo0NDMiLCJmZWF0dXJlIjoiR2VuZXJpY1NlbnNvciIsImV4cGlyeSI6MTUyMzMxODQwMH0=">
<!-- Origin Trial Token, feature = WebVR (For Chrome M62+), origin = https://github.io, expires = 2018-05-07 -->
<meta http-equiv="origin-trial" data-feature="WebXR (For Chrome M62+)" data-expires="2018-05-07" content="AgINztgDnjFV8da2D9SSzIITBRlHX8mduCR7DXfENxjr9ALduKOxBDdn2n66auQSlljVyhnRWWerxC0BWbE8pAoAAABOeyJvcmlnaW4iOiJodHRwczovL2dpdGh1Yi5pbzo0NDMiLCJmZWF0dXJlIjoiV2ViVlIxLjFNNjIiLCJleHBpcnkiOjE1MjU3MjU4MDh9">
<title> | PianoPhase</title>
<title> | ASIL_hubs_V1</title>
<meta name="description" content="">

<link rel="icon" href="favicon.ico">
Expand All @@ -28,7 +28,7 @@
<script src="Build/UnityLoader.js"></script>
<script>
UnityLoader.SystemInfo.mobile = false; // Workaround to force `UnityLoader` to actually load on mobile.
window.gameInstance = UnityLoader.instantiate('gameContainer', 'Build/ASIL_hubs_demo_V1.json', {
window.gameInstance = UnityLoader.instantiate('gameContainer', 'Build/ASIL_hub_V1.json', {
Module: {
// `preserveDrawingBuffer` is needed for WebVR content to be mirrored to the `<canvas>`.
webglContextAttributes: {
Expand Down
108 changes: 55 additions & 53 deletions webxr.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@
// Unity GameObject name which we will SendMessage to
this.unityObjectName = 'WebXRCameraSet';

this.session = null;
this.vrSession = null;
this.isInVRSession = false;
this.inlineSession = null;
this.xrData = new XRData();
this.canvas = null;
this.ctx = null;
this.gameInstance = null;
this.polyfill = null;
this.toggleVRKeyName = '';
this.isPresenting = false;
this.notifiedStartToUnity = false;
this.isVRSupported = false;
this.refSpace = null;
this.vrImmersiveRefSpace = null;
this.xrInlineRefSpace = null;
this.rAFCB = null;
this.originalWidth = null;
this.originalHeight = null;
Expand Down Expand Up @@ -78,37 +82,36 @@
navigator.xr.requestSession('immersive-vr', {
requiredFeatures: ['local-floor']
}).then(async (session) => {
this.onSessionStarted(session)
session.isImmersive = true;
this.isInVRSession = true;
this.vrSession = session;
this.onSessionStarted(session);
});
}

XRManager.prototype.exitSession = function () {
if (!this.session) {
if (!this.vrSession && !this.isInVRSession) {
console.warn('No VR display to exit VR mode');
return;
}

this.session.end();
this.session = null;
this.vrSession.end();
}

XRManager.prototype.onEndSession = function (session) {
if (session && session.end) {
session.end();
}
this.session = null;

this.gameInstance.SendMessage(this.unityObjectName, 'OnEndXR');
this.isPresenting = false;
this.isInVRSession = false;
this.notifiedStartToUnity = false;
this.canvas.width = this.originalWidth;
this.canvas.height = this.originalHeight;

if (this.polyfill) {
this.gameInstance.Module.InternalBrowser.requestAnimationFrame(this.rAFCB);
}
}

XRManager.prototype.toggleVR = function () {
if (this.isVRSupported && this.session && this.gameInstance) {
if (this.isVRSupported && this.isInVRSession && this.gameInstance) {
this.exitSession();
} else {
this.requestPresent();
Expand Down Expand Up @@ -138,14 +141,21 @@
if (!thisXRMananger.rAFCB) {
thisXRMananger.rAFCB = func;
}
if (thisXRMananger.session) {
return thisXRMananger.session.requestAnimationFrame((time, xrFrame) =>
if (thisXRMananger.vrSession && thisXRMananger.isInVRSession) {
return thisXRMananger.vrSession.requestAnimationFrame((time, xrFrame) =>
{
thisXRMananger.animate(time, xrFrame);
if (func) {
func(time);
}
});
} else if (thisXRMananger.inlineSession) {
return thisXRMananger.inlineSession.requestAnimationFrame((time, xrFrame) =>
{
if (func) {
func(time);
}
});
} else {
window.requestAnimationFrame(func);
}
Expand Down Expand Up @@ -181,6 +191,11 @@
supportsImmersiveVR: this.isVRSupported,
})
);

navigator.xr.requestSession('inline').then((session) => {
this.inlineSession = session;
this.onSessionStarted(session);
});
}

XRManager.prototype.getGamepadAxes = function(gamepad) {
Expand All @@ -203,11 +218,11 @@
return buttons;
}

XRManager.prototype.getGamepads = function(frame) {
XRManager.prototype.getGamepads = function(frame, refSpace) {
var gamepads = [];
for (let source of frame.session.inputSources) {
if (source.gripSpace && source.gamepad) {
let sourcePose = frame.getPose(source.gripSpace, this.refSpace);
let sourcePose = frame.getPose(source.gripSpace, refSpace);

var position = sourcePose.transform.position;
var orientation = sourcePose.transform.orientation;
Expand Down Expand Up @@ -265,68 +280,55 @@
}

XRManager.prototype.onSessionStarted = function (session) {
this.session = session;
var onSessionEnded = this.onEndSession.bind(this);
session.addEventListener('end', onSessionEnded);

//this.ctx.makeXRCompatible();
/*
var attributes = this.ctx.getContextAttributes();
let framebufferScaleFactor = 1.0;
var layerInit = {
antialias: attributes.antialias,
alpha: attributes.alpha,
depth: attributes.depth,
stencil: attributes.stencil,
framebufferScaleFactor: framebufferScaleFactor,
xrCompatible: true
};
*/

var glLayer = new XRWebGLLayer( session, this.ctx/*, layerInit */);
var glLayer = new XRWebGLLayer( session, this.ctx);

session.updateRenderState({ baseLayer: glLayer });

first = true;
this.originalWidth = this.canvas.width;
this.originalHeight = this.canvas.height;
this.canvas.width = glLayer.framebufferWidth;
this.canvas.height = glLayer.framebufferHeight;

let animate = this.animate.bind(this);
let refSpaceType = 'viewer';
if (session.isImmersive){
refSpaceType = 'local-floor';
this.originalWidth = this.canvas.width;
this.originalHeight = this.canvas.height;
this.canvas.width = glLayer.framebufferWidth;
this.canvas.height = glLayer.framebufferHeight;
}

session.requestReferenceSpace('local-floor').then((refSpace) => {
this.refSpace = refSpace;
// Inform the session that we're ready to begin drawing.
// session.requestAnimationFrame(animate);
if (!this.polyfill) {
session.requestReferenceSpace(refSpaceType).then((refSpace) => {
if (session.isImmersive) {
this.vrImmersiveRefSpace = refSpace;
// Inform the session that we're ready to begin drawing.
this.gameInstance.Module.InternalBrowser.requestAnimationFrame(this.rAFCB);
} else {
this.xrInlineRefSpace = refSpace;
}
});
}

var first = true;
XRManager.prototype.animate = function (t, frame) {
let session = frame.session;

if (!session)
if (!session && !session.isImmersive)
{
return;
}

let refSpace = this.vrImmersiveRefSpace;

let pose = frame.getViewerPose(this.refSpace);
let pose = frame.getViewerPose(refSpace);
if (!pose) {
return;
}

// !!! session.requestAnimationFrame(this.animate.bind(this));

let glLayer = session.renderState.baseLayer;
this.canvas.width = glLayer.framebufferWidth;
this.canvas.height = glLayer.framebufferHeight;

this.ctx.bindFramebuffer(this.ctx.FRAMEBUFFER, glLayer.framebuffer);
this.ctx.clear(this.ctx.COLOR_BUFFER_BIT | this.ctx.DEPTH_BUFFER_BIT);

var xrData = this.xrData;

for (let view of pose.views) {
Expand All @@ -342,7 +344,7 @@
}

// Gamepads
xrData.gamepads = this.getGamepads(frame);
xrData.gamepads = this.getGamepads(frame, refSpace);

// Dispatch event with headset data to be handled in webxr.jslib
document.dispatchEvent(new CustomEvent('VRData', { detail: {
Expand All @@ -353,10 +355,10 @@
sitStandMatrix: xrData.sitStandMatrix
}}));

if (!this.isPresenting)
if (!this.notifiedStartToUnity)
{
this.gameInstance.SendMessage(this.unityObjectName, 'OnStartXR');
this.isPresenting = true;
this.notifiedStartToUnity = true;
}

this.gameInstance.SendMessage(this.unityObjectName, 'OnWebXRData', JSON.stringify({
Expand Down