@react-three/drei 9.74.11 → 9.74.13

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 +2 -0
  2. package/core/Cloud.js +3 -0
  3. package/core/CubeCamera.js +1 -0
  4. package/core/CubicBezierLine.js +2 -0
  5. package/core/Environment.js +1 -0
  6. package/core/Example.js +6 -0
  7. package/core/FaceControls.cjs.js +1 -1
  8. package/core/FaceControls.js +2 -0
  9. package/core/FaceLandmarker.cjs.js +1 -1
  10. package/core/FaceLandmarker.js +3 -2
  11. package/core/Facemesh.js +2 -0
  12. package/core/GizmoHelper.js +3 -0
  13. package/core/GizmoViewcube.js +4 -0
  14. package/core/GizmoViewport.js +4 -0
  15. package/core/Gltf.js +4 -0
  16. package/core/MeshDiscardMaterial.js +2 -0
  17. package/core/MeshDistortMaterial.js +2 -1
  18. package/core/MeshReflectorMaterial.js +1 -0
  19. package/core/MeshRefractionMaterial.js +2 -0
  20. package/core/MeshTransmissionMaterial.js +1 -0
  21. package/core/OrthographicCamera.js +1 -0
  22. package/core/PerspectiveCamera.js +1 -0
  23. package/core/QuadraticBezierLine.js +2 -0
  24. package/core/Reflector.js +1 -0
  25. package/core/SpotLight.js +2 -1
  26. package/core/Stage.js +7 -0
  27. package/core/Text3D.js +1 -0
  28. package/core/Wireframe.js +1 -0
  29. package/core/index.cjs.js +1 -1
  30. package/core/index.js +0 -1
  31. package/core/useKTX2.js +1 -0
  32. package/core/useMatcapTexture.js +2 -0
  33. package/core/useNormalTexture.js +1 -0
  34. package/index.cjs.js +1 -1
  35. package/materials/DiscardMaterial.js +1 -0
  36. package/materials/MeshRefractionMaterial.js +1 -1
  37. package/native/index.cjs.js +1 -1
  38. package/native/index.js +0 -1
  39. package/package.json +9 -9
  40. package/src/core/AccumulativeShadows.js +311 -0
  41. package/src/core/AdaptiveDpr.js +28 -0
  42. package/src/core/AdaptiveEvents.js +20 -0
  43. package/src/core/ArcballControls.js +67 -0
  44. package/src/core/AsciiRenderer.js +60 -0
  45. package/src/core/BBAnchor.js +37 -0
  46. package/src/core/Backdrop.js +36 -0
  47. package/src/core/BakeShadows.js +16 -0
  48. package/src/core/Billboard.js +41 -0
  49. package/src/core/Bounds.js +245 -0
  50. package/src/core/CameraControls.js +92 -0
  51. package/src/core/CameraShake.js +61 -0
  52. package/src/core/CatmullRomLine.js +44 -0
  53. package/src/core/Caustics.js +375 -0
  54. package/src/core/Center.js +66 -0
  55. package/src/core/Clone.js +102 -0
  56. package/src/core/Cloud.js +59 -0
  57. package/src/core/ComputedAttribute.js +34 -0
  58. package/src/core/ContactShadows.js +114 -0
  59. package/src/core/CubeCamera.js +43 -0
  60. package/src/core/CubicBezierLine.js +28 -0
  61. package/src/core/CurveModifier.js +34 -0
  62. package/src/core/Decal.js +92 -0
  63. package/src/core/Detailed.js +34 -0
  64. package/src/core/DeviceOrientationControls.js +51 -0
  65. package/src/core/Edges.js +36 -0
  66. package/src/core/Effects.js +93 -0
  67. package/src/core/Environment.js +132 -0
  68. package/src/core/Example.js +42 -0
  69. package/src/core/FaceControls.js +315 -0
  70. package/src/core/FaceLandmarker.js +43 -0
  71. package/src/core/Facemesh.js +4545 -0
  72. package/src/core/FirstPersonControls.js +38 -0
  73. package/src/core/Float.js +36 -0
  74. package/src/core/FlyControls.js +55 -0
  75. package/src/core/GizmoHelper.js +111 -0
  76. package/src/core/GizmoViewcube.js +152 -0
  77. package/src/core/GizmoViewport.js +152 -0
  78. package/src/core/Gltf.js +20 -0
  79. package/src/core/GradientTexture.js +33 -0
  80. package/src/core/Grid.js +112 -0
  81. package/src/core/Hud.js +58 -0
  82. package/src/core/Image.js +119 -0
  83. package/src/core/Instances.js +215 -0
  84. package/src/core/Lightformer.js +51 -0
  85. package/src/core/Line.js +68 -0
  86. package/src/core/MapControls.js +64 -0
  87. package/src/core/MarchingCubes.js +76 -0
  88. package/src/core/Mask.js +42 -0
  89. package/src/core/MeshDiscardMaterial.js +15 -0
  90. package/src/core/MeshDistortMaterial.js +79 -0
  91. package/src/core/MeshPortalMaterial.js +381 -0
  92. package/src/core/MeshReflectorMaterial.js +182 -0
  93. package/src/core/MeshRefractionMaterial.js +79 -0
  94. package/src/core/MeshTransmissionMaterial.js +395 -0
  95. package/src/core/MeshWobbleMaterial.js +65 -0
  96. package/src/core/OrbitControls.js +82 -0
  97. package/src/core/OrthographicCamera.js +77 -0
  98. package/src/core/PerformanceMonitor.js +121 -0
  99. package/src/core/PerspectiveCamera.js +73 -0
  100. package/src/core/PointMaterial.js +36 -0
  101. package/src/core/PointerLockControls.js +90 -0
  102. package/src/core/Points.js +227 -0
  103. package/src/core/PositionalAudio.js +51 -0
  104. package/src/core/Preload.js +45 -0
  105. package/src/core/QuadraticBezierLine.js +44 -0
  106. package/src/core/Reflector.js +182 -0
  107. package/src/core/RenderTexture.js +96 -0
  108. package/src/core/Resize.js +39 -0
  109. package/src/core/RoundedBox.js +52 -0
  110. package/src/core/Sampler.js +85 -0
  111. package/src/core/ScreenQuad.js +24 -0
  112. package/src/core/ScreenSpace.js +25 -0
  113. package/src/core/Segments.js +102 -0
  114. package/src/core/Shadow.js +42 -0
  115. package/src/core/Sky.js +39 -0
  116. package/src/core/Sparkles.js +139 -0
  117. package/src/core/SpotLight.js +231 -0
  118. package/src/core/SpriteAnimator.js +342 -0
  119. package/src/core/Stage.js +135 -0
  120. package/src/core/Stars.js +108 -0
  121. package/src/core/Stats.js +30 -0
  122. package/src/core/Svg.js +59 -0
  123. package/src/core/Text.js +58 -0
  124. package/src/core/Text3D.js +76 -0
  125. package/src/core/TrackballControls.js +72 -0
  126. package/src/core/Trail.js +161 -0
  127. package/src/core/TransformControls.js +106 -0
  128. package/src/core/Wireframe.js +185 -0
  129. package/src/core/meshBounds.js +38 -0
  130. package/src/core/shaderMaterial.js +39 -0
  131. package/src/core/shapes.js +68 -0
  132. package/src/core/softShadows.js +161 -0
  133. package/src/core/useAnimations.js +56 -0
  134. package/src/core/useAspect.js +10 -0
  135. package/src/core/useBVH.js +90 -0
  136. package/src/core/useBoxProjectedEnv.js +98 -0
  137. package/src/core/useCamera.js +27 -0
  138. package/src/core/useContextBridge.js +21 -0
  139. package/src/core/useCubeCamera.js +49 -0
  140. package/src/core/useCubeTexture.js +18 -0
  141. package/src/core/useDepthBuffer.js +38 -0
  142. package/src/core/useDetectGPU.js +6 -0
  143. package/src/core/useEnvironment.js +48 -0
  144. package/src/core/useFBO.js +53 -0
  145. package/src/core/useFBX.js +12 -0
  146. package/src/core/useFont.js +20 -0
  147. package/src/core/useGLTF.js +37 -0
  148. package/src/core/useHelper.js +31 -0
  149. package/src/core/useIntersect.js +39 -0
  150. package/src/core/useKTX2.js +38 -0
  151. package/src/core/useMatcapTexture.js +45 -0
  152. package/src/core/useNormalTexture.js +30 -0
  153. package/src/core/useProgress.js +50 -0
  154. package/src/core/useTexture.js +35 -0
  155. package/src/core/useTrailTexture.js +164 -0
  156. package/src/core/useVideoTexture.js +41 -0
  157. package/src/helpers/environment-assets.js +14 -0
  158. package/src/helpers/useEffectfulState.js +18 -0
  159. package/src/materials/BlurPass.js +75 -0
  160. package/src/materials/ConvolutionMaterial.js +99 -0
  161. package/src/materials/DiscardMaterial.js +5 -0
  162. package/src/materials/MeshReflectorMaterial.js +290 -0
  163. package/src/materials/MeshRefractionMaterial.js +171 -0
  164. package/src/materials/SpotLightMaterial.js +111 -0
  165. package/src/materials/WireframeMaterial.js +235 -0
  166. package/src/web/CycleRaycast.js +97 -0
  167. package/src/web/Html.js +417 -0
  168. package/src/web/KeyboardControls.js +101 -0
  169. package/src/web/Loader.js +98 -0
  170. package/src/web/PresentationControls.js +86 -0
  171. package/src/web/ScrollControls.js +246 -0
  172. package/src/web/Select.js +175 -0
  173. package/src/web/View.js +206 -0
  174. package/src/web/pivotControls/AxisArrow.js +202 -0
  175. package/src/web/pivotControls/AxisRotator.js +235 -0
  176. package/src/web/pivotControls/PlaneSlider.js +211 -0
  177. package/src/web/pivotControls/context.js +5 -0
  178. package/src/web/pivotControls/index.js +223 -0
  179. package/src/web/useCursor.js +12 -0
  180. package/web/Loader.js +2 -0
  181. package/web/index.cjs.js +1 -1
  182. package/web/index.js +0 -1
  183. package/web/pivotControls/AxisArrow.js +3 -0
  184. package/web/pivotControls/AxisRotator.js +3 -0
  185. package/web/pivotControls/PlaneSlider.js +3 -0
  186. package/web/pivotControls/index.js +5 -0
  187. /package/{helpers → src/helpers}/glsl/DefaultSpotlightShadowShadows.glsl.js +0 -0
  188. /package/{helpers → src/helpers}/glsl/distort.vert.glsl.js +0 -0
  189. /package/{index.js → src/index.js} +0 -0
@@ -0,0 +1,108 @@
1
+ import * as React from 'react';
2
+ import { useFrame } from '@react-three/fiber';
3
+ import { Color, AdditiveBlending, ShaderMaterial, Vector3, Spherical } from 'three';
4
+
5
+ class StarfieldMaterial extends ShaderMaterial {
6
+ constructor() {
7
+ super({
8
+ uniforms: {
9
+ time: {
10
+ value: 0.0
11
+ },
12
+ fade: {
13
+ value: 1.0
14
+ }
15
+ },
16
+ vertexShader:
17
+ /* glsl */
18
+ `
19
+ uniform float time;
20
+ attribute float size;
21
+ varying vec3 vColor;
22
+ void main() {
23
+ vColor = color;
24
+ vec4 mvPosition = modelViewMatrix * vec4(position, 0.5);
25
+ gl_PointSize = size * (30.0 / -mvPosition.z) * (3.0 + sin(time + 100.0));
26
+ gl_Position = projectionMatrix * mvPosition;
27
+ }`,
28
+ fragmentShader:
29
+ /* glsl */
30
+ `
31
+ uniform sampler2D pointTexture;
32
+ uniform float fade;
33
+ varying vec3 vColor;
34
+ void main() {
35
+ float opacity = 1.0;
36
+ if (fade == 1.0) {
37
+ float d = distance(gl_PointCoord, vec2(0.5, 0.5));
38
+ opacity = 1.0 / (1.0 + exp(16.0 * (d - 0.25)));
39
+ }
40
+ gl_FragColor = vec4(vColor, opacity);
41
+
42
+ #include <tonemapping_fragment>
43
+ #include <encodings_fragment>
44
+ }`
45
+ });
46
+ }
47
+
48
+ }
49
+
50
+ const genStar = r => {
51
+ return new Vector3().setFromSpherical(new Spherical(r, Math.acos(1 - Math.random() * 2), Math.random() * 2 * Math.PI));
52
+ };
53
+
54
+ const Stars = /*#__PURE__*/React.forwardRef(({
55
+ radius = 100,
56
+ depth = 50,
57
+ count = 5000,
58
+ saturation = 0,
59
+ factor = 4,
60
+ fade = false,
61
+ speed = 1
62
+ }, ref) => {
63
+ const material = React.useRef();
64
+ const [position, color, size] = React.useMemo(() => {
65
+ const positions = [];
66
+ const colors = [];
67
+ const sizes = Array.from({
68
+ length: count
69
+ }, () => (0.5 + 0.5 * Math.random()) * factor);
70
+ const color = new Color();
71
+ let r = radius + depth;
72
+ const increment = depth / count;
73
+
74
+ for (let i = 0; i < count; i++) {
75
+ r -= increment * Math.random();
76
+ positions.push(...genStar(r).toArray());
77
+ color.setHSL(i / count, saturation, 0.9);
78
+ colors.push(color.r, color.g, color.b);
79
+ }
80
+
81
+ return [new Float32Array(positions), new Float32Array(colors), new Float32Array(sizes)];
82
+ }, [count, depth, factor, radius, saturation]);
83
+ useFrame(state => material.current && (material.current.uniforms.time.value = state.clock.getElapsedTime() * speed));
84
+ const [starfieldMaterial] = React.useState(() => new StarfieldMaterial());
85
+ return /*#__PURE__*/React.createElement("points", {
86
+ ref: ref
87
+ }, /*#__PURE__*/React.createElement("bufferGeometry", null, /*#__PURE__*/React.createElement("bufferAttribute", {
88
+ attach: "attributes-position",
89
+ args: [position, 3]
90
+ }), /*#__PURE__*/React.createElement("bufferAttribute", {
91
+ attach: "attributes-color",
92
+ args: [color, 3]
93
+ }), /*#__PURE__*/React.createElement("bufferAttribute", {
94
+ attach: "attributes-size",
95
+ args: [size, 1]
96
+ })), /*#__PURE__*/React.createElement("primitive", {
97
+ ref: material,
98
+ object: starfieldMaterial,
99
+ attach: "material",
100
+ blending: AdditiveBlending,
101
+ "uniforms-fade-value": fade,
102
+ depthWrite: false,
103
+ transparent: true,
104
+ vertexColors: true
105
+ }));
106
+ });
107
+
108
+ export { Stars };
@@ -0,0 +1,30 @@
1
+ import * as React from 'react';
2
+ import { addEffect, addAfterEffect } from '@react-three/fiber';
3
+ import StatsImpl from 'stats.js';
4
+ import { useEffectfulState } from '../helpers/useEffectfulState.js';
5
+
6
+ function Stats({
7
+ showPanel = 0,
8
+ className,
9
+ parent
10
+ }) {
11
+ const stats = useEffectfulState(() => new StatsImpl(), []);
12
+ React.useEffect(() => {
13
+ if (stats) {
14
+ const node = parent && parent.current || document.body;
15
+ stats.showPanel(showPanel);
16
+ node == null ? void 0 : node.appendChild(stats.dom);
17
+ if (className) stats.dom.classList.add(...className.split(' ').filter(cls => cls));
18
+ const begin = addEffect(() => stats.begin());
19
+ const end = addAfterEffect(() => stats.end());
20
+ return () => {
21
+ node == null ? void 0 : node.removeChild(stats.dom);
22
+ begin();
23
+ end();
24
+ };
25
+ }
26
+ }, [parent, stats, className, showPanel]);
27
+ return null;
28
+ }
29
+
30
+ export { Stats };
@@ -0,0 +1,59 @@
1
+ import _extends from '@babel/runtime/helpers/esm/extends';
2
+ import { useLoader } from '@react-three/fiber';
3
+ import * as React from 'react';
4
+ import { forwardRef, useMemo, useEffect, Fragment } from 'react';
5
+ import { DoubleSide } from 'three';
6
+ import { SVGLoader } from 'three-stdlib';
7
+
8
+ const Svg = /*#__PURE__*/forwardRef(function R3FSvg({
9
+ src,
10
+ skipFill,
11
+ skipStrokes,
12
+ fillMaterial,
13
+ strokeMaterial,
14
+ fillMeshProps,
15
+ strokeMeshProps,
16
+ ...props
17
+ }, ref) {
18
+ const svg = useLoader(SVGLoader, !src.startsWith('<svg') ? src : `data:image/svg+xml;utf8,${src}`);
19
+ const strokeGeometries = useMemo(() => skipStrokes ? [] : svg.paths.map(path => {
20
+ var _path$userData;
21
+
22
+ return ((_path$userData = path.userData) == null ? void 0 : _path$userData.style.stroke) === undefined || path.userData.style.stroke === 'none' ? null : path.subPaths.map(subPath => SVGLoader.pointsToStroke(subPath.getPoints(), path.userData.style));
23
+ }), [svg, skipStrokes]);
24
+ useEffect(() => {
25
+ return () => strokeGeometries.forEach(group => group && group.map(g => g.dispose()));
26
+ }, [strokeGeometries]);
27
+ return /*#__PURE__*/React.createElement("object3D", _extends({
28
+ ref: ref
29
+ }, props), /*#__PURE__*/React.createElement("object3D", {
30
+ scale: [1, -1, 1]
31
+ }, svg.paths.map((path, p) => {
32
+ var _path$userData2, _path$userData3;
33
+
34
+ return /*#__PURE__*/React.createElement(Fragment, {
35
+ key: p
36
+ }, !skipFill && ((_path$userData2 = path.userData) == null ? void 0 : _path$userData2.style.fill) !== undefined && path.userData.style.fill !== 'none' && SVGLoader.createShapes(path).map((shape, s) => /*#__PURE__*/React.createElement("mesh", _extends({
37
+ key: s
38
+ }, fillMeshProps), /*#__PURE__*/React.createElement("shapeGeometry", {
39
+ args: [shape]
40
+ }), /*#__PURE__*/React.createElement("meshBasicMaterial", _extends({
41
+ color: path.userData.style.fill,
42
+ opacity: path.userData.style.fillOpacity,
43
+ transparent: true,
44
+ side: DoubleSide,
45
+ depthWrite: false
46
+ }, fillMaterial)))), !skipStrokes && ((_path$userData3 = path.userData) == null ? void 0 : _path$userData3.style.stroke) !== undefined && path.userData.style.stroke !== 'none' && path.subPaths.map((_subPath, s) => /*#__PURE__*/React.createElement("mesh", _extends({
47
+ key: s,
48
+ geometry: strokeGeometries[p][s]
49
+ }, strokeMeshProps), /*#__PURE__*/React.createElement("meshBasicMaterial", _extends({
50
+ color: path.userData.style.stroke,
51
+ opacity: path.userData.style.strokeOpacity,
52
+ transparent: true,
53
+ side: DoubleSide,
54
+ depthWrite: false
55
+ }, strokeMaterial)))));
56
+ })));
57
+ });
58
+
59
+ export { Svg };
@@ -0,0 +1,58 @@
1
+ import _extends from '@babel/runtime/helpers/esm/extends';
2
+ import * as React from 'react';
3
+ import { Text as Text$1, preloadFont } from 'troika-three-text';
4
+ import { useThree } from '@react-three/fiber';
5
+ import { suspend } from 'suspend-react';
6
+
7
+ // eslint-disable-next-line prettier/prettier
8
+ const Text = /*#__PURE__*/React.forwardRef(({
9
+ sdfGlyphSize = 64,
10
+ anchorX = 'center',
11
+ anchorY = 'middle',
12
+ font,
13
+ fontSize = 1,
14
+ children,
15
+ characters,
16
+ onSync,
17
+ ...props
18
+ }, ref) => {
19
+ const invalidate = useThree(({
20
+ invalidate
21
+ }) => invalidate);
22
+ const [troikaMesh] = React.useState(() => new Text$1());
23
+ const [nodes, text] = React.useMemo(() => {
24
+ const n = [];
25
+ let t = '';
26
+ React.Children.forEach(children, child => {
27
+ if (typeof child === 'string' || typeof child === 'number') {
28
+ t += child;
29
+ } else {
30
+ n.push(child);
31
+ }
32
+ });
33
+ return [n, t];
34
+ }, [children]);
35
+ suspend(() => new Promise(res => preloadFont({
36
+ font,
37
+ characters
38
+ }, res)), ['troika-text', font, characters]);
39
+ React.useLayoutEffect(() => void troikaMesh.sync(() => {
40
+ invalidate();
41
+ if (onSync) onSync(troikaMesh);
42
+ }));
43
+ React.useEffect(() => {
44
+ return () => troikaMesh.dispose();
45
+ }, [troikaMesh]);
46
+ return /*#__PURE__*/React.createElement("primitive", _extends({
47
+ object: troikaMesh,
48
+ ref: ref,
49
+ font: font,
50
+ text: text,
51
+ anchorX: anchorX,
52
+ anchorY: anchorY,
53
+ fontSize: fontSize,
54
+ sdfGlyphSize: sdfGlyphSize
55
+ }, props), nodes);
56
+ });
57
+
58
+ export { Text };
@@ -0,0 +1,76 @@
1
+ import _extends from '@babel/runtime/helpers/esm/extends';
2
+ import * as React from 'react';
3
+ import { useMemo } from 'react';
4
+ import { extend } from '@react-three/fiber';
5
+ import { TextGeometry, mergeVertices } from 'three-stdlib';
6
+ import { useFont } from './useFont.js';
7
+
8
+ const types = ['string', 'number'];
9
+
10
+ const getTextFromChildren = children => {
11
+ let label = '';
12
+ const rest = [];
13
+ React.Children.forEach(children, child => {
14
+ if (types.includes(typeof child)) label += child + '';else rest.push(child);
15
+ });
16
+ return [label, ...rest];
17
+ };
18
+
19
+ const Text3D = /*#__PURE__*/React.forwardRef(({
20
+ font: _font,
21
+ letterSpacing = 0,
22
+ lineHeight = 1,
23
+ size = 1,
24
+ height = 0.2,
25
+ bevelThickness = 0.1,
26
+ bevelSize = 0.01,
27
+ bevelEnabled = false,
28
+ bevelOffset = 0,
29
+ bevelSegments = 4,
30
+ curveSegments = 8,
31
+ smooth,
32
+ children,
33
+ ...props
34
+ }, fref) => {
35
+ React.useMemo(() => extend({
36
+ RenamedTextGeometry: TextGeometry
37
+ }), []);
38
+ const ref = React.useRef(null);
39
+ const font = useFont(_font);
40
+ const opts = useMemo(() => {
41
+ return {
42
+ font,
43
+ size,
44
+ height,
45
+ bevelThickness,
46
+ bevelSize,
47
+ bevelEnabled,
48
+ bevelSegments,
49
+ bevelOffset,
50
+ curveSegments,
51
+ letterSpacing,
52
+ lineHeight
53
+ };
54
+ }, [font, size, height, bevelThickness, bevelSize, bevelEnabled, bevelSegments, bevelOffset, curveSegments, letterSpacing, lineHeight]);
55
+ /**
56
+ * We need the `children` in the deps because we
57
+ * need to be able to do `<Text3d>{state}</Text3d>`.
58
+ */
59
+
60
+ const [label, ...rest] = useMemo(() => getTextFromChildren(children), [children]);
61
+ const args = React.useMemo(() => [label, opts], [label, opts]);
62
+ React.useLayoutEffect(() => {
63
+ if (smooth) {
64
+ ref.current.geometry = mergeVertices(ref.current.geometry, smooth);
65
+ ref.current.geometry.computeVertexNormals();
66
+ }
67
+ }, [args, smooth]);
68
+ React.useImperativeHandle(fref, () => ref.current, []);
69
+ return /*#__PURE__*/React.createElement("mesh", _extends({}, props, {
70
+ ref: ref
71
+ }), /*#__PURE__*/React.createElement("renamedTextGeometry", {
72
+ args: args
73
+ }), rest);
74
+ });
75
+
76
+ export { Text3D };
@@ -0,0 +1,72 @@
1
+ import _extends from '@babel/runtime/helpers/esm/extends';
2
+ import { useThree, useFrame } from '@react-three/fiber';
3
+ import * as React from 'react';
4
+ import { TrackballControls as TrackballControls$1 } from 'three-stdlib';
5
+
6
+ const TrackballControls = /*#__PURE__*/React.forwardRef(({
7
+ makeDefault,
8
+ camera,
9
+ domElement,
10
+ regress,
11
+ onChange,
12
+ onStart,
13
+ onEnd,
14
+ ...restProps
15
+ }, ref) => {
16
+ const {
17
+ invalidate,
18
+ camera: defaultCamera,
19
+ gl,
20
+ events,
21
+ set,
22
+ get,
23
+ performance,
24
+ viewport
25
+ } = useThree();
26
+ const explCamera = camera || defaultCamera;
27
+ const explDomElement = domElement || events.connected || gl.domElement;
28
+ const controls = React.useMemo(() => new TrackballControls$1(explCamera), [explCamera]);
29
+ useFrame(() => {
30
+ if (controls.enabled) controls.update();
31
+ }, -1);
32
+ React.useEffect(() => {
33
+ controls.connect(explDomElement);
34
+ return () => void controls.dispose();
35
+ }, [explDomElement, regress, controls, invalidate]);
36
+ React.useEffect(() => {
37
+ const callback = e => {
38
+ invalidate();
39
+ if (regress) performance.regress();
40
+ if (onChange) onChange(e);
41
+ };
42
+
43
+ controls.addEventListener('change', callback);
44
+ if (onStart) controls.addEventListener('start', onStart);
45
+ if (onEnd) controls.addEventListener('end', onEnd);
46
+ return () => {
47
+ if (onStart) controls.removeEventListener('start', onStart);
48
+ if (onEnd) controls.removeEventListener('end', onEnd);
49
+ controls.removeEventListener('change', callback);
50
+ };
51
+ }, [onChange, onStart, onEnd, controls, invalidate]);
52
+ React.useEffect(() => {
53
+ controls.handleResize();
54
+ }, [viewport]);
55
+ React.useEffect(() => {
56
+ if (makeDefault) {
57
+ const old = get().controls;
58
+ set({
59
+ controls
60
+ });
61
+ return () => set({
62
+ controls: old
63
+ });
64
+ }
65
+ }, [makeDefault, controls]);
66
+ return /*#__PURE__*/React.createElement("primitive", _extends({
67
+ ref: ref,
68
+ object: controls
69
+ }, restProps));
70
+ });
71
+
72
+ export { TrackballControls };
@@ -0,0 +1,161 @@
1
+ import { useFrame, useThree, createPortal } from '@react-three/fiber';
2
+ import * as React from 'react';
3
+ import { Vector3, Object3D, Vector2 } from 'three';
4
+ import { MeshLineGeometry, MeshLineMaterial } from 'meshline';
5
+
6
+ const defaults = {
7
+ width: 0.2,
8
+ length: 1,
9
+ decay: 1,
10
+ local: false,
11
+ stride: 0,
12
+ interval: 1
13
+ };
14
+
15
+ const shiftLeft = (collection, steps = 1) => {
16
+ collection.set(collection.subarray(steps));
17
+ collection.fill(-Infinity, -steps);
18
+ return collection;
19
+ };
20
+
21
+ function useTrail(target, settings) {
22
+ const {
23
+ length,
24
+ local,
25
+ decay,
26
+ interval,
27
+ stride
28
+ } = { ...defaults,
29
+ ...settings
30
+ };
31
+ const points = React.useRef();
32
+ const [worldPosition] = React.useState(() => new Vector3());
33
+ React.useLayoutEffect(() => {
34
+ if (target) {
35
+ points.current = Float32Array.from({
36
+ length: length * 10 * 3
37
+ }, (_, i) => target.position.getComponent(i % 3));
38
+ }
39
+ }, [length, target]);
40
+ const prevPosition = React.useRef(new Vector3());
41
+ const frameCount = React.useRef(0);
42
+ useFrame(() => {
43
+ if (!target) return;
44
+ if (!points.current) return;
45
+
46
+ if (frameCount.current === 0) {
47
+ let newPosition;
48
+
49
+ if (local) {
50
+ newPosition = target.position;
51
+ } else {
52
+ target.getWorldPosition(worldPosition);
53
+ newPosition = worldPosition;
54
+ }
55
+
56
+ const steps = 1 * decay;
57
+
58
+ for (let i = 0; i < steps; i++) {
59
+ if (newPosition.distanceTo(prevPosition.current) < stride) continue;
60
+ shiftLeft(points.current, 3);
61
+ points.current.set(newPosition.toArray(), points.current.length - 3);
62
+ }
63
+
64
+ prevPosition.current.copy(newPosition);
65
+ }
66
+
67
+ frameCount.current++;
68
+ frameCount.current = frameCount.current % interval;
69
+ });
70
+ return points;
71
+ }
72
+ const Trail = /*#__PURE__*/React.forwardRef((props, forwardRef) => {
73
+ const {
74
+ children
75
+ } = props;
76
+ const {
77
+ width,
78
+ length,
79
+ decay,
80
+ local,
81
+ stride,
82
+ interval
83
+ } = { ...defaults,
84
+ ...props
85
+ };
86
+ const {
87
+ color = 'hotpink',
88
+ attenuation,
89
+ target
90
+ } = props;
91
+ const size = useThree(s => s.size);
92
+ const scene = useThree(s => s.scene);
93
+ const ref = React.useRef(null);
94
+ const [anchor, setAnchor] = React.useState(null);
95
+ const points = useTrail(anchor, {
96
+ length,
97
+ decay,
98
+ local,
99
+ stride,
100
+ interval
101
+ });
102
+ React.useEffect(() => {
103
+ const t = (target == null ? void 0 : target.current) || ref.current.children.find(o => {
104
+ return o instanceof Object3D;
105
+ });
106
+
107
+ if (t) {
108
+ setAnchor(t);
109
+ }
110
+ }, [points, target]);
111
+ const geo = React.useMemo(() => new MeshLineGeometry(), []);
112
+ const mat = React.useMemo(() => {
113
+ var _matOverride;
114
+
115
+ const m = new MeshLineMaterial({
116
+ lineWidth: 0.1 * width,
117
+ color: color,
118
+ sizeAttenuation: 1,
119
+ resolution: new Vector2(size.width, size.height)
120
+ }); // Get and apply first <meshLineMaterial /> from children
121
+
122
+ let matOverride;
123
+
124
+ if (children) {
125
+ if (Array.isArray(children)) {
126
+ matOverride = children.find(child => {
127
+ const c = child;
128
+ return typeof c.type === 'string' && c.type === 'meshLineMaterial';
129
+ });
130
+ } else {
131
+ const c = children;
132
+
133
+ if (typeof c.type === 'string' && c.type === 'meshLineMaterial') {
134
+ matOverride = c;
135
+ }
136
+ }
137
+ }
138
+
139
+ if (typeof ((_matOverride = matOverride) == null ? void 0 : _matOverride.props) === 'object') {
140
+ m.setValues(matOverride.props);
141
+ }
142
+
143
+ return m;
144
+ }, [width, color, size, children]);
145
+ React.useEffect(() => {
146
+ mat.uniforms.resolution.value.set(size.width, size.height);
147
+ }, [size]);
148
+ useFrame(() => {
149
+ if (!points.current) return;
150
+ geo.setPoints(points.current, attenuation);
151
+ });
152
+ return /*#__PURE__*/React.createElement("group", null, createPortal( /*#__PURE__*/React.createElement("mesh", {
153
+ ref: forwardRef,
154
+ geometry: geo,
155
+ material: mat
156
+ }), scene), /*#__PURE__*/React.createElement("group", {
157
+ ref: ref
158
+ }, children));
159
+ });
160
+
161
+ export { Trail, useTrail };
@@ -0,0 +1,106 @@
1
+ import _extends from '@babel/runtime/helpers/esm/extends';
2
+ import { useThree } from '@react-three/fiber';
3
+ import omit from 'lodash.omit';
4
+ import pick from 'lodash.pick';
5
+ import * as React from 'react';
6
+ import * as THREE from 'three';
7
+ import { TransformControls as TransformControls$1 } from 'three-stdlib';
8
+
9
+ const TransformControls = /*#__PURE__*/React.forwardRef(({
10
+ children,
11
+ domElement,
12
+ onChange,
13
+ onMouseDown,
14
+ onMouseUp,
15
+ onObjectChange,
16
+ object,
17
+ makeDefault,
18
+ ...props
19
+ }, ref) => {
20
+ const transformOnlyPropNames = ['enabled', 'axis', 'mode', 'translationSnap', 'rotationSnap', 'scaleSnap', 'space', 'size', 'showX', 'showY', 'showZ'];
21
+ const {
22
+ camera,
23
+ ...rest
24
+ } = props;
25
+ const transformProps = pick(rest, transformOnlyPropNames);
26
+ const objectProps = omit(rest, transformOnlyPropNames); // @ts-expect-error new in @react-three/fiber@7.0.5
27
+
28
+ const defaultControls = useThree(state => state.controls);
29
+ const gl = useThree(state => state.gl);
30
+ const events = useThree(state => state.events);
31
+ const defaultCamera = useThree(state => state.camera);
32
+ const invalidate = useThree(state => state.invalidate);
33
+ const get = useThree(state => state.get);
34
+ const set = useThree(state => state.set);
35
+ const explCamera = camera || defaultCamera;
36
+ const explDomElement = domElement || events.connected || gl.domElement;
37
+ const controls = React.useMemo(() => new TransformControls$1(explCamera, explDomElement), [explCamera, explDomElement]);
38
+ const group = React.useRef();
39
+ React.useLayoutEffect(() => {
40
+ if (object) {
41
+ controls.attach(object instanceof THREE.Object3D ? object : object.current);
42
+ } else if (group.current instanceof THREE.Object3D) {
43
+ controls.attach(group.current);
44
+ }
45
+
46
+ return () => void controls.detach();
47
+ }, [object, children, controls]);
48
+ React.useEffect(() => {
49
+ if (defaultControls) {
50
+ const callback = event => defaultControls.enabled = !event.value;
51
+
52
+ controls.addEventListener('dragging-changed', callback);
53
+ return () => controls.removeEventListener('dragging-changed', callback);
54
+ }
55
+ }, [controls, defaultControls]);
56
+ const onChangeRef = React.useRef();
57
+ const onMouseDownRef = React.useRef();
58
+ const onMouseUpRef = React.useRef();
59
+ const onObjectChangeRef = React.useRef();
60
+ React.useLayoutEffect(() => void (onChangeRef.current = onChange), [onChange]);
61
+ React.useLayoutEffect(() => void (onMouseDownRef.current = onMouseDown), [onMouseDown]);
62
+ React.useLayoutEffect(() => void (onMouseUpRef.current = onMouseUp), [onMouseUp]);
63
+ React.useLayoutEffect(() => void (onObjectChangeRef.current = onObjectChange), [onObjectChange]);
64
+ React.useEffect(() => {
65
+ const onChange = e => {
66
+ invalidate();
67
+ onChangeRef.current == null ? void 0 : onChangeRef.current(e);
68
+ };
69
+
70
+ const onMouseDown = e => onMouseDownRef.current == null ? void 0 : onMouseDownRef.current(e);
71
+
72
+ const onMouseUp = e => onMouseUpRef.current == null ? void 0 : onMouseUpRef.current(e);
73
+
74
+ const onObjectChange = e => onObjectChangeRef.current == null ? void 0 : onObjectChangeRef.current(e);
75
+
76
+ controls.addEventListener('change', onChange);
77
+ controls.addEventListener('mouseDown', onMouseDown);
78
+ controls.addEventListener('mouseUp', onMouseUp);
79
+ controls.addEventListener('objectChange', onObjectChange);
80
+ return () => {
81
+ controls.removeEventListener('change', onChange);
82
+ controls.removeEventListener('mouseDown', onMouseDown);
83
+ controls.removeEventListener('mouseUp', onMouseUp);
84
+ controls.removeEventListener('objectChange', onObjectChange);
85
+ };
86
+ }, [invalidate, controls]);
87
+ React.useEffect(() => {
88
+ if (makeDefault) {
89
+ const old = get().controls;
90
+ set({
91
+ controls
92
+ });
93
+ return () => set({
94
+ controls: old
95
+ });
96
+ }
97
+ }, [makeDefault, controls]);
98
+ return controls ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("primitive", _extends({
99
+ ref: ref,
100
+ object: controls
101
+ }, transformProps)), /*#__PURE__*/React.createElement("group", _extends({
102
+ ref: group
103
+ }, objectProps), children)) : null;
104
+ });
105
+
106
+ export { TransformControls };