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

Introducing FreeFlight fallback #213

Merged
merged 5 commits into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions Assets/WebGLTemplates/WebVR/styles/webvr.css
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ a:link, a:visited {
position: absolute;
top: 0;
width: 100%;
pointer-events: none;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this - thanks for fixing this 👍 😄

}

#instruction button {
Expand All @@ -148,6 +149,7 @@ a:link, a:visited {
display: none;
max-width: 50%;
padding: 10px 30px;
pointer-events: all;
}

.panel[data-enabled='true'] {
Expand Down
111 changes: 64 additions & 47 deletions Assets/WebGLTemplates/WebVR/webvr.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
'use strict';

var defaultHeight = 1.5;
var entervrButton = document.querySelector('#entervr');
var container = document.querySelector('#game');
var status = document.querySelector('#status');
var icons = document.querySelector('#icons');
var controller = document.querySelector('#motion-controller');

var enterVRButton = document.getElementById('entervr');
var gameContainer = document.getElementById('game');
var vrHardwareStatus = document.getElementById('status');
var statusIcons = document.getElementById('icons');
var controllerIconTemplate = document.getElementById('motion-controller');
var noVRInstructions = document.getElementById('novr');

var windowRaf = window.requestAnimationFrame;
var vrDisplay = null;
var canvas = null;
Expand Down Expand Up @@ -46,25 +49,34 @@
}

function onUnity (msg) {
// Measure Round-Trip Time from Unity.
if (msg.detail === 'Timer') {
var delta = window.performance.now() - testTimeStart;
console.log('return time (ms): ',delta);
testTimeStart = null;
return;
}
// This way of passing messages is deprecated. Use rich objects instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a TODO?

if (typeof msg.detail === 'string') {
// Measure Round-Trip Time from Unity.
if (msg.detail === 'Timer') {
var delta = window.performance.now() - testTimeStart;
console.log('return time (ms): ',delta);
testTimeStart = null;
return;
}

// Wait for Unity to render the frame; then submit the frame to the VR display.
if (msg.detail === 'PostRender') {
submitNextFrame = vrDisplay && vrDisplay.isPresenting;
if (submitNextFrame) {
vrDisplay.requestAnimationFrame(onAnimate);
// Wait for Unity to render the frame; then submit the frame to the VR display.
if (msg.detail === 'PostRender') {
submitNextFrame = vrDisplay && vrDisplay.isPresenting;
if (submitNextFrame) {
vrDisplay.requestAnimationFrame(onAnimate);
}
}

// Handle quick VR/normal toggling.
if (msg.detail.indexOf('ConfigureToggleVRKeyName') === 0) {
toggleVRKeyName = msg.detail.split(':')[1];
}
}

// Handle quick VR/normal toggling.
if (msg.detail.indexOf('ConfigureToggleVRKeyName') === 0) {
toggleVRKeyName = msg.detail.split(':')[1];
// Handle an UI command
if (msg.detail.type === 'ShowPanel') {
var panelId = document.getElementById(msg.detail.panelId);
showInstruction(panelId);
}
}

Expand All @@ -88,7 +100,7 @@
return vrDisplay.requestPresent([{source: canvas}]).then(function () {
// Start stereo rendering in Unity.
console.log('Entered VR mode');
gameInstance.SendMessage('WebVRCameraSet', 'Begin');
gameInstance.SendMessage('WebVRCameraSet', 'OnStartVR');
}).catch(function (err) {
console.error('Unable to enter VR mode:', err);
});
Expand All @@ -101,7 +113,7 @@
}
function done () {
// End stereo rendering in Unity.
gameInstance.SendMessage('WebVRCameraSet', 'End');
gameInstance.SendMessage('WebVRCameraSet', 'OnEndVR');
onResize();
}
return vrDisplay.exitPresent().then(function () {
Expand Down Expand Up @@ -223,11 +235,11 @@
// scale game container so we get a proper sized mirror of VR content to desktop.
var scaleX = window.innerWidth / renderWidth;
var scaleY = window.innerHeight / renderHeight;
container.setAttribute('style', `transform: scale(${scaleX}, ${scaleY}); transform-origin: top left;`);
gameContainer.setAttribute('style', `transform: scale(${scaleX}, ${scaleY}); transform-origin: top left;`);
} else {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
container.style.transform = '';
gameContainer.style.transform = '';
}
}

Expand All @@ -242,6 +254,7 @@
}

function showInstruction (el) {
if (el.dataset.enabled) { return; }
var confirmButton = el.querySelector('button');
el.dataset.enabled = true;
confirmButton.addEventListener('click', onConfirm);
Expand All @@ -252,19 +265,19 @@
}

function updateStatus () {
if (parseInt(status.dataset.gamepads) !== vrGamepads.length) {
if (parseInt(vrHardwareStatus.dataset.gamepads) !== vrGamepads.length) {
var controllerClassName = 'controller-icon';
var controlIcons = icons.getElementsByClassName(controllerClassName);
var controlIcons = statusIcons.getElementsByClassName(controllerClassName);
while (controlIcons.length > 0) {
controlIcons[0].parentNode.removeChild(controlIcons[0]);
}

vrGamepads.forEach(function (gamepad) {
var controllerIcon = document.importNode(controller.content, true);
var controllerIcon = document.importNode(controllerIconTemplate.content, true);
controllerIcon.querySelector('img').className = controllerClassName;
icons.appendChild(controllerIcon);
statusIcons.appendChild(controllerIcon);
});
status.dataset.gamepads = vrGamepads.length;
vrHardwareStatus.dataset.gamepads = vrGamepads.length;
}
}

Expand All @@ -287,26 +300,30 @@
frameData = new VRFrameData();

return navigator.getVRDisplays().then(function(displays) {
if (!displays.length) {
return null;
var canPresent = false;
var hasPosition = false;
var hasOrientation = false;
var hasExternalDisplay = false;

if (displays.length) {
vrDisplay = displays[displays.length - 1];
canPresent = vrDisplay.capabilities.canPresent;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps might be easier to just manage 1 variable called capabilities than the 4 intermediate variables?

hasPosition = vrDisplay.capabilities.hasPosition;
hasOrientation = vrDisplay.capabilities.hasOrientation;
hasExternalDisplay = vrDisplay.capabilities.hasExternalDisplay;
}

vrDisplay = displays[displays.length - 1];

if (!vrDisplay) {
return null;
}
enterVRButton.dataset.enabled = canPresent;

if (isPolyfilled(vrDisplay)) {
showInstruction(document.querySelector('#novr'));
} else {
status.dataset.enabled = 'true';
}

if (vrDisplay.capabilities && vrDisplay.capabilities.canPresent) {
// Enable button to toggle entering/exiting VR.
entervrButton.dataset.enabled = 'true';
}
gameInstance.SendMessage(
'WebVRCameraSet', 'OnVRCapabilities',
JSON.stringify({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we not just JSON.stringify(vrDisplay.capabilities)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can handle in #104

canPresent: canPresent,
hasPosition: hasPosition,
hasOrientation: hasOrientation,
hasExternalDisplay: hasExternalDisplay
})
);

return vrDisplay;
}).catch(function (err) {
Expand Down Expand Up @@ -335,7 +352,7 @@
window.addEventListener('keyup', onKeyUp, false);
document.addEventListener('UnityLoaded', onUnityLoaded, false);
document.addEventListener('Unity', onUnity);
entervrButton.addEventListener('click', onToggleVR, false);
enterVRButton.addEventListener('click', onToggleVR, false);

onResize();

Expand Down
4 changes: 4 additions & 0 deletions Assets/WebVR/Plugins/WebGL/webvr.jslib
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ mergeInto(LibraryManager.library, {

ConfigureToggleVRKeyName: function (keyName) {
document.dispatchEvent(new CustomEvent('Unity', {detail: 'ConfigureToggleVRKeyName:' + Pointer_stringify(keyName)}));
},

ShowPanel: function (panelId) {
document.dispatchEvent(new CustomEvent('Unity', {detail: {type:'ShowPanel', panelId: Pointer_stringify(panelId)}}));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space after type:

}
});
16 changes: 16 additions & 0 deletions Assets/WebVR/Prefabs/WebVRCameraSet.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ GameObject:
- component: {fileID: 4620614974547310}
- component: {fileID: 114951743782495552}
- component: {fileID: 81381995457807688}
- component: {fileID: 114848038275145070}
m_Layer: 0
m_Name: WebVRCameraSet
m_TagString: Untagged
Expand Down Expand Up @@ -273,6 +274,21 @@ Behaviour:
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1147971983220084}
m_Enabled: 1
--- !u!114 &114848038275145070
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1514700693580046}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 683f145ef879be447ba25c1080ac1984, type: 3}
m_Name:
m_EditorClassIdentifier:
translationSpeed: 7
rotationSpeed: 90
rotationEnabled: 1
translationEnabled: 1
--- !u!114 &114951743782495552
MonoBehaviour:
m_ObjectHideFlags: 1
Expand Down
18 changes: 14 additions & 4 deletions Assets/WebVR/Scenes/WebVR.unity
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,11 @@ MeshFilter:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 705953490}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &757088923 stripped
GameObject:
m_PrefabParentObject: {fileID: 1147971983220084, guid: 78df02845d4b54181b4ca9188aba0671,
type: 2}
m_PrefabInternal: {fileID: 1315843485}
--- !u!1 &821505835 stripped
GameObject:
m_PrefabParentObject: {fileID: 100030, guid: 013217fcf4bba4f3380d9159876fa8ea, type: 3}
Expand Down Expand Up @@ -1603,14 +1608,14 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 114951743782495552, guid: 78df02845d4b54181b4ca9188aba0671,
type: 2}
propertyPath: rightHandObject
propertyPath: leftHandObject
value:
objectReference: {fileID: 1269233424}
objectReference: {fileID: 757088923}
- target: {fileID: 114951743782495552, guid: 78df02845d4b54181b4ca9188aba0671,
type: 2}
propertyPath: leftHandObject
propertyPath: rightHandObject
value:
objectReference: {fileID: 821505835}
objectReference: {fileID: 2040219167}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 78df02845d4b54181b4ca9188aba0671, type: 2}
m_IsPrefabParent: 0
Expand Down Expand Up @@ -2189,6 +2194,11 @@ Transform:
m_Father: {fileID: 2005427646}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: -16.601002, y: -7.7430005, z: 25.449001}
--- !u!1 &2040219167 stripped
GameObject:
m_PrefabParentObject: {fileID: 1118756453539842, guid: 78df02845d4b54181b4ca9188aba0671,
type: 2}
m_PrefabInternal: {fileID: 1315843485}
--- !u!4 &2066780126 stripped
Transform:
m_PrefabParentObject: {fileID: 400000, guid: 7e57e26a714804d3c9f1baa605131856, type: 3}
Expand Down
10 changes: 10 additions & 0 deletions Assets/WebVR/Scripts/Input.meta

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

Loading