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
getOffsetReferenceSpace(). - The
transformof anXRView. - The
transformof anXRPose. - The
XRReferenceSpaceEventevent'stransformproperty, as found in theresetevent received by anXRReferenceSpace.
The advantage to using XRRigidTransform in these places rather than bare arrays that providing the matrix data is that the XRRigidTransform automatically does things like computing the inverse of the transform. Even better, once it's been computed, it's cached so that subsequent requests are significantly faster.
Constructor
new XRRigidTransform()- Creates a new
XRRigidTransformobject which represents a transform that applies a specified position and/or orientation.
Attributes
XRRigidTransform.positionRead only- A
DOMPointReadOnlyspecifying a 3-dimensional point, expressed in meters, describing the translation component of the transform. Thewattribute is always1.0. XRRigidTransform.orientationRead only- A
DOMPointReadOnlywhich contains a unit quaternion describing the rotational component of the transform. As a unit quaternion, its length is always normalized to1.0. XRRigidTransform.matrixRead only- 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.inverseRead only- Returns a
XRRigidTransformwhich 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 requestAnimationFrame() method.
xrSession.requestReferenceSpace(refSpaceType)
.then((refSpace) => {
xrReferenceSpace = refSpace;
xrReferenceSpace = xrReferenceSpace.getOffsetReferenceSpace(
new XRRigidTransform(viewerStartPosition, cubeOrientation));
animationFrameRequestID = xrSession.requestAnimationFrame(drawFrame);
Specifications
| Specification | Status | Comment |
|---|---|---|
| WebXR Device API The definition of 'XRRigidTransform' in that specification. |
Working Draft | Initial definition. |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
XRRigidTransform | Chrome Full support 79 | Edge Full support 79 | Firefox No support No | IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android Full support 79 | Firefox Android No support No | Opera Android No support No | Safari iOS No support No | Samsung Internet Android Full support 11.2 |
XRRigidTransform() constructor | Chrome Full support 79 | Edge Full support 79 | Firefox No support No | IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android Full support 79 | Firefox Android No support No | Opera Android No support No | Safari iOS No support No | Samsung Internet Android Full support 11.2 |
inverse | Chrome Full support 79 | Edge Full support 79 | Firefox No support No | IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android Full support 79 | Firefox Android No support No | Opera Android No support No | Safari iOS No support No | Samsung Internet Android Full support 11.2 |
matrix | Chrome Full support 79 | Edge Full support 79 | Firefox No support No | IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android Full support 79 | Firefox Android No support No | Opera Android No support No | Safari iOS No support No | Samsung Internet Android Full support 11.2 |
orientation | Chrome Full support 79 | Edge Full support 79 | Firefox No support No | IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android Full support 79 | Firefox Android No support No | Opera Android No support No | Safari iOS No support No | Samsung Internet Android Full support 11.2 |
position | Chrome Full support 79 | Edge Full support 79 | Firefox No support No | IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android Full support 79 | Firefox Android No support No | Opera Android No support No | Safari iOS No support No | Samsung Internet Android Full support 11.2 |
Legend
- Full support
- Full support
- No support
- No support
