The getDepthInformation()
method of the XRFrame
interface returns an XRCPUDepthInformation
object containing CPU depth information for the active and animated frame.
getDepthInformation(view)
const session = navigator.xr.requestSession("immersive-ar", {
requiredFeatures: ["depth-sensing"],
depthSensing: {
usagePreference: ["cpu-optimized", "gpu-optimized"],
formatPreference: ["luminance-alpha", "float32"],
},
});
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) {
renderDepth(depthInformation);
}
}
}
}