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 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
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)}}));
}
});
24 changes: 24 additions & 0 deletions Assets/WebVR/Prefabs/WebVRCameraSet.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ GameObject:
- component: {fileID: 20329244052411564}
- component: {fileID: 124144808855090856}
- component: {fileID: 92017933162973034}
- component: {fileID: 114089120386618070}
m_Layer: 0
m_Name: CameraMain
m_TagString: Untagged
Expand Down Expand Up @@ -273,6 +274,29 @@ Behaviour:
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1147971983220084}
m_Enabled: 1
--- !u!114 &114089120386618070
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1614126958852788}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 683f145ef879be447ba25c1080ac1984, type: 3}
m_Name:
m_EditorClassIdentifier:
rotationEnabled: 1
translationEnabled: 1
noVROffset: {x: 0, y: 1.2, z: 0}
rotationSpeed: 90
translationSpeed: 7
rotationDeadDistance: 0.001
moveForwardKeys: 7700000011010000
moveBackwardKeys: 7300000012010000
strideRightKeys: 6400000013010000
strideLeftKeys: 6100000014010000
moveUpwardKeys: 72000000
moveDownwardKeys: 66000000
--- !u!114 &114951743782495552
MonoBehaviour:
m_ObjectHideFlags: 1
Expand Down
14 changes: 2 additions & 12 deletions Assets/WebVR/Scenes/WebVR.unity
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 400030, guid: 013217fcf4bba4f3380d9159876fa8ea, type: 3}
propertyPath: m_RootOrder
value: 2
value: 1
objectReference: {fileID: 0}
- target: {fileID: 9500000, guid: 013217fcf4bba4f3380d9159876fa8ea, type: 3}
propertyPath: m_Enabled
Expand Down Expand Up @@ -970,7 +970,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 400030, guid: c99aacc3accab4fdaadab5e3ea13b9c7, type: 3}
propertyPath: m_RootOrder
value: 1
value: 2
objectReference: {fileID: 0}
- target: {fileID: 9500000, guid: c99aacc3accab4fdaadab5e3ea13b9c7, type: 3}
propertyPath: m_Enabled
Expand Down Expand Up @@ -1601,16 +1601,6 @@ Prefab:
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 114951743782495552, guid: 78df02845d4b54181b4ca9188aba0671,
type: 2}
propertyPath: rightHandObject
value:
objectReference: {fileID: 1269233424}
- target: {fileID: 114951743782495552, guid: 78df02845d4b54181b4ca9188aba0671,
type: 2}
propertyPath: leftHandObject
value:
objectReference: {fileID: 821505835}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 78df02845d4b54181b4ca9188aba0671, type: 2}
m_IsPrefabParent: 0
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