XRSession.onsqueezeend - Web APIs 编辑

Secure context

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

The XRSession interface's onsqueezeend event handler property is a function to be invokedn when the squeezeend event sent to an XRSession when a primary squeeze action ends. This is sent immediately after the squeeze event, which announces the successful completion of the squeeze action. The squeezeend event handler is where you handle closing out a squeeze action whether it was successfully completed or not.

To learn more about how the sequence of squeeze events works, see Primary squeeze actions in Inputs and input sources.

Syntax

xrSession.onsqueezeend = squeezeendHandlerFunction;

Value

A function to be invoked whenever the XRSession receives a squeezestart event, indicating the ending of a primary squeeze action.

Examples

This snippet of code adds a simple handler for the squeezeend event, which responds only to events on the user's dominant hand. In response to the end of the squeeze operation, this code looks to see if there is an object currently being held by the user by checking to see if the variable user.heldObject contains a reference to an object representing the held item.

If heldObject has an object reference, that object is passed to a function called cancelObjectDrag(), which would be written to return the object to its original position. This takes care of the situation in which the drag is aborted or canceled.

xrSession.onsqueezeend = event => {
  if (event.inputSource.handedness == user.handedness) {
    let targetRayPose = event.frame.getPose(event.inputSource.targetRaySpace, myRefSpace;

    if (user.heldObject) {
       cancelObjectDrag(user.heldObject);
    }
  }
};

This code presumes that if the user actually intentionally completed the drag, user.heldObject will be null here. That's because (in this example, at least) the handler for the squeeze event has already dropped the object into its new location and then cleared the value of heldObject to indicate that the user is no longer holding anything.

Specifications

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

Browser compatibility

BCD tables only load in the browser

See also

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

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

发布评论

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

词条统计

浏览:122 次

字数:4872

最后编辑:7年前

编辑次数:0 次

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