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 |
瀏覽器相容性
載入中…