EnvironmentSyncSystem
Applies the scene-level Environment component to the THREE.js scene: background color, gradient textures, image skyboxes, fog, and the optional lighting block (HDRI environment map, tone mapping, exposure).
Overview
EnvironmentSyncSystem runs every frame and is responsible for:
- Generating canvas-based gradient textures (
linear,radial,angular) from the color stops defined in theEnvironmentcomponent and setting them asscene.background. - Loading image skyboxes: a flat screen backdrop through
THREE.TextureLoaderby default, or a 360° panorama whenskybox.imageProjectionis"equirect"(.hdrand.exrsupported). - Loading
lighting.envMapUrl(HDRLoaderfor.hdr,EXRLoaderfor.exr,TextureLoaderotherwise), pre-filtering it withPMREMGeneratoron WebGL (on WebGPU the equirect texture is assigned as is andWebGPURendererpre-filters it) and assigningscene.environment,scene.environmentIntensityandscene.environmentRotation. Withlighting.useAsBackgroundit also becomesscene.backgroundwith the authored blur, intensity and rotation. - Setting
renderer.toneMappingandrenderer.toneMappingExposurefromlighting.toneMapping/lighting.exposure, combined with the post-processing tone-mapping effect as described on the Environment page. - Applying solid color backgrounds directly as
THREE.Color. - Configuring
THREE.FogExp2orTHREE.Fogfrom the fog sub-state (near,far,density,color). - Disposing previous textures when the background changes to prevent GPU memory leaks.
Queried components
| Component | Access |
|---|---|
Environment | Read (background type, colors, fog state) |
Behavior notes
- Signature-based change detection: the system keeps one signature each for the skybox, fog and lighting. A part is re-applied only when its own signature changes, so animating
lighting.envIntensitynever rebuilds the skybox texture. - Lighting is opt-in: without a
lightingblock the system never writesscene.environmentor the renderer's tone mapping. Removing the block, or disposing the system, restores the values they had before. - Async env maps: a newer
envMapUrlalways wins over a load still in flight, and the previous PMREM target and source texture are disposed when the new map swaps in. - Passthrough: while
world.isXrPassthrough()is true the background staysnullso the real room shows. Fog and image-based lighting keep applying. - Gradient texture: generated on a 512×512
<canvas>element. In server-side or non-DOM environments a single-pixelDataTexturefallback is used instead. - Fog clamping: fog
nearandfarvalues are clamped sofar > near + 0.001and density is clamped to≥ 0. Invalid values are replaced with safe defaults. - Pending image URL: image/HDRI loads are queued via an internal pending URL field; a stale load result is discarded if the component signature changed again before the load finished.
API reference
- Class:
Environment - Source:
core/systems/EnvironmentSyncSystem.ts

