XRSession: thuộc tính depthUsage

Khả dụng hạn chế

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 depthUsage của một XRSession immersive-ar mô tả cách sử dụng cảm biến độ sâu nào được dùng.

Giá trị

Thuộc tính này có thể trả về các giá trị sau:

cpu-optimized

Dữ liệu độ sâu được thiết kế để sử dụng trên CPU; xem giao diện XRCPUDepthInformation.

gpu-optimized

Dữ liệu độ sâu được thiết kế để sử dụng trên GPU; xem giao diện XRWebGLDepthInformation.

Ví dụ

Để yêu cầu phương thức sử dụng mong muốn, bạn cần chỉ định usagePreference khi yêu cầu một phiên bằng XRSystem.requestSession(). Ở đây, người gọi có thể xử lý cả cách sử dụng tối ưu CPU và GPU. Thứ tự thể hiện ưu tiên cho CPU:

js
navigator.xr.requestSession("immersive-ar", {
  requiredFeatures: ["depth-sensing"],
  depthSensing: {
    usagePreference: ["cpu-optimized", "gpu-optimized"],
    formatPreference: ["luminance-alpha", "float32"],
  },
});

Để kiểm tra cách sử dụng nào đã được chọn bởi tác nhân người dùng, bạn có thể gọi thuộc tính depthUsage:

js
console.log(session.depthUsage); // either "cpu-optimized" or "gpu-optimized"

Thông số kỹ thuật

Thông số kỹ thuật
WebXR Depth Sensing Module
# dom-xrsession-depthusage

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