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