@react-three/drei 9.74.13 → 9.74.15

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 +3 -4
  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
package/src/core/Stars.js DELETED
@@ -1,108 +0,0 @@
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 };
package/src/core/Stats.js DELETED
@@ -1,30 +0,0 @@
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 };
package/src/core/Svg.js DELETED
@@ -1,59 +0,0 @@
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 };
package/src/core/Text.js DELETED
@@ -1,58 +0,0 @@
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 };
@@ -1,76 +0,0 @@
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 };
@@ -1,72 +0,0 @@
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 };
package/src/core/Trail.js DELETED
@@ -1,161 +0,0 @@
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 };
@@ -1,106 +0,0 @@
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 };