@adatechnology/game-weapons-three 0.29.8 → 0.29.10

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.
@@ -432,12 +432,12 @@ var GameWeaponsThree = (() => {
432
432
  };
433
433
  var STAGE_EVENT = "stage";
434
434
  var scaleClip = (clip, duration) => {
435
- const factor = clip.duration > 0 ? duration / clip.duration : 1;
435
+ const factor2 = clip.duration > 0 ? duration / clip.duration : 1;
436
436
  return {
437
437
  ...clip,
438
438
  duration,
439
- keys: clip.keys.map((key2) => ({ ...key2, t: key2.t * factor })),
440
- ...clip.events ? { events: clip.events.map((event) => ({ ...event, t: event.t * factor })) } : {}
439
+ keys: clip.keys.map((key2) => ({ ...key2, t: key2.t * factor2 })),
440
+ ...clip.events ? { events: clip.events.map((event) => ({ ...event, t: event.t * factor2 })) } : {}
441
441
  };
442
442
  };
443
443
  var ZERO = [0, 0, 0];
@@ -15397,9 +15397,9 @@ var GameWeaponsThree = (() => {
15397
15397
  }
15398
15398
  };
15399
15399
  var defaultFaultChance = (context) => {
15400
- const factor = context.def.action.kind === "firearm" ? context.def.action.faultFactor ?? 1 : 1;
15400
+ const factor2 = context.def.action.kind === "firearm" ? context.def.action.faultFactor ?? 1 : 1;
15401
15401
  const overheat = 1 + Math.max(0, context.heat - DEFAULT_HEAT.faultFrom) / DEFAULT_HEAT.faultSpan;
15402
- return context.condition.faultChance * factor * overheat;
15402
+ return context.condition.faultChance * factor2 * overheat;
15403
15403
  };
15404
15404
  var DEFAULT_RULES = {
15405
15405
  faults: true,
@@ -15479,11 +15479,11 @@ var GameWeaponsThree = (() => {
15479
15479
  var STILL_STEPS = 2;
15480
15480
  var STILL_SHARE = 0.05;
15481
15481
  var bounce = (velocity2, normal, ground, rules) => {
15482
- const along2 = dot(velocity2, normal);
15483
- if (along2 >= 0) return velocity2;
15482
+ const along3 = dot(velocity2, normal);
15483
+ if (along3 >= 0) return velocity2;
15484
15484
  const restitution = ground ? rules.groundRestitution : rules.wallRestitution;
15485
15485
  const friction = ground ? rules.groundFriction : 1;
15486
- const normalPart = [normal[0] * along2, normal[1] * along2, normal[2] * along2];
15486
+ const normalPart = [normal[0] * along3, normal[1] * along3, normal[2] * along3];
15487
15487
  return [
15488
15488
  (velocity2[0] - normalPart[0]) * friction - normalPart[0] * restitution,
15489
15489
  (velocity2[1] - normalPart[1]) * friction - normalPart[1] * restitution,
@@ -15543,12 +15543,12 @@ var GameWeaponsThree = (() => {
15543
15543
  isTriggeredBy(trigger) {
15544
15544
  return this.triggers.has(trigger);
15545
15545
  }
15546
- step(dt, probe) {
15546
+ step(dt, probe2) {
15547
15547
  const events = [];
15548
15548
  if (this.isDone) return events;
15549
15549
  const seconds = Math.max(0, dt);
15550
15550
  const slice = this.fuseLeft === void 0 ? seconds : Math.min(seconds, this.fuseLeft);
15551
- this.fly(slice, probe, events);
15551
+ this.fly(slice, probe2, events);
15552
15552
  if (this.isDone) return events;
15553
15553
  if (this.isLaunched && this.isSpent()) {
15554
15554
  events.push(this.detonate(this.clock >= this.rules.selfDestructSeconds ? "timer" : "impact"));
@@ -15574,7 +15574,7 @@ var GameWeaponsThree = (() => {
15574
15574
  if (this.clock >= this.rules.selfDestructSeconds) return true;
15575
15575
  return !this.moves() || this.stillSteps >= STILL_STEPS;
15576
15576
  }
15577
- fly(seconds, probe, events) {
15577
+ fly(seconds, probe2, events) {
15578
15578
  if (seconds <= 0 || !this.moves()) {
15579
15579
  this.clock += Math.max(0, seconds);
15580
15580
  return;
@@ -15582,7 +15582,7 @@ var GameWeaponsThree = (() => {
15582
15582
  const start = this.position;
15583
15583
  this.velocity = [this.velocity[0], this.velocity[1] - this.rules.gravity * seconds, this.velocity[2]];
15584
15584
  const next = [this.position[0] + this.velocity[0] * seconds, this.position[1] + this.velocity[1] * seconds, this.position[2] + this.velocity[2] * seconds];
15585
- const hit = probe?.(this.position, next) ?? null;
15585
+ const hit = probe2?.(this.position, next) ?? null;
15586
15586
  const target = hit ? hit.point : next;
15587
15587
  const moved = distance(this.position, target);
15588
15588
  const planned = distance(this.position, next);
@@ -16621,9 +16621,9 @@ var GameWeaponsThree = (() => {
16621
16621
  if (this.isWorking()) return false;
16622
16622
  if (this.underActive && this.under) return this.under.reload(request);
16623
16623
  const base2 = this.action;
16624
- const factor = this.load.secondReloadFactor;
16625
- const isFast = factor !== 1 && this.reloadCount % 2 === 1 && base2.kind === "firearm";
16626
- if (isFast && base2.kind === "firearm") this.action = { ...base2, reload: base2.reload * factor, ...base2.timings ? { timings: { ...base2.timings, reload: base2.timings.reload * factor, ...base2.timings.reloadEmpty === void 0 ? {} : { reloadEmpty: base2.timings.reloadEmpty * factor } } } : {} };
16624
+ const factor2 = this.load.secondReloadFactor;
16625
+ const isFast = factor2 !== 1 && this.reloadCount % 2 === 1 && base2.kind === "firearm";
16626
+ if (isFast && base2.kind === "firearm") this.action = { ...base2, reload: base2.reload * factor2, ...base2.timings ? { timings: { ...base2.timings, reload: base2.timings.reload * factor2, ...base2.timings.reloadEmpty === void 0 ? {} : { reloadEmpty: base2.timings.reloadEmpty * factor2 } } } : {} };
16627
16627
  const started = super.reload(request);
16628
16628
  this.action = base2;
16629
16629
  if (started) this.reloadCount += 1;
@@ -16693,9 +16693,9 @@ var GameWeaponsThree = (() => {
16693
16693
  }
16694
16694
  /** The rules with the chance of a fault scaled by the accessories (a drum magazine jams more); the very rules when nothing scales it. */
16695
16695
  faultRules() {
16696
- const factor = this.load.faultFactor;
16697
- if (factor === 1) return this.rules;
16698
- return { ...this.rules, faultChance: (context) => this.rules.faultChance(context) * factor };
16696
+ const factor2 = this.load.faultFactor;
16697
+ if (factor2 === 1) return this.rules;
16698
+ return { ...this.rules, faultChance: (context) => this.rules.faultChance(context) * factor2 };
16699
16699
  }
16700
16700
  jam(fault, at4, res) {
16701
16701
  this._fault = fault;
@@ -19421,7 +19421,7 @@ ${problems.map((problem) => ` - ${problem}`).join("\n")}`);
19421
19421
  const found = collect(list2);
19422
19422
  const keepRoots = options.keep === void 0 ? [] : Array.isArray(options.keep) ? options.keep : [options.keep];
19423
19423
  const releasing = new Set(list2);
19424
- for (const keep of keepRoots) {
19424
+ for (const keep2 of keepRoots) {
19425
19425
  const walk = (o) => {
19426
19426
  if (releasing.has(o)) return;
19427
19427
  const owner = o;
@@ -19437,7 +19437,7 @@ ${problems.map((problem) => ` - ${problem}`).join("\n")}`);
19437
19437
  }
19438
19438
  for (const c of o.children) walk(c);
19439
19439
  };
19440
- walk(keep);
19440
+ walk(keep2);
19441
19441
  }
19442
19442
  for (const g of found.geometries) {
19443
19443
  if (shared(g)) continue;
@@ -19459,14 +19459,14 @@ ${problems.map((problem) => ` - ${problem}`).join("\n")}`);
19459
19459
  }
19460
19460
  function discardObject3D(objects, options = {}) {
19461
19461
  const list2 = Array.isArray(objects) ? objects : [objects];
19462
- const keep = options.keep === void 0 ? [] : Array.isArray(options.keep) ? [...options.keep] : [options.keep];
19462
+ const keep2 = options.keep === void 0 ? [] : Array.isArray(options.keep) ? [...options.keep] : [options.keep];
19463
19463
  for (const object2 of list2) {
19464
19464
  let top = object2;
19465
19465
  while (top.parent) top = top.parent;
19466
19466
  object2.removeFromParent();
19467
- if (top !== object2 && !keep.includes(top)) keep.push(top);
19467
+ if (top !== object2 && !keep2.includes(top)) keep2.push(top);
19468
19468
  }
19469
- return releaseObject3D(list2, { keep });
19469
+ return releaseObject3D(list2, { keep: keep2 });
19470
19470
  }
19471
19471
  function isMesh(o) {
19472
19472
  return !!o && o.isMesh === true;
@@ -21865,8 +21865,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
21865
21865
  const sorted = [0, 1, 2].sort((x, y) => dims[x] - dims[y]);
21866
21866
  const t = sorted[0];
21867
21867
  const [u, v] = [sorted[1], sorted[2]].sort((x, y) => x - y);
21868
- const along2 = dims[u] >= dims[v] ? u : v;
21869
- const across2 = along2 === u ? v : u;
21868
+ const along3 = dims[u] >= dims[v] ? u : v;
21869
+ const across2 = along3 === u ? v : u;
21870
21870
  const layers = clamp(Math.round(dims[t] / PLY / 2), 2, 3);
21871
21871
  const pitch = dims[t] / layers;
21872
21872
  const th = Math.min(pitch, PLY_SHEET);
@@ -21880,7 +21880,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
21880
21880
  if (out.length >= limit) return out;
21881
21881
  if (rnd2() < 0.35) {
21882
21882
  const strand = cell.s[across2] * (0.15 + 0.2 * rnd2());
21883
- out.push({ center: cell.c, size: [cell.s[along2], strand, th * 0.7], q: frame(along2, across2, t), shape: "splinter", weight: cell.s[along2] * strand * th });
21883
+ out.push({ center: cell.c, size: [cell.s[along3], strand, th * 0.7], q: frame(along3, across2, t), shape: "splinter", weight: cell.s[along3] * strand * th });
21884
21884
  } else {
21885
21885
  out.push({ center: cell.c, size: [cell.s[u], cell.s[v], th], q: frame(u, v, t, (rnd2() - 0.5) * 0.5), shape: "scrap", weight: cell.s[u] * cell.s[v] * th });
21886
21886
  }
@@ -21993,8 +21993,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
21993
21993
  const share = Math.max(1, Math.round(inp.maxFragments * volumes[i] / total));
21994
21994
  const hit = [inp.hit[0] - solid2.center[0], inp.hit[1] - solid2.center[1], inp.hit[2] - solid2.center[2]];
21995
21995
  const { cut, solids: _all, ...rest2 } = inp;
21996
- const along2 = cut ? [0, 1, 2].sort((a, b) => solid2.size[b] - solid2.size[a])[0] : -1;
21997
- const inside3 = cut && Math.abs(cut.at - solid2.center[along2]) < solid2.size[along2] / 2 ? { cut: { at: cut.at - solid2.center[along2], gap: cut.gap } } : {};
21996
+ const along3 = cut ? [0, 1, 2].sort((a, b) => solid2.size[b] - solid2.size[a])[0] : -1;
21997
+ const inside3 = cut && Math.abs(cut.at - solid2.center[along3]) < solid2.size[along3] / 2 ? { cut: { at: cut.at - solid2.center[along3], gap: cut.gap } } : {};
21998
21998
  for (const f of planBox({ ...rest2, ...inside3, dims: [solid2.size[0], solid2.size[1], solid2.size[2]], hit, maxFragments: share, thickness: Math.min(inp.thickness, Math.min(...solid2.size)) })) {
21999
21999
  out.push({ ...f, center: [f.center[0] + solid2.center[0], f.center[1] + solid2.center[1], f.center[2] + solid2.center[2]] });
22000
22000
  }
@@ -22212,11 +22212,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
22212
22212
  lo0 = Math.min(lo0, cell.center[u] - cell.size[u] / 2);
22213
22213
  lo1 = Math.min(lo1, cell.center[v] - cell.size[v] / 2);
22214
22214
  }
22215
- let along2 = 1, up = 1;
22215
+ let along3 = 1, up = 1;
22216
22216
  for (let grow2 = 0; ; grow2++) {
22217
22217
  const bins = /* @__PURE__ */ new Map();
22218
22218
  for (const cell of cells) {
22219
- const key2 = `${Math.floor((cell.center[u] - lo0) / (along2 * unit[0]))}:${Math.floor((cell.center[v] - lo1) / (up * unit[1]))}`;
22219
+ const key2 = `${Math.floor((cell.center[u] - lo0) / (along3 * unit[0]))}:${Math.floor((cell.center[v] - lo1) / (up * unit[1]))}`;
22220
22220
  const bin2 = bins.get(key2) ?? { lo: [Infinity, Infinity, Infinity], hi: [-Infinity, -Infinity, -Infinity] };
22221
22221
  for (let k = 0; k < 3; k++) {
22222
22222
  bin2.lo[k] = Math.min(bin2.lo[k], cell.center[k] - cell.size[k] / 2);
@@ -22228,9 +22228,24 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
22228
22228
  return [...bins.values()].map(({ lo, hi }) => ({ center: [(lo[0] + hi[0]) / 2, (lo[1] + hi[1]) / 2, (lo[2] + hi[2]) / 2], size: [hi[0] - lo[0], hi[1] - lo[1], hi[2] - lo[2]] }));
22229
22229
  }
22230
22230
  if (grow2 % 2 === 0) up++;
22231
- else along2++;
22231
+ else along3++;
22232
22232
  }
22233
22233
  };
22234
+ function put(out, at4, value) {
22235
+ if (at4 < out.length) out[at4] = value;
22236
+ else out.push(value);
22237
+ }
22238
+ function sortFirst(out, count) {
22239
+ for (let i = 1; i < count; i++) {
22240
+ const value = out[i];
22241
+ let j = i - 1;
22242
+ while (j >= 0 && out[j] > value) {
22243
+ out[j + 1] = out[j];
22244
+ j--;
22245
+ }
22246
+ out[j + 1] = value;
22247
+ }
22248
+ }
22234
22249
  var PART_GRID_MIN_PARTS = 64;
22235
22250
  var MAX_CELLS_PER_AXIS = 64;
22236
22251
  var PAD = 1e-4;
@@ -22247,8 +22262,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
22247
22262
  if (![...min2, ...max2].every(Number.isFinite)) {
22248
22263
  return {
22249
22264
  candidates(_origin, _direction, _maxDistance, out) {
22250
- out.length = 0;
22251
- for (let index = 0; index < parts2.length; index++) out.push(index);
22265
+ for (let index = 0; index < parts2.length; index++) put(out, index, index);
22266
+ return parts2.length;
22252
22267
  }
22253
22268
  };
22254
22269
  }
@@ -22288,20 +22303,20 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
22288
22303
  let stamp = 0;
22289
22304
  return {
22290
22305
  candidates(origin, direction, maxDistance, out) {
22291
- out.length = 0;
22306
+ let count = 0;
22292
22307
  let t0 = 0;
22293
22308
  let t1 = maxDistance;
22294
22309
  for (let k = 0; k < 3; k++) {
22295
22310
  const d = direction[k];
22296
22311
  if (Math.abs(d) < 1e-12) {
22297
- if (origin[k] < min2[k] || origin[k] > max2[k]) return;
22312
+ if (origin[k] < min2[k] || origin[k] > max2[k]) return 0;
22298
22313
  continue;
22299
22314
  }
22300
22315
  const a = (min2[k] - origin[k]) / d;
22301
22316
  const b = (max2[k] - origin[k]) / d;
22302
22317
  t0 = Math.max(t0, Math.min(a, b));
22303
22318
  t1 = Math.min(t1, Math.max(a, b));
22304
- if (t0 > t1) return;
22319
+ if (t0 > t1) return 0;
22305
22320
  }
22306
22321
  stamp++;
22307
22322
  if (stamp === 4294967295) {
@@ -22321,7 +22336,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
22321
22336
  const index = items[k];
22322
22337
  if (seen[index] === stamp) continue;
22323
22338
  seen[index] = stamp;
22324
- out.push(index);
22339
+ put(out, count++, index);
22325
22340
  }
22326
22341
  if (nx <= ny && nx <= nz) {
22327
22342
  if (nx > t1) break;
@@ -22340,7 +22355,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
22340
22355
  nz += ez;
22341
22356
  }
22342
22357
  }
22343
- if (out.length > 1) out.sort((a, b) => a - b);
22358
+ sortFirst(out, count);
22359
+ return count;
22344
22360
  }
22345
22361
  };
22346
22362
  }
@@ -22415,14 +22431,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
22415
22431
  const step = count > 1 && room / (count - 1) < spacing ? room / (count - 1) : spacing;
22416
22432
  return Array.from({ length: count }, (_, i) => (i - (count - 1) / 2) * step);
22417
22433
  };
22418
- var bar = (axis2, along2, fixed2) => {
22434
+ var bar = (axis2, along3, fixed2) => {
22419
22435
  const a = [0, 0, 0], b = [0, 0, 0];
22420
22436
  for (const [index, value] of fixed2) {
22421
22437
  a[index] = value;
22422
22438
  b[index] = value;
22423
22439
  }
22424
- a[axis2] = -along2;
22425
- b[axis2] = along2;
22440
+ a[axis2] = -along3;
22441
+ b[axis2] = along3;
22426
22442
  return [a, b];
22427
22443
  };
22428
22444
  var isMember = (dims, role) => {
@@ -23254,7 +23270,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
23254
23270
  };
23255
23271
  var analyzeWind = (parts2, c, ground) => {
23256
23272
  const [dx, dz] = c.direction;
23257
- const along2 = (p) => {
23273
+ const along3 = (p) => {
23258
23274
  const cx = (p.min[0] + p.max[0]) / 2, cz = (p.min[2] + p.max[2]) / 2;
23259
23275
  const hx = (p.max[0] - p.min[0]) / 2, hz2 = (p.max[2] - p.min[2]) / 2;
23260
23276
  return {
@@ -23264,7 +23280,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
23264
23280
  dv: 2 * (Math.abs(dz) * hx + Math.abs(dx) * hz2)
23265
23281
  };
23266
23282
  };
23267
- const g = parts2.map(along2);
23283
+ const g = parts2.map(along3);
23268
23284
  let topY = ground;
23269
23285
  let resists = false;
23270
23286
  for (const p of parts2) {
@@ -25178,6 +25194,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25178
25194
  var FOOT_BAND = 0.03;
25179
25195
  var SEAM_STATIONS = 5;
25180
25196
  var BEAM_PIECES = 4;
25197
+ var SAG_STATIONS = BEAM_PIECES + 1;
25181
25198
  var SLENDER = 4;
25182
25199
  var MAX_DOF = 1500;
25183
25200
  var MECHANISM = 0.5;
@@ -25209,6 +25226,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25209
25226
  const r = t / b;
25210
25227
  return b * t ** 3 * (1 / 3 - 0.21 * r * (1 - r ** 4 / 12));
25211
25228
  }
25229
+ var NO_PLACES = new Int32Array(0);
25212
25230
  var AXES = [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
25213
25231
  function beamOf(part) {
25214
25232
  const d = part.dims;
@@ -25245,8 +25263,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25245
25263
  if (d[2] > d[a]) a = 2;
25246
25264
  const du = d[(a + 1) % 3];
25247
25265
  const dv = d[(a + 2) % 3];
25248
- const along2 = beam.part.grain === void 0 || beam.part.grain === a;
25249
- const e = (along2 ? elastic.alongGPa : elastic.acrossGPa ?? elastic.alongGPa) * 1e9;
25266
+ const along3 = beam.part.grain === void 0 || beam.part.grain === a;
25267
+ const e = (along3 ? elastic.alongGPa : elastic.acrossGPa ?? elastic.alongGPa) * 1e9;
25250
25268
  const g = elastic.shearGPa * 1e9;
25251
25269
  if (beam.part.round && a === 1) {
25252
25270
  const r = du / 2;
@@ -25353,17 +25371,17 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25353
25371
  let c = (n + 2) % 3;
25354
25372
  if (size[c] > size[w]) [w, c] = [c, w];
25355
25373
  const frame2 = [AXES[n], AXES[w], AXES[c]];
25356
- const along2 = size[w];
25374
+ const along3 = size[w];
25357
25375
  const across2 = size[c];
25358
25376
  const d = fastener?.diameter ?? 5e-3;
25359
25377
  const spacing = fastener?.spacing ?? 0.2;
25360
25378
  const end3 = END_D * d;
25361
- const count = along2 > 2 * end3 ? 1 + Math.ceil((along2 - 2 * end3) / spacing) : 1;
25379
+ const count = along3 > 2 * end3 ? 1 + Math.ceil((along3 - 2 * end3) / spacing) : 1;
25362
25380
  const stations = Math.min(count, SEAM_STATIONS);
25363
25381
  const each = count / stations;
25364
25382
  const out = [];
25365
25383
  for (let s = 0; s < stations; s++) {
25366
- const t = stations === 1 ? 0 : -along2 / 2 + end3 + (along2 - 2 * end3) * s / (stations - 1);
25384
+ const t = stations === 1 ? 0 : -along3 / 2 + end3 + (along3 - 2 * end3) * s / (stations - 1);
25367
25385
  const at4 = [middle[0], middle[1], middle[2]];
25368
25386
  at4[w] = middle[w] + t;
25369
25387
  if (stiff || !fastener) {
@@ -25373,43 +25391,148 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25373
25391
  const rows = across2 >= (2 * EDGE_D + ROW_D) * d ? [EDGE_D * d, across2 - EDGE_D * d] : [across2 / 2];
25374
25392
  const pry = rows.reduce((sum2, r) => sum2 + r * r, 0) * fastener.axial * each;
25375
25393
  const lone = stations === 1;
25376
- const pryAlong = lone ? (along2 / 2) ** 2 * fastener.axial * rows.length : 0;
25394
+ const pryAlong = lone ? (along3 / 2) ** 2 * fastener.axial * rows.length : 0;
25377
25395
  const twist = lone && rows.length > 1 ? rows.reduce((sum2, r) => sum2 + (r - across2 / 2) ** 2, 0) * fastener.lateral : 0;
25378
25396
  out.push({ at: at4, frame: frame2, push: [fastener.axial * rows.length * each, fastener.lateral * rows.length * each, fastener.lateral * rows.length * each], turn: [twist, pry, pryAlong] });
25379
25397
  }
25380
25398
  return out;
25381
25399
  }
25382
- function solve(k, f, n) {
25383
- const first = new Int32Array(n);
25384
- for (let i = 0; i < n; i++) {
25385
- let j = 0;
25386
- while (j < i && k[i * n + j] === 0) j++;
25387
- first[i] = j;
25400
+ function sparseOf(count, pairs, last) {
25401
+ const joined = Array.from({ length: count }, () => /* @__PURE__ */ new Set());
25402
+ for (const [a, b] of pairs) {
25403
+ if (a === b) continue;
25404
+ joined[a].add(b);
25405
+ joined[b].add(a);
25406
+ }
25407
+ const order2 = new Int32Array(count).fill(-1);
25408
+ const held = [];
25409
+ for (let rank = 0; rank < count; rank++) {
25410
+ const feet = rank >= count - last.size;
25411
+ let least = -1;
25412
+ for (let i = 0; i < count; i++) if (order2[i] === -1 && last.has(i) === feet && (least === -1 || joined[i].size < joined[least].size)) least = i;
25413
+ order2[least] = rank;
25414
+ const others = [...joined[least]];
25415
+ held.push(others);
25416
+ for (const a of others) {
25417
+ joined[a].delete(least);
25418
+ for (const b of others) if (a !== b) joined[a].add(b);
25419
+ }
25420
+ }
25421
+ const nodeStart = new Int32Array(count + 1);
25422
+ for (let rank = 0; rank < count; rank++) nodeStart[rank + 1] = nodeStart[rank] + held[rank].length;
25423
+ const below = new Int32Array(nodeStart[count]);
25424
+ const beforeStart = new Int32Array(count + 1);
25425
+ for (let rank = 0; rank < count; rank++) {
25426
+ const ranks = held[rank].map((node) => order2[node]).sort((p, q) => p - q);
25427
+ below.set(ranks, nodeStart[rank]);
25428
+ for (const other of ranks) beforeStart[other + 1] = beforeStart[other + 1] + 1;
25429
+ }
25430
+ for (let rank = 0; rank < count; rank++) beforeStart[rank + 1] = beforeStart[rank + 1] + beforeStart[rank];
25431
+ const before = new Int32Array(beforeStart[count]);
25432
+ const filled = beforeStart.slice(0, count);
25433
+ for (let rank = 0; rank < count; rank++) for (let t = nodeStart[rank]; t < nodeStart[rank + 1]; t++) before[filled[below[t]]++] = rank;
25434
+ const n = count * 6;
25435
+ const start = new Int32Array(n + 1);
25436
+ for (let j = 0; j < n; j++) {
25437
+ const rank = Math.floor(j / 6);
25438
+ start[j + 1] = start[j] + (5 - j % 6) + 6 * (nodeStart[rank + 1] - nodeStart[rank]);
25388
25439
  }
25389
- for (let i = 0; i < n; i++) {
25390
- const fi = first[i];
25391
- for (let j = fi; j <= i; j++) {
25392
- let sum2 = k[i * n + j];
25393
- const from = Math.max(fi, first[j]);
25394
- for (let m = from; m < j; m++) sum2 -= k[i * n + m] * k[j * n + m];
25395
- if (j === i) {
25396
- if (!(sum2 > 0)) return false;
25397
- k[i * n + i] = Math.sqrt(sum2);
25398
- } else k[i * n + j] = sum2 / k[j * n + j];
25440
+ const rows = new Int32Array(start[n]);
25441
+ for (let j = 0; j < n; j++) {
25442
+ const rank = Math.floor(j / 6);
25443
+ let p = start[j];
25444
+ for (let i = j + 1; i < rank * 6 + 6; i++) rows[p++] = i;
25445
+ for (let t = nodeStart[rank]; t < nodeStart[rank + 1]; t++) for (let c = 0; c < 6; c++) rows[p++] = below[t] * 6 + c;
25446
+ }
25447
+ const head = (count - last.size) * 6;
25448
+ const tail = start.slice(0, n);
25449
+ for (let j = 0; j < head; j++) while (tail[j] < start[j + 1] && rows[tail[j]] < head) tail[j] = tail[j] + 1;
25450
+ return { order: order2, shape: { n, start, rows, nodeStart, below, beforeStart, before, size: n + rows.length, head, tail } };
25451
+ }
25452
+ function placeOf(shape, i, j) {
25453
+ if (i === j) return i;
25454
+ const rank = Math.floor(j / 6);
25455
+ const other = Math.floor(i / 6);
25456
+ const index = shape.n + shape.start[j];
25457
+ if (other === rank) return index + i - j - 1;
25458
+ let t = shape.nodeStart[rank];
25459
+ const end3 = shape.nodeStart[rank + 1];
25460
+ while (t < end3 && shape.below[t] !== other) t++;
25461
+ if (t === end3) throw new Error(`assemblyFlex: (${i}, ${j}) is of two nodes the matrix was not made with as joined`);
25462
+ return index + 5 - j % 6 + 6 * (t - shape.nodeStart[rank]) + i % 6;
25463
+ }
25464
+ function addAt(shape, k, i, j, value) {
25465
+ if (j > i) return;
25466
+ const index = shape.placeOf(i, j);
25467
+ k[index] = k[index] + value;
25468
+ }
25469
+ function halfQuadratic(shape, k, x) {
25470
+ const { n, start, rows } = shape;
25471
+ let total = 0;
25472
+ for (let j = 0; j < n; j++) {
25473
+ const xj = x[j];
25474
+ if (xj === 0) continue;
25475
+ let column = 0.5 * k[j] * xj;
25476
+ for (let p = start[j]; p < start[j + 1]; p++) column += k[n + p] * x[rows[p]];
25477
+ total += xj * column;
25478
+ }
25479
+ return total;
25480
+ }
25481
+ function factor(shape, k, from, to) {
25482
+ const { n, start, rows, beforeStart, before } = shape;
25483
+ const next = from === 0 ? start.slice(0, n) : shape.tail.slice();
25484
+ const x = new Float64Array(n);
25485
+ const columns = new Int32Array(n);
25486
+ for (let i = from; i < to; i++) {
25487
+ const rank = Math.floor(i / 6);
25488
+ let count = 0;
25489
+ for (let t = beforeStart[rank]; t < beforeStart[rank + 1]; t++) for (let c = 0; c < 6; c++) columns[count++] = before[t] * 6 + c;
25490
+ for (let j = rank * 6; j < i; j++) columns[count++] = j;
25491
+ for (let c = 0; c < count; c++) {
25492
+ const j = columns[c];
25493
+ x[j] = k[n + next[j]];
25399
25494
  }
25495
+ let diagonal = k[i];
25496
+ for (let c = 0; c < count; c++) {
25497
+ const j = columns[c];
25498
+ const value = x[j] / k[j];
25499
+ x[j] = 0;
25500
+ const end3 = next[j];
25501
+ for (let p = start[j]; p < end3; p++) x[rows[p]] = x[rows[p]] - k[n + p] * value;
25502
+ diagonal -= value * value;
25503
+ k[n + end3] = value;
25504
+ next[j] = end3 + 1;
25505
+ }
25506
+ if (!(diagonal > 0)) return false;
25507
+ k[i] = Math.sqrt(diagonal);
25400
25508
  }
25401
- for (let i = 0; i < n; i++) {
25402
- let sum2 = f[i];
25403
- for (let m = first[i]; m < i; m++) sum2 -= k[i * n + m] * f[m];
25404
- f[i] = sum2 / k[i * n + i];
25509
+ return true;
25510
+ }
25511
+ function substitute(shape, k, f) {
25512
+ const { n, start, rows } = shape;
25513
+ for (let j = 0; j < n; j++) {
25514
+ const value = f[j] / k[j];
25515
+ f[j] = value;
25516
+ for (let p = start[j]; p < start[j + 1]; p++) f[rows[p]] = f[rows[p]] - k[n + p] * value;
25405
25517
  }
25406
- for (let i = n - 1; i >= 0; i--) {
25407
- const x = f[i] / k[i * n + i];
25408
- f[i] = x;
25409
- for (let m = first[i]; m < i; m++) f[m] = f[m] - k[i * n + m] * x;
25518
+ for (let j = n - 1; j >= 0; j--) {
25519
+ let sum2 = f[j];
25520
+ for (let p = start[j]; p < start[j + 1]; p++) sum2 -= k[n + p] * f[rows[p]];
25521
+ f[j] = sum2 / k[j];
25410
25522
  }
25411
- return true;
25412
25523
  }
25524
+ var sparseLinear = (count, pairs, last) => {
25525
+ const { order: order2, shape } = sparseOf(count, pairs, last);
25526
+ return {
25527
+ order: order2,
25528
+ size: shape.size,
25529
+ head: shape.head,
25530
+ placeOf: (i, j) => placeOf(shape, i, j),
25531
+ factor: (k, from, to) => factor(shape, k, from, to),
25532
+ substitute: (k, f) => substitute(shape, k, f),
25533
+ halfQuadratic: (k, x) => halfQuadratic(shape, k, x)
25534
+ };
25535
+ };
25413
25536
  function hullOf(points) {
25414
25537
  const sorted = [...points].sort((p, q) => p[0] - q[0] || p[1] - q[1]);
25415
25538
  const turn2 = (o, p, q) => (p[0] - o[0]) * (q[1] - o[1]) - (p[1] - o[1]) * (q[0] - o[0]);
@@ -25441,7 +25564,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25441
25564
  const joints = input.joints.filter((j) => beams.has(j.a) && beams.has(j.b) && j.a !== j.b);
25442
25565
  const structural = (j) => RIGID_KINDS.has(j.kind) || JOINT_FASTENERS[j.kind] !== void 0;
25443
25566
  const stationed = /* @__PURE__ */ new Map();
25444
- const along2 = (beam, p) => Math.max(-beam.length / 2, Math.min(beam.length / 2, vec.dot(vec.sub(p, beam.part.position), beam.axis)));
25567
+ const along3 = (beam, p) => Math.max(-beam.length / 2, Math.min(beam.length / 2, vec.dot(vec.sub(p, beam.part.position), beam.axis)));
25445
25568
  for (const beam of beams.values()) beam.stations.push(-beam.length / 2, beam.length / 2);
25446
25569
  for (const joint2 of joints) {
25447
25570
  if (!structural(joint2)) continue;
@@ -25450,8 +25573,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25450
25573
  const stations = stationsOf(joint2, a, b);
25451
25574
  stationed.set(joint2, stations);
25452
25575
  for (const s of stations) {
25453
- a.stations.push(along2(a, s.at));
25454
- b.stations.push(along2(b, s.at));
25576
+ a.stations.push(along3(a, s.at));
25577
+ b.stations.push(along3(b, s.at));
25455
25578
  }
25456
25579
  }
25457
25580
  const footPoints = /* @__PURE__ */ new Map();
@@ -25463,7 +25586,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25463
25586
  if (c[1] <= beam.min[1] + 5e-3) corners.push(c);
25464
25587
  }
25465
25588
  footPoints.set(beam.part.id, corners);
25466
- for (const c of corners) beam.stations.push(along2(beam, c));
25589
+ for (const c of corners) beam.stations.push(along3(beam, c));
25467
25590
  }
25468
25591
  const nodes = [];
25469
25592
  for (const beam of beams.values()) {
@@ -25487,28 +25610,16 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25487
25610
  beam.nodes = kept.map((s) => nodes.push({ at: vec.madd(beam.part.position, beam.axis, s) }) - 1);
25488
25611
  }
25489
25612
  if (nodes.length * 6 > MAX_DOF) return null;
25490
- const lo = [Infinity, Infinity, Infinity];
25491
- const hi = [-Infinity, -Infinity, -Infinity];
25492
- for (const node of nodes) for (let k = 0; k < 3; k++) {
25493
- lo[k] = Math.min(lo[k], node.at[k]);
25494
- hi[k] = Math.max(hi[k], node.at[k]);
25495
- }
25496
- let main = 0;
25497
- if (hi[1] - lo[1] > hi[main] - lo[main]) main = 1;
25498
- if (hi[2] - lo[2] > hi[main] - lo[main]) main = 2;
25499
- const ranked = nodes.map((_, i) => i).sort((p, q) => nodes[p].at[main] - nodes[q].at[main] || p - q);
25500
25613
  const order2 = new Int32Array(nodes.length);
25501
- ranked.forEach((node, rank) => {
25502
- order2[node] = rank;
25503
- });
25614
+ for (let i = 0; i < nodes.length; i++) order2[i] = i;
25504
25615
  const dofsOf = (node) => [0, 1, 2, 3, 4, 5].map((i) => order2[node] * 6 + i);
25505
25616
  const nearest = (beam, p) => {
25506
- const t = along2(beam, p);
25617
+ const t = along3(beam, p);
25507
25618
  let best = 0;
25508
25619
  for (let i = 1; i < beam.stations.length; i++) if (Math.abs(beam.stations[i] - t) < Math.abs(beam.stations[best] - t)) best = i;
25509
25620
  return beam.nodes[best];
25510
25621
  };
25511
- const elements = [];
25622
+ const made = [];
25512
25623
  for (const beam of beams.values()) {
25513
25624
  const section = sectionOf2(beam);
25514
25625
  if (!section) {
@@ -25519,7 +25630,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25519
25630
  for (let i = 0; i + 1 < beam.nodes.length; i++) {
25520
25631
  const length2 = beam.stations[i + 1] - beam.stations[i];
25521
25632
  const k = toObjectFrame(beamLocal(section, length2), 12, beam.axis, beam.u, beam.v);
25522
- elements.push({ dofs: [...dofsOf(beam.nodes[i]), ...dofsOf(beam.nodes[i + 1])], k, parts: [beam.part.id] });
25633
+ made.push({ dofs: [...dofsOf(beam.nodes[i]), ...dofsOf(beam.nodes[i + 1])], k, parts: [beam.part.id], places: NO_PLACES });
25523
25634
  }
25524
25635
  }
25525
25636
  for (const [joint2, stations] of stationed) {
@@ -25548,7 +25659,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25548
25659
  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];
25549
25660
  }
25550
25661
  }
25551
- elements.push({ dofs: [...dofsOf(na), ...dofsOf(nb)], k, parts: [joint2.a, joint2.b] });
25662
+ made.push({ dofs: [...dofsOf(na), ...dofsOf(nb)], k, parts: [joint2.a, joint2.b], places: NO_PLACES });
25552
25663
  }
25553
25664
  }
25554
25665
  const supports = [];
@@ -25559,7 +25670,15 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25559
25670
  supports.push({ part: id, node, arm: vec.sub(at4, nodes[node].at), at: at4 });
25560
25671
  }
25561
25672
  }
25562
- const frame2 = { nodes, beams, elements, supports, order: order2 };
25673
+ const shape = (input.linear ?? sparseLinear)(nodes.length, made.map((element) => [Math.floor(element.dofs[0] / 6), Math.floor(element.dofs[6] / 6)]), new Set(supports.map((s) => s.node)));
25674
+ order2.set(shape.order);
25675
+ const elements = made.map((element) => {
25676
+ const dofs = element.dofs.map((dof) => order2[Math.floor(dof / 6)] * 6 + dof % 6);
25677
+ const places = new Int32Array(dofs.length * dofs.length);
25678
+ for (let p = 0; p < dofs.length; p++) for (let q = 0; q < dofs.length; q++) places[p * dofs.length + q] = dofs[q] > dofs[p] ? -1 : shape.placeOf(dofs[p], dofs[q]);
25679
+ return { ...element, dofs, places };
25680
+ });
25681
+ const frame2 = { nodes, beams, elements, supports, order: order2, shape };
25563
25682
  const before = lost.size > 0 ? solveFrame(frame2, input, joints, structural, /* @__PURE__ */ new Set(), g, null) : null;
25564
25683
  const after2 = solveFrame(frame2, input, joints, structural, lost, g, before);
25565
25684
  if (!after2) return null;
@@ -25599,12 +25718,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25599
25718
  const delta = new Float64Array(n);
25600
25719
  for (let i = 0; i < n; i++) delta[i] = after2.u[i] - before.u[i];
25601
25720
  for (const beam of beams.values()) if (!after2.standing.has(beam.part.id)) for (const node of beam.nodes) for (const dof of dofsOf(node)) delta[dof] = 0;
25602
- for (let i = 0; i < n; i++) {
25603
- if (delta[i] === 0) continue;
25604
- let row = 0;
25605
- for (let j = 0; j < n; j++) row += after2.k[i * n + j] * delta[j];
25606
- released += 0.5 * delta[i] * row;
25607
- }
25721
+ released = frame2.shape.halfQuadratic(after2.k, delta);
25608
25722
  spin = spinOf({ frame: frame2, after: after2, delta, released, centre: allCentre, mass: all, floor: floor2, g });
25609
25723
  }
25610
25724
  return {
@@ -25619,6 +25733,21 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25619
25733
  if (!beam || !after2.standing.has(id)) return null;
25620
25734
  const node = nearest(beam, point);
25621
25735
  return moved(after2, { part: id, node, arm: vec.sub(point, nodes[node].at), mass: 0 });
25736
+ },
25737
+ settlement(id) {
25738
+ const beam = beams.get(id);
25739
+ if (!beam) return null;
25740
+ const carrier = after2.standing.has(id) ? null : after2.masses.find((p) => p.part === id);
25741
+ if (!after2.standing.has(id) && !carrier) return null;
25742
+ const from = vec.madd(beam.part.position, beam.axis, -beam.length / 2);
25743
+ const to = vec.madd(beam.part.position, beam.axis, beam.length / 2);
25744
+ const drop = [];
25745
+ for (let i = 0; i < SAG_STATIONS; i++) {
25746
+ const point = vec.madd(from, beam.axis, beam.length * i / (SAG_STATIONS - 1));
25747
+ const node = carrier ? carrier.node : nearest(beam, point);
25748
+ drop.push(-moved(after2, { part: id, node, arm: vec.sub(point, nodes[node].at), mass: 0 })[1]);
25749
+ }
25750
+ return { from, to, drop };
25622
25751
  }
25623
25752
  };
25624
25753
  }
@@ -25643,7 +25772,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25643
25772
  return standing;
25644
25773
  }
25645
25774
  function solveFrame(frame2, input, joints, structural, gone, g, from) {
25646
- const { nodes, beams, order: order2 } = frame2;
25775
+ const { nodes, beams, order: order2, shape } = frame2;
25647
25776
  const n = nodes.length * 6;
25648
25777
  const standing = standingParts(frame2, joints, structural, gone);
25649
25778
  if (standing.size === 0) return null;
@@ -25703,50 +25832,50 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25703
25832
  f[base2 + 3] = f[base2 + 3] - p.arm[2] * weight;
25704
25833
  f[base2 + 5] = f[base2 + 5] + p.arm[0] * weight;
25705
25834
  }
25706
- const structure = new Float64Array(n * n);
25835
+ const structure = new Float64Array(shape.size);
25707
25836
  let largest = 0;
25708
25837
  for (const element of frame2.elements) {
25709
25838
  if (!element.parts.every((id) => standing.has(id))) continue;
25710
- const size = element.dofs.length;
25711
- for (let p = 0; p < size; p++) {
25712
- 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];
25713
- }
25839
+ const { places, k: k2 } = element;
25840
+ for (let t = 0; t < places.length; t++) if (places[t] >= 0) structure[places[t]] = structure[places[t]] + k2[t];
25714
25841
  }
25715
- for (let i = 0; i < n; i++) largest = Math.max(largest, structure[i * n + i]);
25842
+ for (let i = 0; i < n; i++) largest = Math.max(largest, structure[i]);
25716
25843
  if (largest <= 0) return null;
25717
25844
  const free = new Uint8Array(n);
25718
25845
  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;
25719
25846
  for (let i = 0; i < n; i++) {
25720
25847
  if (!free[i]) {
25721
- structure[i * n + i] = largest;
25848
+ structure[i] = largest;
25722
25849
  f[i] = 0;
25723
- } else structure[i * n + i] = structure[i * n + i] + largest * SOFT;
25850
+ } else addAt(shape, structure, i, i, largest * SOFT);
25724
25851
  }
25725
25852
  const feet = frame2.supports.filter((s) => standing.has(s.part));
25726
25853
  const holds3 = feet.map((s) => !from || from.holding.includes(s));
25727
25854
  const footed = [...new Set(feet.map((s) => s.part))];
25728
25855
  const grips = new Map(footed.map((id) => [id, true]));
25729
25856
  const friction = input.friction ?? FOOT_FRICTION;
25730
- const k = new Float64Array(n * n);
25857
+ const factored = structure.slice();
25858
+ if (!shape.factor(factored, 0, shape.head)) return null;
25859
+ const k = new Float64Array(shape.size);
25731
25860
  const u = new Float64Array(n);
25732
- const build = () => {
25733
- k.set(structure);
25861
+ const build = (from2) => {
25862
+ k.set(from2);
25734
25863
  const held = /* @__PURE__ */ new Map();
25735
25864
  feet.forEach((s, index) => {
25736
25865
  if (!holds3[index]) return;
25737
25866
  const row = armRows(s.arm)[1];
25738
25867
  const base2 = order2[s.node] * 6;
25739
- 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];
25868
+ for (let p = 0; p < 6; p++) for (let q = 0; q < 6; q++) addAt(shape, k, base2 + p, base2 + q, RIGID_PUSH * row[p] * row[q]);
25740
25869
  held.set(s.part, [...held.get(s.part) ?? [], s]);
25741
25870
  });
25742
25871
  for (const [id, points] of held) {
25743
25872
  const { node, arm } = gripOf(points);
25744
25873
  const upright = order2[node] * 6 + 4;
25745
- k[upright * n + upright] = k[upright * n + upright] + RIGID_TURN;
25874
+ addAt(shape, k, upright, upright, RIGID_TURN);
25746
25875
  if (!grips.get(id)) continue;
25747
25876
  const rows = armRows(arm);
25748
25877
  const base2 = order2[node] * 6;
25749
- 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];
25878
+ for (const row of [rows[0], rows[2]]) for (let p = 0; p < 6; p++) for (let q = 0; q < 6; q++) addAt(shape, k, base2 + p, base2 + q, RIGID_PUSH * row[p] * row[q]);
25750
25879
  }
25751
25880
  };
25752
25881
  const liftOf = (s) => {
@@ -25755,9 +25884,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25755
25884
  };
25756
25885
  const rounds = 4 * feet.length + 2 * footed.length + 4;
25757
25886
  for (let round5 = 0; round5 < rounds; round5++) {
25758
- build();
25887
+ build(factored);
25759
25888
  u.set(f);
25760
- if (!solve(k, u, n)) return null;
25889
+ if (!shape.factor(k, shape.head, n)) return null;
25890
+ shape.substitute(k, u);
25761
25891
  const pull = 1e-12;
25762
25892
  const sink = -1e-9;
25763
25893
  if (round5 === 0) {
@@ -25811,7 +25941,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25811
25941
  if (worst > MECHANISM) return null;
25812
25942
  const holding = feet.filter((_, index) => holds3[index]);
25813
25943
  if (holding.length < 3) return null;
25814
- build();
25944
+ build(structure);
25815
25945
  return { u: u.slice(), k: k.slice(), holding, masses, standing };
25816
25946
  }
25817
25947
  return null;
@@ -26130,8 +26260,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26130
26260
  };
26131
26261
  var sectionKept = (p, residual, borne, through) => {
26132
26262
  let kept = 1;
26133
- forEachSection(p, borne, (c, along2, gone) => {
26134
- const share = through?.(c.center, along2) ?? 1;
26263
+ forEachSection(p, borne, (c, along3, gone) => {
26264
+ const share = through?.(c.center, along3) ?? 1;
26135
26265
  if (share <= 0) return;
26136
26266
  kept = Math.min(kept, Math.max(p.spec.reinforcement ? residual : 0, 1 - gone) / share);
26137
26267
  });
@@ -26156,12 +26286,12 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26156
26286
  const last = cells[cells.length - 1];
26157
26287
  if (!known || known.spec !== p.spec || known.count !== cells.length || known.last !== last) {
26158
26288
  const places = [];
26159
- let along2 = 0;
26289
+ let along3 = 0;
26160
26290
  measureSections(p, cells, void 0, (c, a, gone) => {
26161
- along2 = a;
26291
+ along3 = a;
26162
26292
  places.push({ c, gone });
26163
26293
  });
26164
- known = { spec: p.spec, count: cells.length, last, along: along2, lying: sectionLying(p, along2), places };
26294
+ known = { spec: p.spec, count: cells.length, last, along: along3, lying: sectionLying(p, along3), places };
26165
26295
  sectionsByCells.set(cells, known);
26166
26296
  }
26167
26297
  for (const { c, gone } of known.places) {
@@ -26169,24 +26299,24 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26169
26299
  visit(c, known.along, gone);
26170
26300
  }
26171
26301
  };
26172
- var sectionLying = (p, along2) => {
26302
+ var sectionLying = (p, along3) => {
26173
26303
  const [u, v] = planeAxes(p.thin);
26174
26304
  const up = rotateVec(p.q, [0, 0, 0].map((_, k) => k === v ? 1 : 0));
26175
26305
  const upright = Math.abs(up[1]) > 0.7 ? v : Math.abs(rotateVec(p.q, [0, 0, 0].map((_, k) => k === u ? 1 : 0))[1]) > 0.7 ? u : -1;
26176
- return along2 !== upright || upright < 0;
26306
+ return along3 !== upright || upright < 0;
26177
26307
  };
26178
26308
  var measureSections = (p, cells, borne, visit) => {
26179
26309
  const [u, v] = planeAxes(p.thin);
26180
26310
  const role = p.spec.structure?.role;
26181
26311
  const up = rotateVec(p.q, [0, 0, 0].map((_, k) => k === v ? 1 : 0));
26182
26312
  const upright = Math.abs(up[1]) > 0.7 ? v : Math.abs(rotateVec(p.q, [0, 0, 0].map((_, k) => k === u ? 1 : 0))[1]) > 0.7 ? u : -1;
26183
- const along2 = (role === "wall" || role === "partition" || role === "column") && upright >= 0 ? upright : p.dims[u] >= p.dims[v] ? u : v;
26184
- const across2 = along2 === u ? v : u;
26185
- const lying = along2 !== upright || upright < 0;
26313
+ const along3 = (role === "wall" || role === "partition" || role === "column") && upright >= 0 ? upright : p.dims[u] >= p.dims[v] ? u : v;
26314
+ const across2 = along3 === u ? v : u;
26315
+ const lying = along3 !== upright || upright < 0;
26186
26316
  for (const c of cells) {
26187
- if (lying && borne?.(c.center, along2)) continue;
26317
+ if (lying && borne?.(c.center, along3)) continue;
26188
26318
  const spans = [];
26189
- for (const d of cells) if (Math.abs(d.center[along2] - c.center[along2]) < d.size[along2] / 2 + 1e-6) spans.push([d.center[across2] - d.size[across2] / 2, d.center[across2] + d.size[across2] / 2]);
26319
+ for (const d of cells) if (Math.abs(d.center[along3] - c.center[along3]) < d.size[along3] / 2 + 1e-6) spans.push([d.center[across2] - d.size[across2] / 2, d.center[across2] + d.size[across2] / 2]);
26190
26320
  spans.sort((a, b) => a[0] - b[0]);
26191
26321
  let gone = 0, end3 = -Infinity;
26192
26322
  for (const [a, b] of spans) {
@@ -26194,7 +26324,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26194
26324
  gone += b - Math.max(a, end3);
26195
26325
  end3 = b;
26196
26326
  }
26197
- visit(c, along2, Math.min(1, gone / Math.max(p.dims[across2], 1e-6)));
26327
+ visit(c, along3, Math.min(1, gone / Math.max(p.dims[across2], 1e-6)));
26198
26328
  }
26199
26329
  };
26200
26330
  var HOSTED_TOLERANCE = 0.02;
@@ -26258,6 +26388,12 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26258
26388
  objectsRevision++;
26259
26389
  }
26260
26390
  };
26391
+ const movedObjects = [];
26392
+ const markMoved = (o) => {
26393
+ if (o.rayMoved) return;
26394
+ o.rayMoved = true;
26395
+ movedObjects.push(o);
26396
+ };
26261
26397
  const listeners = /* @__PURE__ */ new Map();
26262
26398
  let cur = [];
26263
26399
  const blasts = [];
@@ -26266,6 +26402,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26266
26402
  const primed = /* @__PURE__ */ new Map();
26267
26403
  let orderCounter = 0;
26268
26404
  const impls = /* @__PURE__ */ new Map();
26405
+ let implsRevision = 0;
26269
26406
  const taken = (id) => objects.has(id) || impls.has(id);
26270
26407
  const emit2 = (e) => {
26271
26408
  cur.push(e);
@@ -26432,6 +26569,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26432
26569
  unsup: [],
26433
26570
  anyAnchor: false,
26434
26571
  order: ++orderCounter,
26572
+ rayStamp: 0,
26573
+ raySlot: 0,
26574
+ rayMoved: false,
26435
26575
  loose: carry?.loose ?? false,
26436
26576
  cast: /* @__PURE__ */ new Map(),
26437
26577
  base: { pos: [pos[0], pos[1], pos[2]], rot: [rot[0], rot[1], rot[2], rot[3]] }
@@ -26653,13 +26793,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26653
26793
  if (load <= 0) return void 0;
26654
26794
  const above2 = Math.max(0, load - p.st.mass);
26655
26795
  const up = rotateVec(p.q, [0, 1, 0]);
26656
- return (local2, along2) => {
26796
+ return (local2, along3) => {
26657
26797
  const axis2 = [0, 0, 0];
26658
- axis2[along2] = 1;
26798
+ axis2[along3] = 1;
26659
26799
  const sign2 = Math.sign(rotateVec(p.q, axis2)[1]);
26660
26800
  if (Math.abs(up[1]) < 0.7 && Math.abs(rotateVec(p.q, axis2)[1]) < 0.7) return 1;
26661
- const half = p.dims[along2] / 2;
26662
- const share = clamp2((half - sign2 * local2[along2]) / Math.max(p.dims[along2], 1e-6), 0, 1);
26801
+ const half = p.dims[along3] / 2;
26802
+ const share = clamp2((half - sign2 * local2[along3]) / Math.max(p.dims[along3], 1e-6), 0, 1);
26663
26803
  return (above2 + p.st.mass * share) / load;
26664
26804
  };
26665
26805
  };
@@ -26721,7 +26861,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26721
26861
  const borneOn = (p, supports) => {
26722
26862
  if (supports.length === 0) return void 0;
26723
26863
  const boxes = supports.map((support) => contactBox(p, support));
26724
- return (local2, along2) => boxes.some(([lo, hi]) => local2[along2] >= lo[along2] - SUPPORT_TOLERANCE && local2[along2] <= hi[along2] + SUPPORT_TOLERANCE);
26864
+ return (local2, along3) => boxes.some(([lo, hi]) => local2[along3] >= lo[along3] - SUPPORT_TOLERANCE && local2[along3] <= hi[along3] + SUPPORT_TOLERANCE);
26725
26865
  };
26726
26866
  const measureContact = (p, support) => {
26727
26867
  const A = aabbOf(p.spec.shape, p.pos, p.q), B = aabbOf(support.spec.shape, support.pos, support.q);
@@ -26826,14 +26966,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26826
26966
  const kinetic = impulseEnergy(impulse, lineLoad(g, weight) / GRAVITY * L, flexure);
26827
26967
  const sec = sectionOf22(p, axis2);
26828
26968
  const EI = s.elasticGPa * 1e9 * sec.section.b * sec.section.h ** 3 / 12;
26829
- const along2 = axis2 === g.gravity ? -Math.sign(away[axis2] * g.up[axis2]) : 0;
26969
+ const along3 = axis2 === g.gravity ? -Math.sign(away[axis2] * g.up[axis2]) : 0;
26830
26970
  const dynamic2 = momentOfEnergy(kinetic, L, EI, flexure.loadFactor);
26831
- const peak = Math.abs(dynamic2 + along2 * p.restMoment);
26971
+ const peak = Math.abs(dynamic2 + along3 * p.restMoment);
26832
26972
  if (peak <= sec.cracking) return;
26833
26973
  if (!p.st.cracked) {
26834
26974
  p.st.cracked = true;
26835
26975
  const tension = [near.point[0], near.point[1], near.point[2]];
26836
- tension[axis2] = dynamic2 + along2 * p.restMoment >= 0 ? -face : face;
26976
+ tension[axis2] = dynamic2 + along3 * p.restMoment >= 0 ? -face : face;
26837
26977
  const n = [0, 0, 0];
26838
26978
  n[axis2] = Math.sign(tension[axis2]) || 1;
26839
26979
  addCrack(o, p, toWorld(c, q, tension), rotateVec(q, n), sec.section.b, src);
@@ -27005,7 +27145,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
27005
27145
  if (!terrain) throw new Error(`unknown wind terrain "${cfg.terrain}"`);
27006
27146
  const inputs = [];
27007
27147
  const at4 = /* @__PURE__ */ new Map();
27008
- const keep = [];
27148
+ const keep2 = [];
27009
27149
  let ground = Infinity, foundationTop = -Infinity;
27010
27150
  o.parts.forEach((p, i) => {
27011
27151
  if (isLost(p) || isTerrain(p) || o.collapsed.has(p.spec.id) || o.unsup[i]) return;
@@ -27014,12 +27154,12 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
27014
27154
  const e = p.mat.strength?.elasticGPa;
27015
27155
  const kind = role === "wall" ? "wall" : role === "column" ? "column" : role === "beam" ? "beam" : role === "foundation" ? "foundation" : "other";
27016
27156
  at4.set(i, inputs.length);
27017
- keep.push(i);
27157
+ keep2.push(i);
27018
27158
  ground = Math.min(ground, box5.min[1]);
27019
27159
  if (kind === "foundation") foundationTop = Math.max(foundationTop, box5.max[1]);
27020
27160
  inputs.push({ min: box5.min, max: box5.max, kind, ...e ? { elasticPa: e * 1e9 } : {}, mass: p.st.mass, ...p.spec.damper ? { damper: true } : {} });
27021
27161
  });
27022
- keep.forEach((i, k) => {
27162
+ keep2.forEach((i, k) => {
27023
27163
  if (inputs[k].kind !== "column") return;
27024
27164
  const beams = [];
27025
27165
  for (const j of o.byPart.get(o.parts[i].spec.id)) {
@@ -27029,7 +27169,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
27029
27169
  }
27030
27170
  inputs[k].beams = beams;
27031
27171
  });
27032
- keep.forEach((i, k) => {
27172
+ keep2.forEach((i, k) => {
27033
27173
  if (inputs[k].kind !== "beam") return;
27034
27174
  for (const j of o.byPart.get(o.parts[i].spec.id)) {
27035
27175
  if (j.st.open) continue;
@@ -27063,14 +27203,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
27063
27203
  };
27064
27204
  const a = inputs.length && cfg.speed > 0 ? analyzeWind(inputs, c, foundationTop > -Infinity ? foundationTop : ground) : null;
27065
27205
  w.analysis = a;
27066
- w.parts = keep;
27206
+ w.parts = keep2;
27067
27207
  for (const p of o.parts) delete p.st.wind;
27068
27208
  if (!a) {
27069
27209
  w.sys = null;
27070
27210
  delete o.st.wind;
27071
27211
  return;
27072
27212
  }
27073
- keep.forEach((i, k) => {
27213
+ keep2.forEach((i, k) => {
27074
27214
  const N = a.axial[k];
27075
27215
  const p = o.parts[i];
27076
27216
  if (!N || !p.structural || o.unsup[i]) return;
@@ -27104,7 +27244,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
27104
27244
  w.gust = makeGust(v10, cfg.gust);
27105
27245
  }
27106
27246
  let md = 0, spec;
27107
- for (const i of keep) {
27247
+ for (const i of keep2) {
27108
27248
  const p = o.parts[i];
27109
27249
  if (!p.spec.damper) continue;
27110
27250
  const phi = shapeAt(a, p.pos[1] - (foundationTop > -Infinity ? foundationTop : ground));
@@ -27248,10 +27388,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
27248
27388
  iz += sp.k * (sp.z - z0) ** 2;
27249
27389
  }
27250
27390
  const { c } = soilWeight(o);
27251
- const along2 = ix <= iz ? 0 : 1;
27252
- const off = along2 === 0 ? c[0] - x0 : c[2] - z0;
27391
+ const along3 = ix <= iz ? 0 : 1;
27392
+ const off = along3 === 0 ? c[0] - x0 : c[2] - z0;
27253
27393
  const sign2 = Math.abs(off) > 1e-6 ? Math.sign(off) : 1;
27254
- so.imp = along2 === 0 ? [sign2 * soilCfg.imperfection, 0] : [0, sign2 * soilCfg.imperfection];
27394
+ so.imp = along3 === 0 ? [sign2 * soilCfg.imperfection, 0] : [0, sign2 * soilCfg.imperfection];
27255
27395
  if (carried) {
27256
27396
  const t = Math.tan(carried.tilt * Math.PI / 180);
27257
27397
  so.s = carried.settlement;
@@ -27266,6 +27406,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
27266
27406
  applySoilPose(o);
27267
27407
  };
27268
27408
  const applySoilPose = (o) => {
27409
+ markMoved(o);
27269
27410
  const so = o.soil;
27270
27411
  if (!so) {
27271
27412
  o.st.position = [o.base.pos[0], o.base.pos[1], o.base.pos[2]];
@@ -27499,10 +27640,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
27499
27640
  const cut = undercutAt(loss, Math.hypot(world2[0] - loss.x, world2[2] - loss.z), b.embed, groundCfg.spread);
27500
27641
  if (cut >= groundCfg.voidDepth) {
27501
27642
  open++;
27502
- const along2 = local2[long] - box5.min[long];
27643
+ const along3 = local2[long] - box5.min[long];
27503
27644
  const side = local2[across2] - box5.min[across2];
27504
- voidBox ?? (voidBox = { long: [along2, along2], across: [side, side] });
27505
- voidBox.long = [Math.min(voidBox.long[0], along2 - step / 2), Math.max(voidBox.long[1], along2 + step / 2)];
27645
+ voidBox ?? (voidBox = { long: [along3, along3], across: [side, side] });
27646
+ voidBox.long = [Math.min(voidBox.long[0], along3 - step / 2), Math.max(voidBox.long[1], along3 + step / 2)];
27506
27647
  voidBox.across = [Math.min(voidBox.across[0], side), Math.max(voidBox.across[1], side)];
27507
27648
  }
27508
27649
  drop += Math.min(cut, groundCfg.maxSettlement);
@@ -27606,9 +27747,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
27606
27747
  if (j.st.open || restsOn(o, j, k) !== b.i) continue;
27607
27748
  const q = o.parts[k];
27608
27749
  const c = aabbOf(q.spec.shape, q.pos, q.q);
27609
- const along2 = (c.min[fp.long] + c.max[fp.long]) / 2 - box5.min[fp.long];
27750
+ const along3 = (c.min[fp.long] + c.max[fp.long]) / 2 - box5.min[fp.long];
27610
27751
  const side = (c.min[across2] + c.max[across2]) / 2 - box5.min[across2];
27611
- if (along2 >= vb.long[0] && along2 <= vb.long[1] && side >= vb.across[0] && side <= vb.across[1]) out.push({ q, j });
27752
+ if (along3 >= vb.long[0] && along3 <= vb.long[1] && side >= vb.across[0] && side <= vb.across[1]) out.push({ q, j });
27612
27753
  }
27613
27754
  return out;
27614
27755
  };
@@ -27826,7 +27967,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
27826
27967
  const units = q.spec.units?.size;
27827
27968
  const step = units ? [Math.max(units[0], units[2]), units[1]] : [BRICK_STEP[0], BRICK_STEP[1]];
27828
27969
  const reach2 = Math.hypot(toward2[0], toward2[2]) || 1;
27829
- const along2 = vec.normalize([toward2[0] / reach2, 1, toward2[2] / reach2]);
27970
+ const along3 = vec.normalize([toward2[0] / reach2, 1, toward2[2] / reach2]);
27830
27971
  const width = clamp2(beta * SETTLEMENT_CRACK_OPENING, MIN_CRACK_WIDTH, MAX_CRACK_WIDTH);
27831
27972
  const through = q.dims[q.thin];
27832
27973
  for (let c = 0; c < count; c++) {
@@ -27834,7 +27975,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
27834
27975
  const local2 = [clamp2(at4[0] - toward2[0] / reach2 * back2, box5.min[0], box5.max[0]), box5.min[1] + height * (0.2 + 0.12 * c), clamp2(at4[2] - toward2[2] / reach2 * back2, box5.min[2], box5.max[2])];
27835
27976
  const face = toLocal(q.pos, q.q, local2);
27836
27977
  face[q.thin] = through / 2;
27837
- addCrack(o, q, toWorld(o.st.position, o.st.rotation, toWorld(q.pos, q.q, face)), normal, length2, src, { along: along2, step, width, through });
27978
+ addCrack(o, q, toWorld(o.st.position, o.st.rotation, toWorld(q.pos, q.q, face)), normal, length2, src, { along: along3, step, width, through });
27838
27979
  }
27839
27980
  if (beta >= damageAt && prior < damageAt) {
27840
27981
  q.st.hp = Math.max(1, q.st.hp - q.st.maxHp * groundCfg.distortionDamage);
@@ -28041,6 +28182,29 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28041
28182
  return turn2;
28042
28183
  };
28043
28184
  const copyOf2 = (v) => [v[0], v[1], v[2]];
28185
+ let bestInto = null;
28186
+ const rayPoint = [0, 0, 0];
28187
+ const keepBest = (into, object2, part, point, normal, distance4, pathLen) => {
28188
+ if (!into) return { object: object2, part, point: copyOf2(point), normal: copyOf2(normal), distance: distance4, pathLen };
28189
+ into.object = object2;
28190
+ into.part = part;
28191
+ into.point[0] = point[0];
28192
+ into.point[1] = point[1];
28193
+ into.point[2] = point[2];
28194
+ into.normal[0] = normal[0];
28195
+ into.normal[1] = normal[1];
28196
+ into.normal[2] = normal[2];
28197
+ into.distance = distance4;
28198
+ into.pathLen = pathLen;
28199
+ return into;
28200
+ };
28201
+ const bestScratch = { object: "", part: "", point: [0, 0, 0], normal: [0, 0, 0], distance: 0, pathLen: 0 };
28202
+ const isTerrainPart = (objectId, partId) => {
28203
+ const parts2 = objects.get(objectId)?.parts;
28204
+ if (!parts2) return false;
28205
+ for (const p of parts2) if (p.spec.id === partId) return p.spec.tags?.includes("terrain") === true;
28206
+ return false;
28207
+ };
28044
28208
  const objectTurnBack = [0, 0, 0, 1];
28045
28209
  const objectOrigin = [0, 0, 0];
28046
28210
  const objectDirection = [0, 0, 0];
@@ -28161,24 +28325,27 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28161
28325
  return grid;
28162
28326
  };
28163
28327
  const partsAlong = (o, lo, ld, maxDist) => {
28164
- if (o.parts.length < PART_GRID_MIN_PARTS || !lo.every(Number.isFinite) || !ld.every(Number.isFinite)) return o.parts;
28165
- partGridOf(o).candidates(lo, ld, maxDist, gridCandidates);
28166
- gridParts.length = 0;
28167
- for (const index of gridCandidates) gridParts.push(o.parts[index]);
28168
- return gridParts;
28328
+ if (o.parts.length < PART_GRID_MIN_PARTS || !(Number.isFinite(lo[0]) && Number.isFinite(lo[1]) && Number.isFinite(lo[2]) && Number.isFinite(ld[0]) && Number.isFinite(ld[1]) && Number.isFinite(ld[2]))) return -1;
28329
+ const count = partGridOf(o).candidates(lo, ld, maxDist, gridCandidates);
28330
+ for (let i = 0; i < count; i++) {
28331
+ const p = o.parts[gridCandidates[i]];
28332
+ if (i < gridParts.length) gridParts[i] = p;
28333
+ else gridParts.push(p);
28334
+ }
28335
+ return count;
28169
28336
  };
28170
28337
  const splitInto = (o, cuts) => {
28171
- const carryFor = (keep, keepOpen = () => false) => ({
28172
- parts: new Map(o.parts.filter((p) => keep(p.spec.id)).map((p) => [p.spec.id, { st: p.st, rt: p.rt }])),
28338
+ const carryFor = (keep2, keepOpen = () => false) => ({
28339
+ parts: new Map(o.parts.filter((p) => keep2(p.spec.id)).map((p) => [p.spec.id, { st: p.st, rt: p.rt }])),
28173
28340
  joints: new Map([
28174
- ...o.joints.filter((j) => keep(j.spec.a) && keep(j.spec.b) || j.st.open && keepOpen(j.spec.a, j.spec.b)).map((j) => [j.spec.id, { st: j.st, step: j.step }]),
28341
+ ...o.joints.filter((j) => keep2(j.spec.a) && keep2(j.spec.b) || j.st.open && keepOpen(j.spec.a, j.spec.b)).map((j) => [j.spec.id, { st: j.st, step: j.step }]),
28175
28342
  ...o.st.joints.filter((st) => st.open && !o.jointMap.has(st.id) && keepOpen(st.a, st.b)).map((st) => [st.id, { st, step: 0 }])
28176
28343
  ]),
28177
- collapsed: [...o.collapsed].filter(keep),
28344
+ collapsed: [...o.collapsed].filter(keep2),
28178
28345
  cast: o.cast
28179
28346
  });
28180
- const sub2 = (keep) => {
28181
- const s = { ...o.spec, parts: o.spec.parts.filter((p) => keep(p.id)), joints: (o.spec.joints ?? []).filter((j) => keep(j.a) && keep(j.b)) };
28347
+ const sub2 = (keep2) => {
28348
+ const s = { ...o.spec, parts: o.spec.parts.filter((p) => keep2(p.id)), joints: (o.spec.joints ?? []).filter((j) => keep2(j.a) && keep2(j.b)) };
28182
28349
  if (o.spec.tags) s.tags = [...o.spec.tags];
28183
28350
  return s;
28184
28351
  };
@@ -28203,6 +28370,162 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28203
28370
  let uncoveredFor = { hook: null, coverage: -1, objects: -1 };
28204
28371
  const metObjects = [];
28205
28372
  const rayObjects = [];
28373
+ let objectList = [];
28374
+ let objectListFor = -1;
28375
+ const objectsInOrder = () => {
28376
+ if (objectListFor !== objectsRevision) {
28377
+ objectList = [...objects.values()];
28378
+ objectListFor = objectsRevision;
28379
+ }
28380
+ return objectList;
28381
+ };
28382
+ let implList = [];
28383
+ let implListFor = -1;
28384
+ const implsInOrder = () => {
28385
+ if (implListFor !== implsRevision) {
28386
+ implList = [...impls.values()];
28387
+ implListFor = implsRevision;
28388
+ }
28389
+ return implList;
28390
+ };
28391
+ const NO_IMPLS = [];
28392
+ const RAY_CELL = 2;
28393
+ const RAY_GRID_BIG = 4;
28394
+ const RAY_GRID_HALF = 512;
28395
+ const RAY_GRID_MAX_CELLS = 64;
28396
+ const gridCells = /* @__PURE__ */ new Map();
28397
+ const gridCentre = [0, 0, 0];
28398
+ const gridSpans = /* @__PURE__ */ new WeakMap();
28399
+ const bigObjects = [];
28400
+ let gridFor = -1;
28401
+ let gridQuery = 0;
28402
+ const gridHits = [];
28403
+ const cellOf = (v) => Math.floor(v / RAY_CELL) | 0;
28404
+ const inGrid = (c) => c >= -RAY_GRID_HALF && c < RAY_GRID_HALF;
28405
+ const cellKey3 = (ix, iy, iz) => ix + RAY_GRID_HALF + (iy + RAY_GRID_HALF) * 1024 + (iz + RAY_GRID_HALF) * 1048576 | 0;
28406
+ const cellAt = (key2) => {
28407
+ let cell = gridCells.get(key2);
28408
+ if (!cell) {
28409
+ cell = [];
28410
+ gridCells.set(key2, cell);
28411
+ }
28412
+ return cell;
28413
+ };
28414
+ const dropFrom = (list2, o) => {
28415
+ const at4 = list2.indexOf(o);
28416
+ if (at4 < 0) return;
28417
+ list2[at4] = list2[list2.length - 1];
28418
+ list2.length--;
28419
+ };
28420
+ const unplace = (o, span) => {
28421
+ if (!span.placed) return;
28422
+ span.placed = false;
28423
+ if (span.big) {
28424
+ dropFrom(bigObjects, o);
28425
+ return;
28426
+ }
28427
+ for (let iz = span.z0; iz <= span.z1; iz++) for (let iy = span.y0; iy <= span.y1; iy++) for (let ix = span.x0; ix <= span.x1; ix++) dropFrom(cellAt(cellKey3(ix, iy, iz)), o);
28428
+ };
28429
+ const place = (o) => {
28430
+ o.raySlot = slots.get(o.id) ?? 0;
28431
+ let span = gridSpans.get(o);
28432
+ const c = rotateVecInto(o.st.rotation, o.bc, gridCentre);
28433
+ c[0] += o.st.position[0];
28434
+ c[1] += o.st.position[1];
28435
+ c[2] += o.st.position[2];
28436
+ const r = o.br;
28437
+ const x0 = cellOf(c[0] - r), y0 = cellOf(c[1] - r), z0 = cellOf(c[2] - r);
28438
+ const x1 = cellOf(c[0] + r), y1 = cellOf(c[1] + r), z1 = cellOf(c[2] + r);
28439
+ const big = !(x1 - x0 < RAY_GRID_BIG && y1 - y0 < RAY_GRID_BIG && z1 - z0 < RAY_GRID_BIG) || !(inGrid(x0) && inGrid(y0) && inGrid(z0) && inGrid(x1) && inGrid(y1) && inGrid(z1));
28440
+ if (span?.placed && span.big === big && (big || span.x0 === x0 && span.y0 === y0 && span.z0 === z0 && span.x1 === x1 && span.y1 === y1 && span.z1 === z1)) return;
28441
+ if (span) unplace(o, span);
28442
+ else {
28443
+ span = { x0, y0, z0, x1, y1, z1, big, placed: false };
28444
+ gridSpans.set(o, span);
28445
+ }
28446
+ span.x0 = x0;
28447
+ span.y0 = y0;
28448
+ span.z0 = z0;
28449
+ span.x1 = x1;
28450
+ span.y1 = y1;
28451
+ span.z1 = z1;
28452
+ span.big = big;
28453
+ span.placed = true;
28454
+ if (big) {
28455
+ bigObjects.push(o);
28456
+ return;
28457
+ }
28458
+ for (let iz = z0; iz <= z1; iz++) for (let iy = y0; iy <= y1; iy++) for (let ix = x0; ix <= x1; ix++) cellAt(cellKey3(ix, iy, iz)).push(o);
28459
+ };
28460
+ const refreshGrid = () => {
28461
+ if (gridFor !== objectsRevision) {
28462
+ for (const cell of gridCells.values()) cell.length = 0;
28463
+ bigObjects.length = 0;
28464
+ const all = objectsInOrder();
28465
+ for (let i = 0; i < all.length; i++) {
28466
+ const span = gridSpans.get(all[i]);
28467
+ if (span) span.placed = false;
28468
+ place(all[i]);
28469
+ }
28470
+ for (let i = 0; i < movedObjects.length; i++) movedObjects[i].rayMoved = false;
28471
+ movedObjects.length = 0;
28472
+ gridFor = objectsRevision;
28473
+ return;
28474
+ }
28475
+ for (let i = 0; i < movedObjects.length; i++) {
28476
+ const o = movedObjects[i];
28477
+ o.rayMoved = false;
28478
+ if (objects.get(o.id) === o) place(o);
28479
+ }
28480
+ movedObjects.length = 0;
28481
+ };
28482
+ const sortBySlot = (list2, count) => {
28483
+ for (let i = 1; i < count; i++) {
28484
+ const o = list2[i];
28485
+ let j = i - 1;
28486
+ while (j >= 0 && list2[j].raySlot > o.raySlot) {
28487
+ list2[j + 1] = list2[j];
28488
+ j--;
28489
+ }
28490
+ list2[j + 1] = o;
28491
+ }
28492
+ };
28493
+ const objectsNear = (origin, d, maxDist) => {
28494
+ if (!(maxDist < Infinity)) return -1;
28495
+ const ex = origin[0] + d[0] * maxDist, ey = origin[1] + d[1] * maxDist, ez = origin[2] + d[2] * maxDist;
28496
+ const x0 = cellOf(Math.min(origin[0], ex)), y0 = cellOf(Math.min(origin[1], ey)), z0 = cellOf(Math.min(origin[2], ez));
28497
+ const x1 = cellOf(Math.max(origin[0], ex)), y1 = cellOf(Math.max(origin[1], ey)), z1 = cellOf(Math.max(origin[2], ez));
28498
+ if (!(inGrid(x0) && inGrid(y0) && inGrid(z0) && inGrid(x1) && inGrid(y1) && inGrid(z1))) return -1;
28499
+ if ((x1 - x0 + 1) * (y1 - y0 + 1) * (z1 - z0 + 1) > RAY_GRID_MAX_CELLS) return -1;
28500
+ refreshGrid();
28501
+ const stamp = ++gridQuery;
28502
+ let count = 0;
28503
+ for (let i = 0; i < bigObjects.length; i++) {
28504
+ bigObjects[i].rayStamp = stamp;
28505
+ if (count < gridHits.length) gridHits[count] = bigObjects[i];
28506
+ else gridHits.push(bigObjects[i]);
28507
+ count++;
28508
+ }
28509
+ for (let iz = z0; iz <= z1; iz++)
28510
+ for (let iy = y0; iy <= y1; iy++)
28511
+ for (let ix = x0; ix <= x1; ix++) {
28512
+ const cell = gridCells.get(cellKey3(ix, iy, iz));
28513
+ if (!cell) continue;
28514
+ for (let i = 0; i < cell.length; i++) {
28515
+ const o = cell[i];
28516
+ if (o.rayStamp === stamp) continue;
28517
+ o.rayStamp = stamp;
28518
+ if (count < gridHits.length) gridHits[count] = o;
28519
+ else gridHits.push(o);
28520
+ count++;
28521
+ }
28522
+ }
28523
+ sortBySlot(gridHits, count);
28524
+ return count;
28525
+ };
28526
+ const NO_SKIP = {};
28527
+ const rayDirections = [];
28528
+ let rayDepth = 0;
28206
28529
  const candidatesOf2 = (hook) => {
28207
28530
  const asked = hook.candidates;
28208
28531
  if (!asked) return null;
@@ -28228,15 +28551,39 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28228
28551
  }
28229
28552
  return rayObjects;
28230
28553
  };
28231
- const raycastInternal = (origin, dir, maxDist, ignore, worldOnly = false, precise = false, skip = {}, scope2, drawn = false, passed) => {
28232
- const d = vec.normalize(dir);
28554
+ const raycastInternal = (origin, dir, maxDist, ignore, worldOnly = false, precise = false, skip = NO_SKIP, scope2, drawn = false, passed) => {
28555
+ const into = bestInto;
28556
+ bestInto = null;
28557
+ const d = rayDirections[rayDepth] ?? (rayDirections[rayDepth] = [0, 0, 0]);
28558
+ const length2 = Math.sqrt(dir[0] * dir[0] + dir[1] * dir[1] + dir[2] * dir[2]);
28559
+ if (length2 < 1e-9) {
28560
+ d[0] = 0;
28561
+ d[1] = 1;
28562
+ d[2] = 0;
28563
+ } else {
28564
+ d[0] = dir[0] / length2;
28565
+ d[1] = dir[1] / length2;
28566
+ d[2] = dir[2] / length2;
28567
+ }
28568
+ rayDepth++;
28569
+ try {
28570
+ return rayFrom(origin, d, maxDist, into, ignore, worldOnly, precise, skip, scope2, drawn, passed);
28571
+ } finally {
28572
+ rayDepth--;
28573
+ }
28574
+ };
28575
+ const rayFrom = (origin, d, maxDist, into, ignore, worldOnly, precise, skip, scope2, drawn, passed) => {
28233
28576
  const asked = rayBroad && !scope2 && rayBroad.begin(origin, d, maxDist) ? rayBroad : null;
28234
28577
  const candidates = asked ? candidatesOf2(asked) : null;
28235
28578
  const outside = candidates ? null : asked;
28236
28579
  const minRadius = skip.minObjectRadius ?? 0;
28237
28580
  let best = null;
28238
28581
  const counts = sweepCounts;
28239
- for (const o of scope2 ? scope2.objects : candidates ?? objects.values()) {
28582
+ const near = scope2 || candidates ? -1 : objectsNear(origin, d, maxDist);
28583
+ const visited = scope2 ? scope2.objects : candidates ?? (near >= 0 ? gridHits : objectsInOrder());
28584
+ const visitedCount = near >= 0 ? near : visited.length;
28585
+ for (let oi = 0; oi < visitedCount; oi++) {
28586
+ const o = visited[oi];
28240
28587
  if (counts) counts.objectVisits++;
28241
28588
  if (skip.skipLoose && o.loose || o.br < minRadius) continue;
28242
28589
  if (outside && !outside.mayMeet(o.id)) continue;
@@ -28251,7 +28598,12 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28251
28598
  objectOrigin[2] = origin[2] - o.st.position[2];
28252
28599
  const lo = rotateVecInto(objectTurnBack, objectOrigin, objectOrigin);
28253
28600
  const ld = rotateVecInto(objectTurnBack, d, objectDirection);
28254
- for (const p of scope2?.parts.get(o) ?? (counts ? o.parts : partsAlong(o, lo, ld, maxDist))) {
28601
+ const scoped = scope2?.parts.get(o);
28602
+ const gathered = scoped || counts ? -1 : partsAlong(o, lo, ld, maxDist);
28603
+ const along3 = scoped ?? (gathered >= 0 ? gridParts : o.parts);
28604
+ const alongCount = gathered >= 0 ? gathered : along3.length;
28605
+ for (let pi = 0; pi < alongCount; pi++) {
28606
+ const p = along3[pi];
28255
28607
  if (counts) counts.partVisits++;
28256
28608
  if (isLost(p) || ignore?.has(`${o.id}\0${p.spec.id}`)) continue;
28257
28609
  if (partSphereMiss(lo, ld, p, maxDist)) continue;
@@ -28260,7 +28612,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28260
28612
  counts.shapeTested.add(o.id);
28261
28613
  }
28262
28614
  const r = rayPartInto(o.st.position, o.st.rotation, p.spec, p.q, origin, d, p.pos);
28263
- if (r && r.t0 < 0 && r.t1 > 0 && p.st.chipped?.length && inGap(p, toLocal(p.pos, p.q, objLocal(o, origin)))) {
28615
+ if ((passed || skip.body) && r && r.t0 < 0 && r.t1 > 0 && p.st.chipped?.length && inGap(p, toLocal(p.pos, p.q, objLocal(o, origin)))) {
28264
28616
  r.t0 = 0;
28265
28617
  r.n = vec.scale(d, -1);
28266
28618
  }
@@ -28293,18 +28645,29 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28293
28645
  }
28294
28646
  }
28295
28647
  if (!best || r.t0 < best.distance) {
28296
- const point = vec.madd(origin, d, r.t0);
28297
- const normal = copyOf2(r.n);
28298
- const member = p.castIn ? castMemberAt(o, { p, point, normal, dir: d, pathLen: r.t1 - r.t0 }, origin, d) : null;
28299
- 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 };
28648
+ if (p.castIn) {
28649
+ const point = vec.madd(origin, d, r.t0);
28650
+ const normal = copyOf2(r.n);
28651
+ const member = castMemberAt(o, { p, point, normal, dir: d, pathLen: r.t1 - r.t0 }, origin, d);
28652
+ best = member ? keepBest(into, o.id, member.p.spec.id, member.point, member.normal, r.t0, member.pathLen) : keepBest(into, o.id, p.spec.id, point, normal, r.t0, r.t1 - r.t0);
28653
+ } else {
28654
+ rayPoint[0] = origin[0] + d[0] * r.t0;
28655
+ rayPoint[1] = origin[1] + d[1] * r.t0;
28656
+ rayPoint[2] = origin[2] + d[2] * r.t0;
28657
+ best = keepBest(into, o.id, p.spec.id, rayPoint, r.n, r.t0, r.t1 - r.t0);
28658
+ }
28300
28659
  }
28301
28660
  }
28302
28661
  }
28303
- for (const im of worldOnly ? [] : scope2 ? scope2.impls : impls.values()) {
28662
+ const hosted = worldOnly ? NO_IMPLS : scope2 ? scope2.impls : implsInOrder();
28663
+ for (let ii = 0; ii < hosted.length; ii++) {
28664
+ const im = hosted[ii];
28304
28665
  if (counts) counts.objectVisits++;
28305
28666
  if (!scope2 && broadPhase && rayMissesBounds(origin, d, maxDist, implBoundsOf(im))) continue;
28306
28667
  let boxHit = null;
28307
- for (const ps of scope2?.implParts.get(im) ?? im.impl.describe().parts) {
28668
+ const implParts2 = scope2?.implParts.get(im) ?? im.impl.describe().parts;
28669
+ for (let si = 0; si < implParts2.length; si++) {
28670
+ const ps = implParts2[si];
28308
28671
  if (counts) counts.partVisits++;
28309
28672
  if (ignore?.has(`${im.impl.id}\0${ps.id}`)) continue;
28310
28673
  if (counts) {
@@ -28325,8 +28688,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28325
28688
  const far = best ? Math.min(maxDist, best.distance) : maxDist;
28326
28689
  const implId = im.impl.id;
28327
28690
  const s = im.impl.surfaceRay({ origin, direction: d, maxDistance: far, ...ignore ? { ignored: (part) => ignore.has(`${implId}\0${part}`) } : {} });
28328
- if (s && (!best || s.distance < best.distance)) best = { object: implId, part: s.part, point: s.point, normal: s.normal, distance: s.distance, pathLen: s.pathLen };
28329
- } else if (!best || boxHit.distance < best.distance) best = boxHit;
28691
+ if (s && (!best || s.distance < best.distance)) best = keepBest(into, implId, s.part, s.point, s.normal, s.distance, s.pathLen);
28692
+ } else if (!best || boxHit.distance < best.distance) best = into ? keepBest(into, boxHit.object, boxHit.part, boxHit.point, boxHit.normal, boxHit.distance, boxHit.pathLen) : boxHit;
28330
28693
  }
28331
28694
  return best;
28332
28695
  };
@@ -28790,8 +29153,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28790
29153
  const dv = lp[v] - (ap.offset?.[1] ?? 0);
28791
29154
  if (Math.abs(du) > ap.size[0] / 2 || Math.abs(dv) > ap.size[1] / 2) return false;
28792
29155
  if (!ap.bars || ap.bars.spacing <= 0) return true;
28793
- const along2 = ap.bars.axis === 0 ? du + ap.size[0] / 2 : dv + ap.size[1] / 2;
28794
- return Math.abs(along2 - Math.round(along2 / ap.bars.spacing) * ap.bars.spacing) > ap.bars.width / 2;
29156
+ const along3 = ap.bars.axis === 0 ? du + ap.size[0] / 2 : dv + ap.size[1] / 2;
29157
+ return Math.abs(along3 - Math.round(along3 / ap.bars.spacing) * ap.bars.spacing) > ap.bars.width / 2;
28795
29158
  });
28796
29159
  };
28797
29160
  const breachAreaOf = (p, damage, blast) => damage / (p.mat.hpPerKg * p.mat.density) / Math.max(p.thickness, 5e-3) * (blast ? breachBlastFactor : 1);
@@ -29035,9 +29398,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
29035
29398
  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);
29036
29399
  const coreStands = (p, lp) => {
29037
29400
  if (!p.spec.reinforcement || !isMember(p.dims, p.spec.structure?.role) || p.st.stripped) return false;
29038
- const along2 = p.dims.indexOf(Math.max(...p.dims));
29039
- const bands = Math.max(1, Math.round(p.dims[along2] / MEMBER_BAND));
29040
- const band = clamp2(Math.floor((lp[along2] + p.dims[along2] / 2) / p.dims[along2] * bands), 0, bands - 1);
29401
+ const along3 = p.dims.indexOf(Math.max(...p.dims));
29402
+ const bands = Math.max(1, Math.round(p.dims[along3] / MEMBER_BAND));
29403
+ const band = clamp2(Math.floor((lp[along3] + p.dims[along3] / 2) / p.dims[along3] * bands), 0, bands - 1);
29041
29404
  return (p.rt.bands?.[band] ?? 0) < MEMBER_CUT_LOSS;
29042
29405
  };
29043
29406
  const insideChip = (p, objectPoint) => {
@@ -29048,35 +29411,35 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
29048
29411
  if (coreStands(p, lp)) return false;
29049
29412
  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);
29050
29413
  };
29051
- const alongAt = (along2, at4) => {
29414
+ const alongAt = (along3, at4) => {
29052
29415
  const point = [0, 0, 0];
29053
- point[along2] = at4;
29416
+ point[along3] = at4;
29054
29417
  return point;
29055
29418
  };
29056
29419
  const wornLocally = (p) => !!p.spec.reinforcement && !!p.spec.units && p.spec.units.mortar === p.spec.material && isMember(p.dims, p.spec.structure?.role) && p.spec.shape.kind === "box";
29057
29420
  const wearMember = (o, p, entry2, d, E, caliber, penMm, src) => {
29058
29421
  var _a, _b, _c;
29059
29422
  if (!p.spec.reinforcement || !p.spec.units || !isMember(p.dims, p.spec.structure?.role) || p.st.stripped || isLost(p) || p.spec.shape.kind !== "box") return false;
29060
- const along2 = p.dims.indexOf(Math.max(...p.dims));
29423
+ const along3 = p.dims.indexOf(Math.max(...p.dims));
29061
29424
  const lp = toLocal(p.pos, p.q, objLocal(o, entry2));
29062
29425
  const ld = rotateVec(quat.conjugate(p.q), objLocalDir(o, d));
29063
29426
  let depth = Infinity;
29064
- for (let a = 0; a < 3; a++) if (a !== along2 && Math.abs(ld[a]) > 1e-3) depth = Math.min(depth, p.dims[a] / Math.abs(ld[a]));
29427
+ for (let a = 0; a < 3; a++) if (a !== along3 && Math.abs(ld[a]) > 1e-3) depth = Math.min(depth, p.dims[a] / Math.abs(ld[a]));
29065
29428
  if (!Number.isFinite(depth)) return true;
29066
29429
  const into = (penMm ?? E / Math.max(p.mat.penetration, 1e-6)) / 1e3;
29067
29430
  const h = Math.min(into, depth);
29068
29431
  const r = Math.min(MEMBER_CRATER_CALIBRES * caliber / 1e3, h);
29069
29432
  const volume = Math.PI / 3 * r * r * h;
29070
- const section = p.dims.reduce((product2, size, a) => a === along2 ? product2 : product2 * size, 1);
29071
- const bands = Math.max(1, Math.round(p.dims[along2] / MEMBER_BAND));
29072
- const band = clamp2(Math.floor((lp[along2] + p.dims[along2] / 2) / p.dims[along2] * bands), 0, bands - 1);
29073
- const height = p.dims[along2] / bands;
29433
+ const section = p.dims.reduce((product2, size, a) => a === along3 ? product2 : product2 * size, 1);
29434
+ const bands = Math.max(1, Math.round(p.dims[along3] / MEMBER_BAND));
29435
+ const band = clamp2(Math.floor((lp[along3] + p.dims[along3] / 2) / p.dims[along3] * bands), 0, bands - 1);
29436
+ const height = p.dims[along3] / bands;
29074
29437
  const worn = (_a = p.rt).bands ?? (_a.bands = {});
29075
29438
  const before = worn[band] ?? 0;
29076
29439
  const after2 = Math.min(1, before + volume / (section * height));
29077
29440
  worn[band] = after2;
29078
29441
  markDamaged(p);
29079
- const bandCenter = -p.dims[along2] / 2 + (band + 0.5) * height;
29442
+ const bandCenter = -p.dims[along3] / 2 + (band + 0.5) * height;
29080
29443
  const grid = gridOf(p);
29081
29444
  const gone = (_b = p.rt).chips ?? (_b.chips = {});
29082
29445
  if (before >= MEMBER_CUT_LOSS || after2 < MEMBER_CUT_LOSS) {
@@ -29093,11 +29456,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
29093
29456
  const out = [];
29094
29457
  for (let i = 0; i < grid.length; i++) {
29095
29458
  if (gone[i] === -1) continue;
29096
- if (Math.abs(grid[i].center[along2] - bandCenter) <= height / 2 + 1e-6) out.push(i);
29459
+ if (Math.abs(grid[i].center[along3] - bandCenter) <= height / 2 + 1e-6) out.push(i);
29097
29460
  }
29098
29461
  worn[band] = 1;
29099
29462
  if (out.length > 0) knockOutUnits(o, p, entry2, E, out, src, d);
29100
- giveAtCut(o, p, src, { at: alongAt(along2, bandCenter), d });
29463
+ giveAtCut(o, p, src, { at: alongAt(along3, bandCenter), d });
29101
29464
  return true;
29102
29465
  };
29103
29466
  const chipUnits = (o, p, kind, wp, hitEnergy, dir, radius, src) => {
@@ -29189,8 +29552,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
29189
29552
  const lo = cell.center[a] - cell.size[a] / 2, hi = cell.center[a] + cell.size[a] / 2;
29190
29553
  const free = (side, sign2) => {
29191
29554
  if (sign2 > 0 ? side >= half - 1e-6 : side <= -half + 1e-6) return sign2 > 0 || a !== planeAxes(p.thin)[1];
29192
- const probe = side + sign2 * 1e-3;
29193
- return gridOf(p).some((c, k) => gone(k) && Math.abs(probe - c.center[a]) <= c.size[a] / 2 && Math.abs(cell.center[b] - c.center[b]) <= c.size[b] / 2);
29555
+ const probe2 = side + sign2 * 1e-3;
29556
+ return gridOf(p).some((c, k) => gone(k) && Math.abs(probe2 - c.center[a]) <= c.size[a] / 2 && Math.abs(cell.center[b] - c.center[b]) <= c.size[b] / 2);
29194
29557
  };
29195
29558
  if (at4 - lo <= reach2 && free(lo, -1)) return [lo, Math.max(crater2[1], lo)];
29196
29559
  if (hi - at4 <= reach2 && free(hi, 1)) return [Math.min(crater2[0], hi), hi];
@@ -29484,19 +29847,19 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
29484
29847
  };
29485
29848
  const cutBandsGone = (o, p, cells, d, src) => {
29486
29849
  var _a;
29487
- const along2 = p.dims.indexOf(Math.max(...p.dims));
29488
- const bands = Math.max(1, Math.round(p.dims[along2] / MEMBER_BAND));
29489
- const height = p.dims[along2] / bands;
29490
- const bandOf2 = (at4) => clamp2(Math.floor((at4 + p.dims[along2] / 2) / p.dims[along2] * bands), 0, bands - 1);
29850
+ const along3 = p.dims.indexOf(Math.max(...p.dims));
29851
+ const bands = Math.max(1, Math.round(p.dims[along3] / MEMBER_BAND));
29852
+ const height = p.dims[along3] / bands;
29853
+ const bandOf2 = (at4) => clamp2(Math.floor((at4 + p.dims[along3] / 2) / p.dims[along3] * bands), 0, bands - 1);
29491
29854
  const grid = gridOf(p);
29492
29855
  const gone = p.rt.chips ?? {};
29493
29856
  const worn = (_a = p.rt).bands ?? (_a.bands = {});
29494
- for (const band of new Set(cells.map((cell) => bandOf2(cell.center[along2])))) {
29857
+ for (const band of new Set(cells.map((cell) => bandOf2(cell.center[along3])))) {
29495
29858
  if ((worn[band] ?? 0) >= 1) continue;
29496
- const center = -p.dims[along2] / 2 + (band + 0.5) * height;
29497
- if (!grid.every((cell, i) => gone[i] === -1 || Math.abs(cell.center[along2] - center) > height / 2 + 1e-6)) continue;
29859
+ const center = -p.dims[along3] / 2 + (band + 0.5) * height;
29860
+ if (!grid.every((cell, i) => gone[i] === -1 || Math.abs(cell.center[along3] - center) > height / 2 + 1e-6)) continue;
29498
29861
  worn[band] = 1;
29499
- return giveAtCut(o, p, src, { at: alongAt(along2, center), d });
29862
+ return giveAtCut(o, p, src, { at: alongAt(along3, center), d });
29500
29863
  }
29501
29864
  return false;
29502
29865
  };
@@ -29541,14 +29904,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
29541
29904
  const r = p.spec.reinforcement;
29542
29905
  if (!r) return 0;
29543
29906
  const left = rebarBars(p.dims, p.thin, r.spacing, p.spec.structure?.role).length - (p.rt.severedBars?.length ?? 0);
29544
- const along2 = p.dims.indexOf(Math.max(...p.dims));
29545
- const side = Math.min(...p.dims.filter((_, a) => a !== along2));
29907
+ const along3 = p.dims.indexOf(Math.max(...p.dims));
29908
+ const side = Math.min(...p.dims.filter((_, a) => a !== along3));
29546
29909
  const fy = (materials.get(r.material)?.bending?.yieldMPa ?? STEEL_YIELD_MPA) * 1e6;
29547
29910
  return Math.max(0, left) / 2 * Math.PI * (r.diameter / 2) ** 2 * fy * Math.max(0, side - 2 * REBAR_COVER);
29548
29911
  };
29549
29912
  const memberSide = (p) => {
29550
- const along2 = p.dims.indexOf(Math.max(...p.dims));
29551
- return Math.min(...p.dims.filter((_, a) => a !== along2));
29913
+ const along3 = p.dims.indexOf(Math.max(...p.dims));
29914
+ return Math.min(...p.dims.filter((_, a) => a !== along3));
29552
29915
  };
29553
29916
  const tubeMoment = (p, share) => {
29554
29917
  const [a = 0, b = 0] = [...p.dims].sort((x, y) => x - y);
@@ -29590,8 +29953,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
29590
29953
  const barAlong = (o, p, origin, d, t0, t1) => {
29591
29954
  const r = p.spec.reinforcement;
29592
29955
  if (!r || !isMember(p.dims, p.spec.structure?.role)) return null;
29593
- const along2 = p.dims.indexOf(Math.max(...p.dims));
29594
- const [u, v] = [0, 1, 2].filter((k) => k !== along2);
29956
+ const along3 = p.dims.indexOf(Math.max(...p.dims));
29957
+ const [u, v] = [0, 1, 2].filter((k) => k !== along3);
29595
29958
  const lo = toLocal(p.pos, p.q, objLocal(o, origin));
29596
29959
  const ld = rotateVec(quat.conjugate(p.q), objLocalDir(o, d));
29597
29960
  const across2 = Math.hypot(ld[u], ld[v]);
@@ -29640,8 +30003,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
29640
30003
  var _a;
29641
30004
  const r = p.spec.reinforcement;
29642
30005
  if (!r || isLost(p) || !isMember(p.dims, p.spec.structure?.role)) return;
29643
- const along2 = p.dims.indexOf(Math.max(...p.dims));
29644
- const [u, v] = [0, 1, 2].filter((k) => k !== along2);
30006
+ const along3 = p.dims.indexOf(Math.max(...p.dims));
30007
+ const [u, v] = [0, 1, 2].filter((k) => k !== along3);
29645
30008
  const lo = toLocal(p.pos, p.q, objLocal(o, origin));
29646
30009
  const ld = rotateVec(quat.conjugate(p.q), objLocalDir(o, d));
29647
30010
  const across2 = Math.hypot(ld[u], ld[v]);
@@ -29752,7 +30115,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
29752
30115
  const hitLocal = toLocal(c, q, hitW);
29753
30116
  const unitPlan = p.spec.units ? unitFragmentPlan(p, maxFragments * UNIT_FRAGMENT_FACTOR) : [];
29754
30117
  const axis2 = style === "splinter" || style === "snap" ? severAxis(p) : -1;
29755
- const cutAt2 = axis2 < 0 ? void 0 : p.rt.cutAt ?? (origin ? hitLocal[axis2] : void 0);
30118
+ const cutAt3 = axis2 < 0 ? void 0 : p.rt.cutAt ?? (origin ? hitLocal[axis2] : void 0);
29756
30119
  const planRnd = p.mat.splitForm ? splitStream(o.id, p.spec.id, hitLocal) : rnd2;
29757
30120
  const plan = unitPlan.length > 0 ? unitPlan : planFragments({
29758
30121
  style,
@@ -29765,7 +30128,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
29765
30128
  rnd: planRnd,
29766
30129
  sheet: p.mat.sheet,
29767
30130
  ...p.mat.splitForm ? { form: p.mat.splitForm } : {},
29768
- ...cutAt2 !== void 0 ? { cut: { at: cutAt2, gap: SEVER_BAND } } : {},
30131
+ ...cutAt3 !== void 0 ? { cut: { at: cutAt3, gap: SEVER_BAND } } : {},
29769
30132
  ...p.spec.solids ? { solids: p.spec.solids } : {}
29770
30133
  });
29771
30134
  const holes = p.st.holes.length > 0 ? localHolesOf(p) : [];
@@ -29842,9 +30205,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
29842
30205
  };
29843
30206
  const bandOf = (o, p, axis2, origin) => {
29844
30207
  const { c, q } = partXf(o, p);
29845
- const along2 = toLocal(c, q, origin)[axis2];
30208
+ const along3 = toLocal(c, q, origin)[axis2];
29846
30209
  const L = p.dims[axis2];
29847
- return clamp2(Math.floor((along2 + L / 2) / SEVER_BAND), 0, Math.ceil(L / SEVER_BAND) - 1);
30210
+ return clamp2(Math.floor((along3 + L / 2) / SEVER_BAND), 0, Math.ceil(L / SEVER_BAND) - 1);
29848
30211
  };
29849
30212
  const applyDamage = (o, p, amount, type, origin, dir, fragEnergy, cap, src, weight = 1, section = 1) => {
29850
30213
  var _a;
@@ -29913,7 +30276,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
29913
30276
  const fibre = tear === "lumps";
29914
30277
  const strips = tear === "strips";
29915
30278
  const { q } = partXf(o, p);
29916
- const along2 = (p.spec.grain ? AXIS[p.spec.grain] : void 0) ?? [0, 1, 2].sort((a, b) => p.dims[b] - p.dims[a])[0];
30279
+ const along3 = (p.spec.grain ? AXIS[p.spec.grain] : void 0) ?? [0, 1, 2].sort((a, b) => p.dims[b] - p.dims[a])[0];
29917
30280
  const fragments = [];
29918
30281
  for (let i = 0; i < n; i++) {
29919
30282
  const back2 = !exit || i % 3 === 2;
@@ -29921,9 +30284,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
29921
30284
  const len = scale * (fibre ? 1.2 + 1.2 * rnd2() : strips ? 6 + 6 * rnd2() : 3 + 4 * rnd2()), w = scale * (strips ? 1 + rnd2() : 0.8 + 0.8 * rnd2());
29922
30285
  const t = strips ? Math.min(p.thickness, STRIP_THICKNESS) : scale * (fibre ? 0.7 + 0.6 * rnd2() : plies ? 0.15 + 0.15 * rnd2() : 0.4 + 0.4 * rnd2());
29923
30286
  const size = [w, w, w];
29924
- size[along2] = len;
29925
- size[(along2 + 1) % 3] = w;
29926
- size[(along2 + 2) % 3] = t;
30287
+ size[along3] = len;
30288
+ size[(along3 + 1) % 3] = w;
30289
+ size[(along3 + 2) % 3] = t;
29927
30290
  const spread3 = [(rnd2() - 0.5) * 0.8, (rnd2() - 0.2) * 0.8, (rnd2() - 0.5) * 0.8];
29928
30291
  const speed = shot ? back2 ? 1.5 + 2 * rnd2() : 2 + 4 * rnd2() : 0.8 + 1.2 * rnd2();
29929
30292
  const v = vec.scale(vec.normalize(vec.add(back2 ? vec.scale(d, -1) : d, spread3)), speed);
@@ -30063,8 +30426,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
30063
30426
  j.st.open = true;
30064
30427
  j.st.openedBy = "break";
30065
30428
  }
30066
- const along2 = p.dims.indexOf(Math.max(...p.dims));
30067
- hingeAcross(o, p, opened, { at: alongAt(along2, toLocal(p.pos, p.q, objLocal(o, entry2))[along2]), d, behind: memberSide(p) / 2, moment: tubeMoment(p, share) }, src);
30429
+ const along3 = p.dims.indexOf(Math.max(...p.dims));
30430
+ hingeAcross(o, p, opened, { at: alongAt(along3, toLocal(p.pos, p.q, objLocal(o, entry2))[along3]), d, behind: memberSide(p) / 2, moment: tubeMoment(p, share) }, src);
30068
30431
  loosened(o, opened, "break", src);
30069
30432
  collapseCheck(o, src);
30070
30433
  };
@@ -30427,7 +30790,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
30427
30790
  if (!r?.part) continue;
30428
30791
  reportShelter(o, r);
30429
30792
  out.push(r);
30430
- for (const [part, factor] of Object.entries(r.blast?.parts ?? {})) summary2.push({ object: o.id, part, factor });
30793
+ for (const [part, factor2] of Object.entries(r.blast?.parts ?? {})) summary2.push({ object: o.id, part, factor: factor2 });
30431
30794
  fragmentHits += r.blast?.fragmentHits ?? 0;
30432
30795
  }
30433
30796
  for (const im of impls.values()) {
@@ -30554,8 +30917,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
30554
30917
  const lineMeetsSphere = (t, point, d, range3) => {
30555
30918
  if (t.distance - t.radius >= range3) return false;
30556
30919
  if (t.distance <= t.radius) return true;
30557
- const along2 = (t.centre[0] - point[0]) * d[0] + (t.centre[1] - point[1]) * d[1] + (t.centre[2] - point[2]) * d[2];
30558
- return along2 > 0 && t.distance * t.distance - along2 * along2 <= t.radius * t.radius;
30920
+ const along3 = (t.centre[0] - point[0]) * d[0] + (t.centre[1] - point[1]) * d[1] + (t.centre[2] - point[2]) * d[2];
30921
+ return along3 > 0 && t.distance * t.distance - along3 * along3 <= t.radius * t.radius;
30559
30922
  };
30560
30923
  const boxDirection = [0, 0, 0];
30561
30924
  const lineMeetsBox = (box5, d, range3) => {
@@ -31314,6 +31677,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
31314
31677
  finishExplosions();
31315
31678
  const id = opts.id ?? impl.id;
31316
31679
  if (taken(id)) throw new Error(`object "${id}" already exists`);
31680
+ implsRevision++;
31317
31681
  impls.set(id, { impl, position: opts.position ?? [0, 0, 0], rotation: opts.rotation ?? [0, 0, 0, 1], poses: /* @__PURE__ */ new Map(), posesVersion: 0 });
31318
31682
  return id;
31319
31683
  },
@@ -31335,6 +31699,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
31335
31699
  poseVersion++;
31336
31700
  objectPoses.set(o, (objectPoses.get(o) ?? 0) + 1);
31337
31701
  updateBound(o);
31702
+ markMoved(o);
31338
31703
  if (o.hosted && (o.hostedHosts?.has(partId) || p.spec.hostedIn !== void 0 && p.st.exposed !== true)) dirtyHosted.add(o);
31339
31704
  },
31340
31705
  remove(id) {
@@ -31344,6 +31709,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
31344
31709
  if (existing) dirtyHosted.delete(existing);
31345
31710
  dropObject(id);
31346
31711
  impls.delete(id);
31712
+ implsRevision++;
31347
31713
  },
31348
31714
  has: (id) => taken(id),
31349
31715
  ids: () => [...objects.keys(), ...impls.keys()],
@@ -31479,6 +31845,29 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
31479
31845
  const terrain = objects.get(r.object)?.parts.find((p) => p.spec.id === r.part)?.spec.tags?.includes("terrain") === true;
31480
31846
  return { object: r.object, part: r.part, point: r.point, normal: r.normal, distance: r.distance, ...terrain ? { terrain: true } : {} };
31481
31847
  },
31848
+ raycastInto(origin, direction, maxDistance, out, options2) {
31849
+ const ignoredParts = options2?.ignoreParts;
31850
+ const ignore = ignoredParts?.length ? new Set(ignoredParts.map((ignored) => `${ignored.object}\0${ignored.part}`)) : void 0;
31851
+ bestInto = bestScratch;
31852
+ let r;
31853
+ try {
31854
+ r = raycastInternal(origin, direction, maxDistance, ignore, false, true, options2);
31855
+ } finally {
31856
+ bestInto = null;
31857
+ }
31858
+ if (!r) return false;
31859
+ out.object = r.object;
31860
+ out.part = r.part;
31861
+ out.point[0] = r.point[0];
31862
+ out.point[1] = r.point[1];
31863
+ out.point[2] = r.point[2];
31864
+ out.normal[0] = r.normal[0];
31865
+ out.normal[1] = r.normal[1];
31866
+ out.normal[2] = r.normal[2];
31867
+ out.distance = r.distance;
31868
+ out.terrain = isTerrainPart(r.object, r.part);
31869
+ return true;
31870
+ },
31482
31871
  sweepBox(box5, direction, distance4, options2 = {}) {
31483
31872
  const d = vec.normalize(direction);
31484
31873
  const ignoredIds = options2.ignore === void 0 ? [] : typeof options2.ignore === "string" ? [options2.ignore] : options2.ignore;
@@ -31737,7 +32126,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
31737
32126
  ...p.spec.shape.kind === "cylinder" ? { round: true } : {}
31738
32127
  }));
31739
32128
  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 }));
31740
- return assemblyFlex({ parts: parts2, joints, lost: [...lost], ...options2?.loads ? { loads: options2.loads } : {}, ...options2?.friction !== void 0 ? { friction: options2.friction } : {} });
32129
+ return assemblyFlex({ parts: parts2, joints, lost: [...lost], ...options2?.loads ? { loads: options2.loads } : {}, ...options2?.friction !== void 0 ? { friction: options2.friction } : {}, ...options2?.linear ? { linear: options2.linear } : {} });
31741
32130
  },
31742
32131
  reset(id) {
31743
32132
  finishExplosions();
@@ -32058,17 +32447,17 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
32058
32447
  return new Map(w.state(id).parts.map((p) => [p.id, p.flexure ?? 0]));
32059
32448
  };
32060
32449
  const base2 = bending(out);
32061
- const factor = new Map(targets.map((p) => [p.id, (base2.get(p.id) ?? 0) / safetyOf(p.structure.role)]));
32450
+ const factor2 = new Map(targets.map((p) => [p.id, (base2.get(p.id) ?? 0) / safetyOf(p.structure.role)]));
32062
32451
  if (options.redundancy !== void 0) {
32063
32452
  const roles = options.redundancyRoles ?? ["column"];
32064
32453
  for (const lost of out.parts) {
32065
32454
  if (!lost.structure || !roles.includes(lost.structure.role)) continue;
32066
32455
  const l = bending(without(out, lost.id));
32067
- for (const p of targets) if (p.id !== lost.id) factor.set(p.id, Math.max(factor.get(p.id), (l.get(p.id) ?? 0) / options.redundancy));
32456
+ for (const p of targets) if (p.id !== lost.id) factor2.set(p.id, Math.max(factor2.get(p.id), (l.get(p.id) ?? 0) / options.redundancy));
32068
32457
  }
32069
32458
  }
32070
32459
  for (const p of targets) {
32071
- const f = factor.get(p.id);
32460
+ const f = factor2.get(p.id);
32072
32461
  const g = bendGeometry(p);
32073
32462
  if (f <= 1 || g.gravity < 0) continue;
32074
32463
  const section = { b: sectionWidth(g, g.gravity), h: g.dims[g.gravity] };
@@ -32886,19 +33275,19 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
32886
33275
  const padded = holds2(line, 0.02, wall.aabb);
32887
33276
  if (!padded) continue;
32888
33277
  const reach2 = context.section.along / 2;
32889
- const along2 = [padded[0] + (padded[0] > 0 ? PLAN_TOLERANCE + JAMB_CLEAR + reach2 : 0), padded[1] - (padded[1] < line.to - line.from ? PLAN_TOLERANCE + JAMB_CLEAR + reach2 : 0)];
32890
- if (along2[1] <= along2[0]) continue;
33278
+ const along3 = [padded[0] + (padded[0] > 0 ? PLAN_TOLERANCE + JAMB_CLEAR + reach2 : 0), padded[1] - (padded[1] < line.to - line.from ? PLAN_TOLERANCE + JAMB_CLEAR + reach2 : 0)];
33279
+ if (along3[1] <= along3[0]) continue;
32891
33280
  const alongU = wall.aabb[2] - wall.aabb[0] >= wall.aabb[3] - wall.aabb[1];
32892
33281
  const openings = context.structure.openings.filter((o) => o.wall === wall.id);
32893
33282
  if (line.dir === "u" === alongU) {
32894
- let pieces = [along2];
33283
+ let pieces = [along3];
32895
33284
  for (const o of openings) {
32896
33285
  const a = o.from - line.from - JAMB_CLEAR - reach2;
32897
33286
  const b = o.to - line.from + JAMB_CLEAR + reach2;
32898
33287
  pieces = pieces.flatMap(([x, y]) => b <= x || a >= y ? [[x, y]] : [[x, a], [b, y]].filter(([p, q]) => q > p));
32899
33288
  }
32900
33289
  out.push(...pieces);
32901
- } else if (!openings.some((o) => line.at > o.from - 0.1 && line.at < o.to + 0.1)) out.push(along2);
33290
+ } else if (!openings.some((o) => line.at > o.from - 0.1 && line.at < o.to + 0.1)) out.push(along3);
32902
33291
  }
32903
33292
  const bottom = context.structure.levels[floor2] ?? 0;
32904
33293
  const half = context.section.along / 2;
@@ -33412,9 +33801,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
33412
33801
  const capacity = input.capacities.get(id);
33413
33802
  capacities.delete(id);
33414
33803
  if (capacity === void 0) continue;
33415
- const along2 = (box22) => Math.max(box22[2] - box22[0], box22[3] - box22[1]);
33416
- const length2 = along2(input.parts.find((part) => part.id === id).aabb);
33417
- for (const piece3 of split.pieces) capacities.set(piece3.id, Math.max(1, capacity * along2(piece3.aabb) / length2));
33804
+ const along3 = (box22) => Math.max(box22[2] - box22[0], box22[3] - box22[1]);
33805
+ const length2 = along3(input.parts.find((part) => part.id === id).aabb);
33806
+ for (const piece3 of split.pieces) capacities.set(piece3.id, Math.max(1, capacity * along3(piece3.aabb) / length2));
33418
33807
  }
33419
33808
  return { ...next, capacities };
33420
33809
  }
@@ -33430,14 +33819,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
33430
33819
  const size = part.shape.size;
33431
33820
  const thin = size.indexOf(Math.min(...size));
33432
33821
  if (thin === 1) return [];
33433
- const [along2] = planeAxes2(thin);
33822
+ const [along3] = planeAxes2(thin);
33434
33823
  const turn2 = part.rotation?.[1] ?? 0;
33435
33824
  const alongU = Math.abs(Math.cos(turn2)) * size[0] + Math.abs(Math.sin(turn2)) * size[2] >= Math.abs(Math.sin(turn2)) * size[0] + Math.abs(Math.cos(turn2)) * size[2];
33436
33825
  return windows.map((opening2) => {
33437
33826
  const middle = (opening2.from + opening2.to) / 2;
33438
33827
  const centre2 = alongU ? [middle, (opening2.y0 + opening2.y1) / 2, part.position[2]] : [part.position[0], (opening2.y0 + opening2.y1) / 2, middle];
33439
33828
  const local2 = toPartFrame(part, centre2);
33440
- return { size: [opening2.to - opening2.from, opening2.y1 - opening2.y0], offset: [local2[along2], local2[1]] };
33829
+ return { size: [opening2.to - opening2.from, opening2.y1 - opening2.y0], offset: [local2[along3], local2[1]] };
33441
33830
  });
33442
33831
  }
33443
33832
  function withWindowApertures(spec, openings) {
@@ -33764,21 +34153,21 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
33764
34153
  parts2.push({ id, material: c.material, shape: box2(size), position, structure: { role: "partition" }, tags: ["infill"] });
33765
34154
  for (const o of on) rests(joints, id, o, "mortar");
33766
34155
  };
33767
- const bay = (side, k, along2, centre2, fixed2, length2, c1, c2) => {
34156
+ const bay = (side, k, along3, centre2, fixed2, length2, c1, c2) => {
33768
34157
  const clear = length2 - g.columnSize;
33769
34158
  const win = clear * c.window;
33770
34159
  const pier = (clear - win) / 2;
33771
- const at23 = (u) => along2 === 0 ? [u, 0, fixed2] : [fixed2, 0, u];
33772
- const size = (u, h) => along2 === 0 ? [u, h, c.thickness] : [c.thickness, h, u];
33773
- const put = (name, u, h, y, centreU, on) => {
34160
+ const at23 = (u) => along3 === 0 ? [u, 0, fixed2] : [fixed2, 0, u];
34161
+ const size = (u, h) => along3 === 0 ? [u, h, c.thickness] : [c.thickness, h, u];
34162
+ const put2 = (name, u, h, y, centreU, on) => {
33774
34163
  const p = at23(centreU);
33775
34164
  wall(`infill_${f}_${side}_${k}_${name}`, size(u, h), [p[0], y, p[2]], on);
33776
34165
  };
33777
34166
  const id = (name) => `infill_${f}_${side}_${k}_${name}`;
33778
- put("sill", clear, sill, yb + sill / 2, centre2, [c1, c2]);
33779
- put("pl", pier, head - sill, yb + sill + (head - sill) / 2, centre2 - clear / 2 + pier / 2, [c1, id("sill")]);
33780
- put("pr", pier, head - sill, yb + sill + (head - sill) / 2, centre2 + clear / 2 - pier / 2, [c2, id("sill")]);
33781
- put("head", clear, room - head, yb + head + (room - head) / 2, centre2, [c1, c2]);
34167
+ put2("sill", clear, sill, yb + sill / 2, centre2, [c1, c2]);
34168
+ put2("pl", pier, head - sill, yb + sill + (head - sill) / 2, centre2 - clear / 2 + pier / 2, [c1, id("sill")]);
34169
+ put2("pr", pier, head - sill, yb + sill + (head - sill) / 2, centre2 + clear / 2 - pier / 2, [c2, id("sill")]);
34170
+ put2("head", clear, room - head, yb + head + (room - head) / 2, centre2, [c1, c2]);
33782
34171
  const gp = at23(centre2);
33783
34172
  const gid = `glass_${f}_${side}_${k}`;
33784
34173
  parts2.push({
@@ -33868,24 +34257,24 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
33868
34257
  const floor2 = `slab_${level - 1}`;
33869
34258
  const y = storeyBase(g, level);
33870
34259
  const shafts = options.shafts ?? [];
33871
- const put = (id, material, size, at23, mass, extra = {}) => {
34260
+ const put2 = (id, material, size, at23, mass, extra = {}) => {
33872
34261
  parts2.push({ id: id + sfx, material, shape: box2(size), position: [at23[0], y + size[1] / 2, at23[1]], mass, fill: 0.2, structure: { role: "partition" }, tags: ["mechanical"], ...extra });
33873
34262
  rests(joints, id + sfx, floor2, "bolt");
33874
34263
  };
33875
- shafts.forEach((at23, k) => put(`machine_${k}`, "steel", [1.2, 1, 0.8], at23, c.machineMass + c.suspendedMass, { tags: ["mechanical", "elevator_machine"] }));
34264
+ shafts.forEach((at23, k) => put2(`machine_${k}`, "steel", [1.2, 1, 0.8], at23, c.machineMass + c.suspendedMass, { tags: ["mechanical", "elevator_machine"] }));
33876
34265
  const liters = options.waterLiters ?? towerWater(level, options);
33877
34266
  const depth = 2;
33878
34267
  const side = Math.sqrt(liters / 1e3 / depth);
33879
34268
  const [hx] = slabHalf(g);
33880
34269
  const tankAt = options.tankAt ?? [-hx / 2, 0];
33881
34270
  const shell = 4 * side * depth + 2 * side * side;
33882
- put("water_tank", c.tankMaterial, [side, depth, side], tankAt, liters + 1100 * c.tankWall * shell, {
34271
+ put2("water_tank", c.tankMaterial, [side, depth, side], tankAt, liters + 1100 * c.tankWall * shell, {
33883
34272
  fill: shell * c.tankWall / (side * side * depth),
33884
34273
  thickness: c.tankWall,
33885
34274
  contains: { fluid: "water", liters },
33886
34275
  tags: ["mechanical", "water_tank"]
33887
34276
  });
33888
- for (let k = 0; k < c.chillers; k++) put(`chiller_${k}`, "steel", [3, 2, 1.5], [-hx + 2 + k * 3.5, -(slabHalf(g)[1] - 2)], c.chillerMass, { tags: ["mechanical", "chiller"] });
34277
+ for (let k = 0; k < c.chillers; k++) put2(`chiller_${k}`, "steel", [3, 2, 1.5], [-hx + 2 + k * 3.5, -(slabHalf(g)[1] - 2)], c.chillerMass, { tags: ["mechanical", "chiller"] });
33889
34278
  return { ...spec, parts: parts2, joints };
33890
34279
  }
33891
34280
  var DAMPER_DEFAULTS = { ratio: 0.01, modalShare: 0.25, material: "steel", maxHeight: 2.5 };
@@ -34079,8 +34468,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
34079
34468
  const ti = given2.innerThickness ?? CORE_DEFAULTS.innerThickness;
34080
34469
  const shaft = given2.shaft ?? CORE_DEFAULTS.shaft;
34081
34470
  const fit = Math.max(1, Math.floor((bay[1] - 2 * CORE_CLEARANCE - 0.2 - 2 * wallThickness + ti) / (shaft + ti)));
34082
- const probe = coreSize({ ...given2, wallThickness, elevators: 2 });
34083
- const wanted = given2.elevators ?? Math.max(2, Math.ceil((o.coreRatio * plate2[0] * plate2[1] / probe[0] - 2 * wallThickness + ti) / (shaft + ti)));
34471
+ const probe2 = coreSize({ ...given2, wallThickness, elevators: 2 });
34472
+ const wanted = given2.elevators ?? Math.max(2, Math.ceil((o.coreRatio * plate2[0] * plate2[1] / probe2[0] - 2 * wallThickness + ti) / (shaft + ti)));
34084
34473
  const elevators = Math.max(1, Math.min(wanted, fit));
34085
34474
  const narrow = coreSize({ ...given2, wallThickness, elevators });
34086
34475
  const room = bay[0] - columnSize - 2 * CORE_CLEARANCE - narrow[0];
@@ -56316,7 +56705,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
56316
56705
  }
56317
56706
  for (const e of planned.items) if (e.type === "lantern_lamp") e.item.on = !!e.lit;
56318
56707
  let scratch3 = null;
56319
- function probe(e, hinge, setback, blockedAt) {
56708
+ function probe2(e, hinge, setback, blockedAt) {
56320
56709
  if (!scratch3) scratch3 = GI.createWorld({ locale, strings: hh.strings, items: hh.items, loot: hh.loot, grid: false });
56321
56710
  const it = at(e.item);
56322
56711
  const x = it.x + Math.sin(it.ry) * setback;
@@ -56340,12 +56729,12 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
56340
56729
  const better = (a, b) => a.sum > b.sum + 1e-9 || Math.abs(a.sum - b.sum) <= 1e-9 && a.min > b.min + 1e-9;
56341
56730
  function fitDoors(e) {
56342
56731
  if (!isBlocked2 || !householdTypes.has(e.type)) return;
56343
- const standard = probe(e, void 0, 0, isBlocked2);
56732
+ const standard = probe2(e, void 0, 0, isBlocked2);
56344
56733
  if (!standard.n || standard.min >= 1) return;
56345
56734
  let bestSide;
56346
56735
  let m = standard;
56347
56736
  for (const side of ["left", "right"]) {
56348
- const r = probe(e, side, 0, isBlocked2);
56737
+ const r = probe2(e, side, 0, isBlocked2);
56349
56738
  if (better(r, m)) {
56350
56739
  m = r;
56351
56740
  bestSide = side;
@@ -56358,7 +56747,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
56358
56747
  if (m.min >= 1) return;
56359
56748
  let target = { setback: 0, r: m };
56360
56749
  for (const setback of [0.01, 0.02, 0.03, 0.04]) {
56361
- const r = probe(e, bestSide, setback, isBlocked2);
56750
+ const r = probe2(e, bestSide, setback, isBlocked2);
56362
56751
  if (better(r, target.r)) target = { setback, r };
56363
56752
  if (r.min >= 1) break;
56364
56753
  }
@@ -57883,7 +58272,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
57883
58272
  try {
57884
58273
  for (const { b, shut } of pieces) {
57885
58274
  shutFaces = shut;
57886
- put(mat, "box", (b[0] + b[3]) / 2, (b[1] + b[4]) / 2, (b[2] + b[5]) / 2, _qi, b[3] - b[0], b[4] - b[1], b[5] - b[2], color2);
58275
+ put2(mat, "box", (b[0] + b[3]) / 2, (b[1] + b[4]) / 2, (b[2] + b[5]) / 2, _qi, b[3] - b[0], b[4] - b[1], b[5] - b[2], color2);
57887
58276
  }
57888
58277
  } finally {
57889
58278
  shared3.ctx.keepOut = taken.length ? taken : void 0;
@@ -57892,7 +58281,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
57892
58281
  }
57893
58282
  return true;
57894
58283
  }
57895
- function put(mat, geo, px, py, pz, q, sx, sy, sz, color2, uvr) {
58284
+ function put2(mat, geo, px, py, pz, q, sx, sy, sz, color2, uvr) {
57896
58285
  if ((shared3.ctx.keepOut || shared3.ctx.itemBoxes) && geo === "box" && !uvr && keptOut(mat, px, py, pz, q, sx, sy, sz, color2)) return;
57897
58286
  if (shared3.ctx.blockBoxes && geo === "box" && mat !== "emissive" && mat !== "glass" && Math.abs(q.x) + Math.abs(q.y) + Math.abs(q.z) < 1e-9) shared3.ctx.blockBoxes.push([px - sx / 2, py - sy / 2, pz - sz / 2, px + sx / 2, py + sy / 2, pz + sz / 2]);
57898
58287
  {
@@ -57986,16 +58375,16 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
57986
58375
  function boxC(mat, cx, cy, cz, sx, sy, sz, color2, rx = 0, ry = 0, rz = 0, uvr) {
57987
58376
  if (rx || ry || rz) _q.setFromEuler(_e.set(rx, ry, rz, "YXZ"));
57988
58377
  else _q.identity();
57989
- put(mat, "box", cx, cy, cz, _q, sx, sy, sz, color2, uvr);
58378
+ put2(mat, "box", cx, cy, cz, _q, sx, sy, sz, color2, uvr);
57990
58379
  }
57991
58380
  function bxBase(mat, x0, y0, z0, x1, y1, z1, color2) {
57992
58381
  if (x1 - x0 < 1e-4 || y1 - y0 < 1e-4 || z1 - z0 < 1e-4) return;
57993
58382
  _q.identity();
57994
- put(mat, "box", (x0 + x1) / 2, (y0 + y1) / 2, (z0 + z1) / 2, _q, x1 - x0, y1 - y0, z1 - z0, color2);
58383
+ put2(mat, "box", (x0 + x1) / 2, (y0 + y1) / 2, (z0 + z1) / 2, _q, x1 - x0, y1 - y0, z1 - z0, color2);
57995
58384
  }
57996
58385
  function cylBase(mat, x, y, z, r, h, color2, seg2 = "cyl") {
57997
58386
  _q.identity();
57998
- put(mat, seg2, x, y + h / 2, z, _q, r * 2, h, r * 2, color2);
58387
+ put2(mat, seg2, x, y + h / 2, z, _q, r * 2, h, r * 2, color2);
57999
58388
  }
58000
58389
  function polyFace(mat, pts, color2, hint) {
58001
58390
  const A = accFor(mat), n = pts.length, O = cursor.org, RY = cursor.ry;
@@ -58059,7 +58448,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58059
58448
  const setBx = (f) => {
58060
58449
  bxImpl = f;
58061
58450
  };
58062
- const defined = { GEO, UV_SCALE, WITH_MAP, Accumulator, cursor, PARTS, MIRRORS, part, applyPart, _Y, _qa, _qb, pieceRecord, structurePiece, accFor, _q, _e, _col, rgbOf, put, boxC, bx, getBx, setBx, cylBase, polyFace };
58451
+ const defined = { GEO, UV_SCALE, WITH_MAP, Accumulator, cursor, PARTS, MIRRORS, part, applyPart, _Y, _qa, _qb, pieceRecord, structurePiece, accFor, _q, _e, _col, rgbOf, put: put2, boxC, bx, getBx, setBx, cylBase, polyFace };
58063
58452
  Object.assign(K, defined);
58064
58453
  }
58065
58454
  function installKernelNoise(K, _shared) {
@@ -58954,12 +59343,12 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58954
59343
  if (p.blocked) {
58955
59344
  part("window_boards", [0, 0, 0], () => {
58956
59345
  const rb = rngString(SEED() + "|" + seedKey(p.id) + "|tabua"), cx0 = alongU ? p.at : L, cz0 = alongU ? L : p.at, nT = Math.max(4, Math.round((visH - 0.3) / 0.3)), Lg = p.width + 0.34, WOODS = [8017460, 7031338, 9071172, 6177320, 7559746];
58957
- const puts = (along2, y, off, comp, alt, thickness, color2, tilt) => {
58958
- const x = alongU ? along2 : L + off, z = alongU ? L + off : along2;
59346
+ const puts = (along22, y, off, comp, alt, thickness, color2, tilt) => {
59347
+ const x = alongU ? along22 : L + off, z = alongU ? L + off : along22;
58959
59348
  boxC("wood", x, y0 + y, z, comp, alt, thickness, color2, 0, alongU ? 0 : K.PE, tilt);
58960
59349
  };
58961
- const nailColor = (along2, y, off) => {
58962
- const x = alongU ? along2 : L + off, z = alongU ? L + off : along2;
59350
+ const nailColor = (along22, y, off) => {
59351
+ const x = alongU ? along22 : L + off, z = alongU ? L + off : along22;
58963
59352
  boxC("metal", x, y0 + y, z, alongU ? 0.022 : 0.016, 0.022, alongU ? 0.016 : 0.022, 3815478);
58964
59353
  };
58965
59354
  for (const sd of [-1, 1]) {
@@ -59415,8 +59804,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
59415
59804
  };
59416
59805
  const underCovering = (items, x, z, y) => items.some((o) => {
59417
59806
  if (o.type !== "blinds" && o.type !== "curtain") return false;
59418
- const co = Math.cos(o.ry || 0), si = Math.sin(o.ry || 0), dx = x - o.x, dz = z - o.z, along2 = dx * co - dz * si, across2 = dx * si + dz * co;
59419
- return Math.abs(along2) < (o.w || 1) / 2 + COVERING_CLEAR && Math.abs(across2) < COVERING_CLEAR && y > (o.y || 0) - COVERING_CLEAR && y < (o.y || 0) + (o.h || 2.3) + COVERING_CLEAR;
59807
+ const co = Math.cos(o.ry || 0), si = Math.sin(o.ry || 0), dx = x - o.x, dz = z - o.z, along22 = dx * co - dz * si, across2 = dx * si + dz * co;
59808
+ return Math.abs(along22) < (o.w || 1) / 2 + COVERING_CLEAR && Math.abs(across2) < COVERING_CLEAR && y > (o.y || 0) - COVERING_CLEAR && y < (o.y || 0) + (o.h || 2.3) + COVERING_CLEAR;
59420
59809
  });
59421
59810
  for (const c of R.rooms) {
59422
59811
  if (c.type === "void" || OPEN_AREA(c)) continue;
@@ -60091,9 +60480,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
60091
60480
  const x0 = xs[i], x1 = xs[i + 1], z0 = zs[j], z1 = zs[j + 1], yb = pe(x0, z0, x1, z1);
60092
60481
  cursor.pc = K.panelAt("slab_top", (x0 + x1) / 2, (z0 + z1) / 2);
60093
60482
  const ex0 = free(j, i - 1) ? o : 0, ex1 = free(j, i + 1) ? o : 0, ez0 = free(j - 1, i) ? o : 0, ez1 = free(j + 1, i) ? o : 0;
60094
- const keep = !shared3.ctx.visorScene, parapet = [];
60483
+ const keep2 = !shared3.ctx.visorScene, parapet = [];
60095
60484
  const lay = (box5, color2, taken) => {
60096
- if (!keep || !taken.length) {
60485
+ if (!keep2 || !taken.length) {
60097
60486
  bx("plaster", box5[0], box5[1], box5[2], box5[3], box5[4], box5[5], color2);
60098
60487
  return;
60099
60488
  }
@@ -60109,7 +60498,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
60109
60498
  for (const [ok, ax0, az0, ax1, az1] of sides) if (ok) parapet.push([ax0, yb, az0, ax1, yb + pr, az1]);
60110
60499
  lay([x0 - ex0, yb, z0 - ez0, x1 + ex1, yb + 0.03, z1 + ez1], slab, parapet);
60111
60500
  {
60112
- const wt = (shared3.ctx.r.walls.find((w) => w.exterior)?.thickness || 0.15) / 2, yc = yb - 0.2, under = keep ? shared3.ctx.occupied : [];
60501
+ const wt = (shared3.ctx.r.walls.find((w) => w.exterior)?.thickness || 0.15) / 2, yc = yb - 0.2, under = keep2 ? shared3.ctx.occupied : [];
60113
60502
  if (free(j, i - 1)) lay([x0 - wt, yc, z0 - (free(j - 1, i) ? wt : 0), x0, yb, z1 + (free(j + 1, i) ? wt : 0)], c, under);
60114
60503
  if (free(j, i + 1)) lay([x1, yc, z0 - (free(j - 1, i) ? wt : 0), x1 + wt, yb, z1 + (free(j + 1, i) ? wt : 0)], c, under);
60115
60504
  if (free(j - 1, i)) lay([x0, yc, z0 - wt, x1, yb, z0], c, under);
@@ -60154,7 +60543,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
60154
60543
  Object.assign(K, defined);
60155
60544
  }
60156
60545
  function installRoofTiles(K, shared3) {
60157
- const { UV_SCALE, _Y, _h2, _q, accFor, cursor, put, rgbOf, structurePiece } = K;
60546
+ const { UV_SCALE, _Y, _h2, _q, accFor, cursor, put: put2, rgbOf, structurePiece } = K;
60158
60547
  const sh = (...a) => K.sh(...a);
60159
60548
  const R_STYLE = () => shared3.ctx.r && shared3.ctx.r.style || "budget";
60160
60549
  function tileRelief(mat, pts, color2, type, origin) {
@@ -60197,8 +60586,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
60197
60586
  ex /= el;
60198
60587
  ey /= el;
60199
60588
  ez /= el;
60200
- const aligned = !shared3.ctx.visorScene, along2 = nx * pts[0][0] + ny * pts[0][1] + nz * pts[0][2];
60201
- const o = aligned ? [nx * along2, ny * along2, nz * along2] : origin ?? pts[0], S = [], T2 = [];
60589
+ const aligned = !shared3.ctx.visorScene, along22 = nx * pts[0][0] + ny * pts[0][1] + nz * pts[0][2];
60590
+ const o = aligned ? [nx * along22, ny * along22, nz * along22] : origin ?? pts[0], S = [], T2 = [];
60202
60591
  for (const p of pts) {
60203
60592
  const rx = p[0] - o[0], ry = p[1] - o[1], rz = p[2] - o[2];
60204
60593
  S.push(rx * ex + ry * ey + rz * ez);
@@ -60292,10 +60681,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
60292
60681
  const colonial = type !== "fiber_cement", r = colonial ? 0.085 : 0.075, c = sh(roofColor, colonial ? 0.82 : 0.9), lift = colonial ? 0.05 : 0.035;
60293
60682
  _q.setFromUnitVectors(_Y, K._v3.set(dx / Ln, dy / Ln, dz / Ln));
60294
60683
  const mx = (a[0] + b[0]) / 2, my = (a[1] + b[1]) / 2 + lift, mz = (a[2] + b[2]) / 2;
60295
- put("plain", colonial ? "cyl" : "cyl6", mx, my, mz, _q, r * 2, Ln, r * 2, c);
60684
+ put2("plain", colonial ? "cyl" : "cyl6", mx, my, mz, _q, r * 2, Ln, r * 2, c);
60296
60685
  if (colonial) for (let t = 0.25; t < Ln - 0.1; t += 0.42) {
60297
60686
  const f = t / Ln;
60298
- put("plain", "cyl", a[0] + dx * f, a[1] + dy * f + lift, a[2] + dz * f, _q, r * 2.25, 0.035, r * 2.25, sh(c, 0.7));
60687
+ put2("plain", "cyl", a[0] + dx * f, a[1] + dy * f + lift, a[2] + dz * f, _q, r * 2.25, 0.035, r * 2.25, sh(c, 0.7));
60299
60688
  }
60300
60689
  }
60301
60690
  function pieceOfPane(x, z) {
@@ -61061,10 +61450,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
61061
61450
  if (opening.floor > floor2 || opening.y1 === void 0) return false;
61062
61451
  return (plan.floors[opening.floor]?.y0 ?? 0) + opening.y1 > (plan.floors[floor2]?.y0 ?? 0);
61063
61452
  }
61064
- function clearOfOpenings(plan, wall, along2, endClear = DEFAULT_END_CLEAR) {
61453
+ function clearOfOpenings(plan, wall, along22, endClear = DEFAULT_END_CLEAR) {
61065
61454
  const line = wall.axis === "u" ? wall.v0 : wall.u0;
61066
61455
  const a0 = wall.axis === "u" ? wall.u0 : wall.v0, a1 = wall.axis === "u" ? wall.u1 : wall.v1;
61067
- let at4 = endClear > DEFAULT_END_CLEAR ? Math.max(a0 + endClear, Math.min(a1 - endClear, along2)) : along2;
61456
+ let at4 = endClear > DEFAULT_END_CLEAR ? Math.max(a0 + endClear, Math.min(a1 - endClear, along22)) : along22;
61068
61457
  for (const o of plan.openings) {
61069
61458
  if (o.axis !== wall.axis || Math.abs(o.pos - line) > 0.05 || !reaches(plan, o, wall.floor)) continue;
61070
61459
  const lo = o.at - o.width / 2 - OPENING_CLEARANCE, hi = o.at + o.width / 2 + OPENING_CLEARANCE;
@@ -61086,7 +61475,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
61086
61475
  if (!best) return null;
61087
61476
  const { wall } = best;
61088
61477
  const alongU = wall.axis === "u";
61089
- const along2 = clearOfOpenings(plan, wall, best.along, options.endClear);
61478
+ const along22 = clearOfOpenings(plan, wall, best.along, options.endClear);
61090
61479
  const line = alongU ? wall.v0 : wall.u0;
61091
61480
  const [ru, rv] = options.toward ?? [u, v];
61092
61481
  const across2 = alongU ? rv - line : ru - line;
@@ -61096,7 +61485,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
61096
61485
  const half = (wall.thickness ?? DEFAULT_THICKNESS) / 2;
61097
61486
  const offset = options.surface ? half + (options.diameter ?? 0.02) / 2 : half - chaseDepth(options.diameter);
61098
61487
  const at4 = line + side * offset;
61099
- return { u: alongU ? along2 : at4, v: alongU ? at4 : along2, wall };
61488
+ return { u: alongU ? along22 : at4, v: alongU ? at4 : along22, wall };
61100
61489
  }
61101
61490
  function buildingBox(plan, wall) {
61102
61491
  if (!wall.outbuilding) return houseFootprint(plan);
@@ -61121,8 +61510,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
61121
61510
  const start = alongU ? first.u : first.v;
61122
61511
  const tries = [start, ...Array.from({ length: Math.ceil((a1 - a0) / FEED_STEP) }, (_, k) => [start - (k + 1) * FEED_STEP, start + (k + 1) * FEED_STEP]).flat().filter((a) => a > a0 + 0.2 && a < a1 - 0.2)];
61123
61512
  let fallback2 = null;
61124
- for (const along2 of tries) {
61125
- const exit = wallDrop(plan, 0, alongU ? along2 : first.u, alongU ? first.v : along2, { ...options, surface: false, walls: [wall], toward: centreOf(houseFootprint(plan)) });
61513
+ for (const along22 of tries) {
61514
+ const exit = wallDrop(plan, 0, alongU ? along22 : first.u, alongU ? first.v : along22, { ...options, surface: false, walls: [wall], toward: centreOf(houseFootprint(plan)) });
61126
61515
  if (!exit) continue;
61127
61516
  for (const turnFirst of [false, true]) {
61128
61517
  const feed = feedFrom(plan, exit, target, y, { ...options, turnFirst });
@@ -61342,10 +61731,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
61342
61731
  const y = rise(s) * Math.pow(Math.max(0, Math.sin(Math.PI * t / width)), 0.8) - MOUND_SINK;
61343
61732
  return alongX ? [x0 + s, y, z0 + t] : [x0 + t, y, z0 + s];
61344
61733
  };
61345
- const along2 = MOUND_GRID.along * humps, { across: across2 } = MOUND_GRID;
61346
- for (let i = 0; i < along2; i++) {
61734
+ const along22 = MOUND_GRID.along * humps, { across: across2 } = MOUND_GRID;
61735
+ for (let i = 0; i < along22; i++) {
61347
61736
  for (let j = 0; j < across2; j++) {
61348
- const s0 = length2 * i / along2, s1 = length2 * (i + 1) / along2, t0 = width * j / across2, t1 = width * (j + 1) / across2;
61737
+ const s0 = length2 * i / along22, s1 = length2 * (i + 1) / along22, t0 = width * j / across2, t1 = width * (j + 1) / across2;
61349
61738
  const quad = [at4(s0, t0), at4(s1, t0), at4(s1, t1), at4(s0, t1)];
61350
61739
  const e1 = [quad[1][0] - quad[0][0], quad[1][1] - quad[0][1], quad[1][2] - quad[0][2]], e2 = [quad[3][0] - quad[0][0], quad[3][1] - quad[0][1], quad[3][2] - quad[0][2]];
61351
61740
  const up = e1[2] * e2[0] - e1[0] * e2[2];
@@ -61763,9 +62152,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
61763
62152
  }
61764
62153
  var CAP_SINK = 2e-3;
61765
62154
  function drawnEnds(span, previous, next) {
61766
- const along2 = [(span.b[0] - span.a[0]) / span.length, (span.b[1] - span.a[1]) / span.length, (span.b[2] - span.a[2]) / span.length];
62155
+ const along22 = [(span.b[0] - span.a[0]) / span.length, (span.b[1] - span.a[1]) / span.length, (span.b[2] - span.a[2]) / span.length];
61767
62156
  const shift = (neighbour) => span.host !== null ? -CAP_SINK : neighbour && neighbour.host !== null ? CAP_SINK : 0;
61768
- const move2 = (end3, amount) => [end3[0] + along2[0] * amount, end3[1] + along2[1] * amount, end3[2] + along2[2] * amount];
62157
+ const move2 = (end3, amount) => [end3[0] + along22[0] * amount, end3[1] + along22[1] * amount, end3[2] + along22[2] * amount];
61769
62158
  return span.length > 4 * CAP_SINK ? [move2(span.a, -shift(previous)), move2(span.b, shift(next))] : [span.a, span.b];
61770
62159
  }
61771
62160
  var PIPE_WALL_FILL = 0.3;
@@ -61774,7 +62163,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
61774
62163
  var UNDER_SINK_VALVE_RISE = 0.1;
61775
62164
  var pipeMass = (diameter, length2) => DENSITY.plastic * Math.PI * (diameter / 2) ** 2 * length2 * PIPE_WALL_FILL;
61776
62165
  function installUtilitiesWater(K, shared3) {
61777
- const { THREE, _Y, _q, cursor, cylBase, part, pieceRecord, put } = K;
62166
+ const { THREE, _Y, _q, cursor, cylBase, part, pieceRecord, put: put2 } = K;
61778
62167
  function createWater(r, state) {
61779
62168
  const H = r.utilities?.plumbing, cap = H ? +H.capacityL || 0 : 0, ls = { dry: [], full: [] }, points = {}, itemPoint = {};
61780
62169
  if (H) for (const p of H.points) {
@@ -61861,7 +62250,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
61861
62250
  const dx = b[0] - a[0], dy = b[1] - a[1], dz = b[2] - a[2], L = Math.hypot(dx, dy, dz);
61862
62251
  if (L < 1e-3) return;
61863
62252
  _q.setFromUnitVectors(_Y, _v3.set(dx / L, dy / L, dz / L));
61864
- put("plain", "cyl", (a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2, _q, diameter, L, diameter, color2);
62253
+ put2("plain", "cyl", (a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2, _q, diameter, L, diameter, color2);
61865
62254
  }
61866
62255
  const _v3 = new THREE.Vector3();
61867
62256
  function layWallRun({ id, routes, diameter, group, meta }) {
@@ -62126,7 +62515,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
62126
62515
  var END_RENDER = 0.02;
62127
62516
  var SLIVER_CLEAR = 5e-4;
62128
62517
  var MORTAR_LIFT = 9e-3;
62129
- function layUnits(rect, coursing, put) {
62518
+ function layUnits(rect, coursing, put2) {
62130
62519
  const { courseH, unitLen, joint: joint2, courseBase } = coursing;
62131
62520
  const first = Math.floor((rect.y0 - courseBase) / courseH + 1e-6);
62132
62521
  for (let row = first; courseBase + row * courseH < rect.y1 - 1e-6; row++) {
@@ -62146,7 +62535,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
62146
62535
  units[units.length - 1][1] = rect.a1;
62147
62536
  if (units.length > 1 && units[0][1] - units[0][0] < MIN_PIECE2) units.splice(0, 2, [rect.a0, units[1][1]]);
62148
62537
  if (units.length > 1 && units[units.length - 1][1] - units[units.length - 1][0] < MIN_PIECE2) units.splice(units.length - 2, 2, [units[units.length - 2][0], rect.a1]);
62149
- for (const [b0, b1] of units) put(b0, ya, b1, yb);
62538
+ for (const [b0, b1] of units) put2(b0, ya, b1, yb);
62150
62539
  }
62151
62540
  }
62152
62541
  function coreWidthOf(thickness, unitId) {
@@ -62342,11 +62731,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
62342
62731
  function chasesIn(wall, core, runs) {
62343
62732
  const out = [];
62344
62733
  for (const r of runs) {
62345
- const along2 = wall.alongU ? r.u : r.v, across2 = (wall.alongU ? r.v : r.u) - core.line;
62346
- if (along2 + r.radius + CHASE_CLEAR2 < wall.a0 || along2 - r.radius - CHASE_CLEAR2 > wall.a1 || r.y1 <= core.y0 || r.y0 >= core.y1) continue;
62734
+ const along22 = wall.alongU ? r.u : r.v, across2 = (wall.alongU ? r.v : r.u) - core.line;
62735
+ if (along22 + r.radius + CHASE_CLEAR2 < wall.a0 || along22 - r.radius - CHASE_CLEAR2 > wall.a1 || r.y1 <= core.y0 || r.y0 >= core.y1) continue;
62347
62736
  if (Math.abs(across2) > wall.thickness / 2 + 1e-6) continue;
62348
62737
  const back2 = Math.abs(across2) - (r.depth ?? r.radius) - CHASE_CLEAR2;
62349
- out.push({ a0: along2 - r.radius - CHASE_CLEAR2, a1: along2 + r.radius + CHASE_CLEAR2, y0: Math.max(core.y0, r.y0), y1: Math.min(core.y1, r.y1), side: across2 >= 0 ? 1 : -1, back: back2, ...r.box ? { box: true } : {} });
62738
+ out.push({ a0: along22 - r.radius - CHASE_CLEAR2, a1: along22 + r.radius + CHASE_CLEAR2, y0: Math.max(core.y0, r.y0), y1: Math.min(core.y1, r.y1), side: across2 >= 0 ? 1 : -1, back: back2, ...r.box ? { box: true } : {} });
62350
62739
  }
62351
62740
  return out;
62352
62741
  }
@@ -62367,11 +62756,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
62367
62756
  const bounds2 = [Math.min(...own.map((s) => s.aabb[0])), Math.min(...own.map((s) => s.aabb[1])), Math.max(...own.map((s) => s.aabb[2])), Math.max(...own.map((s) => s.aabb[3]))];
62368
62757
  const under = carriers.filter((c) => c.floor === f && own.some((s) => overlapArea2(c.aabb, s.aabb) > EPS32 && c.y1 > s.y0 - 0.05 && c.y1 <= s.y1 + EPS32));
62369
62758
  if (!under.length) continue;
62370
- const along2 = (alongU) => {
62759
+ const along22 = (alongU) => {
62371
62760
  const own2 = under.filter((c) => beams.includes(c) && c.aabb[2] - c.aabb[0] >= c.aabb[3] - c.aabb[1] === alongU);
62372
62761
  return own2.length ? own2 : under;
62373
62762
  };
62374
- const [acrossU, acrossV] = [along2(false), along2(true)];
62763
+ const [acrossU, acrossV] = [along22(false), along22(true)];
62375
62764
  const reach2 = [Math.min(...acrossU.map((c) => c.aabb[0])), Math.min(...acrossV.map((c) => c.aabb[1])), Math.max(...acrossU.map((c) => c.aabb[2])), Math.max(...acrossV.map((c) => c.aabb[3]))];
62376
62765
  for (const s of own) {
62377
62766
  for (const k of [0, 1]) if (Math.abs(s.aabb[k] - bounds2[k]) < EPS32 && reach2[k] < s.aabb[k] + SLAB_LIP && s.aabb[k] - reach2[k] < 0.3) s.aabb[k] = reach2[k] - SLAB_LIP;
@@ -62631,7 +63020,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
62631
63020
  const alongHalf = (span + size.holderAlong) / 2 + size.battenOverhang;
62632
63021
  const across2 = size.battenWidth / 2;
62633
63022
  const battenBase = mountY - size.battenHeight;
62634
- const around = (along2, cross5) => alongU ? [x + along2, z + cross5] : [x + cross5, z + along2];
63023
+ const around = (along22, cross5) => alongU ? [x + along22, z + cross5] : [x + cross5, z + along22];
62635
63024
  const rectangle = (along0, along1, cross0, cross1, y0, y1, color2) => {
62636
63025
  const [ax, az] = around(along0, cross0);
62637
63026
  const [bx, bz] = around(along1, cross1);
@@ -62684,7 +63073,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
62684
63073
  function wallBehindOf(walls, point) {
62685
63074
  const alongU = Math.abs(point.frontV) >= Math.abs(point.frontU);
62686
63075
  const across2 = alongU ? point.v : point.u;
62687
- const along2 = alongU ? point.u : point.v;
63076
+ const along22 = alongU ? point.u : point.v;
62688
63077
  let best;
62689
63078
  let bestGap = Infinity;
62690
63079
  for (const wall of walls) {
@@ -62692,7 +63081,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
62692
63081
  const line = alongU ? wall.v0 : wall.u0;
62693
63082
  const [from, to] = alongU ? [Math.min(wall.u0, wall.u1), Math.max(wall.u0, wall.u1)] : [Math.min(wall.v0, wall.v1), Math.max(wall.v0, wall.v1)];
62694
63083
  const gap = Math.abs(across2 - line);
62695
- if (along2 < from - 1e-6 || along2 > to + 1e-6 || gap > wall.thickness || gap >= bestGap) continue;
63084
+ if (along22 < from - 1e-6 || along22 > to + 1e-6 || gap > wall.thickness || gap >= bestGap) continue;
62696
63085
  best = { line, halfThickness: wall.thickness / 2 };
62697
63086
  bestGap = gap;
62698
63087
  }
@@ -62723,7 +63112,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
62723
63112
  var FLOOR_SLAB_UNDERSIDE = 0.24;
62724
63113
  var BOX_COLOR = 15381256;
62725
63114
  function installUtilitiesElectrical(K, shared3) {
62726
- const { _Y, _q, _v3, bx, cursor, cylBase, part, pieceRecord, put } = K;
63115
+ const { _Y, _q, _v3, bx, cursor, cylBase, part, pieceRecord, put: put2 } = K;
62727
63116
  const sh = (...a) => K.sh(...a);
62728
63117
  function electricalStructure() {
62729
63118
  const R = shared3.ctx.r, E = R.utilities?.electrical;
@@ -62735,7 +63124,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
62735
63124
  const L = Math.hypot(b[0] - a[0], b[1] - a[1], b[2] - a[2]);
62736
63125
  if (L < 1e-3) return;
62737
63126
  _q.setFromUnitVectors(_Y, _v3.set((b[0] - a[0]) / L, (b[1] - a[1]) / L, (b[2] - a[2]) / L));
62738
- put("plain", "cyl", (a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2, _q, r_ * 2, L, r_ * 2, wireRun);
63127
+ put2("plain", "cyl", (a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2, _q, r_ * 2, L, r_ * 2, wireRun);
62739
63128
  };
62740
63129
  const pole = (u, v, h) => {
62741
63130
  const buried = postEmbedment(h), below = shared3.ctx.visorScene ? 0 : buried;
@@ -62997,7 +63386,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
62997
63386
  const dx = b[0] - a[0], dy = b[1] - a[1], dz = b[2] - a[2], L = Math.hypot(dx, dy, dz);
62998
63387
  if (L < 1e-3) return;
62999
63388
  _q.setFromUnitVectors(_Y, _v3.set(dx / L, dy / L, dz / L));
63000
- put("plain", "cyl", (a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2, _q, diameter, L, diameter, color2);
63389
+ put2("plain", "cyl", (a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2, _q, diameter, L, diameter, color2);
63001
63390
  }
63002
63391
  const defined = { electricalStructure, pipe2 };
63003
63392
  Object.assign(K, defined);
@@ -63250,7 +63639,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63250
63639
  Object.assign(K, defined);
63251
63640
  }
63252
63641
  function installFurnitureApi(K, shared3) {
63253
- const { _e, _h2, _q, boxC, cursor, macroGround, polyFace, put } = K;
63642
+ const { _e, _h2, _q, boxC, cursor, macroGround, polyFace, put: put2 } = K;
63254
63643
  const MATERIAL_MAP2 = { plain: "plain", metal: "metal", wood: "wood", glass: "glass", fabric: "fabric", foam: "fabric", plant: "plant", water: "water", emissive: "emissive", "atlas_picture": "picture", "atlas_floor": "floor", plaster: "plain", matte: "glass", glass_light: "emissive", light: "emissive", ceramic_tile: "plain", parquet: "plain", ceramic: "plain" };
63255
63644
  const mm = (k) => MATERIAL_MAP2[k] || "plain";
63256
63645
  const LIGHTS = [];
@@ -63267,7 +63656,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63267
63656
  cylinder(M, mat, x, y, z, r, h, color2, rx = 0, rz = 0, seg2) {
63268
63657
  const [px, pz] = loc(M, x, z);
63269
63658
  _q.setFromEuler(_e.set(rx || 0, M.ry, rz || 0, "YXZ"));
63270
- put(mm(mat), seg2 || "cyl", px, M.base + y + (rx || rz ? 0 : h / 2), pz, _q, r * 2, h, r * 2, color2);
63659
+ put2(mm(mat), seg2 || "cyl", px, M.base + y + (rx || rz ? 0 : h / 2), pz, _q, r * 2, h, r * 2, color2);
63271
63660
  },
63272
63661
  leaf(M, x, y, z, w, h, color2, ry = 0, rx = 0) {
63273
63662
  const [px, pz] = loc(M, x, z), a = M.ry + (ry || 0), ca = Math.cos(a), sa = Math.sin(a), t1 = (rx || 0) * 0.8, t2 = (rx || 0) * 1.5, y0 = M.base + y;
@@ -63288,12 +63677,12 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63288
63677
  if (uv && mat === "atlas_floor") {
63289
63678
  const col = Math.floor(uv.u0 * 4 + 1e-6), lin = uv.v0 < 0.5 ? 1 : 0, cell = col + 4 * lin, h0 = _h2(Math.round(px * 8), Math.round(pz * 8)), type = cell === 5 ? "dirt" : cell === 0 || cell === 1 ? "lawn" : null;
63290
63679
  if (type === "dirt") {
63291
- put("dirt", "plane", px, M.base + y, pz, _q, w, h, 1, sh(color2, 1 / 0.965));
63680
+ put2("dirt", "plane", px, M.base + y, pz, _q, w, h, 1, sh(color2, 1 / 0.965));
63292
63681
  return;
63293
63682
  }
63294
63683
  if (type) uv = { u0: uv.u0, u1: uv.u1, v0: uv.v0, v1: uv.v1, rot: h0 * 4 | 0, fx: h0 > 0.5 ? 1 : 0, vc: (wx, wz) => macroGround(wx, wz, type) };
63295
63684
  }
63296
- put(mm(mat), "plane", px, M.base + y, pz, _q, w, h, 1, color2, uv);
63685
+ put2(mm(mat), "plane", px, M.base + y, pz, _q, w, h, 1, color2, uv);
63297
63686
  },
63298
63687
  light(M, x, y, z, color2, range3, type, ex) {
63299
63688
  const [px, pz] = loc(M, x, z);
@@ -63319,7 +63708,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63319
63708
  Object.assign(K, defined);
63320
63709
  }
63321
63710
  function installFurnitureBuilders(K, shared3) {
63322
- const { PE, _q, kit2, kk, paletteColor, put, rngOf, sh } = K;
63711
+ const { PE, _q, kit2, kk, paletteColor, put: put2, rngOf, sh } = K;
63323
63712
  const counterTap = (...a) => K.counterTap(...a);
63324
63713
  const apart = () => !shared3.ctx.visorScene;
63325
63714
  const FURNITURE = {
@@ -63371,7 +63760,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63371
63760
  lc("metal", -0.08, h + 0.03, -0.05, 0.01, 0.2, 9075290);
63372
63761
  _q.identity();
63373
63762
  const [px, pz] = [M.x + -0.08 * Math.cos(M.ry) + -0.05 * Math.sin(M.ry), M.z - -0.08 * Math.sin(M.ry) + -0.05 * Math.cos(M.ry)];
63374
- put("fabric", "cone", px, M.base + h + 0.32, pz, _q, 0.36, 0.2, 0.36, 15259824);
63763
+ put2("fabric", "cone", px, M.base + h + 0.32, pz, _q, 0.36, 0.2, 0.36, 15259824);
63375
63764
  }
63376
63765
  },
63377
63766
  shelf(M, A, o = {}) {
@@ -63649,7 +64038,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63649
64038
  lc("plain", 0, 0, 0, 0.14, 0.03, 2763306);
63650
64039
  lc("metal", 0, 0.03, 0, 0.012, M.h - 0.35, 9075290);
63651
64040
  _q.identity();
63652
- put("fabric", "cone", M.x, M.base + (M.y || 0) + M.h - 0.2, M.z, _q, 0.4, 0.3, 0.4, 14733992);
64041
+ put2("fabric", "cone", M.x, M.base + (M.y || 0) + M.h - 0.2, M.z, _q, 0.4, 0.3, 0.4, 14733992);
63653
64042
  },
63654
64043
  microwave(M, A) {
63655
64044
  const { b: lb } = kk(M, A);
@@ -66523,7 +66912,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66523
66912
  PL.push(l);
66524
66913
  }
66525
66914
  const slotOf = (i) => lease ? lease.handles[i].slot : i;
66526
- const put = (i, v) => {
66915
+ const put2 = (i, v) => {
66527
66916
  if (lease) {
66528
66917
  lease.handles[i].update(v.color === void 0 || typeof v.color === "number" ? v : { ...v, color: new THREE.Color(v.color).getHex() });
66529
66918
  return;
@@ -66662,13 +67051,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66662
67051
  const b0 = LZU.uRB0.value, b1 = LZU.uRB1.value, b2 = LZU.uRB2.value, by = LZU.uRBY.value, ex = LZU.uREx.value;
66663
67052
  A.crates[i] = g ? { k: g.k, rects: g.rects, y: g.y, exterior: !!g.exterior, exclusion: g.exclusion || null, d: g.d } : null;
66664
67053
  if (!g) {
66665
- put(i, { intensity: 0 });
67054
+ put2(i, { intensity: 0 });
66666
67055
  for (const a of [b0, b1, b2, ex]) a.set(EMPTY, at4 * 4);
66667
67056
  by.set([0, 0], at4 * 2);
66668
67057
  continue;
66669
67058
  }
66670
67059
  const lamp = g.exterior ? { intensity: g.lumens, distance: g.dist, decay: g.decay } : { intensity: (7 + g.range * 0.8) * lim(1 + 0.4 * (Math.sqrt(g.n) - 1), 1, 2.2), distance: Math.max(3, g.dm * 1.3 + 0.5), decay: 1.6 };
66671
- put(i, { position: g.pos, color: g.color, ...lamp });
67060
+ put2(i, { position: g.pos, color: g.color, ...lamp });
66672
67061
  const rs = g.rects;
66673
67062
  b0.set(rs[0] || EMPTY, at4 * 4);
66674
67063
  b1.set(rs[1] || EMPTY, at4 * 4);
@@ -67379,8 +67768,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
67379
67768
  for (const part of parts2) {
67380
67769
  const boxes = part.gone?.length ? subtract2(mergeSpans(part.spans), part.gone) : mergeSpans(part.spans);
67381
67770
  for (const s of line.open ? mergeSpans(carve(boxes, line.open), 0) : boxes) {
67382
- const along2 = line.start + (s.a + s.b) / 2;
67383
- point.set(line.alongU ? along2 : part.mid, (s.y0 + s.y1) / 2, line.alongU ? part.mid : along2).applyMatrix4(toMesh);
67771
+ const along22 = line.start + (s.a + s.b) / 2;
67772
+ point.set(line.alongU ? along22 : part.mid, (s.y0 + s.y1) / 2, line.alongU ? part.mid : along22).applyMatrix4(toMesh);
67384
67773
  const length2 = (s.b - s.a) / 2, up = (s.y1 - s.y0) / 2, across2 = part.thick / 2;
67385
67774
  out.push({
67386
67775
  center: [point.x, point.y, point.z],
@@ -67857,13 +68246,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
67857
68246
  }
67858
68247
  function splitUnits(view, id, around) {
67859
68248
  const { mask } = view;
67860
- const along2 = (p) => (mask.alongU ? p[0] : p[2]) - mask.start;
68249
+ const along22 = (p) => (mask.alongU ? p[0] : p[2]) - mask.start;
67861
68250
  const part = structure.byId.get(id), units = specOf(id).units, chips2 = view.chips.get(id), opening = view.openings.get(id);
67862
68251
  const own = cells(part, units, mask);
67863
68252
  const all = (id === view.host ? own.flatMap((c) => besidePillars(c, around.pillars)) : own).flatMap((c) => outsideGaps(c, around.gaps));
67864
68253
  const holes = [], kept = [];
67865
68254
  if (view.fallen.has(id)) return { all, kept, holes: all, boxes: [] };
67866
- const boxes = chips2.map((k) => ({ s0: along2(k.center) - k.along, s1: along2(k.center) + k.along, y0: k.center[1] - k.up, y1: k.center[1] + k.up }));
68255
+ const boxes = chips2.map((k) => ({ s0: along22(k.center) - k.along, s1: along22(k.center) + k.along, y0: k.center[1] - k.up, y1: k.center[1] + k.up }));
67867
68256
  const gone = (c) => {
67868
68257
  const over = boxes.filter((k) => k.s1 > c.a && k.s0 < c.b && k.y1 > c.y0 && k.y0 < c.y1);
67869
68258
  const share = covered(c, over);
@@ -67871,7 +68260,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
67871
68260
  const s = (c.a + c.b) / 2, y = (c.y0 + c.y1) / 2;
67872
68261
  return share >= 0.5 && over.some((k) => s >= k.s0 && s <= k.s1 && y >= k.y0 && y <= k.y1);
67873
68262
  };
67874
- const open = (c) => gone(c) || opening !== void 0 && Math.hypot((c.a + c.b) / 2 - along2(opening.center), (c.y0 + c.y1) / 2 - opening.center[1]) < opening.radius;
68263
+ const open = (c) => gone(c) || opening !== void 0 && Math.hypot((c.a + c.b) / 2 - along22(opening.center), (c.y0 + c.y1) / 2 - opening.center[1]) < opening.radius;
67875
68264
  for (const c of all) (open(c) ? holes : kept).push(c);
67876
68265
  return { all, kept, holes, boxes };
67877
68266
  }
@@ -67884,12 +68273,12 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
67884
68273
  function publishStanding(view) {
67885
68274
  if (!view.saved) return;
67886
68275
  const { mask } = view;
67887
- const along2 = (p) => (mask.alongU ? p[0] : p[2]) - mask.start;
68276
+ const along22 = (p) => (mask.alongU ? p[0] : p[2]) - mask.start;
67888
68277
  const parts2 = view.parts.map((id) => {
67889
68278
  const part = structure.byId.get(id);
67890
68279
  const thick = mask.alongU ? part.aabb[3] - part.aabb[1] : part.aabb[2] - part.aabb[0];
67891
68280
  const mid = mask.alongU ? (part.aabb[1] + part.aabb[3]) / 2 : (part.aabb[0] + part.aabb[2]) / 2;
67892
- 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 }));
68281
+ const gone = (view.chips.get(id) ?? []).map((k) => ({ a: along22(k.center) - k.along, b: along22(k.center) + k.along, y0: k.center[1] - k.up, y1: k.center[1] + k.up }));
67893
68282
  return { spans: view.kept.get(id) ?? [], gone, thick, mid };
67894
68283
  });
67895
68284
  const line = { alongU: mask.alongU, start: mask.start, open: view.core };
@@ -67897,7 +68286,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
67897
68286
  }
67898
68287
  function paint2(view) {
67899
68288
  const { mask, core } = view;
67900
- const along2 = (p) => (mask.alongU ? p[0] : p[2]) - mask.start;
68289
+ const along22 = (p) => (mask.alongU ? p[0] : p[2]) - mask.start;
67901
68290
  const holes = [];
67902
68291
  const pits = [];
67903
68292
  const discs = [];
@@ -67915,8 +68304,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
67915
68304
  }
67916
68305
  const thick = mask.alongU ? part.aabb[3] - part.aabb[1] : part.aabb[2] - part.aabb[0];
67917
68306
  const mid = mask.alongU ? (part.aabb[1] + part.aabb[3]) / 2 : (part.aabb[0] + part.aabb[2]) / 2;
67918
- if (opening) discs.push({ s: along2(opening.center), y: opening.center[1], r: opening.radius });
67919
- for (const k of spalls) flakes.push({ s: along2(k.center), y: k.center[1], r: k.radius });
68307
+ if (opening) discs.push({ s: along22(opening.center), y: opening.center[1], r: opening.radius });
68308
+ for (const k of spalls) flakes.push({ s: along22(k.center), y: k.center[1], r: k.radius });
67920
68309
  holes.push(...lost);
67921
68310
  view.kept.set(id, kept);
67922
68311
  if (units2.mortar === part.material) {
@@ -69421,8 +69810,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
69421
69810
  const ends = rr.alongX ? [[rr.gable ? x0 + EDGE2 : x0 + rr.rm, ridgeY, zm], [rr.gable ? x1 - EDGE2 : x1 - rr.rm, ridgeY, zm]] : [[xm, ridgeY, rr.gable ? z0 + EDGE2 : z0 + rr.rm], [xm, ridgeY, rr.gable ? z1 - EDGE2 : z1 - rr.rm]];
69422
69811
  const ridgeTop = TIMBER.purlin.top;
69423
69812
  addTimberAround(timber, down(ends[0], ridgeTop), down(ends[1], ridgeTop), TIMBER.purlin.width, TIMBER.purlin.height, "purlin", keepOut, (end3) => addPost(timber, end3[0], end3[2], slabTop, end3[1] - TIMBER.purlin.height));
69424
- const along2 = Math.hypot(ends[1][0] - ends[0][0], ends[1][2] - ends[0][2]);
69425
- const posts = Math.max(1, Math.ceil(along2 / TIMBER.post.spacing));
69813
+ const along22 = Math.hypot(ends[1][0] - ends[0][0], ends[1][2] - ends[0][2]);
69814
+ const posts = Math.max(1, Math.ceil(along22 / TIMBER.post.spacing));
69426
69815
  for (let j = 0; j <= posts; j++) {
69427
69816
  const f = posts ? j / posts : 0;
69428
69817
  const x = ends[0][0] + (ends[1][0] - ends[0][0]) * f, z = ends[0][2] + (ends[1][2] - ends[0][2]) * f;
@@ -77833,9 +78222,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
77833
78222
  };
77834
78223
  var fitLength = (kit, inner, lengthMetres) => {
77835
78224
  const box5 = new kit.THREE.Box3().setFromObject(inner);
77836
- const factor = lengthMetres / (box5.max.x - box5.min.x);
77837
- inner.scale.x = factor;
77838
- inner.position.x = -box5.min.x * factor;
78225
+ const factor2 = lengthMetres / (box5.max.x - box5.min.x);
78226
+ inner.scale.x = factor2;
78227
+ inner.position.x = -box5.min.x * factor2;
77839
78228
  const root = kit.group();
77840
78229
  root.add(inner);
77841
78230
  return root;
@@ -84622,9 +85011,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
84622
85011
  } else hip.set(side * NO_GRIP_REAR[0], NO_GRIP_REAR[1], NO_GRIP_REAR[2] + box5.min.x);
84623
85012
  const k = ease(Math.max(0, Math.min(1, placement.aim)));
84624
85013
  if (k > 0) {
84625
- const along2 = box5.min.x + hold.sights.fromRear;
85014
+ const along3 = box5.min.x + hold.sights.fromRear;
84626
85015
  scratch2.aimed ?? (scratch2.aimed = new THREE.Vector3());
84627
- hip.lerp(scratch2.aimed.set(0, -SIGHT_UNDER_EYE - box5.max.y, along2 - hold.sights.distance), k);
85016
+ hip.lerp(scratch2.aimed.set(0, -SIGHT_UNDER_EYE - box5.max.y, along3 - hold.sights.distance), k);
84628
85017
  }
84629
85018
  holder.position.copy(hip).add(placement.offset);
84630
85019
  hand.updateMatrixWorld(true);
@@ -88018,8 +88407,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
88018
88407
  const end3 = CURVE[CURVE.length - 1];
88019
88408
  const before = CURVE[CURVE.length - 2];
88020
88409
  const angle = Math.atan2(end3[1] - before[1], end3[0] - before[0]);
88021
- const along2 = (distance4) => [end3[0] + Math.cos(angle) * distance4, end3[1] + Math.sin(angle) * distance4, 0];
88022
- const prongs = [-1, 1].map((side) => mesh3(bx(0.1, 0.016, 0.022), steel, [...along2(0.03)].map((value, index) => index === 2 ? side * 0.014 : value), [0, 0, angle]));
88410
+ const along3 = (distance4) => [end3[0] + Math.cos(angle) * distance4, end3[1] + Math.sin(angle) * distance4, 0];
88411
+ const prongs = [-1, 1].map((side) => mesh3(bx(0.1, 0.016, 0.022), steel, [...along3(0.03)].map((value, index) => index === 2 ? side * 0.014 : value), [0, 0, angle]));
88023
88412
  const { bar: bar2, chisel } = shapesOf(T2, extrude2);
88024
88413
  return G(mesh3(bar2, forged), mesh3(chisel, steel), ...prongs);
88025
88414
  };
@@ -88749,15 +89138,15 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
88749
89138
  return G(lower, stripe, upper, topCrimp, bottomCrimp, label, drop);
88750
89139
  };
88751
89140
  var syringe = ({ mesh: mesh3, bx, cyl, G, plastic, metal: metal2, glass }) => {
88752
- const along2 = [0, 0, Math.PI / 2];
89141
+ const along3 = [0, 0, Math.PI / 2];
88753
89142
  const alongTip = [0, 0, -Math.PI / 2];
88754
- const barrel = mesh3(cyl(0.075, 0.075, 0.7, 10), glass(13625584, 0.55), [-0.1, 0, 0], along2);
88755
- const flange = mesh3(cyl(0.1, 0.1, 0.025, 12), plastic(15265520), [-0.45, 0, 0], along2);
88756
- const stopper = mesh3(cyl(0.07, 0.07, 0.07, 8), plastic(2829099), [-0.3, 0, 0], along2);
88757
- const rod = mesh3(cyl(0.022, 0.022, 0.5, 6), plastic(15265520), [-0.475, 0, 0], along2);
88758
- const thumbRest = mesh3(cyl(0.09, 0.09, 0.025, 10), plastic(15265520), [-0.7375, 0, 0], along2);
89143
+ const barrel = mesh3(cyl(0.075, 0.075, 0.7, 10), glass(13625584, 0.55), [-0.1, 0, 0], along3);
89144
+ const flange = mesh3(cyl(0.1, 0.1, 0.025, 12), plastic(15265520), [-0.45, 0, 0], along3);
89145
+ const stopper = mesh3(cyl(0.07, 0.07, 0.07, 8), plastic(2829099), [-0.3, 0, 0], along3);
89146
+ const rod = mesh3(cyl(0.022, 0.022, 0.5, 6), plastic(15265520), [-0.475, 0, 0], along3);
89147
+ const thumbRest = mesh3(cyl(0.09, 0.09, 0.025, 10), plastic(15265520), [-0.7375, 0, 0], along3);
88759
89148
  const hub = mesh3(cyl(0.025, 0.06, 0.1, 8), plastic(15790320), [0.3, 0, 0], alongTip);
88760
- const needle = mesh3(cyl(0.012, 0.012, 0.4, 6), metal2(13225683), [0.55, 0, 0], along2);
89149
+ const needle = mesh3(cyl(0.012, 0.012, 0.4, 6), metal2(13225683), [0.55, 0, 0], along3);
88761
89150
  const marks = [-0.3, -0.1, 0.1].map((x) => mesh3(bx(0.012, 0.15, 0.15), plastic(2781109), [x, 0, 0]));
88762
89151
  return G(barrel, flange, stopper, rod, thumbRest, hub, needle, ...marks);
88763
89152
  };
@@ -88792,13 +89181,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
88792
89181
  return G(foam, core, strapLeft, strapRight);
88793
89182
  };
88794
89183
  var thermometer = ({ mesh: mesh3, bx, cyl, G, plastic, metal: metal2, glass }) => {
88795
- const along2 = [0, 0, -Math.PI / 2];
89184
+ const along3 = [0, 0, -Math.PI / 2];
88796
89185
  const body = mesh3(bx(0.8, 0.17, 0.3), plastic(15922421), [-0.2, -0.01, 0]);
88797
89186
  const screen2 = mesh3(bx(0.34, 0.03, 0.16), glass(10471332, 0.9), [-0.3, 0.088, 0]);
88798
89187
  const button = mesh3(cyl(0.05, 0.05, 0.03, 10), plastic(2788054), [0, 0.088, 0]);
88799
- const collar = mesh3(cyl(0.07, 0.07, 0.04, 10), plastic(13949404), [0.22, 0, 0], along2);
88800
- const probe = mesh3(cyl(0.04, 0.06, 0.36, 10), metal2(12041410), [0.42, 0, 0], along2);
88801
- return G(body, screen2, button, collar, probe);
89188
+ const collar = mesh3(cyl(0.07, 0.07, 0.04, 10), plastic(13949404), [0.22, 0, 0], along3);
89189
+ const probe2 = mesh3(cyl(0.04, 0.06, 0.36, 10), metal2(12041410), [0.42, 0, 0], along3);
89190
+ return G(body, screen2, button, collar, probe2);
88802
89191
  };
88803
89192
  var alcohol70 = ({ mesh: mesh3, cyl, lathe: lathe2, G, glass, plastic, paper: paper2 }) => {
88804
89193
  const slim = [1, 1, 0.714];
@@ -91198,8 +91587,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
91198
91587
  var hasItemModel = (id) => defaultItemModels().has(id);
91199
91588
  var DEFAULT_COLOR = 9080724;
91200
91589
  var PI13 = Math.PI;
91201
- function shade2(color2, factor) {
91202
- const channel = (shift) => Math.max(0, Math.min(255, Math.round((color2 >> shift & 255) * factor)));
91590
+ function shade2(color2, factor2) {
91591
+ const channel = (shift) => Math.max(0, Math.min(255, Math.round((color2 >> shift & 255) * factor2)));
91203
91592
  return channel(16) << 16 | channel(8) << 8 | channel(0);
91204
91593
  }
91205
91594
  var PROUD = 2e-3;
@@ -91953,8 +92342,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
91953
92342
  hand.updateMatrixWorld(true);
91954
92343
  const at4 = model.localToWorld(v.copy(frontOf));
91955
92344
  if (inLens) toWorldLens(camera2, at4, camera2.fov ?? 72, VIEW_HOLD.tool.fov);
91956
- const along2 = v2.set(1, 0, 0).applyQuaternion(model.getWorldQuaternion(q2)).normalize();
91957
- return { position: [at4.x, at4.y, at4.z], direction: [along2.x, along2.y, along2.z], drawsFlash: false };
92345
+ const along3 = v2.set(1, 0, 0).applyQuaternion(model.getWorldQuaternion(q2)).normalize();
92346
+ return { position: [at4.x, at4.y, at4.z], direction: [along3.x, along3.y, along3.z], drawsFlash: false };
91958
92347
  },
91959
92348
  handTargets() {
91960
92349
  const held = heldHold();
@@ -92772,7 +93161,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
92772
93161
  const middle = fitted.integral === true ? -length2 / 2 : length2 / 2;
92773
93162
  cylinderX(group, radius, length2, isImprovised ? M.rust : M.dark, middle, 0, 0, 18);
92774
93163
  if (isImprovised) {
92775
- for (const along2 of [0.2, 0.8]) cylinderX(group, radius * 1.04, 0.012, M.tape, middle - length2 / 2 + length2 * along2, 0, 0, 18);
93164
+ for (const along3 of [0.2, 0.8]) cylinderX(group, radius * 1.04, 0.012, M.tape, middle - length2 / 2 + length2 * along3, 0, 0, 18);
92776
93165
  cylinderX(group, radius * 0.7, 8e-3, M.rustD, middle + length2 / 2 - 25e-4, 0, 0, 14);
92777
93166
  } else {
92778
93167
  for (let i = 0; i < BAFFLES; i++) cylinderX(group, radius * 1.03, 4e-3, M.metal, middle - length2 / 2 + length2 * (i + 0.5) / BAFFLES, 0, 0, 18);
@@ -94242,11 +94631,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
94242
94631
  this.spare.push(record);
94243
94632
  }
94244
94633
  /** Keeps the records `keep` accepts, in the same order, without allocating. `context` goes to `keep` so no closure is needed per frame. */
94245
- compact(keep, context) {
94634
+ compact(keep2, context) {
94246
94635
  let write = 0;
94247
94636
  for (let read = 0; read < this.items.length; read++) {
94248
94637
  const record = this.items[read];
94249
- if (keep(record, context)) {
94638
+ if (keep2(record, context)) {
94250
94639
  this.items[write++] = record;
94251
94640
  continue;
94252
94641
  }
@@ -94496,12 +94885,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
94496
94885
  function streamFor3(eventSeed) {
94497
94886
  return lehmer(mixEventSeed(eventSeed));
94498
94887
  }
94888
+ var MAX_PAD = 0.45;
94499
94889
  var SKIN = 5e-3;
94500
94890
  var Solids = class {
94501
94891
  constructor() {
94502
94892
  __publicField3(this, "queries", /* @__PURE__ */ new Map());
94503
94893
  __publicField3(this, "list", []);
94504
- __publicField3(this, "hit", { x: 0, y: 0, z: 0, nx: 0, ny: 0, nz: 0 });
94894
+ __publicField3(this, "hit", { x: 0.5, y: 0.5, z: 0.5, nx: 0.5, ny: 0.5, nz: 0.5, d: 0.5 });
94505
94895
  }
94506
94896
  get empty() {
94507
94897
  return this.list.length === 0;
@@ -94517,18 +94907,19 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
94517
94907
  this.list = [];
94518
94908
  }
94519
94909
  /**
94520
- * Stops a step that goes into a solid: `out` gets the nearest hit, put back `pad` metres off the surface (never behind where the step began) and
94910
+ * Stops a step that goes into a solid: `out` gets the nearest hit, put back the step's `pad` metres (at most `MAX_PAD`) off the surface (never behind where the step began) and
94521
94911
  * the surface's normal. Answers whether the step was stopped.
94522
94912
  */
94523
- stop(move2, pad, out) {
94913
+ stop(move2, out) {
94524
94914
  const dx = move2.x1 - move2.x0;
94525
94915
  const dy = move2.y1 - move2.y0;
94526
94916
  const dz = move2.z1 - move2.z0;
94527
- const length2 = Math.hypot(dx, dy, dz);
94917
+ const length2 = Math.sqrt(dx * dx + dy * dy + dz * dz);
94528
94918
  if (!(length2 > 0)) return false;
94529
94919
  let nearest = Infinity;
94530
- for (const query2 of this.list) {
94531
- if (!query2(move2, this.hit)) continue;
94920
+ const list2 = this.list;
94921
+ for (let index = 0; index < list2.length; index++) {
94922
+ if (!list2[index](move2, this.hit)) continue;
94532
94923
  const reached = ((this.hit.x - move2.x0) * dx + (this.hit.y - move2.y0) * dy + (this.hit.z - move2.z0) * dz) / length2;
94533
94924
  if (reached >= nearest) continue;
94534
94925
  nearest = reached;
@@ -94540,15 +94931,24 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
94540
94931
  out.nz = this.hit.nz;
94541
94932
  }
94542
94933
  if (nearest === Infinity) return false;
94543
- const back2 = Math.min(Math.max(pad, 0) + SKIN, Math.max(nearest, 0));
94934
+ const hitX2 = out.x;
94935
+ const hitY2 = out.y;
94936
+ const hitZ = out.z;
94937
+ out.d = out.nx * hitX2 + out.ny * hitY2 + out.nz * hitZ;
94938
+ const back2 = Math.min(Math.min(Math.max(move2.pad, 0), MAX_PAD) + SKIN, Math.max(nearest, 0));
94544
94939
  out.x -= dx / length2 * back2;
94545
94940
  out.y -= dy / length2 * back2;
94546
94941
  out.z -= dz / length2 * back2;
94942
+ const off = (out.x - hitX2) * out.nx + (out.y - hitY2) * out.ny + (out.z - hitZ) * out.nz;
94943
+ if (off < SKIN) {
94944
+ out.x += out.nx * (SKIN - off);
94945
+ out.y += out.ny * (SKIN - off);
94946
+ out.z += out.nz * (SKIN - off);
94947
+ }
94547
94948
  return true;
94548
94949
  }
94549
94950
  };
94550
94951
  var SKIN2 = 5e-3;
94551
- var MAX_PAD = 0.45;
94552
94952
  function rotation(q) {
94553
94953
  const [x, y, z, w] = q ?? [0, 0, 0, 1];
94554
94954
  const n = Math.hypot(x, y, z, w) || 1;
@@ -94573,7 +94973,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
94573
94973
  __publicField3(this, "spaces", /* @__PURE__ */ new Map());
94574
94974
  __publicField3(this, "list", []);
94575
94975
  __publicField3(this, "random");
94576
- __publicField3(this, "out", { x: 0, y: 0, z: 0, nx: 0, ny: 0, nz: 0 });
94976
+ __publicField3(this, "out", { x: 0.5, y: 0.5, z: 0.5, nx: 0.5, ny: 0.5, nz: 0.5, d: 0.5 });
94577
94977
  __publicField3(this, "l0", new Float64Array(3));
94578
94978
  __publicField3(this, "l1", new Float64Array(3));
94579
94979
  __publicField3(this, "q", new Float64Array(3));
@@ -94648,7 +95048,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
94648
95048
  }
94649
95049
  /** Passes at `rate` per second. */
94650
95050
  chance(rate, dt) {
94651
- return rate > 0 && this.random.next() < 1 - Math.exp(-rate * dt);
95051
+ return rate > 0 && dt > 0 && this.random.next() < 1 - Math.exp(-rate * dt);
94652
95052
  }
94653
95053
  /** The opening the wall point `q` (local) is in lets it through now. */
94654
95054
  through(s, q, dt) {
@@ -94671,7 +95071,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
94671
95071
  }
94672
95072
  confineMove(move2, dt) {
94673
95073
  if (this.confineSpaces(move2, dt)) return true;
94674
- return !this.solids.empty && this.solids.stop(move2, Math.min(Math.max(0, move2.pad), MAX_PAD), this.out);
95074
+ return !this.solids.empty && this.solids.stop(move2, this.out);
94675
95075
  }
94676
95076
  confineSpaces(move2, dt) {
94677
95077
  const list2 = this.list;
@@ -94741,6 +95141,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
94741
95141
  out.nx = r[axis2] * sign2;
94742
95142
  out.ny = r[3 + axis2] * sign2;
94743
95143
  out.nz = r[6 + axis2] * sign2;
95144
+ out.d = out.nx * s.cx + out.ny * s.cy + out.nz * s.cz + (in0 ? -h[axis2] : h[axis2]);
94744
95145
  return true;
94745
95146
  }
94746
95147
  return false;
@@ -94758,6 +95159,127 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
94758
95159
  if (into >= 0) return [vx2, vy2, vz2];
94759
95160
  return [vx2 - into * out.nx, vy2 - into * out.ny, vz2 - into * out.nz];
94760
95161
  }
95162
+ var PUFF_REACH = 1.28;
95163
+ var PROBES = [{ x: 1, y: 0, z: 0 }, { x: -1, y: 0, z: 0 }, { x: 0, y: 0, z: 1 }, { x: 0, y: 0, z: -1 }, { x: 0, y: 1, z: 0 }];
95164
+ var PROBES_PER_SECOND = 60;
95165
+ var FRAMES_PER_PROBE = 3;
95166
+ var GROUND_FACING = 0.7;
95167
+ var SAME_WALL = 0.9;
95168
+ var PROBE = { x0: 0.5, y0: 0.5, z0: 0.5, x1: 0.5, y1: 0.5, z1: 0.5, pad: 0.5 };
95169
+ var KeptCut = class {
95170
+ constructor() {
95171
+ __publicField3(this, "on", false);
95172
+ __publicField3(this, "nx", 0.5);
95173
+ __publicField3(this, "ny", 0.5);
95174
+ __publicField3(this, "nz", 0.5);
95175
+ __publicField3(this, "d", 0.5);
95176
+ }
95177
+ };
95178
+ function createCut() {
95179
+ return new KeptCut();
95180
+ }
95181
+ function clearCuts(puff3) {
95182
+ puff3.cuts[0].on = false;
95183
+ puff3.cuts[1].on = false;
95184
+ }
95185
+ var WrittenWay = class {
95186
+ constructor() {
95187
+ __publicField3(this, "x", 0.5);
95188
+ __publicField3(this, "y", 0.5);
95189
+ __publicField3(this, "z", 0.5);
95190
+ }
95191
+ };
95192
+ var WAY = new WrittenWay();
95193
+ function probe(confiner, puff3, way) {
95194
+ const reach2 = puff3.size * PUFF_REACH;
95195
+ if (!(reach2 > 0)) return false;
95196
+ PROBE.x0 = puff3.x;
95197
+ PROBE.y0 = puff3.y;
95198
+ PROBE.z0 = puff3.z;
95199
+ PROBE.x1 = puff3.x + way.x * reach2;
95200
+ PROBE.y1 = puff3.y + way.y * reach2;
95201
+ PROBE.z1 = puff3.z + way.z * reach2;
95202
+ PROBE.pad = 0;
95203
+ return confiner.confineMove(PROBE, 0) && confiner.out.ny <= GROUND_FACING;
95204
+ }
95205
+ var isFartherFrom = (puff3, a, b) => a.nx * puff3.x + a.ny * puff3.y + a.nz * puff3.z - a.d > b.nx * puff3.x + b.ny * puff3.y + b.nz * puff3.z - b.d;
95206
+ var isBehind = (puff3, face) => face.nx * puff3.x + face.ny * puff3.y + face.nz * puff3.z < face.d;
95207
+ var sameWall = (cut, face) => cut.on && cut.nx * face.nx + cut.ny * face.ny + cut.nz * face.nz > SAME_WALL;
95208
+ function cutFor(puff3, face) {
95209
+ const first = puff3.cuts[0];
95210
+ const second = puff3.cuts[1];
95211
+ if (sameWall(first, face)) return first;
95212
+ if (sameWall(second, face)) return second;
95213
+ if (!first.on) return first;
95214
+ if (!second.on) return second;
95215
+ const farther = isFartherFrom(puff3, first, second) ? first : second;
95216
+ return isFartherFrom(puff3, farther, face) ? farther : void 0;
95217
+ }
95218
+ function cutAtFace(puff3, face) {
95219
+ if (face.ny > GROUND_FACING) return;
95220
+ const cut = cutFor(puff3, face);
95221
+ if (!cut) return;
95222
+ cut.on = true;
95223
+ cut.nx = face.nx;
95224
+ cut.ny = face.ny;
95225
+ cut.nz = face.nz;
95226
+ cut.d = face.d;
95227
+ }
95228
+ function cutFrom(puff3, out) {
95229
+ cutAtFace(puff3, out);
95230
+ }
95231
+ function cutAt2(confiner, puff3, way) {
95232
+ if (!probe(confiner, puff3, way)) return false;
95233
+ cutAtFace(puff3, confiner.out);
95234
+ return true;
95235
+ }
95236
+ function backward(puff3) {
95237
+ const speed = Math.sqrt(puff3.vx * puff3.vx + puff3.vy * puff3.vy + puff3.vz * puff3.vz);
95238
+ if (!(speed > 0)) return null;
95239
+ WAY.x = -puff3.vx / speed;
95240
+ WAY.y = -puff3.vy / speed;
95241
+ WAY.z = -puff3.vz / speed;
95242
+ return WAY;
95243
+ }
95244
+ function along2(cut, sign2) {
95245
+ WAY.x = sign2 * cut.nx;
95246
+ WAY.y = sign2 * cut.ny;
95247
+ WAY.z = sign2 * cut.nz;
95248
+ return WAY;
95249
+ }
95250
+ function dropPassed(confiner, puff3) {
95251
+ for (let i = 0; i < 2; i++) {
95252
+ const cut = puff3.cuts[i];
95253
+ if (!cut.on || !isBehind(puff3, cut)) continue;
95254
+ cut.on = false;
95255
+ cutAt2(confiner, puff3, along2(cut, 1));
95256
+ }
95257
+ }
95258
+ function keep(confiner, puff3, cut) {
95259
+ if (!cut.on) return;
95260
+ if (!probe(confiner, puff3, along2(cut, -1))) {
95261
+ cut.on = false;
95262
+ return;
95263
+ }
95264
+ cut.d = confiner.out.d;
95265
+ }
95266
+ function lookForWalls(confiner, puff3) {
95267
+ dropPassed(confiner, puff3);
95268
+ const turn2 = Math.round(puff3.t * PROBES_PER_SECOND);
95269
+ if (turn2 <= 1) {
95270
+ const back2 = backward(puff3);
95271
+ if (back2) cutAt2(confiner, puff3, back2);
95272
+ for (let i = 0; i < PROBES.length; i++) cutAt2(confiner, puff3, PROBES[i]);
95273
+ return;
95274
+ }
95275
+ if (turn2 % FRAMES_PER_PROBE !== 0) return;
95276
+ const slot = turn2 / FRAMES_PER_PROBE % (PROBES.length + 3);
95277
+ if (slot < 2) keep(confiner, puff3, puff3.cuts[slot]);
95278
+ else if (slot === 2) {
95279
+ const back2 = backward(puff3);
95280
+ if (back2) cutAt2(confiner, puff3, back2);
95281
+ } else cutAt2(confiner, puff3, PROBES[slot - 3]);
95282
+ }
94761
95283
  var FLOOR_FRACTION = 0.4;
94762
95284
  var FLOOR_BOUNCE = -0.2;
94763
95285
  var ARRIVAL_FRAME = 30;
@@ -94797,7 +95319,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
94797
95319
  age: 0,
94798
95320
  heat: 0,
94799
95321
  size: 0,
94800
- source: void 0
95322
+ source: void 0,
95323
+ cuts: [createCut(), createCut()]
94801
95324
  }));
94802
95325
  }
94803
95326
  function spawnPuff(pool, random, init) {
@@ -94831,6 +95354,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
94831
95354
  puff3.heat = 0;
94832
95355
  puff3.size = 0;
94833
95356
  puff3.source = init.source;
95357
+ clearCuts(puff3);
94834
95358
  return puff3;
94835
95359
  }
94836
95360
  function ageOrKeep2(puff3, dt) {
@@ -94880,17 +95404,21 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
94880
95404
  MOVE.z0 = puff3.z;
94881
95405
  if (puff3.ring) moveOnRing(puff3, puff3.ring, wind);
94882
95406
  else moveFree(puff3, dt, age, heat, wind);
94883
- if (confining && CARRIED_KINDS[puff3.kind] && confine(confiner, puff3, dt)) {
95407
+ const carried = confining && CARRIED_KINDS[puff3.kind];
95408
+ if (carried && confine(confiner, puff3, dt)) {
94884
95409
  const out = confiner.out;
94885
95410
  puff3.x = out.x;
94886
95411
  puff3.y = out.y;
94887
95412
  puff3.z = out.z;
94888
95413
  slideInto(out, puff3);
95414
+ cutFrom(puff3, out);
94889
95415
  }
94890
95416
  const size = puff3.s0 + (puff3.s1 - puff3.s0) * (1 - Math.exp(-puff3.t * puff3.gk)) + puff3.sg * Math.min(puff3.t, GROWTH_CAP_SECONDS);
94891
95417
  puff3.size = size * Math.min(1, puff3.t * ARRIVAL_FRAME + ARRIVAL_BASE);
94892
95418
  puff3.age = age;
94893
95419
  puff3.heat = heat;
95420
+ if (carried) lookForWalls(confiner, puff3);
95421
+ else clearCuts(puff3);
94894
95422
  }
94895
95423
  }
94896
95424
  var GROUND_LIFT = 0.02;
@@ -95786,11 +96314,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
95786
96314
  function plus(vector2, x, y, z) {
95787
96315
  return [vector2[0] + x, vector2[1] + y, vector2[2] + z];
95788
96316
  }
95789
- function scaledBy(vector2, factor) {
95790
- return [vector2[0] * factor, vector2[1] * factor, vector2[2] * factor];
96317
+ function scaledBy(vector2, factor2) {
96318
+ return [vector2[0] * factor2, vector2[1] * factor2, vector2[2] * factor2];
95791
96319
  }
95792
- function plusScaled(vector2, direction, factor) {
95793
- return [vector2[0] + direction[0] * factor, vector2[1] + direction[1] * factor, vector2[2] + direction[2] * factor];
96320
+ function plusScaled(vector2, direction, factor2) {
96321
+ return [vector2[0] + direction[0] * factor2, vector2[1] + direction[1] * factor2, vector2[2] + direction[2] * factor2];
95794
96322
  }
95795
96323
  function negated(vector2) {
95796
96324
  return [-vector2[0], -vector2[1], -vector2[2]];
@@ -96821,7 +97349,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
96821
97349
  var ORIGIN = [0, 0, 0];
96822
97350
  var FACING4 = [0, 0, 1];
96823
97351
  var UP11 = [0, 1, 0];
96824
- var grow = (piece3, factor) => [piece3[0] * factor, piece3[1] * factor, piece3[2] * factor];
97352
+ var grow = (piece3, factor2) => [piece3[0] * factor2, piece3[1] * factor2, piece3[2] * factor2];
96825
97353
  var debrisTone = (look) => or(variable(DEBRIS_COLOR_VARIABLE), look.debris);
96826
97354
  var dustTone = (look) => or(variable(DUST_COLOR_VARIABLE), look.dust);
96827
97355
  var sparks = (look, count) => look.sparks ? [call2("spark_at", ORIGIN, FACING4, count, 0.9)] : [];
@@ -97148,8 +97676,36 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
97148
97676
  loop: 2,
97149
97677
  timeline: [call2("bodywork_impact", [0, 0, 0], NORMAL, [variable("dx"), variable("dy"), variable("dz")], variable("bore"), variable("paint"), variable("metal"))]
97150
97678
  };
97679
+ var GLASS_PIECE = 11061464;
97680
+ var GLASS_DUST = 12572386;
97681
+ var HIT = [0, 0, 0];
97682
+ var VEHICLE_GLASS_CHIP = {
97683
+ id: "vehicle_glass_chip",
97684
+ pageId: "vehicle:vehicle_glass_chip",
97685
+ team: "vehicles",
97686
+ budget: { particles: 16, debris: 6 },
97687
+ loop: 2,
97688
+ timeline: [
97689
+ burst("add", 6, { p: HIT, box: [0.04, 0.04, 0.04], size: [8e-3, 0.02], life: [0.12, 0.3], c0: 16777215, a: 0.9, fi: 0.3 }),
97690
+ burst("normal", 6, { p: HIT, dir: NORMAL, sp: [0.3, 0.9], drag: 3, life: [0.4, 0.8], size: [0.04, 0.08], grow: 2, c0: GLASS_DUST, a: 0.18 }),
97691
+ repeat(6, debris({ p: HIT, box: [0.03, 0.03, 0.03], dir: NORMAL, cone: 0.6, sp: [0.4, 1.4], size: [rnd(2e-3, 4e-3), 2e-3, rnd(2e-3, 4e-3)], c: GLASS_PIECE, spin: 20, life: 6, bounce: 0.2 }))
97692
+ ]
97693
+ };
97694
+ var VEHICLE_GLASS_SHATTER = {
97695
+ id: "vehicle_glass_shatter",
97696
+ pageId: "vehicle:vehicle_glass_shatter",
97697
+ team: "vehicles",
97698
+ budget: { particles: 40, debris: 0 },
97699
+ loop: 2,
97700
+ timeline: [
97701
+ burst("add", 24, { p: HIT, box: [0.5, 0.3, 0.5], size: [0.01, 0.03], life: [0.15, 0.5], c0: 16777215, a: 0.9, fi: 0.3 }),
97702
+ burst("normal", 10, { p: [0, -0.15, 0], box: [0.5, 0.2, 0.5], sp: [0.1, 0.4], drag: 2, life: [0.6, 1.1], size: [0.08, 0.14], grow: 2.5, c0: GLASS_DUST, a: 0.14 })
97703
+ ]
97704
+ };
97151
97705
  var VEHICLE_EFFECTS = [
97152
97706
  BODYWORK_IMPACT,
97707
+ VEHICLE_GLASS_CHIP,
97708
+ VEHICLE_GLASS_SHATTER,
97153
97709
  /** The engine on fire: `engine_smoke` at its worst condition (black smoke, flames in the hood, a light). */
97154
97710
  aliasOf(ENGINE_SMOKE, "vehicle_fire", { params: { id: "condition", options: ["100", "60", "30", "10"], default: 3 }, loop: 12 }),
97155
97711
  /** The exhaust of a car under way: `engine_smoke` in the best condition, for half a second so a moving car asks again. */
@@ -97861,10 +98417,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
97861
98417
  var MAX_SCALE = 3;
97862
98418
  var MIN_SCALE = 0.6;
97863
98419
  function reflected(direction, normal) {
97864
- const along2 = direction[0] * normal[0] + direction[1] * normal[1] + direction[2] * normal[2];
97865
- const out = [direction[0] - 2 * along2 * normal[0], direction[1] - 2 * along2 * normal[1], direction[2] - 2 * along2 * normal[2]];
98420
+ const along22 = direction[0] * normal[0] + direction[1] * normal[1] + direction[2] * normal[2];
98421
+ const out = [direction[0] - 2 * along22 * normal[0], direction[1] - 2 * along22 * normal[1], direction[2] - 2 * along22 * normal[2]];
97866
98422
  const length2 = Math.hypot(out[0], out[1], out[2]);
97867
- if (length2 < 1e-6 || Math.abs(along2) > 0.98) return normal;
98423
+ if (length2 < 1e-6 || Math.abs(along22) > 0.98) return normal;
97868
98424
  return [out[0] / length2, out[1] / length2, out[2] / length2];
97869
98425
  }
97870
98426
  var numberOr = (value, fallback2) => typeof value === "number" && Number.isFinite(value) ? value : fallback2;
@@ -97897,13 +98453,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
97897
98453
  var UP12 = [0, 1, 0];
97898
98454
  var ZERO2 = [0, 0, 0];
97899
98455
  var FULL_TURN_DRAWN = 6.283;
97900
- function scaledSizes(range22, factor) {
97901
- return [range22[0] * Math.sqrt(factor), range22[1] * Math.sqrt(factor)];
98456
+ function scaledSizes(range22, factor2) {
98457
+ return [range22[0] * Math.sqrt(factor2), range22[1] * Math.sqrt(factor2)];
97902
98458
  }
97903
- function fireEmit(engine, key2, dt, centre, radius, factor, options = {}) {
98459
+ function fireEmit(engine, key2, dt, centre, radius, factor2, options = {}) {
97904
98460
  const wind = options.wind ?? ZERO2;
97905
- const sqrtFactor = Math.sqrt(factor);
97906
- engine.emit(`${key2}f`, "add", 90 * factor, dt, () => ({
98461
+ const sqrtFactor = Math.sqrt(factor2);
98462
+ engine.emit(`${key2}f`, "add", 90 * factor2, dt, () => ({
97907
98463
  p: centre,
97908
98464
  r: radius,
97909
98465
  flat: true,
@@ -97912,7 +98468,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
97912
98468
  sp: [0.4, 1.4],
97913
98469
  v: wind,
97914
98470
  life: [0.35, 0.85],
97915
- size: scaledSizes([0.22, 0.5], factor),
98471
+ size: scaledSizes([0.22, 0.5], factor2),
97916
98472
  grow: 0.35,
97917
98473
  c0: 16765562,
97918
98474
  c1: 9050629,
@@ -97920,7 +98476,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
97920
98476
  fi: 0.15,
97921
98477
  g: -2.2
97922
98478
  }));
97923
- engine.emit(`${key2}c`, "add", 30 * factor, dt, () => ({
98479
+ engine.emit(`${key2}c`, "add", 30 * factor2, dt, () => ({
97924
98480
  p: centre,
97925
98481
  r: radius * 0.6,
97926
98482
  flat: true,
@@ -97928,7 +98484,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
97928
98484
  cone: 0.3,
97929
98485
  sp: [0.3, 0.8],
97930
98486
  life: [0.2, 0.4],
97931
- size: scaledSizes([0.25, 0.4], factor),
98487
+ size: scaledSizes([0.25, 0.4], factor2),
97932
98488
  grow: 0.6,
97933
98489
  c0: 16773824,
97934
98490
  c1: 16747040,
@@ -97937,13 +98493,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
97937
98493
  g: -1
97938
98494
  }));
97939
98495
  if (engine.quality < 2) {
97940
- engine.emit(`${key2}e`, "streak", 10 * factor, dt, () => {
98496
+ engine.emit(`${key2}e`, "streak", 10 * factor2, dt, () => {
97941
98497
  const jitter = plus(wind, engine.random.between(-0.4, 0.4), 0, engine.random.between(-0.4, 0.4));
97942
98498
  return { p: centre, box: [radius, 0, radius], dir: UP12, cone: 0.5, sp: [1.5, 3.5], v: jitter, life: [0.8, 1.8], len: 0.03, c0: 16756816, c1: 6295552, g: -0.6, drag: 0.4 };
97943
98499
  });
97944
98500
  }
97945
98501
  if (options.noSmoke) return;
97946
- engine.emit(`${key2}s`, "normal", (options.smoke || 14) * factor, dt, () => ({
98502
+ engine.emit(`${key2}s`, "normal", (options.smoke || 14) * factor2, dt, () => ({
97947
98503
  p: plus(centre, 0, 0.8 * sqrtFactor, 0),
97948
98504
  r: radius * 0.7,
97949
98505
  dir: UP12,
@@ -97952,7 +98508,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
97952
98508
  v: wind,
97953
98509
  drag: 0.15,
97954
98510
  life: [2.5, 4.5],
97955
- size: scaledSizes([0.4, 0.8], factor),
98511
+ size: scaledSizes([0.4, 0.8], factor2),
97956
98512
  grow: 4,
97957
98513
  c0: options.smokeColor || 2762018,
97958
98514
  c1: 1184536,
@@ -98037,7 +98593,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
98037
98593
  var MACROS = {
98038
98594
  blood_hit: ({ engine }, [point, direction, age, scale]) => bloodHit(engine, point, direction, age, scale),
98039
98595
  impact: ({ engine }, [material, point, normal, scale, age]) => impact2(engine, material, point, normal, scale, age),
98040
- fire_emit: ({ engine, dt }, [key2, centre, radius, factor, options]) => fireEmit(engine, key2, dt, centre, radius, factor, options),
98596
+ fire_emit: ({ engine, dt }, [key2, centre, radius, factor2, options]) => fireEmit(engine, key2, dt, centre, radius, factor2, options),
98041
98597
  explode: ({ engine, cameraPosition }, [point, scale, chipColor]) => explode(engine, point, scale, cameraPosition, chipColor),
98042
98598
  muzzle: ({ engine }, [weapon2, tip, direction]) => muzzle(engine, weapon2, tip, direction),
98043
98599
  casing: ({ engine }, [port, type]) => casing(engine, port, type),
@@ -98607,6 +99163,110 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
98607
99163
  function addScrape(store, spec) {
98608
99164
  store.add({ kind: "scrape", ...spec, y: spec.y + 2e-3 + nextLift(store) * 2e-4 });
98609
99165
  }
99166
+ var RESTITUTION = -0.32;
99167
+ var GROUND_FRICTION = 0.5;
99168
+ var REST_SPEED = 0.6;
99169
+ var REST_SLIDE = 0.5;
99170
+ var TRAIL_SECONDS = 1.8;
99171
+ var TRAIL_STEP = 0.025;
99172
+ var QUARTER_TURN3 = Math.PI / 2;
99173
+ var TOP_FACING = 0.7;
99174
+ var MOVE2 = { x0: 0.5, y0: 0.5, z0: 0.5, x1: 0.5, y1: 0.5, z1: 0.5, pad: 0.5 };
99175
+ function bounce2(core, chunk, floor2) {
99176
+ chunk.y = floor2;
99177
+ if (chunk.blood && !chunk.splat && core.layers.mark) {
99178
+ chunk.splat = true;
99179
+ addBloodSplat(core.marks, core.ground, chunk.rng, { x: chunk.x, z: chunk.z, radius: chunk.rng.between(0.06, 0.13) });
99180
+ }
99181
+ chunk.vy *= RESTITUTION;
99182
+ chunk.vx *= GROUND_FRICTION;
99183
+ chunk.vz *= GROUND_FRICTION;
99184
+ chunk.ax *= GROUND_FRICTION;
99185
+ chunk.ay *= GROUND_FRICTION;
99186
+ chunk.az *= GROUND_FRICTION;
99187
+ if (Math.abs(chunk.vy) < REST_SPEED && Math.hypot(chunk.vx, chunk.vz) < REST_SLIDE) {
99188
+ chunk.rest = true;
99189
+ chunk.rx = Math.round(chunk.rx / QUARTER_TURN3) * QUARTER_TURN3;
99190
+ chunk.rz = Math.round(chunk.rz / QUARTER_TURN3) * QUARTER_TURN3;
99191
+ }
99192
+ }
99193
+ var chunkPad = (chunk) => Math.max(chunk.sx, chunk.sy, chunk.sz) * 0.45;
99194
+ function hitFace(chunk, out) {
99195
+ chunk.x = out.x;
99196
+ chunk.y = out.y;
99197
+ chunk.z = out.z;
99198
+ const into = chunk.vx * out.nx + chunk.vy * out.ny + chunk.vz * out.nz;
99199
+ if (into >= 0) return;
99200
+ const tx = chunk.vx - into * out.nx;
99201
+ const ty = chunk.vy - into * out.ny;
99202
+ const tz = chunk.vz - into * out.nz;
99203
+ const back2 = into * RESTITUTION;
99204
+ chunk.vx = tx * GROUND_FRICTION + back2 * out.nx;
99205
+ chunk.vy = ty * GROUND_FRICTION + back2 * out.ny;
99206
+ chunk.vz = tz * GROUND_FRICTION + back2 * out.nz;
99207
+ chunk.ax *= GROUND_FRICTION;
99208
+ chunk.ay *= GROUND_FRICTION;
99209
+ chunk.az *= GROUND_FRICTION;
99210
+ if (out.ny > TOP_FACING && Math.abs(back2) < REST_SPEED && Math.sqrt(tx * tx + tz * tz) * GROUND_FRICTION < REST_SLIDE) {
99211
+ chunk.rest = true;
99212
+ chunk.rx = Math.round(chunk.rx / QUARTER_TURN3) * QUARTER_TURN3;
99213
+ chunk.rz = Math.round(chunk.rz / QUARTER_TURN3) * QUARTER_TURN3;
99214
+ }
99215
+ }
99216
+ function leaveTrail(core, chunk, dt) {
99217
+ chunk.trail -= dt;
99218
+ if (chunk.trail > 0) return;
99219
+ chunk.trail = TRAIL_STEP;
99220
+ const random = chunk.rng;
99221
+ addSpark(core, {
99222
+ x: chunk.x,
99223
+ y: chunk.y,
99224
+ z: chunk.z,
99225
+ vx: chunk.vx * 0.15,
99226
+ vy: chunk.vy * 0.15,
99227
+ vz: chunk.vz * 0.15,
99228
+ life: random.between(0.25, 0.45),
99229
+ w: 0.05 + chunk.sx * 0.2,
99230
+ st: 0.05,
99231
+ kind: 0,
99232
+ g: 0,
99233
+ drag: 1,
99234
+ source: chunk.source
99235
+ });
99236
+ if (random.next() < 0.25) {
99237
+ addPuff(core, random, { x: chunk.x, y: chunk.y, z: chunk.z, s0: 0.04, s1: 0.14 + chunk.sx * 0.3, sg: 0.15, life: random.between(1, 1.6), drag: 2, buoy: 0.6, color: SMOKE_COLORS.grey, kind: 0, source: chunk.source });
99238
+ }
99239
+ }
99240
+ function updateChunks(core, dt) {
99241
+ const confiner = core.confiner;
99242
+ const confining = !confiner.empty;
99243
+ const chunks = core.chunks.items;
99244
+ for (let index = 0; index < chunks.length; index++) {
99245
+ const chunk = chunks[index];
99246
+ chunk.t += dt;
99247
+ if (chunk.rest) continue;
99248
+ MOVE2.x0 = chunk.x;
99249
+ MOVE2.y0 = chunk.y;
99250
+ MOVE2.z0 = chunk.z;
99251
+ chunk.vy -= core.gravity * dt;
99252
+ chunk.x += chunk.vx * dt;
99253
+ chunk.y += chunk.vy * dt;
99254
+ chunk.z += chunk.vz * dt;
99255
+ chunk.rx += chunk.ax * dt;
99256
+ chunk.ry += chunk.ay * dt;
99257
+ chunk.rz += chunk.az * dt;
99258
+ if (confining) {
99259
+ MOVE2.x1 = chunk.x;
99260
+ MOVE2.y1 = chunk.y;
99261
+ MOVE2.z1 = chunk.z;
99262
+ MOVE2.pad = chunkPad(chunk);
99263
+ if (confiner.confineMove(MOVE2, dt)) hitFace(chunk, confiner.out);
99264
+ }
99265
+ const floor2 = chunk.sy * 0.45 + core.groundAt(chunk.x, chunk.z);
99266
+ if (chunk.y < floor2) bounce2(core, chunk, floor2);
99267
+ if (chunk.hot && chunk.t < TRAIL_SECONDS && core.layers.smoke) leaveTrail(core, chunk, dt);
99268
+ }
99269
+ }
98610
99270
  function createRingPool(capacity) {
98611
99271
  return new OrderedPool(capacity, () => ({ x: 0, z: 0, y0: 0, rise: 0, rk: 0, R0: 0, R1: 0, r: 0, roll: 0, t: 0, life: 0 }));
98612
99272
  }
@@ -98736,6 +99396,18 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
98736
99396
  puff3.z = out.z;
98737
99397
  slideInto(out, puff3);
98738
99398
  }
99399
+ function chunkBornFrom(core, chunk, ox, oy, oz) {
99400
+ const confiner = core.confiner;
99401
+ if (confiner.empty) return;
99402
+ BIRTH.x0 = ox;
99403
+ BIRTH.y0 = oy;
99404
+ BIRTH.z0 = oz;
99405
+ BIRTH.x1 = chunk.x;
99406
+ BIRTH.y1 = chunk.y;
99407
+ BIRTH.z1 = chunk.z;
99408
+ BIRTH.pad = chunkPad(chunk);
99409
+ if (confiner.confineMove(BIRTH, 0)) hitFace(chunk, confiner.out);
99410
+ }
98739
99411
  function composeFireballs(context) {
98740
99412
  const { core, def, random, x, y, z, size, scale, direction } = context;
98741
99413
  if (!core.layers.fire || !def.fireballs) return;
@@ -98816,7 +99488,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
98816
99488
  spawnShock(core.shocks, spec);
98817
99489
  }
98818
99490
  function composeDust(context) {
98819
- const { core, def, random, x, z, size, scale } = context;
99491
+ const { core, def, random, x, y, z, size, scale } = context;
98820
99492
  if (!core.layers.smoke || !def.dust.count || !(scale > 0.15)) return;
98821
99493
  const count = Math.round(def.dust.count * scale);
98822
99494
  const color2 = hexToLinearRgb(def.dust.color);
@@ -98846,7 +99518,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
98846
99518
  color: color2,
98847
99519
  kind: 1
98848
99520
  });
98849
- bornFrom(core, dust, x, 0.15, z);
99521
+ bornFrom(core, dust, x, y, z);
98850
99522
  }
98851
99523
  }
98852
99524
  function coneAngle(context) {
@@ -98920,7 +99592,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
98920
99592
  const sy = plate2 ? s * 0.3 : s * random.between(0.6, 1);
98921
99593
  const color2 = hexToRgb2(chunks.colors.length > 0 ? pick22(random, chunks.colors) : DEFAULT_CHUNK_COLOR);
98922
99594
  const hot = random.next() < chunks.hot;
98923
- addChunk(core, random, {
99595
+ const chunk = addChunk(core, random, {
98924
99596
  x: x + d.x * 0.2,
98925
99597
  y: y + 0.2,
98926
99598
  z: z + d.z * 0.2,
@@ -98934,10 +99606,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
98934
99606
  plate: plate2,
98935
99607
  hot
98936
99608
  });
99609
+ chunkBornFrom(core, chunk, x, y, z);
98937
99610
  }
98938
99611
  }
98939
99612
  function composeRimDebris(context) {
98940
- const { core, random, x, z } = context;
99613
+ const { core, random, x, y, z } = context;
98941
99614
  const radius = context.def.mark.crater ?? 0;
98942
99615
  if (!core.layers.shrapnel) return;
98943
99616
  const speedScale = context.def.chunks.speed ?? 1;
@@ -98948,7 +99621,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
98948
99621
  const s = random.between(0.12, 0.28);
98949
99622
  const vy2 = random.between(4, 10);
98950
99623
  const color2 = hexToRgb2(random.next() < 0.6 ? ROCK_COLORS[0] : ROCK_COLORS[1]);
98951
- addChunk(core, random, {
99624
+ const chunk = addChunk(core, random, {
98952
99625
  x: x + Math.cos(angle) * 0.3,
98953
99626
  y: 0.1,
98954
99627
  z: z + Math.sin(angle) * 0.3,
@@ -98961,6 +99634,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
98961
99634
  color: color2,
98962
99635
  plate: true
98963
99636
  });
99637
+ chunkBornFrom(core, chunk, x, y, z);
98964
99638
  }
98965
99639
  }
98966
99640
  function composeMushroom(context, spec) {
@@ -99091,71 +99765,6 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
99091
99765
  emitRequests(context);
99092
99766
  return scale;
99093
99767
  }
99094
- var RESTITUTION = -0.32;
99095
- var GROUND_FRICTION = 0.5;
99096
- var REST_SPEED = 0.6;
99097
- var REST_SLIDE = 0.5;
99098
- var TRAIL_SECONDS = 1.8;
99099
- var TRAIL_STEP = 0.025;
99100
- var QUARTER_TURN3 = Math.PI / 2;
99101
- function bounce2(core, chunk, floor2) {
99102
- chunk.y = floor2;
99103
- if (chunk.blood && !chunk.splat && core.layers.mark) {
99104
- chunk.splat = true;
99105
- addBloodSplat(core.marks, core.ground, chunk.rng, { x: chunk.x, z: chunk.z, radius: chunk.rng.between(0.06, 0.13) });
99106
- }
99107
- chunk.vy *= RESTITUTION;
99108
- chunk.vx *= GROUND_FRICTION;
99109
- chunk.vz *= GROUND_FRICTION;
99110
- chunk.ax *= GROUND_FRICTION;
99111
- chunk.ay *= GROUND_FRICTION;
99112
- chunk.az *= GROUND_FRICTION;
99113
- if (Math.abs(chunk.vy) < REST_SPEED && Math.hypot(chunk.vx, chunk.vz) < REST_SLIDE) {
99114
- chunk.rest = true;
99115
- chunk.rx = Math.round(chunk.rx / QUARTER_TURN3) * QUARTER_TURN3;
99116
- chunk.rz = Math.round(chunk.rz / QUARTER_TURN3) * QUARTER_TURN3;
99117
- }
99118
- }
99119
- function leaveTrail(core, chunk, dt) {
99120
- chunk.trail -= dt;
99121
- if (chunk.trail > 0) return;
99122
- chunk.trail = TRAIL_STEP;
99123
- const random = chunk.rng;
99124
- addSpark(core, {
99125
- x: chunk.x,
99126
- y: chunk.y,
99127
- z: chunk.z,
99128
- vx: chunk.vx * 0.15,
99129
- vy: chunk.vy * 0.15,
99130
- vz: chunk.vz * 0.15,
99131
- life: random.between(0.25, 0.45),
99132
- w: 0.05 + chunk.sx * 0.2,
99133
- st: 0.05,
99134
- kind: 0,
99135
- g: 0,
99136
- drag: 1,
99137
- source: chunk.source
99138
- });
99139
- if (random.next() < 0.25) {
99140
- addPuff(core, random, { x: chunk.x, y: chunk.y, z: chunk.z, s0: 0.04, s1: 0.14 + chunk.sx * 0.3, sg: 0.15, life: random.between(1, 1.6), drag: 2, buoy: 0.6, color: SMOKE_COLORS.grey, kind: 0, source: chunk.source });
99141
- }
99142
- }
99143
- function updateChunks(core, dt) {
99144
- for (const chunk of core.chunks.items) {
99145
- chunk.t += dt;
99146
- if (chunk.rest) continue;
99147
- chunk.vy -= core.gravity * dt;
99148
- chunk.x += chunk.vx * dt;
99149
- chunk.y += chunk.vy * dt;
99150
- chunk.z += chunk.vz * dt;
99151
- chunk.rx += chunk.ax * dt;
99152
- chunk.ry += chunk.ay * dt;
99153
- chunk.rz += chunk.az * dt;
99154
- const floor2 = chunk.sy * 0.45 + core.groundAt(chunk.x, chunk.z);
99155
- if (chunk.y < floor2) bounce2(core, chunk, floor2);
99156
- if (chunk.hot && chunk.t < TRAIL_SECONDS && core.layers.smoke) leaveTrail(core, chunk, dt);
99157
- }
99158
- }
99159
99768
  var DECAY = { shake: 5, white: 7, red: 2.2, side: 3, chroma: 3, desat: 0.7, gasSeconds: 5, beat: 6 };
99160
99769
  var INITIAL_FLASH_DECAY = 6;
99161
99770
  function createScreenState() {
@@ -99177,6 +99786,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
99177
99786
  state.beat *= Math.exp(-DECAY.beat * dt);
99178
99787
  }
99179
99788
  var PAD_OF_SIZE2 = 0.35;
99789
+ var STEP = { x0: 0.5, y0: 0.5, z0: 0.5, x1: 0.5, y1: 0.5, z1: 0.5, pad: 0.5 };
99790
+ var GROUND_RESAMPLE = 0.1;
99791
+ var VELOCITY2 = { vx: 0.5, vy: 0.5, vz: 0.5 };
99180
99792
  var clamp42 = (v, lo, hi) => v < lo ? lo : v > hi ? hi : v;
99181
99793
  var lerp4 = (a, b, t) => a + (b - a) * t;
99182
99794
  function rgb(hex2) {
@@ -99223,6 +99835,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
99223
99835
  __publicField3(this, "bounced");
99224
99836
  __publicField3(this, "floor");
99225
99837
  __publicField3(this, "riseMul");
99838
+ __publicField3(this, "ground");
99226
99839
  const n = Math.max(1, capacity);
99227
99840
  this.position = new Float32Array(n * 3);
99228
99841
  this.color = new Float32Array(n * 3);
@@ -99245,6 +99858,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
99245
99858
  this.bounced = new Uint8Array(n);
99246
99859
  this.floor = new Float32Array(n);
99247
99860
  this.riseMul = new Float32Array(n);
99861
+ this.ground = new Float32Array(n * 3);
99248
99862
  }
99249
99863
  spawn(kind, p, v, random, options) {
99250
99864
  if (this.capacity <= 0) return;
@@ -99272,6 +99886,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
99272
99886
  this.bounced[i] = 0;
99273
99887
  this.floor[i] = options?.floor ?? Number.NaN;
99274
99888
  this.riseMul[i] = options?.rise ?? 1;
99889
+ this.ground[i * 3] = Number.NaN;
99275
99890
  this.size[i] = this.size0[i];
99276
99891
  this.alpha[i] = 0;
99277
99892
  }
@@ -99365,18 +99980,36 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
99365
99980
  let z = this.position[i3 + 2] + vz2 * dt;
99366
99981
  const confiner = host.confiner;
99367
99982
  if (def.carried && confiner && !confiner.empty) {
99368
- const pad = this.size0[i] * lerp4(1, def.grow, t) * PAD_OF_SIZE2;
99369
- if (confiner.confine(this.position[i3], this.position[i3 + 1], this.position[i3 + 2], x, y, z, pad, dt)) {
99983
+ STEP.x0 = this.position[i3];
99984
+ STEP.y0 = this.position[i3 + 1];
99985
+ STEP.z0 = this.position[i3 + 2];
99986
+ STEP.x1 = x;
99987
+ STEP.y1 = y;
99988
+ STEP.z1 = z;
99989
+ STEP.pad = this.size0[i] * (1 + (def.grow - 1) * t) * PAD_OF_SIZE2;
99990
+ if (confiner.confineMove(STEP, dt)) {
99370
99991
  const out = confiner.out;
99371
99992
  x = out.x;
99372
99993
  y = out.y;
99373
99994
  z = out.z;
99374
- [vx2, vy2, vz2] = slideAlong(out, vx2, vy2, vz2);
99995
+ VELOCITY2.vx = vx2;
99996
+ VELOCITY2.vy = vy2;
99997
+ VELOCITY2.vz = vz2;
99998
+ slideInto(out, VELOCITY2);
99999
+ vx2 = VELOCITY2.vx;
100000
+ vy2 = VELOCITY2.vy;
100001
+ vz2 = VELOCITY2.vz;
99375
100002
  }
99376
100003
  }
99377
100004
  if (def.ground !== "none") {
99378
100005
  const own = this.floor[i];
99379
- const gy = Number.isNaN(own) ? host.groundAt(x, z) + 5e-3 : own;
100006
+ const ground = this.ground;
100007
+ if (Number.isNaN(own) && !(Math.abs(x - ground[i3]) < GROUND_RESAMPLE && Math.abs(z - ground[i3 + 1]) < GROUND_RESAMPLE)) {
100008
+ ground[i3] = x;
100009
+ ground[i3 + 1] = z;
100010
+ ground[i3 + 2] = host.groundAt(x, z);
100011
+ }
100012
+ const gy = Number.isNaN(own) ? ground[i3 + 2] + 5e-3 : own;
99380
100013
  if (y < gy) {
99381
100014
  if (def.ground === "land") {
99382
100015
  const tag = this.tag[i];
@@ -100222,10 +100855,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
100222
100855
  if (particle.fade) particle.opacity = Math.max(0, particle.startOpacity * (1 - particle.age / particle.life));
100223
100856
  particle.vy -= particle.gravity * dt;
100224
100857
  if (particle.drag) {
100225
- const keep = Math.max(0, 1 - particle.drag * dt);
100226
- particle.vx *= keep;
100227
- particle.vy *= keep;
100228
- particle.vz *= keep;
100858
+ const keep2 = Math.max(0, 1 - particle.drag * dt);
100859
+ particle.vx *= keep2;
100860
+ particle.vy *= keep2;
100861
+ particle.vz *= keep2;
100229
100862
  }
100230
100863
  if (particle.carried) this.ride(particle, dt);
100231
100864
  else {
@@ -100388,10 +101021,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
100388
101021
  const offset = index * FLOATS_PER_VECTOR;
100389
101022
  const age = 1 - this.life[index] / this.maxLife[index];
100390
101023
  velocity2[offset + 1] -= this.gravity[index] * dt;
100391
- const factor = Math.max(0, 1 - this.drag[index] * dt);
100392
- velocity2[offset] *= factor;
100393
- velocity2[offset + 1] *= factor;
100394
- velocity2[offset + 2] *= factor;
101024
+ const factor2 = Math.max(0, 1 - this.drag[index] * dt);
101025
+ velocity2[offset] *= factor2;
101026
+ velocity2[offset + 1] *= factor2;
101027
+ velocity2[offset + 2] *= factor2;
100395
101028
  const x0 = position[offset];
100396
101029
  const y0 = position[offset + 1];
100397
101030
  const z0 = position[offset + 2];
@@ -100539,10 +101172,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
100539
101172
  const offset = index * FLOATS_PER_VECTOR2;
100540
101173
  const age = 1 - this.life[index] / this.maxLife[index];
100541
101174
  velocity2[offset + 1] -= this.gravity[index] * dt;
100542
- const factor = Math.max(0, 1 - this.drag[index] * dt);
100543
- velocity2[offset] *= factor;
100544
- velocity2[offset + 1] *= factor;
100545
- velocity2[offset + 2] *= factor;
101175
+ const factor2 = Math.max(0, 1 - this.drag[index] * dt);
101176
+ velocity2[offset] *= factor2;
101177
+ velocity2[offset + 1] *= factor2;
101178
+ velocity2[offset + 2] *= factor2;
100546
101179
  point[offset] += velocity2[offset] * dt;
100547
101180
  point[offset + 1] += velocity2[offset + 1] * dt;
100548
101181
  point[offset + 2] += velocity2[offset + 2] * dt;
@@ -100878,16 +101511,16 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
100878
101511
  if (profile === void 0) return PROFILES.medium;
100879
101512
  return typeof profile === "string" ? PROFILES[profile] : profile;
100880
101513
  }
100881
- function scaleDefinition(def, factor) {
100882
- if (factor === 1) return def;
100883
- const mushroom = def.mushroom && { ...def.mushroom, height: def.mushroom.height * factor, radius: def.mushroom.radius * factor };
100884
- const residual = def.residualFires?.map((fire) => ({ ...fire, radius: fire.radius * factor, dx: (fire.dx ?? 0) * factor, dz: (fire.dz ?? 0) * factor }));
101514
+ function scaleDefinition(def, factor2) {
101515
+ if (factor2 === 1) return def;
101516
+ const mushroom = def.mushroom && { ...def.mushroom, height: def.mushroom.height * factor2, radius: def.mushroom.radius * factor2 };
101517
+ const residual = def.residualFires?.map((fire) => ({ ...fire, radius: fire.radius * factor2, dx: (fire.dx ?? 0) * factor2, dz: (fire.dz ?? 0) * factor2 }));
100885
101518
  return {
100886
101519
  ...def,
100887
- lethal: def.lethal * factor,
100888
- injury: def.injury * factor,
100889
- visualRadius: def.visualRadius * factor,
100890
- mark: { scorch: def.mark.scorch && def.mark.scorch * factor, crater: def.mark.crater && def.mark.crater * factor, dent: def.mark.dent && def.mark.dent * factor },
101520
+ lethal: def.lethal * factor2,
101521
+ injury: def.injury * factor2,
101522
+ visualRadius: def.visualRadius * factor2,
101523
+ mark: { scorch: def.mark.scorch && def.mark.scorch * factor2, crater: def.mark.crater && def.mark.crater * factor2, dent: def.mark.dent && def.mark.dent * factor2 },
100891
101524
  ...mushroom ? { mushroom } : {},
100892
101525
  ...residual ? { residualFires: residual } : {}
100893
101526
  };
@@ -101069,10 +101702,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
101069
101702
  for (let index = fires.items.length - 1; index >= 0; index--) if (fires.items[index].handle === handle) fires.removeAt(index);
101070
101703
  },
101071
101704
  clearSource(source) {
101072
- const keep = (record, gone) => record.source !== gone;
101705
+ const keep2 = (record, gone) => record.source !== gone;
101073
101706
  const drop = (pool) => {
101074
101707
  const before = pool.count;
101075
- pool.compact(keep, source);
101708
+ pool.compact(keep2, source);
101076
101709
  return before - pool.count;
101077
101710
  };
101078
101711
  return drop(core.fires) + drop(core.puffs) + drop(core.sparks) + drop(core.chunks) + drop(core.glows) + spriteSystem.clearSource(source);
@@ -101169,7 +101802,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
101169
101802
  }
101170
101803
  var DEGREES = 180 / Math.PI;
101171
101804
 
101172
- // ../game-vfx-three/dist/chunk-KIZDMENO.js
101805
+ // ../game-vfx-three/dist/chunk-JM23474M.js
101173
101806
  var GLOW_VERTEX = `attribute vec4 aP;attribute vec4 aC;varying vec2 vU;varying vec4 vC;
101174
101807
  void main(){vec3 R=vec3(viewMatrix[0][0],viewMatrix[1][0],viewMatrix[2][0]);vec3 Up=vec3(viewMatrix[0][1],viewMatrix[1][1],viewMatrix[2][1]);
101175
101808
  vec3 wp=aP.xyz+(R*position.x+Up*position.y)*aP.w;vU=position.xy;vC=aC;gl_Position=projectionMatrix*viewMatrix*vec4(wp,1.);}`;
@@ -101183,23 +101816,24 @@ float vn(vec3 x){vec3 i=floor(x),f=fract(x);f=f*f*(3.-2.*f);
101183
101816
  return mix(mix(mix(h3(i),h3(i+vec3(1,0,0)),f.x),mix(h3(i+vec3(0,1,0)),h3(i+vec3(1,1,0)),f.x),f.y),
101184
101817
  mix(mix(h3(i+vec3(0,0,1)),h3(i+vec3(1,0,1)),f.x),mix(h3(i+vec3(0,1,1)),h3(i+vec3(1,1,1)),f.x),f.y),f.z);}
101185
101818
  `;
101819
+ var PUFF_BASE = (PUFF_REACH - 0.5).toFixed(2);
101186
101820
  var PUFF_VERTEX = `${GL_NOISE}
101187
- attribute vec4 aP;attribute vec4 aD;attribute vec3 aC;
101821
+ attribute vec4 aP;attribute vec4 aD;attribute vec3 aC;attribute vec4 aK;attribute vec4 aK2;varying vec4 vK;varying vec4 vK2;
101188
101822
  varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;
101189
101823
  void main(){
101190
101824
  vec3 p=position;
101191
101825
  float s=aD.z;
101192
101826
  float n=vn(p*1.6+vec3(s*11.0,s*7.0,s*3.0));
101193
- p*=0.78+0.5*n;
101827
+ p*=${PUFF_BASE}+0.5*n;
101194
101828
  float a=s*6.2831;float c=cos(a),si=sin(a);p.xz=mat2(c,-si,si,c)*p.xz;
101195
101829
  vL=p;
101196
101830
  vec3 wp=aP.xyz+p*aP.w;
101197
- vWP=wp;vD=aD;vC=aC;
101831
+ vWP=wp;vD=aD;vC=aC;vK=aK;vK2=aK2;
101198
101832
  gl_Position=projectionMatrix*viewMatrix*vec4(wp,1.0);
101199
101833
  }`;
101200
101834
  var PUFF_FRAGMENT = `${GL_NOISE}
101201
101835
  uniform vec3 uLight;uniform vec3 uSky;uniform vec3 uGround;uniform vec3 uGlowPos;uniform vec3 uGlowCol;uniform float uGlowI;
101202
- varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;
101836
+ varying vec4 vK;varying vec4 vK2;varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;
101203
101837
  vec3 L(vec3 c){return pow(c,vec3(2.2));}
101204
101838
  vec3 ramp(float h){
101205
101839
  vec3 c0=L(vec3(.36,.07,.03)),c1=L(vec3(.76,.21,.1)),c2=L(vec3(1.,.54,.16)),c3=L(vec3(1.,.83,.42)),c4=L(vec3(1.,.96,.84));
@@ -101209,6 +101843,8 @@ vec3 ramp(float h){
101209
101843
  return mix(c3,c4,clamp((h-.8)/.4,0.,1.));
101210
101844
  }
101211
101845
  void main(){
101846
+ // cut at the face of a wall within reach (Puff.cuts): smoke flattens on the wall, it does not show through on its other side
101847
+ if(dot(vWP,vK.xyz)<vK.w||dot(vWP,vK2.xyz)<vK2.w)discard;
101212
101848
  vec3 N=normalize(cross(dFdx(vWP),dFdy(vWP)));
101213
101849
  float age=vD.x,heat=vD.y,kind=vD.w;
101214
101850
  float n=vn(vL*2.4+vD.z*13.0);
@@ -101237,23 +101873,23 @@ void main(){
101237
101873
  #include <colorspace_fragment>
101238
101874
  }`;
101239
101875
  var SOFT_PUFF_VERTEX = `${GL_NOISE}
101240
- attribute vec4 aP;attribute vec4 aD;attribute vec3 aC;
101876
+ attribute vec4 aP;attribute vec4 aD;attribute vec3 aC;attribute vec4 aK;attribute vec4 aK2;varying vec4 vK;varying vec4 vK2;
101241
101877
  varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;varying vec3 vN;
101242
101878
  void main(){
101243
101879
  vec3 p=position;
101244
101880
  vec3 q=normalize(position);
101245
101881
  float s=aD.z;
101246
101882
  float n=vn(p*1.6+vec3(s*11.0,s*7.0,s*3.0));
101247
- p*=0.78+0.5*n;
101883
+ p*=${PUFF_BASE}+0.5*n;
101248
101884
  float a=s*6.2831;float c=cos(a),si=sin(a);p.xz=mat2(c,-si,si,c)*p.xz;q.xz=mat2(c,-si,si,c)*q.xz;
101249
101885
  vL=p;vN=q;
101250
101886
  vec3 wp=aP.xyz+p*aP.w;
101251
- vWP=wp;vD=aD;vC=aC;
101887
+ vWP=wp;vD=aD;vC=aC;vK=aK;vK2=aK2;
101252
101888
  gl_Position=projectionMatrix*viewMatrix*vec4(wp,1.0);
101253
101889
  }`;
101254
101890
  var SOFT_PUFF_FRAGMENT = `${GL_NOISE}
101255
101891
  uniform vec3 uLight;uniform vec3 uSky;uniform vec3 uGround;uniform vec3 uGlowPos;uniform vec3 uGlowCol;uniform float uGlowI;
101256
- varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;varying vec3 vN;
101892
+ varying vec4 vK;varying vec4 vK2;varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;varying vec3 vN;
101257
101893
  vec3 L(vec3 c){return pow(c,vec3(2.2));}
101258
101894
  vec3 ramp(float h){
101259
101895
  vec3 c0=L(vec3(.36,.07,.03)),c1=L(vec3(.76,.21,.1)),c2=L(vec3(1.,.54,.16)),c3=L(vec3(1.,.83,.42)),c4=L(vec3(1.,.96,.84));
@@ -101263,6 +101899,8 @@ vec3 ramp(float h){
101263
101899
  return mix(c3,c4,clamp((h-.8)/.4,0.,1.));
101264
101900
  }
101265
101901
  void main(){
101902
+ // cut at the face of a wall within reach (Puff.cuts): smoke flattens on the wall, it does not show through on its other side
101903
+ if(dot(vWP,vK.xyz)<vK.w||dot(vWP,vK2.xyz)<vK2.w)discard;
101266
101904
  float age=vD.x,heat=vD.y,kind=vD.w;
101267
101905
  float n=vn(vL*2.4+vD.z*13.0);
101268
101906
  // the sphere's own normal, roughened by the noise: a billowing cloud, never facets
@@ -101326,6 +101964,13 @@ void main(){
101326
101964
  function dynamic(THREE, array, size) {
101327
101965
  return new THREE.InstancedBufferAttribute(array, size).setUsage(THREE.DynamicDrawUsage);
101328
101966
  }
101967
+ var NO_CUT = -1e9;
101968
+ function writeCut(into, n, cut) {
101969
+ into[n * 4] = cut.on ? cut.nx : 0;
101970
+ into[n * 4 + 1] = cut.on ? cut.ny : 0;
101971
+ into[n * 4 + 2] = cut.on ? cut.nz : 0;
101972
+ into[n * 4 + 3] = cut.on ? cut.d : NO_CUT;
101973
+ }
101329
101974
  var PUFF_DETAIL = { faceted: 1, soft: 2 };
101330
101975
  function createPuffLayer(THREE, pool, uniforms, style = "faceted") {
101331
101976
  const capacity = pool.capacity;
@@ -101334,10 +101979,14 @@ void main(){
101334
101979
  const a = new Float32Array(capacity * 4);
101335
101980
  const d = new Float32Array(capacity * 4);
101336
101981
  const c = new Float32Array(capacity * 3);
101337
- const attributes = [dynamic(THREE, a, 4), dynamic(THREE, d, 4), dynamic(THREE, c, 3)];
101982
+ const k = new Float32Array(capacity * 4);
101983
+ const k2 = new Float32Array(capacity * 4);
101984
+ const attributes = [dynamic(THREE, a, 4), dynamic(THREE, d, 4), dynamic(THREE, c, 3), dynamic(THREE, k, 4), dynamic(THREE, k2, 4)];
101338
101985
  geometry.setAttribute("aP", attributes[0]);
101339
101986
  geometry.setAttribute("aD", attributes[1]);
101340
101987
  geometry.setAttribute("aC", attributes[2]);
101988
+ geometry.setAttribute("aK", attributes[3]);
101989
+ geometry.setAttribute("aK2", attributes[4]);
101341
101990
  geometry.instanceCount = 0;
101342
101991
  const material = style === "faceted" ? new THREE.ShaderMaterial({ uniforms, vertexShader: PUFF_VERTEX, fragmentShader: PUFF_FRAGMENT }) : new THREE.ShaderMaterial({ uniforms, vertexShader: SOFT_PUFF_VERTEX, fragmentShader: SOFT_PUFF_FRAGMENT, transparent: true, depthWrite: false });
101343
101992
  const mesh3 = new THREE.Mesh(geometry, material);
@@ -101359,6 +102008,8 @@ void main(){
101359
102008
  c[n * 3] = p.color[0];
101360
102009
  c[n * 3 + 1] = p.color[1];
101361
102010
  c[n * 3 + 2] = p.color[2];
102011
+ writeCut(k, n, p.cuts[0]);
102012
+ writeCut(k2, n, p.cuts[1]);
101362
102013
  n++;
101363
102014
  }
101364
102015
  geometry.instanceCount = n;
@@ -104290,7 +104941,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
104290
104941
  if (oneHand) placeOnBody({ THREE, hand, holder, frame: options.bodyHold?.() ?? eyeFrame(), rear: modelRear, lengthMetres: session.lengthMetres, handgun: true, right: heldAnchor(held), left: null, grip: BODY_HOLD.dualGrip, ...side === "L" ? { mirror: true } : {} });
104291
104942
  else placeOnBody({ THREE, hand, holder, frame: options.bodyHold?.() ?? eyeFrame(), rear: modelRear, lengthMetres: session.lengthMetres, handgun: family === "pistol" || family === "revolver", hip: session.model.parts.carry === "hip", right: hold?.right ?? null, left: hold?.left ?? null });
104292
104943
  hand.updateMatrixWorld(true);
104293
- lift += (liftToKeepInView() - lift) * Math.min(1, dt * HAND_IN_VIEW.rate);
104944
+ lift += ((options.bodyHold?.() ? 0 : liftToKeepInView()) - lift) * Math.min(1, dt * HAND_IN_VIEW.rate);
104294
104945
  if (lift > 1e-4) hand.position.addScaledVector(up.set(0, 1, 0).applyQuaternion(camera2.quaternion), lift);
104295
104946
  hand.updateMatrixWorld(true);
104296
104947
  pullFromWall(dt);
@@ -104425,9 +105076,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
104425
105076
  hand.updateMatrixWorld(true);
104426
105077
  const at4 = worldPositionOf(session, mark, muzzleAt);
104427
105078
  if (lens2) toWorldLens(camera2, at4, worldFovOf(), lens2.fov);
104428
- const along2 = muzzleAlong.set(1, 0, 0).applyQuaternion(session.model.root.getWorldQuaternion(rootQuaternion)).normalize();
105079
+ const along3 = muzzleAlong.set(1, 0, 0).applyQuaternion(session.model.root.getWorldQuaternion(rootQuaternion)).normalize();
104429
105080
  const kind = session.def.action.kind;
104430
- return { position: [at4.x, at4.y, at4.z], direction: [along2.x, along2.y, along2.z], drawsFlash: kind === "firearm" || kind === "launcher" };
105081
+ return { position: [at4.x, at4.y, at4.z], direction: [along3.x, along3.y, along3.z], drawsFlash: kind === "firearm" || kind === "launcher" };
104431
105082
  },
104432
105083
  handTargets() {
104433
105084
  const held = heldHold();
@@ -107226,7 +107877,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
107226
107877
  origin.set(body.objectId, body.from);
107227
107878
  }
107228
107879
  const partsBefore = new Map(placed.map((body) => [body.objectId, partsOf(body.objectId)]));
107229
- const partPlaces = (objectId, keep = () => true) => (room.world.state(objectId)?.parts ?? []).filter(keep).map((part) => [part, { mass: part.mass, boxes: room.renderer.shownBoxes?.(objectId, part.id) ?? [] }]);
107880
+ const partPlaces = (objectId, keep2 = () => true) => (room.world.state(objectId)?.parts ?? []).filter(keep2).map((part) => [part, { mass: part.mass, boxes: room.renderer.shownBoxes?.(objectId, part.id) ?? [] }]);
107230
107881
  const heavyBefore = new Map(placed.filter((body) => HEAVY_ITEMS.includes(body.kind)).map((body) => [body.objectId, new Map(partPlaces(body.objectId))]));
107231
107882
  const heavyShift = (objectId) => {
107232
107883
  const before = heavyBefore.get(objectId);