@adatechnology/game-items-three 0.11.6 → 0.11.8

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.
@@ -573,12 +573,12 @@ var GameItemsThree = (() => {
573
573
  }
574
574
  return pack("TorusGeometry", parameters, { vertices, normals, uvs, indices, groups: [] });
575
575
  }
576
- function difference(size, subtract) {
576
+ function difference(size, subtract2) {
577
577
  const [w, h, d] = size;
578
578
  const hw = w / 2;
579
579
  const hh = h / 2;
580
580
  const hd = d / 2;
581
- const holes = subtract.map((hole) => ({ x0: Math.max(-hw, Math.min(hole.min[0], hole.max[0])), x1: Math.min(hw, Math.max(hole.min[0], hole.max[0])), y0: Math.max(-hh, Math.min(hole.min[1], hole.max[1])), y1: Math.min(hh, Math.max(hole.min[1], hole.max[1])) })).filter((hole) => hole.x1 > hole.x0 && hole.y1 > hole.y0);
581
+ const holes = subtract2.map((hole) => ({ x0: Math.max(-hw, Math.min(hole.min[0], hole.max[0])), x1: Math.min(hw, Math.max(hole.min[0], hole.max[0])), y0: Math.max(-hh, Math.min(hole.min[1], hole.max[1])), y1: Math.min(hh, Math.max(hole.min[1], hole.max[1])) })).filter((hole) => hole.x1 > hole.x0 && hole.y1 > hole.y0);
582
582
  const cuts = (lo, hi, values) => [.../* @__PURE__ */ new Set([lo, hi, ...values.filter((v) => v > lo && v < hi)])].sort((a, b) => a - b);
583
583
  const xs = cuts(-hw, hw, holes.flatMap((hole) => [hole.x0, hole.x1]));
584
584
  const ys = cuts(-hh, hh, holes.flatMap((hole) => [hole.y0, hole.y1]));
@@ -11742,7 +11742,7 @@ var GameItemsThree = (() => {
11742
11742
  if (isOpen) for (const s of [-1, 1]) K.box("fabric", s * (w / 2 - pw * 0.25), y + h * 0.4, 0.04, pw * 0.5, 0.05, 0.02, shade2(color2, 0.7));
11743
11743
  };
11744
11744
  B.blinds = (M, a) => {
11745
- const K = kit(M, a), { w, h } = K.dim("blinds"), y = M.y || 1, retract = M.retracted != null ? M.retracted : 0.15, isWood = M.variant === "wood", color2 = isWood ? K.wood(10123858) : K.color("wall_living", 15262420), mat = isWood ? "wood" : "plain", yb = y + h * retract, n = Math.floor((y + h - yb) / 0.055);
11745
+ const K = kit(M, a), { w, h } = K.dim("blinds"), y = M.y || 1, retract = M.retracted != null ? M.retracted : 0.15, isWood2 = M.variant === "wood", color2 = isWood2 ? K.wood(10123858) : K.color("wall_living", 15262420), mat = isWood2 ? "wood" : "plain", yb = y + h * retract, n = Math.floor((y + h - yb) / 0.055);
11746
11746
  K.box("plain", 0, y + h - 0.05, 0, w, 0.05, 0.06, 14473424);
11747
11747
  for (let i = 0; i < n; i++) K.box(mat, 0, y + h - 0.06 - (i + 1) * 0.055, 0, w - 0.05, 0.01, 0.035, color2, 0, 0.3);
11748
11748
  for (const s of [-1, 1]) K.box("plain", s * (w / 2 - 0.05), yb, 0.02, 8e-3, y + h - 0.05 - yb, 8e-3, 12104876);
@@ -14790,6 +14790,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
14790
14790
  tension: {
14791
14791
  elasticGPa: 200,
14792
14792
  ultimateMPa: 400
14793
+ },
14794
+ elastic: {
14795
+ alongGPa: 200,
14796
+ shearGPa: 77
14793
14797
  }
14794
14798
  },
14795
14799
  {
@@ -14828,7 +14832,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
14828
14832
  elasticGPa: 200,
14829
14833
  absorbed: 0.2
14830
14834
  },
14831
- failureMPa: 1400
14835
+ failureMPa: 1400,
14836
+ elastic: {
14837
+ alongGPa: 200,
14838
+ shearGPa: 77
14839
+ }
14832
14840
  },
14833
14841
  {
14834
14842
  id: "cast_iron",
@@ -14899,6 +14907,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
14899
14907
  tension: {
14900
14908
  elasticGPa: 69,
14901
14909
  ultimateMPa: 170
14910
+ },
14911
+ elastic: {
14912
+ alongGPa: 69,
14913
+ shearGPa: 26
14902
14914
  }
14903
14915
  },
14904
14916
  {
@@ -14981,7 +14993,12 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
14981
14993
  tearJoules: 60
14982
14994
  }
14983
14995
  },
14984
- failureMPa: 40
14996
+ failureMPa: 40,
14997
+ elastic: {
14998
+ alongGPa: 12.3,
14999
+ acrossGPa: 1.17,
15000
+ shearGPa: 1
15001
+ }
14985
15002
  },
14986
15003
  {
14987
15004
  id: "wood_hard",
@@ -15032,7 +15049,12 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
15032
15049
  elasticGPa: 12,
15033
15050
  absorbed: 0.3
15034
15051
  },
15035
- failureMPa: 80
15052
+ failureMPa: 80,
15053
+ elastic: {
15054
+ alongGPa: 12,
15055
+ acrossGPa: 1.42,
15056
+ shearGPa: 1.02
15057
+ }
15036
15058
  },
15037
15059
  {
15038
15060
  id: "plywood",
@@ -15164,7 +15186,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
15164
15186
  "brittle"
15165
15187
  ],
15166
15188
  compressive: 1e5,
15167
- failureMPa: 45
15189
+ failureMPa: 45,
15190
+ elastic: {
15191
+ alongGPa: 70,
15192
+ shearGPa: 29
15193
+ }
15168
15194
  },
15169
15195
  {
15170
15196
  id: "tempered_glass",
@@ -15199,7 +15225,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
15199
15225
  damageScale: {
15200
15226
  shelter: 3
15201
15227
  },
15202
- failureMPa: 120
15228
+ failureMPa: 120,
15229
+ elastic: {
15230
+ alongGPa: 70,
15231
+ shearGPa: 29
15232
+ }
15203
15233
  },
15204
15234
  {
15205
15235
  id: "ceramic",
@@ -15222,6 +15252,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
15222
15252
  heatCapacity: 1.5,
15223
15253
  thermalShockC: 200
15224
15254
  },
15255
+ visual: {
15256
+ innerColor: 13148794
15257
+ },
15225
15258
  tags: [
15226
15259
  "ceramic",
15227
15260
  "brittle"
@@ -15519,7 +15552,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
15519
15552
  },
15520
15553
  visual: {
15521
15554
  charColor: 855309,
15522
- innerColor: 15254346
15555
+ innerColor: 14271631
15523
15556
  },
15524
15557
  tags: [
15525
15558
  "fabric",
@@ -16252,6 +16285,828 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
16252
16285
  if (ductility >= 0.3) return 1;
16253
16286
  return (1 + 4 * (0.3 - ductility) / 0.3) * Math.min(25, Math.max(1, (0.02 / Math.max(thickness, 1e-4)) ** 2));
16254
16287
  };
16288
+ var EPS2 = 1e-9;
16289
+ var rotateVecInto = (q, v, out) => {
16290
+ const qx = q[0], qy = q[1], qz = q[2], qw = q[3];
16291
+ const tx = 2 * (qy * v[2] - qz * v[1]);
16292
+ const ty = 2 * (qz * v[0] - qx * v[2]);
16293
+ const tz = 2 * (qx * v[1] - qy * v[0]);
16294
+ const x = v[0] + qw * tx + (qy * tz - qz * ty);
16295
+ const y = v[1] + qw * ty + (qz * tx - qx * tz);
16296
+ const z = v[2] + qw * tz + (qx * ty - qy * tx);
16297
+ out[0] = x;
16298
+ out[1] = y;
16299
+ out[2] = z;
16300
+ return out;
16301
+ };
16302
+ var normalizeInto = (x, y, z, out, fx, fy, fz) => {
16303
+ const l = Math.sqrt(x * x + y * y + z * z);
16304
+ if (l < EPS2) {
16305
+ out[0] = fx;
16306
+ out[1] = fy;
16307
+ out[2] = fz;
16308
+ return;
16309
+ }
16310
+ out[0] = x / l;
16311
+ out[1] = y / l;
16312
+ out[2] = z / l;
16313
+ };
16314
+ var boxInto = (size, o, d, out) => {
16315
+ let tmin = -Infinity, tmax = Infinity;
16316
+ let a0 = 0, s0 = 1;
16317
+ for (let i = 0; i < 3; i++) {
16318
+ const h = size[i] / 2;
16319
+ if (Math.abs(d[i]) < EPS2) {
16320
+ if (Math.abs(o[i]) > h) return false;
16321
+ continue;
16322
+ }
16323
+ let ta = (-h - o[i]) / d[i];
16324
+ let tb = (h - o[i]) / d[i];
16325
+ let sa = -1;
16326
+ if (ta > tb) {
16327
+ const t = ta;
16328
+ ta = tb;
16329
+ tb = t;
16330
+ sa = 1;
16331
+ }
16332
+ if (ta > tmin) {
16333
+ tmin = ta;
16334
+ a0 = i;
16335
+ s0 = sa;
16336
+ }
16337
+ if (tb < tmax) tmax = tb;
16338
+ if (tmin > tmax) return false;
16339
+ }
16340
+ if (tmax < 0 || !Number.isFinite(tmin) || !Number.isFinite(tmax)) return false;
16341
+ out.t0 = tmin;
16342
+ out.t1 = tmax;
16343
+ out.n0[0] = 0;
16344
+ out.n0[1] = 0;
16345
+ out.n0[2] = 0;
16346
+ out.n0[a0] = s0;
16347
+ return true;
16348
+ };
16349
+ var sphereInto = (radius, o, d, out) => {
16350
+ const b = o[0] * d[0] + o[1] * d[1] + o[2] * d[2];
16351
+ const a = d[0] * d[0] + d[1] * d[1] + d[2] * d[2];
16352
+ const c = o[0] * o[0] + o[1] * o[1] + o[2] * o[2] - radius * radius;
16353
+ const disc = b * b - a * c;
16354
+ if (disc < 0) return false;
16355
+ const sq = Math.sqrt(disc);
16356
+ const t0 = (-b - sq) / a;
16357
+ const t1 = (-b + sq) / a;
16358
+ if (t1 < 0) return false;
16359
+ out.t0 = t0;
16360
+ out.t1 = t1;
16361
+ normalizeInto(o[0] + d[0] * t0, o[1] + d[1] * t0, o[2] + d[2] * t0, out.n0, 0, 1, 0);
16362
+ return true;
16363
+ };
16364
+ var cylinderInto = (radius, height, o, d, out) => {
16365
+ const hh = height / 2;
16366
+ const a = d[0] * d[0] + d[2] * d[2];
16367
+ const c = o[0] * o[0] + o[2] * o[2] - radius * radius;
16368
+ let tA = -Infinity, tB = Infinity;
16369
+ if (a > EPS2) {
16370
+ const b = o[0] * d[0] + o[2] * d[2];
16371
+ const disc = b * b - a * c;
16372
+ if (disc < 0) return false;
16373
+ const sq = Math.sqrt(disc);
16374
+ tA = (-b - sq) / a;
16375
+ tB = (-b + sq) / a;
16376
+ } else if (c > 0) return false;
16377
+ let yA = -Infinity, yB = Infinity;
16378
+ if (Math.abs(d[1]) > EPS2) {
16379
+ yA = (-hh - o[1]) / d[1];
16380
+ yB = (hh - o[1]) / d[1];
16381
+ if (yA > yB) {
16382
+ const t = yA;
16383
+ yA = yB;
16384
+ yB = t;
16385
+ }
16386
+ } else if (Math.abs(o[1]) > hh) return false;
16387
+ const t0 = Math.max(tA, yA);
16388
+ const t1 = Math.min(tB, yB);
16389
+ if (t0 > t1 || t1 < 0 || !Number.isFinite(t0) || !Number.isFinite(t1)) return false;
16390
+ out.t0 = t0;
16391
+ out.t1 = t1;
16392
+ if (tA >= yA) normalizeInto(o[0] + d[0] * t0, 0, o[2] + d[2] * t0, out.n0, 1, 0, 0);
16393
+ else {
16394
+ out.n0[0] = 0;
16395
+ out.n0[1] = d[1] > 0 ? -1 : 1;
16396
+ out.n0[2] = 0;
16397
+ }
16398
+ return true;
16399
+ };
16400
+ var rayShapeInto = (s, o, d, out) => {
16401
+ if (s.kind === "box") return boxInto(s.size, o, d, out);
16402
+ if (s.kind === "sphere") return sphereInto(s.radius, o, d, out);
16403
+ return cylinderInto(s.radius, s.height, o, d, out);
16404
+ };
16405
+ var JOINT_FASTENERS = {
16406
+ screw: { diameterMm: 4.5, lateral: "predrilled", spacing: 0.2 },
16407
+ bolt: { diameterMm: 8, lateral: "predrilled", spacing: 0.2 },
16408
+ nail: { diameterMm: 3, lateral: "driven", spacing: 0.15 }
16409
+ };
16410
+ var RIGID_KINDS = /* @__PURE__ */ new Set(["glue", "weld", "fused", "mortar", "rebar"]);
16411
+ var RIGID_PUSH = 1e10;
16412
+ var RIGID_TURN = 1e8;
16413
+ var TOUCH = 0.01;
16414
+ var FOOT_BAND = 0.03;
16415
+ var SEAM_STATIONS = 5;
16416
+ var BEAM_PIECES = 4;
16417
+ var SLENDER = 4;
16418
+ var MAX_DOF = 1500;
16419
+ var MECHANISM = 0.5;
16420
+ var FOOT_FRICTION = 0.4;
16421
+ var UPRIGHT = 0.9;
16422
+ var SOFT = 1e-11;
16423
+ var GRAVITY2 = 9.81;
16424
+ var EDGE_D = 4;
16425
+ var ROW_D = 5;
16426
+ var END_D = 10;
16427
+ var THREAD_D = 6;
16428
+ var isWood = (m) => !!m.tags && m.tags.includes("wood");
16429
+ function fastenerStiffness(kind, a, b) {
16430
+ const f = JOINT_FASTENERS[kind];
16431
+ if (!f) return null;
16432
+ const woods = [a, b].filter(isWood);
16433
+ if (woods.length === 0) return null;
16434
+ const density = woods.length === 2 ? Math.sqrt(a.density * b.density) : woods[0].density;
16435
+ const d = f.diameterMm;
16436
+ const perMm = f.lateral === "predrilled" ? density ** 1.5 * d / 23 : density ** 1.5 * d ** 0.8 / 30;
16437
+ const lateral = perMm * 1e3 * (woods.length === 1 ? 2 : 1);
16438
+ const axial = kind === "screw" ? 234 * (density * d) ** 0.2 * (THREAD_D * d) ** 0.4 * 1e3 : lateral;
16439
+ return { lateral, axial, diameter: d / 1e3, spacing: f.spacing };
16440
+ }
16441
+ function torsionConstant(side, other) {
16442
+ const b = Math.max(side, other);
16443
+ const t = Math.min(side, other);
16444
+ if (b <= 0) return 0;
16445
+ const r = t / b;
16446
+ return b * t ** 3 * (1 / 3 - 0.21 * r * (1 - r ** 4 / 12));
16447
+ }
16448
+ var AXES = [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
16449
+ function beamOf(part) {
16450
+ const d = part.dims;
16451
+ let a = 0;
16452
+ if (d[1] > d[a]) a = 1;
16453
+ if (d[2] > d[a]) a = 2;
16454
+ const ui = (a + 1) % 3;
16455
+ const vi = (a + 2) % 3;
16456
+ const axis = rotateVec(part.rotation, AXES[a]);
16457
+ const u = rotateVec(part.rotation, AXES[ui]);
16458
+ const v = rotateVec(part.rotation, AXES[vi]);
16459
+ const min = [Infinity, Infinity, Infinity];
16460
+ const max = [-Infinity, -Infinity, -Infinity];
16461
+ for (let i = 0; i < 8; i++) {
16462
+ const c = cornerOf(part, i);
16463
+ for (let k = 0; k < 3; k++) {
16464
+ min[k] = Math.min(min[k], c[k]);
16465
+ max[k] = Math.max(max[k], c[k]);
16466
+ }
16467
+ }
16468
+ return { part, axis, u, v, length: d[a], stations: [], nodes: [], min, max };
16469
+ }
16470
+ function cornerOf(part, i) {
16471
+ const d = part.dims;
16472
+ const local = [(i & 1 ? 0.5 : -0.5) * d[0], (i & 2 ? 0.5 : -0.5) * d[1], (i & 4 ? 0.5 : -0.5) * d[2]];
16473
+ return vec.add(part.position, rotateVec(part.rotation, local));
16474
+ }
16475
+ function sectionOf(beam) {
16476
+ const elastic = beam.part.material.elastic;
16477
+ if (!elastic) return null;
16478
+ const d = beam.part.dims;
16479
+ let a = 0;
16480
+ if (d[1] > d[a]) a = 1;
16481
+ if (d[2] > d[a]) a = 2;
16482
+ const du = d[(a + 1) % 3];
16483
+ const dv = d[(a + 2) % 3];
16484
+ const along2 = beam.part.grain === void 0 || beam.part.grain === a;
16485
+ const e = (along2 ? elastic.alongGPa : elastic.acrossGPa ?? elastic.alongGPa) * 1e9;
16486
+ const g = elastic.shearGPa * 1e9;
16487
+ if (beam.part.round && a === 1) {
16488
+ const r = du / 2;
16489
+ const i = Math.PI * r ** 4 / 4;
16490
+ return { area: Math.PI * r * r, iu: i, iv: i, j: 2 * i, e, g };
16491
+ }
16492
+ return { area: du * dv, iu: du * dv ** 3 / 12, iv: dv * du ** 3 / 12, j: torsionConstant(du, dv), e, g };
16493
+ }
16494
+ function beamLocal(s, length) {
16495
+ const k = new Float64Array(144);
16496
+ const set = (i, j, value) => {
16497
+ k[i * 12 + j] = value;
16498
+ k[j * 12 + i] = value;
16499
+ };
16500
+ const L = length;
16501
+ const ea = s.e * s.area / L;
16502
+ const gj = s.g * s.j / L;
16503
+ const z = s.e * s.iv;
16504
+ const y = s.e * s.iu;
16505
+ set(0, 0, ea);
16506
+ set(0, 6, -ea);
16507
+ set(6, 6, ea);
16508
+ set(3, 3, gj);
16509
+ set(3, 9, -gj);
16510
+ set(9, 9, gj);
16511
+ set(1, 1, 12 * z / L ** 3);
16512
+ set(1, 5, 6 * z / L ** 2);
16513
+ set(1, 7, -12 * z / L ** 3);
16514
+ set(1, 11, 6 * z / L ** 2);
16515
+ set(5, 5, 4 * z / L);
16516
+ set(5, 7, -6 * z / L ** 2);
16517
+ set(5, 11, 2 * z / L);
16518
+ set(7, 7, 12 * z / L ** 3);
16519
+ set(7, 11, -6 * z / L ** 2);
16520
+ set(11, 11, 4 * z / L);
16521
+ set(2, 2, 12 * y / L ** 3);
16522
+ set(2, 4, -6 * y / L ** 2);
16523
+ set(2, 8, -12 * y / L ** 3);
16524
+ set(2, 10, -6 * y / L ** 2);
16525
+ set(4, 4, 4 * y / L);
16526
+ set(4, 8, 6 * y / L ** 2);
16527
+ set(4, 10, 2 * y / L);
16528
+ set(8, 8, 12 * y / L ** 3);
16529
+ set(8, 10, 6 * y / L ** 2);
16530
+ set(10, 10, 4 * y / L);
16531
+ return k;
16532
+ }
16533
+ function toObjectFrame(k, n, x, y, z) {
16534
+ const r = [x[0], y[0], z[0], x[1], y[1], z[1], x[2], y[2], z[2]];
16535
+ const half = new Float64Array(n * n);
16536
+ const out = new Float64Array(n * n);
16537
+ for (let block = 0; block < n; block += 3) {
16538
+ for (let col = 0; col < n; col++) {
16539
+ for (let i = 0; i < 3; i++) {
16540
+ let sum = 0;
16541
+ for (let m = 0; m < 3; m++) sum += r[i * 3 + m] * k[(block + m) * n + col];
16542
+ half[(block + i) * n + col] = sum;
16543
+ }
16544
+ }
16545
+ }
16546
+ for (let row = 0; row < n; row++) {
16547
+ for (let block = 0; block < n; block += 3) {
16548
+ for (let i = 0; i < 3; i++) {
16549
+ let sum = 0;
16550
+ for (let m = 0; m < 3; m++) sum += half[row * n + block + m] * r[i * 3 + m];
16551
+ out[row * n + block + i] = sum;
16552
+ }
16553
+ }
16554
+ }
16555
+ return out;
16556
+ }
16557
+ function armRows(arm) {
16558
+ const [x, y, z] = arm;
16559
+ return [
16560
+ [1, 0, 0, 0, z, -y],
16561
+ [0, 1, 0, -z, 0, x],
16562
+ [0, 0, 1, y, -x, 0]
16563
+ ];
16564
+ }
16565
+ function stationsOf(joint, a, b) {
16566
+ const lo = [0, 0, 0];
16567
+ const hi = [0, 0, 0];
16568
+ let touching = true;
16569
+ for (let k = 0; k < 3; k++) {
16570
+ lo[k] = Math.max(a.min[k], b.min[k]);
16571
+ hi[k] = Math.min(a.max[k], b.max[k]);
16572
+ if (hi[k] < lo[k] - TOUCH) touching = false;
16573
+ }
16574
+ const rigid = RIGID_KINDS.has(joint.kind);
16575
+ const fastener = rigid ? null : fastenerStiffness(joint.kind, a.part.material, b.part.material);
16576
+ const stiff = rigid || !fastener && JOINT_FASTENERS[joint.kind] !== void 0;
16577
+ if (!stiff && !fastener) return [];
16578
+ if (!touching) {
16579
+ const frame3 = [[0, 1, 0], [1, 0, 0], [0, 0, 1]];
16580
+ if (stiff || !fastener) return [{ at: joint.position, frame: frame3, push: [RIGID_PUSH, RIGID_PUSH, RIGID_PUSH], turn: [RIGID_TURN, RIGID_TURN, RIGID_TURN] }];
16581
+ return [{ at: joint.position, frame: frame3, push: [fastener.axial, fastener.lateral, fastener.lateral], turn: [0, 0, 0] }];
16582
+ }
16583
+ const size = [Math.max(0, hi[0] - lo[0]), Math.max(0, hi[1] - lo[1]), Math.max(0, hi[2] - lo[2])];
16584
+ const middle = [(lo[0] + hi[0]) / 2, (lo[1] + hi[1]) / 2, (lo[2] + hi[2]) / 2];
16585
+ let n = 0;
16586
+ if (size[1] < size[n]) n = 1;
16587
+ if (size[2] < size[n]) n = 2;
16588
+ let w = (n + 1) % 3;
16589
+ let c = (n + 2) % 3;
16590
+ if (size[c] > size[w]) [w, c] = [c, w];
16591
+ const frame2 = [AXES[n], AXES[w], AXES[c]];
16592
+ const along2 = size[w];
16593
+ const across2 = size[c];
16594
+ const d = fastener?.diameter ?? 5e-3;
16595
+ const spacing = fastener?.spacing ?? 0.2;
16596
+ const end = END_D * d;
16597
+ const count = along2 > 2 * end ? 1 + Math.ceil((along2 - 2 * end) / spacing) : 1;
16598
+ const stations = Math.min(count, SEAM_STATIONS);
16599
+ const each = count / stations;
16600
+ const out = [];
16601
+ for (let s = 0; s < stations; s++) {
16602
+ const t = stations === 1 ? 0 : -along2 / 2 + end + (along2 - 2 * end) * s / (stations - 1);
16603
+ const at2 = [middle[0], middle[1], middle[2]];
16604
+ at2[w] = middle[w] + t;
16605
+ if (stiff || !fastener) {
16606
+ out.push({ at: at2, frame: frame2, push: [RIGID_PUSH, RIGID_PUSH, RIGID_PUSH], turn: [RIGID_TURN, RIGID_TURN, RIGID_TURN] });
16607
+ continue;
16608
+ }
16609
+ const rows = across2 >= (2 * EDGE_D + ROW_D) * d ? [EDGE_D * d, across2 - EDGE_D * d] : [across2 / 2];
16610
+ const pry = rows.reduce((sum, r) => sum + r * r, 0) * fastener.axial * each;
16611
+ const lone = stations === 1;
16612
+ const pryAlong = lone ? (along2 / 2) ** 2 * fastener.axial * rows.length : 0;
16613
+ const twist = lone && rows.length > 1 ? rows.reduce((sum, r) => sum + (r - across2 / 2) ** 2, 0) * fastener.lateral : 0;
16614
+ out.push({ at: at2, frame: frame2, push: [fastener.axial * rows.length * each, fastener.lateral * rows.length * each, fastener.lateral * rows.length * each], turn: [twist, pry, pryAlong] });
16615
+ }
16616
+ return out;
16617
+ }
16618
+ function solve(k, f, n) {
16619
+ const first = new Int32Array(n);
16620
+ for (let i = 0; i < n; i++) {
16621
+ let j = 0;
16622
+ while (j < i && k[i * n + j] === 0) j++;
16623
+ first[i] = j;
16624
+ }
16625
+ for (let i = 0; i < n; i++) {
16626
+ const fi = first[i];
16627
+ for (let j = fi; j <= i; j++) {
16628
+ let sum = k[i * n + j];
16629
+ const from = Math.max(fi, first[j]);
16630
+ for (let m = from; m < j; m++) sum -= k[i * n + m] * k[j * n + m];
16631
+ if (j === i) {
16632
+ if (!(sum > 0)) return false;
16633
+ k[i * n + i] = Math.sqrt(sum);
16634
+ } else k[i * n + j] = sum / k[j * n + j];
16635
+ }
16636
+ }
16637
+ for (let i = 0; i < n; i++) {
16638
+ let sum = f[i];
16639
+ for (let m = first[i]; m < i; m++) sum -= k[i * n + m] * f[m];
16640
+ f[i] = sum / k[i * n + i];
16641
+ }
16642
+ for (let i = n - 1; i >= 0; i--) {
16643
+ const x = f[i] / k[i * n + i];
16644
+ f[i] = x;
16645
+ for (let m = first[i]; m < i; m++) f[m] = f[m] - k[i * n + m] * x;
16646
+ }
16647
+ return true;
16648
+ }
16649
+ function hullOf(points) {
16650
+ const sorted = [...points].sort((p, q) => p[0] - q[0] || p[1] - q[1]);
16651
+ const turn = (o, p, q) => (p[0] - o[0]) * (q[1] - o[1]) - (p[1] - o[1]) * (q[0] - o[0]);
16652
+ const lower = [];
16653
+ for (const p of sorted) {
16654
+ while (lower.length >= 2 && turn(lower[lower.length - 2], lower[lower.length - 1], p) <= 1e-12) lower.pop();
16655
+ lower.push([p[0], p[1]]);
16656
+ }
16657
+ const upper = [];
16658
+ for (let i = sorted.length - 1; i >= 0; i--) {
16659
+ const p = sorted[i];
16660
+ while (upper.length >= 2 && turn(upper[upper.length - 2], upper[upper.length - 1], p) <= 1e-12) upper.pop();
16661
+ upper.push([p[0], p[1]]);
16662
+ }
16663
+ lower.pop();
16664
+ upper.pop();
16665
+ return [...lower, ...upper];
16666
+ }
16667
+ function assemblyFlex(input) {
16668
+ const g = input.gravity ?? GRAVITY2;
16669
+ const lost = new Set(input.lost ?? []);
16670
+ const beams = /* @__PURE__ */ new Map();
16671
+ for (const part of input.parts) {
16672
+ if (part.mass <= 0 || Math.max(...part.dims) <= 0) continue;
16673
+ beams.set(part.id, beamOf(part));
16674
+ }
16675
+ if (beams.size === 0) return null;
16676
+ const floor = input.floor ?? Math.min(...[...beams.values()].map((b) => b.min[1]));
16677
+ const joints = input.joints.filter((j) => beams.has(j.a) && beams.has(j.b) && j.a !== j.b);
16678
+ const structural = (j) => RIGID_KINDS.has(j.kind) || JOINT_FASTENERS[j.kind] !== void 0;
16679
+ const stationed = /* @__PURE__ */ new Map();
16680
+ const along2 = (beam, p) => Math.max(-beam.length / 2, Math.min(beam.length / 2, vec.dot(vec.sub(p, beam.part.position), beam.axis)));
16681
+ for (const beam of beams.values()) beam.stations.push(-beam.length / 2, beam.length / 2);
16682
+ for (const joint of joints) {
16683
+ if (!structural(joint)) continue;
16684
+ const a = beams.get(joint.a);
16685
+ const b = beams.get(joint.b);
16686
+ const stations = stationsOf(joint, a, b);
16687
+ stationed.set(joint, stations);
16688
+ for (const s of stations) {
16689
+ a.stations.push(along2(a, s.at));
16690
+ b.stations.push(along2(b, s.at));
16691
+ }
16692
+ }
16693
+ const footPoints = /* @__PURE__ */ new Map();
16694
+ for (const beam of beams.values()) {
16695
+ if (beam.min[1] > floor + FOOT_BAND) continue;
16696
+ const corners = [];
16697
+ for (let i = 0; i < 8; i++) {
16698
+ const c = cornerOf(beam.part, i);
16699
+ if (c[1] <= beam.min[1] + 5e-3) corners.push(c);
16700
+ }
16701
+ footPoints.set(beam.part.id, corners);
16702
+ for (const c of corners) beam.stations.push(along2(beam, c));
16703
+ }
16704
+ const nodes = [];
16705
+ for (const beam of beams.values()) {
16706
+ const sides = beam.part.dims.filter((d) => d !== beam.length);
16707
+ const merge = Math.max(2e-3, 0.5 * Math.min(...sides, beam.length));
16708
+ const sorted = [...beam.stations].sort((p, q) => p - q);
16709
+ const met = [];
16710
+ for (const s of sorted) if (met.length === 0 || s - met[met.length - 1] > merge) met.push(s);
16711
+ if (met.length > 1 && beam.length / 2 - met[met.length - 1] > 0) met[met.length - 1] = beam.length / 2;
16712
+ const longest = beam.length >= SLENDER * Math.max(...sides, 0) && Math.abs(beam.axis[1]) < UPRIGHT ? beam.length / BEAM_PIECES : Infinity;
16713
+ const kept = [];
16714
+ for (const [i, s] of met.entries()) {
16715
+ const from = met[i - 1];
16716
+ if (from !== void 0 && s - from > longest * 1.01) {
16717
+ const cuts = Math.ceil((s - from) / longest);
16718
+ for (let c = 1; c < cuts; c++) kept.push(from + (s - from) * c / cuts);
16719
+ }
16720
+ kept.push(s);
16721
+ }
16722
+ beam.stations = kept;
16723
+ beam.nodes = kept.map((s) => nodes.push({ at: vec.madd(beam.part.position, beam.axis, s) }) - 1);
16724
+ }
16725
+ if (nodes.length * 6 > MAX_DOF) return null;
16726
+ const lo = [Infinity, Infinity, Infinity];
16727
+ const hi = [-Infinity, -Infinity, -Infinity];
16728
+ for (const node of nodes) for (let k = 0; k < 3; k++) {
16729
+ lo[k] = Math.min(lo[k], node.at[k]);
16730
+ hi[k] = Math.max(hi[k], node.at[k]);
16731
+ }
16732
+ let main = 0;
16733
+ if (hi[1] - lo[1] > hi[main] - lo[main]) main = 1;
16734
+ if (hi[2] - lo[2] > hi[main] - lo[main]) main = 2;
16735
+ const ranked = nodes.map((_, i) => i).sort((p, q) => nodes[p].at[main] - nodes[q].at[main] || p - q);
16736
+ const order2 = new Int32Array(nodes.length);
16737
+ ranked.forEach((node, rank) => {
16738
+ order2[node] = rank;
16739
+ });
16740
+ const dofsOf = (node) => [0, 1, 2, 3, 4, 5].map((i) => order2[node] * 6 + i);
16741
+ const nearest = (beam, p) => {
16742
+ const t = along2(beam, p);
16743
+ let best = 0;
16744
+ for (let i = 1; i < beam.stations.length; i++) if (Math.abs(beam.stations[i] - t) < Math.abs(beam.stations[best] - t)) best = i;
16745
+ return beam.nodes[best];
16746
+ };
16747
+ const elements = [];
16748
+ for (const beam of beams.values()) {
16749
+ const section = sectionOf(beam);
16750
+ if (!section) {
16751
+ const id = beam.part.id;
16752
+ if (footPoints.has(id) || joints.some((j) => structural(j) && (j.a === id || j.b === id))) return null;
16753
+ continue;
16754
+ }
16755
+ for (let i = 0; i + 1 < beam.nodes.length; i++) {
16756
+ const length = beam.stations[i + 1] - beam.stations[i];
16757
+ const k = toObjectFrame(beamLocal(section, length), 12, beam.axis, beam.u, beam.v);
16758
+ elements.push({ dofs: [...dofsOf(beam.nodes[i]), ...dofsOf(beam.nodes[i + 1])], k, parts: [beam.part.id] });
16759
+ }
16760
+ }
16761
+ for (const [joint, stations] of stationed) {
16762
+ const a = beams.get(joint.a);
16763
+ const b = beams.get(joint.b);
16764
+ for (const s of stations) {
16765
+ const na = nearest(a, s.at);
16766
+ const nb = nearest(b, s.at);
16767
+ const ra = armRows(vec.sub(s.at, nodes[na].at));
16768
+ const rb = armRows(vec.sub(s.at, nodes[nb].at));
16769
+ const rows = [];
16770
+ for (let i = 0; i < 3; i++) rows.push([...ra[i].map((x) => -x), ...rb[i]]);
16771
+ for (let i = 0; i < 3; i++) {
16772
+ const row = new Array(12).fill(0);
16773
+ row[3 + i] = -1;
16774
+ row[9 + i] = 1;
16775
+ rows.push(row);
16776
+ }
16777
+ const k = new Float64Array(144);
16778
+ for (let axis = 0; axis < 3; axis++) {
16779
+ const e = s.frame[axis];
16780
+ for (const [stiffness, base2] of [[s.push[axis], 0], [s.turn[axis], 3]]) {
16781
+ if (stiffness === 0) continue;
16782
+ const b12 = new Array(12).fill(0);
16783
+ for (let i = 0; i < 3; i++) for (let m = 0; m < 12; m++) b12[m] = b12[m] + e[i] * rows[base2 + i][m];
16784
+ for (let p = 0; p < 12; p++) for (let q = 0; q < 12; q++) k[p * 12 + q] = k[p * 12 + q] + stiffness * b12[p] * b12[q];
16785
+ }
16786
+ }
16787
+ elements.push({ dofs: [...dofsOf(na), ...dofsOf(nb)], k, parts: [joint.a, joint.b] });
16788
+ }
16789
+ }
16790
+ const supports = [];
16791
+ for (const [id, corners] of footPoints) {
16792
+ const beam = beams.get(id);
16793
+ for (const at2 of corners) {
16794
+ const node = nearest(beam, at2);
16795
+ supports.push({ part: id, node, arm: vec.sub(at2, nodes[node].at), at: at2 });
16796
+ }
16797
+ }
16798
+ const frame2 = { nodes, beams, elements, supports, order: order2 };
16799
+ const before = lost.size > 0 ? solveFrame(frame2, input, joints, structural, /* @__PURE__ */ new Set(), g, null) : null;
16800
+ const after = solveFrame(frame2, input, joints, structural, lost, g, before);
16801
+ if (!after) return null;
16802
+ let mass = 0;
16803
+ const centre = [0, 0, 0];
16804
+ const shift = [0, 0, 0];
16805
+ let all = 0;
16806
+ const allCentre = [0, 0, 0];
16807
+ const moved = (s, point) => {
16808
+ const base2 = order2[point.node] * 6;
16809
+ const theta = [s.u[base2 + 3], s.u[base2 + 4], s.u[base2 + 5]];
16810
+ return vec.add([s.u[base2], s.u[base2 + 1], s.u[base2 + 2]], vec.cross(theta, point.arm));
16811
+ };
16812
+ for (const p of after.masses) {
16813
+ const at2 = vec.add(nodes[p.node].at, p.arm);
16814
+ const by = moved(after, p);
16815
+ all += p.mass;
16816
+ for (let k = 0; k < 3; k++) allCentre[k] = allCentre[k] + (at2[k] + by[k]) * p.mass;
16817
+ if (p.part === null) continue;
16818
+ mass += p.mass;
16819
+ for (let k = 0; k < 3; k++) {
16820
+ centre[k] = centre[k] + at2[k] * p.mass;
16821
+ shift[k] = shift[k] + by[k] * p.mass;
16822
+ }
16823
+ }
16824
+ if (mass <= 0) return null;
16825
+ for (let k = 0; k < 3; k++) {
16826
+ centre[k] = centre[k] / mass;
16827
+ shift[k] = shift[k] / mass;
16828
+ allCentre[k] = allCentre[k] / all;
16829
+ }
16830
+ const feet = after.holding.map((s) => s.at);
16831
+ let released = 0;
16832
+ let spin = null;
16833
+ if (before) {
16834
+ const n = nodes.length * 6;
16835
+ const delta = new Float64Array(n);
16836
+ for (let i = 0; i < n; i++) delta[i] = after.u[i] - before.u[i];
16837
+ for (const beam of beams.values()) if (!after.standing.has(beam.part.id)) for (const node of beam.nodes) for (const dof of dofsOf(node)) delta[dof] = 0;
16838
+ for (let i = 0; i < n; i++) {
16839
+ if (delta[i] === 0) continue;
16840
+ let row = 0;
16841
+ for (let j = 0; j < n; j++) row += after.k[i * n + j] * delta[j];
16842
+ released += 0.5 * delta[i] * row;
16843
+ }
16844
+ spin = spinOf({ frame: frame2, after, delta, released, centre: allCentre, mass: all, floor, g });
16845
+ }
16846
+ return {
16847
+ mass,
16848
+ centre,
16849
+ shift,
16850
+ released,
16851
+ spin,
16852
+ feet,
16853
+ deflection(id, point) {
16854
+ const beam = beams.get(id);
16855
+ if (!beam || !after.standing.has(id)) return null;
16856
+ const node = nearest(beam, point);
16857
+ return moved(after, { part: id, node, arm: vec.sub(point, nodes[node].at), mass: 0 });
16858
+ }
16859
+ };
16860
+ }
16861
+ function standingParts(frame2, joints, structural, gone) {
16862
+ const standing = /* @__PURE__ */ new Set();
16863
+ const queue = [];
16864
+ for (const s of frame2.supports) {
16865
+ if (gone.has(s.part) || standing.has(s.part)) continue;
16866
+ standing.add(s.part);
16867
+ queue.push(s.part);
16868
+ }
16869
+ while (queue.length > 0) {
16870
+ const id = queue.pop();
16871
+ for (const j of joints) {
16872
+ if (!structural(j) || j.a !== id && j.b !== id) continue;
16873
+ const other = j.a === id ? j.b : j.a;
16874
+ if (gone.has(other) || standing.has(other)) continue;
16875
+ standing.add(other);
16876
+ queue.push(other);
16877
+ }
16878
+ }
16879
+ return standing;
16880
+ }
16881
+ function solveFrame(frame2, input, joints, structural, gone, g, from) {
16882
+ const { nodes, beams, order: order2 } = frame2;
16883
+ const n = nodes.length * 6;
16884
+ const standing = standingParts(frame2, joints, structural, gone);
16885
+ if (standing.size === 0) return null;
16886
+ const nearestNode = (p, among) => {
16887
+ let best = -1;
16888
+ let bestDistance = Infinity;
16889
+ for (const id of among) {
16890
+ const beam = beams.get(id);
16891
+ for (const node of beam.nodes) {
16892
+ const d = vec.distance(nodes[node].at, p);
16893
+ if (d < bestDistance) {
16894
+ bestDistance = d;
16895
+ best = node;
16896
+ }
16897
+ }
16898
+ }
16899
+ return best;
16900
+ };
16901
+ const masses = [];
16902
+ for (const id of standing) {
16903
+ const beam = beams.get(id);
16904
+ const perMetre = beam.part.mass / beam.length;
16905
+ for (let i = 0; i < beam.nodes.length; i++) {
16906
+ const before = i > 0 ? beam.stations[i] - beam.stations[i - 1] : 0;
16907
+ const next = i + 1 < beam.nodes.length ? beam.stations[i + 1] - beam.stations[i] : 0;
16908
+ masses.push({ part: id, node: beam.nodes[i], arm: [0, 0, 0], mass: perMetre * (before + next) / 2 });
16909
+ }
16910
+ }
16911
+ const carried = /* @__PURE__ */ new Map();
16912
+ let grew = true;
16913
+ while (grew) {
16914
+ grew = false;
16915
+ for (const j of joints) {
16916
+ for (const [id, host] of [[j.a, j.b], [j.b, j.a]]) {
16917
+ if (gone.has(id) || gone.has(host) || standing.has(id) || carried.has(id)) continue;
16918
+ if (!standing.has(host) && !carried.has(host)) continue;
16919
+ carried.set(id, standing.has(host) ? host : carried.get(host));
16920
+ grew = true;
16921
+ }
16922
+ }
16923
+ }
16924
+ for (const [id, host] of carried) {
16925
+ const part = beams.get(id).part;
16926
+ const node = nearestNode(part.position, [host]);
16927
+ masses.push({ part: id, node, arm: vec.sub(part.position, nodes[node].at), mass: part.mass });
16928
+ }
16929
+ for (const load of input.loads ?? []) {
16930
+ if (load.mass <= 0) continue;
16931
+ const node = nearestNode(load.position, standing);
16932
+ masses.push({ part: null, node, arm: vec.sub(load.position, nodes[node].at), mass: load.mass });
16933
+ }
16934
+ const f = new Float64Array(n);
16935
+ for (const p of masses) {
16936
+ const base2 = order2[p.node] * 6;
16937
+ const weight = -p.mass * g;
16938
+ f[base2 + 1] = f[base2 + 1] + weight;
16939
+ f[base2 + 3] = f[base2 + 3] - p.arm[2] * weight;
16940
+ f[base2 + 5] = f[base2 + 5] + p.arm[0] * weight;
16941
+ }
16942
+ const structure = new Float64Array(n * n);
16943
+ let largest = 0;
16944
+ for (const element of frame2.elements) {
16945
+ if (!element.parts.every((id) => standing.has(id))) continue;
16946
+ const size = element.dofs.length;
16947
+ for (let p = 0; p < size; p++) {
16948
+ for (let q = 0; q < size; q++) structure[element.dofs[p] * n + element.dofs[q]] = structure[element.dofs[p] * n + element.dofs[q]] + element.k[p * size + q];
16949
+ }
16950
+ }
16951
+ for (let i = 0; i < n; i++) largest = Math.max(largest, structure[i * n + i]);
16952
+ if (largest <= 0) return null;
16953
+ const free = new Uint8Array(n);
16954
+ for (const id of standing) for (const node of beams.get(id).nodes) for (let i = 0; i < 6; i++) free[order2[node] * 6 + i] = 1;
16955
+ for (let i = 0; i < n; i++) {
16956
+ if (!free[i]) {
16957
+ structure[i * n + i] = largest;
16958
+ f[i] = 0;
16959
+ } else structure[i * n + i] = structure[i * n + i] + largest * SOFT;
16960
+ }
16961
+ const feet = frame2.supports.filter((s) => standing.has(s.part));
16962
+ const holds2 = feet.map((s) => !from || from.holding.includes(s));
16963
+ const footed = [...new Set(feet.map((s) => s.part))];
16964
+ const grips = new Map(footed.map((id) => [id, true]));
16965
+ const friction = input.friction ?? FOOT_FRICTION;
16966
+ const k = new Float64Array(n * n);
16967
+ const u = new Float64Array(n);
16968
+ const build = () => {
16969
+ k.set(structure);
16970
+ const held = /* @__PURE__ */ new Map();
16971
+ feet.forEach((s, index) => {
16972
+ if (!holds2[index]) return;
16973
+ const row = armRows(s.arm)[1];
16974
+ const base2 = order2[s.node] * 6;
16975
+ for (let p = 0; p < 6; p++) for (let q = 0; q < 6; q++) k[(base2 + p) * n + base2 + q] = k[(base2 + p) * n + base2 + q] + RIGID_PUSH * row[p] * row[q];
16976
+ held.set(s.part, [...held.get(s.part) ?? [], s]);
16977
+ });
16978
+ for (const [id, points] of held) {
16979
+ const { node, arm } = gripOf(points);
16980
+ const upright = order2[node] * 6 + 4;
16981
+ k[upright * n + upright] = k[upright * n + upright] + RIGID_TURN;
16982
+ if (!grips.get(id)) continue;
16983
+ const rows = armRows(arm);
16984
+ const base2 = order2[node] * 6;
16985
+ for (const row of [rows[0], rows[2]]) for (let p = 0; p < 6; p++) for (let q = 0; q < 6; q++) k[(base2 + p) * n + base2 + q] = k[(base2 + p) * n + base2 + q] + RIGID_PUSH * row[p] * row[q];
16986
+ }
16987
+ };
16988
+ const liftOf = (s) => {
16989
+ const base2 = order2[s.node] * 6;
16990
+ return u[base2 + 1] + (u[base2 + 5] * s.arm[0] - u[base2 + 3] * s.arm[2]);
16991
+ };
16992
+ const rounds = 4 * feet.length + 2 * footed.length + 4;
16993
+ for (let round3 = 0; round3 < rounds; round3++) {
16994
+ build();
16995
+ u.set(f);
16996
+ if (!solve(k, u, n)) return null;
16997
+ const pull = 1e-12;
16998
+ const sink = -1e-9;
16999
+ if (round3 === 0) {
17000
+ let any = false;
17001
+ feet.forEach((s, index) => {
17002
+ if (!holds2[index] || liftOf(s) <= pull) return;
17003
+ holds2[index] = false;
17004
+ any = true;
17005
+ });
17006
+ if (any) continue;
17007
+ }
17008
+ const worstOf = /* @__PURE__ */ new Map();
17009
+ feet.forEach((s, index) => {
17010
+ const lift = liftOf(s);
17011
+ const pulls = holds2[index] && lift > pull;
17012
+ if (!pulls && !(!holds2[index] && lift < sink)) return;
17013
+ const key2 = round3 < rounds / 2 ? s.part : "";
17014
+ const by = Math.abs(lift);
17015
+ const now = worstOf.get(key2);
17016
+ if (!now || pulls && !now.pulls || pulls === now.pulls && by > now.by) worstOf.set(key2, { index, by, pulls });
17017
+ });
17018
+ if (worstOf.size > 0) {
17019
+ for (const change of worstOf.values()) holds2[change.index] = !change.pulls;
17020
+ continue;
17021
+ }
17022
+ let slides = null;
17023
+ let over = 1;
17024
+ let gripping = 0;
17025
+ for (const id of footed) {
17026
+ const points = feet.filter((s, index) => s.part === id && holds2[index]);
17027
+ if (points.length === 0 || !grips.get(id)) continue;
17028
+ gripping++;
17029
+ let weight = 0;
17030
+ for (const s of points) weight += -RIGID_PUSH * liftOf(s);
17031
+ const { node, arm } = gripOf(points);
17032
+ const base2 = order2[node] * 6;
17033
+ const x = u[base2] + (u[base2 + 4] * arm[2] - u[base2 + 5] * arm[1]);
17034
+ const z = u[base2 + 2] + (u[base2 + 3] * arm[1] - u[base2 + 4] * arm[0]);
17035
+ const ratio = RIGID_PUSH * Math.hypot(x, z) / Math.max(friction * weight, 1e-9);
17036
+ if (ratio > over) {
17037
+ over = ratio;
17038
+ slides = id;
17039
+ }
17040
+ }
17041
+ if (slides !== null && gripping > 1) {
17042
+ grips.set(slides, false);
17043
+ continue;
17044
+ }
17045
+ let worst = 0;
17046
+ for (let i = 0; i < n; i++) if (free[i]) worst = Math.max(worst, Math.abs(u[i]));
17047
+ if (worst > MECHANISM) return null;
17048
+ const holding = feet.filter((_, index) => holds2[index]);
17049
+ if (holding.length < 3) return null;
17050
+ build();
17051
+ return { u: u.slice(), k: k.slice(), holding, masses, standing };
17052
+ }
17053
+ return null;
17054
+ }
17055
+ function gripOf(points) {
17056
+ const first = points[0];
17057
+ let arm = [0, 0, 0];
17058
+ for (const s of points) arm = vec.add(arm, vec.sub(s.at, vec.sub(first.at, first.arm)));
17059
+ return { node: first.node, arm: vec.scale(arm, 1 / points.length) };
17060
+ }
17061
+ function spinOf(input) {
17062
+ const { frame: frame2, after, delta, released, centre, mass, floor, g } = input;
17063
+ if (!(released > 0)) return null;
17064
+ const { nodes, order: order2 } = frame2;
17065
+ const points = after.masses.map((p) => {
17066
+ const base2 = order2[p.node] * 6;
17067
+ const theta = [delta[base2 + 3], delta[base2 + 4], delta[base2 + 5]];
17068
+ return { at: vec.add(nodes[p.node].at, p.arm), by: vec.add([delta[base2], delta[base2 + 1], delta[base2 + 2]], vec.cross(theta, p.arm)), mass: p.mass };
17069
+ });
17070
+ let moving = 0;
17071
+ for (const p of points) moving += p.mass * vec.dot(p.by, p.by);
17072
+ if (!(moving > 0)) return null;
17073
+ const scale = Math.sqrt(2 * released / moving);
17074
+ const hull = hullOf(after.holding.map((s) => [s.at[0], s.at[2]]));
17075
+ if (hull.length < 3) return null;
17076
+ let best = null;
17077
+ for (let i = 0; i < hull.length; i++) {
17078
+ const p = hull[i];
17079
+ const q = hull[(i + 1) % hull.length];
17080
+ const length = Math.hypot(q[0] - p[0], q[1] - p[1]);
17081
+ if (length < 1e-9) continue;
17082
+ const point = [p[0], floor, p[1]];
17083
+ let axis = [(q[0] - p[0]) / length, 0, (q[1] - p[1]) / length];
17084
+ const inward = [centre[0] - point[0], 0, centre[2] - point[2]];
17085
+ let out = vec.cross(axis, [0, 1, 0]);
17086
+ if (vec.dot(out, inward) > 0) {
17087
+ axis = vec.scale(axis, -1);
17088
+ out = vec.scale(out, -1);
17089
+ }
17090
+ const depth = -vec.dot(out, inward);
17091
+ let momentum = 0;
17092
+ let inertia = 0;
17093
+ for (const m of points) {
17094
+ const r = vec.sub(m.at, point);
17095
+ const off = vec.sub(r, vec.scale(axis, vec.dot(r, axis)));
17096
+ momentum += m.mass * vec.dot(vec.cross(r, vec.scale(m.by, scale)), axis);
17097
+ inertia += m.mass * vec.dot(off, off);
17098
+ }
17099
+ if (!(inertia > 0)) continue;
17100
+ const rate = momentum / inertia;
17101
+ if (!(rate > 0)) continue;
17102
+ const height = centre[1] - floor;
17103
+ const barrier = depth > 0 ? mass * g * (Math.hypot(height, depth) - height) : 0;
17104
+ const energy = 0.5 * inertia * rate * rate;
17105
+ const margin = energy - barrier;
17106
+ if (!best || margin > best.margin) best = { point, axis, rate, margin, energy, barrier };
17107
+ }
17108
+ return best ? { point: best.point, axis: best.axis, rate: best.rate, energy: best.energy, barrier: best.barrier } : null;
17109
+ }
16255
17110
  var SWEEP_BROAD_SLACK = 1e-3;
16256
17111
  var sweptBounds = (origins, direction, length) => {
16257
17112
  if (origins.length === 0 || !Number.isFinite(length)) return null;
@@ -16348,6 +17203,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
16348
17203
  return { ...base2, mesh: { vertices, indices: piece3.mesh.indices } };
16349
17204
  };
16350
17205
  var THIN_SHEET_DISHING = 5e-3;
17206
+ var TEAR_CALIBERS = 1.1;
16351
17207
  var SHELL_YIELD_SHARE = 0.5;
16352
17208
  var STEEL_YIELD_MPA = 250;
16353
17209
  var SWEEP_BACK = 0.01;
@@ -16440,7 +17296,16 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
16440
17296
  var MAX_PLASTER_FLAKES = 24;
16441
17297
  var CHIP_ENERGY = 200;
16442
17298
  var CHIP_SPLASH = 0.5;
17299
+ var SHARD_CUT = [0.3, 0.7];
17300
+ var MORTAR_JOINT = 0.01;
17301
+ var MIN_UNIT_SHARE = 0.8;
17302
+ var CHIP_DRIVE = 0.6;
17303
+ var BLAST_DRIVE = 2.5;
16443
17304
  var CRATER_SPENT = 0.6;
17305
+ var BONDING_JOINTS = /* @__PURE__ */ new Set(["glue", "mortar", "nail", "screw"]);
17306
+ var PLATE_ASPECT = 0.25;
17307
+ var PLATE_BACK_SHARE = 0.5;
17308
+ var BONDED_REMNANT = 0.25;
16444
17309
  var EDGE_REACH = 1.5;
16445
17310
  var BAR_BOW = 0.08;
16446
17311
  var BULLET_JOINT_SPAN = 0.3;
@@ -16471,9 +17336,31 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
16471
17336
  };
16472
17337
  var BURIED_BLAST_REACH = 0.5;
16473
17338
  var GIVE_AT_CUT_HP = 0.5;
17339
+ var lineToSegment = (o, d, a, b) => {
17340
+ const ab = vec.sub(b, a);
17341
+ const ao = vec.sub(a, o);
17342
+ const abab = vec.dot(ab, ab);
17343
+ const abd = vec.dot(ab, d);
17344
+ const denom = abab - abd * abd;
17345
+ if (abab < 1e-12) return null;
17346
+ if (denom < 1e-12) {
17347
+ const end = vec.dot(ao, d) <= vec.dot(vec.sub(b, o), d) ? a : b;
17348
+ return { point: end, distance: vec.distance(end, vec.madd(o, d, vec.dot(vec.sub(end, o), d))) };
17349
+ }
17350
+ const s = clamp2((abd * vec.dot(ao, d) - vec.dot(ao, ab)) / denom, 0, 1);
17351
+ const point = vec.madd(a, ab, s);
17352
+ const t = vec.dot(vec.sub(point, o), d);
17353
+ return { point, distance: vec.distance(point, vec.madd(o, d, t)) };
17354
+ };
17355
+ var cageLeft = (p) => {
17356
+ const r = p.spec.reinforcement;
17357
+ if (!r) return 1;
17358
+ const total = rebarBars(p.dims, p.thin, r.spacing, p.spec.structure?.role).length;
17359
+ return total > 0 ? Math.max(0, total - (p.rt.severedBars?.length ?? 0)) / total : 1;
17360
+ };
16474
17361
  var capacityScale = (p, borne, through) => {
16475
17362
  const residual = p.spec.reinforcement?.residualCapacity ?? RESIDUAL_CAPACITY;
16476
- if (p.st.stripped) return residual;
17363
+ if (p.st.stripped) return residual * cageLeft(p);
16477
17364
  const kept = Math.min(p.rt.removed ? 1 - p.rt.removed / p.mass0 : 1, sectionKept(p, residual, borne, through));
16478
17365
  return Math.max(p.spec.reinforcement ? residual : 0.05, kept);
16479
17366
  };
@@ -16548,6 +17435,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
16548
17435
  };
16549
17436
  var HOSTED_TOLERANCE = 0.02;
16550
17437
  var HOLE_SLACK = 0.05;
17438
+ var GRAIN_AXIS = { x: 0, y: 1, z: 2 };
16551
17439
  var isLost = (p) => p.st.status === "broken" || p.st.status === "melted" || p.st.status === "ashes";
16552
17440
  var clone = (v) => structuredClone(v);
16553
17441
  var overloadRate = (stress) => Math.min(0.6, 0.12 + 0.8 * (stress - 1));
@@ -17122,7 +18010,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
17122
18010
  byKey.set(key2, span);
17123
18011
  return span;
17124
18012
  };
17125
- const sectionOf2 = (p, axis) => {
18013
+ const sectionOf22 = (p, axis) => {
17126
18014
  const g = p.bend;
17127
18015
  const section = { b: sectionWidth(g, axis), h: g.dims[axis] };
17128
18016
  const rebar2 = tensionSteel(p.spec, g.dims, section, flexure);
@@ -17137,7 +18025,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
17137
18025
  }
17138
18026
  p.restMoment = 0;
17139
18027
  if (g.gravity < 0 || p.span <= 0) return 0;
17140
- const sec = sectionOf2(p, g.gravity);
18028
+ const sec = sectionOf22(p, g.gravity);
17141
18029
  p.restMoment = spanMoment(lineLoad(g, p.bendLoad) * Math.abs(g.up[g.gravity]), p.span);
17142
18030
  const holds2 = (p.st.cracked ? sec.steel : sec.ultimate) * capacityScale(p);
17143
18031
  return p.restMoment * structureSafety / Math.max(holds2, 1);
@@ -17172,7 +18060,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
17172
18060
  const impulse = sum / offsets.length * cos * reach2 * width * L;
17173
18061
  const weight = axis === g.gravity ? p.bendLoad : p.st.mass;
17174
18062
  const kinetic = impulseEnergy(impulse, lineLoad(g, weight) / GRAVITY * L, flexure);
17175
- const sec = sectionOf2(p, axis);
18063
+ const sec = sectionOf22(p, axis);
17176
18064
  const EI = s.elasticGPa * 1e9 * sec.section.b * sec.section.h ** 3 / 12;
17177
18065
  const along2 = axis === g.gravity ? -Math.sign(away[axis] * g.up[axis]) : 0;
17178
18066
  const dynamic = momentOfEnergy(kinetic, L, EI, flexure.loadFactor);
@@ -17316,7 +18204,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
17316
18204
  p.bendLoad = p.st.mass + bending[i];
17317
18205
  const bent = restFlexure(o, p, lowerOf(i));
17318
18206
  p.st.flexure = bent;
17319
- p.snap = bent > 1 && !p.st.stripped && !sectionOf2(p, p.bend.gravity).reinforced;
18207
+ p.snap = bent > 1 && !p.st.stripped && !sectionOf22(p, p.bend.gravity).reinforced;
17320
18208
  if (p.spec.structure?.capacity === void 0 || bent > p.st.stress) p.st.stress = bent;
17321
18209
  }
17322
18210
  if (p.st.stress > o.maxStress) o.maxStress = p.st.stress;
@@ -18347,11 +19235,56 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
18347
19235
  return r ? { t0: r.t0, t1: r.t1, n: rotateVec(q, r.n0) } : null;
18348
19236
  };
18349
19237
  const rayPart = (o, p, origin, d) => rayPartRaw(o.st.position, o.st.rotation, p.spec, p.q, origin, d, p.pos);
19238
+ const rayCentre = [0, 0, 0];
19239
+ const rayTurn = [0, 0, 0, 1];
19240
+ const rayTurnBack = [0, 0, 0, 1];
19241
+ const rayOrigin = [0, 0, 0];
19242
+ const rayDirection = [0, 0, 0];
19243
+ const rayShapeHit = { t0: 0, t1: 0, n0: [0, 0, 0] };
19244
+ const rayHitNormal = [0, 0, 0];
19245
+ const rayHit = { t0: 0, t1: 0, n: rayHitNormal };
19246
+ const rayPartInto = (pos, rot, spec, pq, origin, d, lp) => {
19247
+ rotateVecInto(rot, lp, rayCentre);
19248
+ rayCentre[0] += pos[0];
19249
+ rayCentre[1] += pos[1];
19250
+ rayCentre[2] += pos[2];
19251
+ rayTurn[0] = rot[3] * pq[0] + rot[0] * pq[3] + rot[1] * pq[2] - rot[2] * pq[1];
19252
+ rayTurn[1] = rot[3] * pq[1] - rot[0] * pq[2] + rot[1] * pq[3] + rot[2] * pq[0];
19253
+ rayTurn[2] = rot[3] * pq[2] + rot[0] * pq[1] - rot[1] * pq[0] + rot[2] * pq[3];
19254
+ rayTurn[3] = rot[3] * pq[3] - rot[0] * pq[0] - rot[1] * pq[1] - rot[2] * pq[2];
19255
+ rayTurnBack[0] = -rayTurn[0];
19256
+ rayTurnBack[1] = -rayTurn[1];
19257
+ rayTurnBack[2] = -rayTurn[2];
19258
+ rayTurnBack[3] = rayTurn[3];
19259
+ rayOrigin[0] = origin[0] - rayCentre[0];
19260
+ rayOrigin[1] = origin[1] - rayCentre[1];
19261
+ rayOrigin[2] = origin[2] - rayCentre[2];
19262
+ rotateVecInto(rayTurnBack, rayOrigin, rayOrigin);
19263
+ rotateVecInto(rayTurnBack, d, rayDirection);
19264
+ if (!rayShapeInto(spec.shape, rayOrigin, rayDirection, rayShapeHit)) return null;
19265
+ rayHit.t0 = rayShapeHit.t0;
19266
+ rayHit.t1 = rayShapeHit.t1;
19267
+ rayHit.n = rotateVecInto(rayTurn, rayShapeHit.n0, rayHitNormal);
19268
+ return rayHit;
19269
+ };
19270
+ const specTurns = /* @__PURE__ */ new WeakMap();
19271
+ const specTurnOf = (ps) => {
19272
+ let turn = specTurns.get(ps);
19273
+ if (!turn) {
19274
+ turn = quatFromEuler(...ps.rotation ?? [0, 0, 0]);
19275
+ specTurns.set(ps, turn);
19276
+ }
19277
+ return turn;
19278
+ };
19279
+ const copyOf = (v) => [v[0], v[1], v[2]];
19280
+ const objectTurnBack = [0, 0, 0, 1];
19281
+ const objectOrigin = [0, 0, 0];
19282
+ const objectDirection = [0, 0, 0];
18350
19283
  const PART_BOUND_SLACK = 1e-6;
18351
19284
  const raySphereMiss = (origin, d, c, r, maxDist) => {
18352
- const oc = vec.sub(origin, c);
18353
- const b = vec.dot(oc, d);
18354
- const cc = vec.dot(oc, oc) - r * r;
19285
+ const ox = origin[0] - c[0], oy = origin[1] - c[1], oz = origin[2] - c[2];
19286
+ const b = ox * d[0] + oy * d[1] + oz * d[2];
19287
+ const cc = ox * ox + oy * oy + oz * oz - r * r;
18355
19288
  if (cc > 0 && b > 0) return true;
18356
19289
  const disc = b * b - cc;
18357
19290
  if (disc < 0) return true;
@@ -18544,9 +19477,16 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
18544
19477
  if (skip.skipLoose && o.loose || o.br < minRadius) continue;
18545
19478
  if (outside && !outside.mayMeet(o.id)) continue;
18546
19479
  if (raySphereMiss(origin, d, worldCentreOf(o), o.br, best ? Math.min(maxDist, best.distance) : maxDist)) continue;
18547
- const qi = quat.conjugate(o.st.rotation);
18548
- const lo = rotateVec(qi, vec.sub(origin, o.st.position));
18549
- const ld = rotateVec(qi, d);
19480
+ const turn = o.st.rotation;
19481
+ objectTurnBack[0] = -turn[0];
19482
+ objectTurnBack[1] = -turn[1];
19483
+ objectTurnBack[2] = -turn[2];
19484
+ objectTurnBack[3] = turn[3];
19485
+ objectOrigin[0] = origin[0] - o.st.position[0];
19486
+ objectOrigin[1] = origin[1] - o.st.position[1];
19487
+ objectOrigin[2] = origin[2] - o.st.position[2];
19488
+ const lo = rotateVecInto(objectTurnBack, objectOrigin, objectOrigin);
19489
+ const ld = rotateVecInto(objectTurnBack, d, objectDirection);
18550
19490
  for (const p of scope?.parts.get(o) ?? (counts ? o.parts : partsAlong(o, lo, ld, maxDist))) {
18551
19491
  if (counts) counts.partVisits++;
18552
19492
  if (isLost(p) || ignore?.has(`${o.id}\0${p.spec.id}`)) continue;
@@ -18555,15 +19495,27 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
18555
19495
  counts.shapeTests++;
18556
19496
  counts.shapeTested.add(o.id);
18557
19497
  }
18558
- const r = rayPart(o, p, origin, d);
19498
+ const r = rayPartInto(o.st.position, o.st.rotation, p.spec, p.q, origin, d, p.pos);
19499
+ if (r && r.t0 < 0 && r.t1 > 0 && p.st.chipped?.length && inGap(p, toLocal(p.pos, p.q, objLocal(o, origin)))) {
19500
+ r.t0 = 0;
19501
+ r.n = vec.scale(d, -1);
19502
+ }
18559
19503
  if (!r || r.t0 < 0 || r.t0 > maxDist) continue;
18560
19504
  if (p.st.opening && insideOpening(o, p, objLocal(o, vec.madd(origin, d, r.t0)))) continue;
18561
19505
  if (p.spec.apertures && throughAperture(p, objLocal(o, vec.madd(origin, d, r.t0)))) continue;
18562
- if (p.st.chipped && insideChip(p, objLocal(o, vec.madd(origin, d, Math.min(r.t0 + CHIP_PROBE_DEPTH, (r.t0 + r.t1) / 2))))) {
18563
- passed?.push({ o, p, t: r.t0 });
18564
- continue;
19506
+ const cutBand = !!p.st.chipped && insideChip(p, objLocal(o, vec.madd(origin, d, Math.min(r.t0 + CHIP_PROBE_DEPTH, (r.t0 + r.t1) / 2))));
19507
+ if (cutBand) {
19508
+ if (passed) {
19509
+ passed.push({ o, p, t: r.t0 });
19510
+ continue;
19511
+ }
19512
+ const bar2 = skip.body ? barAlong(o, p, origin, d, r.t0, r.t1) : null;
19513
+ if (bar2 === null) continue;
19514
+ r.t0 = bar2;
19515
+ r.n = vec.scale(d, -1);
18565
19516
  }
18566
- const gap = p.st.chipped?.length ? pastChips(o, p, origin, d, r.t0, r.t1) : null;
19517
+ const entry2 = p.st.chipped?.length && !cutBand ? toLocal(p.pos, p.q, objLocal(o, vec.madd(origin, d, Math.min(r.t0 + CHIP_PROBE_DEPTH, (r.t0 + r.t1) / 2)))) : null;
19518
+ const gap = entry2 ? skip.body && coreStands(p, entry2) ? coreBehind(o, p, origin, d, r.t0, r.t1) : pastChips(o, p, origin, d, r.t0, r.t1) : null;
18567
19519
  if (gap === "through") continue;
18568
19520
  if (gap) {
18569
19521
  r.t0 = gap.t;
@@ -18578,8 +19530,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
18578
19530
  }
18579
19531
  if (!best || r.t0 < best.distance) {
18580
19532
  const point = vec.madd(origin, d, r.t0);
18581
- const member = p.castIn ? castMemberAt(o, { p, point, normal: r.n, dir: d, pathLen: r.t1 - r.t0 }, origin, d) : null;
18582
- best = member ? { object: o.id, part: member.p.spec.id, point: member.point, normal: member.normal, distance: r.t0, pathLen: member.pathLen } : { object: o.id, part: p.spec.id, point, normal: r.n, distance: r.t0, pathLen: r.t1 - r.t0 };
19533
+ const normal = copyOf(r.n);
19534
+ const member = p.castIn ? castMemberAt(o, { p, point, normal, dir: d, pathLen: r.t1 - r.t0 }, origin, d) : null;
19535
+ best = member ? { object: o.id, part: member.p.spec.id, point: member.point, normal: member.normal, distance: r.t0, pathLen: member.pathLen } : { object: o.id, part: p.spec.id, point, normal, distance: r.t0, pathLen: r.t1 - r.t0 };
18583
19536
  }
18584
19537
  }
18585
19538
  }
@@ -18595,13 +19548,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
18595
19548
  counts.shapeTested.add(im.impl.id);
18596
19549
  }
18597
19550
  const ov = im.poses.get(ps.id);
18598
- const r = rayPartRaw(im.position, im.rotation, ps, ov?.q ?? quatFromEuler(...ps.rotation ?? [0, 0, 0]), origin, d, ov?.pos);
19551
+ const r = rayPartInto(im.position, im.rotation, ps, ov?.q ?? specTurnOf(ps), origin, d, ov?.pos ?? ps.position);
18599
19552
  if (!r || r.t1 < 0 || r.t0 > maxDist) continue;
18600
19553
  if (r.t0 < 0) {
18601
- if (precise && im.impl.surfaceRay) boxHit = boxHit ?? { object: im.impl.id, part: ps.id, point: origin, normal: r.n, distance: 0, pathLen: r.t1 };
19554
+ if (precise && im.impl.surfaceRay) boxHit = boxHit ?? { object: im.impl.id, part: ps.id, point: origin, normal: copyOf(r.n), distance: 0, pathLen: r.t1 };
18602
19555
  continue;
18603
19556
  }
18604
- if (!boxHit || r.t0 < boxHit.distance) boxHit = { object: im.impl.id, part: ps.id, point: vec.madd(origin, d, r.t0), normal: r.n, distance: r.t0, pathLen: r.t1 - r.t0 };
19557
+ if (!boxHit || r.t0 < boxHit.distance) boxHit = { object: im.impl.id, part: ps.id, point: vec.madd(origin, d, r.t0), normal: copyOf(r.n), distance: r.t0, pathLen: r.t1 - r.t0 };
18605
19558
  }
18606
19559
  if (!boxHit) continue;
18607
19560
  if (precise && im.impl.surfaceRay) {
@@ -18949,6 +19902,34 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
18949
19902
  };
18950
19903
  const isTrim = (p) => (p.spec.structure?.role ?? "none") === "none";
18951
19904
  const fixesTrim = (o, j) => isTrim(o.parts[j.ia]) !== isTrim(o.parts[j.ib]);
19905
+ const bondedPlate = (o, p) => isPlateTrim(p) && (o.byPart.get(p.spec.id) ?? []).some((j) => !j.st.open && bondsPlate(o, j));
19906
+ const isPlateTrim = (p) => {
19907
+ if (!isTrim(p) || p.spec.units || p.spec.reinforcement || p.mat.ductility >= 0.5 || p.mat.fracture === "none" || p.mat.tags?.includes("glass") === true || p.spec.shape.kind !== "box") return false;
19908
+ const [u, v] = planeAxes(p.thin);
19909
+ return p.dims[p.thin] <= PLATE_ASPECT * Math.min(p.dims[u], p.dims[v]) && gridOf(p).length >= 2;
19910
+ };
19911
+ const bondsPlate = (o, j) => {
19912
+ if (!BONDING_JOINTS.has(j.spec.kind)) return false;
19913
+ const a = o.parts[j.ia], b = o.parts[j.ib];
19914
+ return isPlateTrim(a) && !isTrim(b) && backOn(a, b) || isPlateTrim(b) && !isTrim(a) && backOn(b, a);
19915
+ };
19916
+ const backOn = (plate, carrier) => {
19917
+ const A = aabbOf(plate.spec.shape, plate.spec.position, plate.q);
19918
+ const B = aabbOf(carrier.spec.shape, carrier.spec.position, carrier.q);
19919
+ const face = (k) => (Math.min(A.max[k], B.max[k]) - Math.max(A.min[k], B.min[k])) / Math.max(A.max[k] - A.min[k], 1e-9);
19920
+ const sides = [0, 1, 2].sort((x, y) => A.max[y] - A.min[y] - (A.max[x] - A.min[x])).slice(0, 2);
19921
+ return sides.every((k) => face(k) >= PLATE_BACK_SHARE);
19922
+ };
19923
+ const bondedShareLeft = (p) => {
19924
+ const whole2 = p.st.mass + (p.rt.removed ?? 0);
19925
+ return whole2 > 0 ? p.st.mass / whole2 : 0;
19926
+ };
19927
+ const settleBonded = (o, p, origin, dir, src) => {
19928
+ if (isLost(p)) return;
19929
+ const share = bondedShareLeft(p);
19930
+ p.st.hp = Math.max(1, Math.min(p.st.hp, p.st.maxHp * share));
19931
+ if (share < BONDED_REMNANT) failPart(o, p, origin, dir, 0, 4, src);
19932
+ };
18952
19933
  const holdsEmbedded = (o, j) => {
18953
19934
  const a = o.parts[j.ia], b = o.parts[j.ib];
18954
19935
  return a.embedded === true && a.spec.hostedIn === b.spec.id && a.st.exposed !== true || b.embedded === true && b.spec.hostedIn === a.spec.id && b.st.exposed !== true;
@@ -18966,6 +19947,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
18966
19947
  if (j.st.open) continue;
18967
19948
  if (j.spec.kind === "rebar" && (isReinforced(o.parts[j.ia].spec) || isReinforced(o.parts[j.ib].spec))) continue;
18968
19949
  if (holdsEmbedded(o, j)) continue;
19950
+ if (bondsPlate(o, j)) continue;
18969
19951
  if (near && jointReach(o, j, near) > Math.max(radius, jointReachLimit(o, j))) continue;
18970
19952
  if (blast && fixesTrim(o, j) && jointReach(o, j, blast.point) > Math.max(blast.reach, jointReachLimit(o, j))) continue;
18971
19953
  j.st.hp -= span === void 0 ? amount : Math.min(amount, j.st.maxHp) * Math.min(1, span / Math.max(jointLength(o, j), 1e-6));
@@ -19005,19 +19987,20 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19005
19987
  emit({ ...base2(o, src), type: "spall", part: p.spec.id, layer: torn.layer.index, point: centre, area: Math.PI * r * r, ...spallNormal(o, p, s[1]) });
19006
19988
  debris(o, p, torn.layer.mat.hitDebris, toWorld(o.st.position, o.st.rotation, lp), normal, 5, 2, src, torn.layer.mat.id);
19007
19989
  };
19008
- const spallOuter = (o, p, wp, face, normal, radius, src) => {
19990
+ const spallOuter = (o, p, wp, face, normal, radius, src, tearRadius = radius) => {
19009
19991
  var _a;
19010
19992
  if (p.layers.length === 0) return;
19011
19993
  const lp = objLocal(o, wp);
19012
19994
  const torn = tornPatchAt(p.layers, p.rt.spalls, face, lp, radius);
19013
- if (torn) return widenTear(o, p, torn, lp, normal, radius, src);
19995
+ if (torn) return widenTear(o, p, torn, lp, normal, tearRadius, src);
19014
19996
  const layer = outerLayer(p.layers, p.rt.spalls, face, lp);
19015
19997
  if (!layer) return;
19998
+ const patch = layer.mat.fracture === "tear" ? tearRadius : radius;
19016
19999
  const spalls = (_a = p.rt).spalls ?? (_a.spalls = []);
19017
- spalls.push([layer.index, face, lp[0], lp[1], lp[2], radius]);
20000
+ spalls.push([layer.index, face, lp[0], lp[1], lp[2], patch]);
19018
20001
  if (spalls.length > MAX_SPALLS) spalls.shift();
19019
20002
  markDamaged(p);
19020
- emit({ ...base2(o, src), type: "spall", part: p.spec.id, layer: layer.index, point: wp, area: Math.PI * radius * radius, ...spallNormal(o, p, face) });
20003
+ emit({ ...base2(o, src), type: "spall", part: p.spec.id, layer: layer.index, point: wp, area: Math.PI * patch * patch, ...spallNormal(o, p, face) });
19021
20004
  debris(o, p, layer.mat.hitDebris, wp, normal, 5, 2, src, layer.mat.id);
19022
20005
  setStage(o, p, 1, {}, src);
19023
20006
  };
@@ -19057,7 +20040,22 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19057
20040
  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])];
19058
20041
  };
19059
20042
  const FRAGMENT_SHAPE = { shatter: "shard", splinter: "splinter", tear: "scrap" };
19060
- const cellFragments = (o, p, cells, hitW, dir, speed, mass, tag, inner = false, knownHoles) => {
20043
+ const shardsOfCell = (cell, u, v) => {
20044
+ const own = createRng(seedOf2(cell.center[0], cell.center[1], cell.center[2]));
20045
+ const cu = SHARD_CUT[0] + (SHARD_CUT[1] - SHARD_CUT[0]) * own.next(), cv = SHARD_CUT[0] + (SHARD_CUT[1] - SHARD_CUT[0]) * own.next();
20046
+ const out = [];
20047
+ for (const [a0, a1] of [[0, cu], [cu, 1]]) for (const [b0, b1] of [[0, cv], [cv, 1]]) {
20048
+ const size = [cell.size[0], cell.size[1], cell.size[2]];
20049
+ const center = [cell.center[0], cell.center[1], cell.center[2]];
20050
+ size[u] = cell.size[u] * (a1 - a0);
20051
+ size[v] = cell.size[v] * (b1 - b0);
20052
+ center[u] = cell.center[u] - cell.size[u] / 2 + cell.size[u] * (a0 + a1) / 2;
20053
+ center[v] = cell.center[v] - cell.size[v] / 2 + cell.size[v] * (b0 + b1) / 2;
20054
+ out.push({ ...cell, center, size });
20055
+ }
20056
+ return out;
20057
+ };
20058
+ const cellFragments = (o, p, cells, hitW, dir, speed, mass, tag, inner = false, knownHoles, drive = CHIP_DRIVE) => {
19061
20059
  const { c, q } = partXf(o, p);
19062
20060
  const holes = knownHoles ?? (p.st.holes.length > 0 ? localHolesOf(p) : []);
19063
20061
  const [u, v] = planeAxes(p.thin);
@@ -19065,19 +20063,22 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19065
20063
  const total = cells.reduce((sum, cell) => sum + faceArea(cell), 0) || 1;
19066
20064
  const shape = p.spec.units ? "chunk" : FRAGMENT_SHAPE[p.mat.fracture] ?? "chunk";
19067
20065
  const laid = !!p.spec.units && p.spec.units.mortar !== p.spec.material;
19068
- return cells.map((cell, i) => {
20066
+ const pieces = shape === "shard" && bondedPlate(o, p) ? cells.flatMap((cell) => shardsOfCell(cell, u, v)) : cells;
20067
+ return pieces.map((cell, i) => {
19069
20068
  const cw = toWorld(c, q, cell.center);
19070
20069
  const out = vec.normalize(vec.sub(cw, hitW), [0, 1, 0]);
19071
- const dv = dir ? vec.normalize(vec.madd(out, dir, 0.6)) : out;
20070
+ const dv = dir ? vec.normalize(vec.madd(out, dir, drive)) : out;
19072
20071
  const k = speed * (0.6 + 0.8 * rnd());
19073
20072
  const marks = marksInBox(cell.center, cell.size, void 0, holes);
20073
+ const size = [cell.size[0], cell.size[1], cell.size[2]];
20074
+ if (laid) for (const a of [u, v]) size[a] = Math.max(size[a] * MIN_UNIT_SHARE, size[a] - MORTAR_JOINT);
19074
20075
  return {
19075
20076
  id: `${p.spec.id}#${tag}${i}`,
19076
20077
  part: p.spec.id,
19077
20078
  material: p.spec.material,
19078
20079
  shape,
19079
20080
  center: cw,
19080
- size: [cell.size[0], cell.size[1], cell.size[2]],
20081
+ size,
19081
20082
  rotation: q,
19082
20083
  velocity: [dv[0] * k, dv[1] * k + 0.5 * rnd(), dv[2] * k],
19083
20084
  angularVelocity: bornSpin(cell.size, 8, rnd),
@@ -19236,11 +20237,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19236
20237
  const toPart = quat.conjugate(p.q);
19237
20238
  const lo = toLocal(p.pos, p.q, objLocal(o, origin));
19238
20239
  const ld = rotateVec(toPart, objLocalDir(o, d));
19239
- const EPS24 = 1e-4;
20240
+ const EPS33 = 1e-4;
19240
20241
  let t = t0;
19241
20242
  let axis = -1;
19242
20243
  for (let step = 0; step < cells.length + 1; step++) {
19243
- const at2 = vec.madd(lo, ld, t + EPS24);
20244
+ const at2 = vec.madd(lo, ld, t + EPS33);
19244
20245
  const cell = cells.find((c) => Math.abs(at2[0] - c.center[0]) <= c.size[0] / 2 && Math.abs(at2[1] - c.center[1]) <= c.size[1] / 2 && Math.abs(at2[2] - c.center[2]) <= c.size[2] / 2);
19245
20246
  if (!cell) break;
19246
20247
  let out = Infinity;
@@ -19253,25 +20254,34 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19253
20254
  axis = a;
19254
20255
  }
19255
20256
  }
19256
- if (!Number.isFinite(out) || out >= t1 - EPS24) return "through";
19257
- t = out + 2 * EPS24;
20257
+ if (!Number.isFinite(out) || out >= t1 - EPS33) return "through";
20258
+ t = out + 2 * EPS33;
19258
20259
  }
19259
20260
  if (axis < 0) return null;
19260
20261
  const local = [0, 0, 0];
19261
20262
  local[axis] = -Math.sign(ld[axis]);
19262
20263
  return { t, n: rotateVec(o.st.rotation, rotateVec(p.q, local)) };
19263
20264
  };
20265
+ const coreBehind = (o, p, origin, d, t0, t1) => {
20266
+ const gap = pastChips(o, p, origin, d, t0, t1);
20267
+ const core = Math.min(t1, t0 + REBAR_COVER);
20268
+ if (gap === null || gap !== "through" && gap.t <= core) return gap;
20269
+ return { t: core, n: vec.scale(d, -1) };
20270
+ };
20271
+ const inGap = (p, lp) => (p.st.chipped ?? []).some((c) => Math.abs(lp[0] - c.center[0]) <= c.size[0] / 2 && Math.abs(lp[1] - c.center[1]) <= c.size[1] / 2 && Math.abs(lp[2] - c.center[2]) <= c.size[2] / 2);
20272
+ const coreStands = (p, lp) => {
20273
+ if (!p.spec.reinforcement || !isMember(p.dims, p.spec.structure?.role) || p.st.stripped) return false;
20274
+ const along2 = p.dims.indexOf(Math.max(...p.dims));
20275
+ const bands = Math.max(1, Math.round(p.dims[along2] / MEMBER_BAND));
20276
+ const band = clamp2(Math.floor((lp[along2] + p.dims[along2] / 2) / p.dims[along2] * bands), 0, bands - 1);
20277
+ return (p.rt.bands?.[band] ?? 0) < MEMBER_CUT_LOSS;
20278
+ };
19264
20279
  const insideChip = (p, objectPoint) => {
19265
20280
  const cells = p.st.chipped;
19266
20281
  if (!cells?.length) return false;
19267
20282
  const [u, v] = planeAxes(p.thin);
19268
20283
  const lp = toLocal(p.pos, p.q, objectPoint);
19269
- if (p.spec.reinforcement && isMember(p.dims, p.spec.structure?.role) && !p.st.stripped) {
19270
- const along2 = p.dims.indexOf(Math.max(...p.dims));
19271
- const bands = Math.max(1, Math.round(p.dims[along2] / MEMBER_BAND));
19272
- const band = clamp2(Math.floor((lp[along2] + p.dims[along2] / 2) / p.dims[along2] * bands), 0, bands - 1);
19273
- if ((p.rt.bands?.[band] ?? 0) < MEMBER_CUT_LOSS) return false;
19274
- }
20284
+ if (coreStands(p, lp)) return false;
19275
20285
  return cells.some((c) => Math.abs(lp[u] - c.center[u]) <= c.size[u] / 2 && Math.abs(lp[v] - c.center[v]) <= c.size[v] / 2);
19276
20286
  };
19277
20287
  const alongAt = (along2, at2) => {
@@ -19328,7 +20338,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19328
20338
  };
19329
20339
  const chipUnits = (o, p, kind, wp, hitEnergy, dir, radius, src) => {
19330
20340
  var _a, _b, _c;
19331
- if (!p.spec.units || !p.staged || chipEnergy <= 0 || p.st.stripped || isLost(p) || (p.st.stage ?? 0) >= 2) return;
20341
+ const bonded = bondedPlate(o, p);
20342
+ if (!bonded && (!p.spec.units || !p.staged) || chipEnergy <= 0 || p.st.stripped || isLost(p) || (p.st.stage ?? 0) >= 2) return;
19332
20343
  const rule = p.mat.hits?.[kind];
19333
20344
  const perKg = rule?.unitJoules ?? chipEnergy;
19334
20345
  const energy = hitEnergy - (rule?.floor ?? 0);
@@ -19402,6 +20413,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19402
20413
  if (Object.values(worn).filter((w) => w === -1).length > wholeBefore) dropUnsupported(o, p, src);
19403
20414
  if (p.spec.reinforcement) exposeRebar(o, p, src);
19404
20415
  for (const cell of out) addBreach(o, p, toWorld(c, q, cell.center), cell.size[u] * cell.size[v], energy, dir, src);
20416
+ if (bonded) settleBonded(o, p, wp, dir, src);
19405
20417
  if (p.structural && !isLost(p)) {
19406
20418
  solveStructure(o);
19407
20419
  collapseCheck(o, src);
@@ -19517,18 +20529,19 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19517
20529
  if (p.structural) solveStructure(o);
19518
20530
  };
19519
20531
  const blastReachOf = (p, energy) => {
19520
- const perKg = p.mat.hits?.blunt?.unitJoules ?? chipEnergy;
19521
- const resistance = Math.max(1, perKg * p.mat.density * p.thickness);
20532
+ const resistance = Math.max(1, (p.mat.hits?.blunt?.unitJoules ?? chipEnergy) * p.mat.density * p.thickness);
19522
20533
  return BREACH_BLAST_REACH * Math.cbrt(Math.max(0, energy) / 1e3) * clamp2(Math.cbrt(BLAST_REFERENCE_RESISTANCE / resistance), 0.3, 2);
19523
20534
  };
19524
- const blastUnits = (o, p, wp, energy, dist, src) => {
20535
+ const blastUnits = (o, p, wp, energy, dist, src, from) => {
19525
20536
  var _a;
19526
- if (!p.staged || p.st.stripped || isLost(p) || chipEnergy <= 0) return false;
20537
+ if (!p.staged && !bondedPlate(o, p) || p.st.stripped || isLost(p) || chipEnergy <= 0) return false;
19527
20538
  const reach2 = blastReachOf(p, energy);
19528
20539
  if (dist >= reach2) return false;
19529
- const radius = Math.sqrt(reach2 * reach2 - dist * dist);
19530
20540
  const [u, v] = planeAxes(p.thin);
19531
- const lp = toLocal(p.pos, p.q, objLocal(o, wp));
20541
+ const charge = from ? toLocal(p.pos, p.q, objLocal(o, from)) : null;
20542
+ const lp = charge ?? toLocal(p.pos, p.q, objLocal(o, wp));
20543
+ const off = charge ? Math.max(0, Math.abs(charge[p.thin]) - p.dims[p.thin] / 2) : dist;
20544
+ const radius = Math.sqrt(Math.max(0, reach2 * reach2 - off * off));
19532
20545
  const op = p.st.opening ? toLocal(p.pos, p.q, p.st.opening.center) : null;
19533
20546
  const grid = gridOf(p);
19534
20547
  const worn = (_a = p.rt).chips ?? (_a.chips = {});
@@ -19552,7 +20565,12 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19552
20565
  }
19553
20566
  }
19554
20567
  if (out.length === 0) return false;
19555
- return knockOutUnits(o, p, wp, energy, out, src);
20568
+ return knockOutUnits(o, p, wp, energy, out, src, from ? awayFromCharge(o, p, from) : void 0, BLAST_DRIVE);
20569
+ };
20570
+ const awayFromCharge = (o, p, charge) => {
20571
+ const axis = [0, 0, 0];
20572
+ axis[p.thin] = toLocal(p.pos, p.q, objLocal(o, charge))[p.thin] >= 0 ? -1 : 1;
20573
+ return rotateVec(partXf(o, p).q, axis);
19556
20574
  };
19557
20575
  const wedgedUnder = (o, p, loose) => {
19558
20576
  if (loose.length === 0) return loose;
@@ -19644,7 +20662,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19644
20662
  for (const i of out) worn[i] = -1;
19645
20663
  return knockOutUnits(o, p, point, energy, out, src);
19646
20664
  };
19647
- const knockOutUnits = (o, p, wp, energy, out, src, d) => {
20665
+ const knockOutUnits = (o, p, wp, energy, out, src, d, drive = CHIP_DRIVE) => {
19648
20666
  var _a, _b;
19649
20667
  const [u, v] = planeAxes(p.thin);
19650
20668
  const op = p.st.opening ? toLocal(p.pos, p.q, p.st.opening.center) : null;
@@ -19654,7 +20672,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19654
20672
  out = out.filter((i) => !castHere.has(i));
19655
20673
  if (out.length === 0) return false;
19656
20674
  for (const i of out) worn[i] = -1;
19657
- const cast = p.spec.units?.mortar === p.spec.material;
20675
+ const bonded = bondedPlate(o, p);
20676
+ const cast = p.spec.units?.mortar === p.spec.material || bonded;
19658
20677
  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))).filter((i) => !castHere.has(i));
19659
20678
  for (const i of loose) worn[i] = -1;
19660
20679
  const blown = out.map((i) => grid[i]), fallen = loose.map((i) => grid[i]);
@@ -19667,7 +20686,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19667
20686
  const tag = `x${chipped.length}_`;
19668
20687
  const holes = localHolesOf(p);
19669
20688
  const fragments = [
19670
- ...cellFragments(o, p, clumpUnits(blown, p.thin, unitSpan(p), unitClumps), wp, null, speed, blownMass, tag, true, holes),
20689
+ ...cellFragments(o, p, clumpUnits(blown, p.thin, unitSpan(p), unitClumps), wp, d ?? null, speed, blownMass, tag, true, holes, drive),
19671
20690
  ...fallen.length > 0 ? cellFragments(o, p, clumpUnits(fallen, p.thin, unitSpan(p), fallenClumps), wp, null, 0.3, fallenMass, `${tag}f`, true, holes) : [],
19672
20691
  ...plasterFlakes(o, p, blown, wp, speed, `${tag}p`)
19673
20692
  ];
@@ -19692,6 +20711,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19692
20711
  debris(o, p, p.mat.breakDebris, center, vec.normalize(vec.sub(center, wp), [0, 1, 0]), 14, 3, src);
19693
20712
  const cut = wornLocally(p) && cutBandsGone(o, p, cells, d ?? vec.normalize(vec.sub(partXf(o, p).c, wp), [1, 0, 0]), src);
19694
20713
  if (p.spec.reinforcement && !cut) exposeRebar(o, p, src);
20714
+ if (bonded) settleBonded(o, p, wp, d ?? null, src);
19695
20715
  if (p.structural && !isLost(p)) {
19696
20716
  solveStructure(o);
19697
20717
  collapseCheck(o, src);
@@ -19803,6 +20823,55 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19803
20823
  emit({ ...base2(o, src), type: "yield", part: p.spec.id, joint: h.joint, point, toward: rotateVec(o.st.rotation, h.toward), moment: h.moment });
19804
20824
  }
19805
20825
  };
20826
+ const barAlong = (o, p, origin, d, t0, t1) => {
20827
+ const r = p.spec.reinforcement;
20828
+ if (!r || !isMember(p.dims, p.spec.structure?.role)) return null;
20829
+ const along2 = p.dims.indexOf(Math.max(...p.dims));
20830
+ const [u, v] = [0, 1, 2].filter((k) => k !== along2);
20831
+ const lo = toLocal(p.pos, p.q, objLocal(o, origin));
20832
+ const ld = rotateVec(quat.conjugate(p.q), objLocalDir(o, d));
20833
+ const across2 = Math.hypot(ld[u], ld[v]);
20834
+ if (across2 < 1e-6) return null;
20835
+ const cut = p.rt.severedBars ?? [];
20836
+ let best = null;
20837
+ rebarBars(p.dims, p.thin, r.spacing, p.spec.structure?.role).forEach(([a], i) => {
20838
+ if (cut.includes(i)) return;
20839
+ const du = a[u] - lo[u];
20840
+ const dv = a[v] - lo[v];
20841
+ if (Math.abs(du * ld[v] - dv * ld[u]) / across2 > r.diameter / 2) return;
20842
+ const t = (du * ld[u] + dv * ld[v]) / (across2 * across2);
20843
+ if (t >= t0 && t <= t1 && (best === null || t < best)) best = t;
20844
+ });
20845
+ return best;
20846
+ };
20847
+ const cutCageBars = (o, p, origin, d, caliber, src) => {
20848
+ var _a;
20849
+ const r = p.spec.reinforcement;
20850
+ if (!r || isLost(p)) return;
20851
+ const lo = toLocal(p.pos, p.q, objLocal(o, origin));
20852
+ const ld = vec.normalize(rotateVec(quat.conjugate(p.q), objLocalDir(o, d)));
20853
+ const reach2 = r.diameter / 2 + caliber / 2e3;
20854
+ const cut = (_a = p.rt).severedBars ?? (_a.severedBars = []);
20855
+ let severed = 0;
20856
+ rebarBars(p.dims, p.thin, r.spacing, p.spec.structure?.role).forEach(([a, b], i) => {
20857
+ if (cut.includes(i)) return;
20858
+ const near = lineToSegment(lo, ld, a, b);
20859
+ if (!near || near.distance > reach2) return;
20860
+ cut.push(i);
20861
+ severed++;
20862
+ debris(o, p, "sparks", toWorld(o.st.position, o.st.rotation, toWorld(p.pos, p.q, near.point)), vec.scale(d, -1), 6, 3, src);
20863
+ });
20864
+ if (severed === 0) return;
20865
+ markDamaged(p);
20866
+ if (cageLeft(p) <= 0) {
20867
+ if (p.rt.hinges?.length) reyield(o, p, 0, src);
20868
+ loseCage(o, p, src);
20869
+ return;
20870
+ }
20871
+ if (p.rt.hinges?.length) reyield(o, p, barsMoment(p), src);
20872
+ solveStructure(o);
20873
+ collapseCheck(o, src);
20874
+ };
19806
20875
  const severBars = (o, p, origin, d, caliber, src) => {
19807
20876
  var _a;
19808
20877
  const r = p.spec.reinforcement;
@@ -19902,7 +20971,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19902
20971
  return;
19903
20972
  }
19904
20973
  if (p.bend) settleStructure(o);
19905
- if (!force && p.bend && (p.st.flexure ?? 0) > 1 && sectionOf2(p, p.bend.gravity).reinforced) {
20974
+ if (!force && p.bend && (p.st.flexure ?? 0) > 1 && sectionOf22(p, p.bend.gravity).reinforced) {
19906
20975
  hingeDrop(o, p, src);
19907
20976
  return;
19908
20977
  }
@@ -20034,6 +21103,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
20034
21103
  if (chained && p.st.hp <= 0 && p.rt.chainDue === void 0) p.st.hp = Math.min(prev, 1);
20035
21104
  if (p.st.hp <= 0 && p.mat.fracture === "none" && !p.spec.explodes) p.st.hp = Math.min(prev, 1);
20036
21105
  if (p.st.hp <= 0 && type === "ballistic" && wornLocally(p)) p.st.hp = Math.min(prev, 1);
21106
+ if (p.st.hp <= 0 && type !== "fire" && type !== "heat" && bondedPlate(o, p)) p.st.hp = Math.min(prev, 1);
20037
21107
  const done = prev - p.st.hp;
20038
21108
  if (done > 0) emit({ ...base2(o, src), type: "damage", part: p.spec.id, amount: done, hp: Math.max(0, p.st.hp), damageType: type });
20039
21109
  if (p.st.hp <= 0) failPart(o, p, origin, dir, fragEnergy * weight, cap, src);
@@ -20116,6 +21186,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
20116
21186
  const piece3 = round3.piece;
20117
21187
  const weight = piece3?.weight ?? 1;
20118
21188
  const piercing = round3.piercing ?? 1;
21189
+ if (p.st.stripped && p.spec.reinforcement) cutCageBars(o, p, entry2, d, caliber, src);
20119
21190
  if (p.st.stripped || p.st.opening && insideOpening(o, p, objLocal(o, entry2)) || insideChip(p, objLocal(o, vec.madd(entry2, d, Math.min(CHIP_PROBE_DEPTH, pathLen / 2))))) {
20120
21191
  return { penetrated: true, exitEnergy: E, exitPoint: vec.madd(entry2, d, Math.min(pathLen, p.thickness)), damage: 0 };
20121
21192
  }
@@ -20142,7 +21213,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
20142
21213
  const dmg2 = applyDamage(o, p, E * DMG_PER_J * scale * 0.2, "ballistic", entry2, d, E * 0.1, 12, src, weight);
20143
21214
  return { penetrated: false, exitEnergy: 0, damage: dmg2 };
20144
21215
  }
20145
- if (p.layers.length > 0) spallOuter(o, p, entry2, face, n, Math.max(0.03, caliber / 1e3 * 4), src);
21216
+ if (p.layers.length > 0) spallOuter(o, p, entry2, face, n, Math.max(0.03, caliber / 1e3 * 4), src, caliber / 1e3 * TEAR_CALIBERS);
20146
21217
  else if (mat.hits?.ballistic?.crater) crater(o, p, entry2, n, clamp2(0.02 + Math.sqrt(E) * 15e-4, 0.02, 0.15), src);
20147
21218
  const brittle = mat.ductility < 0.3;
20148
21219
  const ratio = Ep / Math.max(thr, 1e-6);
@@ -20155,7 +21226,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
20155
21226
  exitPoint = vec.madd(entry2, d, exitDist);
20156
21227
  const hole = addHole(o, p, entry2, n, holeWidth, true, exitPoint, src);
20157
21228
  shellShare = wearsShell(p, hole.diameter * 2);
20158
- if (p.layers.length > 0) spallOuter(o, p, exitPoint, -face, vec.scale(n, -1), Math.max(0.03, caliber / 1e3 * 4), src);
21229
+ if (p.layers.length > 0) spallOuter(o, p, exitPoint, -face, vec.scale(n, -1), Math.max(0.03, caliber / 1e3 * 4), src, caliber / 1e3 * TEAR_CALIBERS);
20159
21230
  addBreach(o, p, entry2, Math.PI * (hole.diameter / 2) * (hole.diameter / 2), E, d, src);
20160
21231
  if (mat.ductility >= 0.5 && p.thickness <= THIN_SHEET_DISHING) addDent(o, p, entry2, n, Math.max(caliber * 3 / 1e3, 0.012), clamp2(E * 2e-5, 1e-3, 0.03), src);
20161
21232
  if (brittle && mat.fracture === "shatter") addCrack(o, p, entry2, n, crackLen, src);
@@ -20327,13 +21398,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
20327
21398
  const breachReach = BREACH_BLAST_REACH * Math.cbrt(Math.max(0, energy) / 1e3);
20328
21399
  const caged2 = Boolean(p.spec.reinforcement && p.spec.units);
20329
21400
  const member = caged2 && (isMember(p.dims, p.spec.structure?.role) || dist > MEMBER_CUT_REACH * breachReach);
20330
- 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);
21401
+ const bonded = bondedPlate(o, p);
21402
+ const dealt = bonded ? applyDamage(o, p, Math.min(amount, Math.max(0, p.st.hp - 1)), "explosive", null, null, Ein * 0.3, 40, src) : 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);
20331
21403
  res.damage += dealt;
20332
21404
  if (p.bend && flexure.enabled) bendByBlast(o, p, point, energy, radius, reach2, src);
20333
21405
  if (p.spec.units && p.spec.units.mortar !== p.spec.material) {
20334
21406
  blastPanel(o, p, point, energy, src);
20335
- if (!isLost(p)) blastUnits(o, p, wp, energy, dist, src);
20336
- } else if (member) blastUnits(o, p, wp, energy, dist, src);
21407
+ if (!isLost(p)) blastUnits(o, p, wp, energy, dist, src, point);
21408
+ } else if (member || bonded) blastUnits(o, p, wp, energy, dist, src, point);
20337
21409
  else if (dist <= breachReach) addBreach(o, p, wp, breachAreaOf(p, dealt, true), Ein, null, src);
20338
21410
  return reach2;
20339
21411
  };
@@ -21871,6 +22943,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
21871
22943
  }).events;
21872
22944
  },
21873
22945
  state: (id) => objects.get(id)?.st ?? impls.get(id)?.impl.state() ?? null,
22946
+ layers: (id, partId) => objects.get(id)?.byId.get(partId)?.spec.layers ?? [],
21874
22947
  anchoredParts: (id) => objects.get(id)?.parts.filter((p) => p.anchored && !isLost(p)).map((p) => p.spec.id) ?? [],
21875
22948
  fixedInPlace: (id) => {
21876
22949
  const o = objects.get(id);
@@ -21881,6 +22954,27 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
21881
22954
  return st ? clone(st) : null;
21882
22955
  },
21883
22956
  part: (id, partId) => objects.get(id)?.byId.get(partId)?.st ?? impls.get(id)?.impl.state().parts.find((p) => p.id === partId) ?? null,
22957
+ assemblyFlex(id, options2) {
22958
+ const o = objects.get(id);
22959
+ if (!o) return null;
22960
+ const lost = new Set(options2?.lost ?? []);
22961
+ const kept = new Set(o.st.groups[0] ?? []);
22962
+ const framed = o.parts.filter((p) => lost.has(p.spec.id) || kept.has(p.spec.id) && !isLost(p));
22963
+ const ids = new Set(framed.map((p) => p.spec.id));
22964
+ const parts2 = framed.map((p) => ({
22965
+ id: p.spec.id,
22966
+ material: p.mat,
22967
+ dims: p.dims,
22968
+ position: p.pos,
22969
+ rotation: p.q,
22970
+ // a part that went is taken whole, as it was while it held
22971
+ mass: lost.has(p.spec.id) ? p.mass0 : p.st.mass,
22972
+ ...p.spec.grain ? { grain: GRAIN_AXIS[p.spec.grain] } : {},
22973
+ ...p.spec.shape.kind === "cylinder" ? { round: true } : {}
22974
+ }));
22975
+ const joints = o.joints.filter((j) => ids.has(j.spec.a) && ids.has(j.spec.b) && (!j.st.open || lost.has(j.spec.a) || lost.has(j.spec.b))).map((j) => ({ a: j.spec.a, b: j.spec.b, kind: j.spec.kind, position: j.pos }));
22976
+ return assemblyFlex({ parts: parts2, joints, lost: [...lost], ...options2?.loads ? { loads: options2.loads } : {}, ...options2?.friction !== void 0 ? { friction: options2.friction } : {} });
22977
+ },
21884
22978
  reset(id) {
21885
22979
  finishExplosions();
21886
22980
  const im = impls.get(id);
@@ -22422,7 +23516,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
22422
23516
  var MIN_PILLAR_AREA = 0.036;
22423
23517
  var BEAM_DEPTH_RATIO = 10;
22424
23518
  var PLASTER_PER_FACE = 0.015;
22425
- var MORTAR_JOINT = 0.01;
23519
+ var MORTAR_JOINT2 = 0.01;
22426
23520
  var SECTION_STEP = 0.05;
22427
23521
  var ceilTo = (value, step) => Math.ceil(value / step - 1e-9) * step;
22428
23522
  var round22 = (value) => Math.round(value * 100) / 100;
@@ -22436,7 +23530,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
22436
23530
  function coursingOf(unitId, assemblyUnits) {
22437
23531
  if (unitId !== void 0) {
22438
23532
  const unit = getMasonryUnit(unitId);
22439
- return { courseHeight: round22(unit.height + MORTAR_JOINT), unitLength: round22(unit.length + MORTAR_JOINT) };
23533
+ return { courseHeight: round22(unit.height + MORTAR_JOINT2), unitLength: round22(unit.length + MORTAR_JOINT2) };
22440
23534
  }
22441
23535
  return assemblyUnits ? { courseHeight: assemblyUnits.size[1], unitLength: assemblyUnits.size[0] } : void 0;
22442
23536
  }
@@ -22701,7 +23795,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
22701
23795
  });
22702
23796
  return new Map([...sized].map(([part, capacity]) => [part.id, capacity]));
22703
23797
  }
22704
- var EPS2 = 1e-6;
23798
+ var EPS3 = 1e-6;
22705
23799
  function linesOf(boxes) {
22706
23800
  return boxes.map(([u0, v0, u1, v1]) => u1 - u0 >= v1 - v0 ? { dir: "u", at: (v0 + v1) / 2, from: u0, to: u1 } : { dir: "v", at: (u0 + u1) / 2, from: v0, to: v1 });
22707
23801
  }
@@ -22746,11 +23840,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
22746
23840
  const depth = v1 - v0;
22747
23841
  const candidates = [];
22748
23842
  for (const at2 of positions(lines, "v", options.lineTolerance)) {
22749
- if (at2 < u0 + options.minPanel - EPS2 || at2 > u1 - options.minPanel + EPS2) continue;
23843
+ if (at2 < u0 + options.minPanel - EPS3 || at2 > u1 - options.minPanel + EPS3) continue;
22750
23844
  candidates.push({ dir: "v", at: at2, coverage: coverage(lines, "v", at2, v0, v1, options), skew: Math.abs(at2 - (u0 + u1) / 2) / (width / 2) });
22751
23845
  }
22752
23846
  for (const at2 of positions(lines, "u", options.lineTolerance)) {
22753
- if (at2 < v0 + options.minPanel - EPS2 || at2 > v1 - options.minPanel + EPS2) continue;
23847
+ if (at2 < v0 + options.minPanel - EPS3 || at2 > v1 - options.minPanel + EPS3) continue;
22754
23848
  candidates.push({ dir: "u", at: at2, coverage: coverage(lines, "u", at2, u0, u1, options), skew: Math.abs(at2 - (v0 + v1) / 2) / (depth / 2) });
22755
23849
  }
22756
23850
  const boundary = candidates.filter((c) => c.coverage >= options.lineCoverage);
@@ -23058,7 +24152,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
23058
24152
  }
23059
24153
  return { u, v, alongU };
23060
24154
  }
23061
- function sectionOf(structure, options) {
24155
+ function sectionOf2(structure, options) {
23062
24156
  const unit = structure.construction.walls.unit;
23063
24157
  return typeof unit === "string" ? pillarSectionOf(getMasonryUnit(unit)) : { across: options.columnSide, along: options.columnSide };
23064
24158
  }
@@ -23308,7 +24402,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
23308
24402
  panelsOf: /* @__PURE__ */ new Map(),
23309
24403
  pillars: 0,
23310
24404
  groundBase: firstColumn?.on ?? GROUND,
23311
- section: sectionOf(structure, options)
24405
+ section: sectionOf2(structure, options)
23312
24406
  };
23313
24407
  const walls = parts2.filter((p) => /^wall_/.test(p.id) && (p.role === "wall" || p.role === "partition"));
23314
24408
  const jobs = [...bonds.map((part) => ({ part, bond: true })), ...slabs.map((part) => ({ part, bond: false }))].sort((a, b) => a.part.y0 - b.part.y0 || Number(b.bond) - Number(a.bond));
@@ -35743,7 +36837,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
35743
36837
  ],
35744
36838
  estimated: [
35745
36839
  "parts"
35746
- ]
36840
+ ],
36841
+ consumable: {
36842
+ form: "bar",
36843
+ unit: "g",
36844
+ amount: 100,
36845
+ dose: 1.5,
36846
+ emptyKg: 0
36847
+ }
35747
36848
  },
35748
36849
  {
35749
36850
  id: "shampoo",
@@ -35761,7 +36862,15 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
35761
36862
  stack: 3,
35762
36863
  shape: "bottle",
35763
36864
  color: 4885200,
35764
- rarity: "common"
36865
+ rarity: "common",
36866
+ consumable: {
36867
+ form: "liquid",
36868
+ unit: "ml",
36869
+ amount: 300,
36870
+ dose: 8,
36871
+ emptyKg: 0.044,
36872
+ density: 1.02
36873
+ }
35765
36874
  },
35766
36875
  {
35767
36876
  id: "toothpaste",
@@ -35779,7 +36888,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
35779
36888
  stack: 3,
35780
36889
  shape: "tube",
35781
36890
  color: 15790320,
35782
- rarity: "common"
36891
+ rarity: "common",
36892
+ consumable: {
36893
+ form: "paste",
36894
+ unit: "g",
36895
+ amount: 90,
36896
+ dose: 1,
36897
+ emptyKg: 0.01
36898
+ }
35783
36899
  },
35784
36900
  {
35785
36901
  id: "toothbrush",
@@ -47303,7 +48419,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
47303
48419
  }
47304
48420
  var residentialTower = residentialTowerTemplate();
47305
48421
 
47306
- // ../game-floorplan-three/dist/chunk-XI3CKQAV.js
48422
+ // ../game-floorplan-three/dist/chunk-RW7ZTU76.js
47307
48423
  var __defProp3 = Object.defineProperty;
47308
48424
  var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp3(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
47309
48425
  var __publicField = (obj, key2, value) => __defNormalProp(obj, typeof key2 !== "symbol" ? key2 + "" : key2, value);
@@ -47370,20 +48486,20 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
47370
48486
  var OPEN_ROOM_TYPES2 = /* @__PURE__ */ new Set(["balcony", "terrace", "veranda", "balcony_gourmet"]);
47371
48487
  var rectsOf = (c) => c.parts && c.parts.length ? c.parts : [[c.u0, c.v0, c.u1, c.v1]];
47372
48488
  var isOpenArea = (c) => OPEN_ROOM_TYPES2.has(c.type) || c.outdoor === true;
47373
- var EPS3 = 1e-6;
48489
+ var EPS4 = 1e-6;
47374
48490
  function subtractBox(a, b) {
47375
- if (b[0] >= a[3] - EPS3 || b[3] <= a[0] + EPS3 || b[1] >= a[4] - EPS3 || b[4] <= a[1] + EPS3 || b[2] >= a[5] - EPS3 || b[5] <= a[2] + EPS3) return [a];
48491
+ if (b[0] >= a[3] - EPS4 || b[3] <= a[0] + EPS4 || b[1] >= a[4] - EPS4 || b[4] <= a[1] + EPS4 || b[2] >= a[5] - EPS4 || b[5] <= a[2] + EPS4) return [a];
47376
48492
  const out = [];
47377
48493
  const box4 = [...a];
47378
48494
  for (let axis = 0; axis < 3; axis++) {
47379
48495
  const lo = axis, hi = axis + 3;
47380
- if (b[lo] > box4[lo] + EPS3) {
48496
+ if (b[lo] > box4[lo] + EPS4) {
47381
48497
  const piece22 = [...box4];
47382
48498
  piece22[hi] = b[lo];
47383
48499
  out.push(piece22);
47384
48500
  box4[lo] = b[lo];
47385
48501
  }
47386
- if (b[hi] < box4[hi] - EPS3) {
48502
+ if (b[hi] < box4[hi] - EPS4) {
47387
48503
  const piece22 = [...box4];
47388
48504
  piece22[lo] = b[hi];
47389
48505
  out.push(piece22);
@@ -48138,7 +49254,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48138
49254
  const OPEN_ROOM_TYPES22 = /* @__PURE__ */ new Set(["balcony", "terrace", "veranda", "balcony_gourmet"]);
48139
49255
  const NO_CEILING = OPEN_ROOM_TYPES22;
48140
49256
  const OPEN_AREA = (c) => OPEN_ROOM_TYPES22.has(c.type) || c.outdoor === true;
48141
- const EPS4 = 1e-3;
49257
+ const EPS42 = 1e-3;
48142
49258
  const Y0 = (f) => {
48143
49259
  const A = shared2.ctx.r.floors;
48144
49260
  return A[Math.max(0, Math.min(A.length - 1, f))].y0;
@@ -48147,19 +49263,19 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48147
49263
  const rectsOf2 = (c) => c.parts && c.parts.length ? c.parts : [[c.u0, c.v0, c.u1, c.v1]];
48148
49264
  function roomAt(f, u, v) {
48149
49265
  for (const c of shared2.ctx.r.rooms) if (c.floor === f) {
48150
- for (const [a, b, c2, d] of rectsOf2(c)) if (u > a + EPS4 && u < c2 - EPS4 && v > b + EPS4 && v < d - EPS4) return c;
49266
+ for (const [a, b, c2, d] of rectsOf2(c)) if (u > a + EPS42 && u < c2 - EPS42 && v > b + EPS42 && v < d - EPS42) return c;
48151
49267
  }
48152
49268
  return null;
48153
49269
  }
48154
49270
  function subRect(a, b) {
48155
49271
  const [ax0, az0, ax1, az1] = a, [bx0, bz0, bx1, bz1] = b;
48156
- if (bx0 >= ax1 - EPS4 || bx1 <= ax0 + EPS4 || bz0 >= az1 - EPS4 || bz1 <= az0 + EPS4) return [a];
49272
+ if (bx0 >= ax1 - EPS42 || bx1 <= ax0 + EPS42 || bz0 >= az1 - EPS42 || bz1 <= az0 + EPS42) return [a];
48157
49273
  const o = [];
48158
- if (bz0 > az0 + EPS4) o.push([ax0, az0, ax1, bz0]);
48159
- if (bz1 < az1 - EPS4) o.push([ax0, bz1, ax1, az1]);
49274
+ if (bz0 > az0 + EPS42) o.push([ax0, az0, ax1, bz0]);
49275
+ if (bz1 < az1 - EPS42) o.push([ax0, bz1, ax1, az1]);
48160
49276
  const z0 = Math.max(az0, bz0), z1 = Math.min(az1, bz1);
48161
- if (bx0 > ax0 + EPS4) o.push([ax0, z0, bx0, z1]);
48162
- if (bx1 < ax1 - EPS4) o.push([bx1, z0, ax1, z1]);
49277
+ if (bx0 > ax0 + EPS42) o.push([ax0, z0, bx0, z1]);
49278
+ if (bx1 < ax1 - EPS42) o.push([bx1, z0, ax1, z1]);
48163
49279
  return o;
48164
49280
  }
48165
49281
  function subRects(rs, holes) {
@@ -48185,7 +49301,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48185
49301
  const pitch = A[f + 1].y0 - A[f].y0;
48186
49302
  return h > pitch && h - pitch <= 0.45 ? pitch : h;
48187
49303
  }
48188
- const defined = { OPEN_ROOM_TYPES: OPEN_ROOM_TYPES22, NO_CEILING, OPEN_AREA, EPS: EPS4, Y0, colorOf, rectsOf: rectsOf2, roomAt, subRect, subRects, wallColor, floorColor, stairFootprint, effectiveHeight };
49304
+ const defined = { OPEN_ROOM_TYPES: OPEN_ROOM_TYPES22, NO_CEILING, OPEN_AREA, EPS: EPS42, Y0, colorOf, rectsOf: rectsOf2, roomAt, subRect, subRects, wallColor, floorColor, stairFootprint, effectiveHeight };
48189
49305
  Object.assign(K, defined);
48190
49306
  }
48191
49307
  var DOOR_JAMB_WIDTH = 0.05;
@@ -48195,7 +49311,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48195
49311
  var SLAB_CONCRETE = 9408138;
48196
49312
  var WALL_FACE = 0.075;
48197
49313
  function installHouseFloors(K, shared2) {
48198
- const { rectsOf: rectsOf2, EPS: EPS4, OPEN_AREA, Y0, bx, cursor, floorColor, stairFootprint, structurePiece, subRects } = K;
49314
+ const { rectsOf: rectsOf2, EPS: EPS42, OPEN_AREA, Y0, bx, cursor, floorColor, stairFootprint, structurePiece, subRects } = K;
48199
49315
  function outbuildingSlabEdge(room, y0, slab) {
48200
49316
  const R = shared2.ctx.r;
48201
49317
  const e = (R.outbuildings ?? []).find((o) => o.id === room.id);
@@ -48224,7 +49340,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48224
49340
  const k = [m.link.from, m.link.to, m.x.toFixed(2), m.z.toFixed(2), (m.ry || 0).toFixed(2)].join("|");
48225
49341
  if (!mp.has(k)) mp.set(k, { m, from: m.link.from, to: m.link.to, rect: stairFootprint(m) });
48226
49342
  }
48227
- const l = [...mp.values()], inter = (a, b) => a[0] < b[2] - EPS4 && a[2] > b[0] + EPS4 && a[1] < b[3] - EPS4 && a[3] > b[1] + EPS4;
49343
+ const l = [...mp.values()], inter = (a, b) => a[0] < b[2] - EPS42 && a[2] > b[0] + EPS42 && a[1] < b[3] - EPS42 && a[3] > b[1] + EPS42;
48228
49344
  for (const v of l) if (l.some((o) => o !== v && o.to === v.from && inter(o.rect, v.rect))) {
48229
49345
  const m = v.m, H = Y0(v.to) - Y0(v.from), len = Math.min(m.d * 0.5, Math.max(0.7, m.d * (H - 0.24 - 1.95) / H)), c = Math.cos(m.ry), s_ = Math.sin(m.ry), lz = m.d / 2 - len / 2;
48230
49346
  v.landing = stairFootprint({ x: m.x + lz * s_, z: m.z + lz * c, ry: m.ry, w: m.w, d: len });
@@ -48244,7 +49360,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48244
49360
  const out = [], taken = [];
48245
49361
  for (const p of ps) for (const q of panelRects(p)) {
48246
49362
  const r = [Math.max(rc[0], q[0]), Math.max(rc[1], q[1]), Math.min(rc[2], q[2]), Math.min(rc[3], q[3])];
48247
- if (r[2] - r[0] > EPS4 && r[3] - r[1] > EPS4) {
49363
+ if (r[2] - r[0] > EPS42 && r[3] - r[1] > EPS42) {
48248
49364
  out.push([structurePiece(p.id), r]);
48249
49365
  taken.push(r);
48250
49366
  }
@@ -48255,7 +49371,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48255
49371
  function panelAt(parent, x, z) {
48256
49372
  const ps = shared2.ctx.panelsOf && shared2.ctx.panelsOf.get(parent);
48257
49373
  if (!ps) return structurePiece(parent);
48258
- for (const p of ps) for (const q of panelRects(p)) if (x >= q[0] - EPS4 && x <= q[2] + EPS4 && z >= q[1] - EPS4 && z <= q[3] + EPS4) return structurePiece(p.id);
49374
+ for (const p of ps) for (const q of panelRects(p)) if (x >= q[0] - EPS42 && x <= q[2] + EPS42 && z >= q[1] - EPS42 && z <= q[3] + EPS42) return structurePiece(p.id);
48259
49375
  return null;
48260
49376
  }
48261
49377
  const hasSlab = (id) => !!(shared2.ctx.structureIndex[id] || shared2.ctx.panelsOf && shared2.ctx.panelsOf.has(id));
@@ -48342,7 +49458,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48342
49458
  Object.assign(K, { flights, floorsAndSlabs, tilesOf, panelAt });
48343
49459
  }
48344
49460
  function installHouseWalls(K, shared2) {
48345
- const { EPS: EPS4, Y0, boxC, bx, cursor, effectiveHeight, pieceRecord, structurePiece, wallColor } = K;
49461
+ const { EPS: EPS42, Y0, boxC, bx, cursor, effectiveHeight, pieceRecord, structurePiece, wallColor } = K;
48346
49462
  const sh = (...a) => K.sh(...a);
48347
49463
  let solids = null;
48348
49464
  const lay = (rank, mat, x0, y0, z0, x1, y1, z1, color2) => {
@@ -48405,7 +49521,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48405
49521
  function nearestWall(f, axis, L, c) {
48406
49522
  let m = null, md = 1e9;
48407
49523
  for (const w of shared2.ctx.r.walls) {
48408
- if (w.floor !== f || w.axis !== axis || w.type !== "wall" || Math.abs((axis === "u" ? w.v0 : w.u0) - L) > EPS4) continue;
49524
+ if (w.floor !== f || w.axis !== axis || w.type !== "wall" || Math.abs((axis === "u" ? w.v0 : w.u0) - L) > EPS42) continue;
48409
49525
  const a = Math.min(axis === "u" ? w.u0 : w.v0, axis === "u" ? w.u1 : w.v1), b = Math.max(axis === "u" ? w.u0 : w.v0, axis === "u" ? w.u1 : w.v1), d = c < a ? a - c : c > b ? c - b : 0;
48410
49526
  if (d < md) {
48411
49527
  md = d;
@@ -48461,7 +49577,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48461
49577
  wallBox(alongU, L, a, b, y0 + ya, y0 + yb, th, sideL.color, sideH.color, sideL.mat, sideH.mat);
48462
49578
  };
48463
49579
  const win = [
48464
- ...R.windows.filter((j) => j.floor === f && j.axis === w.axis && Math.abs(j.pos - L) < EPS4 && j.at + j.width / 2 > s0 + EPS4 && j.at - j.width / 2 < s1 - EPS4),
49580
+ ...R.windows.filter((j) => j.floor === f && j.axis === w.axis && Math.abs(j.pos - L) < EPS42 && j.at + j.width / 2 > s0 + EPS42 && j.at - j.width / 2 < s1 - EPS42),
48465
49581
  ...doorsInWall(R.doors, w, L, s0, s1).map((d) => ({ at: d.at, width: d.width, y0: 0, y1: doorHeightOf(d, h) }))
48466
49582
  ].sort((p, q) => p.at - q.at);
48467
49583
  let cur = s0;
@@ -48537,14 +49653,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48537
49653
  }
48538
49654
  function installHouseDoors(K, shared2) {
48539
49655
  const seedKey = (id) => K.seedKey(id);
48540
- const { EPS: EPS4, Y0, boxC, bx, cursor, effectiveHeight, nearestWall, part, pieceOf, pieceRecord, roomAt, sideOf, wallBox } = K;
49656
+ const { EPS: EPS42, Y0, boxC, bx, cursor, effectiveHeight, nearestWall, part, pieceOf, pieceRecord, roomAt, sideOf, wallBox } = K;
48541
49657
  const SEED = (...a) => K.SEED(...a);
48542
49658
  const definePiece = (...a) => K.definePiece(...a);
48543
49659
  const rngString = (...a) => K.rngString(...a);
48544
49660
  const sh = (...a) => K.sh(...a);
48545
49661
  function doorLineSides(p) {
48546
49662
  const R = shared2.ctx.r, alongU = p.axis === "u", a = p.at - p.width / 2, b = p.at + p.width / 2;
48547
- const w = R.walls.find((w2) => w2.floor === p.floor && w2.axis === p.axis && Math.abs((alongU ? w2.v0 : w2.u0) - p.pos) < EPS4 && w2.type === "wall" && (Math.abs((alongU ? w2.u1 : w2.v1) - a) < 0.02 || Math.abs((alongU ? w2.u0 : w2.v0) - b) < 0.02));
49663
+ const w = R.walls.find((w2) => w2.floor === p.floor && w2.axis === p.axis && Math.abs((alongU ? w2.v0 : w2.u0) - p.pos) < EPS42 && w2.type === "wall" && (Math.abs((alongU ? w2.u1 : w2.v1) - a) < 0.02 || Math.abs((alongU ? w2.u0 : w2.v0) - b) < 0.02));
48548
49664
  const sides = w ? w.sides : [p.a, p.b];
48549
49665
  return [sideOf(sides[0], false), sideOf(sides[1], false)];
48550
49666
  }
@@ -48556,7 +49672,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48556
49672
  const f = p.floor;
48557
49673
  cursor.group = "f" + f;
48558
49674
  const y0 = Y0(f), alongU = p.axis === "u", L = p.pos, a = p.at - p.width / 2, b = p.at + p.width / 2;
48559
- const wref = R.walls.find((w) => w.floor === f && w.axis === p.axis && Math.abs((alongU ? w.v0 : w.u0) - L) < EPS4), th = wref ? wref.thickness || 0.15 : 0.15, wallHeight = wref ? wref.h : 3;
49675
+ const wref = R.walls.find((w) => w.floor === f && w.axis === p.axis && Math.abs((alongU ? w.v0 : w.u0) - L) < EPS42), th = wref ? wref.thickness || 0.15 : 0.15, wallHeight = wref ? wref.h : 3;
48560
49676
  const PMAT = R.style === "budget" || R.style === "commercial" ? "doorPaint" : "doorWood";
48561
49677
  const dH = doorHeightOf(p, wallHeight), visH = cut ? Math.min(dH, 1.2) : dH, [lL, lH] = doorLineSides(p);
48562
49678
  const inWhole = R.walls.some((w) => doorsInWall([p], w, alongU ? w.v0 : w.u0, Math.min(alongU ? w.u0 : w.v0, alongU ? w.u1 : w.v1), Math.max(alongU ? w.u0 : w.v0, alongU ? w.u1 : w.v1)).length > 0);
@@ -48692,7 +49808,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48692
49808
  Object.assign(K, defined);
48693
49809
  }
48694
49810
  function installHouseWindows(K, shared2) {
48695
- const { EPS: EPS4, Y0, boxC, bx, cursor, pieceRecord, roomAt } = K;
49811
+ const { EPS: EPS42, Y0, boxC, bx, cursor, pieceRecord, roomAt } = K;
48696
49812
  const FRAME_COLORS = { budget: 15856110, mid: 12830924, high: 2829875, commercial: 11844287 };
48697
49813
  const MULLION_THICKNESS = 0.04, PANE_THICKNESS = 0.012, PANE_CLEARANCE = 2e-3, GRILLE_FOOT = 2e-3, ALUMINIUM_PROFILE_KG_PER_M = 1.2, SILL_KG_PER_M = 6, STEEL_KG_PER_M3 = 7850, GRILLE_BAR = 0.016;
48698
49814
  const GLASS_THICKNESS = 4e-3, GLASS_DENSITY = 2500;
@@ -48712,7 +49828,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48712
49828
  if (ya >= 1.2) continue;
48713
49829
  yb = Math.min(yb, 1.2);
48714
49830
  }
48715
- const wref = R.walls.find((w) => w.floor === f && w.axis === j.axis && Math.abs((alongU ? w.v0 : w.u0) - L) < EPS4), th = wref ? wref.thickness || 0.15 : 0.15, t = 0.05, tt = th + 0.02;
49831
+ const wref = R.walls.find((w) => w.floor === f && w.axis === j.axis && Math.abs((alongU ? w.v0 : w.u0) - L) < EPS42), th = wref ? wref.thickness || 0.15 : 0.15, t = 0.05, tt = th + 0.02;
48716
49832
  const bar2 = (u0, y_0, u1, y_1, mat, color2, tw = tt, shift = 0) => {
48717
49833
  const b2 = alongU ? [u0, y0 + y_0, L + shift - tw / 2, u1, y0 + y_1, L + shift + tw / 2] : [L + shift - tw / 2, y0 + y_0, u0, L + shift + tw / 2, y0 + y_1, u1];
48718
49834
  bx(mat, b2[0], b2[1], b2[2], b2[3], b2[4], b2[5], color2);
@@ -49100,7 +50216,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
49100
50216
  }
49101
50217
  var COVERING_CLEAR = 0.15;
49102
50218
  function installLightsDecor(K, shared2) {
49103
- const { EPS: EPS4, OPEN_AREA, SEED, Y0, cursor, rngString, roomAt, stairFootprint } = K;
50219
+ const { EPS: EPS42, OPEN_AREA, SEED, Y0, cursor, rngString, roomAt, stairFootprint } = K;
49104
50220
  const lightItem = (...a) => K.lightItem(...a);
49105
50221
  function decorLights(api) {
49106
50222
  const R = shared2.ctx.r, T2 = shared2.ctx.types, structure = R.style, chance = structure === "budget" ? 0.35 : structure === "mid" ? 0.75 : 1, rnd = rngString(SEED() + "|decorluz");
@@ -49159,7 +50275,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
49159
50275
  }
49160
50276
  const pe = R.doors.find((p) => p.exterior && p.side === "front") || R.doors.find((p) => p.exterior);
49161
50277
  if (pe && T2.outdoor_lamp) {
49162
- const alongU = pe.axis === "u", wref = R.walls.find((w) => w.floor === pe.floor && w.axis === pe.axis && Math.abs((alongU ? w.v0 : w.u0) - pe.pos) < EPS4), th = wref ? wref.thickness || 0.15 : 0.15, n = pe.b === "outside" ? 1 : -1;
50278
+ const alongU = pe.axis === "u", wref = R.walls.find((w) => w.floor === pe.floor && w.axis === pe.axis && Math.abs((alongU ? w.v0 : w.u0) - pe.pos) < EPS42), th = wref ? wref.thickness || 0.15 : 0.15, n = pe.b === "outside" ? 1 : -1;
49163
50279
  const inside22 = roomAt(pe.floor, alongU ? pe.at : pe.pos - 0.4, alongU ? pe.pos - 0.4 : pe.at), sd = inside22 ? 1 : -1;
49164
50280
  const sdf = roomAt(pe.floor, alongU ? pe.at : pe.pos + 0.4, alongU ? pe.pos + 0.4 : pe.at) ? -1 : 1;
49165
50281
  const u = pe.at + pe.width / 2 + 0.32, face = pe.pos + sdf * th / 2, ry = alongU ? sdf > 0 ? 0 : Math.PI : sdf > 0 ? K.PE : -K.PE;
@@ -49241,7 +50357,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
49241
50357
  var LOT_WALL_BEAM_COLOR = 10132118;
49242
50358
  var BURIED_INSET = 2e-3;
49243
50359
  function installLotPerimeter(K, shared2) {
49244
- const { EPS: EPS4, boxC, bx, colorOf, cursor, freeSpans, pieceRecord } = K;
50360
+ const { EPS: EPS42, boxC, bx, colorOf, cursor, freeSpans, pieceRecord } = K;
49245
50361
  const makeApi = (...a) => K.makeApi(...a);
49246
50362
  const sh = (...a) => K.sh(...a);
49247
50363
  function perimeter() {
@@ -49255,7 +50371,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
49255
50371
  const api = makeApi();
49256
50372
  const houseWalls2 = shared2.ctx.visorScene ? [] : groundWallBoxes(shared2.ctx.r.walls);
49257
50373
  for (const s of lt.perimeter) {
49258
- const alongU = Math.abs(s.v1 - s.v0) < EPS4, L = alongU ? s.v0 : s.u0, a = Math.min(alongU ? s.u0 : s.v0, alongU ? s.u1 : s.v1), b = Math.max(alongU ? s.u0 : s.v0, alongU ? s.u1 : s.v1);
50374
+ const alongU = Math.abs(s.v1 - s.v0) < EPS42, L = alongU ? s.v0 : s.u0, a = Math.min(alongU ? s.u0 : s.v0, alongU ? s.u1 : s.v1), b = Math.max(alongU ? s.u0 : s.v0, alongU ? s.u1 : s.v1);
49259
50375
  const material = s.type === "wall" ? "brick" : s.type === "fence" ? "wood_soft" : "steel";
49260
50376
  const length = Math.hypot(s.u1 - s.u0, s.v1 - s.v0);
49261
50377
  cursor.pc = pieceRecord("lot_wall:" + s.id, material, null, { tags: ["wall"], holder: "ground", holdJoint: footingJointOf(material), embedment: { depth: GROUND_BEAM_DEPTH, width: length } });
@@ -49476,7 +50592,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
49476
50592
  Object.assign(K, defined);
49477
50593
  }
49478
50594
  function installRoofRoofs(K, shared2) {
49479
- const { rectsOf: rectsOf2, EPS: EPS4, OPEN_AREA, Y0, bx, cursor } = K;
50595
+ const { rectsOf: rectsOf2, EPS: EPS42, OPEN_AREA, Y0, bx, cursor } = K;
49480
50596
  const gutter = (...a) => K.gutter(...a);
49481
50597
  const gutterConfig = (...a) => K.gutterConfig(...a);
49482
50598
  const roofRect = (...a) => K.roofRect(...a);
@@ -49499,7 +50615,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
49499
50615
  const lines = shared2.ctx.visorScene ? rs : rs.concat(up);
49500
50616
  const within = (v, k) => v >= Math.min(...rs.map((r) => r[k])) && v <= Math.max(...rs.map((r) => r[k + 2]));
49501
50617
  const xs = [...new Set(lines.flatMap((r) => [r[0], r[2]]).filter((v) => within(v, 0)).map((v) => +v.toFixed(3)))].sort((a, b) => a - b), zs = [...new Set(lines.flatMap((r) => [r[1], r[3]]).filter((v) => within(v, 1)).map((v) => +v.toFixed(3)))].sort((a, b) => a - b);
49502
- const em = (L, x, z) => L.some((r) => x > r[0] + EPS4 && x < r[2] - EPS4 && z > r[1] + EPS4 && z < r[3] - EPS4), nx = xs.length - 1, nz = zs.length - 1;
50618
+ const em = (L, x, z) => L.some((r) => x > r[0] + EPS42 && x < r[2] - EPS42 && z > r[1] + EPS42 && z < r[3] - EPS42), nx = xs.length - 1, nz = zs.length - 1;
49503
50619
  const cxs = (i) => (xs[i] + xs[i + 1]) / 2, czs = (j) => (zs[j] + zs[j + 1]) / 2;
49504
50620
  const occ = [];
49505
50621
  for (let j = 0; j < nz; j++) {
@@ -49512,7 +50628,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
49512
50628
  return true;
49513
50629
  };
49514
50630
  const pe = (x0, z0, x1, z1) => {
49515
- const cs = R.rooms.filter((c) => c.floor === f && rectsOf2(c).some((r) => r[0] < x1 - EPS4 && r[2] > x0 + EPS4 && r[1] < z1 - EPS4 && r[3] > z0 + EPS4));
50631
+ const cs = R.rooms.filter((c) => c.floor === f && rectsOf2(c).some((r) => r[0] < x1 - EPS42 && r[2] > x0 + EPS42 && r[1] < z1 - EPS42 && r[3] > z0 + EPS42));
49516
50632
  return Y0(f) + Math.max(...cs.map((c) => c.ceiling)) + 0.2;
49517
50633
  };
49518
50634
  if (type === "slab") {
@@ -55218,7 +56334,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
55218
56334
  var SWITCH_HEIGHT = 1.1;
55219
56335
  var SWITCH_REACH = 0.05;
55220
56336
  function installInteractionFittings(K, shared2) {
55221
- const { t, EPS: EPS4, OPEN_AREA, Y0, applyPiece, bx, cursor, definePiece, gates, lightOn, roomAt, slideDirection, toggleLight, togglePiece } = K;
56337
+ const { t, EPS: EPS42, OPEN_AREA, Y0, applyPiece, bx, cursor, definePiece, gates, lightOn, roomAt, slideDirection, toggleLight, togglePiece } = K;
55222
56338
  const I = () => shared2.inter;
55223
56339
  const house = () => shared2.ctx.r;
55224
56340
  function gatesInteractive() {
@@ -55314,7 +56430,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
55314
56430
  }
55315
56431
  function putSwitch(c, p) {
55316
56432
  const R = house(), f = p.floor, alongU = p.axis === "u", L = p.pos, a = p.at - p.width / 2, b = p.at + p.width / 2;
55317
- const wref = R.walls.find((w) => w.floor === f && w.axis === p.axis && Math.abs((alongU ? w.v0 : w.u0) - L) < EPS4), th = wref ? wref.thickness || 0.15 : 0.15;
56433
+ const wref = R.walls.find((w) => w.floor === f && w.axis === p.axis && Math.abs((alongU ? w.v0 : w.u0) - L) < EPS42), th = wref ? wref.thickness || 0.15 : 0.15;
55318
56434
  const inside22 = (sd2) => {
55319
56435
  const cc = roomAt(f, alongU ? p.at : L + sd2 * 0.4, alongU ? L + sd2 * 0.4 : p.at);
55320
56436
  return !!cc && cc.id === c.id;
@@ -55324,8 +56440,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
55324
56440
  const sides = p.hinge === "end" ? [-1, 1] : [1, -1];
55325
56441
  for (const ld of sides) {
55326
56442
  const u = ld > 0 ? b + 0.2 : a - 0.2, lo = u - 0.1, hi = u + 0.1;
55327
- const wall = R.walls.some((w) => w.floor === f && w.axis === p.axis && w.type === "wall" && Math.abs((alongU ? w.v0 : w.u0) - L) < EPS4 && Math.min(alongU ? w.u0 : w.v0, alongU ? w.u1 : w.v1) <= lo - 0.08 && Math.max(alongU ? w.u0 : w.v0, alongU ? w.u1 : w.v1) >= hi + 0.08);
55328
- const free = !R.doors.concat(R.windows).some((o) => o.floor === f && o.axis === p.axis && Math.abs(o.pos - L) < EPS4 && o.at + o.width / 2 > lo - 0.05 && o.c - o.width / 2 < hi + 0.05);
56443
+ const wall = R.walls.some((w) => w.floor === f && w.axis === p.axis && w.type === "wall" && Math.abs((alongU ? w.v0 : w.u0) - L) < EPS42 && Math.min(alongU ? w.u0 : w.v0, alongU ? w.u1 : w.v1) <= lo - 0.08 && Math.max(alongU ? w.u0 : w.v0, alongU ? w.u1 : w.v1) >= hi + 0.08);
56444
+ const free = !R.doors.concat(R.windows).some((o) => o.floor === f && o.axis === p.axis && Math.abs(o.pos - L) < EPS42 && o.at + o.width / 2 > lo - 0.05 && o.c - o.width / 2 < hi + 0.05);
55329
56445
  if (!wall || !free) continue;
55330
56446
  const y0 = Y0(f), yc = y0 + SWITCH_HEIGHT, face = L + sd * th / 2, roomId = c.id, g0 = cursor.group;
55331
56447
  if (!shared2.ctx.visorScene && behindFurniture(f, alongU ? u : face + sd * SWITCH_REACH, alongU ? face + sd * SWITCH_REACH : u)) continue;
@@ -57015,6 +58131,25 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
57015
58131
  }
57016
58132
  return [...groups.values()];
57017
58133
  };
58134
+ function subtract(boxes, cuts) {
58135
+ let out = [...boxes];
58136
+ for (const k of cuts) {
58137
+ const next = [];
58138
+ for (const b of out) {
58139
+ if (k.a >= b.b - EPSILON22 || k.b <= b.a + EPSILON22 || k.y0 >= b.y1 - EPSILON22 || k.y1 <= b.y0 + EPSILON22) {
58140
+ next.push(b);
58141
+ continue;
58142
+ }
58143
+ const y0 = Math.max(b.y0, k.y0), y1 = Math.min(b.y1, k.y1);
58144
+ if (y0 - b.y0 > EPSILON22) next.push({ a: b.a, b: b.b, y0: b.y0, y1: y0 });
58145
+ if (b.y1 - y1 > EPSILON22) next.push({ a: b.a, b: b.b, y0: y1, y1: b.y1 });
58146
+ if (k.a - b.a > EPSILON22) next.push({ a: b.a, b: k.a, y0, y1 });
58147
+ if (b.b - k.b > EPSILON22) next.push({ a: k.b, b: b.b, y0, y1 });
58148
+ }
58149
+ out = next;
58150
+ }
58151
+ return out;
58152
+ }
57018
58153
  function mergeSpans(spans, share = JOINT_SHARE) {
57019
58154
  const runs = [];
57020
58155
  const unitLengths = /* @__PURE__ */ new Map();
@@ -57065,7 +58200,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
57065
58200
  const point = new THREE.Vector3();
57066
58201
  const out = [];
57067
58202
  for (const part of parts2) {
57068
- const boxes = mergeSpans(part.spans);
58203
+ const boxes = part.gone?.length ? subtract(mergeSpans(part.spans), part.gone) : mergeSpans(part.spans);
57069
58204
  for (const s of line.open ? mergeSpans(carve(boxes, line.open), 0) : boxes) {
57070
58205
  const along2 = line.start + (s.a + s.b) / 2;
57071
58206
  point.set(line.alongU ? along2 : part.mid, (s.y0 + s.y1) / 2, line.alongU ? part.mid : along2).applyMatrix4(toMesh);
@@ -57117,18 +58252,19 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
57117
58252
  if (list2) mesh2.userData.collapsedRanges = list2.filter((r) => r[0] !== v0);
57118
58253
  withdrawSolids(mesh2, v0);
57119
58254
  }
58255
+ var hash2 = (i, j) => {
58256
+ const s = Math.sin(i * 127.1 + j * 311.7) * 43758.5453;
58257
+ return s - Math.floor(s);
58258
+ };
57120
58259
  function noise2(x, y, cell) {
57121
- const h = (i2, j2) => {
57122
- const s = Math.sin(i2 * 127.1 + j2 * 311.7) * 43758.5453;
57123
- return s - Math.floor(s);
57124
- };
57125
58260
  const fx = x / cell, fy = y / cell, i = Math.floor(fx), j = Math.floor(fy), u = fx - i, v = fy - j;
57126
58261
  const su = u * u * (3 - 2 * u), sv = v * v * (3 - 2 * v);
57127
- return (h(i, j) * (1 - su) + h(i + 1, j) * su) * (1 - sv) + (h(i, j + 1) * (1 - su) + h(i + 1, j + 1) * su) * sv;
58262
+ return (hash2(i, j) * (1 - su) + hash2(i + 1, j) * su) * (1 - sv) + (hash2(i, j + 1) * (1 - su) + hash2(i + 1, j + 1) * su) * sv;
57128
58263
  }
57129
58264
  var MASK_TEXEL = 0.02;
57130
58265
  var SPALL_MIN = 0.025;
57131
58266
  var SPALL_RAGGED = 0.045;
58267
+ var PLASTER_REACH = { least: SPALL_MIN, band: SPALL_RAGGED };
57132
58268
  var COVER2 = 0.015;
57133
58269
  var LUMP_BAR_INSET = 0.035;
57134
58270
  var LUMPS_PER_BAR = 1;
@@ -57571,11 +58707,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
57571
58707
  function publishStanding(view) {
57572
58708
  if (!view.saved) return;
57573
58709
  const { mask } = view;
58710
+ const along2 = (p) => (mask.alongU ? p[0] : p[2]) - mask.start;
57574
58711
  const parts2 = view.parts.map((id) => {
57575
58712
  const part = structure.byId.get(id);
57576
58713
  const thick = mask.alongU ? part.aabb[3] - part.aabb[1] : part.aabb[2] - part.aabb[0];
57577
58714
  const mid = mask.alongU ? (part.aabb[1] + part.aabb[3]) / 2 : (part.aabb[0] + part.aabb[2]) / 2;
57578
- return { spans: view.kept.get(id) ?? [], thick, mid };
58715
+ const gone = (view.chips.get(id) ?? []).map((k) => ({ a: along2(k.center) - k.along, b: along2(k.center) + k.along, y0: k.center[1] - k.up, y1: k.center[1] + k.up }));
58716
+ return { spans: view.kept.get(id) ?? [], gone, thick, mid };
57579
58717
  });
57580
58718
  const line = { alongU: mask.alongU, start: mask.start, open: view.core };
57581
58719
  view.items.forEach((it, k) => publishSolids(it.mesh, it.v0, it.v1, k === 0 ? standingSolids(THREE, house, it.mesh, line, parts2) : []));
@@ -57622,7 +58760,19 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
57622
58760
  mask.data.fill(0);
57623
58761
  core.data.fill(0);
57624
58762
  const stamp = (m, s0, s1, y0, y1, inside22) => stampMask(m, { s0, s1, y0, y1, reach: reach2 }, inside22);
57625
- const plaster = (d, s, y) => isPlasterGone(d, { least: SPALL_MIN, band: SPALL_RAGGED }, () => ragged(s, y));
58763
+ const texel = { s: 0, y: 0 };
58764
+ const raggedAtTexel = () => ragged(texel.s, texel.y);
58765
+ const coreNoiseAtTexel = () => noise2(texel.s * 1.7, texel.y * 1.3, 0.012);
58766
+ const plaster = (d, s, y) => {
58767
+ texel.s = s;
58768
+ texel.y = y;
58769
+ return isPlasterGone(d, PLASTER_REACH, raggedAtTexel);
58770
+ };
58771
+ const coreThrough = (distance2, depth, s, y) => {
58772
+ texel.s = s;
58773
+ texel.y = y;
58774
+ return isCoreThrough(distance2, depth, coreNoiseAtTexel);
58775
+ };
57626
58776
  for (const c of holes) stamp(mask, c.a, c.b, c.y0, c.y1, (s, y) => plaster(boxDistance(s, y, c.a, c.b, c.y0, c.y1), s, y));
57627
58777
  for (const d of discs) stamp(mask, d.s - d.r, d.s + d.r, d.y - d.r, d.y + d.r, (s, y) => plaster(Math.max(0, Math.hypot(s - d.s, y - d.y) - d.r), s, y));
57628
58778
  for (const f of flakes) {
@@ -57631,7 +58781,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
57631
58781
  }
57632
58782
  for (const p of pits) {
57633
58783
  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));
57634
- stamp(core, p.s - p.rs, p.s + p.rs, p.y - p.ry, p.y + p.ry, (s, y) => isCoreThrough(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)));
58784
+ stamp(core, p.s - p.rs, p.s + p.rs, p.y - p.ry, p.y + p.ry, (s, y) => coreThrough(ellipseDistance(s, y, p.s, p.y, p.rs, p.ry), 0.35 * Math.min(p.rs, p.ry), s, y));
57635
58785
  }
57636
58786
  for (const q of pillars) {
57637
58787
  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));
@@ -58375,7 +59525,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58375
59525
  const left = breach.standing(part.id);
58376
59526
  if (!left) return true;
58377
59527
  const s0 = (left.alongU ? lx : lz) - left.start;
58378
- if (left.spans.some((c) => c.b > s0 - radius && c.a < s0 + radius && c.y1 > Math.min(ly0, ly1) && c.y0 < Math.max(ly0, ly1))) return true;
59528
+ const low1 = Math.min(ly0, ly1), high1 = Math.max(ly0, ly1);
59529
+ for (const c of left.spans) if (c.b > s0 - radius && c.a < s0 + radius && c.y1 > low1 && c.y0 < high1) return true;
58379
59530
  }
58380
59531
  return false;
58381
59532
  };
@@ -59219,7 +60370,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
59219
60370
  return { u: P.u - Math.sign(P.frontU || 0) * PANEL_RECESS, v: P.v - Math.sign(P.frontV || 0) * PANEL_RECESS, y0: P.y - h / 2 + PANEL_LIFT - BOX_CHASE_CLEAR, y1: P.y + h / 2 + PANEL_LIFT + BOX_CHASE_CLEAR, radius: w / 2, depth: 0 };
59220
60371
  }
59221
60372
  function installBuildBuild(K, shared2) {
59222
- const { THREE, cfg, rectsOf: rectsOf2, invalidateShadow, colliderChanged, VERSION: VERSION2, CARS, EPS: EPS4, LIGHTS, MIRRORS, Y0, animateClotheslines, animateDoors, animateInteractive, applyLeaf, applyOutbuildings, applyPart, applyPiece, assembleInteractive, baseboardAndSidewalk, buildStairs, building, carModel, chooseMirror, closeScene, collideAt, createWater, cursor, doorText, doors, electricalStructure, elevator, floorsAndSlabs, gatesInteractive, houseItems, ivAssemble, ivBuild, ivDispose, ivParts, ivPublish, ivUpdate, lightOn, linkDoorLeaves, mailboxInteractive, walkInInteractive, newInteractiveState, newMirrorState, outbuildings, paths, perimeter, placeSwitches, roofs, roomAt, solar, targetOf, terrain, toggleDoor, toggleLight, walls, waterPipes, drainPipes, windows, props, TYPES, IVK, VEG, vegMaterials, markGroups, assembleStructure, pieceRecord, createHouseDestruction, newState, enter, tagDamage } = K;
60373
+ const { THREE, cfg, rectsOf: rectsOf2, invalidateShadow, colliderChanged, VERSION: VERSION2, CARS, EPS: EPS42, LIGHTS, MIRRORS, Y0, animateClotheslines, animateDoors, animateInteractive, applyLeaf, applyOutbuildings, applyPart, applyPiece, assembleInteractive, baseboardAndSidewalk, buildStairs, building, carModel, chooseMirror, closeScene, collideAt, createWater, cursor, doorText, doors, electricalStructure, elevator, floorsAndSlabs, gatesInteractive, houseItems, ivAssemble, ivBuild, ivDispose, ivParts, ivPublish, ivUpdate, lightOn, linkDoorLeaves, mailboxInteractive, walkInInteractive, newInteractiveState, newMirrorState, outbuildings, paths, perimeter, placeSwitches, roofs, roomAt, solar, targetOf, terrain, toggleDoor, toggleLight, walls, waterPipes, drainPipes, windows, props, TYPES, IVK, VEG, vegMaterials, markGroups, assembleStructure, pieceRecord, createHouseDestruction, newState, enter, tagDamage } = K;
59223
60374
  function build(r0, options) {
59224
60375
  const opts = options || {};
59225
60376
  const r = withLaidConduits(applyOutbuildings(r0), !!(opts.constructionStages || opts.constructionLevel != null));
@@ -59494,7 +60645,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
59494
60645
  });
59495
60646
  cars.push({ i, k: C.k, seed: C.seed, pos: [C.x, C.y, C.z], ry: C.ry || 0, scale: s, parts: ids });
59496
60647
  });
59497
- const wallAt = (f, axis, L) => r.walls.find((w) => w.floor === f && w.axis === axis && Math.abs((axis === "u" ? w.v0 : w.u0) - L) < EPS4);
60648
+ const wallAt = (f, axis, L) => r.walls.find((w) => w.floor === f && w.axis === axis && Math.abs((axis === "u" ? w.v0 : w.u0) - L) < EPS42);
59498
60649
  for (const j of r.windows) {
59499
60650
  const alongU = j.axis === "u", y0 = Y0(j.floor), a = j.at - j.width / 2, b = j.at + j.width / 2, w = wallAt(j.floor, j.axis, j.pos), th = w ? w.thickness || 0.15 : 0.15, L = j.pos, id = "window:" + j.id;
59500
60651
  const jy0 = j.y0, jy1 = j.y1;
@@ -60001,7 +61152,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
60001
61152
  var HOLD_REACH2 = 0.05;
60002
61153
  var BACK_TOUCH = 0.02;
60003
61154
  var AGAINST_WALL = 0.1;
60004
- var SOFT = /* @__PURE__ */ new Set(["fabric", "paper", "foliage"]);
61155
+ var SOFT2 = /* @__PURE__ */ new Set(["fabric", "paper", "foliage"]);
60005
61156
  var gapOf = (a, b) => Math.max(0, ...[0, 1, 2].map((k) => Math.max(a.min[k] - b.max[k], b.min[k] - a.max[k])));
60006
61157
  function groupsOf(parts2, joints) {
60007
61158
  const root = new Map(parts2.map((part) => [part.id, part.id]));
@@ -60072,7 +61223,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
60072
61223
  continue;
60073
61224
  }
60074
61225
  const againstWall = held.length === 0 || held.some((part) => boxOf3(part.id).min[2] <= back2 + AGAINST_WALL);
60075
- const onWall = againstWall ? group.filter((part) => !SOFT.has(part.material) && boxOf3(part.id).min[2] <= back2 + BACK_TOUCH) : [];
61226
+ const onWall = againstWall ? group.filter((part) => !SOFT2.has(part.material) && boxOf3(part.id).min[2] <= back2 + BACK_TOUCH) : [];
60076
61227
  if (onWall.length === 0) continue;
60077
61228
  for (const part of onWall) part.anchored = true;
60078
61229
  changed = true;