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