XRLightEstimate: primaryLightDirection 属性

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

实验性: 这是一项实验性技术
在生产中使用此技术之前,请仔细检查浏览器兼容性表格

安全上下文: 此功能仅在安全上下文(HTTPS)中可用,且支持此功能的浏览器数量有限。

XRLightEstimate 接口的只读 primaryLightDirection 属性返回一个 DOMPointReadOnly 对象,该对象表示来自 XRLightProbeprobeSpace 到主要光源的方向。

一个 DOMPointReadOnly 对象。如果用户环境中没有可估算的值,则该点为 { x: 0.0, y: 1.0, z: 0.0, w: 0.0 },表示有一束光从上方直射下来。

示例

XRFrame 循环中,您可以使用 primaryLightDirectionprimaryLightIntensity 属性来渲染阴影,例如,基于最突出的光源。

js
const lightProbe = await xrSession.requestLightProbe();

// frame loop
function onXRFrame(time, xrFrame) {
  let lightEstimate = xrFrame.getLightEstimate(lightProbe);

  // Render lights

  // Available properties
  lightEstimate.primaryLightDirection;
  lightEstimate.primaryLightIntensity;
}

规范

规范
WebXR 光照估算 API Level 1
# dom-xrlightestimate-primarylightdirection

浏览器兼容性

另见