hz-particles 1.3.0 → 1.4.1

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,4 +1,4 @@
1
- class ds {
1
+ class ms {
2
2
  constructor(t = {}) {
3
3
  this.config = t, this._posOut = [0, 0, 0], this._rotMatrix = null, this._invRotMatrix = null, this._cachedRotX = void 0, this._cachedRotY = void 0, this._cachedRotZ = void 0;
4
4
  }
@@ -245,32 +245,32 @@ class ds {
245
245
  }
246
246
  calculateVelocity(t, e, i, r, n) {
247
247
  const a = this.config.emissionPositionX || 0, o = this.config.emissionPositionY || 0, c = this.config.emissionPositionZ || 0, l = t - a, u = e - o, m = i - c, p = Math.sqrt(l * l + u * u + m * m);
248
- let d, b, M;
248
+ let d, b, w;
249
249
  if (p > 1e-4) {
250
- let C = !1;
250
+ let R = !1;
251
251
  if (this.config.emissionShape === "circle" && this.config.circleVelocityDirection === "tangential") {
252
- const _ = this.inverseRotation(l, u, m), L = Math.sqrt(_[0] * _[0] + _[1] * _[1]);
252
+ const x = this.inverseRotation(l, u, m), L = Math.sqrt(x[0] * x[0] + x[1] * x[1]);
253
253
  if (L > 1e-4) {
254
- const v = -_[1] / L, w = _[0] / L, R = this.applyRotation(v, w, 0);
255
- d = R[0], b = R[1], M = R[2], C = !0;
254
+ const P = -x[1] / L, T = x[0] / L, E = this.applyRotation(P, T, 0);
255
+ d = E[0], b = E[1], w = E[2], R = !0;
256
256
  }
257
257
  } else if (this.config.emissionShape === "cylinder" && this.config.cylinderVelocityDirection === "tangential") {
258
- const _ = this.inverseRotation(l, u, m), L = Math.sqrt(_[0] * _[0] + _[2] * _[2]);
258
+ const x = this.inverseRotation(l, u, m), L = Math.sqrt(x[0] * x[0] + x[2] * x[2]);
259
259
  if (L > 1e-4) {
260
- const v = -_[2] / L, w = _[0] / L, R = this.applyRotation(v, 0, w);
261
- d = R[0], b = R[1], M = R[2], C = !0;
260
+ const P = -x[2] / L, T = x[0] / L, E = this.applyRotation(P, 0, T);
261
+ d = E[0], b = E[1], w = E[2], R = !0;
262
262
  } else {
263
- const v = Math.random() * Math.PI * 2, w = this.applyRotation(Math.cos(v), 0, Math.sin(v));
264
- d = w[0], b = w[1], M = w[2], C = !0;
263
+ const P = Math.random() * Math.PI * 2, T = this.applyRotation(Math.cos(P), 0, Math.sin(P));
264
+ d = T[0], b = T[1], w = T[2], R = !0;
265
265
  }
266
266
  }
267
- C || (d = l / p, b = u / p, M = m / p);
267
+ R || (d = l / p, b = u / p, w = m / p);
268
268
  } else {
269
- const C = Math.random() * Math.PI * 2, _ = Math.acos(2 * Math.random() - 1);
270
- d = Math.sin(_) * Math.cos(C), b = Math.sin(_) * Math.sin(C), M = Math.cos(_);
269
+ const R = Math.random() * Math.PI * 2, x = Math.acos(2 * Math.random() - 1);
270
+ d = Math.sin(x) * Math.cos(R), b = Math.sin(x) * Math.sin(R), w = Math.cos(x);
271
271
  }
272
- let T;
273
- this.config.randomSpeed ? T = (this.config.minSpeed || 0) + Math.random() * ((this.config.maxSpeed || 1) - (this.config.minSpeed || 0)) : T = this.config.particleSpeed, r[n] = this.config.overrideXVelocity ? this.config.xVelocity : d * T, r[n + 1] = this.config.overrideYVelocity ? this.config.yVelocity : b * T, r[n + 2] = this.config.overrideZVelocity ? this.config.zVelocity : M * T, r[n + 3] = 0;
272
+ let M;
273
+ this.config.randomSpeed ? M = (this.config.minSpeed || 0) + Math.random() * ((this.config.maxSpeed || 1) - (this.config.minSpeed || 0)) : M = this.config.particleSpeed, r[n] = this.config.overrideXVelocity ? this.config.xVelocity : d * M, r[n + 1] = this.config.overrideYVelocity ? this.config.yVelocity : b * M, r[n + 2] = this.config.overrideZVelocity ? this.config.zVelocity : w * M, r[n + 3] = 0;
274
274
  }
275
275
  setParticleColor(t, e) {
276
276
  if (this.config.randomColorEnabled && this.config.randomColors.length > 0) {
@@ -283,7 +283,7 @@ class ds {
283
283
  t[e + 6] = 0, t[e + 7] = i + (Math.random() * 0.4 - 0.2) * i;
284
284
  }
285
285
  }
286
- const fs = `
286
+ const ys = `
287
287
  struct Uniforms {
288
288
  transform: mat4x4<f32>,
289
289
  cameraPosition: vec3<f32>,
@@ -299,7 +299,7 @@ const fs = `
299
299
  singleColor: vec3<f32>,
300
300
  rotation: f32,
301
301
  startColor: vec3<f32>,
302
- rotationMode: f32, // 0=fixed, 1=random, 2=towards velocity
302
+ rotationMode: f32, // 0=fixed, 1=random, 2=towards velocity, 3=oriented (world 3D plane), 4=cylindrical billboard
303
303
  endColor: vec3<f32>,
304
304
  minRotation: f32,
305
305
  maxRotation: f32,
@@ -336,6 +336,10 @@ const fs = `
336
336
  systemVelX: f32, // emitter/system world velocity (for velocity-aligned rotation
337
337
  systemVelY: f32, // of trail particles that move WITH the emitter, e.g. a ball —
338
338
  systemVelZ: f32, // their local velocity is ~0 so they need the system velocity)
339
+ orientX: f32, // rotationMode==3 (oriented): world-plane Euler angles (degrees)
340
+ orientY: f32,
341
+ orientZ: f32,
342
+ _pad2: f32, // keep struct size a multiple of 16 bytes (56 floats = 224 B)
339
343
  }
340
344
 
341
345
  @binding(0) @group(0) var<uniform> uniforms : Uniforms;
@@ -505,13 +509,51 @@ const fs = `
505
509
  let rotatedX = scaledX * cosTheta - scaledY * sinTheta;
506
510
  let rotatedY = scaledX * sinTheta + scaledY * cosTheta;
507
511
 
508
- let finalPosition = vec4<f32>(
509
- viewCenter.x + rotatedX * distanceScaleFactor * uniforms.aspectRatio * viewCenter.w,
510
- viewCenter.y + rotatedY * distanceScaleFactor * viewCenter.w,
511
- viewCenter.z,
512
- viewCenter.w
513
- );
514
-
512
+ var finalPosition: vec4<f32>;
513
+ if (appearance.rotationMode == 3.0) {
514
+ // Oriented 3D mode: the sprite lies in a WORLD-space plane defined by Euler angles (degrees),
515
+ // no longer camera-facing. rotatedX/rotatedY already carry aspect + the per-particle in-plane
516
+ // rotation (which acts as roll within the tilted plane). Build the plane's right/up basis by
517
+ // rotating the world axes by Rx, then Ry, then Rz, place the quad corner in world space, and
518
+ // project. worldHalf matches the billboard's apparent size when the plane faces the camera.
519
+ let ox = appearance.orientX * 0.01745329252;
520
+ let oy = appearance.orientY * 0.01745329252;
521
+ let oz = appearance.orientZ * 0.01745329252;
522
+ let cx = cos(ox); let sx = sin(ox);
523
+ let cy = cos(oy); let sy = sin(oy);
524
+ let cz = cos(oz); let sz = sin(oz);
525
+ var rgt = vec3<f32>(1.0, 0.0, 0.0);
526
+ var upv = vec3<f32>(0.0, 1.0, 0.0);
527
+ rgt = vec3<f32>(rgt.x, rgt.y * cx - rgt.z * sx, rgt.y * sx + rgt.z * cx);
528
+ upv = vec3<f32>(upv.x, upv.y * cx - upv.z * sx, upv.y * sx + upv.z * cx);
529
+ rgt = vec3<f32>(rgt.x * cy + rgt.z * sy, rgt.y, -rgt.x * sy + rgt.z * cy);
530
+ upv = vec3<f32>(upv.x * cy + upv.z * sy, upv.y, -upv.x * sy + upv.z * cy);
531
+ rgt = vec3<f32>(rgt.x * cz - rgt.y * sz, rgt.x * sz + rgt.y * cz, rgt.z);
532
+ upv = vec3<f32>(upv.x * cz - upv.y * sz, upv.x * sz + upv.y * cz, upv.z);
533
+ let worldHalf = baseScaleFactor * 10.0;
534
+ let worldCorner = center + (rgt * rotatedX + upv * rotatedY) * worldHalf;
535
+ finalPosition = uniforms.transform * vec4<f32>(worldCorner, 1.0);
536
+ } else if (appearance.rotationMode == 4.0) {
537
+ // Cylindrical (upright) billboard: faces the camera around the world Y axis ONLY and stays
538
+ // vertical. From the side it looks like a normal billboard; from straight above/below you see
539
+ // it edge-on (like a tree/grass sprite). right = horizontal axis ⟂ to the view; up = world up.
540
+ let worldUp = vec3<f32>(0.0, 1.0, 0.0);
541
+ let toCam = uniforms.cameraPosition - center;
542
+ var rgt = cross(worldUp, toCam);
543
+ let rl = length(rgt);
544
+ rgt = select(vec3<f32>(1.0, 0.0, 0.0), rgt / rl, rl > 0.0001);
545
+ let worldHalf = baseScaleFactor * 10.0;
546
+ let worldCorner = center + (rgt * rotatedX + worldUp * rotatedY) * worldHalf;
547
+ finalPosition = uniforms.transform * vec4<f32>(worldCorner, 1.0);
548
+ } else {
549
+ finalPosition = vec4<f32>(
550
+ viewCenter.x + rotatedX * distanceScaleFactor * uniforms.aspectRatio * viewCenter.w,
551
+ viewCenter.y + rotatedY * distanceScaleFactor * viewCenter.w,
552
+ viewCenter.z,
553
+ viewCenter.w
554
+ );
555
+ }
556
+
515
557
  output.position = finalPosition;
516
558
  output.color = finalColor;
517
559
  output.alpha = alpha;
@@ -663,7 +705,7 @@ const fs = `
663
705
  return vec4<f32>(input.color, alpha);
664
706
  }
665
707
  }
666
- `, ps = `
708
+ `, gs = `
667
709
  struct BloomUniforms {
668
710
  direction: vec2<f32>,
669
711
  resolution: vec2<f32>,
@@ -723,7 +765,7 @@ const fs = `
723
765
 
724
766
  return result / totalWeight * 1.1;
725
767
  }
726
- `, hs = `
768
+ `, bs = `
727
769
  struct BloomIntensityUniforms {
728
770
  intensity: f32,
729
771
  color: vec3<f32>,
@@ -769,7 +811,7 @@ const fs = `
769
811
 
770
812
  return vec4<f32>(originalColor.rgb + (mappedBloom * bloomUniforms.intensity), originalColor.a);
771
813
  }
772
- `, ms = `
814
+ `, Ss = `
773
815
  struct BloomIntensityUniforms {
774
816
  intensity: f32,
775
817
  color: vec3<f32>,
@@ -810,7 +852,7 @@ const fs = `
810
852
  fn fs_main(input: VertexOutput) -> @location(0) vec4<f32> {
811
853
  return textureSample(originalTexture, texSampler, input.texCoord);
812
854
  }
813
- `, ys = `
855
+ `, xs = `
814
856
  @binding(0) @group(0) var texSampler: sampler;
815
857
  @binding(1) @group(0) var originalTexture: texture_2d<f32>;
816
858
  @binding(2) @group(0) var blurredTexture: texture_2d<f32>;
@@ -842,7 +884,7 @@ const fs = `
842
884
  let c = textureSample(originalTexture, texSampler, input.texCoord);
843
885
  return vec4<f32>(aces(c.rgb), c.a);
844
886
  }
845
- `, gs = `
887
+ `, vs = `
846
888
  struct PhysicsUniforms {
847
889
  deltaTime: f32,
848
890
  particleSpeed: f32,
@@ -1052,7 +1094,7 @@ const fs = `
1052
1094
  particleBuffer[baseIndex + 1u] = newPos.y;
1053
1095
  particleBuffer[baseIndex + 2u] = newPos.z;
1054
1096
  }
1055
- `, bs = `
1097
+ `, Ps = `
1056
1098
  @group(0) @binding(0) var<storage, read> restData: array<f32>;
1057
1099
  @group(0) @binding(1) var<storage, read> jointWeightsData: array<f32>;
1058
1100
  @group(0) @binding(2) var<storage, read> jointIndicesData: array<u32>;
@@ -1109,7 +1151,7 @@ const fs = `
1109
1151
  outputData[outBase + 7u] = uv_v;
1110
1152
  }
1111
1153
  `;
1112
- class Ss {
1154
+ class _s {
1113
1155
  constructor(t, e = 1e4) {
1114
1156
  this.device = t, this.physicsSettings = {
1115
1157
  deltaTime: 0.016,
@@ -1198,7 +1240,7 @@ class Ss {
1198
1240
  }),
1199
1241
  compute: {
1200
1242
  module: this.device.createShaderModule({
1201
- code: gs
1243
+ code: vs
1202
1244
  }),
1203
1245
  entryPoint: "main"
1204
1246
  }
@@ -1404,7 +1446,7 @@ class Ss {
1404
1446
  t.enabled !== void 0 && (e.softBoundaryEnabled = t.enabled), t.strength !== void 0 && (e.softBoundaryStrength = t.strength), t.falloff !== void 0 && (e.softBoundaryFalloff = t.falloff);
1405
1447
  }
1406
1448
  }
1407
- class xs {
1449
+ class ws {
1408
1450
  constructor(t) {
1409
1451
  this.device = t, this.defaultTexture = null, this.createDefaultTexture();
1410
1452
  }
@@ -1443,7 +1485,7 @@ class xs {
1443
1485
  t && t.label !== "defaultParticleTexture" && t.destroy();
1444
1486
  }
1445
1487
  }
1446
- const bi = Object.freeze({
1488
+ const Pi = Object.freeze({
1447
1489
  sin: Math.sin,
1448
1490
  cos: Math.cos,
1449
1491
  abs: Math.abs,
@@ -1464,10 +1506,10 @@ const bi = Object.freeze({
1464
1506
  return s + (t - s) * e;
1465
1507
  },
1466
1508
  smoothstep(s, t, e) {
1467
- const i = bi.clamp((e - s) / (t - s), 0, 1);
1509
+ const i = Pi.clamp((e - s) / (t - s), 0, 1);
1468
1510
  return i * i * (3 - 2 * i);
1469
1511
  }
1470
- }), Ze = /* @__PURE__ */ new Set([
1512
+ }), $e = /* @__PURE__ */ new Set([
1471
1513
  "particleSize",
1472
1514
  "particleSpeed",
1473
1515
  "particleColor",
@@ -1483,7 +1525,7 @@ const bi = Object.freeze({
1483
1525
  "pulseFrequency",
1484
1526
  "bloomIntensity"
1485
1527
  ]);
1486
- class vs {
1528
+ class Bs {
1487
1529
  constructor(t) {
1488
1530
  this._collection = t, this._pd = null, this._vd = null, this._pi = 0, this._vi = 0;
1489
1531
  }
@@ -1561,9 +1603,9 @@ class vs {
1561
1603
  this._vd[this._vi + 2] = t, this._collection._dirty = !0;
1562
1604
  }
1563
1605
  }
1564
- class Ps {
1606
+ class Ms {
1565
1607
  constructor() {
1566
- this._proxy = new vs(this), this._pd = null, this._vd = null, this.count = 0, this._dirty = !1;
1608
+ this._proxy = new Bs(this), this._pd = null, this._vd = null, this.count = 0, this._dirty = !1;
1567
1609
  }
1568
1610
  _bind(t, e, i) {
1569
1611
  this._pd = t, this._vd = e, this.count = i, this._dirty = !1;
@@ -1572,14 +1614,14 @@ class Ps {
1572
1614
  return t < 0 || t >= this.count ? null : this._proxy._bind(this._pd, this._vd, t);
1573
1615
  }
1574
1616
  }
1575
- const _s = 1e6;
1576
- function Bs(s) {
1617
+ const Rs = 1e6;
1618
+ function Ts(s) {
1577
1619
  let t = 0;
1578
1620
  return s.replace(
1579
1621
  /\b(for|while)\s*\([^)]*\)\s*\{/g,
1580
1622
  (e) => {
1581
1623
  const i = `__lc${t++}`;
1582
- return `${e} if(++${i}>${_s})throw new Error("Loop limit exceeded");`;
1624
+ return `${e} if(++${i}>${Rs})throw new Error("Loop limit exceeded");`;
1583
1625
  }
1584
1626
  ).replace(
1585
1627
  /\b(for|while)\s*\([^)]*\)\s*\{/g,
@@ -1596,10 +1638,10 @@ function Bs(s) {
1596
1638
  }
1597
1639
  );
1598
1640
  }
1599
- const vt = /* @__PURE__ */ new Map();
1600
- for (const s of Ze)
1601
- vt.set(s.toLowerCase(), s);
1602
- function ws(s) {
1641
+ const wt = /* @__PURE__ */ new Map();
1642
+ for (const s of $e)
1643
+ wt.set(s.toLowerCase(), s);
1644
+ function Es(s) {
1603
1645
  const t = { value: !1 }, e = /* @__PURE__ */ new Set();
1604
1646
  return new Proxy(s, {
1605
1647
  get(r, n) {
@@ -1608,16 +1650,16 @@ function ws(s) {
1608
1650
  t.value = !1;
1609
1651
  };
1610
1652
  if (typeof n != "string") return;
1611
- if (Ze.has(n)) return r[n];
1612
- const a = vt.get(n.toLowerCase());
1653
+ if ($e.has(n)) return r[n];
1654
+ const a = wt.get(n.toLowerCase());
1613
1655
  if (a)
1614
1656
  return e.has(n) || (e.add(n), console.warn(`[ParticleScript] config.${n} → did you mean config.${a}?`)), r[a];
1615
1657
  },
1616
1658
  set(r, n, a) {
1617
1659
  if (typeof n != "string") return !0;
1618
1660
  let o = n;
1619
- if (!Ze.has(o)) {
1620
- const c = vt.get(o.toLowerCase());
1661
+ if (!$e.has(o)) {
1662
+ const c = wt.get(o.toLowerCase());
1621
1663
  if (c)
1622
1664
  e.has(n) || (e.add(n), console.warn(`[ParticleScript] config.${n} → did you mean config.${c}?`)), o = c;
1623
1665
  else
@@ -1627,14 +1669,14 @@ function ws(s) {
1627
1669
  }
1628
1670
  });
1629
1671
  }
1630
- class ri {
1672
+ class ui {
1631
1673
  /**
1632
1674
  * @param {string} source - User script source code
1633
1675
  * @param {object} config - ParticleSystem config (will be proxied)
1634
1676
  * @param {number} maxParticles - Max particle count for pre-allocation
1635
1677
  */
1636
1678
  constructor(t, e, i) {
1637
- this._particles = new Ps(), this._configProxy = ws(e), this._configSnapshot = null, this._fn = null, this._error = !1, this.compile(t);
1679
+ this._particles = new Ms(), this._configProxy = Es(e), this._configSnapshot = null, this._fn = null, this._error = !1, this.compile(t);
1638
1680
  }
1639
1681
  /**
1640
1682
  * Compile script source into a sandboxed function.
@@ -1650,7 +1692,7 @@ return function(__deltaTime, __time, __currentFrame, __totalFrames, __particles,
1650
1692
  var deltaTime = __deltaTime, time = __time;
1651
1693
  var currentFrame = __currentFrame, totalFrames = __totalFrames;
1652
1694
  var particles = __particles, config = __config, math = __math;
1653
- ${Bs(t)}
1695
+ ${Ts(t)}
1654
1696
  };`, r = new Function(i);
1655
1697
  this._fn = r();
1656
1698
  } catch (e) {
@@ -1672,7 +1714,7 @@ return function(__deltaTime, __time, __currentFrame, __totalFrames, __particles,
1672
1714
  if (!this._fn || this._error) return { configDirty: !1, particlesDirty: !1 };
1673
1715
  this._particles._bind(n, a, o), this._configProxy.__resetDirty();
1674
1716
  try {
1675
- this._fn(t, e, i, r, this._particles, this._configProxy, bi);
1717
+ this._fn(t, e, i, r, this._particles, this._configProxy, Pi);
1676
1718
  } catch (c) {
1677
1719
  console.warn("[ParticleScript] Runtime error:", c.message);
1678
1720
  }
@@ -1686,7 +1728,7 @@ return function(__deltaTime, __time, __currentFrame, __totalFrames, __particles,
1686
1728
  */
1687
1729
  snapshotConfig(t) {
1688
1730
  const e = {};
1689
- for (const i of Ze) {
1731
+ for (const i of $e) {
1690
1732
  const r = t[i];
1691
1733
  r !== void 0 && (e[i] = Array.isArray(r) ? [...r] : r);
1692
1734
  }
@@ -1697,7 +1739,7 @@ return function(__deltaTime, __time, __currentFrame, __totalFrames, __particles,
1697
1739
  */
1698
1740
  restoreConfig(t) {
1699
1741
  if (this._configSnapshot) {
1700
- for (const e of Ze)
1742
+ for (const e of $e)
1701
1743
  if (e in this._configSnapshot) {
1702
1744
  const i = this._configSnapshot[e];
1703
1745
  t[e] = Array.isArray(i) ? [...i] : i;
@@ -1711,7 +1753,7 @@ return function(__deltaTime, __time, __currentFrame, __totalFrames, __particles,
1711
1753
  this._fn = null, this._particles = null, this._configProxy = null, this._configSnapshot = null;
1712
1754
  }
1713
1755
  }
1714
- async function Rs(s) {
1756
+ async function Cs(s) {
1715
1757
  const t = new DataView(s);
1716
1758
  if (t.getUint32(0, !0) !== 1179937895)
1717
1759
  throw new Error("Invalid GLB file: incorrect magic number");
@@ -1721,12 +1763,12 @@ async function Rs(s) {
1721
1763
  const r = t.getUint32(8, !0);
1722
1764
  let n = 12, a = null, o = null;
1723
1765
  for (; n < r; ) {
1724
- const v = t.getUint32(n, !0), w = t.getUint32(n + 4, !0), R = s.slice(n + 8, n + 8 + v);
1725
- if (w === 1313821514) {
1726
- const X = new TextDecoder("utf-8").decode(R);
1727
- a = JSON.parse(X);
1728
- } else w === 5130562 && (o = R);
1729
- n += 8 + v;
1766
+ const P = t.getUint32(n, !0), T = t.getUint32(n + 4, !0), E = s.slice(n + 8, n + 8 + P);
1767
+ if (T === 1313821514) {
1768
+ const k = new TextDecoder("utf-8").decode(E);
1769
+ a = JSON.parse(k);
1770
+ } else T === 5130562 && (o = E);
1771
+ n += 8 + P;
1730
1772
  }
1731
1773
  if (!a)
1732
1774
  throw new Error("GLB file missing JSON chunk");
@@ -1738,47 +1780,47 @@ async function Rs(s) {
1738
1780
  const u = l.attributes.POSITION;
1739
1781
  if (u === void 0)
1740
1782
  throw new Error("Mesh primitive missing POSITION attribute");
1741
- const m = gt(a, o, u, 3, 5126);
1783
+ const m = xt(a, o, u, 3, 5126);
1742
1784
  let p;
1743
1785
  if (l.attributes.NORMAL !== void 0)
1744
- p = gt(a, o, l.attributes.NORMAL, 3, 5126);
1786
+ p = xt(a, o, l.attributes.NORMAL, 3, 5126);
1745
1787
  else {
1746
- const v = l.indices;
1747
- if (v === void 0)
1788
+ const P = l.indices;
1789
+ if (P === void 0)
1748
1790
  throw new Error("Cannot generate normals without indices");
1749
- const w = ni(a, o, v);
1750
- p = Ms(m, w);
1791
+ const T = di(a, o, P);
1792
+ p = As(m, T);
1751
1793
  }
1752
1794
  const d = l.indices;
1753
1795
  if (d === void 0)
1754
1796
  throw new Error("Mesh primitive missing indices");
1755
- const b = ni(a, o, d), M = m.length / 3, T = b.length;
1756
- let C = null;
1757
- l.attributes.TEXCOORD_0 !== void 0 && (C = gt(a, o, l.attributes.TEXCOORD_0, 2, 5126));
1758
- let _ = !1;
1797
+ const b = di(a, o, d), w = m.length / 3, M = b.length;
1798
+ let R = null;
1799
+ l.attributes.TEXCOORD_0 !== void 0 && (R = xt(a, o, l.attributes.TEXCOORD_0, 2, 5126));
1800
+ let x = !1;
1759
1801
  if (a.materials && a.materials.length > 0) {
1760
- const v = a.materials[0];
1761
- v.pbrMetallicRoughness && v.pbrMetallicRoughness.baseColorTexture !== void 0 && (_ = !0);
1802
+ const P = a.materials[0];
1803
+ P.pbrMetallicRoughness && P.pbrMetallicRoughness.baseColorTexture !== void 0 && (x = !0);
1762
1804
  }
1763
1805
  let L = null;
1764
1806
  if (a.skins && a.skins.length > 0)
1765
1807
  try {
1766
- L = Is(a, o, l), console.log("Animation data extracted:", L);
1767
- } catch (v) {
1768
- console.warn("Failed to extract animation data:", v);
1808
+ L = Fs(a, o, l), globalThis.__HZFX_DEBUG && console.log("Animation data extracted:", L);
1809
+ } catch (P) {
1810
+ console.warn("Failed to extract animation data:", P);
1769
1811
  }
1770
1812
  return {
1771
1813
  positions: m,
1772
1814
  normals: p,
1773
1815
  indices: b,
1774
- texCoords: C,
1775
- vertexCount: M,
1776
- indexCount: T,
1816
+ texCoords: R,
1817
+ vertexCount: w,
1818
+ indexCount: M,
1777
1819
  animationData: L,
1778
- hasBaseColorTexture: _
1820
+ hasBaseColorTexture: x
1779
1821
  };
1780
1822
  }
1781
- function gt(s, t, e, i, r) {
1823
+ function xt(s, t, e, i, r) {
1782
1824
  const n = s.accessors[e], o = {
1783
1825
  SCALAR: 1,
1784
1826
  VEC2: 2,
@@ -1794,7 +1836,7 @@ function gt(s, t, e, i, r) {
1794
1836
  p[d] = m.getFloat32(d * 4, !0);
1795
1837
  return p;
1796
1838
  }
1797
- function ni(s, t, e) {
1839
+ function di(s, t, e) {
1798
1840
  const i = s.accessors[e];
1799
1841
  if (i.type !== "SCALAR")
1800
1842
  throw new Error(`Indices accessor must be SCALAR, got ${i.type}`);
@@ -1812,7 +1854,7 @@ function ni(s, t, e) {
1812
1854
  } else
1813
1855
  throw new Error(`Unsupported index component type: ${i.componentType}`);
1814
1856
  }
1815
- function Ms(s, t) {
1857
+ function As(s, t) {
1816
1858
  const e = new Float32Array(s.length);
1817
1859
  for (let i = 0; i < t.length; i += 3) {
1818
1860
  const r = t[i] * 3, n = t[i + 1] * 3, a = t[i + 2] * 3, o = [s[r], s[r + 1], s[r + 2]], c = [s[n], s[n + 1], s[n + 2]], l = [s[a], s[a + 1], s[a + 2]], u = [c[0] - o[0], c[1] - o[1], c[2] - o[2]], m = [l[0] - o[0], l[1] - o[1], l[2] - o[2]], p = [
@@ -1824,7 +1866,7 @@ function Ms(s, t) {
1824
1866
  }
1825
1867
  return e;
1826
1868
  }
1827
- function Ts(s, t, e) {
1869
+ function Us(s, t, e) {
1828
1870
  const i = s.accessors[e];
1829
1871
  if (i.type !== "VEC4")
1830
1872
  throw new Error(`JOINTS_0 must be VEC4, got ${i.type}`);
@@ -1842,7 +1884,7 @@ function Ts(s, t, e) {
1842
1884
  } else
1843
1885
  throw new Error(`Unsupported JOINTS_0 component type: ${i.componentType}`);
1844
1886
  }
1845
- function Es(s, t, e) {
1887
+ function Is(s, t, e) {
1846
1888
  const i = s.accessors[e];
1847
1889
  if (i.type !== "VEC4")
1848
1890
  throw new Error(`WEIGHTS_0 must be VEC4, got ${i.type}`);
@@ -1860,7 +1902,7 @@ function Es(s, t, e) {
1860
1902
  } else
1861
1903
  throw new Error(`Unsupported WEIGHTS_0 component type: ${i.componentType}`);
1862
1904
  }
1863
- function Cs(s, t, e) {
1905
+ function zs(s, t, e) {
1864
1906
  const i = s.accessors[e];
1865
1907
  if (i.type !== "MAT4")
1866
1908
  throw new Error(`Expected MAT4, got ${i.type}`);
@@ -1871,7 +1913,7 @@ function Cs(s, t, e) {
1871
1913
  c[l] = o.getFloat32(l * 4, !0);
1872
1914
  return c;
1873
1915
  }
1874
- function As(s, t, e) {
1916
+ function Gs(s, t, e) {
1875
1917
  const i = s.accessors[e];
1876
1918
  if (i.type !== "SCALAR")
1877
1919
  throw new Error(`Expected SCALAR, got ${i.type}`);
@@ -1882,7 +1924,7 @@ function As(s, t, e) {
1882
1924
  c[l] = o.getFloat32(l * 4, !0);
1883
1925
  return c;
1884
1926
  }
1885
- function Us(s, t, e) {
1927
+ function Ds(s, t, e) {
1886
1928
  const i = s.accessors[e], n = { VEC3: 3, VEC4: 4 }[i.type];
1887
1929
  if (!n)
1888
1930
  throw new Error(`Expected VEC3 or VEC4, got ${i.type}`);
@@ -1893,8 +1935,8 @@ function Us(s, t, e) {
1893
1935
  u[m] = l.getFloat32(m * 4, !0);
1894
1936
  return u;
1895
1937
  }
1896
- function Is(s, t, e) {
1897
- const i = s.skins[0], r = i.joints, n = Cs(s, t, i.inverseBindMatrices), a = e.attributes.JOINTS_0 !== void 0 ? Ts(s, t, e.attributes.JOINTS_0) : null, o = e.attributes.WEIGHTS_0 !== void 0 ? Es(s, t, e.attributes.WEIGHTS_0) : null;
1938
+ function Fs(s, t, e) {
1939
+ const i = s.skins[0], r = i.joints, n = zs(s, t, i.inverseBindMatrices), a = e.attributes.JOINTS_0 !== void 0 ? Us(s, t, e.attributes.JOINTS_0) : null, o = e.attributes.WEIGHTS_0 !== void 0 ? Is(s, t, e.attributes.WEIGHTS_0) : null;
1898
1940
  if (!a || !o)
1899
1941
  throw new Error("Mesh missing JOINTS_0 or WEIGHTS_0 attributes");
1900
1942
  const c = s.nodes.map((u) => ({
@@ -1909,13 +1951,13 @@ function Is(s, t, e) {
1909
1951
  const m = [];
1910
1952
  let p = 0;
1911
1953
  for (const d of u.channels) {
1912
- const b = u.samplers[d.sampler], M = As(s, t, b.input), T = Us(s, t, b.output), C = M[M.length - 1];
1913
- C > p && (p = C), m.push({
1954
+ const b = u.samplers[d.sampler], w = Gs(s, t, b.input), M = Ds(s, t, b.output), R = w[w.length - 1];
1955
+ R > p && (p = R), m.push({
1914
1956
  targetNode: d.target.node,
1915
1957
  targetPath: d.target.path,
1916
1958
  interpolation: b.interpolation || "LINEAR",
1917
- timestamps: M,
1918
- values: T
1959
+ timestamps: w,
1960
+ values: M
1919
1961
  });
1920
1962
  }
1921
1963
  l.push({
@@ -1933,7 +1975,7 @@ function Is(s, t, e) {
1933
1975
  animations: l
1934
1976
  };
1935
1977
  }
1936
- async function ai(s) {
1978
+ async function fi(s) {
1937
1979
  const t = new DataView(s);
1938
1980
  if (t.getUint32(0, !0) !== 1179937895)
1939
1981
  throw new Error("Invalid GLB file: incorrect magic number");
@@ -1943,11 +1985,11 @@ async function ai(s) {
1943
1985
  const r = t.getUint32(8, !0);
1944
1986
  let n = 12, a = null, o = null;
1945
1987
  for (; n < r; ) {
1946
- const L = t.getUint32(n, !0), v = t.getUint32(n + 4, !0), w = s.slice(n + 8, n + 8 + L);
1947
- if (v === 1313821514) {
1948
- const V = new TextDecoder("utf-8").decode(w);
1949
- a = JSON.parse(V);
1950
- } else v === 5130562 && (o = w);
1988
+ const L = t.getUint32(n, !0), P = t.getUint32(n + 4, !0), T = s.slice(n + 8, n + 8 + L);
1989
+ if (P === 1313821514) {
1990
+ const F = new TextDecoder("utf-8").decode(T);
1991
+ a = JSON.parse(F);
1992
+ } else P === 5130562 && (o = T);
1951
1993
  n += 8 + L;
1952
1994
  }
1953
1995
  if (!a)
@@ -1968,96 +2010,52 @@ async function ai(s) {
1968
2010
  return null;
1969
2011
  if (!o)
1970
2012
  throw new Error("GLB file missing BIN chunk (required for embedded textures)");
1971
- const b = a.bufferViews[p.bufferView], M = b.byteOffset || 0, T = b.byteLength, C = o.slice(M, M + T);
1972
- return { imageBlob: new Blob([C], { type: d }), mimeType: d };
2013
+ const b = a.bufferViews[p.bufferView], w = b.byteOffset || 0, M = b.byteLength, R = o.slice(w, w + M);
2014
+ return { imageBlob: new Blob([R], { type: d }), mimeType: d };
1973
2015
  }
1974
- function oi(s, t, e) {
1975
- return [
1976
- s[0] + (t[0] - s[0]) * e,
1977
- s[1] + (t[1] - s[1]) * e,
1978
- s[2] + (t[2] - s[2]) * e
1979
- ];
2016
+ function Vs(s, t, e, i) {
2017
+ return i = i || [0, 0, 0], i[0] = s[0] + (t[0] - s[0]) * e, i[1] = s[1] + (t[1] - s[1]) * e, i[2] = s[2] + (t[2] - s[2]) * e, i;
1980
2018
  }
1981
- function li(s, t, e) {
1982
- let i = s[0] * t[0] + s[1] * t[1] + s[2] * t[2] + s[3] * t[3], r = t;
1983
- if (i < 0 && (i = -i, r = [-t[0], -t[1], -t[2], -t[3]]), i > 0.9995) {
1984
- const l = [
1985
- s[0] + (r[0] - s[0]) * e,
1986
- s[1] + (r[1] - s[1]) * e,
1987
- s[2] + (r[2] - s[2]) * e,
1988
- s[3] + (r[3] - s[3]) * e
1989
- ];
1990
- return Gs(l);
1991
- }
1992
- const n = Math.acos(i), a = Math.sin(n), o = Math.sin((1 - e) * n) / a, c = Math.sin(e * n) / a;
1993
- return [
1994
- s[0] * o + r[0] * c,
1995
- s[1] * o + r[1] * c,
1996
- s[2] * o + r[2] * c,
1997
- s[3] * o + r[3] * c
1998
- ];
1999
- }
2000
- function Gs(s) {
2001
- const t = Math.sqrt(s[0] * s[0] + s[1] * s[1] + s[2] * s[2] + s[3] * s[3]);
2002
- return t > 1e-4 ? [s[0] / t, s[1] / t, s[2] / t, s[3] / t] : [0, 0, 0, 1];
2019
+ function Os(s, t, e, i) {
2020
+ i = i || [0, 0, 0, 0];
2021
+ let r = s[0] * t[0] + s[1] * t[1] + s[2] * t[2] + s[3] * t[3], n = 1;
2022
+ if (r < 0 && (r = -r, n = -1), r > 0.9995) {
2023
+ i[0] = s[0] + (n * t[0] - s[0]) * e, i[1] = s[1] + (n * t[1] - s[1]) * e, i[2] = s[2] + (n * t[2] - s[2]) * e, i[3] = s[3] + (n * t[3] - s[3]) * e;
2024
+ const u = Math.sqrt(i[0] * i[0] + i[1] * i[1] + i[2] * i[2] + i[3] * i[3]);
2025
+ return u > 1e-4 ? (i[0] /= u, i[1] /= u, i[2] /= u, i[3] /= u) : (i[0] = 0, i[1] = 0, i[2] = 0, i[3] = 1), i;
2026
+ }
2027
+ const a = Math.acos(r), o = Math.sin(a), c = Math.sin((1 - e) * a) / o, l = Math.sin(e * a) / o;
2028
+ return i[0] = s[0] * c + n * t[0] * l, i[1] = s[1] * c + n * t[1] * l, i[2] = s[2] * c + n * t[2] * l, i[3] = s[3] * c + n * t[3] * l, i;
2003
2029
  }
2004
- function Ds(s) {
2005
- const t = s[0], e = s[1], i = s[2], r = s[3], n = t + t, a = e + e, o = i + i, c = t * n, l = t * a, u = t * o, m = e * a, p = e * o, d = i * o, b = r * n, M = r * a, T = r * o;
2006
- return new Float32Array([
2007
- 1 - (m + d),
2008
- l + T,
2009
- u - M,
2010
- 0,
2011
- l - T,
2012
- 1 - (c + d),
2013
- p + b,
2014
- 0,
2015
- u + M,
2016
- p - b,
2017
- 1 - (c + m),
2018
- 0,
2019
- 0,
2020
- 0,
2021
- 0,
2022
- 1
2023
- ]);
2030
+ function Ls(s, t) {
2031
+ const e = s[0], i = s[1], r = s[2], n = s[3], a = e + e, o = i + i, c = r + r, l = e * a, u = e * o, m = e * c, p = i * o, d = i * c, b = r * c, w = n * a, M = n * o, R = n * c, x = t || new Float32Array(16);
2032
+ return x[0] = 1 - (p + b), x[1] = u + R, x[2] = m - M, x[3] = 0, x[4] = u - R, x[5] = 1 - (l + b), x[6] = d + w, x[7] = 0, x[8] = m + M, x[9] = d - w, x[10] = 1 - (l + p), x[11] = 0, x[12] = 0, x[13] = 0, x[14] = 0, x[15] = 1, x;
2024
2033
  }
2025
- function zs(s, t, e) {
2026
- const i = Ds(t);
2027
- return new Float32Array([
2028
- i[0] * e[0],
2029
- i[1] * e[0],
2030
- i[2] * e[0],
2031
- 0,
2032
- i[4] * e[1],
2033
- i[5] * e[1],
2034
- i[6] * e[1],
2035
- 0,
2036
- i[8] * e[2],
2037
- i[9] * e[2],
2038
- i[10] * e[2],
2039
- 0,
2040
- s[0],
2041
- s[1],
2042
- s[2],
2043
- 1
2044
- ]);
2034
+ const Xs = new Float32Array(16);
2035
+ function ks(s, t, e, i) {
2036
+ const r = Ls(t, Xs), n = i || new Float32Array(16);
2037
+ return n[0] = r[0] * e[0], n[1] = r[1] * e[0], n[2] = r[2] * e[0], n[3] = 0, n[4] = r[4] * e[1], n[5] = r[5] * e[1], n[6] = r[6] * e[1], n[7] = 0, n[8] = r[8] * e[2], n[9] = r[9] * e[2], n[10] = r[10] * e[2], n[11] = 0, n[12] = s[0], n[13] = s[1], n[14] = s[2], n[15] = 1, n;
2045
2038
  }
2046
- function ci(s, t) {
2047
- const e = new Float32Array(16);
2048
- for (let i = 0; i < 4; i++)
2049
- for (let r = 0; r < 4; r++)
2050
- e[i * 4 + r] = s[0 + r] * t[i * 4 + 0] + s[4 + r] * t[i * 4 + 1] + s[8 + r] * t[i * 4 + 2] + s[12 + r] * t[i * 4 + 3];
2051
- return e;
2039
+ function pi(s, t, e) {
2040
+ const i = e || new Float32Array(16);
2041
+ for (let r = 0; r < 4; r++)
2042
+ for (let n = 0; n < 4; n++)
2043
+ i[r * 4 + n] = s[0 + n] * t[r * 4 + 0] + s[4 + n] * t[r * 4 + 1] + s[8 + n] * t[r * 4 + 2] + s[12 + n] * t[r * 4 + 3];
2044
+ return i;
2052
2045
  }
2053
- class Vs {
2046
+ class Ns {
2054
2047
  constructor(t) {
2055
2048
  this.joints = t.joints, this.inverseBindMatrices = t.inverseBindMatrices, this.jointWeights = t.jointWeights, this.jointIndices = t.jointIndices, this.nodes = t.nodes, this.animations = t.animations, this.restPositions = null, this.restNormals = null, this.currentAnimIndex = 0, this.currentTime = 0, this.playing = !0, this.speed = 1, this.loop = !0, this.jointLocalTransforms = new Array(this.nodes.length), this.jointGlobalTransforms = new Array(this.nodes.length), this.jointFinalMatrices = new Array(this.joints.length);
2056
2049
  for (let e = 0; e < this.nodes.length; e++)
2057
2050
  this.jointLocalTransforms[e] = new Float32Array(16), this.jointGlobalTransforms[e] = new Float32Array(16);
2058
2051
  for (let e = 0; e < this.joints.length; e++)
2059
2052
  this.jointFinalMatrices[e] = new Float32Array(16);
2060
- this.skinnedPositions = null, this.skinnedNormals = null, this._gpuSkinningReady = !1, this._buildTopologicalOrder(), console.log(`GLBAnimator initialized: ${this.joints.length} joints, ${this.animations.length} animations`);
2053
+ this.skinnedPositions = null, this.skinnedNormals = null, this._gpuSkinningReady = !1, this._sV0 = new Float64Array(4), this._sV1 = new Float64Array(4), this._scrT = new Float64Array(3), this._scrR = new Float64Array(4), this._scrS = new Float64Array(3), this._buildTopologicalOrder(), this._parentMap = new Array(this.nodes.length).fill(-1);
2054
+ for (let e = 0; e < this.nodes.length; e++)
2055
+ for (const i of this.nodes[e].children) this._parentMap[i] = e;
2056
+ this._invBindViews = new Array(this.joints.length);
2057
+ for (let e = 0; e < this.joints.length; e++)
2058
+ this._invBindViews[e] = this.inverseBindMatrices.subarray(e * 16, e * 16 + 16);
2061
2059
  }
2062
2060
  /**
2063
2061
  * Set the rest pose (original vertex data).
@@ -2112,7 +2110,7 @@ class Vs {
2112
2110
  this._gpuSkinningPipeline = t.createComputePipeline({
2113
2111
  layout: t.createPipelineLayout({ bindGroupLayouts: [o] }),
2114
2112
  compute: {
2115
- module: t.createShaderModule({ code: bs }),
2113
+ module: t.createShaderModule({ code: Ps }),
2116
2114
  entryPoint: "main"
2117
2115
  }
2118
2116
  }), this._gpuSkinningBindGroup = t.createBindGroup({
@@ -2124,7 +2122,7 @@ class Vs {
2124
2122
  { binding: 3, resource: { buffer: this._gpuJointMatricesBuffer } },
2125
2123
  { binding: 4, resource: { buffer: this._gpuOutputBuffer } }
2126
2124
  ]
2127
- }), this._gpuVertexCount = r, this._gpuSkinningReady = !0, console.log(`GPU skinning initialized: ${r} vertices, ${this.joints.length} joints`);
2125
+ }), this._gpuVertexCount = r, this._gpuSkinningReady = !0, globalThis.__HZFX_DEBUG && console.log(`GPU skinning initialized: ${r} vertices, ${this.joints.length} joints`);
2128
2126
  } catch (r) {
2129
2127
  console.warn("GPU skinning init failed, using CPU fallback:", r), this._gpuSkinningReady = !1;
2130
2128
  }
@@ -2194,31 +2192,32 @@ class Vs {
2194
2192
  /**
2195
2193
  * Sample a single channel at the given time.
2196
2194
  */
2197
- _sampleChannel(t, e) {
2198
- const { timestamps: i, values: r, interpolation: n, targetPath: a } = t;
2199
- if (e <= i[0])
2200
- return this._extractValue(r, 0, a);
2201
- if (e >= i[i.length - 1])
2202
- return this._extractValue(r, i.length - 1, a);
2203
- let o = 0, c = i.length - 1;
2204
- for (; c - o > 1; ) {
2205
- const b = Math.floor((o + c) / 2);
2206
- i[b] <= e ? o = b : c = b;
2195
+ _sampleChannel(t, e, i) {
2196
+ const { timestamps: r, values: n, interpolation: a, targetPath: o } = t;
2197
+ if (e <= r[0])
2198
+ return this._extractValue(n, 0, o, i);
2199
+ if (e >= r[r.length - 1])
2200
+ return this._extractValue(n, r.length - 1, o, i);
2201
+ let c = 0, l = r.length - 1;
2202
+ for (; l - c > 1; ) {
2203
+ const w = Math.floor((c + l) / 2);
2204
+ r[w] <= e ? c = w : l = w;
2207
2205
  }
2208
- const l = i[o], u = i[c], m = (e - l) / (u - l), p = this._extractValue(r, o, a), d = this._extractValue(r, c, a);
2209
- return n === "STEP" ? p : a === "rotation" ? li(p, d, m) : oi(p, d, m);
2206
+ const u = r[c], m = r[l], p = (e - u) / (m - u), d = this._extractValue(n, c, o, this._sV0), b = this._extractValue(n, l, o, this._sV1);
2207
+ return a === "STEP" ? (i[0] = d[0], i[1] = d[1], i[2] = d[2], o === "rotation" && (i[3] = d[3]), i) : o === "rotation" ? Os(d, b, p, i) : Vs(d, b, p, i);
2210
2208
  }
2211
2209
  /**
2212
2210
  * Extract value from values array at the given index.
2213
2211
  */
2214
- _extractValue(t, e, i) {
2212
+ _extractValue(t, e, i, r) {
2215
2213
  if (i === "rotation") {
2216
- const r = e * 4;
2217
- return [t[r], t[r + 1], t[r + 2], t[r + 3]];
2214
+ const n = e * 4;
2215
+ r[0] = t[n], r[1] = t[n + 1], r[2] = t[n + 2], r[3] = t[n + 3];
2218
2216
  } else {
2219
- const r = e * 3;
2220
- return [t[r], t[r + 1], t[r + 2]];
2217
+ const n = e * 3;
2218
+ r[0] = t[n], r[1] = t[n + 1], r[2] = t[n + 2];
2221
2219
  }
2220
+ return r;
2222
2221
  }
2223
2222
  /**
2224
2223
  * Compute local transforms for all nodes at the given time.
@@ -2229,28 +2228,21 @@ class Vs {
2229
2228
  const r = this.nodes[i];
2230
2229
  let n = r.translation, a = r.rotation, o = r.scale;
2231
2230
  for (const c of e.channels)
2232
- if (c.targetNode === i) {
2233
- const l = this._sampleChannel(c, t);
2234
- c.targetPath === "translation" ? n = l : c.targetPath === "rotation" ? a = l : c.targetPath === "scale" && (o = l);
2235
- }
2236
- this.jointLocalTransforms[i] = zs(n, a, o);
2231
+ c.targetNode === i && (c.targetPath === "translation" ? n = this._sampleChannel(c, t, this._scrT) : c.targetPath === "rotation" ? a = this._sampleChannel(c, t, this._scrR) : c.targetPath === "scale" && (o = this._sampleChannel(c, t, this._scrS)));
2232
+ ks(n, a, o, this.jointLocalTransforms[i]);
2237
2233
  }
2238
2234
  }
2239
2235
  /**
2240
2236
  * Compute global transforms by propagating parent transforms.
2241
2237
  */
2242
2238
  _computeGlobalTransforms() {
2243
- const t = new Array(this.nodes.length).fill(-1);
2244
- for (let e = 0; e < this.nodes.length; e++) {
2245
- const i = this.nodes[e];
2246
- for (const r of i.children)
2247
- t[r] = e;
2248
- }
2239
+ const t = this._parentMap;
2249
2240
  for (const e of this.topologicalOrder) {
2250
2241
  const i = t[e];
2251
- i === -1 ? this.jointGlobalTransforms[e] = this.jointLocalTransforms[e] : this.jointGlobalTransforms[e] = ci(
2242
+ i === -1 ? this.jointGlobalTransforms[e].set(this.jointLocalTransforms[e]) : pi(
2252
2243
  this.jointGlobalTransforms[i],
2253
- this.jointLocalTransforms[e]
2244
+ this.jointLocalTransforms[e],
2245
+ this.jointGlobalTransforms[e]
2254
2246
  );
2255
2247
  }
2256
2248
  }
@@ -2259,8 +2251,8 @@ class Vs {
2259
2251
  */
2260
2252
  _computeFinalMatrices() {
2261
2253
  for (let t = 0; t < this.joints.length; t++) {
2262
- const e = this.joints[t], i = this.jointGlobalTransforms[e], r = t * 16, n = this.inverseBindMatrices.slice(r, r + 16);
2263
- this.jointFinalMatrices[t] = ci(i, n);
2254
+ const e = this.joints[t], i = this.jointGlobalTransforms[e];
2255
+ pi(i, this._invBindViews[t], this.jointFinalMatrices[t]);
2264
2256
  }
2265
2257
  }
2266
2258
  /**
@@ -2270,20 +2262,20 @@ class Vs {
2270
2262
  _applySkinning() {
2271
2263
  const t = this.restPositions.length / 3, e = this.restPositions, i = this.restNormals, r = this.skinnedPositions, n = this.skinnedNormals, a = this.jointWeights, o = this.jointIndices, c = this.jointFinalMatrices;
2272
2264
  for (let l = 0; l < t; l++) {
2273
- const u = l * 3, m = l * 4, p = e[u], d = e[u + 1], b = e[u + 2], M = i[u], T = i[u + 1], C = i[u + 2];
2274
- let _ = 0, L = 0, v = 0, w = 0, R = 0, V = 0;
2275
- for (let j = 0; j < 4; j++) {
2276
- const k = a[m + j];
2277
- if (k === 0) continue;
2278
- const D = c[o[m + j]];
2279
- _ += (D[0] * p + D[4] * d + D[8] * b + D[12]) * k, L += (D[1] * p + D[5] * d + D[9] * b + D[13]) * k, v += (D[2] * p + D[6] * d + D[10] * b + D[14]) * k, w += (D[0] * M + D[4] * T + D[8] * C) * k, R += (D[1] * M + D[5] * T + D[9] * C) * k, V += (D[2] * M + D[6] * T + D[10] * C) * k;
2265
+ const u = l * 3, m = l * 4, p = e[u], d = e[u + 1], b = e[u + 2], w = i[u], M = i[u + 1], R = i[u + 2];
2266
+ let x = 0, L = 0, P = 0, T = 0, E = 0, F = 0;
2267
+ for (let Y = 0; Y < 4; Y++) {
2268
+ const N = a[m + Y];
2269
+ if (N === 0) continue;
2270
+ const G = c[o[m + Y]];
2271
+ x += (G[0] * p + G[4] * d + G[8] * b + G[12]) * N, L += (G[1] * p + G[5] * d + G[9] * b + G[13]) * N, P += (G[2] * p + G[6] * d + G[10] * b + G[14]) * N, T += (G[0] * w + G[4] * M + G[8] * R) * N, E += (G[1] * w + G[5] * M + G[9] * R) * N, F += (G[2] * w + G[6] * M + G[10] * R) * N;
2280
2272
  }
2281
- const X = Math.sqrt(w * w + R * R + V * V);
2282
- X > 1e-4 && (n[u] = w / X, n[u + 1] = R / X, n[u + 2] = V / X), r[u] = _, r[u + 1] = L, r[u + 2] = v;
2273
+ const k = Math.sqrt(T * T + E * E + F * F);
2274
+ k > 1e-4 && (n[u] = T / k, n[u + 1] = E / k, n[u + 2] = F / k), r[u] = x, r[u + 1] = L, r[u + 2] = P;
2283
2275
  }
2284
2276
  }
2285
2277
  }
2286
- class Fs {
2278
+ class js {
2287
2279
  constructor({ duration: t = 0, loop: e = !1, playbackRate: i = 1 } = {}) {
2288
2280
  this.currentTime = 0, this.duration = t, this.loop = e, this.playbackRate = i, this.paused = !1, this._justLooped = !1;
2289
2281
  }
@@ -2304,7 +2296,7 @@ class Fs {
2304
2296
  this.currentTime = Math.max(0, t || 0), this._justLooped = !1;
2305
2297
  }
2306
2298
  }
2307
- const ui = {
2299
+ const hi = {
2308
2300
  linear: (s) => s,
2309
2301
  easeInQuad: (s) => s * s,
2310
2302
  easeOutQuad: (s) => 1 - (1 - s) * (1 - s),
@@ -2323,26 +2315,26 @@ const ui = {
2323
2315
  return Math.pow(2, -10 * s) * Math.sin((s * 10 - 0.75) * t) + 1;
2324
2316
  }
2325
2317
  };
2326
- function Os(s, t, e, i) {
2318
+ function Ys(s, t, e, i) {
2327
2319
  const r = 3 * s, n = 3 * (e - s) - r, a = 1 - r - n, o = 3 * t, c = 3 * (i - t) - o, l = 1 - o - c, u = (d) => ((a * d + n) * d + r) * d, m = (d) => ((l * d + c) * d + o) * d, p = (d) => (3 * a * d + 2 * n) * d + r;
2328
2320
  return (d) => {
2329
2321
  if (d <= 0) return 0;
2330
2322
  if (d >= 1) return 1;
2331
2323
  let b = d;
2332
- for (let M = 0; M < 8; M++) {
2333
- const T = u(b) - d;
2334
- if (Math.abs(T) < 1e-5) break;
2335
- const C = p(b);
2336
- if (Math.abs(C) < 1e-6) break;
2337
- b -= T / C;
2324
+ for (let w = 0; w < 8; w++) {
2325
+ const M = u(b) - d;
2326
+ if (Math.abs(M) < 1e-5) break;
2327
+ const R = p(b);
2328
+ if (Math.abs(R) < 1e-6) break;
2329
+ b -= M / R;
2338
2330
  }
2339
2331
  return m(b);
2340
2332
  };
2341
2333
  }
2342
- function Si(s, t) {
2343
- return typeof s == "function" ? s(t) : Array.isArray(s) && s.length === 4 ? Os(s[0], s[1], s[2], s[3])(t) : (ui[s] || ui.linear)(t);
2334
+ function _i(s, t) {
2335
+ return typeof s == "function" ? s(t) : Array.isArray(s) && s.length === 4 ? Ys(s[0], s[1], s[2], s[3])(t) : (hi[s] || hi.linear)(t);
2344
2336
  }
2345
- function Ls(s, t) {
2337
+ function Hs(s, t) {
2346
2338
  if (!Array.isArray(s) || s.length === 0) return;
2347
2339
  if (s.length === 1 || t <= s[0].t) return s[0].v;
2348
2340
  const e = s[s.length - 1];
@@ -2351,34 +2343,41 @@ function Ls(s, t) {
2351
2343
  const r = s[i], n = s[i + 1];
2352
2344
  if (t >= r.t && t <= n.t) {
2353
2345
  const a = n.t - r.t, o = a > 0 ? (t - r.t) / a : 0;
2354
- return r.v + (n.v - r.v) * Si(r.ease, o);
2346
+ return r.v + (n.v - r.v) * _i(r.ease, o);
2355
2347
  }
2356
2348
  }
2357
2349
  return e.v;
2358
2350
  }
2359
- function Ns(s, t) {
2351
+ function qs(s, t, e) {
2360
2352
  if (!Array.isArray(s) || s.length === 0) return;
2361
- const e = (r, n, a) => [r[0] + (n[0] - r[0]) * a, r[1] + (n[1] - r[1]) * a, r[2] + (n[2] - r[2]) * a];
2362
- if (s.length === 1 || t <= s[0].t) return s[0].v.slice();
2363
- const i = s[s.length - 1];
2364
- if (t >= i.t) return i.v.slice();
2365
- for (let r = 0; r < s.length - 1; r++) {
2366
- const n = s[r], a = s[r + 1];
2367
- if (t >= n.t && t <= a.t) {
2368
- const o = a.t - n.t, c = o > 0 ? (t - n.t) / o : 0;
2369
- return e(n.v, a.v, Si(n.ease, c));
2353
+ const i = s.length, r = s[i - 1];
2354
+ let n, a, o;
2355
+ if (i === 1 || t <= s[0].t)
2356
+ n = a = s[0].v, o = 0;
2357
+ else if (t >= r.t)
2358
+ n = a = r.v, o = 0;
2359
+ else {
2360
+ n = a = r.v, o = 0;
2361
+ for (let m = 0; m < i - 1; m++) {
2362
+ const p = s[m], d = s[m + 1];
2363
+ if (t >= p.t && t <= d.t) {
2364
+ const b = d.t - p.t;
2365
+ n = p.v, a = d.v, o = _i(p.ease, b > 0 ? (t - p.t) / b : 0);
2366
+ break;
2367
+ }
2370
2368
  }
2371
2369
  }
2372
- return i.v.slice();
2370
+ const c = n[0] + (a[0] - n[0]) * o, l = n[1] + (a[1] - n[1]) * o, u = n[2] + (a[2] - n[2]) * o;
2371
+ return e ? (e[0] = c, e[1] = l, e[2] = u, e) : [c, l, u];
2373
2372
  }
2374
- const Xs = ["gravityStrength", "emissionRate", "damping", "particleSize", "particleSpeed"], ks = { square: 0, circle: 1, triangle: 2, diamond: 3, star: 4, hexagon: 5, ring: 6, heart: 7, cross: 8, spark: 9, leaf: 10, capsule: 11, crescent: 12, line: 13, "curved-line": 14 };
2375
- function di(s) {
2373
+ const Zs = ["gravityStrength", "emissionRate", "damping", "particleSize", "particleSpeed"], $s = { square: 0, circle: 1, triangle: 2, diamond: 3, star: 4, hexagon: 5, ring: 6, heart: 7, cross: 8, spark: 9, leaf: 10, capsule: 11, crescent: 12, line: 13, "curved-line": 14 };
2374
+ function mi(s) {
2376
2375
  const t = atob(s), e = new Uint8Array(t.length);
2377
2376
  for (let i = 0; i < t.length; i++)
2378
2377
  e[i] = t.charCodeAt(i);
2379
2378
  return e.buffer;
2380
2379
  }
2381
- class bt {
2380
+ class vt {
2382
2381
  constructor(t, e) {
2383
2382
  this.device = t, this.config = e, this.MAX_PARTICLES = e.maxParticles || 1e4, this.particleCount = e.particleCount || 100, this.activeParticles = 0, this.emitting = !1, this.currentEmissionTime = 0, this.destroyed = !1, this.particleData = new Float32Array(this.MAX_PARTICLES * 8), this.particleVelocities = new Float32Array(this.MAX_PARTICLES * 4), this.instanceBuffer = t.createBuffer({
2384
2383
  size: this.MAX_PARTICLES * 8 * 4,
@@ -2395,8 +2394,8 @@ class bt {
2395
2394
  usage: GPUBufferUsage.STORAGE | GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC,
2396
2395
  label: "particleTrailBuffer"
2397
2396
  }), this._trailResetData = new Float32Array(this.MAX_PARTICLES * 4), this.appearanceUniformBuffer = t.createBuffer({
2398
- size: 208,
2399
- // appearance uniforms + pulse + GLB rotation + system offset + sim rotation + noise distortion
2397
+ size: 224,
2398
+ // appearance uniforms + pulse + GLB rotation + system offset + sim rotation + noise distortion + orient3d
2400
2399
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
2401
2400
  label: "appearanceUniformBuffer"
2402
2401
  }), this.bloomIntensityBuffer = t.createBuffer({
@@ -2404,7 +2403,7 @@ class bt {
2404
2403
  // intensity (f32) + padding
2405
2404
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
2406
2405
  label: "systemBloomIntensityBuffer"
2407
- }), e.overrideXVelocity === void 0 && (e.overrideXVelocity = !1), e.overrideYVelocity === void 0 && (e.overrideYVelocity = !1), e.overrideZVelocity === void 0 && (e.overrideZVelocity = !1), e.xVelocity === void 0 && (e.xVelocity = 0), e.yVelocity === void 0 && (e.yVelocity = 0), e.zVelocity === void 0 && (e.zVelocity = 0), e.textureEnabled === void 0 && (e.textureEnabled = !1), e.glbModelEnabled === void 0 && (e.glbModelEnabled = !1), e.textureType === void 0 && (e.textureType = "image"), e.glbFileName === void 0 && (e.glbFileName = null), e.animationIndex === void 0 && (e.animationIndex = 0), e.animationSpeed === void 0 && (e.animationSpeed = 1), e.animationLoop === void 0 && (e.animationLoop = !0), e.useGlbTexture === void 0 && (e.useGlbTexture = !1), e.glbHasTexture === void 0 && (e.glbHasTexture = !1), e.particleShape === void 0 && (e.particleShape = "square"), e.particleShapeRotation !== void 0 && (e.rotation = (e.rotation || 0) + e.particleShapeRotation, delete e.particleShapeRotation), e.particleShapeRotationX === void 0 && (e.particleShapeRotationX = 0), e.particleShapeRotationY === void 0 && (e.particleShapeRotationY = 0), e.particleShapeRotationZ === void 0 && (e.particleShapeRotationZ = 0), e.particleColor === void 0 && (e.particleColor = [1, 1, 1]), e.startColor === void 0 && (e.startColor = [1, 0, 0]), e.endColor === void 0 && (e.endColor = [0, 0, 1]), e.fadeEnabled === void 0 && (e.fadeEnabled = !0), e.colorTransitionEnabled === void 0 && (e.colorTransitionEnabled = !1), e.randomColorEnabled === void 0 && (e.randomColorEnabled = !1), e.randomColors === void 0 && (e.randomColors = []), e.particleSize === void 0 && (e.particleSize = 0.1), e.particleSpeed === void 0 && (e.particleSpeed = 1), e.opacity === void 0 && (e.opacity = 1), e.aspectRatio === void 0 && (e.aspectRatio = 1), e.rotation === void 0 && (e.rotation = 0), e.rotationMode === void 0 && (e.rotationMode = "fixed"), e.minRotation === void 0 && (e.minRotation = 0), e.maxRotation === void 0 && (e.maxRotation = 90), e.randomSize === void 0 && (e.randomSize = !1), e.minSize === void 0 && (e.minSize = 0.05), e.maxSize === void 0 && (e.maxSize = 0.15), e.randomSpeed === void 0 && (e.randomSpeed = !1), e.minSpeed === void 0 && (e.minSpeed = 0.1), e.maxSpeed === void 0 && (e.maxSpeed = 1), e.fadeSizeEnabled === void 0 && (e.fadeSizeEnabled = !1), e.increaseSizeEnabled === void 0 && (e.increaseSizeEnabled = !1), e.sizeLifetimeSpeed === void 0 && (e.sizeLifetimeSpeed = 1), e.bloomEnabled === void 0 && (e.bloomEnabled = !0), e.bloomIntensity === void 0 && (e.bloomIntensity = 1), e.bloomColor === void 0 && (e.bloomColor = [1, 1, 1]), e.gravityEnabled === void 0 && (e.gravityEnabled = !1), e.gravityStrength === void 0 && (e.gravityStrength = 2), e.dampingEnabled === void 0 && (e.dampingEnabled = !1), e.dampingStrength === void 0 && (e.dampingStrength = 1), e.attractorEnabled === void 0 && (e.attractorEnabled = !1), e.attractorStrength === void 0 && (e.attractorStrength = 1), e.attractorPosition === void 0 && (e.attractorPosition = [0, 0, 0]), e.burstMode === void 0 && (e.burstMode = !1), e.emissionShape === void 0 && (e.emissionShape = "cube"), e.lifetime === void 0 && (e.lifetime = 5), e.emissionRate === void 0 && (e.emissionRate = 10), e.startAt === void 0 && (e.startAt = 0), e.emissionDuration === void 0 && (e.emissionDuration = 10), e.emissionDurationInfinite === void 0 && (e.emissionDurationInfinite = !1), e.emissionDuration > 300 && (e.emissionDurationInfinite = !0, e.emissionDuration = 10), e.outerLength === void 0 && (e.outerLength = e.cubeLength ?? 2), e.innerLength === void 0 && (e.innerLength = 0), e.outerRadius === void 0 && (e.outerRadius = 2), e.innerRadius === void 0 && (e.innerRadius = 0), e.squareSize === void 0 && (e.squareSize = 2), e.squareInnerSize === void 0 && (e.squareInnerSize = 0), e.circleInnerRadius === void 0 && (e.circleInnerRadius = 0), e.circleOuterRadius === void 0 && (e.circleOuterRadius = 2), e.circleVelocityDirection === void 0 && (e.circleVelocityDirection = "outward"), e.cylinderInnerRadius === void 0 && (e.cylinderInnerRadius = 0), e.cylinderOuterRadius === void 0 && (e.cylinderOuterRadius = 2), e.cylinderHeight === void 0 && (e.cylinderHeight = 4), e.cylinderVelocityDirection === void 0 && (e.cylinderVelocityDirection = "outward"), e.planeWidth === void 0 && (e.planeWidth = 2), e.planeDepth === void 0 && (e.planeDepth = 2), e.coneOuterRadius === void 0 && (e.coneOuterRadius = 2), e.coneInnerRadius === void 0 && (e.coneInnerRadius = 0), e.coneHeight === void 0 && (e.coneHeight = 4), e.torusMajorRadius === void 0 && (e.torusMajorRadius = 2), e.torusMinorRadius === void 0 && (e.torusMinorRadius = 0.5), e.lineLength === void 0 && (e.lineLength = 4), e.hemisphereOuterRadius === void 0 && (e.hemisphereOuterRadius = 2), e.hemisphereInnerRadius === void 0 && (e.hemisphereInnerRadius = 0), e.discRadius === void 0 && (e.discRadius = 2), e.annulusInnerRadius === void 0 && (e.annulusInnerRadius = 1), e.annulusOuterRadius === void 0 && (e.annulusOuterRadius = 2), e.capsuleRadius === void 0 && (e.capsuleRadius = 0.5), e.capsuleHeight === void 0 && (e.capsuleHeight = 4), e.arcStartAngle === void 0 && (e.arcStartAngle = 0), e.arcEndAngle === void 0 && (e.arcEndAngle = 180), e.arcInnerRadius === void 0 && (e.arcInnerRadius = 0), e.arcOuterRadius === void 0 && (e.arcOuterRadius = 2), e.spiralTurns === void 0 && (e.spiralTurns = 3), e.spiralRadiusStart === void 0 && (e.spiralRadiusStart = 0.5), e.spiralRadiusEnd === void 0 && (e.spiralRadiusEnd = 2), e.spiralHeight === void 0 && (e.spiralHeight = 4), e.frustumRadiusNear === void 0 && (e.frustumRadiusNear = 0.5), e.frustumRadiusFar === void 0 && (e.frustumRadiusFar = 2), e.frustumHeight === void 0 && (e.frustumHeight = 4), e.cubeSurfaceSize === void 0 && (e.cubeSurfaceSize = 2), e.sphereSurfaceRadius === void 0 && (e.sphereSurfaceRadius = 2), e.boxFrameSize === void 0 && (e.boxFrameSize = 2), e.polygonSides === void 0 && (e.polygonSides = 6), e.polygonRadius === void 0 && (e.polygonRadius = 2), e.emissionRotationX === void 0 && (e.emissionRotationX = 0), e.emissionRotationY === void 0 && (e.emissionRotationY = 0), e.emissionRotationZ === void 0 && (e.emissionRotationZ = 0), e.emissionPositionX === void 0 && (e.emissionPositionX = e.emissionTranslationX ?? 0), e.emissionPositionY === void 0 && (e.emissionPositionY = e.emissionTranslationY ?? 0), e.emissionPositionZ === void 0 && (e.emissionPositionZ = e.emissionTranslationZ ?? 0), e.pulseEnabled === void 0 && (e.pulseEnabled = !1), e.pulseAmplitude === void 0 && (e.pulseAmplitude = 0.5), e.pulseFrequency === void 0 && (e.pulseFrequency = 1), e.pulsePhaseRandom === void 0 && (e.pulsePhaseRandom = 0), e.pulseOpacity === void 0 && (e.pulseOpacity = !1), e.confinementEnabled === void 0 && (e.confinementEnabled = !1), e.confinementShape === void 0 && (e.confinementShape = "box"), e.confinementMode === void 0 && (e.confinementMode = "bounce"), e.confinementSpace === void 0 && (e.confinementSpace = "world"), e.confinementBoxHalfSize === void 0 && (e.confinementBoxHalfSize = [2, 2, 2]), e.confinementSphereRadius === void 0 && (e.confinementSphereRadius = 3), e.confinementRestitution === void 0 && (e.confinementRestitution = 0.8), e.confinementFriction === void 0 && (e.confinementFriction = 0.1), e.softBoundaryEnabled === void 0 && (e.softBoundaryEnabled = !1), e.softBoundaryStrength === void 0 && (e.softBoundaryStrength = 5), e.softBoundaryFalloff === void 0 && (e.softBoundaryFalloff = 0.5), e.depthWriteEnabled === void 0 && (e.depthWriteEnabled = !1), e.velocityStretchEnabled === void 0 && (e.velocityStretchEnabled = !1), e.velocityStretchFactor === void 0 && (e.velocityStretchFactor = 1), e.blendMode === void 0 && (e.blendMode = "normal"), e.noiseDistortEnabled === void 0 && (e.noiseDistortEnabled = !1), e.noiseTilingX === void 0 && (e.noiseTilingX = 3), e.noiseTilingY === void 0 && (e.noiseTilingY = 3), e.noiseSpeed === void 0 && (e.noiseSpeed = -1.5), e.noiseAmplitude === void 0 && (e.noiseAmplitude = 0.08), e.emissionTrailEnabled === void 0 && (e.emissionTrailEnabled = !1), e.emissionTrailDuration === void 0 && (e.emissionTrailDuration = 1), e.emissionTrailWidth === void 0 && (e.emissionTrailWidth = 0.3), e.emissionTrailMinDistance === void 0 && (e.emissionTrailMinDistance = 0.05), e.emissionTrailMaxPoints === void 0 && (e.emissionTrailMaxPoints = 256), e.emissionTrailSegments === void 0 && (e.emissionTrailSegments = 8), e.emissionTrailMode === void 0 && (e.emissionTrailMode = "ribbon"), e.emissionTrailShape === void 0 && (e.emissionTrailShape = "straight"), e.emissionTrailShapeAmplitude === void 0 && (e.emissionTrailShapeAmplitude = 0.1), e.emissionTrailShapeFrequency === void 0 && (e.emissionTrailShapeFrequency = 4), e.emissionTrailShapeSpeed === void 0 && (e.emissionTrailShapeSpeed = 0), e.shapeDisplay === void 0 && (e.shapeDisplay = !0), e.followSystemTranslation === void 0 && (e.followSystemTranslation = !0), e.followSystemId === void 0 && (e.followSystemId = null), this._newEmissions = [], this._emptyEmissions = [], this._pendingFollowEmissions = this._emptyEmissions, this.glbVertexBuffer = null, this.glbIndexBuffer = null, this.glbIndexCount = 0, this.glbIndexFormat = "uint16", this.glbMeshData = null, this.glbRawArrayBuffer = null, this.glbAnimator = null, this.glbAnimated = !1, this._glbInterleavedData = null, this._appearanceData = new Float32Array(52), this._bloomIntensityData = new Float32Array(16), this._simPosition = [0, 0, 0], this._simVelocity = [0, 0, 0], this._simRotMatrix = null, this._simRotX = 0, this._simRotZ = 0, this._emitSimRotY = 0, this.emitter = new ds(e), this.physics = new Ss(t, this.MAX_PARTICLES), this.textureManager = new xs(t), e.gravityEnabled && this.setGravity(e.gravityStrength || 0), e.dampingEnabled && this.physics.setDamping(e.dampingStrength || 0), e.attractorEnabled && e.attractorPosition && this.setAttractor(e.attractorStrength || 0, e.attractorPosition), e.confinementEnabled && this.setConfinement({
2406
+ }), e.overrideXVelocity === void 0 && (e.overrideXVelocity = !1), e.overrideYVelocity === void 0 && (e.overrideYVelocity = !1), e.overrideZVelocity === void 0 && (e.overrideZVelocity = !1), e.xVelocity === void 0 && (e.xVelocity = 0), e.yVelocity === void 0 && (e.yVelocity = 0), e.zVelocity === void 0 && (e.zVelocity = 0), e.textureEnabled === void 0 && (e.textureEnabled = !1), e.glbModelEnabled === void 0 && (e.glbModelEnabled = !1), e.textureType === void 0 && (e.textureType = "image"), e.glbFileName === void 0 && (e.glbFileName = null), e.animationIndex === void 0 && (e.animationIndex = 0), e.animationSpeed === void 0 && (e.animationSpeed = 1), e.animationLoop === void 0 && (e.animationLoop = !0), e.useGlbTexture === void 0 && (e.useGlbTexture = !1), e.glbHasTexture === void 0 && (e.glbHasTexture = !1), e.particleShape === void 0 && (e.particleShape = "square"), e.particleShapeRotation !== void 0 && (e.rotation = (e.rotation || 0) + e.particleShapeRotation, delete e.particleShapeRotation), e.particleShapeRotationX === void 0 && (e.particleShapeRotationX = 0), e.particleShapeRotationY === void 0 && (e.particleShapeRotationY = 0), e.particleShapeRotationZ === void 0 && (e.particleShapeRotationZ = 0), e.particleColor === void 0 && (e.particleColor = [1, 1, 1]), e.startColor === void 0 && (e.startColor = [1, 0, 0]), e.endColor === void 0 && (e.endColor = [0, 0, 1]), e.fadeEnabled === void 0 && (e.fadeEnabled = !0), e.colorTransitionEnabled === void 0 && (e.colorTransitionEnabled = !1), e.randomColorEnabled === void 0 && (e.randomColorEnabled = !1), e.randomColors === void 0 && (e.randomColors = []), e.particleSize === void 0 && (e.particleSize = 0.1), e.particleSpeed === void 0 && (e.particleSpeed = 1), e.opacity === void 0 && (e.opacity = 1), e.aspectRatio === void 0 && (e.aspectRatio = 1), e.rotation === void 0 && (e.rotation = 0), e.rotationMode === void 0 && (e.rotationMode = "fixed"), e.minRotation === void 0 && (e.minRotation = 0), e.maxRotation === void 0 && (e.maxRotation = 90), e.orientX === void 0 && (e.orientX = 0), e.orientY === void 0 && (e.orientY = 0), e.orientZ === void 0 && (e.orientZ = 0), e.randomSize === void 0 && (e.randomSize = !1), e.minSize === void 0 && (e.minSize = 0.05), e.maxSize === void 0 && (e.maxSize = 0.15), e.randomSpeed === void 0 && (e.randomSpeed = !1), e.minSpeed === void 0 && (e.minSpeed = 0.1), e.maxSpeed === void 0 && (e.maxSpeed = 1), e.fadeSizeEnabled === void 0 && (e.fadeSizeEnabled = !1), e.increaseSizeEnabled === void 0 && (e.increaseSizeEnabled = !1), e.sizeLifetimeSpeed === void 0 && (e.sizeLifetimeSpeed = 1), e.bloomEnabled === void 0 && (e.bloomEnabled = !0), e.bloomIntensity === void 0 && (e.bloomIntensity = 1), e.bloomColor === void 0 && (e.bloomColor = [1, 1, 1]), e.gravityEnabled === void 0 && (e.gravityEnabled = !1), e.gravityStrength === void 0 && (e.gravityStrength = 2), e.dampingEnabled === void 0 && (e.dampingEnabled = !1), e.dampingStrength === void 0 && (e.dampingStrength = 1), e.attractorEnabled === void 0 && (e.attractorEnabled = !1), e.attractorStrength === void 0 && (e.attractorStrength = 1), e.attractorPosition === void 0 && (e.attractorPosition = [0, 0, 0]), e.burstMode === void 0 && (e.burstMode = !1), e.emissionShape === void 0 && (e.emissionShape = "cube"), e.lifetime === void 0 && (e.lifetime = 5), e.emissionRate === void 0 && (e.emissionRate = 10), e.startAt === void 0 && (e.startAt = 0), e.emissionDuration === void 0 && (e.emissionDuration = 10), e.emissionDurationInfinite === void 0 && (e.emissionDurationInfinite = !1), e.emissionDuration > 300 && (e.emissionDurationInfinite = !0, e.emissionDuration = 10), e.outerLength === void 0 && (e.outerLength = e.cubeLength ?? 2), e.innerLength === void 0 && (e.innerLength = 0), e.outerRadius === void 0 && (e.outerRadius = 2), e.innerRadius === void 0 && (e.innerRadius = 0), e.squareSize === void 0 && (e.squareSize = 2), e.squareInnerSize === void 0 && (e.squareInnerSize = 0), e.circleInnerRadius === void 0 && (e.circleInnerRadius = 0), e.circleOuterRadius === void 0 && (e.circleOuterRadius = 2), e.circleVelocityDirection === void 0 && (e.circleVelocityDirection = "outward"), e.cylinderInnerRadius === void 0 && (e.cylinderInnerRadius = 0), e.cylinderOuterRadius === void 0 && (e.cylinderOuterRadius = 2), e.cylinderHeight === void 0 && (e.cylinderHeight = 4), e.cylinderVelocityDirection === void 0 && (e.cylinderVelocityDirection = "outward"), e.planeWidth === void 0 && (e.planeWidth = 2), e.planeDepth === void 0 && (e.planeDepth = 2), e.coneOuterRadius === void 0 && (e.coneOuterRadius = 2), e.coneInnerRadius === void 0 && (e.coneInnerRadius = 0), e.coneHeight === void 0 && (e.coneHeight = 4), e.torusMajorRadius === void 0 && (e.torusMajorRadius = 2), e.torusMinorRadius === void 0 && (e.torusMinorRadius = 0.5), e.lineLength === void 0 && (e.lineLength = 4), e.hemisphereOuterRadius === void 0 && (e.hemisphereOuterRadius = 2), e.hemisphereInnerRadius === void 0 && (e.hemisphereInnerRadius = 0), e.discRadius === void 0 && (e.discRadius = 2), e.annulusInnerRadius === void 0 && (e.annulusInnerRadius = 1), e.annulusOuterRadius === void 0 && (e.annulusOuterRadius = 2), e.capsuleRadius === void 0 && (e.capsuleRadius = 0.5), e.capsuleHeight === void 0 && (e.capsuleHeight = 4), e.arcStartAngle === void 0 && (e.arcStartAngle = 0), e.arcEndAngle === void 0 && (e.arcEndAngle = 180), e.arcInnerRadius === void 0 && (e.arcInnerRadius = 0), e.arcOuterRadius === void 0 && (e.arcOuterRadius = 2), e.spiralTurns === void 0 && (e.spiralTurns = 3), e.spiralRadiusStart === void 0 && (e.spiralRadiusStart = 0.5), e.spiralRadiusEnd === void 0 && (e.spiralRadiusEnd = 2), e.spiralHeight === void 0 && (e.spiralHeight = 4), e.frustumRadiusNear === void 0 && (e.frustumRadiusNear = 0.5), e.frustumRadiusFar === void 0 && (e.frustumRadiusFar = 2), e.frustumHeight === void 0 && (e.frustumHeight = 4), e.cubeSurfaceSize === void 0 && (e.cubeSurfaceSize = 2), e.sphereSurfaceRadius === void 0 && (e.sphereSurfaceRadius = 2), e.boxFrameSize === void 0 && (e.boxFrameSize = 2), e.polygonSides === void 0 && (e.polygonSides = 6), e.polygonRadius === void 0 && (e.polygonRadius = 2), e.emissionRotationX === void 0 && (e.emissionRotationX = 0), e.emissionRotationY === void 0 && (e.emissionRotationY = 0), e.emissionRotationZ === void 0 && (e.emissionRotationZ = 0), e.emissionPositionX === void 0 && (e.emissionPositionX = e.emissionTranslationX ?? 0), e.emissionPositionY === void 0 && (e.emissionPositionY = e.emissionTranslationY ?? 0), e.emissionPositionZ === void 0 && (e.emissionPositionZ = e.emissionTranslationZ ?? 0), e.pulseEnabled === void 0 && (e.pulseEnabled = !1), e.pulseAmplitude === void 0 && (e.pulseAmplitude = 0.5), e.pulseFrequency === void 0 && (e.pulseFrequency = 1), e.pulsePhaseRandom === void 0 && (e.pulsePhaseRandom = 0), e.pulseOpacity === void 0 && (e.pulseOpacity = !1), e.confinementEnabled === void 0 && (e.confinementEnabled = !1), e.confinementShape === void 0 && (e.confinementShape = "box"), e.confinementMode === void 0 && (e.confinementMode = "bounce"), e.confinementSpace === void 0 && (e.confinementSpace = "world"), e.confinementBoxHalfSize === void 0 && (e.confinementBoxHalfSize = [2, 2, 2]), e.confinementSphereRadius === void 0 && (e.confinementSphereRadius = 3), e.confinementRestitution === void 0 && (e.confinementRestitution = 0.8), e.confinementFriction === void 0 && (e.confinementFriction = 0.1), e.softBoundaryEnabled === void 0 && (e.softBoundaryEnabled = !1), e.softBoundaryStrength === void 0 && (e.softBoundaryStrength = 5), e.softBoundaryFalloff === void 0 && (e.softBoundaryFalloff = 0.5), e.depthWriteEnabled === void 0 && (e.depthWriteEnabled = !1), e.velocityStretchEnabled === void 0 && (e.velocityStretchEnabled = !1), e.velocityStretchFactor === void 0 && (e.velocityStretchFactor = 1), e.blendMode === void 0 && (e.blendMode = "normal"), e.noiseDistortEnabled === void 0 && (e.noiseDistortEnabled = !1), e.noiseTilingX === void 0 && (e.noiseTilingX = 3), e.noiseTilingY === void 0 && (e.noiseTilingY = 3), e.noiseSpeed === void 0 && (e.noiseSpeed = -1.5), e.noiseAmplitude === void 0 && (e.noiseAmplitude = 0.08), e.emissionTrailEnabled === void 0 && (e.emissionTrailEnabled = !1), e.emissionTrailDuration === void 0 && (e.emissionTrailDuration = 1), e.emissionTrailWidth === void 0 && (e.emissionTrailWidth = 0.3), e.emissionTrailMinDistance === void 0 && (e.emissionTrailMinDistance = 0.05), e.emissionTrailMaxPoints === void 0 && (e.emissionTrailMaxPoints = 256), e.emissionTrailSegments === void 0 && (e.emissionTrailSegments = 8), e.emissionTrailMode === void 0 && (e.emissionTrailMode = "ribbon"), e.emissionTrailShape === void 0 && (e.emissionTrailShape = "straight"), e.emissionTrailShapeAmplitude === void 0 && (e.emissionTrailShapeAmplitude = 0.1), e.emissionTrailShapeFrequency === void 0 && (e.emissionTrailShapeFrequency = 4), e.emissionTrailShapeSpeed === void 0 && (e.emissionTrailShapeSpeed = 0), e.shapeDisplay === void 0 && (e.shapeDisplay = !0), e.followSystemTranslation === void 0 && (e.followSystemTranslation = !0), e.followSystemId === void 0 && (e.followSystemId = null), this._newEmissions = [], this._emptyEmissions = [], this._pendingFollowEmissions = this._emptyEmissions, this.glbVertexBuffer = null, this.glbIndexBuffer = null, this.glbIndexCount = 0, this.glbIndexFormat = "uint16", this.glbMeshData = null, this.glbRawArrayBuffer = null, this.glbAnimator = null, this.glbAnimated = !1, this._glbInterleavedData = null, this._appearanceData = new Float32Array(56), this._bloomIntensityData = new Float32Array(16), this._simPosition = [0, 0, 0], this._simVelocity = [0, 0, 0], this._simRotMatrix = null, this._simRotX = 0, this._simRotZ = 0, this._emitSimRotY = 0, this.emitter = new ms(e), this.physics = new _s(t, this.MAX_PARTICLES), this.textureManager = new ws(t), e.gravityEnabled && this.setGravity(e.gravityStrength || 0), e.dampingEnabled && this.physics.setDamping(e.dampingStrength || 0), e.attractorEnabled && e.attractorPosition && this.setAttractor(e.attractorStrength || 0, e.attractorPosition), e.confinementEnabled && this.setConfinement({
2408
2407
  enabled: !0,
2409
2408
  shape: e.confinementShape,
2410
2409
  mode: e.confinementMode,
@@ -2417,7 +2416,7 @@ class bt {
2417
2416
  enabled: !0,
2418
2417
  strength: e.softBoundaryStrength,
2419
2418
  falloff: e.softBoundaryFalloff
2420
- }), this.particleTexture = this.textureManager.getDefaultTexture(), this.updateBloomIntensity(), this.updateAppearanceUniform(), this.frameCount = 0, this.shouldReset = !1, this._scriptParticleData = new Float32Array(this.MAX_PARTICLES * 8), this._scriptVelocityData = new Float32Array(this.MAX_PARTICLES * 4), this._scriptReadbackPending = !1, this._scriptReadbackReady = !1, this._scriptFrame = 0, this._scriptTime = 0, this._scriptConfigRestored = !1, this._particleScript = null, e.script && (this._particleScript = new ri(e.script, e, this.MAX_PARTICLES)), this.initComputePipeline(t);
2419
+ }), this.particleTexture = this.textureManager.getDefaultTexture(), this.updateBloomIntensity(), this.updateAppearanceUniform(), this.frameCount = 0, this.shouldReset = !1, this._scriptParticleData = new Float32Array(this.MAX_PARTICLES * 8), this._scriptVelocityData = new Float32Array(this.MAX_PARTICLES * 4), this._scriptReadbackPending = !1, this._scriptReadbackReady = !1, this._scriptFrame = 0, this._scriptTime = 0, this._scriptConfigRestored = !1, this._particleScript = null, e.script && (this._particleScript = new ui(e.script, e, this.MAX_PARTICLES)), this.initComputePipeline(t);
2421
2420
  }
2422
2421
  async initComputePipeline(t) {
2423
2422
  this.computeReady = await this.physics.initComputePipeline(this.instanceBuffer, this.velocityBuffer, this.trailBuffer);
@@ -2427,7 +2426,7 @@ class bt {
2427
2426
  * @param {string|null} source - Script source code, or null to disable
2428
2427
  */
2429
2428
  setScript(t) {
2430
- this._particleScript && (this._particleScript.destroy(), this._particleScript = null), this._scriptReadbackPending = !1, this._scriptReadbackReady = !1, this._scriptFrame = 0, this._scriptTime = 0, this._scriptConfigRestored = !1, t ? (this.config.script = t, this._particleScript = new ri(t, this.config, this.MAX_PARTICLES), this._particleScript.snapshotConfig(this.config)) : delete this.config.script;
2429
+ this._particleScript && (this._particleScript.destroy(), this._particleScript = null), this._scriptReadbackPending = !1, this._scriptReadbackReady = !1, this._scriptFrame = 0, this._scriptTime = 0, this._scriptConfigRestored = !1, t ? (this.config.script = t, this._particleScript = new ui(t, this.config, this.MAX_PARTICLES), this._particleScript.snapshotConfig(this.config)) : delete this.config.script;
2431
2430
  }
2432
2431
  async setTexture(t) {
2433
2432
  this.destroyed || (this.textureManager.destroyTexture(this.particleTexture), this.particleTexture = await this.textureManager.loadTexture(t), this.config.textureEnabled = !0, this.updateAppearanceUniform(), this.updateBuffers());
@@ -2438,7 +2437,7 @@ class bt {
2438
2437
  async setGLBModel(t) {
2439
2438
  try {
2440
2439
  this.glbRawArrayBuffer = t;
2441
- const e = await Rs(t);
2440
+ const e = await Cs(t);
2442
2441
  this.glbMeshData = e, this.config.glbHasTexture = e.hasBaseColorTexture || !1;
2443
2442
  const i = new Float32Array(e.vertexCount * 8);
2444
2443
  for (let r = 0; r < e.vertexCount; r++) {
@@ -2454,16 +2453,16 @@ class bt {
2454
2453
  usage: GPUBufferUsage.INDEX | GPUBufferUsage.COPY_DST,
2455
2454
  label: "glbIndexBuffer"
2456
2455
  }), this.device.queue.writeBuffer(this.glbIndexBuffer, 0, e.indices), this.glbIndexCount = e.indexCount, this.glbIndexFormat = e.indices instanceof Uint32Array ? "uint32" : "uint16", this.config.glbModelEnabled = !0, this.config.textureType = "glb", e.animationData) {
2457
- this.glbAnimator = new Vs(e.animationData), this.glbAnimator.setRestPose(e.positions, e.normals), this.glbAnimated = !0, this.config.glbAnimated = !0, this.glbAnimator.loop = this.config.animationLoop, this._glbInterleavedData = new Float32Array(e.vertexCount * 8);
2456
+ this.glbAnimator = new Ns(e.animationData), this.glbAnimator.setRestPose(e.positions, e.normals), this.glbAnimated = !0, this.config.glbAnimated = !0, this.glbAnimator.loop = this.config.animationLoop, this._glbInterleavedData = new Float32Array(e.vertexCount * 8);
2458
2457
  try {
2459
2458
  await this.glbAnimator.initGPUSkinning(this.device, this.glbVertexBuffer, e.texCoords);
2460
2459
  } catch (r) {
2461
2460
  console.warn("GPU skinning init failed, using CPU fallback:", r);
2462
2461
  }
2463
- console.log(`GLB animated model loaded: ${e.animationData.animations.length} animations`);
2462
+ globalThis.__HZFX_DEBUG && console.log(`GLB animated model loaded: ${e.animationData.animations.length} animations`);
2464
2463
  } else
2465
2464
  this.glbAnimator = null, this.glbAnimated = !1, this.config.glbAnimated = !1, this._glbInterleavedData = null;
2466
- console.log(`GLB model loaded: ${e.vertexCount} vertices, ${e.indexCount} indices`);
2465
+ globalThis.__HZFX_DEBUG && console.log(`GLB model loaded: ${e.vertexCount} vertices, ${e.indexCount} indices`);
2467
2466
  } catch (e) {
2468
2467
  throw console.error("Failed to load GLB model:", e), e;
2469
2468
  }
@@ -2515,11 +2514,11 @@ class bt {
2515
2514
  updateAppearanceUniform() {
2516
2515
  if (this.destroyed) return;
2517
2516
  let t = 0;
2518
- this.config.rotationMode === "random" ? t = 1 : this.config.rotationMode === "velocity" && (t = 2);
2519
- const e = ks[this.config.particleShape] ?? 0, i = this._appearanceData;
2517
+ this.config.rotationMode === "random" ? t = 1 : this.config.rotationMode === "velocity" ? t = 2 : this.config.rotationMode === "oriented" ? t = 3 : this.config.rotationMode === "cylindrical" && (t = 4);
2518
+ const e = $s[this.config.particleShape] ?? 0, i = this._appearanceData;
2520
2519
  i[0] = this.config.fadeEnabled ? 1 : 0, i[1] = this.config.randomColorEnabled ? 2 : this.config.colorTransitionEnabled ? 1 : 0, i[2] = this.config.particleSize, i[3] = this.config.textureEnabled ? 1 : 0, i[4] = this.config.particleColor[0], i[5] = this.config.particleColor[1], i[6] = this.config.particleColor[2], i[7] = this.config.rotation || 0, i[8] = this.config.startColor[0], i[9] = this.config.startColor[1], i[10] = this.config.startColor[2], i[11] = t, i[12] = this.config.endColor[0], i[13] = this.config.endColor[1], i[14] = this.config.endColor[2], i[15] = this.config.minRotation || 0, i[16] = this.config.maxRotation || 90, i[17] = this.config.aspectRatio || 1, i[18] = this.config.randomSize ? 1 : 0, i[19] = this.config.minSize || 0.1, i[20] = this.config.maxSize || 0.5, i[21] = this.config.fadeSizeEnabled ? 1 : 0, i[22] = this.config.opacity !== void 0 ? this.config.opacity : 1, i[23] = this.config.increaseSizeEnabled ? 1 : 0, i[24] = this.config.sizeLifetimeSpeed ?? 1, i[25] = e, i[26] = 0, i[27] = this.config.pulseEnabled ? 1 : 0, i[28] = this.config.pulseAmplitude ?? 0.5, i[29] = this.config.pulseFrequency ?? 1, i[30] = this.config.pulsePhaseRandom ?? 0, i[31] = this.config.pulseOpacity ? 1 : 0, i[32] = this.config.particleShapeRotationX || 0, i[33] = this.config.particleShapeRotationY || 0, i[34] = this.config.particleShapeRotationZ || 0, i[35] = 0;
2521
2520
  const r = this.config.followSystemTranslation ?? !0;
2522
- i[36] = r ? this._simPosition[0] : 0, i[37] = r ? this._simPosition[1] : 0, i[38] = r ? this._simPosition[2] : 0, i[39] = 0, i[40] = this._simRotX, i[41] = this._simRotZ, i[42] = this.config.velocityStretchEnabled ? 1 : 0, i[43] = this.config.velocityStretchFactor ?? 1, i[44] = this.config.noiseDistortEnabled ? 1 : 0, i[45] = this.config.noiseTilingX ?? 3, i[46] = this.config.noiseTilingY ?? 3, i[47] = this.config.noiseSpeed ?? -1.5, i[48] = this.config.noiseAmplitude ?? 0.08, i[49] = r ? this._simVelocity[0] : 0, i[50] = r ? this._simVelocity[1] : 0, i[51] = r ? this._simVelocity[2] : 0, this.device.queue.writeBuffer(this.appearanceUniformBuffer, 0, i);
2521
+ i[36] = r ? this._simPosition[0] : 0, i[37] = r ? this._simPosition[1] : 0, i[38] = r ? this._simPosition[2] : 0, i[39] = 0, i[40] = this._simRotX, i[41] = this._simRotZ, i[42] = this.config.velocityStretchEnabled ? 1 : 0, i[43] = this.config.velocityStretchFactor ?? 1, i[44] = this.config.noiseDistortEnabled ? 1 : 0, i[45] = this.config.noiseTilingX ?? 3, i[46] = this.config.noiseTilingY ?? 3, i[47] = this.config.noiseSpeed ?? -1.5, i[48] = this.config.noiseAmplitude ?? 0.08, i[49] = r ? this._simVelocity[0] : 0, i[50] = r ? this._simVelocity[1] : 0, i[51] = r ? this._simVelocity[2] : 0, i[52] = this.config.orientX ?? 0, i[53] = this.config.orientY ?? 0, i[54] = this.config.orientZ ?? 0, i[55] = 0, this.device.queue.writeBuffer(this.appearanceUniformBuffer, 0, i);
2523
2522
  }
2524
2523
  updateBloomIntensity() {
2525
2524
  const t = this._bloomIntensityData;
@@ -2830,16 +2829,16 @@ class bt {
2830
2829
  this.physics.setSoftBoundary(t);
2831
2830
  }
2832
2831
  }
2833
- class js {
2832
+ class Ws {
2834
2833
  constructor(t) {
2835
- this.device = t, this.particleSystems = [], this.activeSystemIndex = 0, this.systemCounter = 1, this.onSystemCreated = null, this.loop = void 0, this.clock = new Fs({ loop: !!this.loop }), this.ready = !0;
2834
+ this.device = t, this.particleSystems = [], this.activeSystemIndex = 0, this.systemCounter = 1, this.onSystemCreated = null, this.loop = void 0, this.clock = new js({ loop: !!this.loop }), this.ready = !0;
2836
2835
  }
2837
2836
  createParticleSystem(t = {}) {
2838
2837
  const e = this.systemCounter++, i = t.name || `System ${e + 1}`, r = {
2839
2838
  ...t,
2840
2839
  name: i,
2841
2840
  id: e
2842
- }, n = new bt(this.device, r);
2841
+ }, n = new vt(this.device, r);
2843
2842
  return this.particleSystems.push({
2844
2843
  system: n,
2845
2844
  config: r
@@ -2903,16 +2902,16 @@ class js {
2903
2902
  for (const { system: o, config: c } of this.particleSystems) {
2904
2903
  const l = c.keyframes;
2905
2904
  if (!(!l || c.keyframesEnabled === !1)) {
2906
- for (const u of Xs) {
2905
+ for (const u of Zs) {
2907
2906
  const m = l[u];
2908
2907
  if (m && m.length) {
2909
- const p = Ls(m, a);
2908
+ const p = Hs(m, a);
2910
2909
  p !== void 0 && (c[u] = p);
2911
2910
  }
2912
2911
  }
2913
2912
  if (l.particleColor && l.particleColor.length) {
2914
- const u = Ns(l.particleColor, a);
2915
- u && (c.particleColor = u, o.updateAppearanceUniform());
2913
+ const u = c.particleColor, m = u && typeof u.length == "number" && u.length >= 3 ? u : void 0, p = qs(l.particleColor, a, m);
2914
+ p && (c.particleColor = p, o.updateAppearanceUniform());
2916
2915
  }
2917
2916
  }
2918
2917
  }
@@ -2963,7 +2962,7 @@ class js {
2963
2962
  const n = this.systemCounter++, a = {
2964
2963
  ...r,
2965
2964
  id: n
2966
- }, o = new bt(this.device, a);
2965
+ }, o = new vt(this.device, a);
2967
2966
  this.particleSystems.push({
2968
2967
  system: o,
2969
2968
  config: a
@@ -2981,7 +2980,7 @@ class js {
2981
2980
  try {
2982
2981
  let a = null;
2983
2982
  if (n.glbModelData)
2984
- a = di(n.glbModelData);
2983
+ a = mi(n.glbModelData);
2985
2984
  else if (n.glbFileName) {
2986
2985
  const o = await fetch(`/${n.glbFileName}`);
2987
2986
  o.ok ? a = await o.arrayBuffer() : console.warn(`GLB file not found: ${n.glbFileName}`);
@@ -2989,10 +2988,10 @@ class js {
2989
2988
  if (a) {
2990
2989
  if (await r.setGLBModel(a), n.animationIndex !== void 0 && r.glbAnimator && r.glbAnimator.setAnimation(n.animationIndex), n.animationSpeed !== void 0 && r.glbAnimator && (r.glbAnimator.speed = n.animationSpeed), n.animationLoop !== void 0 && r.glbAnimator && (r.glbAnimator.loop = n.animationLoop), n.useGlbTexture && (n.textureEnabled = !0), n.useGlbTexture && ((e = r.glbMeshData) != null && e.hasBaseColorTexture))
2991
2990
  try {
2992
- const o = await ai(a);
2991
+ const o = await fi(a);
2993
2992
  if (o) {
2994
2993
  const c = await createImageBitmap(o.imageBlob);
2995
- await r.setTexture(c), console.log(`GLB embedded texture restored for ${n.name}`);
2994
+ await r.setTexture(c), globalThis.__HZFX_DEBUG && console.log(`GLB embedded texture restored for ${n.name}`);
2996
2995
  }
2997
2996
  } catch (o) {
2998
2997
  console.warn(`Failed to restore GLB texture for ${n.name}:`, o), n.useGlbTexture = !1;
@@ -3015,7 +3014,7 @@ class js {
3015
3014
  console.warn(`Failed to restore texture for ${n.name}:`, a), n.textureEnabled = !1;
3016
3015
  }
3017
3016
  for (const { system: r, config: n } of this.particleSystems)
3018
- r.updateAppearanceUniform(), (n.particleShapeRotationX || n.particleShapeRotationY || n.particleShapeRotationZ) && console.log(`[replaceSystems] ${n.name}: glbRotation XYZ = ${n.particleShapeRotationX}, ${n.particleShapeRotationY}, ${n.particleShapeRotationZ} | glbModelEnabled=${n.glbModelEnabled} | glbMeshData=${!!r.glbMeshData}`);
3017
+ r.updateAppearanceUniform();
3019
3018
  return this.respawnAllSystems(), !0;
3020
3019
  } catch (i) {
3021
3020
  return console.error("Error replacing systems:", i), !1;
@@ -3053,7 +3052,7 @@ class js {
3053
3052
  o.attractorPosition[1] + e[1],
3054
3053
  o.attractorPosition[2] + e[2]
3055
3054
  ]);
3056
- const u = new bt(this.device, l);
3055
+ const u = new vt(this.device, l);
3057
3056
  this.particleSystems.push({
3058
3057
  system: u,
3059
3058
  config: l
@@ -3072,7 +3071,7 @@ class js {
3072
3071
  try {
3073
3072
  let l = null;
3074
3073
  if (c.glbModelData)
3075
- l = di(c.glbModelData);
3074
+ l = mi(c.glbModelData);
3076
3075
  else if (c.glbFileName) {
3077
3076
  const u = await fetch(`/${c.glbFileName}`);
3078
3077
  u.ok ? l = await u.arrayBuffer() : console.warn(`GLB file not found: ${c.glbFileName}`);
@@ -3080,10 +3079,10 @@ class js {
3080
3079
  if (l) {
3081
3080
  if (await o.setGLBModel(l), c.animationIndex !== void 0 && o.glbAnimator && o.glbAnimator.setAnimation(c.animationIndex), c.animationSpeed !== void 0 && o.glbAnimator && (o.glbAnimator.speed = c.animationSpeed), c.animationLoop !== void 0 && o.glbAnimator && (o.glbAnimator.loop = c.animationLoop), c.useGlbTexture && (c.textureEnabled = !0), c.useGlbTexture && ((r = o.glbMeshData) != null && r.hasBaseColorTexture))
3082
3081
  try {
3083
- const u = await ai(l);
3082
+ const u = await fi(l);
3084
3083
  if (u) {
3085
3084
  const m = await createImageBitmap(u.imageBlob);
3086
- await o.setTexture(m), console.log(`GLB embedded texture restored for ${c.name}`);
3085
+ await o.setTexture(m), globalThis.__HZFX_DEBUG && console.log(`GLB embedded texture restored for ${c.name}`);
3087
3086
  }
3088
3087
  } catch (u) {
3089
3088
  console.warn(`Failed to restore GLB texture for ${c.name}:`, u), c.useGlbTexture = !1;
@@ -3113,7 +3112,7 @@ class js {
3113
3112
  }
3114
3113
  }
3115
3114
  }
3116
- async function Ys(s) {
3115
+ async function Js(s) {
3117
3116
  if (!s)
3118
3117
  throw new Error("canvas is required for initWebGPU()");
3119
3118
  if (!navigator.gpu)
@@ -3126,7 +3125,7 @@ async function Ys(s) {
3126
3125
  }), { device: i, context: t, format: r, canvas: s };
3127
3126
  }
3128
3127
  const oe = "rgba16float";
3129
- function fi(s, t, e, i) {
3128
+ function yi(s, t, e, i) {
3130
3129
  const r = s.createTexture({
3131
3130
  size: [e, i],
3132
3131
  format: oe,
@@ -3148,14 +3147,14 @@ function fi(s, t, e, i) {
3148
3147
  });
3149
3148
  return { sceneTexture: r, bloomTexA: n, bloomTexB: a };
3150
3149
  }
3151
- function pi(s, t, e) {
3150
+ function gi(s, t, e) {
3152
3151
  return s.createTexture({
3153
3152
  size: [t, e],
3154
3153
  format: "depth24plus",
3155
3154
  usage: GPUTextureUsage.RENDER_ATTACHMENT
3156
3155
  });
3157
3156
  }
3158
- function De(s, t, e) {
3157
+ function Ge(s, t, e) {
3159
3158
  const i = s.createBuffer({
3160
3159
  size: t.byteLength,
3161
3160
  usage: e,
@@ -3163,7 +3162,7 @@ function De(s, t, e) {
3163
3162
  });
3164
3163
  return new t.constructor(i.getMappedRange()).set(t), i.unmap(), i;
3165
3164
  }
3166
- const Hs = `
3165
+ const Qs = `
3167
3166
  struct Uniforms {
3168
3167
  transform: mat4x4<f32>,
3169
3168
  cameraPosition: vec3<f32>,
@@ -3225,7 +3224,7 @@ const Hs = `
3225
3224
 
3226
3225
  return finalColor;
3227
3226
  }
3228
- `, qs = `
3227
+ `, Ks = `
3229
3228
  struct Uniforms {
3230
3229
  transform: mat4x4<f32>,
3231
3230
  cameraPosition: vec3<f32>,
@@ -3461,7 +3460,7 @@ const Hs = `
3461
3460
  return finalColor;
3462
3461
  }
3463
3462
  `;
3464
- function Zs(s) {
3463
+ function er(s) {
3465
3464
  const t = s.createBindGroupLayout({
3466
3465
  entries: [
3467
3466
  {
@@ -3547,7 +3546,7 @@ function Zs(s) {
3547
3546
  object3dBindGroupLayout: r
3548
3547
  };
3549
3548
  }
3550
- function $s(s, t, e, i = {}) {
3549
+ function tr(s, t, e, i = {}) {
3551
3550
  const { depthCompare: r } = i, n = r || "less", {
3552
3551
  particleBindGroupLayout: a,
3553
3552
  bloomBindGroupLayout: o,
@@ -3560,18 +3559,18 @@ function $s(s, t, e, i = {}) {
3560
3559
  }), p = s.createPipelineLayout({
3561
3560
  bindGroupLayouts: [c]
3562
3561
  }), d = s.createShaderModule({
3563
- code: fs
3562
+ code: ys
3564
3563
  }), b = s.createShaderModule({
3565
- code: ps
3564
+ code: gs
3565
+ }), w = s.createShaderModule({
3566
+ code: bs
3566
3567
  }), M = s.createShaderModule({
3567
- code: hs
3568
- }), T = s.createShaderModule({
3569
- code: ms
3570
- }), C = s.createShaderModule({
3571
- code: Hs
3572
- }), _ = s.createShaderModule({
3573
- code: qs
3574
- }), L = ($) => s.createRenderPipeline({
3568
+ code: Ss
3569
+ }), R = s.createShaderModule({
3570
+ code: Qs
3571
+ }), x = s.createShaderModule({
3572
+ code: Ks
3573
+ }), L = (W) => s.createRenderPipeline({
3575
3574
  layout: u,
3576
3575
  vertex: {
3577
3576
  module: d,
@@ -3639,7 +3638,7 @@ function $s(s, t, e, i = {}) {
3639
3638
  entryPoint: "fs_main",
3640
3639
  targets: [{
3641
3640
  format: oe,
3642
- blend: $
3641
+ blend: W
3643
3642
  }]
3644
3643
  },
3645
3644
  primitive: {
@@ -3651,7 +3650,7 @@ function $s(s, t, e, i = {}) {
3651
3650
  depthCompare: n,
3652
3651
  format: "depth24plus"
3653
3652
  }
3654
- }), v = L({
3653
+ }), P = L({
3655
3654
  color: {
3656
3655
  srcFactor: "src-alpha",
3657
3656
  dstFactor: "one-minus-src-alpha",
@@ -3662,7 +3661,7 @@ function $s(s, t, e, i = {}) {
3662
3661
  dstFactor: "one-minus-src-alpha",
3663
3662
  operation: "add"
3664
3663
  }
3665
- }), w = L({
3664
+ }), T = L({
3666
3665
  color: {
3667
3666
  srcFactor: "src-alpha",
3668
3667
  dstFactor: "one",
@@ -3673,7 +3672,7 @@ function $s(s, t, e, i = {}) {
3673
3672
  dstFactor: "one-minus-src-alpha",
3674
3673
  operation: "add"
3675
3674
  }
3676
- }), R = s.createRenderPipeline({
3675
+ }), E = s.createRenderPipeline({
3677
3676
  layout: u,
3678
3677
  vertex: {
3679
3678
  module: d,
@@ -3755,7 +3754,7 @@ function $s(s, t, e, i = {}) {
3755
3754
  // Always write depth (don't self-occlude)
3756
3755
  format: "depth24plus"
3757
3756
  }
3758
- }), V = s.createRenderPipeline({
3757
+ }), F = s.createRenderPipeline({
3759
3758
  layout: m,
3760
3759
  vertex: {
3761
3760
  module: b,
@@ -3771,14 +3770,14 @@ function $s(s, t, e, i = {}) {
3771
3770
  primitive: {
3772
3771
  topology: "triangle-list"
3773
3772
  }
3774
- }), X = s.createRenderPipeline({
3773
+ }), k = s.createRenderPipeline({
3775
3774
  layout: p,
3776
3775
  vertex: {
3777
- module: M,
3776
+ module: w,
3778
3777
  entryPoint: "vs_main"
3779
3778
  },
3780
3779
  fragment: {
3781
- module: M,
3780
+ module: w,
3782
3781
  entryPoint: "fs_main",
3783
3782
  targets: [{
3784
3783
  format: oe,
@@ -3799,14 +3798,14 @@ function $s(s, t, e, i = {}) {
3799
3798
  primitive: {
3800
3799
  topology: "triangle-list"
3801
3800
  }
3802
- }), j = s.createRenderPipeline({
3801
+ }), Y = s.createRenderPipeline({
3803
3802
  layout: p,
3804
3803
  vertex: {
3805
- module: T,
3804
+ module: M,
3806
3805
  entryPoint: "vs_main"
3807
3806
  },
3808
3807
  fragment: {
3809
- module: T,
3808
+ module: M,
3810
3809
  entryPoint: "fs_main",
3811
3810
  targets: [{
3812
3811
  format: oe,
@@ -3827,11 +3826,11 @@ function $s(s, t, e, i = {}) {
3827
3826
  primitive: {
3828
3827
  topology: "triangle-list"
3829
3828
  }
3830
- }), k = s.createShaderModule({ code: ys }), D = s.createRenderPipeline({
3829
+ }), N = s.createShaderModule({ code: xs }), G = s.createRenderPipeline({
3831
3830
  layout: p,
3832
- vertex: { module: k, entryPoint: "vs_main" },
3831
+ vertex: { module: N, entryPoint: "vs_main" },
3833
3832
  fragment: {
3834
- module: k,
3833
+ module: N,
3835
3834
  entryPoint: "fs_main",
3836
3835
  targets: [{
3837
3836
  format: t,
@@ -3842,12 +3841,12 @@ function $s(s, t, e, i = {}) {
3842
3841
  }]
3843
3842
  },
3844
3843
  primitive: { topology: "triangle-list" }
3845
- }), he = s.createPipelineLayout({
3844
+ }), de = s.createPipelineLayout({
3846
3845
  bindGroupLayouts: [l]
3847
- }), ze = s.createRenderPipeline({
3848
- layout: he,
3846
+ }), De = s.createRenderPipeline({
3847
+ layout: de,
3849
3848
  vertex: {
3850
- module: C,
3849
+ module: R,
3851
3850
  entryPoint: "vs_main",
3852
3851
  buffers: [
3853
3852
  {
@@ -3872,7 +3871,7 @@ function $s(s, t, e, i = {}) {
3872
3871
  ]
3873
3872
  },
3874
3873
  fragment: {
3875
- module: C,
3874
+ module: R,
3876
3875
  entryPoint: "fs_main",
3877
3876
  targets: [{
3878
3877
  format: oe,
@@ -3899,10 +3898,10 @@ function $s(s, t, e, i = {}) {
3899
3898
  depthCompare: n,
3900
3899
  format: "depth24plus"
3901
3900
  }
3902
- }), at = s.createRenderPipeline({
3901
+ }), ct = s.createRenderPipeline({
3903
3902
  layout: u,
3904
3903
  vertex: {
3905
- module: _,
3904
+ module: x,
3906
3905
  entryPoint: "vs_main",
3907
3906
  buffers: [
3908
3907
  {
@@ -3974,7 +3973,7 @@ function $s(s, t, e, i = {}) {
3974
3973
  ]
3975
3974
  },
3976
3975
  fragment: {
3977
- module: _,
3976
+ module: x,
3978
3977
  entryPoint: "fs_main",
3979
3978
  targets: [{
3980
3979
  format: oe,
@@ -4003,18 +4002,18 @@ function $s(s, t, e, i = {}) {
4003
4002
  }
4004
4003
  });
4005
4004
  return {
4006
- particlePipeline: v,
4007
- particleAdditivePipeline: w,
4008
- particleDepthWritePipeline: R,
4009
- blurPipeline: V,
4010
- compositePipeline: X,
4011
- directRenderPipeline: j,
4012
- finalCompositePipeline: D,
4013
- object3dPipeline: ze,
4014
- glbMeshPipeline: at
4005
+ particlePipeline: P,
4006
+ particleAdditivePipeline: T,
4007
+ particleDepthWritePipeline: E,
4008
+ blurPipeline: F,
4009
+ compositePipeline: k,
4010
+ directRenderPipeline: Y,
4011
+ finalCompositePipeline: G,
4012
+ object3dPipeline: De,
4013
+ glbMeshPipeline: ct
4015
4014
  };
4016
4015
  }
4017
- function St(s, t, e, i) {
4016
+ function Pt(s, t, e, i) {
4018
4017
  const {
4019
4018
  uniformBuffer: r,
4020
4019
  appearanceUniformBuffer: n,
@@ -4118,7 +4117,7 @@ function St(s, t, e, i) {
4118
4117
  resource: { buffer: o }
4119
4118
  }
4120
4119
  ]
4121
- }), M = s.createBindGroup({
4120
+ }), w = s.createBindGroup({
4122
4121
  layout: s.createBindGroupLayout({
4123
4122
  entries: [
4124
4123
  {
@@ -4161,7 +4160,7 @@ function St(s, t, e, i) {
4161
4160
  resource: { buffer: c }
4162
4161
  }
4163
4162
  ]
4164
- }), T = s.createBindGroup({
4163
+ }), M = s.createBindGroup({
4165
4164
  layout: s.createBindGroupLayout({
4166
4165
  entries: [
4167
4166
  {
@@ -4209,11 +4208,11 @@ function St(s, t, e, i) {
4209
4208
  particleBindGroup: p,
4210
4209
  horizontalBlurBindGroup: d,
4211
4210
  verticalBlurBindGroup: b,
4212
- compositeBindGroup: M,
4213
- directRenderBindGroup: T
4211
+ compositeBindGroup: w,
4212
+ directRenderBindGroup: M
4214
4213
  };
4215
4214
  }
4216
- function Ws(s) {
4215
+ function ir(s) {
4217
4216
  return s.createSampler({
4218
4217
  magFilter: "linear",
4219
4218
  minFilter: "linear",
@@ -4223,7 +4222,7 @@ function Ws(s) {
4223
4222
  maxAnisotropy: 16
4224
4223
  });
4225
4224
  }
4226
- function Js() {
4225
+ function sr() {
4227
4226
  const s = new Float32Array([
4228
4227
  // Front face (z = 0.5)
4229
4228
  -0.5,
@@ -4421,7 +4420,7 @@ function Js() {
4421
4420
  ]);
4422
4421
  return { vertices: s, indices: t };
4423
4422
  }
4424
- function Qs(s = 16, t = 16) {
4423
+ function rr(s = 16, t = 16) {
4425
4424
  const e = [], i = [];
4426
4425
  for (let r = 0; r <= s; r++) {
4427
4426
  const n = r * Math.PI / s, a = Math.sin(n), o = Math.cos(n);
@@ -4440,7 +4439,7 @@ function Qs(s = 16, t = 16) {
4440
4439
  indices: new Uint16Array(i)
4441
4440
  };
4442
4441
  }
4443
- class Ks {
4442
+ class nr {
4444
4443
  constructor(t, e, i, r, n) {
4445
4444
  this.id = t, this.type = e, this.position = i, this.scale = r, this.color = n, this.rotation = [0, 0, 0];
4446
4445
  }
@@ -4574,7 +4573,7 @@ class Ks {
4574
4573
  return i;
4575
4574
  }
4576
4575
  }
4577
- class or {
4576
+ class pr {
4578
4577
  constructor(t) {
4579
4578
  this.device = t, this.objects = [], this.nextId = 0, this.initializeGeometry(), this.onObjectAdded = null, this.onObjectRemoved = null, this.onObjectUpdated = null;
4580
4579
  }
@@ -4582,20 +4581,20 @@ class or {
4582
4581
  * Initialize geometry buffers for cube and sphere
4583
4582
  */
4584
4583
  initializeGeometry() {
4585
- const t = Js(), e = Qs(16, 16);
4586
- this.cubeVertexBuffer = De(
4584
+ const t = sr(), e = rr(16, 16);
4585
+ this.cubeVertexBuffer = Ge(
4587
4586
  this.device,
4588
4587
  t.vertices,
4589
4588
  GPUBufferUsage.VERTEX
4590
- ), this.cubeIndexBuffer = De(
4589
+ ), this.cubeIndexBuffer = Ge(
4591
4590
  this.device,
4592
4591
  t.indices,
4593
4592
  GPUBufferUsage.INDEX
4594
- ), this.cubeIndexCount = t.indices.length, this.sphereVertexBuffer = De(
4593
+ ), this.cubeIndexCount = t.indices.length, this.sphereVertexBuffer = Ge(
4595
4594
  this.device,
4596
4595
  e.vertices,
4597
4596
  GPUBufferUsage.VERTEX
4598
- ), this.sphereIndexBuffer = De(
4597
+ ), this.sphereIndexBuffer = Ge(
4599
4598
  this.device,
4600
4599
  e.indices,
4601
4600
  GPUBufferUsage.INDEX
@@ -4610,7 +4609,7 @@ class or {
4610
4609
  * @returns {Object3D} The created object
4611
4610
  */
4612
4611
  addObject(t, e = [0, 0, 0], i = [1, 1, 1], r = [1, 1, 1, 1]) {
4613
- const n = new Ks(this.nextId++, t, e, i, r);
4612
+ const n = new nr(this.nextId++, t, e, i, r);
4614
4613
  return n.uniformBuffer = this.device.createBuffer({
4615
4614
  size: 192,
4616
4615
  // modelMatrix (64) + normalMatrix (64) + color (16) + padding (48)
@@ -4699,21 +4698,21 @@ class or {
4699
4698
  }
4700
4699
  }
4701
4700
  }
4702
- function lr(s) {
4701
+ function hr(s) {
4703
4702
  const t = parseInt(s.slice(1, 3), 16) / 255, e = parseInt(s.slice(3, 5), 16) / 255, i = parseInt(s.slice(5, 7), 16) / 255;
4704
4703
  return [t, e, i];
4705
4704
  }
4706
- function cr(s) {
4705
+ function mr(s) {
4707
4706
  if (!s) return "#ffffff";
4708
4707
  const t = Math.round(s[0] * 255).toString(16).padStart(2, "0"), e = Math.round(s[1] * 255).toString(16).padStart(2, "0"), i = Math.round(s[2] * 255).toString(16).padStart(2, "0");
4709
4708
  return `#${t}${e}${i}`;
4710
4709
  }
4711
- function ur(s, t, e) {
4712
- const i = hi([
4710
+ function yr(s, t, e) {
4711
+ const i = bi([
4713
4712
  s[0] - t[0],
4714
4713
  s[1] - t[1],
4715
4714
  s[2] - t[2]
4716
- ]), r = hi(mi(e, i)), n = mi(i, r);
4715
+ ]), r = bi(Si(e, i)), n = Si(i, r);
4717
4716
  return new Float32Array([
4718
4717
  r[0],
4719
4718
  n[0],
@@ -4727,13 +4726,13 @@ function ur(s, t, e) {
4727
4726
  n[2],
4728
4727
  i[2],
4729
4728
  0,
4730
- -xt(r, s),
4731
- -xt(n, s),
4732
- -xt(i, s),
4729
+ -_t(r, s),
4730
+ -_t(n, s),
4731
+ -_t(i, s),
4733
4732
  1
4734
4733
  ]);
4735
4734
  }
4736
- function dr(s, t = Math.PI / 4) {
4735
+ function gr(s, t = Math.PI / 4) {
4737
4736
  const r = 1 / Math.tan(t / 2);
4738
4737
  return new Float32Array([
4739
4738
  r * s,
@@ -4754,21 +4753,21 @@ function dr(s, t = Math.PI / 4) {
4754
4753
  0
4755
4754
  ]);
4756
4755
  }
4757
- function hi(s) {
4756
+ function bi(s) {
4758
4757
  const t = Math.sqrt(s[0] * s[0] + s[1] * s[1] + s[2] * s[2]);
4759
4758
  return [s[0] / t, s[1] / t, s[2] / t];
4760
4759
  }
4761
- function mi(s, t) {
4760
+ function Si(s, t) {
4762
4761
  return [
4763
4762
  s[1] * t[2] - s[2] * t[1],
4764
4763
  s[2] * t[0] - s[0] * t[2],
4765
4764
  s[0] * t[1] - s[1] * t[0]
4766
4765
  ];
4767
4766
  }
4768
- function xt(s, t) {
4767
+ function _t(s, t) {
4769
4768
  return s[0] * t[0] + s[1] * t[1] + s[2] * t[2];
4770
4769
  }
4771
- function er(s, t) {
4770
+ function ar(s, t) {
4772
4771
  const e = new Float32Array(16);
4773
4772
  for (let i = 0; i < 4; i++)
4774
4773
  for (let r = 0; r < 4; r++) {
@@ -4779,7 +4778,7 @@ function er(s, t) {
4779
4778
  }
4780
4779
  return e;
4781
4780
  }
4782
- const Pt = 1481005640, xi = 1, vi = 1313821514, Pi = 5130562, qe = "$hzfxAsset", _i = (s) => typeof atob == "function" ? Uint8Array.from(atob(s), (t) => t.charCodeAt(0)) : new Uint8Array(Buffer.from(s, "base64")), yi = (s) => {
4781
+ const Bt = 1481005640, wi = 1, Bi = 1313821514, Mi = 5130562, Ze = "$hzfxAsset", Ri = (s) => typeof atob == "function" ? Uint8Array.from(atob(s), (t) => t.charCodeAt(0)) : new Uint8Array(Buffer.from(s, "base64")), xi = (s) => {
4783
4782
  if (typeof btoa == "function") {
4784
4783
  let t = "";
4785
4784
  for (let e = 0; e < s.length; e++) t += String.fromCharCode(s[e]);
@@ -4787,94 +4786,94 @@ const Pt = 1481005640, xi = 1, vi = 1313821514, Pi = 5130562, qe = "$hzfxAsset",
4787
4786
  }
4788
4787
  return Buffer.from(s).toString("base64");
4789
4788
  };
4790
- function tr(s) {
4791
- const t = s.indexOf(","), e = s.slice(5, t), i = e.split(";")[0] || "application/octet-stream", r = s.slice(t + 1), a = /;base64/i.test(e) ? _i(r) : new TextEncoder().encode(decodeURIComponent(r));
4789
+ function or(s) {
4790
+ const t = s.indexOf(","), e = s.slice(5, t), i = e.split(";")[0] || "application/octet-stream", r = s.slice(t + 1), a = /;base64/i.test(e) ? Ri(r) : new TextEncoder().encode(decodeURIComponent(r));
4792
4791
  return { mime: i, bytes: a };
4793
4792
  }
4794
- function gi(s) {
4793
+ function vi(s) {
4795
4794
  return (4 - s % 4) % 4;
4796
4795
  }
4797
- async function ir(s, t = {}) {
4796
+ async function lr(s, t = {}) {
4798
4797
  const { textureFormat: e = "keep", quality: i = 0.85 } = t, r = [], n = [];
4799
4798
  let a = 0;
4800
- const o = (w, R, V) => {
4801
- const X = a, j = w.length;
4802
- r.push({ offset: X, length: j, mime: R, kind: V }), n.push(w), a += j;
4803
- const k = gi(j);
4804
- return k && (n.push(new Uint8Array(k)), a += k), r.length - 1;
4799
+ const o = (T, E, F) => {
4800
+ const k = a, Y = T.length;
4801
+ r.push({ offset: k, length: Y, mime: E, kind: F }), n.push(T), a += Y;
4802
+ const N = vi(Y);
4803
+ return N && (n.push(new Uint8Array(N)), a += N), r.length - 1;
4805
4804
  }, c = e === "webp" && typeof OffscreenCanvas < "u" && typeof createImageBitmap == "function", l = [];
4806
- for (const w of s.systems || []) {
4807
- const R = { ...w };
4808
- if (typeof R.textureImageData == "string" && R.textureImageData.startsWith("data:")) {
4809
- let { mime: V, bytes: X } = tr(R.textureImageData);
4810
- if (c && V !== "image/webp")
4805
+ for (const T of s.systems || []) {
4806
+ const E = { ...T };
4807
+ if (typeof E.textureImageData == "string" && E.textureImageData.startsWith("data:")) {
4808
+ let { mime: F, bytes: k } = or(E.textureImageData);
4809
+ if (c && F !== "image/webp")
4811
4810
  try {
4812
- const j = await createImageBitmap(new Blob([X], { type: V })), k = new OffscreenCanvas(j.width, j.height);
4813
- k.getContext("2d").drawImage(j, 0, 0);
4814
- const D = await k.convertToBlob({ type: "image/webp", quality: i }), he = new Uint8Array(await D.arrayBuffer());
4815
- he.length < X.length && (X = he, V = "image/webp");
4811
+ const Y = await createImageBitmap(new Blob([k], { type: F })), N = new OffscreenCanvas(Y.width, Y.height);
4812
+ N.getContext("2d").drawImage(Y, 0, 0);
4813
+ const G = await N.convertToBlob({ type: "image/webp", quality: i }), de = new Uint8Array(await G.arrayBuffer());
4814
+ de.length < k.length && (k = de, F = "image/webp");
4816
4815
  } catch {
4817
4816
  }
4818
- R.textureImageData = { [qe]: o(X, V, "texture") };
4817
+ E.textureImageData = { [Ze]: o(k, F, "texture") };
4819
4818
  }
4820
- if (typeof R.glbModelData == "string" && R.glbModelData.length > 0) {
4821
- const V = _i(R.glbModelData);
4822
- R.glbModelData = { [qe]: o(V, "model/gltf-binary", "glb") };
4819
+ if (typeof E.glbModelData == "string" && E.glbModelData.length > 0) {
4820
+ const F = Ri(E.glbModelData);
4821
+ E.glbModelData = { [Ze]: o(F, "model/gltf-binary", "glb") };
4823
4822
  }
4824
- l.push(R);
4823
+ l.push(E);
4825
4824
  }
4826
- const u = { ...s, systems: l, assets: r }, m = new TextEncoder().encode(JSON.stringify(u)), p = gi(m.length), d = new Uint8Array(a);
4825
+ const u = { ...s, systems: l, assets: r }, m = new TextEncoder().encode(JSON.stringify(u)), p = vi(m.length), d = new Uint8Array(a);
4827
4826
  let b = 0;
4828
- for (const w of n)
4829
- d.set(w, b), b += w.length;
4830
- const M = m.length + p, T = 20 + M + 8 + a, C = new ArrayBuffer(T), _ = new DataView(C), L = new Uint8Array(C);
4831
- let v = 0;
4832
- _.setUint32(v, Pt, !0), v += 4, _.setUint32(v, xi, !0), v += 4, _.setUint32(v, T, !0), v += 4, _.setUint32(v, M, !0), v += 4, _.setUint32(v, vi, !0), v += 4, L.set(m, v), v += m.length;
4833
- for (let w = 0; w < p; w++) L[v++] = 32;
4834
- return _.setUint32(v, a, !0), v += 4, _.setUint32(v, Pi, !0), v += 4, L.set(d, v), v += a, C;
4827
+ for (const T of n)
4828
+ d.set(T, b), b += T.length;
4829
+ const w = m.length + p, M = 20 + w + 8 + a, R = new ArrayBuffer(M), x = new DataView(R), L = new Uint8Array(R);
4830
+ let P = 0;
4831
+ x.setUint32(P, Bt, !0), P += 4, x.setUint32(P, wi, !0), P += 4, x.setUint32(P, M, !0), P += 4, x.setUint32(P, w, !0), P += 4, x.setUint32(P, Bi, !0), P += 4, L.set(m, P), P += m.length;
4832
+ for (let T = 0; T < p; T++) L[P++] = 32;
4833
+ return x.setUint32(P, a, !0), P += 4, x.setUint32(P, Mi, !0), P += 4, L.set(d, P), P += a, R;
4835
4834
  }
4836
- function Bi(s) {
4837
- return !s || s.byteLength < 12 ? !1 : new DataView(s).getUint32(0, !0) === Pt;
4835
+ function Ti(s) {
4836
+ return !s || s.byteLength < 12 ? !1 : new DataView(s).getUint32(0, !0) === Bt;
4838
4837
  }
4839
- function wi(s) {
4838
+ function Ei(s) {
4840
4839
  const t = new DataView(s);
4841
- if (t.getUint32(0, !0) !== Pt) throw new Error("[unpackHZFX] bad magic — not an .hzfx file");
4840
+ if (t.getUint32(0, !0) !== Bt) throw new Error("[unpackHZFX] bad magic — not an .hzfx file");
4842
4841
  const e = t.getUint32(4, !0);
4843
- if (e !== xi) throw new Error(`[unpackHZFX] unsupported version ${e}`);
4842
+ if (e !== wi) throw new Error(`[unpackHZFX] unsupported version ${e}`);
4844
4843
  let i = 12, r = null, n = -1;
4845
4844
  const a = new Uint8Array(s);
4846
4845
  for (; i + 8 <= s.byteLength; ) {
4847
4846
  const p = t.getUint32(i, !0);
4848
4847
  i += 4;
4849
4848
  const d = t.getUint32(i, !0);
4850
- i += 4, d === vi ? r = JSON.parse(new TextDecoder().decode(a.subarray(i, i + p))) : d === Pi && (n = i), i += p;
4849
+ i += 4, d === Bi ? r = JSON.parse(new TextDecoder().decode(a.subarray(i, i + p))) : d === Mi && (n = i), i += p;
4851
4850
  }
4852
4851
  if (!r) throw new Error("[unpackHZFX] missing JSON chunk");
4853
4852
  const o = r.assets || [], c = (p) => {
4854
4853
  const d = o[p];
4855
4854
  return !d || n < 0 ? null : { ...d, bytes: a.subarray(n + d.offset, n + d.offset + d.length) };
4856
- }, l = (p) => p && typeof p == "object" && typeof p[qe] == "number", u = (r.systems || []).map((p) => {
4855
+ }, l = (p) => p && typeof p == "object" && typeof p[Ze] == "number", u = (r.systems || []).map((p) => {
4857
4856
  const d = { ...p };
4858
4857
  if (l(d.textureImageData)) {
4859
- const b = c(d.textureImageData[qe]);
4860
- d.textureImageData = b ? `data:${b.mime};base64,${yi(b.bytes)}` : void 0;
4858
+ const b = c(d.textureImageData[Ze]);
4859
+ d.textureImageData = b ? `data:${b.mime};base64,${xi(b.bytes)}` : void 0;
4861
4860
  }
4862
4861
  if (l(d.glbModelData)) {
4863
- const b = c(d.glbModelData[qe]);
4864
- d.glbModelData = b ? yi(b.bytes) : void 0;
4862
+ const b = c(d.glbModelData[Ze]);
4863
+ d.glbModelData = b ? xi(b.bytes) : void 0;
4865
4864
  }
4866
4865
  return d;
4867
4866
  }), m = { ...r, systems: u };
4868
4867
  return delete m.assets, m;
4869
4868
  }
4870
- function sr(s) {
4869
+ function cr(s) {
4871
4870
  const t = new Uint8Array(s);
4872
4871
  let e = "";
4873
4872
  for (let i = 0; i < t.byteLength; i++)
4874
4873
  e += String.fromCharCode(t[i]);
4875
4874
  return btoa(e);
4876
4875
  }
4877
- function rr(s) {
4876
+ function ur(s) {
4878
4877
  return {
4879
4878
  name: s.name,
4880
4879
  id: s.id,
@@ -4939,6 +4938,9 @@ function rr(s) {
4939
4938
  rotationMode: s.rotationMode,
4940
4939
  minRotation: s.minRotation,
4941
4940
  maxRotation: s.maxRotation,
4941
+ orientX: s.orientX,
4942
+ orientY: s.orientY,
4943
+ orientZ: s.orientZ,
4942
4944
  overrideXVelocity: s.overrideXVelocity,
4943
4945
  overrideYVelocity: s.overrideYVelocity,
4944
4946
  overrideZVelocity: s.overrideZVelocity,
@@ -5049,7 +5051,7 @@ function rr(s) {
5049
5051
  displayUnit: s.displayUnit || "m"
5050
5052
  };
5051
5053
  }
5052
- async function fr(s, t, e = "hzfx") {
5054
+ async function br(s, t, e = "hzfx") {
5053
5055
  if (!s || !s.particleSystems || s.particleSystems.length === 0) {
5054
5056
  alert("No particle systems to save.");
5055
5057
  return;
@@ -5059,11 +5061,11 @@ async function fr(s, t, e = "hzfx") {
5059
5061
  version: "1.0",
5060
5062
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
5061
5063
  systems: s.particleSystems.map(({ config: u, system: m }) => ({
5062
- ...rr(u),
5064
+ ...ur(u),
5063
5065
  // single source of truth for config fields
5064
5066
  // Binary assets embedded so replaceSystems() can restore them
5065
5067
  textureImageData: u.textureEnabled && !u.glbModelEnabled && u.textureImageData ? u.textureImageData : void 0,
5066
- glbModelData: u.glbModelEnabled && m.glbRawArrayBuffer ? sr(m.glbRawArrayBuffer) : void 0
5068
+ glbModelData: u.glbModelEnabled && m.glbRawArrayBuffer ? cr(m.glbRawArrayBuffer) : void 0
5067
5069
  })),
5068
5070
  activeSystemIndex: s.activeSystemIndex,
5069
5071
  loop: s.loop || !1
@@ -5071,7 +5073,7 @@ async function fr(s, t, e = "hzfx") {
5071
5073
  }, r = e === "json" ? "json" : "hzfx";
5072
5074
  let n;
5073
5075
  if (r === "hzfx") {
5074
- const u = await ir(i, { textureFormat: "webp" });
5076
+ const u = await lr(i, { textureFormat: "webp" });
5075
5077
  n = new Blob([u], { type: "application/octet-stream" });
5076
5078
  } else
5077
5079
  n = new Blob([JSON.stringify(i, null, 2)], { type: "application/json" });
@@ -5088,7 +5090,7 @@ async function fr(s, t, e = "hzfx") {
5088
5090
  console.error("Error saving scene:", i), alert("Error saving scene. See console for details.");
5089
5091
  }
5090
5092
  }
5091
- function pr(s) {
5093
+ function Sr(s) {
5092
5094
  return new Promise((t, e) => {
5093
5095
  try {
5094
5096
  const i = s.target.files[0];
@@ -5101,7 +5103,7 @@ function pr(s) {
5101
5103
  try {
5102
5104
  const a = n.target.result;
5103
5105
  let o;
5104
- if (Bi(a) ? o = wi(a) : o = JSON.parse(new TextDecoder().decode(a)), !Array.isArray(o.systems) || o.systems.length === 0)
5106
+ if (Ti(a) ? o = Ei(a) : o = JSON.parse(new TextDecoder().decode(a)), !Array.isArray(o.systems) || o.systems.length === 0)
5105
5107
  throw new Error("No valid particle systems found in the file");
5106
5108
  t({
5107
5109
  systems: o.systems.slice(),
@@ -5119,7 +5121,7 @@ function pr(s) {
5119
5121
  }
5120
5122
  });
5121
5123
  }
5122
- async function hr(s) {
5124
+ async function xr(s) {
5123
5125
  if (!s || typeof s != "string")
5124
5126
  throw new Error("[fetchPreset] url must be a non-empty string");
5125
5127
  const t = await fetch(s);
@@ -5127,7 +5129,7 @@ async function hr(s) {
5127
5129
  throw new Error(`[fetchPreset] HTTP ${t.status}: ${t.statusText}`);
5128
5130
  const e = await t.arrayBuffer();
5129
5131
  let i;
5130
- if (Bi(e) ? i = wi(e) : i = JSON.parse(new TextDecoder().decode(e)), !Array.isArray(i.systems) || i.systems.length === 0)
5132
+ if (Ti(e) ? i = Ei(e) : i = JSON.parse(new TextDecoder().decode(e)), !Array.isArray(i.systems) || i.systems.length === 0)
5131
5133
  throw new Error('[fetchPreset] Invalid preset: "systems" must be a non-empty array');
5132
5134
  return {
5133
5135
  version: i.version,
@@ -5135,7 +5137,7 @@ async function hr(s) {
5135
5137
  activeSystemIndex: i.activeSystemIndex ?? 0
5136
5138
  };
5137
5139
  }
5138
- const nr = (s) => `
5140
+ const dr = (s) => `
5139
5141
  @vertex fn vs(@builtin(vertex_index) i: u32) -> @builtin(position) vec4f {
5140
5142
  var p = array<vec2f, 3>(vec2f(-1.0, -3.0), vec2f(-1.0, 1.0), vec2f(3.0, 1.0));
5141
5143
  return vec4f(p[i], 0.0, 1.0);
@@ -5145,16 +5147,16 @@ const nr = (s) => `
5145
5147
  return textureLoad(src, vec2i(pos.xy), 0);
5146
5148
  }
5147
5149
  `;
5148
- async function mr(s, t = {}) {
5150
+ async function vr(s, t = {}) {
5149
5151
  const { getSceneDepth: e = null, autoRespawn: i = !0 } = t;
5150
5152
  let r, n, a;
5151
5153
  const o = !!(s && s.device && s.context);
5152
- o ? ({ device: r, context: n, canvas: a } = s, a || (a = n.canvas)) : (a = s, { device: r, context: n } = await Ys(a));
5153
- const c = navigator.gpu.getPreferredCanvasFormat(), l = t.manager || new js(r), u = { layouts: {}, pipelines: {} };
5154
+ o ? ({ device: r, context: n, canvas: a } = s, a || (a = n.canvas)) : (a = s, { device: r, context: n } = await Js(a));
5155
+ const c = navigator.gpu.getPreferredCanvasFormat(), l = t.manager || new Ws(r), u = { layouts: {}, pipelines: {} };
5154
5156
  function m(f) {
5155
5157
  const h = f ? "ms" : "ss";
5156
5158
  if (!u.pipelines[h]) {
5157
- const S = r.createShaderModule({ code: nr(f) }), g = r.createBindGroupLayout({
5159
+ const S = r.createShaderModule({ code: dr(f) }), g = r.createBindGroupLayout({
5158
5160
  entries: [{ binding: 0, visibility: GPUShaderStage.FRAGMENT, texture: { sampleType: "depth", multisampled: f } }]
5159
5161
  });
5160
5162
  u.layouts[h] = g, u.pipelines[h] = r.createRenderPipeline({
@@ -5214,163 +5216,166 @@ async function mr(s, t = {}) {
5214
5216
  clear() {
5215
5217
  this.systemBindGroups = {}, this.systemBloomHorizontalBindGroups = {}, this.secondHorizontalBindGroups = {}, this.systemBloomCompositeBindGroups = {}, this.combinedBloomCompositeBindGroups = {}, this.combinedInitialBindGroup = null, this.finalBindGroup = null, this.textureStates = {}, this.textureRefs = {};
5216
5218
  }
5217
- }, b = r.createBuffer({ size: 96, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }), M = r.createBuffer({ size: 208, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }), T = r.createBuffer({ size: 32, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }), C = r.createBuffer({ size: 32, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }), _ = r.createBuffer({ size: 64, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }), L = De(r, new Uint16Array([0, 1, 2, 0, 2, 3]), GPUBufferUsage.INDEX), v = {}, w = () => De(r, new Float32Array([-0.5, -0.5, 0, 0.5, -0.5, 0, 0.5, 0.5, 0, -0.5, 0.5, 0]), GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST);
5219
+ }, b = r.createBuffer({ size: 96, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }), w = r.createBuffer({ size: 208, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }), M = r.createBuffer({ size: 32, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }), R = r.createBuffer({ size: 32, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }), x = r.createBuffer({ size: 64, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }), L = Ge(r, new Uint16Array([0, 1, 2, 0, 2, 3]), GPUBufferUsage.INDEX), P = {}, T = () => Ge(r, new Float32Array([-0.5, -0.5, 0, 0.5, -0.5, 0, 0.5, 0.5, 0, -0.5, 0.5, 0]), GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST);
5218
5220
  l.onSystemCreated = (f) => {
5219
- v[f] || (v[f] = w());
5221
+ P[f] || (P[f] = T());
5220
5222
  };
5221
- const R = 4e4, V = new Float32Array(R * 8), X = new Float32Array(R * 4), j = new Float32Array(R * 4), k = r.createBuffer({ size: R * 8 * 4, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST }), D = r.createBuffer({ size: R * 4 * 4, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST }), he = r.createBuffer({ size: R * 4 * 4, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST }), ze = /* @__PURE__ */ new Map(), at = 8, $ = [];
5222
- function _t(f) {
5223
- for (const h of $) if (h.ids.has(f)) return h;
5223
+ const E = 4e4, F = new Float32Array(E * 8), k = new Float32Array(E * 4), Y = new Float32Array(E * 4), N = r.createBuffer({ size: E * 8 * 4, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST }), G = r.createBuffer({ size: E * 4 * 4, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST }), de = r.createBuffer({ size: E * 4 * 4, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST }), De = /* @__PURE__ */ new Map(), ct = 8, W = [];
5224
+ function Mt(f) {
5225
+ for (const h of W) if (h.ids.has(f)) return h;
5224
5226
  return null;
5225
5227
  }
5226
- function Ri(f, h) {
5228
+ function Ci(f, h) {
5227
5229
  if (!f.pos) return;
5228
5230
  f.hist.push({ t: h, x: f.pos[0], y: f.pos[1], z: f.pos[2] });
5229
- const S = h - at;
5231
+ const S = h - ct;
5230
5232
  for (; f.hist.length > 2 && f.hist[0].t < S; ) f.hist.shift();
5231
5233
  }
5232
- function Bt(f, h) {
5233
- const S = f.hist;
5234
- if (S.length === 0) return f.pos;
5235
- if (h >= S[S.length - 1].t) {
5236
- const g = S[S.length - 1];
5237
- return [g.x, g.y, g.z];
5234
+ function Rt(f, h, S) {
5235
+ const g = f.hist;
5236
+ if (g.length === 0) {
5237
+ const H = f.pos;
5238
+ return H && (S[0] = H[0], S[1] = H[1], S[2] = H[2]), S;
5238
5239
  }
5239
- if (h <= S[0].t) return [S[0].x, S[0].y, S[0].z];
5240
- for (let g = S.length - 1; g > 0; g--)
5241
- if (S[g - 1].t <= h) {
5242
- const x = S[g - 1], J = S[g], H = (h - x.t) / Math.max(1e-6, J.t - x.t);
5243
- return [x.x + (J.x - x.x) * H, x.y + (J.y - x.y) * H, x.z + (J.z - x.z) * H];
5240
+ let v;
5241
+ if (h >= g[g.length - 1].t)
5242
+ return v = g[g.length - 1], S[0] = v.x, S[1] = v.y, S[2] = v.z, S;
5243
+ if (h <= g[0].t)
5244
+ return v = g[0], S[0] = v.x, S[1] = v.y, S[2] = v.z, S;
5245
+ for (let H = g.length - 1; H > 0; H--)
5246
+ if (g[H - 1].t <= h) {
5247
+ const j = g[H - 1], Q = g[H], Z = (h - j.t) / Math.max(1e-6, Q.t - j.t);
5248
+ return S[0] = j.x + (Q.x - j.x) * Z, S[1] = j.y + (Q.y - j.y) * Z, S[2] = j.z + (Q.z - j.z) * Z, S;
5244
5249
  }
5245
- return [S[0].x, S[0].y, S[0].z];
5250
+ return v = g[0], S[0] = v.x, S[1] = v.y, S[2] = v.z, S;
5246
5251
  }
5247
- const Mi = 0.41421356;
5248
- function Ti() {
5249
- ze.clear();
5252
+ const Ai = 0.41421356;
5253
+ function Ui() {
5254
+ De.clear();
5250
5255
  let f = 0, h = 0;
5251
5256
  A.position[0], A.position[1], A.position[2];
5252
5257
  for (const { system: S, config: g } of l.particleSystems) {
5253
5258
  if (!g.emissionTrailEnabled || g.hidden || g.glbModelEnabled) continue;
5254
5259
  S.readbackAndProcessParticles();
5255
- const x = S.particleData, J = S.particleVelocities, H = S.activeParticles;
5256
- if (!x || !J || H <= 0) continue;
5257
- const de = g.emissionTrailMode === "particles", q = f, Ae = g.emissionTrailDuration ?? 1, y = g.opacity ?? 1, B = g.particleSize ?? 0.5, U = g.bloomIntensity || 1, I = Math.max(1, Math.min(64, g.emissionTrailSegments ?? 8)), z = g.emissionTrailShape || "straight", W = g.followSystemTranslation ?? !0, Q = S._simPosition, N = W && Q ? Q[0] : 0, Ke = W && Q ? Q[1] : 0, Ft = W && Q ? Q[2] : 0, Ue = S._simVelocity, Ot = Ue ? Ue[0] : 0, es = Ue ? Ue[1] : 0, Lt = Ue ? Ue[2] : 0, Fe = _t(g.id), Nt = !!(W && Fe && Fe.hist && Fe.hist.length > 1);
5258
- for (let et = 0; et < H; et++) {
5259
- const ye = et * 8, tt = x[ye], ft = x[ye + 1], it = x[ye + 2], ts = tt + N, is = ft + Ke, ss = it + Ft;
5260
- let Oe = x[ye + 3], Le = x[ye + 4], Ne = x[ye + 5];
5261
- const Xe = x[ye + 6], Ie = x[ye + 7];
5262
- if (Xe >= Ie || Ie <= 0) continue;
5263
- const ge = Xe / Ie;
5260
+ const v = S.particleData, H = S.particleVelocities, j = S.activeParticles;
5261
+ if (!v || !H || j <= 0) continue;
5262
+ const Q = g.emissionTrailMode === "particles", Z = f, Ae = g.emissionTrailDuration ?? 1, y = g.opacity ?? 1, B = g.particleSize ?? 0.5, U = g.bloomIntensity || 1, I = Math.max(1, Math.min(64, g.emissionTrailSegments ?? 8)), D = g.emissionTrailShape || "straight", J = g.followSystemTranslation ?? !0, K = S._simPosition, X = J && K ? K[0] : 0, it = J && K ? K[1] : 0, jt = J && K ? K[2] : 0, Ue = S._simVelocity, Yt = Ue ? Ue[0] : 0, rs = Ue ? Ue[1] : 0, Ht = Ue ? Ue[2] : 0, Oe = Mt(g.id), qt = !!(J && Oe && Oe.hist && Oe.hist.length > 1);
5263
+ for (let st = 0; st < j; st++) {
5264
+ const he = st * 8, rt = v[he], mt = v[he + 1], nt = v[he + 2], ns = rt + X, as = mt + it, os = nt + jt;
5265
+ let Le = v[he + 3], Xe = v[he + 4], ke = v[he + 5];
5266
+ const Ne = v[he + 6], Ie = v[he + 7];
5267
+ if (Ne >= Ie || Ie <= 0) continue;
5268
+ const me = Ne / Ie;
5264
5269
  if (g.colorTransitionEnabled) {
5265
- const P = g.startColor ?? [1, 0, 0], G = g.endColor ?? [0, 0, 1];
5266
- Oe = P[0] + (G[0] - P[0]) * ge, Le = P[1] + (G[1] - P[1]) * ge, Ne = P[2] + (G[2] - P[2]) * ge;
5270
+ const _ = g.startColor ?? [1, 0, 0], z = g.endColor ?? [0, 0, 1];
5271
+ Le = _[0] + (z[0] - _[0]) * me, Xe = _[1] + (z[1] - _[1]) * me, ke = _[2] + (z[2] - _[2]) * me;
5267
5272
  }
5268
- Oe = Math.min(1, Oe * U), Le = Math.min(1, Le * U), Ne = Math.min(1, Ne * U);
5269
- let ke = B;
5273
+ Le = Math.min(1, Le * U), Xe = Math.min(1, Xe * U), ke = Math.min(1, ke * U);
5274
+ let je = B;
5270
5275
  if (g.randomSize) {
5271
- const P = Math.sin(Ie * 54321.67) * 43758.5453 % 1, G = P < 0 ? P + 1 : P;
5272
- ke = (g.minSize ?? 0.1) + ((g.maxSize ?? 0.5) - (g.minSize ?? 0.1)) * G;
5276
+ const _ = Math.sin(Ie * 54321.67) * 43758.5453 % 1, z = _ < 0 ? _ + 1 : _;
5277
+ je = (g.minSize ?? 0.1) + ((g.maxSize ?? 0.5) - (g.minSize ?? 0.1)) * z;
5273
5278
  }
5274
5279
  if (g.fadeSizeEnabled) {
5275
- const P = Math.max(0.01, Math.min(10, g.sizeLifetimeSpeed ?? 1));
5276
- ke *= 1 - Math.pow(ge, 1 / P);
5280
+ const _ = Math.max(0.01, Math.min(10, g.sizeLifetimeSpeed ?? 1));
5281
+ je *= 1 - Math.pow(me, 1 / _);
5277
5282
  }
5278
5283
  if (g.increaseSizeEnabled) {
5279
- const P = Math.max(0.01, Math.min(10, g.sizeLifetimeSpeed ?? 1));
5280
- ke *= 1 + Math.pow(ge, 1 / P);
5284
+ const _ = Math.max(0.01, Math.min(10, g.sizeLifetimeSpeed ?? 1));
5285
+ je *= 1 + Math.pow(me, 1 / _);
5281
5286
  }
5282
- if (ke <= 0 || ge > 0.9) continue;
5283
- const Xt = Math.min((0.9 - ge) * (1 / 0.2), 1), kt = 0.75 * ke * Mi * Xt;
5284
- let je = y;
5285
- if (g.fadeEnabled && (je *= Math.max(0, 1 - ge)), je *= Xt, je < 0.01) continue;
5286
- const pt = et * 4, jt = J[pt], Yt = J[pt + 1], Ht = J[pt + 2], st = jt + Ot, rt = Yt + es, nt = Ht + Lt, qt = Math.sqrt(st * st + rt * rt + nt * nt);
5287
- if (qt < 1e-3) continue;
5288
- const ht = 1 / qt, Pe = st * ht, _e = rt * ht, be = nt * ht, Zt = A.right[0], $t = A.right[1], Wt = A.right[2];
5289
- let mt = Zt * Pe + $t * _e + Wt * be, re = Zt - mt * Pe, ne = $t - mt * _e, ae = Wt - mt * be, Ye = Math.sqrt(re * re + ne * ne + ae * ae);
5290
- if (Ye < 0.2) {
5291
- const P = A.up[0], G = A.up[1], Z = A.up[2], F = P * Pe + G * _e + Z * be;
5292
- re = P - F * Pe, ne = G - F * _e, ae = Z - F * be, Ye = Math.sqrt(re * re + ne * ne + ae * ae) || 1;
5287
+ if (je <= 0 || me > 0.9) continue;
5288
+ const Zt = Math.min((0.9 - me) * (1 / 0.2), 1), $t = 0.75 * je * Ai * Zt;
5289
+ let Ye = y;
5290
+ if (g.fadeEnabled && (Ye *= Math.max(0, 1 - me)), Ye *= Zt, Ye < 0.01) continue;
5291
+ const yt = st * 4, Wt = H[yt], Jt = H[yt + 1], Qt = H[yt + 2], at = Wt + Yt, ot = Jt + rs, lt = Qt + Ht, Kt = Math.sqrt(at * at + ot * ot + lt * lt);
5292
+ if (Kt < 1e-3) continue;
5293
+ const gt = 1 / Kt, ve = at * gt, Pe = ot * gt, ye = lt * gt, ei = A.right[0], ti = A.right[1], ii = A.right[2];
5294
+ let bt = ei * ve + ti * Pe + ii * ye, re = ei - bt * ve, ne = ti - bt * Pe, ae = ii - bt * ye, He = Math.sqrt(re * re + ne * ne + ae * ae);
5295
+ if (He < 0.2) {
5296
+ const _ = A.up[0], z = A.up[1], $ = A.up[2], V = _ * ve + z * Pe + $ * ye;
5297
+ re = _ - V * ve, ne = z - V * Pe, ae = $ - V * ye, He = Math.sqrt(re * re + ne * ne + ae * ae) || 1;
5293
5298
  }
5294
- re /= Ye, ne /= Ye, ae /= Ye;
5295
- const He = Math.min(Ae, Xe);
5296
- if (He < 1e-3) continue;
5297
- const Jt = g.gravityEnabled && g.gravityStrength || 0, Be = Fi, we = Oi, Re = Li;
5298
- if (g.orientToDirection && g.burstMode && Nt) {
5299
- const P = S._emitSimRotY || 0, G = Ni, Z = Xi, F = ki;
5300
- for (let E = 0; E <= I; E++) {
5301
- const O = Bt(Fe, me - E / I * He);
5302
- G[E] = O[0], Z[E] = O[1], F[E] = O[2];
5299
+ re /= He, ne /= He, ae /= He;
5300
+ const qe = Math.min(Ae, Ne);
5301
+ if (qe < 1e-3) continue;
5302
+ const si = g.gravityEnabled && g.gravityStrength || 0, _e = ki, we = Ni, Be = ji;
5303
+ if (g.orientToDirection && g.burstMode && qt) {
5304
+ const _ = S._emitSimRotY || 0, z = Yi, $ = Hi, V = qi;
5305
+ for (let C = 0; C <= I; C++) {
5306
+ const O = Rt(Oe, pe - C / I * qe, Vt);
5307
+ z[C] = O[0], $[C] = O[1], V[C] = O[2];
5303
5308
  }
5304
- for (let E = 0; E <= I; E++) {
5305
- const O = E > 0 ? E - 1 : 0, Y = E < I ? E + 1 : I;
5306
- let Me = G[O] - G[Y], Te = F[O] - F[Y];
5307
- const Se = (Math.hypot(Me, Te) > 1e-5 ? Math.atan2(Me, Te) : Math.atan2(Ot, Lt)) - P, ie = Math.cos(Se), se = Math.sin(Se), pe = E / I * He, yt = -0.5 * Jt * pe * pe;
5308
- Be[E] = ie * tt + se * it + G[E], we[E] = ft + yt + Z[E], Re[E] = -se * tt + ie * it + F[E];
5309
+ for (let C = 0; C <= I; C++) {
5310
+ const O = C > 0 ? C - 1 : 0, q = C < I ? C + 1 : I;
5311
+ let Me = z[O] - z[q], Re = V[O] - V[q];
5312
+ const ge = (Math.hypot(Me, Re) > 1e-5 ? Math.atan2(Me, Re) : Math.atan2(Yt, Ht)) - _, te = Math.cos(ge), ie = Math.sin(ge), ue = C / I * qe, St = -0.5 * si * ue * ue;
5313
+ _e[C] = te * rt + ie * nt + z[C], we[C] = mt + St + $[C], Be[C] = -ie * rt + te * nt + V[C];
5309
5314
  }
5310
- } else for (let P = 0; P <= I; P++) {
5311
- const G = P / I * He, Z = -0.5 * Jt * G * G;
5312
- if (Nt) {
5313
- const F = Bt(Fe, me - G);
5314
- Be[P] = tt - jt * G + F[0], we[P] = ft - Yt * G + Z + F[1], Re[P] = it - Ht * G + F[2];
5315
+ } else for (let _ = 0; _ <= I; _++) {
5316
+ const z = _ / I * qe, $ = -0.5 * si * z * z;
5317
+ if (qt) {
5318
+ const V = Rt(Oe, pe - z, Vt);
5319
+ _e[_] = rt - Wt * z + V[0], we[_] = mt - Jt * z + $ + V[1], Be[_] = nt - Qt * z + V[2];
5315
5320
  } else
5316
- Be[P] = ts - st * G, we[P] = is - rt * G + Z, Re[P] = ss - nt * G;
5321
+ _e[_] = ns - at * z, we[_] = as - ot * z + $, Be[_] = os - lt * z;
5317
5322
  }
5318
- if (z !== "straight") {
5319
- const P = g.emissionTrailShapeAmplitude ?? 0.1, G = g.emissionTrailShapeFrequency ?? 4, Z = g.emissionTrailShapeSpeed ?? 0;
5320
- let F = -be, E = 0, O = Pe, Y = Math.sqrt(F * F + O * O);
5321
- Y < 1e-6 && (F = 0, E = be, O = -_e, Y = Math.sqrt(F * F + E * E + O * O) || 1), F /= Y, E /= Y, O /= Y;
5322
- const Me = _e * O - be * E, Te = be * F - Pe * O, fe = Pe * E - _e * F;
5323
- for (let K = 1; K <= I; K++) {
5324
- const Se = K / I * He, ie = 2 * Math.PI * G * (me - Se) + Z * me;
5325
- let se = 0, pe = 0;
5326
- z === "zigzag" ? se = P * Math.sign(Math.sin(ie)) : z === "sine" ? se = P * Math.sin(ie) : z === "spiral" && (se = P * Math.sin(ie), pe = P * Math.cos(ie)), Be[K] += F * se + Me * pe, we[K] += E * se + Te * pe, Re[K] += O * se + fe * pe;
5323
+ if (D !== "straight") {
5324
+ const _ = g.emissionTrailShapeAmplitude ?? 0.1, z = g.emissionTrailShapeFrequency ?? 4, $ = g.emissionTrailShapeSpeed ?? 0;
5325
+ let V = -ye, C = 0, O = ve, q = Math.sqrt(V * V + O * O);
5326
+ q < 1e-6 && (V = 0, C = ye, O = -Pe, q = Math.sqrt(V * V + C * C + O * O) || 1), V /= q, C /= q, O /= q;
5327
+ const Me = Pe * O - ye * C, Re = ye * V - ve * O, ce = ve * C - Pe * V;
5328
+ for (let ee = 1; ee <= I; ee++) {
5329
+ const ge = ee / I * qe, te = 2 * Math.PI * z * (pe - ge) + $ * pe;
5330
+ let ie = 0, ue = 0;
5331
+ D === "zigzag" ? ie = _ * Math.sign(Math.sin(te)) : D === "sine" ? ie = _ * Math.sin(te) : D === "spiral" && (ie = _ * Math.sin(te), ue = _ * Math.cos(te)), _e[ee] += V * ie + Me * ue, we[ee] += C * ie + Re * ue, Be[ee] += O * ie + ce * ue;
5327
5332
  }
5328
5333
  }
5329
- if (de)
5330
- for (let P = 1; P <= I && f < R; P++) {
5331
- const G = P / I, Z = Be[P] - N, F = we[P] - Ke, E = Re[P] - Ft, O = f * 8, Y = f * 4;
5332
- V[O] = Z, V[O + 1] = F, V[O + 2] = E, V[O + 3] = Oe, V[O + 4] = Le, V[O + 5] = Ne, V[O + 6] = Xe + (Ie - Xe) * G, V[O + 7] = Ie, X[Y] = 0, X[Y + 1] = 0, X[Y + 2] = 0, X[Y + 3] = 0, j[Y] = Z, j[Y + 1] = F, j[Y + 2] = E, j[Y + 3] = 0, f++;
5334
+ if (Q)
5335
+ for (let _ = 1; _ <= I && f < E; _++) {
5336
+ const z = _ / I, $ = _e[_] - X, V = we[_] - it, C = Be[_] - jt, O = f * 8, q = f * 4;
5337
+ F[O] = $, F[O + 1] = V, F[O + 2] = C, F[O + 3] = Le, F[O + 4] = Xe, F[O + 5] = ke, F[O + 6] = Ne + (Ie - Ne) * z, F[O + 7] = Ie, k[q] = 0, k[q + 1] = 0, k[q + 2] = 0, k[q + 3] = 0, Y[q] = $, Y[q + 1] = V, Y[q + 2] = C, Y[q + 3] = 0, f++;
5333
5338
  }
5334
5339
  else
5335
- for (let P = 0; P < I && !(h + 42 > ce.length); P++) {
5336
- const G = P / I, Z = (P + 1) / I, F = Be[P], E = we[P], O = Re[P], Y = Be[P + 1], Me = we[P + 1], Te = Re[P + 1], fe = kt * (1 - G), K = kt * (1 - Z), Se = je * (1 - G) * (1 - G), ie = je * (1 - Z) * (1 - Z), se = F + re * fe, pe = E + ne * fe, yt = O + ae * fe, Qt = F - re * fe, Kt = E - ne * fe, ei = O - ae * fe, ti = Y + re * K, ii = Me + ne * K, si = Te + ae * K, rs = Y - re * K, ns = Me - ne * K, as = Te - ae * K, Ge = (os, ls, cs, us) => {
5337
- ce[h++] = os, ce[h++] = ls, ce[h++] = cs, ce[h++] = Oe, ce[h++] = Le, ce[h++] = Ne, ce[h++] = us;
5340
+ for (let _ = 0; _ < I && !(h + 42 > le.length); _++) {
5341
+ const z = _ / I, $ = (_ + 1) / I, V = _e[_], C = we[_], O = Be[_], q = _e[_ + 1], Me = we[_ + 1], Re = Be[_ + 1], ce = $t * (1 - z), ee = $t * (1 - $), ge = Ye * (1 - z) * (1 - z), te = Ye * (1 - $) * (1 - $), ie = V + re * ce, ue = C + ne * ce, St = O + ae * ce, ri = V - re * ce, ni = C - ne * ce, ai = O - ae * ce, oi = q + re * ee, li = Me + ne * ee, ci = Re + ae * ee, ls = q - re * ee, cs = Me - ne * ee, us = Re - ae * ee, ze = (ds, fs, ps, hs) => {
5342
+ le[h++] = ds, le[h++] = fs, le[h++] = ps, le[h++] = Le, le[h++] = Xe, le[h++] = ke, le[h++] = hs;
5338
5343
  };
5339
- Ge(se, pe, yt, Se), Ge(Qt, Kt, ei, Se), Ge(ti, ii, si, ie), Ge(Qt, Kt, ei, Se), Ge(rs, ns, as, ie), Ge(ti, ii, si, ie);
5344
+ ze(ie, ue, St, ge), ze(ri, ni, ai, ge), ze(oi, li, ci, te), ze(ri, ni, ai, ge), ze(ls, cs, us, te), ze(oi, li, ci, te);
5340
5345
  }
5341
5346
  }
5342
- de && f > q && ze.set(g.id, { first: q, count: f - q });
5347
+ Q && f > Z && De.set(g.id, { first: Z, count: f - Z });
5343
5348
  }
5344
- f > 0 && (r.queue.writeBuffer(k, 0, V, 0, f * 8), r.queue.writeBuffer(D, 0, X, 0, f * 4), r.queue.writeBuffer(he, 0, j, 0, f * 4)), Ve = h / 7, Ve > 0 && r.queue.writeBuffer(At, 0, ce, 0, h);
5349
+ f > 0 && (r.queue.writeBuffer(N, 0, F, 0, f * 8), r.queue.writeBuffer(G, 0, k, 0, f * 4), r.queue.writeBuffer(de, 0, Y, 0, f * 4)), Fe = h / 7, Fe > 0 && r.queue.writeBuffer(zt, 0, le, 0, h);
5345
5350
  }
5346
- const wt = () => {
5347
- r.queue.writeBuffer(T, 0, new Float32Array([1, 0, a.width, a.height, 0, 0, 0, 0])), r.queue.writeBuffer(C, 0, new Float32Array([0, 1, a.width, a.height, 0, 0, 0, 0]));
5351
+ const Tt = () => {
5352
+ r.queue.writeBuffer(M, 0, new Float32Array([1, 0, a.width, a.height, 0, 0, 0, 0])), r.queue.writeBuffer(R, 0, new Float32Array([0, 1, a.width, a.height, 0, 0, 0, 0]));
5348
5353
  };
5349
- wt();
5350
- const Rt = new Float32Array(16).fill(0);
5351
- Rt[0] = 1, r.queue.writeBuffer(_, 0, Rt);
5352
- const ee = Ws(r), le = Zs(r), {
5353
- particlePipeline: Ei,
5354
- particleAdditivePipeline: Ci,
5355
- particleDepthWritePipeline: Ai,
5356
- blurPipeline: $e,
5357
- compositePipeline: Ui,
5358
- directRenderPipeline: Mt,
5359
- finalCompositePipeline: Ii,
5360
- glbMeshPipeline: Gi
5361
- } = $s(r, c, le), Tt = r.createShaderModule({ code: `
5354
+ Tt();
5355
+ const Et = new Float32Array(16).fill(0);
5356
+ Et[0] = 1, r.queue.writeBuffer(x, 0, Et);
5357
+ const se = ir(r), fe = er(r), {
5358
+ particlePipeline: Ii,
5359
+ particleAdditivePipeline: zi,
5360
+ particleDepthWritePipeline: Gi,
5361
+ blurPipeline: We,
5362
+ compositePipeline: Di,
5363
+ directRenderPipeline: Ct,
5364
+ finalCompositePipeline: Fi,
5365
+ glbMeshPipeline: Vi
5366
+ } = tr(r, c, fe), At = r.createShaderModule({ code: `
5362
5367
  struct U { mvp: mat4x4<f32> };
5363
5368
  @group(0) @binding(0) var<uniform> u: U;
5364
5369
  struct VIn { @location(0) pos: vec3<f32>, @location(1) col: vec4<f32> };
5365
5370
  struct VOut { @builtin(position) pos: vec4<f32>, @location(0) col: vec4<f32> };
5366
5371
  @vertex fn vs(v: VIn) -> VOut { var o: VOut; o.pos = u.mvp * vec4<f32>(v.pos, 1.0); o.col = v.col; return o; }
5367
5372
  @fragment fn fs(i: VOut) -> @location(0) vec4<f32> { return i.col; }
5368
- ` }), Et = r.createBindGroupLayout({
5373
+ ` }), Ut = r.createBindGroupLayout({
5369
5374
  entries: [{ binding: 0, visibility: GPUShaderStage.VERTEX, buffer: { type: "uniform" } }]
5370
- }), Di = r.createRenderPipeline({
5371
- layout: r.createPipelineLayout({ bindGroupLayouts: [Et] }),
5375
+ }), Oi = r.createRenderPipeline({
5376
+ layout: r.createPipelineLayout({ bindGroupLayouts: [Ut] }),
5372
5377
  vertex: {
5373
- module: Tt,
5378
+ module: At,
5374
5379
  entryPoint: "vs",
5375
5380
  buffers: [{ arrayStride: 28, attributes: [
5376
5381
  { shaderLocation: 0, offset: 0, format: "float32x3" },
@@ -5378,7 +5383,7 @@ async function mr(s, t = {}) {
5378
5383
  ] }]
5379
5384
  },
5380
5385
  fragment: {
5381
- module: Tt,
5386
+ module: At,
5382
5387
  entryPoint: "fs",
5383
5388
  targets: [{ format: "rgba16float", blend: {
5384
5389
  // renders into the HDR sceneTexture
@@ -5390,17 +5395,22 @@ async function mr(s, t = {}) {
5390
5395
  // depth24plus to match the non-bloom pass; test against the resolved scene depth
5391
5396
  // (occlusion) but don't write (transparent ribbon).
5392
5397
  depthStencil: { format: "depth24plus", depthWriteEnabled: !1, depthCompare: "less-equal" }
5393
- }), Ct = 512 * 64 * 6, ce = new Float32Array(Ct * 7), At = r.createBuffer({
5394
- size: Ct * 7 * 4,
5398
+ }), It = 512 * 64 * 6, le = new Float32Array(It * 7), zt = r.createBuffer({
5399
+ size: It * 7 * 4,
5395
5400
  usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
5396
5401
  label: "ribbonBuffer"
5397
- }), zi = r.createBindGroup({
5398
- layout: Et,
5402
+ }), Li = r.createBindGroup({
5403
+ layout: Ut,
5399
5404
  entries: [{ binding: 0, resource: { buffer: b } }]
5400
5405
  });
5401
- let Ve = 0, { sceneTexture: te, bloomTexA: xe, bloomTexB: ue } = fi(r, c, a.width, a.height), ve = pi(r, a.width, a.height);
5402
- const ot = { uniformBuffer: b, appearanceUniformBuffer: M, horizontalBlurUniformBuffer: T, verticalBlurUniformBuffer: C, bloomIntensityBuffer: _ };
5403
- let We = St(r, ee, ot, { sceneTexture: te, bloomTexA: xe, bloomTexB: ue });
5406
+ let Fe = 0, { sceneTexture: be, bloomTexA: Se, bloomTexB: xe } = yi(r, c, a.width, a.height), Je = gi(r, a.width, a.height), Te, Gt, Qe, Ve;
5407
+ const Dt = () => {
5408
+ const f = (h) => h.createView();
5409
+ Te = f(be), Gt = f(Se), Qe = f(xe), Ve = f(Je);
5410
+ };
5411
+ Dt();
5412
+ const ut = { uniformBuffer: b, appearanceUniformBuffer: w, horizontalBlurUniformBuffer: M, verticalBlurUniformBuffer: R, bloomIntensityBuffer: x };
5413
+ let Ke = Pt(r, se, ut, { sceneTexture: be, bloomTexA: Se, bloomTexB: xe });
5404
5414
  const A = {
5405
5415
  mvp: new Float32Array(16),
5406
5416
  position: new Float32Array([0, 0, 10]),
@@ -5409,58 +5419,58 @@ async function mr(s, t = {}) {
5409
5419
  up: new Float32Array([0, 1, 0]),
5410
5420
  hasCamera: !1
5411
5421
  };
5412
- let me = 0, Vi = 0;
5413
- const Ee = new Float32Array(5), Ut = new Float32Array(16), Fi = new Array(65), Oi = new Array(65), Li = new Array(65), Ni = new Array(65), Xi = new Array(65), ki = new Array(65), Ce = { key: null, ms: !1, bindGroup: null };
5414
- let It = !1, lt = !0, Je = !1, Qe = null, ct = a.width, ut = a.height;
5415
- function Gt() {
5416
- const f = [te, xe, ue, ve], h = fi(r, c, a.width, a.height);
5417
- te = h.sceneTexture, xe = h.bloomTexA, ue = h.bloomTexB, ve = pi(r, a.width, a.height), wt(), d.clear(), p.resizeTextures(), We = St(r, ee, ot, { sceneTexture: te, bloomTexA: xe, bloomTexB: ue });
5422
+ let pe = 0, Xi = 0;
5423
+ const Ee = new Float32Array(5), Ft = new Float32Array(16), ki = new Array(65), Ni = new Array(65), ji = new Array(65), Yi = new Array(65), Hi = new Array(65), qi = new Array(65), Vt = [0, 0, 0], Ce = { key: null, ms: !1, bindGroup: null };
5424
+ let Ot = !1, dt = !0, et = !1, tt = null, ft = a.width, pt = a.height;
5425
+ function Lt() {
5426
+ const f = [be, Se, xe, Je], h = yi(r, c, a.width, a.height);
5427
+ be = h.sceneTexture, Se = h.bloomTexA, xe = h.bloomTexB, Je = gi(r, a.width, a.height), Dt(), Tt(), d.clear(), p.resizeTextures(), Ke = Pt(r, se, ut, { sceneTexture: be, bloomTexA: Se, bloomTexB: xe });
5418
5428
  let S = !1;
5419
5429
  const g = () => {
5420
5430
  if (!S) {
5421
5431
  S = !0, requestAnimationFrame(g);
5422
5432
  return;
5423
5433
  }
5424
- f.forEach((x) => x.destroy());
5434
+ f.forEach((v) => v.destroy());
5425
5435
  };
5426
5436
  requestAnimationFrame(g);
5427
5437
  }
5428
- function ji(f, h, S) {
5429
- A.mvp.set(er(f, h)), h && h.length >= 10 && (A.right[0] = h[0], A.right[1] = h[4], A.right[2] = h[8], A.up[0] = h[1], A.up[1] = h[5], A.up[2] = h[9]), S && (A.position[0] = S.x ?? S[0], A.position[1] = S.y ?? S[1], A.position[2] = S.z ?? S[2]), A.hasCamera = !0;
5438
+ function Zi(f, h, S) {
5439
+ A.mvp.set(ar(f, h)), h && h.length >= 10 && (A.right[0] = h[0], A.right[1] = h[4], A.right[2] = h[8], A.up[0] = h[1], A.up[1] = h[5], A.up[2] = h[9]), S && (A.position[0] = S.x ?? S[0], A.position[1] = S.y ?? S[1], A.position[2] = S.z ?? S[2]), A.hasCamera = !0;
5430
5440
  }
5431
- function Yi(f, h) {
5441
+ function $i(f, h) {
5432
5442
  A.mvp.set(f), h && (A.position[0] = h.x ?? h[0], A.position[1] = h.y ?? h[1], A.position[2] = h.z ?? h[2]), A.hasCamera = !0;
5433
5443
  }
5434
- async function dt(f) {
5435
- if (Je) {
5436
- Qe = f;
5444
+ async function ht(f) {
5445
+ if (et) {
5446
+ tt = f;
5437
5447
  return;
5438
5448
  }
5439
- Je = !0;
5449
+ et = !0;
5440
5450
  try {
5441
- for (const h in v) delete v[h];
5442
- d.clear(), p.resizeTextures(), We = St(r, ee, ot, { sceneTexture: te, bloomTexA: xe, bloomTexB: ue }), await l.replaceSystems({ systems: [], activeSystemIndex: 0 });
5451
+ for (const h in P) delete P[h];
5452
+ d.clear(), p.resizeTextures(), Ke = Pt(r, se, ut, { sceneTexture: be, bloomTexA: Se, bloomTexB: xe }), await l.replaceSystems({ systems: [], activeSystemIndex: 0 });
5443
5453
  for (const h of f)
5444
5454
  await l.addSystems(h.preset, h.position || [0, 0, 0]);
5445
5455
  for (const { config: h } of l.particleSystems)
5446
- v[h.id] || (v[h.id] = w());
5447
- lt = !0, l.respawnAllSystems();
5456
+ P[h.id] || (P[h.id] = T());
5457
+ dt = !0, l.respawnAllSystems();
5448
5458
  } finally {
5449
- if (Je = !1, Qe) {
5450
- const h = Qe;
5451
- Qe = null, dt(h);
5459
+ if (et = !1, tt) {
5460
+ const h = tt;
5461
+ tt = null, ht(h);
5452
5462
  }
5453
5463
  }
5454
5464
  }
5455
- async function Hi(f, h = [0, 0, 0]) {
5456
- return dt([{ preset: f, position: h }]);
5465
+ async function Wi(f, h = [0, 0, 0]) {
5466
+ return ht([{ preset: f, position: h }]);
5457
5467
  }
5458
- function qi(f) {
5459
- if (It || Je || !l.ready || f <= 0 || l.particleSystems.length === 0) return;
5468
+ function Ji(f) {
5469
+ if (Ot || et || !l.ready || f <= 0 || l.particleSystems.length === 0) return;
5460
5470
  const h = l.clock;
5461
5471
  if (h && (h.loop = l.loop ?? i, h.duration = l.getTotalDuration(), f = h.tick(f)), f > 0.1 && (f = 0.1), f <= 0) return;
5462
- if ((a.width !== ct || a.height !== ut) && (ct = a.width, ut = a.height, Gt()), me += f, $.length) {
5463
- for (const y of $) {
5472
+ if ((a.width !== ft || a.height !== pt) && (ft = a.width, pt = a.height, Lt()), pe += f, W.length) {
5473
+ for (const y of W) {
5464
5474
  if (y.getPosition) {
5465
5475
  const B = y.getPosition();
5466
5476
  B ? (y.pos || (y.pos = y._posBuf), Array.isArray(B) ? (y.pos[0] = B[0], y.pos[1] = B[1], y.pos[2] = B[2]) : (y.pos[0] = B.x, y.pos[1] = B.y, y.pos[2] = B.z)) : y.pos = null;
@@ -5468,128 +5478,128 @@ async function mr(s, t = {}) {
5468
5478
  y.vel = y._velBuf, y.pos && y.prevPos && y.wasActive && f > 0 ? (y.vel[0] = (y.pos[0] - y.prevPos[0]) / f, y.vel[1] = (y.pos[1] - y.prevPos[1]) / f, y.vel[2] = (y.pos[2] - y.prevPos[2]) / f) : (y.vel[0] = 0, y.vel[1] = 0, y.vel[2] = 0), y.justResumed = !!y.pos && !y.wasActive, y.justResumed && (y.hist.length = 0);
5469
5479
  }
5470
5480
  for (const { system: y, config: B } of l.particleSystems) {
5471
- const U = _t(B.id);
5481
+ const U = Mt(B.id);
5472
5482
  if (!(!U || U.historyOnly) && (B.hidden = !U.pos, U.pos)) {
5473
5483
  let I = null;
5474
5484
  if (U.orientToDirection && U.vel) {
5475
- const z = U.vel[0], W = U.vel[2];
5476
- Math.hypot(z, W) > 1e-4 && (I = [0, 0, Math.atan2(z, W)]);
5485
+ const D = U.vel[0], J = U.vel[2];
5486
+ Math.hypot(D, J) > 1e-4 && (I = [0, 0, Math.atan2(D, J)]);
5477
5487
  }
5478
5488
  y.setSimulationTransform({ position: U.pos, velocity: U.vel, rotation: I }), y.updateAppearanceUniform(), (U.justResumed || y.activeParticles === 0) && y.spawnParticles();
5479
5489
  }
5480
5490
  }
5481
- for (const y of $)
5482
- y.pos ? Ri(y, me) : y.hist.length = 0, y.prevPos = y.pos ? y.pos.slice() : null, y.wasActive = !!y.pos;
5483
- if (globalThis.__HZFX_DEBUG && (Vi++ & 63) === 0) {
5484
- const y = l.particleSystems.reduce((z, W) => z + (W.system.activeParticles | 0), 0), B = $.find((z) => z.pos), U = B ? Math.hypot(A.position[0] - B.pos[0], A.position[1] - B.pos[1], A.position[2] - B.pos[2]).toFixed(1) : "-", I = $.map((z) => `{ids:[${[...z.ids]}],pos:${z.pos ? "1" : "0"},hist:${z.hist.length}}`).join(",");
5485
- console.info(`[HZFX] movingGroups(${$.length})=[${I}] activeParticles=${y} systems=${l.particleSystems.length} ribbonVerts=${Ve} camDist=${U} t=${me.toFixed(1)}`);
5491
+ for (const y of W)
5492
+ y.pos ? Ci(y, pe) : y.hist.length = 0, y.pos ? (y._prevPosBuf[0] = y.pos[0], y._prevPosBuf[1] = y.pos[1], y._prevPosBuf[2] = y.pos[2], y.prevPos = y._prevPosBuf) : y.prevPos = null, y.wasActive = !!y.pos;
5493
+ if (globalThis.__HZFX_DEBUG && (Xi++ & 63) === 0) {
5494
+ const y = l.particleSystems.reduce((D, J) => D + (J.system.activeParticles | 0), 0), B = W.find((D) => D.pos), U = B ? Math.hypot(A.position[0] - B.pos[0], A.position[1] - B.pos[1], A.position[2] - B.pos[2]).toFixed(1) : "-", I = W.map((D) => `{ids:[${[...D.ids]}],pos:${D.pos ? "1" : "0"},hist:${D.hist.length}}`).join(",");
5495
+ console.info(`[HZFX] movingGroups(${W.length})=[${I}] activeParticles=${y} systems=${l.particleSystems.length} ribbonVerts=${Fe} camDist=${U} t=${pe.toFixed(1)}`);
5486
5496
  }
5487
5497
  }
5488
5498
  if (l.updateAllSystems(f), h ? h.loop : l.loop ?? i) {
5489
5499
  const y = l.particleSystems.length > 0 && l.particleSystems.every(({ system: B }) => B.activeParticles === 0 && !B.emitting);
5490
- (h && h.justLooped || y && lt) && l.respawnAllSystems(), lt = !y;
5500
+ (h && h.justLooped || y && dt) && l.respawnAllSystems(), dt = !y;
5491
5501
  }
5492
5502
  for (const { system: y, config: B } of l.particleSystems)
5493
5503
  B.glbModelEnabled && y.glbAnimator && (y.glbAnimator.update(f), y.updateAnimatedGLBBuffer());
5494
- r.queue.writeBuffer(b, 0, A.mvp), Ee[0] = A.position[0], Ee[1] = A.position[1], Ee[2] = A.position[2], Ee[3] = a.height / Math.max(1, a.width), Ee[4] = me, r.queue.writeBuffer(b, 64, Ee), Ti();
5495
- const g = l.particleSystems.some(({ config: y }) => y.bloomEnabled), x = r.createCommandEncoder();
5496
- let J = !1;
5504
+ r.queue.writeBuffer(b, 0, A.mvp), Ee[0] = A.position[0], Ee[1] = A.position[1], Ee[2] = A.position[2], Ee[3] = a.height / Math.max(1, a.width), Ee[4] = pe, r.queue.writeBuffer(b, 64, Ee), Ui();
5505
+ const g = l.particleSystems.some(({ config: y }) => y.bloomEnabled), v = r.createCommandEncoder();
5506
+ let H = !1;
5497
5507
  if (e)
5498
5508
  try {
5499
5509
  const y = e();
5500
5510
  if (y) {
5501
5511
  let B = null, U = null, I = !1;
5502
5512
  if (y instanceof GPUTexture ? y.width === a.width && y.height === a.height && (B = y, U = () => y.createView({ aspect: "depth-only" }), I = y.sampleCount > 1) : y.view && (B = y.view, U = () => y.view, I = !!y.multisampled), B) {
5503
- const { pipeline: z, layout: W } = m(I);
5513
+ const { pipeline: D, layout: J } = m(I);
5504
5514
  (Ce.key !== B || Ce.ms !== I) && (Ce.key = B, Ce.ms = I, Ce.bindGroup = r.createBindGroup({
5505
- layout: W,
5515
+ layout: J,
5506
5516
  entries: [{ binding: 0, resource: U() }]
5507
5517
  }));
5508
- const Q = x.beginRenderPass({
5518
+ const K = v.beginRenderPass({
5509
5519
  colorAttachments: [],
5510
- depthStencilAttachment: { view: ve.createView(), depthClearValue: 1, depthLoadOp: "clear", depthStoreOp: "store" }
5520
+ depthStencilAttachment: { view: Ve, depthClearValue: 1, depthLoadOp: "clear", depthStoreOp: "store" }
5511
5521
  });
5512
- Q.setPipeline(z), Q.setBindGroup(0, Ce.bindGroup), Q.draw(3), Q.end(), J = !0;
5522
+ K.setPipeline(D), K.setBindGroup(0, Ce.bindGroup), K.draw(3), K.end(), H = !0;
5513
5523
  }
5514
5524
  }
5515
5525
  } catch {
5516
5526
  }
5517
- const H = x.beginRenderPass({
5518
- colorAttachments: [{ view: te.createView(), loadOp: "clear", storeOp: "store", clearValue: { r: 0, g: 0, b: 0, a: 0 } }],
5519
- depthStencilAttachment: J ? { view: ve.createView(), depthLoadOp: "load", depthStoreOp: "store" } : { view: ve.createView(), depthClearValue: 1, depthLoadOp: "clear", depthStoreOp: "store" }
5527
+ const j = v.beginRenderPass({
5528
+ colorAttachments: [{ view: Te, loadOp: "clear", storeOp: "store", clearValue: { r: 0, g: 0, b: 0, a: 0 } }],
5529
+ depthStencilAttachment: H ? { view: Ve, depthLoadOp: "load", depthStoreOp: "store" } : { view: Ve, depthClearValue: 1, depthLoadOp: "clear", depthStoreOp: "store" }
5520
5530
  });
5521
5531
  for (const { system: y, config: B } of l.particleSystems)
5522
- B.bloomEnabled || B.hidden || y.activeParticles === 0 || Dt(H, y, B, !0);
5523
- if (Ve > 0 && (H.setPipeline(Di), H.setBindGroup(0, zi), H.setVertexBuffer(0, At), H.draw(Ve)), H.end(), g) {
5532
+ B.bloomEnabled || B.hidden || y.activeParticles === 0 || Xt(j, y, B);
5533
+ if (Fe > 0 && (j.setPipeline(Oi), j.setBindGroup(0, Li), j.setVertexBuffer(0, zt), j.draw(Fe)), j.end(), g) {
5524
5534
  const y = {
5525
- colorAttachments: [{ view: xe.createView(), loadOp: "clear", storeOp: "store", clearValue: { r: 0, g: 0, b: 0, a: 0 } }]
5535
+ colorAttachments: [{ view: Gt, loadOp: "clear", storeOp: "store", clearValue: { r: 0, g: 0, b: 0, a: 0 } }]
5526
5536
  }, B = {
5527
- colorAttachments: [{ view: ue.createView(), loadOp: "clear", storeOp: "store", clearValue: { r: 0, g: 0, b: 0, a: 0 } }]
5537
+ colorAttachments: [{ view: Qe, loadOp: "clear", storeOp: "store", clearValue: { r: 0, g: 0, b: 0, a: 0 } }]
5528
5538
  };
5529
5539
  for (const { system: U, config: I } of l.particleSystems) {
5530
5540
  if (!I.bloomEnabled || I.hidden || U.activeParticles === 0) continue;
5531
- const z = U.config.id, W = p.getBloomSourceTexture(z, a.width, a.height), Q = x.beginRenderPass({
5532
- colorAttachments: [{ view: W.createView(), loadOp: "clear", storeOp: "store", clearValue: { r: 0, g: 0, b: 0, a: 0 } }],
5533
- depthStencilAttachment: { view: ve.createView(), depthClearValue: 1, depthLoadOp: "load", depthStoreOp: "store" }
5541
+ const D = U.config.id, J = p.getBloomSourceTexture(D, a.width, a.height), K = v.beginRenderPass({
5542
+ colorAttachments: [{ view: J.createView(), loadOp: "clear", storeOp: "store", clearValue: { r: 0, g: 0, b: 0, a: 0 } }],
5543
+ depthStencilAttachment: { view: Ve, depthClearValue: 1, depthLoadOp: "load", depthStoreOp: "store" }
5534
5544
  });
5535
- Dt(Q, U, I, !1), Q.end(), Ut[0] = I.bloomIntensity, r.queue.writeBuffer(_, 0, Ut), d.systemBloomHorizontalBindGroups[z] || (d.systemBloomHorizontalBindGroups[z] = r.createBindGroup({
5536
- layout: le.bloomBindGroupLayout,
5545
+ Xt(K, U, I), K.end(), Ft[0] = I.bloomIntensity, r.queue.writeBuffer(x, 0, Ft), d.systemBloomHorizontalBindGroups[D] || (d.systemBloomHorizontalBindGroups[D] = r.createBindGroup({
5546
+ layout: fe.bloomBindGroupLayout,
5537
5547
  entries: [
5538
- { binding: 0, resource: ee },
5539
- { binding: 1, resource: W.createView() },
5540
- { binding: 2, resource: { buffer: T } }
5548
+ { binding: 0, resource: se },
5549
+ { binding: 1, resource: J.createView() },
5550
+ { binding: 2, resource: { buffer: M } }
5541
5551
  ]
5542
5552
  }));
5543
- let N = x.beginRenderPass(y);
5544
- N.setPipeline($e), N.setBindGroup(0, d.systemBloomHorizontalBindGroups[z]), N.draw(3), N.end(), N = x.beginRenderPass(B), N.setPipeline($e), N.setBindGroup(0, We.verticalBlurBindGroup), N.draw(3), N.end(), d.secondHorizontalBindGroups[z] || (d.secondHorizontalBindGroups[z] = r.createBindGroup({
5545
- layout: le.bloomBindGroupLayout,
5553
+ let X = v.beginRenderPass(y);
5554
+ X.setPipeline(We), X.setBindGroup(0, d.systemBloomHorizontalBindGroups[D]), X.draw(3), X.end(), X = v.beginRenderPass(B), X.setPipeline(We), X.setBindGroup(0, Ke.verticalBlurBindGroup), X.draw(3), X.end(), d.secondHorizontalBindGroups[D] || (d.secondHorizontalBindGroups[D] = r.createBindGroup({
5555
+ layout: fe.bloomBindGroupLayout,
5546
5556
  entries: [
5547
- { binding: 0, resource: ee },
5548
- { binding: 1, resource: ue.createView() },
5549
- { binding: 2, resource: { buffer: T } }
5557
+ { binding: 0, resource: se },
5558
+ { binding: 1, resource: Qe },
5559
+ { binding: 2, resource: { buffer: M } }
5550
5560
  ]
5551
- })), N = x.beginRenderPass(y), N.setPipeline($e), N.setBindGroup(0, d.secondHorizontalBindGroups[z]), N.draw(3), N.end(), N = x.beginRenderPass(B), N.setPipeline($e), N.setBindGroup(0, We.verticalBlurBindGroup), N.draw(3), N.end();
5552
- const Ke = p.getBloomCompositeTexture(z, a.width, a.height);
5553
- N = x.beginRenderPass({
5554
- colorAttachments: [{ view: Ke.createView(), loadOp: "clear", storeOp: "store", clearValue: { r: 0, g: 0, b: 0, a: 0 } }]
5555
- }), N.setPipeline(Ui), d.systemBloomCompositeBindGroups[z] || (d.systemBloomCompositeBindGroups[z] = r.createBindGroup({
5556
- layout: le.compositeBindGroupLayout,
5561
+ })), X = v.beginRenderPass(y), X.setPipeline(We), X.setBindGroup(0, d.secondHorizontalBindGroups[D]), X.draw(3), X.end(), X = v.beginRenderPass(B), X.setPipeline(We), X.setBindGroup(0, Ke.verticalBlurBindGroup), X.draw(3), X.end();
5562
+ const it = p.getBloomCompositeTexture(D, a.width, a.height);
5563
+ X = v.beginRenderPass({
5564
+ colorAttachments: [{ view: it.createView(), loadOp: "clear", storeOp: "store", clearValue: { r: 0, g: 0, b: 0, a: 0 } }]
5565
+ }), X.setPipeline(Di), d.systemBloomCompositeBindGroups[D] || (d.systemBloomCompositeBindGroups[D] = r.createBindGroup({
5566
+ layout: fe.compositeBindGroupLayout,
5557
5567
  entries: [
5558
- { binding: 0, resource: ee },
5559
- { binding: 1, resource: W.createView() },
5560
- { binding: 2, resource: ue.createView() },
5568
+ { binding: 0, resource: se },
5569
+ { binding: 1, resource: J.createView() },
5570
+ { binding: 2, resource: Qe },
5561
5571
  { binding: 3, resource: { buffer: U.bloomIntensityBuffer } }
5562
5572
  ]
5563
- })), N.setBindGroup(0, d.systemBloomCompositeBindGroups[z]), N.draw(3), N.end();
5573
+ })), X.setBindGroup(0, d.systemBloomCompositeBindGroups[D]), X.draw(3), X.end();
5564
5574
  }
5565
5575
  }
5566
- const de = p.getCombinedTexture(a.width, a.height), q = x.beginRenderPass({
5567
- colorAttachments: [{ view: de.createView(), loadOp: "clear", storeOp: "store", clearValue: { r: 0, g: 0, b: 0, a: 0 } }]
5576
+ const Q = p.getCombinedTexture(a.width, a.height), Z = v.beginRenderPass({
5577
+ colorAttachments: [{ view: Q.createView(), loadOp: "clear", storeOp: "store", clearValue: { r: 0, g: 0, b: 0, a: 0 } }]
5568
5578
  });
5569
- q.setPipeline(Mt), d.combinedInitialBindGroup || (d.combinedInitialBindGroup = r.createBindGroup({
5570
- layout: le.compositeBindGroupLayout,
5579
+ Z.setPipeline(Ct), d.combinedInitialBindGroup || (d.combinedInitialBindGroup = r.createBindGroup({
5580
+ layout: fe.compositeBindGroupLayout,
5571
5581
  entries: [
5572
- { binding: 0, resource: ee },
5573
- { binding: 1, resource: te.createView() },
5574
- { binding: 2, resource: te.createView() },
5575
- { binding: 3, resource: { buffer: _ } }
5582
+ { binding: 0, resource: se },
5583
+ { binding: 1, resource: Te },
5584
+ { binding: 2, resource: Te },
5585
+ { binding: 3, resource: { buffer: x } }
5576
5586
  ]
5577
- })), q.setBindGroup(0, d.combinedInitialBindGroup), q.draw(3);
5587
+ })), Z.setBindGroup(0, d.combinedInitialBindGroup), Z.draw(3);
5578
5588
  for (const { config: y, system: B } of l.particleSystems) {
5579
5589
  if (!y.bloomEnabled || y.hidden || B.activeParticles === 0) continue;
5580
5590
  const U = B.config.id;
5581
- q.setPipeline(Mt), d.combinedBloomCompositeBindGroups[U] || (d.combinedBloomCompositeBindGroups[U] = r.createBindGroup({
5582
- layout: le.compositeBindGroupLayout,
5591
+ Z.setPipeline(Ct), d.combinedBloomCompositeBindGroups[U] || (d.combinedBloomCompositeBindGroups[U] = r.createBindGroup({
5592
+ layout: fe.compositeBindGroupLayout,
5583
5593
  entries: [
5584
- { binding: 0, resource: ee },
5594
+ { binding: 0, resource: se },
5585
5595
  { binding: 1, resource: p.getBloomCompositeTexture(U, a.width, a.height).createView() },
5586
- { binding: 2, resource: te.createView() },
5587
- { binding: 3, resource: { buffer: _ } }
5596
+ { binding: 2, resource: Te },
5597
+ { binding: 3, resource: { buffer: x } }
5588
5598
  ]
5589
- })), q.setBindGroup(0, d.combinedBloomCompositeBindGroups[U]), q.draw(3);
5599
+ })), Z.setBindGroup(0, d.combinedBloomCompositeBindGroups[U]), Z.draw(3);
5590
5600
  }
5591
- q.end();
5592
- const Ae = x.beginRenderPass({
5601
+ Z.end();
5602
+ const Ae = v.beginRenderPass({
5593
5603
  colorAttachments: [{
5594
5604
  view: n.getCurrentTexture().createView(),
5595
5605
  loadOp: o ? "load" : "clear",
@@ -5597,117 +5607,104 @@ async function mr(s, t = {}) {
5597
5607
  clearValue: { r: 0, g: 0, b: 0, a: 0 }
5598
5608
  }]
5599
5609
  });
5600
- Ae.setPipeline(Ii), d.finalBindGroup || (d.finalBindGroup = r.createBindGroup({
5601
- layout: le.compositeBindGroupLayout,
5610
+ Ae.setPipeline(Fi), d.finalBindGroup || (d.finalBindGroup = r.createBindGroup({
5611
+ layout: fe.compositeBindGroupLayout,
5602
5612
  entries: [
5603
- { binding: 0, resource: ee },
5604
- { binding: 1, resource: de.createView() },
5605
- { binding: 2, resource: te.createView() },
5606
- { binding: 3, resource: { buffer: _ } }
5613
+ { binding: 0, resource: se },
5614
+ { binding: 1, resource: Q.createView() },
5615
+ { binding: 2, resource: Te },
5616
+ { binding: 3, resource: { buffer: x } }
5607
5617
  ]
5608
- })), Ae.setBindGroup(0, d.finalBindGroup), Ae.draw(3), Ae.end(), r.queue.submit([x.finish()]);
5609
- }
5610
- function Dt(f, h, S, g) {
5611
- const x = h.config.id, J = S.glbModelEnabled && h.glbMeshData;
5612
- let H;
5613
- if (g) {
5614
- const q = !d.systemBindGroups[x] || d.textureStates[x] !== S.textureEnabled || d.textureRefs[x] !== h.particleTexture;
5615
- d.textureStates[x] = S.textureEnabled, d.textureRefs[x] = h.particleTexture, q && (d.systemBindGroups[x] = r.createBindGroup({
5616
- layout: le.particleBindGroupLayout,
5617
- entries: [
5618
- { binding: 0, resource: { buffer: b } },
5619
- { binding: 1, resource: { buffer: h.appearanceUniformBuffer } },
5620
- { binding: 2, resource: h.particleTexture.createView() },
5621
- { binding: 3, resource: ee }
5622
- ]
5623
- })), H = d.systemBindGroups[x];
5624
- } else
5625
- H = r.createBindGroup({
5626
- layout: le.particleBindGroupLayout,
5627
- entries: [
5628
- { binding: 0, resource: { buffer: b } },
5629
- { binding: 1, resource: { buffer: h.appearanceUniformBuffer } },
5630
- { binding: 2, resource: h.particleTexture.createView() },
5631
- { binding: 3, resource: ee }
5632
- ]
5633
- });
5634
- const de = S.shapeDisplay !== !1;
5635
- if (J)
5636
- de && (f.setPipeline(Gi), f.setBindGroup(0, H), f.setVertexBuffer(0, h.glbVertexBuffer), f.setVertexBuffer(1, h.instanceBuffer), f.setVertexBuffer(2, h.velocityBuffer), f.setIndexBuffer(h.glbIndexBuffer, h.glbIndexFormat), f.drawIndexed(h.glbIndexCount, h.activeParticles));
5618
+ })), Ae.setBindGroup(0, d.finalBindGroup), Ae.draw(3), Ae.end(), r.queue.submit([v.finish()]);
5619
+ }
5620
+ function Xt(f, h, S) {
5621
+ const g = h.config.id, v = S.glbModelEnabled && h.glbMeshData, H = !d.systemBindGroups[g] || d.textureStates[g] !== S.textureEnabled || d.textureRefs[g] !== h.particleTexture;
5622
+ d.textureStates[g] = S.textureEnabled, d.textureRefs[g] = h.particleTexture, H && (d.systemBindGroups[g] = r.createBindGroup({
5623
+ layout: fe.particleBindGroupLayout,
5624
+ entries: [
5625
+ { binding: 0, resource: { buffer: b } },
5626
+ { binding: 1, resource: { buffer: h.appearanceUniformBuffer } },
5627
+ { binding: 2, resource: h.particleTexture.createView() },
5628
+ { binding: 3, resource: se }
5629
+ ]
5630
+ }));
5631
+ const j = d.systemBindGroups[g], Q = S.shapeDisplay !== !1;
5632
+ if (v)
5633
+ Q && (f.setPipeline(Vi), f.setBindGroup(0, j), f.setVertexBuffer(0, h.glbVertexBuffer), f.setVertexBuffer(1, h.instanceBuffer), f.setVertexBuffer(2, h.velocityBuffer), f.setIndexBuffer(h.glbIndexBuffer, h.glbIndexFormat), f.drawIndexed(h.glbIndexCount, h.activeParticles));
5637
5634
  else {
5638
- f.setPipeline(S.blendMode === "additive" ? Ci : Ei), f.setIndexBuffer(L, "uint16"), v[x] || (v[x] = w()), f.setVertexBuffer(0, v[x]), f.setBindGroup(0, H), de && (f.setVertexBuffer(1, h.instanceBuffer), f.setVertexBuffer(2, h.velocityBuffer), f.setVertexBuffer(3, h.trailBuffer), f.drawIndexed(6, h.activeParticles));
5639
- const q = ze.get(x);
5640
- q && (f.setVertexBuffer(1, k), f.setVertexBuffer(2, D), f.setVertexBuffer(3, he), f.drawIndexed(6, q.count, 0, 0, q.first)), de && S.depthWriteEnabled && (f.setPipeline(Ai), f.drawIndexed(6, h.activeParticles));
5635
+ f.setPipeline(S.blendMode === "additive" ? zi : Ii), f.setIndexBuffer(L, "uint16"), P[g] || (P[g] = T()), f.setVertexBuffer(0, P[g]), f.setBindGroup(0, j), Q && (f.setVertexBuffer(1, h.instanceBuffer), f.setVertexBuffer(2, h.velocityBuffer), f.setVertexBuffer(3, h.trailBuffer), f.drawIndexed(6, h.activeParticles));
5636
+ const Z = De.get(g);
5637
+ Z && (f.setVertexBuffer(1, N), f.setVertexBuffer(2, G), f.setVertexBuffer(3, de), f.drawIndexed(6, Z.count, 0, 0, Z.first)), Q && S.depthWriteEnabled && (f.setPipeline(Gi), f.drawIndexed(6, h.activeParticles));
5641
5638
  }
5642
5639
  }
5643
- function Zi() {
5644
- ct = a.width, ut = a.height, Gt();
5640
+ function Qi() {
5641
+ ft = a.width, pt = a.height, Lt();
5645
5642
  }
5646
- function $i() {
5643
+ function Ki() {
5647
5644
  d.clear();
5648
5645
  }
5649
- function Wi() {
5650
- It = !0, l.destroy(), [te, xe, ue, ve].forEach((f) => f == null ? void 0 : f.destroy()), p.resizeTextures(), [
5646
+ function es() {
5647
+ Ot = !0, l.destroy(), [be, Se, xe, Je].forEach((f) => f == null ? void 0 : f.destroy()), p.resizeTextures(), [
5651
5648
  b,
5649
+ w,
5652
5650
  M,
5653
- T,
5654
- C,
5655
- _,
5651
+ R,
5652
+ x,
5656
5653
  L,
5657
- k,
5658
- D,
5659
- he
5660
- ].forEach((f) => f == null ? void 0 : f.destroy()), Object.values(v).forEach((f) => f == null ? void 0 : f.destroy());
5654
+ N,
5655
+ G,
5656
+ de
5657
+ ].forEach((f) => f == null ? void 0 : f.destroy()), Object.values(P).forEach((f) => f == null ? void 0 : f.destroy());
5661
5658
  }
5662
- async function zt(f, h) {
5659
+ async function kt(f, h) {
5663
5660
  const S = await l.addSystems(f, h);
5664
5661
  for (const { config: g } of l.particleSystems)
5665
- v[g.id] || (v[g.id] = w());
5662
+ P[g.id] || (P[g.id] = T());
5666
5663
  return l.respawnAllSystems(), new Set(Array.isArray(S) ? S : []);
5667
5664
  }
5668
- function Vt(f) {
5665
+ function Nt(f) {
5669
5666
  for (const h of f) {
5670
5667
  const S = l.particleSystems.findIndex((g) => g.config.id === h);
5671
5668
  S >= 0 && l.removeSystem(S);
5672
5669
  }
5673
5670
  }
5674
- async function Ji(f, h = [0, 0, 0]) {
5675
- const S = await zt(f, h);
5671
+ async function ts(f, h = [0, 0, 0]) {
5672
+ const S = await kt(f, h);
5676
5673
  return { remove() {
5677
- Vt(S);
5674
+ Nt(S);
5678
5675
  } };
5679
5676
  }
5680
- async function Qi(f, h = {}) {
5681
- const S = await zt(f, [0, 0, 0]);
5677
+ async function is(f, h = {}) {
5678
+ const S = await kt(f, [0, 0, 0]);
5682
5679
  globalThis.__HZFX_DEBUG && console.info(`[HZFX] addMovingEmitter: presetSystems=${(f && f.systems || []).length} newIds=[${[...S]}]`);
5683
- const g = { ids: S, pos: null, hist: [], getPosition: h.getPosition || null, orientToDirection: !!h.orientToDirection, _posBuf: [0, 0, 0], _velBuf: [0, 0, 0] };
5684
- return $.push(g), {
5685
- setPosition(x) {
5686
- x && (g.pos = Array.isArray(x) ? [x[0], x[1], x[2]] : [x.x, x.y, x.z]);
5680
+ const g = { ids: S, pos: null, hist: [], getPosition: h.getPosition || null, orientToDirection: !!h.orientToDirection, _posBuf: [0, 0, 0], _velBuf: [0, 0, 0], _prevPosBuf: [0, 0, 0] };
5681
+ return W.push(g), {
5682
+ setPosition(v) {
5683
+ v && (g.pos = Array.isArray(v) ? [v[0], v[1], v[2]] : [v.x, v.y, v.z]);
5687
5684
  },
5688
- setOrientToDirection(x) {
5689
- g.orientToDirection = !!x;
5685
+ setOrientToDirection(v) {
5686
+ g.orientToDirection = !!v;
5690
5687
  },
5691
5688
  remove() {
5692
- Vt(S);
5693
- const x = $.indexOf(g);
5694
- x >= 0 && $.splice(x, 1);
5689
+ Nt(S);
5690
+ const v = W.indexOf(g);
5691
+ v >= 0 && W.splice(v, 1);
5695
5692
  }
5696
5693
  };
5697
5694
  }
5698
- function Ki(f, h) {
5699
- const g = { ids: f instanceof Set ? f : new Set(f), pos: null, hist: [], getPosition: h, historyOnly: !0, _posBuf: [0, 0, 0], _velBuf: [0, 0, 0] };
5700
- return $.push(g), {
5695
+ function ss(f, h) {
5696
+ const g = { ids: f instanceof Set ? f : new Set(f), pos: null, hist: [], getPosition: h, historyOnly: !0, _posBuf: [0, 0, 0], _velBuf: [0, 0, 0], _prevPosBuf: [0, 0, 0] };
5697
+ return W.push(g), {
5701
5698
  remove() {
5702
- const x = $.indexOf(g);
5703
- x >= 0 && $.splice(x, 1);
5699
+ const v = W.indexOf(g);
5700
+ v >= 0 && W.splice(v, 1);
5704
5701
  },
5705
5702
  // Update which systems this history group covers WITHOUT losing the accumulated path
5706
5703
  // history. Needed when the scene's systems change (e.g. duplicate/add/remove) while the
5707
5704
  // group is active — otherwise a newly-added system's id isn't in the set and its trail
5708
5705
  // can't follow the recorded movement path (it falls back to straight extrapolation).
5709
- setIds(x) {
5710
- g.ids = x instanceof Set ? x : new Set(x);
5706
+ setIds(v) {
5707
+ g.ids = v instanceof Set ? v : new Set(v);
5711
5708
  }
5712
5709
  };
5713
5710
  }
@@ -5715,77 +5712,85 @@ async function mr(s, t = {}) {
5715
5712
  manager: l,
5716
5713
  device: r,
5717
5714
  context: n,
5718
- setCamera: ji,
5719
- setCameraMVP: Yi,
5720
- setEmitters: dt,
5721
- loadPreset: Hi,
5722
- addEmitter: Ji,
5723
- addMovingEmitter: Qi,
5724
- render: qi,
5725
- resize: Zi,
5726
- clearCaches: $i,
5727
- trackHistoryGroup: Ki,
5728
- destroy: Wi
5715
+ setCamera: Zi,
5716
+ setCameraMVP: $i,
5717
+ setEmitters: ht,
5718
+ loadPreset: Wi,
5719
+ addEmitter: ts,
5720
+ addMovingEmitter: is,
5721
+ render: Ji,
5722
+ resize: Qi,
5723
+ clearCaches: Ki,
5724
+ trackHistoryGroup: ss,
5725
+ destroy: es
5729
5726
  };
5730
5727
  }
5731
- function yr(s) {
5728
+ function Pr(s) {
5732
5729
  return () => {
5733
- var t, e, i, r, n, a;
5730
+ var t, e, i, r, n, a, o, c;
5734
5731
  try {
5735
- const o = s.backend;
5736
- if (!o) return null;
5737
- if (s.needsFrameBufferTarget && s._frameBufferTarget) {
5738
- const u = (i = (e = (t = s._textures) == null ? void 0 : t.get) == null ? void 0 : e.call(t, s._frameBufferTarget)) == null ? void 0 : i.depthTexture, m = u ? (r = o.get(u)) == null ? void 0 : r.texture : null;
5739
- if (m && m.width === s.domElement.width && m.height === s.domElement.height) return m;
5732
+ const l = s.backend;
5733
+ if (!l) return null;
5734
+ const u = s.domElement.width, m = s.domElement.height, p = (typeof s._getFrameBufferTarget == "function" ? s._getFrameBufferTarget() : null) || s._frameBufferTarget || null;
5735
+ if (s.needsFrameBufferTarget && p) {
5736
+ const w = l.get(p), M = ((i = (e = (t = s._textures) == null ? void 0 : t.get) == null ? void 0 : e.call(t, p)) == null ? void 0 : i.depthTexture) || p.depthTexture, R = [
5737
+ (r = w == null ? void 0 : w.depthTexture) == null ? void 0 : r.texture,
5738
+ w == null ? void 0 : w.depthTexture,
5739
+ (n = w == null ? void 0 : w.depthBuffer) == null ? void 0 : n.texture,
5740
+ M ? (a = l.get(M)) == null ? void 0 : a.texture : null
5741
+ ];
5742
+ for (const x of R)
5743
+ if (x && typeof x.createView == "function" && x.width === u && x.height === m) return x;
5744
+ return null;
5740
5745
  }
5741
- const c = s.getCanvasTarget ? o.get(s.getCanvasTarget()) : null, l = ((a = (n = c == null ? void 0 : c.descriptor) == null ? void 0 : n.depthStencilAttachment) == null ? void 0 : a.view) ?? null;
5742
- return l ? { view: l, multisampled: (s.currentSamples ?? 0) > 1 } : null;
5746
+ const d = s.getCanvasTarget ? l.get(s.getCanvasTarget()) : null, b = ((c = (o = d == null ? void 0 : d.descriptor) == null ? void 0 : o.depthStencilAttachment) == null ? void 0 : c.view) ?? null;
5747
+ return b ? { view: b, multisampled: (s.currentSamples ?? 0) > 1 } : null;
5743
5748
  } catch {
5744
5749
  return null;
5745
5750
  }
5746
5751
  };
5747
5752
  }
5748
5753
  export {
5749
- Vs as GLBAnimator,
5750
- Fs as HZClock,
5751
- or as Objects3DManager,
5752
- ds as ParticleEmitter,
5753
- Ss as ParticlePhysics,
5754
- ri as ParticleScript,
5755
- bt as ParticleSystem,
5756
- js as ParticleSystemManager,
5757
- xs as ParticleTextureManager,
5758
- ps as blurShader,
5759
- hs as compositeShader,
5760
- Zs as createBindGroupLayouts,
5761
- St as createBindGroups,
5762
- De as createBuffer,
5763
- Js as createCubeGeometry,
5764
- pi as createDepthTexture,
5765
- ur as createLookAtMatrix,
5766
- dr as createProjectionMatrix,
5767
- $s as createRenderPipelines,
5768
- fi as createRenderTextures,
5769
- Ws as createSampler,
5770
- Qs as createSphereGeometry,
5771
- ms as directRenderShader,
5772
- ai as extractGLBTexture,
5773
- hr as fetchPreset,
5774
- qs as glbMeshParticleShader,
5775
- lr as hexToRgb,
5776
- mr as initHzFxOverlay,
5777
- Ys as initWebGPU,
5778
- Bi as isHZFX,
5779
- pr as loadScene,
5780
- yr as makeThreeSceneDepth,
5781
- er as multiplyMatrices,
5782
- Hs as object3dShader,
5783
- ir as packHZFX,
5784
- Rs as parseGLB,
5785
- gs as particlePhysicsShader,
5786
- fs as particleShader,
5787
- cr as rgbToHex,
5788
- fr as saveScene,
5789
- rr as serializeSystemConfig,
5790
- wi as unpackHZFX
5754
+ Ns as GLBAnimator,
5755
+ js as HZClock,
5756
+ pr as Objects3DManager,
5757
+ ms as ParticleEmitter,
5758
+ _s as ParticlePhysics,
5759
+ ui as ParticleScript,
5760
+ vt as ParticleSystem,
5761
+ Ws as ParticleSystemManager,
5762
+ ws as ParticleTextureManager,
5763
+ gs as blurShader,
5764
+ bs as compositeShader,
5765
+ er as createBindGroupLayouts,
5766
+ Pt as createBindGroups,
5767
+ Ge as createBuffer,
5768
+ sr as createCubeGeometry,
5769
+ gi as createDepthTexture,
5770
+ yr as createLookAtMatrix,
5771
+ gr as createProjectionMatrix,
5772
+ tr as createRenderPipelines,
5773
+ yi as createRenderTextures,
5774
+ ir as createSampler,
5775
+ rr as createSphereGeometry,
5776
+ Ss as directRenderShader,
5777
+ fi as extractGLBTexture,
5778
+ xr as fetchPreset,
5779
+ Ks as glbMeshParticleShader,
5780
+ hr as hexToRgb,
5781
+ vr as initHzFxOverlay,
5782
+ Js as initWebGPU,
5783
+ Ti as isHZFX,
5784
+ Sr as loadScene,
5785
+ Pr as makeThreeSceneDepth,
5786
+ ar as multiplyMatrices,
5787
+ Qs as object3dShader,
5788
+ lr as packHZFX,
5789
+ Cs as parseGLB,
5790
+ vs as particlePhysicsShader,
5791
+ ys as particleShader,
5792
+ mr as rgbToHex,
5793
+ br as saveScene,
5794
+ ur as serializeSystemConfig,
5795
+ Ei as unpackHZFX
5791
5796
  };