XRInputSourceEvent - Web APIs 编辑

Secure context

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

The WebXR Device API's XRInputSourceEvent interface describes an event which has occurred on a WebXR user input device such as a hand controller, gaze tracking system, or motion tracking system. More specifically, they represent a change in the state of an XRInputSource.

To learn more about handling inputs in a WebXR project, see the article Inputs and input sources.

Constructor

XRInputSourceEvent()
Creates and returns a new XRInputSourceEvent object whose properties match those provided in the eventInitDict dictionary provided.

Properties

frame Read only
An XRFrame object providing the needed information about the event frame during which the event occurred. This frame may have been rendered in the past rather than being a current frame. Because this is an event frame, not an animation frame, you cannot call the XRFrame method getViewerPose() on it; instead, use getPose().
inputSource Read only
An XRInputSource object indicating which input source generated the input event.

Methods

The XRInputSourceEvent interface doesn't define any methods; however, several methods are inherited from the parent interface, Event.

Event types

select
Sent to an XRSession when the sending input source has fully completed a primary action.
selectend
Sent to an XRSession when an ongoing primary action ends, or when an input source with an ongoing primary action has been disconnected from the system.
selectstart
Sent to an XRSession when an input source begins its primary action, indicating that the user has begun a command-like input, such as pressing a trigger or button, issuing a spoken command, tapping on a touchpad, or the like.
squeeze
Sent to an XRSession when the sending input source has fully completed a primary squeeze action.
squeezeend
Sent to an XRSession when an ongoing primary squeeze action ends or when an input source with an ongoing primary squeeze action is disconnected.
squeezestart
Sent to an XRSession when an input source begins its primary squeeze action, indicating that the user has begun to grab, squeeze, or grip the controller.

Examples

The code below sets up handlers for primary action events in order to determine when the user clicks on (shoots at/pokes at/whatever) objects in the scene.

xrSession.addEventListener("select", event => {
  let targetRayPose = event.frame.getPose(event.inputSource.targetRaySpace, myRefSpace);

  if (targetRayPose) {
    let hit = myHitTest(targetRayPose.transform);
    if (hit) {
      /* handle the hit */
    }
  }
});

Specifications

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

Browser compatibility

BCD tables only load in the browser

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

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

发布评论

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

词条统计

浏览:141 次

字数:6498

最后编辑:7年前

编辑次数:0 次

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