@react-three/drei 9.0.0-beta.1 β 9.0.0-beta.4
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 +461 -48
- package/core/ArcballControls.cjs.js +1 -1
- package/core/ArcballControls.d.ts +8 -8
- package/core/ArcballControls.js +19 -30
- package/core/Bounds.cjs.js +1 -1
- package/core/Bounds.d.ts +2 -1
- package/core/Bounds.js +25 -14
- package/core/Clone.cjs.js +1 -0
- package/core/Clone.d.ts +11 -0
- package/core/Clone.js +92 -0
- package/core/Cloud.cjs.js +1 -1
- package/core/Cloud.d.ts +4 -1
- package/core/Cloud.js +7 -3
- package/core/ComputedAttribute.cjs.js +1 -0
- package/core/ComputedAttribute.d.ts +9 -0
- package/core/ComputedAttribute.js +34 -0
- package/core/ContactShadows.cjs.js +1 -1
- package/core/ContactShadows.d.ts +4 -1
- package/core/ContactShadows.js +33 -13
- package/core/CubeCamera.cjs.js +1 -1
- package/core/CubeCamera.js +6 -7
- package/core/CurveModifier.cjs.js +1 -1
- package/core/CurveModifier.js +18 -22
- package/core/Detailed.d.ts +1 -1
- package/core/DeviceOrientationControls.cjs.js +1 -1
- package/core/DeviceOrientationControls.js +2 -6
- package/core/Effects.cjs.js +1 -1
- package/core/Effects.d.ts +3 -2
- package/core/Effects.js +2 -2
- package/core/Environment.cjs.js +1 -1
- package/core/Environment.d.ts +13 -3
- package/core/Environment.js +100 -56
- package/core/FirstPersonControls.cjs.js +1 -1
- package/core/FirstPersonControls.d.ts +1 -1
- package/core/FirstPersonControls.js +2 -6
- package/core/Float.cjs.js +1 -1
- package/core/Float.d.ts +1 -1
- package/core/Float.js +5 -4
- package/core/GizmoHelper.cjs.js +1 -1
- package/core/GizmoHelper.d.ts +2 -1
- package/core/GizmoHelper.js +31 -41
- package/core/GizmoViewcube.cjs.js +1 -1
- package/core/GizmoViewcube.js +1 -1
- package/core/GradientTexture.cjs.js +1 -1
- package/core/GradientTexture.js +5 -2
- package/core/Image.cjs.js +1 -1
- package/core/Image.d.ts +6 -4
- package/core/Image.js +6 -1
- package/core/Instances.cjs.js +1 -1
- package/core/Instances.d.ts +2 -2
- package/core/Instances.js +5 -11
- package/core/Lightformer.cjs.js +1 -0
- package/core/Lightformer.d.ts +41 -0
- package/core/Lightformer.js +51 -0
- 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 -2
- package/core/MeshReflectorMaterial.js +7 -7
- package/core/MeshWobbleMaterial.d.ts +2 -4
- package/core/OrbitControls.cjs.js +1 -1
- package/core/OrbitControls.d.ts +10 -10
- package/core/OrbitControls.js +14 -26
- package/core/OrthographicCamera.d.ts +1 -1
- package/core/PerspectiveCamera.d.ts +1 -1
- package/core/PointMaterial.cjs.js +1 -1
- package/core/PointMaterial.d.ts +5 -8
- package/core/PointMaterial.js +16 -34
- package/core/PointerLockControls.cjs.js +1 -1
- package/core/PointerLockControls.d.ts +3 -1
- package/core/PointerLockControls.js +36 -22
- package/core/Points.cjs.js +1 -1
- package/core/Points.d.ts +3 -3
- package/core/Points.js +11 -30
- package/core/PositionalAudio.d.ts +1 -1
- package/core/Reflector.cjs.js +1 -1
- package/core/Reflector.d.ts +1 -1
- package/core/Reflector.js +1 -2
- package/core/RoundedBox.cjs.js +1 -1
- package/core/RoundedBox.d.ts +2 -1
- package/core/RoundedBox.js +2 -1
- package/core/Sampler.cjs.js +1 -0
- package/core/Sampler.d.ts +21 -0
- package/core/Sampler.js +65 -0
- package/core/Shadow.d.ts +1 -1
- package/core/SpotLight.d.ts +20 -4
- package/core/Stage.cjs.js +1 -1
- package/core/Stage.d.ts +1 -1
- package/core/Stage.js +1 -2
- package/core/Stars.cjs.js +1 -1
- package/core/Stars.js +3 -0
- package/core/Stats.cjs.js +1 -1
- package/core/Stats.js +2 -2
- package/core/Text.cjs.js +1 -1
- package/core/Text.d.ts +3 -2
- package/core/Text.js +9 -1
- package/core/TrackballControls.cjs.js +1 -1
- package/core/TrackballControls.js +7 -5
- package/core/Trail.cjs.js +1 -0
- package/core/Trail.d.ts +21 -0
- package/core/Trail.js +160 -0
- package/core/TransformControls.cjs.js +1 -1
- package/core/TransformControls.d.ts +1 -1
- package/core/TransformControls.js +13 -11
- package/core/index.cjs.js +1 -1
- package/core/index.d.ts +6 -0
- package/core/index.js +11 -4
- package/core/shaderMaterial.d.ts +1 -1
- package/core/useBoxProjectedEnv.cjs.js +1 -0
- package/core/useBoxProjectedEnv.d.ts +8 -0
- package/core/useBoxProjectedEnv.js +98 -0
- package/core/useDetectGPU.cjs.js +1 -1
- package/core/useDetectGPU.js +2 -2
- package/core/useFBO.cjs.js +1 -1
- package/core/useFBO.d.ts +1 -1
- package/core/useFBO.js +22 -24
- package/core/useHelper.cjs.js +1 -1
- package/core/useHelper.d.ts +4 -1
- package/core/useHelper.js +16 -6
- package/core/useMatcapTexture.cjs.js +1 -1
- package/core/useMatcapTexture.js +2 -5
- package/core/useNormalTexture.cjs.js +1 -1
- package/core/useNormalTexture.js +2 -5
- package/helpers/Position.cjs.js +1 -1
- package/helpers/Position.js +3 -2
- package/helpers/environment-assets.cjs.js +1 -1
- package/helpers/environment-assets.js +10 -10
- package/index.cjs.js +1 -1
- package/index.js +7 -1
- package/materials/ConvolutionMaterial.cjs.js +1 -1
- package/materials/ConvolutionMaterial.js +2 -0
- package/materials/MeshReflectorMaterial.cjs.js +1 -1
- package/materials/MeshReflectorMaterial.d.ts +0 -3
- package/materials/MeshReflectorMaterial.js +8 -35
- package/materials/SpotLightMaterial.cjs.js +1 -1
- package/materials/SpotLightMaterial.js +3 -0
- package/native/index.cjs.js +1 -1
- package/native/index.js +11 -4
- package/package.json +8 -7
- package/web/Html.cjs.js +1 -1
- package/web/Html.js +4 -5
- package/web/ScrollControls.cjs.js +1 -1
- package/web/ScrollControls.js +6 -5
- package/web/Select.cjs.js +1 -1
- package/web/Select.d.ts +2 -1
- package/web/Select.js +3 -2
- package/web/index.cjs.js +1 -1
- package/web/index.js +12 -5
package/README.md
CHANGED
|
@@ -65,6 +65,10 @@ 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>
|
|
68
72
|
<li><a href="#useanimations">useAnimations</a></li>
|
|
69
73
|
</ul>
|
|
70
74
|
<li><a href="#shaders">Shaders</a></li>
|
|
@@ -99,6 +103,8 @@ The `native` route of the library **does not** export `Html` or `Loader`. The de
|
|
|
99
103
|
<li><a href="#useaspect">useAspect</a></li>
|
|
100
104
|
<li><a href="#usecursor">useCursor</a></li>
|
|
101
105
|
<li><a href="#useintersect">useIntersect</a></li>
|
|
106
|
+
<li><a href="#useboxprojectedenv">useBoxProjectedEnv</a></li>
|
|
107
|
+
<li><a href="#useTrail">useTrail</a></li>
|
|
102
108
|
</ul>
|
|
103
109
|
<li><a href="#loading">Loaders</a></li>
|
|
104
110
|
<ul>
|
|
@@ -159,6 +165,7 @@ The `native` route of the library **does not** export `Html` or `Loader`. The de
|
|
|
159
165
|
<li><a href="#stage">Stage</a></li>
|
|
160
166
|
<li><a href="#backdrop">Backdrop</a></li>
|
|
161
167
|
<li><a href="#environment">Environment</a></li>
|
|
168
|
+
<li><a href="#lightformer">Lightformer</a></li>
|
|
162
169
|
<li><a href="#spotlight">SpotLight</a></li>
|
|
163
170
|
<li><a href="#shadow">Shadow</a></li>
|
|
164
171
|
<li><a href="#contactshadows">ContactShadows</a></li>
|
|
@@ -243,12 +250,16 @@ Drei currently exports OrbitControls [. All elements matching the `selector` prop will activate the controls.
|
|
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. It will also center raycast events by default, so regular onPointerOver/etc events on meshes will continue to work.
|
|
247
254
|
|
|
248
255
|
# TransformControls
|
|
249
256
|
|
|
250
257
|
[](https://drei.vercel.app/?path=/story/controls-transformcontrols--transform-controls-story)
|
|
251
258
|
|
|
259
|
+
<p>
|
|
260
|
+
<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
|
+
</p>
|
|
262
|
+
|
|
252
263
|
An abstraction around [THREE.TransformControls](https://threejs.org/docs/#examples/en/controls/TransformControls).
|
|
253
264
|
|
|
254
265
|
You can wrap objects which then receive a transform gizmo.
|
|
@@ -277,13 +288,13 @@ If you are using other controls (Orbit, Trackball, etc), you will notice how the
|
|
|
277
288
|
|
|
278
289
|

|
|
279
290
|
|
|
280
|
-
<p
|
|
281
|
-
<a href="https://codesandbox.io/s/l4klb"><img width="
|
|
282
|
-
<a href="https://codesandbox.io/s/4m0d0"><img width="
|
|
283
|
-
<a href="https://codesandbox.io/s/gsm1y"><img width="
|
|
284
|
-
<a href="https://codesandbox.io/s/x8gvs"><img width="
|
|
285
|
-
<a href="https://codesandbox.io/s/yjhzv"><img width="
|
|
286
|
-
<a href="https://codesandbox.io/s/4jr4p"><img width="
|
|
291
|
+
<p>
|
|
292
|
+
<a href="https://codesandbox.io/s/l4klb"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/l4klb/screenshot.png" alt="Horizontal tiles"/></a>
|
|
293
|
+
<a href="https://codesandbox.io/s/4m0d0"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/4m0d0/screenshot.png" alt="M1 scroll"/></a>
|
|
294
|
+
<a href="https://codesandbox.io/s/gsm1y"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/gsm1y/screenshot.png" alt="useIntersect"/></a>
|
|
295
|
+
<a href="https://codesandbox.io/s/x8gvs"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/x8gvs/screenshot.png" alt="Infinite scroll"/></a>
|
|
296
|
+
<a href="https://codesandbox.io/s/yjhzv"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/yjhzv/screenshot.png" alt="Vertical scroll"/></a>
|
|
297
|
+
<a href="https://codesandbox.io/s/4jr4p"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/4jr4p/screenshot.png" alt="GLTF and useScroll"/></a>
|
|
287
298
|
</p>
|
|
288
299
|
|
|
289
300
|
Scroll controls create a HTML scroll container in front of the canvas. Everything you drop into the `<Scroll>` component will be affected.
|
|
@@ -343,6 +354,11 @@ function Foo(props) {
|
|
|
343
354
|
|
|
344
355
|

|
|
345
356
|
|
|
357
|
+
<p>
|
|
358
|
+
<a href="https://codesandbox.io/s/kheke"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/kheke/screenshot.png" alt="Journey stage 1"/></a>
|
|
359
|
+
<a href="https://codesandbox.io/s/qyz5r"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/qyz5r/screenshot.png" alt="Watch"/></a>
|
|
360
|
+
</p>
|
|
361
|
+
|
|
346
362
|
Semi-OrbitControls with spring-physics, polar zoom and snap-back, for presentational purposes. These controls do not turn the camera but will spin their contents. They will not suddenly come to rest when they reach limits like OrbitControls do, but rather smoothly anticipate stopping position.
|
|
347
363
|
|
|
348
364
|
```jsx
|
|
@@ -355,7 +371,7 @@ Semi-OrbitControls with spring-physics, polar zoom and snap-back, for presentati
|
|
|
355
371
|
rotation={[0, 0, 0]} // Default rotation
|
|
356
372
|
polar={[0, Math.PI / 2]} // Vertical limits
|
|
357
373
|
azimuth={[-Infinity, Infinity]} // Horizontal limits
|
|
358
|
-
config
|
|
374
|
+
config={{ mass: 1, tension: 170, friction: 26 }} // Spring config
|
|
359
375
|
>
|
|
360
376
|
<mesh />
|
|
361
377
|
</PresentationControls>
|
|
@@ -398,6 +414,13 @@ A triangle that fills the screen, ideal for full-screen fragment shader work (ra
|
|
|
398
414
|
|
|
399
415
|
#### Image
|
|
400
416
|
|
|
417
|
+
<p>
|
|
418
|
+
<a href="https://codesandbox.io/s/l4klb"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/l4klb/screenshot.png" alt="Horizontal tiles"/></a>
|
|
419
|
+
<a href="https://codesandbox.io/s/gsm1y"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/gsm1y/screenshot.png" alt="useIntersect"/></a>
|
|
420
|
+
<a href="https://codesandbox.io/s/x8gvs"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/x8gvs/screenshot.png" alt="Infinite scroll"/></a>
|
|
421
|
+
<a href="https://codesandbox.io/s/yjhzv"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/yjhzv/screenshot.png" alt="Vertical scroll"/></a>
|
|
422
|
+
</p>
|
|
423
|
+
|
|
401
424
|
A shader-based image component with auto-cover (similar to css/background: cover).
|
|
402
425
|
|
|
403
426
|
```jsx
|
|
@@ -413,9 +436,13 @@ function Foo() {
|
|
|
413
436
|
|
|
414
437
|
#### Text
|
|
415
438
|
|
|
416
|
-
[](https://drei.vercel.app/?path=/story/abstractions-text--text-st)
|
|
439
|
+
[](https://drei.vercel.app/?path=/story/abstractions-text--text-st) 
|
|
417
440
|
|
|
418
|
-
|
|
441
|
+
<p>
|
|
442
|
+
<a href="https://codesandbox.io/s/yup2o"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/yup2o/screenshot.png" alt="Demo"/></a>
|
|
443
|
+
</p>
|
|
444
|
+
|
|
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! Text is suspense-based!
|
|
419
446
|
|
|
420
447
|
```jsx
|
|
421
448
|
<Text color="black" anchorX="center" anchorY="middle">
|
|
@@ -423,6 +450,14 @@ Hi-quality text rendering w/ signed distance fields (SDF) and antialiasing, usin
|
|
|
423
450
|
</Text>
|
|
424
451
|
```
|
|
425
452
|
|
|
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
|
+
|
|
426
461
|
#### Line
|
|
427
462
|
|
|
428
463
|
[](https://drei.vercel.app/?path=/story/abstractions-line--basic-line)
|
|
@@ -445,6 +480,10 @@ Renders a THREE.Line2.
|
|
|
445
480
|
|
|
446
481
|
[](https://drei.vercel.app/?path=/story/abstractions-line--quadratic-bezier)
|
|
447
482
|
|
|
483
|
+
<p>
|
|
484
|
+
<a href="https://codesandbox.io/s/2ij9u"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/2ij9u/screenshot.png" alt="Demo"/></a>
|
|
485
|
+
</p>
|
|
486
|
+
|
|
448
487
|
Renders a THREE.Line2 using THREE.QuadraticBezierCurve3 for interpolation.
|
|
449
488
|
|
|
450
489
|
```jsx
|
|
@@ -499,6 +538,10 @@ Renders a THREE.Line2 using THREE.CubicBezierCurve3 for interpolation.
|
|
|
499
538
|
|
|
500
539
|
#### PositionalAudio
|
|
501
540
|
|
|
541
|
+
<p>
|
|
542
|
+
<a href="https://codesandbox.io/s/gkfhr"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/gkfhr/screenshot.png" alt="Demo"/></a>
|
|
543
|
+
</p>
|
|
544
|
+
|
|
502
545
|
[](https://drei.vercel.app/?path=/story/abstractions-positionalaudio--positional-audio-scene-st) 
|
|
503
546
|
|
|
504
547
|
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.
|
|
@@ -531,7 +574,7 @@ Adds a `<group />` that always faces the camera.
|
|
|
531
574
|
|
|
532
575
|
#### GizmoHelper
|
|
533
576
|
|
|
534
|
-
[](https://drei.pmnd.rs/?path=/story/gizmos-gizmohelper--
|
|
577
|
+
[](https://drei.pmnd.rs/?path=/story/gizmos-gizmohelper--gizmo-helper-story)
|
|
535
578
|
|
|
536
579
|
Used by widgets that visualize and control camera position.
|
|
537
580
|
|
|
@@ -564,12 +607,16 @@ Abstraction around threes own [EffectComposer](https://threejs.org/docs/#example
|
|
|
564
607
|
|
|
565
608
|
#### GradientTexture
|
|
566
609
|
|
|
610
|
+
<p>
|
|
611
|
+
<a href="https://codesandbox.io/s/l03yb"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/l03yb/screenshot.png" alt="Demo"/></a>
|
|
612
|
+
</p>
|
|
613
|
+
|
|
567
614
|
A declarative THREE.Texture which attaches to "map" by default. You can use this to create gradient backgrounds.
|
|
568
615
|
|
|
569
616
|
```jsx
|
|
570
617
|
<mesh>
|
|
571
618
|
<planeGeometry />
|
|
572
|
-
<meshBasicMaterial
|
|
619
|
+
<meshBasicMaterial>
|
|
573
620
|
<GradientTexture
|
|
574
621
|
stops={[0, 1]} // As many stops as you want
|
|
575
622
|
colors={['aquamarine', 'hotpink']} // Colors need to match the number of stops
|
|
@@ -581,6 +628,10 @@ A declarative THREE.Texture which attaches to "map" by default. You can use this
|
|
|
581
628
|
|
|
582
629
|
#### Edges
|
|
583
630
|
|
|
631
|
+
<p>
|
|
632
|
+
<a href="https://codesandbox.io/s/ny3p4"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/ny3p4/screenshot.png" alt="Demo"/></a>
|
|
633
|
+
</p>
|
|
634
|
+
|
|
584
635
|
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.
|
|
585
636
|
|
|
586
637
|
```jsx
|
|
@@ -595,10 +646,174 @@ Abstracts [THREE.EdgesGeometry](https://threejs.org/docs/#api/en/geometries/Edge
|
|
|
595
646
|
</mesh>
|
|
596
647
|
```
|
|
597
648
|
|
|
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
|
+
|
|
598
809
|
#### useAnimations
|
|
599
810
|
|
|
600
811
|
[](https://drei.pmnd.rs/?path=/story/abstractions-useanimations--use-animations-st)
|
|
601
812
|
|
|
813
|
+
<p>
|
|
814
|
+
<a href="https://codesandbox.io/s/pecl6"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/pecl6/screenshot.png" alt="Demo"/></a>
|
|
815
|
+
</p>
|
|
816
|
+
|
|
602
817
|
A hook that abstracts [AnimationMixer](https://threejs.org/docs/#api/en/animation/AnimationMixer).
|
|
603
818
|
|
|
604
819
|
```jsx
|
|
@@ -625,6 +840,11 @@ return <primitive object={scene} />
|
|
|
625
840
|
|
|
626
841
|
[](https://drei.vercel.app/?path=/story/shaders-meshreflectormaterial--reflector-st)
|
|
627
842
|
|
|
843
|
+
<p>
|
|
844
|
+
<a href="https://codesandbox.io/s/lx2h8"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/lx2h8/screenshot.png" alt="Demo"/></a>
|
|
845
|
+
<a href="https://codesandbox.io/s/l900i"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/l900i/screenshot.png" alt="Demo"/></a>
|
|
846
|
+
</p>
|
|
847
|
+
|
|
628
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/#api/en/materials/MeshStandardMaterial) and accepts all its props.
|
|
629
849
|
|
|
630
850
|
```jsx
|
|
@@ -650,6 +870,7 @@ Easily add reflections and/or blur to any mesh. It takes surface roughness into
|
|
|
650
870
|
3 = distortion channel
|
|
651
871
|
4 = lod channel (based on the roughness)
|
|
652
872
|
*/
|
|
873
|
+
reflectorOffset={0.2} // Offsets the virtual camera that projects the reflection. Useful when the reflective surface is some distance from the object's origin (default = 0)
|
|
653
874
|
>
|
|
654
875
|
</mesh>
|
|
655
876
|
```
|
|
@@ -671,6 +892,10 @@ This material makes your geometry wobble and wave around. It was taken from the
|
|
|
671
892
|
|
|
672
893
|
[](https://drei.vercel.app/?path=/story/shaders-meshdistortmaterial--mesh-distort-material-st)
|
|
673
894
|
|
|
895
|
+
<p>
|
|
896
|
+
<a href="https://codesandbox.io/s/l03yb"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/l03yb/screenshot.png" alt="Demo"/></a>
|
|
897
|
+
</p>
|
|
898
|
+
|
|
674
899
|
This material makes your geometry distort following simplex noise.
|
|
675
900
|
|
|
676
901
|
```jsx
|
|
@@ -682,7 +907,7 @@ This material makes your geometry distort following simplex noise.
|
|
|
682
907
|
|
|
683
908
|
#### PointMaterial
|
|
684
909
|
|
|
685
|
-
|
|
910
|
+
Antialiased round dots. It takes the same props as regular THREE.PointsMaterial
|
|
686
911
|
|
|
687
912
|
```jsx
|
|
688
913
|
<points>
|
|
@@ -694,6 +919,10 @@ An antialiased round dot that always keeps the same size.
|
|
|
694
919
|
|
|
695
920
|
[](https://drei.vercel.app/?path=/story/shaders-softshadows--soft-shadows-st)
|
|
696
921
|
|
|
922
|
+
<p>
|
|
923
|
+
<a href="https://codesandbox.io/s/dh2jc"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/dh2jc/screenshot.png" alt="Demo"/></a>
|
|
924
|
+
</p>
|
|
925
|
+
|
|
697
926
|
Injects [percent closer soft shadows (pcss)](https://threejs.org/examples/#webgl_shadowmap_pcss) into threes shader chunk.
|
|
698
927
|
|
|
699
928
|
```jsx
|
|
@@ -710,6 +939,10 @@ softShadows({
|
|
|
710
939
|
|
|
711
940
|
[](https://drei.vercel.app/?path=/story/shaders-shadermaterial--shader-material-story)
|
|
712
941
|
|
|
942
|
+
<p>
|
|
943
|
+
<a href="https://codesandbox.io/s/ni6v4"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/ni6v4/screenshot.png" alt="Demo"/></a>
|
|
944
|
+
</p>
|
|
945
|
+
|
|
713
946
|
Creates a THREE.ShaderMaterial for you with easier handling of uniforms, which are also automatically declared as setter/getters on the object.
|
|
714
947
|
|
|
715
948
|
```jsx
|
|
@@ -804,6 +1037,12 @@ function Scene() {
|
|
|
804
1037
|
|
|
805
1038
|
[](https://drei.vercel.app/?path=/story/misc-html--html-st) 
|
|
806
1039
|
|
|
1040
|
+
<p>
|
|
1041
|
+
<a href="https://codesandbox.io/s/qyz5r"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/qyz5r/screenshot.png" alt="Demo"/></a>
|
|
1042
|
+
<a href="https://codesandbox.io/s/9keg6"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/9keg6/screenshot.png" alt="Demo"/></a>
|
|
1043
|
+
<a href="https://codesandbox.io/s/6oei7"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/6oei7/screenshot.png" alt="Demo"/></a>
|
|
1044
|
+
</p>
|
|
1045
|
+
|
|
807
1046
|
Allows you to tie HTML content to any object of your scene. It will be projected to the objects whereabouts automatically.
|
|
808
1047
|
|
|
809
1048
|
```jsx
|
|
@@ -857,6 +1096,10 @@ const [hidden, set] = useState()
|
|
|
857
1096
|
|
|
858
1097
|

|
|
859
1098
|
|
|
1099
|
+
<p>
|
|
1100
|
+
<a href="https://codesandbox.io/s/ls503"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/ls503/screenshot.png" alt="Demo"/></a>
|
|
1101
|
+
</p>
|
|
1102
|
+
|
|
860
1103
|
This component allows you to cycle through all objects underneath the cursor with optional visual feedback. This can be useful for non-trivial selection, CAD data, housing, everything that has layers. It does this by changing the raycasters filter function and then refreshing the raycaster.
|
|
861
1104
|
|
|
862
1105
|
For this to work properly your event handler have to call `event.stopPropagation()`, for instance in `onPointerOver` or `onClick`, only one element can be selective for cycling to make sense.
|
|
@@ -874,10 +1117,14 @@ For this to work properly your event handler have to call `event.stopPropagation
|
|
|
874
1117
|
|
|
875
1118
|

|
|
876
1119
|
|
|
877
|
-
|
|
1120
|
+
<p>
|
|
1121
|
+
<a href="https://codesandbox.io/s/ny3p4"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/ny3p4/screenshot.png" alt="Demo"/></a>
|
|
1122
|
+
</p>
|
|
1123
|
+
|
|
1124
|
+
This component allows you to select/unselect objects by clicking on them. It keeps track of the currently selected objects and can select multiple objects (with the shift key). Nested components can request the current selection (which is always an array) with the `useSelect` hook. With the `box` prop it will let you shift-box-select objects by holding and draging the cursor over multiple objects. Optionally you can filter the selected items as well as define in which shape they are stored by defining the `filter` prop.
|
|
878
1125
|
|
|
879
1126
|
```jsx
|
|
880
|
-
<Select box multiple onChange={console.log}>
|
|
1127
|
+
<Select box multiple onChange={console.log} filter={items => items}>
|
|
881
1128
|
<Foo />
|
|
882
1129
|
<Bar />
|
|
883
1130
|
</Select>
|
|
@@ -929,7 +1176,7 @@ return <SomethingThatNeedsADepthBuffer depthBuffer={depthBuffer} />
|
|
|
929
1176
|
|
|
930
1177
|
[](https://drei.vercel.app/?path=/story/misc-usefbo--use-fbo-st)
|
|
931
1178
|
|
|
932
|
-
Creates a `THREE.WebGLRenderTarget
|
|
1179
|
+
Creates a `THREE.WebGLRenderTarget`.
|
|
933
1180
|
|
|
934
1181
|
```jsx
|
|
935
1182
|
const target = useFBO({
|
|
@@ -944,6 +1191,10 @@ The rendertarget is automatically disposed when unmounted.
|
|
|
944
1191
|
|
|
945
1192
|
[](https://drei.vercel.app/?path=/story/misc-usecamera--use-camera-st)
|
|
946
1193
|
|
|
1194
|
+
<p>
|
|
1195
|
+
<a href="https://codesandbox.io/s/py4db"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/py4db/screenshot.png" alt="Demo"/></a>
|
|
1196
|
+
</p>
|
|
1197
|
+
|
|
947
1198
|
A hook for the rare case when you are using non-default cameras for heads-up-displays or portals, and you need events/raytracing to function properly (raycasting uses the default camera otherwise).
|
|
948
1199
|
|
|
949
1200
|
```jsx
|
|
@@ -959,6 +1210,7 @@ A hook for a quick way to add helpers to existing nodes in the scene. It handles
|
|
|
959
1210
|
```jsx
|
|
960
1211
|
const mesh = useRef()
|
|
961
1212
|
useHelper(mesh, BoxHelper, 'cyan')
|
|
1213
|
+
useHelper(condition && mesh, BoxHelper, 'red') // you can passe false instead of the object ref to hide the helper
|
|
962
1214
|
|
|
963
1215
|
<mesh ref={mesh} ... />
|
|
964
1216
|
```
|
|
@@ -1015,6 +1267,10 @@ return (
|
|
|
1015
1267
|
|
|
1016
1268
|
#### useIntersect
|
|
1017
1269
|
|
|
1270
|
+
<p>
|
|
1271
|
+
<a href="https://codesandbox.io/s/gsm1y"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/gsm1y/screenshot.png" alt="Demo"/></a>
|
|
1272
|
+
</p>
|
|
1273
|
+
|
|
1018
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/#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.
|
|
1019
1275
|
|
|
1020
1276
|
```jsx
|
|
@@ -1022,12 +1278,66 @@ const ref = useIntersect((visible) => console.log('object is visible', visible))
|
|
|
1022
1278
|
return <mesh ref={ref} />
|
|
1023
1279
|
```
|
|
1024
1280
|
|
|
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
|
+
|
|
1025
1331
|
# Loading
|
|
1026
1332
|
|
|
1027
1333
|
#### Loader
|
|
1028
1334
|
|
|
1029
1335
|

|
|
1030
1336
|
|
|
1337
|
+
<p>
|
|
1338
|
+
<a href="https://codesandbox.io/s/0buje"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/0buje/screenshot.png" alt="Demo"/></a>
|
|
1339
|
+
</p>
|
|
1340
|
+
|
|
1031
1341
|
A quick and easy loading overlay component that you can drop on top of your canvas. It's intended to "hide" the whole app, so if you have multiple suspense wrappers in your application, you should use multiple loaders. It will show an animated loadingbar and a percentage.
|
|
1032
1342
|
|
|
1033
1343
|
```jsx
|
|
@@ -1156,6 +1466,11 @@ const envMap = useCubeTexture(['px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png',
|
|
|
1156
1466
|
|
|
1157
1467
|
#### Instances
|
|
1158
1468
|
|
|
1469
|
+
<p>
|
|
1470
|
+
<a href="https://codesandbox.io/s/h8o2d"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/h8o2d/screenshot.png" alt="Demo"/></a>
|
|
1471
|
+
<a href="https://codesandbox.io/s/i6t0j"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/i6t0j/screenshot.png" alt="Demo"/></a>
|
|
1472
|
+
</p>
|
|
1473
|
+
|
|
1159
1474
|
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!
|
|
1160
1475
|
|
|
1161
1476
|
```jsx
|
|
@@ -1197,8 +1512,14 @@ You can define events on them!
|
|
|
1197
1512
|
<Instance onClick={...} onPointerOver={...} />
|
|
1198
1513
|
```
|
|
1199
1514
|
|
|
1515
|
+
π Note: While creating instances declaratively keeps all the power of components with reduced draw calls, it comes at the cost of CPU overhead. For cases like foliage where you want no CPU overhead with thousands of intances you should use THREE.InstancedMesh such as in this [example](https://codesandbox.io/s/grass-shader-5xho4?file=/src/Grass.js).
|
|
1516
|
+
|
|
1200
1517
|
#### Merged
|
|
1201
1518
|
|
|
1519
|
+
<p>
|
|
1520
|
+
<a href="https://codesandbox.io/s/l900i"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/l900i/screenshot.png" alt="Demo"/></a>
|
|
1521
|
+
</p>
|
|
1522
|
+
|
|
1202
1523
|
This creates instances for existing meshes and allows you to use them cheaply in the same scene graph. Each type will cost you exactly one draw call, no matter how many you use. `meshes` has to be a collection of pre-existing THREE.Mesh objects.
|
|
1203
1524
|
|
|
1204
1525
|
```jsx
|
|
@@ -1242,27 +1563,12 @@ A wrapper around [THREE.Points](https://threejs.org/docs/#api/en/objects/Points)
|
|
|
1242
1563
|
limit={1000} // Optional: max amount of items (for calculating buffer size)
|
|
1243
1564
|
range={1000} // Optional: draw-range
|
|
1244
1565
|
>
|
|
1245
|
-
<pointsMaterial />
|
|
1566
|
+
<pointsMaterial vertexColors />
|
|
1246
1567
|
<Point position={[1, 2, 3]} color="red" onClick={onClick} onPointerOver={onPointerOver} ... />
|
|
1247
1568
|
// As many as you want, make them conditional, mount/unmount them, lazy load them, etc ...
|
|
1248
1569
|
</Points>
|
|
1249
1570
|
```
|
|
1250
1571
|
|
|
1251
|
-
If you have a material that supports vertex colors (like drei/PointMaterial) you can have individual colors!
|
|
1252
|
-
|
|
1253
|
-
```jsx
|
|
1254
|
-
<Points>
|
|
1255
|
-
<PointMaterial />
|
|
1256
|
-
<Point color="hotpink" />
|
|
1257
|
-
```
|
|
1258
|
-
|
|
1259
|
-
Otherwise use any material you like:
|
|
1260
|
-
|
|
1261
|
-
```jsx
|
|
1262
|
-
<Points>
|
|
1263
|
-
<pointsMaterial vertexColors size={10} />
|
|
1264
|
-
```
|
|
1265
|
-
|
|
1266
1572
|
If you just want to use buffers for position, color and size, you can use the alternative API:
|
|
1267
1573
|
|
|
1268
1574
|
```jsx
|
|
@@ -1310,6 +1616,10 @@ useFrame(() => {
|
|
|
1310
1616
|
|
|
1311
1617
|
[](https://drei.vercel.app/?path=/story/abstractions-detailed--detailed-st)
|
|
1312
1618
|
|
|
1619
|
+
<p>
|
|
1620
|
+
<a href="https://codesandbox.io/s/12nmp"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/12nmp/screenshot.png" alt="Demo"/></a>
|
|
1621
|
+
</p>
|
|
1622
|
+
|
|
1313
1623
|
A wrapper around [THREE.LOD](https://threejs.org/docs/#api/en/objects/LOD) (Level of detail).
|
|
1314
1624
|
|
|
1315
1625
|
```jsx
|
|
@@ -1356,7 +1666,7 @@ A very fast, but often good-enough bounds-only raycast for meshes. You can use t
|
|
|
1356
1666
|
|
|
1357
1667
|
#### AdaptiveDpr
|
|
1358
1668
|
|
|
1359
|
-
Drop this component into your scene and it will cut the pixel-ratio on
|
|
1669
|
+
Drop this component into your scene and it will cut the pixel-ratio on regress according to the canvas's performance min/max settings. This allows you to temporarily reduce visual quality in exchange 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.
|
|
1360
1670
|
|
|
1361
1671
|
```jsx
|
|
1362
1672
|
<AdaptiveDpr pixelated />
|
|
@@ -1387,9 +1697,9 @@ useBVH(mesh)
|
|
|
1387
1697
|
|
|
1388
1698
|
#### Center
|
|
1389
1699
|
|
|
1390
|
-
[](https://drei.
|
|
1700
|
+
[](https://drei.pmnd.rs/?path=/story/staging-center--default-story)
|
|
1391
1701
|
|
|
1392
|
-
Calculates a boundary box and centers its children accordingly. `alignTop`
|
|
1702
|
+
Calculates a boundary box and centers its children accordingly. `alignTop` adjusts it so that it sits flush on y=0.
|
|
1393
1703
|
|
|
1394
1704
|
```jsx
|
|
1395
1705
|
<Center alignTop>
|
|
@@ -1399,10 +1709,14 @@ Calculates a boundary box and centers its children accordingly. `alignTop` makes
|
|
|
1399
1709
|
|
|
1400
1710
|
#### Bounds
|
|
1401
1711
|
|
|
1712
|
+
<p>
|
|
1713
|
+
<a href="https://codesandbox.io/s/rz2g0"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/rz2g0/screenshot.png" alt="Demo"/></a>
|
|
1714
|
+
</p>
|
|
1715
|
+
|
|
1402
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.
|
|
1403
1717
|
|
|
1404
1718
|
```jsx
|
|
1405
|
-
<Bounds fit clip damping={6} margin={1.2}>
|
|
1719
|
+
<Bounds fit clip observe damping={6} margin={1.2}>
|
|
1406
1720
|
<mesh />
|
|
1407
1721
|
</Bounds>
|
|
1408
1722
|
```
|
|
@@ -1425,7 +1739,12 @@ function Foo() {
|
|
|
1425
1739
|
|
|
1426
1740
|
#### CameraShake
|
|
1427
1741
|
|
|
1428
|
-
[](https://drei.
|
|
1742
|
+
[](https://drei.pmnd.rs/?path=/story/staging-camerashake--camera-shake-story)
|
|
1743
|
+
|
|
1744
|
+
<p>
|
|
1745
|
+
<a href="https://codesandbox.io/s/t4l0f"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/t4l0f/screenshot.png" alt="Demo"/></a>
|
|
1746
|
+
<a href="https://codesandbox.io/s/0ycwe"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/0ycwe/screenshot.png" alt="Demo"/></a>
|
|
1747
|
+
</p>
|
|
1429
1748
|
|
|
1430
1749
|
A component for applying a configurable camera shake effect. Currently only supports rotational camera shake. Pass a ref to recieve the `ShakeController` API.
|
|
1431
1750
|
|
|
@@ -1457,6 +1776,10 @@ interface ShakeController {
|
|
|
1457
1776
|
|
|
1458
1777
|
#### Float
|
|
1459
1778
|
|
|
1779
|
+
<p>
|
|
1780
|
+
<a href="https://codesandbox.io/s/2ij9u"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/2ij9u/screenshot.png" alt="Demo"/></a>
|
|
1781
|
+
</p>
|
|
1782
|
+
|
|
1460
1783
|
This component makes its contents float or hover.
|
|
1461
1784
|
|
|
1462
1785
|
```js
|
|
@@ -1471,7 +1794,7 @@ This component makes its contents float or hover.
|
|
|
1471
1794
|
|
|
1472
1795
|
#### Stage
|
|
1473
1796
|
|
|
1474
|
-
[](https://drei.pmnd.rs/?path=/story/
|
|
1797
|
+
[](https://drei.pmnd.rs/?path=/story/staging-stage--stage-st)
|
|
1475
1798
|
|
|
1476
1799
|
Creates a "stage" with proper studio lighting, content centered and planar, shadows and ground-contact shadows.
|
|
1477
1800
|
|
|
@@ -1485,6 +1808,10 @@ Make sure to set the `makeDefault` prop on your controls, in that case you do no
|
|
|
1485
1808
|
|
|
1486
1809
|
#### Backdrop
|
|
1487
1810
|
|
|
1811
|
+
<p>
|
|
1812
|
+
<a href="https://codesandbox.io/s/8yfnd"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/8yfnd/screenshot.png" alt="Demo"/></a>
|
|
1813
|
+
</p>
|
|
1814
|
+
|
|
1488
1815
|
A curved plane, like a studio backdrop. This is for presentational purposes, to break up light and shadows more interestingly.
|
|
1489
1816
|
|
|
1490
1817
|
```jsx
|
|
@@ -1513,12 +1840,16 @@ A cheap canvas-texture-based circular gradient.
|
|
|
1513
1840
|
|
|
1514
1841
|
#### ContactShadows
|
|
1515
1842
|
|
|
1516
|
-
[](https://drei.
|
|
1843
|
+
[](https://drei.pmnd.rs/?path=/story/staging-contactshadows--contact-shadow-st)
|
|
1844
|
+
|
|
1845
|
+
<p>
|
|
1846
|
+
<a href="https://codesandbox.io/s/qxjoj"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/qxjoj/screenshot.png" alt="Demo"/></a>
|
|
1847
|
+
</p>
|
|
1517
1848
|
|
|
1518
1849
|
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]`.
|
|
1519
1850
|
|
|
1520
1851
|
```jsx
|
|
1521
|
-
<ContactShadows opacity={1} scale={10} blur={1} far={10} resolution={256} />
|
|
1852
|
+
<ContactShadows opacity={1} scale={10} blur={1} far={10} resolution={256} color="#000000" />
|
|
1522
1853
|
```
|
|
1523
1854
|
|
|
1524
1855
|
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:
|
|
@@ -1529,6 +1860,11 @@ Since this is a rather expensive effect you can limit the amount of frames it re
|
|
|
1529
1860
|
|
|
1530
1861
|
#### SpotLight
|
|
1531
1862
|
|
|
1863
|
+
<p>
|
|
1864
|
+
<a href="https://codesandbox.io/s/tx1pq"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/tx1pq/screenshot.png" alt="Demo"/></a>
|
|
1865
|
+
<a href="https://codesandbox.io/s/wdzv4"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/wdzv4/screenshot.png" alt="Demo"/></a>
|
|
1866
|
+
</p>
|
|
1867
|
+
|
|
1532
1868
|
A Volumetric spotlight.
|
|
1533
1869
|
|
|
1534
1870
|
```jsx
|
|
@@ -1550,17 +1886,26 @@ function Foo() {
|
|
|
1550
1886
|
|
|
1551
1887
|
#### Environment
|
|
1552
1888
|
|
|
1553
|
-
[](https://drei.pmnd.rs/?path=/story/
|
|
1889
|
+
[](https://drei.pmnd.rs/?path=/story/staging-environment--environment-story)
|
|
1890
|
+
|
|
1891
|
+
<p>
|
|
1892
|
+
<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
|
+
</p>
|
|
1554
1897
|
|
|
1555
1898
|
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.
|
|
1556
1899
|
|
|
1900
|
+
π Note: `preset` property is not meant to be used in production environments. Consider using `files` property together with local files or a CDN of your choice instead.
|
|
1901
|
+
|
|
1557
1902
|
```jsx
|
|
1558
1903
|
<Environment
|
|
1559
|
-
background={false}
|
|
1904
|
+
background={false} // can be true, false or "only" (which only sets the background) (default: false)
|
|
1560
1905
|
files={['px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png', 'nz.png']}
|
|
1561
1906
|
path="/"
|
|
1562
1907
|
preset={null}
|
|
1563
|
-
scene={undefined} // adds the ability to pass a custom THREE.Scene
|
|
1908
|
+
scene={undefined} // adds the ability to pass a custom THREE.Scene, can also be a ref
|
|
1564
1909
|
/>
|
|
1565
1910
|
```
|
|
1566
1911
|
|
|
@@ -1570,9 +1915,67 @@ If you provide a single string it will use THREE.RGBELoader.
|
|
|
1570
1915
|
<Environment files="file.hdr" />
|
|
1571
1916
|
```
|
|
1572
1917
|
|
|
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
|
+
|
|
1573
1972
|
#### Sky
|
|
1574
1973
|
|
|
1575
|
-
[](https://drei.
|
|
1974
|
+
[](https://drei.pmnd.rs/?path=/story/staging-sky--sky-st)
|
|
1975
|
+
|
|
1976
|
+
<p>
|
|
1977
|
+
<a href="https://codesandbox.io/s/vkgi6"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/vkgi6/screenshot.png" alt="Demo"/></a>
|
|
1978
|
+
</p>
|
|
1576
1979
|
|
|
1577
1980
|
Adds a [sky](https://threejs.org/examples/#webgl_shaders_sky) to your scene.
|
|
1578
1981
|
|
|
@@ -1582,7 +1985,7 @@ Adds a [sky](https://threejs.org/examples/#webgl_shaders_sky) to your scene.
|
|
|
1582
1985
|
|
|
1583
1986
|
#### Stars
|
|
1584
1987
|
|
|
1585
|
-
[](https://drei.
|
|
1988
|
+
[](https://drei.pmnd.rs/?path=/story/staging-stars--stars-st)
|
|
1586
1989
|
|
|
1587
1990
|
Adds a blinking shader-based starfield to your scene.
|
|
1588
1991
|
|
|
@@ -1594,8 +1997,14 @@ Adds a blinking shader-based starfield to your scene.
|
|
|
1594
1997
|
|
|
1595
1998
|
[](https://drei.pmnd.rs/?path=/story/staging-cloud--cloud-st) 
|
|
1596
1999
|
|
|
2000
|
+
<p>
|
|
2001
|
+
<a href="https://codesandbox.io/s/mbfzf"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/mbfzf/screenshot.png" alt="Demo"/></a>
|
|
2002
|
+
</p>
|
|
2003
|
+
|
|
1597
2004
|
Particle based cloud.
|
|
1598
2005
|
|
|
2006
|
+
π Note: `<Cloud />` component is not meant to be used in production environments as it relies on third-party CDN.
|
|
2007
|
+
|
|
1599
2008
|
```jsx
|
|
1600
2009
|
<Cloud
|
|
1601
2010
|
opacity={0.5}
|
|
@@ -1608,12 +2017,14 @@ Particle based cloud.
|
|
|
1608
2017
|
|
|
1609
2018
|
#### useMatcapTexture
|
|
1610
2019
|
|
|
1611
|
-
[](https://drei.pmnd.rs/?path=/story/
|
|
2020
|
+
[](https://drei.pmnd.rs/?path=/story/staging-usematcaptexture--use-matcap-texture-st) 
|
|
1612
2021
|
|
|
1613
2022
|
Loads matcap textures from this repository: https://github.com/emmelleppi/matcaps
|
|
1614
2023
|
|
|
1615
2024
|
(It is a fork of this repository: https://github.com/nidorx/matcaps)
|
|
1616
2025
|
|
|
2026
|
+
π Note: `useMatcapTexture` hook is not meant to be used in production environments as it relies on third-party CDN.
|
|
2027
|
+
|
|
1617
2028
|
```jsx
|
|
1618
2029
|
const [matcap, url] = useMatcapTexture(
|
|
1619
2030
|
0, // index of the matcap texture https://github.com/emmelleppi/matcaps/blob/master/matcap-list.json
|
|
@@ -1637,10 +2048,12 @@ const [matcap] = useMatcapTexture('3E2335_D36A1B_8E4A2E_2842A5')
|
|
|
1637
2048
|
|
|
1638
2049
|
#### useNormalTexture
|
|
1639
2050
|
|
|
1640
|
-
[](https://drei.pmnd.rs/?path=/story/
|
|
2051
|
+
[](https://drei.pmnd.rs/?path=/story/staging-usenormaltexture--use-normal-texture-st) 
|
|
1641
2052
|
|
|
1642
2053
|
Loads normal textures from this repository: https://github.com/emmelleppi/normal-maps
|
|
1643
2054
|
|
|
2055
|
+
π Note: `useNormalTexture` hook is not meant to be used in production environments as it relies on third-party CDN.
|
|
2056
|
+
|
|
1644
2057
|
```jsx
|
|
1645
2058
|
const [normalMap, url] = useNormalTexture(
|
|
1646
2059
|
1, // index of the normal texture - https://github.com/emmelleppi/normal-maps/blob/master/normals.json
|