安全上下文
此特征只可用于
安全上下文
(HTTPS),在某些或所有
支持浏览器
.
只读
XRInputSource
property
targetRayMode
indicates the method by which the target ray for the input source should be generated and how it should be presented to the user.
let rayMode = xrInputSource.targetRayMode;
A
DOMString
taken from the
XRTargetRayMode
enumerated type, indicating which method to use when generating and presenting the target ray to the user. The possible values are:
gaze
screen
The direction of the target ray is indicated using a tap on a touch screen, mouse, or other tactile input device.
tracked-pointer
Targeting is being performed using a handheld device or hand-tracking system which the user points in the direction of the target. The target ray extends from the hand (or the object in the hand) in the targeted direction. The direction is determined using platform-specific rules, though if no such rules exist, the direction is chosen by assuming the user is pointing their index finger straight out from their hand.
The input source's
targetRaySpace
indicates the position and orientation of the target ray, and can be used to determine where to render the ray.
This fragment of code shows part of a function to be called once every frame. It looks for inputs which have a non-
NULL
targetRaySpace
. Inputs which have a value for this property represent inputs that project a target ray outward from the user.
For each such input, this example looks for inputs whose
targetRayMode
is
tracked-pointer
, indicating that the input is in fact intended to represent a targeting device rather than a gazing device, screen tap, or mouse click. For tracked pointers, a function
myRenderTargetRayAsBeam()
is called to render a beam from the input controller's virtual position outward in the direction it's pointing.
The code should continue to perform tasks such as drawing controllers or any objects representative of the user's hands' positions in the virtual space, as well as any other input-related tasks.
function updateInputSources(session, frame, refSpace) {
for (let source of session.getInputSources()) {
let targetRayPose = frame.getPose(inputSource.targetRaySpace, refSpace);
if (targetRayPose) {
if (source.targetRayMode == "tracked-pointer") {
myRenderTargetRayAsBeam(targetRayPose);
}
}
/* ... */
}
}
See the article Inputs and input sources for more details and a more complete example.
| 规范 | 状态 | 注释 |
|---|---|---|
|
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