@react-three/drei 9.74.13 → 9.74.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. package/core/CatmullRomLine.js +0 -2
  2. package/core/Cloud.js +0 -3
  3. package/core/CubeCamera.js +0 -1
  4. package/core/CubicBezierLine.js +0 -2
  5. package/core/Environment.js +0 -1
  6. package/core/Example.js +0 -6
  7. package/core/FaceControls.cjs.js +1 -1
  8. package/core/FaceControls.js +0 -2
  9. package/core/FaceLandmarker.cjs.js +1 -1
  10. package/core/FaceLandmarker.js +2 -3
  11. package/core/Facemesh.js +0 -2
  12. package/core/GizmoHelper.js +0 -3
  13. package/core/GizmoViewcube.js +0 -4
  14. package/core/GizmoViewport.js +0 -4
  15. package/core/Gltf.js +0 -4
  16. package/core/MeshDiscardMaterial.js +0 -2
  17. package/core/MeshDistortMaterial.js +1 -2
  18. package/core/MeshReflectorMaterial.js +0 -1
  19. package/core/MeshRefractionMaterial.js +0 -2
  20. package/core/MeshTransmissionMaterial.js +0 -1
  21. package/core/OrthographicCamera.js +0 -1
  22. package/core/PerspectiveCamera.js +0 -1
  23. package/core/QuadraticBezierLine.js +0 -2
  24. package/core/Reflector.js +0 -1
  25. package/core/SpotLight.js +1 -2
  26. package/core/Stage.js +0 -7
  27. package/core/Text3D.js +0 -1
  28. package/core/Wireframe.js +0 -1
  29. package/core/index.cjs.js +1 -1
  30. package/core/index.js +1 -0
  31. package/core/useKTX2.js +0 -1
  32. package/core/useMatcapTexture.js +0 -2
  33. package/core/useNormalTexture.js +0 -1
  34. package/index.cjs.js +1 -1
  35. package/materials/DiscardMaterial.js +0 -1
  36. package/materials/MeshRefractionMaterial.js +1 -1
  37. package/native/index.cjs.js +1 -1
  38. package/native/index.js +1 -0
  39. package/package.json +2 -2
  40. package/web/Loader.js +0 -2
  41. package/web/index.cjs.js +1 -1
  42. package/web/index.js +1 -0
  43. package/web/pivotControls/AxisArrow.js +0 -3
  44. package/web/pivotControls/AxisRotator.js +0 -3
  45. package/web/pivotControls/PlaneSlider.js +0 -3
  46. package/web/pivotControls/index.js +0 -5
  47. package/src/core/AccumulativeShadows.js +0 -311
  48. package/src/core/AdaptiveDpr.js +0 -28
  49. package/src/core/AdaptiveEvents.js +0 -20
  50. package/src/core/ArcballControls.js +0 -67
  51. package/src/core/AsciiRenderer.js +0 -60
  52. package/src/core/BBAnchor.js +0 -37
  53. package/src/core/Backdrop.js +0 -36
  54. package/src/core/BakeShadows.js +0 -16
  55. package/src/core/Billboard.js +0 -41
  56. package/src/core/Bounds.js +0 -245
  57. package/src/core/CameraControls.js +0 -92
  58. package/src/core/CameraShake.js +0 -61
  59. package/src/core/CatmullRomLine.js +0 -44
  60. package/src/core/Caustics.js +0 -375
  61. package/src/core/Center.js +0 -66
  62. package/src/core/Clone.js +0 -102
  63. package/src/core/Cloud.js +0 -59
  64. package/src/core/ComputedAttribute.js +0 -34
  65. package/src/core/ContactShadows.js +0 -114
  66. package/src/core/CubeCamera.js +0 -43
  67. package/src/core/CubicBezierLine.js +0 -28
  68. package/src/core/CurveModifier.js +0 -34
  69. package/src/core/Decal.js +0 -92
  70. package/src/core/Detailed.js +0 -34
  71. package/src/core/DeviceOrientationControls.js +0 -51
  72. package/src/core/Edges.js +0 -36
  73. package/src/core/Effects.js +0 -93
  74. package/src/core/Environment.js +0 -132
  75. package/src/core/Example.js +0 -42
  76. package/src/core/FaceControls.js +0 -315
  77. package/src/core/FaceLandmarker.js +0 -43
  78. package/src/core/Facemesh.js +0 -4545
  79. package/src/core/FirstPersonControls.js +0 -38
  80. package/src/core/Float.js +0 -36
  81. package/src/core/FlyControls.js +0 -55
  82. package/src/core/GizmoHelper.js +0 -111
  83. package/src/core/GizmoViewcube.js +0 -152
  84. package/src/core/GizmoViewport.js +0 -152
  85. package/src/core/Gltf.js +0 -20
  86. package/src/core/GradientTexture.js +0 -33
  87. package/src/core/Grid.js +0 -112
  88. package/src/core/Hud.js +0 -58
  89. package/src/core/Image.js +0 -119
  90. package/src/core/Instances.js +0 -215
  91. package/src/core/Lightformer.js +0 -51
  92. package/src/core/Line.js +0 -68
  93. package/src/core/MapControls.js +0 -64
  94. package/src/core/MarchingCubes.js +0 -76
  95. package/src/core/Mask.js +0 -42
  96. package/src/core/MeshDiscardMaterial.js +0 -15
  97. package/src/core/MeshDistortMaterial.js +0 -79
  98. package/src/core/MeshPortalMaterial.js +0 -381
  99. package/src/core/MeshReflectorMaterial.js +0 -182
  100. package/src/core/MeshRefractionMaterial.js +0 -79
  101. package/src/core/MeshTransmissionMaterial.js +0 -395
  102. package/src/core/MeshWobbleMaterial.js +0 -65
  103. package/src/core/OrbitControls.js +0 -82
  104. package/src/core/OrthographicCamera.js +0 -77
  105. package/src/core/PerformanceMonitor.js +0 -121
  106. package/src/core/PerspectiveCamera.js +0 -73
  107. package/src/core/PointMaterial.js +0 -36
  108. package/src/core/PointerLockControls.js +0 -90
  109. package/src/core/Points.js +0 -227
  110. package/src/core/PositionalAudio.js +0 -51
  111. package/src/core/Preload.js +0 -45
  112. package/src/core/QuadraticBezierLine.js +0 -44
  113. package/src/core/Reflector.js +0 -182
  114. package/src/core/RenderTexture.js +0 -96
  115. package/src/core/Resize.js +0 -39
  116. package/src/core/RoundedBox.js +0 -52
  117. package/src/core/Sampler.js +0 -85
  118. package/src/core/ScreenQuad.js +0 -24
  119. package/src/core/ScreenSpace.js +0 -25
  120. package/src/core/Segments.js +0 -102
  121. package/src/core/Shadow.js +0 -42
  122. package/src/core/Sky.js +0 -39
  123. package/src/core/Sparkles.js +0 -139
  124. package/src/core/SpotLight.js +0 -231
  125. package/src/core/SpriteAnimator.js +0 -342
  126. package/src/core/Stage.js +0 -135
  127. package/src/core/Stars.js +0 -108
  128. package/src/core/Stats.js +0 -30
  129. package/src/core/Svg.js +0 -59
  130. package/src/core/Text.js +0 -58
  131. package/src/core/Text3D.js +0 -76
  132. package/src/core/TrackballControls.js +0 -72
  133. package/src/core/Trail.js +0 -161
  134. package/src/core/TransformControls.js +0 -106
  135. package/src/core/Wireframe.js +0 -185
  136. package/src/core/meshBounds.js +0 -38
  137. package/src/core/shaderMaterial.js +0 -39
  138. package/src/core/shapes.js +0 -68
  139. package/src/core/softShadows.js +0 -161
  140. package/src/core/useAnimations.js +0 -56
  141. package/src/core/useAspect.js +0 -10
  142. package/src/core/useBVH.js +0 -90
  143. package/src/core/useBoxProjectedEnv.js +0 -98
  144. package/src/core/useCamera.js +0 -27
  145. package/src/core/useContextBridge.js +0 -21
  146. package/src/core/useCubeCamera.js +0 -49
  147. package/src/core/useCubeTexture.js +0 -18
  148. package/src/core/useDepthBuffer.js +0 -38
  149. package/src/core/useDetectGPU.js +0 -6
  150. package/src/core/useEnvironment.js +0 -48
  151. package/src/core/useFBO.js +0 -53
  152. package/src/core/useFBX.js +0 -12
  153. package/src/core/useFont.js +0 -20
  154. package/src/core/useGLTF.js +0 -37
  155. package/src/core/useHelper.js +0 -31
  156. package/src/core/useIntersect.js +0 -39
  157. package/src/core/useKTX2.js +0 -38
  158. package/src/core/useMatcapTexture.js +0 -45
  159. package/src/core/useNormalTexture.js +0 -30
  160. package/src/core/useProgress.js +0 -50
  161. package/src/core/useTexture.js +0 -35
  162. package/src/core/useTrailTexture.js +0 -164
  163. package/src/core/useVideoTexture.js +0 -41
  164. package/src/helpers/environment-assets.js +0 -14
  165. package/src/helpers/useEffectfulState.js +0 -18
  166. package/src/materials/BlurPass.js +0 -75
  167. package/src/materials/ConvolutionMaterial.js +0 -99
  168. package/src/materials/DiscardMaterial.js +0 -5
  169. package/src/materials/MeshReflectorMaterial.js +0 -290
  170. package/src/materials/MeshRefractionMaterial.js +0 -171
  171. package/src/materials/SpotLightMaterial.js +0 -111
  172. package/src/materials/WireframeMaterial.js +0 -235
  173. package/src/web/CycleRaycast.js +0 -97
  174. package/src/web/Html.js +0 -417
  175. package/src/web/KeyboardControls.js +0 -101
  176. package/src/web/Loader.js +0 -98
  177. package/src/web/PresentationControls.js +0 -86
  178. package/src/web/ScrollControls.js +0 -246
  179. package/src/web/Select.js +0 -175
  180. package/src/web/View.js +0 -206
  181. package/src/web/pivotControls/AxisArrow.js +0 -202
  182. package/src/web/pivotControls/AxisRotator.js +0 -235
  183. package/src/web/pivotControls/PlaneSlider.js +0 -211
  184. package/src/web/pivotControls/context.js +0 -5
  185. package/src/web/pivotControls/index.js +0 -223
  186. package/src/web/useCursor.js +0 -12
  187. /package/{src/helpers → helpers}/glsl/DefaultSpotlightShadowShadows.glsl.js +0 -0
  188. /package/{src/helpers → helpers}/glsl/distort.vert.glsl.js +0 -0
  189. /package/{src/index.js → index.js} +0 -0
@@ -1,52 +0,0 @@
1
- import _extends from '@babel/runtime/helpers/esm/extends';
2
- import * as React from 'react';
3
- import { Shape } from 'three';
4
- import { toCreasedNormals } from 'three-stdlib';
5
-
6
- const eps = 0.00001;
7
-
8
- function createShape(width, height, radius0) {
9
- const shape = new Shape();
10
- const radius = radius0 - eps;
11
- shape.absarc(eps, eps, eps, -Math.PI / 2, -Math.PI, true);
12
- shape.absarc(eps, height - radius * 2, eps, Math.PI, Math.PI / 2, true);
13
- shape.absarc(width - radius * 2, height - radius * 2, eps, Math.PI / 2, 0, true);
14
- shape.absarc(width - radius * 2, eps, eps, 0, -Math.PI / 2, true);
15
- return shape;
16
- }
17
-
18
- const RoundedBox = /*#__PURE__*/React.forwardRef(function RoundedBox({
19
- args: [width = 1, height = 1, depth = 1] = [],
20
- radius = 0.05,
21
- steps = 1,
22
- smoothness = 4,
23
- creaseAngle = 0.4,
24
- children,
25
- ...rest
26
- }, ref) {
27
- const shape = React.useMemo(() => createShape(width, height, radius), [width, height, radius]);
28
- const params = React.useMemo(() => ({
29
- depth: depth - radius * 2,
30
- bevelEnabled: true,
31
- bevelSegments: smoothness * 2,
32
- steps,
33
- bevelSize: radius - eps,
34
- bevelThickness: radius,
35
- curveSegments: smoothness
36
- }), [depth, radius, smoothness]);
37
- const geomRef = React.useRef();
38
- React.useLayoutEffect(() => {
39
- if (geomRef.current) {
40
- geomRef.current.center();
41
- toCreasedNormals(geomRef.current, creaseAngle);
42
- }
43
- }, [shape, params]);
44
- return /*#__PURE__*/React.createElement("mesh", _extends({
45
- ref: ref
46
- }, rest), /*#__PURE__*/React.createElement("extrudeGeometry", {
47
- ref: geomRef,
48
- args: [shape, params]
49
- }), children);
50
- });
51
-
52
- export { RoundedBox };
@@ -1,85 +0,0 @@
1
- import _extends from '@babel/runtime/helpers/esm/extends';
2
- import * as React from 'react';
3
- import { MeshSurfaceSampler } from 'three-stdlib';
4
- import { InstancedBufferAttribute, Vector3, Color, Object3D } from 'three';
5
-
6
- function useSurfaceSampler(mesh, count = 16, transform, weight, instanceMesh) {
7
- const [buffer, setBuffer] = React.useState(() => {
8
- const arr = Array.from({
9
- length: count
10
- }, () => [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]).flat();
11
- return new InstancedBufferAttribute(Float32Array.from(arr), 16);
12
- });
13
- React.useLayoutEffect(() => {
14
- if (typeof mesh.current === 'undefined') return;
15
- const sampler = new MeshSurfaceSampler(mesh.current);
16
-
17
- if (weight) {
18
- sampler.setWeightAttribute(weight);
19
- }
20
-
21
- sampler.build();
22
- const position = new Vector3();
23
- const normal = new Vector3();
24
- const color = new Color();
25
- const dummy = new Object3D();
26
- mesh.current.updateMatrixWorld(true);
27
-
28
- for (let i = 0; i < count; i++) {
29
- sampler.sample(position, normal, color);
30
-
31
- if (typeof transform === 'function') {
32
- transform({
33
- dummy,
34
- sampledMesh: mesh.current,
35
- position,
36
- normal,
37
- color
38
- }, i);
39
- } else {
40
- dummy.position.copy(position);
41
- }
42
-
43
- dummy.updateMatrix();
44
-
45
- if (instanceMesh != null && instanceMesh.current) {
46
- instanceMesh.current.setMatrixAt(i, dummy.matrix);
47
- }
48
-
49
- dummy.matrix.toArray(buffer.array, i * 16);
50
- }
51
-
52
- if (instanceMesh != null && instanceMesh.current) {
53
- instanceMesh.current.instanceMatrix.needsUpdate = true;
54
- }
55
-
56
- buffer.needsUpdate = true;
57
- setBuffer(buffer.clone());
58
- }, [mesh, instanceMesh, weight, count, transform]);
59
- return buffer;
60
- }
61
- function Sampler({
62
- children,
63
- weight,
64
- transform,
65
- instances,
66
- mesh,
67
- count = 16,
68
- ...props
69
- }) {
70
- const group = React.useRef(null);
71
- const instancedRef = React.useRef(null);
72
- const meshToSampleRef = React.useRef(null);
73
- React.useLayoutEffect(() => {
74
- var _instances$current, _mesh$current;
75
-
76
- instancedRef.current = (_instances$current = instances == null ? void 0 : instances.current) !== null && _instances$current !== void 0 ? _instances$current : group.current.children.find(c => c.hasOwnProperty('instanceMatrix'));
77
- meshToSampleRef.current = (_mesh$current = mesh == null ? void 0 : mesh.current) !== null && _mesh$current !== void 0 ? _mesh$current : group.current.children.find(c => c.type === 'Mesh');
78
- }, [children, mesh == null ? void 0 : mesh.current, instances == null ? void 0 : instances.current]);
79
- useSurfaceSampler(meshToSampleRef, count, transform, weight, instancedRef);
80
- return /*#__PURE__*/React.createElement("group", _extends({
81
- ref: group
82
- }, props), children);
83
- }
84
-
85
- export { Sampler, useSurfaceSampler };
@@ -1,24 +0,0 @@
1
- import _extends from '@babel/runtime/helpers/esm/extends';
2
- import * as THREE from 'three';
3
- import * as React from 'react';
4
-
5
- function createScreenQuadGeometry() {
6
- const geometry = new THREE.BufferGeometry();
7
- const vertices = new Float32Array([-1, -1, 3, -1, -1, 3]);
8
- geometry.setAttribute('position', new THREE.BufferAttribute(vertices, 2));
9
- return geometry;
10
- }
11
-
12
- const ScreenQuad = /*#__PURE__*/React.forwardRef(function ScreenQuad({
13
- children,
14
- ...restProps
15
- }, ref) {
16
- const geometry = React.useMemo(createScreenQuadGeometry, []);
17
- return /*#__PURE__*/React.createElement("mesh", _extends({
18
- ref: ref,
19
- geometry: geometry,
20
- frustumCulled: false
21
- }, restProps), children);
22
- });
23
-
24
- export { ScreenQuad };
@@ -1,25 +0,0 @@
1
- import _extends from '@babel/runtime/helpers/esm/extends';
2
- import * as React from 'react';
3
- import mergeRefs from 'react-merge-refs';
4
- import { useFrame } from '@react-three/fiber';
5
-
6
- const ScreenSpace = /*#__PURE__*/React.forwardRef(({
7
- children,
8
- depth = -1,
9
- ...rest
10
- }, ref) => {
11
- const localRef = React.useRef(null);
12
- useFrame(({
13
- camera
14
- }) => {
15
- localRef.current.quaternion.copy(camera.quaternion);
16
- localRef.current.position.copy(camera.position);
17
- });
18
- return /*#__PURE__*/React.createElement("group", _extends({
19
- ref: mergeRefs([ref, localRef])
20
- }, rest), /*#__PURE__*/React.createElement("group", {
21
- "position-z": -depth
22
- }, children));
23
- });
24
-
25
- export { ScreenSpace };
@@ -1,102 +0,0 @@
1
- import _extends from '@babel/runtime/helpers/esm/extends';
2
- import * as THREE from 'three';
3
- import * as React from 'react';
4
- import mergeRefs from 'react-merge-refs';
5
- import { extend, useFrame } from '@react-three/fiber';
6
- import { Line2, LineMaterial, LineSegmentsGeometry } from 'three-stdlib';
7
-
8
- const context = /*#__PURE__*/React.createContext(null);
9
- const Segments = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
10
- React.useMemo(() => extend({
11
- SegmentObject
12
- }), []);
13
- const {
14
- limit = 1000,
15
- lineWidth = 1.0,
16
- children,
17
- ...rest
18
- } = props;
19
- const [segments, setSegments] = React.useState([]);
20
- const [line] = React.useState(() => new Line2());
21
- const [material] = React.useState(() => new LineMaterial());
22
- const [geometry] = React.useState(() => new LineSegmentsGeometry());
23
- const [resolution] = React.useState(() => new THREE.Vector2(512, 512));
24
- const [positions] = React.useState(() => Array(limit * 6).fill(0));
25
- const [colors] = React.useState(() => Array(limit * 6).fill(0));
26
- const api = React.useMemo(() => ({
27
- subscribe: ref => {
28
- setSegments(segments => [...segments, ref]);
29
- return () => setSegments(segments => segments.filter(item => item.current !== ref.current));
30
- }
31
- }), []);
32
- useFrame(() => {
33
- for (let i = 0; i < limit; i++) {
34
- var _segments$i;
35
-
36
- const segment = (_segments$i = segments[i]) == null ? void 0 : _segments$i.current;
37
-
38
- if (segment) {
39
- positions[i * 6 + 0] = segment.start.x;
40
- positions[i * 6 + 1] = segment.start.y;
41
- positions[i * 6 + 2] = segment.start.z;
42
- positions[i * 6 + 3] = segment.end.x;
43
- positions[i * 6 + 4] = segment.end.y;
44
- positions[i * 6 + 5] = segment.end.z;
45
- colors[i * 6 + 0] = segment.color.r;
46
- colors[i * 6 + 1] = segment.color.g;
47
- colors[i * 6 + 2] = segment.color.b;
48
- colors[i * 6 + 3] = segment.color.r;
49
- colors[i * 6 + 4] = segment.color.g;
50
- colors[i * 6 + 5] = segment.color.b;
51
- }
52
- }
53
-
54
- geometry.setColors(colors);
55
- geometry.setPositions(positions);
56
- line.computeLineDistances();
57
- });
58
- return /*#__PURE__*/React.createElement("primitive", {
59
- object: line,
60
- ref: forwardedRef
61
- }, /*#__PURE__*/React.createElement("primitive", {
62
- object: geometry,
63
- attach: "geometry"
64
- }), /*#__PURE__*/React.createElement("primitive", _extends({
65
- object: material,
66
- attach: "material",
67
- vertexColors: true,
68
- resolution: resolution,
69
- linewidth: lineWidth
70
- }, rest)), /*#__PURE__*/React.createElement(context.Provider, {
71
- value: api
72
- }, children));
73
- });
74
- class SegmentObject {
75
- constructor() {
76
- this.color = new THREE.Color('white');
77
- this.start = new THREE.Vector3(0, 0, 0);
78
- this.end = new THREE.Vector3(0, 0, 0);
79
- }
80
-
81
- }
82
-
83
- const normPos = pos => pos instanceof THREE.Vector3 ? pos : new THREE.Vector3(...(typeof pos === 'number' ? [pos, pos, pos] : pos));
84
-
85
- const Segment = /*#__PURE__*/React.forwardRef(({
86
- color,
87
- start,
88
- end
89
- }, forwardedRef) => {
90
- const api = React.useContext(context);
91
- if (!api) throw 'Segment must used inside Segments component.';
92
- const ref = React.useRef(null);
93
- React.useLayoutEffect(() => api.subscribe(ref), []);
94
- return /*#__PURE__*/React.createElement("segmentObject", {
95
- ref: mergeRefs([ref, forwardedRef]),
96
- color: color,
97
- start: normPos(start),
98
- end: normPos(end)
99
- });
100
- });
101
-
102
- export { Segment, SegmentObject, Segments };
@@ -1,42 +0,0 @@
1
- import _extends from '@babel/runtime/helpers/esm/extends';
2
- import * as React from 'react';
3
- import { Color, DoubleSide } from 'three';
4
-
5
- const Shadow = /*#__PURE__*/React.forwardRef(({
6
- fog = false,
7
- renderOrder,
8
- depthWrite = false,
9
- colorStop = 0.0,
10
- color = 'black',
11
- opacity = 0.5,
12
- ...props
13
- }, ref) => {
14
- const canvas = React.useMemo(() => {
15
- const canvas = document.createElement('canvas');
16
- canvas.width = 128;
17
- canvas.height = 128;
18
- const context = canvas.getContext('2d');
19
- const gradient = context.createRadialGradient(canvas.width / 2, canvas.height / 2, 0, canvas.width / 2, canvas.height / 2, canvas.width / 2);
20
- gradient.addColorStop(colorStop, new Color(color).getStyle());
21
- gradient.addColorStop(1, 'rgba(0,0,0,0)');
22
- context.fillStyle = gradient;
23
- context.fillRect(0, 0, canvas.width, canvas.height);
24
- return canvas;
25
- }, [color, colorStop]);
26
- return /*#__PURE__*/React.createElement("mesh", _extends({
27
- renderOrder: renderOrder,
28
- ref: ref,
29
- "rotation-x": -Math.PI / 2
30
- }, props), /*#__PURE__*/React.createElement("planeGeometry", null), /*#__PURE__*/React.createElement("meshBasicMaterial", {
31
- transparent: true,
32
- opacity: opacity,
33
- fog: fog,
34
- depthWrite: depthWrite,
35
- side: DoubleSide
36
- }, /*#__PURE__*/React.createElement("canvasTexture", {
37
- attach: "map",
38
- args: [canvas]
39
- })));
40
- });
41
-
42
- export { Shadow };
package/src/core/Sky.js DELETED
@@ -1,39 +0,0 @@
1
- import _extends from '@babel/runtime/helpers/esm/extends';
2
- import * as React from 'react';
3
- import { Sky as Sky$1 } from 'three-stdlib';
4
- import { Vector3 } from 'three';
5
-
6
- function calcPosFromAngles(inclination, azimuth, vector = new Vector3()) {
7
- const theta = Math.PI * (inclination - 0.5);
8
- const phi = 2 * Math.PI * (azimuth - 0.5);
9
- vector.x = Math.cos(phi);
10
- vector.y = Math.sin(theta);
11
- vector.z = Math.sin(phi);
12
- return vector;
13
- }
14
- const Sky = /*#__PURE__*/React.forwardRef(({
15
- inclination = 0.6,
16
- azimuth = 0.1,
17
- distance = 1000,
18
- mieCoefficient = 0.005,
19
- mieDirectionalG = 0.8,
20
- rayleigh = 0.5,
21
- turbidity = 10,
22
- sunPosition = calcPosFromAngles(inclination, azimuth),
23
- ...props
24
- }, ref) => {
25
- const scale = React.useMemo(() => new Vector3().setScalar(distance), [distance]);
26
- const [sky] = React.useState(() => new Sky$1());
27
- return /*#__PURE__*/React.createElement("primitive", _extends({
28
- object: sky,
29
- ref: ref,
30
- "material-uniforms-mieCoefficient-value": mieCoefficient,
31
- "material-uniforms-mieDirectionalG-value": mieDirectionalG,
32
- "material-uniforms-rayleigh-value": rayleigh,
33
- "material-uniforms-sunPosition-value": sunPosition,
34
- "material-uniforms-turbidity-value": turbidity,
35
- scale: scale
36
- }, props));
37
- });
38
-
39
- export { Sky, calcPosFromAngles };
@@ -1,139 +0,0 @@
1
- import _extends from '@babel/runtime/helpers/esm/extends';
2
- import * as React from 'react';
3
- import * as THREE from 'three';
4
- import { extend, useThree, useFrame } from '@react-three/fiber';
5
- import { shaderMaterial } from './shaderMaterial.js';
6
-
7
- const SparklesImplMaterial = shaderMaterial({
8
- time: 0,
9
- pixelRatio: 1
10
- }, ` uniform float pixelRatio;
11
- uniform float time;
12
- attribute float size;
13
- attribute float speed;
14
- attribute float opacity;
15
- attribute vec3 noise;
16
- attribute vec3 color;
17
- varying vec3 vColor;
18
- varying float vOpacity;
19
- void main() {
20
- vec4 modelPosition = modelMatrix * vec4(position, 1.0);
21
- modelPosition.y += sin(time * speed + modelPosition.x * noise.x * 100.0) * 0.2;
22
- modelPosition.z += cos(time * speed + modelPosition.x * noise.y * 100.0) * 0.2;
23
- modelPosition.x += cos(time * speed + modelPosition.x * noise.z * 100.0) * 0.2;
24
- vec4 viewPosition = viewMatrix * modelPosition;
25
- vec4 projectionPostion = projectionMatrix * viewPosition;
26
- gl_Position = projectionPostion;
27
- gl_PointSize = size * 25. * pixelRatio;
28
- gl_PointSize *= (1.0 / - viewPosition.z);
29
- vColor = color;
30
- vOpacity = opacity;
31
- }`, ` varying vec3 vColor;
32
- varying float vOpacity;
33
- void main() {
34
- float distanceToCenter = distance(gl_PointCoord, vec2(0.5));
35
- float strength = 0.05 / distanceToCenter - 0.1;
36
- gl_FragColor = vec4(vColor, strength * vOpacity);
37
- #include <tonemapping_fragment>
38
- #include <encodings_fragment>
39
- }`);
40
-
41
- const isFloat32Array = def => def && def.constructor === Float32Array;
42
-
43
- const expandColor = v => [v.r, v.g, v.b];
44
-
45
- const isVector = v => v instanceof THREE.Vector2 || v instanceof THREE.Vector3 || v instanceof THREE.Vector4;
46
-
47
- const normalizeVector = v => {
48
- if (Array.isArray(v)) return v;else if (isVector(v)) return v.toArray();
49
- return [v, v, v];
50
- };
51
-
52
- function usePropAsIsOrAsAttribute(count, prop, setDefault) {
53
- return React.useMemo(() => {
54
- if (prop !== undefined) {
55
- if (isFloat32Array(prop)) {
56
- return prop;
57
- } else {
58
- if (prop instanceof THREE.Color) {
59
- const a = Array.from({
60
- length: count * 3
61
- }, () => expandColor(prop)).flat();
62
- return Float32Array.from(a);
63
- } else if (isVector(prop) || Array.isArray(prop)) {
64
- const a = Array.from({
65
- length: count * 3
66
- }, () => normalizeVector(prop)).flat();
67
- return Float32Array.from(a);
68
- }
69
-
70
- return Float32Array.from({
71
- length: count
72
- }, () => prop);
73
- }
74
- }
75
-
76
- return Float32Array.from({
77
- length: count
78
- }, setDefault);
79
- }, [prop]);
80
- }
81
-
82
- const Sparkles = /*#__PURE__*/React.forwardRef(({
83
- noise = 1,
84
- count = 100,
85
- speed = 1,
86
- opacity = 1,
87
- scale = 1,
88
- size,
89
- color,
90
- children,
91
- ...props
92
- }, forwardRef) => {
93
- React.useMemo(() => extend({
94
- SparklesImplMaterial
95
- }), []);
96
- const ref = React.useRef(null);
97
- const dpr = useThree(state => state.viewport.dpr);
98
- const positions = React.useMemo(() => Float32Array.from(Array.from({
99
- length: count
100
- }, () => normalizeVector(scale).map(THREE.MathUtils.randFloatSpread)).flat()), [count, scale]);
101
- const sizes = usePropAsIsOrAsAttribute(count, size, Math.random);
102
- const opacities = usePropAsIsOrAsAttribute(count, opacity);
103
- const speeds = usePropAsIsOrAsAttribute(count, speed);
104
- const noises = usePropAsIsOrAsAttribute(count * 3, noise);
105
- const colors = usePropAsIsOrAsAttribute(color === undefined ? count * 3 : count, !isFloat32Array(color) ? new THREE.Color(color) : color, () => 1);
106
- useFrame(state => {
107
- if (ref.current && ref.current.material) ref.current.material.time = state.clock.elapsedTime;
108
- });
109
- React.useImperativeHandle(forwardRef, () => ref.current, []);
110
- return /*#__PURE__*/React.createElement("points", _extends({
111
- key: `particle-${count}-${JSON.stringify(scale)}`
112
- }, props, {
113
- ref: ref
114
- }), /*#__PURE__*/React.createElement("bufferGeometry", null, /*#__PURE__*/React.createElement("bufferAttribute", {
115
- attach: "attributes-position",
116
- args: [positions, 3]
117
- }), /*#__PURE__*/React.createElement("bufferAttribute", {
118
- attach: "attributes-size",
119
- args: [sizes, 1]
120
- }), /*#__PURE__*/React.createElement("bufferAttribute", {
121
- attach: "attributes-opacity",
122
- args: [opacities, 1]
123
- }), /*#__PURE__*/React.createElement("bufferAttribute", {
124
- attach: "attributes-speed",
125
- args: [speeds, 1]
126
- }), /*#__PURE__*/React.createElement("bufferAttribute", {
127
- attach: "attributes-color",
128
- args: [colors, 3]
129
- }), /*#__PURE__*/React.createElement("bufferAttribute", {
130
- attach: "attributes-noise",
131
- args: [noises, 3]
132
- })), children ? children : /*#__PURE__*/React.createElement("sparklesImplMaterial", {
133
- transparent: true,
134
- pixelRatio: dpr,
135
- depthWrite: false
136
- }));
137
- });
138
-
139
- export { Sparkles };