@adatechnology/game-interactables-household 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,16 +28,17 @@ var GameInteractablesHousehold = (() => {
28
28
  HOUSEHOLD_TYPES: () => HOUSEHOLD_TYPES,
29
29
  STOVE_WALL_GAP: () => STOVE_WALL_GAP,
30
30
  WALL_PLATE: () => WALL_PLATE,
31
+ assembleHouseholdType: () => assembleHouseholdType,
31
32
  cornersOf: () => cornersOf,
32
33
  createHousehold: () => createHousehold,
34
+ createHouseholdAssemblies: () => createHouseholdAssemblies,
33
35
  createRecorder: () => createRecorder,
36
+ drawHouseholdAssembly: () => drawHouseholdAssembly,
34
37
  motionPoint: () => motionPoint,
35
38
  sweepOf: () => sweepOf
36
39
  });
37
40
 
38
- // ../game-contracts/dist/index.js
39
- var DEFAULT_BLAST_IMPULSE = { bodyArea: 0.7, lift: 0.15, minSpeed: 0.3, tntPerJoule: 0.24 / 2e5 };
40
- var DEFAULT_COST_ALLOCATION_BYTES = 1024 * 1024;
41
+ // ../game-contracts/src/spec.ts
41
42
  var STRUCTURE_ROLES = ["foundation", "column", "beam", "slab", "wall", "partition", "roof", "stair", "none"];
42
43
  var BEARS = [true, false, "a_on_b", "b_on_a"];
43
44
  var finite = (n) => typeof n === "number" && Number.isFinite(n);
@@ -140,48 +141,16 @@ var GameInteractablesHousehold = (() => {
140
141
  }
141
142
  return { ok: problems.length === 0, problems, warnings };
142
143
  };
144
+
145
+ // ../game-contracts/src/seal.ts
143
146
  var sealBlock = (seal, state) => {
144
147
  if (seal.spoilsWhenBreached && state.breached) return "breached";
145
148
  if (seal.spoilsWhenBreached && state.leaked) return "leaked";
146
149
  if (!state.opened) return "sealed";
147
150
  return void 0;
148
151
  };
149
- var DEFERRED_QUEUE_ID = {
150
- DESTRUCTION_EVENTS: "destruction.events",
151
- BREACH_PAINT: "floorplan.breach-paint",
152
- BREACH_CUT: "floorplan.breach-cut",
153
- AUDIO_VOICES: "audio.voices",
154
- VEHICLE_CREASE: "vehicles.crease",
155
- AUDIO_OCCLUSION: "audio.occlusion",
156
- FLUID_FILM: "fluids.film",
157
- VEHICLE_LOD_BATCH: "vehicles.lod-batch",
158
- SETTLED_BATCH: "destruction.settled-batch",
159
- STATIC_BATCH: "render.static-batch",
160
- ANIMALS_STATIC_BATCH: "animals.static-batch",
161
- CHARACTERS_STATIC_BATCH: "characters.static-batch",
162
- HOUSE_SHADOW_BATCH: "floorplan.shadow-batch",
163
- DESTRUCTION_PREFIT: "destruction.prefit"
164
- };
165
- var DEFERRED_PRIORITY = {
166
- [DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS]: { priority: 300, phase: "present" },
167
- // every frame: the walls cut since the last frame are painted once each, and a hole must show in the frame of the blast
168
- [DEFERRED_QUEUE_ID.BREACH_CUT]: { priority: 260, phase: "present", minEveryFrames: 1 },
169
- [DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present", minEveryFrames: 1 },
170
- [DEFERRED_QUEUE_ID.AUDIO_VOICES]: { priority: 200, phase: "idle", reserveMs: 1 },
171
- [DEFERRED_QUEUE_ID.AUDIO_OCCLUSION]: { priority: 190, phase: "idle", minEveryFrames: 8 },
172
- [DEFERRED_QUEUE_ID.FLUID_FILM]: { priority: 120, phase: "idle", minEveryFrames: 2 },
173
- [DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" },
174
- [DEFERRED_QUEUE_ID.VEHICLE_LOD_BATCH]: { priority: 90, phase: "idle", minEveryFrames: 4 },
175
- [DEFERRED_QUEUE_ID.SETTLED_BATCH]: { priority: 70, phase: "idle", minEveryFrames: 8 },
176
- [DEFERRED_QUEUE_ID.STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
177
- [DEFERRED_QUEUE_ID.ANIMALS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
178
- [DEFERRED_QUEUE_ID.CHARACTERS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
179
- [DEFERRED_QUEUE_ID.HOUSE_SHADOW_BATCH]: { priority: 50, phase: "idle", minEveryFrames: 8 },
180
- [DEFERRED_QUEUE_ID.DESTRUCTION_PREFIT]: { priority: 40, phase: "idle", minEveryFrames: 30 }
181
- };
182
- var MUST_DRAIN_QUEUE_IDS = /* @__PURE__ */ new Set([DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS, DEFERRED_QUEUE_ID.BREACH_CUT]);
183
- var BODY_FOAM_SURFACES = ["hands", "arms", "torso", "hair", "mouth"];
184
- var WASH_SURFACES = [...BODY_FOAM_SURFACES, "brush"];
152
+
153
+ // ../game-contracts/src/warn.ts
185
154
  var WARNED_KEY = /* @__PURE__ */ Symbol.for("@adatechnology/game-contracts.warned");
186
155
  var warnedKeys = () => {
187
156
  const holder = globalThis;
@@ -202,6 +171,8 @@ var GameInteractablesHousehold = (() => {
202
171
  seen.add(key);
203
172
  console.warn(`[game-kit] ${message}`);
204
173
  };
174
+
175
+ // ../game-contracts/src/registry.ts
205
176
  var UNSAFE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
206
177
  var isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) && Object.getPrototypeOf(value) === Object.prototype;
207
178
  var deepMerge = (base, patch) => {
@@ -231,6 +202,8 @@ var GameInteractablesHousehold = (() => {
231
202
  if (!entries.delete(id)) warnOnce(`registry.remove.${id}`, `remove of "${id}" ignored: no entry has that id`);
232
203
  }
233
204
  };
205
+
206
+ // ../game-contracts/src/categories.ts
234
207
  var defineCategories = (defs, options = {}) => {
235
208
  const problems = [];
236
209
  const duplicates = (list) => {
@@ -294,60 +267,55 @@ var GameInteractablesHousehold = (() => {
294
267
  return registry;
295
268
  };
296
269
  var resolveEntry = (registry, entry, kindField = "kind") => deepMerge(registry.defaults(String(entry[kindField])), entry);
297
- var SURFACE_IDS = ["concrete", "asphalt", "wood", "tile", "dirt", "grass", "gravel", "sand", "metal", "water", "glass", "carpet"];
298
- var GAIT_IDS = ["walk", "run"];
299
- var LANDING_IDS = ["light", "heavy"];
300
- var BODY_SOUND_IDS = [
301
- "jump",
302
- "cloth_rustle",
303
- "body_fall",
304
- "fall_damage",
305
- "player_hurt",
306
- "player_breath_run",
307
- "player_death",
308
- "bite",
309
- "grab",
310
- "punch_swing",
311
- "punch_hit_body",
312
- "punch_hit_face",
313
- "punch_hit_object",
314
- "kick_swing",
315
- "kick_hit",
316
- "kick_hit_object",
317
- "shove_two_hands",
318
- "knife_swing",
319
- "knife_stab",
320
- "knife_slash",
321
- "knife_hit_object",
322
- "blunt_swing",
323
- "blunt_hit",
324
- "blunt_hit_object",
325
- "axe_swing",
326
- "axe_chop",
327
- "axe_hit_object"
328
- ];
329
- var footstepSoundId = (surface, gait) => `footstep_${surface}_${gait}`;
330
- var FOOTSTEP_SOUND_IDS = SURFACE_IDS.flatMap((surface) => GAIT_IDS.map((gait) => footstepSoundId(surface, gait)));
331
- var LAND_SOUND_IDS = SURFACE_IDS.flatMap((surface) => LANDING_IDS.map((landing) => `land_${surface}_${landing}`));
332
- var BODY_FOLEY_IDS = [...FOOTSTEP_SOUND_IDS, ...LAND_SOUND_IDS, ...BODY_SOUND_IDS];
333
- var WORKER_KIND_ID = {
334
- GROUND_TILES: "destruction.ground-tiles",
335
- CROWD_PHYSICS: "crowd.physics",
336
- PIECE_BOXES: "destruction.piece-boxes",
337
- STATIC_COLLIDERS: "destruction.static-colliders",
338
- SHAPES_GENERATE: "shapes.generate",
339
- WORLD_REGION: "world.region",
340
- VEHICLE_HULL_PLAN: "vehicles.hull-plan"
341
- };
342
- var WORKER_KIND_DEFAULTS = {
343
- [WORKER_KIND_ID.GROUND_TILES]: { lane: "sim", priority: 300, latencyFrames: 2, late: "sync" },
344
- [WORKER_KIND_ID.CROWD_PHYSICS]: { lane: "sim", priority: 250, latencyFrames: 1, late: "sync" },
345
- [WORKER_KIND_ID.PIECE_BOXES]: { lane: "sim", priority: 200, latencyFrames: 2, late: "sync" },
346
- [WORKER_KIND_ID.STATIC_COLLIDERS]: { lane: "build", priority: 150, late: "sync" },
347
- [WORKER_KIND_ID.SHAPES_GENERATE]: { lane: "build", priority: 100, late: "sync" },
348
- [WORKER_KIND_ID.WORLD_REGION]: { lane: "background", priority: 10, latencyFrames: 10, late: "drop" },
349
- [WORKER_KIND_ID.VEHICLE_HULL_PLAN]: { lane: "build", priority: 120, late: "keep-waiting" }
350
- };
270
+
271
+ // ../game-interactables/src/math.ts
272
+ var DEFAULT_AXIS = [0, 1, 0];
273
+ function poseOf(motion, t) {
274
+ const tt = Math.max(0, Math.min(1, t));
275
+ const axis = motion.axis ?? DEFAULT_AXIS;
276
+ const pose = { position: [0, 0, 0], rotation: { axis: [axis[0], axis[1], axis[2]], angle: 0 }, scale: [1, 1, 1] };
277
+ switch (motion.kind) {
278
+ case "hinge":
279
+ case "rocker":
280
+ case "knob":
281
+ pose.rotation.angle = (motion.angle ?? Math.PI / 2) * tt;
282
+ break;
283
+ case "slide": {
284
+ const d = (motion.distance ?? 0.4) * tt;
285
+ pose.position = [axis[0] * d, axis[1] * d, axis[2] * d];
286
+ break;
287
+ }
288
+ case "scale": {
289
+ const k = 1 + ((motion.scale ?? 0.2) - 1) * tt;
290
+ pose.scale = [axis[0] !== 0 ? k : 1, axis[1] !== 0 ? k : 1, axis[2] !== 0 ? k : 1];
291
+ break;
292
+ }
293
+ }
294
+ return pose;
295
+ }
296
+
297
+ // ../game-interactables/src/cast-with-member.ts
298
+ var COLLAR_REACH = 0.03;
299
+ var END_GAP = 5e-3;
300
+ function centredOn(member, other) {
301
+ for (const k of [0, 2]) {
302
+ if (other[k] < member[k] - COLLAR_REACH || other[k + 3] > member[k + 3] + COLLAR_REACH) return false;
303
+ if (Math.abs((other[k] + other[k + 3]) / 2 - (member[k] + member[k + 3]) / 2) > COLLAR_REACH) return false;
304
+ }
305
+ return true;
306
+ }
307
+ function wrapsMember(member, collar) {
308
+ const overlap = Math.min(collar[4], member[4]) - Math.max(collar[1], member[1]);
309
+ return overlap >= (collar[4] - collar[1]) / 2 && centredOn(member, collar);
310
+ }
311
+ function endsMember(member, end) {
312
+ const under = Math.abs(end[4] - member[1]) <= END_GAP;
313
+ const over = Math.abs(end[1] - member[4]) <= END_GAP;
314
+ return (under || over) && end[4] - end[1] <= member[4] - member[1] && centredOn(member, end);
315
+ }
316
+ function castWithMember(member, other) {
317
+ return wrapsMember(member, other) || endsMember(member, other);
318
+ }
351
319
 
352
320
  // ../game-items/dist/index.js
353
321
  var DEFAULT_RULES = {
@@ -1656,6 +1624,111 @@ var GameInteractablesHousehold = (() => {
1656
1624
  }
1657
1625
  ]
1658
1626
  },
1627
+ {
1628
+ id: "rinse_dish",
1629
+ body: "two_hands",
1630
+ duration: 3,
1631
+ note: "the scrubbed dish brought under the running tap and turned so the water runs over one face and then the other, the foam and the rest of the dirt going with it, and back; played again while foam is left; the rinsing keys reach under the tap (aimHandUse)",
1632
+ keys: [
1633
+ {
1634
+ t: 0,
1635
+ position: [
1636
+ 0.22,
1637
+ -0.2,
1638
+ -0.4
1639
+ ],
1640
+ rotation: [
1641
+ 0,
1642
+ 0,
1643
+ 0
1644
+ ]
1645
+ },
1646
+ {
1647
+ t: 0.4,
1648
+ position: [
1649
+ 0,
1650
+ -0.55,
1651
+ -0.43
1652
+ ],
1653
+ rotation: [
1654
+ -0.5,
1655
+ 0,
1656
+ 0
1657
+ ],
1658
+ reach: true
1659
+ },
1660
+ {
1661
+ t: 0.95,
1662
+ position: [
1663
+ 0.02,
1664
+ -0.55,
1665
+ -0.43
1666
+ ],
1667
+ rotation: [
1668
+ -0.9,
1669
+ 0,
1670
+ 0.25
1671
+ ],
1672
+ reach: true
1673
+ },
1674
+ {
1675
+ t: 1.5,
1676
+ position: [
1677
+ -0.02,
1678
+ -0.55,
1679
+ -0.43
1680
+ ],
1681
+ rotation: [
1682
+ -0.2,
1683
+ 0,
1684
+ -0.25
1685
+ ],
1686
+ reach: true,
1687
+ action: "rinse"
1688
+ },
1689
+ {
1690
+ t: 2.05,
1691
+ position: [
1692
+ 0.02,
1693
+ -0.55,
1694
+ -0.43
1695
+ ],
1696
+ rotation: [
1697
+ -0.9,
1698
+ 0,
1699
+ 0.25
1700
+ ],
1701
+ reach: true
1702
+ },
1703
+ {
1704
+ t: 2.6,
1705
+ position: [
1706
+ 0,
1707
+ -0.55,
1708
+ -0.43
1709
+ ],
1710
+ rotation: [
1711
+ -0.5,
1712
+ 0,
1713
+ 0
1714
+ ],
1715
+ reach: true
1716
+ },
1717
+ {
1718
+ t: 3,
1719
+ position: [
1720
+ 0.22,
1721
+ -0.2,
1722
+ -0.4
1723
+ ],
1724
+ rotation: [
1725
+ 0,
1726
+ 0,
1727
+ 0
1728
+ ]
1729
+ }
1730
+ ]
1731
+ },
1659
1732
  {
1660
1733
  id: "fill_cup",
1661
1734
  body: "hand",
@@ -3291,6 +3364,26 @@ var GameInteractablesHousehold = (() => {
3291
3364
  "brake_fluid"
3292
3365
  ]
3293
3366
  },
3367
+ {
3368
+ id: "detergent",
3369
+ color: 15916378,
3370
+ opacity: 0.6,
3371
+ stainColor: 14077068,
3372
+ viscosity: 400,
3373
+ density: 1030,
3374
+ dryTime: 1800,
3375
+ gloss: 0.95,
3376
+ leavesMark: true,
3377
+ drink: {
3378
+ thirst: 0,
3379
+ effects: [
3380
+ "poison"
3381
+ ]
3382
+ },
3383
+ tags: [
3384
+ "soap"
3385
+ ]
3386
+ },
3294
3387
  {
3295
3388
  id: "shampoo",
3296
3389
  color: 6069216,
@@ -3312,6 +3405,65 @@ var GameInteractablesHousehold = (() => {
3312
3405
  "sticky"
3313
3406
  ]
3314
3407
  },
3408
+ {
3409
+ id: "fabric_softener",
3410
+ color: 9225452,
3411
+ opacity: 0.8,
3412
+ stainColor: 11061470,
3413
+ viscosity: 80,
3414
+ density: 1e3,
3415
+ dryTime: 1800,
3416
+ gloss: 0.8,
3417
+ leavesMark: true,
3418
+ drink: {
3419
+ thirst: 0,
3420
+ effects: [
3421
+ "poison"
3422
+ ]
3423
+ },
3424
+ tags: [
3425
+ "soap"
3426
+ ]
3427
+ },
3428
+ {
3429
+ id: "disinfectant",
3430
+ color: 14205040,
3431
+ opacity: 0.6,
3432
+ stainColor: 13154442,
3433
+ viscosity: 1.5,
3434
+ density: 1e3,
3435
+ dryTime: 600,
3436
+ gloss: 0.85,
3437
+ leavesMark: true,
3438
+ drink: {
3439
+ thirst: 0,
3440
+ effects: [
3441
+ "poison"
3442
+ ]
3443
+ },
3444
+ tags: [
3445
+ "corrosive"
3446
+ ]
3447
+ },
3448
+ {
3449
+ id: "yogurt",
3450
+ color: 15986404,
3451
+ opacity: 1,
3452
+ stainColor: 15130576,
3453
+ viscosity: 1500,
3454
+ density: 1040,
3455
+ dryTime: 7200,
3456
+ gloss: 0.5,
3457
+ leavesMark: true,
3458
+ drink: {
3459
+ thirst: 10,
3460
+ effects: []
3461
+ },
3462
+ tags: [
3463
+ "food",
3464
+ "sticky"
3465
+ ]
3466
+ },
3315
3467
  {
3316
3468
  id: "toothpaste",
3317
3469
  color: 16054008,
@@ -14170,8 +14322,13 @@ var GameInteractablesHousehold = (() => {
14170
14322
  shelfLife: 28,
14171
14323
  estimated: [
14172
14324
  "nutrition",
14173
- "shelfLife"
14174
- ]
14325
+ "shelfLife",
14326
+ "fluid"
14327
+ ],
14328
+ fluid: {
14329
+ liquid: "yogurt",
14330
+ liters: 0.17
14331
+ }
14175
14332
  },
14176
14333
  {
14177
14334
  id: "apple",
@@ -14512,8 +14669,13 @@ var GameInteractablesHousehold = (() => {
14512
14669
  }
14513
14670
  ],
14514
14671
  estimated: [
14672
+ "fluid",
14515
14673
  "parts"
14516
- ]
14674
+ ],
14675
+ fluid: {
14676
+ liquid: "shampoo",
14677
+ liters: 0.3
14678
+ }
14517
14679
  },
14518
14680
  {
14519
14681
  id: "toothpaste",
@@ -14690,8 +14852,13 @@ var GameInteractablesHousehold = (() => {
14690
14852
  ],
14691
14853
  estimated: [
14692
14854
  "parts",
14855
+ "fluid",
14693
14856
  "consumable"
14694
14857
  ],
14858
+ fluid: {
14859
+ liquid: "detergent",
14860
+ liters: 0.45
14861
+ },
14695
14862
  consumable: {
14696
14863
  form: "liquid",
14697
14864
  unit: "ml",
@@ -14726,8 +14893,13 @@ var GameInteractablesHousehold = (() => {
14726
14893
  }
14727
14894
  ],
14728
14895
  estimated: [
14729
- "parts"
14730
- ]
14896
+ "parts",
14897
+ "fluid"
14898
+ ],
14899
+ fluid: {
14900
+ liquid: "bleach",
14901
+ liters: 1
14902
+ }
14731
14903
  },
14732
14904
  {
14733
14905
  id: "sponge",
@@ -15330,7 +15502,14 @@ var GameInteractablesHousehold = (() => {
15330
15502
  stack: 1,
15331
15503
  shape: "can",
15332
15504
  color: 15261904,
15333
- rarity: "common"
15505
+ rarity: "common",
15506
+ estimated: [
15507
+ "fluid"
15508
+ ],
15509
+ fluid: {
15510
+ liquid: "paint",
15511
+ liters: 3.6
15512
+ }
15334
15513
  },
15335
15514
  {
15336
15515
  id: "ice_pack",
@@ -15690,8 +15869,13 @@ var GameInteractablesHousehold = (() => {
15690
15869
  }
15691
15870
  ],
15692
15871
  estimated: [
15693
- "parts"
15694
- ]
15872
+ "parts",
15873
+ "fluid"
15874
+ ],
15875
+ fluid: {
15876
+ liquid: "disinfectant",
15877
+ liters: 0.5
15878
+ }
15695
15879
  },
15696
15880
  {
15697
15881
  id: "seasoning",
@@ -15911,8 +16095,12 @@ var GameInteractablesHousehold = (() => {
15911
16095
  }
15912
16096
  ],
15913
16097
  estimated: [
15914
- "parts"
15915
- ]
16098
+ "parts",
16099
+ "powder"
16100
+ ],
16101
+ powder: {
16102
+ color: 15659508
16103
+ }
15916
16104
  },
15917
16105
  {
15918
16106
  id: "broom",
@@ -16024,8 +16212,13 @@ var GameInteractablesHousehold = (() => {
16024
16212
  }
16025
16213
  ],
16026
16214
  estimated: [
16027
- "parts"
16028
- ]
16215
+ "parts",
16216
+ "fluid"
16217
+ ],
16218
+ fluid: {
16219
+ liquid: "fabric_softener",
16220
+ liters: 2
16221
+ }
16029
16222
  },
16030
16223
  {
16031
16224
  id: "clothespins",
@@ -16452,9 +16645,8 @@ var GameInteractablesHousehold = (() => {
16452
16645
  shed: false
16453
16646
  },
16454
16647
  use: {
16455
- clip: "open_can_eat",
16648
+ clip: "eat_food",
16456
16649
  sounds: [
16457
- "can_open",
16458
16650
  "chew"
16459
16651
  ]
16460
16652
  },
@@ -16622,9 +16814,8 @@ var GameInteractablesHousehold = (() => {
16622
16814
  shed: false
16623
16815
  },
16624
16816
  use: {
16625
- clip: "open_can_drink",
16817
+ clip: "drink",
16626
16818
  sounds: [
16627
- "can_open",
16628
16819
  "gulp"
16629
16820
  ]
16630
16821
  },
@@ -22398,7 +22589,7 @@ var GameInteractablesHousehold = (() => {
22398
22589
  return m(16) << 16 | m(8) << 8 | m(0);
22399
22590
  }
22400
22591
  var round3 = (n) => Math.round(n * 1e3) / 1e3;
22401
- function rotateAxis(p, o, axis, ang) {
22592
+ function rotateAxis2(p, o, axis, ang) {
22402
22593
  const l = Math.hypot(axis[0], axis[1], axis[2]) || 1;
22403
22594
  const k = [axis[0] / l, axis[1] / l, axis[2] / l];
22404
22595
  const v = [p[0] - o[0], p[1] - o[1], p[2] - o[2]];
@@ -22462,7 +22653,7 @@ var GameInteractablesHousehold = (() => {
22462
22653
  const dot = (p[0] - pivot[0]) * k[0] + (p[1] - pivot[1]) * k[1] + (p[2] - pivot[2]) * k[2];
22463
22654
  return [p[0] + k[0] * dot * s, p[1] + k[1] * dot * s, p[2] + k[2] * dot * s];
22464
22655
  }
22465
- return rotateAxis(p, pivot, axis, (m.angle ?? 0) * t);
22656
+ return rotateAxis2(p, pivot, axis, (m.angle ?? 0) * t);
22466
22657
  }
22467
22658
  function sweepOf(points, pivot, m, margin = 0.01) {
22468
22659
  let x0 = Infinity;
@@ -25354,7 +25545,8 @@ var GameInteractablesHousehold = (() => {
25354
25545
  label: "use.wash_dishes",
25355
25546
  needs: [...DISH_NEEDS],
25356
25547
  dose: { need: 0 },
25357
- dishes: { ids: [...DISHES], basin: basin.id, rack }
25548
+ dishes: { ids: [...DISHES], basin: basin.id, rack },
25549
+ rinse: { clip: "rinse_dish", seconds: scrubSecondsOf("rinse_dish") }
25358
25550
  });
25359
25551
  }
25360
25552
  function tap2(c, x, y, z, id, partId, basin) {
@@ -28151,6 +28343,688 @@ var GameInteractablesHousehold = (() => {
28151
28343
  };
28152
28344
  return { api, primitives, parts: parts2 };
28153
28345
  }
28346
+
28347
+ // src/assembly/geometry.ts
28348
+ var round = (value, digits = 4) => Math.round(value * 10 ** digits) / 10 ** digits;
28349
+ var sanitize = (id) => String(id).trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
28350
+ var rotateX = (v, angle) => [v[0], v[1] * Math.cos(angle) - v[2] * Math.sin(angle), v[1] * Math.sin(angle) + v[2] * Math.cos(angle)];
28351
+ var rotateY = (v, angle) => [v[0] * Math.cos(angle) + v[2] * Math.sin(angle), v[1], -v[0] * Math.sin(angle) + v[2] * Math.cos(angle)];
28352
+ var rotateZ = (v, angle) => [v[0] * Math.cos(angle) - v[1] * Math.sin(angle), v[0] * Math.sin(angle) + v[1] * Math.cos(angle), v[2]];
28353
+ function aabbOfBox(center, size, turn = {}) {
28354
+ const { ry = 0, rx = 0, rz = 0 } = turn;
28355
+ const lo = [Infinity, Infinity, Infinity];
28356
+ const hi = [-Infinity, -Infinity, -Infinity];
28357
+ for (const sx of [-0.5, 0.5])
28358
+ for (const sy of [-0.5, 0.5])
28359
+ for (const sz of [-0.5, 0.5]) {
28360
+ let v = [sx * size[0], sy * size[1], sz * size[2]];
28361
+ if (rz) v = rotateZ(v, rz);
28362
+ if (rx) v = rotateX(v, rx);
28363
+ if (ry) v = rotateY(v, ry);
28364
+ for (let k = 0; k < 3; k++) {
28365
+ lo[k] = Math.min(lo[k], center[k] + v[k]);
28366
+ hi[k] = Math.max(hi[k], center[k] + v[k]);
28367
+ }
28368
+ }
28369
+ return [...lo, ...hi];
28370
+ }
28371
+ function latheShape(args) {
28372
+ const [, material, x, y, z, points] = args;
28373
+ const radius = Math.max(...points.map((q) => q[0]));
28374
+ const heights = points.map((q) => q[1]);
28375
+ const lo = Math.min(...heights);
28376
+ const hi = Math.max(...heights);
28377
+ let moment = 0;
28378
+ for (let i = 0; i < points.length; i++) {
28379
+ const [r0, y0] = points[i];
28380
+ const [r1, y1] = points[(i + 1) % points.length];
28381
+ moment += (r0 * y1 - r1 * y0) * (r0 + r1) / 6;
28382
+ }
28383
+ return { key: material, aabb: [x - radius, y + lo, z - radius, x + radius, y + hi, z + radius], vol: Math.max(1e-6, 2 * Math.PI * Math.abs(moment)) };
28384
+ }
28385
+ function describePrimitive(fn, args) {
28386
+ if (fn === "box") {
28387
+ const [, material, x2, y2, z2, w2, h2, d, , ry2 = 0, rx = 0, rz = 0] = args;
28388
+ return { key: material, aabb: aabbOfBox([x2, y2 + h2 / 2, z2], [w2, h2, d], { ry: ry2, rx, rz }), vol: w2 * h2 * d };
28389
+ }
28390
+ if (fn === "cylinder") {
28391
+ const [, material, x2, y2, z2, r, h2, , rx = 0, rz = 0, shape] = args;
28392
+ const tilted = rx || rz;
28393
+ const share = shape === "cone" ? 1 / 3 : shape === "sphere" ? 2 / 3 : 1;
28394
+ return { key: material, aabb: aabbOfBox([x2, tilted ? y2 : y2 + h2 / 2, z2], [2 * r, h2, 2 * r], { rx, rz }), vol: Math.PI * r * r * h2 * share };
28395
+ }
28396
+ if (fn === "plane") {
28397
+ const [, material, x2, y2, z2, w2, h2, , ry2 = 0, rx = 0, rz = 0] = args;
28398
+ return { key: material, aabb: aabbOfBox([x2, y2, z2], [w2, h2, 0.012], { ry: ry2, rx, rz }), vol: w2 * h2 * 0.012 };
28399
+ }
28400
+ if (fn === "lathe") return latheShape(args);
28401
+ const [, x, y, z, w, h, , ry = 0] = args;
28402
+ return { key: "plant", aabb: aabbOfBox([x, y + h / 2, z], [w, h, w * 0.2], { ry }), vol: w * h * w * 0.1 };
28403
+ }
28404
+ var unionBox = (a, b) => [Math.min(a[0], b[0]), Math.min(a[1], b[1]), Math.min(a[2], b[2]), Math.max(a[3], b[3]), Math.max(a[4], b[4]), Math.max(a[5], b[5])];
28405
+ var thinnestOf = (b) => Math.min(b[3] - b[0], b[4] - b[1], b[5] - b[2]);
28406
+ var boxVolume = (b) => Math.max(1e-9, (b[3] - b[0]) * (b[4] - b[1]) * (b[5] - b[2]));
28407
+ var centre = (b) => [(b[0] + b[3]) / 2, (b[1] + b[4]) / 2, (b[2] + b[5]) / 2];
28408
+ function coverOf(skin, under) {
28409
+ const sizes = [skin[3] - skin[0], skin[4] - skin[1], skin[5] - skin[2]];
28410
+ const thin = sizes.indexOf(Math.min(...sizes));
28411
+ let share = 1;
28412
+ for (let k = 0; k < 3; k++) {
28413
+ if (k === thin) continue;
28414
+ const overlap = Math.max(0, Math.min(skin[k + 3], under[k + 3]) - Math.max(skin[k], under[k]));
28415
+ share *= overlap / Math.max(sizes[k], 1e-9);
28416
+ }
28417
+ return share;
28418
+ }
28419
+ function boxGap(a, b) {
28420
+ const dx = Math.max(0, a[0] - b[3], b[0] - a[3]);
28421
+ const dy = Math.max(0, a[1] - b[4], b[1] - a[4]);
28422
+ const dz = Math.max(0, a[2] - b[5], b[2] - a[5]);
28423
+ return Math.hypot(dx, dy, dz);
28424
+ }
28425
+ var SOLID_MIN = 2e-3;
28426
+ function solidsOf(prims, box) {
28427
+ if (prims.length < 2) return void 0;
28428
+ const c = centre(box);
28429
+ return prims.map((p) => {
28430
+ const at = centre(p.aabb);
28431
+ return {
28432
+ center: [round(at[0] - c[0]), round(at[1] - c[1]), round(at[2] - c[2])],
28433
+ size: [0, 1, 2].map((k) => round(Math.max(SOLID_MIN, p.aabb[k + 3] - p.aabb[k])))
28434
+ };
28435
+ });
28436
+ }
28437
+ function primitiveBoxInObject(mover, prim) {
28438
+ let box;
28439
+ for (const sx of [prim.aabb[0], prim.aabb[3]])
28440
+ for (const sy of [prim.aabb[1], prim.aabb[4]])
28441
+ for (const sz of [prim.aabb[2], prim.aabb[5]]) {
28442
+ const v = mover.ry ? rotateY([sx, sy, sz], mover.ry) : [sx, sy, sz];
28443
+ const w = [v[0] + mover.pivot[0], v[1] + mover.pivot[1], v[2] + mover.pivot[2]];
28444
+ box = box ? unionBox(box, [...w, ...w]) : [...w, ...w];
28445
+ }
28446
+ return box;
28447
+ }
28448
+ function moverBox(mover) {
28449
+ let box;
28450
+ for (const p of mover.prims) {
28451
+ const b = primitiveBoxInObject(mover, p);
28452
+ box = box ? unionBox(box, b) : b;
28453
+ }
28454
+ return box;
28455
+ }
28456
+
28457
+ // src/assembly/animations.ts
28458
+ var SOUND = { door: "door", drawer: "drawer", lid: "lid", flap: "flap", knob: "knob", button: "click", rocker: "click", breaker: "click" };
28459
+ var OWN_CLIPS_MAX = 8;
28460
+ function quaternionOf(motion) {
28461
+ const pose = poseOf(motion, 1);
28462
+ const [x, y, z] = pose.rotation.axis;
28463
+ const length = Math.hypot(x, y, z) || 1;
28464
+ const s = Math.sin(pose.rotation.angle / 2);
28465
+ return { position: [...pose.position], quaternion: [x / length * s, y / length * s, z / length * s, Math.cos(pose.rotation.angle / 2)] };
28466
+ }
28467
+ function eulerOf([x, y, z, w]) {
28468
+ const m13 = 2 * (x * z + w * y);
28469
+ const ey = Math.asin(Math.max(-1, Math.min(1, m13)));
28470
+ const ex = Math.abs(m13) < 0.9999999 ? Math.atan2(-2 * (y * z - w * x), 1 - 2 * (x * x + y * y)) : Math.atan2(2 * (y * z + w * x), 1 - 2 * (x * x + z * z));
28471
+ const ez = Math.abs(m13) < 0.9999999 ? Math.atan2(-2 * (x * y - w * z), 1 - 2 * (y * y + z * z)) : 0;
28472
+ return [round(ex), round(ey), round(ez)];
28473
+ }
28474
+ function partMotionPose(motion, ry) {
28475
+ const { position: p, quaternion } = quaternionOf(motion);
28476
+ const [x, y, z, w] = quaternion;
28477
+ const px = p[0] * Math.cos(ry) + p[2] * Math.sin(ry);
28478
+ const pz = -p[0] * Math.sin(ry) + p[2] * Math.cos(ry);
28479
+ const position = [round(px), round(p[1]), round(pz)];
28480
+ const along = [x, y, z].map((c) => Math.abs(c) > 1e-9);
28481
+ if (along.filter(Boolean).length <= 1) {
28482
+ const turn = [x, y, z].map((c) => Math.abs(c) > 1e-9 ? 2 * Math.atan2(c, w) : 0);
28483
+ return { position, rotation: [round(turn[0]), round(turn[1]), round(turn[2])] };
28484
+ }
28485
+ return { position, rotation: eulerOf(quaternion) };
28486
+ }
28487
+ function staged(list) {
28488
+ const bySource = new Map(list.map((p) => [p.source, p]));
28489
+ const start = (p) => {
28490
+ const before = p.requires ? bySource.get(p.requires) : void 0;
28491
+ return before ? start(before) + 0.5 : 0;
28492
+ };
28493
+ return list.map((p) => ({ ...p, start: start(p), end: start(p) + p.seconds }));
28494
+ }
28495
+ function clipOf({ id, list, closing, sound }) {
28496
+ const parts2 = staged(list);
28497
+ const duration = Math.max(...parts2.map((p) => p.end));
28498
+ const times = [.../* @__PURE__ */ new Set([0, duration, ...parts2.flatMap((p) => [p.start, p.end])])].sort((a, b) => a - b);
28499
+ const keys = times.map((t) => ({
28500
+ t: round(t, 3),
28501
+ parts: Object.fromEntries(
28502
+ parts2.map((p) => {
28503
+ const share = Math.max(0, Math.min(1, (t - p.start) / (p.end - p.start)));
28504
+ const f = closing ? 1 - share : share;
28505
+ return [p.id, { position: p.pose.position.map((v) => round(v * f)), rotation: p.pose.rotation.map((v) => round(v * f)) }];
28506
+ })
28507
+ )
28508
+ }));
28509
+ return { id, duration: round(duration, 3), keys, events: [{ t: 0, type: "sound", data: { key: `${sound}_${closing ? "close" : "open"}` } }] };
28510
+ }
28511
+ function buildAnimations({ spec, ids, present }) {
28512
+ const movers = (spec.parts ?? []).filter((p) => p.motion.kind !== "scale" && present.has(p.id));
28513
+ if (movers.length === 0) return [];
28514
+ const info = movers.map((p) => {
28515
+ const kind = p.motion.kind;
28516
+ const on = kind === "knob" || kind === "rocker";
28517
+ const piece2 = p.destruction?.piece ?? (kind === "slide" ? "drawer" : "door");
28518
+ return {
28519
+ source: p.id,
28520
+ id: ids.get(p.id) ?? p.id,
28521
+ on,
28522
+ pose: partMotionPose(p.motion, p.ry ?? 0),
28523
+ seconds: on ? 0.4 : kind === "slide" ? 0.8 : 1.1,
28524
+ sound: SOUND[piece2] ?? "door",
28525
+ requires: p.requires
28526
+ };
28527
+ });
28528
+ const clips = [];
28529
+ const doors = info.filter((p) => !p.on);
28530
+ const knobs = info.filter((p) => p.on);
28531
+ if (doors.length) clips.push(clipOf({ id: "open_all", list: doors, closing: false, sound: "door" }), clipOf({ id: "close_all", list: doors, closing: true, sound: "door" }));
28532
+ if (knobs.length) clips.push(clipOf({ id: "on_all", list: knobs, closing: false, sound: "switch" }), clipOf({ id: "off_all", list: knobs, closing: true, sound: "switch" }));
28533
+ if (info.length > OWN_CLIPS_MAX) return clips;
28534
+ for (const p of info) {
28535
+ clips.push(
28536
+ clipOf({ id: `${p.on ? "on" : "open"}_${p.id}`, list: [p], closing: false, sound: p.sound }),
28537
+ clipOf({ id: `${p.on ? "off" : "close"}_${p.id}`, list: [p], closing: true, sound: p.sound })
28538
+ );
28539
+ }
28540
+ return clips;
28541
+ }
28542
+
28543
+ // src/assembly/cluster.ts
28544
+ var MAX_PIECES = {
28545
+ service_entrance: 32,
28546
+ service_mast: 24,
28547
+ bbq: 30,
28548
+ clothesline: 24,
28549
+ dog_house: 24,
28550
+ gas_bottle: 6,
28551
+ microwave: 10,
28552
+ washing_machine: 12,
28553
+ tv: 8,
28554
+ fridge_compact: 12,
28555
+ utility_sink: 12,
28556
+ wall_socket: 3,
28557
+ wall_switch: 3
28558
+ };
28559
+ var DEFAULT_MAX_PIECES = 18;
28560
+ var STRETCH_DIAMETERS = 2.5;
28561
+ var SKIN_MAX = 4e-3;
28562
+ var SKIN_GAP = 1e-3;
28563
+ var SKIN_COVER = 0.9;
28564
+ var SPECK = 0.02;
28565
+ function layInStretches(statics) {
28566
+ let member = 0;
28567
+ for (let i = statics.length - 1; i >= 0; i--) {
28568
+ const prim = statics[i];
28569
+ if (prim.fn !== "cylinder") continue;
28570
+ const [, , , y, , r, h, , rx = 0, rz = 0, shape] = prim.args;
28571
+ if (rx || rz || shape !== void 0 && shape !== "cyl" && shape !== "cyl6" || h < 2 * STRETCH_DIAMETERS * 2 * r) continue;
28572
+ const count = Math.floor(h / (STRETCH_DIAMETERS * 2 * r));
28573
+ const id = member++;
28574
+ const stretches = Array.from({ length: count }, (_, k) => {
28575
+ const args = prim.args.slice();
28576
+ args[3] = y + h * k / count;
28577
+ args[6] = h / count;
28578
+ return { fn: prim.fn, args, member: id, ...describePrimitive(prim.fn, args) };
28579
+ });
28580
+ statics.splice(i, 1, ...stretches);
28581
+ }
28582
+ }
28583
+ var glassy = (p) => p.keys.has("glass") || p.keys.has("emissive");
28584
+ var sizeOf = (p) => Math.max(p.box[3] - p.box[0], p.box[4] - p.box[1], p.box[5] - p.box[2]);
28585
+ function merge(into, from) {
28586
+ into.indices.push(...from.indices);
28587
+ into.box = unionBox(into.box, from.box);
28588
+ into.vol += from.vol;
28589
+ for (const k of from.keys) into.keys.add(k);
28590
+ for (const [k, v] of Object.entries(from.area)) into.area[k] = (into.area[k] ?? 0) + v;
28591
+ }
28592
+ function hostOf(pieces, small) {
28593
+ let best;
28594
+ let bestScore = Infinity;
28595
+ for (const q of pieces) {
28596
+ if (q === small || glassy(q) !== glassy(small)) continue;
28597
+ const score = boxGap(small.box, q.box) * 1e3 - Math.log(boxVolume(q.box));
28598
+ if (score < bestScore) {
28599
+ bestScore = score;
28600
+ best = q;
28601
+ }
28602
+ }
28603
+ return best;
28604
+ }
28605
+ function clusterStatics({ type, statics, castWith }) {
28606
+ const max = MAX_PIECES[type] ?? DEFAULT_MAX_PIECES;
28607
+ let pieces = statics.map((p, i) => ({ indices: [i], box: p.aabb.slice(), vol: p.vol, keys: /* @__PURE__ */ new Set([p.key]), area: { [p.key]: p.vol } }));
28608
+ const join = (host, piece2) => {
28609
+ merge(host, piece2);
28610
+ pieces = pieces.filter((q) => q !== piece2);
28611
+ };
28612
+ const absorb = (small) => {
28613
+ const host = hostOf(pieces, small);
28614
+ if (!host) return false;
28615
+ join(host, small);
28616
+ return true;
28617
+ };
28618
+ for (const p of pieces.slice()) {
28619
+ if (glassy(p) || pieces.length < 2) continue;
28620
+ const thin = thinnestOf(p.box);
28621
+ if (thin > SKIN_MAX) continue;
28622
+ const host = pieces.find((q) => q !== p && !glassy(q) && thinnestOf(q.box) > thin && boxGap(p.box, q.box) <= SKIN_GAP && coverOf(p.box, q.box) >= SKIN_COVER);
28623
+ if (host) join(host, p);
28624
+ }
28625
+ for (const p of pieces.slice()) {
28626
+ if (p.indices.length !== 1 || statics[p.indices[0]].member !== void 0) continue;
28627
+ const host = pieces.find((q) => q !== p && q.indices.some((i) => statics[i].member !== void 0) && castWith?.(q.box, p.box));
28628
+ if (host) join(host, p);
28629
+ }
28630
+ for (const p of pieces.slice()) if (sizeOf(p) < SPECK && pieces.length > 1 && !glassy(p)) absorb(p);
28631
+ while (pieces.length > max) {
28632
+ const candidates = pieces.filter((p) => !glassy(p) || pieces.filter(glassy).length > 3);
28633
+ const small = (candidates.length ? candidates : pieces).reduce((m, p) => boxVolume(p.box) < boxVolume(m.box) ? p : m);
28634
+ if (!absorb(small)) break;
28635
+ }
28636
+ return pieces.sort((a, b) => boxVolume(b.box) - boxVolume(a.box));
28637
+ }
28638
+
28639
+ // src/assembly/draw-recorder.ts
28640
+ var KINDS2 = ["box", "cylinder", "plane", "leaf", "lathe"];
28641
+ var NOOP_API = { part: (_id, _pivot, _ry, draw) => draw(), box() {
28642
+ }, cylinder() {
28643
+ }, plane() {
28644
+ }, leaf() {
28645
+ }, light() {
28646
+ }, lathe() {
28647
+ } };
28648
+ var callOf = (api, kind) => api[kind];
28649
+ function createDrawRecorder(inner) {
28650
+ const statics = [];
28651
+ const movers = /* @__PURE__ */ new Map();
28652
+ const stack = [];
28653
+ const api = {
28654
+ light: (...args) => inner.light?.(...args),
28655
+ part(id, pivot, ry, draw) {
28656
+ stack.push(id);
28657
+ movers.set(id, { id, pivot: [...pivot], ry: ry || 0, prims: [] });
28658
+ inner.part(id, pivot, ry, draw);
28659
+ stack.pop();
28660
+ }
28661
+ };
28662
+ for (const fn of KINDS2) {
28663
+ ;
28664
+ api[fn] = (...args) => {
28665
+ const prim = { fn, args, ...describePrimitive(fn, args) };
28666
+ const open = stack[stack.length - 1];
28667
+ if (open === void 0) {
28668
+ statics.push(prim);
28669
+ return;
28670
+ }
28671
+ movers.get(open)?.prims.push(prim);
28672
+ callOf(inner, fn)(...args);
28673
+ };
28674
+ }
28675
+ const flush = (pieces, laid2 = statics) => {
28676
+ for (const piece2 of pieces) {
28677
+ inner.part(piece2.id, [0, 0, 0], 0, () => {
28678
+ for (const i of piece2.indices) callOf(inner, laid2[i].fn)(...laid2[i].args);
28679
+ });
28680
+ }
28681
+ };
28682
+ return { api, statics, movers, flush };
28683
+ }
28684
+
28685
+ // src/assembly/fluid.ts
28686
+ var BOWL_FILL_MAX = 0.7;
28687
+ var WATER_TEMPERATURE = 18;
28688
+ var FLUIDS = {
28689
+ sink_kitchen: { liters: 4, capacity: 14, size: [0.5, 0.16, 0.36], opening: 0.2 },
28690
+ sink_bathroom: { liters: 2, capacity: 6, size: [0.34, 0.12, 0.28], opening: 0.15 },
28691
+ utility_sink: { liters: 8, capacity: 28, size: [0.5, 0.25, 0.4], opening: 0.22 },
28692
+ toilet: { liters: 3, capacity: 6, size: [0.3, 0.18, 0.3], opening: 0.14 }
28693
+ };
28694
+ function fluidOf({ type, basin, parts: parts2, basinPiece }) {
28695
+ const fixture = FLUIDS[type];
28696
+ if (!fixture) return void 0;
28697
+ if (basin) return bowlFluid(fixture, basin, parts2);
28698
+ const part = parts2.find((p) => p.id === basinPiece);
28699
+ if (!part) return void 0;
28700
+ const top = part.position[1] + part.shape.size[1] / 2;
28701
+ return {
28702
+ container: { capacity: fixture.capacity, liquid: "water", liters: fixture.liters, temperature: WATER_TEMPERATURE, shape: { kind: "box", size: [...fixture.size] }, opening: fixture.opening },
28703
+ part: part.id,
28704
+ uses: ["pour"],
28705
+ offset: [part.position[0], round(top - fixture.size[1] - 0.01), part.position[2]]
28706
+ };
28707
+ }
28708
+ var isInside = (offset, part) => [0, 1, 2].every((k) => Math.abs(offset[k] + (k === 1 ? 5e-3 : 0) - part.position[k]) <= part.shape.size[k] / 2 + 0.01);
28709
+ function bowlFluid(fixture, bowl, parts2) {
28710
+ const size = [0, 1, 2].map((k) => round(bowl.to[k] - bowl.from[k]));
28711
+ const offset = [round((bowl.from[0] + bowl.to[0]) / 2), round(bowl.from[1]), round((bowl.from[2] + bowl.to[2]) / 2)];
28712
+ const radius = round(Math.min(size[0], size[2]) / 2);
28713
+ const isRound = bowl.shape === "round";
28714
+ const capacity = round((isRound ? Math.PI * radius * radius * size[1] : size[0] * size[1] * size[2]) * 1e3, 2);
28715
+ const part = parts2.find((p) => isInside(offset, p)) ?? parts2[0];
28716
+ return {
28717
+ container: {
28718
+ capacity,
28719
+ liquid: "water",
28720
+ liters: Math.min(fixture.liters, round(capacity * BOWL_FILL_MAX, 2)),
28721
+ temperature: WATER_TEMPERATURE,
28722
+ shape: isRound ? { kind: "cylinder", radius, height: size[1] } : { kind: "box", size },
28723
+ opening: Math.min(fixture.opening, radius)
28724
+ },
28725
+ ...part ? { part: part.id } : {},
28726
+ uses: ["pour"],
28727
+ offset
28728
+ };
28729
+ }
28730
+
28731
+ // src/assembly/joints.ts
28732
+ var TOUCH = 0.01;
28733
+ var DEGREE_MAX = 5;
28734
+ var STRETCH_JOINT = { reinforced: "rebar", plain: "weld" };
28735
+ function createGroups(ids) {
28736
+ const parent = new Map(ids.map((id) => [id, id]));
28737
+ const find = (id) => {
28738
+ const up = parent.get(id) ?? id;
28739
+ if (up === id) return id;
28740
+ const root = find(up);
28741
+ parent.set(id, root);
28742
+ return root;
28743
+ };
28744
+ return { find, join: (a, b) => void parent.set(find(a), find(b)) };
28745
+ }
28746
+ function jointsOf({ spec, pieces, movers, statics }) {
28747
+ const body = spec.destruction ?? {};
28748
+ const cage = body.reinforcement;
28749
+ const bodyKind = body.joint ?? "screw";
28750
+ const memberOf = (piece2) => piece2.indices.map((i) => statics[i].member).find((member) => member !== void 0);
28751
+ const kindOf = (a, b) => {
28752
+ const member = memberOf(a);
28753
+ if (member !== void 0 && member === memberOf(b)) return cage ? STRETCH_JOINT.reinforced : STRETCH_JOINT.plain;
28754
+ if (a.material.includes("glass") || b.material.includes("glass")) return "clip";
28755
+ if (a.material === "foam" !== (b.material === "foam")) return "tie";
28756
+ return cage && (a.material !== body.material || b.material !== body.material) ? "bolt" : bodyKind;
28757
+ };
28758
+ const joints = [];
28759
+ const degree = /* @__PURE__ */ new Map();
28760
+ const groups = createGroups(pieces.map((p) => p.id));
28761
+ const edges = [];
28762
+ for (let i = 0; i < pieces.length; i++)
28763
+ for (let j = i + 1; j < pieces.length; j++) {
28764
+ const gap = boxGap(pieces[i].box, pieces[j].box);
28765
+ if (gap <= TOUCH) edges.push({ a: pieces[i], b: pieces[j], gap });
28766
+ }
28767
+ edges.sort((x, y) => x.gap - y.gap || Math.min(boxVolume(y.a.box), boxVolume(y.b.box)) - Math.min(boxVolume(x.a.box), boxVolume(x.b.box)));
28768
+ for (const e of edges) {
28769
+ if ((degree.get(e.a.id) ?? 0) >= DEGREE_MAX || (degree.get(e.b.id) ?? 0) >= DEGREE_MAX) continue;
28770
+ degree.set(e.a.id, (degree.get(e.a.id) ?? 0) + 1);
28771
+ degree.set(e.b.id, (degree.get(e.b.id) ?? 0) + 1);
28772
+ groups.join(e.a.id, e.b.id);
28773
+ joints.push({ a: e.a.id, b: e.b.id, kind: kindOf(e.a, e.b) });
28774
+ }
28775
+ joints.push(...bridgesOf(pieces, groups, kindOf));
28776
+ for (const m of movers) {
28777
+ const host = hostOf2(pieces, m);
28778
+ if (host) joints.push({ a: m.id, b: host.id, kind: m.tag.joint ?? "hinge" });
28779
+ }
28780
+ return joints;
28781
+ }
28782
+ function bridgesOf(pieces, groups, kindOf) {
28783
+ const bridges = [];
28784
+ while (new Set(pieces.map((p) => groups.find(p.id))).size > 1) {
28785
+ let best;
28786
+ for (const a of pieces)
28787
+ for (const b of pieces) {
28788
+ if (groups.find(a.id) === groups.find(b.id)) continue;
28789
+ const gap = boxGap(a.box, b.box);
28790
+ if (!best || gap < best.gap) best = { a, b, gap };
28791
+ }
28792
+ if (!best) break;
28793
+ groups.join(best.a.id, best.b.id);
28794
+ bridges.push({ a: best.a.id, b: best.b.id, kind: kindOf(best.a, best.b) });
28795
+ }
28796
+ return bridges;
28797
+ }
28798
+ function hostOf2(pieces, mover) {
28799
+ let best = pieces[0];
28800
+ let bestScore = Infinity;
28801
+ for (const h of pieces) {
28802
+ const score = boxGap(mover.box, h.box) * 1e3 - Math.log(boxVolume(h.box));
28803
+ if (score < bestScore) {
28804
+ bestScore = score;
28805
+ best = h;
28806
+ }
28807
+ }
28808
+ return best;
28809
+ }
28810
+
28811
+ // src/assembly/materials.ts
28812
+ var WOOD_FAMILY = /* @__PURE__ */ new Set(["wood_soft", "wood_hard", "mdf", "plywood"]);
28813
+ var METAL_FAMILY = /* @__PURE__ */ new Set(["steel", "aluminium", "cast_iron", "copper"]);
28814
+ var KEY_OVERRIDES = {
28815
+ shower: { plain: "ceramic", metal: "aluminium", glass: "tempered_glass" },
28816
+ sink_kitchen: { wood: "mdf" },
28817
+ sink_bathroom: { wood: "mdf" },
28818
+ mailbox: { wood: "steel" },
28819
+ sofa: { metal: "spring_steel" },
28820
+ armchair: { metal: "spring_steel" },
28821
+ bed_double: { metal: "spring_steel" },
28822
+ bed_single: { metal: "spring_steel" },
28823
+ box_bed: { metal: "spring_steel" }
28824
+ };
28825
+ var DENSITY = {
28826
+ steel: 7850,
28827
+ aluminium: 2700,
28828
+ cast_iron: 7200,
28829
+ copper: 8900,
28830
+ wood_soft: 550,
28831
+ wood_hard: 750,
28832
+ mdf: 700,
28833
+ plywood: 600,
28834
+ glass: 2500,
28835
+ tempered_glass: 2500,
28836
+ ceramic: 2300,
28837
+ plastic: 1e3,
28838
+ rubber: 1100,
28839
+ fabric: 250,
28840
+ foam: 40,
28841
+ brick: 1800,
28842
+ concrete: 2400,
28843
+ foliage: 100
28844
+ };
28845
+ var DEFAULT_DENSITY = 800;
28846
+ var THICKNESS = { steel: 12e-4, aluminium: 1e-3, copper: 2e-3, plastic: 3e-3, ceramic: 0.012, glass: 4e-3, tempered_glass: 6e-3 };
28847
+ function materialFor({ type, spec, key }) {
28848
+ const body = spec.destruction?.material ?? "plastic";
28849
+ const over = KEY_OVERRIDES[type]?.[key];
28850
+ if (over) return over;
28851
+ if (key === "glass" || key === "emissive") return body === "tempered_glass" ? "tempered_glass" : "glass";
28852
+ if (key === "metal") return METAL_FAMILY.has(body) ? body : "steel";
28853
+ if (key === "wood") return WOOD_FAMILY.has(body) ? body : "wood_soft";
28854
+ if (key === "foam") return "foam";
28855
+ if (key === "fabric") return "fabric";
28856
+ if (key === "plant") return "foliage";
28857
+ return body;
28858
+ }
28859
+
28860
+ // src/assembly/parts.ts
28861
+ var GROUND_TOUCH = 0.02;
28862
+ var CAGE_UNIT = 0.1;
28863
+ var CAGE_MIN = 0.1;
28864
+ var UPHOLSTERY_COVER = 2e-3;
28865
+ var GLASS_HP = { glass: 20, tempered_glass: 40 };
28866
+ function weightOf(piece2) {
28867
+ const [dx, dy, dz] = [piece2.box[3] - piece2.box[0], piece2.box[4] - piece2.box[1], piece2.box[5] - piece2.box[2]];
28868
+ const thin = THICKNESS[piece2.material];
28869
+ return (thin ? Math.min(piece2.vol, 2 * (dx * dy + dy * dz + dz * dx) * thin) : piece2.vol) * (DENSITY[piece2.material] ?? DEFAULT_DENSITY);
28870
+ }
28871
+ function shapeOf(type, piece2) {
28872
+ const size = [0, 1, 2].map((k) => Math.max(4e-3, piece2.box[k + 3] - piece2.box[k]));
28873
+ const fill = Math.max(0.03, Math.min(1, piece2.vol / (size[0] * size[1] * size[2])));
28874
+ return {
28875
+ id: piece2.id,
28876
+ material: piece2.material,
28877
+ shape: { kind: "box", size: size.map((v) => round(v)) },
28878
+ position: centre(piece2.box).map((v) => round(v)),
28879
+ fill: round(piece2.material === "foam" || piece2.material === "fabric" ? fill * 0.5 : fill, 3),
28880
+ tags: [type, ...piece2.mover && piece2.tag.piece ? [piece2.tag.piece] : []],
28881
+ ...piece2.solids ? { solids: piece2.solids } : {}
28882
+ };
28883
+ }
28884
+ function bodyBuildOf(piece2, body) {
28885
+ if (piece2.mover || piece2.material !== body.material) return {};
28886
+ const side = Math.min(piece2.box[3] - piece2.box[0], piece2.box[4] - piece2.box[1], piece2.box[5] - piece2.box[2]);
28887
+ const cage = body.reinforcement;
28888
+ if (cage && side >= CAGE_MIN) {
28889
+ return {
28890
+ reinforcement: { material: cage.material, spacing: cage.spacing, diameter: cage.diameter },
28891
+ units: { size: [CAGE_UNIT, CAGE_UNIT, round(side)], bond: "stack", mortar: piece2.material },
28892
+ structure: { role: "column" }
28893
+ };
28894
+ }
28895
+ const laid2 = body.units;
28896
+ return laid2 ? { units: { size: [laid2.size[0], laid2.size[1], laid2.size[2]], bond: laid2.bond, mortar: laid2.mortar } } : {};
28897
+ }
28898
+ function partsOf({ type, spec, pieces, all, massKg, planted }) {
28899
+ const body = spec.destruction ?? {};
28900
+ const totalWeight = all.reduce((sum, piece2) => sum + weightOf(piece2), 0) || 1;
28901
+ const parts2 = all.map((piece2) => {
28902
+ const extra = {};
28903
+ if (planted && !piece2.mover && piece2.box[1] <= GROUND_TOUCH) extra.anchored = true;
28904
+ Object.assign(extra, bodyBuildOf(piece2, body));
28905
+ const own = piece2.mover ? piece2.tag : void 0;
28906
+ if (own?.explodes) extra.explodes = { ...own.explodes };
28907
+ if (own?.contains) extra.contains = { ...own.contains };
28908
+ if (massKg) extra.mass = round(Math.max(0.01, massKg * weightOf(piece2) / totalWeight), 3);
28909
+ if (!piece2.mover && piece2.key === "foam") extra.layers = [{ material: "fabric", thickness: UPHOLSTERY_COVER, faces: "all" }];
28910
+ const hp = GLASS_HP[piece2.material];
28911
+ if (hp) extra.hp = hp;
28912
+ const thin = THICKNESS[piece2.material];
28913
+ if (thin) extra.thickness = Math.min(thin, Math.max(5e-4, Math.min(piece2.box[3] - piece2.box[0], piece2.box[4] - piece2.box[1], piece2.box[5] - piece2.box[2])));
28914
+ return Object.assign(shapeOf(type, piece2), extra);
28915
+ });
28916
+ const shell2 = pieces.length ? parts2.find((p) => p.id === pieces[0].id) : void 0;
28917
+ if (shell2 && body.explodes) shell2.explodes = { ...body.explodes };
28918
+ if (shell2 && body.contains) shell2.contains = { ...body.contains };
28919
+ return parts2;
28920
+ }
28921
+
28922
+ // src/assembly/pieces.ts
28923
+ function createIds() {
28924
+ const used = /* @__PURE__ */ new Set();
28925
+ return (base) => {
28926
+ let id = base;
28927
+ for (let n = 2; used.has(id); n++) id = `${base}_${n}`;
28928
+ used.add(id);
28929
+ return id;
28930
+ };
28931
+ }
28932
+ function bodyPiecesOf({ type, spec, clusters, statics, unique }) {
28933
+ const pieces = clusters.map((c) => {
28934
+ const dominant = Object.entries(c.area).sort((a, b) => b[1] - a[1])[0][0];
28935
+ const material = materialFor({ type, spec, key: dominant });
28936
+ const solids = solidsOf(c.indices.map((i) => statics[i]), c.box);
28937
+ return { id: unique(dominant === "emissive" ? "screen" : material), indices: c.indices, box: c.box, vol: c.vol, material, key: dominant, mover: false, ...solids ? { solids } : {} };
28938
+ });
28939
+ return pieces.length ? pieces : wirePiecesOf({ spec, unique });
28940
+ }
28941
+ function wirePiecesOf({ spec, unique }) {
28942
+ const pieces = [];
28943
+ for (const w of spec.wires ?? []) {
28944
+ if (!w.points || w.points.length < 2) continue;
28945
+ const r = w.radius ?? 0.01;
28946
+ const lo = [Infinity, Infinity, Infinity];
28947
+ const hi = [-Infinity, -Infinity, -Infinity];
28948
+ let length = 0;
28949
+ w.points.forEach((q, i) => {
28950
+ for (let k = 0; k < 3; k++) {
28951
+ lo[k] = Math.min(lo[k], q[k] - r);
28952
+ hi[k] = Math.max(hi[k], q[k] + r);
28953
+ }
28954
+ if (i) length += Math.hypot(q[0] - w.points[i - 1][0], q[1] - w.points[i - 1][1], q[2] - w.points[i - 1][2]);
28955
+ });
28956
+ const material = spec.destruction?.material ?? "plastic";
28957
+ pieces.push({ id: unique(w.kind === "conduit" ? "conduit" : w.kind), indices: [], box: [...lo, ...hi], vol: Math.PI * r * r * length, material, key: "plain", mover: false });
28958
+ }
28959
+ return pieces;
28960
+ }
28961
+ function moverPiecesOf({ spec, recorded, partIds }) {
28962
+ const movers = [];
28963
+ for (const p of spec.parts ?? []) {
28964
+ const r = recorded.get(p.id);
28965
+ if (!r || r.prims.length === 0) continue;
28966
+ const box = p.bounds ?? moverBox(r);
28967
+ if (!box) continue;
28968
+ const vol = r.prims.reduce((sum, q) => sum + q.vol, 0);
28969
+ const tag = p.destruction ?? {};
28970
+ const solids = solidsOf(r.prims.map((q) => ({ aabb: primitiveBoxInObject(r, q) })), box);
28971
+ const id = partIds.get(p.id) ?? p.id;
28972
+ movers.push({ id, source: p, indices: [], box, vol, material: tag.material ?? spec.destruction?.material ?? "plastic", mover: true, tag, ...solids ? { solids } : {} });
28973
+ }
28974
+ return movers;
28975
+ }
28976
+ function partIdsOf(spec, unique) {
28977
+ const ids = /* @__PURE__ */ new Map();
28978
+ for (const p of spec.parts ?? []) ids.set(p.id, unique(sanitize(p.id)));
28979
+ return ids;
28980
+ }
28981
+
28982
+ // src/assembly/assemble.ts
28983
+ var ASSEMBLY_SEED = 1;
28984
+ function assembleHouseholdType({ household, type, castWith = castWithMember }) {
28985
+ const recorder = createDrawRecorder(NOOP_API);
28986
+ const spec = household.build(type, { seed: ASSEMBLY_SEED }, recorder.api);
28987
+ const def = household.types.find((t) => t.id === type);
28988
+ const planted = def?.fixed === true && def.y <= 0;
28989
+ if (planted) layInStretches(recorder.statics);
28990
+ const clusters = clusterStatics({ type, statics: recorder.statics, castWith });
28991
+ const unique = createIds();
28992
+ const partIds = partIdsOf(spec, unique);
28993
+ const pieces = bodyPiecesOf({ type, spec, clusters, statics: recorder.statics, unique });
28994
+ const movers = moverPiecesOf({ spec, recorded: recorder.movers, partIds });
28995
+ const parts2 = partsOf({ type, spec, pieces, all: [...pieces, ...movers], massKg: def?.massKg, planted });
28996
+ const joints = jointsOf({ spec, pieces, movers, statics: recorder.statics });
28997
+ const destructible2 = { name: type, parts: parts2, joints, tags: ["furniture", type], ...planted ? { fixed: true } : {} };
28998
+ const animations = buildAnimations({ spec, ids: partIds, present: new Set(movers.map((m) => m.source.id)) });
28999
+ const basinPiece = (pieces.find((p) => p.material === "ceramic") ?? pieces[0])?.id;
29000
+ const fluid = fluidOf({ type, basin: spec.basins?.[0], parts: parts2, basinPiece });
29001
+ return { type, spec, pieces, movers, partIds, destructible: destructible2, animations, fluid, statics: recorder.statics };
29002
+ }
29003
+ function drawHouseholdAssembly(params) {
29004
+ const { household, assembly, api } = params;
29005
+ const recorder = createDrawRecorder(api);
29006
+ const item = { seed: ASSEMBLY_SEED };
29007
+ const spec = household.build(assembly.type, item, recorder.api);
29008
+ recorder.flush(assembly.pieces, assembly.statics);
29009
+ return spec;
29010
+ }
29011
+ var REGION_OF = { en: "us", "pt-BR": "br" };
29012
+ function createHouseholdAssemblies(options = {}) {
29013
+ const households = {};
29014
+ const assemblies = /* @__PURE__ */ new Map();
29015
+ const household = (locale) => households[locale] ?? (households[locale] = createHousehold({ locale, region: REGION_OF[locale] }));
29016
+ const assemble = (locale, type) => {
29017
+ const key = `${locale}:${type}`;
29018
+ let assembly = assemblies.get(key);
29019
+ if (!assembly) assemblies.set(key, assembly = assembleHouseholdType({ household: household(locale), type, ...options.castWith ? { castWith: options.castWith } : {} }));
29020
+ return assembly;
29021
+ };
29022
+ return {
29023
+ household,
29024
+ assemble,
29025
+ draw: (locale, type, api) => drawHouseholdAssembly({ household: household(locale), assembly: assemble(locale, type), api })
29026
+ };
29027
+ }
28154
29028
  return __toCommonJS(index_exports);
28155
29029
  })();
28156
29030
  //# sourceMappingURL=index.global.js.map