XRTransientInputHitTestResult
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
The XRTransientInputHitTestResult
interface of the WebXR Device API contains an array of results of a hit test for transient input, grouped by input source.
You can get an array of XRHitTestResult
objects for a frame by calling XRFrame.getHitTestResultsForTransientInput()
.
Properties
-
XRTransientInputHitTestResult.inputSource
Read only -
Represents the
XRInputSource
that was used to compute theresults
array. -
XRTransientInputHitTestResult.results
Read only -
Represents an array of
XRHitTestResult
objects containing the hit test results for the input source, ordered by the distance along the ray used to perform the hit test, with the closest result at position 0.
Methods
None.
Examples
Accessing transient input hit test results
Two arrays are used to access transient input hit test results. First, you get an array of XRTransientInputHitTestResult
objects by calling XRFrame.getHitTestResultsForTransientInput()
. Second, to get to the actual XRHitTestResult
objects for an input source, you dereference the results
property on one of the XRTransientInputHitTestResult
objects.
// frame loop function onXRFrame(time, xrFrame) { let hitTestResults = xrFrame.getHitTestResultsForTransientInput(transientHitTestSource); hitTestResults.forEach(resultsPerInputSource => { resultsPerInputSource.results.forEach(hitTest => { // do something with the hit test hitTest.getPose(referenceSpace); }); }); }
Filtering input sources
The inputSource
property allows you to filter hit test results by input source.
// frame loop function onXRFrame(time, xrFrame) { let hitTestResults = xrFrame.getHitTestResultsForTransientInput(transientHitTestSource); hitTestResults.forEach(resultsPerInputSource => { if (resultsPerInputSource.inputSource == myPreferredInputSource) { // act on hit test results from the preferred input source } } }
Specifications
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 | |
XRTransientInputHitTestResult |
81 |
81 |
No |
No |
No |
No |
No |
81 |
No |
No |
No |
13.0 |
inputSource |
81 |
81 |
No |
No |
No |
No |
No |
81 |
No |
No |
No |
13.0 |
results |
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/XRTransientInputHitTestResult