// currently returns an empty array
let layers = vrDisplay.getLayers();
if (navigator.getVRDisplays) {
console.log("WebVR 1.1 supported");
// Then get the displays attached to the computer
navigator.getVRDisplays().then((displays) => {
// If a display is available, use it to present the scene
if (displays.length > 0) {
vrDisplay = displays[0];
console.log("Display found");
// Starting the presentation when the button is clicked: It can only be called in response to a user gesture
btn.addEventListener("click", () => {
vrDisplay.requestPresent([{ source: canvas }]).then(() => {
console.log("Presenting to WebVR display");
// Here it returns an array of VRLayerInit objects
layers = vrDisplay.getLayers();
// …
});
});
}
});
}VRLayerInit / notebook
VRLayerInit
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
const init = {
leftBounds: [/* … */],
rightBounds: [/* … */],
source: canvasReference,
};