@adatechnology/game-destruction-three 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2379,6 +2379,7 @@ var GameDestructionThree = (() => {
2379
2379
  var QUALITY = { $: "quality" };
2380
2380
  var FRESH = { $: "fresh" };
2381
2381
  var DIRECTION = { $: "direction" };
2382
+ var NORMAL = { $: "normal" };
2382
2383
  var CAMERA_POSITION = { $: "cameraPosition" };
2383
2384
  var burst = (system, count, spawn2) => ({ op: "burst", system, count, spawn: spawn2 });
2384
2385
  var spawn = (system, options) => ({ op: "spawn", system, spawn: options });
@@ -2900,7 +2901,7 @@ var GameDestructionThree = (() => {
2900
2901
  var TIP2 = [-0.8, 1.38, 3.4 - 0.78];
2901
2902
  var PORT2 = [-0.76, 1.4, 3.32];
2902
2903
  var FORWARD3 = [0, 0, -1];
2903
- var NORMAL = [0, 0, 1];
2904
+ var NORMAL2 = [0, 0, 1];
2904
2905
  var WALL_Z2 = -4.45;
2905
2906
  var SHOTS = [[0, 0.45, 0.9], [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6], [0], [0]];
2906
2907
  var SHOT_TIME = pick(pick(SHOTS, PARAM), INDEX);
@@ -2925,8 +2926,8 @@ var GameDestructionThree = (() => {
2925
2926
  set("target", [add(-0.8, rnd(-0.4, 0.4)), add(1.4, rnd(-0.3, 0.3)), WALL_Z2]),
2926
2927
  when(
2927
2928
  eq(PARAM, SHOTGUN),
2928
- [repeat(8, call2("impact", "concrete", [add(-0.8, rnd(-0.5, 0.5)), add(1.4, rnd(-0.4, 0.4)), WALL_Z2], NORMAL, 0.35))],
2929
- [call2("impact", "concrete", variable("target"), NORMAL, ite(eq(PARAM, BARRETT), 2, 1))]
2929
+ [repeat(8, call2("impact", "concrete", [add(-0.8, rnd(-0.5, 0.5)), add(1.4, rnd(-0.4, 0.4)), WALL_Z2], NORMAL2, 0.35))],
2930
+ [call2("impact", "concrete", variable("target"), NORMAL2, ite(eq(PARAM, BARRETT), 2, 1))]
2930
2931
  ),
2931
2932
  when(and(eq(PARAM, AK), eq(mod(round(mul(SHOT_TIME, 10)), 3), 0)), [spawn("streak", { p: TIP2, dir: FORWARD3, cone: 0, sp: 90, life: 0.09, len: 0.025, c0: 16752704, a: 1 })])
2932
2933
  )
@@ -4321,7 +4322,16 @@ var GameDestructionThree = (() => {
4321
4322
  };
4322
4323
  var VIEWMODEL_EFFECTS = [MUZZLE_FLASH2, SMOKE_PUFF, BACKBLAST, FLAME_JET];
4323
4324
  var aliasOf = (base, id, changes) => ({ ...base, id, pageId: `vehicle:${id}`, anchor: CAR_ORIGIN2, ...changes });
4325
+ var BODYWORK_IMPACT = {
4326
+ id: "impact_bodywork",
4327
+ pageId: "vehicle:impact_bodywork",
4328
+ team: "vehicles",
4329
+ budget: { particles: 80, debris: 20, lights: 1 },
4330
+ loop: 2,
4331
+ timeline: [call2("bodywork_impact", [0, 0, 0], NORMAL, [variable("dx"), variable("dy"), variable("dz")], variable("bore"), variable("paint"), variable("metal"))]
4332
+ };
4324
4333
  var VEHICLE_EFFECTS = [
4334
+ BODYWORK_IMPACT,
4325
4335
  /** The engine on fire: `engine_smoke` at its worst condition (black smoke, flames in the hood, a light). */
4326
4336
  aliasOf(ENGINE_SMOKE, "vehicle_fire", { params: { id: "condition", options: ["100", "60", "30", "10"], default: 3 }, loop: 12 }),
4327
4337
  /** The exhaust of a car under way: `engine_smoke` in the best condition, for half a second so a moving car asks again. */
@@ -5026,6 +5036,46 @@ var GameDestructionThree = (() => {
5026
5036
  return evaluateCall(value.$, args.map((entry) => resolve(entry, context)));
5027
5037
  }
5028
5038
  }
5039
+ var PISTOL_BORE = 9e-3;
5040
+ var BARE_STEEL = 11778236;
5041
+ var DEFAULT_PAINT = 9147290;
5042
+ var DEFAULT_DIRECTION = [0, 0, -1];
5043
+ var MAX_SCALE = 3;
5044
+ var MIN_SCALE = 0.6;
5045
+ function reflected(direction, normal) {
5046
+ const along2 = direction[0] * normal[0] + direction[1] * normal[1] + direction[2] * normal[2];
5047
+ const out = [direction[0] - 2 * along2 * normal[0], direction[1] - 2 * along2 * normal[1], direction[2] - 2 * along2 * normal[2]];
5048
+ const length = Math.hypot(out[0], out[1], out[2]);
5049
+ if (length < 1e-6 || Math.abs(along2) > 0.98) return normal;
5050
+ return [out[0] / length, out[1] / length, out[2] / length];
5051
+ }
5052
+ var numberOr = (value, fallback2) => typeof value === "number" && Number.isFinite(value) ? value : fallback2;
5053
+ function bodyworkHitOf(values) {
5054
+ const raw = Array.isArray(values.direction) ? values.direction : [];
5055
+ const direction = raw.length === 3 && raw.every((entry) => typeof entry === "number" && Number.isFinite(entry)) ? [raw[0], raw[1], raw[2]] : DEFAULT_DIRECTION;
5056
+ return { direction, bore: numberOr(values.bore, PISTOL_BORE), paint: numberOr(values.paint, DEFAULT_PAINT), metal: numberOr(values.metal, BARE_STEEL) };
5057
+ }
5058
+ function bodyworkScale(bore) {
5059
+ return Math.min(MAX_SCALE, Math.max(MIN_SCALE, bore / PISTOL_BORE));
5060
+ }
5061
+ function bodyworkImpact(engine, point, normal, hit) {
5062
+ const scale = bodyworkScale(hit.bore);
5063
+ const off2 = reflected(hit.direction, normal);
5064
+ if (engine.quality < 2) {
5065
+ engine.burst("streak", Math.round(14 * scale), { p: point, dir: off2, cone: 0.75, sp: [4, 12], life: [0.08, 0.3], len: 0.03, c0: 16774352, c1: 16738840, g: 9.8, gnd: 2 });
5066
+ engine.burst("add", 2, { p: plusScaled(point, normal, 0.01), size: [0.06 * scale, 0.12 * scale], life: 0.05, c0: 16770736, fi: 0 });
5067
+ engine.flash([plusScaled(point, normal, 0.15), 16760432, 1.6 * scale, 0.05, 4]);
5068
+ }
5069
+ const flakes = engine.scaled(Math.round(5 * scale));
5070
+ for (let index = 0; index < flakes; index++) {
5071
+ engine.debrisPiece({ p: point, dir: normal, cone: 0.9, sp: [1.2, 3.5], size: [8e-3 * scale, 12e-4, 6e-3 * scale], k: [0.5, 1.4], c: hit.paint, life: 6, bounce: 0.2 });
5072
+ }
5073
+ const slivers = engine.scaled(Math.round(2 * scale));
5074
+ for (let index = 0; index < slivers; index++) {
5075
+ engine.debrisPiece({ p: point, dir: off2, cone: 0.6, sp: [2.5, 6], size: [25e-4, 15e-4, 0.01 * scale], k: [0.6, 1.3], c: hit.metal, life: 6, bounce: 0.35 });
5076
+ }
5077
+ engine.burst("normal", Math.round(6 * scale), { p: point, dir: normal, cone: 0.7, sp: [0.4, 1.4], drag: 2.5, life: [0.4, 0.9], size: [0.03, 0.07], grow: 3, c0: hit.paint, a: 0.45, g: -0.05 });
5078
+ }
5029
5079
  var UP12 = [0, 1, 0];
5030
5080
  var ZERO = [0, 0, 0];
5031
5081
  var FULL_TURN_DRAWN = 6.283;
@@ -5175,9 +5225,10 @@ var GameDestructionThree = (() => {
5175
5225
  casing: ({ engine }, [port, type]) => casing(engine, port, type),
5176
5226
  chips: ({ engine }, [point, direction, count, spread2]) => chips(engine, point, direction, count, spread2),
5177
5227
  spark_at: ({ engine }, [point, direction, count, spread2]) => sparkAt(engine, point, direction, count, spread2),
5178
- rust_at: ({ engine }, [point, count]) => rustAt(engine, point, count)
5228
+ rust_at: ({ engine }, [point, count]) => rustAt(engine, point, count),
5229
+ bodywork_impact: ({ engine }, [point, normal, direction, bore, paint2, metal]) => bodyworkImpact(engine, point, normal, bodyworkHitOf({ direction, bore, paint: paint2, metal }))
5179
5230
  };
5180
- var DEFAULT_DIRECTION = [0, 0, -1];
5231
+ var DEFAULT_DIRECTION2 = [0, 0, -1];
5181
5232
  var DEFAULT_NORMAL = [0, 1, 0];
5182
5233
  var SCREEN_FIELDS = {
5183
5234
  shake: "shake",
@@ -5244,7 +5295,7 @@ var GameDestructionThree = (() => {
5244
5295
  return instance().fresh;
5245
5296
  },
5246
5297
  get direction() {
5247
- return instance().setup.direction ?? DEFAULT_DIRECTION;
5298
+ return instance().setup.direction ?? DEFAULT_DIRECTION2;
5248
5299
  },
5249
5300
  get normal() {
5250
5301
  return instance().setup.normal ?? DEFAULT_NORMAL;
@@ -7002,6 +7053,69 @@ var GameDestructionThree = (() => {
7002
7053
  addScaled(out, tangentB, sinTilt * Math.sin(phase));
7003
7054
  return out;
7004
7055
  }
7056
+ var CELL = 0.12;
7057
+ var OBSTACLE_BOUNCE = 0.3;
7058
+ var radiusOf = (piece) => Math.max(piece.sx, piece.sz) * 0.5;
7059
+ var thicknessOf = (piece) => Math.min(piece.sx, piece.sy, piece.sz);
7060
+ var cellKey = (i, k) => (i + 4096) * 8192 + (k + 4096);
7061
+ var RestingGrid = class {
7062
+ constructor() {
7063
+ __publicField2(this, "cells", /* @__PURE__ */ new Map());
7064
+ }
7065
+ clear() {
7066
+ for (const list of this.cells.values()) list.length = 0;
7067
+ }
7068
+ rebuild(pieces) {
7069
+ this.clear();
7070
+ for (const piece of pieces) {
7071
+ if (!piece.on || !piece.rest) continue;
7072
+ const key = cellKey(Math.floor(piece.x / CELL), Math.floor(piece.z / CELL));
7073
+ const list = this.cells.get(key);
7074
+ if (list) list.push(piece);
7075
+ else this.cells.set(key, [piece]);
7076
+ }
7077
+ }
7078
+ /** The height a piece at `piece`'s place lands at on the pieces under it (the top of the highest one it overlaps), or `-Infinity` over none. */
7079
+ supportUnder(piece) {
7080
+ const i = Math.floor(piece.x / CELL);
7081
+ const k = Math.floor(piece.z / CELL);
7082
+ const reach2 = radiusOf(piece);
7083
+ let top = -Infinity;
7084
+ for (let di = -1; di <= 1; di++) {
7085
+ for (let dk = -1; dk <= 1; dk++) {
7086
+ for (const other of this.cells.get(cellKey(i + di, k + dk)) ?? []) {
7087
+ if (other === piece) continue;
7088
+ if (Math.hypot(other.x - piece.x, other.z - piece.z) > reach2 + radiusOf(other)) continue;
7089
+ const otherTop = other.y + thicknessOf(other) * 0.5;
7090
+ if (otherTop <= piece.y + thicknessOf(piece) * 0.5) top = Math.max(top, otherTop + thicknessOf(piece) * 0.5);
7091
+ }
7092
+ }
7093
+ }
7094
+ return top;
7095
+ }
7096
+ };
7097
+ function pushOutOfObstacles(piece, obstacles) {
7098
+ let moved = false;
7099
+ for (const body of obstacles) {
7100
+ if (piece.y < body.bottom || piece.y > body.top) continue;
7101
+ const dx = piece.x - body.x;
7102
+ const dz = piece.z - body.z;
7103
+ const distance = Math.hypot(dx, dz);
7104
+ const reach2 = body.radius + radiusOf(piece);
7105
+ if (distance >= reach2) continue;
7106
+ const nx = distance > 1e-6 ? dx / distance : 1;
7107
+ const nz = distance > 1e-6 ? dz / distance : 0;
7108
+ piece.x = body.x + nx * reach2;
7109
+ piece.z = body.z + nz * reach2;
7110
+ const into = piece.vx * nx + piece.vz * nz;
7111
+ if (into < 0) {
7112
+ piece.vx -= (1 + OBSTACLE_BOUNCE) * into * nx;
7113
+ piece.vz -= (1 + OBSTACLE_BOUNCE) * into * nz;
7114
+ }
7115
+ moved = true;
7116
+ }
7117
+ return moved;
7118
+ }
7005
7119
  var CAPACITY = 500;
7006
7120
  var GRAVITY2 = 9.8;
7007
7121
  var QUARTER_TURN4 = 1.5708;
@@ -7022,6 +7136,7 @@ var GameDestructionThree = (() => {
7022
7136
  __publicField2(this, "count", 0);
7023
7137
  __publicField2(this, "next", 0);
7024
7138
  __publicField2(this, "direction", { x: 0, y: 0, z: 0 });
7139
+ __publicField2(this, "resting", new RestingGrid());
7025
7140
  }
7026
7141
  spawn(options) {
7027
7142
  const random = this.context.random;
@@ -7059,14 +7174,21 @@ var GameDestructionThree = (() => {
7059
7174
  }
7060
7175
  update(dt) {
7061
7176
  this.count = 0;
7177
+ const contacts = this.context.debrisContacts;
7178
+ const obstacles = contacts?.obstacles() ?? [];
7179
+ let moving = false;
7062
7180
  for (const piece of this.pieces) {
7063
7181
  if (!piece.on) continue;
7064
- this.count++;
7065
7182
  piece.life -= dt;
7066
- if (piece.life <= 0) {
7067
- piece.on = false;
7068
- continue;
7069
- }
7183
+ if (piece.life <= 0) piece.on = false;
7184
+ else if (!piece.rest) moving = true;
7185
+ }
7186
+ if (moving && contacts) this.resting.rebuild(this.pieces);
7187
+ else this.resting.clear();
7188
+ for (const piece of this.pieces) {
7189
+ if (!piece.on) continue;
7190
+ this.count++;
7191
+ if (obstacles.length > 0 && pushOutOfObstacles(piece, obstacles)) piece.rest = false;
7070
7192
  if (!piece.rest) this.move(piece, dt);
7071
7193
  }
7072
7194
  }
@@ -7082,7 +7204,7 @@ var GameDestructionThree = (() => {
7082
7204
  piece.rx += piece.ax * dt;
7083
7205
  piece.ry += piece.ay * dt;
7084
7206
  piece.rz += piece.az * dt;
7085
- const groundHeight = this.context.groundAt(piece.x, piece.z) + Math.min(piece.sx, piece.sy, piece.sz) * 0.5;
7207
+ const groundHeight = Math.max(this.context.groundAt(piece.x, piece.z) + Math.min(piece.sx, piece.sy, piece.sz) * 0.5, this.resting.supportUnder(piece));
7086
7208
  if (piece.y >= groundHeight) return;
7087
7209
  piece.y = groundHeight;
7088
7210
  piece.vy *= -piece.bounce;
@@ -7742,6 +7864,14 @@ var GameDestructionThree = (() => {
7742
7864
  this.decals = new DecalPool(this.context);
7743
7865
  this.lights = new FlashLightPool(this.context);
7744
7866
  }
7867
+ /**
7868
+ * Turns on the touch of the debris pieces (a game's world; the Workshop page's recording has none): they pile on the pieces at rest under them, and the
7869
+ * upright bodies `obstacles` answers (the player, asked once a frame while a piece moves) stop them and push them. `null` turns it off.
7870
+ */
7871
+ setDebrisContacts(obstacles) {
7872
+ if (obstacles) this.context.debrisContacts = { obstacles };
7873
+ else delete this.context.debrisContacts;
7874
+ }
7745
7875
  get random() {
7746
7876
  return this.context.random;
7747
7877
  }
@@ -10526,6 +10656,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
10526
10656
  const normals = new Float32Array(capacity * 3);
10527
10657
  const impact3 = { body: 0, other: 0, impulse: 0, approach: 0, point: [0, 0, 0], normal: [0, 0, 0] };
10528
10658
  const keep = (c, body, other, row, sign) => {
10659
+ if (options.ignores?.(other)) return;
10529
10660
  let at3 = Math.imul(body, 2654435761) & mask;
10530
10661
  while (tableStamp[at3] === stamp && tableKey[at3] !== body) at3 = at3 + 1 & mask;
10531
10662
  let slot;
@@ -11358,6 +11489,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
11358
11489
  var SWEEP_MIN_SPEED = 1;
11359
11490
  var WALL_RESTITUTION = 0.25;
11360
11491
  var WALL_GLIDE = 0.7;
11492
+ var TUMBLE_REACH = 0.1;
11493
+ var LAID_GAP = 5e-3;
11361
11494
  var STAND_RATIO = 0.6;
11362
11495
  var SETTLE_SECONDS = 0.4;
11363
11496
  var isSlow = (f) => f.vel.lengthSq() < 0.012 && f.ang.lengthSq() < 0.2;
@@ -11592,6 +11725,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
11592
11725
  dying: false,
11593
11726
  air: f.shape === "scrap" && sz[2] <= SHEET_MAX ? SHEET_AIR : 0,
11594
11727
  body: null,
11728
+ rigid: null,
11595
11729
  born: this.tick,
11596
11730
  life: lasting ? 0 : Math.max(0, typeof this.o.life === "function" ? this.o.life(f, home) : this.o.life),
11597
11731
  seq: this.nextSeq++,
@@ -11600,9 +11734,12 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
11600
11734
  isMortal: false
11601
11735
  };
11602
11736
  if (lasting || isBig(f.size)) {
11737
+ const rigid = this.o.rigid;
11738
+ if (rigid) live.rigid = rigid.add(mesh2, [sc.x / 2, sc.y / 2, sc.z / 2], f.mass, f.velocity, f.angularVelocity);
11603
11739
  live.body = {
11604
11740
  mass: f.mass,
11605
11741
  push: (x, z) => {
11742
+ if (rigid && live.rigid) return rigid.push(live.rigid, x, z);
11606
11743
  live.vel.x = x;
11607
11744
  live.vel.z = z;
11608
11745
  live.vel.y = Math.max(live.vel.y, 0.3);
@@ -11640,8 +11777,14 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
11640
11777
  const k = (1 - dist / radius) ** 2 * speed;
11641
11778
  d.normalize().multiplyScalar(k);
11642
11779
  d.y += k * 0.4;
11780
+ const spin = this.w.set(this.rng() - 0.5, this.rng() - 0.5, this.rng() - 0.5).multiplyScalar(k);
11781
+ if (f.rigid) {
11782
+ spin.multiplyScalar(Math.min(1, TUMBLE_REACH / Math.max(f.half.x, f.half.y, f.half.z)));
11783
+ this.o.rigid?.shove(f.rigid, [d.x, d.y, d.z], [spin.x, spin.y, spin.z]);
11784
+ continue;
11785
+ }
11643
11786
  f.vel.add(d);
11644
- f.ang.add(this.w.set(this.rng() - 0.5, this.rng() - 0.5, this.rng() - 0.5).multiplyScalar(k));
11787
+ f.ang.add(spin);
11645
11788
  this.rouse(f);
11646
11789
  }
11647
11790
  }
@@ -11695,7 +11838,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
11695
11838
  /** What lies inside the disc looks at the ground again: it was dug or heaped under it. */
11696
11839
  wakeRegion(x, z, radius) {
11697
11840
  for (const f of this.list) {
11698
- if (!f.asleep || Math.hypot(f.mesh.position.x - x, f.mesh.position.z - z) > radius) continue;
11841
+ if (!f.asleep || f.rigid || Math.hypot(f.mesh.position.x - x, f.mesh.position.z - z) > radius) continue;
11699
11842
  this.rouse(f);
11700
11843
  }
11701
11844
  }
@@ -11703,6 +11846,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
11703
11846
  this.tick++;
11704
11847
  this.clock += dt;
11705
11848
  this.wakeUnsupported();
11849
+ this.wakeRigid();
11706
11850
  this.beginTick();
11707
11851
  const g = this.o.gravity;
11708
11852
  for (let i = this.active.length - 1; i >= 0; i--) {
@@ -11713,6 +11857,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
11713
11857
  if (f.fade <= 0) {
11714
11858
  this.instances.remove(f.mesh);
11715
11859
  this.o.scene.remove(f.mesh);
11860
+ this.release(f);
11716
11861
  f.isActive = false;
11717
11862
  this.active.splice(i, 1);
11718
11863
  this.list.splice(this.list.indexOf(f), 1);
@@ -11721,19 +11866,34 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
11721
11866
  f.mesh.scale.copy(f.baseScale).multiplyScalar(f.fade);
11722
11867
  }
11723
11868
  if (f.asleep) continue;
11724
- this.step(f, dt, g);
11869
+ if (f.rigid) this.follow(f);
11870
+ else this.step(f, dt, g);
11725
11871
  }
11726
11872
  this.expireSleepers();
11727
11873
  this.keepBudget();
11728
11874
  this.trail?.commit();
11729
11875
  this.drawInstanced();
11730
11876
  }
11877
+ /** Its body goes with it. */
11878
+ release(f) {
11879
+ if (f.rigid) this.o.rigid?.remove(f.rigid);
11880
+ f.rigid = null;
11881
+ }
11882
+ /** The debris moved by a rigid body that the body's world woke (something fell on it, a blast, its ground dug): it is awake here too. */
11883
+ wakeRigid() {
11884
+ for (const f of this.list) if (f.rigid && f.asleep && !f.dying && !f.rigid.sleeping) this.rouse(f);
11885
+ }
11886
+ /** A piece of debris moved by its rigid body: the body wrote its pose; it sleeps here when the body does. */
11887
+ follow(f) {
11888
+ f.box = void 0;
11889
+ if (f.rigid?.sleeping) this.sleep(f);
11890
+ }
11731
11891
  /** The meshes go back to the step's pose and the ones awake are recorded as the previous one (`interpolate`). */
11732
11892
  beginTick() {
11733
11893
  const trail = this.trail;
11734
11894
  if (!trail) return;
11735
11895
  trail.begin();
11736
- for (const f of this.active) if (!f.asleep) trail.record(f.mesh);
11896
+ for (const f of this.active) if (!f.asleep && !f.rigid) trail.record(f.mesh);
11737
11897
  }
11738
11898
  /** The meshes get the step pose back, before anything reads them. The instances take it at the next `update`. */
11739
11899
  restoreStepPose() {
@@ -11748,7 +11908,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
11748
11908
  /** The fragments in flight are drawn by the instances, those at rest on their own (the settled batches take them): then the instances take the transforms of this update. */
11749
11909
  drawInstanced() {
11750
11910
  for (const f of this.active) {
11751
- if (f.asleep) this.instances.remove(f.mesh);
11911
+ if (f.asleep || f.rigid) this.instances.remove(f.mesh);
11752
11912
  else this.instances.add(f.mesh);
11753
11913
  }
11754
11914
  this.instances.sync();
@@ -11758,12 +11918,12 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
11758
11918
  const most = this.o.maxAwake;
11759
11919
  if (most === void 0 || !Number.isFinite(most)) return;
11760
11920
  let awake = 0;
11761
- for (const f of this.active) if (!f.asleep && !f.dying) awake++;
11921
+ for (const f of this.active) if (!f.asleep && !f.dying && !f.rigid) awake++;
11762
11922
  if (awake <= most) return;
11763
11923
  for (let i = 0; i < this.active.length; i++) {
11764
11924
  const f = this.active[i];
11765
11925
  if (awake <= most) return;
11766
- if (f.asleep || f.dying || !f.contact || !isSlow(f)) continue;
11926
+ if (f.asleep || f.dying || f.rigid || !f.contact || !isSlow(f)) continue;
11767
11927
  this.sleep(f);
11768
11928
  i--;
11769
11929
  awake--;
@@ -11795,7 +11955,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
11795
11955
  for (let k = 0; k < Math.min(SUPPORT_CHECKS, n); k++) {
11796
11956
  this.supportTurn = (this.supportTurn + 1) % n;
11797
11957
  const f = this.list[this.supportTurn];
11798
- if (!f.asleep || f.dying) continue;
11958
+ if (!f.asleep || f.dying || f.rigid) continue;
11799
11959
  const e = this.m.makeRotationFromQuaternion(f.mesh.quaternion).elements;
11800
11960
  const ext = Math.abs(e[1]) * f.half.x + Math.abs(e[5]) * f.half.y + Math.abs(e[9]) * f.half.z;
11801
11961
  f.floor = null;
@@ -11838,6 +11998,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
11838
11998
  const gy = Math.max(floor2, pile);
11839
11999
  const tip = pile > floor2 ? this.offEdge : null;
11840
12000
  let contact = false;
12001
+ let turning = false;
11841
12002
  if (mesh2.position.y - ext < gy) {
11842
12003
  contact = true;
11843
12004
  mesh2.position.y = gy + ext;
@@ -11846,8 +12007,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
11846
12007
  f.vel.x *= 0.7;
11847
12008
  f.vel.z *= 0.7;
11848
12009
  f.ang.multiplyScalar(0.55);
11849
- f.ang.x += (this.rng() - 0.5) * 2;
11850
- f.ang.z += (this.rng() - 0.5) * 2;
12010
+ const tumble = Math.min(1, TUMBLE_REACH / Math.max(h.x, h.y, h.z));
12011
+ f.ang.x += (this.rng() - 0.5) * 2 * tumble;
12012
+ f.ang.z += (this.rng() - 0.5) * 2 * tumble;
11851
12013
  } else {
11852
12014
  f.vel.y = 0;
11853
12015
  const sliding = Math.hypot(f.vel.x, f.vel.z);
@@ -11865,9 +12027,13 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
11865
12027
  f.vel.z += tip.z * TIP_SPEED * dt * 10;
11866
12028
  f.ang.x += tip.z * TIP_TURN * dt * 10;
11867
12029
  f.ang.z -= tip.x * TIP_TURN * dt * 10;
11868
- } else if (contact && f.vel.lengthSq() < 4) this.settle(f, dt);
12030
+ } else if (contact && f.vel.lengthSq() < 4) {
12031
+ turning = this.settle(f, dt);
12032
+ this.m.makeRotationFromQuaternion(mesh2.quaternion);
12033
+ mesh2.position.y = gy + (Math.abs(e[1]) * h.x + Math.abs(e[5]) * h.y + Math.abs(e[9]) * h.z) * sc;
12034
+ }
11869
12035
  f.contact = contact;
11870
- if (contact && isSlow(f)) {
12036
+ if (contact && !turning && isSlow(f)) {
11871
12037
  f.still += dt;
11872
12038
  if (f.still > SETTLE_SECONDS) this.sleep(f);
11873
12039
  } else {
@@ -11945,7 +12111,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
11945
12111
  f.ang.x += (this.rng() - 0.5) * SHEET_SWAY * 4 * dt;
11946
12112
  f.ang.z += (this.rng() - 0.5) * SHEET_SWAY * 4 * dt;
11947
12113
  }
11948
- /** Tip the fragment towards lying on its flattest face. */
12114
+ /** Tip the fragment towards lying on its flattest face. True while its end is still more than `LAID_GAP` from lying. */
11949
12115
  settle(f, dt) {
11950
12116
  const mesh2 = f.mesh;
11951
12117
  this.m.makeRotationFromQuaternion(mesh2.quaternion);
@@ -11967,6 +12133,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
11967
12133
  this.dq.setFromUnitVectors(this.v, this.w);
11968
12134
  this.q.copy(this.dq).multiply(mesh2.quaternion);
11969
12135
  mesh2.quaternion.slerp(this.q, clamp6(dt * 7, 0, 1));
12136
+ return Math.sqrt(Math.max(0, 1 - this.v.y * this.v.y)) * Math.max(half[0], half[1], half[2]) > LAID_GAP;
11970
12137
  }
11971
12138
  /** Remove the fragments of one object (after `restore`). */
11972
12139
  removeHome(home) {
@@ -11974,6 +12141,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
11974
12141
  if (this.list[i].home === home) {
11975
12142
  this.instances.remove(this.list[i].mesh);
11976
12143
  this.o.scene.remove(this.list[i].mesh);
12144
+ this.release(this.list[i]);
11977
12145
  this.deactivate(this.list[i]);
11978
12146
  this.list[i].deadline = Infinity;
11979
12147
  this.list.splice(i, 1);
@@ -11983,7 +12151,10 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
11983
12151
  clear() {
11984
12152
  this.trail?.clear();
11985
12153
  this.instances.clear();
11986
- for (const f of this.list) this.o.scene.remove(f.mesh);
12154
+ for (const f of this.list) {
12155
+ this.o.scene.remove(f.mesh);
12156
+ this.release(f);
12157
+ }
11987
12158
  this.list.length = 0;
11988
12159
  this.active.length = 0;
11989
12160
  this.mortal.length = 0;
@@ -14188,7 +14359,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
14188
14359
  var DEFAULT_HITS_MAX = 32;
14189
14360
  var DEFAULT_MIN_APPROACH = 1.5;
14190
14361
  var DEFAULT_CONTACT_RADIUS = 0.1;
14191
- var createEngineImpacts = (loop, statics, destruction, options = {}) => {
14362
+ var createEngineImpacts = (loop, statics, destruction, options = {}, isDebris) => {
14192
14363
  const hitsMax = options.hitsMax ?? DEFAULT_HITS_MAX;
14193
14364
  const radius = options.contactRadius ?? DEFAULT_CONTACT_RADIUS;
14194
14365
  const minApproach = options.minApproach ?? DEFAULT_MIN_APPROACH;
@@ -14196,8 +14367,11 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
14196
14367
  minImpulse: options.minImpulse ?? DEFAULT_MIN_IMPULSE,
14197
14368
  bodiesMax: hitsMax,
14198
14369
  accepts: (body) => statics.ownerOf.has(body),
14370
+ // what is left of a part that broke breaks nothing again when it lands: a blow of debris is no blow to the world
14371
+ ...isDebris ? { ignores: isDebris } : {},
14199
14372
  onImpact: (impact3) => {
14200
14373
  if (impact3.approach < minApproach) return;
14374
+ if (options.harmless?.(impact3.other)) return;
14201
14375
  const object = statics.ownerOf.get(impact3.body);
14202
14376
  const part = statics.partOf.get(impact3.body);
14203
14377
  if (object === void 0 || part === void 0 || destruction.part(object, part) === null) return;
@@ -14651,6 +14825,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
14651
14825
  var NO_PROGRESS = 0.75;
14652
14826
  var WAY_STEP_MIN = 0.02;
14653
14827
  var WAY_STEP_MAX = 0.1;
14828
+ var BORN_INSIDE = { layers: ["static", "rubble"] };
14654
14829
  var EnginePieces = class {
14655
14830
  constructor(THREE, world, o) {
14656
14831
  __publicField(this, "world", world);
@@ -14693,6 +14868,12 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
14693
14868
  __publicField(this, "blasts", []);
14694
14869
  /** The host's fixed things (`staticSolids`) as static bodies. */
14695
14870
  __publicField(this, "statics");
14871
+ /** The debris still passing through a fixed thing it was made inside (`throughStatics`). */
14872
+ __publicField(this, "passing", /* @__PURE__ */ new Set());
14873
+ /** A set of one fixed body, to ask how deep a piece is in that one. */
14874
+ __publicField(this, "oneStatic", /* @__PURE__ */ new Set());
14875
+ /** The bodies a piece of debris overlaps where it is made (`throughStatics`), kept between asks. */
14876
+ __publicField(this, "overlapped", []);
14696
14877
  __publicField(this, "ignored", /* @__PURE__ */ new Set());
14697
14878
  __publicField(this, "knocks", /* @__PURE__ */ new Map());
14698
14879
  __publicField(this, "footprintOut", { corners: new Float64Array(16), normals: new Float64Array(6), minX: 0, maxX: 0, minZ: 0, maxZ: 0 });
@@ -14797,6 +14978,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
14797
14978
  this.byUser.delete(link.user);
14798
14979
  this.byBody.delete(link.id);
14799
14980
  this.bodyIds.delete(link.id);
14981
+ this.passing.delete(b);
14800
14982
  this.active.delete(b);
14801
14983
  if (this.byObject.get(b.objectId) === b) this.byObject.delete(b.objectId);
14802
14984
  this.links.delete(b);
@@ -14937,6 +15119,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
14937
15119
  this.makeBodies(each);
14938
15120
  each((b) => this.hang(b));
14939
15121
  each((b) => this.sync(b, dt, h));
15122
+ this.meetStaticsAgain();
14940
15123
  if (this.schedule) this.layGroundLater(each, dt);
14941
15124
  else this.layGround(each, dt);
14942
15125
  this.keepApart(apart2);
@@ -15210,7 +15393,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
15210
15393
  this.byBody.set(id, b);
15211
15394
  this.bodyIds.add(id);
15212
15395
  this.byObject.set(b.objectId, b);
15213
- this.outOfStatics(b, link);
15396
+ if (b.debris) this.throughStatics(b, link);
15397
+ else this.outOfStatics(b, link);
15214
15398
  });
15215
15399
  }
15216
15400
  bodyDesc(b, user) {
@@ -15227,7 +15411,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
15227
15411
  centreAtOrigin: true,
15228
15412
  keepPartContacts: shape.kind === "compound" && shape.children.length > 1,
15229
15413
  material: this.material(b),
15230
- layer: "debris",
15414
+ layer: b.debris ? "rubble" : "debris",
15231
15415
  // no air drag: the kit's pieces never had any (a round piece's rolling resistance is the adapter's, `rolling`)
15232
15416
  angularDamping: 0,
15233
15417
  linearDamping: 0,
@@ -15291,6 +15475,52 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
15291
15475
  * lifted (`underGround`). Left to the engine it is pushed out a little each step (`maxPushOut`), which reads as the piece rising by itself: a roof sheet made 1 m
15292
15476
  * into a shelf rose 0.83-0.94 m over the room's 11 s. Only past a contact's sink (`SINK`): resting on a shelf it is not moved.
15293
15477
  */
15478
+ /**
15479
+ * A piece of debris made inside something (the bars of a cage that gave way, inside the wall that still stands; a chunk overlapping the part next to the one that broke,
15480
+ * or the chunk cut beside it) is not moved out of it as a piece is (`outOfStatics`), and the engine does not push the two apart: debris is born
15481
+ * where the thing broke. It passes through what it was made inside until it is out of it, and only through that.
15482
+ */
15483
+ throughStatics(b, link) {
15484
+ const q = b.root.quaternion;
15485
+ const c = this.centre(b);
15486
+ const found = this.overlapped;
15487
+ this.world.overlapShape(this.shapeOf(b), [c.x, c.y, c.z], [q.x, q.y, q.z, q.w], found, BORN_INSIDE);
15488
+ for (const id of found) {
15489
+ if (id === link.id || link.through?.includes(id) || !(this.statics.ids.has(id) || this.bodyIds.has(id))) continue;
15490
+ this.world.ignorePair(link.id, id, true);
15491
+ (link.through ?? (link.through = [])).push(id);
15492
+ }
15493
+ if (link.through?.length) this.passing.add(b);
15494
+ }
15495
+ /** The debris passing through what it was made inside meets it again once it is out of it; what was made again meanwhile (a fixed thing's body is a new one) is looked at afresh. */
15496
+ meetStaticsAgain() {
15497
+ if (this.passing.size === 0 || !this.world.penetration) return;
15498
+ const one = this.oneStatic;
15499
+ for (const b of this.passing) {
15500
+ const link = this.links.get(b);
15501
+ const through = link?.through;
15502
+ if (!link || !through) {
15503
+ this.passing.delete(b);
15504
+ continue;
15505
+ }
15506
+ let remade = false;
15507
+ for (let i = through.length - 1; i >= 0; i--) {
15508
+ const id = through[i];
15509
+ if (!this.statics.ids.has(id) && !this.bodyIds.has(id)) {
15510
+ remade = true;
15511
+ through.splice(i, 1);
15512
+ continue;
15513
+ }
15514
+ one.clear();
15515
+ one.add(id);
15516
+ if (this.world.penetration(link.id, this.outAxis, one) > SINK) continue;
15517
+ this.world.ignorePair(link.id, id, false);
15518
+ through.splice(i, 1);
15519
+ }
15520
+ if (remade) this.throughStatics(b, link);
15521
+ if (through.length === 0) this.passing.delete(b);
15522
+ }
15523
+ }
15294
15524
  outOfStatics(b, link) {
15295
15525
  if (!this.world.penetration) return;
15296
15526
  const axis2 = this.outAxis;
@@ -16132,7 +16362,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
16132
16362
  var KEEP_EVERY = 0.5;
16133
16363
  var SURFACE_CELL = 0.5;
16134
16364
  var SURFACE_CELLS_ACROSS = 24;
16135
- var cellKey = (ix, iz) => (ix + 32768) * 65536 + (iz + 32768);
16365
+ var cellKey2 = (ix, iz) => (ix + 32768) * 65536 + (iz + 32768);
16136
16366
  var KNOCK_FLAT = 0.5;
16137
16367
  var SEPARATE_SPEED = 1.5;
16138
16368
  var LIFT_DEPTH = STEP;
@@ -16304,7 +16534,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
16304
16534
  }
16305
16535
  /** Contact blows on the fixed parts become `blunt` hits of `destruction` (`engine-impacts.ts`). Returns the way to stop it. */
16306
16536
  contactHits(destruction, options) {
16307
- return createEngineImpacts(this.loop, this.engine.statics, destruction, options);
16537
+ return createEngineImpacts(this.loop, this.engine.statics, destruction, options, (body) => this.engine.pieceOfBody(body)?.debris === true);
16308
16538
  }
16309
16539
  /**
16310
16540
  * The pieces a blast at `point` can reach: the bodies the engine's `blastQuery` finds within `radius` (the pieces among them), in the order of `list`, and the pieces that have no
@@ -16825,7 +17055,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
16825
17055
  this.wideSurfaces.push(one);
16826
17056
  continue;
16827
17057
  }
16828
- for (let ix = x0; ix <= x1; ix++) for (let iz = z0; iz <= z1; iz++) this.intoCell(cellKey(ix, iz), one);
17058
+ for (let ix = x0; ix <= x1; ix++) for (let iz = z0; iz <= z1; iz++) this.intoCell(cellKey2(ix, iz), one);
16829
17059
  }
16830
17060
  for (const one of this.wideSurfaces) for (const key of this.surfaceGrid.keys()) this.intoCell(key, one);
16831
17061
  for (let i = 0; i < this.cellLists.length; i++) if (this.cellLists[i].length !== this.cellCounts[i]) this.cellLists[i].length = this.cellCounts[i];
@@ -16880,7 +17110,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
16880
17110
  }
16881
17111
  /** The surfaces whose cell holds `(x, z)`, the wide ones (`wideSurfaces`) among them. */
16882
17112
  surfacesAt(x, z) {
16883
- return this.surfaceGrid.get(cellKey(Math.floor(x / SURFACE_CELL), Math.floor(z / SURFACE_CELL))) ?? this.wideSurfaces;
17113
+ return this.surfaceGrid.get(cellKey2(Math.floor(x / SURFACE_CELL), Math.floor(z / SURFACE_CELL))) ?? this.wideSurfaces;
16884
17114
  }
16885
17115
  /** The highest top of a piece (other than `self`) under `(x, z)` that a point at height `y` stands on (at most `step` above it), -Infinity when none; the boxes of the last update. */
16886
17116
  topAt(x, z, y, step, self) {
@@ -16973,13 +17203,13 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
16973
17203
  if (most === void 0 || !Number.isFinite(most)) return;
16974
17204
  let awake = 0;
16975
17205
  for (const b of this.list) {
16976
- if (b.sleeping || b.held) continue;
17206
+ if (b.sleeping || b.held || b.debris) continue;
16977
17207
  if (this.hasComeToRest(b) && (b.balancing || b.still >= SLEEP_AFTER && !b.hinge && !this.onSteepSupport(b))) this.sleepByBudget(b);
16978
17208
  else awake++;
16979
17209
  }
16980
17210
  for (const b of this.list) {
16981
17211
  if (awake <= most) return;
16982
- if (b.sleeping || b.held || !this.hasComeToRest(b)) continue;
17212
+ if (b.sleeping || b.held || b.debris || !this.hasComeToRest(b)) continue;
16983
17213
  this.sleepByBudget(b);
16984
17214
  awake--;
16985
17215
  }
@@ -16998,12 +17228,13 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
16998
17228
  const c = this.centerOf(b, this.p);
16999
17229
  return Math.hypot(c.x - focus[0], c.y - focus[1], c.z - focus[2]) > keep.far.distance;
17000
17230
  };
17001
- const atRest = this.list.filter((b) => !b.held && this.hasComeToRest(b));
17231
+ const pieces = this.list.filter((b) => !b.debris);
17232
+ const atRest = pieces.filter((b) => !b.held && this.hasComeToRest(b));
17002
17233
  if (keep.far.action === "sleep") {
17003
17234
  for (const b of atRest) if (!b.sleeping && isFarAndOld(b)) this.sleepByBudget(b);
17004
17235
  }
17005
17236
  const fades = keep.far.action === "fade";
17006
- let over2 = this.list.length - keep.maxLive;
17237
+ let over2 = pieces.length - keep.maxLive;
17007
17238
  const far2 = new Set(atRest.filter(isFarAndOld));
17008
17239
  for (const b of [...atRest].sort((a, c) => Number(far2.has(c)) - Number(far2.has(a)))) {
17009
17240
  if (!(over2 > 0 || fades && far2.has(b))) return;
@@ -24126,9 +24357,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
24126
24357
  at3[p.thin] = Math.sign(lp[p.thin]) * p.dims[p.thin] / 2;
24127
24358
  const r = vec.distance(toWorld(p.pos, p.q, at3), centre);
24128
24359
  const side = sideOnOverpressure(tnt, r);
24129
- const reflected = 2 * side + 6 * side * side / (side + 7 * 101325);
24360
+ const reflected2 = 2 * side + 6 * side * side / (side + 7 * 101325);
24130
24361
  const impulse = bodyImpulse(tnt, r);
24131
- if (reflected > PANEL_PRESSURE && impulse > PANEL_IMPULSE && (reflected - PANEL_PRESSURE) * (impulse - PANEL_IMPULSE) >= PANEL_PI) loaded++;
24362
+ if (reflected2 > PANEL_PRESSURE && impulse > PANEL_IMPULSE && (reflected2 - PANEL_PRESSURE) * (impulse - PANEL_IMPULSE) >= PANEL_PI) loaded++;
24132
24363
  }
24133
24364
  if (loaded < PANEL_POINTS_LOADED) return false;
24134
24365
  const grid = gridOf(p);
@@ -28820,6 +29051,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
28820
29051
  var UNDERMINED_KEEP = 0.6;
28821
29052
  var SOLIDS_MAX = 64;
28822
29053
  var UNDERMINED_PUSH = 0.6;
29054
+ var DEBRIS_ID = "debris#";
28823
29055
  var UNDERMINED_STILL = 0.05;
28824
29056
  var SOLID_WELD = 1e-4;
28825
29057
  var UNCHECKED_KINDS = /* @__PURE__ */ new Set(["structure", "room", "ground"]);
@@ -29053,6 +29285,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
29053
29285
  /** The parts the ground went down under, drawn going down (`subside`). */
29054
29286
  __publicField(this, "settlement");
29055
29287
  __publicField(this, "fragments");
29288
+ /** Count of the bodies made for big debris: each gets an id of its own. */
29289
+ __publicField(this, "debrisMade", 0);
29056
29290
  __publicField(this, "ground");
29057
29291
  __publicField(this, "pieceSys");
29058
29292
  __publicField(this, "cages");
@@ -29139,7 +29373,34 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
29139
29373
  // and it meets the walls, ceilings and furniture on its way: it stops on their face instead of flying into them
29140
29374
  sweep: (from, direction, distance) => typeof this.world.raycast === "function" ? this.world.raycast([from[0], from[1], from[2]], [direction[0], direction[1], direction[2]], distance) : null,
29141
29375
  maxAwake: o.maxAwakeFragments ?? Infinity,
29142
- ...o.interpolate ? { interpolate: true } : {}
29376
+ ...o.interpolate ? { interpolate: true } : {},
29377
+ rigid: {
29378
+ add: (mesh2, half, mass, velocity, angular) => {
29379
+ const body = this.pieceSys.create(`${DEBRIS_ID}${++this.debrisMade}`, mesh2, [half[0], half[1], half[2]], new THREE.Vector3(), mass, [velocity[0], velocity[1], velocity[2]], [angular[0], angular[1], angular[2]]);
29380
+ body.debris = true;
29381
+ return body;
29382
+ },
29383
+ remove: (handle) => this.pieceSys.remove(handle.objectId),
29384
+ push: (handle, x, z) => {
29385
+ const body = handle;
29386
+ body.velocity[0] = x;
29387
+ body.velocity[2] = z;
29388
+ body.velocity[1] = Math.max(body.velocity[1], 0.3);
29389
+ body.sleeping = false;
29390
+ body.still = 0;
29391
+ body.calmAt = null;
29392
+ },
29393
+ shove: (handle, velocity, spin) => {
29394
+ const body = handle;
29395
+ for (let i = 0; i < 3; i++) {
29396
+ body.velocity[i] = body.velocity[i] + velocity[i];
29397
+ body.angularVelocity[i] = body.angularVelocity[i] + spin[i];
29398
+ }
29399
+ body.sleeping = false;
29400
+ body.still = 0;
29401
+ body.calmAt = null;
29402
+ }
29403
+ }
29143
29404
  });
29144
29405
  this.cages = new RebarCages(THREE, o.scene);
29145
29406
  this.settledBatches = new SettledBatches(THREE, o.scene, o.settledBatches ?? { enabled: false });
@@ -29611,10 +29872,11 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
29611
29872
  return shape === 0 ? 1 : drawn / shape;
29612
29873
  }
29613
29874
  pieces() {
29614
- return [...this.pieceSys.list];
29875
+ return this.pieceSys.list.filter((piece) => !piece.debris);
29615
29876
  }
29616
29877
  piece(objectId) {
29617
- return this.pieceSys.get(objectId);
29878
+ const piece = this.pieceSys.get(objectId);
29879
+ return piece && !piece.debris ? piece : null;
29618
29880
  }
29619
29881
  impulse(objectId, impulse, point) {
29620
29882
  const p = this.pieceSys.get(objectId);
@@ -29642,6 +29904,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
29642
29904
  }
29643
29905
  /** A piece thrown into a wall: the wall takes the blow of its weight where it met it, the piece takes it too, and each sounds as its material does. */
29644
29906
  slam(p, hit, speed) {
29907
+ if (p.debris) return;
29645
29908
  const energy = 0.5 * p.mass * speed * speed;
29646
29909
  const direction = [-hit.normal[0], -hit.normal[1], -hit.normal[2]];
29647
29910
  this.landingSound(hit.object, hit.point, clamp6(speed / 10, 0.2, 1));
@@ -29653,6 +29916,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
29653
29916
  }
29654
29917
  }
29655
29918
  hardLanding(p, point, speed) {
29919
+ if (p.debris) return;
29656
29920
  this.landingSound(p.objectId, point, clamp6(speed / 10, 0.2, 1));
29657
29921
  this.syncBound(p.objectId);
29658
29922
  try {
@@ -30261,7 +30525,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
30261
30525
  for (const [id, a] of this.staticNow()) scan(a, id, null, 6);
30262
30526
  const c = this.v1;
30263
30527
  for (const pc of this.pieceSys.list) {
30264
- if (pc.held) continue;
30528
+ if (pc.held || pc.debris) continue;
30265
30529
  this.pieceSys.centerOf(pc, c);
30266
30530
  const reach2 = Math.hypot(pc.halfExtents[0], pc.halfExtents[1], pc.halfExtents[2]) + radius;
30267
30531
  if (Math.abs(c.x - x) > reach2 || Math.abs(c.z - z) > reach2) continue;
@@ -31830,7 +32094,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
31830
32094
  reach2(distance, { objectId: pc.objectId, generation: pc.generation, impulse, point }, [c.x, c.y, c.z]);
31831
32095
  };
31832
32096
  const reached = this.o.blastQuery ? this.pieceSys.piecesInBlast(this.o.blastQuery, p, ev.radius) : [...this.pieceSys.list];
31833
- for (const pc of reached) shove(pc);
32097
+ for (const pc of reached) if (!pc.debris) shove(pc);
31834
32098
  if (this.o.shoveable) this.loosen(p, ev.radius, energy, reachOf2, policy, reach2);
31835
32099
  this.advanceWakes(0);
31836
32100
  this.fragments.blast(p, ev.radius, Math.min(20, Math.sqrt(energy) * 0.08));
@@ -31898,6 +32162,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
31898
32162
  if (centre.distanceTo(point) <= ev.radius) cover.set(objectId, reach2.call(this.world, ev.point, [centre.x, centre.y, centre.z], { ignore: [ev.object, objectId] }));
31899
32163
  };
31900
32164
  for (const pc of this.pieceSys.list) {
32165
+ if (pc.debris) continue;
31901
32166
  this.pieceSys.centerOf(pc, centre);
31902
32167
  read(pc.objectId);
31903
32168
  }