XRWebGLBinding: 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.

Die getDepthInformation() Methode des XRWebGLBinding Interfaces gibt ein XRWebGLDepthInformation Objekt zurück, das WebGL-Tiefeninformationen enthält.

Syntax

js
getDepthInformation(view)

Parameter

view

Ein XRView Objekt, das aus einer Betrachterpose erhalten wurde.

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 nicht aktiv oder animiert ist. Das Abrufen von Tiefeninformationen ist nur innerhalb des requestAnimationFrame() Rückrufs gültig.

InvalidStateError DOMException

Wird ausgelöst, wenn die depthUsage der Sitzung nicht "gpu-optimized" ist.

Beispiele

Abrufen von WebGL-Tiefeninformationen

js
const canvasElement = document.querySelector(".output-canvas");
const gl = canvasElement.getContext("webgl");
await gl.makeXRCompatible();

// Make sure to request a session with depth-sensing enabled
const session = navigator.xr.requestSession("immersive-ar", {
  requiredFeatures: ["depth-sensing"],
  depthSensing: {
    usagePreference: ["gpu-optimized"],
    formatPreference: ["luminance-alpha"],
  },
});

const glBinding = new XRWebGLBinding(session, gl);

// …

// 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 = glBinding.getDepthInformation(view);
      if (depthInformation) {
        // Do something with the depth information
        // gl.bindTexture(gl.TEXTURE_2D, depthInformation.texture);
        // …
      }
    }
  }
}

Spezifikationen

Specification
WebXR Depth Sensing Module
# dom-xrwebglbinding-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.

Siehe auch