Environment
The Environment
component is used to configure the environment lighting and skybox for a scene. It provides a comprehensive way to set up atmospheric lighting, skyboxes, and environmental effects that affect the entire scene.
Overview
The Environment component combines several PlayCanvas scene and sky properties into a single, easy-to-use component:
- Skybox: Sets the background texture for the scene
- Environment Atlas: Provides Image-Based Lighting (IBL) for realistic environmental reflections
- Sky Settings: Controls sky dome properties, rotation, scale, and positioning
- Scene Settings: Manages exposure, luminance, and other global lighting parameters
Usage
The Environment component should be placed within an <Application>
component. Only one Environment component should be used per application instance.
Basic Usage
environment-basic.jsx
import { Environment } from '@playcanvas/react/components'
import { useAsset } from '@playcanvas/react/hooks'
const EnvironmentExample = () => {
const skyboxAsset = useAsset('/skybox.jpg')
const envAtlasAsset = useAsset('/env_atlas.png')
return (
<Application>
<Environment
skybox={skyboxAsset}
envAtlas={envAtlasAsset}
exposure={1.2}
/>
{/* Your scene entities here */}
</Application>
)
}
Advanced Configuration
environment-advanced.jsx
import { Environment } from '@playcanvas/react/components'
import { useAsset } from '@playcanvas/react/hooks'
const AdvancedEnvironmentExample = () => {
const skyboxAsset = useAsset('/skybox.jpg')
const envAtlasAsset = useAsset('/env_atlas.png')
return (
<Application>
<Environment
envAtlas={envAtlasAsset}
skybox={skyboxAsset}
// Environment lighting
exposure={1.1}
// Sky dome settings
scale={[200, 200, 200]}
position={[0, 50, 0]}
center={[0, 0.05, 0]}
rotation={[0, 45, 0]}
type="dome"
depthWrite={true}
/>
</Application>
)
}
Important Notes
- Single Instance: Only one
<Environment/>
component should be used per application instance. Multiple instances will cause warnings and only the first will be used. - Asset Requirements: The
skybox
andenvAtlas
props expect PlayCanvas Asset instances, typically loaded using theuseAsset
hook. - Automatic Cleanup: The component automatically restores default values when unmounted.
Props
The following props are based on PlayCanvas version 2.11.8. This documentation is automatically generated from the TypeScript types of the installed PlayCanvas package.
Last updated on