XRHandedness - Web APIs 编辑

The WebXR enumerated type XRHandedness provides values which identify which of a user's hands is being used to operate a particular input controller attached to the XR input device being used. XRHandedness is used as the value of the the XRInputSource property handedness.

Values

none
The input controller is not associated with one of the user's hands.
left
The input controller is being held in, worn on, or is attached to the user's left hand.
right
The input controller is being held in, worn on, or is attached to the user's right hand.

Examples

One important usage scentario for handedness is to determine which hand a controller is in so you can draw a representation of that hand (or the device that hand is controlling) in virtual space.

function updateInputSources(session, frame, refSpace) {
  for (let source of session.inputSources) {
    if (source.gripSpace) {
      let gripPose = frame.getPose(source.gripSpace, refSpace);

      if (gripPose) {
        myRenderHandObject(gripPose, inputSource.handedness);
      }
    }
  }
}

This function, which would be called every animation frame (or possibly just periodically, depending on the degree of smoothness required and any performance constraints), scans the list of input sources looking for any which have a gripSpace which isn't null. If a gripSpace is present, that means the input source is a hand-held device of some sort, so it should be rendered visibly if possible.

If gripSpace is non-null, the function proceeds to get the pose for the gripSpace transformed into the current reference space. Assuming that's then valid, a function called myRenderHandObject() is called with the grip's pose and the value of handedness. With these values in hand (no pun intended), myRenderHandObject() can draw the appropriate model positioned and formed for the correct hand.

Specifications

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

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技术交流群

发布评论

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

词条统计

浏览:85 次

字数:3975

最后编辑:6年前

编辑次数:0 次

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