W3cubDocs

/Web APIs

XRDepthInformation: rawValueToMeters property

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The read-only rawValueToMeters property of the XRDepthInformation interface contains the scale factor by which the raw depth values must be multiplied in order to get the depths in meters.

For CPU depth information, see also the XRCPUDepthInformation.getDepthInMeters() method.

Value

A number.

Examples

Use XRFrame.getDepthInformation() (CPU) or XRWebGLBinding.getDepthInformation() (WebGL) to obtain depth information. The returned objects will contain the rawValueToMeters scale factor, which can be used for further calculations.

For CPU depth information and a buffer that has "luminance-alpha" format:

js

const uint16 = new Uint16Array(depthInfo.data);
const index = column + row * depthInfo.width;
const depthInMeters = uint16[index] * depthInfo.rawValueToMeters;

(Use Float32Array for a "float32" data format.)

Note that the depth in meters is in depth-buffer coordinates. Additional steps are needed to convert them to normalized view coordinates, or the XRCPUDepthInformation.getDepthInMeters() method can be used.

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
rawValueToMeters 90 90 No No 76 No No 90 No 64 No 15.0

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/XRDepthInformation/rawValueToMeters