Skip to content

Commit c353300

Browse files
committed
chore: update dependencies, remove legacy lights
1 parent 82dd461 commit c353300

19 files changed

+119
-223
lines changed

packages/react-three-cannon-examples/package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
],
2222
"devDependencies": {
2323
"@react-three/cannon": "^6.6.0",
24-
"@react-three/drei": "^9.80.1",
25-
"@react-three/fiber": "^8.13.6",
24+
"@react-three/drei": "^9.97.5",
25+
"@react-three/fiber": "^8.15.16",
2626
"@types/lodash-es": "^4.17.6",
2727
"@types/react": "^18.0.5",
2828
"@types/react-dom": "^17.0.14",
@@ -31,7 +31,6 @@
3131
"@types/three": "^0.155.0",
3232
"@typescript-eslint/eslint-plugin": "^5.17.0",
3333
"@typescript-eslint/parser": "^5.17.0",
34-
"@vitejs/plugin-react": "^2.2.0",
3534
"eslint": "^8.12.0",
3635
"eslint-config-prettier": "^8.5.0",
3736
"eslint-plugin-es": "^4.1.0",
@@ -47,16 +46,17 @@
4746
"react-router-dom": "^6.2.2",
4847
"styled-components": "^5.3.5",
4948
"three": "^0.155.0",
50-
"three-stdlib": "^2.24.1",
49+
"three-stdlib": "^2.29.4",
5150
"typescript": "^4.6.3",
52-
"vite": "^3.2.2",
51+
"vite": "^5.1.1",
5352
"vite-react-jsx": "^1.1.2",
54-
"zustand": "^3.7.1"
53+
"zustand": "^4.5.0"
5554
},
5655
"lint-staged": {
5756
"*.{js,jsx,ts,tsx}": "eslint --cache --fix",
5857
"*.{js,json,jsx,md,ts,tsx}": "prettier --write"
5958
},
6059
"license": "MIT",
61-
"sideEffects": false
60+
"sideEffects": false,
61+
"type": "module"
6262
}

packages/react-three-cannon-examples/src/demos/MondayMorning/index.tsx

+15-11
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import {
99
usePointToPointConstraint,
1010
useSphere,
1111
} from '@react-three/cannon'
12+
import { useGLTF } from '@react-three/drei'
1213
import type { BoxGeometryProps, MeshProps, MeshStandardMaterialProps, ThreeEvent } from '@react-three/fiber'
13-
import { Canvas, useFrame, useLoader } from '@react-three/fiber'
14+
import { Canvas, useFrame } from '@react-three/fiber'
1415
import type { ReactNode, RefObject } from 'react'
1516
import {
1617
createContext,
@@ -25,7 +26,6 @@ import {
2526
} from 'react'
2627
import type { Group, Material, Mesh, Object3D, SpotLight } from 'three'
2728
import type { GLTF } from 'three-stdlib/loaders/GLTFLoader'
28-
import { GLTFLoader } from 'three-stdlib/loaders/GLTFLoader'
2929

3030
import type { ShapeName } from './createConfig'
3131
import { createRagdoll } from './createConfig'
@@ -206,7 +206,7 @@ interface CupGLTF extends GLTF {
206206
}
207207

208208
function Mug() {
209-
const { nodes, materials } = useLoader(GLTFLoader, '/cup.glb') as CupGLTF
209+
const { nodes, materials } = useGLTF('/cup.glb') as CupGLTF
210210
const [ref] = useCylinder(
211211
() => ({
212212
args: [0.6, 0.6, 1, 16],
@@ -292,8 +292,16 @@ const Lamp = () => {
292292
<mesh ref={lamp} {...bind}>
293293
<coneGeometry attach="geometry" args={[2, 2.5, 32]} />
294294
<meshStandardMaterial attach="material" />
295-
<pointLight intensity={10} distance={5} />
296-
<spotLight ref={light} position={[0, 20, 0]} angle={0.4} penumbra={1} intensity={0.6} castShadow />
295+
<pointLight decay={5} intensity={10 * Math.PI} />
296+
<spotLight
297+
angle={0.4}
298+
decay={0}
299+
penumbra={1}
300+
position={[0, 20, 0]}
301+
ref={light}
302+
intensity={0.6 * Math.PI}
303+
castShadow
304+
/>
297305
</mesh>
298306
</>
299307
)
@@ -322,15 +330,11 @@ export default () => (
322330
orthographic
323331
shadows
324332
style={{ cursor: 'none' }}
325-
gl={{
326-
// todo: stop using legacy lights
327-
useLegacyLights: true,
328-
}}
329333
>
330334
<color attach="background" args={['#171720']} />
331335
<fog attach="fog" args={['#171720', 20, 70]} />
332-
<ambientLight intensity={0.2} />
333-
<pointLight position={[-10, -10, -10]} color="red" intensity={1.5} />
336+
<ambientLight intensity={0.2 * Math.PI} />
337+
<pointLight decay={0} position={[-10, -10, -10]} color="red" intensity={1.5 * Math.PI} />
334338
<Physics iterations={15} gravity={[0, -200, 0]} allowSleep={false}>
335339
<Cursor />
336340
<Ragdoll position={[0, 0, 0]} />

packages/react-three-cannon-examples/src/demos/Pingpong/index.tsx

+10-20
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { Physics, useBox, usePlane, useSphere } from '@react-three/cannon'
2+
import { useGLTF } from '@react-three/drei'
23
import { Canvas, useFrame, useLoader } from '@react-three/fiber'
34
import lerp from 'lerp'
45
import clamp from 'lodash-es/clamp'
56
import { Suspense, useRef } from 'react'
67
import type { Group, Material, Mesh, Object3D, Skeleton } from 'three'
78
import { TextureLoader } from 'three'
8-
import { DRACOLoader } from 'three-stdlib/loaders/DRACOLoader'
99
import type { GLTF } from 'three-stdlib/loaders/GLTFLoader'
10-
import { GLTFLoader } from 'three-stdlib/loaders/GLTFLoader'
11-
import create from 'zustand'
10+
import { create } from 'zustand'
1211

1312
import earthImg from './resources/cross.jpg'
1413
import pingSound from './resources/ping.mp3'
@@ -46,14 +45,8 @@ type PingPongGLTF = GLTF & {
4645
}
4746
}
4847

49-
const extensions = (loader: GLTFLoader) => {
50-
const dracoLoader = new DRACOLoader()
51-
dracoLoader.setDecoderPath('/draco-gltf/')
52-
loader.setDRACOLoader(dracoLoader)
53-
}
54-
5548
function Paddle() {
56-
const { nodes, materials } = useLoader(GLTFLoader, '/pingpong.glb', extensions) as PingPongGLTF
49+
const { nodes, materials } = useGLTF('/pingpong.glb', '/draco-gltf/') as PingPongGLTF
5750
const { pong } = useStore((state) => state.api)
5851
const welcome = useStore((state) => state.welcome)
5952
const count = useStore((state) => state.count)
@@ -149,23 +142,20 @@ export default function () {
149142
return (
150143
<>
151144
<Canvas
152-
shadows
153145
camera={{ fov: 50, position: [0, 5, 12] }}
154146
onPointerMissed={() => welcome && reset(false)}
155-
gl={{
156-
// todo: stop using legacy lights
157-
useLegacyLights: true,
158-
}}
147+
shadows
159148
>
160149
<color attach="background" args={['#171720']} />
161-
<ambientLight intensity={0.5} />
162-
<pointLight position={[-10, -10, -10]} />
150+
<ambientLight intensity={0.5 * Math.PI} />
151+
<pointLight decay={0} intensity={Math.PI} position={[-10, -10, -10]} />
163152
<spotLight
164-
position={[10, 10, 10]}
165153
angle={0.3}
166-
penumbra={1}
167-
intensity={1}
168154
castShadow
155+
decay={0}
156+
intensity={Math.PI}
157+
penumbra={1}
158+
position={[10, 10, 10]}
169159
shadow-mapSize-width={2048}
170160
shadow-mapSize-height={2048}
171161
shadow-bias={-0.0001}

packages/react-three-cannon-examples/src/demos/Raycast/index.tsx

+5-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
import type { Triplet } from '@react-three/cannon'
22
import { Physics, useBox, useRaycastAll, useSphere } from '@react-three/cannon'
33
import { Html } from '@react-three/drei'
4-
import type { GroupProps, Node, Object3DNode } from '@react-three/fiber'
4+
import { OrbitControls } from '@react-three/drei'
5+
import type { GroupProps, Object3DNode } from '@react-three/fiber'
56
import { Canvas, extend, useFrame, useThree } from '@react-three/fiber'
67
import { Suspense, useLayoutEffect, useMemo, useRef, useState } from 'react'
78
import type { Mesh, PerspectiveCamera } from 'three'
89
import { BufferGeometry, Line as ThreeLine, Vector3 } from 'three'
9-
import { OrbitControls } from 'three-stdlib/controls/OrbitControls'
1010

1111
import { prettyPrint } from './prettyPrint'
1212

13-
extend({ OrbitControls })
1413
extend({ ThreeLine })
1514

1615
declare global {
1716
namespace JSX {
1817
interface IntrinsicElements {
19-
orbitControls: Node<OrbitControls, typeof OrbitControls>
2018
threeLine: Object3DNode<ThreeLine, typeof ThreeLine>
2119
}
2220
}
@@ -114,7 +112,6 @@ function Raycast() {
114112

115113
const Camera = () => {
116114
const cameraRef = useRef<PerspectiveCamera>(null)
117-
const controlsRef = useRef<OrbitControls>(null)
118115
const { gl, camera } = useThree()
119116
const set = useThree((state) => state.set)
120117
const size = useThree((state) => state.size)
@@ -132,18 +129,16 @@ const Camera = () => {
132129
}, [])
133130

134131
useFrame(() => {
135-
if (!cameraRef.current || !controlsRef.current) return
132+
if (!cameraRef.current) return
136133
cameraRef.current.updateMatrixWorld()
137-
controlsRef.current.update()
138134
})
139135

140136
return (
141137
<>
142138
<perspectiveCamera ref={cameraRef} position={[0, -10, 10]} />
143-
<orbitControls
139+
<OrbitControls
144140
autoRotate
145141
enableDamping
146-
ref={controlsRef}
147142
args={[camera, gl.domElement]}
148143
dampingFactor={0.2}
149144
rotateSpeed={0.5}
@@ -155,14 +150,7 @@ const Camera = () => {
155150
}
156151

157152
export default () => (
158-
<Canvas
159-
shadows
160-
gl={{
161-
alpha: false,
162-
// todo: stop using legacy lights
163-
useLegacyLights: true,
164-
}}
165-
>
153+
<Canvas shadows>
166154
<Camera />
167155
<color attach="background" args={['#fcb89d']} />
168156
<hemisphereLight intensity={0.35} />

packages/react-three-cannon-examples/src/demos/RaycastVehicle/index.tsx

+10-10
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,18 @@ const VehicleScene = () => {
5454

5555
return (
5656
<>
57-
<Canvas
58-
shadows
59-
camera={{ fov: 50, position: [0, 5, 15] }}
60-
gl={{
61-
// todo: stop using legacy lights
62-
useLegacyLights: true,
63-
}}
64-
>
57+
<Canvas camera={{ fov: 50, position: [0, 5, 15] }} shadows>
6558
<fog attach="fog" args={['#171720', 10, 50]} />
6659
<color attach="background" args={['#171720']} />
67-
<ambientLight intensity={0.1} />
68-
<spotLight position={[10, 10, 10]} angle={0.5} intensity={1} castShadow penumbra={1} />
60+
<ambientLight intensity={0.1 * Math.PI} />
61+
<spotLight
62+
angle={0.5}
63+
castShadow
64+
decay={0}
65+
intensity={Math.PI}
66+
penumbra={1}
67+
position={[10, 10, 10]}
68+
/>
6969
<Physics
7070
broadphase="SAP"
7171
defaultContactMaterial={{ contactEquationRelaxation: 4, friction: 1e-3 }}

packages/react-three-cannon-examples/src/demos/demo-Chain.tsx

+11-12
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,18 @@ function ChainScene(): JSX.Element {
154154

155155
return (
156156
<>
157-
<Canvas
158-
shadows
159-
camera={{ fov: 50, position: [0, 5, 20] }}
160-
onPointerMissed={reset}
161-
gl={{
162-
// todo: stop using legacy lights
163-
useLegacyLights: true,
164-
}}
165-
>
157+
<Canvas shadows camera={{ fov: 50, position: [0, 5, 20] }} onPointerMissed={reset}>
166158
<color attach="background" args={['#171720']} />
167-
<ambientLight intensity={0.5} />
168-
<pointLight position={[-10, -10, -10]} />
169-
<spotLight position={[10, 10, 10]} angle={0.8} penumbra={1} intensity={1} castShadow />
159+
<ambientLight intensity={0.5 * Math.PI} />
160+
<pointLight position={[-10, -10, -10]} intensity={1 * Math.PI} decay={0} />
161+
<spotLight
162+
position={[10, 10, 10]}
163+
angle={0.8}
164+
penumbra={1}
165+
intensity={1 * Math.PI}
166+
decay={0}
167+
castShadow
168+
/>
170169
<Physics gravity={[0, -40, 0]} allowSleep={false}>
171170
<PointerHandle size={1.5}>
172171
<Chain length={7} />

packages/react-three-cannon-examples/src/demos/demo-CompoundBody.tsx

+1-9
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,7 @@ export default function (): JSX.Element {
9999
}
100100

101101
return (
102-
<Canvas
103-
shadows
104-
camera={{ fov: 50, position: [-2, 1, 7] }}
105-
gl={{
106-
alpha: false,
107-
// todo: stop using legacy lights
108-
useLegacyLights: true,
109-
}}
110-
>
102+
<Canvas shadows camera={{ fov: 50, position: [-2, 1, 7] }}>
111103
<color attach="background" args={['#f6d186']} />
112104
<hemisphereLight intensity={0.35} />
113105
<spotLight

packages/react-three-cannon-examples/src/demos/demo-Constraints.tsx

+1-7
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,7 @@ const style = {
6565
export default () => {
6666
return (
6767
<>
68-
<Canvas
69-
camera={{ fov: 50, position: [0, 0, 8] }}
70-
gl={{
71-
// todo: stop using legacy lights
72-
useLegacyLights: true,
73-
}}
74-
>
68+
<Canvas camera={{ fov: 50, position: [0, 0, 8] }}>
7569
<color attach="background" args={['#171720']} />
7670
<Physics gravity={[0, -40, 0]} allowSleep={false}>
7771
<BoxAndBall />

0 commit comments

Comments
 (0)