XRFrame: 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 XRFrame tạo một XRAnchor nổi tự do, được cố định tương đối với thế giới thực.

Xem XRHitTestResult.createAnchor() để tạo neo từ kết quả kiểm tra va chạm gắn liền với một đối tượng trong thế giới thực.

Cú pháp

js
createAnchor(pose, space)

Tham số

pose

Một đối tượng XRRigidTransform với tư thế ban đầu nơi neo sẽ được tạo. Hệ thống sẽ đảm bảo rằng mối quan hệ với thế giới vật lý được thiết lập tại thời điểm này được duy trì khi hệ thống theo dõi cập nhật hiểu biết về thế giới.

space

Một đối tượng XRSpace mà tư thế tương đối với nó.

Giá trị trả về

Một Promise được giải quyết thành một đối tượng XRAnchor.

Ví dụ

Tạo neo

js
frame.createAnchor(anchorPose, referenceSpace).then(
  (anchor) => {
    // Do stuff with the anchor (assign objects that will be relative to this anchor)
  },
  (error) => {
    console.error(`Could not create anchor: ${error}`);
  },
);

Thông số kỹ thuật

Specification
WebXR Anchors Module
# dom-xrframe-createanchor

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

Xem thêm