XRFrame: getDepthInformation() Methode

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimentell: Dies ist eine experimentelle Technologie
Überprüfen Sie die Browser-Kompatibilitätstabelle sorgfältig vor der Verwendung auf produktiven Webseiten.

Sicherer Kontext: Diese Funktion ist nur in sicheren Kontexten (HTTPS) in einigen oder allen unterstützenden Browsern verfügbar.

Die getDepthInformation() Methode der XRFrame Schnittstelle liefert ein XRCPUDepthInformation Objekt, das CPU-Tiefeninformationen für den aktiven und animierten Frame enthält.

Syntax

js
getDepthInformation(view)

Parameter

view

Ein XRView Objekt, das von einer Betrachterpose erhalten wird.

Rückgabewert

Ausnahmen

NotSupportedError DOMException

Wird ausgelöst, wenn "depth-sensing" nicht in der Liste der aktivierten Funktionen für diese XRSession enthalten ist.

InvalidStateError DOMException

Wird ausgelöst, wenn:

  • das XRFrame weder aktiv noch animiert ist. Das Abrufen von Tiefeninformationen ist nur innerhalb des requestAnimationFrame() Rückrufs gültig.
  • die depthUsage der Sitzung nicht auf "cpu-optimized" gesetzt ist.

Beispiele

Abrufen von CPU-Tiefeninformationen

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);
      }
    }
  }
}

Spezifikationen

Specification
WebXR Depth Sensing Module
# dom-xrframe-getdepthinformation

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
getDepthInformation
Experimental

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.