XRDepthInformation: rawValueToMeters property

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.

Thuộc tính chỉ đọc rawValueToMeters của giao diện XRDepthInformation chứa hệ số tỷ lệ mà các giá trị độ sâu thô phải được nhân để có được độ sâu tính bằng mét.

Đối với thông tin độ sâu CPU, xem thêm phương thức XRCPUDepthInformation.getDepthInMeters().

Giá trị

Một số.

Ví dụ

Sử dụng XRFrame.getDepthInformation() (CPU) hoặc XRWebGLBinding.getDepthInformation() (WebGL) để lấy thông tin độ sâu. Các đối tượng được trả về sẽ chứa hệ số tỷ lệ rawValueToMeters, có thể được sử dụng để tính toán thêm.

Đối với thông tin độ sâu CPU và bộ đệm có định dạng "luminance-alpha":

js
const uint16 = new Uint16Array(depthInfo.data);
const index = column + row * depthInfo.width;
const depthInMeters = uint16[index] * depthInfo.rawValueToMeters;

(Sử dụng Float32Array cho định dạng dữ liệu "float32".)

Lưu ý rằng độ sâu tính bằng mét là trong tọa độ bộ đệm độ sâu. Cần thêm các bước để chuyển đổi sang tọa độ khung nhìn chuẩn hóa, hoặc có thể sử dụng phương thức XRCPUDepthInformation.getDepthInMeters().

Thông số kỹ thuật

Specification
WebXR Depth Sensing Module
# dom-xrdepthinformation-rawvaluetometers

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