XRRay
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
The XRRay interface of the WebXR Device API is a geometric ray described by an origin point and a direction vector.
XRRay objects can be passed to XRSession.requestHitTestSource() or XRSession.requestHitTestSourceForTransientInput() to perform hit testing.
Constructor
XRRay()-
Creates a new
XRRayobject.
Properties
-
XRRay.directionRead only -
A
DOMPointReadOnlyrepresenting the ray's 3-dimensional directional vector. -
XRRay.matrixRead only -
A transform that can be used to position objects along the
XRRay. This is a 4 by 4 matrix given as a 16 elementFloat32Arrayin column major order. -
XRRay.originRead only -
A
DOMPointReadOnlyrepresenting the 3-dimensional point in space that the ray originates from, in meters.
Methods
None.
Examples
Using XRRay to request a hit test source
The XRSession.requestHitTestSource() method takes an XRRay object for its offsetRay option. In this example, the hit test source is positioned slightly above the viewer as the application has some UI elements at the bottom while wanting to maintain the perception of a centered cursor.
const xrSession = navigator.xr.requestSession("immersive-ar", { requiredFeatures: ["local", "hit-test"] }); let hitTestSource = null; xrSession.requestHitTestSource({ space: viewerSpace, // obtained from xrSession.requestReferenceSpace("viewer"); offsetRay: new XRRay({y: 0.5}) }).then((viewerHitTestSource) => { hitTestSource = viewerHitTestSource; });
Specifications
| Specification |
|---|
| WebXR Hit Test Module (WebXR Hit Test) # xrray-interface |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
XRRay |
81 |
81 |
No |
No |
No |
No |
No |
81 |
No |
No |
No |
13.0 |
XRRay |
81 |
81 |
No |
No |
No |
No |
No |
81 |
No |
No |
No |
13.0 |
direction |
81 |
81 |
No |
No |
No |
No |
No |
81 |
No |
No |
No |
13.0 |
matrix |
81 |
81 |
No |
No |
No |
No |
No |
81 |
No |
No |
No |
13.0 |
origin |
81 |
81 |
No |
No |
No |
No |
No |
81 |
No |
No |
No |
13.0 |
See also
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/XRRay