XRView.eye - Web APIs 编辑

Secure context

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

The XRView interface's read-only eye property is a string taken from the XREye enumerated type, indicating which eye's viewpoint the XRView represents: left or right. For views which represent neither eye, such as monoscopic views, this property's value is none.

Syntax

let eye = xrView.eye;

Value

A DOMString whose value is one of the strings enumerated by the XREye type:

left
The XRView represents the point-of-view of the viewer's left eye.
right
The view represents the viewer's right eye.
none
The XRView describes a monoscopic view, or the view otherwise doesn't represent a particular eye's point-of-view.

Usage notes

The primary purpose of this property is to allow the correct area of any pre-rendered stereo content to be presented to the correct eye. For dynamically-rendered 3D content, you can usually ignore this and render each of the viewer's views, one after another.

Examples

This code, from the viewer pose's renderer, iterates over the pose's views and renders them. However, we have flags which, if true, indicate that a particular eye has been injured during gameplay. When rendering that eye, if the flag is true, that view is skipped instead of being rendered.

glLayer = xrSession.renderState.baseLayer;
gl.bindFramebuffer(gl.FRAMEBUFFER, glLayer.framebuffer);
gl.clearColor(0,0, 0, 1.0);
gl.clearDepth(1.0);
gl.clear(gl.COLOR_BUFFER_BIT, gl.DEPTH_BUFFER_BIT);

for (let view of xrPose.views) {
  let skipView = false;

  if (view.eye == "left" && body.leftEye.injured) ||
    skipView = updateInjury(body.leftEye);
  } else if (view.eye == "right" && body.rightEye.injured) {
    skipView = updateInjury(body.rightEye);
  }

  if (!skipView) {
    let viewport = glLayer.getViewport(view);
    gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
    renderScene(gl, view);
  }
}

For each of the views, the value of eye is checked and  if it's either left or right, we check to see if the body.leftEye.injured or body.rightEye.injured property is true; if so, we call a function updateInjury() on that eye to do things such as allow a bit of healing to occur, track the progress of a poison effect, or the like, as appropriate for the game's needs.

updateInjury() returns true if the eye is still injured or false if the eye has been restored to health by the function,. If the result is false, indicating that the eye is now healthy, we render the scene for that eye. Otherwise, we don't.

Specifications

SpecificationStatusComment
WebXR Device API
The definition of 'XRView.eye' in that specification.
Working DraftInitial definition.

Browser compatibility

BCD tables only load in the browser

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

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

发布评论

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

词条统计

浏览:128 次

字数:4734

最后编辑:7年前

编辑次数:0 次

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