hz-particles 1.0.13 → 1.0.14
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,329 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { useThree as
|
|
4
|
-
import * as
|
|
5
|
-
import { fetchPreset as
|
|
6
|
-
import { fetchPreset as
|
|
7
|
-
function
|
|
8
|
-
return Math.abs(Math.sin(
|
|
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
9
|
}
|
|
10
|
-
function
|
|
11
|
-
const
|
|
12
|
-
return
|
|
10
|
+
function We(a) {
|
|
11
|
+
const d = Math.sin(a * 54321.67) * 43758.5453 % 1;
|
|
12
|
+
return d < 0 ? d + 1 : d;
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
if (
|
|
16
|
-
const
|
|
17
|
-
let
|
|
18
|
-
if (
|
|
19
|
-
const
|
|
20
|
-
|
|
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
21
|
}
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
24
|
-
const
|
|
25
|
-
|
|
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
26
|
}
|
|
27
|
-
return Math.max(0,
|
|
27
|
+
return Math.max(0, j);
|
|
28
28
|
}
|
|
29
|
-
function
|
|
30
|
-
if (
|
|
31
|
-
let
|
|
32
|
-
const
|
|
33
|
-
if (
|
|
34
|
-
const
|
|
35
|
-
|
|
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
36
|
}
|
|
37
|
-
return Math.max(0, Math.min(1,
|
|
37
|
+
return Math.max(0, Math.min(1, g));
|
|
38
38
|
}
|
|
39
|
-
function
|
|
40
|
-
return
|
|
41
|
-
...
|
|
42
|
-
systems:
|
|
43
|
-
...
|
|
44
|
-
particleSize: (
|
|
45
|
-
minSize:
|
|
46
|
-
maxSize:
|
|
47
|
-
particleSpeed: (
|
|
48
|
-
minSpeed:
|
|
49
|
-
maxSpeed:
|
|
50
|
-
emissionTrailWidth: (
|
|
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
|
|
51
52
|
}))
|
|
52
53
|
};
|
|
53
54
|
}
|
|
54
|
-
function
|
|
55
|
-
let
|
|
56
|
-
for (const
|
|
57
|
-
|
|
58
|
-
return
|
|
55
|
+
function Xe(a) {
|
|
56
|
+
let d = 0;
|
|
57
|
+
for (const m of a.systems)
|
|
58
|
+
d += m.maxParticles ?? 1e4;
|
|
59
|
+
return d;
|
|
59
60
|
}
|
|
60
|
-
function
|
|
61
|
-
preset:
|
|
62
|
-
position:
|
|
63
|
-
positionRef:
|
|
64
|
-
autoPlay:
|
|
65
|
-
visible:
|
|
66
|
-
scale:
|
|
67
|
-
resetKey:
|
|
68
|
-
onComplete:
|
|
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
|
|
69
70
|
}) {
|
|
70
|
-
var
|
|
71
|
-
const [
|
|
72
|
-
typeof
|
|
71
|
+
var Ft;
|
|
72
|
+
const [Q, st] = Be(
|
|
73
|
+
typeof a == "string" ? null : a
|
|
73
74
|
);
|
|
74
|
-
|
|
75
|
-
typeof
|
|
76
|
-
console.error("[HZParticlesFX] Failed to fetch preset:",
|
|
77
|
-
})) :
|
|
78
|
-
}, [
|
|
79
|
-
const { camera:
|
|
80
|
-
if (!
|
|
81
|
-
const
|
|
82
|
-
|
|
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);
|
|
83
84
|
}
|
|
84
|
-
const
|
|
85
|
-
() =>
|
|
86
|
-
[
|
|
87
|
-
),
|
|
88
|
-
() => (
|
|
89
|
-
[
|
|
90
|
-
),
|
|
91
|
-
() =>
|
|
92
|
-
[
|
|
93
|
-
),
|
|
94
|
-
() => (
|
|
95
|
-
[
|
|
96
|
-
),
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
const
|
|
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({
|
|
106
107
|
color: 16777215,
|
|
107
108
|
transparent: !0,
|
|
108
109
|
depthWrite: !1,
|
|
109
110
|
alphaTest: 0.01,
|
|
110
|
-
map:
|
|
111
|
+
map: z,
|
|
111
112
|
vertexColors: !0,
|
|
112
|
-
side:
|
|
113
|
-
blending:
|
|
113
|
+
side: i.DoubleSide,
|
|
114
|
+
blending: i.AdditiveBlending
|
|
114
115
|
});
|
|
115
|
-
return
|
|
116
|
-
}, []),
|
|
117
|
-
buf: new Float32Array(
|
|
118
|
-
// x, y, z, time
|
|
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
|
|
119
120
|
head: 0,
|
|
120
121
|
count: 0,
|
|
121
122
|
elapsed: 0
|
|
122
|
-
}), { trailGeo:
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
return
|
|
127
|
-
}, []),
|
|
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({
|
|
128
129
|
color: 16777215,
|
|
129
130
|
vertexColors: !0,
|
|
130
131
|
transparent: !0,
|
|
131
132
|
depthWrite: !1,
|
|
132
|
-
side:
|
|
133
|
-
blending:
|
|
133
|
+
side: i.DoubleSide,
|
|
134
|
+
blending: i.AdditiveBlending
|
|
134
135
|
}), []);
|
|
135
|
-
|
|
136
|
-
if (!
|
|
136
|
+
Lt(() => {
|
|
137
|
+
if (!Vt || !h)
|
|
137
138
|
return;
|
|
138
|
-
const
|
|
139
|
-
return
|
|
140
|
-
|
|
141
|
-
}).catch((
|
|
142
|
-
console.error("[HZParticlesFX] replaceSystems FAILED:",
|
|
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);
|
|
143
144
|
}), () => {
|
|
144
|
-
typeof
|
|
145
|
+
typeof c.destroy == "function" && c.destroy(), yt.current = null;
|
|
145
146
|
};
|
|
146
|
-
}, [
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
}, [
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
if (
|
|
153
|
-
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
}, [
|
|
159
|
-
const
|
|
160
|
-
return
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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)
|
|
171
173
|
e.readbackAndProcessParticles();
|
|
172
|
-
if (
|
|
173
|
-
const e =
|
|
174
|
-
e.elapsed +=
|
|
175
|
-
|
|
176
|
-
|
|
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++;
|
|
177
188
|
}
|
|
178
|
-
const
|
|
179
|
-
let
|
|
180
|
-
for (let e = 0; e <
|
|
181
|
-
const { system:
|
|
182
|
-
if (
|
|
183
|
-
const
|
|
184
|
-
if (!(!
|
|
185
|
-
for (let
|
|
186
|
-
const
|
|
187
|
-
let
|
|
188
|
-
const
|
|
189
|
-
if (
|
|
190
|
-
const
|
|
191
|
-
if (
|
|
192
|
-
const
|
|
193
|
-
|
|
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;
|
|
194
205
|
}
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
const
|
|
200
|
-
if (!(
|
|
201
|
-
if (
|
|
202
|
-
const
|
|
203
|
-
if (
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
const
|
|
207
|
-
|
|
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);
|
|
208
219
|
} else
|
|
209
|
-
|
|
220
|
+
tt.set(J, J, 1);
|
|
210
221
|
} else
|
|
211
|
-
|
|
212
|
-
|
|
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++;
|
|
213
224
|
}
|
|
214
225
|
}
|
|
215
226
|
}
|
|
216
|
-
|
|
217
|
-
const
|
|
218
|
-
if (
|
|
219
|
-
const e =
|
|
220
|
-
let
|
|
221
|
-
const
|
|
222
|
-
for (let
|
|
223
|
-
const { system:
|
|
224
|
-
if (!
|
|
225
|
-
const
|
|
226
|
-
if (
|
|
227
|
-
const
|
|
228
|
-
if (
|
|
229
|
-
const
|
|
230
|
-
const
|
|
231
|
-
for (let
|
|
232
|
-
const
|
|
233
|
-
if (
|
|
234
|
-
const
|
|
235
|
-
|
|
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;
|
|
236
247
|
return;
|
|
237
248
|
}
|
|
238
249
|
}
|
|
239
|
-
|
|
240
|
-
},
|
|
241
|
-
|
|
242
|
-
const f =
|
|
243
|
-
|
|
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]);
|
|
244
261
|
}
|
|
245
|
-
const
|
|
246
|
-
if (
|
|
247
|
-
let
|
|
248
|
-
const
|
|
249
|
-
for (let t = 0; t <=
|
|
250
|
-
let
|
|
251
|
-
t === 0 ? (
|
|
252
|
-
let
|
|
253
|
-
|
|
254
|
-
const
|
|
255
|
-
let
|
|
256
|
-
|
|
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);
|
|
257
274
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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;
|
|
261
290
|
}
|
|
262
291
|
}
|
|
263
|
-
const
|
|
264
|
-
if (
|
|
265
|
-
const
|
|
266
|
-
for (let
|
|
267
|
-
e[
|
|
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;
|
|
268
297
|
}
|
|
269
|
-
|
|
298
|
+
L.current = R, rt.setDrawRange(0, R), at.needsUpdate = !0, w.needsUpdate = !0;
|
|
270
299
|
}
|
|
271
|
-
}),
|
|
272
|
-
/* @__PURE__ */
|
|
300
|
+
}), Q ? /* @__PURE__ */ Ee(Ue, { children: [
|
|
301
|
+
/* @__PURE__ */ Nt(
|
|
273
302
|
"instancedMesh",
|
|
274
303
|
{
|
|
275
|
-
ref: (
|
|
276
|
-
|
|
304
|
+
ref: (c) => {
|
|
305
|
+
Dt.current = c, c && (c.count = 0, c.visible = !Bt);
|
|
277
306
|
},
|
|
278
|
-
args: [
|
|
307
|
+
args: [qt, r, jt],
|
|
279
308
|
frustumCulled: !1,
|
|
280
309
|
renderOrder: 100,
|
|
281
|
-
visible:
|
|
310
|
+
visible: g && !Bt
|
|
282
311
|
}
|
|
283
312
|
),
|
|
284
|
-
|
|
313
|
+
St && /* @__PURE__ */ Nt(
|
|
285
314
|
"mesh",
|
|
286
315
|
{
|
|
287
|
-
ref:
|
|
288
|
-
geometry:
|
|
289
|
-
material:
|
|
316
|
+
ref: gt,
|
|
317
|
+
geometry: rt,
|
|
318
|
+
material: O,
|
|
290
319
|
frustumCulled: !1,
|
|
291
320
|
renderOrder: 99,
|
|
292
|
-
visible:
|
|
321
|
+
visible: g
|
|
293
322
|
}
|
|
294
323
|
)
|
|
295
324
|
] }) : null;
|
|
296
325
|
}
|
|
297
|
-
const
|
|
326
|
+
const Ze = (
|
|
298
327
|
/* glsl */
|
|
299
328
|
`
|
|
300
329
|
attribute vec4 aColor;
|
|
@@ -304,7 +333,7 @@ void main() {
|
|
|
304
333
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
305
334
|
}
|
|
306
335
|
`
|
|
307
|
-
),
|
|
336
|
+
), ke = (
|
|
308
337
|
/* glsl */
|
|
309
338
|
`
|
|
310
339
|
varying vec4 vColor;
|
|
@@ -313,113 +342,113 @@ void main() {
|
|
|
313
342
|
}
|
|
314
343
|
`
|
|
315
344
|
);
|
|
316
|
-
function
|
|
317
|
-
positionRef:
|
|
318
|
-
duration:
|
|
319
|
-
width:
|
|
320
|
-
color:
|
|
321
|
-
maxPoints:
|
|
322
|
-
minDistance:
|
|
323
|
-
opacity:
|
|
324
|
-
blending:
|
|
325
|
-
visible:
|
|
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
|
|
326
355
|
}) {
|
|
327
|
-
const { camera:
|
|
328
|
-
positions: new Float32Array(
|
|
329
|
-
times: new Float32Array(
|
|
356
|
+
const { camera: st } = we(), it = $(null), Yt = $({
|
|
357
|
+
positions: new Float32Array(g * 3),
|
|
358
|
+
times: new Float32Array(g),
|
|
330
359
|
head: 0,
|
|
331
360
|
count: 0,
|
|
332
|
-
lastPos: new
|
|
361
|
+
lastPos: new i.Vector3(1 / 0, 1 / 0, 1 / 0),
|
|
333
362
|
elapsed: 0
|
|
334
|
-
}), { geometry:
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
const
|
|
338
|
-
|
|
339
|
-
const
|
|
340
|
-
for (let
|
|
341
|
-
const
|
|
342
|
-
|
|
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;
|
|
343
372
|
}
|
|
344
|
-
const
|
|
345
|
-
return
|
|
346
|
-
}, [
|
|
347
|
-
vertexShader:
|
|
348
|
-
fragmentShader:
|
|
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,
|
|
349
378
|
transparent: !0,
|
|
350
379
|
depthWrite: !1,
|
|
351
|
-
side:
|
|
352
|
-
blending:
|
|
353
|
-
}), [
|
|
354
|
-
return
|
|
355
|
-
if (!
|
|
356
|
-
const
|
|
357
|
-
if (
|
|
358
|
-
|
|
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);
|
|
359
388
|
return;
|
|
360
389
|
}
|
|
361
|
-
const
|
|
362
|
-
if (!
|
|
363
|
-
if (
|
|
364
|
-
const
|
|
365
|
-
|
|
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);
|
|
366
395
|
}
|
|
367
|
-
for (;
|
|
368
|
-
const
|
|
369
|
-
if (
|
|
370
|
-
|
|
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--;
|
|
371
400
|
else
|
|
372
401
|
break;
|
|
373
402
|
}
|
|
374
|
-
if (
|
|
375
|
-
|
|
403
|
+
if (r.count < 2) {
|
|
404
|
+
ft.setDrawRange(0, 0);
|
|
376
405
|
return;
|
|
377
406
|
}
|
|
378
|
-
const
|
|
379
|
-
let
|
|
380
|
-
const
|
|
381
|
-
for (let
|
|
382
|
-
const
|
|
383
|
-
if (
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
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
|
|
389
418
|
);
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
} else
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
),
|
|
398
|
-
let
|
|
399
|
-
|
|
400
|
-
const
|
|
401
|
-
|
|
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);
|
|
402
431
|
}
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
}), /* @__PURE__ */
|
|
432
|
+
const at = (rt - 1) * 6;
|
|
433
|
+
ft.setDrawRange(0, at), Vt.needsUpdate = !0, Dt.needsUpdate = !0;
|
|
434
|
+
}), /* @__PURE__ */ Nt(
|
|
406
435
|
"mesh",
|
|
407
436
|
{
|
|
408
|
-
ref:
|
|
409
|
-
geometry:
|
|
410
|
-
material:
|
|
437
|
+
ref: it,
|
|
438
|
+
geometry: ft,
|
|
439
|
+
material: It,
|
|
411
440
|
frustumCulled: !1,
|
|
412
441
|
renderOrder: 101,
|
|
413
|
-
visible:
|
|
442
|
+
visible: Q
|
|
414
443
|
}
|
|
415
444
|
);
|
|
416
445
|
}
|
|
417
446
|
export {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
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
|
|
425
454
|
};
|