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

瀏覽器相容性