@adatechnology/game-items-three 0.10.3 → 0.10.5

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.
@@ -16100,37 +16100,37 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
16100
16100
  if (shape.kind === "cylinder") return [shape.radius, shape.height / 2, shape.radius];
16101
16101
  return [shape.radius, shape.radius, shape.radius];
16102
16102
  };
16103
- var hostedSolids = (spec, state, pose) => {
16103
+ var hostedSolids = (spec, state, pose3) => {
16104
16104
  const byId = new Map((state?.parts ?? []).map((p) => [p.id, p]));
16105
16105
  const out = [];
16106
16106
  for (const ps of spec.parts) {
16107
16107
  const st = byId.get(ps.id);
16108
16108
  if (st && (GONE.has(st.status) || st.group !== 0)) continue;
16109
- const ov = pose.poses.get(ps.id);
16110
- const center = toWorld(pose.position, pose.rotation, ov?.pos ?? ps.position);
16111
- const rotation = quat.mul(pose.rotation, ov?.q ?? quatFromEuler(...ps.rotation ?? [0, 0, 0]));
16109
+ const ov = pose3.poses.get(ps.id);
16110
+ const center = toWorld(pose3.position, pose3.rotation, ov?.pos ?? ps.position);
16111
+ const rotation = quat.mul(pose3.rotation, ov?.q ?? quatFromEuler(...ps.rotation ?? [0, 0, 0]));
16112
16112
  out.push({ center, half: halfOf(ps.shape), rotation });
16113
16113
  }
16114
16114
  return out;
16115
16115
  };
16116
16116
  var placedPieces = /* @__PURE__ */ new WeakMap();
16117
16117
  var isSamePose = ({ known, position, rotation }) => known.position[0] === position[0] && known.position[1] === position[1] && known.position[2] === position[2] && known.rotation[0] === rotation[0] && known.rotation[1] === rotation[1] && known.rotation[2] === rotation[2] && known.rotation[3] === rotation[3];
16118
- var hostedPieces = (pieces, pose) => pieces.map((piece2, index) => {
16118
+ var hostedPieces = (pieces, pose3) => pieces.map((piece2, index) => {
16119
16119
  const known = placedPieces.get(piece2);
16120
- const p = pose.position, q = pose.rotation;
16120
+ const p = pose3.position, q = pose3.rotation;
16121
16121
  const isSamePlace = known !== void 0 && (piece2.key !== void 0 || known.index === index) && isSamePose({ known, position: p, rotation: q });
16122
16122
  if (known && isSamePlace) return known.solid;
16123
- const solid = placedPiece(piece2, index, pose);
16123
+ const solid = placedPiece(piece2, index, pose3);
16124
16124
  placedPieces.set(piece2, { position: [p[0], p[1], p[2]], rotation: [q[0], q[1], q[2], q[3]], index, solid });
16125
16125
  return solid;
16126
16126
  });
16127
- var placedPiece = (piece2, index, pose) => {
16128
- const base = { center: toWorld(pose.position, pose.rotation, piece2.center), half: piece2.half, rotation: quat.mul(pose.rotation, piece2.rotation), key: piece2.key ?? `${piece2.id}:${index}` };
16127
+ var placedPiece = (piece2, index, pose3) => {
16128
+ const base = { center: toWorld(pose3.position, pose3.rotation, piece2.center), half: piece2.half, rotation: quat.mul(pose3.rotation, piece2.rotation), key: piece2.key ?? `${piece2.id}:${index}` };
16129
16129
  if (!piece2.mesh) return base;
16130
16130
  const source = piece2.mesh.vertices;
16131
16131
  const vertices = new Float32Array(source.length);
16132
16132
  for (let i = 0; i < source.length; i += 3) {
16133
- const world = toWorld(pose.position, pose.rotation, [source[i], source[i + 1], source[i + 2]]);
16133
+ const world = toWorld(pose3.position, pose3.rotation, [source[i], source[i + 1], source[i + 2]]);
16134
16134
  vertices[i] = world[0];
16135
16135
  vertices[i + 1] = world[1];
16136
16136
  vertices[i + 2] = world[2];
@@ -19891,6 +19891,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19891
19891
  return reach2;
19892
19892
  };
19893
19893
  let blastTntPerJoule = TNT_PER_JOULE;
19894
+ let blastHasCharge = false;
19894
19895
  let blastFireball = chargeFireball(0);
19895
19896
  const burstFuel = (p) => {
19896
19897
  const c = p.spec.contains;
@@ -19995,7 +19996,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19995
19996
  }
19996
19997
  for (const im of [...impls.values()]) {
19997
19998
  if (!implInRange(im, point, radius)) continue;
19998
- out.push(implHit(im, { type: "explosive", point, energy, radius, fireball: blastFireball, tnt: energy * blastTntPerJoule, ...lethal !== void 0 ? { lethalRadius: lethal } : {}, ...src !== void 0 ? { source: src } : {} }));
19999
+ 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 } : {} }));
19999
20000
  yield "part";
20000
20001
  }
20001
20002
  return out;
@@ -20120,7 +20121,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
20120
20121
  den += f;
20121
20122
  }
20122
20123
  const k = den > 0 ? num2 / den : 1;
20123
- 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 } : {} });
20124
+ 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 } : {} });
20124
20125
  results.set(im, res);
20125
20126
  report(im).shelter = k;
20126
20127
  }
@@ -20462,13 +20463,16 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
20462
20463
  const fireball = charge?.fuel ? fuelFireball(charge.fuel) : chargeFireball(energy * tntPerJoule);
20463
20464
  const inBlast = (fn) => {
20464
20465
  const outer = blastTntPerJoule;
20466
+ const outerHasCharge = blastHasCharge;
20465
20467
  const outerFireball = blastFireball;
20466
20468
  blastTntPerJoule = tntPerJoule;
20469
+ blastHasCharge = charge?.tnt !== void 0;
20467
20470
  blastFireball = fireball;
20468
20471
  try {
20469
20472
  return fn();
20470
20473
  } finally {
20471
20474
  blastTntPerJoule = outer;
20475
+ blastHasCharge = outerHasCharge;
20472
20476
  blastFireball = outerFireball;
20473
20477
  }
20474
20478
  };
@@ -23950,6 +23954,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
23950
23954
  return ((t ^ t >>> 14) >>> 0) / 4294967296;
23951
23955
  };
23952
23956
  }
23957
+ var pose = new Float64Array(7);
23958
+ var pose2 = new Float64Array(7);
23953
23959
 
23954
23960
  // ../game-items/dist/index.js
23955
23961
  var DEFAULT_RULES = {
@@ -45441,8 +45447,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
45441
45447
  }
45442
45448
  }
45443
45449
  connect(e, spec, valves);
45444
- const pose = at(e.item);
45445
- world.add(e.id, spec, { x: pose.x, y: e.floorY, z: pose.z, ry: pose.ry });
45450
+ const pose3 = at(e.item);
45451
+ world.add(e.id, spec, { x: pose3.x, y: e.floorY, z: pose3.z, ry: pose3.ry });
45446
45452
  out.added++;
45447
45453
  if (!isBlocked) continue;
45448
45454
  for (const p of spec.parts || []) {
@@ -46649,7 +46655,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
46649
46655
  }
46650
46656
  var residentialTower = residentialTowerTemplate();
46651
46657
 
46652
- // ../game-floorplan-three/dist/chunk-W4VG2X7N.js
46658
+ // ../game-floorplan-three/dist/chunk-EYIWURKO.js
46653
46659
  var __defProp3 = Object.defineProperty;
46654
46660
  var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp3(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
46655
46661
  var __publicField = (obj, key2, value) => __defNormalProp(obj, typeof key2 !== "symbol" ? key2 + "" : key2, value);
@@ -48697,7 +48703,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48697
48703
  }
48698
48704
  function paths() {
48699
48705
  const lt = shared2.ctx.r.lot;
48700
- if (!lt || !lt.paths) return;
48706
+ if (!lt || !lt.paths || shared2.ctx.noGroundSurfaces) return;
48701
48707
  cursor.group = "lot";
48702
48708
  for (const c of lt.paths) {
48703
48709
  if (c.type === "vehicle" && c.id !== "cargo_path") continue;
@@ -49991,6 +49997,18 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
49991
49997
  __publicField(this, "positions", []);
49992
49998
  __publicField(this, "normals", []);
49993
49999
  __publicField(this, "indices", []);
50000
+ __publicField(this, "ranges", []);
50001
+ }
50002
+ /** What is added from here on, up to the next call, is the piece `id` (null: no piece). */
50003
+ piece(id) {
50004
+ const v = this.positions.length / 3, i = this.indices.length;
50005
+ const last = this.ranges[this.ranges.length - 1];
50006
+ if (last && last.v1 < 0) {
50007
+ last.v1 = v;
50008
+ last.i1 = i;
50009
+ if (last.v1 === last.v0) this.ranges.pop();
50010
+ }
50011
+ if (id !== null) this.ranges.push({ id, v0: v, v1: -1, i0: i, i1: -1 });
49994
50012
  }
49995
50013
  get count() {
49996
50014
  return this.indices.length / 36;
@@ -50011,12 +50029,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
50011
50029
  }
50012
50030
  /**
50013
50031
  * 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
50014
- * face is wound to look out of the solid.
50032
+ * 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).
50015
50033
  */
50016
- addHexahedron(corners) {
50034
+ addHexahedron(corners, open = {}) {
50017
50035
  if (corners.length !== 8) return;
50018
50036
  const centre = [0, 1, 2].map((k) => corners.reduce((sum, c) => sum + c[k], 0) / 8);
50019
50037
  for (const quad of HEXAHEDRON_FACES) {
50038
+ if (open.start && quad === HEXAHEDRON_FACES[0] || open.end && quad === HEXAHEDRON_FACES[1]) continue;
50020
50039
  const a = corners[quad[0]], b = corners[quad[1]], c = corners[quad[2]], d = corners[quad[3]];
50021
50040
  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]];
50022
50041
  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]];
@@ -50051,6 +50070,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
50051
50070
  /** The mesh of everything added, or null when nothing was. */
50052
50071
  mesh(THREE, material, name) {
50053
50072
  if (!this.indices.length) return null;
50073
+ this.piece(null);
50054
50074
  const geometry = new THREE.BufferGeometry();
50055
50075
  geometry.setAttribute("position", new THREE.Float32BufferAttribute(this.positions, 3));
50056
50076
  geometry.setAttribute("normal", new THREE.Float32BufferAttribute(this.normals, 3));
@@ -50061,6 +50081,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
50061
50081
  mesh2.name = name;
50062
50082
  mesh2.castShadow = true;
50063
50083
  mesh2.receiveShadow = true;
50084
+ if (this.ranges.length) mesh2.userData.ranges = this.ranges.map((range2) => ({ ...range2 }));
50064
50085
  return mesh2;
50065
50086
  }
50066
50087
  };
@@ -50069,7 +50090,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
50069
50090
  var FEED_Y = -0.6;
50070
50091
  var FEED_EXIT_Y = -0.15;
50071
50092
  var FEED_BOX_OFFSET = 0.25;
50072
- var BRICK_FACE_INSET = 0.014;
50093
+ function chaseDepth(diameter = CHASE_DIAMETER) {
50094
+ return PLASTER_PER_FACE + CHASE_CLEAR + diameter;
50095
+ }
50096
+ var CHASE_DIAMETER = 0.025;
50097
+ var CHASE_CLEAR = 6e-3;
50073
50098
  var SLAB_MIDDLE = 0.065;
50074
50099
  var CEILING_SLAB = 0.5;
50075
50100
  var PASSING_END_CLEAR = { water: 0.335, conduit: 0.485 };
@@ -50126,7 +50151,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
50126
50151
  const inward = (alongU ? (box4[1] + box4[3]) / 2 : (box4[0] + box4[2]) / 2) - line;
50127
50152
  const side = Math.abs(across2) > 1e-3 ? Math.sign(across2) : inward >= 0 ? 1 : -1;
50128
50153
  const half = (wall.thickness ?? DEFAULT_THICKNESS) / 2;
50129
- const offset = options.surface ? half + (options.diameter ?? 0.02) / 2 : half - BRICK_FACE_INSET;
50154
+ const offset = options.surface ? half + (options.diameter ?? 0.02) / 2 : half - chaseDepth(options.diameter);
50130
50155
  const at2 = line + side * offset;
50131
50156
  return { u: alongU ? along2 : at2, v: alongU ? at2 : along2, wall };
50132
50157
  }
@@ -50802,6 +50827,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
50802
50827
  }
50803
50828
  var PIPE_WALL_FILL = 0.3;
50804
50829
  var WALL_PIPE_MASS = 3;
50830
+ var UNDER_SINK_RISER_OFF_WALL = 0.08;
50831
+ var UNDER_SINK_VALVE_RISE = 0.1;
50805
50832
  var pipeMass = (diameter, length) => DENSITY.plastic * Math.PI * (diameter / 2) ** 2 * length * PIPE_WALL_FILL;
50806
50833
  function installUtilitiesWater(K, shared2) {
50807
50834
  const { THREE, _Y, _q, cursor, cylBase, part, pieceRecord, put } = K;
@@ -51001,7 +51028,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
51001
51028
  }
51002
51029
  }
51003
51030
  function underSink(tr) {
51004
- const H = shared2.ctx.r.utilities?.plumbing, nA = shared2.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;
51031
+ const H = shared2.ctx.r.utilities?.plumbing, nA = shared2.ctx.r.floors.length, pt = H && H.points.find((p) => p.id === tr.to), d = tr.diameter || 0.025;
51032
+ const pts = riserUnderBack(tr.points.map((p) => [p[0], p[2], p[1]]));
51005
51033
  const stage = cursor.stage;
51006
51034
  if (shared2.ctx.constructionStages) cursor.stage = "furniture";
51007
51035
  cursor.group = pt && pt.floor >= 0 ? "f" + Math.min(pt.floor, nA - 1) : "lot";
@@ -51013,6 +51041,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
51013
51041
  cursor.pc = null;
51014
51042
  cursor.stage = stage;
51015
51043
  }
51044
+ function riserUnderBack(pts) {
51045
+ if (pts.length < 3 || shared2.ctx.visorScene) return pts;
51046
+ const wall = pts[0], mid = pts[1], dx = mid[0] - wall[0], dz = mid[2] - wall[2], L = Math.hypot(dx, dz);
51047
+ if (L <= UNDER_SINK_RISER_OFF_WALL) return pts;
51048
+ const x = wall[0] + dx / L * UNDER_SINK_RISER_OFF_WALL, z = wall[2] + dz / L * UNDER_SINK_RISER_OFF_WALL;
51049
+ const top = mid[1] + UNDER_SINK_VALVE_RISE;
51050
+ return [wall, ...pts.slice(1).map((p) => [x, Math.min(p[1], top), z])];
51051
+ }
51016
51052
  const defined = { createWater, PIPE_COLOR, pipe, _v3, waterPipes };
51017
51053
  Object.assign(K, defined);
51018
51054
  }
@@ -51359,15 +51395,15 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
51359
51395
  const aabb = wall.alongU ? [solid.aabb[0], line - width / 2, solid.aabb[2], line + width / 2] : [line - width / 2, solid.aabb[1], line + width / 2, solid.aabb[3]];
51360
51396
  return { ...solid, aabb };
51361
51397
  }
51362
- var CHASE_CLEAR = 3e-3;
51398
+ var CHASE_CLEAR2 = 3e-3;
51363
51399
  function chasesIn(wall, core, runs) {
51364
51400
  const out = [];
51365
51401
  for (const r of runs) {
51366
51402
  const along2 = wall.alongU ? r.u : r.v, across2 = (wall.alongU ? r.v : r.u) - core.line;
51367
- if (along2 + r.radius + CHASE_CLEAR < wall.a0 || along2 - r.radius - CHASE_CLEAR > wall.a1 || r.y1 <= core.y0 || r.y0 >= core.y1) continue;
51403
+ if (along2 + r.radius + CHASE_CLEAR2 < wall.a0 || along2 - r.radius - CHASE_CLEAR2 > wall.a1 || r.y1 <= core.y0 || r.y0 >= core.y1) continue;
51368
51404
  if (Math.abs(across2) > wall.thickness / 2 + 1e-6) continue;
51369
- const back = Math.abs(across2) - (r.depth ?? r.radius) - CHASE_CLEAR;
51370
- 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 } : {} });
51405
+ const back = Math.abs(across2) - (r.depth ?? r.radius) - CHASE_CLEAR2;
51406
+ 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 } : {} });
51371
51407
  }
51372
51408
  return out;
51373
51409
  }
@@ -52897,7 +52933,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
52897
52933
  alias("tv", "flat_tv");
52898
52934
  alias("tv_large", "flat_tv");
52899
52935
  mine("coffee_table", (M, A) => FURNITURE.table(M, A, { noChairs: true }));
52900
- mine("coffee_table_round", (M, A) => FURNITURE.table(M, A, { without: true, round: true }));
52936
+ mine("coffee_table_round", (M, A) => FURNITURE.table(M, A, { noChairs: true, round: true }));
52901
52937
  mine("rug", FURNITURE.rug);
52902
52938
  mine("rug_small", FURNITURE.rug, "game (rug)");
52903
52939
  mine("shelf_unit", FURNITURE.shelf);
@@ -53626,17 +53662,23 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
53626
53662
  }
53627
53663
  var POTTED_PLANT_TYPES = /* @__PURE__ */ new Set(["floor_plant", "floor_plant_tall", "floor_plant_low", "plant_tall", "plant_short", "outdoor_pot", "table_plant"]);
53628
53664
  var PLANT_CLEAR = 0.04;
53629
- var PLANT_MIN_REACH = 0.14;
53665
+ var PLANT_MIN_REACH = 0.12;
53630
53666
  var PLANT_SPAN = [0.03, 2.4];
53667
+ var PLANT_HEIGHT_MARGIN = 1.5;
53631
53668
  function footprintOf(m) {
53632
53669
  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, hz = ((m.w || 0) * s + (m.d || 0) * c) / 2;
53633
53670
  return [m.x - hx, m.z - hz, m.x + hx, m.z + hz];
53634
53671
  }
53635
53672
  var reachTo = (x, z, x0, z0, x1, z1) => Math.hypot(Math.max(x0 - x, 0, x - x1), Math.max(z0 - z, 0, z - z1));
53636
53673
  function freeReachOf(p) {
53637
- const y0 = p.y + PLANT_SPAN[0], y1 = p.y + PLANT_SPAN[1];
53674
+ const tall = p.self.h != null && p.self.h > 0 ? Math.min(PLANT_SPAN[1], p.self.h * PLANT_HEIGHT_MARGIN) : PLANT_SPAN[1];
53675
+ const y0 = p.y + PLANT_SPAN[0], y1 = p.y + tall;
53638
53676
  let reach2 = Number.POSITIVE_INFINITY;
53639
- 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]));
53677
+ for (const b of p.boxes) {
53678
+ if (b[1] >= y1 || b[4] <= y0) continue;
53679
+ if (b[1] > p.y && p.x >= b[0] && p.x <= b[3] && p.z >= b[2] && p.z <= b[5]) continue;
53680
+ reach2 = Math.min(reach2, reachTo(p.x, p.z, b[0], b[2], b[3], b[5]));
53681
+ }
53640
53682
  for (const m of p.items) {
53641
53683
  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;
53642
53684
  const bottom = p.base + (m.y || 0), top = bottom + (m.h || 0);
@@ -53700,7 +53742,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
53700
53742
  const covers = [];
53701
53743
  for (const m of ordered) {
53702
53744
  if (m.type === "stairs") continue;
53703
- const exterior = m.outdoor || m.floor < 0, f = exterior ? -1 : Math.min(m.floor, R.floors.length - 1);
53745
+ const exterior = m.outdoor || m.floor < 0;
53746
+ if (exterior && m.category === "ground_cover" && shared2.ctx.noGroundSurfaces) continue;
53747
+ const f = exterior ? -1 : Math.min(m.floor, R.floors.length - 1);
53704
53748
  cursor.group = exterior && !(m.type === "cooking_gas_cylinder" && m.shelter && !shared2.ctx.visorScene) ? "lot" : "f" + Math.max(f, 0);
53705
53749
  const com = m.room != null ? shared2.ctx.roomById[m.room] : void 0, lift = !exterior && f === 0 && shared2.ctx.constructionStages && !shared2.ctx.visorScene && !com?.outbuilding ? FLOOR_OVER_GROUND : 0, base = exterior ? 0 : Y0(f) + lift;
53706
53750
  const M = { visorScene: shared2.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: shared2.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: shared2.ctx.night, light: shared2.ctx.night, lit: shared2.ctx.night, open: !!m.doorOpen, overhead: m.overhead, assembly: m.assembly, hose: m.hose, shelter: m.shelter, pipe: m.pipe };
@@ -54746,6 +54790,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
54746
54790
  const defined = { targetOf };
54747
54791
  Object.assign(K, defined);
54748
54792
  }
54793
+ var CORD_RADIUS = 6e-3;
54749
54794
  function installInteractablesBridge(K, shared2) {
54750
54795
  const { t, THREE, invalidate, invalidateShadow, cfg, DOC, LIGHT_TYPES, _Y, _q, _v3, accFor, applyLight, cursor, hashString: hashString2, hudMessage, lightBase, pieceRecord, rgbOf, wallBlocks } = K;
54751
54796
  const enter = (...a) => K.enter(...a);
@@ -54891,9 +54936,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
54891
54936
  const spec = ik.A.household.build(type, loc, mesh2.api);
54892
54937
  const out = mesh2.finish(spec);
54893
54938
  for (const l of out.lights) l.removeFromParent();
54894
- const group = ivGroup(ent), g0 = cursor.group, stage0 = cursor.stage, root = new THREE.Group();
54939
+ const group = type === "gas_bottle" && item.shelter && !shared2.ctx.visorScene ? "f0" : ivGroup(ent), g0 = cursor.group, stage0 = cursor.stage, root = new THREE.Group();
54895
54940
  root.name = "iv:" + ent.id;
54896
- const isInst = type === "electrical_panel" || type === "power_meter" || type === "service_entrance" || type === "gas_bottle";
54941
+ const isInst = type === "electrical_panel" || type === "power_meter" || type === "service_entrance";
54897
54942
  const isPlate = type === "wall_switch" || type === "wall_socket";
54898
54943
  const ivStage = shared2.ctx.constructionStages ? isInst ? "installations" : isPlate ? "finishes" : "furniture" : void 0;
54899
54944
  if (ivStage) root.userData.constructionStage = ivStage;
@@ -54949,6 +54994,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
54949
54994
  if (root.children.length) IV.roots.push(E);
54950
54995
  return spec;
54951
54996
  }
54997
+ const floorFinishOf = (floor) => shared2.ctx.constructionStages && !shared2.ctx.visorScene && floor === 0 ? FLOOR_OVER_GROUND : 0;
54952
54998
  function ivCords(IV) {
54953
54999
  const ik = IV.k, w = IV.world, wl = (o, p) => ik.GI.localToWorld(o.transform, p), g0 = cursor.group;
54954
55000
  const tube2 = (pts, radius, color2, ox, oy, oz, ry) => {
@@ -54975,15 +55021,16 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
54975
55021
  if (!so || !sk) continue;
54976
55022
  const sp = wl(so, sk.pos), dir = [Math.sin(so.transform.ry), Math.cos(so.transform.ry)], last = pts[pts.length - 1];
54977
55023
  if (last[1] < 0.3 + E.pos[1]) {
54978
- const foot = [sp[0] + dir[0] * 0.035, E.pos[1] + 0.012, sp[2] + dir[1] * 0.035];
54979
- 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]);
55024
+ const lie = E.pos[1] + floorFinishOf(E.floor) + CORD_RADIUS + 1e-3;
55025
+ const foot = [sp[0] + dir[0] * 0.035, lie, sp[2] + dir[1] * 0.035];
55026
+ 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]);
54980
55027
  } else {
54981
55028
  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);
54982
55029
  hang.shift();
54983
55030
  for (const p of hang) pts.push(p);
54984
55031
  }
54985
55032
  shared2.ctx.cordPaths?.push({ object: E.id, device: d.id, points: pts.map((p) => [p[0], p[1], p[2]]) });
54986
- tube2(pts, 6e-3, IV_WIRE.cord, 0, 0, 0, 0);
55033
+ tube2(pts, CORD_RADIUS, IV_WIRE.cord, 0, 0, 0, 0);
54987
55034
  }
54988
55035
  }
54989
55036
  } finally {
@@ -57832,6 +57879,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
57832
57879
  return level >= STAGE_LEVEL.openings;
57833
57880
  case "roof":
57834
57881
  return level >= STAGE_LEVEL.roof && opts.roofLayer !== false;
57882
+ // 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
57883
+ case "roofFraming":
57884
+ return level >= STAGE_LEVEL.roofFraming && opts.roofLayer !== false;
57835
57885
  case "furniture":
57836
57886
  return level >= STAGE_LEVEL.last;
57837
57887
  // the protective sidewalk round the house: the last of the work outside
@@ -57897,6 +57947,50 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
57897
57947
  }
57898
57948
  return level;
57899
57949
  }
57950
+ function partStagesOf(house) {
57951
+ const stages = /* @__PURE__ */ new Map();
57952
+ const walk = (o, inherited) => {
57953
+ const own = typeof o.userData?.constructionStage === "string" ? o.userData.constructionStage : inherited;
57954
+ const part = o.userData?.destructionPart;
57955
+ if (own && typeof part === "string" && !stages.has(part)) stages.set(part, own);
57956
+ const ranges = o.userData?.ranges;
57957
+ if (own && Array.isArray(ranges)) {
57958
+ for (const range2 of ranges) if (!stages.has(range2.id)) stages.set(range2.id, own);
57959
+ }
57960
+ for (const c of o.children) walk(c, own);
57961
+ };
57962
+ walk(house, void 0);
57963
+ return stages;
57964
+ }
57965
+ function stageOfPiece(piece2, stages) {
57966
+ let found;
57967
+ piece2.root.traverse((o) => {
57968
+ if (found) return;
57969
+ const part = o.userData?.destructionPart;
57970
+ if (typeof part === "string") found = stages.get(part);
57971
+ });
57972
+ return found;
57973
+ }
57974
+ function stageLoosePieces(pieces, stages, level, opts, held) {
57975
+ let hidden = 0;
57976
+ for (const piece2 of pieces) {
57977
+ const stage = stageOfPiece(piece2, stages);
57978
+ if (!stage) continue;
57979
+ const shown2 = stageVisible(stage, level, opts);
57980
+ piece2.root.visible = shown2;
57981
+ if (!shown2) {
57982
+ hidden++;
57983
+ if (!piece2.held) {
57984
+ piece2.held = true;
57985
+ held.add(piece2);
57986
+ }
57987
+ } else if (held.has(piece2)) {
57988
+ piece2.held = false;
57989
+ held.delete(piece2);
57990
+ }
57991
+ }
57992
+ return hidden;
57993
+ }
57900
57994
  var INSTALLATIONS_STAGE = "stage:4:installations";
57901
57995
  function toWorld2(THREE, object2, x, z) {
57902
57996
  return new THREE.Vector3(x, 0, z).applyMatrix4(object2.matrixWorld);
@@ -57928,24 +58022,53 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
57928
58022
  hip: { top: 0.065, width: 0.06, height: 0.14 },
57929
58023
  post: { side: 0.07, spacing: 2 }
57930
58024
  };
58025
+ 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];
57931
58026
  var EDGE2 = 0.04;
57932
- function addTimber(batch, top0, top1, width, height) {
58027
+ var ROOF_TIMBER_STRETCH = 1.2;
58028
+ var ROOF_TIMBER_MATERIAL = "wood_hard";
58029
+ var TIMBER_DENSITY = 750;
58030
+ var TimberLog = class {
58031
+ constructor(prefix, onPiece) {
58032
+ __publicField(this, "prefix", prefix);
58033
+ __publicField(this, "onPiece", onPiece);
58034
+ __publicField(this, "count", 0);
58035
+ }
58036
+ next(kind, mass, chain) {
58037
+ const id = `${this.prefix}:${this.count++}`;
58038
+ this.onPiece({ id, kind, mass, chain });
58039
+ return id;
58040
+ }
58041
+ };
58042
+ var LOGS = /* @__PURE__ */ new WeakMap();
58043
+ function addTimber(batch, top0, top1, width, height, kind) {
57933
58044
  const dx = top1[0] - top0[0], dz = top1[2] - top0[2];
57934
58045
  const flat = Math.hypot(dx, dz);
57935
58046
  if (flat < 1e-4 && Math.abs(top1[1] - top0[1]) < 1e-4) return;
57936
58047
  const sx = flat < 1e-4 ? width / 2 : -dz / flat * (width / 2);
57937
58048
  const sz = flat < 1e-4 ? 0 : dx / flat * (width / 2);
57938
58049
  const corner = (p, side, down2) => [p[0] + sx * side, p[1] - down2, p[2] + sz * side];
57939
- batch.addHexahedron([
57940
- corner(top0, -1, height),
57941
- corner(top0, 1, height),
57942
- corner(top0, 1, 0),
57943
- corner(top0, -1, 0),
57944
- corner(top1, -1, height),
57945
- corner(top1, 1, height),
57946
- corner(top1, 1, 0),
57947
- corner(top1, -1, 0)
57948
- ]);
58050
+ const log = LOGS.get(batch);
58051
+ const length = Math.hypot(dx, top1[1] - top0[1], dz);
58052
+ const stretches = log ? Math.max(1, Math.ceil(length / ROOF_TIMBER_STRETCH)) : 1;
58053
+ let before = null;
58054
+ for (let k = 0; k < stretches; k++) {
58055
+ const a = along(top0, top1, k / stretches), b = along(top0, top1, (k + 1) / stretches);
58056
+ if (log) {
58057
+ before = log.next(kind, TIMBER_DENSITY * width * height * (length / stretches), before ? [before] : []);
58058
+ batch.piece(before);
58059
+ }
58060
+ batch.addHexahedron([
58061
+ corner(a, -1, height),
58062
+ corner(a, 1, height),
58063
+ corner(a, 1, 0),
58064
+ corner(a, -1, 0),
58065
+ corner(b, -1, height),
58066
+ corner(b, 1, height),
58067
+ corner(b, 1, 0),
58068
+ corner(b, -1, 0)
58069
+ ], { start: k > 0, end: k < stretches - 1 });
58070
+ }
58071
+ if (log) batch.piece(null);
57949
58072
  }
57950
58073
  var KEEP_OUT_GAP = 0.03;
57951
58074
  function clearStretches(top0, top1, width, height, keepOut) {
@@ -57969,16 +58092,15 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
57969
58092
  }
57970
58093
  return stretches;
57971
58094
  }
57972
- 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];
57973
- function addTimberAround(batch, top0, top1, width, height, keepOut, onCut) {
58095
+ function addTimberAround(batch, top0, top1, width, height, kind, keepOut, onCut) {
57974
58096
  if (!keepOut.length) {
57975
- addTimber(batch, top0, top1, width, height);
58097
+ addTimber(batch, top0, top1, width, height, kind);
57976
58098
  return;
57977
58099
  }
57978
58100
  const length = Math.hypot(top1[0] - top0[0], top1[1] - top0[1], top1[2] - top0[2]);
57979
58101
  for (const [f0, f1] of clearStretches(top0, top1, width, height, keepOut)) {
57980
58102
  if ((f1 - f0) * length < 0.05) continue;
57981
- addTimber(batch, along(top0, top1, f0), along(top0, top1, f1), width, height);
58103
+ addTimber(batch, along(top0, top1, f0), along(top0, top1, f1), width, height, kind);
57982
58104
  const inset = TIMBER.post.side / 2 / Math.max(length, 1e-6);
57983
58105
  if (f0 > 0) onCut?.(along(top0, top1, Math.min(f1, f0 + inset)));
57984
58106
  if (f1 < 1) onCut?.(along(top0, top1, Math.max(f0, f1 - inset)));
@@ -57987,7 +58109,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
57987
58109
  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);
57988
58110
  function addPost(batch, x, z, y0, y1) {
57989
58111
  const h = TIMBER.post.side / 2;
57990
- if (y1 - y0 > 0.02) batch.add([x - h, y0, z - h, x + h, y1, z + h], true);
58112
+ if (y1 - y0 <= 0.02) return;
58113
+ const log = LOGS.get(batch);
58114
+ if (log) batch.piece(log.next("post", TIMBER_DENSITY * TIMBER.post.side * TIMBER.post.side * (y1 - y0), []));
58115
+ batch.add([x - h, y0, z - h, x + h, y1, z + h], true);
58116
+ if (log) batch.piece(null);
57991
58117
  }
57992
58118
  function slopesOf(rect) {
57993
58119
  const [x0, z0, x1, z1] = rect.exterior;
@@ -58045,7 +58171,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58045
58171
  const a = a0 + BATTEN_SHORT, b = b0 - BATTEN_SHORT;
58046
58172
  if (b - a <= 0.05) continue;
58047
58173
  const at2 = battenClearOfSolids(slope, s, [a, b], solids);
58048
- addTimberAround(batches.battens, down(slope.point(at2, a), batten.top), down(slope.point(at2, b), batten.top), batten.width, batten.height, keepOut);
58174
+ addTimberAround(batches.battens, down(slope.point(at2, a), batten.top), down(slope.point(at2, b), batten.top), batten.width, batten.height, "batten", keepOut);
58049
58175
  }
58050
58176
  const t0 = slope.t0 + EDGE2, t1 = slope.t1 - EDGE2;
58051
58177
  const count = Math.max(1, Math.round((t1 - t0) / rafter.spacing));
@@ -58055,7 +58181,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58055
58181
  if (end < 0.1) continue;
58056
58182
  const axis = slope.point(0, 1)[0] - slope.point(0, 0)[0] !== 0 ? 0 : 2;
58057
58183
  const t = clearOfSolids(at2, rafter.width, down(slope.point(EDGE2, at2), rafter.top), down(slope.point(end, at2), rafter.top), axis, solids);
58058
- addTimberAround(batches.timber, down(slope.point(EDGE2, t), rafter.top), down(slope.point(end, t), rafter.top), rafter.width, rafter.height, keepOut);
58184
+ addTimberAround(batches.timber, down(slope.point(EDGE2, t), rafter.top), down(slope.point(end, t), rafter.top), rafter.width, rafter.height, "rafter", keepOut);
58059
58185
  }
58060
58186
  const lines = [slope.wall, slope.wall + (slope.run - slope.wall) / 3, slope.wall + (slope.run - slope.wall) * 2 / 3];
58061
58187
  lines.forEach((s, k) => {
@@ -58065,7 +58191,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58065
58191
  const p0 = down(slope.point(s, a), top), p1 = down(slope.point(s, b), top);
58066
58192
  const depth = Math.min(purlin.height, p0[1] - slabTop - 3e-3);
58067
58193
  if (depth < 0.02) return;
58068
- addTimberAround(batches.timber, p0, p1, k === 0 ? purlin.width - PLATE_NARROWER : purlin.width, depth, keepOut, k === 0 ? void 0 : (end) => addPost(batches.timber, end[0], end[2], slabTop, end[1] - purlin.height));
58194
+ addTimberAround(batches.timber, p0, p1, k === 0 ? purlin.width - PLATE_NARROWER : purlin.width, depth, "purlin", keepOut, k === 0 ? void 0 : (end) => addPost(batches.timber, end[0], end[2], slabTop, end[1] - purlin.height));
58069
58195
  if (k === 0) return;
58070
58196
  const posts = Math.max(1, Math.ceil((b - a) / TIMBER.post.spacing));
58071
58197
  for (let j = 0; j <= posts; j++) {
@@ -58097,10 +58223,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58097
58223
  }
58098
58224
  return out;
58099
58225
  }
58100
- function buildRoofFramingStage(THREE, roofRects, material, solids = [], keepOut = []) {
58226
+ function buildRoofFramingStage(THREE, roofRects, material, solids = [], keepOut = [], onPiece) {
58101
58227
  const group = new THREE.Group();
58102
58228
  group.name = "stage:7:roof_framing";
58103
58229
  const timber = new BoxBatch(), battens = new BoxBatch();
58230
+ if (onPiece) {
58231
+ LOGS.set(timber, new TimberLog("roof_timber", onPiece));
58232
+ LOGS.set(battens, new TimberLog("roof_batten", onPiece));
58233
+ }
58104
58234
  for (const rr of roofRects) {
58105
58235
  if (rr.slab || rr.yb === void 0 || rr.tp === void 0 || !rr.exterior || rr.rm === void 0 || rr.alongX === void 0) continue;
58106
58236
  const rect = { yb: rr.yb, tp: rr.tp, exterior: rr.exterior, rm: rr.rm, alongX: rr.alongX, r: rr.r, gable: !!rr.gable };
@@ -58111,7 +58241,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58111
58241
  const xm = (x0 + x1) / 2, zm = (z0 + z1) / 2;
58112
58242
  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]];
58113
58243
  const ridgeTop = TIMBER.purlin.top;
58114
- addTimberAround(timber, down(ends[0], ridgeTop), down(ends[1], ridgeTop), TIMBER.purlin.width, TIMBER.purlin.height, keepOut, (end) => addPost(timber, end[0], end[2], slabTop, end[1] - TIMBER.purlin.height));
58244
+ addTimberAround(timber, down(ends[0], ridgeTop), down(ends[1], ridgeTop), TIMBER.purlin.width, TIMBER.purlin.height, "purlin", keepOut, (end) => addPost(timber, end[0], end[2], slabTop, end[1] - TIMBER.purlin.height));
58115
58245
  const along2 = Math.hypot(ends[1][0] - ends[0][0], ends[1][2] - ends[0][2]);
58116
58246
  const posts = Math.max(1, Math.ceil(along2 / TIMBER.post.spacing));
58117
58247
  for (let j = 0; j <= posts; j++) {
@@ -58127,12 +58257,17 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58127
58257
  const corners = [[x0 + e, h, z0 + e], [x1 - e, h, z0 + e], [x0 + e, h, z1 - e], [x1 - e, h, z1 - e]];
58128
58258
  for (const c of corners) {
58129
58259
  const end = 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];
58130
- addTimberAround(timber, down(c, TIMBER.hip.top), down(end, TIMBER.hip.top), TIMBER.hip.width, TIMBER.hip.height, keepOut);
58260
+ addTimberAround(timber, down(c, TIMBER.hip.top), down(end, TIMBER.hip.top), TIMBER.hip.width, TIMBER.hip.height, "hip", keepOut);
58131
58261
  }
58132
58262
  }
58133
58263
  }
58134
58264
  const wood = material ?? new THREE.MeshStandardMaterial({ color: 11042380, roughness: 0.82 });
58135
- for (const mesh2 of [timber.mesh(THREE, wood, "roof_framing:timber"), battens.mesh(THREE, wood, "roof_framing:battens")]) if (mesh2) group.add(mesh2);
58265
+ for (const mesh2 of [timber.mesh(THREE, wood, "roof_framing:timber"), battens.mesh(THREE, wood, "roof_framing:battens")]) {
58266
+ if (!mesh2) continue;
58267
+ mesh2.userData.constructionStage = "roofFraming";
58268
+ if (onPiece) mesh2.userData.destructionMaterial = ROOF_TIMBER_MATERIAL;
58269
+ group.add(mesh2);
58270
+ }
58136
58271
  return group;
58137
58272
  }
58138
58273
  var HOUSE_SHADOW_BUDGET_MS = 2;
@@ -58175,6 +58310,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58175
58310
  }
58176
58311
  };
58177
58312
  }
58313
+ var ROOF_TIMBER_REACH = 3;
58178
58314
  function withLaidConduits(r, stages) {
58179
58315
  const E = r.utilities?.electrical;
58180
58316
  if (!stages || !E || !E.conduits?.length) return r;
@@ -58232,7 +58368,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58232
58368
  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 };
58233
58369
  }
58234
58370
  function installBuildBuild(K, shared2) {
58235
- const { THREE, cfg, rectsOf: rectsOf2, invalidateShadow, colliderChanged, VERSION: VERSION2, CARS, EPS: EPS4, LIGHTS, MIRRORS, Y0, animateClotheslines, animateDoors, animateInteractive, applyLeaf, applyOutbuildings, applyPart, applyPiece, assembleInteractive, baseboardAndSidewalk, buildStairs, building, carModel, chooseMirror, closeScene, collideAt, createWater, cursor, doorText, doors, electricalStructure, elevator, floorsAndSlabs, gatesInteractive, houseItems, ivAssemble, ivBuild, ivDispose, ivParts, ivPublish, ivUpdate, lightOn, linkDoorLeaves, mailboxInteractive, 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;
58371
+ const { THREE, cfg, rectsOf: rectsOf2, invalidateShadow, colliderChanged, VERSION: VERSION2, CARS, EPS: EPS4, LIGHTS, MIRRORS, Y0, animateClotheslines, animateDoors, animateInteractive, applyLeaf, applyOutbuildings, applyPart, applyPiece, assembleInteractive, baseboardAndSidewalk, buildStairs, building, carModel, chooseMirror, closeScene, collideAt, createWater, cursor, doorText, doors, electricalStructure, elevator, floorsAndSlabs, gatesInteractive, houseItems, ivAssemble, ivBuild, ivDispose, ivParts, ivPublish, ivUpdate, lightOn, linkDoorLeaves, mailboxInteractive, 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;
58236
58372
  function build(r0, options) {
58237
58373
  const opts = options || {};
58238
58374
  const r = withLaidConduits(applyOutbuildings(r0), !!(opts.constructionStages || opts.constructionLevel != null));
@@ -58250,6 +58386,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58250
58386
  shared2.ctx.colliders = [];
58251
58387
  shared2.ctx.stairs = [];
58252
58388
  shared2.ctx.noTerrain = opts.terrain === false;
58389
+ shared2.ctx.noGroundSurfaces = opts.groundSurfaces === false;
58253
58390
  shared2.ctx.serviceFrom = opts.serviceFrom ?? null;
58254
58391
  shared2.ctx.roomById = {};
58255
58392
  for (const c of r.rooms) shared2.ctx.roomById[c.id] = c;
@@ -58401,6 +58538,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58401
58538
  (k === "floor" || k === "building" ? root : house).add(g);
58402
58539
  }
58403
58540
  let currentConstructionLevel = CONSTRUCTION_LEVEL_MAX;
58541
+ let partStages = null, stageOptsNow = {}, piecesStaged = -1;
58542
+ const stageHeld = /* @__PURE__ */ new Set();
58404
58543
  h.groups = gs;
58405
58544
  h.root = root;
58406
58545
  h.house = house;
@@ -58581,22 +58720,34 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58581
58720
  return house.localToWorld(localCenter.clone());
58582
58721
  };
58583
58722
  const distance2 = (focus) => center().distanceTo(focus instanceof THREE.Vector3 ? focus : new THREE.Vector3(focus.x, focus.y, focus.z));
58584
- markGroups(r, root, parts2);
58585
- const structure = assembleStructure(r0, root), destruction = createHouseDestruction(root, house, structure, parts2, colliders, water);
58586
- h.destruction = destruction;
58587
- destruction.breach.setLod(h.lodCurrent);
58588
58723
  if (cs) {
58589
58724
  const bp = buildBlueprintStage(THREE, K.DOC, r, rectsOf2);
58590
58725
  const stGroups = buildStructuralStageGroups(THREE, r0.structure, r.outbuildings || [], [...embeddedRunsOf(house), ...wallBoxRunsOf(r, shared2.ctx.wallBoxShifts)], shared2.ctx.blockLaid ?? []);
58591
58726
  const instGroup = buildInstallationsStage(THREE, r, shared2.ctx.gutterInfo?.drains ?? [], shared2.ctx.paving ?? []);
58592
- const roofFraming = buildRoofFramingStage(THREE, shared2.ctx.roofRects || [], void 0, [...shared2.ctx.occupied ?? [], ...bareBoxesOf(THREE, [stGroups.frame, stGroups.masonry])], [...atticKeepOut(THREE, house, Object.values(parts2)), ...gutterKeepOut(shared2.ctx.gutterInfo?.gutters ?? [])]);
58727
+ const roofFraming = buildRoofFramingStage(THREE, shared2.ctx.roofRects || [], void 0, [...shared2.ctx.occupied ?? [], ...bareBoxesOf(THREE, [stGroups.frame, stGroups.masonry])], [...atticKeepOut(THREE, house, Object.values(parts2)), ...gutterKeepOut(shared2.ctx.gutterInfo?.gutters ?? [])], (t) => {
58728
+ 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 } : {} });
58729
+ });
58593
58730
  const yardBoxes = instGroup.userData.yardBoxes;
58594
58731
  for (const sg of [bp, stGroups.foundation, stGroups.starterBars, stGroups.frame, stGroups.masonry, instGroup, ...yardBoxes ? [yardBoxes] : [], roofFraming]) {
58595
58732
  gs[sg.name] = sg;
58596
58733
  house.add(sg);
58597
58734
  }
58598
- currentConstructionLevel = applyConstructionLevel(house, opts.constructionLevel ?? CONSTRUCTION_LEVEL_MAX);
58599
58735
  }
58736
+ markGroups(r, root, parts2);
58737
+ const structure = assembleStructure(r0, root), destruction = createHouseDestruction(root, house, structure, parts2, colliders, water);
58738
+ h.destruction = destruction;
58739
+ destruction.breach.setLod(h.lodCurrent);
58740
+ if (cs) {
58741
+ currentConstructionLevel = applyConstructionLevel(house, opts.constructionLevel ?? CONSTRUCTION_LEVEL_MAX);
58742
+ partStages = partStagesOf(house);
58743
+ }
58744
+ const stagePieces = () => {
58745
+ const R = destruction.renderer;
58746
+ if (!partStages || !R?.pieces) return;
58747
+ const list2 = R.pieces();
58748
+ piecesStaged = list2.length;
58749
+ stageLoosePieces(list2, partStages, currentConstructionLevel, stageOptsNow, stageHeld);
58750
+ };
58600
58751
  const strikePiece = (id, point, type, amount, d, before) => {
58601
58752
  if (!destruction.world) return;
58602
58753
  const pid = id && structure.byId.has(id) ? id : parts2[id] && parts2[id].type === "water_tank" && structure.byId.has("water_tank") ? "water_tank" : null;
@@ -58678,6 +58829,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58678
58829
  // 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
58679
58830
  update(dt, time, focus) {
58680
58831
  enter(h);
58832
+ if (partStages && currentConstructionLevel < CONSTRUCTION_LEVEL_MAX && destruction.renderer?.pieces && destruction.renderer.pieces().length !== piecesStaged) stagePieces();
58681
58833
  animateDoors(dt);
58682
58834
  animateInteractive(dt);
58683
58835
  water.step(dt);
@@ -58711,12 +58863,16 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58711
58863
  g.visible = v;
58712
58864
  }
58713
58865
  if (cs && currentConstructionLevel < CONSTRUCTION_LEVEL_MAX) {
58714
- applyConstructionLevel(house, currentConstructionLevel, { roofLayer: !cut && sel < 0, lotLayer: o.lot !== false });
58866
+ stageOptsNow = { roofLayer: !cut && sel < 0, lotLayer: o.lot !== false };
58867
+ applyConstructionLevel(house, currentConstructionLevel, stageOptsNow);
58868
+ stagePieces();
58715
58869
  }
58716
58870
  },
58717
58871
  setConstructionLevel(level, stageOpts) {
58718
58872
  enter(h);
58873
+ stageOptsNow = stageOpts ?? {};
58719
58874
  currentConstructionLevel = applyConstructionLevel(house, level, stageOpts);
58875
+ stagePieces();
58720
58876
  invalidateShadow();
58721
58877
  return currentConstructionLevel;
58722
58878
  },
@@ -59089,6 +59245,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
59089
59245
  }
59090
59246
  var FLOOR_TOUCH2 = 5e-3;
59091
59247
  var LOOSE = /* @__PURE__ */ new Set(["paper"]);
59248
+ var PLANTED = /* @__PURE__ */ new Set(["mailbox", "correio", "clothesline", "tree_small", "bbq_simple"]);
59092
59249
  var BASE_MATERIAL = {
59093
59250
  wood: "wood_hard",
59094
59251
  metal: "steel",
@@ -59200,7 +59357,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
59200
59357
  const wallMounted = parts2.some((part) => part.anchored && low(part) > FLOOR_TOUCH2);
59201
59358
  const sunk = parts2.some((part) => low(part) < -FLOOR_TOUCH2);
59202
59359
  const rooted = parts2.some((part) => part.material === "foliage") && parts2.some((part) => part.material.startsWith("wood") && low(part) <= FLOOR_TOUCH2);
59203
- const fixed = wallMounted || sunk || rooted;
59360
+ const fixed = wallMounted || sunk || rooted || PLANTED.has(name);
59204
59361
  const all = drawn.reduce(
59205
59362
  (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]) }),
59206
59363
  { x0: Infinity, x1: -Infinity, z0: Infinity, z1: -Infinity }