@adatechnology/game-items-three 0.7.9 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1785,9 +1785,9 @@ var GameItemsThree = (() => {
1785
1785
  }
1786
1786
  return points;
1787
1787
  }
1788
- function extrudeOf(shapes, options = {}) {
1789
- if (Array.isArray(shapes) || !shapes || options.extrudePath !== void 0 || options.UVGenerator !== void 0) return null;
1790
- const shape = shapes;
1788
+ function extrudeOf(shapes2, options = {}) {
1789
+ if (Array.isArray(shapes2) || !shapes2 || options.extrudePath !== void 0 || options.UVGenerator !== void 0) return null;
1790
+ const shape = shapes2;
1791
1791
  const outer = linePoints(shape);
1792
1792
  if (!outer) return null;
1793
1793
  const holes = [];
@@ -1835,11 +1835,11 @@ var GameItemsThree = (() => {
1835
1835
  return made(viaCache({ kind: "lathe", points: profile, ...defined({ segments, phiStart, phiLength }) }, () => lathe(profile, segments, phiStart, phiLength)));
1836
1836
  },
1837
1837
  TorusGeometry: (radius, tube2, radialSegments, tubularSegments, arc) => made(viaCache({ kind: "torus", ...defined({ radius, tube: tube2, radialSegments, tubularSegments, arc }) }, () => torus(radius, tube2, radialSegments, tubularSegments, arc))),
1838
- ExtrudeGeometry: (shapes, extrudeOptions) => {
1839
- const buffers = shapes === void 0 ? null : extrudeOf(shapes, extrudeOptions);
1840
- if (!buffers) return new THREE.ExtrudeGeometry(shapes, extrudeOptions);
1838
+ ExtrudeGeometry: (shapes2, extrudeOptions) => {
1839
+ const buffers = shapes2 === void 0 ? null : extrudeOf(shapes2, extrudeOptions);
1840
+ if (!buffers) return new THREE.ExtrudeGeometry(shapes2, extrudeOptions);
1841
1841
  const geometry = toGeometry(THREE, buffers);
1842
- geometry.parameters = { shapes, options: extrudeOptions ?? {} };
1842
+ geometry.parameters = { shapes: shapes2, options: extrudeOptions ?? {} };
1843
1843
  return geometry;
1844
1844
  }
1845
1845
  };
@@ -1936,6 +1936,10 @@ var GameItemsThree = (() => {
1936
1936
  return { geometries, materials, textures, skeletons };
1937
1937
  }
1938
1938
  var marked = /* @__PURE__ */ new WeakSet();
1939
+ function markShared(...resources) {
1940
+ for (const resource of resources) marked.add(resource);
1941
+ return resources;
1942
+ }
1939
1943
  var shared = (r) => r.userData?.shared === true || marked.has(r);
1940
1944
  function releaseObject3D(roots, options = {}) {
1941
1945
  const list2 = Array.isArray(roots) ? roots : [roots];
@@ -3431,11 +3435,11 @@ var GameItemsThree = (() => {
3431
3435
  id: "crowbar",
3432
3436
  teamId: "pe_cabra",
3433
3437
  teamBox: [
3434
- 0.428,
3435
- 1.7087,
3436
- 0.11
3438
+ 0.3559,
3439
+ 1.6698,
3440
+ 0.068
3437
3441
  ],
3438
- scale: 0.43893
3442
+ scale: 0.449156
3439
3443
  },
3440
3444
  {
3441
3445
  id: "hammer",
@@ -6003,9 +6007,34 @@ var GameItemsThree = (() => {
6003
6007
  var amoxicillin = ({ T: T2, mesh: mesh2, bx, G, metal, plastic, paper: paper2 }) => G(mesh2(bx(0.8, 0.42, 0.24), paper2(15789798)), mesh2(bx(0.81, 0.1, 0.25), plastic(5141127), [0, 0.1, 0]), mesh2(bx(0.6, 0.04, 0.3), metal(12172736), [0.15, -0.24, 0.25], [0, 0.3, 0]), ...[0, 1, 2, 3].map((k) => mesh2(new T2.SphereGeometry(0.05, 10, 8), plastic(14263361), [-0.05 + k * 0.14, -0.21, 0.3], [0, 0, 0], [1, 0.6, 1])));
6004
6008
 
6005
6009
  // src/models/crowbar.ts
6006
- var crowbar = ({ T: T2, mesh: mesh2, cyl, G, metal }) => {
6007
- const c = new T2.CatmullRomCurve3([[0, -0.8, 0], [0, 0.45, 0], [0.02, 0.62, 0], [0.12, 0.72, 0], [0.26, 0.7, 0], [0.32, 0.6, 0]].map((p) => new T2.Vector3(...p)));
6008
- return G(mesh2(new T2.TubeGeometry(c, 30, 0.055, 8), metal(10168863)), mesh2(cyl(0.02, 0.055, 0.14, 8), metal(3816510), [0, -0.86, 0]));
6010
+ var CURVE = [[0, -0.8, 0], [0, 0.5, 0], [0.012, 0.625, 0], [0.06, 0.7, 0], [0.12, 0.715, 0], [0.19, 0.685, 0], [0.26, 0.63, 0]];
6011
+ var BAR_RADIUS = 0.026;
6012
+ var CHISEL = [[-0.024, -0.79], [0.024, -0.79], [0.016, -0.86], [4e-3, -0.928], [-8e-3, -0.928], [-0.022, -0.86]];
6013
+ var CHISEL_WIDTH = 0.06;
6014
+ var shapes = /* @__PURE__ */ new WeakMap();
6015
+ var shapesOf = (T2, extrude2) => {
6016
+ const cached = shapes.get(T2);
6017
+ if (cached) return cached;
6018
+ const curve = new T2.CatmullRomCurve3(CURVE.map((point) => new T2.Vector3(...point)));
6019
+ const bar2 = new T2.TubeGeometry(curve, 30, BAR_RADIUS, 6);
6020
+ const chisel = extrude2(CHISEL, CHISEL_WIDTH, 4e-3);
6021
+ chisel.translate(0, 0, -CHISEL_WIDTH / 2);
6022
+ markShared(bar2);
6023
+ markShared(chisel);
6024
+ const made = { bar: bar2, chisel };
6025
+ shapes.set(T2, made);
6026
+ return made;
6027
+ };
6028
+ var crowbar = ({ T: T2, mesh: mesh2, bx, extrude: extrude2, G, metal }) => {
6029
+ const forged = metal(7764863);
6030
+ const steel = metal(9277844);
6031
+ const end = CURVE[CURVE.length - 1];
6032
+ const before = CURVE[CURVE.length - 2];
6033
+ const angle = Math.atan2(end[1] - before[1], end[0] - before[0]);
6034
+ const along = (distance2) => [end[0] + Math.cos(angle) * distance2, end[1] + Math.sin(angle) * distance2, 0];
6035
+ const prongs = [-1, 1].map((side) => mesh2(bx(0.1, 0.016, 0.022), steel, [...along(0.03)].map((value, index) => index === 2 ? side * 0.014 : value), [0, 0, angle]));
6036
+ const { bar: bar2, chisel } = shapesOf(T2, extrude2);
6037
+ return G(mesh2(bar2, forged), mesh2(chisel, steel), ...prongs);
6009
6038
  };
6010
6039
 
6011
6040
  // src/models/hammer.ts
@@ -14103,6 +14132,60 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
14103
14132
  const stable = converged && cholesky3(ev.Jt, [0, 0, 0]) !== null;
14104
14133
  return { s, a, b, stable, yielded: ev.yielded, bearing: capSum > 0 ? weight / capSum : Infinity, edge: ev.edge, residual: [ev.r[0], ev.r[1], ev.r[2]] };
14105
14134
  };
14135
+ var GROUND_LOSS_DEFAULTS = {
14136
+ footingDepth: 0.5,
14137
+ spread: 1,
14138
+ voidDepth: 0.05,
14139
+ maxSettlement: 0.05,
14140
+ crackDistortion: 1 / 300,
14141
+ damageDistortion: 1 / 150,
14142
+ distortionDamage: 0.3,
14143
+ bridgeSpanDepth: 10,
14144
+ beamRebarRatio: 4e-3
14145
+ };
14146
+ var DISTORTION_BASE = 1;
14147
+ var FOOTPRINT_STEP = 0.1;
14148
+ var FOOTPRINT_MAX_SAMPLES = 40;
14149
+ var resolveGroundLoss = (options = {}) => ({
14150
+ ...GROUND_LOSS_DEFAULTS,
14151
+ ...Object.fromEntries(Object.entries(options).filter(([, value]) => value !== void 0))
14152
+ });
14153
+ var bowlDepth = (loss, r) => r >= loss.radius ? 0 : loss.depth * (1 - (r / loss.radius) ** 2);
14154
+ var undercutAt = (loss, r, embed, spread2) => {
14155
+ if (loss.depth <= embed || loss.radius <= 0) return 0;
14156
+ const reach = Math.min(r, loss.radius);
14157
+ const cut = (t) => bowlDepth(loss, t) - Math.max(0, r - t) / spread2 - embed;
14158
+ const steepest = loss.radius * loss.radius / (2 * loss.depth * spread2);
14159
+ return Math.max(0, cut(reach), cut(Math.min(reach, steepest)), cut(0));
14160
+ };
14161
+ var longestRun = (flags) => {
14162
+ let best = null;
14163
+ let start = -1;
14164
+ for (let i = 0; i <= flags.length; i++) {
14165
+ if (i < flags.length && flags[i]) {
14166
+ if (start < 0) start = i;
14167
+ continue;
14168
+ }
14169
+ if (start >= 0 && (!best || i - start > best.end - best.start)) best = { start, end: i };
14170
+ start = -1;
14171
+ }
14172
+ return best;
14173
+ };
14174
+ var distortionOf = (drops, step) => {
14175
+ const span = Math.max(1, Math.round(DISTORTION_BASE / step));
14176
+ let value = 0;
14177
+ let at2 = 0;
14178
+ for (let i = 0; i < drops.length; i++) {
14179
+ const j = Math.min(drops.length - 1, i + span);
14180
+ if (j === i) continue;
14181
+ const beta = Math.abs(drops[j] - drops[i]) / Math.max((j - i) * step, DISTORTION_BASE);
14182
+ if (beta > value) {
14183
+ value = beta;
14184
+ at2 = (i + j) / 2;
14185
+ }
14186
+ }
14187
+ return { value, at: at2 };
14188
+ };
14106
14189
  var wind_terrain_default = [
14107
14190
  { id: "I", zg: 250, b: { A: 1.1, B: 1.11, C: 1.12 }, p: { A: 0.06, B: 0.065, C: 0.07 }, z0: 5e-3 },
14108
14191
  { id: "II", zg: 300, b: { A: 1, B: 1, C: 1 }, p: { A: 0.085, B: 0.09, C: 0.1 }, z0: 0.05 },
@@ -15904,6 +15987,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
15904
15987
  var EDGE_REACH = 1.5;
15905
15988
  var BAR_BOW = 0.08;
15906
15989
  var BULLET_JOINT_SPAN = 0.3;
15990
+ var SUBSIDE_MIN = 1e-3;
15991
+ var DISTORTION_GROWTH = 1.2;
15992
+ var MAX_SETTLEMENT_CRACKS = 4;
15993
+ var SETTLEMENT_CRACK_LENGTH = 0.3;
15994
+ var CRACKED_STIFFNESS = 0.4;
15907
15995
  var CUT_SLICE = 1;
15908
15996
  var cutFactorOf = (shape) => clamp2(Math.max(...shapeDims(shape)) / CUT_SLICE, 1, 50);
15909
15997
  var clamp2 = (v, a, b) => Math.max(a, Math.min(b, v));
@@ -16093,6 +16181,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
16093
16181
  dirty: false,
16094
16182
  maxStress: 0,
16095
16183
  collapsed: new Set(carry?.collapsed ?? []),
16184
+ unanchored: new Set(carry?.unanchored ?? []),
16096
16185
  unsup: [],
16097
16186
  anyAnchor: false,
16098
16187
  order: ++orderCounter,
@@ -16188,6 +16277,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
16188
16277
  o.byPart.get(r.b).push(j);
16189
16278
  o.st.joints.push(jst);
16190
16279
  }
16280
+ for (const id2 of o.unanchored) {
16281
+ const p = o.byId.get(id2);
16282
+ if (p) p.anchored = false;
16283
+ }
16191
16284
  for (const [jid, c] of carry?.joints ?? []) if (c.st.open && !o.jointMap.has(jid)) o.st.joints.push(c.st);
16192
16285
  updateBound(o);
16193
16286
  o.anyAnchor = o.parts.some((p) => p.anchored);
@@ -16927,6 +17020,196 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
16927
17020
  }
16928
17021
  }
16929
17022
  };
17023
+ const groundCfg = resolveGroundLoss(options.groundLoss);
17024
+ const pendingLosses = [];
17025
+ const bearersOf = (o) => {
17026
+ const terrain = /* @__PURE__ */ new Set();
17027
+ o.parts.forEach((p, i) => {
17028
+ if (isTerrain(p) && !isLost(p)) terrain.add(i);
17029
+ });
17030
+ const tops = [...terrain].map((i) => aabbOf(o.parts[i].spec.shape, o.parts[i].pos, o.parts[i].q).max[1]);
17031
+ const out = [];
17032
+ o.parts.forEach((p, i) => {
17033
+ if (terrain.has(i) || isLost(p) || o.collapsed.has(p.spec.id) || p.spec.structure?.pile) return;
17034
+ const ground = (o.byPart.get(p.spec.id) ?? []).filter((j) => !j.st.open && terrain.has(restsOn(o, j, i)));
17035
+ if (!p.anchored && ground.length === 0) return;
17036
+ const bottom = aabbOf(p.spec.shape, p.pos, p.q).min[1];
17037
+ const depth = Math.max(0, (tops.length ? Math.max(...tops) : bottom) - bottom);
17038
+ const footed = p.spec.structure?.role === "wall" || p.spec.structure?.role === "column";
17039
+ out.push({ p, i, ground, embed: footed ? Math.max(depth, groundCfg.footingDepth) : depth });
17040
+ });
17041
+ return out;
17042
+ };
17043
+ const nearLoss = (o, p, loss) => {
17044
+ const box4 = partWorldAabb(o, p);
17045
+ const dx = Math.max(box4.min[0] - loss.x, 0, loss.x - box4.max[0]);
17046
+ const dz = Math.max(box4.min[2] - loss.z, 0, loss.z - box4.max[2]);
17047
+ return Math.hypot(dx, dz) < loss.radius + loss.depth * groundCfg.spread;
17048
+ };
17049
+ const footprintOf = (o, b, loss) => {
17050
+ const box4 = aabbOf(b.p.spec.shape, b.p.pos, b.p.q);
17051
+ const long = box4.max[0] - box4.min[0] >= box4.max[2] - box4.min[2] ? 0 : 2;
17052
+ const across2 = long === 0 ? 2 : 0;
17053
+ const n = clamp2(Math.ceil((box4.max[long] - box4.min[long]) / FOOTPRINT_STEP), 1, FOOTPRINT_MAX_SAMPLES);
17054
+ const m = clamp2(Math.ceil((box4.max[across2] - box4.min[across2]) / FOOTPRINT_STEP), 1, FOOTPRINT_MAX_SAMPLES);
17055
+ const step = (box4.max[long] - box4.min[long]) / n;
17056
+ const slices = [];
17057
+ let voids = 0;
17058
+ let sum = 0;
17059
+ let worst = -1;
17060
+ let deepest = toWorld(o.st.position, o.st.rotation, [(box4.min[0] + box4.max[0]) / 2, box4.min[1], (box4.min[2] + box4.max[2]) / 2]);
17061
+ for (let k = 0; k < n; k++) {
17062
+ let open = 0;
17063
+ let drop = 0;
17064
+ for (let c = 0; c < m; c++) {
17065
+ const local = [0, box4.min[1], 0];
17066
+ local[long] = box4.min[long] + (k + 0.5) * step;
17067
+ local[across2] = box4.min[across2] + (c + 0.5) * (box4.max[across2] - box4.min[across2]) / m;
17068
+ const world2 = toWorld(o.st.position, o.st.rotation, local);
17069
+ const cut = undercutAt(loss, Math.hypot(world2[0] - loss.x, world2[2] - loss.z), b.embed, groundCfg.spread);
17070
+ if (cut >= groundCfg.voidDepth) open++;
17071
+ drop += Math.min(cut, groundCfg.maxSettlement);
17072
+ if (cut > worst) {
17073
+ worst = cut;
17074
+ deepest = world2;
17075
+ }
17076
+ }
17077
+ voids += open;
17078
+ sum += drop;
17079
+ slices.push({ void: open * 2 > m, drop: drop / m });
17080
+ }
17081
+ return { long, step, slices, share: voids / (n * m), drop: sum / (n * m), deepest };
17082
+ };
17083
+ const bridgeOf = (b, fp, voids) => {
17084
+ const p = b.p;
17085
+ if (p.spec.shape.kind !== "box" || !p.mat.strength?.tensileMPa) return null;
17086
+ const g = bendGeometry(p.spec);
17087
+ if (g.gravity < 0) return null;
17088
+ const footing = p.spec.structure?.role === "foundation" && g.member && !isReinforced(p.spec);
17089
+ const spec = footing ? { ...p.spec, structure: { ...p.spec.structure, rebar: { ratio: groundCfg.beamRebarRatio } } } : p.spec;
17090
+ const section = { b: sectionWidth(g, g.gravity), h: g.dims[g.gravity] };
17091
+ const m = sectionMoments(p.mat, section, tensionSteel(spec, g.dims, section, flexure), flexure);
17092
+ const span = (voids.end - voids.start) * fp.step;
17093
+ const cantilever = voids.start === 0 || voids.end === fp.slices.length;
17094
+ const w = lineLoad(g, p.st.load ?? p.st.mass);
17095
+ const moment = (cantilever ? w * span * span / 2 : spanMoment(w, span)) * structureSafety;
17096
+ const whole2 = voids.start === 0 && voids.end === fp.slices.length;
17097
+ const holds2 = !whole2 && span <= groundCfg.bridgeSpanDepth * section.h && moment <= (p.st.cracked ? m.steel : m.ultimate);
17098
+ const cracks = moment > m.cracking;
17099
+ const EI = (p.mat.strength.elasticGPa ?? 0) * 1e9 * section.b * section.h ** 3 * (cracks || p.st.cracked ? CRACKED_STIFFNESS : 1) / 12;
17100
+ const sag = EI > 0 ? w * span ** 4 / (cantilever ? 8 * EI : 384 / 5 * EI) : groundCfg.maxSettlement;
17101
+ return { holds: holds2, cracks, cantilever, span, depth: section.h, sag };
17102
+ };
17103
+ const crackBridge = (o, b, fp, voids, bridge, src) => {
17104
+ if (b.p.st.cracked) return;
17105
+ b.p.st.cracked = true;
17106
+ const box4 = aabbOf(b.p.spec.shape, b.p.pos, b.p.q);
17107
+ const local = [(box4.min[0] + box4.max[0]) / 2, bridge.cantilever ? box4.max[1] : box4.min[1], (box4.min[2] + box4.max[2]) / 2];
17108
+ const edge = voids.start === 0 ? voids.end : voids.start;
17109
+ local[fp.long] = box4.min[fp.long] + (bridge.cantilever ? edge : (voids.start + voids.end) / 2) * fp.step;
17110
+ addCrack(o, b.p, toWorld(o.st.position, o.st.rotation, local), rotateVec(o.st.rotation, [0, bridge.cantilever ? 1 : -1, 0]), bridge.depth, src);
17111
+ };
17112
+ const distort = (o, q, beta, at2, src) => {
17113
+ const prior = q.rt.distortion ?? 0;
17114
+ if (beta < groundCfg.crackDistortion || beta <= prior * DISTORTION_GROWTH) return;
17115
+ q.rt.distortion = beta;
17116
+ const box4 = aabbOf(q.spec.shape, q.pos, q.q);
17117
+ const height = box4.max[1] - box4.min[1];
17118
+ const cracks = (d) => d < groundCfg.crackDistortion ? 0 : Math.min(MAX_SETTLEMENT_CRACKS, 1 + Math.floor(Math.log2(d / groundCfg.crackDistortion)));
17119
+ const count = Math.max(1, cracks(beta) - cracks(prior));
17120
+ const axis = [0, 0, 0];
17121
+ axis[q.thin] = 1;
17122
+ const normal = rotateVec(quat.mul(o.st.rotation, q.q), axis);
17123
+ const length = Math.min(height * 0.6, SETTLEMENT_CRACK_LENGTH * Math.sqrt(beta / groundCfg.crackDistortion));
17124
+ for (let c = 0; c < count; c++) {
17125
+ const local = [clamp2(at2[0], box4.min[0], box4.max[0]), box4.min[1] + height * (0.15 + 0.2 * c), clamp2(at2[2], box4.min[2], box4.max[2])];
17126
+ addCrack(o, q, toWorld(o.st.position, o.st.rotation, local), normal, length, src);
17127
+ }
17128
+ if (beta >= groundCfg.damageDistortion && prior < groundCfg.damageDistortion) {
17129
+ q.st.hp = Math.max(1, q.st.hp - q.st.maxHp * groundCfg.distortionDamage);
17130
+ markDamaged(q);
17131
+ }
17132
+ };
17133
+ const crackOver = (o, b, fp, src) => {
17134
+ const box4 = aabbOf(b.p.spec.shape, b.p.pos, b.p.q);
17135
+ const drops = fp.slices.map((slice) => slice.drop);
17136
+ for (const j of o.byPart.get(b.p.spec.id) ?? []) {
17137
+ if (j.st.open) continue;
17138
+ const qi = j.ia === b.i ? j.ib : j.ia;
17139
+ const q = o.parts[qi];
17140
+ if (isLost(q) || isTerrain(q) || o.collapsed.has(q.spec.id) || !isSlender(q.spec, q.mat)) continue;
17141
+ if (restsOn(o, j, qi) !== b.i) {
17142
+ distort(o, q, (b.p.st.subsidence ?? 0) / DISTORTION_BASE, j.pos, src);
17143
+ continue;
17144
+ }
17145
+ const over = aabbOf(q.spec.shape, q.pos, q.q);
17146
+ const k0 = clamp2(Math.floor((over.min[fp.long] - box4.min[fp.long]) / fp.step), 0, drops.length - 1);
17147
+ const k1 = clamp2(Math.ceil((over.max[fp.long] - box4.min[fp.long]) / fp.step), k0 + 1, drops.length);
17148
+ const { value, at: at2 } = distortionOf(drops.slice(k0, k1), fp.step);
17149
+ const point = [(over.min[0] + over.max[0]) / 2, over.min[1], (over.min[2] + over.max[2]) / 2];
17150
+ point[fp.long] = box4.min[fp.long] + (k0 + at2 + 0.5) * fp.step;
17151
+ distort(o, q, value, point, src);
17152
+ }
17153
+ };
17154
+ const loseGround = (o, b, opened) => {
17155
+ if (b.p.anchored) {
17156
+ b.p.anchored = false;
17157
+ o.unanchored.add(b.p.spec.id);
17158
+ }
17159
+ for (const j of b.ground) {
17160
+ if (j.st.open) continue;
17161
+ j.st.open = true;
17162
+ j.st.hp = 0;
17163
+ j.st.openedBy = "break";
17164
+ opened.push(j);
17165
+ }
17166
+ };
17167
+ const bearLoss = (o, b, fp, src) => {
17168
+ const voids = longestRun(fp.slices.map((slice) => slice.void));
17169
+ const bridge = voids ? bridgeOf(b, fp, voids) : null;
17170
+ if (voids && bridge && bridge.span >= bridge.depth) {
17171
+ if (!bridge.holds) return "unsupported";
17172
+ if (bridge.cracks) crackBridge(o, b, fp, voids, bridge, src);
17173
+ for (let k = voids.start; k < voids.end; k++) fp.slices[k].drop = Math.min(fp.slices[k].drop, bridge.sag);
17174
+ fp.drop = fp.slices.reduce((sum, slice) => sum + slice.drop, 0) / fp.slices.length;
17175
+ return "bridged";
17176
+ }
17177
+ return fp.share <= 1 - 1 / soilCfg.safety ? "settled" : "unsupported";
17178
+ };
17179
+ const undermine = (o, loss) => {
17180
+ if (!o.hasStructure || !o.anyAnchor || o.st.soil?.status === "toppled") return;
17181
+ const src = loss.source ?? "ground";
17182
+ const opened = [];
17183
+ const settled = [];
17184
+ let lost = false;
17185
+ for (const b of bearersOf(o)) {
17186
+ if (!nearLoss(o, b.p, loss)) continue;
17187
+ const fp = footprintOf(o, b, loss);
17188
+ if (fp.share <= 0 && fp.drop < SUBSIDE_MIN) continue;
17189
+ const status = bearLoss(o, b, fp, src);
17190
+ const before = b.p.st.subsidence ?? 0;
17191
+ const drop = Math.max(before, fp.drop);
17192
+ if (status === "unsupported") {
17193
+ loseGround(o, b, opened);
17194
+ lost = true;
17195
+ } else settled.push({ b, fp });
17196
+ if (status === "settled" && drop - before < SUBSIDE_MIN) continue;
17197
+ b.p.st.subsidence = drop;
17198
+ emit({ ...base(o, src), type: "subside", part: b.p.spec.id, drop, share: fp.share, point: fp.deepest, status });
17199
+ }
17200
+ for (const { b, fp } of settled) crackOver(o, b, fp, src);
17201
+ o.active = true;
17202
+ if (!lost) return;
17203
+ solveStructure(o);
17204
+ recomputeGroups(o);
17205
+ detachEvents(o, opened, "break", src);
17206
+ collapseCheck(o, src);
17207
+ };
17208
+ const applyGroundLosses = () => {
17209
+ for (let loss = pendingLosses.shift(); loss; loss = pendingLosses.shift()) {
17210
+ for (const o of [...objects.values()]) if (objects.get(o.id) === o) undermine(o, loss);
17211
+ }
17212
+ };
16930
17213
  const getObj = (id) => {
16931
17214
  const o = objects.get(id);
16932
17215
  if (!o) throw new Error(`unknown object "${id}"`);
@@ -18938,18 +19221,27 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
18938
19221
  blastProbe.partsNear = 0;
18939
19222
  return withCollapses(run(() => blastWorld(point, energy, radius, source, blast)));
18940
19223
  },
19224
+ groundLoss(loss) {
19225
+ if (!(loss.radius > 0) || !(loss.depth > 0) || !Number.isFinite(loss.x) || !Number.isFinite(loss.z)) return;
19226
+ pendingLosses.push({ ...loss });
19227
+ },
18941
19228
  raycast(origin, direction, maxDistance = Infinity) {
18942
19229
  const r = raycastInternal(origin, direction, maxDistance, void 0, false, true);
18943
19230
  return r ? { object: r.object, part: r.part, point: r.point, normal: r.normal, distance: r.distance } : null;
18944
19231
  },
18945
19232
  sweepBox(box4, direction, distance2, options2 = {}) {
18946
19233
  const d = vec.normalize(direction);
18947
- const ignored = options2.ignore === void 0 ? void 0 : objects.get(options2.ignore);
18948
- const hosted = options2.ignore === void 0 || ignored ? void 0 : impls.get(options2.ignore);
18949
- const ignore = ignored ? new Set(ignored.parts.map((p) => `${ignored.id}\0${p.spec.id}`)) : hosted ? new Set(hosted.impl.describe().parts.map((p) => `${hosted.impl.id}\0${p.id}`)) : void 0;
19234
+ const ignoredIds = options2.ignore === void 0 ? [] : typeof options2.ignore === "string" ? [options2.ignore] : options2.ignore;
19235
+ const ignore = /* @__PURE__ */ new Set();
19236
+ for (const id of ignoredIds) {
19237
+ const ignored = objects.get(id);
19238
+ const hosted = ignored ? void 0 : impls.get(id);
19239
+ if (ignored) for (const p of ignored.parts) ignore.add(`${ignored.id}\0${p.spec.id}`);
19240
+ else if (hosted) for (const p of hosted.impl.describe().parts) ignore.add(`${hosted.impl.id}\0${p.id}`);
19241
+ }
18950
19242
  let best = null;
18951
19243
  for (const origin of sweepOrigins(box4, d, options2.spacing ?? 0.2)) {
18952
- const r = raycastInternal(origin, d, distance2 + SWEEP_BACK, ignore);
19244
+ const r = raycastInternal(origin, d, distance2 + SWEEP_BACK, ignore.size > 0 ? ignore : void 0);
18953
19245
  if (!r || best && r.distance >= best.distance) continue;
18954
19246
  best = { object: r.object, part: r.part, point: r.point, normal: r.normal, distance: Math.max(0, r.distance - SWEEP_BACK) };
18955
19247
  }
@@ -19140,6 +19432,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19140
19432
  if (!(dt > 0)) return [];
19141
19433
  return run(() => {
19142
19434
  time += dt;
19435
+ applyGroundLosses();
19143
19436
  const sources = [];
19144
19437
  for (const o of [...objects.values()]) if (o.active) stepObject(o, dt, sources);
19145
19438
  for (const o of [...objects.values()]) if (o.soil && objects.get(o.id) === o) stepSoil(o, dt);
@@ -19186,7 +19479,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19186
19479
  rng: rng3.state(),
19187
19480
  counter,
19188
19481
  objects: [...objects.values()].map((o) => {
19189
- const runtime = { parts: {}, joints: {}, collapsed: [...o.collapsed], ...o.soil?.sets.size ? { soil: Object.fromEntries(o.soil.sets) } : {}, ...o.wind ? { wind: [o.wind.dyn.x, o.wind.dyn.v, o.wind.dyn.y, o.wind.dyn.w, o.wind.dyn.peak] } : {} };
19482
+ const runtime = { parts: {}, joints: {}, collapsed: [...o.collapsed], ...o.unanchored.size ? { unanchored: [...o.unanchored] } : {}, ...o.soil?.sets.size ? { soil: Object.fromEntries(o.soil.sets) } : {}, ...o.wind ? { wind: [o.wind.dyn.x, o.wind.dyn.v, o.wind.dyn.y, o.wind.dyn.w, o.wind.dyn.peak] } : {} };
19190
19483
  for (const p of o.parts) runtime.parts[p.spec.id] = clone(p.rt);
19191
19484
  for (const j of o.joints) runtime.joints[j.spec.id] = j.step;
19192
19485
  return { id: o.id, spec: clone(o.spec), state: clone(o.st), runtime };
@@ -19208,6 +19501,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19208
19501
  ),
19209
19502
  joints: new Map(state.joints.map((st) => [st.id, { st, step: e.runtime?.joints[st.id] ?? 0 }])),
19210
19503
  collapsed: e.runtime?.collapsed,
19504
+ ...e.runtime?.unanchored ? { unanchored: e.runtime.unanchored } : {},
19211
19505
  ...e.runtime?.wind ? { wind: e.runtime.wind } : {}
19212
19506
  };
19213
19507
  let pos = state.position, rot = state.rotation;