-
-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(WebXR): Add Looking Glass support to GeometryViewer example
Adds "xrSessionType" URL parameter with Looking Glass option.
- Loading branch information
Showing
2 changed files
with
65 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,44 @@ function preventDefaults(e) { | |
e.stopPropagation(); | ||
} | ||
|
||
// WebXR | ||
let requestedXrSessionType = | ||
userParams.xrSessionType !== undefined ? userParams.xrSessionType : null; | ||
if ( | ||
requestedXrSessionType !== null && | ||
!Object.values(XrSessionTypes).includes(requestedXrSessionType) | ||
) { | ||
console.warn( | ||
'Could not parse requested XR session type: ', | ||
requestedXrSessionType | ||
); | ||
requestedXrSessionType = null; | ||
} | ||
|
||
if (requestedXrSessionType === XrSessionTypes.LookingGlassVR) { | ||
// Import the Looking Glass WebXR Polyfill override | ||
// Assumes that the Looking Glass Bridge native application is already running. | ||
// See https://docs.lookingglassfactory.com/developer-tools/webxr | ||
import( | ||
// eslint-disable-next-line import/no-unresolved, import/extensions | ||
/* webpackIgnore: true */ 'https://unpkg.com/@lookingglass/[email protected]/dist/@lookingglass/bundle/webxr.js' | ||
).then((obj) => { | ||
// eslint-disable-next-line no-new | ||
new obj.LookingGlassWebXRPolyfill(); | ||
}); | ||
} else if (requestedXrSessionType === null && navigator.xr !== undefined) { | ||
// Determine supported session type | ||
navigator.xr.isSessionSupported('immersive-ar').then((arSupported) => { | ||
if (arSupported) { | ||
requestedXrSessionType = XrSessionTypes.MobileAR; | ||
} else { | ||
navigator.xr.isSessionSupported('immersive-vr').then((vrSupported) => { | ||
requestedXrSessionType = vrSupported ? XrSessionTypes.HmdVR : null; | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
// ---------------------------------------------------------------------------- | ||
// DOM containers for UI control | ||
// ---------------------------------------------------------------------------- | ||
|
@@ -198,7 +236,10 @@ function createPipeline(fileName, fileContents) { | |
|
||
const immersionSelector = document.createElement('button'); | ||
immersionSelector.setAttribute('class', selectorClass); | ||
immersionSelector.innerHTML = 'Start AR'; | ||
immersionSelector.innerHTML = | ||
requestedXrSessionType === XrSessionTypes.MobileAR | ||
? 'Start AR' | ||
: 'Start VR'; | ||
|
||
const controlContainer = document.createElement('div'); | ||
controlContainer.setAttribute('class', style.control); | ||
|
@@ -211,8 +252,8 @@ function createPipeline(fileName, fileContents) { | |
|
||
if ( | ||
navigator.xr !== undefined && | ||
navigator.xr.isSessionSupported('immersive-ar') && | ||
fullScreenRenderWindow.getApiSpecificRenderWindow().getXrSupported() | ||
fullScreenRenderWindow.getApiSpecificRenderWindow().getXrSupported() && | ||
requestedXrSessionType !== null | ||
) { | ||
controlContainer.appendChild(immersionSelector); | ||
} | ||
|
@@ -388,22 +429,29 @@ function createPipeline(fileName, fileContents) { | |
// Immersion handling | ||
// -------------------------------------------------------------------- | ||
|
||
function toggleAR() { | ||
if (immersionSelector.textContent === 'Start AR') { | ||
function toggleXR() { | ||
if (requestedXrSessionType === XrSessionTypes.MobileAR) { | ||
fullScreenRenderWindow.setBackground([...background, 0]); | ||
} | ||
|
||
if (immersionSelector.textContent.startsWith('Start')) { | ||
fullScreenRenderWindow | ||
.getApiSpecificRenderWindow() | ||
.startXR(XrSessionTypes.MobileAR); | ||
immersionSelector.textContent = 'Exit AR'; | ||
.startXR(requestedXrSessionType); | ||
immersionSelector.textContent = | ||
requestedXrSessionType === XrSessionTypes.MobileAR | ||
? 'Exit AR' | ||
: 'Exit VR'; | ||
} else { | ||
fullScreenRenderWindow.setBackground([...background, 255]); | ||
fullScreenRenderWindow | ||
.getApiSpecificRenderWindow() | ||
.stopXR(XrSessionTypes.MobileAR); | ||
immersionSelector.textContent = 'Start AR'; | ||
fullScreenRenderWindow.getApiSpecificRenderWindow().stopXR(); | ||
immersionSelector.textContent = | ||
requestedXrSessionType === XrSessionTypes.MobileAR | ||
? 'Start AR' | ||
: 'Start VR'; | ||
} | ||
} | ||
immersionSelector.addEventListener('click', toggleAR); | ||
immersionSelector.addEventListener('click', toggleXR); | ||
|
||
// -------------------------------------------------------------------- | ||
// Pipeline handling | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters