@adatechnology/game-destruction-three 0.24.4 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -50,8 +50,13 @@ var GameDestructionThree = (() => {
50
50
  IMPACT_SOUND_KEYS: () => IMPACT_SOUND_KEYS,
51
51
  ROCKET_MOTOR_LOOP: () => ROCKET_MOTOR_LOOP,
52
52
  SCENE_SOUNDS: () => SCENE_SOUNDS,
53
+ SETTLED_BATCH_DEFAULTS: () => SETTLED_BATCH_DEFAULTS,
54
+ SETTLED_BATCH_ORIGIN: () => SETTLED_BATCH_ORIGIN,
53
55
  SMOKE_HISS_LOOP: () => SMOKE_HISS_LOOP,
56
+ SUGGESTED_MAX_AWAKE_FRAGMENTS: () => SUGGESTED_MAX_AWAKE_FRAGMENTS,
57
+ SUGGESTED_MAX_AWAKE_PIECES: () => SUGGESTED_MAX_AWAKE_PIECES,
54
58
  blastFireSampleBank: () => blastFireSampleBank,
59
+ blastSoundIds: () => blastSoundIds,
55
60
  breakSoundKeys: () => breakSoundKeys,
56
61
  createDestructionRenderer: () => createDestructionRenderer,
57
62
  createDestructionSound: () => createDestructionSound,
@@ -1346,7 +1351,8 @@ var GameDestructionThree = (() => {
1346
1351
  trail: 0,
1347
1352
  glow: null,
1348
1353
  rng: placeholder,
1349
- outColor: [0, 0, 0]
1354
+ outColor: [0, 0, 0],
1355
+ source: void 0
1350
1356
  }),
1351
1357
  freezeFollowingGlow
1352
1358
  );
@@ -1448,7 +1454,8 @@ var GameDestructionThree = (() => {
1448
1454
  outY: 0,
1449
1455
  outZ: 0,
1450
1456
  outSize: 0,
1451
- outIntensity: 0
1457
+ outIntensity: 0,
1458
+ source: void 0
1452
1459
  }));
1453
1460
  }
1454
1461
  function spawnGlow(pool, init) {
@@ -1468,6 +1475,7 @@ var GameDestructionThree = (() => {
1468
1475
  glow.fx = init.fx ?? 0;
1469
1476
  glow.fy = init.fy ?? 0;
1470
1477
  glow.fz = init.fz ?? 0;
1478
+ glow.source = init.source;
1471
1479
  return glow;
1472
1480
  }
1473
1481
  function ageOrKeep(glow, dt) {
@@ -1751,7 +1759,8 @@ var GameDestructionThree = (() => {
1751
1759
  rng: placeholder,
1752
1760
  age: 0,
1753
1761
  heat: 0,
1754
- size: 0
1762
+ size: 0,
1763
+ source: void 0
1755
1764
  }));
1756
1765
  }
1757
1766
  function spawnPuff(pool, random, init) {
@@ -1784,6 +1793,7 @@ var GameDestructionThree = (() => {
1784
1793
  puff3.age = 0;
1785
1794
  puff3.heat = 0;
1786
1795
  puff3.size = 0;
1796
+ puff3.source = init.source;
1787
1797
  return puff3;
1788
1798
  }
1789
1799
  function ageOrKeep2(puff3, dt) {
@@ -1842,7 +1852,7 @@ var GameDestructionThree = (() => {
1842
1852
  var GROUND_LIFT = 0.02;
1843
1853
  var BOUNCE_SLIDE = 0.55;
1844
1854
  function createSparkPool(capacity) {
1845
- return new OrderedPool(capacity, () => ({ x: 0, y: 0, z: 0, vx: 0, vy: 0, vz: 0, t: 0, life: 0.8, w: 0.04, st: 0.035, kind: 0, drag: 0.6, g: 9.8, bounce: 0.35, age: 0 }));
1855
+ return new OrderedPool(capacity, () => ({ x: 0, y: 0, z: 0, vx: 0, vy: 0, vz: 0, t: 0, life: 0.8, w: 0.04, st: 0.035, kind: 0, drag: 0.6, g: 9.8, bounce: 0.35, age: 0, source: void 0 }));
1846
1856
  }
1847
1857
  function spawnSpark(pool, init) {
1848
1858
  const spark = pool.acquire();
@@ -1861,6 +1871,7 @@ var GameDestructionThree = (() => {
1861
1871
  spark.g = init.g ?? 9.8;
1862
1872
  spark.bounce = init.bounce ?? 0.35;
1863
1873
  spark.age = 0;
1874
+ spark.source = init.source;
1864
1875
  return spark;
1865
1876
  }
1866
1877
  function ageOrKeep3(spark, dt) {
@@ -1894,22 +1905,26 @@ var GameDestructionThree = (() => {
1894
1905
  function addPuff(core, random, init) {
1895
1906
  core.spawned.puffs++;
1896
1907
  const puff3 = spawnPuff(core.puffs, random, init);
1908
+ puff3.source = init.source ?? core.source;
1897
1909
  core.trace?.puff?.(puff3);
1898
1910
  return puff3;
1899
1911
  }
1900
1912
  function addSpark(core, init) {
1901
1913
  core.spawned.sparks++;
1902
1914
  const spark = spawnSpark(core.sparks, init);
1915
+ spark.source = init.source ?? core.source;
1903
1916
  core.trace?.spark?.(spark);
1904
1917
  return spark;
1905
1918
  }
1906
1919
  function addGlow(core, init) {
1907
1920
  const glow = spawnGlow(core.glows, init);
1921
+ glow.source = init.source ?? core.source;
1908
1922
  core.trace?.glow?.(glow);
1909
1923
  return glow;
1910
1924
  }
1911
1925
  function addChunk(core, random, init) {
1912
1926
  const chunk = spawnChunk(core.chunks, random, init);
1927
+ chunk.source = core.source;
1913
1928
  core.spawned.chunks++;
1914
1929
  if (chunk.hot && core.layers.shrapnel) {
1915
1930
  chunk.glow = addGlow(core, { follow: chunk, s: 0.35 + chunk.sx, i: 2.2, life: random.between(1, 2.2), color: HOT_GLOW_COLOR, curve: 1.5 });
@@ -1938,7 +1953,8 @@ var GameDestructionThree = (() => {
1938
1953
  fz: 0,
1939
1954
  color: SMOKE_COLORS.black,
1940
1955
  rng: placeholder,
1941
- handle: 0
1956
+ handle: 0,
1957
+ source: void 0
1942
1958
  }));
1943
1959
  }
1944
1960
  function spawnFire(pool, random, init, handle) {
@@ -1963,6 +1979,7 @@ var GameDestructionThree = (() => {
1963
1979
  fire2.color = init.color ?? SMOKE_COLORS.black;
1964
1980
  fire2.rng = random;
1965
1981
  fire2.handle = handle;
1982
+ fire2.source = init.source;
1966
1983
  return fire2;
1967
1984
  }
1968
1985
  function addFire(core, random, init, handle) {
@@ -1997,7 +2014,8 @@ var GameDestructionThree = (() => {
1997
2014
  buoy: 3.2,
1998
2015
  color: fire2.color,
1999
2016
  kind: 0,
2000
- wind: 0.4
2017
+ wind: 0.4,
2018
+ source: fire2.source
2001
2019
  });
2002
2020
  }
2003
2021
  }
@@ -2020,7 +2038,8 @@ var GameDestructionThree = (() => {
2020
2038
  drag: 0.6,
2021
2039
  buoy: 0.55,
2022
2040
  color: fire2.color,
2023
- kind: 0
2041
+ kind: 0,
2042
+ source: fire2.source
2024
2043
  });
2025
2044
  }
2026
2045
  }
@@ -2039,7 +2058,8 @@ var GameDestructionThree = (() => {
2039
2058
  st: 0.02,
2040
2059
  kind: 4,
2041
2060
  g: -0.6,
2042
- drag: 1.2
2061
+ drag: 1.2,
2062
+ source: fire2.source
2043
2063
  });
2044
2064
  }
2045
2065
  function updateFires(core, dt) {
@@ -5969,10 +5989,11 @@ var GameDestructionThree = (() => {
5969
5989
  st: 0.05,
5970
5990
  kind: 0,
5971
5991
  g: 0,
5972
- drag: 1
5992
+ drag: 1,
5993
+ source: chunk.source
5973
5994
  });
5974
5995
  if (random.next() < 0.25) {
5975
- addPuff(core, random, { x: chunk.x, y: chunk.y, z: chunk.z, s0: 0.04, s1: 0.14 + chunk.sx * 0.3, sg: 0.15, life: random.between(1, 1.6), drag: 2, buoy: 0.6, color: SMOKE_COLORS.grey, kind: 0 });
5996
+ addPuff(core, random, { x: chunk.x, y: chunk.y, z: chunk.z, s0: 0.04, s1: 0.14 + chunk.sx * 0.3, sg: 0.15, life: random.between(1, 1.6), drag: 2, buoy: 0.6, color: SMOKE_COLORS.grey, kind: 0, source: chunk.source });
5976
5997
  }
5977
5998
  }
5978
5999
  function updateChunks(core, dt) {
@@ -6028,10 +6049,11 @@ var GameDestructionThree = (() => {
6028
6049
  };
6029
6050
  }
6030
6051
  var SpriteKindPool = class {
6031
- constructor(capacity, defs, owners) {
6052
+ constructor(capacity, defs, owners, sources = { ids: /* @__PURE__ */ new Map(), next: 0 }) {
6032
6053
  __publicField2(this, "capacity", capacity);
6033
6054
  __publicField2(this, "defs", defs);
6034
6055
  __publicField2(this, "owners", owners);
6056
+ __publicField2(this, "sources", sources);
6035
6057
  __publicField2(this, "live", 0);
6036
6058
  __publicField2(this, "drawCount", 0);
6037
6059
  __publicField2(this, "position");
@@ -6050,6 +6072,7 @@ var GameDestructionThree = (() => {
6050
6072
  __publicField2(this, "alphaMul");
6051
6073
  __publicField2(this, "tag");
6052
6074
  __publicField2(this, "owner");
6075
+ __publicField2(this, "source");
6053
6076
  __publicField2(this, "colorHex");
6054
6077
  __publicField2(this, "rgbStart");
6055
6078
  __publicField2(this, "rgbEnd");
@@ -6071,6 +6094,7 @@ var GameDestructionThree = (() => {
6071
6094
  this.alphaMul = new Float32Array(n);
6072
6095
  this.tag = new Int32Array(n);
6073
6096
  this.owner = new Int32Array(n);
6097
+ this.source = new Int32Array(n);
6074
6098
  this.colorHex = new Int32Array(n);
6075
6099
  this.rgbStart = new Float32Array(n * 3);
6076
6100
  this.rgbEnd = new Float32Array(n * 3);
@@ -6097,6 +6121,7 @@ var GameDestructionThree = (() => {
6097
6121
  this.alphaMul[i] = options?.alpha ?? 1;
6098
6122
  this.tag[i] = options?.tag ?? 0;
6099
6123
  this.owner[i] = options?.owner === void 0 ? -1 : this.ownerIndex(options.owner);
6124
+ this.source[i] = options?.source === void 0 ? -1 : this.sourceIndex(options.source);
6100
6125
  this.colorHex[i] = options?.color ?? -1;
6101
6126
  this.rgbStart.set(rgb(options?.color ?? def.c0), i * 3);
6102
6127
  this.rgbEnd.set(rgb(options?.color ?? def.c1), i * 3);
@@ -6111,6 +6136,26 @@ var GameDestructionThree = (() => {
6111
6136
  if (index < 0) index = this.owners.push(name) - 1;
6112
6137
  return index;
6113
6138
  }
6139
+ sourceIndex(name) {
6140
+ let index = this.sources.ids.get(name);
6141
+ if (index === void 0) {
6142
+ index = this.sources.next++;
6143
+ this.sources.ids.set(name, index);
6144
+ }
6145
+ return index;
6146
+ }
6147
+ /** Kills the live sprites made for `source`; returns how many went. */
6148
+ clearSource(source) {
6149
+ const index = this.sources.ids.get(source);
6150
+ if (index === void 0) return 0;
6151
+ let killed = 0;
6152
+ for (let i = 0; i < this.high; i++) {
6153
+ if (!this.alive[i] || this.source[i] !== index) continue;
6154
+ this.kill(i);
6155
+ killed++;
6156
+ }
6157
+ return killed;
6158
+ }
6114
6159
  kill(i) {
6115
6160
  if (!this.alive[i]) return;
6116
6161
  this.alive[i] = 0;
@@ -6556,14 +6601,15 @@ var GameDestructionThree = (() => {
6556
6601
  __publicField2(this, "defs");
6557
6602
  __publicField2(this, "index", /* @__PURE__ */ new Map());
6558
6603
  __publicField2(this, "owners", []);
6604
+ __publicField2(this, "sources", { ids: /* @__PURE__ */ new Map(), next: 0 });
6559
6605
  __publicField2(this, "listeners", /* @__PURE__ */ new Map());
6560
6606
  const kinds = options.kinds ?? SPRITE_KINDS;
6561
6607
  this.ids = Object.keys(kinds);
6562
6608
  this.defs = this.ids.map((id) => kinds[id]);
6563
6609
  this.ids.forEach((id, at3) => this.index.set(id, at3));
6564
6610
  const additiveCapacity = Math.floor(options.capacity * 0.4);
6565
- this.additive = new SpriteKindPool(additiveCapacity, this.defs, this.owners);
6566
- this.normal = new SpriteKindPool(options.capacity - additiveCapacity, this.defs, this.owners);
6611
+ this.additive = new SpriteKindPool(additiveCapacity, this.defs, this.owners, this.sources);
6612
+ this.normal = new SpriteKindPool(options.capacity - additiveCapacity, this.defs, this.owners, this.sources);
6567
6613
  this.random = spriteRandom(options.seed);
6568
6614
  }
6569
6615
  get capacity() {
@@ -6637,9 +6683,16 @@ var GameDestructionThree = (() => {
6637
6683
  if (this.additive.live > 0 || this.additive.drawCount > 0) this.additive.update(dt, host);
6638
6684
  if (this.normal.live > 0 || this.normal.drawCount > 0) this.normal.update(dt, host);
6639
6685
  }
6686
+ /** Kills the live sprites made for `source` (`SpriteSpawnOptions.source`); returns how many went. */
6687
+ clearSource(source) {
6688
+ const killed = this.additive.clearSource(source) + this.normal.clearSource(source);
6689
+ this.sources.ids.delete(source);
6690
+ return killed;
6691
+ }
6640
6692
  clear() {
6641
6693
  this.additive.clear();
6642
6694
  this.normal.clear();
6695
+ this.sources.ids.clear();
6643
6696
  }
6644
6697
  };
6645
6698
  var TWO_PI_ROUNDED = 6.2832;
@@ -7667,7 +7720,8 @@ var GameDestructionThree = (() => {
7667
7720
  groundAt,
7668
7721
  ...options.marklessAt ? { marklessAt: options.marklessAt } : {},
7669
7722
  ...options.cratersAt ? { cratersAt: options.cratersAt } : {},
7670
- emit: (request) => options.onRequest?.(request)
7723
+ emit: (request) => options.onRequest?.(request),
7724
+ source: void 0
7671
7725
  };
7672
7726
  function definitionOf(id) {
7673
7727
  return explosions[id] ?? explosions[aliases[id] ?? ""];
@@ -7678,7 +7732,13 @@ var GameDestructionThree = (() => {
7678
7732
  return streamFor(seed ?? Math.imul(handles.events, AUTO_SEED) + (options.seed ?? 0));
7679
7733
  }
7680
7734
  function detonate(def, point, call3) {
7681
- composeExplosion(core, def, { x: point[0], y: point[1], z: point[2], direction: call3.direction, random: call3.random, handle: call3.handle });
7735
+ const outer = core.source;
7736
+ core.source = call3.source;
7737
+ try {
7738
+ composeExplosion(core, def, { x: point[0], y: point[1], z: point[2], direction: call3.direction, random: call3.random, handle: call3.handle });
7739
+ } finally {
7740
+ core.source = outer;
7741
+ }
7682
7742
  }
7683
7743
  let engine;
7684
7744
  let player;
@@ -7719,8 +7779,9 @@ var GameDestructionThree = (() => {
7719
7779
  const handle = ++handles.next;
7720
7780
  const direction = explosionOptions.direction && { x: explosionOptions.direction[0], y: explosionOptions.direction[1], z: explosionOptions.direction[2] };
7721
7781
  const random = streamOf(explosionOptions.seed);
7722
- if (explosionOptions.delay) core.schedule.at(core.clock.time + explosionOptions.delay, () => detonate(def, point, { direction, random, handle }));
7723
- else detonate(def, point, { direction, random, handle });
7782
+ const source = explosionOptions.source;
7783
+ if (explosionOptions.delay) core.schedule.at(core.clock.time + explosionOptions.delay, () => detonate(def, point, { direction, random, handle, source }));
7784
+ else detonate(def, point, { direction, random, handle, source });
7724
7785
  return handle;
7725
7786
  },
7726
7787
  fire(fireOptions) {
@@ -7762,6 +7823,15 @@ var GameDestructionThree = (() => {
7762
7823
  const fires = core.fires;
7763
7824
  for (let index = fires.items.length - 1; index >= 0; index--) if (fires.items[index].handle === handle) fires.removeAt(index);
7764
7825
  },
7826
+ clearSource(source) {
7827
+ const keep = (record, gone) => record.source !== gone;
7828
+ const drop = (pool) => {
7829
+ const before = pool.count;
7830
+ pool.compact(keep, source);
7831
+ return before - pool.count;
7832
+ };
7833
+ return drop(core.fires) + drop(core.puffs) + drop(core.sparks) + drop(core.chunks) + drop(core.glows) + spriteSystem.clearSource(source);
7834
+ },
7765
7835
  setLayer(layer3, on) {
7766
7836
  layers[layer3] = on;
7767
7837
  },
@@ -7889,6 +7959,211 @@ var GameDestructionThree = (() => {
7889
7959
  street: 150
7890
7960
  };
7891
7961
  var EFFECT_STEP_SECONDS = 1 / 50;
7962
+ var BATCHED_LAYER = 30;
7963
+ var MATRIX_EPSILON = 1e-6;
7964
+ var ATTRIBUTES = ["position", "normal", "uv", "color"];
7965
+ var isShown = (object, root) => {
7966
+ for (let node = object; node; node = node.parent) {
7967
+ if (node === root) return true;
7968
+ if (!node.visible) return false;
7969
+ }
7970
+ return false;
7971
+ };
7972
+ var isBatchable = (mesh2) => {
7973
+ const flags = mesh2;
7974
+ if (flags.isInstancedMesh === true || flags.isSkinnedMesh === true || Array.isArray(mesh2.material)) return false;
7975
+ const geometry = mesh2.geometry;
7976
+ return geometry.attributes.position !== void 0 && Object.keys(geometry.morphAttributes).length === 0;
7977
+ };
7978
+ var signatureOf = (mesh2, materialKey2) => {
7979
+ const { attributes } = mesh2.geometry;
7980
+ const present = ATTRIBUTES.filter((name) => attributes[name] !== void 0).map((name) => `${name}${attributes[name].itemSize}`);
7981
+ return `${materialKey2(mesh2.material)}|${present.join(",")}|${mesh2.castShadow ? 1 : 0}${mesh2.receiveShadow ? 1 : 0}`;
7982
+ };
7983
+ var uuidOf = (material) => material.uuid;
7984
+ var sameMatrix = (a, b) => a.elements.every((value, index) => Math.abs(value - b.elements[index]) < MATRIX_EPSILON);
7985
+ function createStaticBatcher(THREE, root, options = {}) {
7986
+ const include = options.include ?? (() => true);
7987
+ const follow = options.followMeshes === true;
7988
+ root.updateMatrixWorld(true);
7989
+ const inverse = new THREE.Matrix4().copy(root.matrixWorld).invert();
7990
+ const groups = /* @__PURE__ */ new Map();
7991
+ root.traverse((object) => {
7992
+ const mesh2 = object;
7993
+ if (!mesh2.isMesh || !isShown(mesh2, root) || !isBatchable(mesh2) || !include(mesh2)) return;
7994
+ const key = signatureOf(mesh2, options.materialKey ?? uuidOf);
7995
+ groups.set(key, [...groups.get(key) ?? [], mesh2]);
7996
+ });
7997
+ const group = new THREE.Group();
7998
+ group.name = "static-batches";
7999
+ const sources = [];
8000
+ const pending = [...groups.values()].filter((meshes) => meshes.length >= 2);
8001
+ const mergeSome = (deadline) => {
8002
+ while (pending.length > 0) {
8003
+ const meshes = pending.shift();
8004
+ if (meshes.every((mesh2) => isShown(mesh2, root))) sources.push(...mergeGroup(THREE, { meshes, inverse: new THREE.Matrix4().copy(root.matrixWorld).invert(), group, follow, onBatch: options.onBatch }));
8005
+ if (performance.now() >= deadline) return;
8006
+ }
8007
+ };
8008
+ if (options.budgetMs === void 0) mergeSome(Number.POSITIVE_INFINITY);
8009
+ root.add(group);
8010
+ const scratch = new THREE.Matrix4();
8011
+ let released = 0;
8012
+ const release = (source) => {
8013
+ source.released = true;
8014
+ source.mesh.layers.mask = source.mask;
8015
+ const { index } = source.batch;
8016
+ const first = index.array[source.start];
8017
+ for (let at3 = source.start; at3 < source.start + source.count; at3++) index.array[at3] = first;
8018
+ index.needsUpdate = true;
8019
+ if (--source.batch.live === 0) source.batch.mesh.visible = false;
8020
+ released++;
8021
+ };
8022
+ const hasChanged = (source) => {
8023
+ const { mesh: mesh2 } = source;
8024
+ if (mesh2.geometry !== source.geometry || mesh2.material !== source.material || !isShown(mesh2, root)) return true;
8025
+ if (mesh2.geometry.attributes.position.version !== source.version) return true;
8026
+ if (follow || sameMatrix(mesh2.matrixWorld, source.world)) return false;
8027
+ if (!sameMatrix(scratch.multiplyMatrices(inverse, mesh2.matrixWorld), source.local)) return true;
8028
+ source.world.copy(mesh2.matrixWorld);
8029
+ return false;
8030
+ };
8031
+ return {
8032
+ group,
8033
+ update() {
8034
+ if (pending.length > 0) mergeSome(performance.now() + (options.budgetMs ?? Number.POSITIVE_INFINITY));
8035
+ const before = released;
8036
+ inverse.copy(root.matrixWorld).invert();
8037
+ for (const source of sources) if (!source.released && hasChanged(source)) release(source);
8038
+ return released - before;
8039
+ },
8040
+ stats: () => ({ batches: group.children.length, batched: sources.filter((source) => !source.released).length, released }),
8041
+ dispose() {
8042
+ for (const source of sources) if (!source.released) source.mesh.layers.mask = source.mask;
8043
+ group.removeFromParent();
8044
+ for (const child of group.children) {
8045
+ ;
8046
+ child.geometry.dispose();
8047
+ child.skeleton?.dispose();
8048
+ }
8049
+ }
8050
+ };
8051
+ }
8052
+ function copyAttribute(name, attribute, target, offset, matrix, normalMatrix) {
8053
+ const size = attribute.itemSize;
8054
+ const source = attribute.array;
8055
+ const flat = !attribute.isInterleavedBufferAttribute && source.length === attribute.count * size;
8056
+ if (name !== "position" && name !== "normal") {
8057
+ if (flat) target.set(source, offset * size);
8058
+ else for (let at3 = 0; at3 < attribute.count; at3++) for (let k = 0; k < size; k++) target[(offset + at3) * size + k] = attribute.getComponent(at3, k);
8059
+ return;
8060
+ }
8061
+ const e = (name === "position" ? matrix : normalMatrix).elements;
8062
+ const isNormal = name === "normal";
8063
+ for (let at3 = 0; at3 < attribute.count; at3++) {
8064
+ const x = attribute.getX(at3);
8065
+ const y = attribute.getY(at3);
8066
+ const z = attribute.getZ(at3);
8067
+ const out = (offset + at3) * 3;
8068
+ if (isNormal) {
8069
+ const nx = e[0] * x + e[3] * y + e[6] * z;
8070
+ const ny = e[1] * x + e[4] * y + e[7] * z;
8071
+ const nz = e[2] * x + e[5] * y + e[8] * z;
8072
+ const length = Math.hypot(nx, ny, nz) || 1;
8073
+ target[out] = nx / length;
8074
+ target[out + 1] = ny / length;
8075
+ target[out + 2] = nz / length;
8076
+ } else {
8077
+ target[out] = e[0] * x + e[4] * y + e[8] * z + e[12];
8078
+ target[out + 1] = e[1] * x + e[5] * y + e[9] * z + e[13];
8079
+ target[out + 2] = e[2] * x + e[6] * y + e[10] * z + e[14];
8080
+ }
8081
+ }
8082
+ }
8083
+ function skinnedBatch(THREE, merged, material, meshes) {
8084
+ const vertices = merged.attributes.position.count;
8085
+ const skinIndex = new Uint16Array(vertices * 4);
8086
+ const skinWeight = new Float32Array(vertices * 4);
8087
+ let at3 = 0;
8088
+ meshes.forEach((mesh22, bone) => {
8089
+ for (let k = 0; k < mesh22.geometry.attributes.position.count; k++, at3++) {
8090
+ skinIndex[at3 * 4] = bone;
8091
+ skinWeight[at3 * 4] = 1;
8092
+ }
8093
+ });
8094
+ merged.setAttribute("skinIndex", new THREE.BufferAttribute(skinIndex, 4));
8095
+ merged.setAttribute("skinWeight", new THREE.BufferAttribute(skinWeight, 4));
8096
+ const mesh2 = new THREE.SkinnedMesh(merged, material);
8097
+ const identities = meshes.map(() => new THREE.Matrix4());
8098
+ mesh2.bind(new THREE.Skeleton(meshes, identities), new THREE.Matrix4());
8099
+ mesh2.frustumCulled = false;
8100
+ return mesh2;
8101
+ }
8102
+ function mergeGroup(THREE, { meshes, inverse: rootInverse, group, follow, onBatch }) {
8103
+ const identity = new THREE.Matrix4();
8104
+ const inverse = follow ? identity : rootInverse;
8105
+ const first = meshes[0];
8106
+ const names = ATTRIBUTES.filter((name) => first.geometry.attributes[name] !== void 0);
8107
+ const pieces = meshes.map((mesh22) => {
8108
+ const local2 = new THREE.Matrix4().multiplyMatrices(inverse, mesh22.matrixWorld);
8109
+ const vertices = mesh22.geometry.attributes.position.count;
8110
+ const indexCount = mesh22.geometry.index ? mesh22.geometry.index.count : vertices;
8111
+ return { mesh: mesh22, local: local2, vertices, indexCount };
8112
+ });
8113
+ const totalVertices = pieces.reduce((sum, piece) => sum + piece.vertices, 0);
8114
+ const totalIndices = pieces.reduce((sum, piece) => sum + piece.indexCount, 0);
8115
+ const merged = new THREE.BufferGeometry();
8116
+ const normalMatrix = new THREE.Matrix3();
8117
+ for (const name of names) {
8118
+ const size = first.geometry.attributes[name].itemSize;
8119
+ const array = new Float32Array(totalVertices * size);
8120
+ let offset = 0;
8121
+ for (const piece of pieces) {
8122
+ const matrix = follow ? identity : piece.local;
8123
+ copyAttribute(name, piece.mesh.geometry.attributes[name], array, offset, matrix, normalMatrix.getNormalMatrix(matrix));
8124
+ offset += piece.vertices;
8125
+ }
8126
+ merged.setAttribute(name, new THREE.BufferAttribute(array, size));
8127
+ }
8128
+ const indexArray = totalVertices > 65535 ? new Uint32Array(totalIndices) : new Uint16Array(totalIndices);
8129
+ const indexAttribute = new THREE.BufferAttribute(indexArray, 1);
8130
+ merged.setIndex(indexAttribute);
8131
+ const mesh2 = follow ? skinnedBatch(THREE, merged, first.material, meshes) : new THREE.Mesh(merged, first.material);
8132
+ mesh2.name = `batch:${first.material.name || first.material.type}`;
8133
+ mesh2.castShadow = first.castShadow;
8134
+ mesh2.receiveShadow = first.receiveShadow;
8135
+ mesh2.raycast = () => void 0;
8136
+ merged.computeBoundingBox();
8137
+ merged.computeBoundingSphere();
8138
+ group.add(mesh2);
8139
+ onBatch?.(mesh2, meshes);
8140
+ const batch = { mesh: mesh2, live: pieces.length, index: indexAttribute };
8141
+ const sources = [];
8142
+ let vertexOffset = 0;
8143
+ let indexOffset = 0;
8144
+ for (const piece of pieces) {
8145
+ const index = piece.mesh.geometry.index;
8146
+ if (index) for (let at3 = 0; at3 < piece.indexCount; at3++) indexArray[indexOffset + at3] = index.getX(at3) + vertexOffset;
8147
+ else for (let at3 = 0; at3 < piece.indexCount; at3++) indexArray[indexOffset + at3] = at3 + vertexOffset;
8148
+ sources.push({
8149
+ mesh: piece.mesh,
8150
+ geometry: piece.mesh.geometry,
8151
+ material: piece.mesh.material,
8152
+ version: piece.mesh.geometry.attributes.position.version,
8153
+ local: piece.local,
8154
+ world: piece.mesh.matrixWorld.clone(),
8155
+ mask: piece.mesh.layers.mask,
8156
+ batch,
8157
+ start: indexOffset,
8158
+ count: piece.indexCount,
8159
+ released: false
8160
+ });
8161
+ piece.mesh.layers.set(BATCHED_LAYER);
8162
+ vertexOffset += piece.vertices;
8163
+ indexOffset += piece.indexCount;
8164
+ }
8165
+ return sources;
8166
+ }
7892
8167
 
7893
8168
  // ../game-vfx-three/dist/chunk-HJXLYDNY.js
7894
8169
  var GLOW_VERTEX = `attribute vec4 aP;attribute vec4 aC;varying vec2 vU;varying vec4 vC;
@@ -9687,6 +9962,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
9687
9962
  var SUPPORT_CHECKS = 32;
9688
9963
  var SUPPORT_GAP = 0.02;
9689
9964
  var SHARD_SHAPES = 6;
9965
+ var SETTLE_SECONDS = 0.4;
9966
+ var isSlow = (f) => f.vel.lengthSq() < 0.012 && f.ang.lengthSq() < 0.2;
9690
9967
  var isBig = (size) => {
9691
9968
  const [, middle, longest] = [...size].sort((a, b) => a - b);
9692
9969
  return longest >= BIG_LENGTH && middle >= BIG_WIDTH;
@@ -9727,6 +10004,10 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
9727
10004
  meshes() {
9728
10005
  return this.list.map((f) => f.mesh);
9729
10006
  }
10007
+ /** Meshes of the fragments asleep in the scene, without marks on them (a mark is a mesh of its own on the fragment). */
10008
+ restingMeshes() {
10009
+ return this.list.filter((f) => f.asleep && !f.dying && f.mesh.children.length === 0 && f.mesh.parent === this.o.scene).map((f) => f.mesh);
10010
+ }
9730
10011
  /** One shared material per source material id + colour (+ transparency). */
9731
10012
  materialFor(materialId, color, transparent, opacity = 0.5) {
9732
10013
  const key = `${materialId}:${color}:${transparent ? 1 : 0}`;
@@ -9876,6 +10157,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
9876
10157
  baseScale: sc,
9877
10158
  still: 0,
9878
10159
  asleep: false,
10160
+ contact: false,
9879
10161
  rest: 0,
9880
10162
  fade: 1,
9881
10163
  dying: false,
@@ -9969,6 +10251,28 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
9969
10251
  }
9970
10252
  this.step(f, dt, g);
9971
10253
  }
10254
+ this.keepBudget();
10255
+ }
10256
+ /** Over `maxAwake` fragments moving, the oldest at rest on what is under them sleep where they lie (`FragmentSystemOptions.maxAwake`). */
10257
+ keepBudget() {
10258
+ const most = this.o.maxAwake;
10259
+ if (most === void 0 || !Number.isFinite(most)) return;
10260
+ let awake = 0;
10261
+ for (const f of this.list) if (!f.asleep && !f.dying) awake++;
10262
+ for (const f of this.list) {
10263
+ if (awake <= most) return;
10264
+ if (f.asleep || f.dying || !f.contact || !isSlow(f)) continue;
10265
+ this.sleep(f);
10266
+ awake--;
10267
+ }
10268
+ }
10269
+ /** The fragment stops where it lies, and its matrix is no longer recomputed every frame. */
10270
+ sleep(f) {
10271
+ f.asleep = true;
10272
+ f.mesh.updateMatrix();
10273
+ f.mesh.matrixAutoUpdate = false;
10274
+ f.vel.set(0, 0, 0);
10275
+ f.ang.set(0, 0, 0);
9972
10276
  }
9973
10277
  /** A few fragments asleep each update (`SUPPORT_CHECKS`, in turn) look at the ground under them again: one left over air falls. */
9974
10278
  wakeUnsupported() {
@@ -10031,16 +10335,10 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
10031
10335
  if (f.air > 0) this.flutter(f, dt);
10032
10336
  }
10033
10337
  if (contact && f.vel.lengthSq() < 4) this.settle(f, dt);
10034
- const slow = f.vel.lengthSq() < 0.012 && f.ang.lengthSq() < 0.2;
10035
- if (contact && slow) {
10338
+ f.contact = contact;
10339
+ if (contact && isSlow(f)) {
10036
10340
  f.still += dt;
10037
- if (f.still > 0.4) {
10038
- f.asleep = true;
10039
- f.mesh.updateMatrix();
10040
- f.mesh.matrixAutoUpdate = false;
10041
- f.vel.set(0, 0, 0);
10042
- f.ang.set(0, 0, 0);
10043
- }
10341
+ if (f.still > SETTLE_SECONDS) this.sleep(f);
10044
10342
  } else {
10045
10343
  f.still = 0;
10046
10344
  }
@@ -10304,9 +10602,13 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
10304
10602
  var ROLLING_RESISTANCE = 0.015;
10305
10603
  var ROUND_LYING = Math.SQRT1_2;
10306
10604
  var SLEEP_AFTER = 0.5;
10605
+ var STILL_SPEED = 0.12;
10606
+ var STILL_SPIN = 0.45;
10307
10607
  var CALM_DRIFT = 0.01;
10308
10608
  var CALM_TURN = 0.05;
10309
10609
  var CALM_SLEEP_AFTER = 1.5;
10610
+ var STEADY_TURN = 0.1;
10611
+ var STEADY_SECONDS = 1.5;
10310
10612
  var HARD_LANDING = 3;
10311
10613
  var SLOP = 2e-3;
10312
10614
  var NARROW = 0.3;
@@ -10367,6 +10669,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
10367
10669
  rolling: Math.max(a?.rolling ?? 0, b?.rolling ?? ROLLING_RESISTANCE)
10368
10670
  });
10369
10671
  var pairRestitution = (a, b) => Math.sqrt((a ?? SLAM_BOUNCE) * (b ?? SLAM_BOUNCE));
10672
+ var turnBetween = (a, q) => 2 * Math.acos(Math.min(1, Math.abs(a[0] * q.x + a[1] * q.y + a[2] * q.z + a[3] * q.w)));
10370
10673
  var PieceSystem = class {
10371
10674
  constructor(THREE, o) {
10372
10675
  __publicField(this, "THREE", THREE);
@@ -10698,6 +11001,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
10698
11001
  if (Math.hypot(v[0], v[1], v[2]) > WAKE_ABOVE_SPEED || Math.hypot(w[0], w[1], w[2]) > WAKE_ABOVE_SPIN) this.wakeAbove(b);
10699
11002
  }
10700
11003
  this.collide(dt, only?.meets);
11004
+ this.keepBudget();
10701
11005
  }
10702
11006
  /** A few sleeping pieces each update (`SUPPORT_CHECKS`, in turn) look under them again: one whose table broke, or whose shelf fell over, falls. */
10703
11007
  wakeUnsupported() {
@@ -10705,10 +11009,13 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
10705
11009
  for (let k = 0; k < Math.min(SUPPORT_CHECKS2, n); k++) {
10706
11010
  this.supportTurn = (this.supportTurn + 1) % n;
10707
11011
  const b = this.list[this.supportTurn];
10708
- if (!b.sleeping || b.held || this.supported(b, false) || this.supported(b, true)) continue;
11012
+ if (!b.sleeping || b.held) continue;
11013
+ const rest = b.restPoints;
11014
+ if (rest && rest.length > 0 ? rest.every((point) => this.supportsPoint(b, point)) : this.supported(b, false) || this.supported(b, true)) continue;
10709
11015
  b.sleeping = false;
10710
11016
  b.still = 0;
10711
11017
  b.calmAt = null;
11018
+ b.restPoints = void 0;
10712
11019
  }
10713
11020
  }
10714
11021
  /**
@@ -11114,20 +11421,80 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
11114
11421
  b.lastHit = this.time;
11115
11422
  this.o.onHardLanding(b, landPoint, landing2);
11116
11423
  }
11117
- const still = touched && !unstable && Math.hypot(v[0], v[1], v[2]) < 0.12 && Math.hypot(w[0], w[1], w[2]) < 0.45;
11424
+ const still = touched && !unstable && Math.hypot(v[0], v[1], v[2]) < STILL_SPEED && Math.hypot(w[0], w[1], w[2]) < STILL_SPIN;
11118
11425
  if (still) b.still += dt;
11119
11426
  else b.still = 0;
11120
- if (b.still >= SLEEP_AFTER || this.staysInPlace(b, touched && !b.tipping, pos, q, dt)) {
11121
- b.sleeping = true;
11122
- b.calmAt = null;
11123
- v[0] = v[1] = v[2] = 0;
11124
- w[0] = w[1] = w[2] = 0;
11427
+ b.balancing = unstable;
11428
+ this.keepsTilt(b, q, dt);
11429
+ if (b.still >= SLEEP_AFTER || this.staysInPlace(b, touched && !b.tipping, pos, q, dt)) this.sleep(b);
11430
+ }
11431
+ /** The piece sleeps where it lies: its speeds are dropped, nothing moves it. */
11432
+ sleep(b) {
11433
+ b.restPoints = void 0;
11434
+ b.sleeping = true;
11435
+ b.calmAt = null;
11436
+ b.steady = null;
11437
+ b.velocity[0] = b.velocity[1] = b.velocity[2] = 0;
11438
+ b.angularVelocity[0] = b.angularVelocity[1] = b.angularVelocity[2] = 0;
11439
+ }
11440
+ /** How long the piece has kept its tilt (within `STEADY_TURN`): one going over leaves it within a moment, one held up at an angle keeps it. */
11441
+ keepsTilt(b, q, dt) {
11442
+ const at3 = b.steady;
11443
+ if (at3 && turnBetween(at3.quaternion, q) <= STEADY_TURN) {
11444
+ at3.seconds += dt;
11445
+ return;
11125
11446
  }
11447
+ b.steady = { quaternion: [q.x, q.y, q.z, q.w], seconds: 0 };
11448
+ }
11449
+ /**
11450
+ * Over `maxAwake` pieces awake, the oldest that have come to rest sleep where they lie: on the ground, slower than `STILL_SPEED` and `STILL_SPIN`, not falling over (`tip`),
11451
+ * and one held up at an angle (a board leaning on a seat) only once it kept its tilt for `STEADY_SECONDS`; that one sleeps then under the budget too, since nothing else puts
11452
+ * it to sleep. It keeps the points it lies on (`restPoints`) and wakes when any of them loses its support (`wakeUnsupported`): put to sleep sooner than it would have slept by
11453
+ * itself, it answers to every point that holds it.
11454
+ */
11455
+ keepBudget() {
11456
+ const most = this.o.maxAwake;
11457
+ if (most === void 0 || !Number.isFinite(most)) return;
11458
+ let awake = 0;
11459
+ for (const b of this.list) {
11460
+ if (b.sleeping || b.held) continue;
11461
+ if (b.balancing && this.hasComeToRest(b)) this.sleepByBudget(b);
11462
+ else awake++;
11463
+ }
11464
+ for (const b of this.list) {
11465
+ if (awake <= most) return;
11466
+ if (b.sleeping || b.held || !this.hasComeToRest(b)) continue;
11467
+ this.sleepByBudget(b);
11468
+ awake--;
11469
+ }
11470
+ }
11471
+ /** Sleeps sooner than it would by itself, so it answers to every point it lies on (`restPoints`). */
11472
+ sleepByBudget(b) {
11473
+ this.sleep(b);
11474
+ b.restPoints = this.restPointsOf(b);
11475
+ }
11476
+ hasComeToRest(b) {
11477
+ const v = b.velocity;
11478
+ const w = b.angularVelocity;
11479
+ if (!b.onGround || b.tipping || Math.hypot(v[0], v[1], v[2]) >= STILL_SPEED || Math.hypot(w[0], w[1], w[2]) >= STILL_SPIN) return false;
11480
+ return !b.balancing || (b.steady?.seconds ?? 0) >= STEADY_SECONDS;
11481
+ }
11482
+ /** The corners of `b` (its own frame, or its own `contacts`) that have the ground, a piece or a fixed top within `SUPPORT_GAP` under them now; the points along its edges when no corner has. */
11483
+ restPointsOf(b) {
11484
+ const corners = this.samples(b, false).filter((point) => this.supportsPoint(b, point));
11485
+ return corners.length > 0 ? corners : this.samples(b, true).filter((point) => this.supportsPoint(b, point));
11486
+ }
11487
+ /** Whether the point of `b` (its own frame) has the ground, a piece or a fixed top within `SUPPORT_GAP` under it. */
11488
+ supportsPoint(b, [sx, sy, sz]) {
11489
+ const c = this.centerOf(b, this.p);
11490
+ const e = this.m.makeRotationFromQuaternion(b.root.quaternion).elements;
11491
+ const y = c.y + e[1] * sx + e[5] * sy + e[9] * sz;
11492
+ return this.supportAt(b, c.x + e[0] * sx + e[4] * sy + e[8] * sz, y, c.z + e[2] * sx + e[6] * sy + e[10] * sz, STEP) >= y - SUPPORT_GAP2;
11126
11493
  }
11127
11494
  /** Whether the piece has kept to the same spot on the ground for `CALM_SLEEP_AFTER` (see `CALM_DRIFT`). */
11128
11495
  staysInPlace(b, touched, center, q, dt) {
11129
11496
  const at3 = b.calmAt;
11130
- const turned = at3 ? 2 * Math.acos(Math.min(1, Math.abs(at3.quaternion[0] * q.x + at3.quaternion[1] * q.y + at3.quaternion[2] * q.z + at3.quaternion[3] * q.w))) : Infinity;
11497
+ const turned = at3 ? turnBetween(at3.quaternion, q) : Infinity;
11131
11498
  if (!touched || !at3 || Math.hypot(center[0] - at3.center[0], center[1] - at3.center[1], center[2] - at3.center[2]) > CALM_DRIFT || turned > CALM_TURN) {
11132
11499
  b.calmAt = touched ? { center: [center[0], center[1], center[2]], quaternion: [q.x, q.y, q.z, q.w] } : null;
11133
11500
  b.calm = 0;
@@ -14526,7 +14893,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
14526
14893
  };
14527
14894
 
14528
14895
  // src/settlement.ts
14529
- var SETTLE_SECONDS = 1.2;
14896
+ var SETTLE_SECONDS2 = 1.2;
14530
14897
  var SETTLE_REDRAW = 0.1;
14531
14898
  var dropOf = (line, point) => line ? settlementAt(line, point) : 0;
14532
14899
  var sameLine = (a, b) => !!a && a.drop.length === b.drop.length && a.drop.every((v, k) => v === b.drop[k]) && a.from.every((v, k) => v === b.from[k]) && a.to.every((v, k) => v === b.to[k]);
@@ -14553,10 +14920,10 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
14553
14920
  update(dt) {
14554
14921
  for (const s of this.moving.values()) {
14555
14922
  s.elapsed += dt;
14556
- const done = s.elapsed >= SETTLE_SECONDS;
14923
+ const done = s.elapsed >= SETTLE_SECONDS2;
14557
14924
  if (!done && s.elapsed - s.lastDrawn < SETTLE_REDRAW) continue;
14558
14925
  s.lastDrawn = s.elapsed;
14559
- const t = Math.min(1, s.elapsed / SETTLE_SECONDS);
14926
+ const t = Math.min(1, s.elapsed / SETTLE_SECONDS2);
14560
14927
  this.draw(s, t * t * (3 - 2 * t));
14561
14928
  if (done) {
14562
14929
  s.pv.settled = s.target;
@@ -14596,6 +14963,113 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
14596
14963
  }
14597
14964
  };
14598
14965
 
14966
+ // src/settled-batches.ts
14967
+ var SETTLED_BATCH_DEFAULTS = { enabled: true, minMeshes: 16, intervalSeconds: 1, budgetMs: 2, maxVertices: 4e3 };
14968
+ var IDENTITY_KEYS = /* @__PURE__ */ new Set(["uuid", "id", "name", "version", "userData", "_listeners"]);
14969
+ var settingText = (value) => {
14970
+ if (value === null || typeof value === "number" || typeof value === "boolean" || typeof value === "string") return String(value);
14971
+ if (typeof value !== "object") return void 0;
14972
+ const described = value;
14973
+ if (described.isColor === true) return described.getHexString?.();
14974
+ if (described.isTexture === true) return described.uuid;
14975
+ if (described.isVector2 === true) return `${described.x},${described.y}`;
14976
+ if (Object.getPrototypeOf(value) === Object.prototype) {
14977
+ try {
14978
+ return JSON.stringify(value);
14979
+ } catch {
14980
+ return void 0;
14981
+ }
14982
+ }
14983
+ return void 0;
14984
+ };
14985
+ var materialKey = (material) => {
14986
+ const record = material;
14987
+ const settings = [material.type];
14988
+ for (const key of Object.keys(record).sort()) {
14989
+ if (key === "userData" && Object.keys(material.userData).length > 0) return material.uuid;
14990
+ if (IDENTITY_KEYS.has(key)) continue;
14991
+ const text = settingText(record[key]);
14992
+ if (text === void 0) return material.uuid;
14993
+ settings.push(`${key}=${text}`);
14994
+ }
14995
+ return settings.join("|");
14996
+ };
14997
+ var SETTLED_BATCH_ORIGIN = { owner: "game-destruction-three", kind: "debris" };
14998
+ var commonOrigin = (meshes) => {
14999
+ const first = kitOriginOf(meshes[0]);
15000
+ if (!first) return null;
15001
+ for (const mesh2 of meshes) {
15002
+ const origin = kitOriginOf(mesh2);
15003
+ if (!origin || origin.owner !== first.owner || origin.kind !== first.kind || origin.id !== first.id) return null;
15004
+ }
15005
+ return first;
15006
+ };
15007
+ var markBatch = (batch, meshes) => {
15008
+ const origin = commonOrigin(meshes);
15009
+ if (origin) markKitOrigin(batch, origin);
15010
+ };
15011
+ var isBatchableDebris = (mesh2, maxVertices) => {
15012
+ const material = mesh2.material;
15013
+ if (Array.isArray(material) || material.transparent) return false;
15014
+ if (mesh2.layers.isEnabled(BATCHED_LAYER)) return false;
15015
+ return (mesh2.geometry.attributes.position?.count ?? Infinity) <= maxVertices;
15016
+ };
15017
+ var SettledBatches = class {
15018
+ constructor(THREE, scene2, options = {}) {
15019
+ __publicField(this, "THREE", THREE);
15020
+ __publicField(this, "scene", scene2);
15021
+ __publicField(this, "options");
15022
+ __publicField(this, "batcher", null);
15023
+ /** The meshes given to the batcher when it was made. */
15024
+ __publicField(this, "members", /* @__PURE__ */ new Set());
15025
+ __publicField(this, "sinceMade", Infinity);
15026
+ this.options = { ...SETTLED_BATCH_DEFAULTS, ...options };
15027
+ }
15028
+ /** Gives back to its own draw whatever changed, and makes the batches again when `atRest` (the debris meshes at rest) has enough outside them. Once per frame, after the bodies moved. */
15029
+ update(dt, atRest) {
15030
+ this.batcher?.update();
15031
+ this.sinceMade += dt;
15032
+ if (!this.options.enabled || this.sinceMade < this.options.intervalSeconds) return;
15033
+ const meshes = atRest().filter((mesh2) => isBatchableDebris(mesh2, this.options.maxVertices) || this.batched(mesh2));
15034
+ const outside = meshes.length - (this.batcher?.stats().batched ?? 0);
15035
+ if (outside < this.options.minMeshes) return;
15036
+ this.make(meshes);
15037
+ }
15038
+ stats() {
15039
+ const stats = this.batcher?.stats();
15040
+ return { batches: this.batcher ? this.batcher.group.children.filter((child) => child.visible).length : 0, batched: stats?.batched ?? 0 };
15041
+ }
15042
+ /**
15043
+ * Something happened to one of `meshes` (a blow, fire, char): if any is drawn by a batch, every mesh draws on its own again at once and the batches are made again after
15044
+ * `intervalSeconds`. A change the batcher cannot see (a colour written in place) never shows late.
15045
+ */
15046
+ release(meshes) {
15047
+ if (this.members.size === 0 || !meshes.some((mesh2) => this.batched(mesh2))) return;
15048
+ this.clear();
15049
+ this.sinceMade = 0;
15050
+ }
15051
+ /** Every debris mesh draws on its own again and the batches are disposed. */
15052
+ clear() {
15053
+ this.batcher?.dispose();
15054
+ this.batcher = null;
15055
+ this.members = /* @__PURE__ */ new Set();
15056
+ this.sinceMade = Infinity;
15057
+ }
15058
+ /** Drawn by one of these batches now (given to it, and not given back). */
15059
+ batched(mesh2) {
15060
+ return this.members.has(mesh2) && mesh2.layers.isEnabled(BATCHED_LAYER);
15061
+ }
15062
+ make(meshes) {
15063
+ this.batcher?.dispose();
15064
+ const take = new Set(meshes);
15065
+ this.members = take;
15066
+ this.batcher = createStaticBatcher(this.THREE, this.scene, { include: (mesh2) => take.has(mesh2), budgetMs: this.options.budgetMs, materialKey, onBatch: markBatch });
15067
+ this.batcher.group.name = "settled-debris-batches";
15068
+ markKitOrigin(this.batcher.group, SETTLED_BATCH_ORIGIN);
15069
+ this.sinceMade = 0;
15070
+ }
15071
+ };
15072
+
14599
15073
  // src/emitter-anchor.ts
14600
15074
  function anchorOnMesh(THREE, mv, point, normal) {
14601
15075
  mv.mesh.updateWorldMatrix(true, false);
@@ -14618,8 +15092,32 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
14618
15092
  return true;
14619
15093
  }
14620
15094
 
15095
+ // src/vfx-source.ts
15096
+ function stampSource(vfx, current) {
15097
+ const stamped = Object.create(vfx);
15098
+ stamped.burst = (kind, point, normal, count, speed, options) => {
15099
+ const source = current();
15100
+ vfx.burst(kind, point, normal, count, speed, source === void 0 || options?.source !== void 0 ? options : { ...options, source });
15101
+ };
15102
+ stamped.spawn = (kind, point, velocity, options) => {
15103
+ const source = current();
15104
+ vfx.spawn(kind, point, velocity, source === void 0 || options?.source !== void 0 ? options : { ...options, source });
15105
+ };
15106
+ stamped.explosion = (id, point, options) => {
15107
+ const source = current();
15108
+ return vfx.explosion(id, point, source === void 0 || options?.source !== void 0 ? options : { ...options, source });
15109
+ };
15110
+ stamped.fire = (options) => {
15111
+ const source = current();
15112
+ return vfx.fire(source === void 0 || options.source !== void 0 ? options : { ...options, source });
15113
+ };
15114
+ return stamped;
15115
+ }
15116
+
14621
15117
  // src/renderer.ts
14622
15118
  var rendererCount = 0;
15119
+ var SUGGESTED_MAX_AWAKE_PIECES = 24;
15120
+ var SUGGESTED_MAX_AWAKE_FRAGMENTS = 64;
14623
15121
  var COLLAPSE_CLOUD_KG = 1e3;
14624
15122
  var REBAR_COLOR = 7628380;
14625
15123
  var STEEL_DENSITY = 7850;
@@ -14853,6 +15351,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
14853
15351
  __publicField(this, "ground");
14854
15352
  __publicField(this, "pieceSys");
14855
15353
  __publicField(this, "cages");
15354
+ /** The debris at rest drawn in batches. */
15355
+ __publicField(this, "settledBatches");
14856
15356
  __publicField(this, "hitPoints", new HitPoints());
14857
15357
  __publicField(this, "active", /* @__PURE__ */ new Map());
14858
15358
  __publicField(this, "fires", /* @__PURE__ */ new Map());
@@ -14865,6 +15365,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
14865
15365
  __publicField(this, "throttles", /* @__PURE__ */ new Map());
14866
15366
  __publicField(this, "rng", createRng(RNG_SEED));
14867
15367
  __publicField(this, "vfx");
15368
+ /** The object whose event is being applied: what the effects world is given while it is set is that object's (`stampSource`). */
15369
+ __publicField(this, "emitting");
14868
15370
  /** Names this renderer to the world's drips, so a shared world tells each renderer where its own landed. */
14869
15371
  __publicField(this, "owner", `destruction-${++rendererCount}`);
14870
15372
  __publicField(this, "stopLanding");
@@ -14897,7 +15399,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
14897
15399
  this.settlement = new SettlementView(THREE, this.visuals);
14898
15400
  this.ground = new GroundSpots(THREE, o.scene, this.groundAt, 48);
14899
15401
  if (!o.vfx) warnOnce("game-destruction-three.own-effects-world", "game-destruction-three made an effects world of its own because the host lent none (options.vfx); pass the host effects so the effects share one budget");
14900
- this.vfx = o.vfx ?? createVfx({ profile: this.quality, gravity: this.gravity, groundAt: this.groundAt, sprites: { capacity: maxParticles, density: this.low ? 0.6 : 1 } });
15402
+ this.vfx = stampSource(o.vfx ?? createVfx({ profile: this.quality, gravity: this.gravity, groundAt: this.groundAt, sprites: { capacity: maxParticles, density: this.low ? 0.6 : 1 } }), () => this.emitting);
14901
15403
  this.ownVfx = o.vfx ? void 0 : createVfxRenderer(THREE, { scene: o.scene, camera: o.camera ?? new THREE.PerspectiveCamera(), vfx: this.vfx, pointScale: o.pointScale ?? 700 });
14902
15404
  this.stopLanding = this.vfx.onLand(this.owner, (x, _y, z, color, tag) => {
14903
15405
  const home = this.homeTags[tag - 1] ?? "";
@@ -14912,14 +15414,17 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
14912
15414
  formOf: (id) => this.world.materials.get(id)?.splitForm,
14913
15415
  crumbles: (id) => this.world.materials.get(id)?.fracture === "crumble",
14914
15416
  // rubble lands on what is still built (a slab, a wall's top, a floor), not only on the terrain under it
14915
- surfaceAt: (x, y, z) => this.surfaceAt(x, y, z)
15417
+ surfaceAt: (x, y, z) => this.surfaceAt(x, y, z),
15418
+ maxAwake: o.maxAwakeFragments ?? Infinity
14916
15419
  });
14917
15420
  this.cages = new RebarCages(THREE, o.scene);
15421
+ this.settledBatches = new SettledBatches(THREE, o.scene, o.settledBatches ?? { enabled: false });
14918
15422
  this.pieceSys = new PieceSystem(THREE, {
14919
15423
  groundAt: this.groundAt,
14920
15424
  staticTopAt: (x, z, y, step) => this.staticTopAt(x, z, y, step),
14921
15425
  gravity: this.gravity,
14922
15426
  scene: o.scene,
15427
+ maxAwake: o.maxAwakePieces ?? Infinity,
14923
15428
  onHardLanding: (p, point, speed) => this.hardLanding(p, point, speed),
14924
15429
  sweep: (p, from, to) => this.sweepPiece(p, from, to),
14925
15430
  onSlam: (p, hit, speed) => this.slam(p, hit, speed),
@@ -15317,6 +15822,30 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
15317
15822
  this.ground.update(dt);
15318
15823
  this.ownVfx?.update(dt);
15319
15824
  this.syncTransforms();
15825
+ this.settledBatches.update(dt, () => this.restingDebris());
15826
+ }
15827
+ /** An event of the object (a blow, fire, char): its meshes leave the batches before it is drawn (`SettledBatches.release`). */
15828
+ releaseBatched(objectId) {
15829
+ const b = this.bounds.get(objectId);
15830
+ if (b) this.settledBatches.release(this.meshesOf(b).map((mv) => mv.mesh));
15831
+ }
15832
+ /**
15833
+ * The meshes of the debris at rest: the fragments asleep (without marks on them) and the meshes of their own of the pieces asleep, but for an object with a part burning,
15834
+ * hot or still charring (`active`): its colours change in place.
15835
+ */
15836
+ restingDebris() {
15837
+ const meshes = new Set(this.fragments.restingMeshes());
15838
+ const changing = /* @__PURE__ */ new Set();
15839
+ for (const a of this.active.values()) changing.add(a.object);
15840
+ for (const piece of this.pieceSys.list) {
15841
+ const b = piece.sleeping && !piece.held && !changing.has(piece.objectId) ? this.bounds.get(piece.objectId) : void 0;
15842
+ if (!b) continue;
15843
+ for (const mv of this.meshesOf(b)) if ((!mv.host || mv.loose) && !mv.hidden && this.visuals.shown(mv)) meshes.add(mv.mesh);
15844
+ }
15845
+ return [...meshes];
15846
+ }
15847
+ settledBatchStats() {
15848
+ return this.settledBatches.stats();
15320
15849
  }
15321
15850
  deferredQueue() {
15322
15851
  return this.eventQueue;
@@ -15521,7 +16050,17 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
15521
16050
  return found;
15522
16051
  }
15523
16052
  apply(ev) {
16053
+ const outer = this.emitting;
16054
+ this.emitting = ev.object || void 0;
16055
+ try {
16056
+ this.applyEvent(ev);
16057
+ } finally {
16058
+ this.emitting = outer;
16059
+ }
16060
+ }
16061
+ applyEvent(ev) {
15524
16062
  this.staticDirty.add(ev.object);
16063
+ this.releaseBatched(ev.object);
15525
16064
  this.hitPoints.note(ev, this.time);
15526
16065
  if (ev.type === "fracture" || ev.type === "detach" || ev.type === "collapse" || ev.type === "burnout" || ev.type === "destroyed") this.broken.add(ev.object);
15527
16066
  switch (ev.type) {
@@ -15892,7 +16431,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
15892
16431
  if (this.trickles.length >= TRICKLE_MAX) this.trickles.shift();
15893
16432
  const total = TRICKLE_SECONDS[0] + (TRICKLE_SECONDS[1] - TRICKLE_SECONDS[0]) * this.rng();
15894
16433
  const anchor = mv ? anchorOnMesh(this.THREE, mv, point, normal) : null;
15895
- this.trickles.push({ point: [point[0], point[1], point[2]], normal, anchor, color, left: total, total, next: TRICKLE_EVERY });
16434
+ this.trickles.push({ point: [point[0], point[1], point[2]], normal, anchor, color, left: total, total, next: TRICKLE_EVERY, source: this.emitting ?? mv?.home });
15896
16435
  }
15897
16436
  updateTrickles(dt) {
15898
16437
  for (let i = this.trickles.length - 1; i >= 0; i--) {
@@ -15915,7 +16454,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
15915
16454
  const share = t.left / t.total;
15916
16455
  t.next = TRICKLE_EVERY / Math.max(share, 0.25);
15917
16456
  const out = [t.normal[0] * 0.2, -1, t.normal[2] * 0.2];
15918
- const options = t.color !== void 0 ? { color: t.color } : void 0;
16457
+ const options = { ...t.color !== void 0 ? { color: t.color } : {}, ...t.source !== void 0 ? { source: t.source } : {} };
15919
16458
  this.vfx.burst("chips", t.point, out, this.low ? 1 : 2, 0.3, options);
15920
16459
  if (this.rng() < 0.5) this.vfx.burst("dust", t.point, out, 1, 0.2, options);
15921
16460
  }
@@ -16553,7 +17092,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
16553
17092
  this.ground.add("puddle", c.x, c.z, clamp6(footprint * 0.55, 0.05, 1), this.partColor(pv, def) ?? fallbackColor(def), objectId);
16554
17093
  } else {
16555
17094
  this.ground.add("ash", c.x, c.z, clamp6(footprint * 0.35, 0.04, 0.5), 1907224, objectId);
16556
- this.vfx.burst("ash", [c.x, bb.max.y, c.z], [0, 1, 0], 10, 0.8);
17095
+ this.vfx.burst("ash", [c.x, bb.max.y, c.z], [0, 1, 0], 10, 0.8, { source: objectId });
16557
17096
  }
16558
17097
  }
16559
17098
  emitFire(f, pv, def) {
@@ -16561,17 +17100,20 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
16561
17100
  bb.makeEmpty();
16562
17101
  const tmp = new this.THREE.Box3();
16563
17102
  for (const mv of pv.meshes) if (this.visuals.shown(mv)) bb.union(this.visuals.worldBox(mv, tmp));
16564
- if (!bb.isEmpty()) {
16565
- const c = bb.getCenter(this.v1);
16566
- f.follow.x = c.x;
16567
- f.follow.y = bb.min.y;
16568
- f.follow.z = c.z;
17103
+ if (bb.isEmpty()) {
17104
+ if (f.handle !== void 0) this.vfx.stop(f.handle);
17105
+ delete f.handle;
17106
+ return;
16569
17107
  }
17108
+ const c = bb.getCenter(this.v1);
17109
+ f.follow.x = c.x;
17110
+ f.follow.y = bb.min.y;
17111
+ f.follow.z = c.z;
16570
17112
  if (f.handle !== void 0) return;
16571
- const size = bb.isEmpty() ? this.v2.set(0.2, 0.2, 0.2) : bb.getSize(this.v2);
17113
+ const size = bb.getSize(this.v2);
16572
17114
  const radius = clamp6(Math.max(size.x, size.z) * 0.5, 0.12, 1.2);
16573
17115
  const smokeColor = SMOKE_TONES[def?.thermal.smoke ?? "grey"];
16574
- f.handle = this.vfx.fire({ point: [f.follow.x, f.follow.y, f.follow.z], radius, life: FIRE_CEILING_SECONDS, follow: f.follow, ...smokeColor !== void 0 ? { smokeColor } : {} });
17116
+ f.handle = this.vfx.fire({ point: [f.follow.x, f.follow.y, f.follow.z], radius, life: FIRE_CEILING_SECONDS, follow: f.follow, source: f.object, ...smokeColor !== void 0 ? { smokeColor } : {} });
16575
17117
  }
16576
17118
  updateLeaks(dt) {
16577
17119
  for (let i = this.leaks.length - 1; i >= 0; i--) {
@@ -16612,8 +17154,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
16612
17154
  while (l.acc >= 1) {
16613
17155
  l.acc -= 1;
16614
17156
  const vel = [dir[0] / dl * sp + (this.rng() - 0.5) * 0.25, dir[1] / dl * sp + (this.rng() - 0.5) * 0.25, dir[2] / dl * sp + (this.rng() - 0.5) * 0.25];
16615
- if (l.fluid === "gas") this.vfx.spawn("steam", pt, vel, { color, size: 0.5, alpha: 0.5 });
16616
- else this.vfx.spawn("drips", pt, vel, { color, tag: this.rng() < 0.03 ? this.tagOf(l.object) : 0, owner: this.owner });
17157
+ if (l.fluid === "gas") this.vfx.spawn("steam", pt, vel, { color, size: 0.5, alpha: 0.5, source: l.object });
17158
+ else this.vfx.spawn("drips", pt, vel, { color, tag: this.rng() < 0.03 ? this.tagOf(l.object) : 0, owner: this.owner, source: l.object });
16617
17159
  }
16618
17160
  }
16619
17161
  }
@@ -16646,6 +17188,53 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
16646
17188
  this.cages.removeObject(home);
16647
17189
  }
16648
17190
  }
17191
+ release(objectId) {
17192
+ const removed = this.releasePieces(objectId);
17193
+ this.unbind(objectId);
17194
+ return removed;
17195
+ }
17196
+ releasePieces(objectId) {
17197
+ const family = this.familyOf(objectId);
17198
+ const pieces = [...family].filter((id) => id !== objectId);
17199
+ const ofFamily = (key) => [...family].some((id) => key.startsWith(`${id}|`));
17200
+ for (let i = this.queue.length - 1; i >= 0; i--) if (family.has(this.queue[i].object)) this.queue.splice(i, 1);
17201
+ for (const [key, a] of [...this.active]) if (family.has(a.object)) this.active.delete(key);
17202
+ for (const [key, f] of [...this.fires]) if (family.has(f.object)) this.stopFire(key);
17203
+ for (const [key, started] of [...this.burnSounds]) if (family.has(started.object)) this.endBurnSound(key);
17204
+ for (const key of [...this.primedBurning]) if (ofFamily(key)) this.primedBurning.delete(key);
17205
+ for (let i = this.leaks.length - 1; i >= 0; i--) if (family.has(this.leaks[i].object)) this.leaks.splice(i, 1);
17206
+ for (let i = this.trickles.length - 1; i >= 0; i--) if (family.has(this.trickles[i].source ?? "")) this.trickles.splice(i, 1);
17207
+ for (const id of family) {
17208
+ this.fragments.removeHome(id);
17209
+ this.ground.removeHome(id);
17210
+ this.cages.removeObject(id);
17211
+ this.vfx.clearSource(id);
17212
+ }
17213
+ this.restore(objectId);
17214
+ for (const id of pieces) {
17215
+ this.pieceSys.remove(id);
17216
+ this.bounds.delete(id);
17217
+ this.hitPoints.forget(id);
17218
+ this.broken.delete(id);
17219
+ this.staticDirty.add(id);
17220
+ if (this.world.has(id)) this.world.remove(id);
17221
+ }
17222
+ if (pieces.length > 0) this.o.onReleased?.(pieces);
17223
+ return pieces;
17224
+ }
17225
+ /** The object and every piece split from it (a piece holds parts whose home is the object, also a piece of a piece). */
17226
+ familyOf(objectId) {
17227
+ const family = /* @__PURE__ */ new Set([objectId]);
17228
+ for (const b of this.bounds.values()) {
17229
+ if (!b.isSplit) continue;
17230
+ for (const pv of b.parts.values()) {
17231
+ if (pv.home !== objectId) continue;
17232
+ family.add(b.id);
17233
+ break;
17234
+ }
17235
+ }
17236
+ return family;
17237
+ }
16649
17238
  restoreHome(home) {
16650
17239
  const homeBound = this.bounds.get(home);
16651
17240
  for (const b of [...this.bounds.values()]) {
@@ -16668,6 +17257,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
16668
17257
  }
16669
17258
  }
16670
17259
  clear() {
17260
+ this.settledBatches.clear();
16671
17261
  this.staticAll = true;
16672
17262
  this.queue.length = 0;
16673
17263
  this.slices.length = 0;
@@ -16845,7 +17435,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
16845
17435
  var CASING_DEFAULTS = defaultsOf(SAMPLE_LEVELS.casing);
16846
17436
  var MAGAZINE_DROP_DEFAULTS = defaultsOf(SAMPLE_LEVELS.magazine);
16847
17437
 
16848
- // ../game-audio/dist/chunk-KGYMFUK7.js
17438
+ // ../game-audio/dist/chunk-ZFNHDQRV.js
16849
17439
  var DISTANCE_CURVES = {
16850
17440
  /** The game's `sfx`: `vol / (1 + d² × 0.004)`, cutoff `/ (1 + d × 0.01)`, silent below 0.01 (jogo L62091–62092, L62101). */
16851
17441
  game_sfx: { model: "inverse_square", k: 4e-3, cutoffK: 0.01, minGain: 0.01 },
@@ -18864,6 +19454,11 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
18864
19454
  explode: { sound: "explosion_boom" }
18865
19455
  }
18866
19456
  };
19457
+ var BLAST_FAR_SOUND = "explosion_far";
19458
+ var BLAST_INDOOR_TAIL_SOUND = "explosion_indoor_tail";
19459
+ var blastSoundIds = (rules = DESTRUCTION_SOUND_KEYS.art_scene) => [
19460
+ .../* @__PURE__ */ new Set([...Object.values(BLAST_SOUND_OF), BLAST_FAR_SOUND, BLAST_INDOOR_TAIL_SOUND, ...Object.values(FIRE_LOOP_OF), "fire_crackle", "fire_pop", ...impactSoundIds(rules)])
19461
+ ];
18867
19462
  var DEFAULT_FIRE = { perFire: 0.08, max: 0.45 };
18868
19463
  var FIRE_FADE_SECONDS = 0.4;
18869
19464
  var DEFAULT_CRACKLES = { base: 2, perSqrtFire: 3, max: 14, volume: 0.5 };
@@ -18945,7 +19540,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
18945
19540
  const kind = named ?? ((detail?.radius ?? 0) >= BIG_BLAST_RADIUS || volume >= 0.9 ? "big" : "grenade");
18946
19541
  const sound = BLAST_SOUND_OF[kind];
18947
19542
  const distance = engine.plan(sound, { position: point, seed: 1 })?.distance ?? 0;
18948
- return kind !== "molotov" && distance > farDistance ? "explosion_far" : sound;
19543
+ return kind !== "molotov" && distance > farDistance ? BLAST_FAR_SOUND : sound;
18949
19544
  };
18950
19545
  return {
18951
19546
  onSound(key, point, volume, detail) {
@@ -18962,7 +19557,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
18962
19557
  if (key === "explode" && blastByKind) {
18963
19558
  const sound2 = blastSound(point, volume, detail);
18964
19559
  engine.play(sound2, { position: point, volume });
18965
- if (sound2 !== "explosion_far" && sound2 !== "molotov_break_ignite" && (detail?.confinement ?? 1) >= indoorFrom) engine.play("explosion_indoor_tail", { position: point, volume });
19560
+ if (sound2 !== BLAST_FAR_SOUND && sound2 !== "molotov_break_ignite" && (detail?.confinement ?? 1) >= indoorFrom) engine.play(BLAST_INDOOR_TAIL_SOUND, { position: point, volume });
18966
19561
  return;
18967
19562
  }
18968
19563
  let rule;