@adatechnology/game-weapons-three 0.21.0 → 0.21.2

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.
@@ -15024,7 +15024,7 @@ var GameWeaponsThree = (() => {
15024
15024
  heat: DEFAULT_HEAT,
15025
15025
  noiseBurst: { step: 0.05, window: 3, cap: 0.5 },
15026
15026
  // jogo.js (Jogo) explosionsUpdate 68300-68312: vy -= 9,8·dt; chão vy·-0,35 e vx,vz·0,6; parede v·-0,4
15027
- explosives: { gravity: 9.8, groundRestitution: 0.35, groundFriction: 0.6, wallRestitution: 0.4, placeFuseFrom: 10, tripwire: { length: 10, angleDeg: 0, height: 0.15 } },
15027
+ explosives: { gravity: 9.8, groundRestitution: 0.35, groundFriction: 0.6, wallRestitution: 0.4, placeFuseFrom: 10, tripwire: { length: 10, angleDeg: 0, height: 0.15 }, unarmedImpact: "detonate", restSpeed: 0.5, selfDestructSeconds: 20 },
15028
15028
  // Arsenal §11: montar e desmontar exige chave de fenda ou bancada; 2/15/30 s e a troca do lança-granadas (0,8 s) são padrões aprovados pelo dono (2026-10-24)
15029
15029
  attachments: { fitSeconds: { field: 2, tool: 15, bench: 30 }, switchSeconds: 0.8, speedOfSound: 343 },
15030
15030
  // Arsenal §08: tempo de mira = 0,15 s + 0,05 s por kg. O quadril do Arsenal é ×6 (o ZombiAdA liga isso por configuração); o SDK é neutro (1)
@@ -15073,6 +15073,8 @@ var GameWeaponsThree = (() => {
15073
15073
  var distance = (a, b) => length(subtract(a, b));
15074
15074
  var negate = (v) => [0 - v[0], 0 - v[1], 0 - v[2]];
15075
15075
  var EPS = 1e-9;
15076
+ var STILL_STEPS = 2;
15077
+ var STILL_SHARE = 0.05;
15076
15078
  var bounce = (velocity, normal, ground, rules) => {
15077
15079
  const along = dot(velocity, normal);
15078
15080
  if (along >= 0) return velocity;
@@ -15100,6 +15102,8 @@ var GameWeaponsThree = (() => {
15100
15102
  __publicField(this, "isArmed");
15101
15103
  __publicField(this, "isDone", false);
15102
15104
  __publicField(this, "isDud", false);
15105
+ __publicField(this, "isLaunched");
15106
+ __publicField(this, "stillSteps", 0);
15103
15107
  this.explosive = init.explosive;
15104
15108
  this.position = [init.origin[0], init.origin[1], init.origin[2]];
15105
15109
  this.velocity = init.velocity ? [init.velocity[0], init.velocity[1], init.velocity[2]] : [0, 0, 0];
@@ -15109,6 +15113,7 @@ var GameWeaponsThree = (() => {
15109
15113
  this.isArmed = this.armDistance <= 0;
15110
15114
  this.fuseLeft = this.triggers.has("timer") ? init.fuse : void 0;
15111
15115
  this.rules = init.rules;
15116
+ this.isLaunched = this.triggers.has("impact") && this.moves();
15112
15117
  }
15113
15118
  get age() {
15114
15119
  return this.clock;
@@ -15138,6 +15143,10 @@ var GameWeaponsThree = (() => {
15138
15143
  const slice = this.fuseLeft === void 0 ? seconds : Math.min(seconds, this.fuseLeft);
15139
15144
  this.fly(slice, probe, events);
15140
15145
  if (this.isDone) return events;
15146
+ if (this.isLaunched && this.isSpent()) {
15147
+ events.push(this.detonate(this.clock >= this.rules.selfDestructSeconds ? "timer" : "impact"));
15148
+ return events;
15149
+ }
15141
15150
  if (this.fuseLeft !== void 0) {
15142
15151
  this.fuseLeft -= slice;
15143
15152
  if (this.fuseLeft <= EPS) events.push(this.detonate("timer"));
@@ -15153,11 +15162,17 @@ var GameWeaponsThree = (() => {
15153
15162
  moves() {
15154
15163
  return length(this.velocity) > EPS;
15155
15164
  }
15165
+ /** A launched round that came to rest (stopped, or still for `STILL_STEPS` steps) or flew past its self-destruct time. */
15166
+ isSpent() {
15167
+ if (this.clock >= this.rules.selfDestructSeconds) return true;
15168
+ return !this.moves() || this.stillSteps >= STILL_STEPS;
15169
+ }
15156
15170
  fly(seconds, probe, events) {
15157
15171
  if (seconds <= 0 || !this.moves()) {
15158
15172
  this.clock += Math.max(0, seconds);
15159
15173
  return;
15160
15174
  }
15175
+ const start = this.position;
15161
15176
  this.velocity = [this.velocity[0], this.velocity[1] - this.rules.gravity * seconds, this.velocity[2]];
15162
15177
  const next = [this.position[0] + this.velocity[0] * seconds, this.position[1] + this.velocity[1] * seconds, this.position[2] + this.velocity[2] * seconds];
15163
15178
  const hit = probe?.(this.position, next) ?? null;
@@ -15166,11 +15181,12 @@ var GameWeaponsThree = (() => {
15166
15181
  const planned = distance(this.position, next);
15167
15182
  this.flown += moved;
15168
15183
  this.position = [target[0], target[1], target[2]];
15169
- const hitAt = this.clock + (hit && planned > EPS ? seconds * Math.min(1, moved / planned) : seconds);
15184
+ const hitAt2 = this.clock + (hit && planned > EPS ? seconds * Math.min(1, moved / planned) : seconds);
15170
15185
  this.clock += seconds;
15171
15186
  if (length(this.velocity) > EPS) this.facing = normalize(this.velocity);
15187
+ this.stillSteps = distance(start, this.position) < this.rules.restSpeed * STILL_SHARE * seconds ? this.stillSteps + 1 : 0;
15172
15188
  this.checkArmed(events);
15173
- if (hit) this.onImpact(hit, hitAt, events);
15189
+ if (hit) this.onImpact(hit, hitAt2, events);
15174
15190
  }
15175
15191
  checkArmed(events) {
15176
15192
  if (this.isArmed || this.flown < this.armDistance) return;
@@ -15180,7 +15196,7 @@ var GameWeaponsThree = (() => {
15180
15196
  onImpact(hit, at4, events) {
15181
15197
  events.push({ type: "impact", at: at4, point: hit.point, armed: this.isArmed });
15182
15198
  if (this.triggers.has("impact")) {
15183
- if (this.isArmed) events.push(this.detonate("impact", at4));
15199
+ if (this.isArmed || this.rules.unarmedImpact !== "dud") events.push(this.detonate("impact", at4));
15184
15200
  else {
15185
15201
  this.isDone = true;
15186
15202
  this.isDud = true;
@@ -22354,21 +22370,19 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
22354
22370
  for (const row of rows.values()) for (const i of row) if (!held.has(i)) loose.push(i);
22355
22371
  return loose;
22356
22372
  };
22357
- var clumpCells = (cells, thin, cap) => {
22373
+ var clumpUnits = (cells, thin, unit, cap) => {
22358
22374
  if (cells.length <= cap) return [...cells];
22359
22375
  const [u, v] = planeAxes(thin);
22360
- let lo0 = Infinity, lo1 = Infinity, hi0 = -Infinity, hi1 = -Infinity;
22376
+ let lo0 = Infinity, lo1 = Infinity;
22361
22377
  for (const cell of cells) {
22362
22378
  lo0 = Math.min(lo0, cell.center[u] - cell.size[u] / 2);
22363
- hi0 = Math.max(hi0, cell.center[u] + cell.size[u] / 2);
22364
22379
  lo1 = Math.min(lo1, cell.center[v] - cell.size[v] / 2);
22365
- hi1 = Math.max(hi1, cell.center[v] + cell.size[v] / 2);
22366
22380
  }
22367
- let side = Math.sqrt((hi0 - lo0) * (hi1 - lo1) / cap);
22368
- for (; ; ) {
22381
+ let along = 1, up = 1;
22382
+ for (let grow = 0; ; grow++) {
22369
22383
  const bins = /* @__PURE__ */ new Map();
22370
22384
  for (const cell of cells) {
22371
- const key2 = `${Math.floor((cell.center[u] - lo0) / side)}:${Math.floor((cell.center[v] - lo1) / side)}`;
22385
+ const key2 = `${Math.floor((cell.center[u] - lo0) / (along * unit[0]))}:${Math.floor((cell.center[v] - lo1) / (up * unit[1]))}`;
22372
22386
  const bin = bins.get(key2) ?? { lo: [Infinity, Infinity, Infinity], hi: [-Infinity, -Infinity, -Infinity] };
22373
22387
  for (let k = 0; k < 3; k++) {
22374
22388
  bin.lo[k] = Math.min(bin.lo[k], cell.center[k] - cell.size[k] / 2);
@@ -22379,7 +22393,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
22379
22393
  if (bins.size <= cap) {
22380
22394
  return [...bins.values()].map(({ lo, hi }) => ({ center: [(lo[0] + hi[0]) / 2, (lo[1] + hi[1]) / 2, (lo[2] + hi[2]) / 2], size: [hi[0] - lo[0], hi[1] - lo[1], hi[2] - lo[2]] }));
22381
22395
  }
22382
- side *= 1.25;
22396
+ if (grow % 2 === 0) up++;
22397
+ else along++;
22383
22398
  }
22384
22399
  };
22385
22400
  var MAX_SPALLS = 64;
@@ -22448,6 +22463,39 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
22448
22463
  for (const x of spread(dims[u], COVER, spacing, MAX_BARS_PER_DIRECTION)) out.push(bar(v, dims[v] / 2 - 0.02, [[u, x], [thin, 0]]));
22449
22464
  return out;
22450
22465
  };
22466
+ var STIRRUP_SPACING = 0.15;
22467
+ var memberStirrups = (dims, spacing = STIRRUP_SPACING) => {
22468
+ if (!isMember(dims)) return [];
22469
+ const long = dims.indexOf(Math.max(...dims));
22470
+ const [u = 0, v = 0] = [0, 1, 2].filter((i) => i !== long);
22471
+ const hu = dims[u] / 2 - COVER, hv = dims[v] / 2 - COVER;
22472
+ const out = [];
22473
+ for (const s of spread(dims[long], 0.05, spacing, 200)) {
22474
+ const corner = (x, y) => {
22475
+ const c = [0, 0, 0];
22476
+ c[long] = s;
22477
+ c[u] = x;
22478
+ c[v] = y;
22479
+ return c;
22480
+ };
22481
+ out.push([corner(-hu, -hv), corner(hu, -hv)], [corner(hu, -hv), corner(hu, hv)], [corner(hu, hv), corner(-hu, hv)], [corner(-hu, hv), corner(-hu, -hv)]);
22482
+ }
22483
+ return out;
22484
+ };
22485
+ var clipBarsToVolume = (bars, center, size) => {
22486
+ const out = [];
22487
+ for (const [a, b] of bars) {
22488
+ const axis2 = [0, 1, 2].find((k) => a[k] !== b[k]) ?? 0;
22489
+ if ([0, 1, 2].some((k) => k !== axis2 && Math.abs(a[k] - center[k]) > size[k] / 2 + 1e-6)) continue;
22490
+ const lo = Math.max(Math.min(a[axis2], b[axis2]), center[axis2] - size[axis2] / 2), hi = Math.min(Math.max(a[axis2], b[axis2]), center[axis2] + size[axis2] / 2);
22491
+ if (hi - lo < 1e-6) continue;
22492
+ const p = [a[0], a[1], a[2]], q = [b[0], b[1], b[2]];
22493
+ p[axis2] = lo;
22494
+ q[axis2] = hi;
22495
+ out.push([p, q]);
22496
+ }
22497
+ return out;
22498
+ };
22451
22499
  var clipBarsToBox = (bars, u, v, center, size) => {
22452
22500
  const out = [];
22453
22501
  for (const [a, b] of bars) {
@@ -22861,6 +22909,120 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
22861
22909
  const stable = converged && cholesky3(ev.Jt, [0, 0, 0]) !== null;
22862
22910
  return { s, a, b, stable, yielded: ev.yielded, bearing: capSum > 0 ? weight / capSum : Infinity, edge: ev.edge, residual: [ev.r[0], ev.r[1], ev.r[2]] };
22863
22911
  };
22912
+ function voidRuns(flags, step) {
22913
+ const runs = [];
22914
+ let start = -1;
22915
+ for (let i = 0; i <= flags.length; i++) {
22916
+ if (i < flags.length && flags[i]) {
22917
+ if (start < 0) start = i;
22918
+ continue;
22919
+ }
22920
+ if (start >= 0) runs.push({ start: start * step, end: i * step });
22921
+ start = -1;
22922
+ }
22923
+ return runs;
22924
+ }
22925
+ var PILLAR_REACH = 0.15;
22926
+ var pillarNear = (pillars, at4) => pillars.some((p) => Math.abs(p - at4) <= PILLAR_REACH);
22927
+ function splitAtPillars(runs, pillars) {
22928
+ const out = [];
22929
+ for (const run of runs) {
22930
+ const inside2 = pillars.filter((p) => p > run.start + PILLAR_REACH && p < run.end - PILLAR_REACH).sort((a, b) => a - b);
22931
+ let from = run.start;
22932
+ for (const p of inside2) {
22933
+ out.push({ start: from, end: p });
22934
+ from = p;
22935
+ }
22936
+ out.push({ start: from, end: run.end });
22937
+ }
22938
+ return out;
22939
+ }
22940
+ function mergeRuns(runs, check2) {
22941
+ let list2 = [...runs];
22942
+ for (let changed = true; changed; ) {
22943
+ changed = false;
22944
+ for (let k = 0; k <= list2.length && !changed; k++) {
22945
+ const before = list2[k - 1];
22946
+ const after2 = list2[k];
22947
+ const from = before ? before.end : 0;
22948
+ const to = after2 ? after2.start : check2.length;
22949
+ const soil = to - from;
22950
+ if (soil <= 0 || !before && !after2) continue;
22951
+ if (check2.pillars.some((p) => p >= from - PILLAR_REACH && p <= to + PILLAR_REACH)) continue;
22952
+ if (!before && check2.continuous?.[0] || !after2 && check2.continuous?.[1]) continue;
22953
+ const reaction = (before ? (before.end - before.start) / 2 : 0) + (after2 ? (after2.end - after2.start) / 2 : 0);
22954
+ const narrow = soil < check2.depth;
22955
+ const weak = reaction > (check2.soilSafety - 1) * soil;
22956
+ if (!narrow && !weak) continue;
22957
+ const merged2 = { start: before ? before.start : 0, end: after2 ? after2.end : check2.length };
22958
+ list2 = [...list2.slice(0, Math.max(0, k - 1)), merged2, ...list2.slice(after2 ? k + 1 : k)];
22959
+ changed = true;
22960
+ }
22961
+ }
22962
+ return list2;
22963
+ }
22964
+ function judgeBeam(flags, step, check2) {
22965
+ const merged2 = mergeRuns(voidRuns(flags, step), check2);
22966
+ const runs = splitAtPillars(merged2, check2.pillars);
22967
+ const behind = (run, fromStart) => fromStart ? (merged2.find((m) => m.start >= run.end - 1e-9)?.start ?? check2.length) - run.end : run.start - ([...merged2].reverse().find((m) => m.end <= run.start + 1e-9)?.end ?? 0);
22968
+ const verdicts = [];
22969
+ let tips = false;
22970
+ for (const run of runs) {
22971
+ const span = run.end - run.start;
22972
+ const freeStart = run.start <= 1e-9 && !pillarNear(check2.pillars, 0) && !check2.continuous?.[0];
22973
+ const freeEnd = run.end >= check2.length - 1e-9 && !pillarNear(check2.pillars, check2.length) && !check2.continuous?.[1];
22974
+ if (freeStart && freeEnd) {
22975
+ verdicts.push({ ...run, kind: "cantilever", span, moment: Infinity, holds: false, cracks: true });
22976
+ tips = true;
22977
+ continue;
22978
+ }
22979
+ const cantilever = freeStart || freeEnd;
22980
+ const moment = (cantilever ? check2.load * span * span / 2 : check2.load * span * span / 8) * check2.loadFactor;
22981
+ const reach = cantilever ? check2.spanDepth * check2.depth / 2 : check2.spanDepth * check2.depth;
22982
+ const balanced = !cantilever || span <= behind(run, freeStart);
22983
+ const rooted = cantilever && pillarNear(check2.pillars, freeStart ? run.end : run.start);
22984
+ const held = cantilever && !!check2.continuous?.[freeStart ? 1 : 0];
22985
+ const holds3 = span <= reach && moment <= check2.resists && (balanced || rooted);
22986
+ verdicts.push({ ...run, kind: cantilever ? "cantilever" : "span", span, moment, holds: holds3, cracks: moment > check2.cracking });
22987
+ if (cantilever && !holds3 && !balanced && !rooted && !held) tips = true;
22988
+ }
22989
+ return { runs: verdicts, tips };
22990
+ }
22991
+ function judgePlate(check2) {
22992
+ const a = check2.across;
22993
+ const moment = (check2.load * a * a / 8 + check2.points.reduce((sum2, p) => sum2 + p.weight * a / 4, 0)) * check2.loadFactor;
22994
+ const d = Math.max(0.01, check2.effectiveDepth);
22995
+ const punched = check2.points.some((p) => p.weight * check2.loadFactor / (4 * (p.side + d) * d) > check2.punching);
22996
+ return { holds: moment <= check2.resists && !punched, cracks: moment > check2.cracking, moment, punched };
22997
+ }
22998
+ var cross2 = (o, a, b) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);
22999
+ function convexHull(points) {
23000
+ const sorted = [...points].sort((a, b) => a[0] - b[0] || a[1] - b[1]);
23001
+ if (sorted.length < 3) return sorted;
23002
+ const lower = [];
23003
+ for (const p of sorted) {
23004
+ while (lower.length >= 2 && cross2(lower[lower.length - 2], lower[lower.length - 1], p) <= 0) lower.pop();
23005
+ lower.push(p);
23006
+ }
23007
+ const upper = [];
23008
+ for (let i = sorted.length - 1; i >= 0; i--) {
23009
+ const p = sorted[i];
23010
+ while (upper.length >= 2 && cross2(upper[upper.length - 2], upper[upper.length - 1], p) <= 0) upper.pop();
23011
+ upper.push(p);
23012
+ }
23013
+ return [...lower.slice(0, -1), ...upper.slice(0, -1)];
23014
+ }
23015
+ function restsOver(point, contacts, margin) {
23016
+ const hull = convexHull(contacts);
23017
+ if (hull.length < 3) return false;
23018
+ for (let i = 0; i < hull.length; i++) {
23019
+ const a = hull[i];
23020
+ const b = hull[(i + 1) % hull.length];
23021
+ const length2 = Math.hypot(b[0] - a[0], b[1] - a[1]) || 1;
23022
+ if (cross2(a, b, point) / length2 < margin) return false;
23023
+ }
23024
+ return true;
23025
+ }
22864
23026
  var GROUND_LOSS_DEFAULTS = {
22865
23027
  footingDepth: 0.5,
22866
23028
  spread: 1,
@@ -22868,6 +23030,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
22868
23030
  maxSettlement: 0.05,
22869
23031
  crackDistortion: 1 / 300,
22870
23032
  damageDistortion: 1 / 150,
23033
+ bearingCrackDistortion: 1 / 500,
23034
+ bearingDamageDistortion: 1 / 300,
22871
23035
  distortionDamage: 0.3,
22872
23036
  bridgeSpanDepth: 10,
22873
23037
  beamRebarRatio: 4e-3
@@ -22887,33 +23051,77 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
22887
23051
  const steepest = loss.radius * loss.radius / (2 * loss.depth * spread2);
22888
23052
  return Math.max(0, cut(reach), cut(Math.min(reach, steepest)), cut(0));
22889
23053
  };
22890
- var longestRun = (flags) => {
22891
- let best = null;
22892
- let start = -1;
22893
- for (let i = 0; i <= flags.length; i++) {
22894
- if (i < flags.length && flags[i]) {
22895
- if (start < 0) start = i;
22896
- continue;
22897
- }
22898
- if (start >= 0 && (!best || i - start > best.end - best.start)) best = { start, end: i };
22899
- start = -1;
22900
- }
22901
- return best;
23054
+ var relativeToChord = (drops) => {
23055
+ const n = drops.length;
23056
+ if (n < 2) return drops.map(() => 0);
23057
+ const first = drops[0];
23058
+ const last = drops[n - 1];
23059
+ return drops.map((v, k) => v - (first + (last - first) * k / (n - 1)));
22902
23060
  };
22903
23061
  var distortionOf = (drops, step) => {
22904
23062
  const span = Math.max(1, Math.round(DISTORTION_BASE / step));
22905
23063
  let value = 0;
22906
23064
  let at4 = 0;
23065
+ let down = 1;
22907
23066
  for (let i = 0; i < drops.length; i++) {
22908
23067
  const j = Math.min(drops.length - 1, i + span);
22909
23068
  if (j === i) continue;
22910
- const beta = Math.abs(drops[j] - drops[i]) / Math.max((j - i) * step, DISTORTION_BASE);
23069
+ const change = drops[j] - drops[i];
23070
+ const beta = Math.abs(change) / Math.max((j - i) * step, DISTORTION_BASE);
22911
23071
  if (beta > value) {
22912
23072
  value = beta;
22913
23073
  at4 = (i + j) / 2;
23074
+ down = change >= 0 ? 1 : -1;
23075
+ }
23076
+ }
23077
+ return { value, at: at4, down };
23078
+ };
23079
+ var smoothProfile = (drops, step, window2) => {
23080
+ const half = Math.max(0, Math.round(window2 / step / 2));
23081
+ return drops.map((_, k) => {
23082
+ let sum2 = 0;
23083
+ let count = 0;
23084
+ for (let i = Math.max(0, k - half); i <= Math.min(drops.length - 1, k + half); i++) {
23085
+ sum2 += drops[i];
23086
+ count++;
22914
23087
  }
23088
+ return sum2 / count;
23089
+ });
23090
+ };
23091
+ var BEAM_SPREAD = 1;
23092
+ var SETTLEMENT_POINTS = 24;
23093
+ var settlementProfile = (drops, step) => {
23094
+ const n = drops.length;
23095
+ if (n === 0) return [0, 0];
23096
+ const length2 = n * step;
23097
+ const count = Math.max(2, Math.min(SETTLEMENT_POINTS, n + 1));
23098
+ const out = [];
23099
+ for (let k = 0; k < count; k++) {
23100
+ const at4 = clampNumber(k / (count - 1) * length2 / step - 0.5, 0, n - 1);
23101
+ const i = Math.floor(at4);
23102
+ const j = Math.min(n - 1, i + 1);
23103
+ out.push(drops[i] + (drops[j] - drops[i]) * (at4 - i));
22915
23104
  }
22916
- return { value, at: at4 };
23105
+ return out;
23106
+ };
23107
+ var clampNumber = (v, a, b) => Math.max(a, Math.min(b, v));
23108
+ var settlementAt = (settlement, point) => {
23109
+ const d = [settlement.to[0] - settlement.from[0], settlement.to[1] - settlement.from[1], settlement.to[2] - settlement.from[2]];
23110
+ const length2 = d[0] * d[0] + d[1] * d[1] + d[2] * d[2];
23111
+ const t = length2 > 0 ? clampNumber(((point[0] - settlement.from[0]) * d[0] + (point[1] - settlement.from[1]) * d[1] + (point[2] - settlement.from[2]) * d[2]) / length2, 0, 1) : 0;
23112
+ const drops = settlement.drop;
23113
+ if (drops.length === 0) return 0;
23114
+ const at4 = t * (drops.length - 1);
23115
+ const i = Math.floor(at4);
23116
+ const j = Math.min(drops.length - 1, i + 1);
23117
+ return drops[i] + (drops[j] - drops[i]) * (at4 - i);
23118
+ };
23119
+ var mergeSettlement = (old, next) => {
23120
+ if (!old) return next;
23121
+ const same = old.from.every((v, k) => Math.abs(v - next.from[k]) < 1e-6) && old.to.every((v, k) => Math.abs(v - next.to[k]) < 1e-6);
23122
+ if (same && old.drop.length === next.drop.length) return { from: old.from, to: old.to, drop: old.drop.map((v, k) => Math.max(v, next.drop[k])) };
23123
+ const mean = (line) => line.drop.reduce((sum2, v) => sum2 + v, 0) / Math.max(1, line.drop.length);
23124
+ return mean(old) >= mean(next) ? old : next;
22917
23125
  };
22918
23126
  var wind_terrain_default = [
22919
23127
  { id: "I", zg: 250, b: { A: 1.1, B: 1.11, C: 1.12 }, p: { A: 0.06, B: 0.065, C: 0.07 }, z0: 5e-3 },
@@ -24710,6 +24918,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
24710
24918
  var SUPPORT_TOLERANCE = 0.05;
24711
24919
  var UNIT_FRAGMENT_FACTOR = 4;
24712
24920
  var BREACH_GRID_CAP = 4096;
24921
+ var MASONRY_CRUMBLE_SPEED = 0.6;
24922
+ var TILE_CLUMPS = 160;
24923
+ var TILE_THICKNESS = 0.018;
24924
+ var PANEL_EDGE_PILLAR = 2;
24925
+ var PANEL_EDGE_BASE = 4;
24926
+ var PANEL_EDGE_BEAM = 3;
24927
+ var PLASTER_FLAKE_AREA = 0.25;
24928
+ var MAX_PLASTER_FLAKES = 24;
24713
24929
  var CHIP_ENERGY = 200;
24714
24930
  var CHIP_SPLASH = 0.5;
24715
24931
  var CRATER_SPENT = 0.6;
@@ -24720,7 +24936,17 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
24720
24936
  var DISTORTION_GROWTH = 1.2;
24721
24937
  var MAX_SETTLEMENT_CRACKS = 4;
24722
24938
  var SETTLEMENT_CRACK_LENGTH = 0.3;
24939
+ var SETTLEMENT_CRACK_SPACING = 0.4;
24940
+ var SETTLEMENT_CRACK_OPENING = 0.3;
24941
+ var MIN_CRACK_WIDTH = 5e-4;
24942
+ var MAX_CRACK_WIDTH = 0.02;
24943
+ var BESIDE_CRACK_OFFSET = 0.8;
24944
+ var BRICK_STEP = [0.2, 0.1];
24945
+ var SETTLEMENT_FOLLOW_DEPTH = 2;
24723
24946
  var CRACKED_STIFFNESS = 0.4;
24947
+ var PILLAR_SEAT = 0.05;
24948
+ var PUNCHING_SHARE = 0.5;
24949
+ var ARCH_ANGLE = Math.PI / 3;
24724
24950
  var CUT_SLICE = 1;
24725
24951
  var cutFactorOf = (shape) => clamp2(Math.max(...shapeDims(shape)) / CUT_SLICE, 1, 50);
24726
24952
  var clamp2 = (v, a, b) => Math.max(a, Math.min(b, v));
@@ -24796,6 +25022,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
24796
25022
  for (const m of options.materials ?? []) materials.set(m.id, m);
24797
25023
  const ambient = options.ambientC ?? 20;
24798
25024
  const maxFragments = options.maxFragments ?? 24;
25025
+ const unitClumps = maxFragments * UNIT_FRAGMENT_FACTOR;
25026
+ const fallenClumps = Math.max(2, Math.round(unitClumps / 4));
24799
25027
  const maxDents = options.maxDents ?? 24;
24800
25028
  const maxHoles = options.maxHoles ?? 32;
24801
25029
  const fireSpread = options.fireSpread ?? 0.6;
@@ -25106,6 +25334,61 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25106
25334
  return (above2 + p.st.mass * share) / load;
25107
25335
  };
25108
25336
  };
25337
+ const contactsOf = (p, support) => {
25338
+ const box5 = contactBox(p, support);
25339
+ const broken = support.rt.broken;
25340
+ if (!broken?.length) return [box5];
25341
+ let pieces = [box5];
25342
+ for (const [axis2, from, to] of broken) {
25343
+ const a = [p.pos[0], p.pos[1], p.pos[2]];
25344
+ const b = [p.pos[0], p.pos[1], p.pos[2]];
25345
+ a[axis2] = from;
25346
+ b[axis2] = to;
25347
+ const la = toLocal(p.pos, p.q, a);
25348
+ const lb = toLocal(p.pos, p.q, b);
25349
+ const k = [0, 1, 2].reduce((best, c) => Math.abs(lb[c] - la[c]) > Math.abs(lb[best] - la[best]) ? c : best, 0);
25350
+ const lo = Math.min(la[k], lb[k]);
25351
+ const hi = Math.max(la[k], lb[k]);
25352
+ pieces = pieces.flatMap(([min2, max2]) => {
25353
+ if (hi <= min2[k] || lo >= max2[k]) return [[min2, max2]];
25354
+ const out = [];
25355
+ if (lo > min2[k]) {
25356
+ const end3 = [max2[0], max2[1], max2[2]];
25357
+ end3[k] = lo;
25358
+ out.push([min2, end3]);
25359
+ }
25360
+ if (hi < max2[k]) {
25361
+ const start = [min2[0], min2[1], min2[2]];
25362
+ start[k] = hi;
25363
+ out.push([start, max2]);
25364
+ }
25365
+ return out;
25366
+ });
25367
+ }
25368
+ return pieces;
25369
+ };
25370
+ const fixedJoint = (j) => j.spec.kind === "rebar" || j.spec.kind === "fused" || j.spec.kind === "weld";
25371
+ const standsOver = (o, p, lower) => {
25372
+ const role = p.spec.structure?.role;
25373
+ if (role !== "slab" && role !== "roof" || p.spec.shape.kind !== "box" || lower.length === 0) return true;
25374
+ if (Math.abs(rotateVec(p.q, [0, 0, 0].map((_, k) => k === p.thin ? 1 : 0))[1]) < 0.9) return true;
25375
+ const i = o.idx.get(p.spec.id);
25376
+ for (const j of o.byPart.get(p.spec.id) ?? []) {
25377
+ if (j.st.open) continue;
25378
+ if (fixedJoint(j) && lower.includes(restsOn(o, j, i)) || j.spec.kind === "tie") return true;
25379
+ }
25380
+ const corners = [];
25381
+ for (const k of lower) {
25382
+ for (const [lo, hi] of contactsOf(p, o.parts[k])) {
25383
+ for (let c = 0; c < 4; c++) {
25384
+ const local2 = [c & 1 ? hi[0] : lo[0], (lo[1] + hi[1]) / 2, c & 2 ? hi[2] : lo[2]];
25385
+ const at4 = toWorld(p.pos, p.q, local2);
25386
+ corners.push([at4[0], at4[2]]);
25387
+ }
25388
+ }
25389
+ }
25390
+ return restsOver([p.pos[0], p.pos[2]], corners, 0);
25391
+ };
25109
25392
  const borneOn = (p, supports) => {
25110
25393
  if (supports.length === 0) return void 0;
25111
25394
  const boxes = supports.map((support) => contactBox(p, support));
@@ -25161,7 +25444,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25161
25444
  const key2 = lower.join(",");
25162
25445
  if (key2 !== p.spanKey) {
25163
25446
  p.spanKey = key2;
25164
- p.span = spanOf(g, lower.map((k) => contactBox(p, o.parts[k])));
25447
+ p.span = spanOf(g, lower.flatMap((k) => contactsOf(p, o.parts[k])));
25165
25448
  }
25166
25449
  p.restMoment = 0;
25167
25450
  if (g.gravity < 0 || p.span <= 0) return 0;
@@ -25227,9 +25510,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25227
25510
  };
25228
25511
  const freeSpan = (p, supports) => {
25229
25512
  if (supports.length === 0) return Infinity;
25513
+ if (p.spec.shape.kind === "box") {
25514
+ const g = bendGeometry(p.spec);
25515
+ if (!g.member) return spanOf(g, supports.flatMap((k) => contactsOf(p, k)));
25516
+ }
25230
25517
  const d = p.dims;
25231
25518
  const L = [0, 1, 2].sort((a, b) => d[b] - d[a])[0];
25232
- const spans = supports.map((k) => contactBox(p, k)).map(([lo, hi]) => [lo[L], hi[L]]);
25519
+ const spans = supports.flatMap((k) => contactsOf(p, k)).map(([lo, hi]) => [lo[L], hi[L]]);
25233
25520
  let far = 0;
25234
25521
  for (let i = 0; i <= 16; i++) {
25235
25522
  const x = (i / 16 - 0.5) * d[L];
@@ -25279,7 +25566,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25279
25566
  }
25280
25567
  lowerOf.set(i, lower);
25281
25568
  const max2 = parts[i].spec.structure?.maxSpan;
25282
- if (max2 !== void 0 && !parts[i].anchored && freeSpan(parts[i], lower.map((k) => parts[k])) > max2) {
25569
+ const tooLong = max2 !== void 0 && freeSpan(parts[i], lower.map((k) => parts[k])) > max2;
25570
+ const standing = parts[i].heldAsDesigned || standsOver(o, parts[i], lower);
25571
+ if (o.seeding && !standing) parts[i].heldAsDesigned = true;
25572
+ if (!parts[i].anchored && (tooLong || !(standing || parts[i].heldAsDesigned))) {
25283
25573
  out.add(i);
25284
25574
  dropped = true;
25285
25575
  }
@@ -25733,20 +26023,45 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25733
26023
  if (!o.hasStructure || !o.parts.some((p) => p.anchored)) return;
25734
26024
  if (!pendingCollapse.has(o)) pendingCollapse.set(o, src);
25735
26025
  };
26026
+ const isLaidMasonry = (p) => !!p.spec.units && p.spec.units.mortar !== p.spec.material && !p.spec.reinforcement && !p.st.stripped;
26027
+ const isTiledCover = (p) => p.spec.structure?.role === "roof" && p.mat.fracture === "shatter" && !p.spec.reinforcement && !p.spec.units;
26028
+ const crumbleMasonry = (o, p, src) => {
26029
+ if (isLost(p)) return;
26030
+ const [u, v] = planeAxes(p.thin);
26031
+ const grid = gridOf(p);
26032
+ const worn = p.rt.chips ?? {};
26033
+ const op = p.st.opening ? toLocal(p.pos, p.q, p.st.opening.center) : null;
26034
+ const cells = grid.filter((cell, i) => worn[i] !== -1 && !(op && p.st.opening && Math.hypot(cell.center[u] - op[u], cell.center[v] - op[v]) <= p.st.opening.radius));
26035
+ const { c } = partXf(o, p);
26036
+ const tiles = isTiledCover(p);
26037
+ const pieces = cellFragments(o, p, clumpUnits(cells, p.thin, unitSpan(p), tiles ? TILE_CLUMPS : unitClumps), vec.add(c, [0, 1, 0]), null, MASONRY_CRUMBLE_SPEED, p.st.mass, "m_", true);
26038
+ const fragments = cells.length === 0 ? [] : tiles ? pieces.map((f) => ({ ...f, shape: "shard", size: f.size.map((x, k) => k === p.thin ? Math.min(x, TILE_THICKNESS) : x) })) : [...pieces, ...plasterFlakes(o, p, cells, vec.add(c, [0, 1, 0]), MASONRY_CRUMBLE_SPEED, "mp_")];
26039
+ p.st.status = "broken";
26040
+ p.st.hp = 0;
26041
+ p.st.mass = 0;
26042
+ emit2({ ...base(o, src), type: "fracture", part: p.spec.id, style: "crumble", fragments, point: c });
26043
+ debris2(o, p, p.mat.breakDebris, c, [0, 1, 0], clamp2(Math.round(Math.cbrt(partVolume(p.spec.shape)) * 30), 3, 20), 2, src);
26044
+ setStage(o, p, 3, {}, src);
26045
+ partLost(o, p, src);
26046
+ };
25736
26047
  const flushCollapse = () => {
25737
26048
  for (const [o, src] of [...pendingCollapse]) {
25738
26049
  pendingCollapse.delete(o);
25739
26050
  if (!objects.has(o.id) || objects.get(o.id) !== o) continue;
25740
- for (const g of o.st.groups) {
26051
+ const crumbling = [];
26052
+ for (const g of [...o.st.groups]) {
25741
26053
  const ps = g.map((id) => o.byId.get(id)).filter((p) => !isLost(p) && !o.collapsed.has(p.spec.id));
25742
26054
  if (ps.length === 0 || g.some((id) => o.byId.get(id).anchored) || !ps.some((p) => p.structural)) continue;
25743
- for (const p of ps) {
26055
+ const whole2 = ps.filter((p) => !isLaidMasonry(p) && !isTiledCover(p));
26056
+ crumbling.push(...ps.filter((p) => isLaidMasonry(p) || isTiledCover(p)));
26057
+ for (const p of whole2) {
25744
26058
  o.collapsed.add(p.spec.id);
25745
26059
  p.st.status = "collapsed";
25746
26060
  setStage(o, p, 3, {}, src);
25747
26061
  }
25748
- emit2({ ...base(o, src), type: "collapse", parts: ps.map((p) => p.spec.id), mass: ps.reduce((sum2, p) => sum2 + p.st.mass, 0) });
26062
+ if (whole2.length > 0) emit2({ ...base(o, src), type: "collapse", parts: whole2.map((p) => p.spec.id), mass: whole2.reduce((sum2, p) => sum2 + p.st.mass, 0) });
25749
26063
  }
26064
+ for (const p of crumbling) crumbleMasonry(o, p, src);
25750
26065
  }
25751
26066
  };
25752
26067
  const groundCfg = resolveGroundLoss(options.groundLoss);
@@ -25787,17 +26102,27 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25787
26102
  let sum2 = 0;
25788
26103
  let worst = -1;
25789
26104
  let deepest = toWorld(o.st.position, o.st.rotation, [(box5.min[0] + box5.max[0]) / 2, box5.min[1], (box5.min[2] + box5.max[2]) / 2]);
26105
+ let voidBox = null;
25790
26106
  for (let k = 0; k < n; k++) {
25791
26107
  let open = 0;
25792
26108
  let drop = 0;
26109
+ let cutSum = 0;
25793
26110
  for (let c = 0; c < m; c++) {
25794
26111
  const local2 = [0, box5.min[1], 0];
25795
26112
  local2[long] = box5.min[long] + (k + 0.5) * step;
25796
26113
  local2[across2] = box5.min[across2] + (c + 0.5) * (box5.max[across2] - box5.min[across2]) / m;
25797
26114
  const world2 = toWorld(o.st.position, o.st.rotation, local2);
25798
26115
  const cut = undercutAt(loss, Math.hypot(world2[0] - loss.x, world2[2] - loss.z), b.embed, groundCfg.spread);
25799
- if (cut >= groundCfg.voidDepth) open++;
26116
+ if (cut >= groundCfg.voidDepth) {
26117
+ open++;
26118
+ const along = local2[long] - box5.min[long];
26119
+ const side = local2[across2] - box5.min[across2];
26120
+ voidBox ?? (voidBox = { long: [along, along], across: [side, side] });
26121
+ voidBox.long = [Math.min(voidBox.long[0], along - step / 2), Math.max(voidBox.long[1], along + step / 2)];
26122
+ voidBox.across = [Math.min(voidBox.across[0], side), Math.max(voidBox.across[1], side)];
26123
+ }
25800
26124
  drop += Math.min(cut, groundCfg.maxSettlement);
26125
+ cutSum += cut;
25801
26126
  if (cut > worst) {
25802
26127
  worst = cut;
25803
26128
  deepest = world2;
@@ -25805,56 +26130,326 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25805
26130
  }
25806
26131
  voids += open;
25807
26132
  sum2 += drop;
25808
- slices.push({ void: open * 2 > m, drop: drop / m });
26133
+ slices.push({ void: open * 2 > m, drop: drop / m, cut: cutSum / m });
25809
26134
  }
25810
- return { long, step, slices, share: voids / (n * m), drop: sum2 / (n * m), deepest };
26135
+ return { long, step, slices, voidBox, share: voids / (n * m), drop: sum2 / (n * m), deepest };
25811
26136
  };
25812
- const bridgeOf = (b, fp, voids) => {
25813
- const p = b.p;
26137
+ const sectionOfBearer = (p) => {
25814
26138
  if (p.spec.shape.kind !== "box" || !p.mat.strength?.tensileMPa) return null;
25815
26139
  const g = bendGeometry(p.spec);
25816
26140
  if (g.gravity < 0) return null;
25817
26141
  const footing = p.spec.structure?.role === "foundation" && g.member && !isReinforced(p.spec);
25818
26142
  const spec = footing ? { ...p.spec, structure: { ...p.spec.structure, rebar: { ratio: groundCfg.beamRebarRatio } } } : p.spec;
25819
26143
  const section = { b: sectionWidth(g, g.gravity), h: g.dims[g.gravity] };
25820
- const m = sectionMoments(p.mat, section, tensionSteel(spec, g.dims, section, flexure), flexure);
25821
- const span = (voids.end - voids.start) * fp.step;
25822
- const cantilever = voids.start === 0 || voids.end === fp.slices.length;
25823
- const w = lineLoad(g, p.st.load ?? p.st.mass);
25824
- const moment = (cantilever ? w * span * span / 2 : spanMoment(w, span)) * structureSafety;
25825
- const whole2 = voids.start === 0 && voids.end === fp.slices.length;
25826
- const holds3 = !whole2 && span <= groundCfg.bridgeSpanDepth * section.h && moment <= (p.st.cracked ? m.steel : m.ultimate);
25827
- const cracks = moment > m.cracking;
25828
- const EI = (p.mat.strength.elasticGPa ?? 0) * 1e9 * section.b * section.h ** 3 * (cracks || p.st.cracked ? CRACKED_STIFFNESS : 1) / 12;
25829
- const sag = EI > 0 ? w * span ** 4 / (cantilever ? 8 * EI : 384 / 5 * EI) : groundCfg.maxSettlement;
25830
- return { holds: holds3, cracks, cantilever, span, depth: section.h, sag };
25831
- };
25832
- const crackBridge = (o, b, fp, voids, bridge, src) => {
25833
- if (b.p.st.cracked) return;
26144
+ const steel = tensionSteel(spec, g.dims, section, flexure);
26145
+ const m = sectionMoments(p.mat, section, steel, flexure);
26146
+ return { g, section, steel, m, resists: p.st.cracked ? m.steel : m.ultimate };
26147
+ };
26148
+ const pillarsUnder = (o, b, fp, standing) => {
26149
+ const box5 = aabbOf(b.p.spec.shape, b.p.pos, b.p.q);
26150
+ const across2 = fp.long === 0 ? 2 : 0;
26151
+ const out = [];
26152
+ for (const i of standing) {
26153
+ const q = o.parts[i];
26154
+ if (q.spec.structure?.role !== "column") continue;
26155
+ const c = aabbOf(q.spec.shape, q.pos, q.q);
26156
+ const overlaps = c.max[across2] > box5.min[across2] && c.min[across2] < box5.max[across2] && c.max[fp.long] > box5.min[fp.long] && c.min[fp.long] < box5.max[fp.long];
26157
+ if (overlaps && Math.abs(c.min[1] - box5.max[1]) < PILLAR_SEAT) out.push((c.min[fp.long] + c.max[fp.long]) / 2 - box5.min[fp.long]);
26158
+ }
26159
+ return out;
26160
+ };
26161
+ const continuationOf = (o, b, fp, standing) => {
26162
+ const box5 = aabbOf(b.p.spec.shape, b.p.pos, b.p.q);
26163
+ const across2 = fp.long === 0 ? 2 : 0;
26164
+ const ends = [false, false];
26165
+ for (const i of standing) {
26166
+ const q = o.parts[i];
26167
+ if (i === b.i || q.spec.structure?.role !== "foundation" || isTerrain(q)) continue;
26168
+ const c = aabbOf(q.spec.shape, q.pos, q.q);
26169
+ const inLine = Math.abs((c.min[across2] + c.max[across2]) / 2 - (box5.min[across2] + box5.max[across2]) / 2) < PILLAR_SEAT && c.max[1] > box5.min[1] && c.min[1] < box5.max[1];
26170
+ if (!inLine) continue;
26171
+ if (Math.abs(c.max[fp.long] - box5.min[fp.long]) < PILLAR_SEAT) ends[0] = true;
26172
+ if (Math.abs(c.min[fp.long] - box5.max[fp.long]) < PILLAR_SEAT) ends[1] = true;
26173
+ }
26174
+ return ends;
26175
+ };
26176
+ const bearBeam = (o, b, fp, standing, sec) => {
26177
+ const length2 = fp.slices.length * fp.step;
26178
+ const load = lineLoad(sec.g, b.p.st.load ?? b.p.st.mass);
26179
+ const verdict = judgeBeam(fp.slices.map((slice) => slice.void), fp.step, {
26180
+ length: length2,
26181
+ depth: sec.section.h,
26182
+ load,
26183
+ resists: sec.resists,
26184
+ cracking: sec.m.cracking,
26185
+ spanDepth: groundCfg.bridgeSpanDepth,
26186
+ soilSafety: soilCfg.safety,
26187
+ pillars: pillarsUnder(o, b, fp, standing),
26188
+ loadFactor: structureSafety,
26189
+ continuous: continuationOf(o, b, fp, standing)
26190
+ });
26191
+ if (verdict.runs.length === 0) return { status: fp.share <= 1 - 1 / soilCfg.safety ? "settled" : "unsupported", failed: [], cracks: [] };
26192
+ if (verdict.tips) return { status: "unsupported", failed: [], cracks: [] };
26193
+ const cracks = [];
26194
+ const failed = [];
26195
+ const EI = (b.p.mat.strength.elasticGPa ?? 0) * 1e9 * sec.section.b * sec.section.h ** 3 / 12;
26196
+ for (const run2 of verdict.runs) {
26197
+ const k0 = Math.round(run2.start / fp.step);
26198
+ const k1 = Math.round(run2.end / fp.step);
26199
+ if (!run2.holds) {
26200
+ const free = run2.kind !== "cantilever" ? void 0 : run2.start <= 1e-9 ? "start" : "end";
26201
+ failed.push({ start: run2.start, end: run2.end, ...free ? { free } : {} });
26202
+ if (free !== "start") cracks.push({ at: run2.start, top: true });
26203
+ if (free !== "end") cracks.push({ at: run2.end, top: true });
26204
+ for (let k = k0; k < k1; k++) fp.slices[k].drop = Math.min(fp.slices[k].cut, run2.span / 2);
26205
+ continue;
26206
+ }
26207
+ if (run2.cracks) cracks.push(run2.kind === "cantilever" ? { at: run2.start <= 1e-9 ? run2.end : run2.start, top: true } : { at: (run2.start + run2.end) / 2, top: false });
26208
+ const stiffness = EI * (run2.cracks || b.p.st.cracked ? CRACKED_STIFFNESS : 1);
26209
+ const sag = stiffness > 0 ? load * run2.span ** 4 / (run2.kind === "cantilever" ? 8 * stiffness : 384 / 5 * stiffness) : groundCfg.maxSettlement;
26210
+ for (let k = k0; k < k1; k++) fp.slices[k].drop = Math.min(fp.slices[k].drop, sag);
26211
+ }
26212
+ return { status: failed.length ? "opened" : "bridged", failed, cracks };
26213
+ };
26214
+ const standingOver = (o, b, fp) => {
26215
+ const box5 = aabbOf(b.p.spec.shape, b.p.pos, b.p.q);
26216
+ const vb = fp.voidBox;
26217
+ if (!vb) return [];
26218
+ const across2 = fp.long === 0 ? 2 : 0;
26219
+ const out = [];
26220
+ for (const j of o.byPart.get(b.p.spec.id) ?? []) {
26221
+ const k = j.ia === b.i ? j.ib : j.ia;
26222
+ if (j.st.open || restsOn(o, j, k) !== b.i) continue;
26223
+ const q = o.parts[k];
26224
+ const c = aabbOf(q.spec.shape, q.pos, q.q);
26225
+ const along = (c.min[fp.long] + c.max[fp.long]) / 2 - box5.min[fp.long];
26226
+ const side = (c.min[across2] + c.max[across2]) / 2 - box5.min[across2];
26227
+ if (along >= vb.long[0] && along <= vb.long[1] && side >= vb.across[0] && side <= vb.across[1]) out.push({ q, j });
26228
+ }
26229
+ return out;
26230
+ };
26231
+ const bearPlate = (o, b, fp, sec) => {
26232
+ const vb = fp.voidBox;
26233
+ if (!vb) return { status: "settled", failed: [], cracks: [] };
26234
+ const across2 = Math.max(vb.long[1] - vb.long[0], vb.across[1] - vb.across[0]);
26235
+ const over = standingOver(o, b, fp);
26236
+ const verdict = judgePlate({
26237
+ across: across2,
26238
+ load: lineLoad(sec.g, b.p.st.mass),
26239
+ resists: sec.resists,
26240
+ cracking: sec.m.cracking,
26241
+ effectiveDepth: sec.steel.d,
26242
+ punching: PUNCHING_SHARE * (b.p.mat.strength.tensileMPa ?? 0) * 1e6,
26243
+ loadFactor: structureSafety,
26244
+ points: over.map(({ q }) => {
26245
+ const c = aabbOf(q.spec.shape, q.pos, q.q);
26246
+ return { weight: (q.st.load ?? q.st.mass) * GRAVITY, side: Math.min(c.max[0] - c.min[0], c.max[2] - c.min[2]) };
26247
+ })
26248
+ });
26249
+ if (fp.share > 1 - 1 / soilCfg.safety) return { status: "unsupported", failed: [], cracks: [] };
26250
+ const cracks = verdict.cracks || !verdict.holds ? [{ at: vb.long[0], top: true }, { at: vb.long[1], top: true }] : [];
26251
+ if (verdict.holds) return { status: "bridged", failed: [], cracks };
26252
+ const box5 = aabbOf(b.p.spec.shape, b.p.pos, b.p.q);
26253
+ const crossing = fp.long === 0 ? 2 : 0;
26254
+ const center = [(box5.min[0] + box5.max[0]) / 2, (box5.min[1] + box5.max[1]) / 2, (box5.min[2] + box5.max[2]) / 2];
26255
+ center[fp.long] = box5.min[fp.long] + (vb.long[0] + vb.long[1]) / 2;
26256
+ center[crossing] = box5.min[crossing] + (vb.across[0] + vb.across[1]) / 2;
26257
+ const radius = Math.max(vb.long[1] - vb.long[0], vb.across[1] - vb.across[0]) / 2;
26258
+ if (2 * radius >= Math.min(box5.max[0] - box5.min[0], box5.max[2] - box5.min[2])) return { status: "unsupported", failed: [], cracks: [] };
26259
+ return { status: "opened", failed: [{ start: vb.long[0], end: vb.long[1] }], cracks, hole: { center, radius } };
26260
+ };
26261
+ const bearLoss = (o, b, fp, standing) => {
26262
+ const sec = sectionOfBearer(b.p);
26263
+ if (sec?.g.member) return bearBeam(o, b, fp, standing, sec);
26264
+ if (sec && fp.voidBox) return bearPlate(o, b, fp, sec);
26265
+ return { status: fp.share <= 1 - 1 / soilCfg.safety ? "settled" : "unsupported", failed: [], cracks: [] };
26266
+ };
26267
+ const crackBearer = (o, b, fp, bearing2, src) => {
26268
+ if (bearing2.cracks.length === 0) return;
25834
26269
  b.p.st.cracked = true;
25835
26270
  const box5 = aabbOf(b.p.spec.shape, b.p.pos, b.p.q);
25836
- const local2 = [(box5.min[0] + box5.max[0]) / 2, bridge.cantilever ? box5.max[1] : box5.min[1], (box5.min[2] + box5.max[2]) / 2];
25837
- const edge = voids.start === 0 ? voids.end : voids.start;
25838
- local2[fp.long] = box5.min[fp.long] + (bridge.cantilever ? edge : (voids.start + voids.end) / 2) * fp.step;
25839
- addCrack(o, b.p, toWorld(o.st.position, o.st.rotation, local2), rotateVec(o.st.rotation, [0, bridge.cantilever ? 1 : -1, 0]), bridge.depth, src);
26271
+ for (const crack of bearing2.cracks) {
26272
+ const local2 = [(box5.min[0] + box5.max[0]) / 2, crack.top ? box5.max[1] : box5.min[1], (box5.min[2] + box5.max[2]) / 2];
26273
+ local2[fp.long] = box5.min[fp.long] + crack.at;
26274
+ addCrack(o, b.p, toWorld(o.st.position, o.st.rotation, local2), rotateVec(o.st.rotation, [0, crack.top ? 1 : -1, 0]), box5.max[1] - box5.min[1], src);
26275
+ }
25840
26276
  };
25841
- const distort = (o, q, beta, at4, src) => {
26277
+ const openOver = (o, b, fp, failed, opened, src) => {
26278
+ const box5 = aabbOf(b.p.spec.shape, b.p.pos, b.p.q);
26279
+ let lost = false;
26280
+ for (const j of o.byPart.get(b.p.spec.id) ?? []) {
26281
+ const k = j.ia === b.i ? j.ib : j.ia;
26282
+ if (j.st.open || restsOn(o, j, k) !== b.i) continue;
26283
+ const q = o.parts[k];
26284
+ if (isLost(q)) continue;
26285
+ const c = aabbOf(q.spec.shape, q.pos, q.q);
26286
+ const from = c.min[fp.long] - box5.min[fp.long];
26287
+ const to = c.max[fp.long] - box5.min[fp.long];
26288
+ const run2 = failed.find((r) => to > r.start && from < r.end);
26289
+ if (!run2) continue;
26290
+ if (from >= run2.start - fp.step && to <= run2.end + fp.step) {
26291
+ j.st.open = true;
26292
+ j.st.hp = 0;
26293
+ j.st.openedBy = "break";
26294
+ opened.push(j);
26295
+ lost = true;
26296
+ continue;
26297
+ }
26298
+ if (isSlender(q.spec, q.mat) && archOver(o, q, fp.long, [box5.min[fp.long] + run2.start, box5.min[fp.long] + run2.end], run2.free, opened, src)) lost = true;
26299
+ }
26300
+ return lost;
26301
+ };
26302
+ const archOver = (o, q, axis2, span, free, opened, src) => {
26303
+ var _a;
26304
+ const grid = gridOf(q);
26305
+ const worn = (_a = q.rt).chips ?? (_a.chips = {});
26306
+ const bottom = aabbOf(q.spec.shape, q.pos, q.q).min[1];
26307
+ const half = (span[1] - span[0]) / 2;
26308
+ const middle = (span[0] + span[1]) / 2;
26309
+ const out = [];
26310
+ grid.forEach((cell, i) => {
26311
+ if (worn[i] === -1) return;
26312
+ const at4 = toWorld(q.pos, q.q, cell.center);
26313
+ const height2 = at4[1] - bottom;
26314
+ const reach = height2 / Math.tan(ARCH_ANGLE);
26315
+ const under = free === "start" ? at4[axis2] <= span[1] - reach : free === "end" ? at4[axis2] >= span[0] + reach : Math.abs(at4[axis2] - middle) <= half - reach;
26316
+ if (under) out.push(i);
26317
+ });
26318
+ if (out.length === 0) return false;
26319
+ const centre = [0, bottom, 0];
26320
+ centre[axis2] = middle;
26321
+ const other = axis2 === 0 ? 2 : 0;
26322
+ centre[other] = q.pos[other];
26323
+ knockOutUnits(o, q, toWorld(o.st.position, o.st.rotation, centre), 0, out, src);
26324
+ const height = aabbOf(q.spec.shape, q.pos, q.q).max[1] - bottom;
26325
+ const corbel = height / Math.tan(ARCH_ANGLE);
26326
+ const opening = free === "start" ? [span[0], span[1] - corbel] : free === "end" ? [span[0] + corbel, span[1]] : [span[0] + corbel, span[1] - corbel];
26327
+ return opening[1] > opening[0] && spanOpening(o, q, axis2, opening, !!free, opened, src);
26328
+ };
26329
+ const spanOpening = (o, q, axis2, opening, overhang, opened, src) => {
26330
+ const qi = o.idx.get(q.spec.id);
26331
+ const length2 = opening[1] - opening[0];
26332
+ let lost = false;
26333
+ for (const j of [...o.byPart.get(q.spec.id) ?? []]) {
26334
+ const ri = j.ia === qi ? j.ib : j.ia;
26335
+ const r = o.parts[ri];
26336
+ if (j.st.open || isLost(r) || restsOn(o, j, ri) !== qi || !r.structural) continue;
26337
+ const sec = sectionOfBearer(r);
26338
+ if (sec && !sec.g.member && !restsOnlyOn(o, ri, qi)) continue;
26339
+ const load = sec ? lineLoad(sec.g, r.st.load ?? r.st.mass) : 0;
26340
+ const moment = load * length2 * length2 / (overhang ? 2 : 8) * structureSafety;
26341
+ const reach = (overhang ? 0.5 : 1) * groundCfg.bridgeSpanDepth * (sec?.section.h ?? 0);
26342
+ if (sec && length2 <= reach && moment <= sec.resists) {
26343
+ if (moment > sec.m.cracking && !r.st.cracked) {
26344
+ r.st.cracked = true;
26345
+ addCrack(o, r, partXf(o, r).c, rotateVec(o.st.rotation, [0, -1, 0]), sec.section.h, src);
26346
+ }
26347
+ continue;
26348
+ }
26349
+ if (sec?.g.member) {
26350
+ if (breakOver(o, r, axis2, opening, opened, src)) lost = true;
26351
+ continue;
26352
+ }
26353
+ hingeDrop(o, r, src);
26354
+ lost = true;
26355
+ }
26356
+ return lost;
26357
+ };
26358
+ const breakOver = (o, r, axis2, stretch, opened, src) => {
26359
+ var _a;
26360
+ const ri = o.idx.get(r.spec.id);
26361
+ ((_a = r.rt).broken ?? (_a.broken = [])).push([axis2, stretch[0], stretch[1]]);
26362
+ r.st.cracked = true;
26363
+ const box5 = aabbOf(r.spec.shape, r.pos, r.q);
26364
+ for (const edge of stretch) {
26365
+ const at4 = [(box5.min[0] + box5.max[0]) / 2, box5.max[1], (box5.min[2] + box5.max[2]) / 2];
26366
+ at4[axis2] = edge;
26367
+ addCrack(o, r, toWorld(o.st.position, o.st.rotation, at4), rotateVec(o.st.rotation, [0, 1, 0]), box5.max[1] - box5.min[1], src);
26368
+ }
26369
+ const from = [(box5.min[0] + box5.max[0]) / 2, box5.min[1], (box5.min[2] + box5.max[2]) / 2];
26370
+ const to = [from[0], from[1], from[2]];
26371
+ from[axis2] = box5.min[axis2];
26372
+ to[axis2] = box5.max[axis2];
26373
+ const count = SETTLEMENT_POINTS;
26374
+ const drop = Array.from({ length: count }, (_, k) => {
26375
+ const x = box5.min[axis2] + (box5.max[axis2] - box5.min[axis2]) * k / (count - 1);
26376
+ return x <= stretch[0] || x >= stretch[1] ? 0 : Math.min(x - stretch[0], stretch[1] - x, Math.max(0, box5.min[1]));
26377
+ });
26378
+ r.st.settlement = mergeSettlement(r.st.settlement, { from, to, drop });
26379
+ r.st.subsidence = Math.max(r.st.subsidence ?? 0, drop.reduce((sum2, v) => sum2 + v, 0) / count);
26380
+ const middle = [from[0], from[1], from[2]];
26381
+ middle[axis2] = (stretch[0] + stretch[1]) / 2;
26382
+ emit2({ ...base(o, src), type: "subside", part: r.spec.id, drop: r.st.subsidence, share: (stretch[1] - stretch[0]) / Math.max(1e-6, box5.max[axis2] - box5.min[axis2]), point: toWorld(o.st.position, o.st.rotation, middle), status: "opened" });
26383
+ let lost = false;
26384
+ for (const j of [...o.byPart.get(r.spec.id) ?? []]) {
26385
+ const ki = j.ia === ri ? j.ib : j.ia;
26386
+ const k = o.parts[ki];
26387
+ if (j.st.open || isLost(k) || restsOn(o, j, ki) !== ri) continue;
26388
+ const c = aabbOf(k.spec.shape, k.pos, k.q);
26389
+ const within = c.min[axis2] >= stretch[0] - SUPPORT_TOLERANCE && c.max[axis2] <= stretch[1] + SUPPORT_TOLERANCE;
26390
+ const sec = within ? null : sectionOfBearer(k);
26391
+ const plate3 = sec && !sec.g.member;
26392
+ const length2 = stretch[1] - stretch[0];
26393
+ const spans = plate3 && lineLoad(sec.g, k.st.load ?? k.st.mass) * length2 * length2 / 8 * structureSafety <= sec.resists;
26394
+ if (!within && (!plate3 || spans)) continue;
26395
+ j.st.open = true;
26396
+ j.st.hp = 0;
26397
+ j.st.openedBy = "break";
26398
+ opened.push(j);
26399
+ lost = true;
26400
+ }
26401
+ return lost;
26402
+ };
26403
+ const breakOut = (o, p, hole, src) => {
26404
+ if (p.st.opening) return;
26405
+ const lc = toLocal(p.pos, p.q, hole.center);
26406
+ lc[p.thin] = 0;
26407
+ const worldCenter = toWorld(o.st.position, o.st.rotation, toWorld(p.pos, p.q, lc));
26408
+ const [u, v] = planeAxes(p.thin);
26409
+ const worn = p.rt.chips;
26410
+ const cells = cellsWithin(gridOf(p).filter((_, i) => worn?.[i] !== -1), p.thin, lc, hole.radius);
26411
+ const removed = Math.min(p.st.mass, p.st.mass * Math.PI * hole.radius * hole.radius / (p.dims[u] * p.dims[v]));
26412
+ const fragments = cellFragments(o, p, cells, worldCenter, [0, -1, 0], 0.5, removed, "g");
26413
+ p.st.mass = Math.max(0, p.st.mass - removed);
26414
+ p.rt.removed = (p.rt.removed ?? 0) + removed;
26415
+ p.st.opening = { center: objLocal(o, worldCenter), radius: hole.radius };
26416
+ markDamaged(p);
26417
+ if (p.staged) {
26418
+ setStage(o, p, 1, {}, src);
26419
+ setStage(o, p, 2, { opening: { center: worldCenter, radius: hole.radius }, fragments }, src);
26420
+ } else emit2({ ...base(o, src), type: "stage", part: p.spec.id, stage: 2, opening: { center: worldCenter, radius: hole.radius }, fragments });
26421
+ debris2(o, p, p.mat.breakDebris, worldCenter, [0, 1, 0], 14, 2, src);
26422
+ if (p.spec.reinforcement) exposeRebar(o, p, src);
26423
+ };
26424
+ const distort = (o, q, beta, at4, toward2, src) => {
25842
26425
  const prior = q.rt.distortion ?? 0;
25843
- if (beta < groundCfg.crackDistortion || beta <= prior * DISTORTION_GROWTH) return;
26426
+ const bearing2 = q.spec.structure?.role === "wall";
26427
+ const crackAt = bearing2 ? groundCfg.bearingCrackDistortion : groundCfg.crackDistortion;
26428
+ const damageAt = bearing2 ? groundCfg.bearingDamageDistortion : groundCfg.damageDistortion;
26429
+ if (beta < crackAt || beta <= prior * DISTORTION_GROWTH) return;
25844
26430
  q.rt.distortion = beta;
25845
26431
  const box5 = aabbOf(q.spec.shape, q.pos, q.q);
25846
26432
  const height = box5.max[1] - box5.min[1];
25847
- const cracks = (d) => d < groundCfg.crackDistortion ? 0 : Math.min(MAX_SETTLEMENT_CRACKS, 1 + Math.floor(Math.log2(d / groundCfg.crackDistortion)));
26433
+ const cracks = (d) => d < crackAt ? 0 : Math.min(MAX_SETTLEMENT_CRACKS, 1 + Math.floor(Math.log2(d / crackAt)));
25848
26434
  const count = Math.max(1, cracks(beta) - cracks(prior));
25849
26435
  const axis2 = [0, 0, 0];
25850
26436
  axis2[q.thin] = 1;
25851
26437
  const normal = rotateVec(quat.mul(o.st.rotation, q.q), axis2);
25852
- const length2 = Math.min(height * 0.6, SETTLEMENT_CRACK_LENGTH * Math.sqrt(beta / groundCfg.crackDistortion));
26438
+ const length2 = Math.min(height * 0.6, SETTLEMENT_CRACK_LENGTH * Math.sqrt(beta / crackAt));
26439
+ const units = q.spec.units?.size;
26440
+ const step = units ? [Math.max(units[0], units[2]), units[1]] : [BRICK_STEP[0], BRICK_STEP[1]];
26441
+ const reach = Math.hypot(toward2[0], toward2[2]) || 1;
26442
+ const along = vec.normalize([toward2[0] / reach, 1, toward2[2] / reach]);
26443
+ const width = clamp2(beta * SETTLEMENT_CRACK_OPENING, MIN_CRACK_WIDTH, MAX_CRACK_WIDTH);
26444
+ const through = q.dims[q.thin];
25853
26445
  for (let c = 0; c < count; c++) {
25854
- const local2 = [clamp2(at4[0], box5.min[0], box5.max[0]), box5.min[1] + height * (0.15 + 0.2 * c), clamp2(at4[2], box5.min[2], box5.max[2])];
25855
- addCrack(o, q, toWorld(o.st.position, o.st.rotation, local2), normal, length2, src);
26446
+ const back = c * SETTLEMENT_CRACK_SPACING;
26447
+ const local2 = [clamp2(at4[0] - toward2[0] / reach * back, box5.min[0], box5.max[0]), box5.min[1] + height * (0.2 + 0.12 * c), clamp2(at4[2] - toward2[2] / reach * back, box5.min[2], box5.max[2])];
26448
+ const face = toLocal(q.pos, q.q, local2);
26449
+ face[q.thin] = through / 2;
26450
+ addCrack(o, q, toWorld(o.st.position, o.st.rotation, toWorld(q.pos, q.q, face)), normal, length2, src, { along, step, width, through });
25856
26451
  }
25857
- if (beta >= groundCfg.damageDistortion && prior < groundCfg.damageDistortion) {
26452
+ if (beta >= damageAt && prior < damageAt) {
25858
26453
  q.st.hp = Math.max(1, q.st.hp - q.st.maxHp * groundCfg.distortionDamage);
25859
26454
  markDamaged(q);
25860
26455
  }
@@ -25868,18 +26463,53 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25868
26463
  const q = o.parts[qi];
25869
26464
  if (isLost(q) || isTerrain(q) || o.collapsed.has(q.spec.id) || !isSlender(q.spec, q.mat)) continue;
25870
26465
  if (restsOn(o, j, qi) !== b.i) {
25871
- distort(o, q, (b.p.st.subsidence ?? 0) / DISTORTION_BASE, j.pos, src);
26466
+ const side = [j.pos[0] - q.pos[0], 0, j.pos[2] - q.pos[2]];
26467
+ const own = q.st.settlement ? settlementAt(q.st.settlement, j.pos) : 0;
26468
+ const reach = Math.hypot(side[0], side[2]) || 1;
26469
+ const from = [j.pos[0] - side[0] / reach * BESIDE_CRACK_OFFSET, j.pos[1], j.pos[2] - side[2] / reach * BESIDE_CRACK_OFFSET];
26470
+ distort(o, q, Math.abs((b.p.st.subsidence ?? 0) - own) / DISTORTION_BASE, from, side, src);
25872
26471
  continue;
25873
26472
  }
25874
26473
  const over = aabbOf(q.spec.shape, q.pos, q.q);
25875
26474
  const k0 = clamp2(Math.floor((over.min[fp.long] - box5.min[fp.long]) / fp.step), 0, drops.length - 1);
25876
26475
  const k1 = clamp2(Math.ceil((over.max[fp.long] - box5.min[fp.long]) / fp.step), k0 + 1, drops.length);
25877
- const { value, at: at4 } = distortionOf(drops.slice(k0, k1), fp.step);
26476
+ const { value, at: at4, down } = distortionOf(relativeToChord(drops.slice(k0, k1)), fp.step);
25878
26477
  const point = [(over.min[0] + over.max[0]) / 2, over.min[1], (over.min[2] + over.max[2]) / 2];
25879
26478
  point[fp.long] = box5.min[fp.long] + (k0 + at4 + 0.5) * fp.step;
25880
- distort(o, q, value, point, src);
26479
+ const toward2 = [0, 0, 0];
26480
+ toward2[fp.long] = down;
26481
+ distort(o, q, value, point, toward2, src);
26482
+ }
26483
+ };
26484
+ const settle = (o, b, fp) => {
26485
+ const box5 = aabbOf(b.p.spec.shape, b.p.pos, b.p.q);
26486
+ const from = [(box5.min[0] + box5.max[0]) / 2, box5.min[1], (box5.min[2] + box5.max[2]) / 2];
26487
+ const to = [from[0], from[1], from[2]];
26488
+ from[fp.long] = box5.min[fp.long];
26489
+ to[fp.long] = box5.max[fp.long];
26490
+ const line = { from, to, drop: settlementProfile(fp.slices.map((slice) => slice.drop), fp.step) };
26491
+ const follows = { from, to, drop: line.drop.map((v) => Math.min(v, groundCfg.maxSettlement)) };
26492
+ const moved = /* @__PURE__ */ new Set([b.i]);
26493
+ let ring3 = [b.i];
26494
+ for (let depth = 0; depth <= SETTLEMENT_FOLLOW_DEPTH && ring3.length; depth++) {
26495
+ const next = [];
26496
+ for (const i of ring3) {
26497
+ const p = o.parts[i];
26498
+ p.st.settlement = mergeSettlement(p.st.settlement, i === b.i ? line : follows);
26499
+ if (i !== b.i) p.st.subsidence = Math.max(p.st.subsidence ?? 0, settlementAt(p.st.settlement, p.pos));
26500
+ for (const j of o.byPart.get(p.spec.id) ?? []) {
26501
+ const k = j.ia === i ? j.ib : j.ia;
26502
+ const q = o.parts[k];
26503
+ if (j.st.open || moved.has(k) || isLost(q) || isTerrain(q) || q.anchored) continue;
26504
+ if (q.structural && (i !== b.i || restsOn(o, j, k) !== i || !restsOnlyOn(o, k, i))) continue;
26505
+ moved.add(k);
26506
+ next.push(k);
26507
+ }
26508
+ }
26509
+ ring3 = next;
25881
26510
  }
25882
26511
  };
26512
+ const restsOnlyOn = (o, k, i) => (o.byPart.get(o.parts[k].spec.id) ?? []).every((j) => j.st.open || restsOn(o, j, k) < 0 || restsOn(o, j, k) === i);
25883
26513
  const loseGround = (o, b, opened) => {
25884
26514
  if (b.p.anchored) {
25885
26515
  b.p.anchored = false;
@@ -25893,38 +26523,48 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25893
26523
  opened.push(j);
25894
26524
  }
25895
26525
  };
25896
- const bearLoss = (o, b, fp, src) => {
25897
- const voids = longestRun(fp.slices.map((slice) => slice.void));
25898
- const bridge = voids ? bridgeOf(b, fp, voids) : null;
25899
- if (voids && bridge && bridge.span >= bridge.depth) {
25900
- if (!bridge.holds) return "unsupported";
25901
- if (bridge.cracks) crackBridge(o, b, fp, voids, bridge, src);
25902
- for (let k = voids.start; k < voids.end; k++) fp.slices[k].drop = Math.min(fp.slices[k].drop, bridge.sag);
25903
- fp.drop = fp.slices.reduce((sum2, slice) => sum2 + slice.drop, 0) / fp.slices.length;
25904
- return "bridged";
25905
- }
25906
- return fp.share <= 1 - 1 / soilCfg.safety ? "settled" : "unsupported";
25907
- };
25908
26526
  const undermine = (o, loss) => {
25909
26527
  if (!o.hasStructure || !o.anyAnchor || o.st.soil?.status === "toppled") return;
25910
26528
  const src = loss.source ?? "ground";
25911
26529
  const opened = [];
25912
26530
  const settled = [];
25913
26531
  let lost = false;
25914
- for (const b of bearersOf(o)) {
25915
- if (!nearLoss(o, b.p, loss)) continue;
25916
- const fp = footprintOf(o, b, loss);
25917
- if (fp.share <= 0 && fp.drop < SUBSIDE_MIN) continue;
25918
- const status = bearLoss(o, b, fp, src);
26532
+ const touched = bearersOf(o).filter((b) => nearLoss(o, b.p, loss)).map((b) => ({ b, fp: footprintOf(o, b, loss) })).filter(({ fp }) => fp.share > 0 || fp.drop >= SUBSIDE_MIN);
26533
+ const bearers = bearersOf(o);
26534
+ const pillarFirst = (b) => b.p.spec.structure?.role === "column" ? 0 : 1;
26535
+ const order = [...touched].sort((x, y) => pillarFirst(x.b) - pillarFirst(y.b));
26536
+ const standing = new Set(bearers.map((b) => b.i));
26537
+ for (const { b, fp } of order) {
26538
+ const bearing2 = bearLoss(o, b, fp, standing);
26539
+ if (bearing2.status === "unsupported") standing.delete(b.i);
26540
+ if (bearing2.status !== "unsupported" && !bendGeometry(b.p.spec).member) {
26541
+ const kept = fp.slices.filter((slice) => !slice.void);
26542
+ const flat2 = kept.length ? kept.reduce((sum2, slice) => sum2 + slice.drop, 0) / kept.length : 0;
26543
+ fp.slices.forEach((slice) => slice.drop = flat2);
26544
+ fp.drop = flat2;
26545
+ }
26546
+ if (bearing2.status !== "unsupported" && bendGeometry(b.p.spec).member) {
26547
+ const smooth2 = smoothProfile(fp.slices.map((slice) => slice.drop), fp.step, BEAM_SPREAD);
26548
+ fp.slices.forEach((slice, k) => slice.drop = bearing2.failed.some((r) => (k + 0.5) * fp.step > r.start && (k + 0.5) * fp.step < r.end) ? slice.drop : smooth2[k]);
26549
+ fp.drop = fp.slices.reduce((sum2, slice) => sum2 + slice.drop, 0) / Math.max(1, fp.slices.length);
26550
+ }
25919
26551
  const before = b.p.st.subsidence ?? 0;
25920
26552
  const drop = Math.max(before, fp.drop);
25921
- if (status === "unsupported") {
26553
+ const peak = () => Math.max(0, ...b.p.st.settlement?.drop ?? []);
26554
+ const peakBefore = peak();
26555
+ if (bearing2.status === "unsupported") {
25922
26556
  loseGround(o, b, opened);
25923
26557
  lost = true;
25924
- } else settled.push({ b, fp });
25925
- if (status === "settled" && drop - before < SUBSIDE_MIN) continue;
26558
+ } else {
26559
+ crackBearer(o, b, fp, bearing2, src);
26560
+ if (bearing2.failed.length && openOver(o, b, fp, bearing2.failed, opened, src)) lost = true;
26561
+ if (bearing2.hole) breakOut(o, b.p, bearing2.hole, src);
26562
+ settled.push({ b, fp });
26563
+ settle(o, b, fp);
26564
+ }
26565
+ if (bearing2.status === "settled" && drop - before < SUBSIDE_MIN && peak() - peakBefore < SUBSIDE_MIN) continue;
25926
26566
  b.p.st.subsidence = drop;
25927
- emit2({ ...base(o, src), type: "subside", part: b.p.spec.id, drop, share: fp.share, point: fp.deepest, status });
26567
+ emit2({ ...base(o, src), type: "subside", part: b.p.spec.id, drop, share: fp.share, point: fp.deepest, status: bearing2.status });
25928
26568
  }
25929
26569
  for (const { b, fp } of settled) crackOver(o, b, fp, src);
25930
26570
  o.active = true;
@@ -25969,6 +26609,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25969
26609
  return r ? { t0: r.t0, t1: r.t1, n: rotateVec(q, r.n0) } : null;
25970
26610
  };
25971
26611
  const rayPart = (o, p, origin, d) => rayPartRaw(o.st.position, o.st.rotation, p.spec, p.q, origin, d, p.pos);
26612
+ const PART_BOUND_SLACK = 1e-6;
25972
26613
  const raySphereMiss = (origin, d, c, r, maxDist) => {
25973
26614
  const oc = vec.sub(origin, c);
25974
26615
  const b = vec.dot(oc, d);
@@ -25978,13 +26619,27 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25978
26619
  if (disc < 0) return true;
25979
26620
  return -b - Math.sqrt(disc) > maxDist;
25980
26621
  };
26622
+ const partSphereMiss = (o, d, p, maxDist) => {
26623
+ const x = o[0] - p.pos[0], y = o[1] - p.pos[1], z = o[2] - p.pos[2];
26624
+ const r = p.bound + PART_BOUND_SLACK;
26625
+ const b = x * d[0] + y * d[1] + z * d[2];
26626
+ const cc = x * x + y * y + z * z - r * r;
26627
+ if (cc > 0 && b > 0) return true;
26628
+ const disc = b * b - cc;
26629
+ if (disc < 0) return true;
26630
+ return -b - Math.sqrt(disc) > maxDist;
26631
+ };
25981
26632
  const raycastInternal = (origin, dir, maxDist, ignore, worldOnly = false, precise = false) => {
25982
26633
  const d = vec.normalize(dir);
25983
26634
  let best = null;
25984
26635
  for (const o of objects.values()) {
25985
26636
  if (raySphereMiss(origin, d, toWorld(o.st.position, o.st.rotation, o.bc), o.br, best ? Math.min(maxDist, best.distance) : maxDist)) continue;
26637
+ const qi = quat.conjugate(o.st.rotation);
26638
+ const lo = rotateVec(qi, vec.sub(origin, o.st.position));
26639
+ const ld = rotateVec(qi, d);
25986
26640
  for (const p of o.parts) {
25987
26641
  if (isLost(p) || ignore?.has(`${o.id}\0${p.spec.id}`)) continue;
26642
+ if (partSphereMiss(lo, ld, p, maxDist)) continue;
25988
26643
  const r = rayPart(o, p, origin, d);
25989
26644
  if (!r || r.t0 < 0 || r.t0 > maxDist) continue;
25990
26645
  if (p.st.opening && insideOpening(o, p, vec.madd(origin, d, r.t0))) continue;
@@ -26112,8 +26767,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26112
26767
  setStage(o, p, 1, {}, src);
26113
26768
  return hole;
26114
26769
  };
26115
- const addCrack = (o, p, wp, wn, length2, src) => {
26116
- const crack = { point: objLocal(o, wp), normal: objLocalDir(o, wn), length: Math.min(length2, Math.max(p.bound, 0.05)), rays: 5 + Math.floor(rnd2() * 5) };
26770
+ const addCrack = (o, p, wp, wn, length2, src, stair) => {
26771
+ const crack = { point: objLocal(o, wp), normal: objLocalDir(o, wn), length: Math.min(length2, Math.max(p.bound, 0.05)), rays: 5 + Math.floor(rnd2() * 5), ...stair ? { stair } : {} };
26117
26772
  p.st.cracks.push(crack);
26118
26773
  if (p.st.cracks.length > 16) p.st.cracks.shift();
26119
26774
  markDamaged(p);
@@ -26240,6 +26895,12 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26240
26895
  const breachAreaOf = (p, damage, blast) => damage / (p.mat.hpPerKg * p.mat.density) / Math.max(p.thickness, 5e-3) * (blast ? breachBlastFactor : 1);
26241
26896
  const localHolesOf = (p) => p.st.holes.map((h) => ({ point: toLocal(p.pos, p.q, h.point), normal: rotateVec(quat.conjugate(p.q), h.normal), diameter: h.diameter }));
26242
26897
  const unitsOf2 = (p) => p.spec.units ?? { size: [p.mat.fragmentSize?.[1] ?? 0.2, p.mat.fragmentSize?.[1] ?? 0.2, p.thickness], bond: "stack" };
26898
+ const unitSpan = (p) => {
26899
+ const [u, v] = planeAxes(p.thin);
26900
+ const first = gridOf(p)[0];
26901
+ const size = unitsOf2(p).size;
26902
+ return first && first.size[u] > size[0] + 1e-6 ? [first.size[u], first.size[v]] : [Math.min(size[0], p.dims[u]), Math.min(size[1], p.dims[v])];
26903
+ };
26243
26904
  const FRAGMENT_SHAPE = { shatter: "shard", splinter: "splinter", tear: "scrap" };
26244
26905
  const cellFragments = (o, p, cells, hitW, dir, speed, mass, tag, inner = false) => {
26245
26906
  const { c, q } = partXf(o, p);
@@ -26270,6 +26931,44 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26270
26931
  };
26271
26932
  });
26272
26933
  };
26934
+ const plasterFlakes = (o, p, cells, hitW, speed, tag) => {
26935
+ const layer3 = p.layers.find((l) => l.mat.fracture === "crumble");
26936
+ if (!layer3 || cells.length === 0) return [];
26937
+ const { c, q } = partXf(o, p);
26938
+ const [u, v] = planeAxes(p.thin);
26939
+ const faces = layer3.def.faces === "both" ? [1, -1] : [layer3.def.faces === "+" ? 1 : -1];
26940
+ const area3 = cells.reduce((sum2, cell) => sum2 + cell.size[u] * cell.size[v], 0) * faces.length;
26941
+ const count = Math.min(MAX_PLASTER_FLAKES, Math.ceil(area3 / PLASTER_FLAKE_AREA));
26942
+ const out = [];
26943
+ for (let i = 0; i < count; i++) {
26944
+ const cell = cells[Math.floor(rnd2() * cells.length)];
26945
+ const face = faces[i % faces.length];
26946
+ const local2 = [cell.center[0], cell.center[1], cell.center[2]];
26947
+ local2[u] += (rnd2() - 0.5) * cell.size[u];
26948
+ local2[v] += (rnd2() - 0.5) * cell.size[v];
26949
+ local2[p.thin] = cell.center[p.thin] + face * (cell.size[p.thin] / 2 - layer3.def.thickness / 2);
26950
+ const size = [0, 0, 0];
26951
+ size[u] = 0.04 + 0.12 * rnd2();
26952
+ size[v] = 0.03 + 0.09 * rnd2();
26953
+ size[p.thin] = layer3.def.thickness;
26954
+ const cw = toWorld(c, q, local2);
26955
+ const out0 = vec.normalize(vec.sub(cw, hitW), [0, 1, 0]);
26956
+ const k = speed * (0.4 + 0.9 * rnd2());
26957
+ out.push({
26958
+ id: `${p.spec.id}#${tag}${i}`,
26959
+ part: p.spec.id,
26960
+ material: layer3.def.material,
26961
+ shape: "scrap",
26962
+ center: cw,
26963
+ size,
26964
+ rotation: q,
26965
+ velocity: [out0[0] * k, out0[1] * k + 0.5 * rnd2(), out0[2] * k],
26966
+ angularVelocity: [(rnd2() - 0.5) * 12, (rnd2() - 0.5) * 12, (rnd2() - 0.5) * 12],
26967
+ mass: layer3.mat.density * size[0] * size[1] * size[2]
26968
+ });
26969
+ }
26970
+ return out;
26971
+ };
26273
26972
  const worldBars = (o, p, bars) => {
26274
26973
  const { c, q } = partXf(o, p);
26275
26974
  return bars.map(([a, b]) => [toWorld(c, q, a), toWorld(c, q, b)]);
@@ -26507,6 +27206,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26507
27206
  }
26508
27207
  const bow2 = clamp2(((p.st.stress ?? 0) - 1) / 0.5, 0, 1);
26509
27208
  if (bow2 > 0) bars = bars.flatMap((bar2, i) => bendBar(bar2, p.thin, bow2 * BAR_BOW, i));
27209
+ const stirrups = memberStirrups(p.dims);
27210
+ if (stirrups.length > 0 && bars.length > 0) {
27211
+ if (p.st.stripped) bars = [...bars, ...stirrups];
27212
+ else for (const box5 of [...p.st.chipped ?? [], ...p.rt.bared ?? []]) bars.push(...clipBarsToVolume(stirrups, box5.center, box5.size));
27213
+ }
26510
27214
  emit2({ ...base(o, src), type: "expose", part: p.spec.id, bars: worldBars(o, p, bars) });
26511
27215
  };
26512
27216
  const openBreach = (o, p, center, total, energy, dir, src) => {
@@ -26577,6 +27281,33 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26577
27281
  if (out.length === 0) return false;
26578
27282
  return knockOutUnits(o, p, wp, energy, out, src);
26579
27283
  };
27284
+ const wedgedUnder = (o, p, loose) => {
27285
+ if (loose.length === 0) return loose;
27286
+ const beam = (o.byPart.get(p.spec.id) ?? []).some((j) => j.bears === "a_on_b" && j.spec.b === p.spec.id && !j.st.open && !!o.byId.get(j.spec.a)?.spec.reinforcement);
27287
+ if (!beam) return loose;
27288
+ const [, v] = planeAxes(p.thin);
27289
+ const grid = gridOf(p);
27290
+ const top = p.dims[v] / 2, course = unitSpan(p)[1];
27291
+ return loose.filter((i) => grid[i].center[v] + grid[i].size[v] / 2 < top - PANEL_EDGE_BEAM * course + 1e-4);
27292
+ };
27293
+ const panelEdge = (p, faces, seed) => {
27294
+ const [u, v] = planeAxes(p.thin);
27295
+ const [unitU, unitV] = unitSpan(p);
27296
+ const bottom = -p.dims[v] / 2, top = p.dims[v] / 2;
27297
+ const depth = (key2, most) => {
27298
+ const r = createRng2(seed ^ Math.imul(key2 + 1, 2654435761)).next();
27299
+ return Math.floor(r * r * (most + 1));
27300
+ };
27301
+ return (cell) => {
27302
+ const course = Math.round((cell.center[v] - bottom) / unitV - 0.5);
27303
+ const column = Math.round((cell.center[u] - faces.fromFace) / unitU - 0.5);
27304
+ const keyed = course % 2 === 0 ? 0.5 : 0;
27305
+ const side = Math.min(cell.center[u] - faces.fromFace, faces.toFace - cell.center[u]) / unitU;
27306
+ if (side < depth(course * 2, PANEL_EDGE_PILLAR) + keyed + 0.5) return true;
27307
+ if ((cell.center[v] - bottom) / unitV < depth(1e5 + column, PANEL_EDGE_BASE) + 1) return true;
27308
+ return (top - cell.center[v]) / unitV < Math.floor(createRng2(seed ^ Math.imul(200001 + column, 2654435761)).next() * (PANEL_EDGE_BEAM + 1));
27309
+ };
27310
+ };
26580
27311
  const blastPanel = (o, p, point, energy, src) => {
26581
27312
  var _a;
26582
27313
  if (!p.staged || p.st.stripped || isLost(p) || !p.spec.units || p.spec.units.mortar === p.spec.material || p.spec.reinforcement) return false;
@@ -26588,12 +27319,18 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26588
27319
  if (m === p || !m.spec.reinforcement || isLost(m) || m.spec.shape.kind !== "box") continue;
26589
27320
  const mp = toLocal(p.pos, p.q, m.pos);
26590
27321
  if (Math.abs(mp[p.thin]) > p.dims[p.thin] + 0.15 || Math.abs(mp[u]) > half + 0.15 || m.dims[v] < p.dims[v] * 0.5) continue;
26591
- posts.push(mp[u]);
27322
+ posts.push({ x: mp[u], half: m.dims[u] / 2 });
26592
27323
  }
26593
- let from = -half, to = half;
26594
- for (const x of posts) {
26595
- if (x <= lp[u] && x > from) from = x;
26596
- if (x >= lp[u] && x < to) to = x;
27324
+ let from = -half, to = half, fromFace = -half, toFace = half;
27325
+ for (const { x, half: w } of posts) {
27326
+ if (x <= lp[u] && x > from) {
27327
+ from = x;
27328
+ fromFace = x + w;
27329
+ }
27330
+ if (x >= lp[u] && x < to) {
27331
+ to = x;
27332
+ toFace = x - w;
27333
+ }
26597
27334
  }
26598
27335
  if (to - from < 0.2) return false;
26599
27336
  const tnt = energy * DEFAULT_BLAST_IMPULSE.tntPerJoule;
@@ -26615,10 +27352,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26615
27352
  const grid = gridOf(p);
26616
27353
  const worn = (_a = p.rt).chips ?? (_a.chips = {});
26617
27354
  const out = [];
27355
+ const edge = panelEdge(p, { fromFace, toFace }, seedOf2(...Array.from(`${o.id}|${p.spec.id}`, (char) => char.charCodeAt(0) / 1e3), from));
26618
27356
  for (let i = 0; i < grid.length; i++) {
26619
27357
  const cell = grid[i];
26620
27358
  if (worn[i] === -1) continue;
26621
- if (cell.center[u] - cell.size[u] / 2 >= from - 1e-6 && cell.center[u] + cell.size[u] / 2 <= to + 1e-6) out.push(i);
27359
+ if (cell.center[u] - cell.size[u] / 2 >= from - 1e-6 && cell.center[u] + cell.size[u] / 2 <= to + 1e-6 && !edge(cell)) out.push(i);
26622
27360
  }
26623
27361
  if (out.length === 0) return false;
26624
27362
  for (const i of out) worn[i] = -1;
@@ -26631,7 +27369,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26631
27369
  const grid = gridOf(p);
26632
27370
  const worn = (_a = p.rt).chips ?? (_a.chips = {});
26633
27371
  for (const i of out) worn[i] = -1;
26634
- const loose = unsupportedCells(grid, p.thin, p.dims, (i) => worn[i] !== -1 && !(op && p.st.opening && Math.hypot(grid[i].center[u] - op[u], grid[i].center[v] - op[v]) <= p.st.opening.radius));
27372
+ const cast = p.spec.units?.mortar === p.spec.material;
27373
+ const loose = cast ? [] : wedgedUnder(o, p, unsupportedCells(grid, p.thin, p.dims, (i) => worn[i] !== -1 && !(op && p.st.opening && Math.hypot(grid[i].center[u] - op[u], grid[i].center[v] - op[v]) <= p.st.opening.radius)));
26635
27374
  for (const i of loose) worn[i] = -1;
26636
27375
  const blown = out.map((i) => grid[i]), fallen = loose.map((i) => grid[i]);
26637
27376
  const volume = (cells2) => cells2.reduce((sum2, cell) => sum2 + cell.size[0] * cell.size[1] * cell.size[2], 0);
@@ -26642,8 +27381,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26642
27381
  const chipped = (_b = p.st).chipped ?? (_b.chipped = []);
26643
27382
  const tag = `x${chipped.length}_`;
26644
27383
  const fragments = [
26645
- ...cellFragments(o, p, clumpCells(blown, p.thin, maxFragments), wp, null, speed, blownMass, tag, true),
26646
- ...fallen.length > 0 ? cellFragments(o, p, clumpCells(fallen, p.thin, Math.max(2, Math.round(maxFragments / 4))), wp, null, 0.3, fallenMass, `${tag}f`, true) : []
27384
+ ...cellFragments(o, p, clumpUnits(blown, p.thin, unitSpan(p), unitClumps), wp, null, speed, blownMass, tag, true),
27385
+ ...fallen.length > 0 ? cellFragments(o, p, clumpUnits(fallen, p.thin, unitSpan(p), fallenClumps), wp, null, 0.3, fallenMass, `${tag}f`, true) : [],
27386
+ ...plasterFlakes(o, p, blown, wp, speed, `${tag}p`)
26647
27387
  ];
26648
27388
  const cells = [...blown, ...fallen];
26649
27389
  const holes = localHolesOf(p);
@@ -26679,7 +27419,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26679
27419
  const worn = (_a = p.rt).chips ?? (_a.chips = {});
26680
27420
  const op = p.st.opening ? toLocal(p.pos, p.q, p.st.opening.center) : null;
26681
27421
  const opened = (cell) => !!op && !!p.st.opening && Math.hypot(cell.center[u] - op[u], cell.center[v] - op[v]) <= p.st.opening.radius;
26682
- const loose = unsupportedCells(grid, p.thin, p.dims, (i) => worn[i] !== -1 && !opened(grid[i]));
27422
+ const loose = wedgedUnder(o, p, unsupportedCells(grid, p.thin, p.dims, (i) => worn[i] !== -1 && !opened(grid[i])));
26683
27423
  if (loose.length === 0) return 0;
26684
27424
  for (const i of loose) worn[i] = -1;
26685
27425
  const fallen = loose.map((i) => grid[i]);
@@ -26694,7 +27434,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26694
27434
  }
26695
27435
  }
26696
27436
  const center = toWorld(c, q, [(lo[0] + hi[0]) / 2, (lo[1] + hi[1]) / 2, (lo[2] + hi[2]) / 2]);
26697
- const fragments = cellFragments(o, p, clumpCells(fallen, p.thin, Math.max(2, Math.round(maxFragments / 4))), vec.add(center, [0, 1, 0]), null, 0.3, mass, `u${chipped.length}_`, true);
27437
+ const fragments = cellFragments(o, p, clumpUnits(fallen, p.thin, unitSpan(p), fallenClumps), vec.add(center, [0, 1, 0]), null, 0.3, mass, `u${chipped.length}_`, true);
26698
27438
  const holes = localHolesOf(p);
26699
27439
  p.st.holes = p.st.holes.filter((_, k) => !fallen.some((cell) => marksInBox(cell.center, cell.size, void 0, [holes[k]]).length > 0));
26700
27440
  for (const cell of fallen) chipped.push({ center: [cell.center[0], cell.center[1], cell.center[2]], size: [cell.size[0], cell.size[1], cell.size[2]] });
@@ -26785,6 +27525,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26785
27525
  return;
26786
27526
  }
26787
27527
  if (!force && giveAtCut(o, p, src)) return;
27528
+ if (!force && isTiledCover(p)) {
27529
+ crumbleMasonry(o, p, src);
27530
+ return;
27531
+ }
26788
27532
  const ex = p.spec.explodes;
26789
27533
  const style = force ?? (p.snap ? "snap" : p.mat.fracture === "none" ? "snap" : p.mat.fracture);
26790
27534
  const { c, q } = partXf(o, p);
@@ -27114,14 +27858,15 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
27114
27858
  }
27115
27859
  if (Ein > 20 && p.layers.length > 0) spallOuter(o, p, wp, faceOf(o, p, wn), wn, clamp2(0.05 + Math.sqrt(Ein) * 2e-3, 0.05, 0.4), src);
27116
27860
  const breachReach = BREACH_BLAST_REACH * Math.cbrt(Math.max(0, energy) / 1e3);
27117
- const farMember = Boolean(p.spec.reinforcement && p.spec.units) && dist2 > MEMBER_CUT_REACH * breachReach;
27118
- const dealt = farMember ? applyDamage(o, p, Math.min(amount, Math.max(0, p.st.hp - p.st.maxHp * FAR_MEMBER_HP_FLOOR)), "explosive", null, null, Ein * 0.3, 40, src) : applyDamage(o, p, amount, "explosive", point, null, Ein * 0.3, 40, src);
27861
+ const caged2 = Boolean(p.spec.reinforcement && p.spec.units);
27862
+ const member = caged2 && (isMember(p.dims) || dist2 > MEMBER_CUT_REACH * breachReach);
27863
+ const dealt = member ? applyDamage(o, p, Math.min(amount, Math.max(0, p.st.hp - p.st.maxHp * FAR_MEMBER_HP_FLOOR)), "explosive", null, null, Ein * 0.3, 40, src) : applyDamage(o, p, amount, "explosive", point, null, Ein * 0.3, 40, src);
27119
27864
  res.damage += dealt;
27120
27865
  if (p.bend && flexure.enabled) bendByBlast(o, p, point, energy, radius, reach, src);
27121
27866
  if (p.spec.units && p.spec.units.mortar !== p.spec.material) {
27122
27867
  blastPanel(o, p, point, energy, src);
27123
27868
  if (!isLost(p)) blastUnits(o, p, wp, energy, dist2, src);
27124
- } else if (farMember) blastUnits(o, p, wp, energy, dist2, src);
27869
+ } else if (member) blastUnits(o, p, wp, energy, dist2, src);
27125
27870
  else if (dist2 <= breachReach) addBreach(o, p, wp, breachAreaOf(p, dealt, true), Ein, null, src);
27126
27871
  return reach;
27127
27872
  };
@@ -28805,6 +29550,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28805
29550
  return loads;
28806
29551
  }
28807
29552
  var isBearing = (part) => part.role === "column" || part.role === "wall";
29553
+ function isRoofFrame2(part) {
29554
+ return part.role === "roof" || part.id.startsWith("rafter");
29555
+ }
28808
29556
  function sizeCapacities(parts, supports, options) {
28809
29557
  const loads = loadsAtRest(parts, supports);
28810
29558
  const worst = /* @__PURE__ */ new Map();
@@ -28818,7 +29566,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28818
29566
  for (const part of parts) {
28819
29567
  const load = loads.get(part.id);
28820
29568
  if (load === void 0 || part.role === "none") continue;
28821
- const factor = isBearing(part) ? Math.max(1 / options.safety, (worst.get(part.id) ?? 1) / options.redundancy) : 1 / options.safetyOthers;
29569
+ const afterLoss = (worst.get(part.id) ?? 1) / options.redundancy;
29570
+ const factor = isBearing(part) ? Math.max(1 / options.safety, afterLoss) : isRoofFrame2(part) ? Math.max(1 / options.safetyOthers, afterLoss) : 1 / options.safetyOthers;
28822
29571
  capacities.set(part.id, Math.max(1, load * factor));
28823
29572
  }
28824
29573
  return capacities;
@@ -29385,7 +30134,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
29385
30134
  const alongU = wall.aabb[2] - wall.aabb[0] >= wall.aabb[3] - wall.aabb[1];
29386
30135
  const from = alongU ? wall.aabb[0] : wall.aabb[1];
29387
30136
  const to = alongU ? wall.aabb[2] : wall.aabb[3];
29388
- const cross3 = alongU ? [wall.aabb[1], wall.aabb[3]] : [wall.aabb[0], wall.aabb[2]];
30137
+ const cross4 = alongU ? [wall.aabb[1], wall.aabb[3]] : [wall.aabb[0], wall.aabb[2]];
29389
30138
  const rows = Math.max(1, Math.round((wall.y1 - wall.y0) / spec.rowHeight));
29390
30139
  const rowHeight = (wall.y1 - wall.y0) / rows;
29391
30140
  const cells = [];
@@ -29395,7 +30144,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
29395
30144
  for (const [a, b] of cutAt(from, to, openings.filter((o) => o.wall === wall.id), y0, y1)) for (const [x0, x1] of unitsOf(a, b, row, spec)) cells.push({ from: x0, to: x1, row, y0, y1 });
29396
30145
  }
29397
30146
  const total = cells.reduce((sum2, cell) => sum2 + (cell.to - cell.from) * (cell.y1 - cell.y0), 0);
29398
- const box22 = (cell) => alongU ? [cell.from, cross3[0], cell.to, cross3[1]] : [cross3[0], cell.from, cross3[1], cell.to];
30147
+ const box22 = (cell) => alongU ? [cell.from, cross4[0], cell.to, cross4[1]] : [cross4[0], cell.from, cross4[1], cell.to];
29399
30148
  const pieces = cells.map((cell, index) => ({
29400
30149
  id: `${wall.id}_${spec.unitLength ? "u" : "log"}${cell.row}_${index}`,
29401
30150
  role: wall.role,
@@ -29593,7 +30342,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
29593
30342
  }
29594
30343
  return spec;
29595
30344
  };
29596
- var MEMBER_CAGE = { spacing: 0.1, diameter: 8e-3, unit: 0.1 };
30345
+ var MEMBER_CAGE = { spacing: 0.1, diameter: 0.01, unit: 0.1 };
29597
30346
  var CAGED_ROLES = /* @__PURE__ */ new Set(["beam", "column"]);
29598
30347
  var CAGE_COVER = 0.03;
29599
30348
  var CAGE_BUCKLING_SHARE = 0.5;
@@ -31528,7 +32277,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
31528
32277
  }
31529
32278
  var residentialTower = residentialTowerTemplate();
31530
32279
 
31531
- // ../game-floorplan-three/dist/chunk-JPCVF3IZ.js
32280
+ // ../game-floorplan-three/dist/chunk-J3D4FCFR.js
31532
32281
  var __defProp4 = Object.defineProperty;
31533
32282
  var __defNormalProp2 = (obj, key2, value) => key2 in obj ? __defProp4(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
31534
32283
  var __publicField2 = (obj, key2, value) => __defNormalProp2(obj, typeof key2 !== "symbol" ? key2 + "" : key2, value);
@@ -32599,7 +33348,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
32599
33348
  }
32600
33349
  const wref = R.walls.find((w) => w.floor === f && w.axis === j.axis && Math.abs((alongU ? w.v0 : w.u0) - L) < EPS6), th = wref ? wref.thickness || 0.15 : 0.15, t = 0.05, tt = th + 0.02;
32601
33350
  const bar2 = (u0, y_0, u1, y_1, mat, color2, tw = tt) => alongU ? bx(mat, u0, y0 + y_0, L - tw / 2, u1, y0 + y_1, L + tw / 2, color2) : bx(mat, L - tw / 2, y0 + y_0, u0, L + tw / 2, y0 + y_1, u1, color2);
32602
- cursor.pc = pieceRecord("window_frame:" + j.id, "aluminium", null, { floor: f });
33351
+ const frame2 = pieceRecord("window_frame:" + j.id, "aluminium", null, { floor: f });
33352
+ cursor.pc = frame2;
32603
33353
  bar2(a, ya, a + t, yb, "metal", fr);
32604
33354
  bar2(b - t, ya, b, yb, "metal", fr);
32605
33355
  bar2(a, ya, b, ya + t, "metal", fr);
@@ -32612,6 +33362,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
32612
33362
  const am = (sd) => roomAt(f, alongU ? j.at : L + sd * 0.4, alongU ? L + sd * 0.4 : j.at);
32613
33363
  const outside = !am(1) ? 1 : !am(-1) ? -1 : 0;
32614
33364
  if (outside) {
33365
+ cursor.pc = frame2;
32615
33366
  const off = outside * (th / 2 + 0.03);
32616
33367
  if (alongU) bx("plaster", a - 0.05, y0 + ya - 0.04, L + (outside > 0 ? th / 2 : -th / 2 - 0.08), b + 0.05, y0 + ya, L + (outside > 0 ? th / 2 + 0.08 : -th / 2), pe_);
32617
33368
  else bx("plaster", L + (outside > 0 ? th / 2 : -th / 2 - 0.08), y0 + ya - 0.04, a - 0.05, L + (outside > 0 ? th / 2 + 0.08 : -th / 2), y0 + ya, b + 0.05, pe_);
@@ -32627,6 +33378,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
32627
33378
  else bx("metal", L + go - 0.012, y0 + y, a, L + go + 0.012, y0 + y + 0.025, b, g);
32628
33379
  }
32629
33380
  }
33381
+ cursor.pc = null;
32630
33382
  }
32631
33383
  if (j.boards && !boardItems.has(j.id) && !cut) {
32632
33384
  const inside2 = -(outside || -1), off = inside2 * (th / 2 + 0.04), n = Math.max(3, Math.round((yb - ya) / 0.16));
@@ -33559,7 +34311,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
33559
34311
  const { UV_SCALE, _Y, _h2, _q, accFor, cursor, put, rgbOf, structurePiece } = K;
33560
34312
  const sh = (...a) => K.sh(...a);
33561
34313
  const R_STYLE = () => shared3.ctx.r && shared3.ctx.r.style || "budget";
33562
- function tileRelief(mat, pts, color2, type) {
34314
+ function tileRelief(mat, pts, color2, type, origin) {
33563
34315
  const n = pts.length;
33564
34316
  if (n < 3) return;
33565
34317
  const [a, b, c] = pts;
@@ -33593,7 +34345,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
33593
34345
  ex /= el;
33594
34346
  ey /= el;
33595
34347
  ez /= el;
33596
- const o = pts[0], S = [], T2 = [];
34348
+ const o = origin ?? pts[0], S = [], T2 = [];
33597
34349
  for (const p of pts) {
33598
34350
  const rx = p[0] - o[0], ry = p[1] - o[1], rz = p[2] - o[2];
33599
34351
  S.push(rx * ex + ry * ey + rz * ez);
@@ -33658,6 +34410,19 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
33658
34410
  AC.nv += m * 2;
33659
34411
  }
33660
34412
  function ridge(a, b, type, roofColor) {
34413
+ const cuts = K.cfg.destruction ? baysAlong(a, b) : [];
34414
+ if (cuts.length) {
34415
+ let from = a;
34416
+ for (const f of [...cuts, 1]) {
34417
+ const to = [a[0] + (b[0] - a[0]) * f, a[1] + (b[1] - a[1]) * f, a[2] + (b[2] - a[2]) * f];
34418
+ ridgeCap(from, to, type, roofColor);
34419
+ from = to;
34420
+ }
34421
+ return;
34422
+ }
34423
+ ridgeCap(a, b, type, roofColor);
34424
+ }
34425
+ function ridgeCap(a, b, type, roofColor) {
33661
34426
  cursor.pc = pieceOfPane((a[0] + b[0]) / 2, (a[2] + b[2]) / 2);
33662
34427
  const dx = b[0] - a[0], dy = b[1] - a[1], dz = b[2] - a[2], Ln = Math.hypot(dx, dy, dz);
33663
34428
  if (Ln < 0.05) return;
@@ -33684,7 +34449,81 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
33684
34449
  }
33685
34450
  return m ? structurePiece(m.id) : null;
33686
34451
  }
33687
- const defined = { R_STYLE, tileRelief, ridge, pieceOfPane };
34452
+ function paneTiles(mat, pts, color2, type) {
34453
+ const panes = panesUnder(pts), whole = centroidPiece(pts);
34454
+ if (panes.length < 2 || !whole || !K.cfg.destruction) {
34455
+ cursor.pc = whole;
34456
+ tileRelief(mat, pts, color2, type);
34457
+ return;
34458
+ }
34459
+ for (const r of panes) {
34460
+ const part = clipToRect(pts, r);
34461
+ if (part.length < 3 || planArea(part) < 1e-4) continue;
34462
+ cursor.pc = centroidPiece(part);
34463
+ tileRelief(mat, part, color2, type, pts[0]);
34464
+ }
34465
+ }
34466
+ function centroidPiece(pts) {
34467
+ let cx = 0, cz = 0;
34468
+ for (const p of pts) {
34469
+ cx += p[0];
34470
+ cz += p[2];
34471
+ }
34472
+ return pieceOfPane(cx / pts.length, cz / pts.length);
34473
+ }
34474
+ function panesUnder(pts) {
34475
+ if (shared3.ctx.noPiece || !shared3.ctx.panes.length) return [];
34476
+ let x0 = Infinity, z0 = Infinity, x1 = -Infinity, z1 = -Infinity;
34477
+ for (const p of pts) {
34478
+ x0 = Math.min(x0, p[0]);
34479
+ x1 = Math.max(x1, p[0]);
34480
+ z0 = Math.min(z0, p[2]);
34481
+ z1 = Math.max(z1, p[2]);
34482
+ }
34483
+ const boxes = shared3.ctx.panes.map((a) => a.aabb).filter((b) => !!b && b[0] < x1 - 1e-4 && b[2] > x0 + 1e-4 && b[1] < z1 - 1e-4 && b[3] > z0 + 1e-4);
34484
+ if (boxes.length < 2) return boxes;
34485
+ const lo = [Math.min(...boxes.map((b) => b[0])), Math.min(...boxes.map((b) => b[1]))], hi = [Math.max(...boxes.map((b) => b[2])), Math.max(...boxes.map((b) => b[3]))];
34486
+ return boxes.map((b) => [b[0] <= lo[0] + 1e-6 ? -Infinity : b[0], b[1] <= lo[1] + 1e-6 ? -Infinity : b[1], b[2] >= hi[0] - 1e-6 ? Infinity : b[2], b[3] >= hi[1] - 1e-6 ? Infinity : b[3]]);
34487
+ }
34488
+ function baysAlong(a, b) {
34489
+ const rects = panesUnder([a, b, [b[0] + 1e-3, b[1], b[2] + 1e-3], [a[0] - 1e-3, a[1], a[2] - 1e-3]]);
34490
+ const alongX = Math.abs(b[0] - a[0]) >= Math.abs(b[2] - a[2]), i = alongX ? 0 : 2, k = alongX ? 0 : 1, span = b[i] - a[i];
34491
+ if (Math.abs(span) < 1e-6) return [];
34492
+ const cuts = /* @__PURE__ */ new Set();
34493
+ for (const r of rects) for (const v of [r[k], r[k + 2]]) {
34494
+ const f = (v - a[i]) / span;
34495
+ if (Number.isFinite(f) && f > 0.01 && f < 0.99) cuts.add(+f.toFixed(4));
34496
+ }
34497
+ return [...cuts].sort((p, q) => p - q);
34498
+ }
34499
+ function clipToRect(pts, r) {
34500
+ let poly = pts.map((p) => [p[0], p[1], p[2]]);
34501
+ const edges = [[0, r[0], 1], [0, r[2], -1], [2, r[1], 1], [2, r[3], -1]];
34502
+ for (const [axis2, at4, sign2] of edges) {
34503
+ if (!Number.isFinite(at4)) continue;
34504
+ const out = [];
34505
+ for (let i = 0; i < poly.length; i++) {
34506
+ const p = poly[i], q = poly[(i + 1) % poly.length], dp = (p[axis2] - at4) * sign2, dq = (q[axis2] - at4) * sign2;
34507
+ if (dp >= 0) out.push(p);
34508
+ if (dp >= 0 !== dq >= 0) {
34509
+ const t = dp / (dp - dq);
34510
+ out.push([p[0] + (q[0] - p[0]) * t, p[1] + (q[1] - p[1]) * t, p[2] + (q[2] - p[2]) * t]);
34511
+ }
34512
+ }
34513
+ poly = out;
34514
+ if (poly.length < 3) return [];
34515
+ }
34516
+ return poly;
34517
+ }
34518
+ function planArea(pts) {
34519
+ let a = 0;
34520
+ for (let i = 0; i < pts.length; i++) {
34521
+ const p = pts[i], q = pts[(i + 1) % pts.length];
34522
+ a += p[0] * q[2] - q[0] * p[2];
34523
+ }
34524
+ return Math.abs(a) / 2;
34525
+ }
34526
+ const defined = { R_STYLE, tileRelief, paneTiles, ridge, pieceOfPane };
33688
34527
  Object.assign(K, defined);
33689
34528
  }
33690
34529
  function installRoofRect(K, shared3) {
@@ -33693,15 +34532,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
33693
34532
  function roofRect(type, X0, Z0, X1, Z1, yb, roofColor, gable, F, touchesU = [0, 0, 0, 0]) {
33694
34533
  const C = shared3.ctx.colors, o = type === "fiber_cement" ? 0.3 : 0.45, x0 = X0 - (touchesU[0] ? 0 : o), x1 = X1 + (touchesU[2] ? 0 : o), z0 = Z0 - (touchesU[1] ? 0 : o), z1 = Z1 + (touchesU[3] ? 0 : o), dx = x1 - x0, dz = z1 - z0, xm = (x0 + x1) / 2, zm = (z0 + z1) / 2;
33695
34534
  const mat = type === "fiber_cement" ? "fiber_cement" : "tile", tp = type === "fiber_cement" ? 0.2 : 0.5, alongX = dx >= dz, up = [0, 1, 0];
33696
- const Q = (pts) => {
33697
- let cx = 0, cz = 0;
33698
- for (const p of pts) {
33699
- cx += p[0];
33700
- cz += p[2];
33701
- }
33702
- cursor.pc = pieceOfPane(cx / pts.length, cz / pts.length);
33703
- return tileRelief(mat, pts, roofColor, type);
33704
- };
34535
+ const Q = (pts) => K.paneTiles(mat, pts, roofColor, type);
33705
34536
  cursor.pc = pieceOfPane(xm, zm);
33706
34537
  {
33707
34538
  const wt = 0.075, yc = yb - 0.2, cf = C.facade != null ? C.facade : 14209216, fas = R_STYLE() === "budget" ? 7228980 : sh(roofColor, 0.55), sof = 15131352, tz = 0.035;
@@ -37924,7 +38755,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
37924
38755
  if (!pc || pc.unit) return sp;
37925
38756
  if (pc.role !== "wall" && pc.role !== "partition") {
37926
38757
  const def = getAssembly(pc.assembly || (pc.material === "concrete" && ["slab", "beam", "column", "stair"].includes(pc.role) ? "reinforced_concrete" : ""));
37927
- const cage = def && def.reinforcement ? pc.role === "column" && sp.shape.kind === "box" ? { ...def.reinforcement, residualCapacity: cageResidualCapacity(sp.shape.size, def.reinforcement, sp.structure?.capacity) } : { ...def.reinforcement } : null;
38758
+ const bars = def && def.reinforcement ? pc.role === "column" || pc.role === "beam" ? { ...def.reinforcement, diameter: Math.max(def.reinforcement.diameter, MEMBER_CAGE.diameter) } : def.reinforcement : null;
38759
+ const cage = bars ? pc.role === "column" && sp.shape.kind === "box" ? { ...bars, residualCapacity: cageResidualCapacity(sp.shape.size, bars, sp.structure?.capacity) } : { ...bars } : null;
37928
38760
  const out = cage && !sp.reinforcement ? { ...sp, reinforcement: cage } : sp;
37929
38761
  if (out.reinforcement && !out.units && pc.material === "concrete" && (pc.role === "beam" || pc.role === "column") && sp.shape.kind === "box") {
37930
38762
  return { ...out, units: { size: [MEMBER_CAGE.unit, MEMBER_CAGE.unit, Math.min(...sp.shape.size)], bond: "stack", mortar: "concrete" } };
@@ -38130,6 +38962,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
38130
38962
  toHouse.value.copy(house.matrixWorld).invert().multiply(mesh3.matrixWorld);
38131
38963
  return mesh3;
38132
38964
  }
38965
+ const withMask = (material, mask) => {
38966
+ material.userData.breachMask = mask;
38967
+ return material;
38968
+ };
38133
38969
  function unitsMaterial(core) {
38134
38970
  const material = new THREE.MeshLambertMaterial({ color: 16777215, side: THREE.DoubleSide });
38135
38971
  material.onBeforeCompile = (sh) => {
@@ -38214,13 +39050,22 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
38214
39050
  if (opening) discs.push({ s: along(opening.center), y: opening.center[1], r: opening.radius });
38215
39051
  for (const k of spalls) flakes.push({ s: along(k.center), y: k.center[1], r: k.radius });
38216
39052
  const boxes = chips2.map((k) => ({ s0: along(k.center) - k.along, s1: along(k.center) + k.along, y0: k.center[1] - k.up, y1: k.center[1] + k.up }));
38217
- const gone = (c) => covered(c, boxes.filter((k) => k.s1 > c.a && k.s0 < c.b && k.y1 > c.y0 && k.y0 < c.y1)) >= 0.9 || opening && Math.hypot((c.a + c.b) / 2 - along(opening.center), (c.y0 + c.y1) / 2 - opening.center[1]) < opening.radius;
39053
+ const gone = (c) => {
39054
+ const over = boxes.filter((k) => k.s1 > c.a && k.s0 < c.b && k.y1 > c.y0 && k.y0 < c.y1);
39055
+ const share = covered(c, over);
39056
+ if (share >= 0.9) return true;
39057
+ const s = (c.a + c.b) / 2, y = (c.y0 + c.y1) / 2;
39058
+ return share >= 0.5 && over.some((k) => s >= k.s0 && s <= k.s1 && y >= k.y0 && y <= k.y1);
39059
+ };
39060
+ const open = (c) => gone(c) || opening !== void 0 && Math.hypot((c.a + c.b) / 2 - along(opening.center), (c.y0 + c.y1) / 2 - opening.center[1]) < opening.radius;
38218
39061
  const kept = [];
38219
- for (const c of all) (gone(c) ? holes : kept).push(c);
39062
+ for (const c of all) (open(c) ? holes : kept).push(c);
38220
39063
  for (const c of kept) shown.push({ c, part, units: units2, thick, mid });
38221
- for (const k of boxes) {
38222
- if (holes.some((h) => k.s0 >= h.a - 1e-4 && k.s1 <= h.b + 1e-4 && k.y0 >= h.y0 - 1e-4 && k.y1 <= h.y1 + 1e-4)) continue;
38223
- pits.push({ s: (k.s0 + k.s1) / 2, y: (k.y0 + k.y1) / 2, rs: (k.s1 - k.s0) / 2, ry: (k.y1 - k.y0) / 2 });
39064
+ for (const box5 of boxes) {
39065
+ if (holes.some((h) => box5.s0 >= h.a - 1e-4 && box5.s1 <= h.b + 1e-4 && box5.y0 >= h.y0 - 1e-4 && box5.y1 <= h.y1 + 1e-4)) continue;
39066
+ const k = id === view.host ? besidePillars({ a: box5.s0, b: box5.s1, y0: box5.y0, y1: box5.y1 }, pillars)[0] : { a: box5.s0, b: box5.s1, y0: box5.y0, y1: box5.y1 };
39067
+ if (!k) continue;
39068
+ pits.push({ s: (k.a + k.b) / 2, y: (k.y0 + k.y1) / 2, rs: (k.b - k.a) / 2, ry: (k.y1 - k.y0) / 2 });
38224
39069
  }
38225
39070
  }
38226
39071
  const reach = SPALL_MIN + SPALL_RAGGED;
@@ -38249,6 +39094,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
38249
39094
  stamp(mask, p.s - p.rs, p.s + p.rs, p.y - p.ry, p.y + p.ry, (s, y) => plaster(Math.max(0, ellipseDistance(s, y, p.s, p.y, p.rs, p.ry)), s, y));
38250
39095
  stamp(core, p.s - p.rs, p.s + p.rs, p.y - p.ry, p.y + p.ry, (s, y) => ellipseDistance(s, y, p.s, p.y, p.rs, p.ry) <= -0.35 * Math.min(p.rs, p.ry) * noise2(s * 1.7, y * 1.3, 0.012));
38251
39096
  }
39097
+ for (const q of pillars) {
39098
+ const i0 = Math.max(0, Math.floor((q.a + 5e-3) / mask.len * mask.w)), i1 = Math.min(mask.w - 1, Math.floor((q.b - 5e-3) / mask.len * mask.w));
39099
+ const j0 = Math.max(0, Math.floor((q.y0 - mask.y0) / mask.height * mask.h)), j1 = Math.min(mask.h - 1, Math.floor((q.y1 - mask.y0) / mask.height * mask.h));
39100
+ for (let j = j0; j <= j1; j++) if (mask.data[j * mask.w + i0] && mask.data[j * mask.w + i1]) mask.data.fill(255, j * mask.w + i0, j * mask.w + i1 + 1);
39101
+ }
38252
39102
  mask.texture.needsUpdate = true;
38253
39103
  core.texture.needsUpdate = true;
38254
39104
  const near = (c) => holes.some((h) => boxDistance((c.a + c.b) / 2, (c.y0 + c.y1) / 2, h.a - (c.b - c.a) / 2, h.b + (c.b - c.a) / 2, h.y0 - (c.y1 - c.y0) / 2, h.y1 + (c.y1 - c.y0) / 2) <= reach) || discs.some((d) => boxDistance(d.s, d.y, c.a, c.b, c.y0, c.y1) <= d.r + reach) || pits.some((p) => boxDistance(p.s, p.y, c.a, c.b, c.y0, c.y1) <= Math.max(p.rs, p.ry) + reach) || flakes.some((f) => boxDistance(f.s, f.y, c.a, c.b, c.y0, c.y1) <= 2 * f.r);
@@ -38315,7 +39165,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
38315
39165
  items,
38316
39166
  mask,
38317
39167
  core,
38318
- unitMaterial: unitsMaterial(core),
39168
+ unitMaterial: withMask(unitsMaterial(core), mask),
38319
39169
  shells: [],
38320
39170
  saved: null,
38321
39171
  units: null,
@@ -68474,7 +69324,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
68474
69324
  var tangentA = { x: 0, y: 0, z: 0 };
68475
69325
  var tangentB = { x: 0, y: 0, z: 0 };
68476
69326
  var axis = { x: 0, y: 0, z: 0 };
68477
- function cross2(out, a, b) {
69327
+ function cross3(out, a, b) {
68478
69328
  const x = a.y * b.z - a.z * b.y;
68479
69329
  const y = a.z * b.x - a.x * b.z;
68480
69330
  const z = a.x * b.y - a.y * b.x;
@@ -68499,8 +69349,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
68499
69349
  tangentA.x = 0;
68500
69350
  tangentA.y = 1;
68501
69351
  }
68502
- normalize2(cross2(tangentB, axis, tangentA));
68503
- normalize2(cross2(tangentA, tangentB, axis));
69352
+ normalize2(cross3(tangentB, axis, tangentA));
69353
+ normalize2(cross3(tangentA, tangentB, axis));
68504
69354
  out.x = dx * cosTilt;
68505
69355
  out.y = dy * cosTilt;
68506
69356
  out.z = dz * cosTilt;