@react-three/drei 9.0.0-beta.1 → 9.0.0-beta.2
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 +168 -22
- package/core/ArcballControls.cjs.js +1 -1
- package/core/ArcballControls.d.ts +8 -8
- package/core/ArcballControls.js +6 -5
- package/core/Cloud.cjs.js +1 -1
- package/core/Cloud.d.ts +2 -1
- package/core/Cloud.js +3 -2
- package/core/ContactShadows.cjs.js +1 -1
- package/core/ContactShadows.d.ts +2 -1
- package/core/ContactShadows.js +18 -11
- package/core/CubeCamera.cjs.js +1 -1
- package/core/CubeCamera.js +1 -2
- package/core/CurveModifier.cjs.js +1 -1
- package/core/CurveModifier.js +18 -22
- package/core/Detailed.d.ts +1 -1
- package/core/Effects.d.ts +1 -1
- package/core/Environment.cjs.js +1 -1
- package/core/Environment.js +8 -27
- package/core/FirstPersonControls.d.ts +1 -1
- 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.d.ts +1 -1
- package/core/Instances.d.ts +1 -1
- 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 +4 -3
- 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 +5 -4
- package/core/OrthographicCamera.d.ts +1 -1
- package/core/PerspectiveCamera.d.ts +1 -1
- package/core/PositionalAudio.d.ts +1 -1
- package/core/Reflector.cjs.js +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/Shadow.d.ts +1 -1
- package/core/SpotLight.d.ts +19 -3
- package/core/Stage.cjs.js +1 -1
- package/core/Stage.d.ts +1 -1
- package/core/Stats.cjs.js +1 -1
- package/core/Stats.js +1 -1
- package/core/Text.cjs.js +1 -1
- package/core/Text.d.ts +1 -1
- package/core/Text.js +8 -1
- package/core/TransformControls.cjs.js +1 -1
- package/core/TransformControls.d.ts +1 -1
- package/core/TransformControls.js +9 -1
- package/core/index.cjs.js +1 -1
- package/core/index.js +2 -2
- package/core/shaderMaterial.d.ts +1 -1
- package/core/useDetectGPU.cjs.js +1 -1
- package/core/useDetectGPU.js +2 -2
- package/core/useGLTF.d.ts +1 -1
- package/core/useHelper.cjs.js +1 -1
- package/core/useHelper.d.ts +2 -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/materials/MeshReflectorMaterial.cjs.js +1 -1
- package/materials/MeshReflectorMaterial.js +4 -5
- package/native/index.cjs.js +1 -1
- package/native/index.js +2 -2
- package/package.json +6 -6
- 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 +2 -2
package/README.md
CHANGED
|
@@ -249,6 +249,10 @@ PointerLockControls additionally supports a `selector` prop, which enables the b
|
|
|
249
249
|
|
|
250
250
|
[](https://drei.vercel.app/?path=/story/controls-transformcontrols--transform-controls-story)
|
|
251
251
|
|
|
252
|
+
<p>
|
|
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>
|
|
254
|
+
</p>
|
|
255
|
+
|
|
252
256
|
An abstraction around [THREE.TransformControls](https://threejs.org/docs/#examples/en/controls/TransformControls).
|
|
253
257
|
|
|
254
258
|
You can wrap objects which then receive a transform gizmo.
|
|
@@ -277,13 +281,13 @@ If you are using other controls (Orbit, Trackball, etc), you will notice how the
|
|
|
277
281
|
|
|
278
282
|

|
|
279
283
|
|
|
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="
|
|
284
|
+
<p>
|
|
285
|
+
<a href="https://codesandbox.io/s/l4klb"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/l4klb/screenshot.png" alt="Horizontal tiles"/></a>
|
|
286
|
+
<a href="https://codesandbox.io/s/4m0d0"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/4m0d0/screenshot.png" alt="M1 scroll"/></a>
|
|
287
|
+
<a href="https://codesandbox.io/s/gsm1y"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/gsm1y/screenshot.png" alt="useIntersect"/></a>
|
|
288
|
+
<a href="https://codesandbox.io/s/x8gvs"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/x8gvs/screenshot.png" alt="Infinite scroll"/></a>
|
|
289
|
+
<a href="https://codesandbox.io/s/yjhzv"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/yjhzv/screenshot.png" alt="Vertical scroll"/></a>
|
|
290
|
+
<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
291
|
</p>
|
|
288
292
|
|
|
289
293
|
Scroll controls create a HTML scroll container in front of the canvas. Everything you drop into the `<Scroll>` component will be affected.
|
|
@@ -343,6 +347,11 @@ function Foo(props) {
|
|
|
343
347
|
|
|
344
348
|

|
|
345
349
|
|
|
350
|
+
<p>
|
|
351
|
+
<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>
|
|
352
|
+
<a href="https://codesandbox.io/s/qyz5r"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/qyz5r/screenshot.png" alt="Watch"/></a>
|
|
353
|
+
</p>
|
|
354
|
+
|
|
346
355
|
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
356
|
|
|
348
357
|
```jsx
|
|
@@ -398,6 +407,13 @@ A triangle that fills the screen, ideal for full-screen fragment shader work (ra
|
|
|
398
407
|
|
|
399
408
|
#### Image
|
|
400
409
|
|
|
410
|
+
<p>
|
|
411
|
+
<a href="https://codesandbox.io/s/l4klb"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/l4klb/screenshot.png" alt="Horizontal tiles"/></a>
|
|
412
|
+
<a href="https://codesandbox.io/s/gsm1y"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/gsm1y/screenshot.png" alt="useIntersect"/></a>
|
|
413
|
+
<a href="https://codesandbox.io/s/x8gvs"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/x8gvs/screenshot.png" alt="Infinite scroll"/></a>
|
|
414
|
+
<a href="https://codesandbox.io/s/yjhzv"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/yjhzv/screenshot.png" alt="Vertical scroll"/></a>
|
|
415
|
+
</p>
|
|
416
|
+
|
|
401
417
|
A shader-based image component with auto-cover (similar to css/background: cover).
|
|
402
418
|
|
|
403
419
|
```jsx
|
|
@@ -413,9 +429,13 @@ function Foo() {
|
|
|
413
429
|
|
|
414
430
|
#### Text
|
|
415
431
|
|
|
416
|
-
[](https://drei.vercel.app/?path=/story/abstractions-text--text-st)
|
|
432
|
+
[](https://drei.vercel.app/?path=/story/abstractions-text--text-st) 
|
|
433
|
+
|
|
434
|
+
<p>
|
|
435
|
+
<a href="https://codesandbox.io/s/yup2o"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/yup2o/screenshot.png" alt="Demo"/></a>
|
|
436
|
+
</p>
|
|
417
437
|
|
|
418
|
-
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!
|
|
419
439
|
|
|
420
440
|
```jsx
|
|
421
441
|
<Text color="black" anchorX="center" anchorY="middle">
|
|
@@ -445,6 +465,10 @@ Renders a THREE.Line2.
|
|
|
445
465
|
|
|
446
466
|
[](https://drei.vercel.app/?path=/story/abstractions-line--quadratic-bezier)
|
|
447
467
|
|
|
468
|
+
<p>
|
|
469
|
+
<a href="https://codesandbox.io/s/2ij9u"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/2ij9u/screenshot.png" alt="Demo"/></a>
|
|
470
|
+
</p>
|
|
471
|
+
|
|
448
472
|
Renders a THREE.Line2 using THREE.QuadraticBezierCurve3 for interpolation.
|
|
449
473
|
|
|
450
474
|
```jsx
|
|
@@ -499,6 +523,10 @@ Renders a THREE.Line2 using THREE.CubicBezierCurve3 for interpolation.
|
|
|
499
523
|
|
|
500
524
|
#### PositionalAudio
|
|
501
525
|
|
|
526
|
+
<p>
|
|
527
|
+
<a href="https://codesandbox.io/s/gkfhr"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/gkfhr/screenshot.png" alt="Demo"/></a>
|
|
528
|
+
</p>
|
|
529
|
+
|
|
502
530
|
[](https://drei.vercel.app/?path=/story/abstractions-positionalaudio--positional-audio-scene-st) 
|
|
503
531
|
|
|
504
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.
|
|
@@ -531,7 +559,7 @@ Adds a `<group />` that always faces the camera.
|
|
|
531
559
|
|
|
532
560
|
#### GizmoHelper
|
|
533
561
|
|
|
534
|
-
[](https://drei.pmnd.rs/?path=/story/gizmos-gizmohelper--
|
|
562
|
+
[](https://drei.pmnd.rs/?path=/story/gizmos-gizmohelper--gizmo-helper-story)
|
|
535
563
|
|
|
536
564
|
Used by widgets that visualize and control camera position.
|
|
537
565
|
|
|
@@ -564,12 +592,16 @@ Abstraction around threes own [EffectComposer](https://threejs.org/docs/#example
|
|
|
564
592
|
|
|
565
593
|
#### GradientTexture
|
|
566
594
|
|
|
595
|
+
<p>
|
|
596
|
+
<a href="https://codesandbox.io/s/l03yb"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/l03yb/screenshot.png" alt="Demo"/></a>
|
|
597
|
+
</p>
|
|
598
|
+
|
|
567
599
|
A declarative THREE.Texture which attaches to "map" by default. You can use this to create gradient backgrounds.
|
|
568
600
|
|
|
569
601
|
```jsx
|
|
570
602
|
<mesh>
|
|
571
603
|
<planeGeometry />
|
|
572
|
-
<meshBasicMaterial
|
|
604
|
+
<meshBasicMaterial>
|
|
573
605
|
<GradientTexture
|
|
574
606
|
stops={[0, 1]} // As many stops as you want
|
|
575
607
|
colors={['aquamarine', 'hotpink']} // Colors need to match the number of stops
|
|
@@ -581,6 +613,10 @@ A declarative THREE.Texture which attaches to "map" by default. You can use this
|
|
|
581
613
|
|
|
582
614
|
#### Edges
|
|
583
615
|
|
|
616
|
+
<p>
|
|
617
|
+
<a href="https://codesandbox.io/s/ny3p4"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/ny3p4/screenshot.png" alt="Demo"/></a>
|
|
618
|
+
</p>
|
|
619
|
+
|
|
584
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.
|
|
585
621
|
|
|
586
622
|
```jsx
|
|
@@ -599,6 +635,10 @@ Abstracts [THREE.EdgesGeometry](https://threejs.org/docs/#api/en/geometries/Edge
|
|
|
599
635
|
|
|
600
636
|
[](https://drei.pmnd.rs/?path=/story/abstractions-useanimations--use-animations-st)
|
|
601
637
|
|
|
638
|
+
<p>
|
|
639
|
+
<a href="https://codesandbox.io/s/pecl6"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/pecl6/screenshot.png" alt="Demo"/></a>
|
|
640
|
+
</p>
|
|
641
|
+
|
|
602
642
|
A hook that abstracts [AnimationMixer](https://threejs.org/docs/#api/en/animation/AnimationMixer).
|
|
603
643
|
|
|
604
644
|
```jsx
|
|
@@ -625,6 +665,11 @@ return <primitive object={scene} />
|
|
|
625
665
|
|
|
626
666
|
[](https://drei.vercel.app/?path=/story/shaders-meshreflectormaterial--reflector-st)
|
|
627
667
|
|
|
668
|
+
<p>
|
|
669
|
+
<a href="https://codesandbox.io/s/lx2h8"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/lx2h8/screenshot.png" alt="Demo"/></a>
|
|
670
|
+
<a href="https://codesandbox.io/s/l900i"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/l900i/screenshot.png" alt="Demo"/></a>
|
|
671
|
+
</p>
|
|
672
|
+
|
|
628
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.
|
|
629
674
|
|
|
630
675
|
```jsx
|
|
@@ -650,6 +695,7 @@ Easily add reflections and/or blur to any mesh. It takes surface roughness into
|
|
|
650
695
|
3 = distortion channel
|
|
651
696
|
4 = lod channel (based on the roughness)
|
|
652
697
|
*/
|
|
698
|
+
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
699
|
>
|
|
654
700
|
</mesh>
|
|
655
701
|
```
|
|
@@ -671,6 +717,10 @@ This material makes your geometry wobble and wave around. It was taken from the
|
|
|
671
717
|
|
|
672
718
|
[](https://drei.vercel.app/?path=/story/shaders-meshdistortmaterial--mesh-distort-material-st)
|
|
673
719
|
|
|
720
|
+
<p>
|
|
721
|
+
<a href="https://codesandbox.io/s/l03yb"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/l03yb/screenshot.png" alt="Demo"/></a>
|
|
722
|
+
</p>
|
|
723
|
+
|
|
674
724
|
This material makes your geometry distort following simplex noise.
|
|
675
725
|
|
|
676
726
|
```jsx
|
|
@@ -694,6 +744,10 @@ An antialiased round dot that always keeps the same size.
|
|
|
694
744
|
|
|
695
745
|
[](https://drei.vercel.app/?path=/story/shaders-softshadows--soft-shadows-st)
|
|
696
746
|
|
|
747
|
+
<p>
|
|
748
|
+
<a href="https://codesandbox.io/s/dh2jc"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/dh2jc/screenshot.png" alt="Demo"/></a>
|
|
749
|
+
</p>
|
|
750
|
+
|
|
697
751
|
Injects [percent closer soft shadows (pcss)](https://threejs.org/examples/#webgl_shadowmap_pcss) into threes shader chunk.
|
|
698
752
|
|
|
699
753
|
```jsx
|
|
@@ -710,6 +764,10 @@ softShadows({
|
|
|
710
764
|
|
|
711
765
|
[](https://drei.vercel.app/?path=/story/shaders-shadermaterial--shader-material-story)
|
|
712
766
|
|
|
767
|
+
<p>
|
|
768
|
+
<a href="https://codesandbox.io/s/ni6v4"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/ni6v4/screenshot.png" alt="Demo"/></a>
|
|
769
|
+
</p>
|
|
770
|
+
|
|
713
771
|
Creates a THREE.ShaderMaterial for you with easier handling of uniforms, which are also automatically declared as setter/getters on the object.
|
|
714
772
|
|
|
715
773
|
```jsx
|
|
@@ -804,6 +862,12 @@ function Scene() {
|
|
|
804
862
|
|
|
805
863
|
[](https://drei.vercel.app/?path=/story/misc-html--html-st) 
|
|
806
864
|
|
|
865
|
+
<p>
|
|
866
|
+
<a href="https://codesandbox.io/s/qyz5r"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/qyz5r/screenshot.png" alt="Demo"/></a>
|
|
867
|
+
<a href="https://codesandbox.io/s/9keg6"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/9keg6/screenshot.png" alt="Demo"/></a>
|
|
868
|
+
<a href="https://codesandbox.io/s/6oei7"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/6oei7/screenshot.png" alt="Demo"/></a>
|
|
869
|
+
</p>
|
|
870
|
+
|
|
807
871
|
Allows you to tie HTML content to any object of your scene. It will be projected to the objects whereabouts automatically.
|
|
808
872
|
|
|
809
873
|
```jsx
|
|
@@ -857,6 +921,10 @@ const [hidden, set] = useState()
|
|
|
857
921
|
|
|
858
922
|

|
|
859
923
|
|
|
924
|
+
<p>
|
|
925
|
+
<a href="https://codesandbox.io/s/ls503"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/ls503/screenshot.png" alt="Demo"/></a>
|
|
926
|
+
</p>
|
|
927
|
+
|
|
860
928
|
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
929
|
|
|
862
930
|
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 +942,14 @@ For this to work properly your event handler have to call `event.stopPropagation
|
|
|
874
942
|
|
|
875
943
|

|
|
876
944
|
|
|
877
|
-
|
|
945
|
+
<p>
|
|
946
|
+
<a href="https://codesandbox.io/s/ny3p4"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/ny3p4/screenshot.png" alt="Demo"/></a>
|
|
947
|
+
</p>
|
|
948
|
+
|
|
949
|
+
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
950
|
|
|
879
951
|
```jsx
|
|
880
|
-
<Select box multiple onChange={console.log}>
|
|
952
|
+
<Select box multiple onChange={console.log} filter={items => items}>
|
|
881
953
|
<Foo />
|
|
882
954
|
<Bar />
|
|
883
955
|
</Select>
|
|
@@ -944,6 +1016,10 @@ The rendertarget is automatically disposed when unmounted.
|
|
|
944
1016
|
|
|
945
1017
|
[](https://drei.vercel.app/?path=/story/misc-usecamera--use-camera-st)
|
|
946
1018
|
|
|
1019
|
+
<p>
|
|
1020
|
+
<a href="https://codesandbox.io/s/py4db"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/py4db/screenshot.png" alt="Demo"/></a>
|
|
1021
|
+
</p>
|
|
1022
|
+
|
|
947
1023
|
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
1024
|
|
|
949
1025
|
```jsx
|
|
@@ -959,6 +1035,7 @@ A hook for a quick way to add helpers to existing nodes in the scene. It handles
|
|
|
959
1035
|
```jsx
|
|
960
1036
|
const mesh = useRef()
|
|
961
1037
|
useHelper(mesh, BoxHelper, 'cyan')
|
|
1038
|
+
useHelper(condition && mesh, BoxHelper, 'red') // you can passe false instead of the object ref to hide the helper
|
|
962
1039
|
|
|
963
1040
|
<mesh ref={mesh} ... />
|
|
964
1041
|
```
|
|
@@ -1015,6 +1092,10 @@ return (
|
|
|
1015
1092
|
|
|
1016
1093
|
#### useIntersect
|
|
1017
1094
|
|
|
1095
|
+
<p>
|
|
1096
|
+
<a href="https://codesandbox.io/s/gsm1y"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/gsm1y/screenshot.png" alt="Demo"/></a>
|
|
1097
|
+
</p>
|
|
1098
|
+
|
|
1018
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.
|
|
1019
1100
|
|
|
1020
1101
|
```jsx
|
|
@@ -1028,6 +1109,10 @@ return <mesh ref={ref} />
|
|
|
1028
1109
|
|
|
1029
1110
|

|
|
1030
1111
|
|
|
1112
|
+
<p>
|
|
1113
|
+
<a href="https://codesandbox.io/s/0buje"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/0buje/screenshot.png" alt="Demo"/></a>
|
|
1114
|
+
</p>
|
|
1115
|
+
|
|
1031
1116
|
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
1117
|
|
|
1033
1118
|
```jsx
|
|
@@ -1156,6 +1241,11 @@ const envMap = useCubeTexture(['px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png',
|
|
|
1156
1241
|
|
|
1157
1242
|
#### Instances
|
|
1158
1243
|
|
|
1244
|
+
<p>
|
|
1245
|
+
<a href="https://codesandbox.io/s/h8o2d"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/h8o2d/screenshot.png" alt="Demo"/></a>
|
|
1246
|
+
<a href="https://codesandbox.io/s/i6t0j"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/i6t0j/screenshot.png" alt="Demo"/></a>
|
|
1247
|
+
</p>
|
|
1248
|
+
|
|
1159
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!
|
|
1160
1250
|
|
|
1161
1251
|
```jsx
|
|
@@ -1197,8 +1287,14 @@ You can define events on them!
|
|
|
1197
1287
|
<Instance onClick={...} onPointerOver={...} />
|
|
1198
1288
|
```
|
|
1199
1289
|
|
|
1290
|
+
👉 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).
|
|
1291
|
+
|
|
1200
1292
|
#### Merged
|
|
1201
1293
|
|
|
1294
|
+
<p>
|
|
1295
|
+
<a href="https://codesandbox.io/s/l900i"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/l900i/screenshot.png" alt="Demo"/></a>
|
|
1296
|
+
</p>
|
|
1297
|
+
|
|
1202
1298
|
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
1299
|
|
|
1204
1300
|
```jsx
|
|
@@ -1310,6 +1406,10 @@ useFrame(() => {
|
|
|
1310
1406
|
|
|
1311
1407
|
[](https://drei.vercel.app/?path=/story/abstractions-detailed--detailed-st)
|
|
1312
1408
|
|
|
1409
|
+
<p>
|
|
1410
|
+
<a href="https://codesandbox.io/s/12nmp"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/12nmp/screenshot.png" alt="Demo"/></a>
|
|
1411
|
+
</p>
|
|
1412
|
+
|
|
1313
1413
|
A wrapper around [THREE.LOD](https://threejs.org/docs/#api/en/objects/LOD) (Level of detail).
|
|
1314
1414
|
|
|
1315
1415
|
```jsx
|
|
@@ -1387,7 +1487,7 @@ useBVH(mesh)
|
|
|
1387
1487
|
|
|
1388
1488
|
#### Center
|
|
1389
1489
|
|
|
1390
|
-
[](https://drei.
|
|
1490
|
+
[](https://drei.pmnd.rs/?path=/story/staging-center--default-story)
|
|
1391
1491
|
|
|
1392
1492
|
Calculates a boundary box and centers its children accordingly. `alignTop` makes adjusts it so that it's sits flush on y=0.
|
|
1393
1493
|
|
|
@@ -1399,6 +1499,10 @@ Calculates a boundary box and centers its children accordingly. `alignTop` makes
|
|
|
1399
1499
|
|
|
1400
1500
|
#### Bounds
|
|
1401
1501
|
|
|
1502
|
+
<p>
|
|
1503
|
+
<a href="https://codesandbox.io/s/rz2g0"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/rz2g0/screenshot.png" alt="Demo"/></a>
|
|
1504
|
+
</p>
|
|
1505
|
+
|
|
1402
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.
|
|
1403
1507
|
|
|
1404
1508
|
```jsx
|
|
@@ -1425,7 +1529,12 @@ function Foo() {
|
|
|
1425
1529
|
|
|
1426
1530
|
#### CameraShake
|
|
1427
1531
|
|
|
1428
|
-
[](https://drei.
|
|
1532
|
+
[](https://drei.pmnd.rs/?path=/story/staging-camerashake--camera-shake-story)
|
|
1533
|
+
|
|
1534
|
+
<p>
|
|
1535
|
+
<a href="https://codesandbox.io/s/t4l0f"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/t4l0f/screenshot.png" alt="Demo"/></a>
|
|
1536
|
+
<a href="https://codesandbox.io/s/0ycwe"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/0ycwe/screenshot.png" alt="Demo"/></a>
|
|
1537
|
+
</p>
|
|
1429
1538
|
|
|
1430
1539
|
A component for applying a configurable camera shake effect. Currently only supports rotational camera shake. Pass a ref to recieve the `ShakeController` API.
|
|
1431
1540
|
|
|
@@ -1457,6 +1566,10 @@ interface ShakeController {
|
|
|
1457
1566
|
|
|
1458
1567
|
#### Float
|
|
1459
1568
|
|
|
1569
|
+
<p>
|
|
1570
|
+
<a href="https://codesandbox.io/s/2ij9u"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/2ij9u/screenshot.png" alt="Demo"/></a>
|
|
1571
|
+
</p>
|
|
1572
|
+
|
|
1460
1573
|
This component makes its contents float or hover.
|
|
1461
1574
|
|
|
1462
1575
|
```js
|
|
@@ -1471,7 +1584,7 @@ This component makes its contents float or hover.
|
|
|
1471
1584
|
|
|
1472
1585
|
#### Stage
|
|
1473
1586
|
|
|
1474
|
-
[](https://drei.pmnd.rs/?path=/story/
|
|
1587
|
+
[](https://drei.pmnd.rs/?path=/story/staging-stage--stage-st)
|
|
1475
1588
|
|
|
1476
1589
|
Creates a "stage" with proper studio lighting, content centered and planar, shadows and ground-contact shadows.
|
|
1477
1590
|
|
|
@@ -1485,6 +1598,10 @@ Make sure to set the `makeDefault` prop on your controls, in that case you do no
|
|
|
1485
1598
|
|
|
1486
1599
|
#### Backdrop
|
|
1487
1600
|
|
|
1601
|
+
<p>
|
|
1602
|
+
<a href="https://codesandbox.io/s/8yfnd"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/8yfnd/screenshot.png" alt="Demo"/></a>
|
|
1603
|
+
</p>
|
|
1604
|
+
|
|
1488
1605
|
A curved plane, like a studio backdrop. This is for presentational purposes, to break up light and shadows more interestingly.
|
|
1489
1606
|
|
|
1490
1607
|
```jsx
|
|
@@ -1513,7 +1630,11 @@ A cheap canvas-texture-based circular gradient.
|
|
|
1513
1630
|
|
|
1514
1631
|
#### ContactShadows
|
|
1515
1632
|
|
|
1516
|
-
[](https://drei.
|
|
1633
|
+
[](https://drei.pmnd.rs/?path=/story/staging-contactshadows--contact-shadow-st)
|
|
1634
|
+
|
|
1635
|
+
<p>
|
|
1636
|
+
<a href="https://codesandbox.io/s/qxjoj"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/qxjoj/screenshot.png" alt="Demo"/></a>
|
|
1637
|
+
</p>
|
|
1517
1638
|
|
|
1518
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]`.
|
|
1519
1640
|
|
|
@@ -1529,6 +1650,11 @@ Since this is a rather expensive effect you can limit the amount of frames it re
|
|
|
1529
1650
|
|
|
1530
1651
|
#### SpotLight
|
|
1531
1652
|
|
|
1653
|
+
<p>
|
|
1654
|
+
<a href="https://codesandbox.io/s/tx1pq"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/tx1pq/screenshot.png" alt="Demo"/></a>
|
|
1655
|
+
<a href="https://codesandbox.io/s/wdzv4"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/wdzv4/screenshot.png" alt="Demo"/></a>
|
|
1656
|
+
</p>
|
|
1657
|
+
|
|
1532
1658
|
A Volumetric spotlight.
|
|
1533
1659
|
|
|
1534
1660
|
```jsx
|
|
@@ -1550,10 +1676,16 @@ function Foo() {
|
|
|
1550
1676
|
|
|
1551
1677
|
#### Environment
|
|
1552
1678
|
|
|
1553
|
-
[](https://drei.pmnd.rs/?path=/story/
|
|
1679
|
+
[](https://drei.pmnd.rs/?path=/story/staging-environment--environment-story)
|
|
1680
|
+
|
|
1681
|
+
<p>
|
|
1682
|
+
<a href="https://codesandbox.io/s/t4l0f"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/t4l0f/screenshot.png" alt="Demo"/></a>
|
|
1683
|
+
</p>
|
|
1554
1684
|
|
|
1555
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.
|
|
1556
1686
|
|
|
1687
|
+
👉 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.
|
|
1688
|
+
|
|
1557
1689
|
```jsx
|
|
1558
1690
|
<Environment
|
|
1559
1691
|
background={false}
|
|
@@ -1572,7 +1704,11 @@ If you provide a single string it will use THREE.RGBELoader.
|
|
|
1572
1704
|
|
|
1573
1705
|
#### Sky
|
|
1574
1706
|
|
|
1575
|
-
[](https://drei.
|
|
1707
|
+
[](https://drei.pmnd.rs/?path=/story/staging-sky--sky-st)
|
|
1708
|
+
|
|
1709
|
+
<p>
|
|
1710
|
+
<a href="https://codesandbox.io/s/vkgi6"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/vkgi6/screenshot.png" alt="Demo"/></a>
|
|
1711
|
+
</p>
|
|
1576
1712
|
|
|
1577
1713
|
Adds a [sky](https://threejs.org/examples/#webgl_shaders_sky) to your scene.
|
|
1578
1714
|
|
|
@@ -1582,7 +1718,7 @@ Adds a [sky](https://threejs.org/examples/#webgl_shaders_sky) to your scene.
|
|
|
1582
1718
|
|
|
1583
1719
|
#### Stars
|
|
1584
1720
|
|
|
1585
|
-
[](https://drei.
|
|
1721
|
+
[](https://drei.pmnd.rs/?path=/story/staging-stars--stars-st)
|
|
1586
1722
|
|
|
1587
1723
|
Adds a blinking shader-based starfield to your scene.
|
|
1588
1724
|
|
|
@@ -1594,8 +1730,14 @@ Adds a blinking shader-based starfield to your scene.
|
|
|
1594
1730
|
|
|
1595
1731
|
[](https://drei.pmnd.rs/?path=/story/staging-cloud--cloud-st) 
|
|
1596
1732
|
|
|
1733
|
+
<p>
|
|
1734
|
+
<a href="https://codesandbox.io/s/mbfzf"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/mbfzf/screenshot.png" alt="Demo"/></a>
|
|
1735
|
+
</p>
|
|
1736
|
+
|
|
1597
1737
|
Particle based cloud.
|
|
1598
1738
|
|
|
1739
|
+
👉 Note: `<Cloud />` component is not meant to be used in production environments as it relies on third-party CDN.
|
|
1740
|
+
|
|
1599
1741
|
```jsx
|
|
1600
1742
|
<Cloud
|
|
1601
1743
|
opacity={0.5}
|
|
@@ -1608,12 +1750,14 @@ Particle based cloud.
|
|
|
1608
1750
|
|
|
1609
1751
|
#### useMatcapTexture
|
|
1610
1752
|
|
|
1611
|
-
[](https://drei.pmnd.rs/?path=/story/
|
|
1753
|
+
[](https://drei.pmnd.rs/?path=/story/staging-usematcaptexture--use-matcap-texture-st) 
|
|
1612
1754
|
|
|
1613
1755
|
Loads matcap textures from this repository: https://github.com/emmelleppi/matcaps
|
|
1614
1756
|
|
|
1615
1757
|
(It is a fork of this repository: https://github.com/nidorx/matcaps)
|
|
1616
1758
|
|
|
1759
|
+
👉 Note: `useMatcapTexture` hook is not meant to be used in production environments as it relies on third-party CDN.
|
|
1760
|
+
|
|
1617
1761
|
```jsx
|
|
1618
1762
|
const [matcap, url] = useMatcapTexture(
|
|
1619
1763
|
0, // index of the matcap texture https://github.com/emmelleppi/matcaps/blob/master/matcap-list.json
|
|
@@ -1637,10 +1781,12 @@ const [matcap] = useMatcapTexture('3E2335_D36A1B_8E4A2E_2842A5')
|
|
|
1637
1781
|
|
|
1638
1782
|
#### useNormalTexture
|
|
1639
1783
|
|
|
1640
|
-
[](https://drei.pmnd.rs/?path=/story/
|
|
1784
|
+
[](https://drei.pmnd.rs/?path=/story/staging-usenormaltexture--use-normal-texture-st) 
|
|
1641
1785
|
|
|
1642
1786
|
Loads normal textures from this repository: https://github.com/emmelleppi/normal-maps
|
|
1643
1787
|
|
|
1788
|
+
👉 Note: `useNormalTexture` hook is not meant to be used in production environments as it relies on third-party CDN.
|
|
1789
|
+
|
|
1644
1790
|
```jsx
|
|
1645
1791
|
const [normalMap, url] = useNormalTexture(
|
|
1646
1792
|
1, // index of the normal texture - https://github.com/emmelleppi/normal-maps/blob/master/normals.json
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),r=require("@react-three/fiber"),t=require("react"),n=require("three-stdlib");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function s(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var a=o(e),c=s(t);const u=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),r=require("@react-three/fiber"),t=require("react"),n=require("three-stdlib");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function s(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var a=o(e),c=s(t);const u=t.forwardRef((({camera:e,makeDefault:o,regress:s,domElement:u,onChange:i,onStart:l,onEnd:d,...f},b)=>{const m=r.useThree((({invalidate:e})=>e)),v=r.useThree((({camera:e})=>e)),h=r.useThree((({gl:e})=>e)),p=r.useThree((({events:e})=>e)),E=r.useThree((({set:e})=>e)),g=r.useThree((({get:e})=>e)),j=r.useThree((({performance:e})=>e)),O=e||v,T=u||("boolean"!=typeof p.connected?p.connected:h.domElement),y=t.useMemo((()=>new n.ArcballControls(O)),[O]);return r.useFrame((()=>{y.enabled&&y.update()})),t.useEffect((()=>{const e=e=>{m(),s&&j.regress(),i&&i(e)};return y.connect(T),y.addEventListener("change",e),l&&y.addEventListener("start",l),d&&y.addEventListener("end",d),()=>{y.removeEventListener("change",e),l&&y.removeEventListener("start",l),d&&y.removeEventListener("end",d),y.dispose()}}),[T,i,l,d,s,y,m]),t.useEffect((()=>{if(o){const e=g().controls;return E({controls:y}),()=>E({controls:e})}}),[o,y]),c.createElement("primitive",a.default({ref:b,object:y},f))}));exports.ArcballControls=u;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { ReactThreeFiber } from '@react-three/fiber';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import * as THREE from 'three';
|
|
4
3
|
import { ArcballControls as ArcballControlsImpl } from 'three-stdlib';
|
|
5
|
-
|
|
4
|
+
import type { Event, OrthographicCamera, PerspectiveCamera } from 'three';
|
|
5
|
+
export declare type ArcballControlsProps = Omit<ReactThreeFiber.Overwrite<ReactThreeFiber.Object3DNode<ArcballControlsImpl, typeof ArcballControlsImpl>, {
|
|
6
6
|
target?: ReactThreeFiber.Vector3;
|
|
7
|
-
camera?:
|
|
7
|
+
camera?: OrthographicCamera | PerspectiveCamera;
|
|
8
8
|
domElement?: HTMLElement;
|
|
9
9
|
regress?: boolean;
|
|
10
10
|
makeDefault?: boolean;
|
|
11
|
-
onChange?: (e?:
|
|
12
|
-
onStart?: (e?:
|
|
13
|
-
onEnd?: (e?:
|
|
14
|
-
}>;
|
|
15
|
-
export declare const ArcballControls: React.ForwardRefExoticComponent<
|
|
11
|
+
onChange?: (e?: Event) => void;
|
|
12
|
+
onStart?: (e?: Event) => void;
|
|
13
|
+
onEnd?: (e?: Event) => void;
|
|
14
|
+
}>, 'ref'>;
|
|
15
|
+
export declare const ArcballControls: React.ForwardRefExoticComponent<ArcballControlsProps & React.RefAttributes<ArcballControlsImpl>>;
|
package/core/ArcballControls.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
2
|
import { useThree, useFrame } from '@react-three/fiber';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
+
import { forwardRef, useMemo, useEffect } from 'react';
|
|
4
5
|
import { ArcballControls as ArcballControls$1 } from 'three-stdlib';
|
|
5
6
|
|
|
6
|
-
const ArcballControls = /*#__PURE__*/
|
|
7
|
-
makeDefault,
|
|
7
|
+
const ArcballControls = /*#__PURE__*/forwardRef(({
|
|
8
8
|
camera,
|
|
9
|
+
makeDefault,
|
|
9
10
|
regress,
|
|
10
11
|
domElement,
|
|
11
12
|
onChange,
|
|
@@ -36,11 +37,11 @@ const ArcballControls = /*#__PURE__*/React.forwardRef(({
|
|
|
36
37
|
}) => performance);
|
|
37
38
|
const explCamera = camera || defaultCamera;
|
|
38
39
|
const explDomElement = domElement || (typeof events.connected !== 'boolean' ? events.connected : gl.domElement);
|
|
39
|
-
const controls =
|
|
40
|
+
const controls = useMemo(() => new ArcballControls$1(explCamera), [explCamera]);
|
|
40
41
|
useFrame(() => {
|
|
41
42
|
if (controls.enabled) controls.update();
|
|
42
43
|
});
|
|
43
|
-
|
|
44
|
+
useEffect(() => {
|
|
44
45
|
const callback = e => {
|
|
45
46
|
invalidate();
|
|
46
47
|
if (regress) performance.regress();
|
|
@@ -58,7 +59,7 @@ const ArcballControls = /*#__PURE__*/React.forwardRef(({
|
|
|
58
59
|
controls.dispose();
|
|
59
60
|
};
|
|
60
61
|
}, [explDomElement, onChange, onStart, onEnd, regress, controls, invalidate]);
|
|
61
|
-
|
|
62
|
+
useEffect(() => {
|
|
62
63
|
if (makeDefault) {
|
|
63
64
|
const old = get().controls;
|
|
64
65
|
set({
|
package/core/Cloud.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("@react-three/fiber"),t=require("./Billboard.cjs.js"),a=require("./shapes.cjs.js"),n=require("./useTexture.cjs.js");function s(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var a=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,a.get?a:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}require("@babel/runtime/helpers/extends"),require("react-merge-refs"),require("three");var c=s(e);exports.Cloud=function({opacity:e=.5,speed:s=.4,width:i=10,depth:o=1.5,segments:u=20
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("@react-three/fiber"),t=require("./Billboard.cjs.js"),a=require("./shapes.cjs.js"),n=require("./useTexture.cjs.js");function s(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var a=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,a.get?a:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}require("@babel/runtime/helpers/extends"),require("react-merge-refs"),require("three");var c=s(e);exports.Cloud=function({opacity:e=.5,speed:s=.4,width:i=10,depth:o=1.5,segments:u=20,texture:l="https://rawcdn.githack.com/pmndrs/drei-assets/9225a9f1fbd449d9411125c2f419b843d0308c9f/cloud.png",...d}){const h=c.useRef(),m=n.useTexture(l),p=c.useMemo((()=>[...new Array(u)].map(((e,r)=>({x:i/2-Math.random()*i,y:i/2-Math.random()*i,scale:.4+Math.sin((r+1)/u*Math.PI)*(10*(.2+Math.random())),density:Math.max(.2,Math.random()),rotation:Math.max(.002,.005*Math.random())*s})))),[i,u,s]);return r.useFrame((e=>{var r;return null==(r=h.current)?void 0:r.children.forEach(((r,t)=>{r.children[0].rotation.z+=p[t].rotation,r.children[0].scale.setScalar(p[t].scale+(1+Math.sin(e.clock.getElapsedTime()/10))/2*t/10)}))})),c.createElement("group",d,c.createElement("group",{position:[0,0,u/2*o],ref:h},p.map((({x:r,y:n,scale:s,density:i},u)=>c.createElement(t.Billboard,{key:u,position:[r,n,-u*o]},c.createElement(a.Plane,{scale:s,rotation:[0,0,0]},c.createElement("meshStandardMaterial",{map:m,transparent:!0,opacity:s/6*i*e,depthTest:!1})))))))};
|
package/core/Cloud.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
export declare function Cloud({ opacity, speed, width, depth, segments, ...props }: {
|
|
2
|
+
export declare function Cloud({ opacity, speed, width, depth, segments, texture, ...props }: {
|
|
3
3
|
[x: string]: any;
|
|
4
4
|
opacity?: number | undefined;
|
|
5
5
|
speed?: number | undefined;
|
|
6
6
|
width?: number | undefined;
|
|
7
7
|
depth?: number | undefined;
|
|
8
8
|
segments?: number | undefined;
|
|
9
|
+
texture?: string | undefined;
|
|
9
10
|
}): JSX.Element;
|
package/core/Cloud.js
CHANGED
|
@@ -11,10 +11,11 @@ function Cloud({
|
|
|
11
11
|
width = 10,
|
|
12
12
|
depth = 1.5,
|
|
13
13
|
segments = 20,
|
|
14
|
+
texture = CLOUD_URL,
|
|
14
15
|
...props
|
|
15
16
|
}) {
|
|
16
17
|
const group = React.useRef();
|
|
17
|
-
const
|
|
18
|
+
const cloudTexture = useTexture(texture);
|
|
18
19
|
const clouds = React.useMemo(() => [...new Array(segments)].map((_, index) => ({
|
|
19
20
|
x: width / 2 - Math.random() * width,
|
|
20
21
|
y: width / 2 - Math.random() * width,
|
|
@@ -45,7 +46,7 @@ function Cloud({
|
|
|
45
46
|
scale: scale,
|
|
46
47
|
rotation: [0, 0, 0]
|
|
47
48
|
}, /*#__PURE__*/React.createElement("meshStandardMaterial", {
|
|
48
|
-
map:
|
|
49
|
+
map: cloudTexture,
|
|
49
50
|
transparent: true,
|
|
50
51
|
opacity: scale / 6 * density * opacity,
|
|
51
52
|
depthTest: false
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),r=require("react"),t=require("three"),a=require("@react-three/fiber"),n=require("three-stdlib");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function o(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var a=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,a.get?a:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var i=u(e),s=o(r),l=o(t);const c=s.forwardRef((({scale:e,frames:r=1/0,opacity:t=1,width:u=1,height:o=1,blur:c=1,far:d=10,resolution:f=256,...
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),r=require("react"),t=require("three"),a=require("@react-three/fiber"),n=require("three-stdlib");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function o(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var a=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,a.get?a:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var i=u(e),s=o(r),l=o(t);const c=s.forwardRef((({scale:e,frames:r=1/0,opacity:t=1,width:u=1,height:o=1,blur:c=1,far:d=10,resolution:f=256,smooth:h=!0,...m},p)=>{const g=a.useThree((({scene:e})=>e)),b=a.useThree((({gl:e})=>e)),M=s.useRef(null);u*=Array.isArray(e)?e[0]:e||1,o*=Array.isArray(e)?e[1]:e||1;const[v,y,w,T,x,R,j]=s.useMemo((()=>{const e=new l.WebGLRenderTarget(f,f),r=new l.WebGLRenderTarget(f,f);r.texture.generateMipmaps=e.texture.generateMipmaps=!1;const t=new l.PlaneBufferGeometry(u,o).rotateX(Math.PI/2),a=new l.Mesh(t),i=new l.MeshDepthMaterial;i.depthTest=i.depthWrite=!1,i.onBeforeCompile=e=>e.fragmentShader=e.fragmentShader.replace("1.0 - fragCoordZ ), opacity );","0.0 ), ( 1.0 - fragCoordZ ) * 1.0 );");const s=new l.ShaderMaterial(n.HorizontalBlurShader),c=new l.ShaderMaterial(n.VerticalBlurShader);return c.depthTest=s.depthTest=!1,[e,t,i,a,s,c,r]}),[f,u,o,e]),O=s.useCallback((e=>{T.visible=!0,T.material=x,x.uniforms.tDiffuse.value=v.texture,x.uniforms.h.value=1*e/256,b.setRenderTarget(j),b.render(T,M.current),T.material=R,R.uniforms.tDiffuse.value=j.texture,R.uniforms.v.value=1*e/256,b.setRenderTarget(v),b.render(T,M.current),T.visible=!1}),[]);let P=0;return a.useFrame((()=>{if(M.current&&(r===1/0||P<r)){const e=g.background;g.background=null,g.overrideMaterial=w,b.setRenderTarget(v),b.render(g,M.current),g.overrideMaterial=null,O(c),h&&O(.4*c),b.setRenderTarget(null),g.background=e,P++}})),s.createElement("group",i.default({"rotation-x":Math.PI/2},m,{ref:p}),s.createElement("mesh",{geometry:y,scale:[1,-1,1],rotation:[-Math.PI/2,0,0]},s.createElement("meshBasicMaterial",{map:v.texture,transparent:!0,opacity:t})),s.createElement("orthographicCamera",{ref:M,args:[-u/2,u/2,o/2,-o/2,0,d]}))}));exports.ContactShadows=c;
|