XRFrame: phương thức getDepthInformation()
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.
Phương thức getDepthInformation() của giao diện XRFrame trả về một đối tượng XRCPUDepthInformation chứa thông tin độ sâu CPU cho khung đang hoạt động và đang được hoạt họa.
Cú pháp
js
getDepthInformation(view)
Tham số
Giá trị trả về
Một đối tượng XRCPUDepthInformation.
Ngoại lệ
NotSupportedErrorDOMException-
Được ném nếu
"depth-sensing"không có trong danh sách tính năng được bật choXRSessionnày. InvalidStateErrorDOMException-
Được ném nếu:
XRFramekhông đang hoạt động hoặc không đang được hoạt họa. Việc lấy thông tin độ sâu chỉ hợp lệ trong callback củarequestAnimationFrame().depthUsagecủa phiên không phải là"cpu-optimized".
Ví dụ
>Lấy thông tin độ sâu CPU
js
// Make sure to request a session with depth-sensing enabled
const session = navigator.xr.requestSession("immersive-ar", {
requiredFeatures: ["depth-sensing"],
depthSensing: {
usagePreference: ["cpu-optimized", "gpu-optimized"],
formatPreference: ["luminance-alpha", "float32"],
},
});
// …
// Obtain depth information in an active and animated frame
function rafCallback(time, frame) {
session.requestAnimationFrame(rafCallback);
const pose = frame.getViewerPose(referenceSpace);
if (pose) {
for (const view of pose.views) {
const depthInformation = frame.getDepthInformation(view);
if (depthInformation) {
// Do something with the depth information
renderDepth(depthInformation);
}
}
}
}
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| WebXR Depth Sensing Module> # dom-xrframe-getdepthinformation> |