XRHitTestResult: phương thức createAnchor()

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 createAnchor() của giao diện XRHitTestResult tạo một XRAnchor từ kết quả kiểm tra va chạm được gắn vào một đối tượng thực tế.

Cú pháp

js
createAnchor()

Tham số

Không có.

Giá trị trả về

Một Promise phân giải thành một đối tượng XRAnchor.

Ví dụ

Tạo một anchor từ kết quả kiểm tra va chạm

Ví dụ sau bắt đầu với một XRHitTestResult được truy xuất bằng cách gọi XRFrame.getHitTestResults(). Sau khi gọi createAnchor(), Promise phân giải thành một XRAnchor để đính kèm một đối tượng ảo vào vị trí đó.

js
hitTestResult.createAnchor().then(
  (anchor) => {
    // add anchored objects to the scene
  },
  (error) => {
    console.error(`Could not create anchor: ${error}`);
  },
);

Thông số kỹ thuật

Specification
WebXR Anchors Module
# dom-xrhittestresult-createanchor

Tương thích trình duyệt

Xem thêm