Skip to content

Commit 44d98ec

Browse files
🚚 Drei
1 parent 7b93afb commit 44d98ec

File tree

7 files changed

+71
-77
lines changed

7 files changed

+71
-77
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
"vite": "^4.5.0"
1313
},
1414
"dependencies": {
15+
"@react-three/drei": "^9.88.7",
16+
"@react-three/fiber": "^8.15.8",
1517
"react": "18.2",
1618
"react-dom": "18.2",
17-
"@react-three/fiber": "^8.15.8",
1819
"three": "^0.158.0"
1920
}
20-
}
21+
}
24.5 KB
Binary file not shown.

src/CustomObject.jsx

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/Experience.jsx

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,74 @@
1-
import { useThree, extend, useFrame } from '@react-three/fiber'
1+
import { MeshReflectorMaterial, Float, Text, Html, PivotControls, TransformControls, OrbitControls } from '@react-three/drei'
22
import { useRef } from 'react'
3-
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'
4-
import CustomObject from './CustomObject.jsx'
5-
6-
extend({ OrbitControls })
73

84
export default function Experience()
95
{
10-
const { camera, gl } = useThree()
11-
12-
const cubeRef = useRef()
13-
const groupRef = useRef()
14-
15-
useFrame((state, delta) =>
16-
{
17-
// const angle = state.clock.elapsedTime
18-
// state.camera.position.x = Math.sin(angle) * 8
19-
// state.camera.position.z = Math.cos(angle) * 8
20-
// state.camera.lookAt(0, 0, 0)
21-
22-
cubeRef.current.rotation.y += delta
23-
// groupRef.current.rotation.y += delta
24-
})
6+
const cube = useRef()
7+
const sphere = useRef()
258

269
return <>
27-
<orbitControls args={ [ camera, gl.domElement ] } />
10+
11+
<OrbitControls makeDefault />
2812

2913
<directionalLight position={ [ 1, 2, 3 ] } intensity={ 4.5 } />
3014
<ambientLight intensity={ 1.5 } />
3115

32-
<group ref={ groupRef }>
33-
<mesh position-x={ - 2 }>
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 }>
3425
<sphereGeometry />
3526
<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> */}
3636
</mesh>
37+
</PivotControls>
3738

38-
<mesh ref={ cubeRef } rotation-y={ Math.PI * 0.25 } position-x={ 2 } scale={ 1.5 }>
39-
<boxGeometry />
40-
<meshStandardMaterial color="mediumpurple" />
41-
</mesh>
42-
</group>
39+
<mesh ref={ cube } position-x={ 2 } scale={ 1.5 }>
40+
<boxGeometry />
41+
<meshStandardMaterial color="mediumpurple" />
42+
</mesh>
43+
44+
<TransformControls object={ cube } />
4345

4446
<mesh position-y={ - 1 } rotation-x={ - Math.PI * 0.5 } scale={ 10 }>
4547
<planeGeometry />
46-
<meshStandardMaterial color="greenyellow" />
48+
<MeshReflectorMaterial
49+
resolution={ 512 }
50+
blur={ [ 1000, 1000 ] }
51+
mixBlur={ 1 }
52+
mirror={ 0.5 }
53+
color="greenyellow"
54+
/>
4755
</mesh>
4856

49-
<CustomObject />
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+
5073
</>
5174
}

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>43 - First React Three Fiber Application</title>
7+
<title>44 - R3F and Drei</title>
88
</head>
99
<body>
1010
<div id="root"></div>

src/index.jsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,16 @@ 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 * as THREE from 'three'
65

76
const root = ReactDOM.createRoot(document.querySelector('#root'))
87

98
root.render(
109
<Canvas
11-
gl={ {
12-
antialias: true,
13-
toneMapping: THREE.ACESFilmicToneMapping,
14-
// outputColorSpace: THREE.SRGBColorSpace
15-
} }
1610
camera={ {
1711
fov: 45,
1812
near: 0.1,
1913
far: 200,
20-
position: [ 3, 2, 6 ]
14+
position: [ - 4, 3, 6 ]
2115
} }
2216
>
2317
<Experience />

src/style.css

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ body,
77
left: 0;
88
width: 100%;
99
height: 100%;
10+
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;
1021
overflow: hidden;
11-
background: LightSkyBlue;
22+
border-radius: 30px;
23+
user-select: none;
1224
}

0 commit comments

Comments
 (0)