@react-three/fiber 10.0.0-alpha.2 → 10.0.0-canary.b0fafc8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/fiber",
3
- "version": "10.0.0-alpha.2",
3
+ "version": "10.0.0-canary.b0fafc8",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",
@@ -57,6 +57,7 @@
57
57
  },
58
58
  "dependencies": {
59
59
  "@babel/runtime": "^7.28.6",
60
+ "@monogrid/gainmap-js": "^3.4.0",
60
61
  "dequal": "^2.0.3",
61
62
  "its-fine": "^2.0.0",
62
63
  "react-use-measure": "^2.1.7",
@@ -84,6 +85,7 @@
84
85
  "scripts": {
85
86
  "prebuild": "node -e \"require('fs').copyFileSync('../../readme.md', 'readme.md')\"",
86
87
  "build": "unbuild",
88
+ "postbuild": "node ../../scripts/fix-three-types.js",
87
89
  "stub": "unbuild --stub"
88
90
  }
89
91
  }
package/readme.md CHANGED
@@ -1,318 +1,244 @@
1
- <h1>@react-three/fiber</h1>
2
-
3
- [![Version](https://img.shields.io/npm/v/@react-three/fiber?style=flat&colorA=000000&colorB=000000)](https://npmjs.com/package/@react-three/fiber)
4
- [![Downloads](https://img.shields.io/npm/dt/@react-three/fiber.svg?style=flat&colorA=000000&colorB=000000)](https://npmjs.com/package/@react-three/fiber)
5
- [![Twitter](https://img.shields.io/twitter/follow/pmndrs?label=%40pmndrs&style=flat&colorA=000000&colorB=000000&logo=twitter&logoColor=000000)](https://twitter.com/pmndrs)
6
- [![Discord](https://img.shields.io/discord/740090768164651008?style=flat&colorA=000000&colorB=000000&label=discord&logo=discord&logoColor=000000)](https://discord.gg/ZZjjNvJ)
7
- [![Open Collective](https://img.shields.io/opencollective/all/react-three-fiber?style=flat&colorA=000000&colorB=000000)](https://opencollective.com/react-three-fiber)
8
- [![ETH](https://img.shields.io/badge/ETH-f5f5f5?style=flat&colorA=000000&colorB=000000)](https://blockchain.com/eth/address/0x6E3f79Ea1d0dcedeb33D3fC6c34d2B1f156F2682)
9
- [![BTC](https://img.shields.io/badge/BTC-f5f5f5?style=flat&colorA=000000&colorB=000000)](https://blockchain.com/btc/address/36fuguTPxGCNnYZSRdgdh6Ea94brCAjMbH)
10
-
11
- <a href="https://docs.pmnd.rs/react-three-fiber/getting-started/examples"><img src="docs/banner-r3f.jpg" /></a>
12
-
13
- react-three-fiber is a <a href="https://reactjs.org/docs/codebase-overview.html#renderers">React renderer</a> for threejs.
14
-
15
- Build your scene declaratively with re-usable, self-contained components that react to state, are readily interactive and can participate in React's ecosystem.
16
-
17
- ```bash
18
- yarn install three @types/three @react-three/fiber
19
- ```
20
-
21
- > [!WARNING]
22
- > Three-fiber is a React renderer, it must pair with a major version of React, just like react-dom, react-native, etc. @react-three/fiber@8 pairs with react@18, @react-three/fiber@9+ pairs with react@19.
23
-
24
- ---
25
-
26
- #### Does it have limitations?
27
-
28
- None. Everything that works in Threejs will work here without exception.
29
-
30
- #### Is it slower than plain Threejs?
31
-
32
- No. There is no overhead. Components render outside of React. It outperforms Threejs in scale due to React's scheduling abilities.
33
-
34
- #### Can it keep up with frequent feature updates to Threejs?
35
-
36
- Yes. It merely expresses Threejs in JSX, `<mesh />` dynamically turns into `new THREE.Mesh()`. If a new Threejs version adds, removes or changes features, it will be available to you instantly without depending on updates to this library.
37
-
38
- ### What does it look like?
39
-
40
- <table>
41
- <tbody>
42
- <tr>
43
- <td>Let's make a re-usable component that has its own state, reacts to user-input and participates in the render-loop. (<a href="https://codesandbox.io/s/rrppl0y8l4?file=/src/App.js">live demo</a>).</td>
44
- <td>
45
- <a href="https://codesandbox.io/s/rrppl0y8l4">
46
- <img src="/docs/basic-app.gif" />
47
- </a>
48
- </td>
49
- </tr>
50
- </tbody>
51
- </table>
52
-
53
- ```jsx
54
- import { createRoot } from 'react-dom/client'
55
- import React, { useRef, useState } from 'react'
56
- import { Canvas, useFrame } from '@react-three/fiber'
57
-
58
- function Box(props) {
59
- // This reference gives us direct access to the THREE.Mesh object
60
- const ref = useRef()
61
- // Hold state for hovered and clicked events
62
- const [hovered, hover] = useState(false)
63
- const [clicked, click] = useState(false)
64
- // Subscribe this component to the render-loop, rotate the mesh every frame
65
- useFrame(({ delta }) => (ref.current.rotation.x += delta))
66
- // Return the view, these are regular Threejs elements expressed in JSX
67
- return (
68
- <mesh
69
- {...props}
70
- ref={ref}
71
- scale={clicked ? 1.5 : 1}
72
- onClick={(event) => click(!clicked)}
73
- onPointerOver={(event) => hover(true)}
74
- onPointerOut={(event) => hover(false)}>
75
- <boxGeometry args={[1, 1, 1]} />
76
- <meshStandardMaterial color={hovered ? 'hotpink' : 'orange'} />
77
- </mesh>
78
- )
79
- }
80
-
81
- createRoot(document.getElementById('root')).render(
82
- <Canvas>
83
- <ambientLight intensity={Math.PI / 2} />
84
- <spotLight position={[10, 10, 10]} angle={0.15} penumbra={1} decay={0} intensity={Math.PI} />
85
- <pointLight position={[-10, -10, -10]} decay={0} intensity={Math.PI} />
86
- <Box position={[-1.2, 0, 0]} />
87
- <Box position={[1.2, 0, 0]} />
88
- </Canvas>,
89
- )
90
- ```
91
-
92
- <details>
93
- <summary>Show TypeScript example</summary>
94
-
95
- ```bash
96
- npm install @types/three
97
- ```
98
-
99
- ```tsx
100
- import * as THREE from 'three'
101
- import { createRoot } from 'react-dom/client'
102
- import React, { useRef, useState } from 'react'
103
- import { Canvas, useFrame, ThreeElements } from '@react-three/fiber'
104
-
105
- function Box(props: ThreeElements['mesh']) {
106
- const ref = useRef<THREE.Mesh>(null!)
107
- const [hovered, hover] = useState(false)
108
- const [clicked, click] = useState(false)
109
- useFrame((state, delta) => (ref.current.rotation.x += delta))
110
- return (
111
- <mesh
112
- {...props}
113
- ref={ref}
114
- scale={clicked ? 1.5 : 1}
115
- onClick={(event) => click(!clicked)}
116
- onPointerOver={(event) => hover(true)}
117
- onPointerOut={(event) => hover(false)}>
118
- <boxGeometry args={[1, 1, 1]} />
119
- <meshStandardMaterial color={hovered ? 'hotpink' : 'orange'} />
120
- </mesh>
121
- )
122
- }
123
-
124
- createRoot(document.getElementById('root') as HTMLElement).render(
125
- <Canvas>
126
- <ambientLight intensity={Math.PI / 2} />
127
- <spotLight position={[10, 10, 10]} angle={0.15} penumbra={1} decay={0} intensity={Math.PI} />
128
- <pointLight position={[-10, -10, -10]} decay={0} intensity={Math.PI} />
129
- <Box position={[-1.2, 0, 0]} />
130
- <Box position={[1.2, 0, 0]} />
131
- </Canvas>,
132
- )
133
- ```
134
-
135
- TODO: Move this
136
- Live demo: https://codesandbox.io/s/icy-tree-brnsm?file=/src/App.tsx
137
-
138
- </details>
139
-
140
- <details>
141
- <summary>Show React Native example</summary>
142
-
143
- This example relies on react 18 and uses `expo-cli`, but you can create a bare project with their template or with the `react-native` CLI.
144
-
145
- ```bash
146
- # Install expo-cli, this will create our app
147
- npm install expo-cli -g
148
- # Create app and cd into it
149
- expo init my-app
150
- cd my-app
151
- # Install dependencies
152
- npm install three @react-three/fiber@beta react@rc
153
- # Start
154
- expo start
155
- ```
156
-
157
- Some configuration may be required to tell the Metro bundler about your assets if you use `useLoader` or Drei abstractions like `useGLTF` and `useTexture`:
158
-
159
- ```js
160
- // metro.config.js
161
- module.exports = {
162
- resolver: {
163
- sourceExts: ['js', 'jsx', 'json', 'ts', 'tsx', 'cjs'],
164
- assetExts: ['glb', 'png', 'jpg'],
165
- },
166
- }
167
- ```
168
-
169
- ```tsx
170
- import React, { useRef, useState } from 'react'
171
- import { Canvas, useFrame } from '@react-three/fiber/native'
172
- function Box(props) {
173
- const mesh = useRef(null)
174
- const [hovered, setHover] = useState(false)
175
- const [active, setActive] = useState(false)
176
- useFrame((state, delta) => (mesh.current.rotation.x += delta))
177
- return (
178
- <mesh
179
- {...props}
180
- ref={mesh}
181
- scale={active ? 1.5 : 1}
182
- onClick={(event) => setActive(!active)}
183
- onPointerOver={(event) => setHover(true)}
184
- onPointerOut={(event) => setHover(false)}>
185
- <boxGeometry args={[1, 1, 1]} />
186
- <meshStandardMaterial color={hovered ? 'hotpink' : 'orange'} />
187
- </mesh>
188
- )
189
- }
190
- export default function App() {
191
- return (
192
- <Canvas>
193
- <ambientLight intensity={Math.PI / 2} />
194
- <spotLight position={[10, 10, 10]} angle={0.15} penumbra={1} decay={0} intensity={Math.PI} />
195
- <pointLight position={[-10, -10, -10]} decay={0} intensity={Math.PI} />
196
- <Box position={[-1.2, 0, 0]} />
197
- <Box position={[1.2, 0, 0]} />
198
- </Canvas>
199
- )
200
- }
201
- ```
202
-
203
- </details>
204
-
205
- ---
206
-
207
- # Documentation, tutorials, examples
208
-
209
- Visit [docs.pmnd.rs](https://docs.pmnd.rs/react-three-fiber)
210
-
211
- # First steps
212
-
213
- You need to be versed in both React and Threejs before rushing into this. If you are unsure about React consult the official [React docs](https://react.dev/learn), especially [the section about hooks](https://react.dev/reference/react). As for Threejs, make sure you at least glance over the following links:
214
-
215
- 1. Make sure you have a [basic grasp of Threejs](https://threejs.org/docs/index.html#manual/en/introduction/Creating-a-scene). Keep that site open.
216
- 2. When you know what a scene is, a camera, mesh, geometry, material, fork the [demo above](https://github.com/pmndrs/react-three-fiber#what-does-it-look-like).
217
- 3. [Look up](https://threejs.org/docs/index.html#api/en/objects/Mesh) the JSX elements that you see (mesh, ambientLight, etc), _all_ threejs exports are native to three-fiber.
218
- 4. Try changing some values, scroll through our [API](https://docs.pmnd.rs/react-three-fiber) to see what the various settings and hooks do.
219
-
220
- Some helpful material:
221
-
222
- - [Threejs-docs](https://threejs.org/docs) and [examples](https://threejs.org/examples)
223
- - [Discover Threejs](https://discoverthreejs.com), especially the [Tips and Tricks](https://discoverthreejs.com/tips-and-tricks) chapter for best practices
224
- - [Bruno Simons Threejs Journey](https://threejs-journey.com), arguably the best learning resource, now includes a full [R3F chapter](https://threejs-journey.com/lessons/what-are-react-and-react-three-fiber)
225
-
226
- <a href="https://threejs-journey.com"><img src="docs/banner-journey.jpg" /></a>
227
-
228
- # Ecosystem
229
-
230
- There is a vibrant and extensive eco system around three-fiber, full of libraries, helpers and abstractions.
231
-
232
- - [`@react-three/drei`](https://github.com/pmndrs/drei) &ndash; useful helpers, this is an eco system in itself
233
- - [`@react-three/gltfjsx`](https://github.com/pmndrs/gltfjsx) &ndash; turns GLTFs into JSX components
234
- - [`@react-three/postprocessing`](https://github.com/pmndrs/react-postprocessing) &ndash; post-processing effects
235
- - [`@react-three/uikit`](https://github.com/pmndrs/uikit) &ndash; WebGL rendered UI components for three-fiber
236
- - [`@react-three/test-renderer`](https://github.com/pmndrs/react-three-fiber/tree/master/packages/test-renderer) &ndash; for unit tests in node
237
- - [`@react-three/offscreen`](https://github.com/pmndrs/react-three-offscreen) &ndash; offscreen/worker canvas for react-three-fiber
238
- - [`@react-three/flex`](https://github.com/pmndrs/react-three-flex) &ndash; flexbox for react-three-fiber
239
- - [`@react-three/xr`](https://github.com/pmndrs/react-xr) &ndash; VR/AR controllers and events
240
- - [`@react-three/csg`](https://github.com/pmndrs/react-three-csg) &ndash; constructive solid geometry
241
- - [`@react-three/rapier`](https://github.com/pmndrs/react-three-rapier) &ndash; 3D physics using Rapier
242
- - [`@react-three/cannon`](https://github.com/pmndrs/use-cannon) &ndash; 3D physics using Cannon
243
- - [`@react-three/p2`](https://github.com/pmndrs/use-p2) &ndash; 2D physics using P2
244
- - [`@react-three/a11y`](https://github.com/pmndrs/react-three-a11y) &ndash; real a11y for your scene
245
- - [`@react-three/gpu-pathtracer`](https://github.com/pmndrs/react-three-gpu-pathtracer) &ndash; realistic path tracing
246
- - [`create-r3f-app next`](https://github.com/pmndrs/react-three-next) &ndash; nextjs starter
247
- - [`lamina`](https://github.com/pmndrs/lamina) &ndash; layer based shader materials
248
- - [`zustand`](https://github.com/pmndrs/zustand) &ndash; flux based state management
249
- - [`jotai`](https://github.com/pmndrs/jotai) &ndash; atoms based state management
250
- - [`valtio`](https://github.com/pmndrs/valtio) &ndash; proxy based state management
251
- - [`react-spring`](https://github.com/pmndrs/react-spring) &ndash; a spring-physics-based animation library
252
- - [`framer-motion-3d`](https://www.framer.com/docs/three-introduction/) &ndash; framer motion, a popular animation library
253
- - [`use-gesture`](https://github.com/pmndrs/react-use-gesture) &ndash; mouse/touch gestures
254
- - [`leva`](https://github.com/pmndrs/leva) &ndash; create GUI controls in seconds
255
- - [`maath`](https://github.com/pmndrs/maath) &ndash; a kitchen sink for math helpers
256
- - [`miniplex`](https://github.com/hmans/miniplex) &ndash; ECS (entity management system)
257
- - [`composer-suite`](https://github.com/hmans/composer-suite) &ndash; composing shaders, particles, effects and game mechanics
258
- - [`triplex`](https://triplex.dev/) &ndash; visual editor for react-three-fiber
259
- - [`koestlich`](https://github.com/coconut-xr/koestlich) &ndash; UI component library for react-three-fiber
260
-
261
- [Usage Trend of the @react-three Family](https://npm-compare.com/@react-three/a11y,@react-three/cannon,@react-three/csg,@react-three/drei,@react-three/flex,@react-three/gltfjsx,@react-three/gpu-pathtracer,@react-three/offscreen,@react-three/p2,@react-three/postprocessing,@react-three/rapier,@react-three/test-renderer,@react-three/uikit,@react-three/xr)
262
-
263
- # Who is using Three-fiber
264
-
265
- A small selection of companies and projects relying on three-fiber.
266
-
267
- - [`vercel`](https://www.vercel.com) (design agency)
268
- - [`basement`](https://basement.studio) (design agency)
269
- - [`studio freight`](https://studiofreight.com) (design agency)
270
- - [`14 islands`](https://www.14islands.com) (design agency)
271
- - [`ueno`](https://dribbble.com/ueno) (design agency) — [video](https://twitter.com/0xca0a/status/1204373807408013312)
272
- - [`flux.ai`](https://www.flux.ai) (PCB builder)
273
- - [`colorful.app`](https://www.colorful.app) (modeller)
274
- - [`bezi`](https://www.bezi.com) (modeller)
275
- - [`readyplayer.me`](https://readyplayer.me) (avatar configurator)
276
- - [`zillow`](https://www.zillow.com) (real estate)
277
- - [`lumalabs.ai/genie`](https://lumalabs.ai/genie) (AI models)
278
- - [`skybox.blockadelabs`](https://skybox.blockadelabs.com) (AI envmaps)
279
- - [`3dconfig`](https://3dconfig.com) (floor planer)
280
- - [`buerli.io`](https://buerli.io) (CAD)
281
- - [`getencube`](https://www.getencube.com) (CAD)
282
- - [`glowbuzzer`](https://www.glowbuzzer.com) (CAD) — [video](https://twitter.com/glowbuzzer/status/1678396014644940800)
283
- - [`triplex`](https://triplex.dev) (editor) — [video](https://twitter.com/_douges/status/1708859381369221539)
284
- - [`theatrejs`](https://www.theatrejs.com) (editor) — [video](https://twitter.com/0xca0a/status/1566838823170068480)
285
-
286
- # How to contribute
287
-
288
- Checkout the detailed [contribution docs.](docs/development/README.md)
289
-
290
- If you like this project, please consider helping out. All contributions are welcome as well as donations to [Opencollective](https://opencollective.com/pmndrs)
291
-
292
- # Testing
293
-
294
- R3F uses Jest for unit testing and bundle verification scripts to ensure correct THREE.js imports across entry points. For detailed testing instructions, see the [Testing Guide](docs/development/TESTING.md).
295
-
296
- ```bash
297
- # Run all tests
298
- yarn test
299
-
300
- # Build and verify bundles
301
- yarn build && yarn verify-bundles
302
- ```
303
-
304
- #### Backers
305
-
306
- Thank you to all our backers! 🙏
307
-
308
- <a href="https://opencollective.com/pmndrsr#backers" target="_blank">
309
- <img src="https://opencollective.com/pmndrs/backers.svg?width=890"/>
310
- </a>
311
-
312
- #### Contributors
313
-
314
- This project exists thanks to all the people who contribute.
315
-
316
- <a href="https://github.com/pmndrs/react-three-fiber/graphs/contributors">
317
- <img src="https://opencollective.com/react-three-fiber/contributors.svg?width=890" />
318
- </a>
1
+ <h1>@react-three/fiber</h1>
2
+
3
+ [![Version](https://img.shields.io/npm/v/@react-three/fiber?style=flat&colorA=000000&colorB=000000)](https://npmjs.com/package/@react-three/fiber)
4
+ [![Downloads](https://img.shields.io/npm/dt/@react-three/fiber.svg?style=flat&colorA=000000&colorB=000000)](https://npmjs.com/package/@react-three/fiber)
5
+ [![Twitter](https://img.shields.io/twitter/follow/pmndrs?label=%40pmndrs&style=flat&colorA=000000&colorB=000000&logo=twitter&logoColor=000000)](https://twitter.com/pmndrs)
6
+ [![Discord](https://img.shields.io/discord/740090768164651008?style=flat&colorA=000000&colorB=000000&label=discord&logo=discord&logoColor=000000)](https://discord.gg/ZZjjNvJ)
7
+ [![Open Collective](https://img.shields.io/opencollective/all/react-three-fiber?style=flat&colorA=000000&colorB=000000)](https://opencollective.com/react-three-fiber)
8
+ [![ETH](https://img.shields.io/badge/ETH-f5f5f5?style=flat&colorA=000000&colorB=000000)](https://blockchain.com/eth/address/0x6E3f79Ea1d0dcedeb33D3fC6c34d2B1f156F2682)
9
+ [![BTC](https://img.shields.io/badge/BTC-f5f5f5?style=flat&colorA=000000&colorB=000000)](https://blockchain.com/btc/address/36fuguTPxGCNnYZSRdgdh6Ea94brCAjMbH)
10
+
11
+ <a href="https://docs.pmnd.rs/react-three-fiber/getting-started/examples"><img src="docs/banner-r3f.jpg" /></a>
12
+
13
+ react-three-fiber is a <a href="https://reactjs.org/docs/codebase-overview.html#renderers">React renderer</a> for threejs.
14
+
15
+ Build your scene declaratively with re-usable, self-contained components that react to state, are readily interactive and can participate in React's ecosystem.
16
+
17
+ ```bash
18
+ yarn install three @types/three @react-three/fiber
19
+ ```
20
+
21
+ > [!WARNING]
22
+ > Three-fiber is a React renderer, it must pair with a major version of React, just like react-dom, react-native, etc. @react-three/fiber@8 pairs with react@18, @react-three/fiber@9+ pairs with react@19.
23
+
24
+ ---
25
+
26
+ #### Does it have limitations?
27
+
28
+ None. Everything that works in Threejs will work here without exception.
29
+
30
+ #### Is it slower than plain Threejs?
31
+
32
+ No. There is no overhead. Components render outside of React. It outperforms Threejs in scale due to React's scheduling abilities.
33
+
34
+ #### Can it keep up with frequent feature updates to Threejs?
35
+
36
+ Yes. It merely expresses Threejs in JSX, `<mesh />` dynamically turns into `new THREE.Mesh()`. If a new Threejs version adds, removes or changes features, it will be available to you instantly without depending on updates to this library.
37
+
38
+ #### Does it support WebGPU?
39
+
40
+ Yes. With minor changes in v9 and significant work in v10 WebGPU support is first class. We support all ThreeJS WebGPU features/Nodes and expand it with our own hooks and utilities.
41
+
42
+ ### What does it look like?
43
+
44
+ <table>
45
+ <tbody>
46
+ <tr>
47
+ <td>Let's make a re-usable component that has its own state, reacts to user-input and participates in the render-loop. (<a href="https://codesandbox.io/s/rrppl0y8l4?file=/src/App.js">live demo</a>).</td>
48
+ <td>
49
+ <a href="https://codesandbox.io/s/rrppl0y8l4">
50
+ <img src="/docs/basic-app.gif" />
51
+ </a>
52
+ </td>
53
+ </tr>
54
+ </tbody>
55
+ </table>
56
+
57
+ ```jsx
58
+ import { createRoot } from 'react-dom/client'
59
+ import React, { useRef, useState } from 'react'
60
+ import { Canvas, useFrame } from '@react-three/fiber'
61
+
62
+ function Box(props) {
63
+ // This reference gives us direct access to the THREE.Mesh object
64
+ const ref = useRef()
65
+ // Hold state for hovered and clicked events
66
+ const [hovered, hover] = useState(false)
67
+ const [clicked, click] = useState(false)
68
+ // Subscribe this component to the render-loop, rotate the mesh every frame
69
+ useFrame(({ delta }) => (ref.current.rotation.x += delta))
70
+ // Return the view, these are regular Threejs elements expressed in JSX
71
+ return (
72
+ <mesh
73
+ {...props}
74
+ ref={ref}
75
+ scale={clicked ? 1.5 : 1}
76
+ onClick={(event) => click(!clicked)}
77
+ onPointerOver={(event) => hover(true)}
78
+ onPointerOut={(event) => hover(false)}>
79
+ <boxGeometry args={[1, 1, 1]} />
80
+ <meshStandardMaterial color={hovered ? 'hotpink' : 'orange'} />
81
+ </mesh>
82
+ )
83
+ }
84
+
85
+ createRoot(document.getElementById('root')).render(
86
+ <Canvas>
87
+ <ambientLight intensity={Math.PI / 2} />
88
+ <spotLight position={[10, 10, 10]} angle={0.15} penumbra={1} decay={0} intensity={Math.PI} />
89
+ <pointLight position={[-10, -10, -10]} decay={0} intensity={Math.PI} />
90
+ <Box position={[-1.2, 0, 0]} />
91
+ <Box position={[1.2, 0, 0]} />
92
+ </Canvas>,
93
+ )
94
+ ```
95
+
96
+ <details>
97
+ <summary>Show TypeScript example</summary>
98
+
99
+ ```bash
100
+ npm install @types/three
101
+ ```
102
+
103
+ ```tsx
104
+ import * as THREE from 'three'
105
+ import { createRoot } from 'react-dom/client'
106
+ import React, { useRef, useState } from 'react'
107
+ import { Canvas, useFrame, ThreeElements } from '@react-three/fiber'
108
+
109
+ function Box(props: ThreeElements['mesh']) {
110
+ const ref = useRef<THREE.Mesh>(null!)
111
+ const [hovered, hover] = useState(false)
112
+ const [clicked, click] = useState(false)
113
+ useFrame((state, delta) => (ref.current.rotation.x += delta))
114
+ return (
115
+ <mesh
116
+ {...props}
117
+ ref={ref}
118
+ scale={clicked ? 1.5 : 1}
119
+ onClick={(event) => click(!clicked)}
120
+ onPointerOver={(event) => hover(true)}
121
+ onPointerOut={(event) => hover(false)}>
122
+ <boxGeometry args={[1, 1, 1]} />
123
+ <meshStandardMaterial color={hovered ? 'hotpink' : 'orange'} />
124
+ </mesh>
125
+ )
126
+ }
127
+
128
+ createRoot(document.getElementById('root') as HTMLElement).render(
129
+ <Canvas>
130
+ <ambientLight intensity={Math.PI / 2} />
131
+ <spotLight position={[10, 10, 10]} angle={0.15} penumbra={1} decay={0} intensity={Math.PI} />
132
+ <pointLight position={[-10, -10, -10]} decay={0} intensity={Math.PI} />
133
+ <Box position={[-1.2, 0, 0]} />
134
+ <Box position={[1.2, 0, 0]} />
135
+ </Canvas>,
136
+ )
137
+ ```
138
+
139
+ TODO: Move this
140
+ Live demo: https://codesandbox.io/s/icy-tree-brnsm?file=/src/App.tsx
141
+
142
+ </details>
143
+
144
+ <details>
145
+ <summary>Show React Native example</summary>
146
+
147
+ This example relies on react 18 and uses `expo-cli`, but you can create a bare project with their template or with the `react-native` CLI.
148
+
149
+ ```bash
150
+ # Install expo-cli, this will create our app
151
+ npm install expo-cli -g
152
+ # Create app and cd into it
153
+ expo init my-app
154
+ cd my-app
155
+ # Install dependencies
156
+ npm install three @react-three/fiber@beta react@rc
157
+ # Start
158
+ expo start
159
+ ```
160
+
161
+ Some configuration may be required to tell the Metro bundler about your assets if you use `useLoader` or Drei abstractions like `useGLTF` and `useTexture`:
162
+
163
+ ```js
164
+ // metro.config.js
165
+ module.exports = {
166
+ resolver: {
167
+ sourceExts: ['js', 'jsx', 'json', 'ts', 'tsx', 'cjs'],
168
+ assetExts: ['glb', 'png', 'jpg'],
169
+ },
170
+ }
171
+ ```
172
+
173
+ ```tsx
174
+ import React, { useRef, useState } from 'react'
175
+ import { Canvas, useFrame } from '@react-three/fiber/native'
176
+ function Box(props) {
177
+ const mesh = useRef(null)
178
+ const [hovered, setHover] = useState(false)
179
+ const [active, setActive] = useState(false)
180
+ useFrame((state, delta) => (mesh.current.rotation.x += delta))
181
+ return (
182
+ <mesh
183
+ {...props}
184
+ ref={mesh}
185
+ scale={active ? 1.5 : 1}
186
+ onClick={(event) => setActive(!active)}
187
+ onPointerOver={(event) => setHover(true)}
188
+ onPointerOut={(event) => setHover(false)}>
189
+ <boxGeometry args={[1, 1, 1]} />
190
+ <meshStandardMaterial color={hovered ? 'hotpink' : 'orange'} />
191
+ </mesh>
192
+ )
193
+ }
194
+ export default function App() {
195
+ return (
196
+ <Canvas>
197
+ <ambientLight intensity={Math.PI / 2} />
198
+ <spotLight position={[10, 10, 10]} angle={0.15} penumbra={1} decay={0} intensity={Math.PI} />
199
+ <pointLight position={[-10, -10, -10]} decay={0} intensity={Math.PI} />
200
+ <Box position={[-1.2, 0, 0]} />
201
+ <Box position={[1.2, 0, 0]} />
202
+ </Canvas>
203
+ )
204
+ }
205
+ ```
206
+
207
+ </details>
208
+
209
+ ---
210
+
211
+ # Documentation, tutorials, examples
212
+
213
+ Visit [docs.pmnd.rs](https://docs.pmnd.rs/react-three-fiber) | [Awesome React Three Fiber](AwesomeR3F.md)
214
+
215
+ # First steps
216
+
217
+ You need to be versed in both React and Threejs before rushing into this. If you are unsure about React consult the official [React docs](https://react.dev/learn), especially [the section about hooks](https://react.dev/reference/react). As for Threejs, make sure you at least glance over the following links:
218
+
219
+ 1. Make sure you have a [basic grasp of Threejs](https://threejs.org/docs/index.html#manual/en/introduction/Creating-a-scene). Keep that site open.
220
+ 2. When you know what a scene is, a camera, mesh, geometry, material, fork the [demo above](https://github.com/pmndrs/react-three-fiber#what-does-it-look-like).
221
+ 3. [Look up](https://threejs.org/docs/index.html#api/en/objects/Mesh) the JSX elements that you see (mesh, ambientLight, etc), _all_ threejs exports are native to three-fiber.
222
+ 4. Try changing some values, scroll through our [API](https://docs.pmnd.rs/react-three-fiber) to see what the various settings and hooks do.
223
+
224
+ # How to contribute
225
+
226
+ See the [Development Guide](docs/development/README.md) for setup, workflow, and [contributing standards](docs/development/CONTRIBUTING.md).
227
+
228
+ All contributions are welcome as well as donations to [Open Collective](https://opencollective.com/pmndrs).
229
+
230
+ #### Backers
231
+
232
+ Thank you to all our backers! 🙏
233
+
234
+ <a href="https://opencollective.com/pmndrsr#backers" target="_blank">
235
+ <img src="https://opencollective.com/pmndrs/backers.svg?width=890"/>
236
+ </a>
237
+
238
+ #### Contributors
239
+
240
+ This project exists thanks to all the people who contribute.
241
+
242
+ <a href="https://github.com/pmndrs/react-three-fiber/graphs/contributors">
243
+ <img src="https://opencollective.com/react-three-fiber/contributors.svg?width=890" />
244
+ </a>