hz-particles 1.0.15 → 1.2.0

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.
@@ -1,368 +1,100 @@
1
- import { jsxs as Ut, Fragment as qt, jsx as Je } from "react/jsx-runtime";
2
- import { useState as Bt, useEffect as _e, useRef as j, useMemo as T } from "react";
3
- import { useThree as wt, useFrame as bt } from "@react-three/fiber";
4
- import * as a from "three";
5
- import { fetchPreset as Ht, ParticleSystemManager as Lt } from "hz-particles";
6
- import { fetchPreset as tn } from "hz-particles";
7
- function At(l) {
8
- return Math.abs(Math.sin(l * 12.9898) * 43758.5453) % 1;
9
- }
10
- function Ot(l) {
11
- const r = Math.sin(l * 54321.67) * 43758.5453 % 1;
12
- return r < 0 ? r + 1 : r;
13
- }
14
- function Wt(l, r, U, e) {
15
- if (U <= 0) return 0;
16
- const g = r / U;
17
- let N = l.particleSize ?? 0.5;
18
- if (l.randomSize) {
19
- const X = l.minSize ?? 0.1, Q = l.maxSize ?? 0.5;
20
- N = X + (Q - X) * Ot(U);
21
- }
22
- const K = Math.max(0.01, Math.min(10, l.sizeLifetimeSpeed ?? 1));
23
- if (l.fadeSizeEnabled && (N *= 1 - Math.pow(g, 1 / K)), l.increaseSizeEnabled && (N *= 1 + Math.pow(g, 1 / K)), l.pulseEnabled) {
24
- const X = l.pulseAmplitude ?? 0.5, Q = l.pulseFrequency ?? 1, ce = (l.pulsePhaseRandom ?? 0) * At(e) * Math.PI * 2;
25
- N *= 1 + X * Math.sin(r * Q * Math.PI * 2 + ce);
26
- }
27
- return Math.max(0, N);
28
- }
29
- function _t(l, r, U, e) {
30
- if (U <= 0) return 0;
31
- let g = l.opacity ?? 1;
32
- const N = r / U;
33
- if (l.fadeEnabled && (g *= Math.max(0, 1 - N)), l.pulseEnabled && l.pulseOpacity) {
34
- const K = l.pulseAmplitude ?? 0.5, X = l.pulseFrequency ?? 1, re = (l.pulsePhaseRandom ?? 0) * At(e) * Math.PI * 2;
35
- g *= Math.max(0, 1 + K * Math.sin(r * X * Math.PI * 2 + re));
36
- }
37
- return Math.max(0, Math.min(1, g));
38
- }
39
- function Gt(l, r) {
40
- if (r === 1) return l;
41
- const U = (e, g) => e != null ? e * r : g * r;
1
+ import { useRef as b, useMemo as D, useEffect as k } from "react";
2
+ import { useFrame as J, useThree as N } from "@react-three/fiber";
3
+ import { initHzFxOverlay as Q, makeThreeSceneDepth as Y } from "hz-particles";
4
+ import { fetchPreset as he } from "hz-particles";
5
+ import { jsx as $ } from "react/jsx-runtime";
6
+ import * as s from "three";
7
+ function ee(r, t) {
8
+ if (t === 1) return r;
9
+ const h = (e, i) => e != null ? e * t : i * t;
42
10
  return {
43
- ...l,
44
- systems: l.systems.map((e) => ({
11
+ ...r,
12
+ systems: r.systems.map((e) => ({
45
13
  ...e,
46
14
  // Particle visual size
47
- particleSize: U(e.particleSize, 0.5),
48
- minSize: e.minSize != null ? e.minSize * r : void 0,
49
- maxSize: e.maxSize != null ? e.maxSize * r : void 0,
15
+ particleSize: h(e.particleSize, 0.5),
16
+ minSize: e.minSize != null ? e.minSize * t : void 0,
17
+ maxSize: e.maxSize != null ? e.maxSize * t : void 0,
50
18
  // Speed
51
- particleSpeed: (e.particleSpeed ?? 1) * r,
52
- minSpeed: e.minSpeed != null ? e.minSpeed * r : void 0,
53
- maxSpeed: e.maxSpeed != null ? e.maxSpeed * r : void 0,
19
+ particleSpeed: (e.particleSpeed ?? 1) * t,
20
+ minSpeed: e.minSpeed != null ? e.minSpeed * t : void 0,
21
+ maxSpeed: e.maxSpeed != null ? e.maxSpeed * t : void 0,
54
22
  // Emission shape dimensions
55
- cubeLength: e.cubeLength != null ? e.cubeLength * r : void 0,
56
- outerLength: e.outerLength != null ? e.outerLength * r : void 0,
57
- innerLength: e.innerLength != null ? e.innerLength * r : void 0,
58
- outerRadius: e.outerRadius != null ? e.outerRadius * r : void 0,
59
- innerRadius: e.innerRadius != null ? e.innerRadius * r : void 0,
60
- squareSize: e.squareSize != null ? e.squareSize * r : void 0,
61
- squareInnerSize: e.squareInnerSize != null ? e.squareInnerSize * r : void 0,
62
- circleInnerRadius: e.circleInnerRadius != null ? e.circleInnerRadius * r : void 0,
63
- circleOuterRadius: e.circleOuterRadius != null ? e.circleOuterRadius * r : void 0,
64
- cylinderInnerRadius: e.cylinderInnerRadius != null ? e.cylinderInnerRadius * r : void 0,
65
- cylinderOuterRadius: e.cylinderOuterRadius != null ? e.cylinderOuterRadius * r : void 0,
66
- cylinderHeight: e.cylinderHeight != null ? e.cylinderHeight * r : void 0,
23
+ cubeLength: e.cubeLength != null ? e.cubeLength * t : void 0,
24
+ outerLength: e.outerLength != null ? e.outerLength * t : void 0,
25
+ innerLength: e.innerLength != null ? e.innerLength * t : void 0,
26
+ outerRadius: e.outerRadius != null ? e.outerRadius * t : void 0,
27
+ innerRadius: e.innerRadius != null ? e.innerRadius * t : void 0,
28
+ squareSize: e.squareSize != null ? e.squareSize * t : void 0,
29
+ squareInnerSize: e.squareInnerSize != null ? e.squareInnerSize * t : void 0,
30
+ circleInnerRadius: e.circleInnerRadius != null ? e.circleInnerRadius * t : void 0,
31
+ circleOuterRadius: e.circleOuterRadius != null ? e.circleOuterRadius * t : void 0,
32
+ cylinderInnerRadius: e.cylinderInnerRadius != null ? e.cylinderInnerRadius * t : void 0,
33
+ cylinderOuterRadius: e.cylinderOuterRadius != null ? e.cylinderOuterRadius * t : void 0,
34
+ cylinderHeight: e.cylinderHeight != null ? e.cylinderHeight * t : void 0,
67
35
  // Trail
68
- emissionTrailWidth: (e.emissionTrailWidth ?? 0.3) * r,
69
- emissionTrailDuration: (e.emissionTrailDuration ?? 1) * r,
70
- emissionTrailMinDistance: e.emissionTrailMinDistance != null ? e.emissionTrailMinDistance * r : void 0,
71
- emissionTrailShapeAmplitude: e.emissionTrailShapeAmplitude != null ? e.emissionTrailShapeAmplitude * r : void 0
36
+ emissionTrailWidth: (e.emissionTrailWidth ?? 0.3) * t,
37
+ emissionTrailDuration: (e.emissionTrailDuration ?? 1) * t,
38
+ emissionTrailMinDistance: e.emissionTrailMinDistance != null ? e.emissionTrailMinDistance * t : void 0,
39
+ emissionTrailShapeAmplitude: e.emissionTrailShapeAmplitude != null ? e.emissionTrailShapeAmplitude * t : void 0
72
40
  }))
73
41
  };
74
42
  }
75
- function Xt(l) {
76
- let r = 0;
77
- for (const U of l.systems)
78
- r += U.maxParticles ?? 1e4;
79
- return r;
80
- }
81
- function Jt({
82
- preset: l,
83
- position: r,
84
- positionRef: U,
85
- autoPlay: e = !0,
86
- visible: g = !0,
87
- scale: N = 1,
88
- resetKey: K = 0,
89
- onComplete: X
43
+ function le({
44
+ preset: r,
45
+ positionRef: t,
46
+ position: h = [0, 0, 0],
47
+ scale: e = 1,
48
+ active: i = !0,
49
+ renderPriority: z = 1,
50
+ noOcclusion: A = !1
90
51
  }) {
91
- var Le;
92
- const [Q, re] = Bt(
93
- typeof l == "string" ? null : l
94
- );
95
- _e(() => {
96
- typeof l == "string" ? (re(null), Ht(l).then(re).catch((u) => {
97
- console.error("[HZParticlesFX] Failed to fetch preset:", u);
98
- })) : re(l);
99
- }, [l]);
100
- const { camera: ce, gl: Ye } = wt(), pe = j(null);
101
- if (!pe.current) {
102
- const u = (Le = Ye.backend) == null ? void 0 : Le.device;
103
- u && (pe.current = u);
104
- }
105
- const De = pe.current, Pe = j(null), ge = j(null), Ve = j(!1), H = j(!1), f = T(
106
- () => Q ? Gt(Q, N) : null,
107
- [Q, N]
108
- ), Be = T(
109
- () => (f == null ? void 0 : f.systems.every((u) => u.emissionTrailEnabled)) ?? !1,
110
- [f]
111
- ), je = T(
112
- () => f ? f.systems.every((u) => u.emissionTrailEnabled) ? 1 : Xt(f) : 0,
113
- [f]
114
- ), Ge = T(() => r ? r instanceof a.Vector3 ? r.clone() : new a.Vector3(...r) : new a.Vector3(0, 0, 0), [r]), ye = T(
115
- () => (f == null ? void 0 : f.systems.some((u) => u.emissionTrailEnabled)) ?? !1,
116
- [f]
117
- ), He = T(() => new a.PlaneGeometry(1, 1), []), n = T(() => {
118
- const u = document.createElement("canvas");
119
- u.width = 64, u.height = 64;
120
- const R = u.getContext("2d");
121
- R.clearRect(0, 0, 64, 64);
122
- const w = R.createRadialGradient(32, 32, 0, 32, 32, 32);
123
- w.addColorStop(0, "rgba(255,255,255,1)"), w.addColorStop(0.7, "rgba(255,255,255,1)"), w.addColorStop(1, "rgba(255,255,255,0)"), R.fillStyle = w, R.beginPath(), R.arc(32, 32, 32, 0, Math.PI * 2), R.fill();
124
- const b = new a.CanvasTexture(u);
125
- b.flipY = !1;
126
- const _ = new a.MeshBasicMaterial({
127
- color: 16777215,
128
- transparent: !0,
129
- depthWrite: !1,
130
- alphaTest: 0.01,
131
- map: b,
132
- vertexColors: !0,
133
- side: a.DoubleSide,
134
- blending: a.NormalBlending
135
- });
136
- return _.needsUpdate = !0, _;
137
- }, []), D = j(null);
138
- _e(() => {
139
- if (!f) return;
140
- const u = f.systems.find(
141
- (w) => !w.emissionTrailEnabled && w.textureEnabled && w.textureImageData
142
- );
143
- if (!u) {
144
- D.current && n.map !== D.current && (n.map = D.current, n.needsUpdate = !0);
145
- return;
52
+ const l = b(null), v = b(null), w = b(!1), I = b(0), H = b(i);
53
+ H.current = i;
54
+ const C = b(h);
55
+ C.current = h;
56
+ const F = D(
57
+ () => e && e !== 1 ? ee(r, e) : r,
58
+ [r, e]
59
+ ), V = (c) => t ? c.addMovingEmitter(F, {
60
+ getPosition: () => {
61
+ const d = t.current;
62
+ return H.current && d ? [d.x, d.y, d.z] : null;
146
63
  }
147
- D.current || (D.current = n.map);
148
- const R = new Image();
149
- return R.onload = () => {
150
- const w = new a.Texture(R);
151
- w.needsUpdate = !0, n.map = w, n.needsUpdate = !0;
152
- }, R.src = u.textureImageData, () => {
153
- n.map && n.map !== D.current && n.map.dispose();
154
- };
155
- }, [f, n]);
156
- const Se = 64, Z = j(null), k = j(0), y = 512, se = j({
157
- buf: new Float32Array(y * 6),
158
- // x, y, z, time, d1, d2
159
- head: 0,
160
- count: 0,
161
- elapsed: 0
162
- }), { trailGeo: ie, trailPosAttr: z, trailColAttr: L } = T(() => {
163
- const R = 8 * Se * 6, w = new Float32Array(R * 3), b = new Float32Array(R * 3), _ = new a.BufferGeometry(), he = new a.BufferAttribute(w, 3);
164
- he.setUsage(a.DynamicDrawUsage), _.setAttribute("position", he);
165
- const ve = new a.BufferAttribute(b, 3);
166
- return ve.setUsage(a.DynamicDrawUsage), _.setAttribute("color", ve), _.setDrawRange(0, 0), { trailGeo: _, trailPosAttr: he, trailColAttr: ve };
167
- }, []), Fe = T(() => new a.MeshBasicMaterial({
168
- color: 16777215,
169
- vertexColors: !0,
170
- transparent: !0,
171
- depthWrite: !1,
172
- side: a.DoubleSide,
173
- blending: a.NormalBlending
174
- }), []);
175
- _e(() => {
176
- if (!De || !f)
177
- return;
178
- const u = new Lt(De);
179
- return ge.current = u, H.current = !1, u.replaceSystems(f).then(() => {
180
- e && g && (u.respawnAllSystems(), H.current = !0);
181
- }).catch((R) => {
182
- console.error("[HZParticlesFX] replaceSystems FAILED:", R);
64
+ }) : c.addEmitter(F, C.current);
65
+ return k(() => {
66
+ var p, a;
67
+ const c = l.current;
68
+ if (!c) return;
69
+ let d = !1;
70
+ return (a = (p = v.current) == null ? void 0 : p.remove) == null || a.call(p), v.current = null, V(c).then((u) => {
71
+ var T;
72
+ d ? (T = u == null ? void 0 : u.remove) == null || T.call(u) : v.current = u;
183
73
  }), () => {
184
- typeof u.destroy == "function" && u.destroy(), ge.current = null;
74
+ d = !0;
185
75
  };
186
- }, [De, f]), _e(() => {
187
- const u = ge.current;
188
- u && e && g && !H.current && (u.respawnAllSystems(), H.current = !0, Ve.current = !1);
189
- }, [e, g]);
190
- const me = j(null), xe = j(K);
191
- _e(() => {
192
- if (K === xe.current) return;
193
- xe.current = K;
194
- const u = se.current;
195
- u.head = 0, u.count = 0, u.elapsed = 0, ie.setDrawRange(0, 0), me.current = null;
196
- const R = ge.current;
197
- R && (R.respawnAllSystems(), H.current = !0, Ve.current = !1);
198
- }, [K]);
199
- const Ne = T(() => new a.Matrix4(), []), fe = T(() => new a.Vector3(), []), ee = T(() => new a.Vector3(), []), oe = T(() => new a.Quaternion(), []), Me = T(() => new a.Vector3(), []), V = T(() => new a.Vector3(0, 0, 1), []), Ee = T(() => new a.Color(), []);
200
- return bt((u, R) => {
201
- var Ke;
202
- if (!g || !Pe.current || !ge.current) return;
203
- const w = ge.current, b = (U == null ? void 0 : U.current) ?? Ge, _ = R > 1 ? R / 1e3 : R, he = me.current, ve = he && _ > 0, Tt = ve ? (b.x - he.x) / _ : 0, Rt = ve ? (b.y - he.y) / _ : 0, It = ve ? (b.z - he.z) / _ : 0;
204
- me.current = { x: b.x, y: b.y, z: b.z };
205
- for (const { system: s, config: c } of w.particleSystems)
206
- c.emissionTrailEnabled ? (s.setSimulationTransform({
207
- position: [b.x, b.y, b.z],
208
- velocity: [Tt, Rt, It]
209
- }), c.emissionTranslationX = 0, c.emissionTranslationY = 0, c.emissionTranslationZ = 0) : (c.emissionTranslationX = b.x, c.emissionTranslationY = b.y, c.emissionTranslationZ = b.z);
210
- w.updateAllSystems(_);
211
- for (const { system: s } of w.particleSystems)
212
- s.readbackAndProcessParticles();
213
- if (ye) {
214
- const s = se.current;
215
- s.elapsed += _;
216
- let c = 0, P = 0;
217
- const q = (Ke = w.particleSystems.find(({ config: O }) => O.emissionTrailEnabled)) == null ? void 0 : Ke.config;
218
- if (q) {
219
- const O = q.emissionTrailShape ?? "straight";
220
- if (O !== "straight") {
221
- const B = q.emissionTrailShapeAmplitude ?? 0.1, le = q.emissionTrailShapeFrequency ?? 4, ne = 2 * Math.PI * le * s.elapsed;
222
- O === "zigzag" ? c = B * Math.sign(Math.sin(ne)) : O === "sine" ? c = B * Math.sin(ne) : O === "spiral" && (c = B * Math.sin(ne), P = B * Math.cos(ne));
223
- }
224
- }
225
- const te = s.head * 6;
226
- s.buf[te] = b.x, s.buf[te + 1] = b.y, s.buf[te + 2] = b.z, s.buf[te + 3] = s.elapsed, s.buf[te + 4] = c, s.buf[te + 5] = P, s.head = (s.head + 1) % y, s.count < y && s.count++;
76
+ }, [F]), k(() => () => {
77
+ var c, d;
78
+ (d = (c = l.current) == null ? void 0 : c.destroy) == null || d.call(c), l.current = null, v.current = null, w.current = !1;
79
+ }, []), J((c) => {
80
+ c.gl.render(c.scene, c.camera);
81
+ const d = performance.now(), p = I.current ? Math.min(0.05, (d - I.current) / 1e3) : 0.016;
82
+ I.current = d;
83
+ const a = c.gl, u = a.backend;
84
+ !l.current && !w.current && (u != null && u.device) && (u != null && u.context) && (w.current = !0, Q(
85
+ { device: u.device, context: u.context, canvas: a.domElement },
86
+ { getSceneDepth: A ? () => null : Y(a) }
87
+ ).then((S) => (l.current = S, V(S))).then((S) => {
88
+ v.current = S;
89
+ }).catch((S) => console.error("[HZFaithfulFX] init failed:", S)));
90
+ const T = l.current;
91
+ if (T) {
92
+ const S = c.camera;
93
+ T.setCamera(S.projectionMatrix.elements, S.matrixWorldInverse.elements, S.position), T.render(p);
227
94
  }
228
- const ze = Pe.current;
229
- let we = 0;
230
- for (let s = 0; s < w.particleSystems.length; s++) {
231
- const { system: c, config: P } = w.particleSystems[s];
232
- if (P.emissionTrailEnabled) continue;
233
- const q = c.particleData, te = c.activeParticles;
234
- if (!(!q || te <= 0))
235
- for (let O = 0; O < te; O++) {
236
- const B = O * 8, le = q[B + 0], ne = q[B + 1], C = q[B + 2];
237
- let be = q[B + 3], Ae = q[B + 4], J = q[B + 5];
238
- const Te = q[B + 6], ae = q[B + 7];
239
- if (Te >= ae || ae <= 0) continue;
240
- const x = Te / ae;
241
- if (P.colorTransitionEnabled) {
242
- const F = P.startColor ?? [1, 0, 0], ue = P.endColor ?? [0, 0, 1];
243
- be = F[0] + (ue[0] - F[0]) * x, Ae = F[1] + (ue[1] - F[1]) * x, J = F[2] + (ue[2] - F[2]) * x;
244
- }
245
- const Re = P.bloomIntensity ?? 1;
246
- be = Math.min(1, be * Re), Ae = Math.min(1, Ae * Re), J = Math.min(1, J * Re);
247
- const Ie = _t(P, Te, ae, O);
248
- be *= Ie, Ae *= Ie, J *= Ie;
249
- const $ = Wt(P, Te, ae, O);
250
- if (!($ <= 0)) {
251
- if (fe.set(le, ne, C), ee.subVectors(ce.position, fe).normalize(), oe.setFromUnitVectors(V, ee), P.velocityStretchEnabled && c.particleVelocities) {
252
- const F = O * 4, ue = c.particleVelocities[F], Ue = c.particleVelocities[F + 1], E = c.particleVelocities[F + 2], de = Math.sqrt(ue * ue + Ue * Ue + E * E);
253
- if (de > 1e-3) {
254
- const Qe = P.velocityStretchFactor ?? 1, G = $ * (1 + de * Qe);
255
- Me.set($, G, 1), ee.set(ue, Ue, E).normalize(), oe.setFromUnitVectors(V, ee);
256
- const i = (G - $) * 0.5;
257
- fe.addScaledVector(ee, i);
258
- } else
259
- Me.set($, $, 1);
260
- } else
261
- Me.set($, $, 1);
262
- Ne.compose(fe, oe, Me), ze.setMatrixAt(we, Ne), Ee.setRGB(be, Ae, J), ze.setColorAt(we, Ee), we++;
263
- }
264
- }
265
- }
266
- ze.count = we, ze.visible = we > 0, we > 0 && (ze.instanceMatrix.needsUpdate = !0, ze.instanceColor && (ze.instanceColor.needsUpdate = !0));
267
- const $e = we > 0 || w.particleSystems.some(({ system: s }) => s.emitting || s.activeParticles > 0);
268
- if (Ve.current && !$e && (H.current = !1, X == null || X()), Ve.current = $e, ye && Z.current) {
269
- const s = z.array, c = L.array;
270
- let P = 0;
271
- const q = ce.position.x, te = ce.position.y, O = ce.position.z;
272
- for (let le = 0; le < w.particleSystems.length; le++) {
273
- const { system: ne, config: C } = w.particleSystems[le];
274
- if (!C.emissionTrailEnabled || !ne.emitting && ne.activeParticles <= 0) continue;
275
- const be = C.emissionTrailDuration ?? 1, Ae = C.emissionTrailWidth ?? 0.3, J = C.bloomIntensity ?? 1, Te = Ae * 0.5, ae = se.current, x = ae.buf, Re = ae.count, Ie = ae.head, $ = ae.elapsed;
276
- if (Re < 2) continue;
277
- const F = ((Ie - Re) % y + y) % y, ue = $ - x[F * 6 + 3], Ue = Math.min(be, ue);
278
- if (Ue < 1e-3) continue;
279
- const E = C.colorTransitionEnabled ? C.startColor ?? [1, 1, 1] : C.particleColor ?? [1, 1, 1], de = C.colorTransitionEnabled ? C.endColor ?? [1, 1, 1] : E, Qe = (t, o) => {
280
- const h = $ - t;
281
- for (let d = 0; d < Re - 1; d++) {
282
- const M = ((Ie - 1 - d) % y + y) % y, I = ((Ie - 2 - d) % y + y) % y, W = x[M * 6 + 3], A = x[I * 6 + 3];
283
- if (h >= A && h <= W) {
284
- const m = W !== A ? (h - A) / (W - A) : 0;
285
- o[0] = x[I * 6] + (x[M * 6] - x[I * 6]) * m, o[1] = x[I * 6 + 1] + (x[M * 6 + 1] - x[I * 6 + 1]) * m, o[2] = x[I * 6 + 2] + (x[M * 6 + 2] - x[I * 6 + 2]) * m, o[3] = x[I * 6 + 4] + (x[M * 6 + 4] - x[I * 6 + 4]) * m, o[4] = x[I * 6 + 5] + (x[M * 6 + 5] - x[I * 6 + 5]) * m;
286
- return;
287
- }
288
- }
289
- o[0] = x[F * 6], o[1] = x[F * 6 + 1], o[2] = x[F * 6 + 2], o[3] = x[F * 6 + 4], o[4] = x[F * 6 + 5];
290
- }, G = Math.max(1, Math.min(Se, C.emissionTrailSegments ?? 8)), i = [b.x, b.y, b.z], Oe = C.emissionTrailShape ?? "straight", Xe = [];
291
- {
292
- const t = C.emissionTrailShapeAmplitude ?? 0.1, o = C.emissionTrailShapeFrequency ?? 4, h = 2 * Math.PI * o * $;
293
- let d = 0, M = 0;
294
- Oe === "zigzag" ? d = t * Math.sign(Math.sin(h)) : Oe === "sine" ? d = t * Math.sin(h) : Oe === "spiral" && (d = t * Math.sin(h), M = t * Math.cos(h)), Xe.push(d, M);
295
- }
296
- const qe = [0, 0, 0, 0, 0];
297
- for (let t = 1; t <= G; t++) {
298
- const o = t / G * Ue;
299
- Qe(o, qe), i.push(qe[0], qe[1], qe[2]), Xe.push(qe[3], qe[4]);
300
- }
301
- const et = i[0] - i[G * 3], tt = i[1] - i[G * 3 + 1], nt = i[2] - i[G * 3 + 2];
302
- if (et * et + tt * tt + nt * nt < 1e-6) continue;
303
- let rt = 0, st = 0, it = 0;
304
- const Ce = [], Ze = [];
305
- for (let t = 0; t <= G; t++) {
306
- let o, h, d;
307
- t === 0 ? (o = i[3] - i[0], h = i[4] - i[1], d = i[5] - i[2]) : t === G ? (o = i[t * 3] - i[(t - 1) * 3], h = i[t * 3 + 1] - i[(t - 1) * 3 + 1], d = i[t * 3 + 2] - i[(t - 1) * 3 + 2]) : (o = i[(t + 1) * 3] - i[(t - 1) * 3], h = i[(t + 1) * 3 + 1] - i[(t - 1) * 3 + 1], d = i[(t + 1) * 3 + 2] - i[(t - 1) * 3 + 2]);
308
- let M = Math.sqrt(o * o + h * h + d * d);
309
- M < 1e-8 && (o = 0, h = 0, d = 1, M = 1), o /= M, h /= M, d /= M, Ze.push(o, h, d);
310
- const I = q - i[t * 3], W = te - i[t * 3 + 1], A = O - i[t * 3 + 2];
311
- let m = h * A - d * W, S = d * I - o * A, v = o * W - h * I, Y = Math.sqrt(m * m + S * S + v * v);
312
- Y < 1e-8 && (m = -d, S = 0, v = o, Y = Math.sqrt(m * m + S * S + v * v)), Y < 1e-8 && (m = 0, S = 1, v = 0, Y = 1), m /= Y, S /= Y, v /= Y, t > 0 && m * rt + S * st + v * it < 0 && (m = -m, S = -S, v = -v), rt = m, st = S, it = v, Ce.push(m, S, v);
313
- }
314
- if (Oe !== "straight")
315
- for (let t = 1; t <= G; t++) {
316
- const o = Xe[t * 2], h = Xe[t * 2 + 1];
317
- if (Math.abs(o) < 1e-8 && Math.abs(h) < 1e-8) continue;
318
- const d = t * 3, M = Ze[d], I = Ze[d + 1], W = Ze[d + 2];
319
- let A = -W, m = 0, S = M, v = Math.sqrt(A * A + S * S);
320
- if (v < 1e-6 && (A = 0, m = W, S = -I, v = Math.sqrt(A * A + m * m + S * S), v < 1e-6 && (A = 1, m = 0, S = 0, v = 1)), A /= v, m /= v, S /= v, Oe === "spiral") {
321
- const Y = I * S - W * m, We = W * A - M * S, ke = M * m - I * A;
322
- i[d] += A * o + Y * h, i[d + 1] += m * o + We * h, i[d + 2] += S * o + ke * h;
323
- } else
324
- i[d] += A * o, i[d + 1] += m * o, i[d + 2] += S * o;
325
- }
326
- for (let t = 0; t < G; t++) {
327
- const o = t / G, h = (t + 1) / G, d = Te * (1 - o), M = Te * (1 - h), I = (1 - o) * (1 - o), W = (1 - h) * (1 - h), A = Math.min(1, (E[0] + (de[0] - E[0]) * o) * J) * I, m = Math.min(1, (E[1] + (de[1] - E[1]) * o) * J) * I, S = Math.min(1, (E[2] + (de[2] - E[2]) * o) * J) * I, v = Math.min(1, (E[0] + (de[0] - E[0]) * h) * J) * W, Y = Math.min(1, (E[1] + (de[1] - E[1]) * h) * J) * W, We = Math.min(1, (E[2] + (de[2] - E[2]) * h) * J) * W, ke = i[t * 3], ot = i[t * 3 + 1], at = i[t * 3 + 2], ct = i[(t + 1) * 3], lt = i[(t + 1) * 3 + 1], ut = i[(t + 1) * 3 + 2], dt = Ce[t * 3], pt = Ce[t * 3 + 1], mt = Ce[t * 3 + 2], ft = Ce[(t + 1) * 3], ht = Ce[(t + 1) * 3 + 1], gt = Ce[(t + 1) * 3 + 2], Ct = ke + dt * d, Dt = ot + pt * d, Pt = at + mt * d, yt = ke - dt * d, St = ot - pt * d, xt = at - mt * d, Mt = ct + ft * M, vt = lt + ht * M, zt = ut + gt * M, Vt = ct - ft * M, Ft = lt - ht * M, Et = ut - gt * M, p = P * 3;
328
- s[p] = Ct, s[p + 1] = Dt, s[p + 2] = Pt, c[p] = A, c[p + 1] = m, c[p + 2] = S, s[p + 3] = yt, s[p + 4] = St, s[p + 5] = xt, c[p + 3] = A, c[p + 4] = m, c[p + 5] = S, s[p + 6] = Mt, s[p + 7] = vt, s[p + 8] = zt, c[p + 6] = v, c[p + 7] = Y, c[p + 8] = We, s[p + 9] = yt, s[p + 10] = St, s[p + 11] = xt, c[p + 9] = A, c[p + 10] = m, c[p + 11] = S, s[p + 12] = Vt, s[p + 13] = Ft, s[p + 14] = Et, c[p + 12] = v, c[p + 13] = Y, c[p + 14] = We, s[p + 15] = Mt, s[p + 16] = vt, s[p + 17] = zt, c[p + 15] = v, c[p + 16] = Y, c[p + 17] = We, P += 6;
329
- }
330
- }
331
- const B = k.current;
332
- if (P < B) {
333
- const le = P * 3, ne = B * 3;
334
- for (let C = le; C < ne; C++)
335
- s[C] = 0, c[C] = 0;
336
- }
337
- k.current = P, ie.setDrawRange(0, P), z.needsUpdate = !0, L.needsUpdate = !0;
338
- }
339
- }), Q ? /* @__PURE__ */ Ut(qt, { children: [
340
- /* @__PURE__ */ Je(
341
- "instancedMesh",
342
- {
343
- ref: (u) => {
344
- Pe.current = u, u && (u.count = 0, u.visible = !Be);
345
- },
346
- args: [He, n, je],
347
- frustumCulled: !1,
348
- renderOrder: 100,
349
- visible: g && !Be
350
- }
351
- ),
352
- ye && /* @__PURE__ */ Je(
353
- "mesh",
354
- {
355
- ref: Z,
356
- geometry: ie,
357
- material: Fe,
358
- frustumCulled: !1,
359
- renderOrder: 99,
360
- visible: g
361
- }
362
- )
363
- ] }) : null;
95
+ }, z), null;
364
96
  }
365
- const Zt = (
97
+ const te = (
366
98
  /* glsl */
367
99
  `
368
100
  attribute vec4 aColor;
@@ -372,7 +104,7 @@ void main() {
372
104
  gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
373
105
  }
374
106
  `
375
- ), kt = (
107
+ ), ne = (
376
108
  /* glsl */
377
109
  `
378
110
  varying vec4 vColor;
@@ -381,113 +113,145 @@ void main() {
381
113
  }
382
114
  `
383
115
  );
384
- function $t({
385
- positionRef: l,
386
- duration: r = 1,
387
- width: U = 0.3,
116
+ function se({
117
+ positionRef: r,
118
+ duration: t = 1,
119
+ width: h = 0.3,
388
120
  color: e = [1, 1, 1],
389
- maxPoints: g = 256,
390
- minDistance: N = 0.05,
391
- opacity: K = 1,
392
- blending: X = a.AdditiveBlending,
393
- visible: Q = !0
121
+ maxPoints: i = 256,
122
+ minDistance: z = 0.05,
123
+ opacity: A = 1,
124
+ blending: l = s.AdditiveBlending,
125
+ visible: v = !0
394
126
  }) {
395
- const { camera: re } = wt(), ce = j(null), Ye = j({
396
- positions: new Float32Array(g * 3),
397
- times: new Float32Array(g),
127
+ const { camera: w } = N(), I = b(null), H = b({
128
+ positions: new Float32Array(i * 3),
129
+ times: new Float32Array(i),
398
130
  head: 0,
399
131
  count: 0,
400
- lastPos: new a.Vector3(1 / 0, 1 / 0, 1 / 0),
132
+ lastPos: new s.Vector3(1 / 0, 1 / 0, 1 / 0),
401
133
  elapsed: 0
402
- }), { geometry: pe, posAttr: De, colorAttr: Pe, indexBuf: ge } = T(() => {
403
- const ye = g * 2, He = new Float32Array(ye * 3), n = new Float32Array(ye * 4), D = new a.BufferGeometry(), Se = new a.BufferAttribute(He, 3);
404
- Se.setUsage(a.DynamicDrawUsage), D.setAttribute("position", Se);
405
- const Z = new a.BufferAttribute(n, 4);
406
- Z.setUsage(a.DynamicDrawUsage), D.setAttribute("aColor", Z);
407
- const k = (g - 1) * 6, y = new Uint32Array(k);
408
- for (let ie = 0; ie < g - 1; ie++) {
409
- const z = ie * 2, L = ie * 6;
410
- y[L] = z, y[L + 1] = z + 1, y[L + 2] = z + 2, y[L + 3] = z + 1, y[L + 4] = z + 3, y[L + 5] = z + 2;
134
+ }), { geometry: C, posAttr: F, colorAttr: V, indexBuf: c } = D(() => {
135
+ const W = i * 2, j = new Float32Array(W * 3), n = new Float32Array(W * 4), R = new s.BufferGeometry(), O = new s.BufferAttribute(j, 3);
136
+ O.setUsage(s.DynamicDrawUsage), R.setAttribute("position", O);
137
+ const g = new s.BufferAttribute(n, 4);
138
+ g.setUsage(s.DynamicDrawUsage), R.setAttribute("aColor", g);
139
+ const M = (i - 1) * 6, m = new Uint32Array(M);
140
+ for (let E = 0; E < i - 1; E++) {
141
+ const o = E * 2, x = E * 6;
142
+ m[x] = o, m[x + 1] = o + 1, m[x + 2] = o + 2, m[x + 3] = o + 1, m[x + 4] = o + 3, m[x + 5] = o + 2;
411
143
  }
412
- const se = new a.BufferAttribute(y, 1);
413
- return D.setIndex(se), D.setDrawRange(0, 0), { geometry: D, posAttr: Se, colorAttr: Z, indexBuf: se };
414
- }, [g]), Ve = T(() => new a.ShaderMaterial({
415
- vertexShader: Zt,
416
- fragmentShader: kt,
144
+ const y = new s.BufferAttribute(m, 1);
145
+ return R.setIndex(y), R.setDrawRange(0, 0), { geometry: R, posAttr: O, colorAttr: g, indexBuf: y };
146
+ }, [i]), d = D(() => new s.ShaderMaterial({
147
+ vertexShader: te,
148
+ fragmentShader: ne,
417
149
  transparent: !0,
418
150
  depthWrite: !1,
419
- side: a.DoubleSide,
420
- blending: X
421
- }), [X]), H = T(() => new a.Vector3(), []), f = T(() => new a.Vector3(), []), Be = T(() => new a.Vector3(), []), je = T(() => new a.Vector3(0, 1, 0), []), Ge = T(() => new a.Vector3(), []);
422
- return bt((ye, He) => {
423
- if (!ce.current) return;
424
- const n = Ye.current;
425
- if (n.elapsed += He, !Q) {
426
- n.count = 0, n.head = 0, n.lastPos.set(1 / 0, 1 / 0, 1 / 0), pe.setDrawRange(0, 0);
151
+ side: s.DoubleSide,
152
+ blending: l
153
+ }), [l]), p = D(() => new s.Vector3(), []), a = D(() => new s.Vector3(), []), u = D(() => new s.Vector3(), []), T = D(() => new s.Vector3(0, 1, 0), []), S = D(() => new s.Vector3(), []);
154
+ return J((W, j) => {
155
+ if (!I.current) return;
156
+ const n = H.current;
157
+ if (n.elapsed += j, !v) {
158
+ n.count = 0, n.head = 0, n.lastPos.set(1 / 0, 1 / 0, 1 / 0), C.setDrawRange(0, 0);
427
159
  return;
428
160
  }
429
- const D = l.current;
430
- if (!D) return;
431
- if (n.lastPos.distanceTo(D) >= N) {
432
- const z = (n.head + n.count) % g;
433
- n.positions[z * 3] = D.x, n.positions[z * 3 + 1] = D.y, n.positions[z * 3 + 2] = D.z, n.times[z] = n.elapsed, n.count < g ? n.count++ : n.head = (n.head + 1) % g, n.lastPos.copy(D);
161
+ const R = r.current;
162
+ if (!R) return;
163
+ if (n.lastPos.distanceTo(R) >= z) {
164
+ const o = (n.head + n.count) % i;
165
+ n.positions[o * 3] = R.x, n.positions[o * 3 + 1] = R.y, n.positions[o * 3 + 2] = R.z, n.times[o] = n.elapsed, n.count < i ? n.count++ : n.head = (n.head + 1) % i, n.lastPos.copy(R);
434
166
  }
435
167
  for (; n.count > 0; ) {
436
- const z = n.head;
437
- if (n.elapsed - n.times[z] > r)
438
- n.head = (n.head + 1) % g, n.count--;
168
+ const o = n.head;
169
+ if (n.elapsed - n.times[o] > t)
170
+ n.head = (n.head + 1) % i, n.count--;
439
171
  else
440
172
  break;
441
173
  }
442
174
  if (n.count < 2) {
443
- pe.setDrawRange(0, 0);
175
+ C.setDrawRange(0, 0);
444
176
  return;
445
177
  }
446
- const Z = De.array, k = Pe.array;
447
- let y = null;
448
- const se = n.count;
449
- for (let z = 0; z < se; z++) {
450
- const L = (n.head + z) % g, Fe = n.positions[L * 3], me = n.positions[L * 3 + 1], xe = n.positions[L * 3 + 2], fe = 1 - (n.elapsed - n.times[L]) / r;
451
- if (z < se - 1) {
452
- const Ee = (n.head + z + 1) % g;
453
- H.set(
454
- n.positions[Ee * 3] - Fe,
455
- n.positions[Ee * 3 + 1] - me,
456
- n.positions[Ee * 3 + 2] - xe
178
+ const g = F.array, M = V.array;
179
+ let m = null;
180
+ const y = n.count;
181
+ for (let o = 0; o < y; o++) {
182
+ const x = (n.head + o) % i, B = n.positions[x * 3], U = n.positions[x * 3 + 1], P = n.positions[x * 3 + 2], Z = 1 - (n.elapsed - n.times[x]) / t;
183
+ if (o < y - 1) {
184
+ const _ = (n.head + o + 1) % i;
185
+ p.set(
186
+ n.positions[_ * 3] - B,
187
+ n.positions[_ * 3 + 1] - U,
188
+ n.positions[_ * 3 + 2] - P
457
189
  );
458
- const Le = H.length();
459
- Le > 1e-6 ? H.divideScalar(Le) : y && H.copy(y);
460
- } else y && H.copy(y);
461
- Be.set(
462
- re.position.x - Fe,
463
- re.position.y - me,
464
- re.position.z - xe
465
- ), f.crossVectors(H, Be);
466
- let ee = f.length();
467
- ee < 1e-6 && (Ge.crossVectors(H, je), f.copy(Ge), ee = f.length(), ee < 1e-6 && (f.set(1, 0, 0), ee = 1)), f.divideScalar(ee);
468
- const oe = U * fe, Me = K * fe * fe, V = z * 2;
469
- Z[V * 3] = Fe + f.x * oe, Z[V * 3 + 1] = me + f.y * oe, Z[V * 3 + 2] = xe + f.z * oe, Z[(V + 1) * 3] = Fe - f.x * oe, Z[(V + 1) * 3 + 1] = me - f.y * oe, Z[(V + 1) * 3 + 2] = xe - f.z * oe, k[V * 4] = e[0], k[V * 4 + 1] = e[1], k[V * 4 + 2] = e[2], k[V * 4 + 3] = Me, k[(V + 1) * 4] = e[0], k[(V + 1) * 4 + 1] = e[1], k[(V + 1) * 4 + 2] = e[2], k[(V + 1) * 4 + 3] = Me, y = y || new a.Vector3(), y.copy(H);
190
+ const G = p.length();
191
+ G > 1e-6 ? p.divideScalar(G) : m && p.copy(m);
192
+ } else m && p.copy(m);
193
+ u.set(
194
+ w.position.x - B,
195
+ w.position.y - U,
196
+ w.position.z - P
197
+ ), a.crossVectors(p, u);
198
+ let q = a.length();
199
+ q < 1e-6 && (S.crossVectors(p, T), a.copy(S), q = a.length(), q < 1e-6 && (a.set(1, 0, 0), q = 1)), a.divideScalar(q);
200
+ const L = h * Z, X = A * Z * Z, f = o * 2;
201
+ g[f * 3] = B + a.x * L, g[f * 3 + 1] = U + a.y * L, g[f * 3 + 2] = P + a.z * L, g[(f + 1) * 3] = B - a.x * L, g[(f + 1) * 3 + 1] = U - a.y * L, g[(f + 1) * 3 + 2] = P - a.z * L, M[f * 4] = e[0], M[f * 4 + 1] = e[1], M[f * 4 + 2] = e[2], M[f * 4 + 3] = X, M[(f + 1) * 4] = e[0], M[(f + 1) * 4 + 1] = e[1], M[(f + 1) * 4 + 2] = e[2], M[(f + 1) * 4 + 3] = X, m = m || new s.Vector3(), m.copy(p);
470
202
  }
471
- const ie = (se - 1) * 6;
472
- pe.setDrawRange(0, ie), De.needsUpdate = !0, Pe.needsUpdate = !0;
473
- }), /* @__PURE__ */ Je(
203
+ const E = (y - 1) * 6;
204
+ C.setDrawRange(0, E), F.needsUpdate = !0, V.needsUpdate = !0;
205
+ }), /* @__PURE__ */ $(
474
206
  "mesh",
475
207
  {
476
- ref: ce,
477
- geometry: pe,
478
- material: Ve,
208
+ ref: I,
209
+ geometry: C,
210
+ material: d,
479
211
  frustumCulled: !1,
480
212
  renderOrder: 101,
481
- visible: Q
213
+ visible: v
482
214
  }
483
215
  );
484
216
  }
217
+ function K(r) {
218
+ return Math.abs(Math.sin(r * 12.9898) * 43758.5453) % 1;
219
+ }
220
+ function re(r) {
221
+ const t = Math.sin(r * 54321.67) * 43758.5453 % 1;
222
+ return t < 0 ? t + 1 : t;
223
+ }
224
+ function de(r, t, h, e) {
225
+ if (h <= 0) return 0;
226
+ const i = t / h;
227
+ let z = r.particleSize ?? 0.5;
228
+ if (r.randomSize) {
229
+ const l = r.minSize ?? 0.1, v = r.maxSize ?? 0.5;
230
+ z = l + (v - l) * re(h);
231
+ }
232
+ const A = Math.max(0.01, Math.min(10, r.sizeLifetimeSpeed ?? 1));
233
+ if (r.fadeSizeEnabled && (z *= 1 - Math.pow(i, 1 / A)), r.increaseSizeEnabled && (z *= 1 + Math.pow(i, 1 / A)), r.pulseEnabled) {
234
+ const l = r.pulseAmplitude ?? 0.5, v = r.pulseFrequency ?? 1, I = (r.pulsePhaseRandom ?? 0) * K(e) * Math.PI * 2;
235
+ z *= 1 + l * Math.sin(t * v * Math.PI * 2 + I);
236
+ }
237
+ return Math.max(0, z);
238
+ }
239
+ function pe(r, t, h, e) {
240
+ if (h <= 0) return 0;
241
+ let i = r.opacity ?? 1;
242
+ const z = t / h;
243
+ if (r.fadeEnabled && (i *= Math.max(0, 1 - z)), r.pulseEnabled && r.pulseOpacity) {
244
+ const A = r.pulseAmplitude ?? 0.5, l = r.pulseFrequency ?? 1, w = (r.pulsePhaseRandom ?? 0) * K(e) * Math.PI * 2;
245
+ i *= Math.max(0, 1 + A * Math.sin(t * l * Math.PI * 2 + w));
246
+ }
247
+ return Math.max(0, Math.min(1, i));
248
+ }
485
249
  export {
486
- Jt as HZParticlesFX,
487
- $t as HZTrailRibbon,
488
- _t as computeParticleOpacity,
489
- Wt as computeParticleSize,
490
- tn as fetchPreset,
491
- At as particleHash,
492
- Gt as scalePreset
250
+ le as HZFaithfulFX,
251
+ se as HZTrailRibbon,
252
+ pe as computeParticleOpacity,
253
+ de as computeParticleSize,
254
+ he as fetchPreset,
255
+ K as particleHash,
256
+ ee as scalePreset
493
257
  };