XRDepthInformation: rawValueToMeters 属性
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 |
浏览器兼容性
加载中…