@adatechnology/game-weapons-three 0.26.0 → 0.26.2

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.
@@ -739,7 +739,8 @@ var GameWeaponsThree = (() => {
739
739
  PIECE_BOXES: "destruction.piece-boxes",
740
740
  STATIC_COLLIDERS: "destruction.static-colliders",
741
741
  SHAPES_GENERATE: "shapes.generate",
742
- WORLD_REGION: "world.region"
742
+ WORLD_REGION: "world.region",
743
+ VEHICLE_HULL_PLAN: "vehicles.hull-plan"
743
744
  };
744
745
  var WORKER_KIND_DEFAULTS = {
745
746
  [WORKER_KIND_ID.GROUND_TILES]: { lane: "sim", priority: 300, latencyFrames: 2, late: "sync" },
@@ -747,7 +748,8 @@ var GameWeaponsThree = (() => {
747
748
  [WORKER_KIND_ID.PIECE_BOXES]: { lane: "sim", priority: 200, latencyFrames: 2, late: "sync" },
748
749
  [WORKER_KIND_ID.STATIC_COLLIDERS]: { lane: "build", priority: 150, late: "sync" },
749
750
  [WORKER_KIND_ID.SHAPES_GENERATE]: { lane: "build", priority: 100, late: "sync" },
750
- [WORKER_KIND_ID.WORLD_REGION]: { lane: "background", priority: 10, latencyFrames: 10, late: "drop" }
751
+ [WORKER_KIND_ID.WORLD_REGION]: { lane: "background", priority: 10, latencyFrames: 10, late: "drop" },
752
+ [WORKER_KIND_ID.VEHICLE_HULL_PLAN]: { lane: "build", priority: 120, late: "keep-waiting" }
751
753
  };
752
754
 
753
755
  // ../game-weapons/dist/index.js
@@ -25000,6 +25002,20 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25000
25002
  let time = 0;
25001
25003
  let counter = 0;
25002
25004
  const objects = /* @__PURE__ */ new Map();
25005
+ const slots = /* @__PURE__ */ new Map();
25006
+ let slotCounter = 0;
25007
+ let objectsRevision = 0;
25008
+ const putObject = (id, object2) => {
25009
+ if (!objects.has(id)) slots.set(id, ++slotCounter);
25010
+ objectsRevision++;
25011
+ objects.set(id, object2);
25012
+ };
25013
+ const dropObject = (id) => {
25014
+ if (objects.delete(id)) {
25015
+ slots.delete(id);
25016
+ objectsRevision++;
25017
+ }
25018
+ };
25003
25019
  const listeners = /* @__PURE__ */ new Map();
25004
25020
  let cur = [];
25005
25021
  const blasts = [];
@@ -26890,18 +26906,52 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26890
26906
  if (o.soil?.sets.size) restCarry.soilSets = Object.fromEntries(o.soil.sets);
26891
26907
  const rest2 = build(sub2(inOld), o.id, o.soil ? o.base.pos : pos, o.soil ? o.base.rot : rot, restCarry);
26892
26908
  dirtyHosted.delete(o);
26893
- objects.set(o.id, rest2);
26894
- for (const [nid, object2] of fresh) objects.set(nid, object2);
26909
+ putObject(o.id, rest2);
26910
+ for (const [nid, object2] of fresh) putObject(nid, object2);
26895
26911
  return fresh.map(([nid]) => nid);
26896
26912
  };
26913
+ let rayBroad = null;
26914
+ let uncovered = [];
26915
+ let uncoveredFor = { hook: null, coverage: -1, objects: -1 };
26916
+ const metObjects = [];
26917
+ const rayObjects = [];
26918
+ const candidatesOf2 = (hook) => {
26919
+ const asked = hook.candidates;
26920
+ if (!asked) return null;
26921
+ const coverage2 = asked.revision();
26922
+ if (uncoveredFor.hook !== hook || uncoveredFor.coverage !== coverage2 || uncoveredFor.objects !== objectsRevision) {
26923
+ uncovered = [];
26924
+ for (const o of objects.values()) if (!asked.covers(o.id)) uncovered.push(o);
26925
+ uncoveredFor = { hook, coverage: coverage2, objects: objectsRevision };
26926
+ }
26927
+ if (uncovered.length * 2 > objects.size) return null;
26928
+ metObjects.length = 0;
26929
+ for (const id of asked.met()) {
26930
+ const o = objects.get(id);
26931
+ if (o && asked.covers(id)) metObjects.push(o);
26932
+ }
26933
+ metObjects.sort((a, b) => slots.get(a.id) - slots.get(b.id));
26934
+ rayObjects.length = 0;
26935
+ let m = 0;
26936
+ let u = 0;
26937
+ while (m < metObjects.length || u < uncovered.length) {
26938
+ const takeMet = u >= uncovered.length || m < metObjects.length && slots.get(metObjects[m].id) < slots.get(uncovered[u].id);
26939
+ rayObjects.push(takeMet ? metObjects[m++] : uncovered[u++]);
26940
+ }
26941
+ return rayObjects;
26942
+ };
26897
26943
  const raycastInternal = (origin, dir, maxDist, ignore, worldOnly = false, precise = false, skip = {}, scope2) => {
26898
26944
  const d = vec.normalize(dir);
26945
+ const asked = rayBroad && !scope2 && rayBroad.begin(origin, d, maxDist) ? rayBroad : null;
26946
+ const candidates = asked ? candidatesOf2(asked) : null;
26947
+ const outside = candidates ? null : asked;
26899
26948
  const minRadius = skip.minObjectRadius ?? 0;
26900
26949
  let best = null;
26901
26950
  const counts = sweepCounts;
26902
- for (const o of scope2 ? scope2.objects : objects.values()) {
26951
+ for (const o of scope2 ? scope2.objects : candidates ?? objects.values()) {
26903
26952
  if (counts) counts.objectVisits++;
26904
26953
  if (skip.skipLoose && o.loose || o.br < minRadius) continue;
26954
+ if (outside && !outside.mayMeet(o.id)) continue;
26905
26955
  if (raySphereMiss(origin, d, worldCentreOf(o), o.br, best ? Math.min(maxDist, best.distance) : maxDist)) continue;
26906
26956
  const qi = quat.conjugate(o.st.rotation);
26907
26957
  const lo = rotateVec(qi, vec.sub(origin, o.st.position));
@@ -28523,6 +28573,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28523
28573
  return reach2;
28524
28574
  };
28525
28575
  let blastTntPerJoule = TNT_PER_JOULE;
28576
+ let blastHasCharge = false;
28526
28577
  let blastFireball = chargeFireball(0);
28527
28578
  const burstFuel = (p) => {
28528
28579
  const c = p.spec.contains;
@@ -28627,7 +28678,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28627
28678
  }
28628
28679
  for (const im of [...impls.values()]) {
28629
28680
  if (!implInRange(im, point, radius)) continue;
28630
- out.push(implHit(im, { type: "explosive", point, energy, radius, fireball: blastFireball, tnt: energy * blastTntPerJoule, ...lethal !== void 0 ? { lethalRadius: lethal } : {}, ...src !== void 0 ? { source: src } : {} }));
28681
+ 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 } : {} }));
28631
28682
  yield "part";
28632
28683
  }
28633
28684
  return out;
@@ -28752,7 +28803,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28752
28803
  den += f;
28753
28804
  }
28754
28805
  const k = den > 0 ? num3 / den : 1;
28755
- 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 } : {} });
28806
+ 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 } : {} });
28756
28807
  results.set(im, res);
28757
28808
  report(im).shelter = k;
28758
28809
  }
@@ -29094,13 +29145,16 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
29094
29145
  const fireball = charge2?.fuel ? fuelFireball(charge2.fuel) : chargeFireball(energy * tntPerJoule);
29095
29146
  const inBlast = (fn) => {
29096
29147
  const outer = blastTntPerJoule;
29148
+ const outerHasCharge = blastHasCharge;
29097
29149
  const outerFireball = blastFireball;
29098
29150
  blastTntPerJoule = tntPerJoule;
29151
+ blastHasCharge = charge2?.tnt !== void 0;
29099
29152
  blastFireball = fireball;
29100
29153
  try {
29101
29154
  return fn();
29102
29155
  } finally {
29103
29156
  blastTntPerJoule = outer;
29157
+ blastHasCharge = outerHasCharge;
29104
29158
  blastFireball = outerFireball;
29105
29159
  }
29106
29160
  };
@@ -29650,7 +29704,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
29650
29704
  finishExplosions();
29651
29705
  const id = opts.id ?? nextId();
29652
29706
  if (taken(id)) throw new Error(`object "${id}" already exists`);
29653
- objects.set(id, build(resolveSpec(spec), id, opts.position ?? [0, 0, 0], opts.rotation ?? [0, 0, 0, 1]));
29707
+ putObject(id, build(resolveSpec(spec), id, opts.position ?? [0, 0, 0], opts.rotation ?? [0, 0, 0, 1]));
29654
29708
  return id;
29655
29709
  },
29656
29710
  register(impl, opts = {}) {
@@ -29685,7 +29739,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
29685
29739
  impls.get(id)?.impl.dispose?.();
29686
29740
  const existing = objects.get(id);
29687
29741
  if (existing) dirtyHosted.delete(existing);
29688
- objects.delete(id);
29742
+ dropObject(id);
29689
29743
  impls.delete(id);
29690
29744
  },
29691
29745
  has: (id) => taken(id),
@@ -29804,6 +29858,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
29804
29858
  },
29805
29859
  beginExplosion,
29806
29860
  cancelExplosions,
29861
+ setRayBroadPhase(broadPhase2) {
29862
+ rayBroad = broadPhase2;
29863
+ },
29807
29864
  groundLoss(loss) {
29808
29865
  if (!(loss.radius > 0) || !(loss.depth > 0) || !Number.isFinite(loss.x) || !Number.isFinite(loss.z)) return;
29809
29866
  pendingLosses.push({ ...loss });
@@ -30058,7 +30115,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
30058
30115
  }
30059
30116
  const o = getObj(id);
30060
30117
  dirtyHosted.delete(o);
30061
- objects.set(id, build(o.spec, id, o.base.pos, o.base.rot));
30118
+ putObject(id, build(o.spec, id, o.base.pos, o.base.rot));
30062
30119
  },
30063
30120
  on(type, fn) {
30064
30121
  const known = listeners.get(type) ?? [];
@@ -30087,17 +30144,19 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
30087
30144
  finishExplosions();
30088
30145
  const existing = objects.get(id);
30089
30146
  if (existing) dirtyHosted.delete(existing);
30090
- objects.set(id, buildFromEntry(entry2, id));
30147
+ putObject(id, buildFromEntry(entry2, id));
30091
30148
  },
30092
30149
  load(snap) {
30093
30150
  cancelExplosions();
30094
30151
  if (snap.version !== 1) throw new Error(`unsupported snapshot version ${String(snap.version)}`);
30095
30152
  dirtyHosted.clear();
30096
30153
  objects.clear();
30154
+ slots.clear();
30155
+ objectsRevision++;
30097
30156
  time = snap.time;
30098
30157
  rng2.set(snap.rng);
30099
30158
  counter = snap.counter ?? 0;
30100
- for (const e of snap.objects) objects.set(e.id, buildFromEntry(e, e.id));
30159
+ for (const e of snap.objects) putObject(e.id, buildFromEntry(e, e.id));
30101
30160
  for (const e of snap.impls ?? []) {
30102
30161
  const im = impls.get(e.id);
30103
30162
  if (!im) continue;
@@ -54895,7 +54954,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
54895
54954
  }
54896
54955
  var residentialTower = residentialTowerTemplate();
54897
54956
 
54898
- // ../game-floorplan-three/dist/chunk-ANCD3HXE.js
54957
+ // ../game-floorplan-three/dist/chunk-EYIWURKO.js
54899
54958
  var __defProp4 = Object.defineProperty;
54900
54959
  var __defNormalProp2 = (obj, key2, value) => key2 in obj ? __defProp4(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
54901
54960
  var __publicField2 = (obj, key2, value) => __defNormalProp2(obj, typeof key2 !== "symbol" ? key2 + "" : key2, value);
@@ -56943,7 +57002,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
56943
57002
  }
56944
57003
  function paths() {
56945
57004
  const lt2 = shared3.ctx.r.lot;
56946
- if (!lt2 || !lt2.paths) return;
57005
+ if (!lt2 || !lt2.paths || shared3.ctx.noGroundSurfaces) return;
56947
57006
  cursor.group = "lot";
56948
57007
  for (const c of lt2.paths) {
56949
57008
  if (c.type === "vehicle" && c.id !== "cargo_path") continue;
@@ -58237,6 +58296,18 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58237
58296
  __publicField2(this, "positions", []);
58238
58297
  __publicField2(this, "normals", []);
58239
58298
  __publicField2(this, "indices", []);
58299
+ __publicField2(this, "ranges", []);
58300
+ }
58301
+ /** What is added from here on, up to the next call, is the piece `id` (null: no piece). */
58302
+ piece(id) {
58303
+ const v = this.positions.length / 3, i = this.indices.length;
58304
+ const last = this.ranges[this.ranges.length - 1];
58305
+ if (last && last.v1 < 0) {
58306
+ last.v1 = v;
58307
+ last.i1 = i;
58308
+ if (last.v1 === last.v0) this.ranges.pop();
58309
+ }
58310
+ if (id !== null) this.ranges.push({ id, v0: v, v1: -1, i0: i, i1: -1 });
58240
58311
  }
58241
58312
  get count() {
58242
58313
  return this.indices.length / 36;
@@ -58257,12 +58328,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58257
58328
  }
58258
58329
  /**
58259
58330
  * 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
58260
- * face is wound to look out of the solid.
58331
+ * 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).
58261
58332
  */
58262
- addHexahedron(corners) {
58333
+ addHexahedron(corners, open = {}) {
58263
58334
  if (corners.length !== 8) return;
58264
58335
  const centre = [0, 1, 2].map((k) => corners.reduce((sum2, c) => sum2 + c[k], 0) / 8);
58265
58336
  for (const quad of HEXAHEDRON_FACES) {
58337
+ if (open.start && quad === HEXAHEDRON_FACES[0] || open.end && quad === HEXAHEDRON_FACES[1]) continue;
58266
58338
  const a = corners[quad[0]], b = corners[quad[1]], c = corners[quad[2]], d = corners[quad[3]];
58267
58339
  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]];
58268
58340
  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]];
@@ -58297,6 +58369,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58297
58369
  /** The mesh of everything added, or null when nothing was. */
58298
58370
  mesh(THREE, material, name) {
58299
58371
  if (!this.indices.length) return null;
58372
+ this.piece(null);
58300
58373
  const geometry = new THREE.BufferGeometry();
58301
58374
  geometry.setAttribute("position", new THREE.Float32BufferAttribute(this.positions, 3));
58302
58375
  geometry.setAttribute("normal", new THREE.Float32BufferAttribute(this.normals, 3));
@@ -58307,6 +58380,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58307
58380
  mesh3.name = name;
58308
58381
  mesh3.castShadow = true;
58309
58382
  mesh3.receiveShadow = true;
58383
+ if (this.ranges.length) mesh3.userData.ranges = this.ranges.map((range3) => ({ ...range3 }));
58310
58384
  return mesh3;
58311
58385
  }
58312
58386
  };
@@ -58315,7 +58389,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58315
58389
  var FEED_Y = -0.6;
58316
58390
  var FEED_EXIT_Y = -0.15;
58317
58391
  var FEED_BOX_OFFSET = 0.25;
58318
- var BRICK_FACE_INSET = 0.014;
58392
+ function chaseDepth(diameter = CHASE_DIAMETER) {
58393
+ return PLASTER_PER_FACE + CHASE_CLEAR + diameter;
58394
+ }
58395
+ var CHASE_DIAMETER = 0.025;
58396
+ var CHASE_CLEAR = 6e-3;
58319
58397
  var SLAB_MIDDLE = 0.065;
58320
58398
  var CEILING_SLAB = 0.5;
58321
58399
  var PASSING_END_CLEAR = { water: 0.335, conduit: 0.485 };
@@ -58372,7 +58450,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58372
58450
  const inward = (alongU ? (box5[1] + box5[3]) / 2 : (box5[0] + box5[2]) / 2) - line;
58373
58451
  const side = Math.abs(across2) > 1e-3 ? Math.sign(across2) : inward >= 0 ? 1 : -1;
58374
58452
  const half = (wall.thickness ?? DEFAULT_THICKNESS) / 2;
58375
- const offset = options.surface ? half + (options.diameter ?? 0.02) / 2 : half - BRICK_FACE_INSET;
58453
+ const offset = options.surface ? half + (options.diameter ?? 0.02) / 2 : half - chaseDepth(options.diameter);
58376
58454
  const at4 = line + side * offset;
58377
58455
  return { u: alongU ? along2 : at4, v: alongU ? at4 : along2, wall };
58378
58456
  }
@@ -59048,6 +59126,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
59048
59126
  }
59049
59127
  var PIPE_WALL_FILL = 0.3;
59050
59128
  var WALL_PIPE_MASS = 3;
59129
+ var UNDER_SINK_RISER_OFF_WALL = 0.08;
59130
+ var UNDER_SINK_VALVE_RISE = 0.1;
59051
59131
  var pipeMass = (diameter, length2) => DENSITY.plastic * Math.PI * (diameter / 2) ** 2 * length2 * PIPE_WALL_FILL;
59052
59132
  function installUtilitiesWater(K, shared3) {
59053
59133
  const { THREE, _Y, _q, cursor, cylBase, part, pieceRecord, put } = K;
@@ -59247,7 +59327,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
59247
59327
  }
59248
59328
  }
59249
59329
  function underSink(tr) {
59250
- 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;
59330
+ 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;
59331
+ const pts = riserUnderBack(tr.points.map((p) => [p[0], p[2], p[1]]));
59251
59332
  const stage2 = cursor.stage;
59252
59333
  if (shared3.ctx.constructionStages) cursor.stage = "furniture";
59253
59334
  cursor.group = pt && pt.floor >= 0 ? "f" + Math.min(pt.floor, nA - 1) : "lot";
@@ -59259,6 +59340,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
59259
59340
  cursor.pc = null;
59260
59341
  cursor.stage = stage2;
59261
59342
  }
59343
+ function riserUnderBack(pts) {
59344
+ if (pts.length < 3 || shared3.ctx.visorScene) return pts;
59345
+ const wall = pts[0], mid = pts[1], dx = mid[0] - wall[0], dz = mid[2] - wall[2], L = Math.hypot(dx, dz);
59346
+ if (L <= UNDER_SINK_RISER_OFF_WALL) return pts;
59347
+ const x = wall[0] + dx / L * UNDER_SINK_RISER_OFF_WALL, z = wall[2] + dz / L * UNDER_SINK_RISER_OFF_WALL;
59348
+ const top = mid[1] + UNDER_SINK_VALVE_RISE;
59349
+ return [wall, ...pts.slice(1).map((p) => [x, Math.min(p[1], top), z])];
59350
+ }
59262
59351
  const defined = { createWater, PIPE_COLOR, pipe, _v3, waterPipes };
59263
59352
  Object.assign(K, defined);
59264
59353
  }
@@ -59605,15 +59694,15 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
59605
59694
  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]];
59606
59695
  return { ...solid2, aabb };
59607
59696
  }
59608
- var CHASE_CLEAR = 3e-3;
59697
+ var CHASE_CLEAR2 = 3e-3;
59609
59698
  function chasesIn(wall, core, runs) {
59610
59699
  const out = [];
59611
59700
  for (const r of runs) {
59612
59701
  const along2 = wall.alongU ? r.u : r.v, across2 = (wall.alongU ? r.v : r.u) - core.line;
59613
- if (along2 + r.radius + CHASE_CLEAR < wall.a0 || along2 - r.radius - CHASE_CLEAR > wall.a1 || r.y1 <= core.y0 || r.y0 >= core.y1) continue;
59702
+ if (along2 + r.radius + CHASE_CLEAR2 < wall.a0 || along2 - r.radius - CHASE_CLEAR2 > wall.a1 || r.y1 <= core.y0 || r.y0 >= core.y1) continue;
59614
59703
  if (Math.abs(across2) > wall.thickness / 2 + 1e-6) continue;
59615
- const back = Math.abs(across2) - (r.depth ?? r.radius) - CHASE_CLEAR;
59616
- 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 } : {} });
59704
+ const back = Math.abs(across2) - (r.depth ?? r.radius) - CHASE_CLEAR2;
59705
+ 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 } : {} });
59617
59706
  }
59618
59707
  return out;
59619
59708
  }
@@ -61143,7 +61232,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
61143
61232
  alias("tv", "flat_tv");
61144
61233
  alias("tv_large", "flat_tv");
61145
61234
  mine("coffee_table", (M, A) => FURNITURE.table(M, A, { noChairs: true }));
61146
- mine("coffee_table_round", (M, A) => FURNITURE.table(M, A, { without: true, round: true }));
61235
+ mine("coffee_table_round", (M, A) => FURNITURE.table(M, A, { noChairs: true, round: true }));
61147
61236
  mine("rug", FURNITURE.rug);
61148
61237
  mine("rug_small", FURNITURE.rug, "game (rug)");
61149
61238
  mine("shelf_unit", FURNITURE.shelf);
@@ -61872,17 +61961,23 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
61872
61961
  }
61873
61962
  var POTTED_PLANT_TYPES = /* @__PURE__ */ new Set(["floor_plant", "floor_plant_tall", "floor_plant_low", "plant_tall", "plant_short", "outdoor_pot", "table_plant"]);
61874
61963
  var PLANT_CLEAR = 0.04;
61875
- var PLANT_MIN_REACH = 0.14;
61964
+ var PLANT_MIN_REACH = 0.12;
61876
61965
  var PLANT_SPAN = [0.03, 2.4];
61966
+ var PLANT_HEIGHT_MARGIN = 1.5;
61877
61967
  function footprintOf(m) {
61878
61968
  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;
61879
61969
  return [m.x - hx, m.z - hz2, m.x + hx, m.z + hz2];
61880
61970
  }
61881
61971
  var reachTo = (x, z, x0, z0, x1, z1) => Math.hypot(Math.max(x0 - x, 0, x - x1), Math.max(z0 - z, 0, z - z1));
61882
61972
  function freeReachOf(p) {
61883
- const y0 = p.y + PLANT_SPAN[0], y1 = p.y + PLANT_SPAN[1];
61973
+ const tall = p.self.h != null && p.self.h > 0 ? Math.min(PLANT_SPAN[1], p.self.h * PLANT_HEIGHT_MARGIN) : PLANT_SPAN[1];
61974
+ const y0 = p.y + PLANT_SPAN[0], y1 = p.y + tall;
61884
61975
  let reach2 = Number.POSITIVE_INFINITY;
61885
- 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]));
61976
+ for (const b of p.boxes) {
61977
+ if (b[1] >= y1 || b[4] <= y0) continue;
61978
+ if (b[1] > p.y && p.x >= b[0] && p.x <= b[3] && p.z >= b[2] && p.z <= b[5]) continue;
61979
+ reach2 = Math.min(reach2, reachTo(p.x, p.z, b[0], b[2], b[3], b[5]));
61980
+ }
61886
61981
  for (const m of p.items) {
61887
61982
  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;
61888
61983
  const bottom = p.base + (m.y || 0), top = bottom + (m.h || 0);
@@ -61946,7 +62041,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
61946
62041
  const covers = [];
61947
62042
  for (const m of ordered) {
61948
62043
  if (m.type === "stairs") continue;
61949
- const exterior = m.outdoor || m.floor < 0, f = exterior ? -1 : Math.min(m.floor, R.floors.length - 1);
62044
+ const exterior = m.outdoor || m.floor < 0;
62045
+ if (exterior && m.category === "ground_cover" && shared3.ctx.noGroundSurfaces) continue;
62046
+ const f = exterior ? -1 : Math.min(m.floor, R.floors.length - 1);
61950
62047
  cursor.group = exterior && !(m.type === "cooking_gas_cylinder" && m.shelter && !shared3.ctx.visorScene) ? "lot" : "f" + Math.max(f, 0);
61951
62048
  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;
61952
62049
  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 };
@@ -62992,6 +63089,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
62992
63089
  const defined = { targetOf };
62993
63090
  Object.assign(K, defined);
62994
63091
  }
63092
+ var CORD_RADIUS = 6e-3;
62995
63093
  function installInteractablesBridge(K, shared3) {
62996
63094
  const { t, THREE, invalidate, invalidateShadow, cfg, DOC, LIGHT_TYPES, _Y, _q, _v3, accFor, applyLight, cursor, hashString, hudMessage, lightBase, pieceRecord, rgbOf, wallBlocks } = K;
62997
63095
  const enter = (...a) => K.enter(...a);
@@ -63137,9 +63235,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63137
63235
  const spec = ik.A.household.build(type, loc, mesh3.api);
63138
63236
  const out = mesh3.finish(spec);
63139
63237
  for (const l of out.lights) l.removeFromParent();
63140
- const group = ivGroup(ent), g0 = cursor.group, stage0 = cursor.stage, root = new THREE.Group();
63238
+ const group = type === "gas_bottle" && item.shelter && !shared3.ctx.visorScene ? "f0" : ivGroup(ent), g0 = cursor.group, stage0 = cursor.stage, root = new THREE.Group();
63141
63239
  root.name = "iv:" + ent.id;
63142
- const isInst = type === "electrical_panel" || type === "power_meter" || type === "service_entrance" || type === "gas_bottle";
63240
+ const isInst = type === "electrical_panel" || type === "power_meter" || type === "service_entrance";
63143
63241
  const isPlate = type === "wall_switch" || type === "wall_socket";
63144
63242
  const ivStage = shared3.ctx.constructionStages ? isInst ? "installations" : isPlate ? "finishes" : "furniture" : void 0;
63145
63243
  if (ivStage) root.userData.constructionStage = ivStage;
@@ -63195,6 +63293,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63195
63293
  if (root.children.length) IV.roots.push(E);
63196
63294
  return spec;
63197
63295
  }
63296
+ const floorFinishOf = (floor2) => shared3.ctx.constructionStages && !shared3.ctx.visorScene && floor2 === 0 ? FLOOR_OVER_GROUND : 0;
63198
63297
  function ivCords(IV) {
63199
63298
  const ik = IV.k, w = IV.world, wl = (o, p) => ik.GI.localToWorld(o.transform, p), g0 = cursor.group;
63200
63299
  const tube2 = (pts, radius, color2, ox, oy, oz, ry) => {
@@ -63221,15 +63320,16 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63221
63320
  if (!so || !sk) continue;
63222
63321
  const sp = wl(so, sk.pos), dir = [Math.sin(so.transform.ry), Math.cos(so.transform.ry)], last = pts[pts.length - 1];
63223
63322
  if (last[1] < 0.3 + E.pos[1]) {
63224
- const foot = [sp[0] + dir[0] * 0.035, E.pos[1] + 0.012, sp[2] + dir[1] * 0.035];
63225
- 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]);
63323
+ const lie = E.pos[1] + floorFinishOf(E.floor) + CORD_RADIUS + 1e-3;
63324
+ const foot = [sp[0] + dir[0] * 0.035, lie, sp[2] + dir[1] * 0.035];
63325
+ 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]);
63226
63326
  } else {
63227
63327
  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);
63228
63328
  hang.shift();
63229
63329
  for (const p of hang) pts.push(p);
63230
63330
  }
63231
63331
  shared3.ctx.cordPaths?.push({ object: E.id, device: d.id, points: pts.map((p) => [p[0], p[1], p[2]]) });
63232
- tube2(pts, 6e-3, IV_WIRE.cord, 0, 0, 0, 0);
63332
+ tube2(pts, CORD_RADIUS, IV_WIRE.cord, 0, 0, 0, 0);
63233
63333
  }
63234
63334
  }
63235
63335
  } finally {
@@ -66078,6 +66178,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66078
66178
  return level >= STAGE_LEVEL.openings;
66079
66179
  case "roof":
66080
66180
  return level >= STAGE_LEVEL.roof && opts.roofLayer !== false;
66181
+ // 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
66182
+ case "roofFraming":
66183
+ return level >= STAGE_LEVEL.roofFraming && opts.roofLayer !== false;
66081
66184
  case "furniture":
66082
66185
  return level >= STAGE_LEVEL.last;
66083
66186
  // the protective sidewalk round the house: the last of the work outside
@@ -66143,6 +66246,50 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66143
66246
  }
66144
66247
  return level;
66145
66248
  }
66249
+ function partStagesOf(house) {
66250
+ const stages = /* @__PURE__ */ new Map();
66251
+ const walk = (o, inherited) => {
66252
+ const own = typeof o.userData?.constructionStage === "string" ? o.userData.constructionStage : inherited;
66253
+ const part = o.userData?.destructionPart;
66254
+ if (own && typeof part === "string" && !stages.has(part)) stages.set(part, own);
66255
+ const ranges = o.userData?.ranges;
66256
+ if (own && Array.isArray(ranges)) {
66257
+ for (const range3 of ranges) if (!stages.has(range3.id)) stages.set(range3.id, own);
66258
+ }
66259
+ for (const c of o.children) walk(c, own);
66260
+ };
66261
+ walk(house, void 0);
66262
+ return stages;
66263
+ }
66264
+ function stageOfPiece(piece2, stages) {
66265
+ let found;
66266
+ piece2.root.traverse((o) => {
66267
+ if (found) return;
66268
+ const part = o.userData?.destructionPart;
66269
+ if (typeof part === "string") found = stages.get(part);
66270
+ });
66271
+ return found;
66272
+ }
66273
+ function stageLoosePieces(pieces, stages, level, opts, held) {
66274
+ let hidden = 0;
66275
+ for (const piece2 of pieces) {
66276
+ const stage2 = stageOfPiece(piece2, stages);
66277
+ if (!stage2) continue;
66278
+ const shown2 = stageVisible(stage2, level, opts);
66279
+ piece2.root.visible = shown2;
66280
+ if (!shown2) {
66281
+ hidden++;
66282
+ if (!piece2.held) {
66283
+ piece2.held = true;
66284
+ held.add(piece2);
66285
+ }
66286
+ } else if (held.has(piece2)) {
66287
+ piece2.held = false;
66288
+ held.delete(piece2);
66289
+ }
66290
+ }
66291
+ return hidden;
66292
+ }
66146
66293
  var INSTALLATIONS_STAGE = "stage:4:installations";
66147
66294
  function toWorld2(THREE, object2, x, z) {
66148
66295
  return new THREE.Vector3(x, 0, z).applyMatrix4(object2.matrixWorld);
@@ -66174,24 +66321,53 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66174
66321
  hip: { top: 0.065, width: 0.06, height: 0.14 },
66175
66322
  post: { side: 0.07, spacing: 2 }
66176
66323
  };
66324
+ 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];
66177
66325
  var EDGE2 = 0.04;
66178
- function addTimber(batch, top0, top1, width, height) {
66326
+ var ROOF_TIMBER_STRETCH = 1.2;
66327
+ var ROOF_TIMBER_MATERIAL = "wood_hard";
66328
+ var TIMBER_DENSITY = 750;
66329
+ var TimberLog = class {
66330
+ constructor(prefix, onPiece) {
66331
+ __publicField2(this, "prefix", prefix);
66332
+ __publicField2(this, "onPiece", onPiece);
66333
+ __publicField2(this, "count", 0);
66334
+ }
66335
+ next(kind, mass, chain) {
66336
+ const id = `${this.prefix}:${this.count++}`;
66337
+ this.onPiece({ id, kind, mass, chain });
66338
+ return id;
66339
+ }
66340
+ };
66341
+ var LOGS = /* @__PURE__ */ new WeakMap();
66342
+ function addTimber(batch, top0, top1, width, height, kind) {
66179
66343
  const dx = top1[0] - top0[0], dz = top1[2] - top0[2];
66180
66344
  const flat2 = Math.hypot(dx, dz);
66181
66345
  if (flat2 < 1e-4 && Math.abs(top1[1] - top0[1]) < 1e-4) return;
66182
66346
  const sx = flat2 < 1e-4 ? width / 2 : -dz / flat2 * (width / 2);
66183
66347
  const sz = flat2 < 1e-4 ? 0 : dx / flat2 * (width / 2);
66184
66348
  const corner = (p, side, down2) => [p[0] + sx * side, p[1] - down2, p[2] + sz * side];
66185
- batch.addHexahedron([
66186
- corner(top0, -1, height),
66187
- corner(top0, 1, height),
66188
- corner(top0, 1, 0),
66189
- corner(top0, -1, 0),
66190
- corner(top1, -1, height),
66191
- corner(top1, 1, height),
66192
- corner(top1, 1, 0),
66193
- corner(top1, -1, 0)
66194
- ]);
66349
+ const log = LOGS.get(batch);
66350
+ const length2 = Math.hypot(dx, top1[1] - top0[1], dz);
66351
+ const stretches = log ? Math.max(1, Math.ceil(length2 / ROOF_TIMBER_STRETCH)) : 1;
66352
+ let before = null;
66353
+ for (let k = 0; k < stretches; k++) {
66354
+ const a = along(top0, top1, k / stretches), b = along(top0, top1, (k + 1) / stretches);
66355
+ if (log) {
66356
+ before = log.next(kind, TIMBER_DENSITY * width * height * (length2 / stretches), before ? [before] : []);
66357
+ batch.piece(before);
66358
+ }
66359
+ batch.addHexahedron([
66360
+ corner(a, -1, height),
66361
+ corner(a, 1, height),
66362
+ corner(a, 1, 0),
66363
+ corner(a, -1, 0),
66364
+ corner(b, -1, height),
66365
+ corner(b, 1, height),
66366
+ corner(b, 1, 0),
66367
+ corner(b, -1, 0)
66368
+ ], { start: k > 0, end: k < stretches - 1 });
66369
+ }
66370
+ if (log) batch.piece(null);
66195
66371
  }
66196
66372
  var KEEP_OUT_GAP = 0.03;
66197
66373
  function clearStretches(top0, top1, width, height, keepOut) {
@@ -66215,16 +66391,15 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66215
66391
  }
66216
66392
  return stretches;
66217
66393
  }
66218
- 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];
66219
- function addTimberAround(batch, top0, top1, width, height, keepOut, onCut) {
66394
+ function addTimberAround(batch, top0, top1, width, height, kind, keepOut, onCut) {
66220
66395
  if (!keepOut.length) {
66221
- addTimber(batch, top0, top1, width, height);
66396
+ addTimber(batch, top0, top1, width, height, kind);
66222
66397
  return;
66223
66398
  }
66224
66399
  const length2 = Math.hypot(top1[0] - top0[0], top1[1] - top0[1], top1[2] - top0[2]);
66225
66400
  for (const [f0, f1] of clearStretches(top0, top1, width, height, keepOut)) {
66226
66401
  if ((f1 - f0) * length2 < 0.05) continue;
66227
- addTimber(batch, along(top0, top1, f0), along(top0, top1, f1), width, height);
66402
+ addTimber(batch, along(top0, top1, f0), along(top0, top1, f1), width, height, kind);
66228
66403
  const inset = TIMBER.post.side / 2 / Math.max(length2, 1e-6);
66229
66404
  if (f0 > 0) onCut?.(along(top0, top1, Math.min(f1, f0 + inset)));
66230
66405
  if (f1 < 1) onCut?.(along(top0, top1, Math.max(f0, f1 - inset)));
@@ -66233,7 +66408,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66233
66408
  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);
66234
66409
  function addPost(batch, x, z, y0, y1) {
66235
66410
  const h = TIMBER.post.side / 2;
66236
- if (y1 - y0 > 0.02) batch.add([x - h, y0, z - h, x + h, y1, z + h], true);
66411
+ if (y1 - y0 <= 0.02) return;
66412
+ const log = LOGS.get(batch);
66413
+ if (log) batch.piece(log.next("post", TIMBER_DENSITY * TIMBER.post.side * TIMBER.post.side * (y1 - y0), []));
66414
+ batch.add([x - h, y0, z - h, x + h, y1, z + h], true);
66415
+ if (log) batch.piece(null);
66237
66416
  }
66238
66417
  function slopesOf(rect) {
66239
66418
  const [x0, z0, x1, z1] = rect.exterior;
@@ -66291,7 +66470,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66291
66470
  const a = a0 + BATTEN_SHORT, b = b0 - BATTEN_SHORT;
66292
66471
  if (b - a <= 0.05) continue;
66293
66472
  const at4 = battenClearOfSolids(slope, s, [a, b], solids2);
66294
- addTimberAround(batches.battens, down(slope.point(at4, a), batten.top), down(slope.point(at4, b), batten.top), batten.width, batten.height, keepOut);
66473
+ addTimberAround(batches.battens, down(slope.point(at4, a), batten.top), down(slope.point(at4, b), batten.top), batten.width, batten.height, "batten", keepOut);
66295
66474
  }
66296
66475
  const t0 = slope.t0 + EDGE2, t1 = slope.t1 - EDGE2;
66297
66476
  const count = Math.max(1, Math.round((t1 - t0) / rafter.spacing));
@@ -66301,7 +66480,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66301
66480
  if (end3 < 0.1) continue;
66302
66481
  const axis2 = slope.point(0, 1)[0] - slope.point(0, 0)[0] !== 0 ? 0 : 2;
66303
66482
  const t = clearOfSolids(at4, rafter.width, down(slope.point(EDGE2, at4), rafter.top), down(slope.point(end3, at4), rafter.top), axis2, solids2);
66304
- addTimberAround(batches.timber, down(slope.point(EDGE2, t), rafter.top), down(slope.point(end3, t), rafter.top), rafter.width, rafter.height, keepOut);
66483
+ addTimberAround(batches.timber, down(slope.point(EDGE2, t), rafter.top), down(slope.point(end3, t), rafter.top), rafter.width, rafter.height, "rafter", keepOut);
66305
66484
  }
66306
66485
  const lines = [slope.wall, slope.wall + (slope.run - slope.wall) / 3, slope.wall + (slope.run - slope.wall) * 2 / 3];
66307
66486
  lines.forEach((s, k) => {
@@ -66311,7 +66490,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66311
66490
  const p0 = down(slope.point(s, a), top), p1 = down(slope.point(s, b), top);
66312
66491
  const depth = Math.min(purlin.height, p0[1] - slabTop - 3e-3);
66313
66492
  if (depth < 0.02) return;
66314
- 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));
66493
+ 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));
66315
66494
  if (k === 0) return;
66316
66495
  const posts = Math.max(1, Math.ceil((b - a) / TIMBER.post.spacing));
66317
66496
  for (let j = 0; j <= posts; j++) {
@@ -66343,10 +66522,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66343
66522
  }
66344
66523
  return out;
66345
66524
  }
66346
- function buildRoofFramingStage(THREE, roofRects, material, solids2 = [], keepOut = []) {
66525
+ function buildRoofFramingStage(THREE, roofRects, material, solids2 = [], keepOut = [], onPiece) {
66347
66526
  const group = new THREE.Group();
66348
66527
  group.name = "stage:7:roof_framing";
66349
66528
  const timber = new BoxBatch(), battens = new BoxBatch();
66529
+ if (onPiece) {
66530
+ LOGS.set(timber, new TimberLog("roof_timber", onPiece));
66531
+ LOGS.set(battens, new TimberLog("roof_batten", onPiece));
66532
+ }
66350
66533
  for (const rr of roofRects) {
66351
66534
  if (rr.slab || rr.yb === void 0 || rr.tp === void 0 || !rr.exterior || rr.rm === void 0 || rr.alongX === void 0) continue;
66352
66535
  const rect = { yb: rr.yb, tp: rr.tp, exterior: rr.exterior, rm: rr.rm, alongX: rr.alongX, r: rr.r, gable: !!rr.gable };
@@ -66357,7 +66540,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66357
66540
  const xm = (x0 + x1) / 2, zm = (z0 + z1) / 2;
66358
66541
  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]];
66359
66542
  const ridgeTop = TIMBER.purlin.top;
66360
- 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));
66543
+ 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));
66361
66544
  const along2 = Math.hypot(ends[1][0] - ends[0][0], ends[1][2] - ends[0][2]);
66362
66545
  const posts = Math.max(1, Math.ceil(along2 / TIMBER.post.spacing));
66363
66546
  for (let j = 0; j <= posts; j++) {
@@ -66373,12 +66556,17 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66373
66556
  const corners = [[x0 + e, h, z0 + e], [x1 - e, h, z0 + e], [x0 + e, h, z1 - e], [x1 - e, h, z1 - e]];
66374
66557
  for (const c of corners) {
66375
66558
  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];
66376
- addTimberAround(timber, down(c, TIMBER.hip.top), down(end3, TIMBER.hip.top), TIMBER.hip.width, TIMBER.hip.height, keepOut);
66559
+ addTimberAround(timber, down(c, TIMBER.hip.top), down(end3, TIMBER.hip.top), TIMBER.hip.width, TIMBER.hip.height, "hip", keepOut);
66377
66560
  }
66378
66561
  }
66379
66562
  }
66380
66563
  const wood = material ?? new THREE.MeshStandardMaterial({ color: 11042380, roughness: 0.82 });
66381
- for (const mesh3 of [timber.mesh(THREE, wood, "roof_framing:timber"), battens.mesh(THREE, wood, "roof_framing:battens")]) if (mesh3) group.add(mesh3);
66564
+ for (const mesh3 of [timber.mesh(THREE, wood, "roof_framing:timber"), battens.mesh(THREE, wood, "roof_framing:battens")]) {
66565
+ if (!mesh3) continue;
66566
+ mesh3.userData.constructionStage = "roofFraming";
66567
+ if (onPiece) mesh3.userData.destructionMaterial = ROOF_TIMBER_MATERIAL;
66568
+ group.add(mesh3);
66569
+ }
66382
66570
  return group;
66383
66571
  }
66384
66572
  var HOUSE_SHADOW_BUDGET_MS = 2;
@@ -66421,6 +66609,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66421
66609
  }
66422
66610
  };
66423
66611
  }
66612
+ var ROOF_TIMBER_REACH = 3;
66424
66613
  function withLaidConduits(r, stages) {
66425
66614
  const E = r.utilities?.electrical;
66426
66615
  if (!stages || !E || !E.conduits?.length) return r;
@@ -66478,7 +66667,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66478
66667
  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 };
66479
66668
  }
66480
66669
  function installBuildBuild(K, shared3) {
66481
- 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;
66670
+ 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;
66482
66671
  function build(r0, options) {
66483
66672
  const opts = options || {};
66484
66673
  const r = withLaidConduits(applyOutbuildings(r0), !!(opts.constructionStages || opts.constructionLevel != null));
@@ -66496,6 +66685,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66496
66685
  shared3.ctx.colliders = [];
66497
66686
  shared3.ctx.stairs = [];
66498
66687
  shared3.ctx.noTerrain = opts.terrain === false;
66688
+ shared3.ctx.noGroundSurfaces = opts.groundSurfaces === false;
66499
66689
  shared3.ctx.serviceFrom = opts.serviceFrom ?? null;
66500
66690
  shared3.ctx.roomById = {};
66501
66691
  for (const c of r.rooms) shared3.ctx.roomById[c.id] = c;
@@ -66647,6 +66837,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66647
66837
  (k === "floor" || k === "building" ? root : house).add(g);
66648
66838
  }
66649
66839
  let currentConstructionLevel = CONSTRUCTION_LEVEL_MAX;
66840
+ let partStages = null, stageOptsNow = {}, piecesStaged = -1;
66841
+ const stageHeld = /* @__PURE__ */ new Set();
66650
66842
  h.groups = gs;
66651
66843
  h.root = root;
66652
66844
  h.house = house;
@@ -66827,22 +67019,34 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66827
67019
  return house.localToWorld(localCenter.clone());
66828
67020
  };
66829
67021
  const distance4 = (focus) => center().distanceTo(focus instanceof THREE.Vector3 ? focus : new THREE.Vector3(focus.x, focus.y, focus.z));
66830
- markGroups(r, root, parts2);
66831
- const structure = assembleStructure(r0, root), destruction = createHouseDestruction(root, house, structure, parts2, colliders, water);
66832
- h.destruction = destruction;
66833
- destruction.breach.setLod(h.lodCurrent);
66834
67022
  if (cs) {
66835
67023
  const bp = buildBlueprintStage(THREE, K.DOC, r, rectsOf2);
66836
67024
  const stGroups = buildStructuralStageGroups(THREE, r0.structure, r.outbuildings || [], [...embeddedRunsOf(house), ...wallBoxRunsOf(r, shared3.ctx.wallBoxShifts)], shared3.ctx.blockLaid ?? []);
66837
67025
  const instGroup = buildInstallationsStage(THREE, r, shared3.ctx.gutterInfo?.drains ?? [], shared3.ctx.paving ?? []);
66838
- 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 ?? [])]);
67026
+ 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) => {
67027
+ 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 } : {} });
67028
+ });
66839
67029
  const yardBoxes = instGroup.userData.yardBoxes;
66840
67030
  for (const sg of [bp, stGroups.foundation, stGroups.starterBars, stGroups.frame, stGroups.masonry, instGroup, ...yardBoxes ? [yardBoxes] : [], roofFraming]) {
66841
67031
  gs[sg.name] = sg;
66842
67032
  house.add(sg);
66843
67033
  }
66844
- currentConstructionLevel = applyConstructionLevel(house, opts.constructionLevel ?? CONSTRUCTION_LEVEL_MAX);
66845
67034
  }
67035
+ markGroups(r, root, parts2);
67036
+ const structure = assembleStructure(r0, root), destruction = createHouseDestruction(root, house, structure, parts2, colliders, water);
67037
+ h.destruction = destruction;
67038
+ destruction.breach.setLod(h.lodCurrent);
67039
+ if (cs) {
67040
+ currentConstructionLevel = applyConstructionLevel(house, opts.constructionLevel ?? CONSTRUCTION_LEVEL_MAX);
67041
+ partStages = partStagesOf(house);
67042
+ }
67043
+ const stagePieces = () => {
67044
+ const R = destruction.renderer;
67045
+ if (!partStages || !R?.pieces) return;
67046
+ const list2 = R.pieces();
67047
+ piecesStaged = list2.length;
67048
+ stageLoosePieces(list2, partStages, currentConstructionLevel, stageOptsNow, stageHeld);
67049
+ };
66846
67050
  const strikePiece = (id, point, type, amount, d, before) => {
66847
67051
  if (!destruction.world) return;
66848
67052
  const pid = id && structure.byId.has(id) ? id : parts2[id] && parts2[id].type === "water_tank" && structure.byId.has("water_tank") ? "water_tank" : null;
@@ -66924,6 +67128,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66924
67128
  // 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
66925
67129
  update(dt, time, focus) {
66926
67130
  enter(h);
67131
+ if (partStages && currentConstructionLevel < CONSTRUCTION_LEVEL_MAX && destruction.renderer?.pieces && destruction.renderer.pieces().length !== piecesStaged) stagePieces();
66927
67132
  animateDoors(dt);
66928
67133
  animateInteractive(dt);
66929
67134
  water.step(dt);
@@ -66957,12 +67162,16 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
66957
67162
  g.visible = v;
66958
67163
  }
66959
67164
  if (cs && currentConstructionLevel < CONSTRUCTION_LEVEL_MAX) {
66960
- applyConstructionLevel(house, currentConstructionLevel, { roofLayer: !cut && sel < 0, lotLayer: o.lot !== false });
67165
+ stageOptsNow = { roofLayer: !cut && sel < 0, lotLayer: o.lot !== false };
67166
+ applyConstructionLevel(house, currentConstructionLevel, stageOptsNow);
67167
+ stagePieces();
66961
67168
  }
66962
67169
  },
66963
67170
  setConstructionLevel(level, stageOpts) {
66964
67171
  enter(h);
67172
+ stageOptsNow = stageOpts ?? {};
66965
67173
  currentConstructionLevel = applyConstructionLevel(house, level, stageOpts);
67174
+ stagePieces();
66966
67175
  invalidateShadow();
66967
67176
  return currentConstructionLevel;
66968
67177
  },
@@ -98067,7 +98276,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
98067
98276
  }
98068
98277
  var DEGREES = 180 / Math.PI;
98069
98278
 
98070
- // ../game-vfx-three/dist/chunk-GHLGSWLP.js
98279
+ // ../game-vfx-three/dist/chunk-EE6XER4D.js
98071
98280
  var GLOW_VERTEX = `attribute vec4 aP;attribute vec4 aC;varying vec2 vU;varying vec4 vC;
98072
98281
  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]);
98073
98282
  vec3 wp=aP.xyz+(R*position.x+Up*position.y)*aP.w;vU=position.xy;vC=aC;gl_Position=projectionMatrix*viewMatrix*vec4(wp,1.);}`;
@@ -98083,21 +98292,22 @@ float vn(vec3 x){vec3 i=floor(x),f=fract(x);f=f*f*(3.-2.*f);
98083
98292
  `;
98084
98293
  var PUFF_VERTEX = `${GL_NOISE}
98085
98294
  attribute vec4 aP;attribute vec4 aD;attribute vec3 aC;
98086
- varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;
98295
+ varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;varying vec3 vN;
98087
98296
  void main(){
98088
98297
  vec3 p=position;
98298
+ vec3 q=normalize(position);
98089
98299
  float s=aD.z;
98090
98300
  float n=vn(p*1.6+vec3(s*11.0,s*7.0,s*3.0));
98091
98301
  p*=0.78+0.5*n;
98092
- float a=s*6.2831;float c=cos(a),si=sin(a);p.xz=mat2(c,-si,si,c)*p.xz;
98093
- vL=p;
98302
+ 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;
98303
+ vL=p;vN=q;
98094
98304
  vec3 wp=aP.xyz+p*aP.w;
98095
98305
  vWP=wp;vD=aD;vC=aC;
98096
98306
  gl_Position=projectionMatrix*viewMatrix*vec4(wp,1.0);
98097
98307
  }`;
98098
98308
  var PUFF_FRAGMENT = `${GL_NOISE}
98099
98309
  uniform vec3 uLight;uniform vec3 uSky;uniform vec3 uGround;uniform vec3 uGlowPos;uniform vec3 uGlowCol;uniform float uGlowI;
98100
- varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;
98310
+ varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;varying vec3 vN;
98101
98311
  vec3 L(vec3 c){return pow(c,vec3(2.2));}
98102
98312
  vec3 ramp(float h){
98103
98313
  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));
@@ -98107,30 +98317,35 @@ vec3 ramp(float h){
98107
98317
  return mix(c3,c4,clamp((h-.8)/.4,0.,1.));
98108
98318
  }
98109
98319
  void main(){
98110
- vec3 N=normalize(cross(dFdx(vWP),dFdy(vWP)));
98111
98320
  float age=vD.x,heat=vD.y,kind=vD.w;
98112
98321
  float n=vn(vL*2.4+vD.z*13.0);
98113
- float diss=smoothstep(.5,1.,age);
98114
- if(n<diss*1.08-.04)discard;
98322
+ // the sphere's own normal, roughened by the noise: a billowing cloud, never facets
98323
+ 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;
98324
+ vec3 N=normalize(normalize(vN)+g*.9);
98325
+ vec3 V=normalize(cameraPosition-vWP);
98115
98326
  float lam=max(dot(N,uLight),0.);
98116
- float band=lam>.55?1.:lam>.15?.68:.42;
98117
- // 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)
98327
+ float light=.42+.62*smoothstep(-.1,.9,lam);
98118
98328
  float dark=1.-smoothstep(.02,.12,dot(vC,vec3(.2126,.7152,.0722)));
98119
98329
  vec3 alb=max(vC,vec3(.055)*dark);
98120
- vec3 col=alb*(vec3(.5,.56,.7)*band*1.05+vec3(.2,.19,.18)+uGround*(.4-.4*N.y));
98121
- float rim=pow(1.-clamp(abs(dot(N,normalize(cameraPosition-vWP))),0.,1.),2.);
98330
+ vec3 col=alb*(vec3(.5,.56,.7)*light*1.05+vec3(.2,.19,.18)+uGround*(.4-.4*N.y));
98331
+ float rim=pow(1.-clamp(abs(dot(normalize(vN),V)),0.,1.),2.);
98122
98332
  col+=dark*rim*(uSky*.9+alb);
98123
98333
  vec3 tg=uGlowPos-vWP;float dg=length(tg)+.001;
98124
98334
  float gi=uGlowI/(1.+dg*dg*.05)*(.3+.7*max(dot(N,tg/dg),0.));
98125
98335
  col+=uGlowCol*gi*alb*1.6;
98336
+ // seen through: thin where the camera grazes the puff, thicker where the noise is, thinning out with age
98337
+ float facing=abs(dot(normalize(vN),V));
98338
+ float alpha=smoothstep(.0,.75,facing)*(.35+.65*smoothstep(.2,.8,n))*(1.-smoothstep(.3,1.,age))*.78;
98126
98339
  float h=heat*(.72+.56*n)+heat*(-N.y)*.18;
98127
98340
  if(h>.05){
98128
- float hq=floor(h*5.+.5)/5.;
98129
- vec3 fc=ramp(clamp(hq,0.,1.2))*(1.1+3.1*hq);
98130
- col=mix(col,fc,smoothstep(.04,.2,h));
98341
+ vec3 fc=ramp(clamp(h,0.,1.2))*(1.1+3.1*h);
98342
+ float hot=smoothstep(.04,.2,h);
98343
+ col=mix(col,fc,hot);
98344
+ alpha=max(alpha,hot*smoothstep(.0,.45,facing)*(1.-smoothstep(.5,1.,age)));
98131
98345
  }
98132
98346
  if(kind>2.5&&kind<3.5){col+=vec3(.02,.025,.03);}
98133
- gl_FragColor=vec4(col,1.);
98347
+ if(alpha<.01)discard;
98348
+ gl_FragColor=vec4(col,alpha);
98134
98349
  #include <tonemapping_fragment>
98135
98350
  #include <colorspace_fragment>
98136
98351
  }`;
@@ -98165,10 +98380,11 @@ void main(){
98165
98380
  function dynamic(THREE, array, size) {
98166
98381
  return new THREE.InstancedBufferAttribute(array, size).setUsage(THREE.DynamicDrawUsage);
98167
98382
  }
98383
+ var PUFF_DETAIL = 2;
98168
98384
  function createPuffLayer(THREE, pool, uniforms) {
98169
98385
  const capacity = pool.capacity;
98170
98386
  const geometry = new THREE.InstancedBufferGeometry();
98171
- geometry.setAttribute("position", new THREE.IcosahedronGeometry(1, 1).getAttribute("position"));
98387
+ geometry.setAttribute("position", new THREE.IcosahedronGeometry(1, PUFF_DETAIL).getAttribute("position"));
98172
98388
  const a = new Float32Array(capacity * 4);
98173
98389
  const d = new Float32Array(capacity * 4);
98174
98390
  const c = new Float32Array(capacity * 3);
@@ -98177,7 +98393,7 @@ void main(){
98177
98393
  geometry.setAttribute("aD", attributes[1]);
98178
98394
  geometry.setAttribute("aC", attributes[2]);
98179
98395
  geometry.instanceCount = 0;
98180
- const material = new THREE.ShaderMaterial({ uniforms, vertexShader: PUFF_VERTEX, fragmentShader: PUFF_FRAGMENT });
98396
+ const material = new THREE.ShaderMaterial({ uniforms, vertexShader: PUFF_VERTEX, fragmentShader: PUFF_FRAGMENT, transparent: true, depthWrite: false });
98181
98397
  const mesh3 = new THREE.Mesh(geometry, material);
98182
98398
  mesh3.name = "vfx-puffs";
98183
98399
  mesh3.frustumCulled = false;