The getHitTestResults()
method of the XRFrame
interface returns an array of XRHitTestResult
objects containing hit test results for a given XRHitTestSource
.
getHitTestResults(hitTestSource)
An array of XRHitTestResult
objects.
To request a hit test source, start an XRSession
with the hit-test
session feature enabled. Next, request a the hit test source with XRSession.requestHitTestSource()
and store it for later use in the frame loop. Finally, call getHitTestResults()
to obtain the result.
const xrSession = navigator.xr.requestSession("immersive-ar", {
requiredFeatures: ["local", "hit-test"],
});
let hitTestSource = null;
xrSession
.requestHitTestSource({
space: viewerSpace,
offsetRay: new XRRay({ y: 0.5 }),
})
.then((viewerHitTestSource) => {
hitTestSource = viewerHitTestSource;
});
function onXRFrame(time, xrFrame) {
let hitTestResults = xrFrame.getHitTestResults(hitTestSource);
}