XRFrame: phương thức getHitTestResults()
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Phương thức getHitTestResults() của giao diện XRFrame trả về một mảng các đối tượng XRHitTestResult chứa kết quả kiểm tra va chạm cho một XRHitTestSource cho trước.
Cú pháp
getHitTestResults(hitTestSource)
Tham số
hitTestSource-
Một đối tượng
XRHitTestSourcechứa các đăng ký kiểm tra va chạm.
Giá trị trả về
Một mảng các đối tượng XRHitTestResult.
Ví dụ
>Lấy kết quả kiểm tra va chạm
Để yêu cầu nguồn kiểm tra va chạm, hãy bắt đầu một XRSession với tính năng phiên hit-test được bật. Tiếp theo, yêu cầu nguồn kiểm tra va chạm bằng XRSession.requestHitTestSource() và lưu lại để sử dụng trong vòng lặp khung. Cuối cùng, gọi getHitTestResults() để lấy kết quả.
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;
});
// frame loop
function onXRFrame(time, xrFrame) {
let hitTestResults = xrFrame.getHitTestResults(hitTestSource);
// do things with the hit test results
}
Thông số kỹ thuật
| Specification |
|---|
| WebXR Hit Test Module> # dom-xrframe-gethittestresults> |