XRDepthInformation: rawValueToMeters 属性

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

实验性: 这是一项实验性技术
在生产中使用此技术之前,请仔细检查浏览器兼容性表格

安全上下文: 此功能仅在安全上下文(HTTPS)中可用,且支持此功能的浏览器数量有限。

XRDepthInformation 接口的只读 rawValueToMeters 属性包含一个比例因子,原始深度值必须乘以该因子才能获得以米为单位的深度。

对于 CPU 深度信息,另请参阅 XRCPUDepthInformation.getDepthInMeters() 方法。

一个数字。

示例

使用 XRFrame.getDepthInformation() (CPU) 或 XRWebGLBinding.getDepthInformation() (WebGL) 来获取深度信息。返回的对象将包含 rawValueToMeters 比例因子,可用于进一步计算。

对于 CPU 深度信息以及具有“亮度-Alpha”格式的缓冲区

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

(对于“float32”数据格式,请使用 Float32Array 。)

请注意,以米为单位的深度是以深度缓冲区坐标表示的。需要额外的步骤才能将其转换为标准化的视图坐标,或者可以使用 XRCPUDepthInformation.getDepthInMeters() 方法。

规范

规范
WebXR Depth Sensing 模块
# dom-xrdepthinformation-rawvaluetometers

浏览器兼容性