Skip to content

Commit 637d196

Browse files
authored
New <Environment/> Component (#195)
* Deprecates EnvAtlas component and introduce Environment component - Marked the EnvAtlas component as deprecated, advising users to use the new Environment component instead. - Added a new Environment component to manage environment lighting and skybox settings, including validation and warnings for multiple instances. - Updated documentation to reflect the changes and provide usage examples for the new Environment component. * Introduce new <Environment/> component and deprecate EnvAtlas - Added a new <Environment/> component for managing environment lighting. - Marked the EnvAtlas component as deprecated, advising users to transition to the new component. * Enhance Environment component and update dependencies - Added new features to the Environment component, including support for scale, rotation, and position properties. - Integrated dedent for improved string formatting in warnings. - Updated package dependencies to include dedent version 1.6.0. - Added new example link for the Environment component in documentation. * Update PostEffects and ShadowCatcher components; enhance environment example - Adjusted contrast setting in PostEffects for improved visual output. - Reduced vsmBlurSize in ShadowCatcher for better shadow clarity. - Modified environment example to include new properties for Environment component, enhancing lighting and camera settings. - Added a red light entity to the primitives example for improved visual effects. * Docs and better deps * Added docs and deprecation warning
1 parent c373646 commit 637d196

File tree

15 files changed

+463
-10
lines changed

15 files changed

+463
-10
lines changed

.changeset/red-poets-rush.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@playcanvas/react": minor
3+
---
4+
5+
Introduces a new <Environment/> component for environment lighting and deprecates the EnvAtlas component

packages/docs/client-mdx-components.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Application, Entity } from '@playcanvas/react'
22
import { OrbitControls } from '@playcanvas/react/scripts'
3-
import { Align, Light, Anim, Camera, Collision, EnvAtlas, GSplat, Script, Render, RigidBody } from '@playcanvas/react/components'
3+
import { Align, Light, Anim, Camera, Collision, EnvAtlas, GSplat, Script, Render, RigidBody, Environment } from '@playcanvas/react/components'
44

55
import ReactQueryProvider from '@docs-components/ReactQueryProvider'
66

@@ -11,6 +11,7 @@ import ShadowCatcher from '@components/ShadowCatcher'
1111
import AutoRotate from '@components/AutoRotate'
1212
import { MotionEntity, MotionLight } from '@components/MotionEntity'
1313
import { Glb } from '@components/Glb'
14+
import { useEnvAtlas } from '@playcanvas/react/hooks'
1415

1516
import { version } from 'playcanvas';
1617
const PcVersion = () => <span>{version}</span>;
@@ -20,7 +21,7 @@ export const defaultComponents = {
2021
ReactQueryProvider,
2122
Application,
2223
Entity,
23-
Align, Anim, Camera, Collision, EnvAtlas, GSplat, Script, Render, RigidBody, Light,
24+
Align, Anim, Camera, Collision, EnvAtlas, GSplat, Script, Render, RigidBody, Light, Environment,
2425
OrbitControls,
2526
EnvAtlasComponent,
2627
Grid,
@@ -30,5 +31,6 @@ export const defaultComponents = {
3031
AutoRotate,
3132
MotionEntity,
3233
MotionLight,
34+
useEnvAtlas,
3335
Glb
3436
}

packages/docs/components/PostEffects.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const defaultPostSettings = {
8282
"grading": {
8383
"enabled": true,
8484
"brightness": 0.83,
85-
"contrast": 1.06,
85+
"contrast": 1.1,
8686
"saturation": 1.2,
8787
"tint": {
8888
"r": 1,

packages/docs/components/ShadowCatcher.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ const ShadowCatcherComponent: FC<ShadowCatcherProps> = (props) => {
2424
shadowResolution={1024}
2525
shadowType={SHADOW_VSM_16F}
2626
shadowUpdateMode={SHADOWUPDATE_REALTIME}
27-
vsmBlurSize={16}
27+
vsmBlurSize={8}
2828
shadowIntensity={intensity}
2929
intensity={0} />
30-
3130
<Script script={ShadowCatcher} intensity={intensity} scale={scale} />
3231
</Entity>
3332
}

packages/docs/content/_meta.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ const examplesList = {
2222
title: 'Pointer Events',
2323
href: '/examples/pointer-events'
2424
},
25+
'environment' : {
26+
title: 'Environment',
27+
href: '/examples/environment'
28+
},
2529
// "Advanced" : {
2630
// type: 'separator',
2731
// },

packages/docs/content/docs/api/components/envatlas.mdx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ openGraph:
1111
---
1212

1313
# EnvAtlas
14-
The `EnvAtlas` is used to add realtistic lighting to a scene.
14+
15+
> [!NOTE]
16+
>
17+
> The `EnvAtlas` component is deprecated. Please use the [`Environment`](./environment) component instead.
18+
19+
The `EnvAtlas` is used to add realistic lighting to a scene.
1520

1621
Image Based Lighting (IBL) is a technique to simulate environmental lighting often using an capture of a real world environment. It can add much more natural nuanced lighting to a scene than simply by using [Lights](/api/components/light) alone.
1722

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
title: Environment
3+
description: Documentation for the Environment component
4+
openGraph:
5+
title: playcanvas/react docs - Environment
6+
description: Documentation for @playcanvas/react
7+
images:
8+
- url: https://playcanvas-react.vercel.app/pc_react-og.png
9+
width: 1200
10+
height: 630
11+
---
12+
13+
# Environment
14+
15+
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.
16+
17+
## Overview
18+
19+
The Environment component combines several PlayCanvas scene and sky properties into a single, easy-to-use component:
20+
21+
- **Skybox**: Sets the background texture for the scene
22+
- **Environment Atlas**: Provides Image-Based Lighting (IBL) for realistic environmental reflections
23+
- **Sky Settings**: Controls sky dome properties, rotation, scale, and positioning
24+
- **Scene Settings**: Manages exposure, luminance, and other global lighting parameters
25+
26+
## Usage
27+
28+
The Environment component should be placed within an `<Application>` component. Only one Environment component should be used per application instance.
29+
30+
### Basic Usage
31+
32+
```jsx copy filename="environment-basic.jsx"
33+
import { Environment } from '@playcanvas/react/components'
34+
import { useAsset } from '@playcanvas/react/hooks'
35+
36+
const EnvironmentExample = () => {
37+
const skyboxAsset = useAsset('/skybox.jpg')
38+
const envAtlasAsset = useAsset('/env_atlas.png')
39+
40+
return (
41+
<Application>
42+
<Environment
43+
skybox={skyboxAsset}
44+
envAtlas={envAtlasAsset}
45+
exposure={1.2}
46+
/>
47+
{/* Your scene entities here */}
48+
</Application>
49+
)
50+
}
51+
```
52+
53+
### Advanced Configuration
54+
55+
```jsx copy filename="environment-advanced.jsx"
56+
import { Environment } from '@playcanvas/react/components'
57+
import { useAsset } from '@playcanvas/react/hooks'
58+
59+
const AdvancedEnvironmentExample = () => {
60+
const skyboxAsset = useAsset('/skybox.jpg')
61+
const envAtlasAsset = useAsset('/env_atlas.png')
62+
63+
return (
64+
<Application>
65+
<Environment
66+
envAtlas={envAtlasAsset}
67+
skybox={skyboxAsset}
68+
69+
// Environment lighting
70+
exposure={1.1}
71+
72+
// Sky dome settings
73+
scale={[200, 200, 200]}
74+
position={[0, 50, 0]}
75+
center={[0, 0.05, 0]}
76+
rotation={[0, 45, 0]}
77+
type="dome"
78+
depthWrite={true}
79+
/>
80+
</Application>
81+
)
82+
}
83+
```
84+
85+
## Important Notes
86+
87+
- **Single Instance**: Only one `<Environment/>` component should be used per application instance. Multiple instances will cause warnings and only the first will be used.
88+
- **Asset Requirements**: The `skybox` and `envAtlas` props expect PlayCanvas Asset instances, typically loaded using the `useAsset` hook.
89+
- **Automatic Cleanup**: The component automatically restores default values when unmounted.
90+
91+
## Props
92+
93+
The following props are based on PlayCanvas version **<PcVersion />**. This documentation is automatically generated from the TypeScript types of the installed PlayCanvas package.
94+
95+
<TSDoc
96+
code={`import type { Environment } from '@playcanvas/react/components'
97+
type $ = React.ComponentProps<typeof Environment>
98+
export default $`}
99+
/>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
export const Example = () => {
2+
3+
/**
4+
* Load an asset and some environment settings.
5+
*/
6+
7+
const { data: asset } = useModel('/lamborghini_vision_gt.glb')
8+
const { data: envAtlas } = useEnvAtlas('/environment-map.png')
9+
const { data: skybox } = useTexture('/wide-street.hdr')
10+
11+
if (!envAtlas || !skybox) return null;
12+
13+
return (<Entity>
14+
{/* Create some environment lighting */}
15+
<Environment
16+
type="dome"
17+
envAtlas={envAtlas}
18+
skybox={skybox}
19+
exposure={0.75}
20+
scale={[15, 15, 15]}
21+
center={[0.0, 0.04, 0.0]}
22+
rotation={[0, 290, 0]}
23+
/>
24+
25+
{/* Add a shadow catcher to catch the shadows from the model */}
26+
<ShadowCatcher width={5} depth={5} />
27+
28+
{/* Create a camera entity */}
29+
<Entity name='camera' position={[5, 1, -5]}>
30+
<Camera clearColor='#090707' fov={45} />
31+
<OrbitControls inertiaFactor={0.07} distanceMin={3} distanceMax={10} pitchAngleMin={1} pitchAngleMax={90}/>
32+
{asset && <PostEffects />}
33+
<AutoRotate />
34+
</Entity>
35+
36+
{/* Load our asset */}
37+
<Render asset={asset} />
38+
</Entity>)
39+
}
40+
41+
{/* Leave this here to render the demo */}
42+
<Example />
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"title": "Environment Example 🚀",
3+
"description": "Learn how to use the Environment component in @playcanvas/react",
4+
"openGraph": {
5+
"title": "Environment Example 🚀",
6+
"description": "Learn how to use the Environment component in @playcanvas/react",
7+
"images": [
8+
{
9+
"url": "https://playcanvas-react.vercel.app/pc_react-og.png",
10+
"width": 1200,
11+
"height": 630
12+
}
13+
]
14+
}
15+
}

packages/docs/content/examples/primitives.mdx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export const Primitives = () => {
1717
const [primitive, setPrimitive] = useState('box')
1818
const material = useMaterial({ diffuse: 'gray' })
1919

20+
const app = useApp();
21+
22+
console.log(app.root);
23+
2024
// Create a button for each primitive
2125
const buttons = primitives.map(type => (
2226
<button
@@ -30,11 +34,15 @@ export const Primitives = () => {
3034

3135
return <Entity>
3236

33-
<EnvAtlasComponent src='/environment-map.png' intensity={2}/>
37+
3438

3539
{/* Render the background grid */}
3640
<Grid />
3741

42+
<Entity position={[0, 2, 0]}>
43+
<Light intensity={10} color='#ff0000' />
44+
</Entity>
45+
3846
{/* Add a shadow catcher to catch the shadows from the model */}
3947
<ShadowCatcher width={5} depth={5} />
4048

@@ -43,7 +51,6 @@ export const Primitives = () => {
4351
<Camera clearColor='#111111' fov={28} />
4452
<OrbitControls inertiaFactor={0.07} distanceMin={6} distanceMax={10} pitchAngleMin={1} pitchAngleMax={90}/>
4553
<AutoRotate />
46-
<StaticPostEffects bloom={{ intensity: 0.02 }} vignette={false} fringing={{ intensity: 3 }}/>
4754
</Entity>
4855

4956
{/* Create the right box entity */}

0 commit comments

Comments
 (0)