草案
此页面不完整。
In this guide, we'll get a birds-eye view of what's involved in creating and driving a WebXR application, without diving down to the code level in detail. This serves as preparation for the next few articles in these WebXR guides, which cover starting up and shutting down a WebXR session, geometry , simulating cameras , spatial tracking ,等。
Most applications using WebXR will follow a similar overall design pattern:
navigator.xr
is undefined, you can assume the user's browser and/or device doesn't support WebXR. If it's not supported, disable any user interface used to activate XR features and abort any attempts to enter XR mode.
navigator.xr.isSessionSupported()
, specifying the WebXR experience mode you want to provide:
inline
,
immersive-vr
,或
immersive-ar
, in order to determine whether or not the type of session you wish to provide is available.
XRSession
using the desired mode. This is done by calling
navigator.xr.requestSession()
, again specifying the string indicating the mode you want to enable:
inline
,
immersive-vr
,或
immersive-ar
.
requestSession()
resolves, use the new
XRSession
to manage the WebXR session for the duration of the WebXR experience. This will involve managing inputs, animations, and rendering.
XRSession
方法
requestAnimationFrame()
to schedule the first frame render for the XR device.
Worker
—or using one that you've previously created for this purpose—to perform the computations needed for each frame to be rendered. This will reduce the chance that the rendering process will noticeably stall the app.
requestAnimationFrame()
callback should use the information provided about the objects located in the 3D world to render the frame using WebGL.
requestAnimationFrame()
again in order to let the browser know that the callback needs to be run again when it's time to render the next frame.
XRSession.end()
.
XRSession
event
end
event to be informed when the session is ending, regardless of whether your code, the user, or the browser initiated the termination of the session.