XRViewerPose.views - Web APIs 编辑

Secure context

This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The read-only XRViewerPose property views returns an array which contains every XRView which must be rendered in order to fully represent the scene from the viewpoint defined by the viewer pose. For monoscopic devices, this array contains a single view.

Important: There is no guarantee that the number of views will remain constant over the lifetime of an XRSession. For each frame, you should always use the current length of this array rather than caching the value.

Stereo views require two views to render properly, with the left eye's view having its eye set to the string left and the right eye's view a value of right.

Syntax

let viewList = xrViewerPose.views;

Value

An array of XRView objects, one for each view available as part of the scene for the current viewer pose. This array's length may potentially vary over the lifetime of the XRSession (for example, if the viewer enables or disables stereo mode on their XR output device).

Examples

In this example—part of the code to render an XRFrame, getViewerPose() is called to get an XRViewerPose using the same reference space the code is using as its base reference space. If a valid pose is returned, the frame is rendered by clearing the backbuffer and then rendering each of the views in the pose; these are most likely the views for the left and right eyes.

let pose = frame.getViewerPose(xrReferenceSpace);

if (pose) {
  let glLayer = xrSession.renderState.baseLayer;

  gl.bindFrameBuffer(gl.FRAMEBUFFER, glLayer.framebuffer);
  gl.clearColor(0, 0, 0, 1);
  gl.clearDepth(1);
  gl.clear(gl.COLOR_BUFFER_BIT, gl.DEPTH_BUFFER_BIT);

  for (let view of pose.views) {
    let viewport = glLayer.getViewport(view);
    gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);

    /* render the scene for the eye view.eye */
  }
}

Passing each view to getViewport() returns the WebGL viewport to apply in order to cause the rendered output to be positioned correctly in the framebuffer for renderijng to the corresponding eye on the output device.

This code is derived from Drawing a frame in Movement, orientation, and motion: A WebXR example. You can see more context and see much more on that page.

Specifications

SpecificationStatusComment
WebXR Device API
The definition of 'XRViewerPose.views' in that specification.
Working DraftInitial definition.

Browser compatibility

BCD tables only load in the browser

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:40 次

字数:4928

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文