@react-three/fiber 9.4.2 → 10.0.0-alpha.0

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.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.cjs +14832 -0
  3. package/dist/index.d.cts +3350 -0
  4. package/dist/index.d.mts +3350 -0
  5. package/dist/index.d.ts +3350 -0
  6. package/dist/index.mjs +14747 -0
  7. package/dist/legacy.cjs +14820 -0
  8. package/dist/legacy.d.cts +3347 -0
  9. package/dist/legacy.d.mts +3347 -0
  10. package/dist/legacy.d.ts +3347 -0
  11. package/dist/legacy.mjs +14735 -0
  12. package/dist/webgpu/index.cjs +15274 -0
  13. package/dist/webgpu/index.d.cts +3470 -0
  14. package/dist/webgpu/index.d.mts +3470 -0
  15. package/dist/webgpu/index.d.ts +3470 -0
  16. package/dist/webgpu/index.mjs +15177 -0
  17. package/package.json +44 -44
  18. package/react-reconciler/constants.d.ts +7 -0
  19. package/react-reconciler/constants.js +9 -0
  20. package/react-reconciler/index.d.ts +1044 -0
  21. package/react-reconciler/index.js +224 -0
  22. package/readme.md +98 -33
  23. package/CHANGELOG.md +0 -1186
  24. package/dist/declarations/src/core/events.d.ts +0 -92
  25. package/dist/declarations/src/core/hooks.d.ts +0 -53
  26. package/dist/declarations/src/core/index.d.ts +0 -13
  27. package/dist/declarations/src/core/loop.d.ts +0 -31
  28. package/dist/declarations/src/core/reconciler.d.ts +0 -50
  29. package/dist/declarations/src/core/renderer.d.ts +0 -89
  30. package/dist/declarations/src/core/store.d.ts +0 -130
  31. package/dist/declarations/src/core/utils.d.ts +0 -191
  32. package/dist/declarations/src/index.d.ts +0 -6
  33. package/dist/declarations/src/native/Canvas.d.ts +0 -13
  34. package/dist/declarations/src/native/events.d.ts +0 -4
  35. package/dist/declarations/src/native.d.ts +0 -6
  36. package/dist/declarations/src/three-types.d.ts +0 -68
  37. package/dist/declarations/src/web/Canvas.d.ts +0 -23
  38. package/dist/declarations/src/web/events.d.ts +0 -4
  39. package/dist/events-1eccaf1c.esm.js +0 -2510
  40. package/dist/events-5c8d1731.cjs.prod.js +0 -2569
  41. package/dist/events-c80effae.cjs.dev.js +0 -2569
  42. package/dist/react-three-fiber.cjs.d.ts +0 -2
  43. package/dist/react-three-fiber.cjs.dev.js +0 -222
  44. package/dist/react-three-fiber.cjs.js +0 -7
  45. package/dist/react-three-fiber.cjs.prod.js +0 -222
  46. package/dist/react-three-fiber.esm.js +0 -167
  47. package/native/dist/react-three-fiber-native.cjs.d.ts +0 -2
  48. package/native/dist/react-three-fiber-native.cjs.dev.js +0 -569
  49. package/native/dist/react-three-fiber-native.cjs.js +0 -7
  50. package/native/dist/react-three-fiber-native.cjs.prod.js +0 -569
  51. package/native/dist/react-three-fiber-native.esm.js +0 -517
  52. package/native/package.json +0 -5
package/readme.md CHANGED
@@ -1,21 +1,28 @@
1
- <h1>react-three-fiber</h1>
1
+ <h1>@react-three/fiber</h1>
2
2
 
3
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)
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
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
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
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
8
  [![ETH](https://img.shields.io/badge/ETH-f5f5f5?style=flat&colorA=000000&colorB=000000)](https://blockchain.com/eth/address/0x6E3f79Ea1d0dcedeb33D3fC6c34d2B1f156F2682)
9
9
  [![BTC](https://img.shields.io/badge/BTC-f5f5f5?style=flat&colorA=000000&colorB=000000)](https://blockchain.com/btc/address/36fuguTPxGCNnYZSRdgdh6Ea94brCAjMbH)
10
10
 
11
+ <a href="https://docs.pmnd.rs/react-three-fiber/getting-started/examples"><img src="docs/banner-r3f.jpg" /></a>
12
+
11
13
  react-three-fiber is a <a href="https://reactjs.org/docs/codebase-overview.html#renderers">React renderer</a> for threejs.
12
14
 
13
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.
14
16
 
15
17
  ```bash
16
- npm install three @react-three/fiber
18
+ yarn install three @types/three @react-three/fiber
17
19
  ```
18
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
+
19
26
  #### Does it have limitations?
20
27
 
21
28
  None. Everything that works in Threejs will work here without exception.
@@ -26,7 +33,7 @@ No. There is no overhead. Components render outside of React. It outperforms Thr
26
33
 
27
34
  #### Can it keep up with frequent feature updates to Threejs?
28
35
 
29
- Yes. It merely expresses Threejs in JSX: `<mesh />` becomes `new THREE.Mesh()`, and that happens dynamically. If a new Threejs version adds, removes or changes features, it will be available to you instantly without depending on updates to this library.
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.
30
37
 
31
38
  ### What does it look like?
32
39
 
@@ -36,7 +43,7 @@ Yes. It merely expresses Threejs in JSX: `<mesh />` becomes `new THREE.Mesh()`,
36
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>
37
44
  <td>
38
45
  <a href="https://codesandbox.io/s/rrppl0y8l4">
39
- <img src="https://i.imgur.com/sS4ArrZ.gif" />
46
+ <img src="/docs/basic-app.gif" />
40
47
  </a>
41
48
  </td>
42
49
  </tr>
@@ -55,7 +62,7 @@ function Box(props) {
55
62
  const [hovered, hover] = useState(false)
56
63
  const [clicked, click] = useState(false)
57
64
  // Subscribe this component to the render-loop, rotate the mesh every frame
58
- useFrame((state, delta) => (ref.current.rotation.x += delta))
65
+ useFrame(({ delta }) => (ref.current.rotation.x += delta))
59
66
  // Return the view, these are regular Threejs elements expressed in JSX
60
67
  return (
61
68
  <mesh
@@ -73,8 +80,9 @@ function Box(props) {
73
80
 
74
81
  createRoot(document.getElementById('root')).render(
75
82
  <Canvas>
76
- <ambientLight />
77
- <pointLight position={[10, 10, 10]} />
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} />
78
86
  <Box position={[-1.2, 0, 0]} />
79
87
  <Box position={[1.2, 0, 0]} />
80
88
  </Canvas>,
@@ -83,7 +91,7 @@ createRoot(document.getElementById('root')).render(
83
91
 
84
92
  <details>
85
93
  <summary>Show TypeScript example</summary>
86
-
94
+
87
95
  ```bash
88
96
  npm install @types/three
89
97
  ```
@@ -115,14 +123,16 @@ function Box(props: ThreeElements['mesh']) {
115
123
 
116
124
  createRoot(document.getElementById('root') as HTMLElement).render(
117
125
  <Canvas>
118
- <ambientLight />
119
- <pointLight position={[10, 10, 10]} />
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} />
120
129
  <Box position={[-1.2, 0, 0]} />
121
130
  <Box position={[1.2, 0, 0]} />
122
131
  </Canvas>,
123
132
  )
124
133
  ```
125
134
 
135
+ TODO: Move this
126
136
  Live demo: https://codesandbox.io/s/icy-tree-brnsm?file=/src/App.tsx
127
137
 
128
138
  </details>
@@ -139,7 +149,7 @@ npm install expo-cli -g
139
149
  expo init my-app
140
150
  cd my-app
141
151
  # Install dependencies
142
- npm install three @react-three/fiber react
152
+ npm install three @react-three/fiber@beta react@rc
143
153
  # Start
144
154
  expo start
145
155
  ```
@@ -180,8 +190,9 @@ function Box(props) {
180
190
  export default function App() {
181
191
  return (
182
192
  <Canvas>
183
- <ambientLight />
184
- <pointLight position={[10, 10, 10]} />
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} />
185
196
  <Box position={[-1.2, 0, 0]} />
186
197
  <Box position={[1.2, 0, 0]} />
187
198
  </Canvas>
@@ -197,51 +208,105 @@ export default function App() {
197
208
 
198
209
  Visit [docs.pmnd.rs](https://docs.pmnd.rs/react-three-fiber)
199
210
 
200
- <a href="https://docs.pmnd.rs/react-three-fiber"><img src="/docs/preview.jpg"></a>
201
-
202
- # Fundamentals
211
+ # First steps
203
212
 
204
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:
205
214
 
206
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.
207
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).
208
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.
209
- 4. Try changing some values, scroll through our [API](https://docs.pmnd.rs/react-three-fiber/API) to see what the various settings and hooks do.
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:
210
221
 
211
- Some reading material:
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)
212
225
 
213
- - [Threejs-docs](https://threejs.org/docs)
214
- - [Threejs-examples](https://threejs.org/examples)
215
- - [Threejs-fundamentals](https://threejs.org/manual/#en/fundamentals)
216
- - [three.js-journey](https://threejs-journey.com)
217
- - [Discover Threejs](https://discoverthreejs.com)
218
- - [Do's and don'ts](https://discoverthreejs.com/tips-and-tricks) for performance and best practices
219
- - [react-three-fiber alligator.io tutorial](https://alligator.io/react/react-with-threejs) by [@dghez\_](https://twitter.com/dghez_)
226
+ <a href="https://threejs-journey.com"><img src="docs/banner-journey.jpg" /></a>
220
227
 
221
228
  # Ecosystem
222
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
223
233
  - [`@react-three/gltfjsx`](https://github.com/pmndrs/gltfjsx) &ndash; turns GLTFs into JSX components
224
- - [`@react-three/drei`](https://github.com/pmndrs/drei) &ndash; useful helpers for react-three-fiber
225
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
226
238
  - [`@react-three/flex`](https://github.com/pmndrs/react-three-flex) &ndash; flexbox for react-three-fiber
227
239
  - [`@react-three/xr`](https://github.com/pmndrs/react-xr) &ndash; VR/AR controllers and events
228
- - [`@react-three/cannon`](https://github.com/pmndrs/use-cannon) &ndash; physics based hooks
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
229
244
  - [`@react-three/a11y`](https://github.com/pmndrs/react-three-a11y) &ndash; real a11y for your scene
230
- - [`zustand`](https://github.com/pmndrs/zustand) &ndash; state management
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
231
251
  - [`react-spring`](https://github.com/pmndrs/react-spring) &ndash; a spring-physics-based animation library
232
- - [`react-use-gesture`](https://github.com/pmndrs/react-use-gesture) &ndash; mouse/touch gestures
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
233
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)
234
285
 
235
286
  # How to contribute
236
287
 
237
- If you like this project, please consider helping out. All contributions are welcome as well as donations to [Opencollective](https://opencollective.com/react-three-fiber), or in crypto `BTC: 36fuguTPxGCNnYZSRdgdh6Ea94brCAjMbH`, `ETH: 0x6E3f79Ea1d0dcedeb33D3fC6c34d2B1f156F2682`.
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
+ ```
238
303
 
239
304
  #### Backers
240
305
 
241
306
  Thank you to all our backers! 🙏
242
307
 
243
- <a href="https://opencollective.com/react-three-fiber#backers" target="_blank">
244
- <img src="https://opencollective.com/react-three-fiber/backers.svg?width=890"/>
308
+ <a href="https://opencollective.com/pmndrsr#backers" target="_blank">
309
+ <img src="https://opencollective.com/pmndrs/backers.svg?width=890"/>
245
310
  </a>
246
311
 
247
312
  #### Contributors