Skip to content

Commit 93f6cfc

Browse files
🚚 Debug -> leva
1 parent 44d98ec commit 93f6cfc

File tree

6 files changed

+61
-76
lines changed

6 files changed

+61
-76
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
"dependencies": {
1515
"@react-three/drei": "^9.88.7",
1616
"@react-three/fiber": "^8.15.8",
17+
"leva": "^0.9.35",
18+
"r3f-perf": "^7.1.2",
1719
"react": "18.2",
1820
"react-dom": "18.2",
1921
"three": "^0.158.0"
-24.5 KB
Binary file not shown.

src/Experience.jsx

Lines changed: 43 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,65 @@
1-
import { MeshReflectorMaterial, Float, Text, Html, PivotControls, TransformControls, OrbitControls } from '@react-three/drei'
2-
import { useRef } from 'react'
1+
import { OrbitControls } from '@react-three/drei'
2+
import { useControls, button } from 'leva'
3+
import { Perf } from 'r3f-perf'
34

45
export default function Experience()
56
{
6-
const cube = useRef()
7-
const sphere = useRef()
7+
const { position, color, visible } = useControls('sphere', {
8+
position:
9+
{
10+
value: { x: - 2, y: 0 },
11+
step: 0.01,
12+
joystick: 'invertY'
13+
},
14+
color: '#ff0000',
15+
visible: true,
16+
myInterval:
17+
{
18+
min: 0,
19+
max: 10,
20+
value: [4, 5],
21+
},
22+
clickMe: button(() => { console.log('ok') }),
23+
choice: { options: [ 'a', 'b', 'c' ] }
24+
})
25+
26+
const { scale } = useControls('cube', {
27+
scale:
28+
{
29+
value: 1.5,
30+
step: 0.01,
31+
min: 0,
32+
max: 5
33+
}
34+
})
35+
36+
const { perfVisible } = useControls('debug', {
37+
perfVisible: false
38+
})
839

940
return <>
1041

42+
{ perfVisible && <Perf position="top-left" /> }
43+
1144
<OrbitControls makeDefault />
1245

1346
<directionalLight position={ [ 1, 2, 3 ] } intensity={ 4.5 } />
1447
<ambientLight intensity={ 1.5 } />
1548

16-
<PivotControls
17-
anchor={ [ 0, 0, 0 ] }
18-
depthTest={ false }
19-
lineWidth={ 4 }
20-
axisColors={ [ '#9381ff', '#ff4d6d', '#7ae582' ] }
21-
scale={ 200 }
22-
fixed={ true }
23-
>
24-
<mesh ref={ sphere } position-x={ - 2 }>
25-
<sphereGeometry />
26-
<meshStandardMaterial color="orange" />
27-
{/* <Html
28-
position={ [ 1, 1, 0 ] }
29-
wrapperClass="label"
30-
center
31-
distanceFactor={ 8 }
32-
occlude={ [ sphere, cube ] }
33-
>
34-
That's a sphere 👍
35-
</Html> */}
36-
</mesh>
37-
</PivotControls>
49+
<mesh visible={ visible } position={ [ position.x, position.y, 0 ] }>
50+
<sphereGeometry />
51+
<meshStandardMaterial color={ color } />
52+
</mesh>
3853

39-
<mesh ref={ cube } position-x={ 2 } scale={ 1.5 }>
54+
<mesh position-x={ 2 } scale={ scale }>
4055
<boxGeometry />
4156
<meshStandardMaterial color="mediumpurple" />
4257
</mesh>
4358

44-
<TransformControls object={ cube } />
45-
4659
<mesh position-y={ - 1 } rotation-x={ - Math.PI * 0.5 } scale={ 10 }>
4760
<planeGeometry />
48-
<MeshReflectorMaterial
49-
resolution={ 512 }
50-
blur={ [ 1000, 1000 ] }
51-
mixBlur={ 1 }
52-
mirror={ 0.5 }
53-
color="greenyellow"
54-
/>
61+
<meshStandardMaterial color="greenyellow" />
5562
</mesh>
5663

57-
<Float
58-
speed={ 5 }
59-
floatIntensity={ 2 }
60-
>
61-
<Text
62-
font="./bangers-v20-latin-regular.woff"
63-
fontSize={ 1 }
64-
color="salmon"
65-
position-y={ 2 }
66-
maxWidth={ 2 }
67-
textAlign="center"
68-
>
69-
I LOVE R3F
70-
</Text>
71-
</Float>
72-
7364
</>
7465
}

src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8">
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7-
<title>44 - R3F and Drei</title>
7+
<title>45 - Debug and monitoring with R3F</title>
88
</head>
99
<body>
1010
<div id="root"></div>

src/index.jsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,23 @@ import './style.css'
22
import ReactDOM from 'react-dom/client'
33
import { Canvas } from '@react-three/fiber'
44
import Experience from './Experience.jsx'
5+
import { StrictMode } from 'react'
6+
import { Leva } from 'leva'
57

68
const root = ReactDOM.createRoot(document.querySelector('#root'))
79

810
root.render(
9-
<Canvas
10-
camera={ {
11-
fov: 45,
12-
near: 0.1,
13-
far: 200,
14-
position: [ - 4, 3, 6 ]
15-
} }
16-
>
17-
<Experience />
18-
</Canvas>
11+
<StrictMode>
12+
<Leva collapsed />
13+
<Canvas
14+
camera={ {
15+
fov: 45,
16+
near: 0.1,
17+
far: 200,
18+
position: [ - 4, 3, 6 ]
19+
} }
20+
>
21+
<Experience />
22+
</Canvas>
23+
</StrictMode>
1924
)

src/style.css

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,4 @@ body,
88
width: 100%;
99
height: 100%;
1010
background: ivory;
11-
}
12-
13-
.label > div
14-
{
15-
font-family: Helvetica, Arial;
16-
position: absolute;
17-
background: #00000088;
18-
color: white;
19-
padding: 15px;
20-
white-space: nowrap;
21-
overflow: hidden;
22-
border-radius: 30px;
23-
user-select: none;
2411
}

0 commit comments

Comments
 (0)