@chanmeng666/archlang-3d 0.6.0 → 0.8.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.
@@ -1,1198 +0,0 @@
1
- import {
2
- FLOOR_LIFT_UM,
3
- FLOOR_OVERLAP_MIN_UM2,
4
- T0_HEIGHT_MM,
5
- T0_HUNG_FROM_TOP,
6
- T0_MATERIALS,
7
- T0_MOUNT_MM,
8
- assetFor,
9
- buildScene3D,
10
- cutSector,
11
- degenerateHoles,
12
- floorOverlaps,
13
- insideCut,
14
- isHandedAsset,
15
- isHung,
16
- mixedHeightJoints,
17
- overlapArea,
18
- prism,
19
- rect,
20
- sectorBand,
21
- slab2d,
22
- t0Shells,
23
- wallOwnership,
24
- where
25
- } from "./chunk-6WCS4TAT.js";
26
- import {
27
- FENCE_PALETTE,
28
- GROUND_PLANE,
29
- GROUND_SPLITS,
30
- GROUND_TINT,
31
- GROUND_WASH,
32
- STAIR_MATERIAL,
33
- floorFinish
34
- } from "./chunk-TNNJ7CAO.js";
35
-
36
- // src/adapter/adapt.ts
37
- import * as core from "@chanmeng666/archlang";
38
- var MIN_CORE = "1.57.0";
39
- var hasHanded = (storeys) => storeys.some((s) => s.ir.elements.some((e) => e.kind === "furniture" && isHandedAsset(assetFor(e.category))));
40
- function mirroredIds(source, world, n) {
41
- const unknown = Array.from({ length: n }, () => null);
42
- const planToJson2 = core.planToJson;
43
- if (typeof planToJson2 !== "function") return unknown;
44
- const r = planToJson2(source, world ? { world } : {});
45
- const pages = r.pages ? r.pages.map((p) => p.json) : r.json ? [r.json] : [];
46
- if (pages.length !== n) return unknown;
47
- return pages.map((j) => new Set(j.furniture.flatMap((f) => f.mirror === true && f.id !== void 0 ? [f.id] : [])));
48
- }
49
- function adaptPlan(source, opts = {}) {
50
- const resolvePlan2 = core.resolvePlan;
51
- const hatches = core.hatchKey;
52
- if (typeof resolvePlan2 !== "function" || typeof hatches !== "function") {
53
- return {
54
- ok: false,
55
- refusal: {
56
- code: "E3D_CORE_TOO_OLD",
57
- message: `@chanmeng666/archlang is too old (no resolvePlan or hatchKey); archlang-3d needs ${MIN_CORE} or later.`
58
- }
59
- };
60
- }
61
- const res = resolvePlan2(source, opts.world ? { world: opts.world } : {});
62
- const errors = res.diagnostics.filter((d) => d.severity === "error");
63
- if (!res.ir || errors.length > 0) {
64
- const codes = [...new Set(errors.map((d) => d.code))].join(", ");
65
- return {
66
- ok: false,
67
- refusal: {
68
- code: "E3D_PLAN_ERRORS",
69
- message: `The plan does not resolve (${codes || "no IR"}); fix it with \`arch validate\` first.`,
70
- diagnostics: errors
71
- }
72
- };
73
- }
74
- const storeys = res.levels.length > 0 ? res.levels.map((l) => ({ level: l.level, ...l.name ? { name: l.name } : {}, ir: l.ir })) : [{ level: 1, ir: res.ir }];
75
- if (storeys.every((s) => s.ir.walls.length === 0)) {
76
- return {
77
- ok: false,
78
- refusal: { code: "E3D_NO_WALLS", message: "The plan has no walls, so there is nothing to raise." }
79
- };
80
- }
81
- const scene = buildScene3D(storeys, {
82
- coreVersion: opts.coreVersion ?? "unknown",
83
- ...opts.curveTolMm !== void 0 ? { curveTolMm: opts.curveTolMm } : {},
84
- ...hasHanded(storeys) ? { mirrored: mirroredIds(source, opts.world, storeys.length) } : {}
85
- });
86
- return {
87
- ok: true,
88
- scene,
89
- storeys,
90
- diagnostics: res.diagnostics,
91
- warnings: [
92
- ...storeys.flatMap((s) => mixedHeightJoints(wallOwnership(s.ir.walls)).map((w) => ({ ...w, level: s.level }))),
93
- ...scene.levels.flatMap((lv) => floorOverlaps(lv.floors).map((w) => ({ ...w, level: lv.level })))
94
- ]
95
- };
96
- }
97
-
98
- // src/mesh/slab.ts
99
- var rectPolygon = (r) => ({
100
- outer: [
101
- [r[0], r[1]],
102
- [r[2], r[1]],
103
- [r[2], r[3]],
104
- [r[0], r[3]]
105
- ]
106
- });
107
- function rectMinus(a, b) {
108
- const [x0, y0, x1, y1] = [Math.max(a[0], b[0]), Math.max(a[1], b[1]), Math.min(a[2], b[2]), Math.min(a[3], b[3])];
109
- if (!(x0 < x1 && y0 < y1)) return [a];
110
- const out = [];
111
- if (a[1] < y0) out.push([a[0], a[1], a[2], y0]);
112
- if (y1 < a[3]) out.push([a[0], y1, a[2], a[3]]);
113
- if (a[0] < x0) out.push([a[0], y0, x0, y1]);
114
- if (x1 < a[2]) out.push([x1, y0, a[2], y1]);
115
- return out;
116
- }
117
- var rectilinear = (r) => r.every((p, i) => {
118
- const q = r[(i + 1) % r.length];
119
- return p[0] === q[0] || p[1] === q[1];
120
- });
121
- function rectsOf(r) {
122
- const ys = [...new Set(r.map((p) => p[1]))].sort((a, b) => a - b);
123
- const out = [];
124
- for (let k = 0; k + 1 < ys.length; k++) {
125
- const [y0, y1] = [ys[k], ys[k + 1]];
126
- const xs = [];
127
- for (let i = 0; i < r.length; i++) {
128
- const a = r[i];
129
- const b = r[(i + 1) % r.length];
130
- if (a[0] === b[0] && Math.min(a[1], b[1]) <= y0 && Math.max(a[1], b[1]) >= y1) xs.push(a[0]);
131
- }
132
- xs.sort((a, b) => a - b);
133
- for (let i = 0; i + 1 < xs.length; i += 2)
134
- if (xs[i] < xs[i + 1]) out.push([xs[i], y0, xs[i + 1], y1]);
135
- }
136
- return out;
137
- }
138
- function covered(room, rings) {
139
- const probes = room.flatMap((p, i) => {
140
- const q = room[(i + 1) % room.length];
141
- return [p, [(p[0] + q[0]) / 2, (p[1] + q[1]) / 2]];
142
- });
143
- return rings.some((r) => probes.every((p) => where(p, r) !== false) && !r.some((p) => where(p, room) === true));
144
- }
145
- function apart(room, rings) {
146
- return rings.every((r) => room.every((p) => where(p, r) !== true) && r.every((p) => where(p, room) !== true));
147
- }
148
- function slabRegion(footprint, floors, ledger) {
149
- const out = footprint.map((r) => ({ outer: [...r] }));
150
- const exact = footprint.every(rectilinear);
151
- let taken = exact ? footprint.flatMap(rectsOf) : [];
152
- const added = [];
153
- for (const f of floors) {
154
- const room = f.polygon.outer;
155
- const unsplit = () => {
156
- ledger.push({
157
- kind: "slab",
158
- id: f.id,
159
- field: "union",
160
- value: "room overlaps the outline or an earlier room: added whole",
161
- provenance: "default",
162
- rule: "slab-room-unsplit"
163
- });
164
- };
165
- if (exact && rectilinear(room)) {
166
- let pieces = rectsOf(room);
167
- for (const t of taken) pieces = pieces.flatMap((p) => rectMinus(p, t));
168
- taken = [...taken, ...pieces];
169
- for (const p of pieces) out.push(rectPolygon(p));
170
- if (!pieces.every((p) => apart(rectPolygon(p).outer, added))) unsplit();
171
- continue;
172
- }
173
- const others = [...footprint, ...added, ...taken.map((t) => rectPolygon(t).outer)];
174
- if (covered(room, others)) continue;
175
- if (!apart(room, others)) unsplit();
176
- out.push({ outer: [...room] });
177
- added.push(room);
178
- }
179
- return out;
180
- }
181
- var PROBE_MIN = 2;
182
- var PROBE_OFF = 1;
183
- function meets(a, b, c, d) {
184
- const rx = b[0] - a[0];
185
- const ry = b[1] - a[1];
186
- const sx = d[0] - c[0];
187
- const sy = d[1] - c[1];
188
- const qx = c[0] - a[0];
189
- const qy = c[1] - a[1];
190
- const den = rx * sy - ry * sx;
191
- if (den !== 0) {
192
- const t = (qx * sy - qy * sx) / den;
193
- const u = (qx * ry - qy * rx) / den;
194
- return t >= 0 && t <= 1 && u >= 0 && u <= 1 ? [t] : [];
195
- }
196
- if (qx * ry - qy * rx !== 0) return [];
197
- const rr = rx * rx + ry * ry;
198
- return [qx * rx + qy * ry, (d[0] - a[0]) * rx + (d[1] - a[1]) * ry].map((x) => x / rr).filter((t) => t > 0 && t < 1);
199
- }
200
- function stretches(a, b, cutters) {
201
- const len = Math.hypot(b[0] - a[0], b[1] - a[1]);
202
- const ts = [0, 1, ...cutters.flatMap(([c, d]) => meets(a, b, c, d))].sort((x, y) => x - y);
203
- const out = [];
204
- for (let i = 1; i < ts.length; i++) {
205
- const t0 = ts[i - 1];
206
- const t1 = ts[i];
207
- if ((t1 - t0) * len < PROBE_MIN) continue;
208
- const t = (t0 + t1) / 2;
209
- out.push([a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t]);
210
- }
211
- return out;
212
- }
213
- var edgesOf = (r) => r.map((p, i) => [p, r[(i + 1) % r.length]]);
214
- function coveredBy(ring, region) {
215
- if (region.length === 0 || ring.length < 3) return false;
216
- const inRegion = (p) => region.some((s) => where(p, s.outer) !== false && !(s.holes ?? []).some((h) => where(p, h) === true));
217
- const ringEdges = edgesOf(ring);
218
- const regionEdges = region.flatMap((s) => [s.outer, ...s.holes ?? []].flatMap(edgesOf));
219
- for (const [a, b] of ringEdges) {
220
- if (!inRegion(a)) return false;
221
- if (!stretches(a, b, regionEdges).every(inRegion)) return false;
222
- }
223
- for (const [a, b] of regionEdges) {
224
- const len = Math.hypot(b[0] - a[0], b[1] - a[1]);
225
- if (len === 0) continue;
226
- const nx = -(b[1] - a[1]) / len * PROBE_OFF;
227
- const ny = (b[0] - a[0]) / len * PROBE_OFF;
228
- for (const m of stretches(a, b, ringEdges)) {
229
- if (where(m, ring) !== true) continue;
230
- if (!inRegion([m[0] + nx, m[1] + ny]) || !inRegion([m[0] - nx, m[1] - ny])) return false;
231
- }
232
- }
233
- return true;
234
- }
235
-
236
- // src/mesh/stair.ts
237
- function stairRisers(flights) {
238
- return flights.reduce((n, f) => n + f.treads + 1, 0);
239
- }
240
- function runCoordinate(f, d) {
241
- const [x, y] = f.at;
242
- switch (f.foot) {
243
- case "bottom":
244
- return y + f.size.h - d;
245
- case "top":
246
- return y + d;
247
- case "right":
248
- return x + f.size.w - d;
249
- case "left":
250
- return x + d;
251
- }
252
- }
253
- var alongY = (foot) => foot === "top" || foot === "bottom";
254
- function sideways(section, c0, c1, runAlongY) {
255
- const up = prism({ outer: section }, c0, c1);
256
- if (!up) return null;
257
- const positions = [];
258
- for (let i = 0; i < up.positions.length; i += 3) {
259
- const [u, h, v] = [up.positions[i], up.positions[i + 1], up.positions[i + 2]];
260
- if (runAlongY) positions.push(h, v, u);
261
- else positions.push(u, v, h);
262
- }
263
- const indices = [...up.indices];
264
- if (!runAlongY) {
265
- for (let t = 0; t < indices.length; t += 3) {
266
- const b = indices[t + 1];
267
- indices[t + 1] = indices[t + 2];
268
- indices[t + 2] = b;
269
- }
270
- }
271
- return { positions, indices };
272
- }
273
- function stairSolid(stair, z0, rise) {
274
- const flights = stair.flights;
275
- if (!flights?.length || !(rise > 0)) return null;
276
- const R = stairRisers(flights);
277
- const riserTop = (k) => z0 + Math.round(rise * k / R);
278
- const shells = [];
279
- const landingTops = [];
280
- let dropped = 0;
281
- let climbed = 0;
282
- flights.forEach((f, i) => {
283
- const n = f.treads;
284
- const yRun = alongY(f.foot);
285
- const run = yRun ? f.size.h : f.size.w;
286
- const [lo, extent] = yRun ? [f.at[0], f.size.w] : [f.at[1], f.size.h];
287
- const width = Math.min(stair.width, extent);
288
- const c0 = lo + Math.round((extent - width) / 2);
289
- const c1 = c0 + width;
290
- const at2 = (t) => runCoordinate(f, Math.round(run * t / n));
291
- const section = [[at2(0), z0]];
292
- for (let t = 0; t < n; t++) {
293
- const h = riserTop(climbed + t + 1);
294
- section.push([at2(t), h], [at2(t + 1), h]);
295
- }
296
- section.push([at2(n), z0]);
297
- const s = sideways(section, c0, c1, yRun);
298
- if (s) shells.push(s);
299
- else dropped++;
300
- climbed += n + 1;
301
- const landing = stair.landings?.[i];
302
- if (landing && i < flights.length - 1) {
303
- const top = riserTop(climbed);
304
- landingTops.push(top);
305
- const box = prism(
306
- rect(landing.at[0], landing.at[1], landing.at[0] + landing.size.w, landing.at[1] + landing.size.h),
307
- z0,
308
- top
309
- );
310
- if (box) shells.push(box);
311
- else dropped++;
312
- }
313
- });
314
- return { shells, risers: R, landingTops, top: riserTop(R - 1), dropped };
315
- }
316
-
317
- // src/mesh/outdoor.ts
318
- import { DEFAULT_THEME } from "@chanmeng666/archlang";
319
- var OUTDOOR_MM = 50;
320
- var FENCE_HEIGHT_MM = { picket: 1e3, panel: 1800, post: 1100 };
321
- var CORE_POST_PITCH_MM = { picket: 600, panel: 1800, post: 1800 };
322
- var CORE_POSTS_PER_RUN = [1, 60];
323
- var FENCE_PROFILES = {
324
- picket: {
325
- post: 80,
326
- rails: [
327
- [20, 150, 220],
328
- [20, 700, 770]
329
- ],
330
- pickets: [70, 20, 140]
331
- },
332
- panel: { post: 100, rails: [[40, 0, 1800]] },
333
- post: { post: 100, rails: [[60, 1040, 1100]] }
334
- };
335
- var MAX_FENCE_REPEAT = 400;
336
- var MM = 1e3;
337
- var tintOf = (surface) => GROUND_TINT[surface];
338
- function groundColour(tint, theme = DEFAULT_THEME) {
339
- const ch = (hex, i) => Number.parseInt(hex.slice(i, i + 2), 16);
340
- const bg = theme.bg;
341
- const wash = theme[tint];
342
- const out = [1, 3, 5].map((i) => {
343
- const v = ch(bg, i) - GROUND_WASH * (ch(bg, i) - ch(wash, i));
344
- return Math.max(0, Math.min(255, v)).toString(16).padStart(2, "0");
345
- });
346
- return `#${out.join("")}`;
347
- }
348
- function outdoorColour(surface) {
349
- const split = GROUND_SPLITS[surface];
350
- if (split) return { srgb: split.srgb, rule: "outdoor-colour-3d" };
351
- return { srgb: groundColour(tintOf(surface) ?? "paving"), rule: "outdoor-colour-theme" };
352
- }
353
- var fenceColour = (style) => (FENCE_PALETTE[style] ?? FENCE_PALETTE.picket).srgb;
354
- var at = (a, b, f) => [
355
- Math.round(a[0] + (b[0] - a[0]) * f),
356
- Math.round(a[1] + (b[1] - a[1]) * f)
357
- ];
358
- function corePostCount(lenUm, style) {
359
- const pitch = CORE_POST_PITCH_MM[style] ?? CORE_POST_PITCH_MM.picket;
360
- const [lo, hi] = CORE_POSTS_PER_RUN;
361
- return Math.max(lo, Math.min(hi, Math.round(lenUm / MM / pitch)));
362
- }
363
- function fenceRuns(f) {
364
- const pts = f.points;
365
- const all = [];
366
- for (let i = 0; i + 1 < pts.length; i++) all.push([pts[i], pts[i + 1]]);
367
- if (f.closed && pts.length > 2) all.push([pts[pts.length - 1], pts[0]]);
368
- const runs = all.filter(([a, b]) => Math.hypot(b[0] - a[0], b[1] - a[1]) > 0);
369
- return { runs, ring: f.closed && pts.length > 2 && runs.length > 1 };
370
- }
371
- function fencePosts(f) {
372
- const { runs, ring } = fenceRuns(f);
373
- const out = [];
374
- runs.forEach(([a, b], i) => {
375
- const n = corePostCount(Math.hypot(b[0] - a[0], b[1] - a[1]), f.style);
376
- for (let k = 0; k < n; k++) out.push({ at: at(a, b, k / n), run: [a, b] });
377
- if (i === runs.length - 1 && !ring) out.push({ at: b, run: [a, b] });
378
- });
379
- return out;
380
- }
381
- function fencePieces(f, profile, height) {
382
- const out = [];
383
- const box = (c, [a, b], w, d) => {
384
- const len = Math.hypot(b[0] - a[0], b[1] - a[1]);
385
- const ux = (b[0] - a[0]) / len;
386
- const uy = (b[1] - a[1]) / len;
387
- const p = (s) => [Math.round(c[0] + ux * s), Math.round(c[1] + uy * s)];
388
- return slab2d(p(-w / 2), p(w / 2), d);
389
- };
390
- for (const p of fencePosts(f))
391
- out.push({ poly: box(p.at, p.run, profile.post * MM, profile.post * MM), z: [0, height] });
392
- for (const [a, b] of fenceRuns(f).runs) {
393
- const len = Math.hypot(b[0] - a[0], b[1] - a[1]);
394
- for (const [depth, z0, z1] of profile.rails)
395
- out.push({ poly: slab2d(a, b, depth * MM), z: [Math.min(z0, height), Math.min(z1, height)] });
396
- if (profile.pickets) {
397
- const [w, d, pitch] = profile.pickets;
398
- const m = Math.max(1, Math.min(MAX_FENCE_REPEAT, Math.ceil(len / (pitch * MM))));
399
- const pw = Math.min(w * MM, len / m);
400
- for (let j = 0; j < m; j++) out.push({ poly: box(at(a, b, (j + 0.5) / m), [a, b], pw, d * MM), z: [0, height] });
401
- }
402
- }
403
- return out;
404
- }
405
-
406
- // src/mesh/build.ts
407
- var MM2 = 1e3;
408
- var SLAB_MM = 200;
409
- var FLOOR_FINISH_MM = 5;
410
- var ROOF_MM = 150;
411
- var LEAF_MM = 40;
412
- var GLASS_MM = 16;
413
- var FRAME_WIDTH_MM = 40;
414
- var FRAME_DEPTH_MM = 60;
415
- var FURNITURE_DEFAULT_MM = 750;
416
- var FURNITURE_HEIGHT_MM = {
417
- bed: 500,
418
- double_bed: 500,
419
- bunk_bed: 1600,
420
- sofa: 800,
421
- armchair: 800,
422
- chair: 850,
423
- table: 750,
424
- dining_table: 750,
425
- desk: 750,
426
- wardrobe: 2e3,
427
- bookshelf: 1800,
428
- fridge: 1800,
429
- stove: 900,
430
- kitchen_sink: 900,
431
- counter: 900,
432
- dishwasher: 850,
433
- washing_machine: 850,
434
- wc: 750,
435
- basin: 850,
436
- bath: 550,
437
- shower: 50,
438
- tv: 600,
439
- rug: 10
440
- };
441
- var STAGE = {
442
- slab: "brief",
443
- floor: "rooms",
444
- column: "walls",
445
- wall: "walls",
446
- roof: "walls",
447
- door: "openings",
448
- window: "openings",
449
- opening: "openings",
450
- furniture: "fixtures",
451
- stair: "walls",
452
- // The site (card RM8.3): its surfaces are laid out with the slab, before the rooms; a fence rises
453
- // with the storey's walls.
454
- outdoor: "brief",
455
- fence: "walls"
456
- };
457
- var byText = (a, b) => a < b ? -1 : a > b ? 1 : 0;
458
- function along(a, b, d) {
459
- const len = Math.hypot(b[0] - a[0], b[1] - a[1]) || 1;
460
- return [Math.round(a[0] + (b[0] - a[0]) / len * d), Math.round(a[1] + (b[1] - a[1]) / len * d)];
461
- }
462
- var inRing = (p, r) => {
463
- let c = false;
464
- for (let i = 0, j = r.length - 1; i < r.length; j = i++) {
465
- const a = r[i];
466
- const b = r[j];
467
- if (a[1] > p[1] !== b[1] > p[1] && p[0] < (b[0] - a[0]) * (p[1] - a[1]) / (b[1] - a[1]) + a[0]) c = !c;
468
- }
469
- return c;
470
- };
471
- function asRect(ring) {
472
- if (ring.length !== 4) return null;
473
- const xs = [...new Set(ring.map((p) => p[0]))];
474
- const ys = [...new Set(ring.map((p) => p[1]))];
475
- if (xs.length !== 2 || ys.length !== 2) return null;
476
- const axis = ring.every((p, i) => {
477
- const q = ring[(i + 1) % 4];
478
- return p[0] === q[0] || p[1] === q[1];
479
- });
480
- return axis ? [Math.min(...xs), Math.min(...ys), Math.max(...xs), Math.max(...ys)] : null;
481
- }
482
- function rectTouches(r, ring) {
483
- const corners = [
484
- [r[0], r[1]],
485
- [r[2], r[1]],
486
- [r[2], r[3]],
487
- [r[0], r[3]]
488
- ];
489
- if (corners.some((c) => inRing(c, ring))) return true;
490
- return ring.some((p) => p[0] >= r[0] && p[0] <= r[2] && p[1] >= r[1] && p[1] <= r[3]);
491
- }
492
- function lessVoids(outer, voids, where2, ledger) {
493
- const rects = voids.map((v) => ({ id: v.id, r: [v.at[0], v.at[1], v.at[0] + v.size.w, v.at[1] + v.size.h] }));
494
- const box = asRect(outer);
495
- if (box) {
496
- let pieces = [box];
497
- for (const v of rects) pieces = pieces.flatMap((p) => rectMinus(p, v.r));
498
- return pieces.map((p) => rect(p[0], p[1], p[2], p[3]));
499
- }
500
- const holes = [];
501
- const taken = [];
502
- for (const v of rects) {
503
- if (!rectTouches(v.r, outer)) continue;
504
- const corners = rect(v.r[0], v.r[1], v.r[2], v.r[3]).outer;
505
- const strict = corners.every((c) => inRing(c, outer)) && !outer.some((p) => p[0] >= v.r[0] && p[0] <= v.r[2] && p[1] >= v.r[1] && p[1] <= v.r[3]) && taken.every((t) => t[2] < v.r[0] || v.r[2] < t[0] || t[3] < v.r[1] || v.r[3] < t[1]);
506
- if (strict) {
507
- holes.push(corners);
508
- taken.push(v.r);
509
- } else {
510
- ledger.push({
511
- kind: "void",
512
- id: v.id,
513
- field: "cut",
514
- value: where2,
515
- provenance: "default",
516
- rule: "void-not-cut-non-rect"
517
- });
518
- }
519
- }
520
- return [{ outer: [...outer], ...holes.length ? { holes } : {} }];
521
- }
522
- var DOOR_POSES = ["closed", "plan"];
523
- function openLeaf(h, f, end, t) {
524
- const r = Math.hypot(end[0] - h[0], end[1] - h[1]);
525
- const c = Math.hypot(f[0] - h[0], f[1] - h[1]);
526
- if (r === 0 || c === 0) return { outer: [h, h, h] };
527
- const tt = Math.min(t, r / 2);
528
- const ox = (end[0] - h[0]) / r;
529
- const oy = (end[1] - h[1]) / r;
530
- const ax = (f[0] - h[0]) / c;
531
- const ay = (f[1] - h[1]) / c;
532
- const reach = Math.sqrt(r * r - tt * tt) - 1;
533
- const p = (x, y) => [Math.round(x), Math.round(y)];
534
- return {
535
- outer: [h, end, p(h[0] + ox * reach + ax * tt, h[1] + oy * reach + ay * tt), p(h[0] + ax * tt, h[1] + ay * tt)]
536
- };
537
- }
538
- function leafThroughWall(leaf, walls) {
539
- const [h, end, , inner] = leaf.outer;
540
- if (!h || !end || !inner) return false;
541
- const ox = (inner[0] - h[0]) / 2;
542
- const oy = (inner[1] - h[1]) / 2;
543
- for (let k = 1; k <= 19; k++) {
544
- const s = k / 20;
545
- const p = [h[0] + (end[0] - h[0]) * s + ox, h[1] + (end[1] - h[1]) * s + oy];
546
- for (const w of walls)
547
- for (const piece of w.body)
548
- if (inRing(p, piece.outer) && !(piece.holes ?? []).some((r) => inRing(p, r))) return true;
549
- }
550
- return false;
551
- }
552
- function levelNodes(lv, ledger, defaulted, isTop, doors, below, above) {
553
- const e = lv.elevation;
554
- const out = [];
555
- let holesLeftOut = 0;
556
- const prism2 = (poly, z0, z1, splits2) => {
557
- const s = prism(poly, z0, z1, splits2);
558
- if (s) holesLeftOut += degenerateHoles(poly);
559
- return s;
560
- };
561
- const node = (kind, id, order, shells, extras = {}, part) => {
562
- const ok = shells.filter((s) => s !== null);
563
- if (ok.length < shells.length) {
564
- ledger.push({
565
- kind,
566
- id,
567
- field: "shells_dropped",
568
- value: shells.length - ok.length,
569
- provenance: "derived",
570
- rule: "shell-degenerate-or-touching-hole"
571
- });
572
- }
573
- if (holesLeftOut > 0) {
574
- ledger.push({
575
- kind,
576
- id,
577
- field: "holes_dropped",
578
- value: holesLeftOut,
579
- provenance: "derived",
580
- rule: "hole-degenerate"
581
- });
582
- holesLeftOut = 0;
583
- }
584
- if (ok.length === 0) return;
585
- out.push({
586
- key: `L${lv.level}/${kind}:${id}${part ? `:${part}` : ""}`,
587
- level: lv.level,
588
- kind,
589
- id,
590
- ...part ? { part } : {},
591
- stage: STAGE[kind],
592
- order,
593
- ...kind === "roof" ? { hidden: true } : {},
594
- extras,
595
- shells: ok
596
- });
597
- };
598
- node(
599
- "slab",
600
- "slab",
601
- 0,
602
- slabRegion(lv.footprint, lv.floors, ledger).flatMap((r) => lessVoids(r.outer, lv.voids, "slab", ledger)).map((p) => prism2(p, e - SLAB_MM * MM2, e)),
603
- { thickness_mm: SLAB_MM }
604
- );
605
- lv.floors.forEach((f, i) => {
606
- const pieces = f.polygon.holes?.length ? [f.polygon] : lessVoids(f.polygon.outer, lv.voids, `floor:${f.id}`, ledger);
607
- const z0 = e + (f.lift ?? 0);
608
- const finish = floorFinish(f.uses);
609
- ledger.push({
610
- kind: "floor",
611
- id: f.id,
612
- field: "finish",
613
- value: finish,
614
- provenance: "default",
615
- rule: "floor-finish-default"
616
- });
617
- node(
618
- "floor",
619
- f.id,
620
- i,
621
- pieces.map((p) => prism2(p, z0, z0 + FLOOR_FINISH_MM * MM2)),
622
- {
623
- ...f.uses?.length ? { uses: f.uses.join(" ") } : {},
624
- ...f.lift ? { lift_mm: f.lift / MM2 } : {},
625
- finish
626
- }
627
- );
628
- });
629
- const ceiling = above ? above.elevation - SLAB_MM * MM2 - e : 0;
630
- const slabAbove = above && ceiling > 0 ? slabRegion(above.footprint, above.floors, []).flatMap((r) => lessVoids(r.outer, above.voids, "slab", [])) : [];
631
- const stopped = (height, rings) => height > ceiling && ceiling > 0 && rings.every((r) => coveredBy(r, slabAbove));
632
- const stopLedger = (kind, id) => {
633
- ledger.push({
634
- kind,
635
- id,
636
- field: `top_mm(L${lv.level})`,
637
- value: ceiling / MM2,
638
- provenance: "derived",
639
- rule: "stops-under-slab-above"
640
- });
641
- };
642
- lv.columns.forEach((c, i) => {
643
- const box = rect(c.at[0], c.at[1], c.at[0] + c.size.w, c.at[1] + c.size.h);
644
- const stop = stopped(lv.storeyHeight, [box.outer]);
645
- if (stop) stopLedger("column", c.id);
646
- node("column", c.id, i, [prism2(box, e, e + (stop ? ceiling : lv.storeyHeight))]);
647
- });
648
- const climbs = [];
649
- lv.stairs.forEach((s, i) => {
650
- if (s.dir === "up") {
651
- climbs.push({ s, order: i, rise: above ? above.elevation - e : lv.storeyHeight, from: "own" });
652
- if (!above) {
653
- ledger.push({
654
- kind: "stair",
655
- id: s.id,
656
- field: "rise_mm",
657
- value: lv.storeyHeight / MM2,
658
- provenance: "default",
659
- rule: "stair-rise-storey-height"
660
- });
661
- }
662
- } else if (!below) {
663
- ledger.push({
664
- kind: "stair",
665
- id: s.id,
666
- field: "geometry",
667
- value: "omitted",
668
- provenance: "default",
669
- rule: "stair-down-no-storey-below"
670
- });
671
- }
672
- });
673
- (above?.stairs ?? []).forEach((s, i) => {
674
- const partnered = lv.stairs.some((t) => t.id === s.id && t.dir === "up");
675
- if (s.dir === "down" && !partnered && above)
676
- climbs.push({ s, order: lv.stairs.length + i, rise: above.elevation - e, from: "above" });
677
- });
678
- const stairFloor = e + FLOOR_FINISH_MM * MM2;
679
- for (const { s, order, rise, from } of climbs) {
680
- const solid = stairSolid(s, stairFloor, rise);
681
- if (!solid) {
682
- ledger.push({
683
- kind: "stair",
684
- id: s.id,
685
- field: "geometry",
686
- value: "omitted",
687
- provenance: "default",
688
- rule: s.flights?.length ? "stair-rise-not-positive" : "stair-no-flights"
689
- });
690
- continue;
691
- }
692
- if (!defaulted.has("stair:defaults")) {
693
- defaulted.add("stair:defaults");
694
- ledger.push(
695
- {
696
- kind: "stair",
697
- field: "material",
698
- value: STAIR_MATERIAL,
699
- provenance: "default",
700
- rule: "stair-material-default"
701
- },
702
- { kind: "stair", field: "form", value: "solid", provenance: "default", rule: "stair-solid-default" }
703
- );
704
- }
705
- ledger.push({
706
- kind: "stair",
707
- id: s.id,
708
- field: "risers",
709
- value: solid.risers,
710
- provenance: "derived",
711
- rule: "stair-risers-from-treads"
712
- });
713
- node("stair", s.id, order, [...solid.shells, ...Array.from({ length: solid.dropped }, () => null)], {
714
- dir: s.dir,
715
- width_mm: s.width / MM2,
716
- flights: s.flights?.length ?? 0,
717
- risers: solid.risers,
718
- rise_mm: rise / MM2,
719
- ...from === "above" ? { from_storey_above: true } : {}
720
- });
721
- }
722
- const openings = new Map(lv.openings.map((o) => [o.id, o]));
723
- const wallHeight = new Map(
724
- lv.walls.map((w) => {
725
- const cut = w.cuts.flatMap((id) => {
726
- const o = openings.get(id);
727
- return o ? [o] : [];
728
- });
729
- const stop = stopped(w.height, [...w.body.map((p) => p.outer), ...cut.map((o) => o.cut)]);
730
- if (!stop) return [w.id, w.height];
731
- stopLedger("wall", w.id);
732
- for (const o of cut.filter((x) => x.head > ceiling)) {
733
- ledger.push({
734
- kind: o.kind,
735
- id: o.id,
736
- field: `head_mm(L${lv.level})`,
737
- value: ceiling / MM2,
738
- provenance: "derived",
739
- rule: "head-at-slab-above"
740
- });
741
- }
742
- return [w.id, ceiling];
743
- })
744
- );
745
- const hostHeight = wallHeight;
746
- const splitAt = /* @__PURE__ */ new Map();
747
- for (const o of lv.openings) {
748
- const h = hostHeight.get(o.host);
749
- if (h === void 0) continue;
750
- const hs = [...o.sill > 0 ? [Math.min(o.sill, h)] : [], ...o.head < h ? [o.head] : []];
751
- for (const p of o.cut) {
752
- const k = `${p[0]},${p[1]}`;
753
- splitAt.set(k, [...splitAt.get(k) ?? [], ...hs]);
754
- }
755
- }
756
- const splits = (p) => (splitAt.get(`${p[0]},${p[1]}`) ?? []).map((h) => e + h);
757
- lv.walls.forEach((w, i) => {
758
- const height = wallHeight.get(w.id) ?? w.height;
759
- const top = e + height;
760
- const shells = w.body.map((p) => prism2(p, e, top, splits));
761
- for (const id of w.cuts) {
762
- const o = openings.get(id);
763
- if (!o) continue;
764
- if (o.sill > 0) shells.push(prism2({ outer: o.cut }, e, e + Math.min(o.sill, height)));
765
- if (o.head < height) shells.push(prism2({ outer: o.cut }, e + o.head, top));
766
- }
767
- node("wall", w.id, i, shells, {
768
- ...w.category ? { category: w.category } : {},
769
- height_mm: w.height / MM2,
770
- thickness_mm: w.thickness / MM2
771
- });
772
- });
773
- (lv.demolished ?? []).forEach((w, i) => {
774
- node(
775
- "wall",
776
- w.id,
777
- lv.walls.length + i,
778
- w.body.map((p) => prism2(p, e, e + w.height)),
779
- {
780
- ...w.category ? { category: w.category } : {},
781
- height_mm: w.height / MM2,
782
- status: "demolish",
783
- thickness_mm: w.thickness / MM2
784
- },
785
- "demolish"
786
- );
787
- });
788
- lv.openings.forEach((o, i) => {
789
- const [j0, j1] = o.jambs;
790
- const head = Math.min(o.head, hostHeight.get(o.host) ?? o.head);
791
- const extras = { host: o.host, width_mm: o.width / MM2, sill_mm: o.sill / MM2, head_mm: o.head / MM2 };
792
- if (o.kind === "door") {
793
- const z0 = e + o.sill;
794
- const swung = o.leaves?.every((l) => l.length === 3) ? o.leaves : void 0;
795
- if (doors === "plan" && swung) {
796
- const open = swung.map(([h, f, end]) => openLeaf(h, f, end, LEAF_MM * MM2));
797
- const through = open.some((leaf) => leafThroughWall(leaf, lv.walls));
798
- if (through) {
799
- ledger.push({
800
- kind: "door",
801
- id: o.id,
802
- field: "leaf",
803
- value: "through-wall",
804
- provenance: "derived",
805
- rule: "door-leaf-through-wall"
806
- });
807
- }
808
- node(
809
- "door",
810
- o.id,
811
- i,
812
- open.map((leaf) => prism2(leaf, z0, e + head)),
813
- // `through_wall` rides on the node, so a GLB reader (whose file carries no ledger) sees it too.
814
- { ...extras, door_kind: o.doorKind ?? "hinged", pose: "plan", ...through ? { through_wall: true } : {} }
815
- );
816
- return;
817
- }
818
- if (doors === "plan") {
819
- ledger.push({
820
- kind: "door",
821
- id: o.id,
822
- field: "pose",
823
- value: "closed",
824
- provenance: "default",
825
- rule: "door-pose-plan-no-swing"
826
- });
827
- }
828
- const leaves = o.leaves ?? [[j0, j1]];
829
- node(
830
- "door",
831
- o.id,
832
- i,
833
- leaves.map(([h, f]) => prism2(slab2d(h, f, LEAF_MM * MM2), z0, e + head)),
834
- { ...extras, door_kind: o.doorKind ?? "hinged", pose: "closed" }
835
- );
836
- } else if (o.kind === "window") {
837
- const z0 = e + o.sill;
838
- const z1 = e + head;
839
- const fw = FRAME_WIDTH_MM * MM2;
840
- const fd = FRAME_DEPTH_MM * MM2;
841
- const sector = cutSector(o.cut, o.jambs, o.centre);
842
- if (sector) {
843
- const band = (depth, f0, f1) => sectorBand(sector, -depth / 2, depth / 2, f0, f1);
844
- const f = Math.min(0.5, fw / (sector.r * Math.abs(sector.sweep)));
845
- node("window", o.id, i, [prism2(band(GLASS_MM * MM2), z0, z1)], extras, "glass");
846
- node(
847
- "window",
848
- o.id,
849
- i,
850
- [
851
- prism2(band(fd, 0, f), z0, z1),
852
- prism2(band(fd, 1 - f, 1), z0, z1),
853
- prism2(band(fd), z0, z0 + fw),
854
- prism2(band(fd), z1 - fw, z1)
855
- ],
856
- extras,
857
- "frame"
858
- );
859
- return;
860
- }
861
- const fit = (p, a, b) => {
862
- const q = insideCut(p, o.cut);
863
- return q ? prism2(q, a, b) : null;
864
- };
865
- node("window", o.id, i, [fit(slab2d(j0, j1, GLASS_MM * MM2), z0, z1)], extras, "glass");
866
- node(
867
- "window",
868
- o.id,
869
- i,
870
- [
871
- fit(slab2d(j0, along(j0, j1, fw), fd), z0, z1),
872
- fit(slab2d(along(j1, j0, fw), j1, fd), z0, z1),
873
- fit(slab2d(j0, j1, fd), z0, z0 + fw),
874
- fit(slab2d(j0, j1, fd), z1 - fw, z1)
875
- ],
876
- extras,
877
- "frame"
878
- );
879
- }
880
- });
881
- const floorTop = e + FLOOR_FINISH_MM * MM2;
882
- const tallest = lv.walls.reduce((m, w) => Math.max(m, w.height), 0) || lv.storeyHeight;
883
- const tallestBuilt = lv.walls.reduce((m, w) => Math.max(m, wallHeight.get(w.id) ?? w.height), 0) || lv.storeyHeight;
884
- lv.furniture.forEach((f, i) => {
885
- const parts = t0Shells(f, floorTop);
886
- const family = parts ? f.asset.slice("t0:".length) : void 0;
887
- const h = family ? T0_HEIGHT_MM[family] ?? 0 : FURNITURE_HEIGHT_MM[f.category] ?? FURNITURE_DEFAULT_MM;
888
- if (!defaulted.has(f.category)) {
889
- defaulted.add(f.category);
890
- ledger.push({
891
- kind: "furniture",
892
- field: `height_mm(${f.category})`,
893
- value: h,
894
- provenance: "default",
895
- rule: family ? "furniture-height-t0" : f.category in FURNITURE_HEIGHT_MM ? "furniture-height-family" : "furniture-height-greybox"
896
- });
897
- const mount = family ? T0_MOUNT_MM[family] : void 0;
898
- if (mount !== void 0) {
899
- ledger.push({
900
- kind: "furniture",
901
- field: `mount_mm(${f.category})`,
902
- value: mount,
903
- provenance: "default",
904
- rule: "furniture-mount-default"
905
- });
906
- }
907
- const slots = family ? T0_MATERIALS[family] : void 0;
908
- if (slots?.length) {
909
- ledger.push({
910
- kind: "furniture",
911
- field: `material(${f.category})`,
912
- value: [...slots],
913
- provenance: "default",
914
- rule: "furniture-material-default"
915
- });
916
- }
917
- }
918
- const asset = parts ? f.asset : "greybox";
919
- if (f.asset !== asset) {
920
- ledger.push({
921
- kind: "furniture",
922
- id: f.id,
923
- field: "asset",
924
- value: "greybox",
925
- provenance: "default",
926
- rule: "furniture-t0-not-quarter-turn"
927
- });
928
- }
929
- if (parts && family && isHung(family)) {
930
- if (T0_HUNG_FROM_TOP.has(family)) {
931
- const low = Math.min(...parts.shells.flatMap((s) => s ? s.positions.filter((_, k) => k % 3 === 1) : []));
932
- ledger.push({
933
- kind: "furniture",
934
- id: f.id,
935
- field: "mount_mm",
936
- value: (low - floorTop) / MM2,
937
- provenance: "default",
938
- rule: "furniture-mount-from-top"
939
- });
940
- }
941
- if (floorTop + h * MM2 > e + tallestBuilt) {
942
- ledger.push({
943
- kind: "furniture",
944
- id: f.id,
945
- field: "top_mm",
946
- value: h,
947
- provenance: "default",
948
- rule: "furniture-hung-above-walls"
949
- });
950
- }
951
- } else if (parts && family && floorTop + h * MM2 > e + tallestBuilt) {
952
- ledger.push({
953
- kind: "furniture",
954
- id: f.id,
955
- field: "top_mm",
956
- value: h,
957
- provenance: "default",
958
- rule: "furniture-above-walls"
959
- });
960
- }
961
- const [cx, cy] = f.centre;
962
- const box = rect(cx - f.size.w / 2, cy - f.size.d / 2, cx + f.size.w / 2, cy + f.size.d / 2);
963
- if (parts) holesLeftOut += parts.holesDropped;
964
- const shells = parts ? parts.shells : [prism2(box, floorTop, floorTop + h * MM2)];
965
- node("furniture", f.id, i, shells, {
966
- category: f.category,
967
- yaw_deg: f.yawDeg,
968
- asset,
969
- ...f.room ? { room: f.room } : {},
970
- ...parts && f.mirror ? { mirror: true } : {}
971
- });
972
- });
973
- const roofZ = [e + tallest, e + tallest + ROOF_MM * MM2];
974
- lv.roofs.forEach((r, i) => {
975
- node("roof", r.id, i, [prism2({ outer: r.ring }, ...roofZ)], { form: r.form });
976
- });
977
- if (isTop && lv.roofs.length === 0 && lv.footprint.length > 0) {
978
- ledger.push({
979
- kind: "roof",
980
- id: `L${lv.level}`,
981
- field: "ring",
982
- value: "wall footprint",
983
- provenance: "default",
984
- rule: "roof-default-footprint"
985
- });
986
- node(
987
- "roof",
988
- "roof",
989
- 0,
990
- lv.footprint.map((ring) => prism2({ outer: ring }, ...roofZ)),
991
- { form: "flat" }
992
- );
993
- }
994
- const slabHere = slabRegion(lv.footprint, lv.floors, []).flatMap((r) => lessVoids(r.outer, lv.voids, "slab", []));
995
- const over = (p, q) => overlapArea(p, q) > FLOOR_OVERLAP_MIN_UM2;
996
- const steps = /* @__PURE__ */ new Map();
997
- lv.outdoor.forEach((o, i) => {
998
- const earlier = lv.outdoor.slice(0, i).filter((p) => over(p.polygon, o.polygon));
999
- const onSlab = slabHere.some((s) => over(s, o.polygon));
1000
- const floorsUnder = lv.floors.filter((f) => over(f.polygon, o.polygon));
1001
- const taken = /* @__PURE__ */ new Set([
1002
- ...onSlab ? [0] : [],
1003
- ...floorsUnder.flatMap((f) => [f.lift ?? 0, (f.lift ?? 0) + FLOOR_FINISH_MM * MM2]),
1004
- ...earlier.map((p) => (steps.get(p.id) ?? 0) * FLOOR_LIFT_UM)
1005
- ]);
1006
- let step = Math.max(onSlab ? 1 : 0, ...earlier.map((p) => 1 + (steps.get(p.id) ?? 0)));
1007
- while (taken.has(step * FLOOR_LIFT_UM)) step++;
1008
- steps.set(o.id, step);
1009
- const lift = step * FLOOR_LIFT_UM;
1010
- if (lift > 0) {
1011
- ledger.push({
1012
- kind: "outdoor",
1013
- id: o.id,
1014
- field: "lift_mm",
1015
- value: lift / MM2,
1016
- provenance: "derived",
1017
- rule: "outdoor-overlap-lift"
1018
- });
1019
- }
1020
- if (!defaulted.has("outdoor:thickness")) {
1021
- defaulted.add("outdoor:thickness");
1022
- ledger.push({
1023
- kind: "outdoor",
1024
- field: "thickness_mm",
1025
- value: OUTDOOR_MM,
1026
- provenance: "default",
1027
- rule: "outdoor-thickness-default"
1028
- });
1029
- ledger.push({
1030
- kind: "outdoor",
1031
- field: "wash",
1032
- value: GROUND_WASH,
1033
- provenance: "default",
1034
- rule: "outdoor-colour-wash"
1035
- });
1036
- }
1037
- const colour = outdoorColour(o.surface);
1038
- if (!defaulted.has(`outdoor:${o.surface}`)) {
1039
- defaulted.add(`outdoor:${o.surface}`);
1040
- ledger.push({
1041
- kind: "outdoor",
1042
- field: `colour(${o.surface})`,
1043
- value: colour.srgb,
1044
- provenance: "default",
1045
- rule: tintOf(o.surface) ? colour.rule : "outdoor-surface-unknown"
1046
- });
1047
- }
1048
- if (o.rail?.length) {
1049
- ledger.push({
1050
- kind: "outdoor",
1051
- id: o.id,
1052
- field: "rail",
1053
- value: "omitted",
1054
- provenance: "default",
1055
- rule: "outdoor-rail-omitted"
1056
- });
1057
- }
1058
- node("outdoor", o.id, i, [prism2(o.polygon, e - OUTDOOR_MM * MM2 + lift, e + lift)], {
1059
- surface: o.surface,
1060
- colour: colour.srgb,
1061
- thickness_mm: OUTDOOR_MM,
1062
- ...lift > 0 ? { lift_mm: lift / MM2 } : {}
1063
- });
1064
- });
1065
- lv.fences.forEach((f, i) => {
1066
- const known = f.style in FENCE_PROFILES;
1067
- const style = known ? f.style : "picket";
1068
- const profile = FENCE_PROFILES[style];
1069
- const height = FENCE_HEIGHT_MM[style];
1070
- const pieces = fencePieces({ ...f, style }, profile, height);
1071
- if (pieces.length === 0) {
1072
- ledger.push({
1073
- kind: "fence",
1074
- id: f.id,
1075
- field: "geometry",
1076
- value: "omitted",
1077
- provenance: "derived",
1078
- rule: "fence-no-run"
1079
- });
1080
- return;
1081
- }
1082
- if (!defaulted.has(`fence:${f.style}`)) {
1083
- defaulted.add(`fence:${f.style}`);
1084
- ledger.push(
1085
- {
1086
- kind: "fence",
1087
- field: `height_mm(${f.style})`,
1088
- value: height,
1089
- provenance: "default",
1090
- rule: known ? "fence-height-default" : "fence-style-unknown"
1091
- },
1092
- {
1093
- kind: "fence",
1094
- field: `profile(${f.style})`,
1095
- value: {
1096
- post_mm: profile.post,
1097
- // The core's own spacing: a post on every tick it draws (`fencePosts`).
1098
- post_pitch_mm: CORE_POST_PITCH_MM[style],
1099
- rails_mm: profile.rails.map((r) => [...r]),
1100
- ...profile.pickets ? { pickets_mm: [...profile.pickets] } : {}
1101
- },
1102
- provenance: "default",
1103
- rule: "fence-profile-default"
1104
- },
1105
- {
1106
- kind: "fence",
1107
- field: `colour(${f.style})`,
1108
- value: fenceColour(f.style),
1109
- provenance: "default",
1110
- rule: "fence-colour-default"
1111
- }
1112
- );
1113
- }
1114
- node(
1115
- "fence",
1116
- f.id,
1117
- i,
1118
- pieces.map((p) => prism2(p.poly, e + p.z[0] * MM2, e + p.z[1] * MM2)),
1119
- { style: f.style, colour: fenceColour(f.style), height_mm: height, closed: f.closed }
1120
- );
1121
- });
1122
- return out;
1123
- }
1124
- function buildMesh(scene, opts = {}) {
1125
- const doors = opts.doors ?? "closed";
1126
- const asked = {
1127
- kind: "door",
1128
- field: "pose",
1129
- value: "plan",
1130
- provenance: "user-param",
1131
- rule: "door-pose-plan"
1132
- };
1133
- const ledger = [
1134
- ...doors === "closed" ? scene.meta.assumptions : scene.meta.assumptions.map((a) => a.rule === "door-pose-closed" ? asked : a),
1135
- { kind: "slab", field: "thickness_mm", value: SLAB_MM, provenance: "default", rule: "slab-default-200" },
1136
- { kind: "floor", field: "finish_mm", value: FLOOR_FINISH_MM, provenance: "default", rule: "floor-finish-5" },
1137
- {
1138
- kind: "window",
1139
- field: "frame_mm",
1140
- value: [FRAME_WIDTH_MM, FRAME_DEPTH_MM],
1141
- provenance: "default",
1142
- rule: "window-frame-40x60"
1143
- },
1144
- { kind: "door", field: "leaf_mm", value: LEAF_MM, provenance: "default", rule: "door-leaf-40" },
1145
- { kind: "roof", field: "thickness_mm", value: ROOF_MM, provenance: "default", rule: "roof-flat-150" },
1146
- // Card RM8.3 builds outdoor surfaces and fences (it replaced the two `m1-omits-outdoor-fences`
1147
- // rows here; their defaults are ledgered per kind and style where they are built). The ground
1148
- // plane the viewer draws round the building is in no node, so it is said here, in every Mesh3D.
1149
- {
1150
- kind: "ground",
1151
- field: "plane",
1152
- value: {
1153
- drawn: "viewer only",
1154
- level: scene.levels[0]?.level ?? 0,
1155
- margin_mm: GROUND_PLANE.marginMm,
1156
- colour: GROUND_PLANE.light,
1157
- colour_dark: GROUND_PLANE.dark
1158
- },
1159
- provenance: "default",
1160
- rule: "ground-plane-viewer-only"
1161
- }
1162
- ];
1163
- const defaulted = /* @__PURE__ */ new Set();
1164
- const top = scene.levels.length - 1;
1165
- const nodes = scene.levels.flatMap(
1166
- (lv, i) => levelNodes(lv, ledger, defaulted, i === top, doors, scene.levels[i - 1], scene.levels[i + 1])
1167
- );
1168
- nodes.sort(
1169
- (a, b) => a.level - b.level || byText(a.kind, b.kind) || byText(a.id, b.id) || byText(a.part ?? "", b.part ?? "")
1170
- );
1171
- return { version: 0, kind: "mesh3d", name: scene.meta.name, assumptions: ledger, nodes };
1172
- }
1173
-
1174
- export {
1175
- MIN_CORE,
1176
- adaptPlan,
1177
- rectsOf,
1178
- slabRegion,
1179
- stairRisers,
1180
- stairSolid,
1181
- OUTDOOR_MM,
1182
- FENCE_HEIGHT_MM,
1183
- CORE_POST_PITCH_MM,
1184
- CORE_POSTS_PER_RUN,
1185
- FENCE_PROFILES,
1186
- MAX_FENCE_REPEAT,
1187
- groundColour,
1188
- outdoorColour,
1189
- fenceColour,
1190
- corePostCount,
1191
- fenceRuns,
1192
- fencePosts,
1193
- fencePieces,
1194
- FURNITURE_HEIGHT_MM,
1195
- DOOR_POSES,
1196
- openLeaf,
1197
- buildMesh
1198
- };