安全上下文
此特征只可用于
安全上下文
(HTTPS),在某些或所有
支持浏览器
.
XRSession
接口的
onsqueeze
event handler property can be set to a function which is then invoked to handle the
squeeze
event that's sent when the user successfully completes a
primary squeeze action
on a WebXR input device.
These actions represent the user squeezing or gripping an object or controller.
To learn more about how to use and handle WebXR controller inputs, see Inputs and input sources .
xrSession.onsqueeze = squeezeHandlerFunction;
A function to be invoked whenever the
XRSession
接收
squeeze
事件。
This snippet of code adds a simple handler for the
squeeze
event, which responds only to events on the user's off-hand (that is, the hand that isn't their dominant hand). This is determined by comparing the input source's
handedness
against the value of a
handedness
property on a
user
object we've established previously.
xrSession.onsqueeze = event => {
if (event.inputSource.handedness != user.handedness) {
handleOffhandSqueeze(event.inputSource, event.frame);
}
};
This example exapnds somewhat on the previous example by demonstrating a way to implement the ability for the user to drop an object that was previously picked up by the user.. This is just a snippet of code, but should establish the general idea.
After checking that the event occurred on the user's dominant hand, the pose's target ray is obtained. Then we pass the currently held object and the target ray's transform matrix into a function we call
dropObjectUsingRay()
to drop the object, using the target ray to determine the surface upon which the object should be placed. This also clears the value of
heldObject
so we know that there's no longer an object in hand.
xrSession.onsqueeze = event => {
if (event.inputSource.handedness == user.handedness) {
let targetRayPose = event.frame.getPose(event.inputSource.targetRaySpace, myRefSpace);
if (user.heldObject && targetRayPose) {
dropObjectUsingRay(user.heldObject, targetRayPose.transform.matrix):
}
}
};
See the examples in the
onsqueezestart
and
onsqueezeend
event handlers for the reset of the event handling related to this approach.
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebXR 设备 API
The definition of 'XRSession.onsqueeze' in that specification. |
工作草案 | 初始定义。 |
No compatibility data found. Please contribute data for "api.XRSession.onsqueeze" (depth: 1) to the MDN 兼容性数据存储库 .
onsqueeze*
handlers:
onsqueezestart
and
onsqueezeend
squeeze
,
squeezestart
,和
squeezeend
events
XRSession
Navigator.xr
WebGLRenderingContext.makeXRCompatible()
XR
XRBoundedReferenceSpace
XRFrame
XRInputSource
XRInputSourceArray
XRInputSourceEvent
XRInputSourcesChangeEvent
XRPose
XRReferenceSpace
XRReferenceSpaceEvent
XRRenderState
XRRigidTransform
XRSessionEvent
XRSpace
XRView
XRViewerPose
XRViewport
XRWebGLLayer