@adatechnology/game-weapons-three 0.25.0 → 0.26.1

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.
@@ -91,6 +91,7 @@ var GameWeaponsThree = (() => {
91
91
  defaultWeaponProps: () => defaultWeaponProps,
92
92
  deriveFrames: () => deriveFrames,
93
93
  dropLoose: () => dropLoose,
94
+ explosiveCollider: () => explosiveCollider,
94
95
  explosivesTextOf: () => explosivesTextOf,
95
96
  fitAttachmentModels: () => fitAttachmentModels,
96
97
  hasExplosiveModel: () => hasExplosiveModel,
@@ -28522,6 +28523,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28522
28523
  return reach2;
28523
28524
  };
28524
28525
  let blastTntPerJoule = TNT_PER_JOULE;
28526
+ let blastHasCharge = false;
28525
28527
  let blastFireball = chargeFireball(0);
28526
28528
  const burstFuel = (p) => {
28527
28529
  const c = p.spec.contains;
@@ -28626,7 +28628,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28626
28628
  }
28627
28629
  for (const im of [...impls.values()]) {
28628
28630
  if (!implInRange(im, point, radius)) continue;
28629
- out.push(implHit(im, { type: "explosive", point, energy, radius, fireball: blastFireball, tnt: energy * blastTntPerJoule, ...lethal !== void 0 ? { lethalRadius: lethal } : {}, ...src !== void 0 ? { source: src } : {} }));
28631
+ out.push(implHit(im, { type: "explosive", point, energy, radius, fireball: blastFireball, tnt: energy * blastTntPerJoule, ...blastHasCharge ? { hasCharge: true } : {}, ...lethal !== void 0 ? { lethalRadius: lethal } : {}, ...src !== void 0 ? { source: src } : {} }));
28630
28632
  yield "part";
28631
28633
  }
28632
28634
  return out;
@@ -28751,7 +28753,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28751
28753
  den += f;
28752
28754
  }
28753
28755
  const k = den > 0 ? num3 / den : 1;
28754
- const res = implHit(im, { type: "explosive", point, energy: E * k, radius, fireball: blastFireball, tnt: energy * blastTntPerJoule * k, ...lethal !== void 0 ? { lethalRadius: lethal } : {}, ...shelter ? { shelter: k } : {}, ...src !== void 0 ? { source: src } : {} });
28756
+ const res = implHit(im, { type: "explosive", point, energy: E * k, radius, fireball: blastFireball, tnt: energy * blastTntPerJoule * k, ...blastHasCharge ? { hasCharge: true } : {}, ...lethal !== void 0 ? { lethalRadius: lethal } : {}, ...shelter ? { shelter: k } : {}, ...src !== void 0 ? { source: src } : {} });
28755
28757
  results.set(im, res);
28756
28758
  report(im).shelter = k;
28757
28759
  }
@@ -29093,13 +29095,16 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
29093
29095
  const fireball = charge2?.fuel ? fuelFireball(charge2.fuel) : chargeFireball(energy * tntPerJoule);
29094
29096
  const inBlast = (fn) => {
29095
29097
  const outer = blastTntPerJoule;
29098
+ const outerHasCharge = blastHasCharge;
29096
29099
  const outerFireball = blastFireball;
29097
29100
  blastTntPerJoule = tntPerJoule;
29101
+ blastHasCharge = charge2?.tnt !== void 0;
29098
29102
  blastFireball = fireball;
29099
29103
  try {
29100
29104
  return fn();
29101
29105
  } finally {
29102
29106
  blastTntPerJoule = outer;
29107
+ blastHasCharge = outerHasCharge;
29103
29108
  blastFireball = outerFireball;
29104
29109
  }
29105
29110
  };
@@ -54894,7 +54899,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
54894
54899
  }
54895
54900
  var residentialTower = residentialTowerTemplate();
54896
54901
 
54897
- // ../game-floorplan-three/dist/chunk-W4VG2X7N.js
54902
+ // ../game-floorplan-three/dist/chunk-EYIWURKO.js
54898
54903
  var __defProp4 = Object.defineProperty;
54899
54904
  var __defNormalProp2 = (obj, key2, value) => key2 in obj ? __defProp4(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
54900
54905
  var __publicField2 = (obj, key2, value) => __defNormalProp2(obj, typeof key2 !== "symbol" ? key2 + "" : key2, value);
@@ -56942,7 +56947,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
56942
56947
  }
56943
56948
  function paths() {
56944
56949
  const lt2 = shared3.ctx.r.lot;
56945
- if (!lt2 || !lt2.paths) return;
56950
+ if (!lt2 || !lt2.paths || shared3.ctx.noGroundSurfaces) return;
56946
56951
  cursor.group = "lot";
56947
56952
  for (const c of lt2.paths) {
56948
56953
  if (c.type === "vehicle" && c.id !== "cargo_path") continue;
@@ -58236,6 +58241,18 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58236
58241
  __publicField2(this, "positions", []);
58237
58242
  __publicField2(this, "normals", []);
58238
58243
  __publicField2(this, "indices", []);
58244
+ __publicField2(this, "ranges", []);
58245
+ }
58246
+ /** What is added from here on, up to the next call, is the piece `id` (null: no piece). */
58247
+ piece(id) {
58248
+ const v = this.positions.length / 3, i = this.indices.length;
58249
+ const last = this.ranges[this.ranges.length - 1];
58250
+ if (last && last.v1 < 0) {
58251
+ last.v1 = v;
58252
+ last.i1 = i;
58253
+ if (last.v1 === last.v0) this.ranges.pop();
58254
+ }
58255
+ if (id !== null) this.ranges.push({ id, v0: v, v1: -1, i0: i, i1: -1 });
58239
58256
  }
58240
58257
  get count() {
58241
58258
  return this.indices.length / 36;
@@ -58256,12 +58273,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58256
58273
  }
58257
58274
  /**
58258
58275
  * A six-faced solid from its eight corners: four at the start (in turn around the section) and the same four at the end, for a timber laid on a slope. Each
58259
- * face is wound to look out of the solid.
58276
+ * face is wound to look out of the solid. `open`: the start or end face is left out (a stretch of a timber cut into pieces, against the next one).
58260
58277
  */
58261
- addHexahedron(corners) {
58278
+ addHexahedron(corners, open = {}) {
58262
58279
  if (corners.length !== 8) return;
58263
58280
  const centre = [0, 1, 2].map((k) => corners.reduce((sum2, c) => sum2 + c[k], 0) / 8);
58264
58281
  for (const quad of HEXAHEDRON_FACES) {
58282
+ if (open.start && quad === HEXAHEDRON_FACES[0] || open.end && quad === HEXAHEDRON_FACES[1]) continue;
58265
58283
  const a = corners[quad[0]], b = corners[quad[1]], c = corners[quad[2]], d = corners[quad[3]];
58266
58284
  const e1 = [b[0] - a[0], b[1] - a[1], b[2] - a[2]], e2 = [d[0] - a[0], d[1] - a[1], d[2] - a[2]];
58267
58285
  let n = [e1[1] * e2[2] - e1[2] * e2[1], e1[2] * e2[0] - e1[0] * e2[2], e1[0] * e2[1] - e1[1] * e2[0]];
@@ -58296,6 +58314,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58296
58314
  /** The mesh of everything added, or null when nothing was. */
58297
58315
  mesh(THREE, material, name) {
58298
58316
  if (!this.indices.length) return null;
58317
+ this.piece(null);
58299
58318
  const geometry = new THREE.BufferGeometry();
58300
58319
  geometry.setAttribute("position", new THREE.Float32BufferAttribute(this.positions, 3));
58301
58320
  geometry.setAttribute("normal", new THREE.Float32BufferAttribute(this.normals, 3));
@@ -58306,6 +58325,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58306
58325
  mesh3.name = name;
58307
58326
  mesh3.castShadow = true;
58308
58327
  mesh3.receiveShadow = true;
58328
+ if (this.ranges.length) mesh3.userData.ranges = this.ranges.map((range3) => ({ ...range3 }));
58309
58329
  return mesh3;
58310
58330
  }
58311
58331
  };
@@ -58314,7 +58334,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58314
58334
  var FEED_Y = -0.6;
58315
58335
  var FEED_EXIT_Y = -0.15;
58316
58336
  var FEED_BOX_OFFSET = 0.25;
58317
- var BRICK_FACE_INSET = 0.014;
58337
+ function chaseDepth(diameter = CHASE_DIAMETER) {
58338
+ return PLASTER_PER_FACE + CHASE_CLEAR + diameter;
58339
+ }
58340
+ var CHASE_DIAMETER = 0.025;
58341
+ var CHASE_CLEAR = 6e-3;
58318
58342
  var SLAB_MIDDLE = 0.065;
58319
58343
  var CEILING_SLAB = 0.5;
58320
58344
  var PASSING_END_CLEAR = { water: 0.335, conduit: 0.485 };
@@ -58371,7 +58395,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58371
58395
  const inward = (alongU ? (box5[1] + box5[3]) / 2 : (box5[0] + box5[2]) / 2) - line;
58372
58396
  const side = Math.abs(across2) > 1e-3 ? Math.sign(across2) : inward >= 0 ? 1 : -1;
58373
58397
  const half = (wall.thickness ?? DEFAULT_THICKNESS) / 2;
58374
- const offset = options.surface ? half + (options.diameter ?? 0.02) / 2 : half - BRICK_FACE_INSET;
58398
+ const offset = options.surface ? half + (options.diameter ?? 0.02) / 2 : half - chaseDepth(options.diameter);
58375
58399
  const at4 = line + side * offset;
58376
58400
  return { u: alongU ? along2 : at4, v: alongU ? at4 : along2, wall };
58377
58401
  }
@@ -59047,6 +59071,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
59047
59071
  }
59048
59072
  var PIPE_WALL_FILL = 0.3;
59049
59073
  var WALL_PIPE_MASS = 3;
59074
+ var UNDER_SINK_RISER_OFF_WALL = 0.08;
59075
+ var UNDER_SINK_VALVE_RISE = 0.1;
59050
59076
  var pipeMass = (diameter, length2) => DENSITY.plastic * Math.PI * (diameter / 2) ** 2 * length2 * PIPE_WALL_FILL;
59051
59077
  function installUtilitiesWater(K, shared3) {
59052
59078
  const { THREE, _Y, _q, cursor, cylBase, part, pieceRecord, put } = K;
@@ -59246,7 +59272,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
59246
59272
  }
59247
59273
  }
59248
59274
  function underSink(tr) {
59249
- const H = shared3.ctx.r.utilities?.plumbing, nA = shared3.ctx.r.floors.length, pt = H && H.points.find((p) => p.id === tr.to), pts = tr.points.map((p) => [p[0], p[2], p[1]]), d = tr.diameter || 0.025;
59275
+ const H = shared3.ctx.r.utilities?.plumbing, nA = shared3.ctx.r.floors.length, pt = H && H.points.find((p) => p.id === tr.to), d = tr.diameter || 0.025;
59276
+ const pts = riserUnderBack(tr.points.map((p) => [p[0], p[2], p[1]]));
59250
59277
  const stage2 = cursor.stage;
59251
59278
  if (shared3.ctx.constructionStages) cursor.stage = "furniture";
59252
59279
  cursor.group = pt && pt.floor >= 0 ? "f" + Math.min(pt.floor, nA - 1) : "lot";
@@ -59258,6 +59285,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
59258
59285
  cursor.pc = null;
59259
59286
  cursor.stage = stage2;
59260
59287
  }
59288
+ function riserUnderBack(pts) {
59289
+ if (pts.length < 3 || shared3.ctx.visorScene) return pts;
59290
+ const wall = pts[0], mid = pts[1], dx = mid[0] - wall[0], dz = mid[2] - wall[2], L = Math.hypot(dx, dz);
59291
+ if (L <= UNDER_SINK_RISER_OFF_WALL) return pts;
59292
+ const x = wall[0] + dx / L * UNDER_SINK_RISER_OFF_WALL, z = wall[2] + dz / L * UNDER_SINK_RISER_OFF_WALL;
59293
+ const top = mid[1] + UNDER_SINK_VALVE_RISE;
59294
+ return [wall, ...pts.slice(1).map((p) => [x, Math.min(p[1], top), z])];
59295
+ }
59261
59296
  const defined = { createWater, PIPE_COLOR, pipe, _v3, waterPipes };
59262
59297
  Object.assign(K, defined);
59263
59298
  }
@@ -59604,15 +59639,15 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
59604
59639
  const aabb = wall.alongU ? [solid2.aabb[0], line - width / 2, solid2.aabb[2], line + width / 2] : [line - width / 2, solid2.aabb[1], line + width / 2, solid2.aabb[3]];
59605
59640
  return { ...solid2, aabb };
59606
59641
  }
59607
- var CHASE_CLEAR = 3e-3;
59642
+ var CHASE_CLEAR2 = 3e-3;
59608
59643
  function chasesIn(wall, core, runs) {
59609
59644
  const out = [];
59610
59645
  for (const r of runs) {
59611
59646
  const along2 = wall.alongU ? r.u : r.v, across2 = (wall.alongU ? r.v : r.u) - core.line;
59612
- if (along2 + r.radius + CHASE_CLEAR < wall.a0 || along2 - r.radius - CHASE_CLEAR > wall.a1 || r.y1 <= core.y0 || r.y0 >= core.y1) continue;
59647
+ if (along2 + r.radius + CHASE_CLEAR2 < wall.a0 || along2 - r.radius - CHASE_CLEAR2 > wall.a1 || r.y1 <= core.y0 || r.y0 >= core.y1) continue;
59613
59648
  if (Math.abs(across2) > wall.thickness / 2 + 1e-6) continue;
59614
- const back = Math.abs(across2) - (r.depth ?? r.radius) - CHASE_CLEAR;
59615
- out.push({ a0: along2 - r.radius - CHASE_CLEAR, a1: along2 + r.radius + CHASE_CLEAR, y0: Math.max(core.y0, r.y0), y1: Math.min(core.y1, r.y1), side: across2 >= 0 ? 1 : -1, back, ...r.box ? { box: true } : {} });
59649
+ const back = Math.abs(across2) - (r.depth ?? r.radius) - CHASE_CLEAR2;
59650
+ 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, ...r.box ? { box: true } : {} });
59616
59651
  }
59617
59652
  return out;
59618
59653
  }
@@ -61142,7 +61177,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
61142
61177
  alias("tv", "flat_tv");
61143
61178
  alias("tv_large", "flat_tv");
61144
61179
  mine("coffee_table", (M, A) => FURNITURE.table(M, A, { noChairs: true }));
61145
- mine("coffee_table_round", (M, A) => FURNITURE.table(M, A, { without: true, round: true }));
61180
+ mine("coffee_table_round", (M, A) => FURNITURE.table(M, A, { noChairs: true, round: true }));
61146
61181
  mine("rug", FURNITURE.rug);
61147
61182
  mine("rug_small", FURNITURE.rug, "game (rug)");
61148
61183
  mine("shelf_unit", FURNITURE.shelf);
@@ -61871,17 +61906,23 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
61871
61906
  }
61872
61907
  var POTTED_PLANT_TYPES = /* @__PURE__ */ new Set(["floor_plant", "floor_plant_tall", "floor_plant_low", "plant_tall", "plant_short", "outdoor_pot", "table_plant"]);
61873
61908
  var PLANT_CLEAR = 0.04;
61874
- var PLANT_MIN_REACH = 0.14;
61909
+ var PLANT_MIN_REACH = 0.12;
61875
61910
  var PLANT_SPAN = [0.03, 2.4];
61911
+ var PLANT_HEIGHT_MARGIN = 1.5;
61876
61912
  function footprintOf(m) {
61877
61913
  const c = Math.abs(Math.cos(m.ry || 0)), s = Math.abs(Math.sin(m.ry || 0)), hx = ((m.w || 0) * c + (m.d || 0) * s) / 2, hz2 = ((m.w || 0) * s + (m.d || 0) * c) / 2;
61878
61914
  return [m.x - hx, m.z - hz2, m.x + hx, m.z + hz2];
61879
61915
  }
61880
61916
  var reachTo = (x, z, x0, z0, x1, z1) => Math.hypot(Math.max(x0 - x, 0, x - x1), Math.max(z0 - z, 0, z - z1));
61881
61917
  function freeReachOf(p) {
61882
- const y0 = p.y + PLANT_SPAN[0], y1 = p.y + PLANT_SPAN[1];
61918
+ const tall = p.self.h != null && p.self.h > 0 ? Math.min(PLANT_SPAN[1], p.self.h * PLANT_HEIGHT_MARGIN) : PLANT_SPAN[1];
61919
+ const y0 = p.y + PLANT_SPAN[0], y1 = p.y + tall;
61883
61920
  let reach2 = Number.POSITIVE_INFINITY;
61884
- for (const b of p.boxes) if (b[1] < y1 && b[4] > y0) reach2 = Math.min(reach2, reachTo(p.x, p.z, b[0], b[2], b[3], b[5]));
61921
+ for (const b of p.boxes) {
61922
+ if (b[1] >= y1 || b[4] <= y0) continue;
61923
+ if (b[1] > p.y && p.x >= b[0] && p.x <= b[3] && p.z >= b[2] && p.z <= b[5]) continue;
61924
+ reach2 = Math.min(reach2, reachTo(p.x, p.z, b[0], b[2], b[3], b[5]));
61925
+ }
61885
61926
  for (const m of p.items) {
61886
61927
  if (m === p.self || m.id === p.self.id || m.floor !== p.self.floor || m.flat || m.category === "ground_cover" || m.w == null || m.d == null) continue;
61887
61928
  const bottom = p.base + (m.y || 0), top = bottom + (m.h || 0);
@@ -61945,7 +61986,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
61945
61986
  const covers = [];
61946
61987
  for (const m of ordered) {
61947
61988
  if (m.type === "stairs") continue;
61948
- const exterior = m.outdoor || m.floor < 0, f = exterior ? -1 : Math.min(m.floor, R.floors.length - 1);
61989
+ const exterior = m.outdoor || m.floor < 0;
61990
+ if (exterior && m.category === "ground_cover" && shared3.ctx.noGroundSurfaces) continue;
61991
+ const f = exterior ? -1 : Math.min(m.floor, R.floors.length - 1);
61949
61992
  cursor.group = exterior && !(m.type === "cooking_gas_cylinder" && m.shelter && !shared3.ctx.visorScene) ? "lot" : "f" + Math.max(f, 0);
61950
61993
  const com = m.room != null ? shared3.ctx.roomById[m.room] : void 0, lift = !exterior && f === 0 && shared3.ctx.constructionStages && !shared3.ctx.visorScene && !com?.outbuilding ? FLOOR_OVER_GROUND : 0, base = exterior ? 0 : Y0(f) + lift;
61951
61994
  const M = { visorScene: shared3.ctx.visorScene, x: m.x, z: m.z, ry: m.ry || 0, w: m.w, d: m.d, h: m.h, y: m.y || 0, base, floor: exterior ? -1 : f, palette: shared3.ctx.colors, color: m.category === "ground_cover" ? void 0 : colorOf(m.color) ?? void 0, seed: m.id, room: m.room, typeWith: com ? com.type : null, ceiling: com ? com.ceiling : 2.9, on: shared3.ctx.night, light: shared3.ctx.night, lit: shared3.ctx.night, open: !!m.doorOpen, overhead: m.overhead, assembly: m.assembly, hose: m.hose, shelter: m.shelter, pipe: m.pipe };
@@ -62991,6 +63034,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
62991
63034
  const defined = { targetOf };
62992
63035
  Object.assign(K, defined);
62993
63036
  }
63037
+ var CORD_RADIUS = 6e-3;
62994
63038
  function installInteractablesBridge(K, shared3) {
62995
63039
  const { t, THREE, invalidate, invalidateShadow, cfg, DOC, LIGHT_TYPES, _Y, _q, _v3, accFor, applyLight, cursor, hashString, hudMessage, lightBase, pieceRecord, rgbOf, wallBlocks } = K;
62996
63040
  const enter = (...a) => K.enter(...a);
@@ -63136,9 +63180,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63136
63180
  const spec = ik.A.household.build(type, loc, mesh3.api);
63137
63181
  const out = mesh3.finish(spec);
63138
63182
  for (const l of out.lights) l.removeFromParent();
63139
- const group = ivGroup(ent), g0 = cursor.group, stage0 = cursor.stage, root = new THREE.Group();
63183
+ const group = type === "gas_bottle" && item.shelter && !shared3.ctx.visorScene ? "f0" : ivGroup(ent), g0 = cursor.group, stage0 = cursor.stage, root = new THREE.Group();
63140
63184
  root.name = "iv:" + ent.id;
63141
- const isInst = type === "electrical_panel" || type === "power_meter" || type === "service_entrance" || type === "gas_bottle";
63185
+ const isInst = type === "electrical_panel" || type === "power_meter" || type === "service_entrance";
63142
63186
  const isPlate = type === "wall_switch" || type === "wall_socket";
63143
63187
  const ivStage = shared3.ctx.constructionStages ? isInst ? "installations" : isPlate ? "finishes" : "furniture" : void 0;
63144
63188
  if (ivStage) root.userData.constructionStage = ivStage;
@@ -63194,6 +63238,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63194
63238
  if (root.children.length) IV.roots.push(E);
63195
63239
  return spec;
63196
63240
  }
63241
+ const floorFinishOf = (floor2) => shared3.ctx.constructionStages && !shared3.ctx.visorScene && floor2 === 0 ? FLOOR_OVER_GROUND : 0;
63197
63242
  function ivCords(IV) {
63198
63243
  const ik = IV.k, w = IV.world, wl = (o, p) => ik.GI.localToWorld(o.transform, p), g0 = cursor.group;
63199
63244
  const tube2 = (pts, radius, color2, ox, oy, oz, ry) => {
@@ -63220,15 +63265,16 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63220
63265
  if (!so || !sk) continue;
63221
63266
  const sp = wl(so, sk.pos), dir = [Math.sin(so.transform.ry), Math.cos(so.transform.ry)], last = pts[pts.length - 1];
63222
63267
  if (last[1] < 0.3 + E.pos[1]) {
63223
- const foot = [sp[0] + dir[0] * 0.035, E.pos[1] + 0.012, sp[2] + dir[1] * 0.035];
63224
- pts.push([last[0] + (foot[0] - last[0]) * 0.4, E.pos[1] + 0.012, last[2] + (foot[2] - last[2]) * 0.4], [last[0] + (foot[0] - last[0]) * 0.75, E.pos[1] + 0.012, last[2] + (foot[2] - last[2]) * 0.75], foot, [foot[0], Math.max(E.pos[1] + 0.1, sp[1] - 0.04), foot[2]], [sp[0] + dir[0] * 0.012, sp[1] - 0.01, sp[2] + dir[1] * 0.012]);
63268
+ const lie = E.pos[1] + floorFinishOf(E.floor) + CORD_RADIUS + 1e-3;
63269
+ const foot = [sp[0] + dir[0] * 0.035, lie, sp[2] + dir[1] * 0.035];
63270
+ pts.push([last[0] + (foot[0] - last[0]) * 0.4, lie, last[2] + (foot[2] - last[2]) * 0.4], [last[0] + (foot[0] - last[0]) * 0.75, lie, last[2] + (foot[2] - last[2]) * 0.75], foot, [foot[0], Math.max(E.pos[1] + 0.1, sp[1] - 0.04), foot[2]], [sp[0] + dir[0] * 0.012, sp[1] - 0.01, sp[2] + dir[1] * 0.012]);
63225
63271
  } else {
63226
63272
  const hang = ik.gfx.catenary(last, [sp[0] + dir[0] * 0.012, sp[1] - 0.01, sp[2] + dir[1] * 0.012], 0.1, 8);
63227
63273
  hang.shift();
63228
63274
  for (const p of hang) pts.push(p);
63229
63275
  }
63230
63276
  shared3.ctx.cordPaths?.push({ object: E.id, device: d.id, points: pts.map((p) => [p[0], p[1], p[2]]) });
63231
- tube2(pts, 6e-3, IV_WIRE.cord, 0, 0, 0, 0);
63277
+ tube2(pts, CORD_RADIUS, IV_WIRE.cord, 0, 0, 0, 0);
63232
63278
  }
63233
63279
  }
63234
63280
  } finally {
@@ -66077,6 +66123,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66077
66123
  return level >= STAGE_LEVEL.openings;
66078
66124
  case "roof":
66079
66125
  return level >= STAGE_LEVEL.roof && opts.roofLayer !== false;
66126
+ // the timber of the roof (its stage group is shown by name, `groupVisible`): a stretch of it broken off the frame keeps the frame's stage
66127
+ case "roofFraming":
66128
+ return level >= STAGE_LEVEL.roofFraming && opts.roofLayer !== false;
66080
66129
  case "furniture":
66081
66130
  return level >= STAGE_LEVEL.last;
66082
66131
  // the protective sidewalk round the house: the last of the work outside
@@ -66142,6 +66191,50 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66142
66191
  }
66143
66192
  return level;
66144
66193
  }
66194
+ function partStagesOf(house) {
66195
+ const stages = /* @__PURE__ */ new Map();
66196
+ const walk = (o, inherited) => {
66197
+ const own = typeof o.userData?.constructionStage === "string" ? o.userData.constructionStage : inherited;
66198
+ const part = o.userData?.destructionPart;
66199
+ if (own && typeof part === "string" && !stages.has(part)) stages.set(part, own);
66200
+ const ranges = o.userData?.ranges;
66201
+ if (own && Array.isArray(ranges)) {
66202
+ for (const range3 of ranges) if (!stages.has(range3.id)) stages.set(range3.id, own);
66203
+ }
66204
+ for (const c of o.children) walk(c, own);
66205
+ };
66206
+ walk(house, void 0);
66207
+ return stages;
66208
+ }
66209
+ function stageOfPiece(piece2, stages) {
66210
+ let found;
66211
+ piece2.root.traverse((o) => {
66212
+ if (found) return;
66213
+ const part = o.userData?.destructionPart;
66214
+ if (typeof part === "string") found = stages.get(part);
66215
+ });
66216
+ return found;
66217
+ }
66218
+ function stageLoosePieces(pieces, stages, level, opts, held) {
66219
+ let hidden = 0;
66220
+ for (const piece2 of pieces) {
66221
+ const stage2 = stageOfPiece(piece2, stages);
66222
+ if (!stage2) continue;
66223
+ const shown2 = stageVisible(stage2, level, opts);
66224
+ piece2.root.visible = shown2;
66225
+ if (!shown2) {
66226
+ hidden++;
66227
+ if (!piece2.held) {
66228
+ piece2.held = true;
66229
+ held.add(piece2);
66230
+ }
66231
+ } else if (held.has(piece2)) {
66232
+ piece2.held = false;
66233
+ held.delete(piece2);
66234
+ }
66235
+ }
66236
+ return hidden;
66237
+ }
66145
66238
  var INSTALLATIONS_STAGE = "stage:4:installations";
66146
66239
  function toWorld2(THREE, object2, x, z) {
66147
66240
  return new THREE.Vector3(x, 0, z).applyMatrix4(object2.matrixWorld);
@@ -66173,24 +66266,53 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66173
66266
  hip: { top: 0.065, width: 0.06, height: 0.14 },
66174
66267
  post: { side: 0.07, spacing: 2 }
66175
66268
  };
66269
+ var along = (p0, p1, f) => [p0[0] + (p1[0] - p0[0]) * f, p0[1] + (p1[1] - p0[1]) * f, p0[2] + (p1[2] - p0[2]) * f];
66176
66270
  var EDGE2 = 0.04;
66177
- function addTimber(batch, top0, top1, width, height) {
66271
+ var ROOF_TIMBER_STRETCH = 1.2;
66272
+ var ROOF_TIMBER_MATERIAL = "wood_hard";
66273
+ var TIMBER_DENSITY = 750;
66274
+ var TimberLog = class {
66275
+ constructor(prefix, onPiece) {
66276
+ __publicField2(this, "prefix", prefix);
66277
+ __publicField2(this, "onPiece", onPiece);
66278
+ __publicField2(this, "count", 0);
66279
+ }
66280
+ next(kind, mass, chain) {
66281
+ const id = `${this.prefix}:${this.count++}`;
66282
+ this.onPiece({ id, kind, mass, chain });
66283
+ return id;
66284
+ }
66285
+ };
66286
+ var LOGS = /* @__PURE__ */ new WeakMap();
66287
+ function addTimber(batch, top0, top1, width, height, kind) {
66178
66288
  const dx = top1[0] - top0[0], dz = top1[2] - top0[2];
66179
66289
  const flat2 = Math.hypot(dx, dz);
66180
66290
  if (flat2 < 1e-4 && Math.abs(top1[1] - top0[1]) < 1e-4) return;
66181
66291
  const sx = flat2 < 1e-4 ? width / 2 : -dz / flat2 * (width / 2);
66182
66292
  const sz = flat2 < 1e-4 ? 0 : dx / flat2 * (width / 2);
66183
66293
  const corner = (p, side, down2) => [p[0] + sx * side, p[1] - down2, p[2] + sz * side];
66184
- batch.addHexahedron([
66185
- corner(top0, -1, height),
66186
- corner(top0, 1, height),
66187
- corner(top0, 1, 0),
66188
- corner(top0, -1, 0),
66189
- corner(top1, -1, height),
66190
- corner(top1, 1, height),
66191
- corner(top1, 1, 0),
66192
- corner(top1, -1, 0)
66193
- ]);
66294
+ const log = LOGS.get(batch);
66295
+ const length2 = Math.hypot(dx, top1[1] - top0[1], dz);
66296
+ const stretches = log ? Math.max(1, Math.ceil(length2 / ROOF_TIMBER_STRETCH)) : 1;
66297
+ let before = null;
66298
+ for (let k = 0; k < stretches; k++) {
66299
+ const a = along(top0, top1, k / stretches), b = along(top0, top1, (k + 1) / stretches);
66300
+ if (log) {
66301
+ before = log.next(kind, TIMBER_DENSITY * width * height * (length2 / stretches), before ? [before] : []);
66302
+ batch.piece(before);
66303
+ }
66304
+ batch.addHexahedron([
66305
+ corner(a, -1, height),
66306
+ corner(a, 1, height),
66307
+ corner(a, 1, 0),
66308
+ corner(a, -1, 0),
66309
+ corner(b, -1, height),
66310
+ corner(b, 1, height),
66311
+ corner(b, 1, 0),
66312
+ corner(b, -1, 0)
66313
+ ], { start: k > 0, end: k < stretches - 1 });
66314
+ }
66315
+ if (log) batch.piece(null);
66194
66316
  }
66195
66317
  var KEEP_OUT_GAP = 0.03;
66196
66318
  function clearStretches(top0, top1, width, height, keepOut) {
@@ -66214,16 +66336,15 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66214
66336
  }
66215
66337
  return stretches;
66216
66338
  }
66217
- var along = (p0, p1, f) => [p0[0] + (p1[0] - p0[0]) * f, p0[1] + (p1[1] - p0[1]) * f, p0[2] + (p1[2] - p0[2]) * f];
66218
- function addTimberAround(batch, top0, top1, width, height, keepOut, onCut) {
66339
+ function addTimberAround(batch, top0, top1, width, height, kind, keepOut, onCut) {
66219
66340
  if (!keepOut.length) {
66220
- addTimber(batch, top0, top1, width, height);
66341
+ addTimber(batch, top0, top1, width, height, kind);
66221
66342
  return;
66222
66343
  }
66223
66344
  const length2 = Math.hypot(top1[0] - top0[0], top1[1] - top0[1], top1[2] - top0[2]);
66224
66345
  for (const [f0, f1] of clearStretches(top0, top1, width, height, keepOut)) {
66225
66346
  if ((f1 - f0) * length2 < 0.05) continue;
66226
- addTimber(batch, along(top0, top1, f0), along(top0, top1, f1), width, height);
66347
+ addTimber(batch, along(top0, top1, f0), along(top0, top1, f1), width, height, kind);
66227
66348
  const inset = TIMBER.post.side / 2 / Math.max(length2, 1e-6);
66228
66349
  if (f0 > 0) onCut?.(along(top0, top1, Math.min(f1, f0 + inset)));
66229
66350
  if (f1 < 1) onCut?.(along(top0, top1, Math.max(f0, f1 - inset)));
@@ -66232,7 +66353,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66232
66353
  var postBlocked = (x, z, keepOut) => keepOut.some((b) => x > b[0] - TIMBER.post.side / 2 - KEEP_OUT_GAP && x < b[3] + TIMBER.post.side / 2 + KEEP_OUT_GAP && z > b[2] - TIMBER.post.side / 2 - KEEP_OUT_GAP && z < b[5] + TIMBER.post.side / 2 + KEEP_OUT_GAP);
66233
66354
  function addPost(batch, x, z, y0, y1) {
66234
66355
  const h = TIMBER.post.side / 2;
66235
- if (y1 - y0 > 0.02) batch.add([x - h, y0, z - h, x + h, y1, z + h], true);
66356
+ if (y1 - y0 <= 0.02) return;
66357
+ const log = LOGS.get(batch);
66358
+ if (log) batch.piece(log.next("post", TIMBER_DENSITY * TIMBER.post.side * TIMBER.post.side * (y1 - y0), []));
66359
+ batch.add([x - h, y0, z - h, x + h, y1, z + h], true);
66360
+ if (log) batch.piece(null);
66236
66361
  }
66237
66362
  function slopesOf(rect) {
66238
66363
  const [x0, z0, x1, z1] = rect.exterior;
@@ -66290,7 +66415,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66290
66415
  const a = a0 + BATTEN_SHORT, b = b0 - BATTEN_SHORT;
66291
66416
  if (b - a <= 0.05) continue;
66292
66417
  const at4 = battenClearOfSolids(slope, s, [a, b], solids2);
66293
- addTimberAround(batches.battens, down(slope.point(at4, a), batten.top), down(slope.point(at4, b), batten.top), batten.width, batten.height, keepOut);
66418
+ addTimberAround(batches.battens, down(slope.point(at4, a), batten.top), down(slope.point(at4, b), batten.top), batten.width, batten.height, "batten", keepOut);
66294
66419
  }
66295
66420
  const t0 = slope.t0 + EDGE2, t1 = slope.t1 - EDGE2;
66296
66421
  const count = Math.max(1, Math.round((t1 - t0) / rafter.spacing));
@@ -66300,7 +66425,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66300
66425
  if (end3 < 0.1) continue;
66301
66426
  const axis2 = slope.point(0, 1)[0] - slope.point(0, 0)[0] !== 0 ? 0 : 2;
66302
66427
  const t = clearOfSolids(at4, rafter.width, down(slope.point(EDGE2, at4), rafter.top), down(slope.point(end3, at4), rafter.top), axis2, solids2);
66303
- addTimberAround(batches.timber, down(slope.point(EDGE2, t), rafter.top), down(slope.point(end3, t), rafter.top), rafter.width, rafter.height, keepOut);
66428
+ addTimberAround(batches.timber, down(slope.point(EDGE2, t), rafter.top), down(slope.point(end3, t), rafter.top), rafter.width, rafter.height, "rafter", keepOut);
66304
66429
  }
66305
66430
  const lines = [slope.wall, slope.wall + (slope.run - slope.wall) / 3, slope.wall + (slope.run - slope.wall) * 2 / 3];
66306
66431
  lines.forEach((s, k) => {
@@ -66310,7 +66435,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66310
66435
  const p0 = down(slope.point(s, a), top), p1 = down(slope.point(s, b), top);
66311
66436
  const depth = Math.min(purlin.height, p0[1] - slabTop - 3e-3);
66312
66437
  if (depth < 0.02) return;
66313
- addTimberAround(batches.timber, p0, p1, k === 0 ? purlin.width - PLATE_NARROWER : purlin.width, depth, keepOut, k === 0 ? void 0 : (end3) => addPost(batches.timber, end3[0], end3[2], slabTop, end3[1] - purlin.height));
66438
+ addTimberAround(batches.timber, p0, p1, k === 0 ? purlin.width - PLATE_NARROWER : purlin.width, depth, "purlin", keepOut, k === 0 ? void 0 : (end3) => addPost(batches.timber, end3[0], end3[2], slabTop, end3[1] - purlin.height));
66314
66439
  if (k === 0) return;
66315
66440
  const posts = Math.max(1, Math.ceil((b - a) / TIMBER.post.spacing));
66316
66441
  for (let j = 0; j <= posts; j++) {
@@ -66342,10 +66467,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66342
66467
  }
66343
66468
  return out;
66344
66469
  }
66345
- function buildRoofFramingStage(THREE, roofRects, material, solids2 = [], keepOut = []) {
66470
+ function buildRoofFramingStage(THREE, roofRects, material, solids2 = [], keepOut = [], onPiece) {
66346
66471
  const group = new THREE.Group();
66347
66472
  group.name = "stage:7:roof_framing";
66348
66473
  const timber = new BoxBatch(), battens = new BoxBatch();
66474
+ if (onPiece) {
66475
+ LOGS.set(timber, new TimberLog("roof_timber", onPiece));
66476
+ LOGS.set(battens, new TimberLog("roof_batten", onPiece));
66477
+ }
66349
66478
  for (const rr of roofRects) {
66350
66479
  if (rr.slab || rr.yb === void 0 || rr.tp === void 0 || !rr.exterior || rr.rm === void 0 || rr.alongX === void 0) continue;
66351
66480
  const rect = { yb: rr.yb, tp: rr.tp, exterior: rr.exterior, rm: rr.rm, alongX: rr.alongX, r: rr.r, gable: !!rr.gable };
@@ -66356,7 +66485,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66356
66485
  const xm = (x0 + x1) / 2, zm = (z0 + z1) / 2;
66357
66486
  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]];
66358
66487
  const ridgeTop = TIMBER.purlin.top;
66359
- addTimberAround(timber, down(ends[0], ridgeTop), down(ends[1], ridgeTop), TIMBER.purlin.width, TIMBER.purlin.height, keepOut, (end3) => addPost(timber, end3[0], end3[2], slabTop, end3[1] - TIMBER.purlin.height));
66488
+ 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));
66360
66489
  const along2 = Math.hypot(ends[1][0] - ends[0][0], ends[1][2] - ends[0][2]);
66361
66490
  const posts = Math.max(1, Math.ceil(along2 / TIMBER.post.spacing));
66362
66491
  for (let j = 0; j <= posts; j++) {
@@ -66372,12 +66501,17 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66372
66501
  const corners = [[x0 + e, h, z0 + e], [x1 - e, h, z0 + e], [x0 + e, h, z1 - e], [x1 - e, h, z1 - e]];
66373
66502
  for (const c of corners) {
66374
66503
  const end3 = Math.hypot(c[0] - ends[0][0], c[2] - ends[0][2]) <= Math.hypot(c[0] - ends[1][0], c[2] - ends[1][2]) ? ends[0] : ends[1];
66375
- addTimberAround(timber, down(c, TIMBER.hip.top), down(end3, TIMBER.hip.top), TIMBER.hip.width, TIMBER.hip.height, keepOut);
66504
+ addTimberAround(timber, down(c, TIMBER.hip.top), down(end3, TIMBER.hip.top), TIMBER.hip.width, TIMBER.hip.height, "hip", keepOut);
66376
66505
  }
66377
66506
  }
66378
66507
  }
66379
66508
  const wood = material ?? new THREE.MeshStandardMaterial({ color: 11042380, roughness: 0.82 });
66380
- for (const mesh3 of [timber.mesh(THREE, wood, "roof_framing:timber"), battens.mesh(THREE, wood, "roof_framing:battens")]) if (mesh3) group.add(mesh3);
66509
+ for (const mesh3 of [timber.mesh(THREE, wood, "roof_framing:timber"), battens.mesh(THREE, wood, "roof_framing:battens")]) {
66510
+ if (!mesh3) continue;
66511
+ mesh3.userData.constructionStage = "roofFraming";
66512
+ if (onPiece) mesh3.userData.destructionMaterial = ROOF_TIMBER_MATERIAL;
66513
+ group.add(mesh3);
66514
+ }
66381
66515
  return group;
66382
66516
  }
66383
66517
  var HOUSE_SHADOW_BUDGET_MS = 2;
@@ -66420,6 +66554,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66420
66554
  }
66421
66555
  };
66422
66556
  }
66557
+ var ROOF_TIMBER_REACH = 3;
66423
66558
  function withLaidConduits(r, stages) {
66424
66559
  const E = r.utilities?.electrical;
66425
66560
  if (!stages || !E || !E.conduits?.length) return r;
@@ -66477,7 +66612,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66477
66612
  return { u: P.u - Math.sign(P.frontU || 0) * PANEL_RECESS, v: P.v - Math.sign(P.frontV || 0) * PANEL_RECESS, y0: P.y - h / 2 + PANEL_LIFT - BOX_CHASE_CLEAR, y1: P.y + h / 2 + PANEL_LIFT + BOX_CHASE_CLEAR, radius: w / 2, depth: 0 };
66478
66613
  }
66479
66614
  function installBuildBuild(K, shared3) {
66480
- const { THREE, cfg, rectsOf: rectsOf2, invalidateShadow, colliderChanged, VERSION: VERSION2, CARS, EPS: EPS42, LIGHTS, MIRRORS, Y0, animateClotheslines, animateDoors, animateInteractive, applyLeaf, applyOutbuildings, applyPart, applyPiece, assembleInteractive, baseboardAndSidewalk, buildStairs, building, carModel, chooseMirror, closeScene, collideAt, createWater, cursor, doorText, doors, electricalStructure, elevator, floorsAndSlabs, gatesInteractive, houseItems, ivAssemble, ivBuild, ivDispose, ivParts, ivPublish, ivUpdate, lightOn, linkDoorLeaves, mailboxInteractive, newInteractiveState, newMirrorState, outbuildings, paths, perimeter, placeSwitches, roofs, roomAt, solar, targetOf, terrain, toggleDoor, toggleLight, walls, waterPipes, drainPipes, windows, props, TYPES, IVK, VEG, vegMaterials, markGroups, assembleStructure, createHouseDestruction, newState, enter, tagDamage } = K;
66615
+ const { THREE, cfg, rectsOf: rectsOf2, invalidateShadow, colliderChanged, VERSION: VERSION2, CARS, EPS: EPS42, LIGHTS, MIRRORS, Y0, animateClotheslines, animateDoors, animateInteractive, applyLeaf, applyOutbuildings, applyPart, applyPiece, assembleInteractive, baseboardAndSidewalk, buildStairs, building, carModel, chooseMirror, closeScene, collideAt, createWater, cursor, doorText, doors, electricalStructure, elevator, floorsAndSlabs, gatesInteractive, houseItems, ivAssemble, ivBuild, ivDispose, ivParts, ivPublish, ivUpdate, lightOn, linkDoorLeaves, mailboxInteractive, newInteractiveState, newMirrorState, outbuildings, paths, perimeter, placeSwitches, roofs, roomAt, solar, targetOf, terrain, toggleDoor, toggleLight, walls, waterPipes, drainPipes, windows, props, TYPES, IVK, VEG, vegMaterials, markGroups, assembleStructure, pieceRecord, createHouseDestruction, newState, enter, tagDamage } = K;
66481
66616
  function build(r0, options) {
66482
66617
  const opts = options || {};
66483
66618
  const r = withLaidConduits(applyOutbuildings(r0), !!(opts.constructionStages || opts.constructionLevel != null));
@@ -66495,6 +66630,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66495
66630
  shared3.ctx.colliders = [];
66496
66631
  shared3.ctx.stairs = [];
66497
66632
  shared3.ctx.noTerrain = opts.terrain === false;
66633
+ shared3.ctx.noGroundSurfaces = opts.groundSurfaces === false;
66498
66634
  shared3.ctx.serviceFrom = opts.serviceFrom ?? null;
66499
66635
  shared3.ctx.roomById = {};
66500
66636
  for (const c of r.rooms) shared3.ctx.roomById[c.id] = c;
@@ -66646,6 +66782,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66646
66782
  (k === "floor" || k === "building" ? root : house).add(g);
66647
66783
  }
66648
66784
  let currentConstructionLevel = CONSTRUCTION_LEVEL_MAX;
66785
+ let partStages = null, stageOptsNow = {}, piecesStaged = -1;
66786
+ const stageHeld = /* @__PURE__ */ new Set();
66649
66787
  h.groups = gs;
66650
66788
  h.root = root;
66651
66789
  h.house = house;
@@ -66826,22 +66964,34 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66826
66964
  return house.localToWorld(localCenter.clone());
66827
66965
  };
66828
66966
  const distance4 = (focus) => center().distanceTo(focus instanceof THREE.Vector3 ? focus : new THREE.Vector3(focus.x, focus.y, focus.z));
66829
- markGroups(r, root, parts2);
66830
- const structure = assembleStructure(r0, root), destruction = createHouseDestruction(root, house, structure, parts2, colliders, water);
66831
- h.destruction = destruction;
66832
- destruction.breach.setLod(h.lodCurrent);
66833
66967
  if (cs) {
66834
66968
  const bp = buildBlueprintStage(THREE, K.DOC, r, rectsOf2);
66835
66969
  const stGroups = buildStructuralStageGroups(THREE, r0.structure, r.outbuildings || [], [...embeddedRunsOf(house), ...wallBoxRunsOf(r, shared3.ctx.wallBoxShifts)], shared3.ctx.blockLaid ?? []);
66836
66970
  const instGroup = buildInstallationsStage(THREE, r, shared3.ctx.gutterInfo?.drains ?? [], shared3.ctx.paving ?? []);
66837
- const roofFraming = buildRoofFramingStage(THREE, shared3.ctx.roofRects || [], void 0, [...shared3.ctx.occupied ?? [], ...bareBoxesOf(THREE, [stGroups.frame, stGroups.masonry])], [...atticKeepOut(THREE, house, Object.values(parts2)), ...gutterKeepOut(shared3.ctx.gutterInfo?.gutters ?? [])]);
66971
+ const roofFraming = buildRoofFramingStage(THREE, shared3.ctx.roofRects || [], void 0, [...shared3.ctx.occupied ?? [], ...bareBoxesOf(THREE, [stGroups.frame, stGroups.masonry])], [...atticKeepOut(THREE, house, Object.values(parts2)), ...gutterKeepOut(shared3.ctx.gutterInfo?.gutters ?? [])], (t) => {
66972
+ pieceRecord(t.id, ROOF_TIMBER_MATERIAL, null, { holdOn: t.kind === "post" ? "floor" : "wall", holdReach: ROOF_TIMBER_REACH, holdJoint: "nail", mass: t.mass, tags: ["roof_timber", t.kind], ...t.chain.length ? { chain: t.chain } : {} });
66973
+ });
66838
66974
  const yardBoxes = instGroup.userData.yardBoxes;
66839
66975
  for (const sg of [bp, stGroups.foundation, stGroups.starterBars, stGroups.frame, stGroups.masonry, instGroup, ...yardBoxes ? [yardBoxes] : [], roofFraming]) {
66840
66976
  gs[sg.name] = sg;
66841
66977
  house.add(sg);
66842
66978
  }
66843
- currentConstructionLevel = applyConstructionLevel(house, opts.constructionLevel ?? CONSTRUCTION_LEVEL_MAX);
66844
66979
  }
66980
+ markGroups(r, root, parts2);
66981
+ const structure = assembleStructure(r0, root), destruction = createHouseDestruction(root, house, structure, parts2, colliders, water);
66982
+ h.destruction = destruction;
66983
+ destruction.breach.setLod(h.lodCurrent);
66984
+ if (cs) {
66985
+ currentConstructionLevel = applyConstructionLevel(house, opts.constructionLevel ?? CONSTRUCTION_LEVEL_MAX);
66986
+ partStages = partStagesOf(house);
66987
+ }
66988
+ const stagePieces = () => {
66989
+ const R = destruction.renderer;
66990
+ if (!partStages || !R?.pieces) return;
66991
+ const list2 = R.pieces();
66992
+ piecesStaged = list2.length;
66993
+ stageLoosePieces(list2, partStages, currentConstructionLevel, stageOptsNow, stageHeld);
66994
+ };
66845
66995
  const strikePiece = (id, point, type, amount, d, before) => {
66846
66996
  if (!destruction.world) return;
66847
66997
  const pid = id && structure.byId.has(id) ? id : parts2[id] && parts2[id].type === "water_tank" && structure.byId.has("water_tank") ? "water_tank" : null;
@@ -66923,6 +67073,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66923
67073
  // per frame: doors, parts, wind-blown laundry and (with a focus) distance LOD; dt in seconds, time in ms (rAF); focus = {x,y,z} in world coordinates
66924
67074
  update(dt, time, focus) {
66925
67075
  enter(h);
67076
+ if (partStages && currentConstructionLevel < CONSTRUCTION_LEVEL_MAX && destruction.renderer?.pieces && destruction.renderer.pieces().length !== piecesStaged) stagePieces();
66926
67077
  animateDoors(dt);
66927
67078
  animateInteractive(dt);
66928
67079
  water.step(dt);
@@ -66956,12 +67107,16 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66956
67107
  g.visible = v;
66957
67108
  }
66958
67109
  if (cs && currentConstructionLevel < CONSTRUCTION_LEVEL_MAX) {
66959
- applyConstructionLevel(house, currentConstructionLevel, { roofLayer: !cut && sel < 0, lotLayer: o.lot !== false });
67110
+ stageOptsNow = { roofLayer: !cut && sel < 0, lotLayer: o.lot !== false };
67111
+ applyConstructionLevel(house, currentConstructionLevel, stageOptsNow);
67112
+ stagePieces();
66960
67113
  }
66961
67114
  },
66962
67115
  setConstructionLevel(level, stageOpts) {
66963
67116
  enter(h);
67117
+ stageOptsNow = stageOpts ?? {};
66964
67118
  currentConstructionLevel = applyConstructionLevel(house, level, stageOpts);
67119
+ stagePieces();
66965
67120
  invalidateShadow();
66966
67121
  return currentConstructionLevel;
66967
67122
  },
@@ -67334,6 +67489,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
67334
67489
  }
67335
67490
  var FLOOR_TOUCH2 = 5e-3;
67336
67491
  var LOOSE = /* @__PURE__ */ new Set(["paper"]);
67492
+ var PLANTED = /* @__PURE__ */ new Set(["mailbox", "correio", "clothesline", "tree_small", "bbq_simple"]);
67337
67493
  var BASE_MATERIAL = {
67338
67494
  wood: "wood_hard",
67339
67495
  metal: "steel",
@@ -67445,7 +67601,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
67445
67601
  const wallMounted = parts2.some((part) => part.anchored && low(part) > FLOOR_TOUCH2);
67446
67602
  const sunk = parts2.some((part) => low(part) < -FLOOR_TOUCH2);
67447
67603
  const rooted = parts2.some((part) => part.material === "foliage") && parts2.some((part) => part.material.startsWith("wood") && low(part) <= FLOOR_TOUCH2);
67448
- const fixed2 = wallMounted || sunk || rooted;
67604
+ const fixed2 = wallMounted || sunk || rooted || PLANTED.has(name);
67449
67605
  const all = drawn.reduce(
67450
67606
  (m, p) => ({ x0: Math.min(m.x0, p.min[0]), x1: Math.max(m.x1, p.max[0]), z0: Math.min(m.z0, p.min[2]), z1: Math.max(m.z1, p.max[2]) }),
67451
67607
  { x0: Infinity, x1: -Infinity, z0: Infinity, z1: -Infinity }
@@ -98065,7 +98221,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
98065
98221
  }
98066
98222
  var DEGREES = 180 / Math.PI;
98067
98223
 
98068
- // ../game-vfx-three/dist/chunk-GHLGSWLP.js
98224
+ // ../game-vfx-three/dist/chunk-EE6XER4D.js
98069
98225
  var GLOW_VERTEX = `attribute vec4 aP;attribute vec4 aC;varying vec2 vU;varying vec4 vC;
98070
98226
  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]);
98071
98227
  vec3 wp=aP.xyz+(R*position.x+Up*position.y)*aP.w;vU=position.xy;vC=aC;gl_Position=projectionMatrix*viewMatrix*vec4(wp,1.);}`;
@@ -98081,21 +98237,22 @@ float vn(vec3 x){vec3 i=floor(x),f=fract(x);f=f*f*(3.-2.*f);
98081
98237
  `;
98082
98238
  var PUFF_VERTEX = `${GL_NOISE}
98083
98239
  attribute vec4 aP;attribute vec4 aD;attribute vec3 aC;
98084
- varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;
98240
+ varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;varying vec3 vN;
98085
98241
  void main(){
98086
98242
  vec3 p=position;
98243
+ vec3 q=normalize(position);
98087
98244
  float s=aD.z;
98088
98245
  float n=vn(p*1.6+vec3(s*11.0,s*7.0,s*3.0));
98089
98246
  p*=0.78+0.5*n;
98090
- float a=s*6.2831;float c=cos(a),si=sin(a);p.xz=mat2(c,-si,si,c)*p.xz;
98091
- vL=p;
98247
+ 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;
98248
+ vL=p;vN=q;
98092
98249
  vec3 wp=aP.xyz+p*aP.w;
98093
98250
  vWP=wp;vD=aD;vC=aC;
98094
98251
  gl_Position=projectionMatrix*viewMatrix*vec4(wp,1.0);
98095
98252
  }`;
98096
98253
  var PUFF_FRAGMENT = `${GL_NOISE}
98097
98254
  uniform vec3 uLight;uniform vec3 uSky;uniform vec3 uGround;uniform vec3 uGlowPos;uniform vec3 uGlowCol;uniform float uGlowI;
98098
- varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;
98255
+ varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;varying vec3 vN;
98099
98256
  vec3 L(vec3 c){return pow(c,vec3(2.2));}
98100
98257
  vec3 ramp(float h){
98101
98258
  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));
@@ -98105,30 +98262,35 @@ vec3 ramp(float h){
98105
98262
  return mix(c3,c4,clamp((h-.8)/.4,0.,1.));
98106
98263
  }
98107
98264
  void main(){
98108
- vec3 N=normalize(cross(dFdx(vWP),dFdy(vWP)));
98109
98265
  float age=vD.x,heat=vD.y,kind=vD.w;
98110
98266
  float n=vn(vL*2.4+vD.z*13.0);
98111
- float diss=smoothstep(.5,1.,age);
98112
- if(n<diss*1.08-.04)discard;
98267
+ // the sphere's own normal, roughened by the noise: a billowing cloud, never facets
98268
+ vec3 g=vec3(vn(vL*3.1+vD.z*5.0),vn(vL*3.1+vD.z*5.0+7.3),vn(vL*3.1+vD.z*5.0+13.7))-.5;
98269
+ vec3 N=normalize(normalize(vN)+g*.9);
98270
+ vec3 V=normalize(cameraPosition-vWP);
98113
98271
  float lam=max(dot(N,uLight),0.);
98114
- float band=lam>.55?1.:lam>.15?.68:.42;
98115
- // soot: a dark smoke still scatters some light, so it never goes flat black, and its rim takes the sky so its volume reads (only the dark puffs; the rest as the Lab)
98272
+ float light=.42+.62*smoothstep(-.1,.9,lam);
98116
98273
  float dark=1.-smoothstep(.02,.12,dot(vC,vec3(.2126,.7152,.0722)));
98117
98274
  vec3 alb=max(vC,vec3(.055)*dark);
98118
- vec3 col=alb*(vec3(.5,.56,.7)*band*1.05+vec3(.2,.19,.18)+uGround*(.4-.4*N.y));
98119
- float rim=pow(1.-clamp(abs(dot(N,normalize(cameraPosition-vWP))),0.,1.),2.);
98275
+ vec3 col=alb*(vec3(.5,.56,.7)*light*1.05+vec3(.2,.19,.18)+uGround*(.4-.4*N.y));
98276
+ float rim=pow(1.-clamp(abs(dot(normalize(vN),V)),0.,1.),2.);
98120
98277
  col+=dark*rim*(uSky*.9+alb);
98121
98278
  vec3 tg=uGlowPos-vWP;float dg=length(tg)+.001;
98122
98279
  float gi=uGlowI/(1.+dg*dg*.05)*(.3+.7*max(dot(N,tg/dg),0.));
98123
98280
  col+=uGlowCol*gi*alb*1.6;
98281
+ // seen through: thin where the camera grazes the puff, thicker where the noise is, thinning out with age
98282
+ float facing=abs(dot(normalize(vN),V));
98283
+ float alpha=smoothstep(.0,.75,facing)*(.35+.65*smoothstep(.2,.8,n))*(1.-smoothstep(.3,1.,age))*.78;
98124
98284
  float h=heat*(.72+.56*n)+heat*(-N.y)*.18;
98125
98285
  if(h>.05){
98126
- float hq=floor(h*5.+.5)/5.;
98127
- vec3 fc=ramp(clamp(hq,0.,1.2))*(1.1+3.1*hq);
98128
- col=mix(col,fc,smoothstep(.04,.2,h));
98286
+ vec3 fc=ramp(clamp(h,0.,1.2))*(1.1+3.1*h);
98287
+ float hot=smoothstep(.04,.2,h);
98288
+ col=mix(col,fc,hot);
98289
+ alpha=max(alpha,hot*smoothstep(.0,.45,facing)*(1.-smoothstep(.5,1.,age)));
98129
98290
  }
98130
98291
  if(kind>2.5&&kind<3.5){col+=vec3(.02,.025,.03);}
98131
- gl_FragColor=vec4(col,1.);
98292
+ if(alpha<.01)discard;
98293
+ gl_FragColor=vec4(col,alpha);
98132
98294
  #include <tonemapping_fragment>
98133
98295
  #include <colorspace_fragment>
98134
98296
  }`;
@@ -98163,10 +98325,11 @@ void main(){
98163
98325
  function dynamic(THREE, array, size) {
98164
98326
  return new THREE.InstancedBufferAttribute(array, size).setUsage(THREE.DynamicDrawUsage);
98165
98327
  }
98328
+ var PUFF_DETAIL = 2;
98166
98329
  function createPuffLayer(THREE, pool, uniforms) {
98167
98330
  const capacity = pool.capacity;
98168
98331
  const geometry = new THREE.InstancedBufferGeometry();
98169
- geometry.setAttribute("position", new THREE.IcosahedronGeometry(1, 1).getAttribute("position"));
98332
+ geometry.setAttribute("position", new THREE.IcosahedronGeometry(1, PUFF_DETAIL).getAttribute("position"));
98170
98333
  const a = new Float32Array(capacity * 4);
98171
98334
  const d = new Float32Array(capacity * 4);
98172
98335
  const c = new Float32Array(capacity * 3);
@@ -98175,7 +98338,7 @@ void main(){
98175
98338
  geometry.setAttribute("aD", attributes[1]);
98176
98339
  geometry.setAttribute("aC", attributes[2]);
98177
98340
  geometry.instanceCount = 0;
98178
- const material = new THREE.ShaderMaterial({ uniforms, vertexShader: PUFF_VERTEX, fragmentShader: PUFF_FRAGMENT });
98341
+ const material = new THREE.ShaderMaterial({ uniforms, vertexShader: PUFF_VERTEX, fragmentShader: PUFF_FRAGMENT, transparent: true, depthWrite: false });
98179
98342
  const mesh3 = new THREE.Mesh(geometry, material);
98180
98343
  mesh3.name = "vfx-puffs";
98181
98344
  mesh3.frustumCulled = false;
@@ -99804,11 +99967,13 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
99804
99967
  var LOOSE_ROLLING_RESISTANCE = 0.015;
99805
99968
  var CASING_FILL = 0.25;
99806
99969
  var BRASS_DENSITY = 8500;
99807
- var LOOSE_USER = { casing: 100 };
99970
+ var GRENADE_MASS_KG = 0.4;
99971
+ var LOOSE_USER = { casing: 100, grenade: 2 };
99808
99972
  var BOUNCE_FALL_SPEED = 0.5;
99809
99973
  var BOUNCE_RISE_SPEED = 0.2;
99810
99974
  var QUARTER_TURN_Z = [0, 0, Math.SQRT1_2, Math.SQRT1_2];
99811
99975
  var CASING_MATERIAL = { frictionStatic: 0.4, frictionDynamic: 0.3, restitution: 0.4 };
99976
+ var GRENADE_MATERIAL = { frictionStatic: 0.6, frictionDynamic: 0.5, restitution: 0.35 };
99812
99977
  function casingCollider(radius, length2) {
99813
99978
  return {
99814
99979
  shape: { kind: "compound", children: [{ shape: { kind: "cylinder", halfHeight: length2 / 2, radius }, position: [0, 0, 0], rotation: QUARTER_TURN_Z }] },
@@ -99818,6 +99983,28 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
99818
99983
  user: LOOSE_USER.casing
99819
99984
  };
99820
99985
  }
99986
+ function explosiveCollider(THREE, explosive) {
99987
+ if (explosive !== "m67") return void 0;
99988
+ const model = buildExplosiveModel(THREE, explosive);
99989
+ if (!model) return void 0;
99990
+ const centre = new THREE.Box3().setFromObject(model).getCenter(new THREE.Vector3());
99991
+ const { bodyRadius, fuze, spoon } = M67_PARTS;
99992
+ const at4 = (x, y) => [x - centre.x, y + bodyRadius - centre.y, 0 - centre.z];
99993
+ return {
99994
+ shape: {
99995
+ kind: "compound",
99996
+ children: [
99997
+ { shape: { kind: "sphere", radius: bodyRadius }, position: at4(0, 0) },
99998
+ { shape: { kind: "cylinder", halfHeight: fuze.height / 2, radius: fuze.radius }, position: at4(0, fuze.y) },
99999
+ { shape: { kind: "box", half: [spoon.size[0] / 2, spoon.size[1] / 2, spoon.size[2] / 2] }, position: at4(spoon.x, spoon.y), rotation: [0, 0, Math.sin(spoon.tilt / 2), Math.cos(spoon.tilt / 2)] }
100000
+ ]
100001
+ },
100002
+ mass: GRENADE_MASS_KG,
100003
+ material: GRENADE_MATERIAL,
100004
+ rolling: { coefficient: LOOSE_ROLLING_RESISTANCE, radius: bodyRadius },
100005
+ user: LOOSE_USER.grenade
100006
+ };
100007
+ }
99821
100008
  function spawnLoose(world, collider, launch) {
99822
100009
  const desc = {
99823
100010
  shape: collider.shape,