@react-three/drei 11.0.0-alpha.1 → 11.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/index.d.mts +1858 -0
- package/core/index.d.ts +1858 -0
- package/core/index.mjs +8559 -0
- package/experimental/index.d.mts +222 -0
- package/experimental/index.d.ts +222 -0
- package/experimental/index.mjs +353 -0
- package/external/index.d.mts +464 -0
- package/external/index.d.ts +464 -0
- package/external/index.mjs +5079 -0
- package/index.d.mts +1746 -2147
- package/index.d.ts +2166 -0
- package/index.mjs +12940 -19766
- package/legacy/index.d.mts +2350 -0
- package/legacy/index.d.ts +2350 -0
- package/legacy/index.mjs +12325 -0
- package/native/index.d.mts +2515 -0
- package/native/index.d.ts +2515 -0
- package/native/index.mjs +12383 -0
- package/package.json +18 -15
- package/webgpu/index.d.mts +2514 -0
- package/webgpu/index.d.ts +2514 -0
- package/webgpu/index.mjs +12547 -0
- package/_chunks/hls.mjs +0 -3
- package/_chunks/libs/@mediapipe/tasks-vision.mjs +0 -4781
- package/_chunks/libs/@monogrid/gainmap-js.mjs +0 -1137
- package/_chunks/libs/@use-gesture/core.mjs +0 -1650
- package/_chunks/libs/@use-gesture/react.mjs +0 -207
- package/_chunks/libs/camera-controls.mjs +0 -2207
- package/_chunks/libs/detect-gpu.mjs +0 -515
- package/_chunks/libs/hls.js.mjs +0 -21925
- package/_chunks/libs/maath.mjs +0 -5200
- package/_chunks/libs/stats-gl.mjs +0 -301
- package/_chunks/libs/stats.js.mjs +0 -90
- package/_chunks/libs/suspend-react.mjs +0 -60
- package/_chunks/libs/three.mjs +0 -23169
- package/_chunks/libs/tunnel-rat.mjs +0 -458
- package/_chunks/libs/zustand.mjs +0 -104
- package/_chunks/rolldown-runtime.mjs +0 -47
- package/_chunks/vision_bundle.mjs +0 -3
- package/core/_chunks/hls.mjs +0 -3
- package/core/_chunks/libs/@monogrid/gainmap-js.mjs +0 -1137
- package/core/_chunks/libs/@use-gesture/core.mjs +0 -1650
- package/core/_chunks/libs/@use-gesture/react.mjs +0 -207
- package/core/_chunks/libs/detect-gpu.mjs +0 -515
- package/core/_chunks/libs/hls.js.mjs +0 -21925
- package/core/_chunks/libs/maath.mjs +0 -5200
- package/core/_chunks/libs/stats-gl.mjs +0 -301
- package/core/_chunks/libs/stats.js.mjs +0 -90
- package/core/_chunks/libs/suspend-react.mjs +0 -60
- package/core/_chunks/libs/three.mjs +0 -22457
- package/core/_chunks/libs/tunnel-rat.mjs +0 -458
- package/core/_chunks/libs/zustand.mjs +0 -104
- package/core/_chunks/rolldown-runtime.mjs +0 -47
- package/core/core/index.d.mts +0 -2232
- package/core/core/index.mjs +0 -11082
- package/experimental/_chunks/libs/three.mjs +0 -15386
- package/experimental/experimental/index.d.mts +0 -253
- package/experimental/experimental/index.mjs +0 -434
- package/external/_chunks/hls.mjs +0 -3
- package/external/_chunks/libs/@mediapipe/tasks-vision.mjs +0 -4781
- package/external/_chunks/libs/camera-controls.mjs +0 -2207
- package/external/_chunks/libs/hls.js.mjs +0 -21925
- package/external/_chunks/libs/maath.mjs +0 -5200
- package/external/_chunks/libs/suspend-react.mjs +0 -58
- package/external/_chunks/libs/three.mjs +0 -15387
- package/external/_chunks/rolldown-runtime.mjs +0 -32
- package/external/_chunks/vision_bundle.mjs +0 -3
- package/external/external/index.d.mts +0 -499
- package/external/external/index.mjs +0 -9422
- package/legacy/_chunks/hls.mjs +0 -3
- package/legacy/_chunks/libs/@monogrid/gainmap-js.mjs +0 -1137
- package/legacy/_chunks/libs/@use-gesture/core.mjs +0 -1650
- package/legacy/_chunks/libs/@use-gesture/react.mjs +0 -207
- package/legacy/_chunks/libs/bidi-js.mjs +0 -675
- package/legacy/_chunks/libs/detect-gpu.mjs +0 -515
- package/legacy/_chunks/libs/hls.js.mjs +0 -21925
- package/legacy/_chunks/libs/maath.mjs +0 -5200
- package/legacy/_chunks/libs/stats-gl.mjs +0 -301
- package/legacy/_chunks/libs/stats.js.mjs +0 -90
- package/legacy/_chunks/libs/suspend-react.mjs +0 -60
- package/legacy/_chunks/libs/three.mjs +0 -26062
- package/legacy/_chunks/libs/troika-three-text.mjs +0 -6494
- package/legacy/_chunks/libs/tunnel-rat.mjs +0 -458
- package/legacy/_chunks/libs/zustand.mjs +0 -104
- package/legacy/_chunks/rolldown-runtime.mjs +0 -47
- package/legacy/legacy/index.d.mts +0 -2788
- package/legacy/legacy/index.mjs +0 -14984
- package/native/_chunks/hls.mjs +0 -3
- package/native/_chunks/libs/@monogrid/gainmap-js.mjs +0 -1137
- package/native/_chunks/libs/@use-gesture/core.mjs +0 -1650
- package/native/_chunks/libs/@use-gesture/react.mjs +0 -207
- package/native/_chunks/libs/detect-gpu.mjs +0 -515
- package/native/_chunks/libs/hls.js.mjs +0 -21925
- package/native/_chunks/libs/maath.mjs +0 -5200
- package/native/_chunks/libs/stats-gl.mjs +0 -301
- package/native/_chunks/libs/stats.js.mjs +0 -90
- package/native/_chunks/libs/suspend-react.mjs +0 -60
- package/native/_chunks/libs/three.mjs +0 -22592
- package/native/_chunks/libs/tunnel-rat.mjs +0 -458
- package/native/_chunks/libs/zustand.mjs +0 -104
- package/native/_chunks/rolldown-runtime.mjs +0 -47
- package/native/native/index.d.mts +0 -3168
- package/native/native/index.mjs +0 -14863
- package/webgpu/_chunks/hls.mjs +0 -3
- package/webgpu/_chunks/libs/@monogrid/gainmap-js.mjs +0 -1137
- package/webgpu/_chunks/libs/@use-gesture/core.mjs +0 -1650
- package/webgpu/_chunks/libs/@use-gesture/react.mjs +0 -207
- package/webgpu/_chunks/libs/detect-gpu.mjs +0 -515
- package/webgpu/_chunks/libs/hls.js.mjs +0 -21925
- package/webgpu/_chunks/libs/maath.mjs +0 -5200
- package/webgpu/_chunks/libs/stats-gl.mjs +0 -301
- package/webgpu/_chunks/libs/stats.js.mjs +0 -90
- package/webgpu/_chunks/libs/suspend-react.mjs +0 -60
- package/webgpu/_chunks/libs/three.mjs +0 -22592
- package/webgpu/_chunks/libs/tunnel-rat.mjs +0 -458
- package/webgpu/_chunks/libs/zustand.mjs +0 -104
- package/webgpu/_chunks/rolldown-runtime.mjs +0 -47
- package/webgpu/webgpu/index.d.mts +0 -3166
- package/webgpu/webgpu/index.mjs +0 -15015
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { REVISION, Object3D, Vector2, Vector3 } from 'three';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { MarchingCubes as MarchingCubes$1 } from 'three/examples/jsm/objects/MarchingCubes.js';
|
|
5
|
+
import { useFrame, useThree, extend, applyProps, createPortal } from '@react-three/fiber';
|
|
6
|
+
import { toCreasedNormals } from 'three/examples/jsm/utils/BufferGeometryUtils.js';
|
|
7
|
+
import { Line2 } from 'three/examples/jsm/lines/Line2.js';
|
|
8
|
+
import { LineGeometry } from 'three/examples/jsm/lines/LineGeometry.js';
|
|
9
|
+
import { LineMaterial } from 'three/examples/jsm/lines/LineMaterial.js';
|
|
10
|
+
|
|
11
|
+
const globalContext = /* @__PURE__ */ React.createContext(null);
|
|
12
|
+
const MarchingCubes = /* @__PURE__ */ React.forwardRef(
|
|
13
|
+
({ resolution = 28, maxPolyCount = 1e4, enableUvs = false, enableColors = false, children, ...props }, ref) => {
|
|
14
|
+
const marchingCubesRef = React.useRef(null);
|
|
15
|
+
React.useImperativeHandle(ref, () => marchingCubesRef.current, []);
|
|
16
|
+
const marchingCubes = React.useMemo(
|
|
17
|
+
() => new MarchingCubes$1(resolution, null, enableUvs, enableColors, maxPolyCount),
|
|
18
|
+
[resolution, maxPolyCount, enableUvs, enableColors]
|
|
19
|
+
);
|
|
20
|
+
const api = React.useMemo(() => ({ getParent: () => marchingCubesRef }), []);
|
|
21
|
+
useFrame(() => {
|
|
22
|
+
marchingCubes.update();
|
|
23
|
+
marchingCubes.reset();
|
|
24
|
+
}, -1);
|
|
25
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("primitive", { object: marchingCubes, ref: marchingCubesRef, ...props }, /* @__PURE__ */ React.createElement(globalContext.Provider, { value: api }, children)));
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
const MarchingCube = /* @__PURE__ */ React.forwardRef(
|
|
29
|
+
({ strength = 0.5, subtract = 12, color, ...props }, ref) => {
|
|
30
|
+
const { getParent } = React.useContext(globalContext);
|
|
31
|
+
const parentRef = React.useMemo(() => getParent(), [getParent]);
|
|
32
|
+
const cubeRef = React.useRef(null);
|
|
33
|
+
React.useImperativeHandle(ref, () => cubeRef.current, []);
|
|
34
|
+
const vec = new THREE.Vector3();
|
|
35
|
+
useFrame((state) => {
|
|
36
|
+
if (!parentRef.current || !cubeRef.current) return;
|
|
37
|
+
cubeRef.current.getWorldPosition(vec);
|
|
38
|
+
parentRef.current.addBall(0.5 + vec.x * 0.5, 0.5 + vec.y * 0.5, 0.5 + vec.z * 0.5, strength, subtract, color);
|
|
39
|
+
});
|
|
40
|
+
return /* @__PURE__ */ React.createElement("group", { ref: cubeRef, ...props });
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
const MarchingPlane = /* @__PURE__ */ React.forwardRef(
|
|
44
|
+
({ planeType: _planeType = "x", strength = 0.5, subtract = 12, ...props }, ref) => {
|
|
45
|
+
const { getParent } = React.useContext(globalContext);
|
|
46
|
+
const parentRef = React.useMemo(() => getParent(), [getParent]);
|
|
47
|
+
const wallRef = React.useRef(null);
|
|
48
|
+
React.useImperativeHandle(ref, () => wallRef.current, []);
|
|
49
|
+
const planeType = React.useMemo(
|
|
50
|
+
() => _planeType === "x" ? "addPlaneX" : _planeType === "y" ? "addPlaneY" : "addPlaneZ",
|
|
51
|
+
[_planeType]
|
|
52
|
+
);
|
|
53
|
+
useFrame(() => {
|
|
54
|
+
if (!parentRef.current || !wallRef.current) return;
|
|
55
|
+
parentRef.current[planeType](strength, subtract);
|
|
56
|
+
});
|
|
57
|
+
return /* @__PURE__ */ React.createElement("group", { ref: wallRef, ...props });
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
function shaderMaterial(uniforms, vertexShader, fragmentShader, onInit) {
|
|
62
|
+
return class extends THREE.ShaderMaterial {
|
|
63
|
+
static key = THREE.MathUtils.generateUUID();
|
|
64
|
+
constructor(parameters) {
|
|
65
|
+
super({ vertexShader, fragmentShader, ...parameters });
|
|
66
|
+
for (const key in uniforms) {
|
|
67
|
+
this.uniforms[key] = new THREE.Uniform(uniforms[key]);
|
|
68
|
+
Object.defineProperty(this, key, {
|
|
69
|
+
get() {
|
|
70
|
+
return this.uniforms[key].value;
|
|
71
|
+
},
|
|
72
|
+
set(value) {
|
|
73
|
+
this.uniforms[key].value = value;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
this.uniforms = THREE.UniformsUtils.clone(this.uniforms);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const getVersion = () => parseInt(REVISION.replace(/\D+/g, ""));
|
|
83
|
+
const version = /* @__PURE__ */ getVersion();
|
|
84
|
+
|
|
85
|
+
const OutlinesMaterial = /* @__PURE__ */ shaderMaterial(
|
|
86
|
+
{
|
|
87
|
+
screenspace: false,
|
|
88
|
+
color: /* @__PURE__ */ new THREE.Color("black"),
|
|
89
|
+
opacity: 1,
|
|
90
|
+
thickness: 0.05,
|
|
91
|
+
size: /* @__PURE__ */ new THREE.Vector2()
|
|
92
|
+
},
|
|
93
|
+
`#include <common>
|
|
94
|
+
#include <morphtarget_pars_vertex>
|
|
95
|
+
#include <skinning_pars_vertex>
|
|
96
|
+
#include <clipping_planes_pars_vertex>
|
|
97
|
+
uniform float thickness;
|
|
98
|
+
uniform bool screenspace;
|
|
99
|
+
uniform vec2 size;
|
|
100
|
+
void main() {
|
|
101
|
+
#if defined (USE_SKINNING)
|
|
102
|
+
#include <beginnormal_vertex>
|
|
103
|
+
#include <morphnormal_vertex>
|
|
104
|
+
#include <skinbase_vertex>
|
|
105
|
+
#include <skinnormal_vertex>
|
|
106
|
+
#include <defaultnormal_vertex>
|
|
107
|
+
#endif
|
|
108
|
+
#include <begin_vertex>
|
|
109
|
+
#include <morphtarget_vertex>
|
|
110
|
+
#include <skinning_vertex>
|
|
111
|
+
#include <project_vertex>
|
|
112
|
+
#include <clipping_planes_vertex>
|
|
113
|
+
vec4 tNormal = vec4(normal, 0.0);
|
|
114
|
+
vec4 tPosition = vec4(transformed, 1.0);
|
|
115
|
+
#ifdef USE_INSTANCING
|
|
116
|
+
tNormal = instanceMatrix * tNormal;
|
|
117
|
+
tPosition = instanceMatrix * tPosition;
|
|
118
|
+
#endif
|
|
119
|
+
if (screenspace) {
|
|
120
|
+
vec3 newPosition = tPosition.xyz + tNormal.xyz * thickness;
|
|
121
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(newPosition, 1.0);
|
|
122
|
+
} else {
|
|
123
|
+
vec4 clipPosition = projectionMatrix * modelViewMatrix * tPosition;
|
|
124
|
+
vec4 clipNormal = projectionMatrix * modelViewMatrix * tNormal;
|
|
125
|
+
vec2 offset = normalize(clipNormal.xy) * thickness / size * clipPosition.w * 2.0;
|
|
126
|
+
clipPosition.xy += offset;
|
|
127
|
+
gl_Position = clipPosition;
|
|
128
|
+
}
|
|
129
|
+
}`,
|
|
130
|
+
`uniform vec3 color;
|
|
131
|
+
uniform float opacity;
|
|
132
|
+
#include <clipping_planes_pars_fragment>
|
|
133
|
+
void main(){
|
|
134
|
+
#include <clipping_planes_fragment>
|
|
135
|
+
gl_FragColor = vec4(color, opacity);
|
|
136
|
+
#include <tonemapping_fragment>
|
|
137
|
+
#include <${version >= 154 ? "colorspace_fragment" : "encodings_fragment"}>
|
|
138
|
+
}`
|
|
139
|
+
);
|
|
140
|
+
function Outlines({
|
|
141
|
+
color = "black",
|
|
142
|
+
opacity = 1,
|
|
143
|
+
transparent = false,
|
|
144
|
+
screenspace = false,
|
|
145
|
+
toneMapped = true,
|
|
146
|
+
polygonOffset = false,
|
|
147
|
+
polygonOffsetFactor = 0,
|
|
148
|
+
renderOrder = 0,
|
|
149
|
+
thickness = 0.05,
|
|
150
|
+
angle = Math.PI,
|
|
151
|
+
clippingPlanes,
|
|
152
|
+
...props
|
|
153
|
+
}) {
|
|
154
|
+
const ref = React.useRef(null);
|
|
155
|
+
const [material] = React.useState(() => new OutlinesMaterial({ side: THREE.BackSide }));
|
|
156
|
+
const { gl } = useThree();
|
|
157
|
+
const contextSize = gl.getDrawingBufferSize(new THREE.Vector2());
|
|
158
|
+
React.useMemo(() => extend({ OutlinesMaterial }), []);
|
|
159
|
+
const oldAngle = React.useRef(0);
|
|
160
|
+
const oldGeometry = React.useRef(null);
|
|
161
|
+
React.useLayoutEffect(() => {
|
|
162
|
+
const group = ref.current;
|
|
163
|
+
if (!group) return;
|
|
164
|
+
const parent = group.parent;
|
|
165
|
+
if (parent && parent.geometry) {
|
|
166
|
+
if (oldAngle.current !== angle || oldGeometry.current !== parent.geometry) {
|
|
167
|
+
oldAngle.current = angle;
|
|
168
|
+
oldGeometry.current = parent.geometry;
|
|
169
|
+
let mesh = group.children?.[0];
|
|
170
|
+
if (mesh) {
|
|
171
|
+
if (angle) mesh.geometry.dispose();
|
|
172
|
+
group.remove(mesh);
|
|
173
|
+
}
|
|
174
|
+
if (parent.skeleton) {
|
|
175
|
+
mesh = new THREE.SkinnedMesh();
|
|
176
|
+
mesh.material = material;
|
|
177
|
+
mesh.bind(parent.skeleton, parent.bindMatrix);
|
|
178
|
+
group.add(mesh);
|
|
179
|
+
} else if (parent.isInstancedMesh) {
|
|
180
|
+
mesh = new THREE.InstancedMesh(parent.geometry, material, parent.count);
|
|
181
|
+
mesh.instanceMatrix = parent.instanceMatrix;
|
|
182
|
+
group.add(mesh);
|
|
183
|
+
} else {
|
|
184
|
+
mesh = new THREE.Mesh();
|
|
185
|
+
mesh.material = material;
|
|
186
|
+
group.add(mesh);
|
|
187
|
+
}
|
|
188
|
+
mesh.geometry = angle ? toCreasedNormals(parent.geometry, angle) : parent.geometry;
|
|
189
|
+
mesh.morphTargetInfluences = parent.morphTargetInfluences;
|
|
190
|
+
mesh.morphTargetDictionary = parent.morphTargetDictionary;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
React.useLayoutEffect(() => {
|
|
195
|
+
const group = ref.current;
|
|
196
|
+
if (!group) return;
|
|
197
|
+
const mesh = group.children[0];
|
|
198
|
+
if (mesh) {
|
|
199
|
+
mesh.renderOrder = renderOrder;
|
|
200
|
+
const parent = group.parent;
|
|
201
|
+
applyProps(mesh, {
|
|
202
|
+
morphTargetInfluences: parent.morphTargetInfluences,
|
|
203
|
+
morphTargetDictionary: parent.morphTargetDictionary
|
|
204
|
+
});
|
|
205
|
+
applyProps(mesh.material, {
|
|
206
|
+
transparent,
|
|
207
|
+
thickness,
|
|
208
|
+
color,
|
|
209
|
+
opacity,
|
|
210
|
+
size: contextSize,
|
|
211
|
+
screenspace,
|
|
212
|
+
toneMapped,
|
|
213
|
+
polygonOffset,
|
|
214
|
+
polygonOffsetFactor,
|
|
215
|
+
clippingPlanes,
|
|
216
|
+
clipping: clippingPlanes && clippingPlanes.length > 0
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
React.useEffect(() => {
|
|
221
|
+
return () => {
|
|
222
|
+
const group = ref.current;
|
|
223
|
+
if (!group) return;
|
|
224
|
+
const mesh = group.children[0];
|
|
225
|
+
if (mesh) {
|
|
226
|
+
if (angle) mesh.geometry.dispose();
|
|
227
|
+
group.remove(mesh);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
}, []);
|
|
231
|
+
return /* @__PURE__ */ React.createElement("group", { ref, ...props });
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const defaults = {
|
|
235
|
+
width: 0.2,
|
|
236
|
+
length: 1,
|
|
237
|
+
decay: 1,
|
|
238
|
+
local: false,
|
|
239
|
+
stride: 0,
|
|
240
|
+
interval: 1
|
|
241
|
+
};
|
|
242
|
+
const shiftLeft = (collection, steps = 1) => {
|
|
243
|
+
const lastX = collection[collection.length - 3];
|
|
244
|
+
const lastY = collection[collection.length - 2];
|
|
245
|
+
const lastZ = collection[collection.length - 1];
|
|
246
|
+
collection.set(collection.subarray(steps));
|
|
247
|
+
const fillStart = collection.length - steps;
|
|
248
|
+
for (let i = fillStart; i < collection.length; i += 3) {
|
|
249
|
+
collection[i] = lastX;
|
|
250
|
+
collection[i + 1] = lastY;
|
|
251
|
+
collection[i + 2] = lastZ;
|
|
252
|
+
}
|
|
253
|
+
return collection;
|
|
254
|
+
};
|
|
255
|
+
function useTrail(target, settings, pointCount) {
|
|
256
|
+
const { local, decay, interval, stride } = { ...defaults, ...settings };
|
|
257
|
+
const points = React.useRef(null);
|
|
258
|
+
const [worldPosition] = React.useState(() => new Vector3());
|
|
259
|
+
React.useLayoutEffect(() => {
|
|
260
|
+
if (target) {
|
|
261
|
+
const pos = target.position;
|
|
262
|
+
points.current = Float32Array.from({ length: pointCount * 3 }, (_, i) => pos.getComponent(i % 3));
|
|
263
|
+
}
|
|
264
|
+
}, [pointCount, target]);
|
|
265
|
+
const prevPosition = React.useRef(new Vector3());
|
|
266
|
+
const frameCount = React.useRef(0);
|
|
267
|
+
useFrame(() => {
|
|
268
|
+
if (!target) return;
|
|
269
|
+
if (!points.current) return;
|
|
270
|
+
if (frameCount.current === 0) {
|
|
271
|
+
let newPosition;
|
|
272
|
+
if (local) newPosition = target.position;
|
|
273
|
+
else {
|
|
274
|
+
target.getWorldPosition(worldPosition);
|
|
275
|
+
newPosition = worldPosition;
|
|
276
|
+
}
|
|
277
|
+
const steps = 1 * decay;
|
|
278
|
+
for (let i = 0; i < steps; i++) {
|
|
279
|
+
if (newPosition.distanceTo(prevPosition.current) < stride) continue;
|
|
280
|
+
shiftLeft(points.current, 3);
|
|
281
|
+
points.current.set(newPosition.toArray(), points.current.length - 3);
|
|
282
|
+
}
|
|
283
|
+
prevPosition.current.copy(newPosition);
|
|
284
|
+
}
|
|
285
|
+
frameCount.current++;
|
|
286
|
+
frameCount.current = frameCount.current % interval;
|
|
287
|
+
});
|
|
288
|
+
return points;
|
|
289
|
+
}
|
|
290
|
+
const Trail = /* @__PURE__ */ React.forwardRef((props, forwardRef) => {
|
|
291
|
+
const { children } = props;
|
|
292
|
+
const { width, length, decay, local, stride, interval } = { ...defaults, ...props };
|
|
293
|
+
const { color = "hotpink", attenuation, target } = props;
|
|
294
|
+
const size = useThree((s) => s.size);
|
|
295
|
+
const scene = useThree((s) => s.scene);
|
|
296
|
+
const ref = React.useRef(null);
|
|
297
|
+
const [anchor, setAnchor] = React.useState(null);
|
|
298
|
+
const pointCount = length * 10;
|
|
299
|
+
const points = useTrail(anchor, { decay, local, stride, interval }, pointCount);
|
|
300
|
+
React.useEffect(() => {
|
|
301
|
+
const t = target?.current || ref.current.children.find((o) => o instanceof Object3D);
|
|
302
|
+
if (t) setAnchor(t);
|
|
303
|
+
}, [points, target]);
|
|
304
|
+
const line = React.useMemo(() => new Line2(), []);
|
|
305
|
+
const geo = React.useMemo(() => {
|
|
306
|
+
const geometry = new LineGeometry();
|
|
307
|
+
const initialPositions = new Float32Array(pointCount * 3).fill(0);
|
|
308
|
+
const initialColors = new Float32Array(pointCount * 3).fill(1);
|
|
309
|
+
geometry.setPositions(initialPositions);
|
|
310
|
+
geometry.setColors(initialColors);
|
|
311
|
+
return geometry;
|
|
312
|
+
}, [pointCount]);
|
|
313
|
+
const [resolution] = React.useState(() => new Vector2(size.width, size.height));
|
|
314
|
+
const colorsRef = React.useRef(new Float32Array(pointCount * 3));
|
|
315
|
+
const baseColor = React.useMemo(() => new THREE.Color(color), [color]);
|
|
316
|
+
const mat = React.useMemo(
|
|
317
|
+
() => new LineMaterial({
|
|
318
|
+
color: 16777215,
|
|
319
|
+
linewidth: width,
|
|
320
|
+
vertexColors: true,
|
|
321
|
+
resolution: new Vector2(size.width, size.height),
|
|
322
|
+
transparent: true,
|
|
323
|
+
alphaToCoverage: true
|
|
324
|
+
}),
|
|
325
|
+
[width, size]
|
|
326
|
+
);
|
|
327
|
+
React.useEffect(() => {
|
|
328
|
+
resolution.set(size.width, size.height);
|
|
329
|
+
mat.resolution.set(size.width, size.height);
|
|
330
|
+
}, [size, mat, resolution]);
|
|
331
|
+
useFrame(() => {
|
|
332
|
+
if (!points.current) return;
|
|
333
|
+
const count = points.current.length / 3;
|
|
334
|
+
const colors = colorsRef.current;
|
|
335
|
+
for (let i = 0; i < count; i++) {
|
|
336
|
+
const t = i / (count - 1);
|
|
337
|
+
const alpha = attenuation ? attenuation(t) : t;
|
|
338
|
+
colors[i * 3 + 0] = baseColor.r * alpha;
|
|
339
|
+
colors[i * 3 + 1] = baseColor.g * alpha;
|
|
340
|
+
colors[i * 3 + 2] = baseColor.b * alpha;
|
|
341
|
+
}
|
|
342
|
+
geo.setPositions(points.current);
|
|
343
|
+
geo.setColors(colors);
|
|
344
|
+
line.computeLineDistances();
|
|
345
|
+
});
|
|
346
|
+
React.useLayoutEffect(() => {
|
|
347
|
+
line.geometry = geo;
|
|
348
|
+
line.material = mat;
|
|
349
|
+
}, [line, geo, mat]);
|
|
350
|
+
return /* @__PURE__ */ React.createElement("group", null, createPortal(/* @__PURE__ */ React.createElement("primitive", { object: line, ref: forwardRef }), scene), /* @__PURE__ */ React.createElement("group", { ref }, children));
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
export { MarchingCube, MarchingCubes, MarchingPlane, Outlines, Trail, useTrail };
|