[page:Group] →

XR估计光照([name])

[name] 使用 WebXR 的光照估计来创建光探针、定向光和(可选)模拟用户真实世界环境和照明的环境图。
当 WebXR 更新光照和环境估计时,[name] 会自动更新光照探针、定向光和环境贴图。

在创建 WebXR 会话时,将光照估计指定为可选或必需的功能非常重要,否则光照估计将无法工作。

有关浏览器兼容性信息,请参阅 此处,因为这仍然是 WebXR 中的一个实验功能。

要使用它,就像 /examples 目录中的所有文件一样,您必须在HTML中单独包含该文件。

导入

[name] 是一个附加组件,必须显式导入。请参阅 [link:#manual/introduction/Installation Installation / Addons]。

import { XREstimatedLight } from 'three/addons/webxr/XREstimatedLight.js';

代码示例

renderer.xr.enabled = true; // Don't add the XREstimatedLight to the scene initially. // It doesn't have any estimated lighting values until an AR session starts. const xrLight = new XREstimatedLight( renderer ); xrLight.addEventListener( 'estimationstart' , () => { scene.add( xrLight ); if ( xrLight.environment ) { scene.environment = xrLight.environment; } } ); xrLight.addEventListener( 'estimationend', () => { scene.remove( xrLight ); scene.environment = null; } ); // In order for lighting estimation to work, 'light-estimation' must be included as either // an optional or required feature. document.body.appendChild( XRButton.createButton( renderer, { optionalFeatures: [ 'light-estimation' ] } ) );

例子

[example:webxr_ar_lighting webxr / light estimation]

构造函数

[name]( [param:WebGLRenderer renderer], [param:Boolean environmentEstimation] )

[page:WebGLRenderer renderer]: (必需)用于渲染场景的渲染器。主要用于与 WebXRManager 交互。

environmentEstimation: 如果 `true`,则使用 WebXR 来估计环境地图。

事件

estimationstart

当估计的照明值开始更新时触发。

estimationend

当估计的照明值停止更新时触发。

Properties

[property:Texture environment]

WebXR 估计的环境地图。仅当 environmentEstimation 为 时,此选项才可用 `true`。

它可以用作 [page:Scene.environment] 的 [page:MeshStandardMaterial.envMap] 或 [page:Scene.background]。

源代码

[link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/webxr/XREstimatedLight.js examples/jsm/webxr/XREstimatedLight.js]