安全上下文
此特征只可用于
安全上下文
(HTTPS),在某些或所有
支持浏览器
.
只读
XRInputSource
property
handedness
indicates which of the user's hands the WebXR input source is associated with, or if it's not associated with a hand at all.
let hand = xrInputSource.handedness;
A
DOMString
indicating whether the input controller is held in one of the user's hands, and if it is, which hand. The value, which comes from the
XRHandedness
enumerated type, is one of the following:
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.
If the input source is not a device associated with a user's hand (whether by being held, attached, or worn), the value of
handedness
is
none
. This may indicate, for example, an input source which isn't hand-held, such as controls built into a headset or an input device attached to the head or body.
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.
若
gripSpace
为非
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.
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebXR 设备 API
The definition of 'XRInputSource.handedness' in that specification. |
工作草案 | 初始定义。 |
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.
更新 GitHub 上的兼容性数据| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
handedness
|
Chrome 79 | Edge 79 | Firefox No | IE No | Opera No | Safari No | WebView Android No | Chrome Android 79 | Firefox Android No | Opera Android No | Safari iOS No | Samsung Internet Android 11.2 |
完整支持
不支持
XRInputSource
gripSpace
handedness
profiles
targetRayMode
targetRaySpace