XRLightEstimate

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

安全上下文: 此功能僅在安全上下文(HTTPS)中可用,且支援此功能的瀏覽器數量有限。

實驗性: 這是一項實驗性技術
在生產中使用此技術之前,請仔細檢查瀏覽器相容性表格

XRLightEstimate 介面是 WebXR 裝置 API 的一部分,它提供 XRLightProbeXRFrame 所表示的時間點的估計光照值。

要獲取 XRLightEstimate 物件,請呼叫 XRFrame.getLightEstimate() 方法。

例項屬性

XRLightEstimate.primaryLightDirection 只讀 實驗性

一個 DOMPointReadOnly 物件,表示來自 XRLightProbeprobeSpace 的主光源方向。

XRLightEstimate.primaryLightIntensity 只讀 實驗性

一個 DOMPointReadOnly 物件(其 xyz 值對映到 RGB),表示來自 XRLightProbeprobeSpace 的主光源強度。

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

瀏覽器相容性

另見