安全上下文
此特征只可用于
安全上下文
(HTTPS),在某些或所有
支持浏览器
.
草案
此页面不完整。
The WebXR Device API's
XRSession
interface represents an ongoing XR session, providing methods and properties used to interact with and control the session. To open a WebXR session, use the
XRSystem
接口的
requestSession()
方法。
采用
XRSession
methods, you can poll the viewer's position and orientation (the
XRViewerPose
), gather information about the user's environment, and present imagery to the user.
XRSession
supports both inline and immersive virtual and augmented reality modes.
In addition to the properties listed below,
XRSession
继承来自其父级接口的特性,
EventTarget
.
environmentBlendMode
只读
Returns this session's blend mode which denotes how much of the real-world environment is visible through the XR device and how the device will blend the device imagery with it.
注意:
environmentBlendMode()
属于
WebXR Augmented Reality Module
, which has not been completed.
inputSources
只读
XRInputSource
s, each representing an input device used to control the camera and/or scene.
renderState
只读
XRRenderState
object which contains options affecting how the imagery is rendered. This includes things such as the near and far clipping planes (distances defining how close and how far away objects can be and still get rendered), as well as field of view information.
visibilityState
只读
DOMString
whose value is one of those found in the
XRVisibilityState
enumerated type, indicating whether or not the session's imagery is visible to the user, and if so, if it's being visible but not currently the target for user events.
XRSession
provides the following methods in addition to those inherited from its parent interface,
EventTarget
.
cancelAnimationFrame()
XRSession
's set of animation frame rendering callbacks, given the identifying handle returned by a previous call to
requestAnimationFrame()
.
end()
promise
which resolves when the session has been shut down.
requestAnimationFrame()
cancelAnimationFrame()
. This method is comparable to the
Window.requestAnimationFrame()
方法。
requestReferenceSpace()
XRReferenceSpace
of the specified type be created. Returns a promise which resolves with the
XRReferenceSpace
or
XRBoundedReferenceSpace
which was requested, or throws a
NotSupportedError
if the requested space type isn't supported by the device.
updateRenderState()
XRRenderStateInit
dictionary. Any properties not included in the given dictionary are left unchanged from their current values.
The following events are delivered to
XRSession
对象。
| 事件 | 描述 |
|---|---|
end
|
Sent to the
XRSession
object after the WebXR session has ended and all hardware-related functions have completed. The event is represented by an object of type
XRSessionEvent
.
Also available through the
onend
event handler property.
|
inputsourceschange
|
An event of type
XRInputSourcesChangeEvent
sent to the
XRSession
when the list of active XR input sources has changed.
Also available through the
oninputsourceschange
event handler property.
|
select
|
An event of type
XRInputSourceEvent
which is sent to the session when one of the session's input sources has successfully completed a
primary action
. This generally corresponds to the user pressing a trigger, touchpad, or button, speaks a command, or performs a recognizable gesture. The
select
event is sent after the
selectstart
event is sent and immediately before the
selectend
event is sent. If
select
is
not
sent, then the select action was aborted before being completed.
Also available through the
onselect
event handler property.
|
selectend
|
An event of type
XRInputSourceEvent
which gets sent to the session object when one of its input devices finishes its primary action or gets disconnected while in the process of handling a primary action. For example: for button or trigger actions, this means the button has been released; for spoken commands, it means the user has finished speaking. This is the last of the three
select*
events to be sent.
Also available through the
onselectend
event handler property.
|
selectstart
|
An event of type
XRInputSourceEvent
which is sent to the session object when one of its input devices is first engaged by the user in such a way as to cause the primary action to begin. This is the first of the
session*
event to be sent.
Also available through the
onselectstart
event handler property.
|
squeeze
|
XRInputSourceEvent
sent to indicate that a
primary squeeze action
has successfully completed. This indicates that the device being squeezed has been released, and may represent dropping a grabbed object, for example. It is sent immediately before the
squeezeend
event is sent to indicate that the squeeze action is over.
Also available through the
onsqueeze
event handler property.
|
squeezeend
|
XRInputSourceEvent
sent to the
XRSession
当
primary squeeze action
ends, whether or not the action was successful.
Also available using the
onsqueezeend
event handler property.
|
squeezestart
|
An event of type
XRInputSourceEvent
which is sent to the
XRSession
when the user initially squeezes a squeezable controller. This may be, for example, a trigger which is used to represent grabbing objects, or might represent actual squeezing when wearing a haptic glove.
Also available through the
onsqueezestart
event handler property.
|
visibilitychange
|
XRSessionEvent
which is sent to the session when its visibility state as indicated by the
visibilityState
改变。
Also available through the
onvisibilitychange
event handler property.
|
This example establishes a new
XRSession
in
inline
mode so that it can be displayed within an HTML element, avoiding the need for a dedicated AR or VR viewing device such as a headset.
const XR = navigator.xr;
if (XR) {
XR.requestSession("inline").then((xrSession) => {
xrSession.requestReferenceSpace("local").then((xrReferenceSpace) => {
xrSession.requestAnimationFrame((time, xrFrame) => {
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);
}
});
});
});
} else {
/* WebXR is not available */
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebXR 设备 API
The definition of 'XRSession' in that specification. |
工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
XRSession
|
Chrome 79 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 11.2 |
cancelAnimationFrame()
|
Chrome 79 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 11.2 |
end()
|
Chrome 79 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 11.2 |
end
event
|
Chrome 79 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 11.2 |
environmentBlendMode
|
Chrome 79 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 11.2 |
inputSources
|
Chrome 79 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 11.2 |
inputsourceschange
event
|
Chrome 79 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 11.2 |
onend
|
Chrome 79 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 11.2 |
oninputsourceschange
|
Chrome 79 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 11.2 |
onselect
|
Chrome 79 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 11.2 |
onselectend
|
Chrome 79 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 11.2 |
onselectstart
|
Chrome 79 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 11.2 |
onvisibilitychange
|
Chrome 79 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 11.2 |
renderState
|
Chrome 79 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 11.2 |
requestAnimationFrame()
|
Chrome 79 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 11.2 |
requestHitTestSource
|
Chrome 81 | Edge 81 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 81 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 12.1 |
requestReferenceSpace()
|
Chrome 79 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 11.2 |
select
event
|
Chrome 79 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 11.2 |
selectend
event
|
Chrome 79 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 11.2 |
selectstart
event
|
Chrome 79 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 11.2 |
updateRenderState()
|
Chrome 79 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 11.2 |
visibilitychange
event
|
Chrome 79 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 11.2 |
visibilityState
|
Chrome 79 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 11.2 |
完整支持
不支持
实验。期望将来行为有所改变。
XRSession
Navigator.xr
WebGLRenderingContext.makeXRCompatible()
XR
XRBoundedReferenceSpace
XRFrame
XRInputSource
XRInputSourceArray
XRInputSourceEvent
XRInputSourcesChangeEvent
XRPose
XRReferenceSpace
XRReferenceSpaceEvent
XRRenderState
XRRigidTransform
XRSessionEvent
XRSpace
XRView
XRViewerPose
XRViewport
XRWebGLLayer