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().
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.
function onXRFrame(time, xrFrame) {
let hitTestResults = xrFrame.getHitTestResultsForTransientInput(
transientHitTestSource,
);
hitTestResults.forEach((resultsPerInputSource) => {
resultsPerInputSource.results.forEach((hitTest) => {
hitTest.getPose(referenceSpace);
});
});
}
The inputSource property allows you to filter hit test results by input source.
function onXRFrame(time, xrFrame) {
let hitTestResults = xrFrame.getHitTestResultsForTransientInput(
transientHitTestSource,
);
hitTestResults.forEach((resultsPerInputSource) => {
if (resultsPerInputSource.inputSource === myPreferredInputSource) {
}
});
}