@react-three/drei 8.19.5 → 9.0.0-beta.3
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/README.md +62 -329
- package/core/ArcballControls.cjs.js +1 -1
- package/core/ArcballControls.js +27 -18
- package/core/Billboard.d.ts +2 -2
- package/core/Bounds.cjs.js +1 -1
- package/core/Bounds.d.ts +1 -2
- package/core/Bounds.js +15 -26
- package/core/Center.d.ts +1 -1
- package/core/Cloud.cjs.js +1 -1
- package/core/Cloud.d.ts +1 -3
- package/core/Cloud.js +1 -4
- package/core/ContactShadows.cjs.js +1 -1
- package/core/ContactShadows.d.ts +1 -3
- package/core/ContactShadows.js +2 -15
- package/core/CubeCamera.cjs.js +1 -1
- package/core/CubeCamera.js +7 -7
- package/core/Detailed.d.ts +2 -2
- package/core/DeviceOrientationControls.cjs.js +1 -1
- package/core/DeviceOrientationControls.d.ts +1 -1
- package/core/DeviceOrientationControls.js +6 -2
- package/core/Effects.cjs.js +1 -1
- package/core/Effects.d.ts +2 -2
- package/core/Effects.js +2 -2
- package/core/Environment.cjs.js +1 -1
- package/core/Environment.d.ts +3 -13
- package/core/Environment.js +30 -95
- package/core/FirstPersonControls.cjs.js +1 -1
- package/core/FirstPersonControls.d.ts +1 -1
- package/core/FirstPersonControls.js +6 -2
- package/core/Float.cjs.js +1 -1
- package/core/Float.d.ts +1 -1
- package/core/Float.js +4 -5
- package/core/FlyControls.d.ts +1 -1
- package/core/GizmoHelper.cjs.js +1 -1
- package/core/GizmoHelper.d.ts +1 -2
- package/core/GizmoHelper.js +41 -31
- package/core/GizmoViewcube.cjs.js +1 -1
- package/core/GizmoViewcube.d.ts +2 -2
- package/core/GizmoViewcube.js +1 -1
- package/core/GizmoViewport.d.ts +2 -2
- package/core/Image.cjs.js +1 -1
- package/core/Image.d.ts +2 -4
- package/core/Image.js +1 -6
- package/core/Instances.cjs.js +1 -1
- package/core/Instances.d.ts +3 -3
- package/core/Instances.js +11 -5
- package/core/Line.d.ts +1 -1
- package/core/MapControls.d.ts +1 -1
- package/core/MeshDistortMaterial.d.ts +2 -4
- package/core/MeshReflectorMaterial.cjs.js +1 -1
- package/core/MeshReflectorMaterial.d.ts +2 -1
- package/core/MeshReflectorMaterial.js +5 -4
- package/core/MeshWobbleMaterial.d.ts +2 -4
- package/core/OrbitControls.cjs.js +1 -1
- package/core/OrbitControls.js +33 -23
- package/core/OrthographicCamera.d.ts +2 -2
- package/core/PerspectiveCamera.d.ts +2 -2
- package/core/PointMaterial.cjs.js +1 -1
- package/core/PointMaterial.d.ts +7 -3
- package/core/PointMaterial.js +32 -14
- package/core/PointerLockControls.cjs.js +1 -1
- package/core/PointerLockControls.d.ts +1 -3
- package/core/PointerLockControls.js +22 -36
- package/core/Points.cjs.js +1 -1
- package/core/Points.d.ts +3 -3
- package/core/Points.js +36 -17
- package/core/PositionalAudio.d.ts +2 -2
- package/core/Reflector.d.ts +1 -1
- package/core/RoundedBox.d.ts +1 -1
- package/core/ScreenQuad.d.ts +1 -1
- package/core/Segments.d.ts +1 -1
- package/core/Shadow.d.ts +2 -2
- package/core/SpotLight.d.ts +20 -4
- package/core/Stage.cjs.js +1 -1
- package/core/Stage.js +2 -1
- package/core/Stars.cjs.js +1 -1
- package/core/Stars.js +3 -6
- package/core/Text.cjs.js +1 -1
- package/core/Text.d.ts +2 -3
- package/core/Text.js +2 -3
- package/core/TrackballControls.cjs.js +1 -1
- package/core/TrackballControls.d.ts +1 -1
- package/core/TrackballControls.js +7 -12
- package/core/TransformControls.cjs.js +1 -1
- package/core/TransformControls.d.ts +1 -1
- package/core/TransformControls.js +13 -7
- package/core/index.cjs.js +1 -1
- package/core/index.d.ts +0 -6
- package/core/index.js +2 -9
- package/core/shapes.d.ts +17 -17
- package/core/useFBO.cjs.js +1 -1
- package/core/useFBO.d.ts +1 -1
- package/core/useFBO.js +24 -21
- package/core/useFBX.d.ts +1 -1
- package/core/useFBX.js +1 -2
- package/core/useGLTF.d.ts +1 -1
- package/core/useGLTF.js +1 -2
- package/core/useHelper.d.ts +1 -3
- package/core/useKTX2.d.ts +1 -1
- package/core/useKTX2.js +1 -2
- package/core/useTexture.d.ts +1 -1
- package/core/useTexture.js +1 -2
- package/index.cjs.js +1 -1
- package/index.js +1 -7
- package/materials/ConvolutionMaterial.cjs.js +1 -1
- package/materials/ConvolutionMaterial.js +0 -2
- package/materials/MeshReflectorMaterial.cjs.js +1 -1
- package/materials/MeshReflectorMaterial.d.ts +3 -0
- package/materials/MeshReflectorMaterial.js +27 -1
- package/materials/SpotLightMaterial.cjs.js +1 -1
- package/materials/SpotLightMaterial.js +0 -3
- package/native/index.cjs.js +1 -1
- package/native/index.js +2 -9
- package/package.json +8 -9
- package/web/Html.cjs.js +1 -1
- package/web/Html.js +7 -6
- package/web/ScrollControls.cjs.js +1 -1
- package/web/ScrollControls.js +5 -4
- package/web/Select.js +0 -1
- package/web/index.cjs.js +1 -1
- package/web/index.js +3 -10
- package/core/Clone.cjs.js +0 -1
- package/core/Clone.d.ts +0 -11
- package/core/Clone.js +0 -92
- package/core/ComputedAttribute.cjs.js +0 -1
- package/core/ComputedAttribute.d.ts +0 -9
- package/core/ComputedAttribute.js +0 -34
- package/core/Lightformer.cjs.js +0 -1
- package/core/Lightformer.d.ts +0 -41
- package/core/Lightformer.js +0 -51
- package/core/Sampler.cjs.js +0 -1
- package/core/Sampler.d.ts +0 -21
- package/core/Sampler.js +0 -65
- package/core/Trail.cjs.js +0 -1
- package/core/Trail.d.ts +0 -20
- package/core/Trail.js +0 -160
- package/core/useBoxProjectedEnv.cjs.js +0 -1
- package/core/useBoxProjectedEnv.d.ts +0 -8
- package/core/useBoxProjectedEnv.js +0 -98
package/README.md
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/@react-three/drei)
|
|
5
5
|
[](https://discord.gg/poimandres)
|
|
6
6
|
|
|
7
|
-
A growing collection of useful helpers and fully functional, ready-made abstractions for [react-three
|
|
7
|
+
A growing collection of useful helpers and fully functional, ready-made abstractions for [@react-three/fiber](https://github.com/pmndrs/react-three-fiber). If you make a component that is generic enough to be useful to others, think about making it available here through a PR!
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
npm install @react-three/drei
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
:point_right: this package is using the stand-alone [`three-stdlib`](https://github.com/pmndrs/three-stdlib) instead of [`three/examples/jsm`](https://github.com/mrdoob/three.js/tree/
|
|
13
|
+
:point_right: this package is using the stand-alone [`three-stdlib`](https://github.com/pmndrs/three-stdlib) instead of [`three/examples/jsm`](https://github.com/mrdoob/three.js/tree/master/examples/jsm). :point_left:
|
|
14
14
|
|
|
15
15
|
### Basic usage:
|
|
16
16
|
|
|
@@ -65,10 +65,6 @@ The `native` route of the library **does not** export `Html` or `Loader`. The de
|
|
|
65
65
|
<li><a href="#effects">Effects</a></li>
|
|
66
66
|
<li><a href="#gradienttexture">GradientTexture</a></li>
|
|
67
67
|
<li><a href="#edges">Edges</a></li>
|
|
68
|
-
<li><a href="#trail">Trail</a></li>
|
|
69
|
-
<li><a href="#sampler">Sampler</a></li>
|
|
70
|
-
<li><a href="#computedattribute">Computed Attribute</a></li>
|
|
71
|
-
<li><a href="#clone">Clone</a></li>
|
|
72
68
|
<li><a href="#useanimations">useAnimations</a></li>
|
|
73
69
|
</ul>
|
|
74
70
|
<li><a href="#shaders">Shaders</a></li>
|
|
@@ -103,8 +99,6 @@ The `native` route of the library **does not** export `Html` or `Loader`. The de
|
|
|
103
99
|
<li><a href="#useaspect">useAspect</a></li>
|
|
104
100
|
<li><a href="#usecursor">useCursor</a></li>
|
|
105
101
|
<li><a href="#useintersect">useIntersect</a></li>
|
|
106
|
-
<li><a href="#useboxprojectedenv">useBoxProjectedEnv</a></li>
|
|
107
|
-
<li><a href="#useTrail">useTrail</a></li>
|
|
108
102
|
</ul>
|
|
109
103
|
<li><a href="#loading">Loaders</a></li>
|
|
110
104
|
<ul>
|
|
@@ -165,7 +159,6 @@ The `native` route of the library **does not** export `Html` or `Loader`. The de
|
|
|
165
159
|
<li><a href="#stage">Stage</a></li>
|
|
166
160
|
<li><a href="#backdrop">Backdrop</a></li>
|
|
167
161
|
<li><a href="#environment">Environment</a></li>
|
|
168
|
-
<li><a href="#lightformer">Lightformer</a></li>
|
|
169
162
|
<li><a href="#spotlight">SpotLight</a></li>
|
|
170
163
|
<li><a href="#shadow">Shadow</a></li>
|
|
171
164
|
<li><a href="#contactshadows">ContactShadows</a></li>
|
|
@@ -186,7 +179,7 @@ The `native` route of the library **does not** export `Html` or `Loader`. The de
|
|
|
186
179
|
|
|
187
180
|
[](https://drei.vercel.app/?path=/story/camera-perspectivecamera--perspective-camera-scene-st)
|
|
188
181
|
|
|
189
|
-
A responsive [THREE.PerspectiveCamera](https://threejs.org/docs
|
|
182
|
+
A responsive [THREE.PerspectiveCamera](https://threejs.org/docs/#api/en/cameras/PerspectiveCamera) that can set itself as the default.
|
|
190
183
|
|
|
191
184
|
```jsx
|
|
192
185
|
<PerspectiveCamera makeDefault {...props} />
|
|
@@ -211,7 +204,7 @@ You can also drive it manually, it won't be responsive and you have to calculate
|
|
|
211
204
|
|
|
212
205
|
[](https://drei.vercel.app/?path=/story/camera-orthographiccamera--orthographic-camera-scene-st)
|
|
213
206
|
|
|
214
|
-
A responsive [THREE.OrthographicCamera](https://threejs.org/docs
|
|
207
|
+
A responsive [THREE.OrthographicCamera](https://threejs.org/docs/#api/en/cameras/OrthographicCamera) that can set itself as the default.
|
|
215
208
|
|
|
216
209
|
```jsx
|
|
217
210
|
<OrthographicCamera makeDefault {...props}>
|
|
@@ -223,7 +216,7 @@ A responsive [THREE.OrthographicCamera](https://threejs.org/docs/index.html#api/
|
|
|
223
216
|
|
|
224
217
|
[](https://drei.pmnd.rs/?path=/story/camera-cubecamera--default-story)
|
|
225
218
|
|
|
226
|
-
A [THREE.CubeCamera](https://threejs.org/docs
|
|
219
|
+
A [THREE.CubeCamera](https://threejs.org/docs/#api/en/cameras/CubeCamera) that returns its texture as a render-prop. It makes children invisible while rendering to the internal buffer so that they are not included in the reflection.
|
|
227
220
|
|
|
228
221
|
Using the `frames` prop you can control if this camera renders indefinitively or statically (a given number of times).
|
|
229
222
|
If you have two static objects in the scene, make it `frames={2}` for instance, so that both objects get to "see" one another in the reflections, which takes multiple renders.
|
|
@@ -242,15 +235,15 @@ If you have moving objects, unset the prop and use a smaller `resolution` instea
|
|
|
242
235
|
|
|
243
236
|
# Controls
|
|
244
237
|
|
|
245
|
-
If available controls have damping enabled by default, they manage their own updates, remove themselves on unmount, are compatible with the `invalidateFrameloop` canvas-flag. They inherit all props from their underlying [THREE controls](https://github.com/mrdoob/three.js/tree/
|
|
238
|
+
If available controls have damping enabled by default, they manage their own updates, remove themselves on unmount, are compatible with the `invalidateFrameloop` canvas-flag. They inherit all props from their underlying [THREE controls](https://github.com/mrdoob/three.js/tree/master/examples/jsm/controls).
|
|
246
239
|
|
|
247
|
-
Some controls allow you to set `makeDefault`, similar to, for instance, PerspectiveCamera. This will set react-three
|
|
240
|
+
Some controls allow you to set `makeDefault`, similar to, for instance, PerspectiveCamera. This will set @react-three/fiber's `controls` field in the root store. This can make it easier in situations where you want controls to be known and other parts of the app could respond to it. Some drei controls already take it into account, like CameraShake, Gizmo and TransformControls.
|
|
248
241
|
|
|
249
242
|
Drei currently exports OrbitControls [](https://drei.vercel.app/?path=/story/controls-orbitcontrols--orbit-controls-story), MapControls [](https://drei.vercel.app/?path=/story/controls-mapcontrols--map-controls-scene-st), TrackballControls, ArcballControls, FlyControls, DeviceOrientationControls, PointerLockControls [](https://drei.vercel.app/?path=/story/controls-pointerlockcontrols--pointer-lock-controls-scene-st), FirstPersonControls [](https://drei.vercel.app/?path=/story/controls-firstpersoncontrols--first-person-controls-story)
|
|
250
243
|
|
|
251
244
|
All controls react to the default camera. If you have a `<PerspectiveCamera makeDefault />` in your scene, they will control it. If you need to inject an imperative camera or one that isn't the default, use the `camera` prop: `<OrbitControls camera={MyCamera} />`.
|
|
252
245
|
|
|
253
|
-
PointerLockControls additionally supports a `selector` prop, which enables the binding of `click` event handlers for control activation to other elements than `document` (e.g. a 'Click here to play' button). All elements matching the `selector` prop will activate the controls.
|
|
246
|
+
PointerLockControls additionally supports a `selector` prop, which enables the binding of `click` event handlers for control activation to other elements than `document` (e.g. a 'Click here to play' button). All elements matching the `selector` prop will activate the controls.
|
|
254
247
|
|
|
255
248
|
# TransformControls
|
|
256
249
|
|
|
@@ -260,7 +253,7 @@ PointerLockControls additionally supports a `selector` prop, which enables the b
|
|
|
260
253
|
<a href="https://codesandbox.io/s/btsbj"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/btsbj/screenshot.png" alt="Tranform controls"/></a>
|
|
261
254
|
</p>
|
|
262
255
|
|
|
263
|
-
An abstraction around [THREE.TransformControls](https://threejs.org/docs
|
|
256
|
+
An abstraction around [THREE.TransformControls](https://threejs.org/docs/#examples/en/controls/TransformControls).
|
|
264
257
|
|
|
265
258
|
You can wrap objects which then receive a transform gizmo.
|
|
266
259
|
|
|
@@ -371,7 +364,7 @@ Semi-OrbitControls with spring-physics, polar zoom and snap-back, for presentati
|
|
|
371
364
|
rotation={[0, 0, 0]} // Default rotation
|
|
372
365
|
polar={[0, Math.PI / 2]} // Vertical limits
|
|
373
366
|
azimuth={[-Infinity, Infinity]} // Horizontal limits
|
|
374
|
-
config={
|
|
367
|
+
config = { mass: 1, tension: 170, friction: 26 } // Spring config
|
|
375
368
|
>
|
|
376
369
|
<mesh />
|
|
377
370
|
</PresentationControls>
|
|
@@ -379,12 +372,12 @@ Semi-OrbitControls with spring-physics, polar zoom and snap-back, for presentati
|
|
|
379
372
|
|
|
380
373
|
# Shapes
|
|
381
374
|
|
|
382
|
-
[Buffer-geometry](https://threejs.org/docs
|
|
375
|
+
[Buffer-geometry](https://threejs.org/docs/#api/en/core/BufferGeometry) short-cuts for Plane, Box, Sphere, Circle, Cone, Cylinder, Tube, Torus, TorusKnot, Ring, Tetrahedron, Polyhedron, Icosahedron, Octahedron, Dodecahedron, Extrude, Lathe.
|
|
383
376
|
|
|
384
377
|
```jsx
|
|
385
378
|
<Plane args={[2, 2]} />
|
|
386
379
|
<Sphere>
|
|
387
|
-
<meshBasicMaterial
|
|
380
|
+
<meshBasicMaterial color="hotpink" />
|
|
388
381
|
</Sphere>
|
|
389
382
|
```
|
|
390
383
|
|
|
@@ -394,7 +387,7 @@ A box buffer geometry with rounded corners, done with extrusion.
|
|
|
394
387
|
|
|
395
388
|
```jsx
|
|
396
389
|
<RoundedBox args={[1, 1, 1]} radius={0.05} smoothness={4} {...meshProps}>
|
|
397
|
-
<meshPhongMaterial
|
|
390
|
+
<meshPhongMaterial color="#f3f3f3" wireframe />
|
|
398
391
|
</RoundedBox>
|
|
399
392
|
```
|
|
400
393
|
|
|
@@ -442,7 +435,7 @@ function Foo() {
|
|
|
442
435
|
<a href="https://codesandbox.io/s/yup2o"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/yup2o/screenshot.png" alt="Demo"/></a>
|
|
443
436
|
</p>
|
|
444
437
|
|
|
445
|
-
Hi-quality text rendering w/ signed distance fields (SDF) and antialiasing, using [troika-3d-text](https://github.com/protectwise/troika/tree/master/packages/troika-3d-text). All of troikas props are valid!
|
|
438
|
+
Hi-quality text rendering w/ signed distance fields (SDF) and antialiasing, using [troika-3d-text](https://github.com/protectwise/troika/tree/master/packages/troika-3d-text). All of troikas props are valid! Text is suspense-based!
|
|
446
439
|
|
|
447
440
|
```jsx
|
|
448
441
|
<Text color="black" anchorX="center" anchorY="middle">
|
|
@@ -450,14 +443,6 @@ Hi-quality text rendering w/ signed distance fields (SDF) and antialiasing, usin
|
|
|
450
443
|
</Text>
|
|
451
444
|
```
|
|
452
445
|
|
|
453
|
-
Text will suspend while loading the font data, but in order to completely avoid FOUC you can pass the characters it needs to render.
|
|
454
|
-
|
|
455
|
-
```jsx
|
|
456
|
-
<Text font={fontUrl} characters="abcdefghijklmnopqrstuvwxyz0123456789!">
|
|
457
|
-
hello world!
|
|
458
|
-
</Text>
|
|
459
|
-
```
|
|
460
|
-
|
|
461
446
|
#### Line
|
|
462
447
|
|
|
463
448
|
[](https://drei.vercel.app/?path=/story/abstractions-line--basic-line)
|
|
@@ -544,7 +529,7 @@ Renders a THREE.Line2 using THREE.CubicBezierCurve3 for interpolation.
|
|
|
544
529
|
|
|
545
530
|
[](https://drei.vercel.app/?path=/story/abstractions-positionalaudio--positional-audio-scene-st) 
|
|
546
531
|
|
|
547
|
-
A wrapper around [THREE.PositionalAudio](https://threejs.org/docs
|
|
532
|
+
A wrapper around [THREE.PositionalAudio](https://threejs.org/docs/#api/en/audio/PositionalAudio). Add this to groups or meshes to tie them to a sound that plays when the camera comes near.
|
|
548
533
|
|
|
549
534
|
```jsx
|
|
550
535
|
<PositionalAudio
|
|
@@ -597,11 +582,11 @@ Make sure to set the `makeDefault` prop on your controls, in that case you do no
|
|
|
597
582
|
|
|
598
583
|
#### Effects
|
|
599
584
|
|
|
600
|
-
Abstraction around threes own [EffectComposer](https://threejs.org/docs
|
|
585
|
+
Abstraction around threes own [EffectComposer](https://threejs.org/docs/#examples/en/postprocessing/EffectComposer).
|
|
601
586
|
|
|
602
587
|
```jsx
|
|
603
588
|
<Effects multisamping={8} renderIndex={1} disableGamma={false} disableRenderPass={false}>
|
|
604
|
-
<lUTPass
|
|
589
|
+
<lUTPass attach="passes" lut={texture3D} />
|
|
605
590
|
</Effects>
|
|
606
591
|
```
|
|
607
592
|
|
|
@@ -632,7 +617,7 @@ A declarative THREE.Texture which attaches to "map" by default. You can use this
|
|
|
632
617
|
<a href="https://codesandbox.io/s/ny3p4"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/ny3p4/screenshot.png" alt="Demo"/></a>
|
|
633
618
|
</p>
|
|
634
619
|
|
|
635
|
-
Abstracts [THREE.EdgesGeometry](https://threejs.org/docs
|
|
620
|
+
Abstracts [THREE.EdgesGeometry](https://threejs.org/docs/#api/en/geometries/EdgesGeometry). It pulls the geometry automatically from its parent, optionally you can ungroup it and give it a `geometry` prop. You can give it children, for instance a custom material.
|
|
636
621
|
|
|
637
622
|
```jsx
|
|
638
623
|
<mesh>
|
|
@@ -646,166 +631,6 @@ Abstracts [THREE.EdgesGeometry](https://threejs.org/docs/index.html?q=EdgesGeome
|
|
|
646
631
|
</mesh>
|
|
647
632
|
```
|
|
648
633
|
|
|
649
|
-
#### Trail
|
|
650
|
-
|
|
651
|
-
[](https://drei.vercel.app/?path=/story/misc-trail--use-trail-st)
|
|
652
|
-
|
|
653
|
-
A declarative, `three.MeshLine` based Trails implementation. You can attach it to any mesh and it will give it a beautiful trail.
|
|
654
|
-
|
|
655
|
-
Props defined bellow with their default values.
|
|
656
|
-
|
|
657
|
-
```jsx
|
|
658
|
-
<Trail
|
|
659
|
-
width={0.2} // Width of the line
|
|
660
|
-
color={'hotpink'} // Color of the line
|
|
661
|
-
length={1} // Length of the line
|
|
662
|
-
decay={1} // How fast the line fades away
|
|
663
|
-
local={false} // Wether to use the target's world or local positions
|
|
664
|
-
stride={0} // Min distance between previous and current point
|
|
665
|
-
interval={1} // Number of frames to wait before next calculation
|
|
666
|
-
target={undefined} // Optional target. This object will produce the trail.
|
|
667
|
-
attenuation={(width) => width} // A function to define the width in each point along it.
|
|
668
|
-
>
|
|
669
|
-
{/* If `target` is not defined, Trail will use the first `Object3D` child as the target. */}
|
|
670
|
-
<mesh>
|
|
671
|
-
<sphereGeometry />
|
|
672
|
-
<meshBasicMaterial />
|
|
673
|
-
</mesh>
|
|
674
|
-
|
|
675
|
-
{/* You can optionally define a custom meshLineMaterial to use. */}
|
|
676
|
-
{/* <meshLineMaterial color={"red"} /> */}
|
|
677
|
-
</Trail>
|
|
678
|
-
```
|
|
679
|
-
|
|
680
|
-
👉 Inspired by [TheSpite's Codevember 2021 #9](https://spite.github.io/codevember-2021/9/)
|
|
681
|
-
|
|
682
|
-
#### Sampler
|
|
683
|
-
|
|
684
|
-
[](https://drei.vercel.app/?path=/story/misc-sampler--sampler-st)
|
|
685
|
-
|
|
686
|
-
<p>
|
|
687
|
-
<a href="https://codesandbox.io/s/ehflx3">
|
|
688
|
-
<img width="20%" src="https://codesandbox.io/api/v1/sandboxes/ehflx3/screenshot.png" alt="Demo"/>
|
|
689
|
-
</a> <br />
|
|
690
|
-
<small>– <a href="https://codesandbox.io/s/ehflx3">Complex Demo</a> by <a href="https://twitter.com/CantBeFaraz">@CantBeFaraz</a></small> <br />
|
|
691
|
-
<small>– <a href="https://codesandbox.io/s/k6rcp2">Simple Demo</a> by <a href="https://twitter.com/ggsimm">@ggsimm</a></small>
|
|
692
|
-
</p>
|
|
693
|
-
|
|
694
|
-
Declarative abstraction around MeshSurfaceSampler & InstancedMesh.
|
|
695
|
-
It samples points from the passed mesh and transforms an InstancedMesh's matrix to distribute instances on the points.
|
|
696
|
-
|
|
697
|
-
Check the demos & code for more.
|
|
698
|
-
|
|
699
|
-
You can either pass a Mesh and InstancedMesh as children:
|
|
700
|
-
|
|
701
|
-
```tsx
|
|
702
|
-
// This simple example scatters 1000 spheres on the surface of the sphere mesh.
|
|
703
|
-
<Sampler
|
|
704
|
-
weight={"normal"} // the name of the attribute to be used as sampling weight
|
|
705
|
-
transform={transformPoint} // a function that transforms each instance given a sample. See the examples for more.
|
|
706
|
-
>
|
|
707
|
-
<mesh>
|
|
708
|
-
<sphereGeometry args={[2]} />
|
|
709
|
-
</mesh>
|
|
710
|
-
|
|
711
|
-
<instancedMesh args={[null, null, 1_000]}>
|
|
712
|
-
<sphereGeometry args={[0.1]}>
|
|
713
|
-
</instancedMesh>
|
|
714
|
-
</Sampler>
|
|
715
|
-
```
|
|
716
|
-
|
|
717
|
-
or use refs when you can't compose declaratively:
|
|
718
|
-
|
|
719
|
-
```tsx
|
|
720
|
-
const { nodes } = useGLTF('my/mesh/url')
|
|
721
|
-
const mesh = useRef(nodes)
|
|
722
|
-
const instances = useRef()
|
|
723
|
-
|
|
724
|
-
return <>
|
|
725
|
-
<instancedMesh args={[null, null, 1_000]}>
|
|
726
|
-
<sphereGeometry args={[0.1]}>
|
|
727
|
-
</instancedMesh>
|
|
728
|
-
|
|
729
|
-
<Sampler mesh={mesh} instances={instances}>
|
|
730
|
-
</>
|
|
731
|
-
```
|
|
732
|
-
|
|
733
|
-
#### ComputedAttribute
|
|
734
|
-
|
|
735
|
-
[](https://drei.vercel.app/?path=/story/misc-sampler--sampler-weight-st)
|
|
736
|
-
|
|
737
|
-
Create and attach an attribute declaratively.
|
|
738
|
-
|
|
739
|
-
```tsx
|
|
740
|
-
<sphereGeometry>
|
|
741
|
-
<ComputedAttribute
|
|
742
|
-
// attribute will be added to the geometry with this name
|
|
743
|
-
name="my-attribute-name"
|
|
744
|
-
compute={(geometry) => {
|
|
745
|
-
// ...someLogic;
|
|
746
|
-
return new THREE.BufferAttribute([1, 2, 3], 1)
|
|
747
|
-
}}
|
|
748
|
-
// you can pass any BufferAttribute prop to this component, eg.
|
|
749
|
-
usage={THREE.StaticReadUsage}
|
|
750
|
-
/>
|
|
751
|
-
</sphereGeometry>
|
|
752
|
-
```
|
|
753
|
-
|
|
754
|
-
#### Clone
|
|
755
|
-
|
|
756
|
-
<p>
|
|
757
|
-
<a href="https://codesandbox.io/s/42glz0"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/42glz0/screenshot.png" alt="Demo"/></a>
|
|
758
|
-
</p>
|
|
759
|
-
|
|
760
|
-
Declarative abstraction around THREE.Object3D.clone. This is useful when you want to create a shallow copy of an existing fragment (and Object3D, Groups, etc) into your scene, for instance a group from a loaded GLTF. This clone is now re-usable, but it will still refer to the original geometries and materials.
|
|
761
|
-
|
|
762
|
-
```ts
|
|
763
|
-
<Clone
|
|
764
|
-
/** Any pre-existing THREE.Object3D (groups, meshes, ...), or an array of objects */
|
|
765
|
-
object: THREE.Object3D | THREE.Object3D[]
|
|
766
|
-
/** Children will be placed within the object, or within the group that holds arrayed objects */
|
|
767
|
-
children?: React.ReactNode
|
|
768
|
-
/** Can clone materials and/or geometries deeply (default: false) */
|
|
769
|
-
deep?: boolean | 'materialsOnly' | 'geometriesOnly'
|
|
770
|
-
/** The property keys it will shallow-clone (material, geometry, visible, ...) */
|
|
771
|
-
keys?: string[]
|
|
772
|
-
/** Can either spread over props or fill in JSX children, applies to every mesh within */
|
|
773
|
-
inject?: MeshProps | React.ReactNode | ((object: THREE.Object3D) => React.ReactNode)
|
|
774
|
-
/** Short access castShadow, applied to every mesh within */
|
|
775
|
-
castShadow?: boolean
|
|
776
|
-
/** Short access receiveShadow, applied to every mesh within */
|
|
777
|
-
receiveShadow?: boolean
|
|
778
|
-
/>
|
|
779
|
-
```
|
|
780
|
-
|
|
781
|
-
You create a shallow clone by passing a pre-existing object to the `object` prop.
|
|
782
|
-
|
|
783
|
-
```jsx
|
|
784
|
-
const { nodes } = useGLTF(url)
|
|
785
|
-
return (
|
|
786
|
-
<Clone object={nodes.table} />
|
|
787
|
-
```
|
|
788
|
-
|
|
789
|
-
Or, multiple objects:
|
|
790
|
-
|
|
791
|
-
```jsx
|
|
792
|
-
<Clone object={[nodes.foo, nodes.bar]} />
|
|
793
|
-
```
|
|
794
|
-
|
|
795
|
-
You can dynamically insert objects, these will apply to anything that isn't a group or a plain object3d (meshes, lines, etc):
|
|
796
|
-
|
|
797
|
-
```jsx
|
|
798
|
-
<Clone object={nodes.table} inject={<meshStandardMaterial color="green" />} />
|
|
799
|
-
```
|
|
800
|
-
|
|
801
|
-
Or make inserts conditional:
|
|
802
|
-
|
|
803
|
-
```jsx
|
|
804
|
-
<Clone object={nodes.table} inject={
|
|
805
|
-
{(object) => (object.name === 'table' ? <meshStandardMaterial color="green" /> : null)}
|
|
806
|
-
} />
|
|
807
|
-
```
|
|
808
|
-
|
|
809
634
|
#### useAnimations
|
|
810
635
|
|
|
811
636
|
[](https://drei.pmnd.rs/?path=/story/abstractions-useanimations--use-animations-st)
|
|
@@ -814,7 +639,7 @@ Or make inserts conditional:
|
|
|
814
639
|
<a href="https://codesandbox.io/s/pecl6"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/pecl6/screenshot.png" alt="Demo"/></a>
|
|
815
640
|
</p>
|
|
816
641
|
|
|
817
|
-
A hook that abstracts [AnimationMixer](https://threejs.org/docs
|
|
642
|
+
A hook that abstracts [AnimationMixer](https://threejs.org/docs/#api/en/animation/AnimationMixer).
|
|
818
643
|
|
|
819
644
|
```jsx
|
|
820
645
|
const { nodes, materials, animations } = useGLTF(url)
|
|
@@ -845,7 +670,7 @@ return <primitive object={scene} />
|
|
|
845
670
|
<a href="https://codesandbox.io/s/l900i"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/l900i/screenshot.png" alt="Demo"/></a>
|
|
846
671
|
</p>
|
|
847
672
|
|
|
848
|
-
Easily add reflections and/or blur to any mesh. It takes surface roughness into account for a more realistic effect. This material extends from [THREE.MeshStandardMaterial](https://threejs.org/docs
|
|
673
|
+
Easily add reflections and/or blur to any mesh. It takes surface roughness into account for a more realistic effect. This material extends from [THREE.MeshStandardMaterial](https://threejs.org/docs/#api/en/materials/MeshStandardMaterial) and accepts all its props.
|
|
849
674
|
|
|
850
675
|
```jsx
|
|
851
676
|
<mesh>
|
|
@@ -883,8 +708,8 @@ This material makes your geometry wobble and wave around. It was taken from the
|
|
|
883
708
|
|
|
884
709
|
```jsx
|
|
885
710
|
<mesh>
|
|
886
|
-
<
|
|
887
|
-
<MeshWobbleMaterial
|
|
711
|
+
<boxGeometry />
|
|
712
|
+
<MeshWobbleMaterial factor={1} speed={10} />
|
|
888
713
|
</mesh>
|
|
889
714
|
```
|
|
890
715
|
|
|
@@ -900,14 +725,14 @@ This material makes your geometry distort following simplex noise.
|
|
|
900
725
|
|
|
901
726
|
```jsx
|
|
902
727
|
<mesh>
|
|
903
|
-
<
|
|
904
|
-
<MeshDistortMaterial
|
|
728
|
+
<boxGeometry />
|
|
729
|
+
<MeshDistortMaterial distort={1} speed={10} />
|
|
905
730
|
</mesh>
|
|
906
731
|
```
|
|
907
732
|
|
|
908
733
|
#### PointMaterial
|
|
909
734
|
|
|
910
|
-
|
|
735
|
+
An antialiased round dot that always keeps the same size.
|
|
911
736
|
|
|
912
737
|
```jsx
|
|
913
738
|
<points>
|
|
@@ -923,7 +748,7 @@ Antialiased round dots. It takes the same props as regular THREE.PointsMaterial
|
|
|
923
748
|
<a href="https://codesandbox.io/s/dh2jc"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/dh2jc/screenshot.png" alt="Demo"/></a>
|
|
924
749
|
</p>
|
|
925
750
|
|
|
926
|
-
Injects [percent closer soft shadows (pcss)](https://threejs.org/examples
|
|
751
|
+
Injects [percent closer soft shadows (pcss)](https://threejs.org/examples/#webgl_shadowmap_pcss) into threes shader chunk.
|
|
927
752
|
|
|
928
753
|
```jsx
|
|
929
754
|
softShadows({
|
|
@@ -946,7 +771,7 @@ softShadows({
|
|
|
946
771
|
Creates a THREE.ShaderMaterial for you with easier handling of uniforms, which are also automatically declared as setter/getters on the object.
|
|
947
772
|
|
|
948
773
|
```jsx
|
|
949
|
-
import { extend } from 'react-three
|
|
774
|
+
import { extend } from '@react-three/fiber'
|
|
950
775
|
import glsl from 'babel-plugin-glsl/macro'
|
|
951
776
|
|
|
952
777
|
const ColorShiftMaterial = shaderMaterial(
|
|
@@ -974,7 +799,7 @@ extend({ ColorShiftMaterial })
|
|
|
974
799
|
|
|
975
800
|
// in your component
|
|
976
801
|
<mesh>
|
|
977
|
-
<colorShiftMaterial
|
|
802
|
+
<colorShiftMaterial color="hotpink" time={1} />
|
|
978
803
|
</mesh>
|
|
979
804
|
```
|
|
980
805
|
|
|
@@ -984,7 +809,7 @@ extend({ ColorShiftMaterial })
|
|
|
984
809
|
|
|
985
810
|
[](https://drei.pmnd.rs/?path=/story/modifiers-curvemodifier)
|
|
986
811
|
|
|
987
|
-
Given a curve will replace the children of this component with a mesh that move along said curve calling the property `moveAlongCurve` on the passed ref. Uses [three's Curve Modifier](https://threejs.org/examples
|
|
812
|
+
Given a curve will replace the children of this component with a mesh that move along said curve calling the property `moveAlongCurve` on the passed ref. Uses [three's Curve Modifier](https://threejs.org/examples/#webgl_modifier_curve)
|
|
988
813
|
|
|
989
814
|
```jsx
|
|
990
815
|
const curveRef = useRef()
|
|
@@ -994,7 +819,7 @@ const curve = React.useMemo(() => new THREE.CatmullRomCurve3([...handlePos], tru
|
|
|
994
819
|
return (
|
|
995
820
|
<CurveModifier ref={curveRef} curve={curve}>
|
|
996
821
|
<mesh>
|
|
997
|
-
<
|
|
822
|
+
<boxGeometry args={[10, 10]} />
|
|
998
823
|
</mesh>
|
|
999
824
|
</CurveModifier>
|
|
1000
825
|
)
|
|
@@ -1221,7 +1046,7 @@ useHelper(condition && mesh, BoxHelper, 'red') // you can passe false instead of
|
|
|
1221
1046
|
|
|
1222
1047
|
This hook uses [DetectGPU by @TimvanScherpenzeel](https://github.com/TimvanScherpenzeel/detect-gpu), wrapped into suspense, to determine what tier should be assigned to the user's GPU.
|
|
1223
1048
|
|
|
1224
|
-
👉 This hook CAN be used outside the react-three
|
|
1049
|
+
👉 This hook CAN be used outside the @react-three/fiber `Canvas`.
|
|
1225
1050
|
|
|
1226
1051
|
```jsx
|
|
1227
1052
|
function App() {
|
|
@@ -1248,7 +1073,7 @@ const scale = useAspect(
|
|
|
1248
1073
|
)
|
|
1249
1074
|
return (
|
|
1250
1075
|
<mesh scale={scale}>
|
|
1251
|
-
<
|
|
1076
|
+
<planeGeometry />
|
|
1252
1077
|
<meshBasicMaterial map={imageTexture} />
|
|
1253
1078
|
```
|
|
1254
1079
|
|
|
@@ -1271,63 +1096,13 @@ return (
|
|
|
1271
1096
|
<a href="https://codesandbox.io/s/gsm1y"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/gsm1y/screenshot.png" alt="Demo"/></a>
|
|
1272
1097
|
</p>
|
|
1273
1098
|
|
|
1274
|
-
A very cheap frustum check that gives you a reference you can observe in order to know if the object has entered the view or is outside of it. This relies on [THREE.Object3D.onBeforeRender](https://threejs.org/docs
|
|
1099
|
+
A very cheap frustum check that gives you a reference you can observe in order to know if the object has entered the view or is outside of it. This relies on [THREE.Object3D.onBeforeRender](https://threejs.org/docs/#api/en/core/Object3D.onBeforeRender) so it only works on objects that are effectively rendered, like meshes, lines, sprites. It won't work on groups, object3d's, bones, etc.
|
|
1275
1100
|
|
|
1276
1101
|
```jsx
|
|
1277
1102
|
const ref = useIntersect((visible) => console.log('object is visible', visible))
|
|
1278
1103
|
return <mesh ref={ref} />
|
|
1279
1104
|
```
|
|
1280
1105
|
|
|
1281
|
-
#### useBoxProjectedEnv
|
|
1282
|
-
|
|
1283
|
-
<p>
|
|
1284
|
-
<a href="https://codesandbox.io/s/s006f"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/s006f/screenshot.png" alt="Demo"/></a>
|
|
1285
|
-
</p>
|
|
1286
|
-
|
|
1287
|
-
The cheapest possible way of getting reflections in threejs. This will box-project the current environment map onto a plane. It returns an object that you need to spread over its material. The spread object contains a ref, onBeforeCompile and customProgramCacheKey. If you combine it with drei/CubeCamera you can "film" a single frame of the environment and feed it to the material, thereby getting realistic reflections at no cost. Align it with the position and scale properties.
|
|
1288
|
-
|
|
1289
|
-
```jsx
|
|
1290
|
-
const projection = useBoxProjectedEnv(
|
|
1291
|
-
[0, 0, 0], // Position
|
|
1292
|
-
[1, 1, 1] // Scale
|
|
1293
|
-
)
|
|
1294
|
-
|
|
1295
|
-
<CubeCamera frames={1}>
|
|
1296
|
-
{(texture) => (
|
|
1297
|
-
<mesh>
|
|
1298
|
-
<planeGeometry />
|
|
1299
|
-
<meshStandardMaterial envMap={texture} {...projection} />
|
|
1300
|
-
</mesh>
|
|
1301
|
-
)}
|
|
1302
|
-
</CubeCamera>
|
|
1303
|
-
```
|
|
1304
|
-
|
|
1305
|
-
#### useTrail
|
|
1306
|
-
|
|
1307
|
-
[](https://drei.vercel.app/?path=/story/misc-trail--use-trail-st)
|
|
1308
|
-
|
|
1309
|
-
A hook to obtain an array of points that make up a [Trail](#trail). You can use this array to drive your own `MeshLine` or make a trail out of anything you please.
|
|
1310
|
-
|
|
1311
|
-
Note: The hook returns a ref (`MutableRefObject<Vector3[]>`) this means updates to it will not trigger a re-draw, thus keeping this cheap.
|
|
1312
|
-
|
|
1313
|
-
```js
|
|
1314
|
-
const points = useTrail(
|
|
1315
|
-
target, // Required target object. This object will produce the trail.
|
|
1316
|
-
{
|
|
1317
|
-
length, // Length of the line
|
|
1318
|
-
decay, // How fast the line fades away
|
|
1319
|
-
local, // Wether to use the target's world or local positions
|
|
1320
|
-
stride, // Min distance between previous and current point
|
|
1321
|
-
interval, // Number of frames to wait before next calculation
|
|
1322
|
-
}
|
|
1323
|
-
)
|
|
1324
|
-
|
|
1325
|
-
// To use...
|
|
1326
|
-
useFrame(() => {
|
|
1327
|
-
meshLineRef.current.position.setPoints(points.current)
|
|
1328
|
-
})
|
|
1329
|
-
```
|
|
1330
|
-
|
|
1331
1106
|
# Loading
|
|
1332
1107
|
|
|
1333
1108
|
#### Loader
|
|
@@ -1471,7 +1246,7 @@ const envMap = useCubeTexture(['px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png',
|
|
|
1471
1246
|
<a href="https://codesandbox.io/s/i6t0j"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/i6t0j/screenshot.png" alt="Demo"/></a>
|
|
1472
1247
|
</p>
|
|
1473
1248
|
|
|
1474
|
-
A wrapper around [THREE.InstancedMesh](https://threejs.org/docs
|
|
1249
|
+
A wrapper around [THREE.InstancedMesh](https://threejs.org/docs/#api/en/objects/InstancedMesh). This allows you to define hundreds of thousands of objects in a single draw call, but declaratively!
|
|
1475
1250
|
|
|
1476
1251
|
```jsx
|
|
1477
1252
|
<Instances
|
|
@@ -1556,19 +1331,34 @@ function Model({ url }) {
|
|
|
1556
1331
|
|
|
1557
1332
|
#### Points
|
|
1558
1333
|
|
|
1559
|
-
A wrapper around [THREE.Points](https://threejs.org/docs
|
|
1334
|
+
A wrapper around [THREE.Points](https://threejs.org/docs/#api/en/objects/Points). It has the same api and properties as Instances.
|
|
1560
1335
|
|
|
1561
1336
|
```jsx
|
|
1562
1337
|
<Points
|
|
1563
1338
|
limit={1000} // Optional: max amount of items (for calculating buffer size)
|
|
1564
1339
|
range={1000} // Optional: draw-range
|
|
1565
1340
|
>
|
|
1566
|
-
<pointsMaterial
|
|
1341
|
+
<pointsMaterial />
|
|
1567
1342
|
<Point position={[1, 2, 3]} color="red" onClick={onClick} onPointerOver={onPointerOver} ... />
|
|
1568
1343
|
// As many as you want, make them conditional, mount/unmount them, lazy load them, etc ...
|
|
1569
1344
|
</Points>
|
|
1570
1345
|
```
|
|
1571
1346
|
|
|
1347
|
+
If you have a material that supports vertex colors (like drei/PointMaterial) you can have individual colors!
|
|
1348
|
+
|
|
1349
|
+
```jsx
|
|
1350
|
+
<Points>
|
|
1351
|
+
<PointMaterial />
|
|
1352
|
+
<Point color="hotpink" />
|
|
1353
|
+
```
|
|
1354
|
+
|
|
1355
|
+
Otherwise use any material you like:
|
|
1356
|
+
|
|
1357
|
+
```jsx
|
|
1358
|
+
<Points>
|
|
1359
|
+
<pointsMaterial vertexColors size={10} />
|
|
1360
|
+
```
|
|
1361
|
+
|
|
1572
1362
|
If you just want to use buffers for position, color and size, you can use the alternative API:
|
|
1573
1363
|
|
|
1574
1364
|
```jsx
|
|
@@ -1620,7 +1410,7 @@ useFrame(() => {
|
|
|
1620
1410
|
<a href="https://codesandbox.io/s/12nmp"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/12nmp/screenshot.png" alt="Demo"/></a>
|
|
1621
1411
|
</p>
|
|
1622
1412
|
|
|
1623
|
-
A wrapper around [THREE.LOD](https://threejs.org/docs
|
|
1413
|
+
A wrapper around [THREE.LOD](https://threejs.org/docs/#api/en/objects/LOD) (Level of detail).
|
|
1624
1414
|
|
|
1625
1415
|
```jsx
|
|
1626
1416
|
<Detailed distances={[0, 10, 20]} {...props}>
|
|
@@ -1632,7 +1422,7 @@ A wrapper around [THREE.LOD](https://threejs.org/docs/index.html#api/en/objects/
|
|
|
1632
1422
|
|
|
1633
1423
|
#### Preload
|
|
1634
1424
|
|
|
1635
|
-
The WebGLRenderer will compile materials only when they hit the frustrum, which can cause jank. This component precompiles the scene using [gl.compile](https://threejs.org/docs
|
|
1425
|
+
The WebGLRenderer will compile materials only when they hit the frustrum, which can cause jank. This component precompiles the scene using [gl.compile](https://threejs.org/docs/#api/en/renderers/WebGLRenderer.compile) which makes sure that your app is responsive from the get go.
|
|
1636
1426
|
|
|
1637
1427
|
By default gl.compile will only preload visible objects, if you supply the `all` prop, it will circumvent that. With the `scene` and `camera` props you could also use it in portals.
|
|
1638
1428
|
|
|
@@ -1666,7 +1456,7 @@ A very fast, but often good-enough bounds-only raycast for meshes. You can use t
|
|
|
1666
1456
|
|
|
1667
1457
|
#### AdaptiveDpr
|
|
1668
1458
|
|
|
1669
|
-
Drop this component into your scene and it will cut the pixel-ratio on regress according to the
|
|
1459
|
+
Drop this component into your scene and it will cut the pixel-ratio on [regress](#) according to the canvases perrformance min/max settings. This allows you to temporarily reduce visuals for more performance, for instance when the camera moves (look into drei's controls `regress` flag). Optionally you can set the canvas to a pixelated filter, which would be even faster.
|
|
1670
1460
|
|
|
1671
1461
|
```jsx
|
|
1672
1462
|
<AdaptiveDpr pixelated />
|
|
@@ -1699,7 +1489,7 @@ useBVH(mesh)
|
|
|
1699
1489
|
|
|
1700
1490
|
[](https://drei.pmnd.rs/?path=/story/staging-center--default-story)
|
|
1701
1491
|
|
|
1702
|
-
Calculates a boundary box and centers its children accordingly. `alignTop` adjusts it so that it sits flush on y=0.
|
|
1492
|
+
Calculates a boundary box and centers its children accordingly. `alignTop` makes adjusts it so that it's sits flush on y=0.
|
|
1703
1493
|
|
|
1704
1494
|
```jsx
|
|
1705
1495
|
<Center alignTop>
|
|
@@ -1713,10 +1503,10 @@ Calculates a boundary box and centers its children accordingly. `alignTop` adjus
|
|
|
1713
1503
|
<a href="https://codesandbox.io/s/rz2g0"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/rz2g0/screenshot.png" alt="Demo"/></a>
|
|
1714
1504
|
</p>
|
|
1715
1505
|
|
|
1716
|
-
Calculates a boundary box and centers the camera accordingly. If you are using controls, make sure to pass them the `makeDefault` prop. `fit` fits the current view on first render. `clip` sets the cameras near/far planes.
|
|
1506
|
+
Calculates a boundary box and centers the camera accordingly. If you are using controls, make sure to pass them the `makeDefault` prop. `fit` fits the current view on first render. `clip` sets the cameras near/far planes.
|
|
1717
1507
|
|
|
1718
1508
|
```jsx
|
|
1719
|
-
<Bounds fit clip
|
|
1509
|
+
<Bounds fit clip damping={6} margin={1.2}>
|
|
1720
1510
|
<mesh />
|
|
1721
1511
|
</Bounds>
|
|
1722
1512
|
```
|
|
@@ -1846,10 +1636,10 @@ A cheap canvas-texture-based circular gradient.
|
|
|
1846
1636
|
<a href="https://codesandbox.io/s/qxjoj"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/qxjoj/screenshot.png" alt="Demo"/></a>
|
|
1847
1637
|
</p>
|
|
1848
1638
|
|
|
1849
|
-
A [contact shadow](https://threejs.org/examples
|
|
1639
|
+
A [contact shadow](https://threejs.org/examples/#webgl_shadow_contact) implementation, facing upwards (positive Y) by default. `scale` can be a positive number or a 2D array `[x: number, y: number]`.
|
|
1850
1640
|
|
|
1851
1641
|
```jsx
|
|
1852
|
-
<ContactShadows opacity={1} scale={10} blur={1} far={10} resolution={256}
|
|
1642
|
+
<ContactShadows opacity={1} scale={10} blur={1} far={10} resolution={256} />
|
|
1853
1643
|
```
|
|
1854
1644
|
|
|
1855
1645
|
Since this is a rather expensive effect you can limit the amount of frames it renders when your objects are static. For instance making it render only once:
|
|
@@ -1890,9 +1680,6 @@ function Foo() {
|
|
|
1890
1680
|
|
|
1891
1681
|
<p>
|
|
1892
1682
|
<a href="https://codesandbox.io/s/t4l0f"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/t4l0f/screenshot.png" alt="Demo"/></a>
|
|
1893
|
-
<a href="https://codesandbox.io/s/mih0lx"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/mih0lx/screenshot.png" alt="Demo"/></a>
|
|
1894
|
-
<a href="https://codesandbox.io/s/e662p3"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/e662p3/screenshot.png" alt="Demo"/></a>
|
|
1895
|
-
<a href="https://codesandbox.io/s/lwo219"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/lwo219/screenshot.png" alt="Demo"/></a>
|
|
1896
1683
|
</p>
|
|
1897
1684
|
|
|
1898
1685
|
Sets up a global cubemap, which affects the default `scene.environment`, and optionally `scene.background`, unless a custom scene has been passed. A selection of [presets](src/helpers/environment-assets.ts) from [HDRI Haven](https://hdrihaven.com/) are available for convenience. If you pass an array of files it will use THREE.CubeTextureLoader.
|
|
@@ -1901,11 +1688,11 @@ Sets up a global cubemap, which affects the default `scene.environment`, and opt
|
|
|
1901
1688
|
|
|
1902
1689
|
```jsx
|
|
1903
1690
|
<Environment
|
|
1904
|
-
background={false}
|
|
1691
|
+
background={false}
|
|
1905
1692
|
files={['px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png', 'nz.png']}
|
|
1906
1693
|
path="/"
|
|
1907
1694
|
preset={null}
|
|
1908
|
-
scene={undefined} // adds the ability to pass a custom THREE.Scene
|
|
1695
|
+
scene={undefined} // adds the ability to pass a custom THREE.Scene
|
|
1909
1696
|
/>
|
|
1910
1697
|
```
|
|
1911
1698
|
|
|
@@ -1915,60 +1702,6 @@ If you provide a single string it will use THREE.RGBELoader.
|
|
|
1915
1702
|
<Environment files="file.hdr" />
|
|
1916
1703
|
```
|
|
1917
1704
|
|
|
1918
|
-
If you already have a cube texture you can pass it directly:
|
|
1919
|
-
|
|
1920
|
-
```jsx
|
|
1921
|
-
<CubeCamera>{(texture) => <Environment map={texture} />}</CubeCamera>
|
|
1922
|
-
```
|
|
1923
|
-
|
|
1924
|
-
If you provide children you can even render a custom environment. It will render the contents into an off-buffer and film a single frame with a cube camera (whose props you can configure: near=1, far=1000, resolution=256).
|
|
1925
|
-
|
|
1926
|
-
```jsx
|
|
1927
|
-
<Environment background near={1} far={1000} resolution={256}>
|
|
1928
|
-
<mesh scale={100}>
|
|
1929
|
-
<sphereGeometry args={[1, 64, 64]} />
|
|
1930
|
-
<meshBasicMaterial map={texture} side={THREE.BackSide} />
|
|
1931
|
-
</mesh>
|
|
1932
|
-
</Environment>
|
|
1933
|
-
```
|
|
1934
|
-
|
|
1935
|
-
You can even mix a generic HDRI environment into a custom one with either the `preset` or the `files` prop.
|
|
1936
|
-
|
|
1937
|
-
```jsx
|
|
1938
|
-
return (
|
|
1939
|
-
<Environment background near={1} far={1000} resolution={256} preset="warehouse">
|
|
1940
|
-
<mesh />
|
|
1941
|
-
```
|
|
1942
|
-
|
|
1943
|
-
Declarative environment content can also animate with the `frames` prop, the envmap can be live. Give it a low resolution and this will happen at very little cost
|
|
1944
|
-
|
|
1945
|
-
```jsx
|
|
1946
|
-
return (
|
|
1947
|
-
<Environment frames={Infinity} resolution={256}>
|
|
1948
|
-
<Float>
|
|
1949
|
-
<mesh />
|
|
1950
|
-
</Float>
|
|
1951
|
-
```
|
|
1952
|
-
|
|
1953
|
-
#### Lightformer
|
|
1954
|
-
|
|
1955
|
-
<p>
|
|
1956
|
-
<a href="https://codesandbox.io/s/lwo219"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/lwo219/screenshot.png" alt="Demo"/></a>
|
|
1957
|
-
</p>
|
|
1958
|
-
|
|
1959
|
-
This component draws flat rectangles, circles or rings, mimicking the look of a light-former. You can set the output `intensity`, which will effect emissiveness once you put it into an HDRI `<Environment>`, where it mostly belong. It will act like a real light without the expense, you can have as many as you want.
|
|
1960
|
-
|
|
1961
|
-
```jsx
|
|
1962
|
-
<Environment>
|
|
1963
|
-
<Lightformer
|
|
1964
|
-
form="rect" // circle | ring | rect (optional, default = rect)
|
|
1965
|
-
intensity={1} // power level (optional = 1)
|
|
1966
|
-
color="white" // (optional = white)
|
|
1967
|
-
scale={[10, 5]} // Scale it any way you prefer (optional = [1, 1])
|
|
1968
|
-
target={[0, 0, 0]} // Target position (optional = undefined)
|
|
1969
|
-
/>
|
|
1970
|
-
```
|
|
1971
|
-
|
|
1972
1705
|
#### Sky
|
|
1973
1706
|
|
|
1974
1707
|
[](https://drei.pmnd.rs/?path=/story/staging-sky--sky-st)
|
|
@@ -1977,7 +1710,7 @@ This component draws flat rectangles, circles or rings, mimicking the look of a
|
|
|
1977
1710
|
<a href="https://codesandbox.io/s/vkgi6"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/vkgi6/screenshot.png" alt="Demo"/></a>
|
|
1978
1711
|
</p>
|
|
1979
1712
|
|
|
1980
|
-
Adds a [sky](https://threejs.org/examples
|
|
1713
|
+
Adds a [sky](https://threejs.org/examples/#webgl_shaders_sky) to your scene.
|
|
1981
1714
|
|
|
1982
1715
|
```jsx
|
|
1983
1716
|
<Sky distance={450000} sunPosition={[0, 1, 0]} inclination={0} azimuth={0.25} {...props} />
|