console log navigator xr let res await navigator xr isSessionSupported immersive vr console log res let res await navigator xr isSessionSupported immersive ar console log res let res await navigator xr isSessionSupported inline console log res for key in navigator xr console log key navigator xr key without await let session navigator xr requestSession inline console log Promise session instanceof Promise console log session with await let session await navigator xr requestSession inline console log Promise session instanceof Promise console log session Calling requestSession starts a request and returns a promise When the request completes the promise resolves to the response object From the response object you can extract data you need to proceed Because requestSession returns a promise you can simplify the code by using the async await syntax session await navigator xr requestSession The await waits until ready then returns the final object not the Promise let session await navigator xr requestSession inline console log session for key in session if key depthUsage continue if key depthDataFormat continue console log key session key navigator xr requestSession inline then session xrSession session continue to set up the session console log xrSession for key in xrSession console log key xrSession key let xrSession await navigator xr requestSession inline console log xrSession let res await xrSession requestAnimationFrame onXRFrame console log res function onXRFrame t frame console log frame document body style height 200px let xrSession await navigator xr requestSession inline console log xrSession function onXRFrame t frame console log frame frame xrSession requestAnimationFrame onXRFrame let glLayer xrSession renderState baseLayer gl clearColor 0 0 0 1 0 gl clearDepth 1 0 gl clear gl COLOR_BUFFER_BIT gl DEPTH_BUFFER_BIT let canvas document createElement canvas canvas style width 100px canvas style height 100px document body appendChild canvas console log canvas canvas let gl canvas getContext webgl xrCompatible true console log gl gl let glLayer new XRWebGLLayer xrSession gl console log glLayer glLayer let rs await xrSession updateRenderState baseLayer glLayer console log rs let refSpace await xrSession requestReferenceSpace viewer console log refSpace refSpace let res xrSession requestAnimationFrame onXRFrame console log res document body style height 200px Obtain XR object const XR navigator xr Request a new XRSession XR requestSession inline then xrSession xrSession requestAnimationFrame time xrFrame console log here let viewer xrFrame getViewerPose xrReferenceSpace gl bindFramebuffer xrWebGLLayer framebuffer for xrView of viewer views let xrViewport xrWebGLLayer getViewport xrView gl viewport xrViewport x xrViewport y xrViewport width xrViewport height WebGL draw calls will now be rendered into the appropriate viewport let count 0 let xrSession null document body style height 200px let canvas document createElement canvas canvas style width 100px canvas style height 100px document body appendChild canvas console log canvas canvas let gl canvas getContext webgl xrCompatible true console log gl gl function onWindowAnimationFrame time window requestAnimationFrame onWindowAnimationFrame count This may be called while an immersive session is running on some devices such as a desktop with a tethered headset To prevent two loops from rendering in parallel skip drawing in this one until the session ends if xrSession renderFrame time null if count 5 console log nonXRFrame The window animation loop can be started immediately upon the page loading window requestAnimationFrame onWindowAnimationFrame function onXRAnimationFrame time xrFrame xrSession requestAnimationFrame onXRAnimationFrame console log xrFrame xrFrame renderFrame time xrFrame function renderFrame time xrFrame gl clearColor 0 1 0 1 0 gl clearDepth 1 0 gl clear gl COLOR_BUFFER_BIT gl DEPTH_BUFFER_BIT if count 5 console log renderFrame count Assumed to be called by a user gesture event elsewhere in code function startXRSession console log startXRSession called navigator xr requestSession inline then session xrSession session console log xrSession xrSession xrSession addEventListener end onXRSessionEnded Do necessary session setup here Begin the sessions animation loop console log Begin the sessions animation loop count 0 xrSession requestAnimationFrame onXRAnimationFrame function onXRSessionEnded xrSession null let button document createElement button button innerHTML startXRSession button onclick function startXRSession document body appendChild button
ion requestAnimationFrame onXRFrame console log res document body style height 200px Obtain XR object const XR navigator xr Request a new XRSession XR requestSession inline then xrSession xrSession requestAnimationFrame time xrFrame console log here let viewer xrFrame getViewerPose xrReferenceSpace gl bindFramebuffer xrWebGLLayer framebuffer for xrView of viewer views let xrViewport xrWebGLLayer getViewport xrView gl viewport xrViewport x xrViewport y xrViewport width xrViewport height WebGL draw calls will now be rendered into the appropriate viewport let count 0 let xrSession null document body style height 200px let canvas document createElement canvas canvas style width 100px canvas style height 100px document body appendChild canvas console log canvas canvas let gl canvas getContext webgl xrCompatible true console log gl gl function onWindowAnimationFrame time window requestAnimationFrame onWindowAnimationFrame count This may be called while an immersive session is running on some devices such as a desktop with a tethered headset To prevent two loops from rendering in parallel skip drawing in this one until the session ends if xrSession renderFrame time null if count 5 console log nonXRFrame The window animation loop can be started immediately upon the page loading window requestAnimationFrame onWindowAnimationFrame function onXRAnimationFrame time xrFrame xrSession requestAnimationFrame onXRAnimationFrame console log xrFrame xrFrame renderFrame time xrFrame function renderFrame time xrFrame gl clearColor 0 1 0 1 0 gl clearDepth 1 0 gl clear gl COLOR_BUFFER_BIT gl DEPTH_BUFFER_BIT if count 5 console log renderFrame count Assumed to be called by a user gesture event elsewhere in code function startXRSession console log startXRSession called navigator xr requestSession inline then session xrSession session console log xrSession xrSession xrSession addEventListener end onXRSessionEnded Do necessary session setup here Begin the sessions animation loop console log Begin the sessions animation loop count 0 xrSession requestAnimationFrame onXRAnimationFrame function onXRSessionEnded xrSession null let button document createElement button button innerHTML startXRSession button onclick function startXRSession document body appendChild button