@adatechnology/game-items-three 0.11.8 → 0.13.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.
@@ -21,6 +21,7 @@ var GameItemsThree = (() => {
21
21
  // src/index.ts
22
22
  var index_exports = {};
23
23
  __export(index_exports, {
24
+ CUP_FLOOR_SHARE: () => CUP_FLOOR_SHARE,
24
25
  DESTRUCTION_MATERIAL_BY_TAG: () => DESTRUCTION_MATERIAL_BY_TAG,
25
26
  FINDS_TABLE_ID: () => FINDS_TABLE_ID,
26
27
  HUMAN_HEIGHT: () => HUMAN_HEIGHT,
@@ -40,6 +41,7 @@ var GameItemsThree = (() => {
40
41
  SHIPPED_MODELS: () => SHIPPED_MODELS,
41
42
  SHOWCASE_PREFIX: () => SHOWCASE_PREFIX,
42
43
  SHOWCASE_STAND_ID: () => SHOWCASE_STAND_ID,
44
+ WASH_NAME: () => WASH_NAME,
43
45
  WEAR_AMOUNT: () => WEAR_AMOUNT,
44
46
  WEAR_TAGS: () => WEAR_TAGS,
45
47
  WEAR_TARGET: () => WEAR_TARGET,
@@ -70,12 +72,15 @@ var GameItemsThree = (() => {
70
72
  itemOpening: () => itemOpening,
71
73
  itemThumbnail: () => itemThumbnail,
72
74
  itemThumbnailSvg: () => itemThumbnailSvg,
75
+ itemVessel: () => itemVessel,
73
76
  listItemModels: () => listItemModels,
74
77
  makeupSpec: () => makeupSpec,
75
78
  mergeItem: () => mergeItem,
76
79
  openItem: () => openItem,
77
80
  registerItemModel: () => registerItemModel,
78
81
  renderItemThumbnail: () => renderItemThumbnail,
82
+ setItemDirt: () => setItemDirt,
83
+ setItemFoam: () => setItemFoam,
79
84
  setOpeningContents: () => setOpeningContents,
80
85
  setWear: () => setWear,
81
86
  shade: () => shade,
@@ -93,6 +98,454 @@ var GameItemsThree = (() => {
93
98
  wearableMaterials: () => wearableMaterials
94
99
  });
95
100
 
101
+ // ../game-contracts/dist/index.js
102
+ var DEFAULT_BLAST_IMPULSE = { bodyArea: 0.7, lift: 0.15, minSpeed: 0.3, tntPerJoule: 0.24 / 2e5 };
103
+ var NEAREST = 0.3;
104
+ function sideOnImpulse(tnt, distance2, nearest = NEAREST) {
105
+ if (!(tnt > 0)) return 0;
106
+ const w3 = Math.cbrt(tnt);
107
+ const z = Math.max(distance2, nearest) / w3;
108
+ const near = z / 0.23 * (z / 0.23);
109
+ const far = z / 1.55;
110
+ const scaled = 0.067 * Math.sqrt(1 + near * near) / (z * z * Math.cbrt(1 + far * far * far));
111
+ return scaled * w3 * 100;
112
+ }
113
+ var ATMOSPHERE = 101325;
114
+ function sideOnOverpressure(tnt, distance2, nearest = NEAREST) {
115
+ if (!(tnt > 0)) return 0;
116
+ const z = Math.max(distance2, nearest) / Math.cbrt(tnt);
117
+ const ratio = 808 * (1 + (z / 4.5) ** 2) / (Math.sqrt(1 + (z / 0.048) ** 2) * Math.sqrt(1 + (z / 0.32) ** 2) * Math.sqrt(1 + (z / 1.35) ** 2));
118
+ return ratio * ATMOSPHERE;
119
+ }
120
+ function bodyImpulse(tnt, distance2) {
121
+ if (!(tnt > 0)) return 0;
122
+ const z = Math.max(distance2, NEAREST) / Math.cbrt(tnt);
123
+ return sideOnImpulse(tnt, distance2) * (2 + 4 / (1 + z * z));
124
+ }
125
+ var CHARGE_RADIUS = 1.3;
126
+ var CHARGE_SECONDS = 0.01;
127
+ var CHARGE_FLUX = 15e5;
128
+ var FUEL_RADIUS = 2.9;
129
+ var FUEL_SECONDS = 0.45;
130
+ var FUEL_FLUX = 25e4;
131
+ var DOSE_PER_DEGREE = 300;
132
+ function chargeFireball(tnt) {
133
+ const cube = Math.cbrt(Math.max(0, tnt));
134
+ return { radius: CHARGE_RADIUS * cube, seconds: CHARGE_SECONDS * cube, flux: CHARGE_FLUX };
135
+ }
136
+ function fuelFireball(fuel) {
137
+ const cube = Math.cbrt(Math.max(0, fuel));
138
+ return { radius: FUEL_RADIUS * cube, seconds: FUEL_SECONDS * cube, flux: FUEL_FLUX };
139
+ }
140
+ function fireballDose(fireball, distance2) {
141
+ const share = distance2 <= fireball.radius ? 1 : (fireball.radius / distance2) ** 2;
142
+ return fireball.flux * fireball.seconds * share;
143
+ }
144
+ function ignitionDose(ignitionC, ambientC = 20) {
145
+ return DOSE_PER_DEGREE * Math.max(1, ignitionC - ambientC);
146
+ }
147
+ var ATMOSPHERE2 = 101325;
148
+ var NEAREST_SCALED = 0.2;
149
+ var LOADED_MARGIN = 0.15;
150
+ var TNT_JOULES = 4184e3;
151
+ var SHOCK_COUPLING = 0.04;
152
+ var SHOCK_SCALED = 0.6;
153
+ function reflectedLoad(tnt, distance2) {
154
+ if (!(tnt > 0)) return { pressure: 0, impulse: 0 };
155
+ const cube = Math.cbrt(tnt);
156
+ const nearest = NEAREST_SCALED * cube;
157
+ const side = sideOnOverpressure(tnt, distance2, nearest);
158
+ const z = Math.max(distance2, nearest) / cube;
159
+ const pressure = 2 * side * (7 * ATMOSPHERE2 + 4 * side) / (7 * ATMOSPHERE2 + side);
160
+ const impulse = sideOnImpulse(tnt, distance2, nearest) * (2 + 4 / (1 + z * z));
161
+ return { pressure, impulse };
162
+ }
163
+ function waveWork(input) {
164
+ const load = reflectedLoad(input.tnt, input.distance);
165
+ const reach2 = Math.min(1, Math.max(0, input.reach));
166
+ const pressure = load.pressure * reach2;
167
+ if (!(input.area > 0) || !(input.mass > 0) || pressure <= 0) return { energy: 0, shock: 0, pressure, loaded: 0 };
168
+ const loaded = Math.min(input.area, Math.PI * (input.distance + LOADED_MARGIN) ** 2);
169
+ const mass = input.mass * (loaded / input.area);
170
+ const impulse = load.impulse * reach2 * loaded;
171
+ const impulsive = impulse * impulse / (2 * mass);
172
+ const quasiStatic = pressure * loaded * Math.max(input.thickness, 1e-4);
173
+ return { energy: Math.min(impulsive, quasiStatic), shock: shockWork(input), pressure, loaded };
174
+ }
175
+ function shockWork(input) {
176
+ const cube = Math.cbrt(input.tnt);
177
+ if (!(cube > 0) || !(input.area > 0)) return 0;
178
+ const z = Math.max(input.distance, 0) / cube;
179
+ const radius = Math.cbrt(3 * input.tnt / (4 * Math.PI * 1600));
180
+ const share = Math.min(0.5, input.area / (4 * Math.PI * (input.distance + radius) ** 2));
181
+ const falloff = 1 + z / SHOCK_SCALED * (z / SHOCK_SCALED);
182
+ const reach2 = Math.min(1, Math.max(0, input.reach));
183
+ return SHOCK_COUPLING * input.tnt * TNT_JOULES * share * reach2 * reach2 / (falloff * falloff);
184
+ }
185
+ var DEFAULT_COST_ALLOCATION_BYTES = 1024 * 1024;
186
+ var STRUCTURE_ROLES = ["foundation", "column", "beam", "slab", "wall", "partition", "roof", "stair", "none"];
187
+ var BEARS = [true, false, "a_on_b", "b_on_a"];
188
+ var finite = (n) => typeof n === "number" && Number.isFinite(n);
189
+ var positive = (n) => finite(n) && n > 0;
190
+ var vec3 = (v) => Array.isArray(v) && v.length === 3 && v.every(finite);
191
+ var nonNegative = (n) => n === void 0 || finite(n) && n >= 0;
192
+ var FACES = ["both", "+", "-", "all"];
193
+ var BONDS = ["running", "stack"];
194
+ var checkStagedFields = (p, label, materials, problems) => {
195
+ const known = (m, what) => {
196
+ if (materials && !materials.has(m)) problems.push(`${label} ${what} has unknown material "${String(m)}"`);
197
+ };
198
+ (p?.layers ?? []).forEach((l, i) => {
199
+ known(l?.material, `layer ${i}`);
200
+ if (!positive(l?.thickness)) problems.push(`${label} layer ${i} thickness must be finite and positive`);
201
+ if (!FACES.includes(l?.faces)) problems.push(`${label} layer ${i} has an invalid faces "${String(l?.faces)}"`);
202
+ });
203
+ const r = p?.reinforcement;
204
+ if (r) {
205
+ known(r.material, "reinforcement");
206
+ if (!positive(r.spacing) || !positive(r.diameter)) problems.push(`${label} reinforcement spacing and diameter must be finite and positive`);
207
+ if (r.residualCapacity !== void 0 && !(finite(r.residualCapacity) && r.residualCapacity >= 0 && r.residualCapacity <= 1)) problems.push(`${label} reinforcement residualCapacity must be between 0 and 1`);
208
+ }
209
+ const u = p?.units;
210
+ if (u) {
211
+ known(u.mortar, "units mortar");
212
+ if (!vec3(u.size) || !u.size.every(positive)) problems.push(`${label} units size must be three finite positive numbers`);
213
+ if (!BONDS.includes(u.bond)) problems.push(`${label} units has an invalid bond "${String(u.bond)}"`);
214
+ }
215
+ if (p?.breach && p.breach.area !== void 0 && !positive(p.breach.area)) problems.push(`${label} breach area must be finite and positive`);
216
+ };
217
+ var checkSpec = (spec, options = {}) => {
218
+ const problems = [];
219
+ const warnings = [];
220
+ const materials = options.materials ? new Set(options.materials) : null;
221
+ const parts2 = Array.isArray(spec?.parts) ? spec.parts : [];
222
+ if (!Array.isArray(spec?.parts) || parts2.length === 0) problems.push("the spec needs at least one part");
223
+ const ids = /* @__PURE__ */ new Set();
224
+ for (const p of parts2) {
225
+ const id = String(p?.id ?? "");
226
+ const label = `part "${id}"`;
227
+ if (id === "") problems.push("a part has no id");
228
+ else if (ids.has(id)) problems.push(`duplicate part id "${id}"`);
229
+ ids.add(id);
230
+ if (materials && !materials.has(p?.material)) problems.push(`${label} has unknown material "${String(p?.material)}"`);
231
+ else if (typeof p?.material !== "string" || p.material === "") problems.push(`${label} needs a material`);
232
+ const s = p?.shape;
233
+ if (s?.kind === "box") {
234
+ if (!Array.isArray(s.size) || s.size.length !== 3 || !s.size.every(positive)) problems.push(`${label} box size must be three finite positive numbers`);
235
+ } else if (s?.kind === "cylinder") {
236
+ if (!positive(s.radius) || !positive(s.height)) problems.push(`${label} cylinder radius and height must be finite and positive`);
237
+ } else if (s?.kind === "sphere") {
238
+ if (!positive(s.radius)) problems.push(`${label} sphere radius must be finite and positive`);
239
+ } else problems.push(`${label} has an unknown shape`);
240
+ if (!vec3(p?.position)) problems.push(`${label} needs a finite position [x, y, z]`);
241
+ if (p?.rotation !== void 0 && !vec3(p.rotation)) problems.push(`${label} has an invalid rotation`);
242
+ for (const f of ["mass", "hp", "thickness"]) if (!nonNegative(p?.[f])) problems.push(`${label} ${f} must be a finite number >= 0`);
243
+ if (p?.fill !== void 0 && !(finite(p.fill) && p.fill >= 0 && p.fill <= 1)) problems.push(`${label} fill must be between 0 and 1`);
244
+ if (p?.structure) {
245
+ if (!STRUCTURE_ROLES.includes(p.structure.role)) problems.push(`${label} has an invalid structure role "${String(p.structure.role)}"`);
246
+ if (!nonNegative(p.structure.capacity)) problems.push(`${label} structure capacity must be a finite number >= 0`);
247
+ }
248
+ if (p?.contains && !nonNegative(p.contains.liters)) problems.push(`${label} contains.liters must be a finite number >= 0`);
249
+ checkStagedFields(p, label, materials, problems);
250
+ }
251
+ const jointIds = /* @__PURE__ */ new Set();
252
+ const edges = [];
253
+ for (const j of spec?.joints ?? []) {
254
+ const id = j.id ?? `${j.a}~${j.b}`;
255
+ const label = `joint "${id}"`;
256
+ if (jointIds.has(id)) problems.push(`duplicate joint id "${id}"`);
257
+ jointIds.add(id);
258
+ if (!ids.has(j.a)) problems.push(`${label} references unknown part "${String(j.a)}"`);
259
+ if (!ids.has(j.b)) problems.push(`${label} references unknown part "${String(j.b)}"`);
260
+ if (j.a === j.b) problems.push(`${label} joins part "${String(j.a)}" to itself`);
261
+ if (j.bears !== void 0 && !BEARS.includes(j.bears)) problems.push(`${label} has an invalid bears "${String(j.bears)}"`);
262
+ if (!nonNegative(j.strength)) problems.push(`${label} strength must be a finite number >= 0`);
263
+ if (!nonNegative(j.seconds)) problems.push(`${label} seconds must be a finite number >= 0`);
264
+ if (j.bears !== false && ids.has(j.a) && ids.has(j.b) && j.a !== j.b) edges.push([j.a, j.b]);
265
+ }
266
+ const structural = parts2.filter((p) => p?.structure && p.structure.role !== "none");
267
+ if (structural.length && spec.joints) {
268
+ const anchored = parts2.filter((p) => p.anchored || p.structure?.role === "foundation").map((p) => p.id);
269
+ const adj = /* @__PURE__ */ new Map();
270
+ for (const [a, b] of edges) {
271
+ adj.set(a, [...adj.get(a) ?? [], b]);
272
+ adj.set(b, [...adj.get(b) ?? [], a]);
273
+ }
274
+ const seen = new Set(anchored);
275
+ const queue = [...anchored];
276
+ while (queue.length) {
277
+ for (const n of adj.get(queue.pop()) ?? []) {
278
+ if (seen.has(n)) continue;
279
+ seen.add(n);
280
+ queue.push(n);
281
+ }
282
+ }
283
+ const lost = structural.filter((p) => !seen.has(p.id)).map((p) => p.id);
284
+ if (lost.length) warnings.push(`structural part(s) ${lost.map((i) => `"${i}"`).join(", ")} cannot reach an anchored part, so they will fall`);
285
+ }
286
+ return { ok: problems.length === 0, problems, warnings };
287
+ };
288
+ var DEFAULT_IGNITION_RULES = {
289
+ fillCurve: [
290
+ [0, 0.6],
291
+ [0.1, 1],
292
+ [0.35, 0.6],
293
+ [0.65, 0.3],
294
+ [0.9, 0.15],
295
+ [1, 0.12]
296
+ ],
297
+ flameFillInfluence: 0.5,
298
+ flameDefaults: { incendiary: 0.7, tracer: 0.2 },
299
+ sparkTarget: { steel: 1, iron: 1, aluminium: 0.25 },
300
+ sparkMetalDefault: 0.5,
301
+ sparkFluid: { diesel: 0.15 },
302
+ fireNear: { radius: 1.5, chancePerSecond: 0.5 }
303
+ };
304
+ var resolveIgnitionRules = (rules) => ({
305
+ ...DEFAULT_IGNITION_RULES,
306
+ ...rules,
307
+ flameDefaults: { ...DEFAULT_IGNITION_RULES.flameDefaults, ...rules?.flameDefaults },
308
+ sparkTarget: { ...DEFAULT_IGNITION_RULES.sparkTarget, ...rules?.sparkTarget },
309
+ sparkFluid: { ...DEFAULT_IGNITION_RULES.sparkFluid, ...rules?.sparkFluid },
310
+ fireNear: { ...DEFAULT_IGNITION_RULES.fireNear, ...rules?.fireNear }
311
+ });
312
+ var fillFactor = (fill2, curve = DEFAULT_IGNITION_RULES.fillCurve) => {
313
+ if (curve.length === 0) return 1;
314
+ const f = Math.min(1, Math.max(0, fill2));
315
+ if (f <= curve[0][0]) return curve[0][1];
316
+ for (let i = 1; i < curve.length; i++) {
317
+ const [x1, y1] = curve[i];
318
+ const [x0, y0] = curve[i - 1];
319
+ if (f <= x1) return x1 === x0 ? y1 : y0 + (y1 - y0) * (f - x0) / (x1 - x0);
320
+ }
321
+ return curve[curve.length - 1][1];
322
+ };
323
+ var sparkTargetFactor = (materialId, metal, rules = DEFAULT_IGNITION_RULES) => !metal ? 0 : rules.sparkTarget[materialId] ?? rules.sparkMetalDefault;
324
+ var ignitionChance = (hit, target, rules = DEFAULT_IGNITION_RULES) => {
325
+ const k = fillFactor(target.fill, rules.fillCurve);
326
+ const spark = (hit.ignition?.spark ?? 0) * target.sparkTarget * (target.fluid === void 0 ? 1 : rules.sparkFluid[target.fluid] ?? 1) * k;
327
+ const flameBase = hit.ignition?.flame ?? Math.max(hit.incendiary ? rules.flameDefaults.incendiary : 0, hit.tracer ? rules.flameDefaults.tracer : 0);
328
+ const flame = flameBase * (1 - rules.flameFillInfluence * (1 - k));
329
+ return 1 - (1 - Math.min(1, Math.max(0, spark))) * (1 - Math.min(1, Math.max(0, flame)));
330
+ };
331
+ var sealBlock = (seal, state) => {
332
+ if (seal.spoilsWhenBreached && state.breached) return "breached";
333
+ if (seal.spoilsWhenBreached && state.leaked) return "leaked";
334
+ if (!state.opened) return "sealed";
335
+ return void 0;
336
+ };
337
+ var CARRY_HANDLE_TAG = "carryHandle";
338
+ var DEFERRED_QUEUE_ID = {
339
+ DESTRUCTION_EVENTS: "destruction.events",
340
+ BREACH_PAINT: "floorplan.breach-paint",
341
+ BREACH_CUT: "floorplan.breach-cut",
342
+ AUDIO_VOICES: "audio.voices",
343
+ VEHICLE_CREASE: "vehicles.crease",
344
+ AUDIO_OCCLUSION: "audio.occlusion",
345
+ FLUID_FILM: "fluids.film",
346
+ VEHICLE_LOD_BATCH: "vehicles.lod-batch",
347
+ SETTLED_BATCH: "destruction.settled-batch",
348
+ STATIC_BATCH: "render.static-batch",
349
+ ANIMALS_STATIC_BATCH: "animals.static-batch",
350
+ CHARACTERS_STATIC_BATCH: "characters.static-batch",
351
+ HOUSE_SHADOW_BATCH: "floorplan.shadow-batch",
352
+ DESTRUCTION_PREFIT: "destruction.prefit"
353
+ };
354
+ var DEFERRED_PRIORITY = {
355
+ [DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS]: { priority: 300, phase: "present" },
356
+ // every frame: the walls cut since the last frame are painted once each, and a hole must show in the frame of the blast
357
+ [DEFERRED_QUEUE_ID.BREACH_CUT]: { priority: 260, phase: "present", minEveryFrames: 1 },
358
+ [DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present", minEveryFrames: 1 },
359
+ [DEFERRED_QUEUE_ID.AUDIO_VOICES]: { priority: 200, phase: "idle", reserveMs: 1 },
360
+ [DEFERRED_QUEUE_ID.AUDIO_OCCLUSION]: { priority: 190, phase: "idle", minEveryFrames: 8 },
361
+ [DEFERRED_QUEUE_ID.FLUID_FILM]: { priority: 120, phase: "idle", minEveryFrames: 2 },
362
+ [DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" },
363
+ [DEFERRED_QUEUE_ID.VEHICLE_LOD_BATCH]: { priority: 90, phase: "idle", minEveryFrames: 4 },
364
+ [DEFERRED_QUEUE_ID.SETTLED_BATCH]: { priority: 70, phase: "idle", minEveryFrames: 8 },
365
+ [DEFERRED_QUEUE_ID.STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
366
+ [DEFERRED_QUEUE_ID.ANIMALS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
367
+ [DEFERRED_QUEUE_ID.CHARACTERS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
368
+ [DEFERRED_QUEUE_ID.HOUSE_SHADOW_BATCH]: { priority: 50, phase: "idle", minEveryFrames: 8 },
369
+ [DEFERRED_QUEUE_ID.DESTRUCTION_PREFIT]: { priority: 40, phase: "idle", minEveryFrames: 30 }
370
+ };
371
+ var MUST_DRAIN_QUEUE_IDS = /* @__PURE__ */ new Set([DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS, DEFERRED_QUEUE_ID.BREACH_CUT]);
372
+ function drainDetached(queue, budgetMs, clock = () => performance.now()) {
373
+ return queue.run(clock() + budgetMs, clock);
374
+ }
375
+ var WARNED_KEY = /* @__PURE__ */ Symbol.for("@adatechnology/game-contracts.warned");
376
+ var warnedKeys = () => {
377
+ const holder = globalThis;
378
+ return holder[WARNED_KEY] ?? (holder[WARNED_KEY] = /* @__PURE__ */ new Set());
379
+ };
380
+ var isProduction = () => {
381
+ try {
382
+ return process.env.NODE_ENV === "production";
383
+ } catch {
384
+ return false;
385
+ }
386
+ };
387
+ var isQuiet = () => globalThis.__GAME_KIT_QUIET__ === true;
388
+ var warnOnce = (key2, message) => {
389
+ if (isQuiet() || isProduction()) return;
390
+ const seen = warnedKeys();
391
+ if (seen.has(key2)) return;
392
+ seen.add(key2);
393
+ console.warn(`[game-kit] ${message}`);
394
+ };
395
+ var UNSAFE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
396
+ var isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) && Object.getPrototypeOf(value) === Object.prototype;
397
+ var deepMerge = (base2, patch) => {
398
+ if (!patch) return base2;
399
+ const result = { ...base2 };
400
+ for (const [key2, value] of Object.entries(patch)) {
401
+ if (value === void 0 || UNSAFE_KEYS.has(key2)) continue;
402
+ const current = result[key2];
403
+ result[key2] = isPlainObject(current) && isPlainObject(value) ? deepMerge(current, value) : value;
404
+ }
405
+ return result;
406
+ };
407
+ var mergeById = (shipped, extra) => {
408
+ const entries = /* @__PURE__ */ new Map();
409
+ for (const entry2 of [...shipped, ...extra ?? []]) entries.set(entry2.id, entry2);
410
+ return entries;
411
+ };
412
+ var applyPatches = (entries, patches) => {
413
+ for (const [id, patch] of Object.entries(patches ?? {})) {
414
+ const entry2 = entries.get(id);
415
+ if (entry2) entries.set(id, deepMerge(entry2, patch));
416
+ else warnOnce(`registry.patch.${id}`, `patch for "${id}" ignored: no entry has that id`);
417
+ }
418
+ };
419
+ var removeIds = (entries, ids) => {
420
+ for (const id of ids ?? []) {
421
+ if (!entries.delete(id)) warnOnce(`registry.remove.${id}`, `remove of "${id}" ignored: no entry has that id`);
422
+ }
423
+ };
424
+ var defineCategories = (defs, options = {}) => {
425
+ const problems = [];
426
+ const duplicates = (list2) => {
427
+ const ids = /* @__PURE__ */ new Set();
428
+ for (const def of list2) {
429
+ if (ids.has(def.id)) problems.push(`duplicate category "${def.id}"`);
430
+ ids.add(def.id);
431
+ }
432
+ };
433
+ duplicates(defs);
434
+ duplicates(options.extra ?? []);
435
+ const entries = mergeById(defs, options.extra);
436
+ applyPatches(entries, options.patches);
437
+ removeIds(entries, options.remove);
438
+ const chain = (id) => {
439
+ const path = [];
440
+ let current = id;
441
+ while (current !== void 0) {
442
+ const def = entries.get(current);
443
+ if (!def) throw new Error(path.length === 0 ? `unknown category "${current}"` : `category "${path[0]}" has unknown parent "${current}"`);
444
+ if (path.includes(current)) throw new Error(`category cycle: ${[...path, current].reverse().join(" -> ")}`);
445
+ path.push(current);
446
+ current = def.extends;
447
+ }
448
+ return path.reverse();
449
+ };
450
+ const registry = {
451
+ get: (id) => entries.get(id),
452
+ has: (id) => entries.has(id),
453
+ ids: () => [...entries.keys()],
454
+ chain,
455
+ defaults: (id) => chain(id).reduce((acc, ancestor) => deepMerge(acc, entries.get(ancestor)?.defaults), {}),
456
+ requires: (id) => {
457
+ const out = [];
458
+ for (const ancestor of chain(id)) for (const contract of entries.get(ancestor)?.requires ?? []) if (!out.includes(contract)) out.push(contract);
459
+ return out;
460
+ },
461
+ isA: (id, ancestorId) => {
462
+ try {
463
+ return chain(id).includes(ancestorId);
464
+ } catch {
465
+ return false;
466
+ }
467
+ },
468
+ check: () => {
469
+ const found = [...problems];
470
+ for (const [id, def] of entries) {
471
+ if (def.extends !== void 0 && !entries.has(def.extends)) found.push(`category "${id}" extends unknown "${def.extends}"`);
472
+ else {
473
+ try {
474
+ chain(id);
475
+ } catch (error) {
476
+ const message = error.message;
477
+ if (message.startsWith("category cycle") && !found.includes(message)) found.push(message);
478
+ }
479
+ }
480
+ }
481
+ return found;
482
+ }
483
+ };
484
+ return registry;
485
+ };
486
+ var resolveEntry = (registry, entry2, kindField = "kind") => deepMerge(registry.defaults(String(entry2[kindField])), entry2);
487
+ var KIT_ORIGIN_KEY = "kitOrigin";
488
+ function markKitOrigin(object2, origin) {
489
+ const node = object2;
490
+ node.userData = node.userData ?? {};
491
+ node.userData[KIT_ORIGIN_KEY] = { ...origin };
492
+ return object2;
493
+ }
494
+ var SURFACE_IDS = ["concrete", "asphalt", "wood", "tile", "dirt", "grass", "gravel", "sand", "metal", "water", "glass", "carpet"];
495
+ var GAIT_IDS = ["walk", "run"];
496
+ var LANDING_IDS = ["light", "heavy"];
497
+ var BODY_SOUND_IDS = [
498
+ "jump",
499
+ "cloth_rustle",
500
+ "body_fall",
501
+ "fall_damage",
502
+ "player_hurt",
503
+ "player_breath_run",
504
+ "player_death",
505
+ "bite",
506
+ "grab",
507
+ "punch_swing",
508
+ "punch_hit_body",
509
+ "punch_hit_face",
510
+ "punch_hit_object",
511
+ "kick_swing",
512
+ "kick_hit",
513
+ "kick_hit_object",
514
+ "shove_two_hands",
515
+ "knife_swing",
516
+ "knife_stab",
517
+ "knife_slash",
518
+ "knife_hit_object",
519
+ "blunt_swing",
520
+ "blunt_hit",
521
+ "blunt_hit_object",
522
+ "axe_swing",
523
+ "axe_chop",
524
+ "axe_hit_object"
525
+ ];
526
+ var footstepSoundId = (surface, gait) => `footstep_${surface}_${gait}`;
527
+ var FOOTSTEP_SOUND_IDS = SURFACE_IDS.flatMap((surface) => GAIT_IDS.map((gait) => footstepSoundId(surface, gait)));
528
+ var LAND_SOUND_IDS = SURFACE_IDS.flatMap((surface) => LANDING_IDS.map((landing) => `land_${surface}_${landing}`));
529
+ var BODY_FOLEY_IDS = [...FOOTSTEP_SOUND_IDS, ...LAND_SOUND_IDS, ...BODY_SOUND_IDS];
530
+ var WORKER_KIND_ID = {
531
+ GROUND_TILES: "destruction.ground-tiles",
532
+ CROWD_PHYSICS: "crowd.physics",
533
+ PIECE_BOXES: "destruction.piece-boxes",
534
+ STATIC_COLLIDERS: "destruction.static-colliders",
535
+ SHAPES_GENERATE: "shapes.generate",
536
+ WORLD_REGION: "world.region",
537
+ VEHICLE_HULL_PLAN: "vehicles.hull-plan"
538
+ };
539
+ var WORKER_KIND_DEFAULTS = {
540
+ [WORKER_KIND_ID.GROUND_TILES]: { lane: "sim", priority: 300, latencyFrames: 2, late: "sync" },
541
+ [WORKER_KIND_ID.CROWD_PHYSICS]: { lane: "sim", priority: 250, latencyFrames: 1, late: "sync" },
542
+ [WORKER_KIND_ID.PIECE_BOXES]: { lane: "sim", priority: 200, latencyFrames: 2, late: "sync" },
543
+ [WORKER_KIND_ID.STATIC_COLLIDERS]: { lane: "build", priority: 150, late: "sync" },
544
+ [WORKER_KIND_ID.SHAPES_GENERATE]: { lane: "build", priority: 100, late: "sync" },
545
+ [WORKER_KIND_ID.WORLD_REGION]: { lane: "background", priority: 10, latencyFrames: 10, late: "drop" },
546
+ [WORKER_KIND_ID.VEHICLE_HULL_PLAN]: { lane: "build", priority: 120, late: "keep-waiting" }
547
+ };
548
+
96
549
  // ../game-shapes/dist/chunk-QETSTM6M.js
97
550
  function canonicalJson(value) {
98
551
  if (value === null) return "null";
@@ -1563,453 +2016,6 @@ var GameItemsThree = (() => {
1563
2016
  return { positions: positions2, normals, uvs };
1564
2017
  }
1565
2018
 
1566
- // ../game-contracts/dist/index.js
1567
- var DEFAULT_BLAST_IMPULSE = { bodyArea: 0.7, lift: 0.15, minSpeed: 0.3, tntPerJoule: 0.24 / 2e5 };
1568
- var NEAREST = 0.3;
1569
- function sideOnImpulse(tnt, distance2, nearest = NEAREST) {
1570
- if (!(tnt > 0)) return 0;
1571
- const w3 = Math.cbrt(tnt);
1572
- const z = Math.max(distance2, nearest) / w3;
1573
- const near = z / 0.23 * (z / 0.23);
1574
- const far = z / 1.55;
1575
- const scaled = 0.067 * Math.sqrt(1 + near * near) / (z * z * Math.cbrt(1 + far * far * far));
1576
- return scaled * w3 * 100;
1577
- }
1578
- var ATMOSPHERE = 101325;
1579
- function sideOnOverpressure(tnt, distance2, nearest = NEAREST) {
1580
- if (!(tnt > 0)) return 0;
1581
- const z = Math.max(distance2, nearest) / Math.cbrt(tnt);
1582
- const ratio = 808 * (1 + (z / 4.5) ** 2) / (Math.sqrt(1 + (z / 0.048) ** 2) * Math.sqrt(1 + (z / 0.32) ** 2) * Math.sqrt(1 + (z / 1.35) ** 2));
1583
- return ratio * ATMOSPHERE;
1584
- }
1585
- function bodyImpulse(tnt, distance2) {
1586
- if (!(tnt > 0)) return 0;
1587
- const z = Math.max(distance2, NEAREST) / Math.cbrt(tnt);
1588
- return sideOnImpulse(tnt, distance2) * (2 + 4 / (1 + z * z));
1589
- }
1590
- var CHARGE_RADIUS = 1.3;
1591
- var CHARGE_SECONDS = 0.01;
1592
- var CHARGE_FLUX = 15e5;
1593
- var FUEL_RADIUS = 2.9;
1594
- var FUEL_SECONDS = 0.45;
1595
- var FUEL_FLUX = 25e4;
1596
- var DOSE_PER_DEGREE = 300;
1597
- function chargeFireball(tnt) {
1598
- const cube = Math.cbrt(Math.max(0, tnt));
1599
- return { radius: CHARGE_RADIUS * cube, seconds: CHARGE_SECONDS * cube, flux: CHARGE_FLUX };
1600
- }
1601
- function fuelFireball(fuel) {
1602
- const cube = Math.cbrt(Math.max(0, fuel));
1603
- return { radius: FUEL_RADIUS * cube, seconds: FUEL_SECONDS * cube, flux: FUEL_FLUX };
1604
- }
1605
- function fireballDose(fireball, distance2) {
1606
- const share = distance2 <= fireball.radius ? 1 : (fireball.radius / distance2) ** 2;
1607
- return fireball.flux * fireball.seconds * share;
1608
- }
1609
- function ignitionDose(ignitionC, ambientC = 20) {
1610
- return DOSE_PER_DEGREE * Math.max(1, ignitionC - ambientC);
1611
- }
1612
- var ATMOSPHERE2 = 101325;
1613
- var NEAREST_SCALED = 0.2;
1614
- var LOADED_MARGIN = 0.15;
1615
- var TNT_JOULES = 4184e3;
1616
- var SHOCK_COUPLING = 0.04;
1617
- var SHOCK_SCALED = 0.6;
1618
- function reflectedLoad(tnt, distance2) {
1619
- if (!(tnt > 0)) return { pressure: 0, impulse: 0 };
1620
- const cube = Math.cbrt(tnt);
1621
- const nearest = NEAREST_SCALED * cube;
1622
- const side = sideOnOverpressure(tnt, distance2, nearest);
1623
- const z = Math.max(distance2, nearest) / cube;
1624
- const pressure = 2 * side * (7 * ATMOSPHERE2 + 4 * side) / (7 * ATMOSPHERE2 + side);
1625
- const impulse = sideOnImpulse(tnt, distance2, nearest) * (2 + 4 / (1 + z * z));
1626
- return { pressure, impulse };
1627
- }
1628
- function waveWork(input) {
1629
- const load = reflectedLoad(input.tnt, input.distance);
1630
- const reach2 = Math.min(1, Math.max(0, input.reach));
1631
- const pressure = load.pressure * reach2;
1632
- if (!(input.area > 0) || !(input.mass > 0) || pressure <= 0) return { energy: 0, shock: 0, pressure, loaded: 0 };
1633
- const loaded = Math.min(input.area, Math.PI * (input.distance + LOADED_MARGIN) ** 2);
1634
- const mass = input.mass * (loaded / input.area);
1635
- const impulse = load.impulse * reach2 * loaded;
1636
- const impulsive = impulse * impulse / (2 * mass);
1637
- const quasiStatic = pressure * loaded * Math.max(input.thickness, 1e-4);
1638
- return { energy: Math.min(impulsive, quasiStatic), shock: shockWork(input), pressure, loaded };
1639
- }
1640
- function shockWork(input) {
1641
- const cube = Math.cbrt(input.tnt);
1642
- if (!(cube > 0) || !(input.area > 0)) return 0;
1643
- const z = Math.max(input.distance, 0) / cube;
1644
- const radius = Math.cbrt(3 * input.tnt / (4 * Math.PI * 1600));
1645
- const share = Math.min(0.5, input.area / (4 * Math.PI * (input.distance + radius) ** 2));
1646
- const falloff = 1 + z / SHOCK_SCALED * (z / SHOCK_SCALED);
1647
- const reach2 = Math.min(1, Math.max(0, input.reach));
1648
- return SHOCK_COUPLING * input.tnt * TNT_JOULES * share * reach2 * reach2 / (falloff * falloff);
1649
- }
1650
- var DEFAULT_COST_ALLOCATION_BYTES = 1024 * 1024;
1651
- var STRUCTURE_ROLES = ["foundation", "column", "beam", "slab", "wall", "partition", "roof", "stair", "none"];
1652
- var BEARS = [true, false, "a_on_b", "b_on_a"];
1653
- var finite = (n) => typeof n === "number" && Number.isFinite(n);
1654
- var positive = (n) => finite(n) && n > 0;
1655
- var vec3 = (v) => Array.isArray(v) && v.length === 3 && v.every(finite);
1656
- var nonNegative = (n) => n === void 0 || finite(n) && n >= 0;
1657
- var FACES = ["both", "+", "-", "all"];
1658
- var BONDS = ["running", "stack"];
1659
- var checkStagedFields = (p, label, materials, problems) => {
1660
- const known = (m, what) => {
1661
- if (materials && !materials.has(m)) problems.push(`${label} ${what} has unknown material "${String(m)}"`);
1662
- };
1663
- (p?.layers ?? []).forEach((l, i) => {
1664
- known(l?.material, `layer ${i}`);
1665
- if (!positive(l?.thickness)) problems.push(`${label} layer ${i} thickness must be finite and positive`);
1666
- if (!FACES.includes(l?.faces)) problems.push(`${label} layer ${i} has an invalid faces "${String(l?.faces)}"`);
1667
- });
1668
- const r = p?.reinforcement;
1669
- if (r) {
1670
- known(r.material, "reinforcement");
1671
- if (!positive(r.spacing) || !positive(r.diameter)) problems.push(`${label} reinforcement spacing and diameter must be finite and positive`);
1672
- if (r.residualCapacity !== void 0 && !(finite(r.residualCapacity) && r.residualCapacity >= 0 && r.residualCapacity <= 1)) problems.push(`${label} reinforcement residualCapacity must be between 0 and 1`);
1673
- }
1674
- const u = p?.units;
1675
- if (u) {
1676
- known(u.mortar, "units mortar");
1677
- if (!vec3(u.size) || !u.size.every(positive)) problems.push(`${label} units size must be three finite positive numbers`);
1678
- if (!BONDS.includes(u.bond)) problems.push(`${label} units has an invalid bond "${String(u.bond)}"`);
1679
- }
1680
- if (p?.breach && p.breach.area !== void 0 && !positive(p.breach.area)) problems.push(`${label} breach area must be finite and positive`);
1681
- };
1682
- var checkSpec = (spec, options = {}) => {
1683
- const problems = [];
1684
- const warnings = [];
1685
- const materials = options.materials ? new Set(options.materials) : null;
1686
- const parts2 = Array.isArray(spec?.parts) ? spec.parts : [];
1687
- if (!Array.isArray(spec?.parts) || parts2.length === 0) problems.push("the spec needs at least one part");
1688
- const ids = /* @__PURE__ */ new Set();
1689
- for (const p of parts2) {
1690
- const id = String(p?.id ?? "");
1691
- const label = `part "${id}"`;
1692
- if (id === "") problems.push("a part has no id");
1693
- else if (ids.has(id)) problems.push(`duplicate part id "${id}"`);
1694
- ids.add(id);
1695
- if (materials && !materials.has(p?.material)) problems.push(`${label} has unknown material "${String(p?.material)}"`);
1696
- else if (typeof p?.material !== "string" || p.material === "") problems.push(`${label} needs a material`);
1697
- const s = p?.shape;
1698
- if (s?.kind === "box") {
1699
- if (!Array.isArray(s.size) || s.size.length !== 3 || !s.size.every(positive)) problems.push(`${label} box size must be three finite positive numbers`);
1700
- } else if (s?.kind === "cylinder") {
1701
- if (!positive(s.radius) || !positive(s.height)) problems.push(`${label} cylinder radius and height must be finite and positive`);
1702
- } else if (s?.kind === "sphere") {
1703
- if (!positive(s.radius)) problems.push(`${label} sphere radius must be finite and positive`);
1704
- } else problems.push(`${label} has an unknown shape`);
1705
- if (!vec3(p?.position)) problems.push(`${label} needs a finite position [x, y, z]`);
1706
- if (p?.rotation !== void 0 && !vec3(p.rotation)) problems.push(`${label} has an invalid rotation`);
1707
- for (const f of ["mass", "hp", "thickness"]) if (!nonNegative(p?.[f])) problems.push(`${label} ${f} must be a finite number >= 0`);
1708
- if (p?.fill !== void 0 && !(finite(p.fill) && p.fill >= 0 && p.fill <= 1)) problems.push(`${label} fill must be between 0 and 1`);
1709
- if (p?.structure) {
1710
- if (!STRUCTURE_ROLES.includes(p.structure.role)) problems.push(`${label} has an invalid structure role "${String(p.structure.role)}"`);
1711
- if (!nonNegative(p.structure.capacity)) problems.push(`${label} structure capacity must be a finite number >= 0`);
1712
- }
1713
- if (p?.contains && !nonNegative(p.contains.liters)) problems.push(`${label} contains.liters must be a finite number >= 0`);
1714
- checkStagedFields(p, label, materials, problems);
1715
- }
1716
- const jointIds = /* @__PURE__ */ new Set();
1717
- const edges = [];
1718
- for (const j of spec?.joints ?? []) {
1719
- const id = j.id ?? `${j.a}~${j.b}`;
1720
- const label = `joint "${id}"`;
1721
- if (jointIds.has(id)) problems.push(`duplicate joint id "${id}"`);
1722
- jointIds.add(id);
1723
- if (!ids.has(j.a)) problems.push(`${label} references unknown part "${String(j.a)}"`);
1724
- if (!ids.has(j.b)) problems.push(`${label} references unknown part "${String(j.b)}"`);
1725
- if (j.a === j.b) problems.push(`${label} joins part "${String(j.a)}" to itself`);
1726
- if (j.bears !== void 0 && !BEARS.includes(j.bears)) problems.push(`${label} has an invalid bears "${String(j.bears)}"`);
1727
- if (!nonNegative(j.strength)) problems.push(`${label} strength must be a finite number >= 0`);
1728
- if (!nonNegative(j.seconds)) problems.push(`${label} seconds must be a finite number >= 0`);
1729
- if (j.bears !== false && ids.has(j.a) && ids.has(j.b) && j.a !== j.b) edges.push([j.a, j.b]);
1730
- }
1731
- const structural = parts2.filter((p) => p?.structure && p.structure.role !== "none");
1732
- if (structural.length && spec.joints) {
1733
- const anchored = parts2.filter((p) => p.anchored || p.structure?.role === "foundation").map((p) => p.id);
1734
- const adj = /* @__PURE__ */ new Map();
1735
- for (const [a, b] of edges) {
1736
- adj.set(a, [...adj.get(a) ?? [], b]);
1737
- adj.set(b, [...adj.get(b) ?? [], a]);
1738
- }
1739
- const seen = new Set(anchored);
1740
- const queue = [...anchored];
1741
- while (queue.length) {
1742
- for (const n of adj.get(queue.pop()) ?? []) {
1743
- if (seen.has(n)) continue;
1744
- seen.add(n);
1745
- queue.push(n);
1746
- }
1747
- }
1748
- const lost = structural.filter((p) => !seen.has(p.id)).map((p) => p.id);
1749
- if (lost.length) warnings.push(`structural part(s) ${lost.map((i) => `"${i}"`).join(", ")} cannot reach an anchored part, so they will fall`);
1750
- }
1751
- return { ok: problems.length === 0, problems, warnings };
1752
- };
1753
- var DEFAULT_IGNITION_RULES = {
1754
- fillCurve: [
1755
- [0, 0.6],
1756
- [0.1, 1],
1757
- [0.35, 0.6],
1758
- [0.65, 0.3],
1759
- [0.9, 0.15],
1760
- [1, 0.12]
1761
- ],
1762
- flameFillInfluence: 0.5,
1763
- flameDefaults: { incendiary: 0.7, tracer: 0.2 },
1764
- sparkTarget: { steel: 1, iron: 1, aluminium: 0.25 },
1765
- sparkMetalDefault: 0.5,
1766
- sparkFluid: { diesel: 0.15 },
1767
- fireNear: { radius: 1.5, chancePerSecond: 0.5 }
1768
- };
1769
- var resolveIgnitionRules = (rules) => ({
1770
- ...DEFAULT_IGNITION_RULES,
1771
- ...rules,
1772
- flameDefaults: { ...DEFAULT_IGNITION_RULES.flameDefaults, ...rules?.flameDefaults },
1773
- sparkTarget: { ...DEFAULT_IGNITION_RULES.sparkTarget, ...rules?.sparkTarget },
1774
- sparkFluid: { ...DEFAULT_IGNITION_RULES.sparkFluid, ...rules?.sparkFluid },
1775
- fireNear: { ...DEFAULT_IGNITION_RULES.fireNear, ...rules?.fireNear }
1776
- });
1777
- var fillFactor = (fill2, curve = DEFAULT_IGNITION_RULES.fillCurve) => {
1778
- if (curve.length === 0) return 1;
1779
- const f = Math.min(1, Math.max(0, fill2));
1780
- if (f <= curve[0][0]) return curve[0][1];
1781
- for (let i = 1; i < curve.length; i++) {
1782
- const [x1, y1] = curve[i];
1783
- const [x0, y0] = curve[i - 1];
1784
- if (f <= x1) return x1 === x0 ? y1 : y0 + (y1 - y0) * (f - x0) / (x1 - x0);
1785
- }
1786
- return curve[curve.length - 1][1];
1787
- };
1788
- var sparkTargetFactor = (materialId, metal, rules = DEFAULT_IGNITION_RULES) => !metal ? 0 : rules.sparkTarget[materialId] ?? rules.sparkMetalDefault;
1789
- var ignitionChance = (hit, target, rules = DEFAULT_IGNITION_RULES) => {
1790
- const k = fillFactor(target.fill, rules.fillCurve);
1791
- const spark = (hit.ignition?.spark ?? 0) * target.sparkTarget * (target.fluid === void 0 ? 1 : rules.sparkFluid[target.fluid] ?? 1) * k;
1792
- const flameBase = hit.ignition?.flame ?? Math.max(hit.incendiary ? rules.flameDefaults.incendiary : 0, hit.tracer ? rules.flameDefaults.tracer : 0);
1793
- const flame = flameBase * (1 - rules.flameFillInfluence * (1 - k));
1794
- return 1 - (1 - Math.min(1, Math.max(0, spark))) * (1 - Math.min(1, Math.max(0, flame)));
1795
- };
1796
- var sealBlock = (seal, state) => {
1797
- if (seal.spoilsWhenBreached && state.breached) return "breached";
1798
- if (seal.spoilsWhenBreached && state.leaked) return "leaked";
1799
- if (!state.opened) return "sealed";
1800
- return void 0;
1801
- };
1802
- var DEFERRED_QUEUE_ID = {
1803
- DESTRUCTION_EVENTS: "destruction.events",
1804
- BREACH_PAINT: "floorplan.breach-paint",
1805
- BREACH_CUT: "floorplan.breach-cut",
1806
- AUDIO_VOICES: "audio.voices",
1807
- VEHICLE_CREASE: "vehicles.crease",
1808
- AUDIO_OCCLUSION: "audio.occlusion",
1809
- FLUID_FILM: "fluids.film",
1810
- VEHICLE_LOD_BATCH: "vehicles.lod-batch",
1811
- SETTLED_BATCH: "destruction.settled-batch",
1812
- STATIC_BATCH: "render.static-batch",
1813
- ANIMALS_STATIC_BATCH: "animals.static-batch",
1814
- CHARACTERS_STATIC_BATCH: "characters.static-batch",
1815
- HOUSE_SHADOW_BATCH: "floorplan.shadow-batch",
1816
- DESTRUCTION_PREFIT: "destruction.prefit"
1817
- };
1818
- var DEFERRED_PRIORITY = {
1819
- [DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS]: { priority: 300, phase: "present" },
1820
- // every frame: the walls cut since the last frame are painted once each, and a hole must show in the frame of the blast
1821
- [DEFERRED_QUEUE_ID.BREACH_CUT]: { priority: 260, phase: "present", minEveryFrames: 1 },
1822
- [DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present", minEveryFrames: 1 },
1823
- [DEFERRED_QUEUE_ID.AUDIO_VOICES]: { priority: 200, phase: "idle", reserveMs: 1 },
1824
- [DEFERRED_QUEUE_ID.AUDIO_OCCLUSION]: { priority: 190, phase: "idle", minEveryFrames: 8 },
1825
- [DEFERRED_QUEUE_ID.FLUID_FILM]: { priority: 120, phase: "idle", minEveryFrames: 2 },
1826
- [DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" },
1827
- [DEFERRED_QUEUE_ID.VEHICLE_LOD_BATCH]: { priority: 90, phase: "idle", minEveryFrames: 4 },
1828
- [DEFERRED_QUEUE_ID.SETTLED_BATCH]: { priority: 70, phase: "idle", minEveryFrames: 8 },
1829
- [DEFERRED_QUEUE_ID.STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
1830
- [DEFERRED_QUEUE_ID.ANIMALS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
1831
- [DEFERRED_QUEUE_ID.CHARACTERS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
1832
- [DEFERRED_QUEUE_ID.HOUSE_SHADOW_BATCH]: { priority: 50, phase: "idle", minEveryFrames: 8 },
1833
- [DEFERRED_QUEUE_ID.DESTRUCTION_PREFIT]: { priority: 40, phase: "idle", minEveryFrames: 30 }
1834
- };
1835
- var MUST_DRAIN_QUEUE_IDS = /* @__PURE__ */ new Set([DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS, DEFERRED_QUEUE_ID.BREACH_CUT]);
1836
- function drainDetached(queue, budgetMs, clock = () => performance.now()) {
1837
- return queue.run(clock() + budgetMs, clock);
1838
- }
1839
- var WARNED_KEY = /* @__PURE__ */ Symbol.for("@adatechnology/game-contracts.warned");
1840
- var warnedKeys = () => {
1841
- const holder = globalThis;
1842
- return holder[WARNED_KEY] ?? (holder[WARNED_KEY] = /* @__PURE__ */ new Set());
1843
- };
1844
- var isProduction = () => {
1845
- try {
1846
- return process.env.NODE_ENV === "production";
1847
- } catch {
1848
- return false;
1849
- }
1850
- };
1851
- var isQuiet = () => globalThis.__GAME_KIT_QUIET__ === true;
1852
- var warnOnce = (key2, message) => {
1853
- if (isQuiet() || isProduction()) return;
1854
- const seen = warnedKeys();
1855
- if (seen.has(key2)) return;
1856
- seen.add(key2);
1857
- console.warn(`[game-kit] ${message}`);
1858
- };
1859
- var UNSAFE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
1860
- var isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) && Object.getPrototypeOf(value) === Object.prototype;
1861
- var deepMerge = (base2, patch) => {
1862
- if (!patch) return base2;
1863
- const result = { ...base2 };
1864
- for (const [key2, value] of Object.entries(patch)) {
1865
- if (value === void 0 || UNSAFE_KEYS.has(key2)) continue;
1866
- const current = result[key2];
1867
- result[key2] = isPlainObject(current) && isPlainObject(value) ? deepMerge(current, value) : value;
1868
- }
1869
- return result;
1870
- };
1871
- var mergeById = (shipped, extra) => {
1872
- const entries = /* @__PURE__ */ new Map();
1873
- for (const entry2 of [...shipped, ...extra ?? []]) entries.set(entry2.id, entry2);
1874
- return entries;
1875
- };
1876
- var applyPatches = (entries, patches) => {
1877
- for (const [id, patch] of Object.entries(patches ?? {})) {
1878
- const entry2 = entries.get(id);
1879
- if (entry2) entries.set(id, deepMerge(entry2, patch));
1880
- else warnOnce(`registry.patch.${id}`, `patch for "${id}" ignored: no entry has that id`);
1881
- }
1882
- };
1883
- var removeIds = (entries, ids) => {
1884
- for (const id of ids ?? []) {
1885
- if (!entries.delete(id)) warnOnce(`registry.remove.${id}`, `remove of "${id}" ignored: no entry has that id`);
1886
- }
1887
- };
1888
- var defineCategories = (defs, options = {}) => {
1889
- const problems = [];
1890
- const duplicates = (list2) => {
1891
- const ids = /* @__PURE__ */ new Set();
1892
- for (const def of list2) {
1893
- if (ids.has(def.id)) problems.push(`duplicate category "${def.id}"`);
1894
- ids.add(def.id);
1895
- }
1896
- };
1897
- duplicates(defs);
1898
- duplicates(options.extra ?? []);
1899
- const entries = mergeById(defs, options.extra);
1900
- applyPatches(entries, options.patches);
1901
- removeIds(entries, options.remove);
1902
- const chain = (id) => {
1903
- const path = [];
1904
- let current = id;
1905
- while (current !== void 0) {
1906
- const def = entries.get(current);
1907
- if (!def) throw new Error(path.length === 0 ? `unknown category "${current}"` : `category "${path[0]}" has unknown parent "${current}"`);
1908
- if (path.includes(current)) throw new Error(`category cycle: ${[...path, current].reverse().join(" -> ")}`);
1909
- path.push(current);
1910
- current = def.extends;
1911
- }
1912
- return path.reverse();
1913
- };
1914
- const registry = {
1915
- get: (id) => entries.get(id),
1916
- has: (id) => entries.has(id),
1917
- ids: () => [...entries.keys()],
1918
- chain,
1919
- defaults: (id) => chain(id).reduce((acc, ancestor) => deepMerge(acc, entries.get(ancestor)?.defaults), {}),
1920
- requires: (id) => {
1921
- const out = [];
1922
- for (const ancestor of chain(id)) for (const contract of entries.get(ancestor)?.requires ?? []) if (!out.includes(contract)) out.push(contract);
1923
- return out;
1924
- },
1925
- isA: (id, ancestorId) => {
1926
- try {
1927
- return chain(id).includes(ancestorId);
1928
- } catch {
1929
- return false;
1930
- }
1931
- },
1932
- check: () => {
1933
- const found = [...problems];
1934
- for (const [id, def] of entries) {
1935
- if (def.extends !== void 0 && !entries.has(def.extends)) found.push(`category "${id}" extends unknown "${def.extends}"`);
1936
- else {
1937
- try {
1938
- chain(id);
1939
- } catch (error) {
1940
- const message = error.message;
1941
- if (message.startsWith("category cycle") && !found.includes(message)) found.push(message);
1942
- }
1943
- }
1944
- }
1945
- return found;
1946
- }
1947
- };
1948
- return registry;
1949
- };
1950
- var resolveEntry = (registry, entry2, kindField = "kind") => deepMerge(registry.defaults(String(entry2[kindField])), entry2);
1951
- var KIT_ORIGIN_KEY = "kitOrigin";
1952
- function markKitOrigin(object2, origin) {
1953
- const node = object2;
1954
- node.userData = node.userData ?? {};
1955
- node.userData[KIT_ORIGIN_KEY] = { ...origin };
1956
- return object2;
1957
- }
1958
- var SURFACE_IDS = ["concrete", "asphalt", "wood", "tile", "dirt", "grass", "gravel", "sand", "metal", "water", "glass", "carpet"];
1959
- var GAIT_IDS = ["walk", "run"];
1960
- var LANDING_IDS = ["light", "heavy"];
1961
- var BODY_SOUND_IDS = [
1962
- "jump",
1963
- "cloth_rustle",
1964
- "body_fall",
1965
- "fall_damage",
1966
- "player_hurt",
1967
- "player_breath_run",
1968
- "player_death",
1969
- "bite",
1970
- "grab",
1971
- "punch_swing",
1972
- "punch_hit_body",
1973
- "punch_hit_face",
1974
- "punch_hit_object",
1975
- "kick_swing",
1976
- "kick_hit",
1977
- "kick_hit_object",
1978
- "shove_two_hands",
1979
- "knife_swing",
1980
- "knife_stab",
1981
- "knife_slash",
1982
- "knife_hit_object",
1983
- "blunt_swing",
1984
- "blunt_hit",
1985
- "blunt_hit_object",
1986
- "axe_swing",
1987
- "axe_chop",
1988
- "axe_hit_object"
1989
- ];
1990
- var footstepSoundId = (surface, gait) => `footstep_${surface}_${gait}`;
1991
- var FOOTSTEP_SOUND_IDS = SURFACE_IDS.flatMap((surface) => GAIT_IDS.map((gait) => footstepSoundId(surface, gait)));
1992
- var LAND_SOUND_IDS = SURFACE_IDS.flatMap((surface) => LANDING_IDS.map((landing) => `land_${surface}_${landing}`));
1993
- var BODY_FOLEY_IDS = [...FOOTSTEP_SOUND_IDS, ...LAND_SOUND_IDS, ...BODY_SOUND_IDS];
1994
- var WORKER_KIND_ID = {
1995
- GROUND_TILES: "destruction.ground-tiles",
1996
- CROWD_PHYSICS: "crowd.physics",
1997
- PIECE_BOXES: "destruction.piece-boxes",
1998
- STATIC_COLLIDERS: "destruction.static-colliders",
1999
- SHAPES_GENERATE: "shapes.generate",
2000
- WORLD_REGION: "world.region",
2001
- VEHICLE_HULL_PLAN: "vehicles.hull-plan"
2002
- };
2003
- var WORKER_KIND_DEFAULTS = {
2004
- [WORKER_KIND_ID.GROUND_TILES]: { lane: "sim", priority: 300, latencyFrames: 2, late: "sync" },
2005
- [WORKER_KIND_ID.CROWD_PHYSICS]: { lane: "sim", priority: 250, latencyFrames: 1, late: "sync" },
2006
- [WORKER_KIND_ID.PIECE_BOXES]: { lane: "sim", priority: 200, latencyFrames: 2, late: "sync" },
2007
- [WORKER_KIND_ID.STATIC_COLLIDERS]: { lane: "build", priority: 150, late: "sync" },
2008
- [WORKER_KIND_ID.SHAPES_GENERATE]: { lane: "build", priority: 100, late: "sync" },
2009
- [WORKER_KIND_ID.WORLD_REGION]: { lane: "background", priority: 10, latencyFrames: 10, late: "drop" },
2010
- [WORKER_KIND_ID.VEHICLE_HULL_PLAN]: { lane: "build", priority: 120, late: "keep-waiting" }
2011
- };
2012
-
2013
2019
  // ../game-shapes/dist/index.js
2014
2020
  var SAME_COLOUR = 1 / 512;
2015
2021
  var SAME_FACING = 1 - 1e-6;
@@ -2200,13 +2206,16 @@ var GameItemsThree = (() => {
2200
2206
  for (const u of Object.values(uniforms)) if (isTexture(u?.value)) out.add(u.value);
2201
2207
  }
2202
2208
  }
2209
+ var isInstanced = (o) => o.isInstancedMesh === true;
2203
2210
  function collect(roots) {
2204
2211
  const geometries = /* @__PURE__ */ new Set();
2205
2212
  const materials = /* @__PURE__ */ new Set();
2206
2213
  const textures = /* @__PURE__ */ new Set();
2207
2214
  const skeletons = /* @__PURE__ */ new Set();
2215
+ const instanced = /* @__PURE__ */ new Set();
2208
2216
  for (const root of roots) {
2209
2217
  root.traverse((object2) => {
2218
+ if (isInstanced(object2)) instanced.add(object2);
2210
2219
  const o = object2;
2211
2220
  if (o.geometry && typeof o.geometry.dispose === "function") geometries.add(o.geometry);
2212
2221
  if (o.skeleton && typeof o.skeleton.dispose === "function") skeletons.add(o.skeleton);
@@ -2218,7 +2227,7 @@ var GameItemsThree = (() => {
2218
2227
  }
2219
2228
  });
2220
2229
  }
2221
- return { geometries, materials, textures, skeletons };
2230
+ return { geometries, materials, textures, skeletons, instanced };
2222
2231
  }
2223
2232
  var marked = /* @__PURE__ */ new WeakSet();
2224
2233
  function markShared(...resources) {
@@ -2267,6 +2276,7 @@ var GameItemsThree = (() => {
2267
2276
  report.textures++;
2268
2277
  }
2269
2278
  for (const s of found.skeletons) s.dispose();
2279
+ for (const mesh2 of found.instanced) mesh2.dispose();
2270
2280
  return report;
2271
2281
  }
2272
2282
  function discardObject3D(objects, options = {}) {
@@ -2323,6 +2333,10 @@ var GameItemsThree = (() => {
2323
2333
  return object2;
2324
2334
  };
2325
2335
  return {
2336
+ carryHandle: (part) => {
2337
+ part.userData[CARRY_HANDLE_TAG] = true;
2338
+ return part;
2339
+ },
2326
2340
  T: T2,
2327
2341
  materials,
2328
2342
  M,
@@ -2352,7 +2366,7 @@ var GameItemsThree = (() => {
2352
2366
  }
2353
2367
 
2354
2368
  // src/wear.ts
2355
- var WEAR_TARGET = { food: 6122286, metal: 8011293, wood: 4141862, cloth: 4866099, plastic: 7038294, paper: 9075282, glass: 5591098 };
2369
+ var WEAR_TARGET = { food: 6122286, metal: 8011293, wood: 4141862, cloth: 4866099, plastic: 7038294, paper: 9075282, glass: 5591098, rubber: 4860452 };
2356
2370
  var WEAR_AMOUNT = [0, 0.3, 0.62];
2357
2371
  var hexToRgb = (hex3) => [(hex3 >> 16 & 255) / 255, (hex3 >> 8 & 255) / 255, (hex3 & 255) / 255];
2358
2372
  var dataOf = (material) => {
@@ -2415,8 +2429,8 @@ var GameItemsThree = (() => {
2415
2429
  ];
2416
2430
  var DEFAULT_COLOR = 9080724;
2417
2431
  var PI = Math.PI;
2418
- function shade(color2, factor) {
2419
- const channel = (shift) => Math.max(0, Math.min(255, Math.round((color2 >> shift & 255) * factor)));
2432
+ function shade(color2, factor2) {
2433
+ const channel = (shift) => Math.max(0, Math.min(255, Math.round((color2 >> shift & 255) * factor2)));
2420
2434
  return channel(16) << 16 | channel(8) << 8 | channel(0);
2421
2435
  }
2422
2436
  var PROUD = 2e-3;
@@ -2485,9 +2499,11 @@ var GameItemsThree = (() => {
2485
2499
  const { k, w, h, d } = c;
2486
2500
  return k.G(k.mesh(k.cyl(0.5, 0.35, h, seg(c, 16)), k.plastic(c.color), [0, 0, 0], [0, 0, 0], [w, 1, d]));
2487
2501
  };
2502
+ var CUP_FLOOR_SHARE = 0.06;
2488
2503
  var cup = (c) => {
2489
2504
  const { k, w, h, d } = c;
2490
- const profile = [[0, -h / 2], [0.38, -h / 2], [0.5, h / 2], [0.44, h / 2], [0.33, -h / 2 + h * 0.06], [0, -h / 2 + h * 0.06]];
2505
+ const floor = -h / 2 + h * CUP_FLOOR_SHARE;
2506
+ const profile = [[0, -h / 2], [0.38, -h / 2], [0.5, h / 2], [0.44, h / 2], [0.33, floor], [0, floor]];
2491
2507
  return k.G(k.mesh(k.lathe(profile, seg(c, 14)), k.plastic(c.color), [0, 0, 0], [0, 0, 0], [w, 1, d]));
2492
2508
  };
2493
2509
  var tube = (c) => {
@@ -3607,6 +3623,7 @@ var GameItemsThree = (() => {
3607
3623
  paper: "paper",
3608
3624
  plastic: "plastic",
3609
3625
  cloth: "fabric",
3626
+ rubber: "rubber",
3610
3627
  food: "flesh_fruit"
3611
3628
  };
3612
3629
  var FAMILIES = destruction_default.families;
@@ -3642,6 +3659,16 @@ var GameItemsThree = (() => {
3642
3659
  };
3643
3660
  return { container, liquid: contents.liquid, liters };
3644
3661
  }
3662
+ var VESSEL_FLOORS = { cup: CUP_FLOOR_SHARE };
3663
+ function itemVessel(subject) {
3664
+ const capacity = subject.capacityLiters;
3665
+ const floor = subject.shape === void 0 ? void 0 : VESSEL_FLOORS[subject.shape];
3666
+ if (capacity === void 0 || !(capacity > 0) || floor === void 0) return void 0;
3667
+ const [width, height, depth] = subject.size;
3668
+ const radius = Math.min(width, depth) / 2 * WALL_SHARE;
3669
+ const container = { capacity, liters: 0, shape: { kind: "cylinder", radius, height: height * WALL_SHARE }, opening: radius, closed: false };
3670
+ return { container, offset: [0, height * floor, 0] };
3671
+ }
3645
3672
  function tagOf(mesh2) {
3646
3673
  const material = Array.isArray(mesh2.material) ? mesh2.material[0] : mesh2.material;
3647
3674
  const tag = material?.userData?.tag;
@@ -3735,6 +3762,7 @@ var GameItemsThree = (() => {
3735
3762
  return;
3736
3763
  }
3737
3764
  const rule = modelId !== void 0 ? itemDestruction(modelId) : shapeId !== void 0 ? shapeDestruction(shapeId) : void 0;
3765
+ const body = options.parts?.length === 1 ? options.parts[0] : void 0;
3738
3766
  if (rule?.tessellate) tessellateShapes(root, rule.tessellate, three);
3739
3767
  const solid = [];
3740
3768
  root.traverse((object2) => {
@@ -3748,6 +3776,10 @@ var GameItemsThree = (() => {
3748
3776
  mesh2.userData.destructionSkin = true;
3749
3777
  return;
3750
3778
  }
3779
+ if (body) {
3780
+ mesh2.userData.destructionMaterial = body.material;
3781
+ if (body.thickness !== void 0) mesh2.userData.destructionThickness = body.thickness;
3782
+ }
3751
3783
  if (rule?.hollow) mesh2.userData.hollow = true;
3752
3784
  if (powder) mesh2.userData.destructionPowder = { color: powder.color };
3753
3785
  solid.push(mesh2);
@@ -6253,6 +6285,16 @@ var GameItemsThree = (() => {
6253
6285
  0.553
6254
6286
  ],
6255
6287
  scale: 0.092308
6288
+ },
6289
+ {
6290
+ id: "plunger",
6291
+ teamId: "desentupidor",
6292
+ teamBox: [
6293
+ 1.4,
6294
+ 5.5,
6295
+ 1.4
6296
+ ],
6297
+ scale: 0.1
6256
6298
  }
6257
6299
  ];
6258
6300
 
@@ -7434,6 +7476,16 @@ var GameItemsThree = (() => {
7434
7476
  return G(bottle2, label, stripe, cap, nozzle);
7435
7477
  };
7436
7478
 
7479
+ // src/models/plunger.ts
7480
+ var plunger = ({ mesh: mesh2, cyl, G, M, wood }) => {
7481
+ const rubber = M(11545120, "rubber", { roughness: 0.75 });
7482
+ const cup2 = mesh2(cyl(0.3, 0.7, 0.75, 16), rubber, [0, 0.455, 0]);
7483
+ const lip = mesh2(cyl(0.7, 0.7, 0.08, 16), M(9314841, "rubber", { roughness: 0.8 }), [0, 0.04, 0]);
7484
+ const neck = mesh2(cyl(0.2, 0.3, 0.3, 12), rubber, [0, 0.98, 0]);
7485
+ const handle = mesh2(cyl(0.15, 0.15, 4.4, 10), wood(10122312), [0, 3.3, 0]);
7486
+ return G(cup2, lip, neck, handle);
7487
+ };
7488
+
7437
7489
  // src/models/can-opener.ts
7438
7490
  var canOpener = ({ mesh: mesh2, bx, cyl, G, metal, plastic }) => {
7439
7491
  const steel = metal(11120050);
@@ -7485,7 +7537,7 @@ var GameItemsThree = (() => {
7485
7537
  };
7486
7538
 
7487
7539
  // src/models/bucket.ts
7488
- var bucket = ({ mesh: mesh2, bx, cyl, G, plastic, metal }) => {
7540
+ var bucket = ({ mesh: mesh2, bx, cyl, G, plastic, metal, carryHandle }) => {
7489
7541
  const body = plastic(2908062);
7490
7542
  const wire = metal(9080209);
7491
7543
  return G(
@@ -7494,7 +7546,7 @@ var GameItemsThree = (() => {
7494
7546
  mesh2(cyl(11.8, 11.8, 1, 16), plastic(2313602), [0, -13, 0]),
7495
7547
  mesh2(bx(0.6, 3.7, 0.6), wire, [13, 11.35, 0]),
7496
7548
  mesh2(bx(0.6, 3.7, 0.6), wire, [-13, 11.35, 0]),
7497
- mesh2(bx(27.2, 0.5, 1.1), wire, [0, 13.25, 0])
7549
+ carryHandle(mesh2(bx(27.2, 0.5, 1.1), wire, [0, 13.25, 0]))
7498
7550
  );
7499
7551
  };
7500
7552
 
@@ -10110,7 +10162,8 @@ var GameItemsThree = (() => {
10110
10162
  tshirt,
10111
10163
  watering_can: wateringCan,
10112
10164
  wheelbarrow,
10113
- windup_alarm_clock: windupAlarmClock
10165
+ windup_alarm_clock: windupAlarmClock,
10166
+ plunger
10114
10167
  };
10115
10168
  var SHIPPED_MODELS = models_default.map((entry2) => {
10116
10169
  const builder = BUILDERS[entry2.id];
@@ -10175,11 +10228,158 @@ var GameItemsThree = (() => {
10175
10228
  const materials = kit.materials.slice(first);
10176
10229
  if (options.wear) setWear(materials, options.wear);
10177
10230
  root.userData.wear = options.wear ?? 0;
10178
- if (options.destructible) tagForDestruction(root, { ...kind === "model" && item.model !== void 0 ? { modelId: item.model } : {}, ...shape === void 0 ? {} : { shapeId: shape }, ...item.weight === void 0 ? {} : { weight: item.weight }, size: item.size, ...item.powder ? { powder: item.powder } : {}, three: T2 });
10231
+ if (options.destructible) tagForDestruction(root, { ...kind === "model" && item.model !== void 0 ? { modelId: item.model } : {}, ...shape === void 0 ? {} : { shapeId: shape }, ...item.weight === void 0 ? {} : { weight: item.weight }, size: item.size, ...item.powder ? { powder: item.powder } : {}, ...item.parts ? { parts: item.parts } : {}, three: T2 });
10179
10232
  markKitOrigin(root, { owner: "game-items-three", kind: "item", id: item.id, ...kind === "shape" ? { standIn: true } : {} });
10180
10233
  return { root, kind, ...shape ? { shape } : {}, size: item.size, materials };
10181
10234
  }
10182
10235
 
10236
+ // src/wash.ts
10237
+ var WASH_NAME = "item_wash";
10238
+ var STAIN_LIFT = 15e-4;
10239
+ var SPOTS = [
10240
+ [0, 0],
10241
+ [0.5, 0],
10242
+ [0.155, 0.476],
10243
+ [-0.405, 0.294],
10244
+ [-0.405, -0.294],
10245
+ [0.155, -0.476]
10246
+ ];
10247
+ var STAIN_RADIUS = 0.12;
10248
+ var BUBBLE_RADIUS = 0.1;
10249
+ var BUBBLE_CLUSTER = [
10250
+ [0, 0, 1],
10251
+ [1.1, 0.3, 0.7],
10252
+ [-0.6, 0.9, 0.6]
10253
+ ];
10254
+ var STAIN_COLORS = [8014370, 10903070, 6175260, 12088362, 9067050, 10243866];
10255
+ var FOAM_COLOR = 16054008;
10256
+ var overlays = /* @__PURE__ */ new WeakMap();
10257
+ var isOwnMesh = (mesh2) => !mesh2.userData.destructionDebris && mesh2.parent?.name !== WASH_NAME;
10258
+ function localBox2(T2, root) {
10259
+ root.updateMatrixWorld(true);
10260
+ const toRoot = new T2.Matrix4().copy(root.matrixWorld).invert();
10261
+ const box4 = new T2.Box3();
10262
+ const part = new T2.Box3();
10263
+ const m = new T2.Matrix4();
10264
+ root.traverse((o) => {
10265
+ const mesh2 = o;
10266
+ if (!mesh2.isMesh || !isOwnMesh(mesh2)) return;
10267
+ if (!mesh2.geometry.boundingBox) mesh2.geometry.computeBoundingBox();
10268
+ const bounds = mesh2.geometry.boundingBox;
10269
+ if (!bounds) return;
10270
+ part.copy(bounds).applyMatrix4(m.multiplyMatrices(toRoot, mesh2.matrixWorld));
10271
+ box4.union(part);
10272
+ });
10273
+ return box4;
10274
+ }
10275
+ function spotsOn(T2, root, box4) {
10276
+ const meshes = [];
10277
+ root.traverse((o) => {
10278
+ const mesh2 = o;
10279
+ if (mesh2.isMesh && isOwnMesh(mesh2)) meshes.push(mesh2);
10280
+ });
10281
+ const toRoot = new T2.Matrix4().copy(root.matrixWorld).invert();
10282
+ const down2 = new T2.Vector3(0, -1, 0).transformDirection(root.matrixWorld);
10283
+ const ray = new T2.Raycaster();
10284
+ const centre = box4.getCenter(new T2.Vector3());
10285
+ const half = box4.getSize(new T2.Vector3()).multiplyScalar(0.5);
10286
+ const above = box4.max.y + half.y + 0.01;
10287
+ const spots = [];
10288
+ for (const [x, z] of SPOTS) {
10289
+ const origin = new T2.Vector3(centre.x + x * half.x, above, centre.z + z * half.z).applyMatrix4(root.matrixWorld);
10290
+ ray.set(origin, down2);
10291
+ const hit = ray.intersectObjects(meshes, false)[0];
10292
+ if (!hit?.face) continue;
10293
+ const normal = hit.face.normal.clone().transformDirection(hit.object.matrixWorld);
10294
+ if (normal.dot(down2) > 0) normal.negate();
10295
+ const point = hit.point.clone().addScaledVector(normal, STAIN_LIFT).applyMatrix4(toRoot);
10296
+ spots.push({ point, normal: normal.transformDirection(toRoot) });
10297
+ }
10298
+ return spots;
10299
+ }
10300
+ function layerOf(T2, geometry, material, bases, name) {
10301
+ const mesh2 = new T2.InstancedMesh(geometry, material, bases.length);
10302
+ mesh2.name = name;
10303
+ bases.forEach((base2, i) => mesh2.setMatrixAt(i, base2));
10304
+ mesh2.computeBoundingSphere();
10305
+ mesh2.visible = false;
10306
+ mesh2.userData.destructionDebris = true;
10307
+ mesh2.raycast = () => {
10308
+ };
10309
+ return { mesh: mesh2, bases, value: 0 };
10310
+ }
10311
+ function blotGeometry(T2) {
10312
+ const geometry = new T2.CircleGeometry(1, 9);
10313
+ const position = geometry.getAttribute("position");
10314
+ for (let i = 1; i < position.count; i++) {
10315
+ const wobble = 0.75 + 0.25 * Math.abs(Math.sin(i * 2.3));
10316
+ position.setXY(i, position.getX(i) * wobble, position.getY(i) * wobble);
10317
+ }
10318
+ return geometry.rotateX(-Math.PI / 2);
10319
+ }
10320
+ function createOverlay(T2, root) {
10321
+ const scratch = { matrix: new T2.Matrix4(), scale: new T2.Matrix4() };
10322
+ const box4 = localBox2(T2, root);
10323
+ const spots = box4.isEmpty() ? [] : spotsOn(T2, root, box4);
10324
+ if (spots.length === 0) return { dirt: void 0, foam: void 0, scratch };
10325
+ const size = box4.getSize(new T2.Vector3());
10326
+ const small = Math.min(size.x, size.z) / 2;
10327
+ const up = new T2.Vector3(0, 1, 0);
10328
+ const turn = (normal, spin) => new T2.Quaternion().setFromUnitVectors(up, normal).multiply(new T2.Quaternion().setFromAxisAngle(up, spin));
10329
+ const stains = spots.map((spot, i) => {
10330
+ const r = small * STAIN_RADIUS;
10331
+ return new T2.Matrix4().compose(spot.point, turn(spot.normal, i * 1.7), new T2.Vector3(r, 1, r * (0.65 + 0.35 * (i * 0.37 % 1))));
10332
+ });
10333
+ const bubbleRadius = small * BUBBLE_RADIUS;
10334
+ const bubbles = spots.flatMap((spot, i) => {
10335
+ const q = turn(spot.normal, i * 1.1);
10336
+ return BUBBLE_CLUSTER.map(([along2, across2, share]) => {
10337
+ const r = bubbleRadius * share;
10338
+ const at2 = new T2.Vector3(along2 * bubbleRadius, r * 0.4 - STAIN_LIFT, across2 * bubbleRadius).applyQuaternion(q).add(spot.point);
10339
+ return new T2.Matrix4().compose(at2, q, new T2.Vector3(r, r, r));
10340
+ });
10341
+ });
10342
+ const group = new T2.Group();
10343
+ group.name = WASH_NAME;
10344
+ group.userData.destructionIgnore = true;
10345
+ const dirt = layerOf(T2, blotGeometry(T2), new T2.MeshStandardMaterial({ roughness: 0.95, metalness: 0 }), stains, "item_dirt");
10346
+ stains.forEach((_, i) => dirt.mesh.setColorAt(i, new T2.Color(STAIN_COLORS[i % STAIN_COLORS.length])));
10347
+ const foam = layerOf(T2, new T2.SphereGeometry(1, 8, 6), new T2.MeshStandardMaterial({ color: FOAM_COLOR, roughness: 0.55, metalness: 0 }), bubbles, "item_foam");
10348
+ group.add(dirt.mesh, foam.mesh);
10349
+ root.add(group);
10350
+ return { dirt, foam, scratch };
10351
+ }
10352
+ function overlayOf(T2, root) {
10353
+ const found = overlays.get(root);
10354
+ if (found) return found;
10355
+ const created = createOverlay(T2, root);
10356
+ overlays.set(root, created);
10357
+ return created;
10358
+ }
10359
+ function showLayer(layer, value, scratch) {
10360
+ if (!layer) return;
10361
+ const share = Math.max(0, Math.min(1, value));
10362
+ if (share === layer.value) return;
10363
+ layer.value = share;
10364
+ layer.mesh.visible = share > 0;
10365
+ if (share === 0) return;
10366
+ const grow = 0.45 + 0.55 * share;
10367
+ scratch.scale.makeScale(grow, grow, grow);
10368
+ layer.bases.forEach((base2, i) => {
10369
+ scratch.matrix.copy(base2).multiply(scratch.scale);
10370
+ layer.mesh.setMatrixAt(i, scratch.matrix);
10371
+ });
10372
+ layer.mesh.instanceMatrix.needsUpdate = true;
10373
+ }
10374
+ function setItemDirt(T2, root, dirt) {
10375
+ const overlay = overlayOf(T2, root);
10376
+ showLayer(overlay.dirt, dirt, overlay.scratch);
10377
+ }
10378
+ function setItemFoam(T2, root, amount) {
10379
+ const overlay = overlayOf(T2, root);
10380
+ showLayer(overlay.foam, amount, overlay.scratch);
10381
+ }
10382
+
10183
10383
  // src/contained.ts
10184
10384
  function createContainedItemModel(items, options = {}) {
10185
10385
  const byId = /* @__PURE__ */ new Map();
@@ -10189,6 +10389,8 @@ var GameItemsThree = (() => {
10189
10389
  if (!item) return null;
10190
10390
  const model = buildItem(T2, item, options);
10191
10391
  model.root.userData.item = { id: item.id, kind: model.kind };
10392
+ const dirt = stack.data?.["dirt"];
10393
+ if (typeof dirt === "number" && dirt > 0) setItemDirt(T2, model.root, dirt);
10192
10394
  return model.root;
10193
10395
  };
10194
10396
  }
@@ -12676,63 +12878,6 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
12676
12878
  }
12677
12879
 
12678
12880
  // ../game-destruction/dist/index.js
12679
- var AIR_DENSITY = 1.2;
12680
- var DRAG_AREA_FACTOR = 1.5;
12681
- var STEEL_DENSITY = 7850;
12682
- var FRAGMENT_MIN_SPEED = 30;
12683
- var GLASS_STIFFENING = 2.5;
12684
- var PLATE_COEFFICIENT = 0.2874;
12685
- var BEAM_COEFFICIENT = 0.75;
12686
- var TNT_PER_JOULE = DEFAULT_BLAST_IMPULSE.tntPerJoule;
12687
- function projectedArea(shape, toward) {
12688
- const [dx, dy, dz] = [Math.abs(toward[0]), Math.abs(toward[1]), Math.abs(toward[2])];
12689
- if (shape.kind === "box") return dx * shape.size[1] * shape.size[2] + dy * shape.size[0] * shape.size[2] + dz * shape.size[0] * shape.size[1];
12690
- if (shape.kind === "cylinder") return Math.PI * shape.radius ** 2 * dy + 2 * shape.radius * shape.height * Math.sqrt(Math.max(0, 1 - dy * dy));
12691
- return Math.PI * shape.radius ** 2;
12692
- }
12693
- function failureWork(input) {
12694
- const ratio = input.thickness / Math.max(input.span, input.thickness);
12695
- const stiffening = input.isGlass ? GLASS_STIFFENING : 1;
12696
- const pressure = stiffening * input.failureMPa * 1e6 * ratio * ratio / (input.isBeam ? BEAM_COEFFICIENT : PLATE_COEFFICIENT);
12697
- const deflection = input.thickness * (1 + 25 * input.ductility * input.ductility);
12698
- return { pressure, work: (0.5 + 0.5 * input.ductility) * pressure * input.loaded * deflection };
12699
- }
12700
- function casingFlight(casing) {
12701
- const k = casing.geometry === "cylinder" ? 0.5 : 0.6;
12702
- return {
12703
- mottScale: casing.mass / (2 * Math.max(1, casing.fragments)),
12704
- speed: casing.gurneyVelocity / Math.sqrt(casing.mass / Math.max(casing.chargeMass, 1e-6) + k)
12705
- };
12706
- }
12707
- function mottMass(u, scale, fragments) {
12708
- const lowest = 1 / Math.max(1, fragments);
12709
- return scale * Math.log(1 / Math.max(u, lowest)) ** 2;
12710
- }
12711
- function fragmentCaliberMm(mass) {
12712
- return 2e3 * Math.cbrt(3 * mass / (4 * Math.PI * STEEL_DENSITY));
12713
- }
12714
- function fragmentDrag(mass) {
12715
- const sphereArea = Math.PI * Math.cbrt(3 * mass / (4 * Math.PI * STEEL_DENSITY)) ** 2;
12716
- return AIR_DENSITY * DRAG_AREA_FACTOR * sphereArea / (2 * mass);
12717
- }
12718
- var BLUNT_FRAGMENT_NOSE = 0.84;
12719
- var NDRC_CONSTANT = 38e-6;
12720
- function concretePerforation(input) {
12721
- const { mass, caliber, speed } = input;
12722
- if (!(mass > 0) || !(caliber > 0) || !(speed > 0)) return { depth: 0, perforation: 0 };
12723
- const g = NDRC_CONSTANT * (input.nose ?? BLUNT_FRAGMENT_NOSE) * mass / (caliber * Math.sqrt(input.compressiveMPa * 1e6)) * (speed / caliber) ** 1.8;
12724
- const relative = g <= 1 ? 2 * Math.sqrt(g) : g + 1;
12725
- const through = relative <= 1.35 ? 3.19 * relative - 0.718 * relative * relative : 1.32 + 1.24 * relative;
12726
- return { depth: relative * caliber, perforation: through * caliber };
12727
- }
12728
- var FIRE_PRIME_C = 300;
12729
- var drawChainDelay = (delay, random) => {
12730
- if (typeof delay === "number") return delay;
12731
- const [min, max] = delay;
12732
- return min + random() * (max - min);
12733
- };
12734
- var chainDelayOf = (spec, trigger) => spec.explodes?.chain?.[trigger];
12735
- var shotDamageFractionOf = (spec) => spec.explodes?.chain?.shotDamageFraction ?? 0;
12736
12881
  var EPS = 1e-9;
12737
12882
  var vec = {
12738
12883
  add: (a, b) => [a[0] + b[0], a[1] + b[1], a[2] + b[2]],
@@ -13014,6 +13159,343 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
13014
13159
  }
13015
13160
  };
13016
13161
  };
13162
+ var planeAxes = (thin) => thin === 1 ? [0, 2] : [thin === 0 ? 2 : 0, 1];
13163
+ var BREACH_GRID_CAP = 4096;
13164
+ var unitGrid = (dims, thin, units, cap) => {
13165
+ const [u, v] = planeAxes(thin);
13166
+ let unitU = Math.min(units.size[0], dims[u]), unitV = Math.min(units.size[1], dims[v]);
13167
+ const rowsFor = (h) => Math.ceil(dims[v] / h - 1e-9);
13168
+ const colsFor = (w) => Math.ceil(dims[u] / w - 1e-9) + (units.bond === "running" ? 1 : 0);
13169
+ const merge = Math.ceil(Math.sqrt(rowsFor(unitV) * colsFor(unitU) / cap));
13170
+ if (merge > 1) {
13171
+ unitU = Math.min(unitU * merge, dims[u]);
13172
+ unitV = Math.min(unitV * merge, dims[v]);
13173
+ }
13174
+ const cells = [];
13175
+ for (let row = 0; row < rowsFor(unitV); row++) {
13176
+ const v0 = -dims[v] / 2 + row * unitV, v1 = Math.min(v0 + unitV, dims[v] / 2);
13177
+ const shift = units.bond === "running" && row % 2 === 1 ? unitU / 2 : 0;
13178
+ for (let col = 0; col < colsFor(unitU); col++) {
13179
+ const u0 = Math.max(-dims[u] / 2 + col * unitU - shift, -dims[u] / 2), u1 = Math.min(-dims[u] / 2 + (col + 1) * unitU - shift, dims[u] / 2);
13180
+ if (u1 - u0 < 0.01) continue;
13181
+ const center = [0, 0, 0], size = [0, 0, 0];
13182
+ center[u] = (u0 + u1) / 2;
13183
+ center[v] = (v0 + v1) / 2;
13184
+ size[u] = u1 - u0;
13185
+ size[v] = v1 - v0;
13186
+ size[thin] = dims[thin];
13187
+ cells.push({ center, size });
13188
+ }
13189
+ }
13190
+ return cells;
13191
+ };
13192
+ var rowsOfGrid = /* @__PURE__ */ new WeakMap();
13193
+ var unitRowsWithin = (cells, thin, point, radius) => {
13194
+ const [u, v] = planeAxes(thin);
13195
+ if (!Number.isFinite(point[u]) || !Number.isFinite(point[v]) || !Number.isFinite(radius)) return [[0, cells.length]];
13196
+ let rows = rowsOfGrid.get(cells);
13197
+ if (!rows) {
13198
+ const found = [];
13199
+ cells.forEach((cell, i) => {
13200
+ const last = found[found.length - 1];
13201
+ if (last && last.center === cell.center[v] && last.size === cell.size[v]) last.to = i + 1;
13202
+ else found.push({ from: i, to: i + 1, center: cell.center[v], size: cell.size[v] });
13203
+ });
13204
+ rowsOfGrid.set(cells, rows = found);
13205
+ }
13206
+ const ranges = [];
13207
+ for (const row of rows) {
13208
+ if (Math.max(0, Math.abs(point[v] - row.center) - row.size / 2) > radius) continue;
13209
+ const last = ranges[ranges.length - 1];
13210
+ if (last && last[1] === row.from) last[1] = row.to;
13211
+ else ranges.push([row.from, row.to]);
13212
+ }
13213
+ return ranges;
13214
+ };
13215
+ var planeDistance = (cell, thin, point) => {
13216
+ const [u, v] = planeAxes(thin);
13217
+ const du = cell.center[u] - point[u], dv = cell.center[v] - point[v];
13218
+ return Math.sqrt(du * du + dv * dv);
13219
+ };
13220
+ var cellsWithin = (cells, thin, point, radius) => {
13221
+ const inside3 = cells.filter((c) => planeDistance(c, thin, point) <= radius);
13222
+ if (inside3.length > 0 || cells.length === 0) return inside3;
13223
+ return [cells.reduce((best, c) => planeDistance(c, thin, point) < planeDistance(best, thin, point) ? c : best)];
13224
+ };
13225
+ var cellsOutside = (cells, thin, point, radius) => cells.filter((c) => planeDistance(c, thin, point) > radius);
13226
+ var MAX_MARKS_PER_FRAGMENT = 12;
13227
+ var marksInBox = (center, size, rotation, holes) => {
13228
+ const inverse = rotation ? quat.conjugate(rotation) : void 0;
13229
+ const marks = [];
13230
+ for (const hole of holes) {
13231
+ const offset = [hole.point[0] - center[0], hole.point[1] - center[1], hole.point[2] - center[2]];
13232
+ const point = inverse ? rotateVec(inverse, offset) : offset;
13233
+ const inside3 = point.every((value, k) => Math.abs(value) <= size[k] / 2 + hole.diameter / 2);
13234
+ if (!inside3) continue;
13235
+ marks.push({ point, normal: inverse ? rotateVec(inverse, hole.normal) : hole.normal, diameter: hole.diameter });
13236
+ if (marks.length >= MAX_MARKS_PER_FRAGMENT) break;
13237
+ }
13238
+ return marks;
13239
+ };
13240
+ var rowLayouts = /* @__PURE__ */ new WeakMap();
13241
+ var rowLayoutOf = (cells, thin, bottom) => {
13242
+ const known = rowLayouts.get(cells);
13243
+ if (known && known.thin === thin && known.bottom === bottom && known.count === cells.length) return known;
13244
+ const [u, v] = planeAxes(thin);
13245
+ const keys = cells.map((cell) => Math.round((cell.center[v] - cell.size[v] / 2 - bottom) * 1e4));
13246
+ const alongOrder = cells.map((_, i) => i).sort((a, b) => cells[a].center[u] - cells[b].center[u]);
13247
+ const layout = { thin, bottom, count: cells.length, keys, alongOrder };
13248
+ rowLayouts.set(cells, layout);
13249
+ return layout;
13250
+ };
13251
+ var holeInBox = (center, size, hole) => {
13252
+ for (let k = 0; k < 3; k++) if (!(Math.abs(hole.point[k] - center[k]) <= size[k] / 2 + hole.diameter / 2)) return false;
13253
+ return true;
13254
+ };
13255
+ var JOINT_GAP = 1e-4;
13256
+ var MIN_BEARING_SHARE = 0.25;
13257
+ var unsupportedCells = (cells, thin, dims, standing, bears) => {
13258
+ if (thin === 1) return unheldSlabCells(cells, dims, standing);
13259
+ const [u, v] = planeAxes(thin);
13260
+ const bottom = -dims[v] / 2;
13261
+ const layout = rowLayoutOf(cells, thin, bottom);
13262
+ const rows = /* @__PURE__ */ new Map();
13263
+ const isStanding = new Uint8Array(cells.length);
13264
+ for (let i = 0; i < cells.length; i++) {
13265
+ if (!standing(i)) continue;
13266
+ isStanding[i] = 1;
13267
+ const key2 = layout.keys[i];
13268
+ if (!rows.has(key2)) rows.set(key2, []);
13269
+ }
13270
+ for (const i of layout.alongOrder) if (isStanding[i] === 1) rows.get(layout.keys[i]).push(i);
13271
+ const rowOf = (y) => Math.round((y - bottom) * 1e4);
13272
+ const held = /* @__PURE__ */ new Set();
13273
+ const queue = [];
13274
+ for (const i of rows.get(0) ?? []) {
13275
+ if (bears && !bears(i)) continue;
13276
+ held.add(i);
13277
+ queue.push(i);
13278
+ }
13279
+ const overlap = (a, b) => Math.min(a.center[u] + a.size[u] / 2, b.center[u] + b.size[u] / 2) - Math.max(a.center[u] - a.size[u] / 2, b.center[u] - b.size[u] / 2);
13280
+ const climb = () => {
13281
+ while (queue.length > 0) {
13282
+ const cell = cells[queue.pop()];
13283
+ for (const j of rows.get(rowOf(cell.center[v] + cell.size[v] / 2)) ?? []) {
13284
+ const other = cells[j];
13285
+ if (held.has(j) || overlap(cell, other) <= Math.max(JOINT_GAP, MIN_BEARING_SHARE * Math.min(cell.size[u], other.size[u]))) continue;
13286
+ held.add(j);
13287
+ queue.push(j);
13288
+ }
13289
+ }
13290
+ };
13291
+ const touching = (a, b) => Math.abs(a.center[u] + a.size[u] / 2 - (b.center[u] - b.size[u] / 2)) <= 1e-3;
13292
+ for (let wedged = true; wedged; ) {
13293
+ climb();
13294
+ wedged = false;
13295
+ for (const row of rows.values()) {
13296
+ for (let k = 1; k < row.length - 1; k++) {
13297
+ const i = row[k];
13298
+ if (held.has(i) || !held.has(row[k - 1]) || !held.has(row[k + 1])) continue;
13299
+ if (!touching(cells[row[k - 1]], cells[i]) || !touching(cells[i], cells[row[k + 1]])) continue;
13300
+ held.add(i);
13301
+ queue.push(i);
13302
+ wedged = true;
13303
+ }
13304
+ }
13305
+ }
13306
+ const loose = [];
13307
+ for (const row of rows.values()) for (const i of row) if (!held.has(i)) loose.push(i);
13308
+ return loose;
13309
+ };
13310
+ var slabGrids = /* @__PURE__ */ new WeakMap();
13311
+ function slabGridOf(cells) {
13312
+ const known = slabGrids.get(cells);
13313
+ if (known && known.place.length === cells.length * 2) return known;
13314
+ const [u, v] = planeAxes(1);
13315
+ const round3 = (x) => Math.round(x * 1e4);
13316
+ const columns = [...new Set(cells.map((cell) => round3(cell.center[u])))].sort((a, b) => a - b);
13317
+ const rows = [...new Set(cells.map((cell) => round3(cell.center[v])))].sort((a, b) => a - b);
13318
+ const columnOf = new Map(columns.map((c, k) => [c, k])), rowOf = new Map(rows.map((r, k) => [r, k]));
13319
+ const place = new Int32Array(cells.length * 2);
13320
+ cells.forEach((cell, i) => {
13321
+ place[i * 2] = columnOf.get(round3(cell.center[u]));
13322
+ place[i * 2 + 1] = rowOf.get(round3(cell.center[v]));
13323
+ });
13324
+ const grid = { columns: columns.length, rows: rows.length, place };
13325
+ slabGrids.set(cells, grid);
13326
+ return grid;
13327
+ }
13328
+ var unheldSlabCells = (cells, dims, standing) => {
13329
+ const [u, v] = planeAxes(1);
13330
+ const edge = (cell) => cell.center[u] - cell.size[u] / 2 <= -dims[u] / 2 + JOINT_GAP || cell.center[u] + cell.size[u] / 2 >= dims[u] / 2 - JOINT_GAP || cell.center[v] - cell.size[v] / 2 <= -dims[v] / 2 + JOINT_GAP || cell.center[v] + cell.size[v] / 2 >= dims[v] / 2 - JOINT_GAP;
13331
+ const { columns, rows, place } = slabGridOf(cells);
13332
+ const at2 = /* @__PURE__ */ new Map();
13333
+ for (let i = 0; i < cells.length; i++) if (standing(i)) at2.set(place[i * 2 + 1] * columns + place[i * 2], i);
13334
+ const held = new Uint8Array(cells.length);
13335
+ const queue = [];
13336
+ for (const i of at2.values()) if (edge(cells[i])) {
13337
+ held[i] = 1;
13338
+ queue.push(i);
13339
+ }
13340
+ while (queue.length > 0) {
13341
+ const i = queue.pop();
13342
+ const c = place[i * 2], r = place[i * 2 + 1];
13343
+ for (const [nc, nr] of [[c - 1, r], [c + 1, r], [c, r - 1], [c, r + 1]]) {
13344
+ if (nc < 0 || nr < 0 || nc >= columns || nr >= rows) continue;
13345
+ const j = at2.get(nr * columns + nc);
13346
+ if (j === void 0 || held[j] === 1) continue;
13347
+ held[j] = 1;
13348
+ queue.push(j);
13349
+ }
13350
+ }
13351
+ const loose = [];
13352
+ for (const i of at2.values()) if (held[i] !== 1) loose.push(i);
13353
+ return loose.sort((a, b) => a - b);
13354
+ };
13355
+ var clumpUnits = (cells, thin, unit, cap) => {
13356
+ if (cells.length <= cap) return [...cells];
13357
+ const [u, v] = planeAxes(thin);
13358
+ let lo0 = Infinity, lo1 = Infinity;
13359
+ for (const cell of cells) {
13360
+ lo0 = Math.min(lo0, cell.center[u] - cell.size[u] / 2);
13361
+ lo1 = Math.min(lo1, cell.center[v] - cell.size[v] / 2);
13362
+ }
13363
+ let along2 = 1, up = 1;
13364
+ for (let grow = 0; ; grow++) {
13365
+ const bins = /* @__PURE__ */ new Map();
13366
+ for (const cell of cells) {
13367
+ const key2 = `${Math.floor((cell.center[u] - lo0) / (along2 * unit[0]))}:${Math.floor((cell.center[v] - lo1) / (up * unit[1]))}`;
13368
+ const bin2 = bins.get(key2) ?? { lo: [Infinity, Infinity, Infinity], hi: [-Infinity, -Infinity, -Infinity] };
13369
+ for (let k = 0; k < 3; k++) {
13370
+ bin2.lo[k] = Math.min(bin2.lo[k], cell.center[k] - cell.size[k] / 2);
13371
+ bin2.hi[k] = Math.max(bin2.hi[k], cell.center[k] + cell.size[k] / 2);
13372
+ }
13373
+ bins.set(key2, bin2);
13374
+ }
13375
+ if (bins.size <= cap) {
13376
+ return [...bins.values()].map(({ lo, hi }) => ({ center: [(lo[0] + hi[0]) / 2, (lo[1] + hi[1]) / 2, (lo[2] + hi[2]) / 2], size: [hi[0] - lo[0], hi[1] - lo[1], hi[2] - lo[2]] }));
13377
+ }
13378
+ if (grow % 2 === 0) up++;
13379
+ else along2++;
13380
+ }
13381
+ };
13382
+ var MAX_SPALLS = 64;
13383
+ var thinAxisOf = (dims) => dims[0] <= dims[1] && dims[0] <= dims[2] ? 0 : dims[1] <= dims[2] ? 1 : 2;
13384
+ var resolveLayer = (def, index, mat) => ({ index, def, mat, energy: mat.penetration * def.thickness * 1e3 });
13385
+ var faceCode = (thin, axis, sign2) => {
13386
+ const [u] = planeAxes(thin);
13387
+ return (sign2 >= 0 ? 1 : -1) * (axis === thin ? 1 : axis === u ? 2 : 3);
13388
+ };
13389
+ var faceAxis = (thin, face) => {
13390
+ const k = Math.abs(face);
13391
+ return k === 1 ? thin : planeAxes(thin)[k - 2];
13392
+ };
13393
+ var faceOfNormal = (layers, thin, localNormal) => {
13394
+ if (!layers.some((l) => l.def.faces === "all")) return localNormal[thin] >= 0 ? 1 : -1;
13395
+ let axis = thin;
13396
+ for (let k = 0; k < 3; k++) if (Math.abs(localNormal[k]) > Math.abs(localNormal[axis])) axis = k;
13397
+ return faceCode(thin, axis, localNormal[axis]);
13398
+ };
13399
+ var onFace = (layer, face) => {
13400
+ const faces = layer.def.faces;
13401
+ if (faces === "all") return true;
13402
+ if (Math.abs(face) !== 1) return false;
13403
+ return faces === "both" || faces === (face > 0 ? "+" : "-");
13404
+ };
13405
+ var thinSidesOf = (def) => def.faces === "both" || def.faces === "all" ? [1, -1] : [def.faces === "+" ? 1 : -1];
13406
+ var isSpalled = (spalls, layer, face, point) => {
13407
+ for (const s of spalls ?? []) {
13408
+ if (s[0] !== layer || s[1] !== face) continue;
13409
+ const dx = s[2] - point[0], dy = s[3] - point[1], dz = s[4] - point[2];
13410
+ if (dx * dx + dy * dy + dz * dz <= s[5] * s[5]) return true;
13411
+ }
13412
+ return false;
13413
+ };
13414
+ var outerLayer = (layers, spalls, face, point) => layers.find((l) => onFace(l, face) && !isSpalled(spalls, l.index, face, point));
13415
+ var layersEnergy = (layers, spalls, face, point) => {
13416
+ let sum = 0;
13417
+ for (const l of layers) if (onFace(l, face) && !isSpalled(spalls, l.index, face, point)) sum += l.energy;
13418
+ return sum;
13419
+ };
13420
+ var layersThickness = (layers, face) => {
13421
+ let sum = 0;
13422
+ for (const l of layers) if (onFace(l, face)) sum += l.def.thickness;
13423
+ return sum;
13424
+ };
13425
+ var tornPatchAt = (layers, spalls, face, point, radius) => {
13426
+ for (const l of layers) {
13427
+ if (!onFace(l, face)) continue;
13428
+ if (l.mat.fracture === "tear") {
13429
+ let best = -1;
13430
+ (spalls ?? []).forEach((s, i) => {
13431
+ if (s[0] !== l.index || s[1] !== face) return;
13432
+ const dx = s[2] - point[0], dy = s[3] - point[1], dz = s[4] - point[2];
13433
+ const reach2 = s[5] + radius;
13434
+ if (dx * dx + dy * dy + dz * dz <= reach2 * reach2 && (best < 0 || s[5] > spalls[best][5])) best = i;
13435
+ });
13436
+ if (best >= 0) return { layer: l, spall: best };
13437
+ }
13438
+ if (!isSpalled(spalls, l.index, face, point)) return void 0;
13439
+ }
13440
+ return void 0;
13441
+ };
13442
+ var AIR_DENSITY = 1.2;
13443
+ var DRAG_AREA_FACTOR = 1.5;
13444
+ var STEEL_DENSITY = 7850;
13445
+ var FRAGMENT_MIN_SPEED = 30;
13446
+ var GLASS_STIFFENING = 2.5;
13447
+ var PLATE_COEFFICIENT = 0.2874;
13448
+ var BEAM_COEFFICIENT = 0.75;
13449
+ var TNT_PER_JOULE = DEFAULT_BLAST_IMPULSE.tntPerJoule;
13450
+ function projectedArea(shape, toward) {
13451
+ const [dx, dy, dz] = [Math.abs(toward[0]), Math.abs(toward[1]), Math.abs(toward[2])];
13452
+ if (shape.kind === "box") return dx * shape.size[1] * shape.size[2] + dy * shape.size[0] * shape.size[2] + dz * shape.size[0] * shape.size[1];
13453
+ if (shape.kind === "cylinder") return Math.PI * shape.radius ** 2 * dy + 2 * shape.radius * shape.height * Math.sqrt(Math.max(0, 1 - dy * dy));
13454
+ return Math.PI * shape.radius ** 2;
13455
+ }
13456
+ function failureWork(input) {
13457
+ const ratio = input.thickness / Math.max(input.span, input.thickness);
13458
+ const stiffening = input.isGlass ? GLASS_STIFFENING : 1;
13459
+ const pressure = stiffening * input.failureMPa * 1e6 * ratio * ratio / (input.isBeam ? BEAM_COEFFICIENT : PLATE_COEFFICIENT);
13460
+ const deflection = input.thickness * (1 + 25 * input.ductility * input.ductility);
13461
+ return { pressure, work: (0.5 + 0.5 * input.ductility) * pressure * input.loaded * deflection };
13462
+ }
13463
+ function casingFlight(casing) {
13464
+ const k = casing.geometry === "cylinder" ? 0.5 : 0.6;
13465
+ return {
13466
+ mottScale: casing.mass / (2 * Math.max(1, casing.fragments)),
13467
+ speed: casing.gurneyVelocity / Math.sqrt(casing.mass / Math.max(casing.chargeMass, 1e-6) + k)
13468
+ };
13469
+ }
13470
+ function mottMass(u, scale, fragments) {
13471
+ const lowest = 1 / Math.max(1, fragments);
13472
+ return scale * Math.log(1 / Math.max(u, lowest)) ** 2;
13473
+ }
13474
+ function fragmentCaliberMm(mass) {
13475
+ return 2e3 * Math.cbrt(3 * mass / (4 * Math.PI * STEEL_DENSITY));
13476
+ }
13477
+ function fragmentDrag(mass) {
13478
+ const sphereArea = Math.PI * Math.cbrt(3 * mass / (4 * Math.PI * STEEL_DENSITY)) ** 2;
13479
+ return AIR_DENSITY * DRAG_AREA_FACTOR * sphereArea / (2 * mass);
13480
+ }
13481
+ var BLUNT_FRAGMENT_NOSE = 0.84;
13482
+ var NDRC_CONSTANT = 38e-6;
13483
+ function concretePerforation(input) {
13484
+ const { mass, caliber, speed } = input;
13485
+ if (!(mass > 0) || !(caliber > 0) || !(speed > 0)) return { depth: 0, perforation: 0 };
13486
+ const g = NDRC_CONSTANT * (input.nose ?? BLUNT_FRAGMENT_NOSE) * mass / (caliber * Math.sqrt(input.compressiveMPa * 1e6)) * (speed / caliber) ** 1.8;
13487
+ const relative = g <= 1 ? 2 * Math.sqrt(g) : g + 1;
13488
+ const through = relative <= 1.35 ? 3.19 * relative - 0.718 * relative * relative : 1.32 + 1.24 * relative;
13489
+ return { depth: relative * caliber, perforation: through * caliber };
13490
+ }
13491
+ var FIRE_PRIME_C = 300;
13492
+ var drawChainDelay = (delay, random) => {
13493
+ if (typeof delay === "number") return delay;
13494
+ const [min, max] = delay;
13495
+ return min + random() * (max - min);
13496
+ };
13497
+ var chainDelayOf = (spec, trigger) => spec.explodes?.chain?.[trigger];
13498
+ var shotDamageFractionOf = (spec) => spec.explodes?.chain?.shotDamageFraction ?? 0;
13017
13499
  var bsp = (root, count, axes, rnd) => {
13018
13500
  const pieces = [root];
13019
13501
  const vol = (b) => axes.reduce((v, a) => v * b.s[a], 1);
@@ -13294,179 +13776,21 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
13294
13776
  const n = clamp(Math.round(dims[u] * dims[v] / (mean * mean)), 6, maxFragments);
13295
13777
  return radialPlates(inp, root, { t, u, v }, n, Math.min(inp.thickness, dims[t]), fmax * 1.5);
13296
13778
  };
13297
- var planeAxes = (thin) => thin === 1 ? [0, 2] : [thin === 0 ? 2 : 0, 1];
13298
- var unitGrid = (dims, thin, units, cap) => {
13299
- const [u, v] = planeAxes(thin);
13300
- let unitU = Math.min(units.size[0], dims[u]), unitV = Math.min(units.size[1], dims[v]);
13301
- const rowsFor = (h) => Math.ceil(dims[v] / h - 1e-9);
13302
- const colsFor = (w) => Math.ceil(dims[u] / w - 1e-9) + (units.bond === "running" ? 1 : 0);
13303
- const merge = Math.ceil(Math.sqrt(rowsFor(unitV) * colsFor(unitU) / cap));
13304
- if (merge > 1) {
13305
- unitU = Math.min(unitU * merge, dims[u]);
13306
- unitV = Math.min(unitV * merge, dims[v]);
13307
- }
13308
- const cells = [];
13309
- for (let row = 0; row < rowsFor(unitV); row++) {
13310
- const v0 = -dims[v] / 2 + row * unitV, v1 = Math.min(v0 + unitV, dims[v] / 2);
13311
- const shift = units.bond === "running" && row % 2 === 1 ? unitU / 2 : 0;
13312
- for (let col = 0; col < colsFor(unitU); col++) {
13313
- const u0 = Math.max(-dims[u] / 2 + col * unitU - shift, -dims[u] / 2), u1 = Math.min(-dims[u] / 2 + (col + 1) * unitU - shift, dims[u] / 2);
13314
- if (u1 - u0 < 0.01) continue;
13315
- const center = [0, 0, 0], size = [0, 0, 0];
13316
- center[u] = (u0 + u1) / 2;
13317
- center[v] = (v0 + v1) / 2;
13318
- size[u] = u1 - u0;
13319
- size[v] = v1 - v0;
13320
- size[thin] = dims[thin];
13321
- cells.push({ center, size });
13322
- }
13323
- }
13324
- return cells;
13325
- };
13326
- var rowsOfGrid = /* @__PURE__ */ new WeakMap();
13327
- var unitRowsWithin = (cells, thin, point, radius) => {
13328
- const [u, v] = planeAxes(thin);
13329
- if (!Number.isFinite(point[u]) || !Number.isFinite(point[v]) || !Number.isFinite(radius)) return [[0, cells.length]];
13330
- let rows = rowsOfGrid.get(cells);
13331
- if (!rows) {
13332
- const found = [];
13333
- cells.forEach((cell, i) => {
13334
- const last = found[found.length - 1];
13335
- if (last && last.center === cell.center[v] && last.size === cell.size[v]) last.to = i + 1;
13336
- else found.push({ from: i, to: i + 1, center: cell.center[v], size: cell.size[v] });
13337
- });
13338
- rowsOfGrid.set(cells, rows = found);
13339
- }
13340
- const ranges = [];
13341
- for (const row of rows) {
13342
- if (Math.max(0, Math.abs(point[v] - row.center) - row.size / 2) > radius) continue;
13343
- const last = ranges[ranges.length - 1];
13344
- if (last && last[1] === row.from) last[1] = row.to;
13345
- else ranges.push([row.from, row.to]);
13346
- }
13347
- return ranges;
13348
- };
13349
- var planeDistance = (cell, thin, point) => {
13350
- const [u, v] = planeAxes(thin);
13351
- const du = cell.center[u] - point[u], dv = cell.center[v] - point[v];
13352
- return Math.sqrt(du * du + dv * dv);
13353
- };
13354
- var cellsWithin = (cells, thin, point, radius) => {
13355
- const inside3 = cells.filter((c) => planeDistance(c, thin, point) <= radius);
13356
- if (inside3.length > 0 || cells.length === 0) return inside3;
13357
- return [cells.reduce((best, c) => planeDistance(c, thin, point) < planeDistance(best, thin, point) ? c : best)];
13358
- };
13359
- var cellsOutside = (cells, thin, point, radius) => cells.filter((c) => planeDistance(c, thin, point) > radius);
13360
- var MAX_MARKS_PER_FRAGMENT = 12;
13361
- var marksInBox = (center, size, rotation, holes) => {
13362
- const inverse = rotation ? quat.conjugate(rotation) : void 0;
13363
- const marks = [];
13364
- for (const hole of holes) {
13365
- const offset = [hole.point[0] - center[0], hole.point[1] - center[1], hole.point[2] - center[2]];
13366
- const point = inverse ? rotateVec(inverse, offset) : offset;
13367
- const inside3 = point.every((value, k) => Math.abs(value) <= size[k] / 2 + hole.diameter / 2);
13368
- if (!inside3) continue;
13369
- marks.push({ point, normal: inverse ? rotateVec(inverse, hole.normal) : hole.normal, diameter: hole.diameter });
13370
- if (marks.length >= MAX_MARKS_PER_FRAGMENT) break;
13371
- }
13372
- return marks;
13373
- };
13374
- var rowLayouts = /* @__PURE__ */ new WeakMap();
13375
- var rowLayoutOf = (cells, thin, bottom) => {
13376
- const known = rowLayouts.get(cells);
13377
- if (known && known.thin === thin && known.bottom === bottom && known.count === cells.length) return known;
13378
- const [u, v] = planeAxes(thin);
13379
- const keys = cells.map((cell) => Math.round((cell.center[v] - cell.size[v] / 2 - bottom) * 1e4));
13380
- const alongOrder = cells.map((_, i) => i).sort((a, b) => cells[a].center[u] - cells[b].center[u]);
13381
- const layout = { thin, bottom, count: cells.length, keys, alongOrder };
13382
- rowLayouts.set(cells, layout);
13383
- return layout;
13384
- };
13385
- var holeInBox = (center, size, hole) => {
13386
- for (let k = 0; k < 3; k++) if (!(Math.abs(hole.point[k] - center[k]) <= size[k] / 2 + hole.diameter / 2)) return false;
13387
- return true;
13388
- };
13389
- var JOINT_GAP = 1e-4;
13390
- var MIN_BEARING_SHARE = 0.25;
13391
- var unsupportedCells = (cells, thin, dims, standing) => {
13392
- if (thin === 1) return [];
13393
- const [u, v] = planeAxes(thin);
13394
- const bottom = -dims[v] / 2;
13395
- const layout = rowLayoutOf(cells, thin, bottom);
13396
- const rows = /* @__PURE__ */ new Map();
13397
- const isStanding = new Uint8Array(cells.length);
13398
- for (let i = 0; i < cells.length; i++) {
13399
- if (!standing(i)) continue;
13400
- isStanding[i] = 1;
13401
- const key2 = layout.keys[i];
13402
- if (!rows.has(key2)) rows.set(key2, []);
13403
- }
13404
- for (const i of layout.alongOrder) if (isStanding[i] === 1) rows.get(layout.keys[i]).push(i);
13405
- const rowOf = (y) => Math.round((y - bottom) * 1e4);
13406
- const held = /* @__PURE__ */ new Set();
13407
- const queue = [];
13408
- for (const i of rows.get(0) ?? []) {
13409
- held.add(i);
13410
- queue.push(i);
13411
- }
13412
- const overlap = (a, b) => Math.min(a.center[u] + a.size[u] / 2, b.center[u] + b.size[u] / 2) - Math.max(a.center[u] - a.size[u] / 2, b.center[u] - b.size[u] / 2);
13413
- const climb = () => {
13414
- while (queue.length > 0) {
13415
- const cell = cells[queue.pop()];
13416
- for (const j of rows.get(rowOf(cell.center[v] + cell.size[v] / 2)) ?? []) {
13417
- const other = cells[j];
13418
- if (held.has(j) || overlap(cell, other) <= Math.max(JOINT_GAP, MIN_BEARING_SHARE * Math.min(cell.size[u], other.size[u]))) continue;
13419
- held.add(j);
13420
- queue.push(j);
13421
- }
13422
- }
13423
- };
13424
- const touching = (a, b) => Math.abs(a.center[u] + a.size[u] / 2 - (b.center[u] - b.size[u] / 2)) <= 1e-3;
13425
- for (let wedged = true; wedged; ) {
13426
- climb();
13427
- wedged = false;
13428
- for (const row of rows.values()) {
13429
- for (let k = 1; k < row.length - 1; k++) {
13430
- const i = row[k];
13431
- if (held.has(i) || !held.has(row[k - 1]) || !held.has(row[k + 1])) continue;
13432
- if (!touching(cells[row[k - 1]], cells[i]) || !touching(cells[i], cells[row[k + 1]])) continue;
13433
- held.add(i);
13434
- queue.push(i);
13435
- wedged = true;
13436
- }
13437
- }
13438
- }
13439
- const loose = [];
13440
- for (const row of rows.values()) for (const i of row) if (!held.has(i)) loose.push(i);
13441
- return loose;
13442
- };
13443
- var clumpUnits = (cells, thin, unit, cap) => {
13444
- if (cells.length <= cap) return [...cells];
13445
- const [u, v] = planeAxes(thin);
13446
- let lo0 = Infinity, lo1 = Infinity;
13447
- for (const cell of cells) {
13448
- lo0 = Math.min(lo0, cell.center[u] - cell.size[u] / 2);
13449
- lo1 = Math.min(lo1, cell.center[v] - cell.size[v] / 2);
13450
- }
13451
- let along2 = 1, up = 1;
13452
- for (let grow = 0; ; grow++) {
13453
- const bins = /* @__PURE__ */ new Map();
13454
- for (const cell of cells) {
13455
- const key2 = `${Math.floor((cell.center[u] - lo0) / (along2 * unit[0]))}:${Math.floor((cell.center[v] - lo1) / (up * unit[1]))}`;
13456
- const bin2 = bins.get(key2) ?? { lo: [Infinity, Infinity, Infinity], hi: [-Infinity, -Infinity, -Infinity] };
13457
- for (let k = 0; k < 3; k++) {
13458
- bin2.lo[k] = Math.min(bin2.lo[k], cell.center[k] - cell.size[k] / 2);
13459
- bin2.hi[k] = Math.max(bin2.hi[k], cell.center[k] + cell.size[k] / 2);
13460
- }
13461
- bins.set(key2, bin2);
13462
- }
13463
- if (bins.size <= cap) {
13464
- return [...bins.values()].map(({ lo, hi }) => ({ center: [(lo[0] + hi[0]) / 2, (lo[1] + hi[1]) / 2, (lo[2] + hi[2]) / 2], size: [hi[0] - lo[0], hi[1] - lo[1], hi[2] - lo[2]] }));
13779
+ function put(out, at2, value) {
13780
+ if (at2 < out.length) out[at2] = value;
13781
+ else out.push(value);
13782
+ }
13783
+ function sortFirst(out, count) {
13784
+ for (let i = 1; i < count; i++) {
13785
+ const value = out[i];
13786
+ let j = i - 1;
13787
+ while (j >= 0 && out[j] > value) {
13788
+ out[j + 1] = out[j];
13789
+ j--;
13465
13790
  }
13466
- if (grow % 2 === 0) up++;
13467
- else along2++;
13791
+ out[j + 1] = value;
13468
13792
  }
13469
- };
13793
+ }
13470
13794
  var PART_GRID_MIN_PARTS = 64;
13471
13795
  var MAX_CELLS_PER_AXIS = 64;
13472
13796
  var PAD = 1e-4;
@@ -13483,8 +13807,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
13483
13807
  if (![...min, ...max].every(Number.isFinite)) {
13484
13808
  return {
13485
13809
  candidates(_origin, _direction, _maxDistance, out) {
13486
- out.length = 0;
13487
- for (let index = 0; index < parts2.length; index++) out.push(index);
13810
+ for (let index = 0; index < parts2.length; index++) put(out, index, index);
13811
+ return parts2.length;
13488
13812
  }
13489
13813
  };
13490
13814
  }
@@ -13524,20 +13848,20 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
13524
13848
  let stamp = 0;
13525
13849
  return {
13526
13850
  candidates(origin, direction, maxDistance, out) {
13527
- out.length = 0;
13851
+ let count = 0;
13528
13852
  let t0 = 0;
13529
13853
  let t1 = maxDistance;
13530
13854
  for (let k = 0; k < 3; k++) {
13531
13855
  const d = direction[k];
13532
13856
  if (Math.abs(d) < 1e-12) {
13533
- if (origin[k] < min[k] || origin[k] > max[k]) return;
13857
+ if (origin[k] < min[k] || origin[k] > max[k]) return 0;
13534
13858
  continue;
13535
13859
  }
13536
13860
  const a = (min[k] - origin[k]) / d;
13537
13861
  const b = (max[k] - origin[k]) / d;
13538
13862
  t0 = Math.max(t0, Math.min(a, b));
13539
13863
  t1 = Math.min(t1, Math.max(a, b));
13540
- if (t0 > t1) return;
13864
+ if (t0 > t1) return 0;
13541
13865
  }
13542
13866
  stamp++;
13543
13867
  if (stamp === 4294967295) {
@@ -13557,7 +13881,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
13557
13881
  const index = items[k];
13558
13882
  if (seen[index] === stamp) continue;
13559
13883
  seen[index] = stamp;
13560
- out.push(index);
13884
+ put(out, count++, index);
13561
13885
  }
13562
13886
  if (nx <= ny && nx <= nz) {
13563
13887
  if (nx > t1) break;
@@ -13576,70 +13900,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
13576
13900
  nz += ez;
13577
13901
  }
13578
13902
  }
13579
- if (out.length > 1) out.sort((a, b) => a - b);
13903
+ sortFirst(out, count);
13904
+ return count;
13580
13905
  }
13581
13906
  };
13582
13907
  }
13583
- var MAX_SPALLS = 64;
13584
- var thinAxisOf = (dims) => dims[0] <= dims[1] && dims[0] <= dims[2] ? 0 : dims[1] <= dims[2] ? 1 : 2;
13585
- var resolveLayer = (def, index, mat) => ({ index, def, mat, energy: mat.penetration * def.thickness * 1e3 });
13586
- var faceCode = (thin, axis, sign2) => {
13587
- const [u] = planeAxes(thin);
13588
- return (sign2 >= 0 ? 1 : -1) * (axis === thin ? 1 : axis === u ? 2 : 3);
13589
- };
13590
- var faceAxis = (thin, face) => {
13591
- const k = Math.abs(face);
13592
- return k === 1 ? thin : planeAxes(thin)[k - 2];
13593
- };
13594
- var faceOfNormal = (layers, thin, localNormal) => {
13595
- if (!layers.some((l) => l.def.faces === "all")) return localNormal[thin] >= 0 ? 1 : -1;
13596
- let axis = thin;
13597
- for (let k = 0; k < 3; k++) if (Math.abs(localNormal[k]) > Math.abs(localNormal[axis])) axis = k;
13598
- return faceCode(thin, axis, localNormal[axis]);
13599
- };
13600
- var onFace = (layer, face) => {
13601
- const faces = layer.def.faces;
13602
- if (faces === "all") return true;
13603
- if (Math.abs(face) !== 1) return false;
13604
- return faces === "both" || faces === (face > 0 ? "+" : "-");
13605
- };
13606
- var thinSidesOf = (def) => def.faces === "both" || def.faces === "all" ? [1, -1] : [def.faces === "+" ? 1 : -1];
13607
- var isSpalled = (spalls, layer, face, point) => {
13608
- for (const s of spalls ?? []) {
13609
- if (s[0] !== layer || s[1] !== face) continue;
13610
- const dx = s[2] - point[0], dy = s[3] - point[1], dz = s[4] - point[2];
13611
- if (dx * dx + dy * dy + dz * dz <= s[5] * s[5]) return true;
13612
- }
13613
- return false;
13614
- };
13615
- var outerLayer = (layers, spalls, face, point) => layers.find((l) => onFace(l, face) && !isSpalled(spalls, l.index, face, point));
13616
- var layersEnergy = (layers, spalls, face, point) => {
13617
- let sum = 0;
13618
- for (const l of layers) if (onFace(l, face) && !isSpalled(spalls, l.index, face, point)) sum += l.energy;
13619
- return sum;
13620
- };
13621
- var layersThickness = (layers, face) => {
13622
- let sum = 0;
13623
- for (const l of layers) if (onFace(l, face)) sum += l.def.thickness;
13624
- return sum;
13625
- };
13626
- var tornPatchAt = (layers, spalls, face, point, radius) => {
13627
- for (const l of layers) {
13628
- if (!onFace(l, face)) continue;
13629
- if (l.mat.fracture === "tear") {
13630
- let best = -1;
13631
- (spalls ?? []).forEach((s, i) => {
13632
- if (s[0] !== l.index || s[1] !== face) return;
13633
- const dx = s[2] - point[0], dy = s[3] - point[1], dz = s[4] - point[2];
13634
- const reach2 = s[5] + radius;
13635
- if (dx * dx + dy * dy + dz * dz <= reach2 * reach2 && (best < 0 || s[5] > spalls[best][5])) best = i;
13636
- });
13637
- if (best >= 0) return { layer: l, spall: best };
13638
- }
13639
- if (!isSpalled(spalls, l.index, face, point)) return void 0;
13640
- }
13641
- return void 0;
13642
- };
13643
13908
  var REBAR_COVER = 0.03;
13644
13909
  var COVER = REBAR_COVER;
13645
13910
  var MAX_BARS_PER_DIRECTION = 24;
@@ -14362,19 +14627,31 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
14362
14627
  var clampNumber = (v, a, b) => Math.max(a, Math.min(b, v));
14363
14628
  var settlementAt = (settlement, point) => {
14364
14629
  const d = [settlement.to[0] - settlement.from[0], settlement.to[1] - settlement.from[1], settlement.to[2] - settlement.from[2]];
14630
+ const px = point[0] - settlement.from[0];
14631
+ const py = point[1] - settlement.from[1];
14632
+ const pz = point[2] - settlement.from[2];
14365
14633
  const length2 = d[0] * d[0] + d[1] * d[1] + d[2] * d[2];
14366
- const t = length2 > 0 ? clampNumber(((point[0] - settlement.from[0]) * d[0] + (point[1] - settlement.from[1]) * d[1] + (point[2] - settlement.from[2]) * d[2]) / length2, 0, 1) : 0;
14634
+ const along2 = length2 > 0 ? (px * d[0] + py * d[1] + pz * d[2]) / length2 : 0;
14635
+ const t = clampNumber(along2, 0, 1);
14367
14636
  const drops = settlement.drop;
14368
14637
  if (drops.length === 0) return 0;
14369
14638
  const at2 = t * (drops.length - 1);
14370
14639
  const i = Math.floor(at2);
14371
14640
  const j = Math.min(drops.length - 1, i + 1);
14372
- return drops[i] + (drops[j] - drops[i]) * (at2 - i);
14641
+ const f = at2 - i;
14642
+ const drop = drops[i] + (drops[j] - drops[i]) * f;
14643
+ const turn = settlement.turn;
14644
+ if (!turn || turn.length !== drops.length) return drop;
14645
+ const a = turn[i];
14646
+ const b = turn[j];
14647
+ const armX = px - d[0] * along2;
14648
+ const armZ = pz - d[2] * along2;
14649
+ return drop - ((a[2] + (b[2] - a[2]) * f) * armX - (a[0] + (b[0] - a[0]) * f) * armZ);
14373
14650
  };
14374
14651
  var mergeSettlement = (old, next) => {
14375
14652
  if (!old) return next;
14376
14653
  const same = old.from.every((v, k) => Math.abs(v - next.from[k]) < 1e-6) && old.to.every((v, k) => Math.abs(v - next.to[k]) < 1e-6);
14377
- if (same && old.drop.length === next.drop.length) return { from: old.from, to: old.to, drop: old.drop.map((v, k) => Math.max(v, next.drop[k])) };
14654
+ if (same && old.drop.length === next.drop.length && !old.turn && !next.turn) return { from: old.from, to: old.to, drop: old.drop.map((v, k) => Math.max(v, next.drop[k])) };
14378
14655
  const mean = (line) => line.drop.reduce((sum, v) => sum + v, 0) / Math.max(1, line.drop.length);
14379
14656
  return mean(old) >= mean(next) ? old : next;
14380
14657
  };
@@ -14753,6 +15030,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
14753
15030
  var materials_default = [
14754
15031
  {
14755
15032
  id: "steel",
15033
+ splitForm: "sheets",
14756
15034
  density: 7850,
14757
15035
  hpPerKg: 400,
14758
15036
  penetration: 110,
@@ -14876,6 +15154,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
14876
15154
  },
14877
15155
  {
14878
15156
  id: "aluminium",
15157
+ splitForm: "sheets",
14879
15158
  density: 2700,
14880
15159
  hpPerKg: 250,
14881
15160
  penetration: 60,
@@ -14915,6 +15194,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
14915
15194
  },
14916
15195
  {
14917
15196
  id: "copper",
15197
+ splitForm: "sheets",
14918
15198
  density: 8960,
14919
15199
  hpPerKg: 300,
14920
15200
  penetration: 70,
@@ -15103,7 +15383,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
15103
15383
  tearJoules: 80
15104
15384
  }
15105
15385
  },
15106
- failureMPa: 40
15386
+ failureMPa: 40,
15387
+ elastic: {
15388
+ alongGPa: 6.96,
15389
+ shearGPa: 0.44
15390
+ }
15107
15391
  },
15108
15392
  {
15109
15393
  id: "mdf",
@@ -15150,7 +15434,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
15150
15434
  tearJoules: 20
15151
15435
  }
15152
15436
  },
15153
- failureMPa: 25
15437
+ failureMPa: 25,
15438
+ elastic: {
15439
+ alongGPa: 3,
15440
+ shearGPa: 0.8
15441
+ }
15154
15442
  },
15155
15443
  {
15156
15444
  id: "glass",
@@ -15409,6 +15697,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
15409
15697
  },
15410
15698
  {
15411
15699
  id: "plastic",
15700
+ splitForm: "plates",
15412
15701
  density: 1100,
15413
15702
  hpPerKg: 60,
15414
15703
  penetration: 8,
@@ -15443,6 +15732,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
15443
15732
  },
15444
15733
  {
15445
15734
  id: "rubber",
15735
+ splitForm: "strips",
15446
15736
  density: 1100,
15447
15737
  hpPerKg: 80,
15448
15738
  penetration: 12,
@@ -15475,6 +15765,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
15475
15765
  },
15476
15766
  {
15477
15767
  id: "fabric",
15768
+ splitForm: "strips",
15478
15769
  density: 400,
15479
15770
  hpPerKg: 20,
15480
15771
  penetration: 0.8,
@@ -15572,6 +15863,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
15572
15863
  },
15573
15864
  {
15574
15865
  id: "leather",
15866
+ splitForm: "strips",
15575
15867
  density: 900,
15576
15868
  hpPerKg: 50,
15577
15869
  penetration: 4,
@@ -15608,6 +15900,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
15608
15900
  },
15609
15901
  {
15610
15902
  id: "paper",
15903
+ splitForm: "strips",
15611
15904
  density: 700,
15612
15905
  hpPerKg: 8,
15613
15906
  penetration: 0.3,
@@ -16414,6 +16707,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
16414
16707
  var FOOT_BAND = 0.03;
16415
16708
  var SEAM_STATIONS = 5;
16416
16709
  var BEAM_PIECES = 4;
16710
+ var SAG_STATIONS = BEAM_PIECES + 1;
16417
16711
  var SLENDER = 4;
16418
16712
  var MAX_DOF = 1500;
16419
16713
  var MECHANISM = 0.5;
@@ -16445,6 +16739,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
16445
16739
  const r = t / b;
16446
16740
  return b * t ** 3 * (1 / 3 - 0.21 * r * (1 - r ** 4 / 12));
16447
16741
  }
16742
+ var NO_PLACES = new Int32Array(0);
16448
16743
  var AXES = [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
16449
16744
  function beamOf(part) {
16450
16745
  const d = part.dims;
@@ -16615,37 +16910,143 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
16615
16910
  }
16616
16911
  return out;
16617
16912
  }
16618
- function solve(k, f, n) {
16619
- const first = new Int32Array(n);
16620
- for (let i = 0; i < n; i++) {
16621
- let j = 0;
16622
- while (j < i && k[i * n + j] === 0) j++;
16623
- first[i] = j;
16913
+ function sparseOf(count, pairs, last) {
16914
+ const joined = Array.from({ length: count }, () => /* @__PURE__ */ new Set());
16915
+ for (const [a, b] of pairs) {
16916
+ if (a === b) continue;
16917
+ joined[a].add(b);
16918
+ joined[b].add(a);
16919
+ }
16920
+ const order2 = new Int32Array(count).fill(-1);
16921
+ const held = [];
16922
+ for (let rank = 0; rank < count; rank++) {
16923
+ const feet = rank >= count - last.size;
16924
+ let least = -1;
16925
+ for (let i = 0; i < count; i++) if (order2[i] === -1 && last.has(i) === feet && (least === -1 || joined[i].size < joined[least].size)) least = i;
16926
+ order2[least] = rank;
16927
+ const others = [...joined[least]];
16928
+ held.push(others);
16929
+ for (const a of others) {
16930
+ joined[a].delete(least);
16931
+ for (const b of others) if (a !== b) joined[a].add(b);
16932
+ }
16933
+ }
16934
+ const nodeStart = new Int32Array(count + 1);
16935
+ for (let rank = 0; rank < count; rank++) nodeStart[rank + 1] = nodeStart[rank] + held[rank].length;
16936
+ const below = new Int32Array(nodeStart[count]);
16937
+ const beforeStart = new Int32Array(count + 1);
16938
+ for (let rank = 0; rank < count; rank++) {
16939
+ const ranks = held[rank].map((node) => order2[node]).sort((p, q) => p - q);
16940
+ below.set(ranks, nodeStart[rank]);
16941
+ for (const other of ranks) beforeStart[other + 1] = beforeStart[other + 1] + 1;
16942
+ }
16943
+ for (let rank = 0; rank < count; rank++) beforeStart[rank + 1] = beforeStart[rank + 1] + beforeStart[rank];
16944
+ const before = new Int32Array(beforeStart[count]);
16945
+ const filled = beforeStart.slice(0, count);
16946
+ for (let rank = 0; rank < count; rank++) for (let t = nodeStart[rank]; t < nodeStart[rank + 1]; t++) before[filled[below[t]]++] = rank;
16947
+ const n = count * 6;
16948
+ const start = new Int32Array(n + 1);
16949
+ for (let j = 0; j < n; j++) {
16950
+ const rank = Math.floor(j / 6);
16951
+ start[j + 1] = start[j] + (5 - j % 6) + 6 * (nodeStart[rank + 1] - nodeStart[rank]);
16624
16952
  }
16625
- for (let i = 0; i < n; i++) {
16626
- const fi = first[i];
16627
- for (let j = fi; j <= i; j++) {
16628
- let sum = k[i * n + j];
16629
- const from = Math.max(fi, first[j]);
16630
- for (let m = from; m < j; m++) sum -= k[i * n + m] * k[j * n + m];
16631
- if (j === i) {
16632
- if (!(sum > 0)) return false;
16633
- k[i * n + i] = Math.sqrt(sum);
16634
- } else k[i * n + j] = sum / k[j * n + j];
16953
+ const rows = new Int32Array(start[n]);
16954
+ for (let j = 0; j < n; j++) {
16955
+ const rank = Math.floor(j / 6);
16956
+ let p = start[j];
16957
+ for (let i = j + 1; i < rank * 6 + 6; i++) rows[p++] = i;
16958
+ for (let t = nodeStart[rank]; t < nodeStart[rank + 1]; t++) for (let c = 0; c < 6; c++) rows[p++] = below[t] * 6 + c;
16959
+ }
16960
+ const head = (count - last.size) * 6;
16961
+ const tail = start.slice(0, n);
16962
+ for (let j = 0; j < head; j++) while (tail[j] < start[j + 1] && rows[tail[j]] < head) tail[j] = tail[j] + 1;
16963
+ return { order: order2, shape: { n, start, rows, nodeStart, below, beforeStart, before, size: n + rows.length, head, tail } };
16964
+ }
16965
+ function placeOf(shape, i, j) {
16966
+ if (i === j) return i;
16967
+ const rank = Math.floor(j / 6);
16968
+ const other = Math.floor(i / 6);
16969
+ const index = shape.n + shape.start[j];
16970
+ if (other === rank) return index + i - j - 1;
16971
+ let t = shape.nodeStart[rank];
16972
+ const end = shape.nodeStart[rank + 1];
16973
+ while (t < end && shape.below[t] !== other) t++;
16974
+ if (t === end) throw new Error(`assemblyFlex: (${i}, ${j}) is of two nodes the matrix was not made with as joined`);
16975
+ return index + 5 - j % 6 + 6 * (t - shape.nodeStart[rank]) + i % 6;
16976
+ }
16977
+ function addAt(shape, k, i, j, value) {
16978
+ if (j > i) return;
16979
+ const index = shape.placeOf(i, j);
16980
+ k[index] = k[index] + value;
16981
+ }
16982
+ function multiply2(shape, k, x, out) {
16983
+ const { n, start, rows } = shape;
16984
+ for (let j = 0; j < n; j++) out[j] = k[j] * x[j];
16985
+ for (let j = 0; j < n; j++) {
16986
+ const xj = x[j];
16987
+ for (let p = start[j]; p < start[j + 1]; p++) {
16988
+ const i = rows[p];
16989
+ const value = k[n + p];
16990
+ out[i] = out[i] + value * xj;
16991
+ out[j] = out[j] + value * x[i];
16992
+ }
16993
+ }
16994
+ }
16995
+ function factor(shape, k, from, to) {
16996
+ const { n, start, rows, beforeStart, before } = shape;
16997
+ const next = from === 0 ? start.slice(0, n) : shape.tail.slice();
16998
+ const x = new Float64Array(n);
16999
+ const columns = new Int32Array(n);
17000
+ for (let i = from; i < to; i++) {
17001
+ const rank = Math.floor(i / 6);
17002
+ let count = 0;
17003
+ for (let t = beforeStart[rank]; t < beforeStart[rank + 1]; t++) for (let c = 0; c < 6; c++) columns[count++] = before[t] * 6 + c;
17004
+ for (let j = rank * 6; j < i; j++) columns[count++] = j;
17005
+ for (let c = 0; c < count; c++) {
17006
+ const j = columns[c];
17007
+ x[j] = k[n + next[j]];
16635
17008
  }
17009
+ let diagonal = k[i];
17010
+ for (let c = 0; c < count; c++) {
17011
+ const j = columns[c];
17012
+ const value = x[j] / k[j];
17013
+ x[j] = 0;
17014
+ const end = next[j];
17015
+ for (let p = start[j]; p < end; p++) x[rows[p]] = x[rows[p]] - k[n + p] * value;
17016
+ diagonal -= value * value;
17017
+ k[n + end] = value;
17018
+ next[j] = end + 1;
17019
+ }
17020
+ if (!(diagonal > 0)) return false;
17021
+ k[i] = Math.sqrt(diagonal);
16636
17022
  }
16637
- for (let i = 0; i < n; i++) {
16638
- let sum = f[i];
16639
- for (let m = first[i]; m < i; m++) sum -= k[i * n + m] * f[m];
16640
- f[i] = sum / k[i * n + i];
17023
+ return true;
17024
+ }
17025
+ function substitute(shape, k, f) {
17026
+ const { n, start, rows } = shape;
17027
+ for (let j = 0; j < n; j++) {
17028
+ const value = f[j] / k[j];
17029
+ f[j] = value;
17030
+ for (let p = start[j]; p < start[j + 1]; p++) f[rows[p]] = f[rows[p]] - k[n + p] * value;
16641
17031
  }
16642
- for (let i = n - 1; i >= 0; i--) {
16643
- const x = f[i] / k[i * n + i];
16644
- f[i] = x;
16645
- for (let m = first[i]; m < i; m++) f[m] = f[m] - k[i * n + m] * x;
17032
+ for (let j = n - 1; j >= 0; j--) {
17033
+ let sum = f[j];
17034
+ for (let p = start[j]; p < start[j + 1]; p++) sum -= k[n + p] * f[rows[p]];
17035
+ f[j] = sum / k[j];
16646
17036
  }
16647
- return true;
16648
17037
  }
17038
+ var sparseLinear = (count, pairs, last) => {
17039
+ const { order: order2, shape } = sparseOf(count, pairs, last);
17040
+ return {
17041
+ order: order2,
17042
+ size: shape.size,
17043
+ head: shape.head,
17044
+ placeOf: (i, j) => placeOf(shape, i, j),
17045
+ factor: (k, from, to) => factor(shape, k, from, to),
17046
+ substitute: (k, f) => substitute(shape, k, f),
17047
+ multiply: (k, x, out) => multiply2(shape, k, x, out)
17048
+ };
17049
+ };
16649
17050
  function hullOf(points) {
16650
17051
  const sorted = [...points].sort((p, q) => p[0] - q[0] || p[1] - q[1]);
16651
17052
  const turn = (o, p, q) => (p[0] - o[0]) * (q[1] - o[1]) - (p[1] - o[1]) * (q[0] - o[0]);
@@ -16723,20 +17124,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
16723
17124
  beam.nodes = kept.map((s) => nodes.push({ at: vec.madd(beam.part.position, beam.axis, s) }) - 1);
16724
17125
  }
16725
17126
  if (nodes.length * 6 > MAX_DOF) return null;
16726
- const lo = [Infinity, Infinity, Infinity];
16727
- const hi = [-Infinity, -Infinity, -Infinity];
16728
- for (const node of nodes) for (let k = 0; k < 3; k++) {
16729
- lo[k] = Math.min(lo[k], node.at[k]);
16730
- hi[k] = Math.max(hi[k], node.at[k]);
16731
- }
16732
- let main = 0;
16733
- if (hi[1] - lo[1] > hi[main] - lo[main]) main = 1;
16734
- if (hi[2] - lo[2] > hi[main] - lo[main]) main = 2;
16735
- const ranked = nodes.map((_, i) => i).sort((p, q) => nodes[p].at[main] - nodes[q].at[main] || p - q);
16736
17127
  const order2 = new Int32Array(nodes.length);
16737
- ranked.forEach((node, rank) => {
16738
- order2[node] = rank;
16739
- });
17128
+ for (let i = 0; i < nodes.length; i++) order2[i] = i;
16740
17129
  const dofsOf = (node) => [0, 1, 2, 3, 4, 5].map((i) => order2[node] * 6 + i);
16741
17130
  const nearest = (beam, p) => {
16742
17131
  const t = along2(beam, p);
@@ -16744,7 +17133,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
16744
17133
  for (let i = 1; i < beam.stations.length; i++) if (Math.abs(beam.stations[i] - t) < Math.abs(beam.stations[best] - t)) best = i;
16745
17134
  return beam.nodes[best];
16746
17135
  };
16747
- const elements = [];
17136
+ const made = [];
16748
17137
  for (const beam of beams.values()) {
16749
17138
  const section = sectionOf(beam);
16750
17139
  if (!section) {
@@ -16755,7 +17144,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
16755
17144
  for (let i = 0; i + 1 < beam.nodes.length; i++) {
16756
17145
  const length = beam.stations[i + 1] - beam.stations[i];
16757
17146
  const k = toObjectFrame(beamLocal(section, length), 12, beam.axis, beam.u, beam.v);
16758
- elements.push({ dofs: [...dofsOf(beam.nodes[i]), ...dofsOf(beam.nodes[i + 1])], k, parts: [beam.part.id] });
17147
+ made.push({ dofs: [...dofsOf(beam.nodes[i]), ...dofsOf(beam.nodes[i + 1])], k, parts: [beam.part.id], places: NO_PLACES });
16759
17148
  }
16760
17149
  }
16761
17150
  for (const [joint, stations] of stationed) {
@@ -16784,7 +17173,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
16784
17173
  for (let p = 0; p < 12; p++) for (let q = 0; q < 12; q++) k[p * 12 + q] = k[p * 12 + q] + stiffness * b12[p] * b12[q];
16785
17174
  }
16786
17175
  }
16787
- elements.push({ dofs: [...dofsOf(na), ...dofsOf(nb)], k, parts: [joint.a, joint.b] });
17176
+ made.push({ dofs: [...dofsOf(na), ...dofsOf(nb)], k, parts: [joint.a, joint.b], places: NO_PLACES });
16788
17177
  }
16789
17178
  }
16790
17179
  const supports = [];
@@ -16795,7 +17184,15 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
16795
17184
  supports.push({ part: id, node, arm: vec.sub(at2, nodes[node].at), at: at2 });
16796
17185
  }
16797
17186
  }
16798
- const frame2 = { nodes, beams, elements, supports, order: order2 };
17187
+ const shape = (input.linear ?? sparseLinear)(nodes.length, made.map((element) => [Math.floor(element.dofs[0] / 6), Math.floor(element.dofs[6] / 6)]), new Set(supports.map((s) => s.node)));
17188
+ order2.set(shape.order);
17189
+ const elements = made.map((element) => {
17190
+ const dofs = element.dofs.map((dof) => order2[Math.floor(dof / 6)] * 6 + dof % 6);
17191
+ const places = new Int32Array(dofs.length * dofs.length);
17192
+ for (let p = 0; p < dofs.length; p++) for (let q = 0; q < dofs.length; q++) places[p * dofs.length + q] = dofs[q] > dofs[p] ? -1 : shape.placeOf(dofs[p], dofs[q]);
17193
+ return { ...element, dofs, places };
17194
+ });
17195
+ const frame2 = { nodes, beams, elements, supports, order: order2, shape };
16799
17196
  const before = lost.size > 0 ? solveFrame(frame2, input, joints, structural, /* @__PURE__ */ new Set(), g, null) : null;
16800
17197
  const after = solveFrame(frame2, input, joints, structural, lost, g, before);
16801
17198
  if (!after) return null;
@@ -16835,12 +17232,15 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
16835
17232
  const delta = new Float64Array(n);
16836
17233
  for (let i = 0; i < n; i++) delta[i] = after.u[i] - before.u[i];
16837
17234
  for (const beam of beams.values()) if (!after.standing.has(beam.part.id)) for (const node of beam.nodes) for (const dof of dofsOf(node)) delta[dof] = 0;
16838
- for (let i = 0; i < n; i++) {
16839
- if (delta[i] === 0) continue;
16840
- let row = 0;
16841
- for (let j = 0; j < n; j++) row += after.k[i * n + j] * delta[j];
16842
- released += 0.5 * delta[i] * row;
16843
- }
17235
+ const d = new Float64Array(n);
17236
+ for (let i = 0; i < n; i++) d[i] = -delta[i];
17237
+ const kd = new Float64Array(n);
17238
+ frame2.shape.multiply(after.structure, d, kd);
17239
+ const ku = new Float64Array(n);
17240
+ frame2.shape.multiply(after.structure, after.u, ku);
17241
+ let change = 0;
17242
+ for (let i = 0; i < n; i++) change += d[i] * (0.5 * kd[i] + (ku[i] - after.load[i]));
17243
+ released = Math.max(0, change);
16844
17244
  spin = spinOf({ frame: frame2, after, delta, released, centre: allCentre, mass: all, floor, g });
16845
17245
  }
16846
17246
  return {
@@ -16855,6 +17255,24 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
16855
17255
  if (!beam || !after.standing.has(id)) return null;
16856
17256
  const node = nearest(beam, point);
16857
17257
  return moved(after, { part: id, node, arm: vec.sub(point, nodes[node].at), mass: 0 });
17258
+ },
17259
+ settlement(id) {
17260
+ const beam = beams.get(id);
17261
+ if (!beam) return null;
17262
+ const carrier = after.standing.has(id) ? null : after.masses.find((p) => p.part === id);
17263
+ if (!after.standing.has(id) && !carrier) return null;
17264
+ const from = vec.madd(beam.part.position, beam.axis, -beam.length / 2);
17265
+ const to = vec.madd(beam.part.position, beam.axis, beam.length / 2);
17266
+ const drop = [];
17267
+ const turn = [];
17268
+ for (let i = 0; i < SAG_STATIONS; i++) {
17269
+ const point = vec.madd(from, beam.axis, beam.length * i / (SAG_STATIONS - 1));
17270
+ const node = carrier ? carrier.node : nearest(beam, point);
17271
+ drop.push(-moved(after, { part: id, node, arm: vec.sub(point, nodes[node].at), mass: 0 })[1]);
17272
+ const base2 = order2[node] * 6;
17273
+ turn.push([after.u[base2 + 3], after.u[base2 + 4], after.u[base2 + 5]]);
17274
+ }
17275
+ return { from, to, drop, turn };
16858
17276
  }
16859
17277
  };
16860
17278
  }
@@ -16879,7 +17297,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
16879
17297
  return standing;
16880
17298
  }
16881
17299
  function solveFrame(frame2, input, joints, structural, gone, g, from) {
16882
- const { nodes, beams, order: order2 } = frame2;
17300
+ const { nodes, beams, order: order2, shape } = frame2;
16883
17301
  const n = nodes.length * 6;
16884
17302
  const standing = standingParts(frame2, joints, structural, gone);
16885
17303
  if (standing.size === 0) return null;
@@ -16939,50 +17357,50 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
16939
17357
  f[base2 + 3] = f[base2 + 3] - p.arm[2] * weight;
16940
17358
  f[base2 + 5] = f[base2 + 5] + p.arm[0] * weight;
16941
17359
  }
16942
- const structure = new Float64Array(n * n);
17360
+ const structure = new Float64Array(shape.size);
16943
17361
  let largest = 0;
16944
17362
  for (const element of frame2.elements) {
16945
17363
  if (!element.parts.every((id) => standing.has(id))) continue;
16946
- const size = element.dofs.length;
16947
- for (let p = 0; p < size; p++) {
16948
- for (let q = 0; q < size; q++) structure[element.dofs[p] * n + element.dofs[q]] = structure[element.dofs[p] * n + element.dofs[q]] + element.k[p * size + q];
16949
- }
17364
+ const { places, k: k2 } = element;
17365
+ for (let t = 0; t < places.length; t++) if (places[t] >= 0) structure[places[t]] = structure[places[t]] + k2[t];
16950
17366
  }
16951
- for (let i = 0; i < n; i++) largest = Math.max(largest, structure[i * n + i]);
17367
+ for (let i = 0; i < n; i++) largest = Math.max(largest, structure[i]);
16952
17368
  if (largest <= 0) return null;
16953
17369
  const free = new Uint8Array(n);
16954
17370
  for (const id of standing) for (const node of beams.get(id).nodes) for (let i = 0; i < 6; i++) free[order2[node] * 6 + i] = 1;
16955
17371
  for (let i = 0; i < n; i++) {
16956
17372
  if (!free[i]) {
16957
- structure[i * n + i] = largest;
17373
+ structure[i] = largest;
16958
17374
  f[i] = 0;
16959
- } else structure[i * n + i] = structure[i * n + i] + largest * SOFT;
17375
+ } else addAt(shape, structure, i, i, largest * SOFT);
16960
17376
  }
16961
17377
  const feet = frame2.supports.filter((s) => standing.has(s.part));
16962
17378
  const holds2 = feet.map((s) => !from || from.holding.includes(s));
16963
17379
  const footed = [...new Set(feet.map((s) => s.part))];
16964
17380
  const grips = new Map(footed.map((id) => [id, true]));
16965
17381
  const friction = input.friction ?? FOOT_FRICTION;
16966
- const k = new Float64Array(n * n);
17382
+ const factored = structure.slice();
17383
+ if (!shape.factor(factored, 0, shape.head)) return null;
17384
+ const k = new Float64Array(shape.size);
16967
17385
  const u = new Float64Array(n);
16968
- const build = () => {
16969
- k.set(structure);
17386
+ const build = (from2) => {
17387
+ k.set(from2);
16970
17388
  const held = /* @__PURE__ */ new Map();
16971
17389
  feet.forEach((s, index) => {
16972
17390
  if (!holds2[index]) return;
16973
17391
  const row = armRows(s.arm)[1];
16974
17392
  const base2 = order2[s.node] * 6;
16975
- for (let p = 0; p < 6; p++) for (let q = 0; q < 6; q++) k[(base2 + p) * n + base2 + q] = k[(base2 + p) * n + base2 + q] + RIGID_PUSH * row[p] * row[q];
17393
+ for (let p = 0; p < 6; p++) for (let q = 0; q < 6; q++) addAt(shape, k, base2 + p, base2 + q, RIGID_PUSH * row[p] * row[q]);
16976
17394
  held.set(s.part, [...held.get(s.part) ?? [], s]);
16977
17395
  });
16978
17396
  for (const [id, points] of held) {
16979
17397
  const { node, arm } = gripOf(points);
16980
17398
  const upright = order2[node] * 6 + 4;
16981
- k[upright * n + upright] = k[upright * n + upright] + RIGID_TURN;
17399
+ addAt(shape, k, upright, upright, RIGID_TURN);
16982
17400
  if (!grips.get(id)) continue;
16983
17401
  const rows = armRows(arm);
16984
17402
  const base2 = order2[node] * 6;
16985
- for (const row of [rows[0], rows[2]]) for (let p = 0; p < 6; p++) for (let q = 0; q < 6; q++) k[(base2 + p) * n + base2 + q] = k[(base2 + p) * n + base2 + q] + RIGID_PUSH * row[p] * row[q];
17403
+ for (const row of [rows[0], rows[2]]) for (let p = 0; p < 6; p++) for (let q = 0; q < 6; q++) addAt(shape, k, base2 + p, base2 + q, RIGID_PUSH * row[p] * row[q]);
16986
17404
  }
16987
17405
  };
16988
17406
  const liftOf = (s) => {
@@ -16991,9 +17409,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
16991
17409
  };
16992
17410
  const rounds = 4 * feet.length + 2 * footed.length + 4;
16993
17411
  for (let round3 = 0; round3 < rounds; round3++) {
16994
- build();
17412
+ build(factored);
16995
17413
  u.set(f);
16996
- if (!solve(k, u, n)) return null;
17414
+ if (!shape.factor(k, shape.head, n)) return null;
17415
+ shape.substitute(k, u);
16997
17416
  const pull = 1e-12;
16998
17417
  const sink = -1e-9;
16999
17418
  if (round3 === 0) {
@@ -17047,8 +17466,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
17047
17466
  if (worst > MECHANISM) return null;
17048
17467
  const holding = feet.filter((_, index) => holds2[index]);
17049
17468
  if (holding.length < 3) return null;
17050
- build();
17051
- return { u: u.slice(), k: k.slice(), holding, masses, standing };
17469
+ return { u: u.slice(), structure, load: f, holding, masses, standing };
17052
17470
  }
17053
17471
  return null;
17054
17472
  }
@@ -17277,7 +17695,6 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
17277
17695
  var TEAR_JOULES = 150;
17278
17696
  var STRIP_THICKNESS = 15e-4;
17279
17697
  var UNIT_FRAGMENT_FACTOR = 4;
17280
- var BREACH_GRID_CAP = 4096;
17281
17698
  var MASONRY_CRUMBLE_SPEED = 0.6;
17282
17699
  var MASONRY_TOPPLE = 0.4;
17283
17700
  var MASONRY_TOPPLE_MIN_HEIGHT = 0.5;
@@ -17494,6 +17911,12 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
17494
17911
  objectsRevision++;
17495
17912
  }
17496
17913
  };
17914
+ const movedObjects = [];
17915
+ const markMoved = (o) => {
17916
+ if (o.rayMoved) return;
17917
+ o.rayMoved = true;
17918
+ movedObjects.push(o);
17919
+ };
17497
17920
  const listeners = /* @__PURE__ */ new Map();
17498
17921
  let cur = [];
17499
17922
  const blasts = [];
@@ -17502,6 +17925,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
17502
17925
  const primed = /* @__PURE__ */ new Map();
17503
17926
  let orderCounter = 0;
17504
17927
  const impls = /* @__PURE__ */ new Map();
17928
+ let implsRevision = 0;
17505
17929
  const taken = (id) => objects.has(id) || impls.has(id);
17506
17930
  const emit = (e) => {
17507
17931
  cur.push(e);
@@ -17668,6 +18092,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
17668
18092
  unsup: [],
17669
18093
  anyAnchor: false,
17670
18094
  order: ++orderCounter,
18095
+ rayStamp: 0,
18096
+ raySlot: 0,
18097
+ rayMoved: false,
17671
18098
  loose: carry?.loose ?? false,
17672
18099
  cast: /* @__PURE__ */ new Map(),
17673
18100
  base: { pos: [pos[0], pos[1], pos[2]], rot: [rot[0], rot[1], rot[2], rot[3]] }
@@ -18502,6 +18929,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
18502
18929
  applySoilPose(o);
18503
18930
  };
18504
18931
  const applySoilPose = (o) => {
18932
+ markMoved(o);
18505
18933
  const so = o.soil;
18506
18934
  if (!so) {
18507
18935
  o.st.position = [o.base.pos[0], o.base.pos[1], o.base.pos[2]];
@@ -19043,6 +19471,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19043
19471
  } else emit({ ...base2(o, src), type: "stage", part: p.spec.id, stage: 2, opening: { center: worldCenter, radius: hole.radius }, fragments });
19044
19472
  debris(o, p, p.mat.breakDebris, worldCenter, [0, 1, 0], 14, 2, src);
19045
19473
  if (p.spec.reinforcement) exposeRebar(o, p, src);
19474
+ dropOverOpening(o, p, src);
19046
19475
  };
19047
19476
  const distort = (o, q, beta, at2, toward, src) => {
19048
19477
  const prior = q.rt.distortion ?? 0;
@@ -19277,6 +19706,29 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19277
19706
  return turn;
19278
19707
  };
19279
19708
  const copyOf = (v) => [v[0], v[1], v[2]];
19709
+ let bestInto = null;
19710
+ const rayPoint = [0, 0, 0];
19711
+ const keepBest = (into, object2, part, point, normal, distance2, pathLen) => {
19712
+ if (!into) return { object: object2, part, point: copyOf(point), normal: copyOf(normal), distance: distance2, pathLen };
19713
+ into.object = object2;
19714
+ into.part = part;
19715
+ into.point[0] = point[0];
19716
+ into.point[1] = point[1];
19717
+ into.point[2] = point[2];
19718
+ into.normal[0] = normal[0];
19719
+ into.normal[1] = normal[1];
19720
+ into.normal[2] = normal[2];
19721
+ into.distance = distance2;
19722
+ into.pathLen = pathLen;
19723
+ return into;
19724
+ };
19725
+ const bestScratch = { object: "", part: "", point: [0, 0, 0], normal: [0, 0, 0], distance: 0, pathLen: 0 };
19726
+ const isTerrainPart = (objectId, partId) => {
19727
+ const parts2 = objects.get(objectId)?.parts;
19728
+ if (!parts2) return false;
19729
+ for (const p of parts2) if (p.spec.id === partId) return p.spec.tags?.includes("terrain") === true;
19730
+ return false;
19731
+ };
19280
19732
  const objectTurnBack = [0, 0, 0, 1];
19281
19733
  const objectOrigin = [0, 0, 0];
19282
19734
  const objectDirection = [0, 0, 0];
@@ -19397,11 +19849,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19397
19849
  return grid;
19398
19850
  };
19399
19851
  const partsAlong = (o, lo, ld, maxDist) => {
19400
- if (o.parts.length < PART_GRID_MIN_PARTS || !lo.every(Number.isFinite) || !ld.every(Number.isFinite)) return o.parts;
19401
- partGridOf(o).candidates(lo, ld, maxDist, gridCandidates);
19402
- gridParts.length = 0;
19403
- for (const index of gridCandidates) gridParts.push(o.parts[index]);
19404
- return gridParts;
19852
+ if (o.parts.length < PART_GRID_MIN_PARTS || !(Number.isFinite(lo[0]) && Number.isFinite(lo[1]) && Number.isFinite(lo[2]) && Number.isFinite(ld[0]) && Number.isFinite(ld[1]) && Number.isFinite(ld[2]))) return -1;
19853
+ const count = partGridOf(o).candidates(lo, ld, maxDist, gridCandidates);
19854
+ for (let i = 0; i < count; i++) {
19855
+ const p = o.parts[gridCandidates[i]];
19856
+ if (i < gridParts.length) gridParts[i] = p;
19857
+ else gridParts.push(p);
19858
+ }
19859
+ return count;
19405
19860
  };
19406
19861
  const splitInto = (o, cuts) => {
19407
19862
  const carryFor = (keep, keepOpen = () => false) => ({
@@ -19439,6 +19894,162 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19439
19894
  let uncoveredFor = { hook: null, coverage: -1, objects: -1 };
19440
19895
  const metObjects = [];
19441
19896
  const rayObjects = [];
19897
+ let objectList = [];
19898
+ let objectListFor = -1;
19899
+ const objectsInOrder = () => {
19900
+ if (objectListFor !== objectsRevision) {
19901
+ objectList = [...objects.values()];
19902
+ objectListFor = objectsRevision;
19903
+ }
19904
+ return objectList;
19905
+ };
19906
+ let implList = [];
19907
+ let implListFor = -1;
19908
+ const implsInOrder = () => {
19909
+ if (implListFor !== implsRevision) {
19910
+ implList = [...impls.values()];
19911
+ implListFor = implsRevision;
19912
+ }
19913
+ return implList;
19914
+ };
19915
+ const NO_IMPLS = [];
19916
+ const RAY_CELL = 2;
19917
+ const RAY_GRID_BIG = 4;
19918
+ const RAY_GRID_HALF = 512;
19919
+ const RAY_GRID_MAX_CELLS = 64;
19920
+ const gridCells = /* @__PURE__ */ new Map();
19921
+ const gridCentre = [0, 0, 0];
19922
+ const gridSpans = /* @__PURE__ */ new WeakMap();
19923
+ const bigObjects = [];
19924
+ let gridFor = -1;
19925
+ let gridQuery = 0;
19926
+ const gridHits = [];
19927
+ const cellOf = (v) => Math.floor(v / RAY_CELL) | 0;
19928
+ const inGrid = (c) => c >= -RAY_GRID_HALF && c < RAY_GRID_HALF;
19929
+ const cellKey2 = (ix, iy, iz) => ix + RAY_GRID_HALF + (iy + RAY_GRID_HALF) * 1024 + (iz + RAY_GRID_HALF) * 1048576 | 0;
19930
+ const cellAt = (key2) => {
19931
+ let cell = gridCells.get(key2);
19932
+ if (!cell) {
19933
+ cell = [];
19934
+ gridCells.set(key2, cell);
19935
+ }
19936
+ return cell;
19937
+ };
19938
+ const dropFrom = (list2, o) => {
19939
+ const at2 = list2.indexOf(o);
19940
+ if (at2 < 0) return;
19941
+ list2[at2] = list2[list2.length - 1];
19942
+ list2.length--;
19943
+ };
19944
+ const unplace = (o, span) => {
19945
+ if (!span.placed) return;
19946
+ span.placed = false;
19947
+ if (span.big) {
19948
+ dropFrom(bigObjects, o);
19949
+ return;
19950
+ }
19951
+ for (let iz = span.z0; iz <= span.z1; iz++) for (let iy = span.y0; iy <= span.y1; iy++) for (let ix = span.x0; ix <= span.x1; ix++) dropFrom(cellAt(cellKey2(ix, iy, iz)), o);
19952
+ };
19953
+ const place = (o) => {
19954
+ o.raySlot = slots.get(o.id) ?? 0;
19955
+ let span = gridSpans.get(o);
19956
+ const c = rotateVecInto(o.st.rotation, o.bc, gridCentre);
19957
+ c[0] += o.st.position[0];
19958
+ c[1] += o.st.position[1];
19959
+ c[2] += o.st.position[2];
19960
+ const r = o.br;
19961
+ const x0 = cellOf(c[0] - r), y0 = cellOf(c[1] - r), z0 = cellOf(c[2] - r);
19962
+ const x1 = cellOf(c[0] + r), y1 = cellOf(c[1] + r), z1 = cellOf(c[2] + r);
19963
+ const big = !(x1 - x0 < RAY_GRID_BIG && y1 - y0 < RAY_GRID_BIG && z1 - z0 < RAY_GRID_BIG) || !(inGrid(x0) && inGrid(y0) && inGrid(z0) && inGrid(x1) && inGrid(y1) && inGrid(z1));
19964
+ if (span?.placed && span.big === big && (big || span.x0 === x0 && span.y0 === y0 && span.z0 === z0 && span.x1 === x1 && span.y1 === y1 && span.z1 === z1)) return;
19965
+ if (span) unplace(o, span);
19966
+ else {
19967
+ span = { x0, y0, z0, x1, y1, z1, big, placed: false };
19968
+ gridSpans.set(o, span);
19969
+ }
19970
+ span.x0 = x0;
19971
+ span.y0 = y0;
19972
+ span.z0 = z0;
19973
+ span.x1 = x1;
19974
+ span.y1 = y1;
19975
+ span.z1 = z1;
19976
+ span.big = big;
19977
+ span.placed = true;
19978
+ if (big) {
19979
+ bigObjects.push(o);
19980
+ return;
19981
+ }
19982
+ for (let iz = z0; iz <= z1; iz++) for (let iy = y0; iy <= y1; iy++) for (let ix = x0; ix <= x1; ix++) cellAt(cellKey2(ix, iy, iz)).push(o);
19983
+ };
19984
+ const refreshGrid = () => {
19985
+ if (gridFor !== objectsRevision) {
19986
+ for (const cell of gridCells.values()) cell.length = 0;
19987
+ bigObjects.length = 0;
19988
+ const all = objectsInOrder();
19989
+ for (let i = 0; i < all.length; i++) {
19990
+ const span = gridSpans.get(all[i]);
19991
+ if (span) span.placed = false;
19992
+ place(all[i]);
19993
+ }
19994
+ for (let i = 0; i < movedObjects.length; i++) movedObjects[i].rayMoved = false;
19995
+ movedObjects.length = 0;
19996
+ gridFor = objectsRevision;
19997
+ return;
19998
+ }
19999
+ for (let i = 0; i < movedObjects.length; i++) {
20000
+ const o = movedObjects[i];
20001
+ o.rayMoved = false;
20002
+ if (objects.get(o.id) === o) place(o);
20003
+ }
20004
+ movedObjects.length = 0;
20005
+ };
20006
+ const sortBySlot = (list2, count) => {
20007
+ for (let i = 1; i < count; i++) {
20008
+ const o = list2[i];
20009
+ let j = i - 1;
20010
+ while (j >= 0 && list2[j].raySlot > o.raySlot) {
20011
+ list2[j + 1] = list2[j];
20012
+ j--;
20013
+ }
20014
+ list2[j + 1] = o;
20015
+ }
20016
+ };
20017
+ const objectsNear = (origin, d, maxDist) => {
20018
+ if (!(maxDist < Infinity)) return -1;
20019
+ const ex = origin[0] + d[0] * maxDist, ey = origin[1] + d[1] * maxDist, ez = origin[2] + d[2] * maxDist;
20020
+ const x0 = cellOf(Math.min(origin[0], ex)), y0 = cellOf(Math.min(origin[1], ey)), z0 = cellOf(Math.min(origin[2], ez));
20021
+ const x1 = cellOf(Math.max(origin[0], ex)), y1 = cellOf(Math.max(origin[1], ey)), z1 = cellOf(Math.max(origin[2], ez));
20022
+ if (!(inGrid(x0) && inGrid(y0) && inGrid(z0) && inGrid(x1) && inGrid(y1) && inGrid(z1))) return -1;
20023
+ if ((x1 - x0 + 1) * (y1 - y0 + 1) * (z1 - z0 + 1) > RAY_GRID_MAX_CELLS) return -1;
20024
+ refreshGrid();
20025
+ const stamp = ++gridQuery;
20026
+ let count = 0;
20027
+ for (let i = 0; i < bigObjects.length; i++) {
20028
+ bigObjects[i].rayStamp = stamp;
20029
+ if (count < gridHits.length) gridHits[count] = bigObjects[i];
20030
+ else gridHits.push(bigObjects[i]);
20031
+ count++;
20032
+ }
20033
+ for (let iz = z0; iz <= z1; iz++)
20034
+ for (let iy = y0; iy <= y1; iy++)
20035
+ for (let ix = x0; ix <= x1; ix++) {
20036
+ const cell = gridCells.get(cellKey2(ix, iy, iz));
20037
+ if (!cell) continue;
20038
+ for (let i = 0; i < cell.length; i++) {
20039
+ const o = cell[i];
20040
+ if (o.rayStamp === stamp) continue;
20041
+ o.rayStamp = stamp;
20042
+ if (count < gridHits.length) gridHits[count] = o;
20043
+ else gridHits.push(o);
20044
+ count++;
20045
+ }
20046
+ }
20047
+ sortBySlot(gridHits, count);
20048
+ return count;
20049
+ };
20050
+ const NO_SKIP = {};
20051
+ const rayDirections = [];
20052
+ let rayDepth = 0;
19442
20053
  const candidatesOf2 = (hook) => {
19443
20054
  const asked = hook.candidates;
19444
20055
  if (!asked) return null;
@@ -19464,15 +20075,39 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19464
20075
  }
19465
20076
  return rayObjects;
19466
20077
  };
19467
- const raycastInternal = (origin, dir, maxDist, ignore, worldOnly = false, precise = false, skip = {}, scope, drawn = false, passed) => {
19468
- const d = vec.normalize(dir);
20078
+ const raycastInternal = (origin, dir, maxDist, ignore, worldOnly = false, precise = false, skip = NO_SKIP, scope, drawn = false, passed) => {
20079
+ const into = bestInto;
20080
+ bestInto = null;
20081
+ const d = rayDirections[rayDepth] ?? (rayDirections[rayDepth] = [0, 0, 0]);
20082
+ const length = Math.sqrt(dir[0] * dir[0] + dir[1] * dir[1] + dir[2] * dir[2]);
20083
+ if (length < 1e-9) {
20084
+ d[0] = 0;
20085
+ d[1] = 1;
20086
+ d[2] = 0;
20087
+ } else {
20088
+ d[0] = dir[0] / length;
20089
+ d[1] = dir[1] / length;
20090
+ d[2] = dir[2] / length;
20091
+ }
20092
+ rayDepth++;
20093
+ try {
20094
+ return rayFrom(origin, d, maxDist, into, ignore, worldOnly, precise, skip, scope, drawn, passed);
20095
+ } finally {
20096
+ rayDepth--;
20097
+ }
20098
+ };
20099
+ const rayFrom = (origin, d, maxDist, into, ignore, worldOnly, precise, skip, scope, drawn, passed) => {
19469
20100
  const asked = rayBroad && !scope && rayBroad.begin(origin, d, maxDist) ? rayBroad : null;
19470
20101
  const candidates = asked ? candidatesOf2(asked) : null;
19471
20102
  const outside = candidates ? null : asked;
19472
20103
  const minRadius = skip.minObjectRadius ?? 0;
19473
20104
  let best = null;
19474
20105
  const counts = sweepCounts;
19475
- for (const o of scope ? scope.objects : candidates ?? objects.values()) {
20106
+ const near = scope || candidates ? -1 : objectsNear(origin, d, maxDist);
20107
+ const visited = scope ? scope.objects : candidates ?? (near >= 0 ? gridHits : objectsInOrder());
20108
+ const visitedCount = near >= 0 ? near : visited.length;
20109
+ for (let oi = 0; oi < visitedCount; oi++) {
20110
+ const o = visited[oi];
19476
20111
  if (counts) counts.objectVisits++;
19477
20112
  if (skip.skipLoose && o.loose || o.br < minRadius) continue;
19478
20113
  if (outside && !outside.mayMeet(o.id)) continue;
@@ -19487,7 +20122,12 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19487
20122
  objectOrigin[2] = origin[2] - o.st.position[2];
19488
20123
  const lo = rotateVecInto(objectTurnBack, objectOrigin, objectOrigin);
19489
20124
  const ld = rotateVecInto(objectTurnBack, d, objectDirection);
19490
- for (const p of scope?.parts.get(o) ?? (counts ? o.parts : partsAlong(o, lo, ld, maxDist))) {
20125
+ const scoped = scope?.parts.get(o);
20126
+ const gathered = scoped || counts ? -1 : partsAlong(o, lo, ld, maxDist);
20127
+ const along2 = scoped ?? (gathered >= 0 ? gridParts : o.parts);
20128
+ const alongCount = gathered >= 0 ? gathered : along2.length;
20129
+ for (let pi = 0; pi < alongCount; pi++) {
20130
+ const p = along2[pi];
19491
20131
  if (counts) counts.partVisits++;
19492
20132
  if (isLost(p) || ignore?.has(`${o.id}\0${p.spec.id}`)) continue;
19493
20133
  if (partSphereMiss(lo, ld, p, maxDist)) continue;
@@ -19496,7 +20136,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19496
20136
  counts.shapeTested.add(o.id);
19497
20137
  }
19498
20138
  const r = rayPartInto(o.st.position, o.st.rotation, p.spec, p.q, origin, d, p.pos);
19499
- if (r && r.t0 < 0 && r.t1 > 0 && p.st.chipped?.length && inGap(p, toLocal(p.pos, p.q, objLocal(o, origin)))) {
20139
+ if ((passed || skip.body) && r && r.t0 < 0 && r.t1 > 0 && p.st.chipped?.length && inGap(p, toLocal(p.pos, p.q, objLocal(o, origin)))) {
19500
20140
  r.t0 = 0;
19501
20141
  r.n = vec.scale(d, -1);
19502
20142
  }
@@ -19529,18 +20169,29 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19529
20169
  }
19530
20170
  }
19531
20171
  if (!best || r.t0 < best.distance) {
19532
- const point = vec.madd(origin, d, r.t0);
19533
- const normal = copyOf(r.n);
19534
- const member = p.castIn ? castMemberAt(o, { p, point, normal, dir: d, pathLen: r.t1 - r.t0 }, origin, d) : null;
19535
- best = member ? { object: o.id, part: member.p.spec.id, point: member.point, normal: member.normal, distance: r.t0, pathLen: member.pathLen } : { object: o.id, part: p.spec.id, point, normal, distance: r.t0, pathLen: r.t1 - r.t0 };
20172
+ if (p.castIn) {
20173
+ const point = vec.madd(origin, d, r.t0);
20174
+ const normal = copyOf(r.n);
20175
+ const member = castMemberAt(o, { p, point, normal, dir: d, pathLen: r.t1 - r.t0 }, origin, d);
20176
+ best = member ? keepBest(into, o.id, member.p.spec.id, member.point, member.normal, r.t0, member.pathLen) : keepBest(into, o.id, p.spec.id, point, normal, r.t0, r.t1 - r.t0);
20177
+ } else {
20178
+ rayPoint[0] = origin[0] + d[0] * r.t0;
20179
+ rayPoint[1] = origin[1] + d[1] * r.t0;
20180
+ rayPoint[2] = origin[2] + d[2] * r.t0;
20181
+ best = keepBest(into, o.id, p.spec.id, rayPoint, r.n, r.t0, r.t1 - r.t0);
20182
+ }
19536
20183
  }
19537
20184
  }
19538
20185
  }
19539
- for (const im of worldOnly ? [] : scope ? scope.impls : impls.values()) {
20186
+ const hosted = worldOnly ? NO_IMPLS : scope ? scope.impls : implsInOrder();
20187
+ for (let ii = 0; ii < hosted.length; ii++) {
20188
+ const im = hosted[ii];
19540
20189
  if (counts) counts.objectVisits++;
19541
20190
  if (!scope && broadPhase && rayMissesBounds(origin, d, maxDist, implBoundsOf(im))) continue;
19542
20191
  let boxHit = null;
19543
- for (const ps of scope?.implParts.get(im) ?? im.impl.describe().parts) {
20192
+ const implParts2 = scope?.implParts.get(im) ?? im.impl.describe().parts;
20193
+ for (let si = 0; si < implParts2.length; si++) {
20194
+ const ps = implParts2[si];
19544
20195
  if (counts) counts.partVisits++;
19545
20196
  if (ignore?.has(`${im.impl.id}\0${ps.id}`)) continue;
19546
20197
  if (counts) {
@@ -19561,8 +20212,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19561
20212
  const far = best ? Math.min(maxDist, best.distance) : maxDist;
19562
20213
  const implId = im.impl.id;
19563
20214
  const s = im.impl.surfaceRay({ origin, direction: d, maxDistance: far, ...ignore ? { ignored: (part) => ignore.has(`${implId}\0${part}`) } : {} });
19564
- if (s && (!best || s.distance < best.distance)) best = { object: implId, part: s.part, point: s.point, normal: s.normal, distance: s.distance, pathLen: s.pathLen };
19565
- } else if (!best || boxHit.distance < best.distance) best = boxHit;
20215
+ if (s && (!best || s.distance < best.distance)) best = keepBest(into, implId, s.part, s.point, s.normal, s.distance, s.pathLen);
20216
+ } else if (!best || boxHit.distance < best.distance) best = into ? keepBest(into, boxHit.object, boxHit.part, boxHit.point, boxHit.normal, boxHit.distance, boxHit.pathLen) : boxHit;
19566
20217
  }
19567
20218
  return best;
19568
20219
  };
@@ -20062,7 +20713,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
20062
20713
  const faceArea = (cell) => cell.size[u] * cell.size[v];
20063
20714
  const total = cells.reduce((sum, cell) => sum + faceArea(cell), 0) || 1;
20064
20715
  const shape = p.spec.units ? "chunk" : FRAGMENT_SHAPE[p.mat.fracture] ?? "chunk";
20065
- const laid = !!p.spec.units && p.spec.units.mortar !== p.spec.material;
20716
+ const laid2 = !!p.spec.units && p.spec.units.mortar !== p.spec.material;
20066
20717
  const pieces = shape === "shard" && bondedPlate(o, p) ? cells.flatMap((cell) => shardsOfCell(cell, u, v)) : cells;
20067
20718
  return pieces.map((cell, i) => {
20068
20719
  const cw = toWorld(c, q, cell.center);
@@ -20071,7 +20722,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
20071
20722
  const k = speed * (0.6 + 0.8 * rnd());
20072
20723
  const marks = marksInBox(cell.center, cell.size, void 0, holes);
20073
20724
  const size = [cell.size[0], cell.size[1], cell.size[2]];
20074
- if (laid) for (const a of [u, v]) size[a] = Math.max(size[a] * MIN_UNIT_SHARE, size[a] - MORTAR_JOINT);
20725
+ if (laid2) for (const a of [u, v]) size[a] = Math.max(size[a] * MIN_UNIT_SHARE, size[a] - MORTAR_JOINT);
20075
20726
  return {
20076
20727
  id: `${p.spec.id}#${tag}${i}`,
20077
20728
  part: p.spec.id,
@@ -20084,7 +20735,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
20084
20735
  angularVelocity: bornSpin(cell.size, 8, rnd),
20085
20736
  mass: mass * faceArea(cell) / total,
20086
20737
  ...marks.length > 0 ? { marks } : {},
20087
- ...inner && laid ? { unit: true } : inner ? { inner } : {}
20738
+ ...inner && laid2 ? { unit: true } : inner ? { inner } : {}
20088
20739
  };
20089
20740
  });
20090
20741
  };
@@ -20495,7 +21146,19 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
20495
21146
  if (p.st.stripped) bars = [...bars, ...stirrups];
20496
21147
  else for (const box4 of [...p.st.chipped ?? [], ...p.rt.bared ?? []]) bars.push(...clipBarsToVolume(stirrups, box4.center, box4.size));
20497
21148
  }
20498
- emit({ ...base2(o, src), type: "expose", part: p.spec.id, bars: worldBars(o, p, bars) });
21149
+ emit({ ...base2(o, src), type: "expose", part: p.spec.id, bars: worldBars(o, p, belowCut(p, bars)) });
21150
+ };
21151
+ const belowCut = (p, bars) => {
21152
+ const cut = p.rt.cutThrough;
21153
+ if (cut === void 0) return bars.map(([a, b]) => [a, b]);
21154
+ const height = (x) => p.pos[1] + rotateVec(p.q, x)[1];
21155
+ return bars.flatMap(([a, b]) => {
21156
+ const ha = height(a) - cut, hb = height(b) - cut;
21157
+ if (ha <= 0 && hb <= 0) return [[a, b]];
21158
+ if (ha > 0 && hb > 0) return [];
21159
+ const at2 = vec.add(a, vec.scale(vec.sub(b, a), ha / (ha - hb)));
21160
+ return [ha <= 0 ? [a, at2] : [at2, b]];
21161
+ });
20499
21162
  };
20500
21163
  const openBreach = (o, p, center, total, energy, dir, src) => {
20501
21164
  const [u, v] = planeAxes(p.thin);
@@ -20524,6 +21187,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
20524
21187
  setStage(o, p, 2, { opening: { center: worldCenter, radius }, fragments }, src);
20525
21188
  debris(o, p, p.mat.breakDebris, worldCenter, vec.scale(dir ?? [0, 1, 0], -1), 14, 3, src);
20526
21189
  dropUnsupported(o, p, src);
21190
+ dropOverOpening(o, p, src);
20527
21191
  const reinforcement = p.spec.reinforcement;
20528
21192
  if (reinforcement) exposeRebar(o, p, src);
20529
21193
  if (p.structural) solveStructure(o);
@@ -20662,7 +21326,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
20662
21326
  for (const i of out) worn[i] = -1;
20663
21327
  return knockOutUnits(o, p, point, energy, out, src);
20664
21328
  };
20665
- const knockOutUnits = (o, p, wp, energy, out, src, d, drive = CHIP_DRIVE) => {
21329
+ const knockOutUnits = (o, p, wp, energy, out, src, d, drive = CHIP_DRIVE, severed) => {
20666
21330
  var _a, _b;
20667
21331
  const [u, v] = planeAxes(p.thin);
20668
21332
  const op = p.st.opening ? toLocal(p.pos, p.q, p.st.opening.center) : null;
@@ -20707,7 +21371,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
20707
21371
  setStage(o, p, 1, {}, src);
20708
21372
  const center = toWorld(c, q, [(lo[0] + hi[0]) / 2, (lo[1] + hi[1]) / 2, (lo[2] + hi[2]) / 2]);
20709
21373
  const units = cells.map((cell) => ({ center: toWorld(c, q, cell.center), size: [cell.size[0], cell.size[1], cell.size[2]] }));
20710
- emit({ ...base2(o, src), type: "chip", part: p.spec.id, center, size: [hi[0] - lo[0], hi[1] - lo[1], hi[2] - lo[2]], rotation: q, fragments, units });
21374
+ emit({ ...base2(o, src), type: "chip", part: p.spec.id, center, size: [hi[0] - lo[0], hi[1] - lo[1], hi[2] - lo[2]], rotation: q, fragments, units, ...severed ? { severed } : {} });
20711
21375
  debris(o, p, p.mat.breakDebris, center, vec.normalize(vec.sub(center, wp), [0, 1, 0]), 14, 3, src);
20712
21376
  const cut = wornLocally(p) && cutBandsGone(o, p, cells, d ?? vec.normalize(vec.sub(partXf(o, p).c, wp), [1, 0, 0]), src);
20713
21377
  if (p.spec.reinforcement && !cut) exposeRebar(o, p, src);
@@ -20727,15 +21391,50 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
20727
21391
  const grid = gridOf(p);
20728
21392
  const gone = p.rt.chips ?? {};
20729
21393
  const worn = (_a = p.rt).bands ?? (_a.bands = {});
21394
+ const [u, v] = [0, 1, 2].filter((k) => k !== along2);
21395
+ const standing = (band) => grid.filter((cell, i) => gone[i] !== -1 && bandOf2(cell.center[along2]) === band);
21396
+ const bearOn = (a, b) => Math.abs(a.center[u] - b.center[u]) < (a.size[u] + b.size[u]) / 2 - 1e-6 && Math.abs(a.center[v] - b.center[v]) < (a.size[v] + b.size[v]) / 2 - 1e-6;
20730
21397
  for (const band of new Set(cells.map((cell) => bandOf2(cell.center[along2])))) {
20731
21398
  if ((worn[band] ?? 0) >= 1) continue;
21399
+ const left = standing(band);
20732
21400
  const center = -p.dims[along2] / 2 + (band + 0.5) * height;
20733
- if (!grid.every((cell, i) => gone[i] === -1 || Math.abs(cell.center[along2] - center) > height / 2 + 1e-6)) continue;
20734
- worn[band] = 1;
20735
- return giveAtCut(o, p, src, { at: alongAt(along2, center), d });
21401
+ if (left.length === 0) {
21402
+ worn[band] = 1;
21403
+ return giveAtCut(o, p, src, { at: alongAt(along2, center), d });
21404
+ }
21405
+ for (const next of [band - 1, band + 1]) {
21406
+ if (next < 0 || next >= bands || (worn[next] ?? 0) >= 1) continue;
21407
+ const beyond = standing(next);
21408
+ if (beyond.length === 0 || left.some((a) => beyond.some((b) => bearOn(a, b)))) continue;
21409
+ worn[band] = 1;
21410
+ worn[next] = 1;
21411
+ return giveAtCut(o, p, src, { at: alongAt(along2, (center + (-p.dims[along2] / 2 + (next + 0.5) * height)) / 2), d });
21412
+ }
20736
21413
  }
20737
21414
  return false;
20738
21415
  };
21416
+ const bedOverHoles = (o, p, grid) => {
21417
+ const bases = (o.byPart.get(p.spec.id) ?? []).filter((j) => j.bears === "a_on_b" && j.spec.a === p.spec.id && !j.st.open).map((j) => o.parts[j.ib]).filter((q) => !!q.st.opening);
21418
+ if (bases.length === 0) return void 0;
21419
+ const [, v] = planeAxes(p.thin);
21420
+ const bed = [0, 0, 0];
21421
+ return (i) => {
21422
+ const cell = grid[i];
21423
+ bed[0] = cell.center[0];
21424
+ bed[1] = cell.center[1];
21425
+ bed[2] = cell.center[2];
21426
+ bed[v] = cell.center[v] - cell.size[v] / 2;
21427
+ const at2 = toWorld(p.pos, p.q, bed);
21428
+ return !bases.some((q) => insideOpening(o, q, at2));
21429
+ };
21430
+ };
21431
+ const dropOverOpening = (o, q, src) => {
21432
+ for (const j of o.byPart.get(q.spec.id) ?? []) {
21433
+ if (j.bears !== "a_on_b" || j.spec.b !== q.spec.id || j.st.open) continue;
21434
+ const p = o.parts[j.ia];
21435
+ if (p.spec.units && !isLost(p)) dropUnsupported(o, p, src);
21436
+ }
21437
+ };
20739
21438
  const dropUnsupported = (o, p, src) => {
20740
21439
  var _a, _b;
20741
21440
  if (!p.spec.units || p.spec.units.mortar === p.spec.material || p.st.stripped || isLost(p)) return 0;
@@ -20745,7 +21444,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
20745
21444
  const op = p.st.opening ? toLocal(p.pos, p.q, p.st.opening.center) : null;
20746
21445
  const opened = (cell) => !!op && !!p.st.opening && Math.hypot(cell.center[u] - op[u], cell.center[v] - op[v]) <= p.st.opening.radius;
20747
21446
  const castHere = castCells(p);
20748
- const loose = wedgedUnder(o, p, unsupportedCells(grid, p.thin, p.dims, (i) => worn[i] !== -1 && !opened(grid[i]))).filter((i) => !castHere.has(i));
21447
+ const loose = wedgedUnder(o, p, unsupportedCells(grid, p.thin, p.dims, (i) => worn[i] !== -1 && !opened(grid[i]), bedOverHoles(o, p, grid))).filter((i) => !castHere.has(i));
20749
21448
  if (loose.length === 0) return 0;
20750
21449
  for (const i of loose) worn[i] = -1;
20751
21450
  const fallen = loose.map((i) => grid[i]);
@@ -20895,7 +21594,26 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
20895
21594
  const at2 = vec.madd(origin, d, s * vec.length(d));
20896
21595
  debris(o, p, "sparks", at2, vec.scale(d, -1), 6, 3, src);
20897
21596
  });
20898
- if (severed > 0) reyield(o, p, barsMoment(p), src);
21597
+ if (severed === 0) return;
21598
+ reyield(o, p, barsMoment(p), src);
21599
+ if (barsMoment(p) <= 0) dropAboveCut(o, p, origin, src);
21600
+ };
21601
+ const dropAboveCut = (o, p, wp, src) => {
21602
+ const cut = p.rt.hinges?.reduce((low, h) => Math.min(low, h.point[1]), Infinity) ?? Infinity;
21603
+ if (!Number.isFinite(cut)) return;
21604
+ const gone = p.rt.chips ?? {};
21605
+ const grid = gridOf(p);
21606
+ const above = grid.flatMap((cell, i) => gone[i] !== -1 && vec.add(p.pos, rotateVec(p.q, cell.center))[1] > cut ? [i] : []);
21607
+ if (above.length === 0) return;
21608
+ const ax = [rotateVec(p.q, [1, 0, 0])[1], rotateVec(p.q, [0, 1, 0])[1], rotateVec(p.q, [0, 0, 1])[1]];
21609
+ const floor = Math.min(...above.map((i) => {
21610
+ const cell = grid[i];
21611
+ return vec.add(p.pos, rotateVec(p.q, cell.center))[1] - (Math.abs(ax[0]) * cell.size[0] + Math.abs(ax[1]) * cell.size[1] + Math.abs(ax[2]) * cell.size[2]) / 2;
21612
+ }));
21613
+ p.rt.cutThrough = floor;
21614
+ const severed = { point: toWorld(o.st.position, o.st.rotation, [p.pos[0], floor, p.pos[2]]), normal: rotateVec(o.st.rotation, [0, 1, 0]) };
21615
+ knockOutUnits(o, p, wp, 0, above, src, [0, -1, 0], 0, severed);
21616
+ exposeRebar(o, p, src);
20899
21617
  };
20900
21618
  const giveAtCut = (o, p, src, cut) => {
20901
21619
  if (!p.spec.reinforcement || !p.spec.units || !p.st.chipped?.length || sectionLoss(p) <= 0) return false;
@@ -20989,7 +21707,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
20989
21707
  const unitPlan = p.spec.units ? unitFragmentPlan(p, maxFragments * UNIT_FRAGMENT_FACTOR) : [];
20990
21708
  const axis = style === "splinter" || style === "snap" ? severAxis(p) : -1;
20991
21709
  const cutAt2 = axis < 0 ? void 0 : p.rt.cutAt ?? (origin ? hitLocal[axis] : void 0);
20992
- const planRnd = p.mat.splitForm ? splitStream(o.id, p.spec.id, hitLocal) : rnd;
21710
+ const woodForm = p.mat.splitForm === "slivers" || p.mat.splitForm === "plies" || p.mat.splitForm === "granules" ? p.mat.splitForm : void 0;
21711
+ const planRnd = woodForm ? splitStream(o.id, p.spec.id, hitLocal) : rnd;
20993
21712
  const plan = unitPlan.length > 0 ? unitPlan : planFragments({
20994
21713
  style,
20995
21714
  dims: p.dims,
@@ -21000,7 +21719,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
21000
21719
  maxFragments,
21001
21720
  rnd: planRnd,
21002
21721
  sheet: p.mat.sheet,
21003
- ...p.mat.splitForm ? { form: p.mat.splitForm } : {},
21722
+ ...woodForm ? { form: woodForm } : {},
21004
21723
  ...cutAt2 !== void 0 ? { cut: { at: cutAt2, gap: SEVER_BAND } } : {},
21005
21724
  ...p.spec.solids ? { solids: p.spec.solids } : {}
21006
21725
  });
@@ -21663,7 +22382,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
21663
22382
  if (!r?.part) continue;
21664
22383
  reportShelter(o, r);
21665
22384
  out.push(r);
21666
- for (const [part, factor] of Object.entries(r.blast?.parts ?? {})) summary2.push({ object: o.id, part, factor });
22385
+ for (const [part, factor2] of Object.entries(r.blast?.parts ?? {})) summary2.push({ object: o.id, part, factor: factor2 });
21667
22386
  fragmentHits += r.blast?.fragmentHits ?? 0;
21668
22387
  }
21669
22388
  for (const im of impls.values()) {
@@ -22550,6 +23269,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
22550
23269
  finishExplosions();
22551
23270
  const id = opts.id ?? impl.id;
22552
23271
  if (taken(id)) throw new Error(`object "${id}" already exists`);
23272
+ implsRevision++;
22553
23273
  impls.set(id, { impl, position: opts.position ?? [0, 0, 0], rotation: opts.rotation ?? [0, 0, 0, 1], poses: /* @__PURE__ */ new Map(), posesVersion: 0 });
22554
23274
  return id;
22555
23275
  },
@@ -22571,6 +23291,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
22571
23291
  poseVersion++;
22572
23292
  objectPoses.set(o, (objectPoses.get(o) ?? 0) + 1);
22573
23293
  updateBound(o);
23294
+ markMoved(o);
22574
23295
  if (o.hosted && (o.hostedHosts?.has(partId) || p.spec.hostedIn !== void 0 && p.st.exposed !== true)) dirtyHosted.add(o);
22575
23296
  },
22576
23297
  remove(id) {
@@ -22580,6 +23301,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
22580
23301
  if (existing) dirtyHosted.delete(existing);
22581
23302
  dropObject(id);
22582
23303
  impls.delete(id);
23304
+ implsRevision++;
22583
23305
  },
22584
23306
  has: (id) => taken(id),
22585
23307
  ids: () => [...objects.keys(), ...impls.keys()],
@@ -22715,6 +23437,29 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
22715
23437
  const terrain = objects.get(r.object)?.parts.find((p) => p.spec.id === r.part)?.spec.tags?.includes("terrain") === true;
22716
23438
  return { object: r.object, part: r.part, point: r.point, normal: r.normal, distance: r.distance, ...terrain ? { terrain: true } : {} };
22717
23439
  },
23440
+ raycastInto(origin, direction, maxDistance, out, options2) {
23441
+ const ignoredParts = options2?.ignoreParts;
23442
+ const ignore = ignoredParts?.length ? new Set(ignoredParts.map((ignored) => `${ignored.object}\0${ignored.part}`)) : void 0;
23443
+ bestInto = bestScratch;
23444
+ let r;
23445
+ try {
23446
+ r = raycastInternal(origin, direction, maxDistance, ignore, false, true, options2);
23447
+ } finally {
23448
+ bestInto = null;
23449
+ }
23450
+ if (!r) return false;
23451
+ out.object = r.object;
23452
+ out.part = r.part;
23453
+ out.point[0] = r.point[0];
23454
+ out.point[1] = r.point[1];
23455
+ out.point[2] = r.point[2];
23456
+ out.normal[0] = r.normal[0];
23457
+ out.normal[1] = r.normal[1];
23458
+ out.normal[2] = r.normal[2];
23459
+ out.distance = r.distance;
23460
+ out.terrain = isTerrainPart(r.object, r.part);
23461
+ return true;
23462
+ },
22718
23463
  sweepBox(box4, direction, distance2, options2 = {}) {
22719
23464
  const d = vec.normalize(direction);
22720
23465
  const ignoredIds = options2.ignore === void 0 ? [] : typeof options2.ignore === "string" ? [options2.ignore] : options2.ignore;
@@ -22973,7 +23718,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
22973
23718
  ...p.spec.shape.kind === "cylinder" ? { round: true } : {}
22974
23719
  }));
22975
23720
  const joints = o.joints.filter((j) => ids.has(j.spec.a) && ids.has(j.spec.b) && (!j.st.open || lost.has(j.spec.a) || lost.has(j.spec.b))).map((j) => ({ a: j.spec.a, b: j.spec.b, kind: j.spec.kind, position: j.pos }));
22976
- return assemblyFlex({ parts: parts2, joints, lost: [...lost], ...options2?.loads ? { loads: options2.loads } : {}, ...options2?.friction !== void 0 ? { friction: options2.friction } : {} });
23721
+ return assemblyFlex({ parts: parts2, joints, lost: [...lost], ...options2?.loads ? { loads: options2.loads } : {}, ...options2?.friction !== void 0 ? { friction: options2.friction } : {}, ...options2?.linear ? { linear: options2.linear } : {} });
22977
23722
  },
22978
23723
  reset(id) {
22979
23724
  finishExplosions();
@@ -23294,17 +24039,17 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
23294
24039
  return new Map(w.state(id).parts.map((p) => [p.id, p.flexure ?? 0]));
23295
24040
  };
23296
24041
  const base2 = bending(out);
23297
- const factor = new Map(targets.map((p) => [p.id, (base2.get(p.id) ?? 0) / safetyOf(p.structure.role)]));
24042
+ const factor2 = new Map(targets.map((p) => [p.id, (base2.get(p.id) ?? 0) / safetyOf(p.structure.role)]));
23298
24043
  if (options.redundancy !== void 0) {
23299
24044
  const roles = options.redundancyRoles ?? ["column"];
23300
24045
  for (const lost of out.parts) {
23301
24046
  if (!lost.structure || !roles.includes(lost.structure.role)) continue;
23302
24047
  const l = bending(without(out, lost.id));
23303
- for (const p of targets) if (p.id !== lost.id) factor.set(p.id, Math.max(factor.get(p.id), (l.get(p.id) ?? 0) / options.redundancy));
24048
+ for (const p of targets) if (p.id !== lost.id) factor2.set(p.id, Math.max(factor2.get(p.id), (l.get(p.id) ?? 0) / options.redundancy));
23304
24049
  }
23305
24050
  }
23306
24051
  for (const p of targets) {
23307
- const f = factor.get(p.id);
24052
+ const f = factor2.get(p.id);
23308
24053
  const g = bendGeometry(p);
23309
24054
  if (f <= 1 || g.gravity < 0) continue;
23310
24055
  const section = { b: sectionWidth(g, g.gravity), h: g.dims[g.gravity] };
@@ -24215,6 +24960,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
24215
24960
  else slab.y0 = round2(slab.y1 - thickness);
24216
24961
  slab.mass = Math.max(1, Math.round((slab.aabb[2] - slab.aabb[0]) * (slab.aabb[3] - slab.aabb[1]) * (slab.y1 - slab.y0) * densityOf(slab.material)));
24217
24962
  };
24963
+ function footprintWithin(leaf, footprint) {
24964
+ const out = [];
24965
+ for (const r of footprint) {
24966
+ const cut = [Math.max(leaf[0], r[0]), Math.max(leaf[1], r[1]), Math.min(leaf[2], r[2]), Math.min(leaf[3], r[3])];
24967
+ if (cut[2] - cut[0] > 1e-6 && cut[3] - cut[1] > 1e-6) out.push(cut);
24968
+ }
24969
+ return out;
24970
+ }
24218
24971
  function cutSlab(context, slab, wallBoxes) {
24219
24972
  const { options } = context;
24220
24973
  const roof = slab.cover === true;
@@ -24243,7 +24996,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
24243
24996
  floor: slab.floor,
24244
24997
  ...slab.cover ? { cover: true } : {},
24245
24998
  slab: slab.id,
24246
- ...slab.footprint ? { footprint: slab.footprint } : {}
24999
+ ...slab.footprint ? { footprint: footprintWithin(leaf, slab.footprint) } : {}
24247
25000
  })
24248
25001
  );
24249
25002
  context.parts.splice(context.parts.indexOf(slab), 1, ...panels);
@@ -24728,7 +25481,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
24728
25481
  return spec;
24729
25482
  };
24730
25483
  var MEMBER_CAGE = { spacing: 0.1, diameter: 0.01, unit: 0.1 };
24731
- var CAGED_ROLES = /* @__PURE__ */ new Set(["beam", "column"]);
25484
+ var CAGED_ROLES = /* @__PURE__ */ new Set(["beam", "column", "slab"]);
24732
25485
  var CAGE_COVER = 0.03;
24733
25486
  var CAGE_BUCKLING_SHARE = 0.5;
24734
25487
  var DEFAULT_RESIDUAL = 0.15;
@@ -25006,15 +25759,15 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25006
25759
  const pier = (clear - win) / 2;
25007
25760
  const at2 = (u) => along2 === 0 ? [u, 0, fixed] : [fixed, 0, u];
25008
25761
  const size = (u, h) => along2 === 0 ? [u, h, c.thickness] : [c.thickness, h, u];
25009
- const put = (name, u, h, y, centreU, on) => {
25762
+ const put2 = (name, u, h, y, centreU, on) => {
25010
25763
  const p = at2(centreU);
25011
25764
  wall(`infill_${f}_${side}_${k}_${name}`, size(u, h), [p[0], y, p[2]], on);
25012
25765
  };
25013
25766
  const id = (name) => `infill_${f}_${side}_${k}_${name}`;
25014
- put("sill", clear, sill, yb + sill / 2, centre2, [c1, c2]);
25015
- put("pl", pier, head - sill, yb + sill + (head - sill) / 2, centre2 - clear / 2 + pier / 2, [c1, id("sill")]);
25016
- put("pr", pier, head - sill, yb + sill + (head - sill) / 2, centre2 + clear / 2 - pier / 2, [c2, id("sill")]);
25017
- put("head", clear, room - head, yb + head + (room - head) / 2, centre2, [c1, c2]);
25767
+ put2("sill", clear, sill, yb + sill / 2, centre2, [c1, c2]);
25768
+ put2("pl", pier, head - sill, yb + sill + (head - sill) / 2, centre2 - clear / 2 + pier / 2, [c1, id("sill")]);
25769
+ put2("pr", pier, head - sill, yb + sill + (head - sill) / 2, centre2 + clear / 2 - pier / 2, [c2, id("sill")]);
25770
+ put2("head", clear, room - head, yb + head + (room - head) / 2, centre2, [c1, c2]);
25018
25771
  const gp = at2(centre2);
25019
25772
  const gid = `glass_${f}_${side}_${k}`;
25020
25773
  parts2.push({
@@ -25104,24 +25857,24 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25104
25857
  const floor = `slab_${level - 1}`;
25105
25858
  const y = storeyBase(g, level);
25106
25859
  const shafts = options.shafts ?? [];
25107
- const put = (id, material, size, at2, mass, extra = {}) => {
25860
+ const put2 = (id, material, size, at2, mass, extra = {}) => {
25108
25861
  parts2.push({ id: id + sfx, material, shape: box3(size), position: [at2[0], y + size[1] / 2, at2[1]], mass, fill: 0.2, structure: { role: "partition" }, tags: ["mechanical"], ...extra });
25109
25862
  rests(joints, id + sfx, floor, "bolt");
25110
25863
  };
25111
- shafts.forEach((at2, k) => put(`machine_${k}`, "steel", [1.2, 1, 0.8], at2, c.machineMass + c.suspendedMass, { tags: ["mechanical", "elevator_machine"] }));
25864
+ shafts.forEach((at2, k) => put2(`machine_${k}`, "steel", [1.2, 1, 0.8], at2, c.machineMass + c.suspendedMass, { tags: ["mechanical", "elevator_machine"] }));
25112
25865
  const liters = options.waterLiters ?? towerWater(level, options);
25113
25866
  const depth = 2;
25114
25867
  const side = Math.sqrt(liters / 1e3 / depth);
25115
25868
  const [hx] = slabHalf(g);
25116
25869
  const tankAt = options.tankAt ?? [-hx / 2, 0];
25117
25870
  const shell = 4 * side * depth + 2 * side * side;
25118
- put("water_tank", c.tankMaterial, [side, depth, side], tankAt, liters + 1100 * c.tankWall * shell, {
25871
+ put2("water_tank", c.tankMaterial, [side, depth, side], tankAt, liters + 1100 * c.tankWall * shell, {
25119
25872
  fill: shell * c.tankWall / (side * side * depth),
25120
25873
  thickness: c.tankWall,
25121
25874
  contains: { fluid: "water", liters },
25122
25875
  tags: ["mechanical", "water_tank"]
25123
25876
  });
25124
- for (let k = 0; k < c.chillers; k++) put(`chiller_${k}`, "steel", [3, 2, 1.5], [-hx + 2 + k * 3.5, -(slabHalf(g)[1] - 2)], c.chillerMass, { tags: ["mechanical", "chiller"] });
25877
+ for (let k = 0; k < c.chillers; k++) put2(`chiller_${k}`, "steel", [3, 2, 1.5], [-hx + 2 + k * 3.5, -(slabHalf(g)[1] - 2)], c.chillerMass, { tags: ["mechanical", "chiller"] });
25125
25878
  return { ...spec, parts: parts2, joints };
25126
25879
  }
25127
25880
  var DAMPER_DEFAULTS = { ratio: 0.01, modalShare: 0.25, material: "steel", maxHeight: 2.5 };
@@ -36773,7 +37526,20 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
36773
37526
  stack: 6,
36774
37527
  shape: "cup",
36775
37528
  color: 14215408,
36776
- rarity: "common"
37529
+ rarity: "common",
37530
+ parts: [
37531
+ {
37532
+ id: "body",
37533
+ material: "glass",
37534
+ thickness: 3e-3
37535
+ }
37536
+ ],
37537
+ container: {
37538
+ capacityLiters: 0.3
37539
+ },
37540
+ estimated: [
37541
+ "container"
37542
+ ]
36777
37543
  },
36778
37544
  {
36779
37545
  id: "cutlery",
@@ -37024,8 +37790,17 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
37024
37790
  }
37025
37791
  ],
37026
37792
  estimated: [
37027
- "parts"
37028
- ]
37793
+ "parts",
37794
+ "consumable"
37795
+ ],
37796
+ consumable: {
37797
+ form: "liquid",
37798
+ unit: "ml",
37799
+ amount: 450,
37800
+ dose: 5,
37801
+ emptyKg: 0.03,
37802
+ density: 1.03
37803
+ }
37029
37804
  },
37030
37805
  {
37031
37806
  id: "bleach",
@@ -38515,8 +39290,12 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
38515
39290
  thickness: 2e-3
38516
39291
  }
38517
39292
  ],
39293
+ container: {
39294
+ capacityLiters: 0.35
39295
+ },
38518
39296
  estimated: [
38519
- "parts"
39297
+ "parts",
39298
+ "container"
38520
39299
  ]
38521
39300
  },
38522
39301
  {
@@ -38663,6 +39442,41 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
38663
39442
  },
38664
39443
  weapon: "brass_knuckles",
38665
39444
  model: "brass_knuckles"
39445
+ },
39446
+ {
39447
+ id: "plunger",
39448
+ category: "tools",
39449
+ kind: "tool",
39450
+ tags: [
39451
+ "cleaning"
39452
+ ],
39453
+ tools: [
39454
+ "plunger"
39455
+ ],
39456
+ size: [
39457
+ 0.14,
39458
+ 0.55,
39459
+ 0.14
39460
+ ],
39461
+ weight: 0.45,
39462
+ stack: 1,
39463
+ shape: "tool",
39464
+ color: 11545120,
39465
+ rarity: "common",
39466
+ finds: {
39467
+ places: [
39468
+ "house",
39469
+ "apartment"
39470
+ ]
39471
+ },
39472
+ parts: [
39473
+ {
39474
+ id: "body",
39475
+ material: "rubber",
39476
+ thickness: 4e-3
39477
+ }
39478
+ ],
39479
+ model: "plunger"
38666
39480
  }
38667
39481
  ];
38668
39482
  var kinds_default = [
@@ -40346,6 +41160,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
40346
41160
  "alicate"
40347
41161
  ]
40348
41162
  },
41163
+ plunger: {
41164
+ created: true,
41165
+ idSource: "decision",
41166
+ sizeSource: "REF",
41167
+ vc3: [
41168
+ "desentupidor"
41169
+ ]
41170
+ },
40349
41171
  adjustable_wrench: {
40350
41172
  ite: "chave_inglesa",
40351
41173
  idSource: "decision",
@@ -43472,14 +44294,18 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
43472
44294
  var ITEM_CONTRACTS = createItemContracts();
43473
44295
  var createGoodsKinds = (options = {}) => defineCategories(GOODS_KINDS, options);
43474
44296
  var KINDS2 = createGoodsKinds();
43475
- var withSeal = (item) => {
44297
+ var withKind = (item) => {
43476
44298
  const kind = item.kind;
43477
- const seal = kind && KINDS2.has(kind) ? KINDS2.defaults(kind).seal : void 0;
43478
- return seal ? { ...item, seal: { ...seal, ...item.seal } } : item;
44299
+ if (!kind || !KINDS2.has(kind)) return item;
44300
+ const defaults = KINDS2.defaults(kind);
44301
+ const seal = defaults.seal;
44302
+ const parts2 = defaults.parts;
44303
+ const own = item.parts;
44304
+ return { ...item, ...seal ? { seal: { ...seal, ...item.seal } } : {}, ...!own && parts2 ? { parts: parts2 } : {} };
43479
44305
  };
43480
44306
  var goodsPack = {
43481
44307
  id: "goods",
43482
- items: GOODS_ITEMS.map(withSeal),
44308
+ items: GOODS_ITEMS.map(withKind),
43483
44309
  categories: GOODS_CATEGORIES,
43484
44310
  places: GOODS_PLACES,
43485
44311
  containers: GOODS_CONTAINERS,
@@ -43761,6 +44587,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
43761
44587
  "item.toothbrush": "Toothbrush",
43762
44588
  "item.deodorant": "Deodorant",
43763
44589
  "item.toilet_paper": "Toilet paper",
44590
+ "item.plunger": "Toilet plunger",
43764
44591
  "item.towel": "Towel",
43765
44592
  "item.detergent": "Detergent",
43766
44593
  "item.bleach": "Bleach",
@@ -44269,6 +45096,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
44269
45096
  "item.toothbrush": "Escova de dente",
44270
45097
  "item.deodorant": "Desodorante",
44271
45098
  "item.toilet_paper": "Papel higi\xEAnico",
45099
+ "item.plunger": "Desentupidor",
44272
45100
  "item.towel": "Toalha",
44273
45101
  "item.detergent": "Detergente",
44274
45102
  "item.bleach": "\xC1gua sanit\xE1ria",
@@ -44569,7 +45397,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
44569
45397
  },
44570
45398
  toilet: {
44571
45399
  body: { material: "ceramic", joint: "bolt" },
44572
- parts: [["lid", door("plastic", "hinge", "lid")], ["flush_button", { material: "plastic", joint: "clip", piece: "button" }]]
45400
+ parts: [["lid", door("plastic", "hinge", "lid")], ["seat_ring", door("plastic", "hinge", "lid")], ["flush_button", { material: "plastic", joint: "clip", piece: "button" }]]
44573
45401
  },
44574
45402
  wall_socket: { body: { material: "plastic", joint: "screw" }, parts: [] },
44575
45403
  wall_switch: { body: { material: "plastic", joint: "screw" }, parts: [["rocker", { material: "plastic", joint: "clip", piece: "rocker" }]] },
@@ -44738,6 +45566,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
44738
45566
  "prompt.toilet_lid": "Toilet lid",
44739
45567
  "prompt.toilet_lid.open": "Close the lid",
44740
45568
  "prompt.toilet_lid.closed": "Lift the lid",
45569
+ "prompt.toilet_seat": "Toilet seat",
45570
+ "prompt.toilet_seat.open": "Lower the seat",
45571
+ "prompt.toilet_seat.closed": "Lift the seat",
44741
45572
  "prompt.switch": "Light switch",
44742
45573
  "prompt.switch.on": "Switch off",
44743
45574
  "prompt.switch.on.verb": "Switch off",
@@ -44996,6 +45827,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
44996
45827
  "prompt.toilet_lid": "Tampa do vaso",
44997
45828
  "prompt.toilet_lid.open": "Fechar a tampa",
44998
45829
  "prompt.toilet_lid.closed": "Levantar a tampa",
45830
+ "prompt.toilet_seat": "Assento do vaso",
45831
+ "prompt.toilet_seat.open": "Abaixar o assento",
45832
+ "prompt.toilet_seat.closed": "Levantar o assento",
44999
45833
  "prompt.switch": "Interruptor",
45000
45834
  "prompt.switch.on": "Desligar a luz",
45001
45835
  "prompt.switch.on.verb": "Desligar",
@@ -45816,6 +46650,25 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
45816
46650
  }
45817
46651
  ];
45818
46652
  var WALL_PLATE = { width: 0.075, height: 0.12, thickness: 0.012, sink: 5e-3 };
46653
+ var DIRTY_PLATE = 0.8;
46654
+ var DIRTY_CUP = 0.5;
46655
+ var DIRTY_CUTLERY = 0.6;
46656
+ function goodsSize(id) {
46657
+ const item = GOODS_ITEMS.find((candidate) => candidate.id === id);
46658
+ if (!item) throw new Error(`game-interactables-household: the sinks lay "${id}", which the goods catalogue does not have`);
46659
+ return [item.size[0], item.size[1], item.size[2]];
46660
+ }
46661
+ var laid = (type, data) => ({ stack: { type, qty: 1, ...data ? { data } : {} }, size: goodsSize(type) });
46662
+ var DIRTY_DISHES = [
46663
+ laid("plate", { dirt: DIRTY_PLATE }),
46664
+ laid("cup", { dirt: DIRTY_CUP }),
46665
+ laid("cutlery", { dirt: DIRTY_CUTLERY })
46666
+ ];
46667
+ var WASHING_THINGS = [
46668
+ laid("detergent"),
46669
+ laid("sponge"),
46670
+ laid("cup")
46671
+ ];
45819
46672
  var DEFS2 = types_default;
45820
46673
  var HOUSEHOLD_ITEMS = GOODS_ITEMS.filter((item) => GOODS_PROVENANCE[item.id]?.household !== void 0);
45821
46674
  var itemTexts = (locale) => Object.fromEntries(HOUSEHOLD_ITEMS.map((item) => [`item.${item.id}`, GOODS_STRINGS[locale][`item.${item.id}`] ?? item.id]));
@@ -47083,7 +47936,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
47083
47936
  worlds.set(world, info);
47084
47937
  return world;
47085
47938
  }
47086
- function pointOf2(world, fixtureId) {
47939
+ function pointOf3(world, fixtureId) {
47087
47940
  const info = worlds.get(world);
47088
47941
  return info ? info.points.get(fixtureId) : void 0;
47089
47942
  }
@@ -47224,7 +48077,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
47224
48077
  if (info) for (const f of planned.fixtures) info.points.set(f.global, f.point);
47225
48078
  return out;
47226
48079
  }
47227
- return { version: ADAPTER_VERSION, household: hh, plan, createWorld, add, blockedOf, pointOf: pointOf2, ownSpec, registries: { typeMap, contentMap, contentByGroup, chairTables, fixturesOfPoint, substitutes, preference, ownTypes } };
48080
+ return { version: ADAPTER_VERSION, household: hh, plan, createWorld, add, blockedOf, pointOf: pointOf3, ownSpec, registries: { typeMap, contentMap, contentByGroup, chairTables, fixturesOfPoint, substitutes, preference, ownTypes } };
47228
48081
  }
47229
48082
  var FloorplanInteractables = { version: ADAPTER_VERSION, create: create2, TYPE_MAP, CONTENT_MAP, CONTENT_BY_GROUP, CHAIR_TABLES, PREFERENCE, mergeRegistry };
47230
48083
 
@@ -47304,21 +48157,21 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
47304
48157
  { type: "buffet", category: "buffet", w: 1.6, d: 0.5, h: 0.9, opening: 0.45 },
47305
48158
  { type: "china_cabinet", category: "china_cabinet", w: 1.2, d: 0.45, h: 2, opening: 0.45 },
47306
48159
  { type: "stairs", category: "stairs", w: 1, d: 3.2, h: 2.8 },
47307
- { type: "planter_bed", category: "planter_bed", w: 3, d: 0.7, h: 0.4, color: { role: "dirt" } },
47308
- { type: "planter_bed_small", category: "planter_bed", w: 1.8, d: 0.6, h: 0.4, color: { role: "dirt" } },
48160
+ { type: "planter_bed", category: "planter_bed", w: 3, d: 0.7, h: 0.4, color: { role: "dirt" }, material: "concrete" },
48161
+ { type: "planter_bed_small", category: "planter_bed", w: 1.8, d: 0.6, h: 0.4, color: { role: "dirt" }, material: "concrete" },
47309
48162
  { type: "tree_small", category: "tree", w: 1.2, d: 1.2, h: 3, color: { role: "lawn" } },
47310
48163
  { type: "tree_large", category: "tree_large", w: 3, d: 3, h: 6, color: { role: "lawn" } },
47311
- { type: "shrub", category: "shrub", w: 0.8, d: 0.8, h: 0.9, color: { role: "lawn" } },
47312
- { type: "outdoor_pot", category: "outdoor_pot", w: 0.5, d: 0.5, h: 0.7 },
47313
- { type: "fountain", category: "fountain", w: 2, d: 2, h: 1.2 },
48164
+ { type: "shrub", category: "shrub", w: 0.8, d: 0.8, h: 0.9, color: { role: "lawn" }, material: "foliage" },
48165
+ { type: "outdoor_pot", category: "outdoor_pot", w: 0.5, d: 0.5, h: 0.7, material: "ceramic" },
48166
+ { type: "fountain", category: "fountain", w: 2, d: 2, h: 1.2, material: "concrete" },
47314
48167
  { type: "garden_bench", category: "garden_bench", w: 1.5, d: 0.5, h: 0.5 },
47315
48168
  { type: "clothesline", category: "clothesline", w: 3.6, d: 0.4, h: 2 },
47316
48169
  { type: "bbq_grill", category: "bbq_grill", w: 1, d: 0.7, h: 1.4 },
47317
48170
  { type: "outbuilding", category: "outbuilding", w: 3.2, d: 3, h: 2.6 },
47318
48171
  { type: "doghouse", category: "doghouse", w: 0.6, d: 0.8, h: 0.7 },
47319
48172
  { type: "water_tank", category: "water_tank", w: 1, d: 1, h: 1.8 },
47320
- { type: "pool", category: "pool", w: 7, d: 3.5, h: 0, rim: 1.2, color: { role: "water" } },
47321
- { type: "pool_large", category: "pool", w: 9, d: 4.5, h: 0, rim: 1.2, color: { role: "water" } },
48173
+ { type: "pool", category: "pool", w: 7, d: 3.5, h: 0, rim: 1.2, color: { role: "water" }, material: "concrete" },
48174
+ { type: "pool_large", category: "pool", w: 9, d: 4.5, h: 0, rim: 1.2, color: { role: "water" }, material: "concrete" },
47322
48175
  { type: "sun_lounger", category: "sun_lounger", w: 0.7, d: 2, h: 0.4, deck: true },
47323
48176
  { type: "outdoor_table", category: "outdoor_table", w: 1.6, d: 1, h: 0.75, deck: true },
47324
48177
  { type: "gas_cylinder", category: "gas_cylinder", w: 0.35, d: 0.35, h: 0.6 },
@@ -47328,12 +48181,12 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
47328
48181
  { type: "track_spot", category: "ceiling_light", w: 0.6, d: 0.1, h: 0.12, decor: true, mount: "ceiling", color: { role: "metal" } },
47329
48182
  { type: "chandelier", category: "ceiling_light", w: 0.7, d: 0.7, h: 0.6, decor: true, mount: "ceiling", color: { role: "metal" } },
47330
48183
  { type: "wall_ac", category: "air_conditioner", w: 0.9, d: 0.25, h: 0.28, decor: true, mount: "wall", color: { role: "ceiling" } },
47331
- { type: "ac_condenser", category: "ac_condenser", w: 0.8, d: 0.35, h: 0.6, decor: true, mount: "floor", color: { role: "ceiling" } },
48184
+ { type: "ac_condenser", category: "ac_condenser", w: 0.8, d: 0.35, h: 0.6, decor: true, mount: "floor", color: { role: "ceiling" }, material: "steel" },
47332
48185
  { type: "picture_small", category: "picture", w: 0.4, d: 0.03, h: 0.5, decor: true, mount: "wall", color: { role: "picture_accent" } },
47333
48186
  { type: "picture_large", category: "picture", w: 0.9, d: 0.03, h: 0.6, decor: true, mount: "wall", color: { role: "picture_accent" } },
47334
- { type: "mirror", category: "picture", w: 0.6, d: 0.03, h: 0.9, decor: true, mount: "wall", color: { role: "metal" } },
47335
- { type: "floor_plant", category: "plant", w: 0.4, d: 0.4, h: 0.9, decor: true, mount: "floor", color: { role: "lawn" } },
47336
- { type: "table_plant", category: "plant", w: 0.2, d: 0.2, h: 0.3, decor: true, mount: "support", color: { role: "lawn" } },
48187
+ { type: "mirror", category: "picture", w: 0.6, d: 0.03, h: 0.9, decor: true, mount: "wall", color: { role: "metal" }, material: "glass" },
48188
+ { type: "floor_plant", category: "plant", w: 0.4, d: 0.4, h: 0.9, decor: true, mount: "floor", color: { role: "lawn" }, material: "ceramic" },
48189
+ { type: "table_plant", category: "plant", w: 0.2, d: 0.2, h: 0.3, decor: true, mount: "support", color: { role: "lawn" }, material: "ceramic" },
47337
48190
  { type: "mailbox", category: "mailbox", w: 0.35, d: 0.3, h: 0.3, decor: true, mount: "wall_top", color: { role: "metal" } },
47338
48191
  { type: "table_lamp", category: "table_light", w: 0.36, d: 0.36, h: 0.5, decor: true, mount: "support", powered: true },
47339
48192
  { type: "hanging_plant", category: "plant", w: 0.3, d: 0.3, h: 0.7, decor: true, mount: "ceiling", color: { role: "lawn" } },
@@ -47348,11 +48201,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
47348
48201
  { type: "gourmet_counter_small", category: "gourmet", w: 1.8, d: 0.65, h: 1, window: true, equip: ["bbq_grill", "kitchen_cabinet"] },
47349
48202
  { type: "gourmet_table", category: "gourmet", w: 2.8, d: 0.9, h: 0.78 },
47350
48203
  { type: "gourmet_table_small", category: "gourmet", w: 1.2, d: 0.9, h: 0.78 },
47351
- { type: "pool_small", category: "pool", w: 5, d: 2.6, h: 0, rim: 1.2, color: { role: "water" } },
47352
- { type: "pool_medium", category: "pool", w: 6, d: 3, h: 0, rim: 1.2, color: { role: "water" } },
48204
+ { type: "pool_small", category: "pool", w: 5, d: 2.6, h: 0, rim: 1.2, color: { role: "water" }, material: "concrete" },
48205
+ { type: "pool_medium", category: "pool", w: 6, d: 3, h: 0, rim: 1.2, color: { role: "water" }, material: "concrete" },
47353
48206
  { type: "deck", category: "deck", w: 3, d: 2, h: 0.15, flat: true, deck: true, color: { role: "deck_floor" } },
47354
- { type: "garden_bed", category: "garden_bed", w: 2, d: 0.8, h: 0.3, color: { role: "dirt" } },
47355
- { type: "fruit_tree", category: "tree", w: 2.2, d: 2.2, h: 3.5, color: { role: "lawn" } },
48207
+ { type: "garden_bed", category: "garden_bed", w: 2, d: 0.8, h: 0.3, color: { role: "dirt" }, material: "concrete" },
48208
+ { type: "fruit_tree", category: "tree", w: 2.2, d: 2.2, h: 3.5, color: { role: "lawn" }, material: "foliage" },
47356
48209
  { type: "palm_tree", category: "tree", w: 1.2, d: 1.2, h: 4, color: { role: "lawn" } },
47357
48210
  { type: "pergola", category: "pergola", w: 3.6, d: 3.2, h: 2.4, flat: true, mount: "roof", color: { role: "deck_floor" } },
47358
48211
  { type: "bbq_simple", category: "bbq_simple", w: 0.8, d: 0.6, h: 1.2 },
@@ -48419,7 +49272,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48419
49272
  }
48420
49273
  var residentialTower = residentialTowerTemplate();
48421
49274
 
48422
- // ../game-floorplan-three/dist/chunk-RW7ZTU76.js
49275
+ // ../game-floorplan-three/dist/chunk-KOJFBQRC.js
48423
49276
  var __defProp3 = Object.defineProperty;
48424
49277
  var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp3(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
48425
49278
  var __publicField = (obj, key2, value) => __defNormalProp(obj, typeof key2 !== "symbol" ? key2 + "" : key2, value);
@@ -48429,6 +49282,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48429
49282
  "prompt.lockedDoor": "E: locked door",
48430
49283
  "prompt.lightOn": "E: turn on the light",
48431
49284
  "prompt.lightOff": "E: turn off the light",
49285
+ "prompt.sit": "E: sit",
49286
+ "prompt.lie": "E: lie down",
48432
49287
  "what.door": "the door",
48433
49288
  "what.curtain": "the curtain",
48434
49289
  "what.mailbox": "the mailbox",
@@ -48455,6 +49310,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48455
49310
  "prompt.lockedDoor": "E: porta trancada",
48456
49311
  "prompt.lightOn": "E: acender a luz",
48457
49312
  "prompt.lightOff": "E: apagar a luz",
49313
+ "prompt.sit": "E: sentar",
49314
+ "prompt.lie": "E: deitar",
48458
49315
  "what.door": "a porta",
48459
49316
  "what.curtain": "a cortina",
48460
49317
  "what.mailbox": "a caixa de correio",
@@ -48509,13 +49366,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48509
49366
  return out;
48510
49367
  }
48511
49368
  function exclusiveBoxes(solids) {
48512
- const laid = [];
49369
+ const laid2 = [];
48513
49370
  for (const solid of solids) {
48514
49371
  let pieces = [solid.box];
48515
- for (const before of laid) pieces = pieces.flatMap((piece22) => subtractBox(piece22, before.box));
48516
- for (const box4 of pieces) laid.push({ ...solid, box: box4 });
49372
+ for (const before of laid2) pieces = pieces.flatMap((piece22) => subtractBox(piece22, before.box));
49373
+ for (const box4 of pieces) laid2.push({ ...solid, box: box4 });
48517
49374
  }
48518
- return laid;
49375
+ return laid2;
48519
49376
  }
48520
49377
  function outsideBoxes(box4, taken) {
48521
49378
  let pieces = [box4];
@@ -48706,7 +49563,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48706
49563
  try {
48707
49564
  for (const { b, shut } of pieces) {
48708
49565
  shutFaces = shut;
48709
- put(mat, "box", (b[0] + b[3]) / 2, (b[1] + b[4]) / 2, (b[2] + b[5]) / 2, _qi, b[3] - b[0], b[4] - b[1], b[5] - b[2], color2);
49566
+ put2(mat, "box", (b[0] + b[3]) / 2, (b[1] + b[4]) / 2, (b[2] + b[5]) / 2, _qi, b[3] - b[0], b[4] - b[1], b[5] - b[2], color2);
48710
49567
  }
48711
49568
  } finally {
48712
49569
  shared2.ctx.keepOut = taken.length ? taken : void 0;
@@ -48715,7 +49572,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48715
49572
  }
48716
49573
  return true;
48717
49574
  }
48718
- function put(mat, geo, px, py, pz, q, sx, sy, sz, color2, uvr) {
49575
+ function put2(mat, geo, px, py, pz, q, sx, sy, sz, color2, uvr) {
48719
49576
  if ((shared2.ctx.keepOut || shared2.ctx.itemBoxes) && geo === "box" && !uvr && keptOut(mat, px, py, pz, q, sx, sy, sz, color2)) return;
48720
49577
  if (shared2.ctx.blockBoxes && geo === "box" && mat !== "emissive" && mat !== "glass" && Math.abs(q.x) + Math.abs(q.y) + Math.abs(q.z) < 1e-9) shared2.ctx.blockBoxes.push([px - sx / 2, py - sy / 2, pz - sz / 2, px + sx / 2, py + sy / 2, pz + sz / 2]);
48721
49578
  {
@@ -48809,16 +49666,16 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48809
49666
  function boxC(mat, cx, cy, cz, sx, sy, sz, color2, rx = 0, ry = 0, rz = 0, uvr) {
48810
49667
  if (rx || ry || rz) _q.setFromEuler(_e.set(rx, ry, rz, "YXZ"));
48811
49668
  else _q.identity();
48812
- put(mat, "box", cx, cy, cz, _q, sx, sy, sz, color2, uvr);
49669
+ put2(mat, "box", cx, cy, cz, _q, sx, sy, sz, color2, uvr);
48813
49670
  }
48814
49671
  function bxBase(mat, x0, y0, z0, x1, y1, z1, color2) {
48815
49672
  if (x1 - x0 < 1e-4 || y1 - y0 < 1e-4 || z1 - z0 < 1e-4) return;
48816
49673
  _q.identity();
48817
- put(mat, "box", (x0 + x1) / 2, (y0 + y1) / 2, (z0 + z1) / 2, _q, x1 - x0, y1 - y0, z1 - z0, color2);
49674
+ put2(mat, "box", (x0 + x1) / 2, (y0 + y1) / 2, (z0 + z1) / 2, _q, x1 - x0, y1 - y0, z1 - z0, color2);
48818
49675
  }
48819
49676
  function cylBase(mat, x, y, z, r, h, color2, seg2 = "cyl") {
48820
49677
  _q.identity();
48821
- put(mat, seg2, x, y + h / 2, z, _q, r * 2, h, r * 2, color2);
49678
+ put2(mat, seg2, x, y + h / 2, z, _q, r * 2, h, r * 2, color2);
48822
49679
  }
48823
49680
  function polyFace(mat, pts, color2, hint) {
48824
49681
  const A = accFor(mat), n = pts.length, O = cursor.org, RY = cursor.ry;
@@ -48882,7 +49739,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48882
49739
  const setBx = (f) => {
48883
49740
  bxImpl = f;
48884
49741
  };
48885
- const defined = { GEO, UV_SCALE, WITH_MAP, Accumulator, cursor, PARTS, MIRRORS, part, applyPart, _Y, _qa, _qb, pieceRecord, structurePiece, accFor, _q, _e, _col, rgbOf, put, boxC, bx, getBx, setBx, cylBase, polyFace };
49742
+ const defined = { GEO, UV_SCALE, WITH_MAP, Accumulator, cursor, PARTS, MIRRORS, part, applyPart, _Y, _qa, _qb, pieceRecord, structurePiece, accFor, _q, _e, _col, rgbOf, put: put2, boxC, bx, getBx, setBx, cylBase, polyFace };
48886
49743
  Object.assign(K, defined);
48887
49744
  }
48888
49745
  function installKernelNoise(K, _shared) {
@@ -50977,7 +51834,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
50977
51834
  Object.assign(K, defined);
50978
51835
  }
50979
51836
  function installRoofTiles(K, shared2) {
50980
- const { UV_SCALE, _Y, _h2, _q, accFor, cursor, put, rgbOf, structurePiece } = K;
51837
+ const { UV_SCALE, _Y, _h2, _q, accFor, cursor, put: put2, rgbOf, structurePiece } = K;
50981
51838
  const sh = (...a) => K.sh(...a);
50982
51839
  const R_STYLE = () => shared2.ctx.r && shared2.ctx.r.style || "budget";
50983
51840
  function tileRelief(mat, pts, color2, type, origin) {
@@ -51115,10 +51972,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
51115
51972
  const colonial = type !== "fiber_cement", r = colonial ? 0.085 : 0.075, c = sh(roofColor, colonial ? 0.82 : 0.9), lift = colonial ? 0.05 : 0.035;
51116
51973
  _q.setFromUnitVectors(_Y, K._v3.set(dx / Ln, dy / Ln, dz / Ln));
51117
51974
  const mx = (a[0] + b[0]) / 2, my = (a[1] + b[1]) / 2 + lift, mz = (a[2] + b[2]) / 2;
51118
- put("plain", colonial ? "cyl" : "cyl6", mx, my, mz, _q, r * 2, Ln, r * 2, c);
51975
+ put2("plain", colonial ? "cyl" : "cyl6", mx, my, mz, _q, r * 2, Ln, r * 2, c);
51119
51976
  if (colonial) for (let t = 0.25; t < Ln - 0.1; t += 0.42) {
51120
51977
  const f = t / Ln;
51121
- put("plain", "cyl", a[0] + dx * f, a[1] + dy * f + lift, a[2] + dz * f, _q, r * 2.25, 0.035, r * 2.25, sh(c, 0.7));
51978
+ put2("plain", "cyl", a[0] + dx * f, a[1] + dy * f + lift, a[2] + dz * f, _q, r * 2.25, 0.035, r * 2.25, sh(c, 0.7));
51122
51979
  }
51123
51980
  }
51124
51981
  function pieceOfPane(x, z) {
@@ -52213,7 +53070,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
52213
53070
  function addSpoil(THREE, parent, trenches, material, site) {
52214
53071
  const heap = new BoxBatch();
52215
53072
  const rects = trenches.map((t) => t.rect);
52216
- const laid = [];
53073
+ const laid2 = [];
52217
53074
  trenches.forEach(({ rect: r }, i) => {
52218
53075
  const others = rects.filter((_, k) => k !== i);
52219
53076
  for (const e of openEdges(r, others, site.solids)) {
@@ -52222,10 +53079,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
52222
53079
  const w = TRENCH.berm.width;
52223
53080
  const heapAt = ox ? [ox > 0 ? x1 + SPOIL_CLEAR : x0 - SPOIL_CLEAR - w, z0, ox > 0 ? x1 + SPOIL_CLEAR + w : x0 - SPOIL_CLEAR, z1] : [x0, oz > 0 ? z1 + SPOIL_CLEAR : z0 - SPOIL_CLEAR - w, x1, oz > 0 ? z1 + SPOIL_CLEAR + w : z0 - SPOIL_CLEAR];
52224
53081
  const onBuilding = [site.footprint, ...site.buildings].some(([bx0, bz0, bx1, bz1]) => heapAt[2] > bx0 - 0.4 && heapAt[0] < bx1 + 0.4 && heapAt[3] > bz0 - 0.4 && heapAt[1] < bz1 + 0.4);
52225
- if (!onBuilding) for (const piece22 of rectMinus(heapAt, [...rects.map((t) => [t[0] - SPOIL_CLEAR, t[1] - SPOIL_CLEAR, t[2] + SPOIL_CLEAR, t[3] + SPOIL_CLEAR]), ...laid])) {
53082
+ if (!onBuilding) for (const piece22 of rectMinus(heapAt, [...rects.map((t) => [t[0] - SPOIL_CLEAR, t[1] - SPOIL_CLEAR, t[2] + SPOIL_CLEAR, t[3] + SPOIL_CLEAR]), ...laid2])) {
52226
53083
  if (Math.min(piece22[2] - piece22[0], piece22[3] - piece22[1]) < TRENCH.berm.crest * 2) continue;
52227
53084
  addHumps(heap, piece22);
52228
- laid.push(piece22);
53085
+ laid2.push(piece22);
52229
53086
  }
52230
53087
  }
52231
53088
  });
@@ -52597,7 +53454,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
52597
53454
  var UNDER_SINK_VALVE_RISE = 0.1;
52598
53455
  var pipeMass = (diameter, length) => DENSITY.plastic * Math.PI * (diameter / 2) ** 2 * length * PIPE_WALL_FILL;
52599
53456
  function installUtilitiesWater(K, shared2) {
52600
- const { THREE, _Y, _q, cursor, cylBase, part, pieceRecord, put } = K;
53457
+ const { THREE, _Y, _q, cursor, cylBase, part, pieceRecord, put: put2 } = K;
52601
53458
  function createWater(r, state) {
52602
53459
  const H = r.utilities?.plumbing, cap = H ? +H.capacityL || 0 : 0, ls = { dry: [], full: [] }, points = {}, itemPoint = {};
52603
53460
  if (H) for (const p of H.points) {
@@ -52684,7 +53541,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
52684
53541
  const dx = b[0] - a[0], dy = b[1] - a[1], dz = b[2] - a[2], L = Math.hypot(dx, dy, dz);
52685
53542
  if (L < 1e-3) return;
52686
53543
  _q.setFromUnitVectors(_Y, _v3.set(dx / L, dy / L, dz / L));
52687
- put("plain", "cyl", (a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2, _q, diameter, L, diameter, color2);
53544
+ put2("plain", "cyl", (a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2, _q, diameter, L, diameter, color2);
52688
53545
  }
52689
53546
  const _v3 = new THREE.Vector3();
52690
53547
  function layWallRun({ id, routes, diameter, group, meta }) {
@@ -52949,7 +53806,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
52949
53806
  var END_RENDER = 0.02;
52950
53807
  var SLIVER_CLEAR = 5e-4;
52951
53808
  var MORTAR_LIFT = 9e-3;
52952
- function layUnits(rect, coursing, put) {
53809
+ function layUnits(rect, coursing, put2) {
52953
53810
  const { courseH, unitLen, joint, courseBase } = coursing;
52954
53811
  const first = Math.floor((rect.y0 - courseBase) / courseH + 1e-6);
52955
53812
  for (let row = first; courseBase + row * courseH < rect.y1 - 1e-6; row++) {
@@ -52969,7 +53826,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
52969
53826
  units[units.length - 1][1] = rect.a1;
52970
53827
  if (units.length > 1 && units[0][1] - units[0][0] < MIN_PIECE2) units.splice(0, 2, [rect.a0, units[1][1]]);
52971
53828
  if (units.length > 1 && units[units.length - 1][1] - units[units.length - 1][0] < MIN_PIECE2) units.splice(units.length - 2, 2, [units[units.length - 2][0], rect.a1]);
52972
- for (const [b0, b1] of units) put(b0, ya, b1, yb);
53829
+ for (const [b0, b1] of units) put2(b0, ya, b1, yb);
52973
53830
  }
52974
53831
  }
52975
53832
  function coreWidthOf(thickness, unitId) {
@@ -53067,8 +53924,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
53067
53924
  const isBlock = part.assembly === "concrete_block_wall" || part.material === "concrete";
53068
53925
  const coreTh = coreWidthOf(th, unitId);
53069
53926
  for (const r of slivers) chased(batches.mortar, r.a0 + SLIVER_CLEAR, r.y0 + SLIVER_CLEAR, r.a1 - SLIVER_CLEAR, r.y1 - SLIVER_CLEAR, coreTh * 0.98, MORTAR_CHASE_INSET);
53070
- const laid = coursingOf(unitId, getAssembly(part.assembly ?? (isBlock ? "concrete_block_wall" : "brick_wall_plastered"))?.units);
53071
- const coursing = { courseH: laid.courseHeight, unitLen: laid.unitLength, joint: 0.012, courseBase };
53927
+ const laid2 = coursingOf(unitId, getAssembly(part.assembly ?? (isBlock ? "concrete_block_wall" : "brick_wall_plastered"))?.units);
53928
+ const coursing = { courseH: laid2.courseHeight, unitLen: laid2.unitLength, joint: 0.012, courseBase };
53072
53929
  const unit = isBlock ? batches.block : batches.brick;
53073
53930
  for (const r of pieces) {
53074
53931
  unitEnds.length = 0;
@@ -53387,13 +54244,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
53387
54244
  const lintels = beamParts.filter((p) => isLintel(p.id)).map(solidOf).map(toCoreWidth).map(inWall).map((l) => fitLintel(l, beams, columns, wallCores.filter((w) => wallLineOf(w.aabb).alongU !== wallLineOf(l.aabb).alongU))).filter((l) => l !== null);
53388
54245
  for (const l of lintels) addStageBox(THREE, masonry, l.aabb[0], l.y0, l.aabb[1], l.aabb[2], l.y1, l.aabb[3], mats.lintel, l.id);
53389
54246
  const batches = createMasonryBatches();
53390
- const laid = [];
54247
+ const laid2 = [];
53391
54248
  const solids = [...foundations, ...columns, ...beams, ...slabs, ...lintels];
53392
54249
  for (const run of wallRuns(wallParts)) {
53393
54250
  const p = run.part;
53394
54251
  const wall = wallLineOf(p.aabb);
53395
54252
  const cuts = [...run.gaps];
53396
- for (const s of [...solids, ...laid]) {
54253
+ for (const s of [...solids, ...laid2]) {
53397
54254
  const top = columns.includes(s) ? s.y1 + 0.3 : s.y1;
53398
54255
  const cut = cutOf(wall, s.aabb, s.y0, top);
53399
54256
  if (cut) cuts.push(cut);
@@ -53406,7 +54263,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
53406
54263
  const coreLine = coreLineOf(wall, p, columns, coreWidth);
53407
54264
  const filled = buildMasonryPanel(batches, p, { cuts, courseBase: (p.floor ?? 0) === 0 ? FOUNDATION_TOP : p.y0, unitId: unit, coreLine, chases: chasesIn(wall, { line: coreLine, width: coreWidth, y0: p.y0, y1: p.y1 }, runs) });
53408
54265
  const half = coreWidth / 2;
53409
- for (const r of filled) laid.push({ id: p.id, aabb: wall.alongU ? [r.a0, coreLine - half, r.a1, coreLine + half] : [coreLine - half, r.a0, coreLine + half, r.a1], y0: r.y0, y1: r.y1, floor: p.floor ?? 0 });
54266
+ for (const r of filled) laid2.push({ id: p.id, aabb: wall.alongU ? [r.a0, coreLine - half, r.a1, coreLine + half] : [coreLine - half, r.a0, coreLine + half, r.a1], y0: r.y0, y1: r.y1, floor: p.floor ?? 0 });
53410
54267
  }
53411
54268
  for (const mesh2 of masonryMeshes(THREE, batches, mats, "masonry")) masonry.add(mesh2);
53412
54269
  return groups;
@@ -53546,7 +54403,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
53546
54403
  var FLOOR_SLAB_UNDERSIDE = 0.24;
53547
54404
  var BOX_COLOR = 15381256;
53548
54405
  function installUtilitiesElectrical(K, shared2) {
53549
- const { _Y, _q, _v3, bx, cursor, cylBase, part, pieceRecord, put } = K;
54406
+ const { _Y, _q, _v3, bx, cursor, cylBase, part, pieceRecord, put: put2 } = K;
53550
54407
  const sh = (...a) => K.sh(...a);
53551
54408
  function electricalStructure() {
53552
54409
  const R = shared2.ctx.r, E = R.utilities?.electrical;
@@ -53558,7 +54415,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
53558
54415
  const L = Math.hypot(b[0] - a[0], b[1] - a[1], b[2] - a[2]);
53559
54416
  if (L < 1e-3) return;
53560
54417
  _q.setFromUnitVectors(_Y, _v3.set((b[0] - a[0]) / L, (b[1] - a[1]) / L, (b[2] - a[2]) / L));
53561
- put("plain", "cyl", (a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2, _q, r_ * 2, L, r_ * 2, wireRun);
54418
+ put2("plain", "cyl", (a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2, _q, r_ * 2, L, r_ * 2, wireRun);
53562
54419
  };
53563
54420
  const pole = (u, v, h) => {
53564
54421
  const buried = postEmbedment(h), below = shared2.ctx.visorScene ? 0 : buried;
@@ -53820,7 +54677,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
53820
54677
  const dx = b[0] - a[0], dy = b[1] - a[1], dz = b[2] - a[2], L = Math.hypot(dx, dy, dz);
53821
54678
  if (L < 1e-3) return;
53822
54679
  _q.setFromUnitVectors(_Y, _v3.set(dx / L, dy / L, dz / L));
53823
- put("plain", "cyl", (a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2, _q, diameter, L, diameter, color2);
54680
+ put2("plain", "cyl", (a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2, _q, diameter, L, diameter, color2);
53824
54681
  }
53825
54682
  const defined = { electricalStructure, pipe2 };
53826
54683
  Object.assign(K, defined);
@@ -53855,7 +54712,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
53855
54712
  };
53856
54713
  for (const A of ws) for (const [side, sd] of [[A.w.sides[0], -1], [A.w.sides[1], 1]]) {
53857
54714
  if (!sideOf(side, false).exterior) continue;
53858
- const strip = (k, y1, y2, o0, o1, mat, c, piece22, laid = BASEBOARD_TILES) => {
54715
+ const strip = (k, y1, y2, o0, o1, mat, c, piece22, laid2 = BASEBOARD_TILES) => {
53859
54716
  const ea = junction(A, A.a, sd) > 0 ? A.th / 2 + k : junction(A, A.a, sd) < 0 ? -A.th / 2 : 0, eb = junction(A, A.b, sd) > 0 ? A.th / 2 + k : junction(A, A.b, sd) < 0 ? -A.th / 2 : 0;
53860
54717
  const s0 = A.a - ea, s1 = A.b + eb, f0 = A.L + sd * (A.th / 2 + o0), f1 = A.L + sd * (A.th / 2 + o1), lo = Math.min(f0, f1), hi = Math.max(f0, f1);
53861
54718
  if (s1 - s0 < 1e-3) return;
@@ -53865,14 +54722,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
53865
54722
  if (!shared2.ctx.visorScene) (mat === "sidewalk" ? shared2.ctx.paving : shared2.ctx.baseboards)?.push(p);
53866
54723
  }
53867
54724
  };
53868
- const tag = laid === BASEBOARD_TILES ? "baseboard" : "sidewalk";
54725
+ const tag = laid2 === BASEBOARD_TILES ? "baseboard" : "sidewalk";
53869
54726
  const tile = (id, a, b) => {
53870
- cursor.pc = pieceRecord(id, laid.material, null, { floor: 0, mass: Math.round((b - a) * (y2 - y1) * (hi - lo) * laid.density * 100) / 100, tags: [tag] });
54727
+ cursor.pc = pieceRecord(id, laid2.material, null, { floor: 0, mass: Math.round((b - a) * (y2 - y1) * (hi - lo) * laid2.density * 100) / 100, tags: [tag] });
53871
54728
  box4(a, b);
53872
54729
  };
53873
54730
  const runs = [];
53874
54731
  let from = s0;
53875
- if (laid === BASEBOARD_TILES) for (const d of doorsInWall(R.doors, A.w, A.L, A.a, A.b).sort((p, q) => p.at - q.at)) {
54732
+ if (laid2 === BASEBOARD_TILES) for (const d of doorsInWall(R.doors, A.w, A.L, A.a, A.b).sort((p, q) => p.at - q.at)) {
53876
54733
  runs.push([from, d.at - d.width / 2]);
53877
54734
  from = d.at + d.width / 2;
53878
54735
  }
@@ -53883,7 +54740,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
53883
54740
  if (!id) box4(r0, r1);
53884
54741
  else if (shared2.ctx.baseboardBand) tile(id, r0, r1);
53885
54742
  else {
53886
- const n = Math.max(1, Math.round((r1 - r0) / laid.length)), w = (r1 - r0) / n, j = laid.joint / 2;
54743
+ const n = Math.max(1, Math.round((r1 - r0) / laid2.length)), w = (r1 - r0) / n, j = laid2.joint / 2;
53887
54744
  for (let i = 0; i < n; i++) tile(`${id}:${i}`, r0 + i * w + (i > 0 ? j : 0), r0 + (i + 1) * w - (i < n - 1 ? j : 0));
53888
54745
  }
53889
54746
  });
@@ -54073,7 +54930,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
54073
54930
  Object.assign(K, defined);
54074
54931
  }
54075
54932
  function installFurnitureApi(K, shared2) {
54076
- const { _e, _h2, _q, boxC, cursor, macroGround, polyFace, put } = K;
54933
+ const { _e, _h2, _q, boxC, cursor, macroGround, polyFace, put: put2 } = K;
54077
54934
  const MATERIAL_MAP2 = { plain: "plain", metal: "metal", wood: "wood", glass: "glass", fabric: "fabric", foam: "fabric", plant: "plant", water: "water", emissive: "emissive", "atlas_picture": "picture", "atlas_floor": "floor", plaster: "plain", matte: "glass", glass_light: "emissive", light: "emissive", ceramic_tile: "plain", parquet: "plain", ceramic: "plain" };
54078
54935
  const mm = (k) => MATERIAL_MAP2[k] || "plain";
54079
54936
  const LIGHTS = [];
@@ -54090,7 +54947,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
54090
54947
  cylinder(M, mat, x, y, z, r, h, color2, rx = 0, rz = 0, seg2) {
54091
54948
  const [px, pz] = loc(M, x, z);
54092
54949
  _q.setFromEuler(_e.set(rx || 0, M.ry, rz || 0, "YXZ"));
54093
- put(mm(mat), seg2 || "cyl", px, M.base + y + (rx || rz ? 0 : h / 2), pz, _q, r * 2, h, r * 2, color2);
54950
+ put2(mm(mat), seg2 || "cyl", px, M.base + y + (rx || rz ? 0 : h / 2), pz, _q, r * 2, h, r * 2, color2);
54094
54951
  },
54095
54952
  leaf(M, x, y, z, w, h, color2, ry = 0, rx = 0) {
54096
54953
  const [px, pz] = loc(M, x, z), a = M.ry + (ry || 0), ca = Math.cos(a), sa = Math.sin(a), t1 = (rx || 0) * 0.8, t2 = (rx || 0) * 1.5, y0 = M.base + y;
@@ -54111,12 +54968,12 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
54111
54968
  if (uv && mat === "atlas_floor") {
54112
54969
  const col = Math.floor(uv.u0 * 4 + 1e-6), lin = uv.v0 < 0.5 ? 1 : 0, cell = col + 4 * lin, h0 = _h2(Math.round(px * 8), Math.round(pz * 8)), type = cell === 5 ? "dirt" : cell === 0 || cell === 1 ? "lawn" : null;
54113
54970
  if (type === "dirt") {
54114
- put("dirt", "plane", px, M.base + y, pz, _q, w, h, 1, sh(color2, 1 / 0.965));
54971
+ put2("dirt", "plane", px, M.base + y, pz, _q, w, h, 1, sh(color2, 1 / 0.965));
54115
54972
  return;
54116
54973
  }
54117
54974
  if (type) uv = { u0: uv.u0, u1: uv.u1, v0: uv.v0, v1: uv.v1, rot: h0 * 4 | 0, fx: h0 > 0.5 ? 1 : 0, vc: (wx, wz) => macroGround(wx, wz, type) };
54118
54975
  }
54119
- put(mm(mat), "plane", px, M.base + y, pz, _q, w, h, 1, color2, uv);
54976
+ put2(mm(mat), "plane", px, M.base + y, pz, _q, w, h, 1, color2, uv);
54120
54977
  },
54121
54978
  light(M, x, y, z, color2, range2, type, ex) {
54122
54979
  const [px, pz] = loc(M, x, z);
@@ -54142,7 +54999,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
54142
54999
  Object.assign(K, defined);
54143
55000
  }
54144
55001
  function installFurnitureBuilders(K, shared2) {
54145
- const { PE, _q, kit2, kk, paletteColor, put, rngOf, sh } = K;
55002
+ const { PE, _q, kit2, kk, paletteColor, put: put2, rngOf, sh } = K;
54146
55003
  const counterTap = (...a) => K.counterTap(...a);
54147
55004
  const apart = () => !shared2.ctx.visorScene;
54148
55005
  const FURNITURE = {
@@ -54194,7 +55051,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
54194
55051
  lc("metal", -0.08, h + 0.03, -0.05, 0.01, 0.2, 9075290);
54195
55052
  _q.identity();
54196
55053
  const [px, pz] = [M.x + -0.08 * Math.cos(M.ry) + -0.05 * Math.sin(M.ry), M.z - -0.08 * Math.sin(M.ry) + -0.05 * Math.cos(M.ry)];
54197
- put("fabric", "cone", px, M.base + h + 0.32, pz, _q, 0.36, 0.2, 0.36, 15259824);
55054
+ put2("fabric", "cone", px, M.base + h + 0.32, pz, _q, 0.36, 0.2, 0.36, 15259824);
54198
55055
  }
54199
55056
  },
54200
55057
  shelf(M, A, o = {}) {
@@ -54472,7 +55329,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
54472
55329
  lc("plain", 0, 0, 0, 0.14, 0.03, 2763306);
54473
55330
  lc("metal", 0, 0.03, 0, 0.012, M.h - 0.35, 9075290);
54474
55331
  _q.identity();
54475
- put("fabric", "cone", M.x, M.base + (M.y || 0) + M.h - 0.2, M.z, _q, 0.4, 0.3, 0.4, 14733992);
55332
+ put2("fabric", "cone", M.x, M.base + (M.y || 0) + M.h - 0.2, M.z, _q, 0.4, 0.3, 0.4, 14733992);
54476
55333
  },
54477
55334
  microwave(M, A) {
54478
55335
  const { b: lb } = kk(M, A);
@@ -54998,8 +55855,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
54998
55855
  }
54999
55856
  var BLOB_LEANS = [[0.06, 0], [-0.06, 0], [0, 0.06], [0, -0.06], [0.06, 0.06], [-0.06, -0.06], [0.06, -0.06], [-0.06, 0.06], [0.12, 0], [0, 0.12]];
55000
55857
  var BLOB_CROSSING = Math.cos(20 * Math.PI / 180);
55001
- function grazes(laid, x, y, z, r) {
55002
- return laid.some(([x0, y0, z0, r0]) => {
55858
+ function grazes(laid2, x, y, z, r) {
55859
+ return laid2.some(([x0, y0, z0, r0]) => {
55003
55860
  const d = Math.hypot(x - x0, y - y0, z - z0);
55004
55861
  if (d <= Math.abs(r - r0) || d >= r + r0) return false;
55005
55862
  return (r * r + r0 * r0 - d * d) / (2 * r * r0) > BLOB_CROSSING;
@@ -55012,14 +55869,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
55012
55869
  const GREENS2 = [4160058, 3107376, 5212738, 5936200, 3832396];
55013
55870
  const FLOWERS = [14700682, 15909424, 16118506, 14168874, 9067216, 15764026];
55014
55871
  function blobs(K2, cx, cy, cz, R, n, green2, rnd, o = {}) {
55015
- const laid = [];
55872
+ const laid2 = [];
55016
55873
  for (let i = 0; i < n; i++) {
55017
55874
  const a = rnd() * 6.283, u = Math.sqrt(rnd()), ph = (rnd() - 0.2) * 1.2, dx = Math.cos(a) * u * R * 0.75, dz = Math.sin(a) * u * R * 0.75, dy = (o.flatten ? 0.35 : 0.55) * R * (Math.sin(ph) * 0.5 + 0.5) * 1.5 - R * 0.15;
55018
55875
  const r = R * (0.34 + rnd() * 0.22) * (1 - u * 0.25), alt = r * 2 * (o.flatten ? 0.75 : 0.95), f = 0.72 + Math.min(1, (dy + R * 0.2) / (R * 1.2)) * 0.32 + rnd() * 0.12;
55019
- const shown2 = shared2.ctx.visorScene || !grazes(laid, cx + dx, cy + dy + r * 0.5, cz + dz, r);
55876
+ const shown2 = shared2.ctx.visorScene || !grazes(laid2, cx + dx, cy + dy + r * 0.5, cz + dz, r);
55020
55877
  if (shared2.ctx.visorScene) K2.e("plant", cx + dx, cy + dy + r * 0.5, cz + dz, r, alt, sh(green2, f));
55021
55878
  else if (shown2) {
55022
- laid.push([cx + dx, cy + dy + r * 0.5, cz + dz, r]);
55879
+ laid2.push([cx + dx, cy + dy + r * 0.5, cz + dz, r]);
55023
55880
  const [wx, , wz] = K2.W(cx + dx, 0, cz + dz), lean = BLOB_LEANS[i % BLOB_LEANS.length];
55024
55881
  K2.A.cylinder({ ...K2.M, x: wx, z: wz, ry: K2.M.ry + i / n * (Math.PI / 5) }, "plant", 0, K2.y0 + cy + dy + r * 0.5, 0, r, alt, sh(green2, f), lean[0], lean[1], "sphere");
55025
55882
  }
@@ -56173,6 +57030,17 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
56173
57030
  const defined = { NO_COLLIDE, registerCollision, objectDistance, collideObject, collideAt, walkInSolids, kitCollides };
56174
57031
  Object.assign(K, defined);
56175
57032
  }
57033
+ var PELVIS_FROM_HEAD = 0.95;
57034
+ var SWING_SEAT = 0.45;
57035
+ var SAUNA_BENCH = 0.45;
57036
+ var TUB_FLOOR = 0.12;
57037
+ var PLAN_FURNITURE_SEATS = {
57038
+ sun_lounger: ({ w, d, h }) => [{ id: "lie", pose: "lie", pos: [0, h, -d / 2 + PELVIS_FROM_HEAD], ry: 0, eye: 0.2, exit: [w / 2 + 0.5, 0, 0] }],
57039
+ swing: ({ d }) => [{ id: "seat", pose: "sit", pos: [0, SWING_SEAT, 0], ry: 0, exit: [0, 0, d / 2 + 0.6] }],
57040
+ soaking_tub: ({ d }) => [{ id: "seat", pose: "sit", pos: [0, TUB_FLOOR, -d / 6], ry: 0, exit: [0, 0, d / 2 + 0.5] }],
57041
+ sauna: ({ d }) => [{ id: "bench", pose: "sit", pos: [0, SAUNA_BENCH, -d / 4], ry: 0, exit: [0, 0, d / 2 + 0.5] }]
57042
+ };
57043
+ var planFurnitureSeats = (type, size) => PLAN_FURNITURE_SEATS[type]?.(size) ?? [];
56176
57044
  function installInteractionItems(K, shared2) {
56177
57045
  const { t, LIGHTS, cursor, definePiece, localOf, registerCollision, togglePiece } = K;
56178
57046
  const DOOR_ITEM = /^(tv_unit|tv_unit_small|tv_unit_large|sideboard|china_cabinet|filing_cabinet|pantry|laundry_cabinet|wardrobe|wardrobe_small|wardrobe_large|closet_wardrobe|kitchen_cabinet|kitchen_cabinet_large|kitchen_cabinet_small|fridge|fridge_large|display_fridge_medium|display_fridge)$/;
@@ -56192,11 +57060,19 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
56192
57060
  function buildItem2(m, M, ent, api, parent) {
56193
57061
  registerCollision(m, M);
56194
57062
  const type = m.type;
57063
+ seatItem(m, M);
56195
57064
  if (LIGHT_TYPES.has(type)) return lightItem(m, M, ent, api, parent);
56196
57065
  if (type === "curtain") return curtainItem(m, M, ent, api, parent);
56197
57066
  if (DOOR_ITEM.test(type) || DRAWER_ITEM.test(type)) return furnitureItem(m, M, ent, api, parent, DRAWER_ITEM.test(type));
56198
57067
  ent.f(M, api);
56199
57068
  }
57069
+ function seatItem(m, M) {
57070
+ const seats = planFurnitureSeats(m.type, { w: M.w, d: M.d, h: M.h });
57071
+ const first = seats[0];
57072
+ if (!first) return;
57073
+ const base2 = M.base + (M.y || 0), [ax, az] = localOf(M, first.pos[0], first.pos[2]);
57074
+ I().items.push({ type: "seat", id: m.id, floor: M.floor, anchor: [ax, base2 + first.pos[1], az], range: 1.6, angle: 1.1, pieces: [], seats, mount: { x: M.x, y: base2, z: M.z, ry: M.ry }, text: () => t(first.pose === "lie" ? "prompt.lie" : "prompt.sit"), action: () => void 0 });
57075
+ }
56200
57076
  function lightItem(m, M, ent, api, parent) {
56201
57077
  M.on = M.light = M.lit = true;
56202
57078
  const n0 = LIGHTS.length, name = shared2.quality === "game" ? "ix:light:" + m.room + "@" + parent : "ix:light:" + m.id;
@@ -57346,7 +58222,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
57346
58222
  PL.push(l);
57347
58223
  }
57348
58224
  const slotOf = (i) => lease ? lease.handles[i].slot : i;
57349
- const put = (i, v) => {
58225
+ const put2 = (i, v) => {
57350
58226
  if (lease) {
57351
58227
  lease.handles[i].update(v.color === void 0 || typeof v.color === "number" ? v : { ...v, color: new THREE.Color(v.color).getHex() });
57352
58228
  return;
@@ -57485,13 +58361,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
57485
58361
  const b0 = LZU.uRB0.value, b1 = LZU.uRB1.value, b2 = LZU.uRB2.value, by = LZU.uRBY.value, ex = LZU.uREx.value;
57486
58362
  A.crates[i] = g ? { k: g.k, rects: g.rects, y: g.y, exterior: !!g.exterior, exclusion: g.exclusion || null, d: g.d } : null;
57487
58363
  if (!g) {
57488
- put(i, { intensity: 0 });
58364
+ put2(i, { intensity: 0 });
57489
58365
  for (const a of [b0, b1, b2, ex]) a.set(EMPTY, at2 * 4);
57490
58366
  by.set([0, 0], at2 * 2);
57491
58367
  continue;
57492
58368
  }
57493
58369
  const lamp = g.exterior ? { intensity: g.lumens, distance: g.dist, decay: g.decay } : { intensity: (7 + g.range * 0.8) * lim(1 + 0.4 * (Math.sqrt(g.n) - 1), 1, 2.2), distance: Math.max(3, g.dm * 1.3 + 0.5), decay: 1.6 };
57494
- put(i, { position: g.pos, color: g.color, ...lamp });
58370
+ put2(i, { position: g.pos, color: g.color, ...lamp });
57495
58371
  const rs = g.rects;
57496
58372
  b0.set(rs[0] || EMPTY, at2 * 4);
57497
58373
  b1.set(rs[1] || EMPTY, at2 * 4);
@@ -58031,7 +58907,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58031
58907
  const bars = def && def.reinforcement ? pc.role === "column" || pc.role === "beam" ? { ...def.reinforcement, diameter: Math.max(def.reinforcement.diameter, MEMBER_CAGE.diameter) } : def.reinforcement : null;
58032
58908
  const cage = bars ? pc.role === "column" && sp.shape.kind === "box" ? { ...bars, residualCapacity: cageResidualCapacity(sp.shape.size, bars, sp.structure?.capacity) } : { ...bars } : null;
58033
58909
  const out = cage && !sp.reinforcement ? { ...sp, reinforcement: cage } : sp;
58034
- if (out.reinforcement && !out.units && pc.material === "concrete" && (pc.role === "beam" || pc.role === "column") && sp.shape.kind === "box") {
58910
+ if (out.reinforcement && !out.units && pc.material === "concrete" && CAGED_ROLES.has(pc.role) && sp.shape.kind === "box") {
58035
58911
  return { ...out, units: { size: [MEMBER_CAGE.unit, MEMBER_CAGE.unit, Math.min(...sp.shape.size)], bond: "stack", mortar: "concrete" } };
58036
58912
  }
58037
58913
  return out;
@@ -58094,6 +58970,25 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58094
58970
  if (distance2 <= -depth) return true;
58095
58971
  return distance2 <= -depth * noise3();
58096
58972
  }
58973
+ var WALL_ALONG_U = { along: 0, up: 1, across: 2 };
58974
+ var WALL_ALONG_V = { along: 2, up: 1, across: 0 };
58975
+ var LYING = { along: 0, up: 2, across: 1 };
58976
+ function extentOf(part, axis) {
58977
+ if (axis === 1) return [part.y0, part.y1];
58978
+ return axis === 0 ? [part.aabb[0], part.aabb[2]] : [part.aabb[1], part.aabb[3]];
58979
+ }
58980
+ function planeAxesOf(part) {
58981
+ const [u0, v0, u1, v1] = part.aabb;
58982
+ if (thinAxisOf([u1 - u0, part.y1 - part.y0, v1 - v0]) === 1) return LYING;
58983
+ return u1 - u0 >= v1 - v0 ? WALL_ALONG_U : WALL_ALONG_V;
58984
+ }
58985
+ function pointOf2(axes, along2, up, across2) {
58986
+ const out = [0, 0, 0];
58987
+ out[axes.along] = along2;
58988
+ out[axes.up] = up;
58989
+ out[axes.across] = across2;
58990
+ return out;
58991
+ }
58097
58992
  var JOINT_SHARE = 0.5;
58098
58993
  var EPSILON22 = 1e-4;
58099
58994
  function carve(boxes, grid) {
@@ -58203,11 +59098,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58203
59098
  const boxes = part.gone?.length ? subtract(mergeSpans(part.spans), part.gone) : mergeSpans(part.spans);
58204
59099
  for (const s of line.open ? mergeSpans(carve(boxes, line.open), 0) : boxes) {
58205
59100
  const along2 = line.start + (s.a + s.b) / 2;
58206
- point.set(line.alongU ? along2 : part.mid, (s.y0 + s.y1) / 2, line.alongU ? part.mid : along2).applyMatrix4(toMesh);
58207
- const length = (s.b - s.a) / 2, up = (s.y1 - s.y0) / 2, across2 = part.thick / 2;
59101
+ point.set(...pointOf2(line.axes, along2, (s.y0 + s.y1) / 2, part.mid)).applyMatrix4(toMesh);
59102
+ const [hx, hy, hz] = pointOf2(line.axes, (s.b - s.a) / 2, (s.y1 - s.y0) / 2, part.thick / 2);
58208
59103
  out.push({
58209
59104
  center: [point.x, point.y, point.z],
58210
- half: [(line.alongU ? length : across2) * scale.x, up * scale.y, (line.alongU ? across2 : length) * scale.z],
59105
+ half: [hx * scale.x, hy * scale.y, hz * scale.z],
58211
59106
  rotation: [turn.x, turn.y, turn.z, turn.w],
58212
59107
  kind: "box"
58213
59108
  });
@@ -58265,6 +59160,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58265
59160
  var SPALL_MIN = 0.025;
58266
59161
  var SPALL_RAGGED = 0.045;
58267
59162
  var PLASTER_REACH = { least: SPALL_MIN, band: SPALL_RAGGED };
59163
+ var CAST_GAP = 2e-3;
58268
59164
  var COVER2 = 0.015;
58269
59165
  var LUMP_BAR_INSET = 0.035;
58270
59166
  var LUMPS_PER_BAR = 1;
@@ -58283,6 +59179,28 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58283
59179
  if (hi[0] - lo[0] <= 1e-4 || hi[1] - lo[1] <= 1e-4 || hi[2] - lo[2] <= 1e-4) return null;
58284
59180
  return { x: (lo[0] + hi[0]) / 2, y: (lo[1] + hi[1]) / 2, z: (lo[2] + hi[2]) / 2, sx: hi[0] - lo[0], sy: hi[1] - lo[1], sz: hi[2] - lo[2], colour: unit.colour };
58285
59181
  }
59182
+ var axisVector = (axis) => [axis === 0 ? 1 : 0, axis === 1 ? 1 : 0, axis === 2 ? 1 : 0];
59183
+ function isSliver(unit, size) {
59184
+ return Math.min(unit.sx, unit.sy, unit.sz) < 0.5 * Math.min(...size);
59185
+ }
59186
+ function overlapsStone(a, b) {
59187
+ const reach2 = 0.62 * (Math.max(a.sx, a.sy, a.sz) + Math.max(b.sx, b.sy, b.sz));
59188
+ return Math.hypot(a.x - b.x, a.y - b.y, a.z - b.z) < reach2;
59189
+ }
59190
+ function unitBoxOf(axes, centre, size, colour) {
59191
+ const [x, y, z] = pointOf2(axes, centre[0], centre[1], centre[2]), [sx, sy, sz] = pointOf2(axes, size[0], size[1], size[2]);
59192
+ return { x, y, z, sx, sy, sz, colour };
59193
+ }
59194
+ function coatedInside(bounds2, axes) {
59195
+ const inner = [...bounds2];
59196
+ inner[axes.along] = bounds2[axes.along] + COVER2;
59197
+ inner[axes.along + 3] = bounds2[axes.along + 3] - COVER2;
59198
+ inner[axes.up + 3] = bounds2[axes.up + 3] - COVER2;
59199
+ if (axes.up !== 1) inner[axes.up] = bounds2[axes.up] + COVER2;
59200
+ inner[axes.across] = bounds2[axes.across] + COVER2;
59201
+ inner[axes.across + 3] = bounds2[axes.across + 3] - COVER2;
59202
+ return inner;
59203
+ }
58286
59204
  function installDestructionBreach(K, _shared) {
58287
59205
  const { THREE, fragmentMaterial, invalidate, invalidateShadow } = K;
58288
59206
  const paintState = { attached: false };
@@ -58451,13 +59369,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58451
59369
  hasStrike = true;
58452
59370
  };
58453
59371
  function cells(part, units, mask) {
58454
- const [u0, v0, u1, v1] = part.aabb;
58455
- const alongU = mask.alongU;
58456
- const len = alongU ? u1 - u0 : v1 - v0;
58457
- const offset = (alongU ? u0 : v0) - mask.start;
58458
- const [ul, uh] = units.size;
58459
- const rows = Math.max(1, Math.round((part.y1 - part.y0) / uh));
58460
- const rowH = (part.y1 - part.y0) / rows;
59372
+ const [a0, a1] = extentOf(part, mask.axes.along), [up0, up1] = extentOf(part, mask.axes.up);
59373
+ const len = a1 - a0;
59374
+ const offset = a0 - mask.start;
59375
+ const merge = Math.max(1, Math.ceil(Math.sqrt(Math.max(1, Math.round((up1 - up0) / units.size[1])) * Math.max(1, Math.round(len / units.size[0])) / BREACH_GRID_CAP)));
59376
+ const ul = units.size[0] * merge, uh = units.size[1] * merge;
59377
+ const rows = Math.max(1, Math.round((up1 - up0) / uh));
59378
+ const rowH = (up1 - up0) / rows;
58461
59379
  const per = Math.max(1, Math.round(len / ul));
58462
59380
  const w = len / per;
58463
59381
  const out = [];
@@ -58465,7 +59383,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58465
59383
  const shift = units.bond === "running" && r & 1 ? w / 2 : 0;
58466
59384
  for (let i = 0; i < per + (shift ? 1 : 0); i++) {
58467
59385
  const a = Math.max(0, i * w - shift), b = Math.min(len, i * w - shift + w);
58468
- if (b - a > 1e-3) out.push({ a: offset + a, b: offset + b, y0: part.y0 + r * rowH, y1: part.y0 + (r + 1) * rowH, r, i });
59386
+ if (b - a > 1e-3) out.push({ a: offset + a, b: offset + b, y0: up0 + r * rowH, y1: up0 + (r + 1) * rowH, r, i });
58469
59387
  }
58470
59388
  }
58471
59389
  return out;
@@ -58533,8 +59451,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58533
59451
  return [...first, ...other];
58534
59452
  }
58535
59453
  const pillarSpans = (view) => structure.parts.filter((q) => q.role === "column" && wallsAround(q).includes(view.host)).map((q) => {
58536
- const a = (view.mask.alongU ? q.aabb[0] : q.aabb[1]) - view.mask.start, b = (view.mask.alongU ? q.aabb[2] : q.aabb[3]) - view.mask.start;
58537
- return { a, b, y0: q.y0, y1: q.y1 };
59454
+ const [from, to] = extentOf(q, view.mask.axes.along), [y0, y1] = extentOf(q, view.mask.axes.up);
59455
+ return { a: from - view.mask.start, b: to - view.mask.start, y0, y1 };
58538
59456
  });
58539
59457
  const windowGaps = (view) => (structure.openings ?? []).filter((o) => o.kind === "window" && o.wall === view.host).map((o) => ({ a: Math.min(o.from, o.to) - view.mask.start, b: Math.max(o.from, o.to) - view.mask.start, y0: o.y0, y1: o.y1 }));
58540
59458
  function outsideGaps(c, gaps) {
@@ -58583,9 +59501,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58583
59501
  sh.uniforms.uToHouse = toHouse;
58584
59502
  sh.uniforms.uMask = { value: mask.texture };
58585
59503
  sh.uniforms.uMaskRect = { value: mask.rect };
58586
- sh.uniforms.uMaskAlongX = { value: mask.alongU ? 1 : 0 };
59504
+ sh.uniforms.uMaskAlong = { value: axisVector(mask.axes.along) };
59505
+ sh.uniforms.uMaskUp = { value: axisVector(mask.axes.up) };
58587
59506
  sh.vertexShader = sh.vertexShader.replace("void main() {", "uniform mat4 uToHouse;\nvarying vec3 vHousePos;\nvoid main() {").replace("#include <begin_vertex>", "#include <begin_vertex>\nvHousePos = (uToHouse * vec4(transformed, 1.0)).xyz;");
58588
- sh.fragmentShader = sh.fragmentShader.replace("void main() {", "uniform sampler2D uMask;\nuniform vec4 uMaskRect;\nuniform float uMaskAlongX;\nvarying vec3 vHousePos;\nvoid main() {\n vec2 mUv = vec2(((uMaskAlongX > 0.5 ? vHousePos.x : vHousePos.z) - uMaskRect.x) / uMaskRect.z, (vHousePos.y - uMaskRect.y) / uMaskRect.w);\n if (mUv.x >= 0.0 && mUv.x <= 1.0 && mUv.y >= 0.0 && mUv.y <= 1.0 && texture2D(uMask, mUv).r > 0.5) discard;");
59507
+ sh.fragmentShader = sh.fragmentShader.replace("void main() {", "uniform sampler2D uMask;\nuniform vec4 uMaskRect;\nuniform vec3 uMaskAlong;\nuniform vec3 uMaskUp;\nvarying vec3 vHousePos;\nvoid main() {\n vec2 mUv = vec2((dot(vHousePos, uMaskAlong) - uMaskRect.x) / uMaskRect.z, (dot(vHousePos, uMaskUp) - uMaskRect.y) / uMaskRect.w);\n if (mUv.x >= 0.0 && mUv.x <= 1.0 && mUv.y >= 0.0 && mUv.y <= 1.0 && texture2D(uMask, mUv).r > 0.5) discard;");
58589
59508
  };
58590
59509
  material.customProgramCacheKey = () => "breachMask" + (base2.customProgramCacheKey?.() ?? "");
58591
59510
  const mesh2 = new THREE.Mesh(g, material);
@@ -58593,7 +59512,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58593
59512
  mesh2.userData.breachMask = mask;
58594
59513
  mesh2.userData.cutAt = (p) => {
58595
59514
  const v = local([p.x, p.y, p.z]);
58596
- const i = Math.floor(((mask.alongU ? v[0] : v[2]) - mask.start) / mask.len * mask.w), j = Math.floor((v[1] - mask.y0) / mask.height * mask.h);
59515
+ const i = Math.floor((v[mask.axes.along] - mask.start) / mask.len * mask.w), j = Math.floor((v[mask.axes.up] - mask.y0) / mask.height * mask.h);
58597
59516
  return i >= 0 && i < mask.w && j >= 0 && j < mask.h && mask.data[j * mask.w + i] > 127;
58598
59517
  };
58599
59518
  mesh2.position.copy(it.mesh.position);
@@ -58620,9 +59539,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58620
59539
  material.onBeforeCompile = (sh) => {
58621
59540
  sh.uniforms.uCore = { value: core.texture };
58622
59541
  sh.uniforms.uCoreRect = { value: core.rect };
58623
- sh.uniforms.uCoreAlongX = { value: core.alongU ? 1 : 0 };
59542
+ sh.uniforms.uCoreAlong = { value: axisVector(core.axes.along) };
59543
+ sh.uniforms.uCoreUp = { value: axisVector(core.axes.up) };
58624
59544
  sh.vertexShader = sh.vertexShader.replace("void main() {", "varying vec3 vHousePos;\nvoid main() {").replace("#include <begin_vertex>", "#include <begin_vertex>\n#ifdef USE_INSTANCING\nvHousePos = (instanceMatrix * vec4(transformed, 1.0)).xyz;\n#else\nvHousePos = transformed;\n#endif");
58625
- sh.fragmentShader = sh.fragmentShader.replace("void main() {", "uniform sampler2D uCore;\nuniform vec4 uCoreRect;\nuniform float uCoreAlongX;\nvarying vec3 vHousePos;\nvoid main() {\n vec2 cUv = vec2(((uCoreAlongX > 0.5 ? vHousePos.x : vHousePos.z) - uCoreRect.x) / uCoreRect.z, (vHousePos.y - uCoreRect.y) / uCoreRect.w);\n if (cUv.x >= 0.0 && cUv.x <= 1.0 && cUv.y >= 0.0 && cUv.y <= 1.0 && texture2D(uCore, cUv).r > 0.5) discard;").replace("#include <color_fragment>", "#include <color_fragment>\nif (!gl_FrontFacing) diffuseColor.rgb *= 0.55;");
59545
+ sh.fragmentShader = sh.fragmentShader.replace("void main() {", "uniform sampler2D uCore;\nuniform vec4 uCoreRect;\nuniform vec3 uCoreAlong;\nuniform vec3 uCoreUp;\nvarying vec3 vHousePos;\nvoid main() {\n vec2 cUv = vec2((dot(vHousePos, uCoreAlong) - uCoreRect.x) / uCoreRect.z, (dot(vHousePos, uCoreUp) - uCoreRect.y) / uCoreRect.w);\n if (cUv.x >= 0.0 && cUv.x <= 1.0 && cUv.y >= 0.0 && cUv.y <= 1.0 && texture2D(uCore, cUv).r > 0.5) discard;").replace("#include <color_fragment>", "#include <color_fragment>\nif (!gl_FrontFacing) diffuseColor.rgb *= 0.55;");
58626
59546
  };
58627
59547
  material.customProgramCacheKey = () => "breachCore";
58628
59548
  material.userData.breachCore = core;
@@ -58641,17 +59561,17 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58641
59561
  }
58642
59562
  function maskOf(hostId, parts2) {
58643
59563
  const host = structure.byId.get(hostId);
58644
- const [u0, v0, u1, v1] = host.aabb;
58645
- const alongU = u1 - u0 >= v1 - v0;
58646
- const y0 = Math.min(...parts2.map((id) => structure.byId.get(id).y0)), y1 = Math.max(...parts2.map((id) => structure.byId.get(id).y1));
58647
- const len = alongU ? u1 - u0 : v1 - v0;
59564
+ const axes = planeAxesOf(host);
59565
+ const [start, end] = extentOf(host, axes.along);
59566
+ const y0 = Math.min(...parts2.map((id) => extentOf(structure.byId.get(id), axes.up)[0])), y1 = Math.max(...parts2.map((id) => extentOf(structure.byId.get(id), axes.up)[1]));
59567
+ const len = end - start;
58648
59568
  const w = Math.max(2, Math.min(2048, Math.ceil(len / MASK_TEXEL))), h = Math.max(2, Math.min(1024, Math.ceil((y1 - y0) / MASK_TEXEL)));
58649
59569
  const data = new Uint8Array(w * h);
58650
59570
  const texture = new THREE.DataTexture(data, w, h, THREE.RedFormat);
58651
59571
  texture.magFilter = THREE.LinearFilter;
58652
59572
  texture.minFilter = THREE.LinearFilter;
58653
59573
  texture.needsUpdate = true;
58654
- return { data, texture, w, h, alongU, start: alongU ? u0 : v0, len, y0, height: y1 - y0, rect: new THREE.Vector4(alongU ? u0 : v0, y0, len, y1 - y0) };
59574
+ return { data, texture, w, h, axes, start, len, y0, height: y1 - y0, rect: new THREE.Vector4(start, y0, len, y1 - y0) };
58655
59575
  }
58656
59576
  function besidePillars(c, pillars) {
58657
59577
  let { a, b } = c;
@@ -58680,13 +59600,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58680
59600
  }
58681
59601
  function splitUnits(view, id, around) {
58682
59602
  const { mask } = view;
58683
- const along2 = (p) => (mask.alongU ? p[0] : p[2]) - mask.start;
59603
+ const along2 = (p) => p[mask.axes.along] - mask.start;
59604
+ const upOf = (p) => p[mask.axes.up];
58684
59605
  const part = structure.byId.get(id), units = specOf(id).units, chips = view.chips.get(id), opening = view.openings.get(id);
58685
59606
  const own = cells(part, units, mask);
58686
59607
  const all = (id === view.host ? own.flatMap((c) => besidePillars(c, around.pillars)) : own).flatMap((c) => outsideGaps(c, around.gaps));
58687
59608
  const holes = [], kept = [];
58688
59609
  if (view.fallen.has(id)) return { all, kept, holes: all, boxes: [] };
58689
- const boxes = chips.map((k) => ({ s0: along2(k.center) - k.along, s1: along2(k.center) + k.along, y0: k.center[1] - k.up, y1: k.center[1] + k.up }));
59610
+ const boxes = chips.map((k) => ({ s0: along2(k.center) - k.along, s1: along2(k.center) + k.along, y0: upOf(k.center) - k.up, y1: upOf(k.center) + k.up }));
58690
59611
  const gone = (c) => {
58691
59612
  const over = boxes.filter((k) => k.s1 > c.a && k.s0 < c.b && k.y1 > c.y0 && k.y0 < c.y1);
58692
59613
  const share = covered(c, over);
@@ -58694,7 +59615,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58694
59615
  const s = (c.a + c.b) / 2, y = (c.y0 + c.y1) / 2;
58695
59616
  return share >= 0.5 && over.some((k) => s >= k.s0 && s <= k.s1 && y >= k.y0 && y <= k.y1);
58696
59617
  };
58697
- const open = (c) => gone(c) || opening !== void 0 && Math.hypot((c.a + c.b) / 2 - along2(opening.center), (c.y0 + c.y1) / 2 - opening.center[1]) < opening.radius;
59618
+ const open = (c) => gone(c) || opening !== void 0 && Math.hypot((c.a + c.b) / 2 - along2(opening.center), (c.y0 + c.y1) / 2 - upOf(opening.center)) < opening.radius;
58698
59619
  for (const c of all) (open(c) ? holes : kept).push(c);
58699
59620
  return { all, kept, holes, boxes };
58700
59621
  }
@@ -58707,20 +59628,22 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58707
59628
  function publishStanding(view) {
58708
59629
  if (!view.saved) return;
58709
59630
  const { mask } = view;
58710
- const along2 = (p) => (mask.alongU ? p[0] : p[2]) - mask.start;
59631
+ const along2 = (p) => p[mask.axes.along] - mask.start;
59632
+ const upOf = (p) => p[mask.axes.up];
58711
59633
  const parts2 = view.parts.map((id) => {
58712
59634
  const part = structure.byId.get(id);
58713
- const thick = mask.alongU ? part.aabb[3] - part.aabb[1] : part.aabb[2] - part.aabb[0];
58714
- const mid = mask.alongU ? (part.aabb[1] + part.aabb[3]) / 2 : (part.aabb[0] + part.aabb[2]) / 2;
58715
- const gone = (view.chips.get(id) ?? []).map((k) => ({ a: along2(k.center) - k.along, b: along2(k.center) + k.along, y0: k.center[1] - k.up, y1: k.center[1] + k.up }));
59635
+ const [across0, across1] = extentOf(part, mask.axes.across);
59636
+ const thick = across1 - across0, mid = (across0 + across1) / 2;
59637
+ const gone = (view.chips.get(id) ?? []).map((k) => ({ a: along2(k.center) - k.along, b: along2(k.center) + k.along, y0: upOf(k.center) - k.up, y1: upOf(k.center) + k.up }));
58716
59638
  return { spans: view.kept.get(id) ?? [], gone, thick, mid };
58717
59639
  });
58718
- const line = { alongU: mask.alongU, start: mask.start, open: view.core };
59640
+ const line = { axes: mask.axes, start: mask.start, open: view.core };
58719
59641
  view.items.forEach((it, k) => publishSolids(it.mesh, it.v0, it.v1, k === 0 ? standingSolids(THREE, house, it.mesh, line, parts2) : []));
58720
59642
  }
58721
59643
  function paint(view) {
58722
59644
  const { mask, core } = view;
58723
- const along2 = (p) => (mask.alongU ? p[0] : p[2]) - mask.start;
59645
+ const along2 = (p) => p[mask.axes.along] - mask.start;
59646
+ const upOf = (p) => p[mask.axes.up];
58724
59647
  const holes = [];
58725
59648
  const pits = [];
58726
59649
  const discs = [];
@@ -58736,10 +59659,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58736
59659
  view.kept.set(id, []);
58737
59660
  continue;
58738
59661
  }
58739
- const thick = mask.alongU ? part.aabb[3] - part.aabb[1] : part.aabb[2] - part.aabb[0];
58740
- const mid = mask.alongU ? (part.aabb[1] + part.aabb[3]) / 2 : (part.aabb[0] + part.aabb[2]) / 2;
58741
- if (opening) discs.push({ s: along2(opening.center), y: opening.center[1], r: opening.radius });
58742
- for (const k of spalls) flakes.push({ s: along2(k.center), y: k.center[1], r: k.radius });
59662
+ const [across0, across1] = extentOf(part, mask.axes.across);
59663
+ const thick = across1 - across0, mid = (across0 + across1) / 2;
59664
+ if (opening) discs.push({ s: along2(opening.center), y: upOf(opening.center), r: opening.radius });
59665
+ for (const k of spalls) flakes.push({ s: along2(k.center), y: upOf(k.center), r: k.radius });
58743
59666
  holes.push(...lost);
58744
59667
  view.kept.set(id, kept);
58745
59668
  if (units2.mortar === part.material) {
@@ -58795,18 +59718,21 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58795
59718
  const list2 = [];
58796
59719
  const tone = (hex3, k) => tmp.c.setHex(hex3).multiplyScalar(k).getHex();
58797
59720
  const b = view.bounds;
58798
- const inner = mask.alongU ? [b[0] + COVER2, b[1], b[2], b[3] - COVER2, b[4] - COVER2, b[5]] : [b[0], b[1], b[2] + COVER2, b[3], b[4] - COVER2, b[5] - COVER2];
59721
+ const inner = coatedInside(b, mask.axes);
58799
59722
  for (const { c, part, units: units2, thick, mid } of shown2) {
58800
59723
  if (!near(c)) continue;
58801
59724
  const centre = mask.start + (c.a + c.b) / 2, y = (c.y0 + c.y1) / 2, len = c.b - c.a, h = c.y1 - c.y0;
58802
59725
  const at2 = (s, dy, d, colour) => {
58803
- const unit = clipToBox({ x: mask.alongU ? centre : mid, y, z: mask.alongU ? mid : centre, sx: mask.alongU ? s : d, sy: dy, sz: mask.alongU ? d : s, colour }, inner);
58804
- if (unit && !discs.some((k) => Math.hypot((mask.alongU ? unit.x : unit.z) - mask.start - k.s, unit.y - k.y) < k.r)) list2.push(unit);
59726
+ const unit = clipToBox(unitBoxOf(mask.axes, [centre, y, mid], [s, dy, d], colour), inner);
59727
+ if (unit && !discs.some((k) => {
59728
+ const p = [unit.x, unit.y, unit.z];
59729
+ return Math.hypot(p[mask.axes.along] - mask.start - k.s, p[mask.axes.up] - k.y) < k.r;
59730
+ })) list2.push(unit);
58805
59731
  };
58806
59732
  const base2 = fragmentMaterial(part.material).color.getHex();
58807
59733
  const n = noise2(centre * 3.1, y * 2.7, 0.07);
58808
59734
  if (units2.mortar === "concrete") {
58809
- at2(len, h, thick - 2 * COVER2, tone(base2, 0.9 + 0.04 * n));
59735
+ at2(len - CAST_GAP, h - CAST_GAP, thick - 2 * COVER2, tone(base2, 0.9 + 0.04 * n));
58810
59736
  } else {
58811
59737
  at2(len, h, thick - 2 * COVER2 - 0.012, 10327948);
58812
59738
  at2(len - 0.012, h - 0.012, thick - 2 * COVER2, tone(base2, 0.8 + 0.35 * n));
@@ -58835,14 +59761,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58835
59761
  view.flakes = flakes.length;
58836
59762
  publishStanding(view);
58837
59763
  }
58838
- function chipBox(chip, alongU) {
59764
+ function chipBox(chip, axes) {
58839
59765
  house.updateWorldMatrix(true, false);
58840
59766
  const q = tmp.q.set(chip.rotation[0], chip.rotation[1], chip.rotation[2], chip.rotation[3]).premultiply(house.getWorldQuaternion(new THREE.Quaternion()).invert());
58841
59767
  let a = 0, u = 0;
58842
59768
  for (let k = 0; k < 3; k++) {
58843
59769
  const axis = tmp.p.set(k === 0 ? 1 : 0, k === 1 ? 1 : 0, k === 2 ? 1 : 0).applyQuaternion(q);
58844
- a += Math.abs(alongU ? axis.x : axis.z) * chip.size[k] / 2;
58845
- u += Math.abs(axis.y) * chip.size[k] / 2;
59770
+ a += Math.abs(axis.getComponent(axes.along)) * chip.size[k] / 2;
59771
+ u += Math.abs(axis.getComponent(axes.up)) * chip.size[k] / 2;
58846
59772
  }
58847
59773
  return { center: local(chip.center), along: a, up: u };
58848
59774
  }
@@ -58878,12 +59804,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58878
59804
  const grey = fragmentMaterial("concrete").color.getHex();
58879
59805
  const stone = (s, y, d, size, r) => {
58880
59806
  const centre = mask.start + s;
58881
- const unit = clipToBox({ x: mask.alongU ? centre : d, y, z: mask.alongU ? d : centre, sx: mask.alongU ? size[0] : size[2], sy: size[1], sz: mask.alongU ? size[2] : size[0], colour: tmp.c.setHex(grey).multiplyScalar(0.85 + 0.2 * r(7)).getHex() }, bounds2);
58882
- if (unit) out.push(unit);
59807
+ const unit = clipToBox(unitBoxOf(mask.axes, [centre, y, d], size, tmp.c.setHex(grey).multiplyScalar(0.85 + 0.2 * r(7)).getHex()), bounds2);
59808
+ if (unit && !isSliver(unit, size) && !out.some((k) => overlapsStone(k, unit))) out.push(unit);
58883
59809
  };
58884
59810
  for (const { c, part, thick, mid } of gone) {
58885
- const p0 = (mask.alongU ? part.aabb[0] : part.aabb[1]) - mask.start, p1 = (mask.alongU ? part.aabb[2] : part.aabb[3]) - mask.start;
58886
- const lying = p1 - p0 > part.y1 - part.y0;
59811
+ const [from, to] = extentOf(part, mask.axes.along), [up0, up1] = extentOf(part, mask.axes.up);
59812
+ const p0 = from - mask.start, p1 = to - mask.start;
59813
+ const lying = p1 - p0 > up1 - up0;
58887
59814
  const random = (seed) => (n) => {
58888
59815
  const x = Math.sin(seed + n * 3.3) * 43758.5453;
58889
59816
  return x - Math.floor(x);
@@ -58901,7 +59828,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58901
59828
  stone(s, y, d, [size, size * (0.6 + 0.5 * r(4)), size], r);
58902
59829
  }
58903
59830
  }
58904
- const bars = lying ? [part.y0 + LUMP_BAR_INSET, part.y1 - LUMP_BAR_INSET].filter((y) => y >= c.y0 - 1e-6 && y <= c.y1 + 1e-6) : [p0 + LUMP_BAR_INSET, p1 - LUMP_BAR_INSET].filter((s) => s >= c.a - 1e-6 && s <= c.b + 1e-6);
59831
+ const bars = lying ? [up0 + LUMP_BAR_INSET, up1 - LUMP_BAR_INSET].filter((y) => y >= c.y0 - 1e-6 && y <= c.y1 + 1e-6) : [p0 + LUMP_BAR_INSET, p1 - LUMP_BAR_INSET].filter((s) => s >= c.a - 1e-6 && s <= c.b + 1e-6);
58905
59832
  for (const bar2 of bars) {
58906
59833
  for (const side of [-1, 1]) {
58907
59834
  const d = mid + side * (thick / 2 - LUMP_BAR_INSET);
@@ -58961,8 +59888,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
58961
59888
  if (view.openings.has(partId)) return false;
58962
59889
  view.openings.set(partId, { center: local(change.opening.center), radius: change.opening.radius });
58963
59890
  }
58964
- if (change.chip) view.chips.get(partId).push(chipBox(change.chip, view.mask.alongU));
58965
- for (const chip of change.chips ?? []) view.chips.get(partId).push(chipBox(chip, view.mask.alongU));
59891
+ if (change.chip) view.chips.get(partId).push(chipBox(change.chip, view.mask.axes));
59892
+ for (const chip of change.chips ?? []) view.chips.get(partId).push(chipBox(chip, view.mask.axes));
58966
59893
  if (change.spall) {
58967
59894
  const list2 = view.spalls.get(partId);
58968
59895
  list2.push({ center: local(change.spall.center), radius: change.spall.radius });
@@ -59063,13 +59990,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
59063
59990
  },
59064
59991
  /**
59065
59992
  * What still stands of the units of `partId` once its wall is cut, as drawn: spans along the wall from `start` (in the house's space, along u when
59066
- * `alongU`) and up. Null while the wall is whole (all of the part stands).
59993
+ * `axes.along`) and up `axes.up`. Null while the wall is whole (all of the part stands).
59067
59994
  */
59068
59995
  standing(partId) {
59069
59996
  const hostId = hostOf(partId), view = hostId ? views.get(hostId) : void 0;
59070
59997
  if (view?.keptStale) refreshKept(view);
59071
59998
  const spans = view?.saved ? view.kept.get(partId) : void 0;
59072
- return view && spans ? { spans, alongU: view.mask.alongU, start: view.mask.start } : null;
59999
+ return view && spans ? { spans, axes: view.mask.axes, start: view.mask.start } : null;
59073
60000
  },
59074
60001
  /** Handles a `stage` event of the house's object. Returns true when the wall was cut. */
59075
60002
  stage(event) {
@@ -59524,8 +60451,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
59524
60451
  if (du * du + dv * dv >= radius * radius) continue;
59525
60452
  const left = breach.standing(part.id);
59526
60453
  if (!left) return true;
59527
- const s0 = (left.alongU ? lx : lz) - left.start;
59528
- const low1 = Math.min(ly0, ly1), high1 = Math.max(ly0, ly1);
60454
+ const s0 = (left.axes.along === 0 ? lx : lz) - left.start;
60455
+ const flat = left.axes.up !== 1, t0 = left.axes.up === 0 ? lx : lz;
60456
+ const low1 = flat ? t0 - radius : Math.min(ly0, ly1), high1 = flat ? t0 + radius : Math.max(ly0, ly1);
59529
60457
  for (const c of left.spans) if (c.b > s0 - radius && c.a < s0 + radius && c.y1 > low1 && c.y0 < high1) return true;
59530
60458
  }
59531
60459
  return false;
@@ -61782,18 +62710,19 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
61782
62710
  };
61783
62711
  return { spec, build, top, fixed };
61784
62712
  }
62713
+ var furnitureCatalogEntry = (type, catalog) => (catalog ?? residentialItems).find((i) => i.type === type);
61785
62714
  function furnitureSpec(THREE, type, opts = {}) {
61786
62715
  const renderer = rendererOf(THREE, opts.document);
61787
62716
  const ent = renderer.types[type];
61788
62717
  if (!ent) throw new Error(`game-floorplan-three: no builder for the furniture type "${type}"`);
61789
- const entry2 = (opts.catalog ?? residentialItems).find((i) => i.type === type);
62718
+ const entry2 = furnitureCatalogEntry(type, opts.catalog);
61790
62719
  const w = opts.w ?? entry2?.w;
61791
62720
  const d = opts.d ?? entry2?.d;
61792
62721
  const h = opts.h ?? entry2?.h;
61793
62722
  if (w === void 0 || d === void 0 || h === void 0) throw new Error(`game-floorplan-three: furniture type "${type}" is not in the catalogue, so give w, d and h`);
61794
62723
  const o = opts.options ?? {};
61795
62724
  const seed = Math.round(opts.seed ?? 1);
61796
- const plain2 = SHELVING.test(type) ? "paper" : "plastic";
62725
+ const plain2 = entry2?.material ?? (SHELVING.test(type) ? "paper" : "plastic");
61797
62726
  const root = { x: seed, z: 0, ry: 0, w, d, h, y: 0, base: 0, palette: o.palette, seed: `furniture_${type}_${seed}` };
61798
62727
  const { K, shared: shared2 } = renderer.internals;
61799
62728
  const before = K.PARTS.length;
@@ -62036,11 +62965,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
62036
62965
  const id = item.seal?.openWith?.find((tool2) => catalog.has(tool2));
62037
62966
  return id === void 0 ? void 0 : catalog.get(id);
62038
62967
  };
62039
- const laid = items.flatMap((item) => {
62968
+ const laid2 = items.flatMap((item) => {
62040
62969
  const opener = openerOf(item);
62041
62970
  return opener ? [item, { id: opener.id, category: item.category, size: opener.size }] : [item];
62042
62971
  });
62043
- const shelves = shelvesLayout(laid, categories);
62972
+ const shelves = shelvesLayout(laid2, categories);
62044
62973
  const showcase = modelSet.list().map((id) => ({ id, size: sizeOfModel(modelSet, id), def: catalog.has(id) ? catalog.get(id) : void 0 }));
62045
62974
  const state = {
62046
62975
  category: CATEGORY_ALL,
@@ -62091,6 +63020,20 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
62091
63020
  const contents = itemContents(subject);
62092
63021
  return contents ? { fluid: { container: contents.container, part: SHELL_PART_ID } } : {};
62093
63022
  };
63023
+ const vesselOf = (def) => {
63024
+ const shape = def.model !== void 0 && modelSet.builder(def.model) ? void 0 : shapeOf(def);
63025
+ const vessel = itemVessel({ size: def.size, ...def.container?.capacityLiters === void 0 ? {} : { capacityLiters: def.container.capacityLiters }, ...shape === void 0 ? {} : { shape } });
63026
+ return vessel ? { fluid: { container: vessel.container, uses: ["drink", "sip", "pour", "pour_out"], offset: vessel.offset } } : {};
63027
+ };
63028
+ const washable = options.washable ?? ((def) => def.category !== "food" && (def.tags?.includes("kitchen") ?? false));
63029
+ const washOf = (def) => {
63030
+ if (!washable(def)) return {};
63031
+ const wash = {
63032
+ dirt: (root, dirt) => void (latestTHREE && setItemDirt(latestTHREE, root, dirt)),
63033
+ foam: (root, amount) => void (latestTHREE && setItemFoam(latestTHREE, root, amount))
63034
+ };
63035
+ return { wash };
63036
+ };
62094
63037
  const sealOf = (def, fluid) => {
62095
63038
  const model = def.model;
62096
63039
  if (!def.seal || model === void 0 || !itemOpening(model)) return fluid;
@@ -62112,7 +63055,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
62112
63055
  };
62113
63056
  const usesOf = (def) => {
62114
63057
  const use = options.itemUse?.(def);
62115
- const liquid = sealOf(def, fluidOf({ ...def.model === void 0 ? {} : { model: def.model }, size: def.size, weight: def.weight }));
63058
+ const contents = fluidOf({ ...def.model === void 0 ? {} : { model: def.model }, size: def.size, weight: def.weight });
63059
+ const liquid = sealOf(def, contents.fluid ? contents : vesselOf(def));
62116
63060
  if (!use) return liquid;
62117
63061
  const edible2 = def.category === "food" || def.category === "drink";
62118
63062
  return { ...liquid, ...liquid.fluid && !edible2 ? { fluid: { ...liquid.fluid, uses: ["pour", "pour_out"] } } : {}, use };
@@ -62123,10 +63067,15 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
62123
63067
  movable: true,
62124
63068
  thumbnail: itemThumbnailSvg(drawable(def)),
62125
63069
  ...usesOf(def),
63070
+ ...washOf(def),
63071
+ catalogId: def.id,
63072
+ // what the item spends at each use (detergent, soap): the room takes its doses and shows what is left
63073
+ ...def.consumable ? { consumable: def.consumable } : {},
62126
63074
  // an item with a make-up (a shovel: ash handle riveted to a steel blade) is that spec, not the parts guessed from its meshes
62127
63075
  ...makeupSpecOf(def.model),
62128
63076
  // an item that is also a tool of the arsenal (a shovel) is picked up as that tool
62129
63077
  ...def.weapon ? { weapon: def.weapon } : {},
63078
+ ...def.tools ? { tools: def.tools } : {},
62130
63079
  physical: { weightKg: def.weight, size: def.size, ...def.volume === void 0 ? {} : { litres: def.volume } },
62131
63080
  build: (THREE) => {
62132
63081
  const T2 = THREE;