大网数据广告活动
Web 标准与前端开发

XRRigidTransform

· 52CE 我爱测

The **`XRRigidTransform`** is a WebXR API interface that represents the 3D geometric transform described by a position and orientation.

WebXR Device API

The XRRigidTransform is a WebXR API interface that represents the 3D geometric transform described by a position and orientation.

XRRigidTransform is used to specify transforms throughout the WebXR APIs, including:

  • The offset and orientation relative to the parent reference space to use when creating a new reference space with XRReferenceSpace.getOffsetReferenceSpace.
  • The XRView.transform of an XRView.
  • The XRPose.transform of an XRPose.
  • The XRReferenceSpaceEvent event's XRReferenceSpaceEvent.transform property, as found in the XRReferenceSpace.reset_event event received by an XRReferenceSpace.

Using XRRigidTransform in these places rather than bare arrays that provide the matrix data has an advantage. It automatically computes the inverse of the transform and even caches it making subsequent requests significantly faster.

Constructor

  • XRRigidTransform.XRRigidTransform
    • : Creates a new XRRigidTransform object which represents a transform that applies a specified position and/or orientation.

Instance properties

  • XRRigidTransform.position
    • : A DOMPointReadOnly specifying a 3-dimensional point, expressed in meters, describing the translation component of the transform. The DOMPointReadonly.w property is always 1.0.
  • XRRigidTransform.orientation
    • : A DOMPointReadOnly which contains a unit quaternion describing the rotational component of the transform. As a unit quaternion, its length is always normalized to 1.0.
  • XRRigidTransform.matrix
    • : Returns the transform matrix in the form of a 16-member Float32Array. See the section Matrix format for how the array is used to represent a matrix.
  • XRRigidTransform.inverse
    • : Returns a XRRigidTransform which is the inverse of this transform. That is, if applied to an object that had been previously transformed by the original transform, it will undo the transform and return the original object.

Usage notes

When an XRRigidTransform is interpreted, the orientation is always applied to the affected object before the position is applied.

Example

This code snippet creates an XRRigidTransform to specify the offset and orientation in relation to the current reference space to use when creating a new reference space. It then requests the first animation frame callback by calling the session's XRSession.requestAnimationFrame method.

xrSession.requestReferenceSpace(refSpaceType).then((refSpace) => {
  xrReferenceSpace = refSpace;
  xrReferenceSpace = xrReferenceSpace.getOffsetReferenceSpace(
    new XRRigidTransform(viewerStartPosition, cubeOrientation),
  );
  animationFrameRequestID = xrSession.requestAnimationFrame(drawFrame);
});

Specifications

Browser compatibility

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。