XRLightEstimate
XRLightEstimate 介面是 WebXR 裝置 API 的一部分,它提供 XRLightProbe 在 XRFrame 所表示的時間點的估計光照值。
要獲取 XRLightEstimate 物件,請呼叫 XRFrame.getLightEstimate() 方法。
例項屬性
XRLightEstimate.primaryLightDirection只讀 實驗性-
一個
DOMPointReadOnly物件,表示來自XRLightProbe的probeSpace的主光源方向。 XRLightEstimate.primaryLightIntensity只讀 實驗性-
一個
DOMPointReadOnly物件(其x、y、z值對映到 RGB),表示來自XRLightProbe的probeSpace的主光源強度。 XRLightEstimate.sphericalHarmonicsCoefficients只讀 實驗性-
一個
Float32Array,包含 9 個球諧函式係數。
例項方法
無。
示例
獲取 XRLightProbe 物件
首先,使用 XRSession.requestLightProbe() 方法從會話中獲取一個光照探測器。然後,在 XRFrame 迴圈中,getLightEstimate() 方法將返回一個 XRLightEstimate 物件,其中包含每一幀的光照值。
js
const lightProbe = await xrSession.requestLightProbe();
// frame loop
function onXRFrame(time, xrFrame) {
let lightEstimate = xrFrame.getLightEstimate(lightProbe);
// Use light estimate data to light the scene
// Available properties
lightEstimate.sphericalHarmonicsCoefficients;
lightEstimate.primaryLightDirection;
lightEstimate.primaryLightIntensity;
}
規範
| 規範 |
|---|
| WebXR 光照估算 API Level 1 # xrlightestimate-interface |
瀏覽器相容性
載入中…