安全上下文
此特征只可用于 安全上下文 (HTTPS),在某些或所有 支持浏览器 .

只读 XRInputSource property gripSpace 返回 XRSpace whose native origin tracks the pose used to render virtual objects so they appear to be held in (or part of) the user's hand. For example, if a user were holding a virtual straight rod, the native origin of this XRSpace would be located at the approximate center of mass of the user's fist.

句法

var xrSpace = xrInputSource.gripSpace;
					

XRSpace object representing the position and orientation of the input device in virtual space, suitable for rendering an image of the device into the scene. gripSpace is null if the input source is inherently untrackable. For example, only inputs whose targetRayMode is tracked-pointer provide a gripSpace .

Imagine that the controller is shaped like a straight rod, held in the user's fist. The native origin of the grip space is located at the centroid—the center of mass—of the user's fist, tracking the position of the user's hand.

The coordinate system for the left hand's grip space.
A diagram showing how the grip space indicates the local coordinate system for the player's hand relative to the world.
The coordinate system for the right hand's grip space.
A diagram showing how the grip space indicates the local coordinate system for the player's hand relative to the world.

As shown in the diagram above, the coordinate system is oriented as follows:

范例

In tis example, taken from the frame rendering callback, the gripSpace is used to render a mesh that represents the position and orieintation of the controller in the virtual environment.

for (let source in xrSession.inputSources) {
  if (source.gripSpace) {
    let gripPose = frame.getPose(source.gripSpace, xrRefSpace);
    if (gripPose) {
      myDrawMeshUsingTransform(controllerMesh, gripPose.transform.matrix);
    }
  }
}
				

For each input source which has a value for gripSpace , this loop obtains the XRPose representing the position and orientation that are described by gripSpace . If a valid pose is returned, a method myDrawMeshUsingTransform() is called to  draw the controller's mesh transformed using the grip pose's transform matrix.

规范

规范 状态 注释
WebXR 设备 API
The definition of 'XRInputSource.gripSpace' 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 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
gripSpace 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

图例

完整支持

完整支持

不支持

不支持

元数据

  • 最后修改:
  1. XRInputSource
  2. 特性
    1. gripSpace
    2. handedness
    3. profiles
    4. targetRayMode
    5. targetRaySpace