Skip to content

Environment

Loading... 0 %
🍰

Is a component abstraction that automatically sets up a global cubemap, which affects the default scene.environment, and optionally scene.background.

It uses the composable useEnvironment under the hood to load the cubemap.

Usage

vue
<Suspense>
  <Environment
    :files="[
      '/px.jpg',
      '/nx.jpg',
      '/py.jpg',
      '/ny.jpg',
      '/pz.jpg',
      '/nz.jpg'
    ]"
  />
</Suspense>

You can also pass the .hdr file directly:

vue
<Suspense>
   <Environment files="/sunset.hdr" />
</Suspense>

Environment

Texture reference

You can access the model reference by passing a ref to the <Environment /> prop and then using the method getTexture() to get the object.

vue
<script setup lang="ts">
import { Environment } from '@tresjs/cientos'

const environmentRef = shallowRef()

watch(environmentRef, texture => {
  console.log(texture)
})
</script>

<template>
  <Environment ref="environmentRef" />
  <TresMesh>
    <TresSphereGeometry />
    <TresMeshStandardMaterial :env-map="envMap" />
  </TresMesh>
</template>

Presets

You can use one of the available presets by passing the preset prop:

html
<Environment preset="city" />
Loading... 86 %
🍰

Lightformer

You can incorporate Lightformer into the environment just like a slot.

html
<script setup>
  import { Environment, Lightformer } from '@tresjs/cientos'
</script>

<template>
  <Environment>
    <Lightformer :intensity="0.75" :position="[0, 5, -9]" />
    <Lightformer from="ring" :rotation-y="-Math.PI / 2" :scale="[10, 10, 1]" />
  </Environment>
</template>

Environment Rotation

The environment component supports both background and environment rotation. You can control them independently or sync them together:

vue
<template>
  <Environment
    preset="sunset"
    :background="true"
    :background-rotation="[0, Math.PI / 2, 0]"
    :environment-rotation="[0, Math.PI / 4, 0]"
  />
</template>

Syncing Rotations

You can sync the environment rotation with the background rotation using the syncMaterials prop:

vue
<template>
  <Environment
    preset="sunset"
    :background="true"
    :sync-materials="true"
    :background-rotation="[0, Math.PI / 2, 0]"
  />
</template>

When syncMaterials is enabled:

  • The environment rotation will automatically match the background rotation
  • All materials in the scene will update to reflect the new rotation
  • This ensures visual consistency between the background and environment reflections

Props

PropDescriptionDefault
filesArray of 6 urls to images, one for each side of the CubeTexture, or an HDR fileundefined
pathPath to the environment map filesundefined
encodingEncoding of the environment mapSRGBColorSpace for array files, LinearEncoding for single texture
backgroundIf true, the environment map will be used as the scene backgroundfalse
blurBlur factor between 0 and 1 (only works with three 0.146 and up)0
presetPreset environment mapundefined
resolutionThe resolution of the WebGLCubeRenderTarget256
nearThe near of the CubeCamera1
farThe far of the CubeCamera1000
framesThe frames of the cubeCamera.updateInfinity
backgroundIntensityIntensity of the background1
environmentIntensityIntensity of the environment1
backgroundRotationRotation of the background (in radians)[0, 0, 0]
environmentRotationRotation of the environment (in radians)[0, 0, 0]
syncMaterialsIf true, environment rotation will sync with background rotationfalse

Props for Lightformer

Lightformer inherits from mesh, and its extension parameters include:

PropDescriptionDefault
from'circle', 'ring', 'rect', or any other Mesh typerect
intensityThe intensity of the light1
colorThe color of the light0xffffff
argsThe arguments of the GeometryWhen using other geometries, set the corresponding arguments