@chanmeng666/archlang-3d 0.6.0 → 0.7.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.
- package/CHANGELOG.md +35 -0
- package/dist/browser.d.ts +3 -3
- package/dist/browser.js +13 -5
- package/dist/{camera-DcyxtBjK.d.ts → camera-CGIIudHj.d.ts} +1 -1
- package/dist/{chunk-CX6IVI7I.js → chunk-FHBR2U5Z.js} +1 -1
- package/dist/{chunk-LMFD5NP4.js → chunk-FVD3DZU2.js} +6 -4
- package/dist/{chunk-6WCS4TAT.js → chunk-GXWLZ2KC.js} +61 -9
- package/dist/chunk-QN4LQTVG.js +2192 -0
- package/dist/{chunk-TNNJ7CAO.js → chunk-TI4RYEOL.js} +28 -4
- package/dist/cli.js +5 -5
- package/dist/{facts-Dje5wcHh.d.ts → facts-3wb9egIT.d.ts} +1 -1
- package/dist/index.d.ts +242 -7
- package/dist/index.js +20 -4
- package/dist/node.d.ts +3 -3
- package/dist/node.js +4 -4
- package/dist/replay.d.ts +1 -1
- package/dist/{strip-CA-IAT0N.d.ts → strip-Sdsm54Qw.d.ts} +45 -1
- package/dist/viewer.iife.js +173 -173
- package/package.json +1 -1
- package/dist/chunk-VXGQYUMN.js +0 -1198
|
@@ -0,0 +1,2192 @@
|
|
|
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
|
+
clipToConvex,
|
|
11
|
+
cutSector,
|
|
12
|
+
degenerateHoles,
|
|
13
|
+
floorOverlaps,
|
|
14
|
+
insideCut,
|
|
15
|
+
isHandedAsset,
|
|
16
|
+
isHung,
|
|
17
|
+
mixedHeightJoints,
|
|
18
|
+
overlapArea,
|
|
19
|
+
prism,
|
|
20
|
+
rect,
|
|
21
|
+
sectorBand,
|
|
22
|
+
slab2d,
|
|
23
|
+
t0Shells,
|
|
24
|
+
wallOwnership,
|
|
25
|
+
where
|
|
26
|
+
} from "./chunk-GXWLZ2KC.js";
|
|
27
|
+
import {
|
|
28
|
+
FENCE_PALETTE,
|
|
29
|
+
GROUND_PLANE,
|
|
30
|
+
GROUND_SPLITS,
|
|
31
|
+
GROUND_TINT,
|
|
32
|
+
GROUND_WASH,
|
|
33
|
+
STAIR_MATERIAL,
|
|
34
|
+
STAIR_RAIL_MATERIAL,
|
|
35
|
+
TRIM_MATERIAL,
|
|
36
|
+
floorFinish
|
|
37
|
+
} from "./chunk-TI4RYEOL.js";
|
|
38
|
+
|
|
39
|
+
// src/adapter/adapt.ts
|
|
40
|
+
import * as core from "@chanmeng666/archlang";
|
|
41
|
+
var MIN_CORE = "1.57.0";
|
|
42
|
+
var hasHanded = (storeys) => storeys.some((s) => s.ir.elements.some((e) => e.kind === "furniture" && isHandedAsset(assetFor(e.category))));
|
|
43
|
+
function mirroredIds(source, world, n) {
|
|
44
|
+
const unknown = Array.from({ length: n }, () => null);
|
|
45
|
+
const planToJson2 = core.planToJson;
|
|
46
|
+
if (typeof planToJson2 !== "function") return unknown;
|
|
47
|
+
const r = planToJson2(source, world ? { world } : {});
|
|
48
|
+
const pages = r.pages ? r.pages.map((p) => p.json) : r.json ? [r.json] : [];
|
|
49
|
+
if (pages.length !== n) return unknown;
|
|
50
|
+
return pages.map((j) => new Set(j.furniture.flatMap((f) => f.mirror === true && f.id !== void 0 ? [f.id] : [])));
|
|
51
|
+
}
|
|
52
|
+
function adaptPlan(source, opts = {}) {
|
|
53
|
+
const resolvePlan2 = core.resolvePlan;
|
|
54
|
+
const hatches = core.hatchKey;
|
|
55
|
+
if (typeof resolvePlan2 !== "function" || typeof hatches !== "function") {
|
|
56
|
+
return {
|
|
57
|
+
ok: false,
|
|
58
|
+
refusal: {
|
|
59
|
+
code: "E3D_CORE_TOO_OLD",
|
|
60
|
+
message: `@chanmeng666/archlang is too old (no resolvePlan or hatchKey); archlang-3d needs ${MIN_CORE} or later.`
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const res = resolvePlan2(source, opts.world ? { world: opts.world } : {});
|
|
65
|
+
const errors = res.diagnostics.filter((d) => d.severity === "error");
|
|
66
|
+
if (!res.ir || errors.length > 0) {
|
|
67
|
+
const codes = [...new Set(errors.map((d) => d.code))].join(", ");
|
|
68
|
+
return {
|
|
69
|
+
ok: false,
|
|
70
|
+
refusal: {
|
|
71
|
+
code: "E3D_PLAN_ERRORS",
|
|
72
|
+
message: `The plan does not resolve (${codes || "no IR"}); fix it with \`arch validate\` first.`,
|
|
73
|
+
diagnostics: errors
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
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 }];
|
|
78
|
+
if (storeys.every((s) => s.ir.walls.length === 0)) {
|
|
79
|
+
return {
|
|
80
|
+
ok: false,
|
|
81
|
+
refusal: { code: "E3D_NO_WALLS", message: "The plan has no walls, so there is nothing to raise." }
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const scene = buildScene3D(storeys, {
|
|
85
|
+
coreVersion: opts.coreVersion ?? "unknown",
|
|
86
|
+
...opts.curveTolMm !== void 0 ? { curveTolMm: opts.curveTolMm } : {},
|
|
87
|
+
...hasHanded(storeys) ? { mirrored: mirroredIds(source, opts.world, storeys.length) } : {}
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
ok: true,
|
|
91
|
+
scene,
|
|
92
|
+
storeys,
|
|
93
|
+
diagnostics: res.diagnostics,
|
|
94
|
+
warnings: [
|
|
95
|
+
...storeys.flatMap((s) => mixedHeightJoints(wallOwnership(s.ir.walls)).map((w) => ({ ...w, level: s.level }))),
|
|
96
|
+
...scene.levels.flatMap((lv) => floorOverlaps(lv.floors).map((w) => ({ ...w, level: lv.level })))
|
|
97
|
+
]
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/mesh/slab.ts
|
|
102
|
+
var rectPolygon = (r) => ({
|
|
103
|
+
outer: [
|
|
104
|
+
[r[0], r[1]],
|
|
105
|
+
[r[2], r[1]],
|
|
106
|
+
[r[2], r[3]],
|
|
107
|
+
[r[0], r[3]]
|
|
108
|
+
]
|
|
109
|
+
});
|
|
110
|
+
function rectMinus(a, b) {
|
|
111
|
+
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])];
|
|
112
|
+
if (!(x0 < x1 && y0 < y1)) return [a];
|
|
113
|
+
const out = [];
|
|
114
|
+
if (a[1] < y0) out.push([a[0], a[1], a[2], y0]);
|
|
115
|
+
if (y1 < a[3]) out.push([a[0], y1, a[2], a[3]]);
|
|
116
|
+
if (a[0] < x0) out.push([a[0], y0, x0, y1]);
|
|
117
|
+
if (x1 < a[2]) out.push([x1, y0, a[2], y1]);
|
|
118
|
+
return out;
|
|
119
|
+
}
|
|
120
|
+
var rectilinear = (r) => r.every((p, i) => {
|
|
121
|
+
const q = r[(i + 1) % r.length];
|
|
122
|
+
return p[0] === q[0] || p[1] === q[1];
|
|
123
|
+
});
|
|
124
|
+
function rectsOf(r) {
|
|
125
|
+
const ys = [...new Set(r.map((p) => p[1]))].sort((a, b) => a - b);
|
|
126
|
+
const out = [];
|
|
127
|
+
for (let k = 0; k + 1 < ys.length; k++) {
|
|
128
|
+
const [y0, y1] = [ys[k], ys[k + 1]];
|
|
129
|
+
const xs = [];
|
|
130
|
+
for (let i = 0; i < r.length; i++) {
|
|
131
|
+
const a = r[i];
|
|
132
|
+
const b = r[(i + 1) % r.length];
|
|
133
|
+
if (a[0] === b[0] && Math.min(a[1], b[1]) <= y0 && Math.max(a[1], b[1]) >= y1) xs.push(a[0]);
|
|
134
|
+
}
|
|
135
|
+
xs.sort((a, b) => a - b);
|
|
136
|
+
for (let i = 0; i + 1 < xs.length; i += 2)
|
|
137
|
+
if (xs[i] < xs[i + 1]) out.push([xs[i], y0, xs[i + 1], y1]);
|
|
138
|
+
}
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
function covered(room, rings) {
|
|
142
|
+
const probes = room.flatMap((p, i) => {
|
|
143
|
+
const q = room[(i + 1) % room.length];
|
|
144
|
+
return [p, [(p[0] + q[0]) / 2, (p[1] + q[1]) / 2]];
|
|
145
|
+
});
|
|
146
|
+
return rings.some((r) => probes.every((p) => where(p, r) !== false) && !r.some((p) => where(p, room) === true));
|
|
147
|
+
}
|
|
148
|
+
function apart(room, rings) {
|
|
149
|
+
return rings.every((r) => room.every((p) => where(p, r) !== true) && r.every((p) => where(p, room) !== true));
|
|
150
|
+
}
|
|
151
|
+
function slabRegion(footprint, floors, ledger) {
|
|
152
|
+
const out = footprint.map((r) => ({ outer: [...r] }));
|
|
153
|
+
const exact = footprint.every(rectilinear);
|
|
154
|
+
let taken = exact ? footprint.flatMap(rectsOf) : [];
|
|
155
|
+
const added = [];
|
|
156
|
+
for (const f of floors) {
|
|
157
|
+
const room = f.polygon.outer;
|
|
158
|
+
const unsplit = () => {
|
|
159
|
+
ledger.push({
|
|
160
|
+
kind: "slab",
|
|
161
|
+
id: f.id,
|
|
162
|
+
field: "union",
|
|
163
|
+
value: "room overlaps the outline or an earlier room: added whole",
|
|
164
|
+
provenance: "default",
|
|
165
|
+
rule: "slab-room-unsplit"
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
if (exact && rectilinear(room)) {
|
|
169
|
+
let pieces = rectsOf(room);
|
|
170
|
+
for (const t of taken) pieces = pieces.flatMap((p) => rectMinus(p, t));
|
|
171
|
+
taken = [...taken, ...pieces];
|
|
172
|
+
for (const p of pieces) out.push(rectPolygon(p));
|
|
173
|
+
if (!pieces.every((p) => apart(rectPolygon(p).outer, added))) unsplit();
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
const others = [...footprint, ...added, ...taken.map((t) => rectPolygon(t).outer)];
|
|
177
|
+
if (covered(room, others)) continue;
|
|
178
|
+
if (!apart(room, others)) unsplit();
|
|
179
|
+
out.push({ outer: [...room] });
|
|
180
|
+
added.push(room);
|
|
181
|
+
}
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
var PROBE_MIN = 2;
|
|
185
|
+
var PROBE_OFF = 1;
|
|
186
|
+
function meets(a, b, c, d) {
|
|
187
|
+
const rx = b[0] - a[0];
|
|
188
|
+
const ry = b[1] - a[1];
|
|
189
|
+
const sx = d[0] - c[0];
|
|
190
|
+
const sy = d[1] - c[1];
|
|
191
|
+
const qx = c[0] - a[0];
|
|
192
|
+
const qy = c[1] - a[1];
|
|
193
|
+
const den = rx * sy - ry * sx;
|
|
194
|
+
if (den !== 0) {
|
|
195
|
+
const t = (qx * sy - qy * sx) / den;
|
|
196
|
+
const u = (qx * ry - qy * rx) / den;
|
|
197
|
+
return t >= 0 && t <= 1 && u >= 0 && u <= 1 ? [t] : [];
|
|
198
|
+
}
|
|
199
|
+
if (qx * ry - qy * rx !== 0) return [];
|
|
200
|
+
const rr = rx * rx + ry * ry;
|
|
201
|
+
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);
|
|
202
|
+
}
|
|
203
|
+
function stretches(a, b, cutters) {
|
|
204
|
+
const len = Math.hypot(b[0] - a[0], b[1] - a[1]);
|
|
205
|
+
const ts = [0, 1, ...cutters.flatMap(([c, d]) => meets(a, b, c, d))].sort((x, y) => x - y);
|
|
206
|
+
const out = [];
|
|
207
|
+
for (let i = 1; i < ts.length; i++) {
|
|
208
|
+
const t0 = ts[i - 1];
|
|
209
|
+
const t1 = ts[i];
|
|
210
|
+
if ((t1 - t0) * len < PROBE_MIN) continue;
|
|
211
|
+
const t = (t0 + t1) / 2;
|
|
212
|
+
out.push([a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t]);
|
|
213
|
+
}
|
|
214
|
+
return out;
|
|
215
|
+
}
|
|
216
|
+
var edgesOf = (r) => r.map((p, i) => [p, r[(i + 1) % r.length]]);
|
|
217
|
+
function coveredBy(ring, region) {
|
|
218
|
+
if (region.length === 0 || ring.length < 3) return false;
|
|
219
|
+
const inRegion = (p) => region.some((s) => where(p, s.outer) !== false && !(s.holes ?? []).some((h) => where(p, h) === true));
|
|
220
|
+
const ringEdges = edgesOf(ring);
|
|
221
|
+
const regionEdges = region.flatMap((s) => [s.outer, ...s.holes ?? []].flatMap(edgesOf));
|
|
222
|
+
for (const [a, b] of ringEdges) {
|
|
223
|
+
if (!inRegion(a)) return false;
|
|
224
|
+
if (!stretches(a, b, regionEdges).every(inRegion)) return false;
|
|
225
|
+
}
|
|
226
|
+
for (const [a, b] of regionEdges) {
|
|
227
|
+
const len = Math.hypot(b[0] - a[0], b[1] - a[1]);
|
|
228
|
+
if (len === 0) continue;
|
|
229
|
+
const nx = -(b[1] - a[1]) / len * PROBE_OFF;
|
|
230
|
+
const ny = (b[0] - a[0]) / len * PROBE_OFF;
|
|
231
|
+
for (const m of stretches(a, b, ringEdges)) {
|
|
232
|
+
if (where(m, ring) !== true) continue;
|
|
233
|
+
if (!inRegion([m[0] + nx, m[1] + ny]) || !inRegion([m[0] - nx, m[1] - ny])) return false;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// src/mesh/openings.ts
|
|
240
|
+
var MM = 1e3;
|
|
241
|
+
var clamp = (x, lo, hi) => Math.max(lo, Math.min(hi, x));
|
|
242
|
+
var share = (k, t, lo, hi) => clamp(Math.round(k * t), lo, hi);
|
|
243
|
+
var OPENING_DETAIL = {
|
|
244
|
+
/** The slot a door's lining leaves for its leaf: the leaf's own thickness (`LEAF_MM`). */
|
|
245
|
+
slot: 40,
|
|
246
|
+
lining: (t) => share(0.1, t, 12, 25),
|
|
247
|
+
casingWidth: (t) => share(0.35, t, 50, 90),
|
|
248
|
+
casingProud: (t) => share(0.1, t, 10, 20),
|
|
249
|
+
sillThickness: (t) => share(0.15, t, 20, 40),
|
|
250
|
+
/** The core's `SILL_PROJECTION` and `SILL_HORN` (both 0.2 of the host's thickness). */
|
|
251
|
+
sillProjection: (t) => Math.round(0.2 * t),
|
|
252
|
+
sillHorn: (t) => Math.round(0.2 * t),
|
|
253
|
+
boardThickness: (t) => share(0.1, t, 18, 30),
|
|
254
|
+
boardOverhang: (t) => share(0.1, t, 15, 30),
|
|
255
|
+
reveal: (t) => share(0.075, t, 10, 20),
|
|
256
|
+
/** The window frame's half depth (`FRAME_DEPTH_MM` / 2): where the reveal and the sills start. */
|
|
257
|
+
frameHalfDepth: 30
|
|
258
|
+
};
|
|
259
|
+
function jambFrame(o) {
|
|
260
|
+
const [j0, j1] = o.jambs;
|
|
261
|
+
const dx = j1[0] - j0[0];
|
|
262
|
+
const dy = j1[1] - j0[1];
|
|
263
|
+
const w = Math.hypot(dx, dy);
|
|
264
|
+
if (!(w > 0)) return null;
|
|
265
|
+
const [ux, uy] = [dx / w, dy / w];
|
|
266
|
+
const at2 = (u, v) => [Math.round(j0[0] + u * ux - v * uy), Math.round(j0[1] + u * uy + v * ux)];
|
|
267
|
+
return {
|
|
268
|
+
w,
|
|
269
|
+
at: at2,
|
|
270
|
+
quad: (u0, u1, v0, v1) => ({ outer: [at2(u0, v0), at2(u1, v0), at2(u1, v1), at2(u0, v1)] })
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
function toFrame(o, p) {
|
|
274
|
+
const [j0, j1] = o.jambs;
|
|
275
|
+
const w = Math.hypot(j1[0] - j0[0], j1[1] - j0[1]) || 1;
|
|
276
|
+
const [ux, uy] = [(j1[0] - j0[0]) / w, (j1[1] - j0[1]) / w];
|
|
277
|
+
const [dx, dy] = [p[0] - j0[0], p[1] - j0[1]];
|
|
278
|
+
return [dx * ux + dy * uy, -dx * uy + dy * ux];
|
|
279
|
+
}
|
|
280
|
+
function cutEnds(o, w) {
|
|
281
|
+
if (o.cut.length !== 4) return null;
|
|
282
|
+
const pts = o.cut.map((p) => toFrame(o, p)).sort((a, b) => a[0] - b[0]);
|
|
283
|
+
const ends = [pts.slice(0, 2), pts.slice(2)];
|
|
284
|
+
const mitred = ends.map((e) => Math.abs(e[0][0] - e[1][0]) > MM);
|
|
285
|
+
return {
|
|
286
|
+
mitred,
|
|
287
|
+
u: (end, v) => {
|
|
288
|
+
if (!mitred[end]) return end === 0 ? 0 : w;
|
|
289
|
+
const [a, b] = ends[end];
|
|
290
|
+
return a[1] === b[1] ? a[0] : a[0] + (b[0] - a[0]) * (v - a[1]) / (b[1] - a[1]);
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
function floorAt(level, p) {
|
|
295
|
+
return level.floors.some((f) => where(p, f.polygon.outer) === true) || level.voids.some((v) => p[0] > v.at[0] && p[0] < v.at[0] + v.size.w && p[1] > v.at[1] && p[1] < v.at[1] + v.size.h);
|
|
296
|
+
}
|
|
297
|
+
function insideOf(o, t, level) {
|
|
298
|
+
const f = jambFrame(o);
|
|
299
|
+
if (!f) return null;
|
|
300
|
+
const mid = f.w / 2;
|
|
301
|
+
const d = Math.max(t, 1);
|
|
302
|
+
const plus = floorAt(level, f.at(mid, d));
|
|
303
|
+
const minus = floorAt(level, f.at(mid, -d));
|
|
304
|
+
return plus && minus ? "both" : plus ? 1 : minus ? -1 : null;
|
|
305
|
+
}
|
|
306
|
+
var CLASH_UM2 = 1e6;
|
|
307
|
+
var boxPoly = (x0, y0, x1, y1) => ({
|
|
308
|
+
outer: [
|
|
309
|
+
[x0, y0],
|
|
310
|
+
[x1, y0],
|
|
311
|
+
[x1, y1],
|
|
312
|
+
[x0, y1]
|
|
313
|
+
]
|
|
314
|
+
});
|
|
315
|
+
function boxOf(poly) {
|
|
316
|
+
const xs = poly.outer.map((p) => p[0]);
|
|
317
|
+
const ys = poly.outer.map((p) => p[1]);
|
|
318
|
+
return [Math.min(...xs), Math.min(...ys), Math.max(...xs), Math.max(...ys)];
|
|
319
|
+
}
|
|
320
|
+
var Obstacles = class {
|
|
321
|
+
list = [];
|
|
322
|
+
add(cls, name, piece, owner) {
|
|
323
|
+
this.list.push({ ...piece, cls, name, ...owner !== void 0 ? { owner } : {}, box: boxOf(piece.poly) });
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* What, of `classes`, a piece of `owner`'s trim would stand in, or `null`: of all it meets, the
|
|
327
|
+
* name that sorts first, so the answer never depends on the order the plan writes its openings in
|
|
328
|
+
* (review of PR #732, B1).
|
|
329
|
+
*/
|
|
330
|
+
clash(owner, piece, classes) {
|
|
331
|
+
const [x0, y0, x1, y1] = boxOf(piece.poly);
|
|
332
|
+
let first = null;
|
|
333
|
+
for (const o of this.list) {
|
|
334
|
+
if (o.owner === owner || !classes.includes(o.cls)) continue;
|
|
335
|
+
if (o.z1 <= piece.z0 || o.z0 >= piece.z1) continue;
|
|
336
|
+
if (o.box[2] <= x0 || o.box[0] >= x1 || o.box[3] <= y0 || o.box[1] >= y1) continue;
|
|
337
|
+
if (first !== null && o.name >= first) continue;
|
|
338
|
+
if (overlapArea(o.poly, piece.poly) > CLASH_UM2) first = o.name;
|
|
339
|
+
}
|
|
340
|
+
return first;
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
var FLAT_MM = 50;
|
|
344
|
+
var STATIC = ["wall", "column", "furniture", "opening"];
|
|
345
|
+
var TRIM = ["trim"];
|
|
346
|
+
function fixedObstacles(level, furnitureZ) {
|
|
347
|
+
const site = new Obstacles();
|
|
348
|
+
const UP = Number.POSITIVE_INFINITY;
|
|
349
|
+
for (const w of level.walls) for (const b of w.body) site.add("wall", "wall", { poly: b, z0: 0, z1: UP });
|
|
350
|
+
for (const c of level.columns)
|
|
351
|
+
site.add("column", "column", {
|
|
352
|
+
poly: boxPoly(c.at[0], c.at[1], c.at[0] + c.size.w, c.at[1] + c.size.h),
|
|
353
|
+
z0: 0,
|
|
354
|
+
z1: UP
|
|
355
|
+
});
|
|
356
|
+
for (const f of level.furniture) {
|
|
357
|
+
const [z0, z1] = furnitureZ(f);
|
|
358
|
+
if (z1 - z0 < FLAT_MM * MM) continue;
|
|
359
|
+
site.add("furniture", `furniture ${f.id}`, {
|
|
360
|
+
poly: boxPoly(
|
|
361
|
+
f.centre[0] - f.size.w / 2,
|
|
362
|
+
f.centre[1] - f.size.d / 2,
|
|
363
|
+
f.centre[0] + f.size.w / 2,
|
|
364
|
+
f.centre[1] + f.size.d / 2
|
|
365
|
+
),
|
|
366
|
+
z0,
|
|
367
|
+
z1
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
const thick = new Map(level.walls.map((w) => [w.id, w.thickness]));
|
|
371
|
+
const reach = OPENING_DETAIL.casingProud(Number.POSITIVE_INFINITY) * MM;
|
|
372
|
+
for (const b of level.openings) {
|
|
373
|
+
const fb = jambFrame(b);
|
|
374
|
+
const hb = (thick.get(b.host) ?? 0) / 2 + reach;
|
|
375
|
+
if (!fb) continue;
|
|
376
|
+
const band = fb.quad(0, fb.w, -hb, hb);
|
|
377
|
+
site.add("opening", `opening ${b.id}`, { poly: band, z0: b.sill, z1: b.head }, b.id);
|
|
378
|
+
site.add("doorway", `opening ${b.id}`, { poly: band, z0: 0, z1: UP }, b.id);
|
|
379
|
+
site.add("jamb", `opening ${b.id}`, { poly: fb.quad(-MM, fb.w + MM, -hb, hb), z0: 0, z1: UP }, b.id);
|
|
380
|
+
}
|
|
381
|
+
return site;
|
|
382
|
+
}
|
|
383
|
+
function cutOverlap(o, level) {
|
|
384
|
+
const own = { outer: o.cut };
|
|
385
|
+
const hits = level.openings.filter((b) => b.id !== o.id && overlapArea({ outer: b.cut }, own) > CLASH_UM2).map((b) => b.id).sort();
|
|
386
|
+
return hits[0] ?? null;
|
|
387
|
+
}
|
|
388
|
+
function curvedLining(sector, l, bands, z0, head, withHead, prism2) {
|
|
389
|
+
const f = Math.min(0.5, l / (sector.r * Math.abs(sector.sweep)));
|
|
390
|
+
return bands.flatMap(([v0, v1]) => [
|
|
391
|
+
prism2(sectorBand(sector, v0, v1, 0, f), z0, head),
|
|
392
|
+
prism2(sectorBand(sector, v0, v1, 1 - f, 1), z0, head),
|
|
393
|
+
...withHead && f < 0.5 ? [prism2(sectorBand(sector, v0, v1, f, 1 - f), head - l, head)] : []
|
|
394
|
+
]);
|
|
395
|
+
}
|
|
396
|
+
var END = ["start", "end"];
|
|
397
|
+
function storeyTrim(level, inputs, e, prism2, furnitureZ) {
|
|
398
|
+
const site = fixedObstacles(level, furnitureZ);
|
|
399
|
+
const out = /* @__PURE__ */ new Map();
|
|
400
|
+
const doors = [];
|
|
401
|
+
const windows = [];
|
|
402
|
+
for (const input of inputs) {
|
|
403
|
+
const plan = input.o.kind === "window" ? planWindow(input, level, e, prism2) : planDoor(input, level, e, prism2);
|
|
404
|
+
out.set(input.o.id, plan.result);
|
|
405
|
+
if (plan.kind === "door") doors.push(plan);
|
|
406
|
+
else if (plan.kind === "window") windows.push(plan);
|
|
407
|
+
}
|
|
408
|
+
const plannedLegs = new Obstacles();
|
|
409
|
+
for (const d of doors)
|
|
410
|
+
for (const face of d.faces)
|
|
411
|
+
for (const leg of face.legs) plannedLegs.add("trim", `casing ${d.input.o.id}`, leg, d.input.o.id);
|
|
412
|
+
for (const d of doors) {
|
|
413
|
+
const id = d.input.o.id;
|
|
414
|
+
for (const face of d.faces)
|
|
415
|
+
face.legs.forEach((leg, k) => {
|
|
416
|
+
const what = site.clash(id, leg, STATIC) ?? plannedLegs.clash(id, leg, TRIM);
|
|
417
|
+
if (what) {
|
|
418
|
+
face.keep[k] = false;
|
|
419
|
+
d.omitted.push(`${face.name}:${END[k]}:${what}`);
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
for (const d of doors) {
|
|
424
|
+
const id = d.input.o.id;
|
|
425
|
+
for (const face of d.faces) {
|
|
426
|
+
if (!face.ends || !face.mid) continue;
|
|
427
|
+
const heads = [];
|
|
428
|
+
face.ends.forEach((end, k) => {
|
|
429
|
+
if (!face.keep[k]) {
|
|
430
|
+
face.endKeep[k] = false;
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
const what2 = site.clash(id, end, STATIC);
|
|
434
|
+
if (what2) {
|
|
435
|
+
face.endKeep[k] = false;
|
|
436
|
+
heads.push(`${face.name}:head-${END[k]}:${what2}`);
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
const what = site.clash(id, face.mid, STATIC);
|
|
440
|
+
if (what) {
|
|
441
|
+
face.midKeep = false;
|
|
442
|
+
d.omitted.push(`${face.name}:head:${what}`);
|
|
443
|
+
} else d.omitted.push(...heads);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
const casings = new Obstacles();
|
|
447
|
+
for (const d of doors) finishDoor(d, casings, e, prism2);
|
|
448
|
+
const plannedSlabs = new Obstacles();
|
|
449
|
+
const plannedCores = new Obstacles();
|
|
450
|
+
for (const w of windows)
|
|
451
|
+
for (const sl of w.slabs) {
|
|
452
|
+
plannedCores.add("trim", `${sl.part} ${w.input.o.id}`, sl.core, w.input.o.id);
|
|
453
|
+
plannedSlabs.add("trim", `${sl.part} ${w.input.o.id}`, sl.core, w.input.o.id);
|
|
454
|
+
for (const h of sl.horns) if (h) plannedSlabs.add("trim", `${sl.part} ${w.input.o.id}`, h, w.input.o.id);
|
|
455
|
+
}
|
|
456
|
+
const NEAR = ["jamb"];
|
|
457
|
+
for (const w of windows) {
|
|
458
|
+
const id = w.input.o.id;
|
|
459
|
+
for (const sl of w.slabs) {
|
|
460
|
+
sl.horns.forEach((h, k) => {
|
|
461
|
+
if (!h) return;
|
|
462
|
+
const what2 = site.clash(id, h, NEAR) ?? casings.clash(id, h, TRIM) ?? plannedSlabs.clash(id, h, TRIM);
|
|
463
|
+
if (what2) {
|
|
464
|
+
sl.hornKeep[k] = false;
|
|
465
|
+
sl.hornWhy[k] = what2;
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
const what = site.clash(id, sl.core, ["doorway"]) ?? casings.clash(id, sl.core, TRIM) ?? plannedCores.clash(id, sl.core, TRIM);
|
|
469
|
+
if (what) {
|
|
470
|
+
sl.coreKeep = false;
|
|
471
|
+
sl.coreWhy = what;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
for (const w of windows) w.finish();
|
|
476
|
+
return out;
|
|
477
|
+
}
|
|
478
|
+
function planDoor(input, level, e, prism2) {
|
|
479
|
+
const { o, t, head, top } = input;
|
|
480
|
+
const result = { parts: [], ledger: [] };
|
|
481
|
+
const { parts, ledger } = result;
|
|
482
|
+
const f = jambFrame(o);
|
|
483
|
+
if (!f) return { kind: "none", result };
|
|
484
|
+
const tm = t / MM;
|
|
485
|
+
const kind = o.kind;
|
|
486
|
+
const door = kind === "door";
|
|
487
|
+
const sector = cutSector(o.cut, o.jambs, o.centre);
|
|
488
|
+
const blocked = cutOverlap(o, level);
|
|
489
|
+
if (blocked || door && sector) {
|
|
490
|
+
ledger.push({
|
|
491
|
+
kind,
|
|
492
|
+
id: o.id,
|
|
493
|
+
field: "trim",
|
|
494
|
+
value: blocked ? `cut overlaps ${blocked}` : "curved host",
|
|
495
|
+
provenance: "default",
|
|
496
|
+
rule: "door-trim-omitted"
|
|
497
|
+
});
|
|
498
|
+
return { kind: "none", result };
|
|
499
|
+
}
|
|
500
|
+
const l = OPENING_DETAIL.lining(tm) * MM;
|
|
501
|
+
const slot = OPENING_DETAIL.slot * MM / 2;
|
|
502
|
+
const half = t / 2;
|
|
503
|
+
const z0 = e + o.sill;
|
|
504
|
+
const zh = e + head;
|
|
505
|
+
const withHead = head < top;
|
|
506
|
+
const bands = door ? half - slot >= MM ? [
|
|
507
|
+
[-half, -slot],
|
|
508
|
+
[slot, half]
|
|
509
|
+
] : [] : [[-half, half]];
|
|
510
|
+
const lining = sector ? curvedLining(sector, l, bands, z0, zh, withHead, prism2) : bands.flatMap(([v0, v1]) => [
|
|
511
|
+
prism2(f.quad(0, l, v0, v1), z0, zh),
|
|
512
|
+
prism2(f.quad(f.w - l, f.w, v0, v1), z0, zh),
|
|
513
|
+
...withHead && f.w > 2 * l ? [prism2(f.quad(l, f.w - l, v0, v1), zh - l, zh)] : []
|
|
514
|
+
]);
|
|
515
|
+
if (lining.length) parts.push({ part: "lining", shells: lining });
|
|
516
|
+
ledger.push({
|
|
517
|
+
kind,
|
|
518
|
+
id: o.id,
|
|
519
|
+
field: "lining_mm",
|
|
520
|
+
value: bands.length ? { thickness: l / MM, ...door ? { slot: OPENING_DETAIL.slot } : {}, head: withHead } : "omitted",
|
|
521
|
+
provenance: "default",
|
|
522
|
+
rule: bands.length ? "door-lining-default" : "door-lining-omitted"
|
|
523
|
+
});
|
|
524
|
+
const why = o.doorKind === "garage" ? "garage" : sector ? "curved" : null;
|
|
525
|
+
if (why) {
|
|
526
|
+
ledger.push({ kind, id: o.id, field: "casing", value: why, provenance: "default", rule: "door-casing-omitted" });
|
|
527
|
+
return { kind: "none", result };
|
|
528
|
+
}
|
|
529
|
+
const c = OPENING_DETAIL.casingWidth(tm) * MM;
|
|
530
|
+
const p = OPENING_DETAIL.casingProud(tm) * MM;
|
|
531
|
+
const panel = o.doorKind === "barn" ? o.swing === "out" ? -1 : 1 : 0;
|
|
532
|
+
const omitted = [];
|
|
533
|
+
const barTop = Math.min(head + c, top);
|
|
534
|
+
const faces = [];
|
|
535
|
+
for (const s of [1, -1]) {
|
|
536
|
+
const name = s > 0 ? "+face" : "-face";
|
|
537
|
+
if (s === panel) {
|
|
538
|
+
omitted.push(`${name}:barn`);
|
|
539
|
+
continue;
|
|
540
|
+
}
|
|
541
|
+
const [v0, v1] = s > 0 ? [half, half + p] : [-half - p, -half];
|
|
542
|
+
const bar = barTop > head;
|
|
543
|
+
faces.push({
|
|
544
|
+
s,
|
|
545
|
+
name,
|
|
546
|
+
v0,
|
|
547
|
+
v1,
|
|
548
|
+
legs: [
|
|
549
|
+
{ poly: f.quad(-c, 0, v0, v1), z0: 0, z1: head },
|
|
550
|
+
{ poly: f.quad(f.w, f.w + c, v0, v1), z0: 0, z1: head }
|
|
551
|
+
],
|
|
552
|
+
keep: [true, true],
|
|
553
|
+
ends: bar ? [
|
|
554
|
+
{ poly: f.quad(-c, 0, v0, v1), z0: head, z1: barTop },
|
|
555
|
+
{ poly: f.quad(f.w, f.w + c, v0, v1), z0: head, z1: barTop }
|
|
556
|
+
] : null,
|
|
557
|
+
mid: bar ? { poly: f.quad(0, f.w, v0, v1), z0: head, z1: barTop } : null,
|
|
558
|
+
endKeep: [true, true],
|
|
559
|
+
midKeep: true
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
return { kind: "door", input, f, result, faces, omitted, c, p, barTop };
|
|
563
|
+
}
|
|
564
|
+
function finishDoor(d, casings, e, prism2) {
|
|
565
|
+
const { o, head } = d.input;
|
|
566
|
+
const { f, c, p, barTop } = d;
|
|
567
|
+
const shells = [];
|
|
568
|
+
const id = o.id;
|
|
569
|
+
for (const face of d.faces) {
|
|
570
|
+
face.legs.forEach((leg, k) => {
|
|
571
|
+
if (!face.keep[k]) return;
|
|
572
|
+
shells.push(prism2(leg.poly, e, e + head));
|
|
573
|
+
casings.add("trim", `casing ${id}`, leg, id);
|
|
574
|
+
});
|
|
575
|
+
if (face.ends && face.midKeep) {
|
|
576
|
+
const u0 = face.endKeep[0] ? -c : 0;
|
|
577
|
+
const u1 = face.endKeep[1] ? f.w + c : f.w;
|
|
578
|
+
const bar = { poly: f.quad(u0, u1, face.v0, face.v1), z0: head, z1: barTop };
|
|
579
|
+
shells.push(prism2(bar.poly, e + head, e + barTop));
|
|
580
|
+
casings.add("trim", `casing ${id}`, bar, id);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
const { parts, ledger } = d.result;
|
|
584
|
+
if (shells.length) {
|
|
585
|
+
parts.push({ part: "casing", shells });
|
|
586
|
+
ledger.push({
|
|
587
|
+
kind: o.kind,
|
|
588
|
+
id,
|
|
589
|
+
field: "casing_mm",
|
|
590
|
+
value: { width: c / MM, proud: p / MM, head: barTop > head },
|
|
591
|
+
provenance: "default",
|
|
592
|
+
rule: "door-casing-default"
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
if (d.omitted.length)
|
|
596
|
+
ledger.push({
|
|
597
|
+
kind: o.kind,
|
|
598
|
+
id,
|
|
599
|
+
field: "casing",
|
|
600
|
+
value: d.omitted,
|
|
601
|
+
provenance: "default",
|
|
602
|
+
rule: "door-casing-omitted"
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
function planWindow(input, level, e, prism2) {
|
|
606
|
+
const { o, t, head, top } = input;
|
|
607
|
+
const result = { parts: [], ledger: [] };
|
|
608
|
+
const { parts, ledger } = result;
|
|
609
|
+
const f = jambFrame(o);
|
|
610
|
+
if (!f) return { kind: "none", result };
|
|
611
|
+
const tm = t / MM;
|
|
612
|
+
const half = t / 2;
|
|
613
|
+
const ff = Math.min(OPENING_DETAIL.frameHalfDepth * MM, half);
|
|
614
|
+
const inside = insideOf(o, t, level);
|
|
615
|
+
ledger.push({
|
|
616
|
+
kind: "window",
|
|
617
|
+
id: o.id,
|
|
618
|
+
field: "inside",
|
|
619
|
+
value: inside === null ? "neither" : inside === "both" ? "both" : inside > 0 ? "+normal" : "-normal",
|
|
620
|
+
provenance: "derived",
|
|
621
|
+
rule: "window-inside-probe"
|
|
622
|
+
});
|
|
623
|
+
if (inside === null) return { kind: "none", result };
|
|
624
|
+
const blocked = cutOverlap(o, level);
|
|
625
|
+
if (blocked) {
|
|
626
|
+
ledger.push({
|
|
627
|
+
kind: "window",
|
|
628
|
+
id: o.id,
|
|
629
|
+
field: "trim",
|
|
630
|
+
value: `cut overlaps ${blocked}`,
|
|
631
|
+
provenance: "default",
|
|
632
|
+
rule: "window-trim-omitted"
|
|
633
|
+
});
|
|
634
|
+
return { kind: "none", result };
|
|
635
|
+
}
|
|
636
|
+
const sector = cutSector(o.cut, o.jambs, o.centre);
|
|
637
|
+
const ends = sector ? null : cutEnds(o, f.w);
|
|
638
|
+
const hasSill = o.sill > 0;
|
|
639
|
+
const zs = e + o.sill;
|
|
640
|
+
const zh = e + head;
|
|
641
|
+
const withHead = head < top;
|
|
642
|
+
const bt = OPENING_DETAIL.boardThickness(tm) * MM;
|
|
643
|
+
const st = OPENING_DETAIL.sillThickness(tm) * MM;
|
|
644
|
+
const rl = OPENING_DETAIL.reveal(tm) * MM;
|
|
645
|
+
const sides = inside === "both" ? [1, -1] : [inside];
|
|
646
|
+
const reveal = (boardBuilt) => {
|
|
647
|
+
const shells = [];
|
|
648
|
+
if (half - ff >= MM) {
|
|
649
|
+
for (const s of sides) {
|
|
650
|
+
const [v0, v1] = s > 0 ? [ff, half] : [-half, -ff];
|
|
651
|
+
const base = boardBuilt ? zs + bt : zs;
|
|
652
|
+
if (sector) {
|
|
653
|
+
const k = sectorSign(o, sector);
|
|
654
|
+
const [a2, b2] = s > 0 ? [ff + MM, half] : [-half, -ff - MM];
|
|
655
|
+
shells.push(
|
|
656
|
+
...curvedLining(
|
|
657
|
+
sector,
|
|
658
|
+
rl,
|
|
659
|
+
[[a2 * k, b2 * k].sort((x, y) => x - y)],
|
|
660
|
+
base,
|
|
661
|
+
zh,
|
|
662
|
+
withHead,
|
|
663
|
+
prism2
|
|
664
|
+
)
|
|
665
|
+
);
|
|
666
|
+
continue;
|
|
667
|
+
}
|
|
668
|
+
const m0 = ends?.mitred[0] ?? false;
|
|
669
|
+
const m1 = ends?.mitred[1] ?? false;
|
|
670
|
+
if (!m0) shells.push(prism2(f.quad(0, rl, v0, v1), base, zh));
|
|
671
|
+
if (!m1) shells.push(prism2(f.quad(f.w - rl, f.w, v0, v1), base, zh));
|
|
672
|
+
const [a, b] = [m0 ? 0 : rl, m1 ? f.w : f.w - rl];
|
|
673
|
+
if (withHead && b > a) shells.push(prism2(f.quad(a, b, v0, v1), zh - rl, zh));
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
if (shells.length) parts.unshift({ part: "reveal", shells });
|
|
677
|
+
ledger.splice(1, 0, {
|
|
678
|
+
kind: "window",
|
|
679
|
+
id: o.id,
|
|
680
|
+
field: "reveal_mm",
|
|
681
|
+
value: shells.length ? { thickness: rl / MM, head: withHead } : "omitted",
|
|
682
|
+
provenance: "default",
|
|
683
|
+
rule: "window-reveal-lining"
|
|
684
|
+
});
|
|
685
|
+
};
|
|
686
|
+
if (inside === "both" || !hasSill) {
|
|
687
|
+
reveal(false);
|
|
688
|
+
ledger.push({
|
|
689
|
+
kind: "window",
|
|
690
|
+
id: o.id,
|
|
691
|
+
field: "sill",
|
|
692
|
+
value: inside === "both" ? "interior window" : "sill 0",
|
|
693
|
+
provenance: "derived",
|
|
694
|
+
rule: "window-sill-omitted"
|
|
695
|
+
});
|
|
696
|
+
return { kind: "none", result };
|
|
697
|
+
}
|
|
698
|
+
const sIn = inside;
|
|
699
|
+
const sOut = -inside;
|
|
700
|
+
if (sector) {
|
|
701
|
+
const k = sectorSign(o, sector);
|
|
702
|
+
const band = (s) => (s > 0 ? [ff * k, half * k] : [-half * k, -ff * k]).sort((a, b) => a - b);
|
|
703
|
+
const [o0, o1] = band(sOut);
|
|
704
|
+
const [i0, i1] = band(sIn);
|
|
705
|
+
reveal(true);
|
|
706
|
+
parts.push({ part: "sill", shells: [prism2(sectorBand(sector, o0, o1), zs, zs + st)] });
|
|
707
|
+
parts.push({ part: "board", shells: [prism2(sectorBand(sector, i0, i1), zs, zs + bt)] });
|
|
708
|
+
ledger.push({
|
|
709
|
+
kind: "window",
|
|
710
|
+
id: o.id,
|
|
711
|
+
field: "sill_mm",
|
|
712
|
+
value: { thickness: st / MM, board: bt / MM },
|
|
713
|
+
provenance: "default",
|
|
714
|
+
rule: "window-sill-curved-inside-cut"
|
|
715
|
+
});
|
|
716
|
+
return { kind: "none", result };
|
|
717
|
+
}
|
|
718
|
+
const proj = OPENING_DETAIL.sillProjection(tm) * MM;
|
|
719
|
+
const horn = OPENING_DETAIL.sillHorn(tm) * MM;
|
|
720
|
+
const over = OPENING_DETAIL.boardOverhang(tm) * MM;
|
|
721
|
+
const quadAt = (s, reach, u0, u1) => {
|
|
722
|
+
const [va, vb] = s > 0 ? [ff, half + reach] : [-half - reach, -ff];
|
|
723
|
+
return { outer: [f.at(u0(va), va), f.at(u1(va), va), f.at(u1(vb), vb), f.at(u0(vb), vb)] };
|
|
724
|
+
};
|
|
725
|
+
const jamb0 = (v) => ends?.mitred[0] ? ends.u(0, v) : 0;
|
|
726
|
+
const jamb1 = (v) => ends?.mitred[1] ? ends.u(1, v) : f.w;
|
|
727
|
+
const slabOf = (part, s, reach, past, thickness) => {
|
|
728
|
+
const z = { z0: o.sill, z1: o.sill + thickness };
|
|
729
|
+
return {
|
|
730
|
+
part,
|
|
731
|
+
core: { poly: quadAt(s, reach, jamb0, jamb1), ...z },
|
|
732
|
+
// No horn at a mitred end (a window run to a corner stops on the mitre).
|
|
733
|
+
horns: [
|
|
734
|
+
ends?.mitred[0] ? null : {
|
|
735
|
+
poly: quadAt(
|
|
736
|
+
s,
|
|
737
|
+
reach,
|
|
738
|
+
() => -past,
|
|
739
|
+
() => 0
|
|
740
|
+
),
|
|
741
|
+
...z
|
|
742
|
+
},
|
|
743
|
+
ends?.mitred[1] ? null : {
|
|
744
|
+
poly: quadAt(
|
|
745
|
+
s,
|
|
746
|
+
reach,
|
|
747
|
+
() => f.w,
|
|
748
|
+
() => f.w + past
|
|
749
|
+
),
|
|
750
|
+
...z
|
|
751
|
+
}
|
|
752
|
+
],
|
|
753
|
+
hornKeep: [true, true],
|
|
754
|
+
hornWhy: ["", ""],
|
|
755
|
+
coreKeep: true,
|
|
756
|
+
coreWhy: "",
|
|
757
|
+
built: null,
|
|
758
|
+
thickness
|
|
759
|
+
};
|
|
760
|
+
};
|
|
761
|
+
const slabs = [slabOf("sill", sOut, proj, horn, st), slabOf("board", sIn, over, over, bt)];
|
|
762
|
+
const finish = (boardBuilt) => {
|
|
763
|
+
reveal(boardBuilt);
|
|
764
|
+
for (const sl of slabs) {
|
|
765
|
+
if (!sl.built) continue;
|
|
766
|
+
parts.push({ part: sl.part, shells: [prism2(sl.built, zs, zs + sl.thickness)] });
|
|
767
|
+
}
|
|
768
|
+
const [sill, board] = slabs;
|
|
769
|
+
if (sill.built)
|
|
770
|
+
ledger.push({
|
|
771
|
+
kind: "window",
|
|
772
|
+
id: o.id,
|
|
773
|
+
field: "sill_mm",
|
|
774
|
+
value: { thickness: st / MM, projection: proj / MM, horn: horn / MM, mitred: ends?.mitred ?? [false, false] },
|
|
775
|
+
provenance: "default",
|
|
776
|
+
rule: "window-sill-exterior"
|
|
777
|
+
});
|
|
778
|
+
if (board.built)
|
|
779
|
+
ledger.push({
|
|
780
|
+
kind: "window",
|
|
781
|
+
id: o.id,
|
|
782
|
+
field: "board_mm",
|
|
783
|
+
value: {
|
|
784
|
+
thickness: bt / MM,
|
|
785
|
+
overhang: over / MM,
|
|
786
|
+
// A mitred end (a window run to a corner) stops on the mitre, the board's as the sill's.
|
|
787
|
+
...ends?.mitred.some(Boolean) ? { mitred: ends.mitred } : {}
|
|
788
|
+
},
|
|
789
|
+
provenance: "default",
|
|
790
|
+
rule: "window-board-interior"
|
|
791
|
+
});
|
|
792
|
+
};
|
|
793
|
+
return {
|
|
794
|
+
kind: "window",
|
|
795
|
+
input,
|
|
796
|
+
f,
|
|
797
|
+
result,
|
|
798
|
+
slabs,
|
|
799
|
+
finish: () => {
|
|
800
|
+
for (const sl of slabs) {
|
|
801
|
+
if (!sl.coreKeep) {
|
|
802
|
+
ledger.push({
|
|
803
|
+
kind: "window",
|
|
804
|
+
id: o.id,
|
|
805
|
+
field: sl.part,
|
|
806
|
+
value: `clash ${sl.coreWhy}`,
|
|
807
|
+
provenance: "derived",
|
|
808
|
+
rule: sl.part === "sill" ? "window-sill-omitted" : "window-board-omitted"
|
|
809
|
+
});
|
|
810
|
+
continue;
|
|
811
|
+
}
|
|
812
|
+
const cut = END.flatMap((name, k) => sl.horns[k] && !sl.hornKeep[k] ? [`${name}:${sl.hornWhy[k]}`] : []);
|
|
813
|
+
if (cut.length)
|
|
814
|
+
ledger.push({
|
|
815
|
+
kind: "window",
|
|
816
|
+
id: o.id,
|
|
817
|
+
field: `${sl.part}_horn`,
|
|
818
|
+
value: cut,
|
|
819
|
+
provenance: "derived",
|
|
820
|
+
rule: "window-sill-horn-omitted"
|
|
821
|
+
});
|
|
822
|
+
const s = sl.part === "sill" ? sOut : sIn;
|
|
823
|
+
const reach = sl.part === "sill" ? proj : over;
|
|
824
|
+
const past = sl.part === "sill" ? horn : over;
|
|
825
|
+
sl.built = quadAt(
|
|
826
|
+
s,
|
|
827
|
+
reach,
|
|
828
|
+
sl.horns[0] && sl.hornKeep[0] ? () => -past : jamb0,
|
|
829
|
+
sl.horns[1] && sl.hornKeep[1] ? () => f.w + past : jamb1
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
finish(slabs[1].built !== null);
|
|
833
|
+
}
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
function sectorSign(o, sector) {
|
|
837
|
+
const [j0, j1] = o.jambs;
|
|
838
|
+
const [dx, dy] = [j1[0] - j0[0], j1[1] - j0[1]];
|
|
839
|
+
const [nx, ny] = [-dy, dx];
|
|
840
|
+
const [rx, ry] = [o.centre[0] - sector.c[0], o.centre[1] - sector.c[1]];
|
|
841
|
+
return nx * rx + ny * ry >= 0 ? 1 : -1;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
// src/mesh/stair.ts
|
|
845
|
+
function stairRisers(flights) {
|
|
846
|
+
return flights.reduce((n, f) => n + f.treads + 1, 0);
|
|
847
|
+
}
|
|
848
|
+
function runCoordinate(f, d) {
|
|
849
|
+
const [x, y] = f.at;
|
|
850
|
+
switch (f.foot) {
|
|
851
|
+
case "bottom":
|
|
852
|
+
return y + f.size.h - d;
|
|
853
|
+
case "top":
|
|
854
|
+
return y + d;
|
|
855
|
+
case "right":
|
|
856
|
+
return x + f.size.w - d;
|
|
857
|
+
case "left":
|
|
858
|
+
return x + d;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
var alongY = (foot) => foot === "top" || foot === "bottom";
|
|
862
|
+
function sideways(section, c0, c1, runAlongY) {
|
|
863
|
+
const up = prism({ outer: section }, c0, c1);
|
|
864
|
+
if (!up) return null;
|
|
865
|
+
const positions = [];
|
|
866
|
+
for (let i = 0; i < up.positions.length; i += 3) {
|
|
867
|
+
const [u, h, v] = [up.positions[i], up.positions[i + 1], up.positions[i + 2]];
|
|
868
|
+
if (runAlongY) positions.push(h, v, u);
|
|
869
|
+
else positions.push(u, v, h);
|
|
870
|
+
}
|
|
871
|
+
const indices = [...up.indices];
|
|
872
|
+
if (!runAlongY) {
|
|
873
|
+
for (let t = 0; t < indices.length; t += 3) {
|
|
874
|
+
const b = indices[t + 1];
|
|
875
|
+
indices[t + 1] = indices[t + 2];
|
|
876
|
+
indices[t + 2] = b;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
return { positions, indices };
|
|
880
|
+
}
|
|
881
|
+
function stairSolid(stair, z0, rise) {
|
|
882
|
+
const flights = stair.flights;
|
|
883
|
+
if (!flights?.length || !(rise > 0)) return null;
|
|
884
|
+
const R = stairRisers(flights);
|
|
885
|
+
const riserTop = (k) => z0 + Math.round(rise * k / R);
|
|
886
|
+
const shells = [];
|
|
887
|
+
const landingTops = [];
|
|
888
|
+
let dropped = 0;
|
|
889
|
+
let climbed = 0;
|
|
890
|
+
flights.forEach((f, i) => {
|
|
891
|
+
const n = f.treads;
|
|
892
|
+
const yRun = alongY(f.foot);
|
|
893
|
+
const run = yRun ? f.size.h : f.size.w;
|
|
894
|
+
const [lo, extent] = yRun ? [f.at[0], f.size.w] : [f.at[1], f.size.h];
|
|
895
|
+
const width = Math.min(stair.width, extent);
|
|
896
|
+
const c0 = lo + Math.round((extent - width) / 2);
|
|
897
|
+
const c1 = c0 + width;
|
|
898
|
+
const at2 = (t) => runCoordinate(f, Math.round(run * t / n));
|
|
899
|
+
const section = [[at2(0), z0]];
|
|
900
|
+
for (let t = 0; t < n; t++) {
|
|
901
|
+
const h = riserTop(climbed + t + 1);
|
|
902
|
+
section.push([at2(t), h], [at2(t + 1), h]);
|
|
903
|
+
}
|
|
904
|
+
section.push([at2(n), z0]);
|
|
905
|
+
const s = sideways(section, c0, c1, yRun);
|
|
906
|
+
if (s) shells.push(s);
|
|
907
|
+
else dropped++;
|
|
908
|
+
climbed += n + 1;
|
|
909
|
+
const landing = stair.landings?.[i];
|
|
910
|
+
if (landing && i < flights.length - 1) {
|
|
911
|
+
const top = riserTop(climbed);
|
|
912
|
+
landingTops.push(top);
|
|
913
|
+
const box = prism(
|
|
914
|
+
rect(landing.at[0], landing.at[1], landing.at[0] + landing.size.w, landing.at[1] + landing.size.h),
|
|
915
|
+
z0,
|
|
916
|
+
top
|
|
917
|
+
);
|
|
918
|
+
if (box) shells.push(box);
|
|
919
|
+
else dropped++;
|
|
920
|
+
}
|
|
921
|
+
});
|
|
922
|
+
return { shells, risers: R, landingTops, top: riserTop(R - 1), dropped };
|
|
923
|
+
}
|
|
924
|
+
var clampMm = (x, lo, hi) => Math.max(lo, Math.min(hi, x));
|
|
925
|
+
var STAIR_DETAIL = {
|
|
926
|
+
/** A tread board, 0.25 r in [30, 50] thick (never more than half a riser). */
|
|
927
|
+
tread: (r) => Math.min(clampMm(Math.round(0.25 * r), 30, 50), Math.max(1, Math.floor(r / 2))),
|
|
928
|
+
/** Its nosing past the front edge (not on a flight's first tread), 0.1 g in [15, 30]. */
|
|
929
|
+
nosing: (g) => clampMm(Math.round(0.1 * g), 15, 30),
|
|
930
|
+
/** A stringer, 0.05 W in [40, 60] wide (at most a quarter of the band). */
|
|
931
|
+
stringer: (W) => Math.min(clampMm(Math.round(0.05 * W), 40, 60), Math.max(1, Math.floor(W / 4))),
|
|
932
|
+
/** The stringer's band: 0.3 r in [40, 60] over the nosing line, 1.2 r in [150, 250] under it. */
|
|
933
|
+
above: (r) => clampMm(Math.round(0.3 * r), 40, 60),
|
|
934
|
+
below: (r) => clampMm(Math.round(1.2 * r), 150, 250),
|
|
935
|
+
/** The handrail's top over the nosing line (measured upright), and its 50 × 50 section. */
|
|
936
|
+
railHeight: 900,
|
|
937
|
+
rail: 50,
|
|
938
|
+
/** A baluster a tread, 0.03 W in [20, 30] square. */
|
|
939
|
+
baluster: (W) => clampMm(Math.round(0.03 * W), 20, 30),
|
|
940
|
+
/** A newel at each end of a flight, 0.06 W in [60, 90] square, this far over the handrail. */
|
|
941
|
+
newel: (W) => clampMm(Math.round(0.06 * W), 60, 90),
|
|
942
|
+
newelAbove: 100,
|
|
943
|
+
/** A landing's open edge: its handrail's top over the landing; balusters a going apart. */
|
|
944
|
+
landingRailHeight: 1e3,
|
|
945
|
+
/** How far past an edge the wall probe looks. */
|
|
946
|
+
probe: 100
|
|
947
|
+
};
|
|
948
|
+
function freeRuns(s0, s1, taken, min = 0) {
|
|
949
|
+
let runs = [[s0, s1]];
|
|
950
|
+
for (const [a, b] of taken)
|
|
951
|
+
runs = runs.flatMap(
|
|
952
|
+
([p, q]) => b <= p || a >= q ? [[p, q]] : [
|
|
953
|
+
[p, Math.min(a, q)],
|
|
954
|
+
[Math.max(b, p), q]
|
|
955
|
+
].filter(([u, v]) => v > u)
|
|
956
|
+
);
|
|
957
|
+
return runs.filter(([u, v]) => v - u >= min);
|
|
958
|
+
}
|
|
959
|
+
function stairDetail(stair, z0, rise, solidAt) {
|
|
960
|
+
const flights = stair.flights;
|
|
961
|
+
if (!flights?.length || !(rise > 0)) return null;
|
|
962
|
+
const MM4 = 1e3;
|
|
963
|
+
const D = STAIR_DETAIL;
|
|
964
|
+
const R = stairRisers(flights);
|
|
965
|
+
const riserTop = (k) => z0 + Math.round(rise * k / R);
|
|
966
|
+
const r = rise / R / MM4;
|
|
967
|
+
const W = stair.width / MM4;
|
|
968
|
+
const [T, above, below] = [D.tread(r) * MM4, D.above(r) * MM4, D.below(r) * MM4];
|
|
969
|
+
const [sw, bb, np] = [D.stringer(W) * MM4, D.baluster(W) * MM4, D.newel(W) * MM4];
|
|
970
|
+
const [railH, railW] = [D.railHeight * MM4, D.rail * MM4];
|
|
971
|
+
const out = {
|
|
972
|
+
treads: [],
|
|
973
|
+
stringers: [],
|
|
974
|
+
rails: [],
|
|
975
|
+
sides: [],
|
|
976
|
+
dropped: 0
|
|
977
|
+
};
|
|
978
|
+
const keep = (into, s) => {
|
|
979
|
+
if (s) into.push(s);
|
|
980
|
+
else out.dropped++;
|
|
981
|
+
};
|
|
982
|
+
const nosings = [];
|
|
983
|
+
const planAt = (f, d, a) => alongY(f.foot) ? [a, runCoordinate(f, d)] : [runCoordinate(f, d), a];
|
|
984
|
+
const planBox = (f, d0, d1, a0, a1) => {
|
|
985
|
+
const [p, q] = [planAt(f, d0, a0), planAt(f, d1, a1)];
|
|
986
|
+
return [Math.min(p[0], q[0]), Math.min(p[1], q[1]), Math.max(p[0], q[0]), Math.max(p[1], q[1])];
|
|
987
|
+
};
|
|
988
|
+
const solid = (b, za, zb) => prism(rect(b[0], b[1], b[2], b[3]), za, zb);
|
|
989
|
+
const section = (f, pts, a0, a1) => sideways(
|
|
990
|
+
pts.map(([d, z]) => [runCoordinate(f, d), z]),
|
|
991
|
+
a0,
|
|
992
|
+
a1,
|
|
993
|
+
alongY(f.foot)
|
|
994
|
+
);
|
|
995
|
+
const flightBoxes = flights.map((f) => [f.at[0], f.at[1], f.at[0] + f.size.w, f.at[1] + f.size.h]);
|
|
996
|
+
const landingBoxes = (stair.landings ?? []).slice(0, flights.length - 1).map((l) => [l.at[0], l.at[1], l.at[0] + l.size.w, l.at[1] + l.size.h]);
|
|
997
|
+
const newels = [];
|
|
998
|
+
const landings = [];
|
|
999
|
+
let climbed = 0;
|
|
1000
|
+
let base = z0;
|
|
1001
|
+
flights.forEach((f, i) => {
|
|
1002
|
+
const n = f.treads;
|
|
1003
|
+
const yRun = alongY(f.foot);
|
|
1004
|
+
const run = yRun ? f.size.h : f.size.w;
|
|
1005
|
+
const [lo, extent] = yRun ? [f.at[0], f.size.w] : [f.at[1], f.size.h];
|
|
1006
|
+
const width = Math.min(stair.width, extent);
|
|
1007
|
+
const c0 = lo + Math.round((extent - width) / 2);
|
|
1008
|
+
const c1 = c0 + width;
|
|
1009
|
+
const g = run / n / MM4;
|
|
1010
|
+
const nos = D.nosing(g) * MM4;
|
|
1011
|
+
nosings.push(nos / MM4);
|
|
1012
|
+
const line = (t) => Math.round(run * t / n);
|
|
1013
|
+
const first = riserTop(climbed + 1);
|
|
1014
|
+
const head = riserTop(climbed + n + 1);
|
|
1015
|
+
const slope = (head - first) / run;
|
|
1016
|
+
const h = (d) => first + slope * d;
|
|
1017
|
+
for (let t = 0; t < n; t++) {
|
|
1018
|
+
const top = riserTop(climbed + t + 1);
|
|
1019
|
+
keep(out.treads, solid(planBox(f, t === 0 ? 0 : line(t) - nos, line(t + 1), c0 + sw, c1 - sw), top - T, top));
|
|
1020
|
+
}
|
|
1021
|
+
const band = clipToConvex(
|
|
1022
|
+
[
|
|
1023
|
+
[0, Math.min(Math.round(h(0) - below), base)],
|
|
1024
|
+
[run, Math.round(h(run) - below)],
|
|
1025
|
+
[run, Math.round(h(run) + above)],
|
|
1026
|
+
[0, Math.round(h(0) + above)]
|
|
1027
|
+
],
|
|
1028
|
+
rect(0, z0, run, head).outer
|
|
1029
|
+
);
|
|
1030
|
+
keep(out.stringers, band ? section(f, band.outer, c0, c0 + sw) : null);
|
|
1031
|
+
keep(out.stringers, band ? section(f, band.outer, c1 - sw, c1) : null);
|
|
1032
|
+
const edges = [
|
|
1033
|
+
{ side: yRun ? "left" : "top", strip: [c0 - D.probe * MM4, c0], past: c0 - D.probe * MM4, cc: c0 + sw / 2 },
|
|
1034
|
+
{ side: yRun ? "right" : "bottom", strip: [c1, c1 + D.probe * MM4], past: c1 + D.probe * MM4, cc: c1 - sw / 2 }
|
|
1035
|
+
];
|
|
1036
|
+
const r0 = runCoordinate(f, 0);
|
|
1037
|
+
const dir = runCoordinate(f, 1) - r0;
|
|
1038
|
+
const dOf = (r2) => dir * (r2 - r0);
|
|
1039
|
+
for (const { side, strip, past, cc } of edges) {
|
|
1040
|
+
const touching = (boxes) => boxes.filter(([a, b, c, d]) => {
|
|
1041
|
+
const [x0, x1] = yRun ? [a, c] : [b, d];
|
|
1042
|
+
const [y0, y1] = yRun ? [b, d] : [a, c];
|
|
1043
|
+
return x0 < strip[1] && x1 > strip[0] && y1 > Math.min(r0, r0 + dir * run) && y0 < Math.max(r0, r0 + dir * run);
|
|
1044
|
+
});
|
|
1045
|
+
const byFlight = touching(flightBoxes.filter((_, j) => j !== i)).length > 0;
|
|
1046
|
+
const covered2 = [...flightBoxes.filter((_, j) => j !== i), ...landingBoxes].filter(([a, b, c, d]) => {
|
|
1047
|
+
const [x0, x1] = yRun ? [a, c] : [b, d];
|
|
1048
|
+
const [y0, y1] = yRun ? [b, d] : [a, c];
|
|
1049
|
+
return x0 < strip[1] && x1 > strip[0] && y1 > Math.min(r0, r0 + dir * run) && y0 < Math.max(r0, r0 + dir * run);
|
|
1050
|
+
}).map(([a, b, c, d]) => {
|
|
1051
|
+
const [y0, y1] = yRun ? [b, d] : [a, c];
|
|
1052
|
+
const [da, db] = [dOf(y0), dOf(y1)].sort((x, y) => x - y);
|
|
1053
|
+
return [Math.max(0, da), Math.min(run, db)];
|
|
1054
|
+
});
|
|
1055
|
+
const free = freeRuns(0, run, covered2, np);
|
|
1056
|
+
const open = free.filter(([da, db]) => !solidAt(planAt(f, Math.round((da + db) / 2), past)));
|
|
1057
|
+
const against = free.length === 0 ? byFlight ? "flight" : "landing" : open.length === 0 ? "wall" : "open";
|
|
1058
|
+
out.sides.push({ of: `flight ${i + 1}`, side, against });
|
|
1059
|
+
const ra = Math.round(cc - railW / 2);
|
|
1060
|
+
const lean = Math.ceil(slope * bb / 2) + MM4;
|
|
1061
|
+
const ba = Math.round(cc - bb / 2);
|
|
1062
|
+
const na = Math.round(cc - np / 2);
|
|
1063
|
+
for (const [da, db] of open) {
|
|
1064
|
+
keep(
|
|
1065
|
+
out.rails,
|
|
1066
|
+
section(
|
|
1067
|
+
f,
|
|
1068
|
+
[
|
|
1069
|
+
[da, Math.round(h(da) + railH - railW)],
|
|
1070
|
+
[db, Math.round(h(db) + railH - railW)],
|
|
1071
|
+
[db, Math.round(h(db) + railH)],
|
|
1072
|
+
[da, Math.round(h(da) + railH)]
|
|
1073
|
+
],
|
|
1074
|
+
ra,
|
|
1075
|
+
ra + railW
|
|
1076
|
+
)
|
|
1077
|
+
);
|
|
1078
|
+
for (let t = 0; t < n; t++) {
|
|
1079
|
+
const dm = Math.round((line(t) + line(t + 1)) / 2);
|
|
1080
|
+
if (dm - bb / 2 < da || dm + bb / 2 > db) continue;
|
|
1081
|
+
keep(
|
|
1082
|
+
out.rails,
|
|
1083
|
+
solid(
|
|
1084
|
+
planBox(f, dm - bb / 2, dm + bb / 2, ba, ba + bb),
|
|
1085
|
+
Math.round(h(dm) + above) - lean,
|
|
1086
|
+
Math.round(h(dm) + railH - railW) + lean
|
|
1087
|
+
)
|
|
1088
|
+
);
|
|
1089
|
+
}
|
|
1090
|
+
for (const [d, za] of [
|
|
1091
|
+
[0, base],
|
|
1092
|
+
[run, riserTop(climbed + n)]
|
|
1093
|
+
]) {
|
|
1094
|
+
if (d !== da && d !== db) continue;
|
|
1095
|
+
const nb = planBox(f, d - np / 2, d + np / 2, na, na + np);
|
|
1096
|
+
keep(out.rails, solid(nb, za, Math.round(h(d) + railH + D.newelAbove * MM4)));
|
|
1097
|
+
newels.push(nb);
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
climbed += n + 1;
|
|
1102
|
+
const landing = stair.landings?.[i];
|
|
1103
|
+
if (landing && i < flights.length - 1) {
|
|
1104
|
+
const top = riserTop(climbed);
|
|
1105
|
+
base = top;
|
|
1106
|
+
const box = [landing.at[0], landing.at[1], landing.at[0] + landing.size.w, landing.at[1] + landing.size.h];
|
|
1107
|
+
keep(out.treads, solid(box, z0, top));
|
|
1108
|
+
landings.push({ box, top, going: Math.round(g * MM4), k: i + 1 });
|
|
1109
|
+
}
|
|
1110
|
+
});
|
|
1111
|
+
const taken = [...newels];
|
|
1112
|
+
for (const { box, top, going, k } of landings) {
|
|
1113
|
+
const [x0, y0, x1, y1] = box;
|
|
1114
|
+
const p = D.probe * MM4;
|
|
1115
|
+
const edges = [
|
|
1116
|
+
{ side: "top", horizontal: true, at: y0, out: -1 },
|
|
1117
|
+
{ side: "right", horizontal: false, at: x1, out: 1 },
|
|
1118
|
+
{ side: "bottom", horizontal: true, at: y1, out: 1 },
|
|
1119
|
+
{ side: "left", horizontal: false, at: x0, out: -1 }
|
|
1120
|
+
];
|
|
1121
|
+
const railTop = top + D.landingRailHeight * MM4;
|
|
1122
|
+
for (const { side, horizontal, at: at2, out: dir } of edges) {
|
|
1123
|
+
const [a0, a1] = horizontal ? [x0, x1] : [y0, y1];
|
|
1124
|
+
const [s0, s1] = dir > 0 ? [at2, at2 + p] : [at2 - p, at2];
|
|
1125
|
+
const flightRuns = flightBoxes.filter(
|
|
1126
|
+
([fa, fb, fc, fd]) => horizontal ? fb < s1 && fd > s0 && fa < a1 && fc > a0 : fa < s1 && fc > s0 && fb < a1 && fd > a0
|
|
1127
|
+
).map(([fa, fb, fc, fd]) => horizontal ? [fa, fc] : [fb, fd]);
|
|
1128
|
+
const free = freeRuns(a0, a1, flightRuns, np);
|
|
1129
|
+
const open = free.filter(([r0, r1]) => {
|
|
1130
|
+
const m = Math.round((r0 + r1) / 2);
|
|
1131
|
+
return !solidAt(horizontal ? [m, at2 + dir * p] : [at2 + dir * p, m]);
|
|
1132
|
+
});
|
|
1133
|
+
const sideAt = out.sides.length;
|
|
1134
|
+
out.sides.push({
|
|
1135
|
+
of: `landing ${k}`,
|
|
1136
|
+
side,
|
|
1137
|
+
against: free.length === 0 ? "flight" : open.length === 0 ? "wall" : "open"
|
|
1138
|
+
});
|
|
1139
|
+
let railed = false;
|
|
1140
|
+
const across = side === "top" ? [y0, y0 + railW] : side === "bottom" ? [y1 - railW, y1] : side === "left" ? [x0, x0 + railW] : [x1 - railW, x1];
|
|
1141
|
+
for (const [r0, r1] of open) {
|
|
1142
|
+
const held = taken.filter((b) => horizontal ? b[1] < across[1] && b[3] > across[0] : b[0] < across[1] && b[2] > across[0]).map((b) => horizontal ? [b[0], b[2]] : [b[1], b[3]]);
|
|
1143
|
+
for (const [q0, q1] of freeRuns(r0, r1, held, np)) {
|
|
1144
|
+
const b = horizontal ? [q0, across[0], q1, across[1]] : [across[0], q0, across[1], q1];
|
|
1145
|
+
keep(out.rails, solid(b, railTop - railW, railTop));
|
|
1146
|
+
taken.push(b);
|
|
1147
|
+
railed = true;
|
|
1148
|
+
const len = q1 - q0;
|
|
1149
|
+
const count = Math.max(1, Math.min(64, Math.floor(len / going)));
|
|
1150
|
+
const mid = Math.round((across[0] + across[1] - bb) / 2);
|
|
1151
|
+
for (let j = 0; j < count; j++) {
|
|
1152
|
+
const c = Math.round(q0 + len * (2 * j + 1) / (2 * count) - bb / 2);
|
|
1153
|
+
const bal = horizontal ? [c, mid, c + bb, mid + bb] : [mid, c, mid + bb, c + bb];
|
|
1154
|
+
keep(out.rails, solid(bal, top, railTop - railW + MM4));
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
if (open.length > 0 && !railed) out.sides[sideAt].against = "newel";
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
return {
|
|
1162
|
+
treads: out.treads,
|
|
1163
|
+
stringers: out.stringers,
|
|
1164
|
+
rails: out.rails,
|
|
1165
|
+
risers: R,
|
|
1166
|
+
dropped: out.dropped,
|
|
1167
|
+
sides: out.sides,
|
|
1168
|
+
dims: {
|
|
1169
|
+
tread: T / MM4,
|
|
1170
|
+
nosing: nosings,
|
|
1171
|
+
stringer: { width: sw / MM4, above: above / MM4, below: below / MM4 },
|
|
1172
|
+
balustrade: {
|
|
1173
|
+
height: D.railHeight,
|
|
1174
|
+
rail: [D.rail, D.rail],
|
|
1175
|
+
baluster: bb / MM4,
|
|
1176
|
+
newel: np / MM4,
|
|
1177
|
+
newel_above: D.newelAbove,
|
|
1178
|
+
landing_height: D.landingRailHeight
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
// src/mesh/outdoor.ts
|
|
1185
|
+
import { DEFAULT_THEME } from "@chanmeng666/archlang";
|
|
1186
|
+
var OUTDOOR_MM = 50;
|
|
1187
|
+
var FENCE_HEIGHT_MM = { picket: 1e3, panel: 1800, post: 1100 };
|
|
1188
|
+
var CORE_POST_PITCH_MM = { picket: 600, panel: 1800, post: 1800 };
|
|
1189
|
+
var CORE_POSTS_PER_RUN = [1, 60];
|
|
1190
|
+
var FENCE_PROFILES = {
|
|
1191
|
+
picket: {
|
|
1192
|
+
post: 80,
|
|
1193
|
+
rails: [
|
|
1194
|
+
[20, 150, 220],
|
|
1195
|
+
[20, 700, 770]
|
|
1196
|
+
],
|
|
1197
|
+
pickets: [70, 20, 140]
|
|
1198
|
+
},
|
|
1199
|
+
panel: { post: 100, rails: [[40, 0, 1800]] },
|
|
1200
|
+
post: { post: 100, rails: [[60, 1040, 1100]] }
|
|
1201
|
+
};
|
|
1202
|
+
var MAX_FENCE_REPEAT = 400;
|
|
1203
|
+
var MM2 = 1e3;
|
|
1204
|
+
var tintOf = (surface) => GROUND_TINT[surface];
|
|
1205
|
+
function groundColour(tint, theme = DEFAULT_THEME) {
|
|
1206
|
+
const ch = (hex, i) => Number.parseInt(hex.slice(i, i + 2), 16);
|
|
1207
|
+
const bg = theme.bg;
|
|
1208
|
+
const wash = theme[tint];
|
|
1209
|
+
const out = [1, 3, 5].map((i) => {
|
|
1210
|
+
const v = ch(bg, i) - GROUND_WASH * (ch(bg, i) - ch(wash, i));
|
|
1211
|
+
return Math.max(0, Math.min(255, v)).toString(16).padStart(2, "0");
|
|
1212
|
+
});
|
|
1213
|
+
return `#${out.join("")}`;
|
|
1214
|
+
}
|
|
1215
|
+
function outdoorColour(surface) {
|
|
1216
|
+
const split = GROUND_SPLITS[surface];
|
|
1217
|
+
if (split) return { srgb: split.srgb, rule: "outdoor-colour-3d" };
|
|
1218
|
+
return { srgb: groundColour(tintOf(surface) ?? "paving"), rule: "outdoor-colour-theme" };
|
|
1219
|
+
}
|
|
1220
|
+
var fenceColour = (style) => (FENCE_PALETTE[style] ?? FENCE_PALETTE.picket).srgb;
|
|
1221
|
+
var at = (a, b, f) => [
|
|
1222
|
+
Math.round(a[0] + (b[0] - a[0]) * f),
|
|
1223
|
+
Math.round(a[1] + (b[1] - a[1]) * f)
|
|
1224
|
+
];
|
|
1225
|
+
function corePostCount(lenUm, style) {
|
|
1226
|
+
const pitch = CORE_POST_PITCH_MM[style] ?? CORE_POST_PITCH_MM.picket;
|
|
1227
|
+
const [lo, hi] = CORE_POSTS_PER_RUN;
|
|
1228
|
+
return Math.max(lo, Math.min(hi, Math.round(lenUm / MM2 / pitch)));
|
|
1229
|
+
}
|
|
1230
|
+
function fenceRuns(f) {
|
|
1231
|
+
const pts = f.points;
|
|
1232
|
+
const all = [];
|
|
1233
|
+
for (let i = 0; i + 1 < pts.length; i++) all.push([pts[i], pts[i + 1]]);
|
|
1234
|
+
if (f.closed && pts.length > 2) all.push([pts[pts.length - 1], pts[0]]);
|
|
1235
|
+
const runs = all.filter(([a, b]) => Math.hypot(b[0] - a[0], b[1] - a[1]) > 0);
|
|
1236
|
+
return { runs, ring: f.closed && pts.length > 2 && runs.length > 1 };
|
|
1237
|
+
}
|
|
1238
|
+
function fencePosts(f) {
|
|
1239
|
+
const { runs, ring } = fenceRuns(f);
|
|
1240
|
+
const out = [];
|
|
1241
|
+
runs.forEach(([a, b], i) => {
|
|
1242
|
+
const n = corePostCount(Math.hypot(b[0] - a[0], b[1] - a[1]), f.style);
|
|
1243
|
+
for (let k = 0; k < n; k++) out.push({ at: at(a, b, k / n), run: [a, b] });
|
|
1244
|
+
if (i === runs.length - 1 && !ring) out.push({ at: b, run: [a, b] });
|
|
1245
|
+
});
|
|
1246
|
+
return out;
|
|
1247
|
+
}
|
|
1248
|
+
function fencePieces(f, profile, height) {
|
|
1249
|
+
const out = [];
|
|
1250
|
+
const box = (c, [a, b], w, d) => {
|
|
1251
|
+
const len = Math.hypot(b[0] - a[0], b[1] - a[1]);
|
|
1252
|
+
const ux = (b[0] - a[0]) / len;
|
|
1253
|
+
const uy = (b[1] - a[1]) / len;
|
|
1254
|
+
const p = (s) => [Math.round(c[0] + ux * s), Math.round(c[1] + uy * s)];
|
|
1255
|
+
return slab2d(p(-w / 2), p(w / 2), d);
|
|
1256
|
+
};
|
|
1257
|
+
for (const p of fencePosts(f))
|
|
1258
|
+
out.push({ poly: box(p.at, p.run, profile.post * MM2, profile.post * MM2), z: [0, height] });
|
|
1259
|
+
for (const [a, b] of fenceRuns(f).runs) {
|
|
1260
|
+
const len = Math.hypot(b[0] - a[0], b[1] - a[1]);
|
|
1261
|
+
for (const [depth, z0, z1] of profile.rails)
|
|
1262
|
+
out.push({ poly: slab2d(a, b, depth * MM2), z: [Math.min(z0, height), Math.min(z1, height)] });
|
|
1263
|
+
if (profile.pickets) {
|
|
1264
|
+
const [w, d, pitch] = profile.pickets;
|
|
1265
|
+
const m = Math.max(1, Math.min(MAX_FENCE_REPEAT, Math.ceil(len / (pitch * MM2))));
|
|
1266
|
+
const pw = Math.min(w * MM2, len / m);
|
|
1267
|
+
for (let j = 0; j < m; j++) out.push({ poly: box(at(a, b, (j + 0.5) / m), [a, b], pw, d * MM2), z: [0, height] });
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
return out;
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
// src/mesh/build.ts
|
|
1274
|
+
var MM3 = 1e3;
|
|
1275
|
+
var SLAB_MM = 200;
|
|
1276
|
+
var FLOOR_FINISH_MM = 5;
|
|
1277
|
+
var ROOF_MM = 150;
|
|
1278
|
+
var LEAF_MM = 40;
|
|
1279
|
+
var GLASS_MM = 16;
|
|
1280
|
+
var FRAME_WIDTH_MM = 40;
|
|
1281
|
+
var FRAME_DEPTH_MM = 60;
|
|
1282
|
+
var FURNITURE_DEFAULT_MM = 750;
|
|
1283
|
+
var FURNITURE_HEIGHT_MM = {
|
|
1284
|
+
bed: 500,
|
|
1285
|
+
double_bed: 500,
|
|
1286
|
+
bunk_bed: 1600,
|
|
1287
|
+
sofa: 800,
|
|
1288
|
+
armchair: 800,
|
|
1289
|
+
chair: 850,
|
|
1290
|
+
table: 750,
|
|
1291
|
+
dining_table: 750,
|
|
1292
|
+
desk: 750,
|
|
1293
|
+
wardrobe: 2e3,
|
|
1294
|
+
bookshelf: 1800,
|
|
1295
|
+
fridge: 1800,
|
|
1296
|
+
stove: 900,
|
|
1297
|
+
kitchen_sink: 900,
|
|
1298
|
+
counter: 900,
|
|
1299
|
+
dishwasher: 850,
|
|
1300
|
+
washing_machine: 850,
|
|
1301
|
+
wc: 750,
|
|
1302
|
+
basin: 850,
|
|
1303
|
+
bath: 550,
|
|
1304
|
+
shower: 50,
|
|
1305
|
+
tv: 600,
|
|
1306
|
+
rug: 10
|
|
1307
|
+
};
|
|
1308
|
+
var STAGE = {
|
|
1309
|
+
slab: "brief",
|
|
1310
|
+
floor: "rooms",
|
|
1311
|
+
column: "walls",
|
|
1312
|
+
wall: "walls",
|
|
1313
|
+
roof: "walls",
|
|
1314
|
+
door: "openings",
|
|
1315
|
+
window: "openings",
|
|
1316
|
+
opening: "openings",
|
|
1317
|
+
furniture: "fixtures",
|
|
1318
|
+
stair: "walls",
|
|
1319
|
+
// The site (card RM8.3): its surfaces are laid out with the slab, before the rooms; a fence rises
|
|
1320
|
+
// with the storey's walls.
|
|
1321
|
+
outdoor: "brief",
|
|
1322
|
+
fence: "walls"
|
|
1323
|
+
};
|
|
1324
|
+
var byText = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
1325
|
+
function along(a, b, d) {
|
|
1326
|
+
const len = Math.hypot(b[0] - a[0], b[1] - a[1]) || 1;
|
|
1327
|
+
return [Math.round(a[0] + (b[0] - a[0]) / len * d), Math.round(a[1] + (b[1] - a[1]) / len * d)];
|
|
1328
|
+
}
|
|
1329
|
+
var inRing = (p, r) => {
|
|
1330
|
+
let c = false;
|
|
1331
|
+
for (let i = 0, j = r.length - 1; i < r.length; j = i++) {
|
|
1332
|
+
const a = r[i];
|
|
1333
|
+
const b = r[j];
|
|
1334
|
+
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;
|
|
1335
|
+
}
|
|
1336
|
+
return c;
|
|
1337
|
+
};
|
|
1338
|
+
function asRect(ring) {
|
|
1339
|
+
if (ring.length !== 4) return null;
|
|
1340
|
+
const xs = [...new Set(ring.map((p) => p[0]))];
|
|
1341
|
+
const ys = [...new Set(ring.map((p) => p[1]))];
|
|
1342
|
+
if (xs.length !== 2 || ys.length !== 2) return null;
|
|
1343
|
+
const axis = ring.every((p, i) => {
|
|
1344
|
+
const q = ring[(i + 1) % 4];
|
|
1345
|
+
return p[0] === q[0] || p[1] === q[1];
|
|
1346
|
+
});
|
|
1347
|
+
return axis ? [Math.min(...xs), Math.min(...ys), Math.max(...xs), Math.max(...ys)] : null;
|
|
1348
|
+
}
|
|
1349
|
+
function rectTouches(r, ring) {
|
|
1350
|
+
const corners = [
|
|
1351
|
+
[r[0], r[1]],
|
|
1352
|
+
[r[2], r[1]],
|
|
1353
|
+
[r[2], r[3]],
|
|
1354
|
+
[r[0], r[3]]
|
|
1355
|
+
];
|
|
1356
|
+
if (corners.some((c) => inRing(c, ring))) return true;
|
|
1357
|
+
return ring.some((p) => p[0] >= r[0] && p[0] <= r[2] && p[1] >= r[1] && p[1] <= r[3]);
|
|
1358
|
+
}
|
|
1359
|
+
function lessVoids(outer, voids, where2, ledger) {
|
|
1360
|
+
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] }));
|
|
1361
|
+
const box = asRect(outer);
|
|
1362
|
+
if (box) {
|
|
1363
|
+
let pieces = [box];
|
|
1364
|
+
for (const v of rects) pieces = pieces.flatMap((p) => rectMinus(p, v.r));
|
|
1365
|
+
return pieces.map((p) => rect(p[0], p[1], p[2], p[3]));
|
|
1366
|
+
}
|
|
1367
|
+
const holes = [];
|
|
1368
|
+
const taken = [];
|
|
1369
|
+
for (const v of rects) {
|
|
1370
|
+
if (!rectTouches(v.r, outer)) continue;
|
|
1371
|
+
const corners = rect(v.r[0], v.r[1], v.r[2], v.r[3]).outer;
|
|
1372
|
+
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]);
|
|
1373
|
+
if (strict) {
|
|
1374
|
+
holes.push(corners);
|
|
1375
|
+
taken.push(v.r);
|
|
1376
|
+
} else {
|
|
1377
|
+
ledger.push({
|
|
1378
|
+
kind: "void",
|
|
1379
|
+
id: v.id,
|
|
1380
|
+
field: "cut",
|
|
1381
|
+
value: where2,
|
|
1382
|
+
provenance: "default",
|
|
1383
|
+
rule: "void-not-cut-non-rect"
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
return [{ outer: [...outer], ...holes.length ? { holes } : {} }];
|
|
1388
|
+
}
|
|
1389
|
+
var DOOR_POSES = ["closed", "plan"];
|
|
1390
|
+
function openLeaf(h, f, end, t) {
|
|
1391
|
+
const r = Math.hypot(end[0] - h[0], end[1] - h[1]);
|
|
1392
|
+
const c = Math.hypot(f[0] - h[0], f[1] - h[1]);
|
|
1393
|
+
if (r === 0 || c === 0) return { outer: [h, h, h] };
|
|
1394
|
+
const tt = Math.min(t, r / 2);
|
|
1395
|
+
const ox = (end[0] - h[0]) / r;
|
|
1396
|
+
const oy = (end[1] - h[1]) / r;
|
|
1397
|
+
const ax = (f[0] - h[0]) / c;
|
|
1398
|
+
const ay = (f[1] - h[1]) / c;
|
|
1399
|
+
const reach = Math.sqrt(r * r - tt * tt) - 1;
|
|
1400
|
+
const p = (x, y) => [Math.round(x), Math.round(y)];
|
|
1401
|
+
return {
|
|
1402
|
+
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)]
|
|
1403
|
+
};
|
|
1404
|
+
}
|
|
1405
|
+
function leafThroughWall(leaf, walls) {
|
|
1406
|
+
const [h, end, , inner] = leaf.outer;
|
|
1407
|
+
if (!h || !end || !inner) return false;
|
|
1408
|
+
const ox = (inner[0] - h[0]) / 2;
|
|
1409
|
+
const oy = (inner[1] - h[1]) / 2;
|
|
1410
|
+
for (let k = 1; k <= 19; k++) {
|
|
1411
|
+
const s = k / 20;
|
|
1412
|
+
const p = [h[0] + (end[0] - h[0]) * s + ox, h[1] + (end[1] - h[1]) * s + oy];
|
|
1413
|
+
for (const w of walls)
|
|
1414
|
+
for (const piece of w.body)
|
|
1415
|
+
if (inRing(p, piece.outer) && !(piece.holes ?? []).some((r) => inRing(p, r))) return true;
|
|
1416
|
+
}
|
|
1417
|
+
return false;
|
|
1418
|
+
}
|
|
1419
|
+
function levelNodes(lv, ledger, defaulted, isTop, doors, below, above) {
|
|
1420
|
+
const e = lv.elevation;
|
|
1421
|
+
const out = [];
|
|
1422
|
+
let holesLeftOut = 0;
|
|
1423
|
+
const prism2 = (poly, z0, z1, splits2) => {
|
|
1424
|
+
const s = prism(poly, z0, z1, splits2);
|
|
1425
|
+
if (s) holesLeftOut += degenerateHoles(poly);
|
|
1426
|
+
return s;
|
|
1427
|
+
};
|
|
1428
|
+
const node = (kind, id, order, shells, extras = {}, part) => {
|
|
1429
|
+
const ok = shells.filter((s) => s !== null);
|
|
1430
|
+
if (ok.length < shells.length) {
|
|
1431
|
+
ledger.push({
|
|
1432
|
+
kind,
|
|
1433
|
+
id,
|
|
1434
|
+
field: "shells_dropped",
|
|
1435
|
+
value: shells.length - ok.length,
|
|
1436
|
+
provenance: "derived",
|
|
1437
|
+
rule: "shell-degenerate-or-touching-hole"
|
|
1438
|
+
});
|
|
1439
|
+
}
|
|
1440
|
+
if (holesLeftOut > 0) {
|
|
1441
|
+
ledger.push({
|
|
1442
|
+
kind,
|
|
1443
|
+
id,
|
|
1444
|
+
field: "holes_dropped",
|
|
1445
|
+
value: holesLeftOut,
|
|
1446
|
+
provenance: "derived",
|
|
1447
|
+
rule: "hole-degenerate"
|
|
1448
|
+
});
|
|
1449
|
+
holesLeftOut = 0;
|
|
1450
|
+
}
|
|
1451
|
+
if (ok.length === 0) return;
|
|
1452
|
+
out.push({
|
|
1453
|
+
key: `L${lv.level}/${kind}:${id}${part ? `:${part}` : ""}`,
|
|
1454
|
+
level: lv.level,
|
|
1455
|
+
kind,
|
|
1456
|
+
id,
|
|
1457
|
+
...part ? { part } : {},
|
|
1458
|
+
stage: STAGE[kind],
|
|
1459
|
+
order,
|
|
1460
|
+
...kind === "roof" ? { hidden: true } : {},
|
|
1461
|
+
extras,
|
|
1462
|
+
shells: ok
|
|
1463
|
+
});
|
|
1464
|
+
};
|
|
1465
|
+
node(
|
|
1466
|
+
"slab",
|
|
1467
|
+
"slab",
|
|
1468
|
+
0,
|
|
1469
|
+
slabRegion(lv.footprint, lv.floors, ledger).flatMap((r) => lessVoids(r.outer, lv.voids, "slab", ledger)).map((p) => prism2(p, e - SLAB_MM * MM3, e)),
|
|
1470
|
+
{ thickness_mm: SLAB_MM }
|
|
1471
|
+
);
|
|
1472
|
+
lv.floors.forEach((f, i) => {
|
|
1473
|
+
const pieces = f.polygon.holes?.length ? [f.polygon] : lessVoids(f.polygon.outer, lv.voids, `floor:${f.id}`, ledger);
|
|
1474
|
+
const z0 = e + (f.lift ?? 0);
|
|
1475
|
+
const finish = floorFinish(f.uses);
|
|
1476
|
+
ledger.push({
|
|
1477
|
+
kind: "floor",
|
|
1478
|
+
id: f.id,
|
|
1479
|
+
field: "finish",
|
|
1480
|
+
value: finish,
|
|
1481
|
+
provenance: "default",
|
|
1482
|
+
rule: "floor-finish-default"
|
|
1483
|
+
});
|
|
1484
|
+
node(
|
|
1485
|
+
"floor",
|
|
1486
|
+
f.id,
|
|
1487
|
+
i,
|
|
1488
|
+
pieces.map((p) => prism2(p, z0, z0 + FLOOR_FINISH_MM * MM3)),
|
|
1489
|
+
{
|
|
1490
|
+
...f.uses?.length ? { uses: f.uses.join(" ") } : {},
|
|
1491
|
+
...f.lift ? { lift_mm: f.lift / MM3 } : {},
|
|
1492
|
+
finish
|
|
1493
|
+
}
|
|
1494
|
+
);
|
|
1495
|
+
});
|
|
1496
|
+
const ceiling = above ? above.elevation - SLAB_MM * MM3 - e : 0;
|
|
1497
|
+
const slabAbove = above && ceiling > 0 ? slabRegion(above.footprint, above.floors, []).flatMap((r) => lessVoids(r.outer, above.voids, "slab", [])) : [];
|
|
1498
|
+
const stopped = (height, rings) => height > ceiling && ceiling > 0 && rings.every((r) => coveredBy(r, slabAbove));
|
|
1499
|
+
const stopLedger = (kind, id) => {
|
|
1500
|
+
ledger.push({
|
|
1501
|
+
kind,
|
|
1502
|
+
id,
|
|
1503
|
+
field: `top_mm(L${lv.level})`,
|
|
1504
|
+
value: ceiling / MM3,
|
|
1505
|
+
provenance: "derived",
|
|
1506
|
+
rule: "stops-under-slab-above"
|
|
1507
|
+
});
|
|
1508
|
+
};
|
|
1509
|
+
lv.columns.forEach((c, i) => {
|
|
1510
|
+
const box = rect(c.at[0], c.at[1], c.at[0] + c.size.w, c.at[1] + c.size.h);
|
|
1511
|
+
const stop = stopped(lv.storeyHeight, [box.outer]);
|
|
1512
|
+
if (stop) stopLedger("column", c.id);
|
|
1513
|
+
node("column", c.id, i, [prism2(box, e, e + (stop ? ceiling : lv.storeyHeight))]);
|
|
1514
|
+
});
|
|
1515
|
+
const climbs = [];
|
|
1516
|
+
lv.stairs.forEach((s, i) => {
|
|
1517
|
+
if (s.dir === "up") {
|
|
1518
|
+
climbs.push({ s, order: i, rise: above ? above.elevation - e : lv.storeyHeight, from: "own" });
|
|
1519
|
+
if (!above) {
|
|
1520
|
+
ledger.push({
|
|
1521
|
+
kind: "stair",
|
|
1522
|
+
id: s.id,
|
|
1523
|
+
field: "rise_mm",
|
|
1524
|
+
value: lv.storeyHeight / MM3,
|
|
1525
|
+
provenance: "default",
|
|
1526
|
+
rule: "stair-rise-storey-height"
|
|
1527
|
+
});
|
|
1528
|
+
}
|
|
1529
|
+
} else if (!below) {
|
|
1530
|
+
ledger.push({
|
|
1531
|
+
kind: "stair",
|
|
1532
|
+
id: s.id,
|
|
1533
|
+
field: "geometry",
|
|
1534
|
+
value: "omitted",
|
|
1535
|
+
provenance: "default",
|
|
1536
|
+
rule: "stair-down-no-storey-below"
|
|
1537
|
+
});
|
|
1538
|
+
}
|
|
1539
|
+
});
|
|
1540
|
+
(above?.stairs ?? []).forEach((s, i) => {
|
|
1541
|
+
const partnered = lv.stairs.some((t) => t.id === s.id && t.dir === "up");
|
|
1542
|
+
if (s.dir === "down" && !partnered && above)
|
|
1543
|
+
climbs.push({ s, order: lv.stairs.length + i, rise: above.elevation - e, from: "above" });
|
|
1544
|
+
});
|
|
1545
|
+
const stairFloor = e + FLOOR_FINISH_MM * MM3;
|
|
1546
|
+
const solidAt = (p) => lv.walls.some((w) => w.body.some((b) => inRing(p, b.outer) && !(b.holes ?? []).some((r) => inRing(p, r)))) || lv.columns.some((c) => p[0] > c.at[0] && p[0] < c.at[0] + c.size.w && p[1] > c.at[1] && p[1] < c.at[1] + c.size.h);
|
|
1547
|
+
for (const { s, order, rise, from } of climbs) {
|
|
1548
|
+
const solid = stairDetail(s, stairFloor, rise, solidAt);
|
|
1549
|
+
if (!solid) {
|
|
1550
|
+
ledger.push({
|
|
1551
|
+
kind: "stair",
|
|
1552
|
+
id: s.id,
|
|
1553
|
+
field: "geometry",
|
|
1554
|
+
value: "omitted",
|
|
1555
|
+
provenance: "default",
|
|
1556
|
+
rule: s.flights?.length ? "stair-rise-not-positive" : "stair-no-flights"
|
|
1557
|
+
});
|
|
1558
|
+
continue;
|
|
1559
|
+
}
|
|
1560
|
+
if (!defaulted.has("stair:defaults")) {
|
|
1561
|
+
defaulted.add("stair:defaults");
|
|
1562
|
+
ledger.push(
|
|
1563
|
+
{
|
|
1564
|
+
kind: "stair",
|
|
1565
|
+
field: "material",
|
|
1566
|
+
value: STAIR_MATERIAL,
|
|
1567
|
+
provenance: "default",
|
|
1568
|
+
rule: "stair-material-default"
|
|
1569
|
+
},
|
|
1570
|
+
// Card RM8.6: the handrails, balusters and newels in the walnut of the palette.
|
|
1571
|
+
{
|
|
1572
|
+
kind: "stair",
|
|
1573
|
+
field: "material(rail)",
|
|
1574
|
+
value: STAIR_RAIL_MATERIAL,
|
|
1575
|
+
provenance: "default",
|
|
1576
|
+
rule: "stair-rail-material-default"
|
|
1577
|
+
}
|
|
1578
|
+
);
|
|
1579
|
+
}
|
|
1580
|
+
ledger.push({
|
|
1581
|
+
kind: "stair",
|
|
1582
|
+
id: s.id,
|
|
1583
|
+
field: "risers",
|
|
1584
|
+
value: solid.risers,
|
|
1585
|
+
provenance: "derived",
|
|
1586
|
+
rule: "stair-risers-from-treads"
|
|
1587
|
+
});
|
|
1588
|
+
const d = solid.dims;
|
|
1589
|
+
ledger.push(
|
|
1590
|
+
{
|
|
1591
|
+
kind: "stair",
|
|
1592
|
+
id: s.id,
|
|
1593
|
+
field: "tread_mm",
|
|
1594
|
+
value: { thickness: d.tread, nosing: d.nosing },
|
|
1595
|
+
provenance: "default",
|
|
1596
|
+
rule: "stair-tread-default"
|
|
1597
|
+
},
|
|
1598
|
+
{ kind: "stair", id: s.id, field: "risers_form", value: "open", provenance: "default", rule: "stair-open-riser" },
|
|
1599
|
+
{
|
|
1600
|
+
kind: "stair",
|
|
1601
|
+
id: s.id,
|
|
1602
|
+
field: "stringer_mm",
|
|
1603
|
+
value: d.stringer,
|
|
1604
|
+
provenance: "default",
|
|
1605
|
+
rule: "stair-stringer-default"
|
|
1606
|
+
},
|
|
1607
|
+
...s.landings?.length ? [
|
|
1608
|
+
{
|
|
1609
|
+
kind: "stair",
|
|
1610
|
+
id: s.id,
|
|
1611
|
+
field: "landing",
|
|
1612
|
+
value: "solid",
|
|
1613
|
+
provenance: "default",
|
|
1614
|
+
rule: "stair-landing-solid"
|
|
1615
|
+
}
|
|
1616
|
+
] : [],
|
|
1617
|
+
{
|
|
1618
|
+
kind: "stair",
|
|
1619
|
+
id: s.id,
|
|
1620
|
+
field: "balustrade_mm",
|
|
1621
|
+
value: d.balustrade,
|
|
1622
|
+
provenance: "default",
|
|
1623
|
+
rule: "stair-balustrade-default"
|
|
1624
|
+
},
|
|
1625
|
+
...solid.sides.map((x) => ({
|
|
1626
|
+
kind: "stair",
|
|
1627
|
+
id: s.id,
|
|
1628
|
+
field: `side(${x.of}, ${x.side})`,
|
|
1629
|
+
value: x.against,
|
|
1630
|
+
provenance: "derived",
|
|
1631
|
+
rule: "stair-balustrade-side"
|
|
1632
|
+
})),
|
|
1633
|
+
...above ? [
|
|
1634
|
+
{
|
|
1635
|
+
kind: "stair",
|
|
1636
|
+
id: s.id,
|
|
1637
|
+
field: "void_guard",
|
|
1638
|
+
value: "omitted",
|
|
1639
|
+
provenance: "default",
|
|
1640
|
+
rule: "stair-void-guard-omitted"
|
|
1641
|
+
}
|
|
1642
|
+
] : []
|
|
1643
|
+
);
|
|
1644
|
+
node("stair", s.id, order, [...solid.treads, ...Array.from({ length: solid.dropped }, () => null)], {
|
|
1645
|
+
dir: s.dir,
|
|
1646
|
+
width_mm: s.width / MM3,
|
|
1647
|
+
flights: s.flights?.length ?? 0,
|
|
1648
|
+
risers: solid.risers,
|
|
1649
|
+
rise_mm: rise / MM3,
|
|
1650
|
+
...from === "above" ? { from_storey_above: true } : {}
|
|
1651
|
+
});
|
|
1652
|
+
node("stair", s.id, order, solid.stringers, {}, "stringer");
|
|
1653
|
+
if (solid.rails.length) node("stair", s.id, order, solid.rails, {}, "rail");
|
|
1654
|
+
}
|
|
1655
|
+
const openings = new Map(lv.openings.map((o) => [o.id, o]));
|
|
1656
|
+
const wallHeight = new Map(
|
|
1657
|
+
lv.walls.map((w) => {
|
|
1658
|
+
const cut = w.cuts.flatMap((id) => {
|
|
1659
|
+
const o = openings.get(id);
|
|
1660
|
+
return o ? [o] : [];
|
|
1661
|
+
});
|
|
1662
|
+
const stop = stopped(w.height, [...w.body.map((p) => p.outer), ...cut.map((o) => o.cut)]);
|
|
1663
|
+
if (!stop) return [w.id, w.height];
|
|
1664
|
+
stopLedger("wall", w.id);
|
|
1665
|
+
for (const o of cut.filter((x) => x.head > ceiling)) {
|
|
1666
|
+
ledger.push({
|
|
1667
|
+
kind: o.kind,
|
|
1668
|
+
id: o.id,
|
|
1669
|
+
field: `head_mm(L${lv.level})`,
|
|
1670
|
+
value: ceiling / MM3,
|
|
1671
|
+
provenance: "derived",
|
|
1672
|
+
rule: "head-at-slab-above"
|
|
1673
|
+
});
|
|
1674
|
+
}
|
|
1675
|
+
return [w.id, ceiling];
|
|
1676
|
+
})
|
|
1677
|
+
);
|
|
1678
|
+
const hostHeight = wallHeight;
|
|
1679
|
+
const splitAt = /* @__PURE__ */ new Map();
|
|
1680
|
+
for (const o of lv.openings) {
|
|
1681
|
+
const h = hostHeight.get(o.host);
|
|
1682
|
+
if (h === void 0) continue;
|
|
1683
|
+
const hs = [...o.sill > 0 ? [Math.min(o.sill, h)] : [], ...o.head < h ? [o.head] : []];
|
|
1684
|
+
for (const p of o.cut) {
|
|
1685
|
+
const k = `${p[0]},${p[1]}`;
|
|
1686
|
+
splitAt.set(k, [...splitAt.get(k) ?? [], ...hs]);
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
const splits = (p) => (splitAt.get(`${p[0]},${p[1]}`) ?? []).map((h) => e + h);
|
|
1690
|
+
lv.walls.forEach((w, i) => {
|
|
1691
|
+
const height = wallHeight.get(w.id) ?? w.height;
|
|
1692
|
+
const top = e + height;
|
|
1693
|
+
const shells = w.body.map((p) => prism2(p, e, top, splits));
|
|
1694
|
+
for (const id of w.cuts) {
|
|
1695
|
+
const o = openings.get(id);
|
|
1696
|
+
if (!o) continue;
|
|
1697
|
+
if (o.sill > 0) shells.push(prism2({ outer: o.cut }, e, e + Math.min(o.sill, height)));
|
|
1698
|
+
if (o.head < height) shells.push(prism2({ outer: o.cut }, e + o.head, top));
|
|
1699
|
+
}
|
|
1700
|
+
node("wall", w.id, i, shells, {
|
|
1701
|
+
...w.category ? { category: w.category } : {},
|
|
1702
|
+
height_mm: w.height / MM3,
|
|
1703
|
+
thickness_mm: w.thickness / MM3
|
|
1704
|
+
});
|
|
1705
|
+
});
|
|
1706
|
+
(lv.demolished ?? []).forEach((w, i) => {
|
|
1707
|
+
node(
|
|
1708
|
+
"wall",
|
|
1709
|
+
w.id,
|
|
1710
|
+
lv.walls.length + i,
|
|
1711
|
+
w.body.map((p) => prism2(p, e, e + w.height)),
|
|
1712
|
+
{
|
|
1713
|
+
...w.category ? { category: w.category } : {},
|
|
1714
|
+
height_mm: w.height / MM3,
|
|
1715
|
+
status: "demolish",
|
|
1716
|
+
thickness_mm: w.thickness / MM3
|
|
1717
|
+
},
|
|
1718
|
+
"demolish"
|
|
1719
|
+
);
|
|
1720
|
+
});
|
|
1721
|
+
const hostOf = new Map(lv.walls.map((w) => [w.id, w]));
|
|
1722
|
+
const nameless = (o) => /[:/\s]/.test(o.id);
|
|
1723
|
+
const trimInputs = lv.openings.flatMap((o) => {
|
|
1724
|
+
const host = hostOf.get(o.host);
|
|
1725
|
+
if (!host || nameless(o)) return [];
|
|
1726
|
+
const head = Math.min(o.head, hostHeight.get(o.host) ?? o.head);
|
|
1727
|
+
return [{ o, t: host.thickness, head, top: hostHeight.get(o.host) ?? host.height }];
|
|
1728
|
+
});
|
|
1729
|
+
const trims = storeyTrim(
|
|
1730
|
+
lv,
|
|
1731
|
+
trimInputs,
|
|
1732
|
+
e,
|
|
1733
|
+
(poly, a, b) => prism2(poly, a, b),
|
|
1734
|
+
(f) => {
|
|
1735
|
+
const floor = FLOOR_FINISH_MM * MM3;
|
|
1736
|
+
const family = f.asset.startsWith("t0:") ? f.asset.slice(3) : void 0;
|
|
1737
|
+
const turn = (-f.yawDeg % 360 + 360) % 360 % 90 === 0;
|
|
1738
|
+
if (!family || !turn) return [floor, floor + (FURNITURE_HEIGHT_MM[f.category] ?? FURNITURE_DEFAULT_MM) * MM3];
|
|
1739
|
+
const h = (T0_HEIGHT_MM[family] ?? 0) * MM3;
|
|
1740
|
+
if (T0_HUNG_FROM_TOP.has(family)) {
|
|
1741
|
+
const ys = (t0Shells(f, floor)?.shells ?? []).flatMap(
|
|
1742
|
+
(sh) => sh ? sh.positions.filter((_, k) => k % 3 === 1) : []
|
|
1743
|
+
);
|
|
1744
|
+
return [ys.length ? Math.min(...ys) : floor, floor + h];
|
|
1745
|
+
}
|
|
1746
|
+
return [floor + (T0_MOUNT_MM[family] ?? 0) * MM3, floor + h];
|
|
1747
|
+
}
|
|
1748
|
+
);
|
|
1749
|
+
lv.openings.forEach((o, i) => {
|
|
1750
|
+
const [j0, j1] = o.jambs;
|
|
1751
|
+
const head = Math.min(o.head, hostHeight.get(o.host) ?? o.head);
|
|
1752
|
+
const extras = { host: o.host, width_mm: o.width / MM3, sill_mm: o.sill / MM3, head_mm: o.head / MM3 };
|
|
1753
|
+
const trim = trims.get(o.id);
|
|
1754
|
+
if (hostOf.has(o.host) && nameless(o)) {
|
|
1755
|
+
ledger.push({
|
|
1756
|
+
kind: o.kind,
|
|
1757
|
+
id: o.id,
|
|
1758
|
+
field: "trim",
|
|
1759
|
+
value: "the id names no part node",
|
|
1760
|
+
provenance: "default",
|
|
1761
|
+
rule: "opening-trim-omitted"
|
|
1762
|
+
});
|
|
1763
|
+
} else if (trim) {
|
|
1764
|
+
ledger.push(...trim.ledger);
|
|
1765
|
+
for (const t of trim.parts) {
|
|
1766
|
+
const slot = `${o.kind}:${t.part}`;
|
|
1767
|
+
if (!defaulted.has(`trim:${slot}`)) {
|
|
1768
|
+
defaulted.add(`trim:${slot}`);
|
|
1769
|
+
ledger.push({
|
|
1770
|
+
kind: o.kind,
|
|
1771
|
+
field: `material(${t.part})`,
|
|
1772
|
+
value: TRIM_MATERIAL[slot] ?? o.kind,
|
|
1773
|
+
provenance: "default",
|
|
1774
|
+
rule: "trim-material-default"
|
|
1775
|
+
});
|
|
1776
|
+
}
|
|
1777
|
+
node(o.kind, o.id, i, t.shells, { host: o.host }, t.part);
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
if (o.kind === "door") {
|
|
1781
|
+
const z0 = e + o.sill;
|
|
1782
|
+
const swung = o.leaves?.every((l) => l.length === 3) ? o.leaves : void 0;
|
|
1783
|
+
if (doors === "plan" && swung) {
|
|
1784
|
+
const open = swung.map(([h, f, end]) => openLeaf(h, f, end, LEAF_MM * MM3));
|
|
1785
|
+
const through = open.some((leaf) => leafThroughWall(leaf, lv.walls));
|
|
1786
|
+
if (through) {
|
|
1787
|
+
ledger.push({
|
|
1788
|
+
kind: "door",
|
|
1789
|
+
id: o.id,
|
|
1790
|
+
field: "leaf",
|
|
1791
|
+
value: "through-wall",
|
|
1792
|
+
provenance: "derived",
|
|
1793
|
+
rule: "door-leaf-through-wall"
|
|
1794
|
+
});
|
|
1795
|
+
}
|
|
1796
|
+
node(
|
|
1797
|
+
"door",
|
|
1798
|
+
o.id,
|
|
1799
|
+
i,
|
|
1800
|
+
open.map((leaf) => prism2(leaf, z0, e + head)),
|
|
1801
|
+
// `through_wall` rides on the node, so a GLB reader (whose file carries no ledger) sees it too.
|
|
1802
|
+
{ ...extras, door_kind: o.doorKind ?? "hinged", pose: "plan", ...through ? { through_wall: true } : {} }
|
|
1803
|
+
);
|
|
1804
|
+
return;
|
|
1805
|
+
}
|
|
1806
|
+
if (doors === "plan") {
|
|
1807
|
+
ledger.push({
|
|
1808
|
+
kind: "door",
|
|
1809
|
+
id: o.id,
|
|
1810
|
+
field: "pose",
|
|
1811
|
+
value: "closed",
|
|
1812
|
+
provenance: "default",
|
|
1813
|
+
rule: "door-pose-plan-no-swing"
|
|
1814
|
+
});
|
|
1815
|
+
}
|
|
1816
|
+
const leaves = o.leaves ?? [[j0, j1]];
|
|
1817
|
+
node(
|
|
1818
|
+
"door",
|
|
1819
|
+
o.id,
|
|
1820
|
+
i,
|
|
1821
|
+
leaves.map(([h, f]) => prism2(slab2d(h, f, LEAF_MM * MM3), z0, e + head)),
|
|
1822
|
+
{ ...extras, door_kind: o.doorKind ?? "hinged", pose: "closed" }
|
|
1823
|
+
);
|
|
1824
|
+
} else if (o.kind === "window") {
|
|
1825
|
+
const z0 = e + o.sill;
|
|
1826
|
+
const z1 = e + head;
|
|
1827
|
+
const fw = FRAME_WIDTH_MM * MM3;
|
|
1828
|
+
const fd = FRAME_DEPTH_MM * MM3;
|
|
1829
|
+
const sector = cutSector(o.cut, o.jambs, o.centre);
|
|
1830
|
+
if (sector) {
|
|
1831
|
+
const band = (depth, f0, f1) => sectorBand(sector, -depth / 2, depth / 2, f0, f1);
|
|
1832
|
+
const f = Math.min(0.5, fw / (sector.r * Math.abs(sector.sweep)));
|
|
1833
|
+
node("window", o.id, i, [prism2(band(GLASS_MM * MM3), z0, z1)], extras, "glass");
|
|
1834
|
+
node(
|
|
1835
|
+
"window",
|
|
1836
|
+
o.id,
|
|
1837
|
+
i,
|
|
1838
|
+
[
|
|
1839
|
+
prism2(band(fd, 0, f), z0, z1),
|
|
1840
|
+
prism2(band(fd, 1 - f, 1), z0, z1),
|
|
1841
|
+
prism2(band(fd), z0, z0 + fw),
|
|
1842
|
+
prism2(band(fd), z1 - fw, z1)
|
|
1843
|
+
],
|
|
1844
|
+
extras,
|
|
1845
|
+
"frame"
|
|
1846
|
+
);
|
|
1847
|
+
return;
|
|
1848
|
+
}
|
|
1849
|
+
const fit = (p, a, b) => {
|
|
1850
|
+
const q = insideCut(p, o.cut);
|
|
1851
|
+
return q ? prism2(q, a, b) : null;
|
|
1852
|
+
};
|
|
1853
|
+
node("window", o.id, i, [fit(slab2d(j0, j1, GLASS_MM * MM3), z0, z1)], extras, "glass");
|
|
1854
|
+
node(
|
|
1855
|
+
"window",
|
|
1856
|
+
o.id,
|
|
1857
|
+
i,
|
|
1858
|
+
[
|
|
1859
|
+
fit(slab2d(j0, along(j0, j1, fw), fd), z0, z1),
|
|
1860
|
+
fit(slab2d(along(j1, j0, fw), j1, fd), z0, z1),
|
|
1861
|
+
fit(slab2d(j0, j1, fd), z0, z0 + fw),
|
|
1862
|
+
fit(slab2d(j0, j1, fd), z1 - fw, z1)
|
|
1863
|
+
],
|
|
1864
|
+
extras,
|
|
1865
|
+
"frame"
|
|
1866
|
+
);
|
|
1867
|
+
}
|
|
1868
|
+
});
|
|
1869
|
+
const floorTop = e + FLOOR_FINISH_MM * MM3;
|
|
1870
|
+
const tallest = lv.walls.reduce((m, w) => Math.max(m, w.height), 0) || lv.storeyHeight;
|
|
1871
|
+
const tallestBuilt = lv.walls.reduce((m, w) => Math.max(m, wallHeight.get(w.id) ?? w.height), 0) || lv.storeyHeight;
|
|
1872
|
+
lv.furniture.forEach((f, i) => {
|
|
1873
|
+
const parts = t0Shells(f, floorTop);
|
|
1874
|
+
const family = parts ? f.asset.slice("t0:".length) : void 0;
|
|
1875
|
+
const h = family ? T0_HEIGHT_MM[family] ?? 0 : FURNITURE_HEIGHT_MM[f.category] ?? FURNITURE_DEFAULT_MM;
|
|
1876
|
+
if (!defaulted.has(f.category)) {
|
|
1877
|
+
defaulted.add(f.category);
|
|
1878
|
+
ledger.push({
|
|
1879
|
+
kind: "furniture",
|
|
1880
|
+
field: `height_mm(${f.category})`,
|
|
1881
|
+
value: h,
|
|
1882
|
+
provenance: "default",
|
|
1883
|
+
rule: family ? "furniture-height-t0" : f.category in FURNITURE_HEIGHT_MM ? "furniture-height-family" : "furniture-height-greybox"
|
|
1884
|
+
});
|
|
1885
|
+
const mount = family ? T0_MOUNT_MM[family] : void 0;
|
|
1886
|
+
if (mount !== void 0) {
|
|
1887
|
+
ledger.push({
|
|
1888
|
+
kind: "furniture",
|
|
1889
|
+
field: `mount_mm(${f.category})`,
|
|
1890
|
+
value: mount,
|
|
1891
|
+
provenance: "default",
|
|
1892
|
+
rule: "furniture-mount-default"
|
|
1893
|
+
});
|
|
1894
|
+
}
|
|
1895
|
+
const slots = family ? T0_MATERIALS[family] : void 0;
|
|
1896
|
+
if (slots?.length) {
|
|
1897
|
+
ledger.push({
|
|
1898
|
+
kind: "furniture",
|
|
1899
|
+
field: `material(${f.category})`,
|
|
1900
|
+
value: [...slots],
|
|
1901
|
+
provenance: "default",
|
|
1902
|
+
rule: "furniture-material-default"
|
|
1903
|
+
});
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
const asset = parts ? f.asset : "greybox";
|
|
1907
|
+
if (f.asset !== asset) {
|
|
1908
|
+
ledger.push({
|
|
1909
|
+
kind: "furniture",
|
|
1910
|
+
id: f.id,
|
|
1911
|
+
field: "asset",
|
|
1912
|
+
value: "greybox",
|
|
1913
|
+
provenance: "default",
|
|
1914
|
+
rule: "furniture-t0-not-quarter-turn"
|
|
1915
|
+
});
|
|
1916
|
+
}
|
|
1917
|
+
if (parts && family && isHung(family)) {
|
|
1918
|
+
if (T0_HUNG_FROM_TOP.has(family)) {
|
|
1919
|
+
const low = Math.min(...parts.shells.flatMap((s) => s ? s.positions.filter((_, k) => k % 3 === 1) : []));
|
|
1920
|
+
ledger.push({
|
|
1921
|
+
kind: "furniture",
|
|
1922
|
+
id: f.id,
|
|
1923
|
+
field: "mount_mm",
|
|
1924
|
+
value: (low - floorTop) / MM3,
|
|
1925
|
+
provenance: "default",
|
|
1926
|
+
rule: "furniture-mount-from-top"
|
|
1927
|
+
});
|
|
1928
|
+
}
|
|
1929
|
+
if (floorTop + h * MM3 > e + tallestBuilt) {
|
|
1930
|
+
ledger.push({
|
|
1931
|
+
kind: "furniture",
|
|
1932
|
+
id: f.id,
|
|
1933
|
+
field: "top_mm",
|
|
1934
|
+
value: h,
|
|
1935
|
+
provenance: "default",
|
|
1936
|
+
rule: "furniture-hung-above-walls"
|
|
1937
|
+
});
|
|
1938
|
+
}
|
|
1939
|
+
} else if (parts && family && floorTop + h * MM3 > e + tallestBuilt) {
|
|
1940
|
+
ledger.push({
|
|
1941
|
+
kind: "furniture",
|
|
1942
|
+
id: f.id,
|
|
1943
|
+
field: "top_mm",
|
|
1944
|
+
value: h,
|
|
1945
|
+
provenance: "default",
|
|
1946
|
+
rule: "furniture-above-walls"
|
|
1947
|
+
});
|
|
1948
|
+
}
|
|
1949
|
+
const [cx, cy] = f.centre;
|
|
1950
|
+
const box = rect(cx - f.size.w / 2, cy - f.size.d / 2, cx + f.size.w / 2, cy + f.size.d / 2);
|
|
1951
|
+
if (parts) holesLeftOut += parts.holesDropped;
|
|
1952
|
+
const shells = parts ? parts.shells : [prism2(box, floorTop, floorTop + h * MM3)];
|
|
1953
|
+
node("furniture", f.id, i, shells, {
|
|
1954
|
+
category: f.category,
|
|
1955
|
+
yaw_deg: f.yawDeg,
|
|
1956
|
+
asset,
|
|
1957
|
+
...f.room ? { room: f.room } : {},
|
|
1958
|
+
...parts && f.mirror ? { mirror: true } : {}
|
|
1959
|
+
});
|
|
1960
|
+
});
|
|
1961
|
+
const roofZ = [e + tallest, e + tallest + ROOF_MM * MM3];
|
|
1962
|
+
lv.roofs.forEach((r, i) => {
|
|
1963
|
+
node("roof", r.id, i, [prism2({ outer: r.ring }, ...roofZ)], { form: r.form });
|
|
1964
|
+
});
|
|
1965
|
+
if (isTop && lv.roofs.length === 0 && lv.footprint.length > 0) {
|
|
1966
|
+
ledger.push({
|
|
1967
|
+
kind: "roof",
|
|
1968
|
+
id: `L${lv.level}`,
|
|
1969
|
+
field: "ring",
|
|
1970
|
+
value: "wall footprint",
|
|
1971
|
+
provenance: "default",
|
|
1972
|
+
rule: "roof-default-footprint"
|
|
1973
|
+
});
|
|
1974
|
+
node(
|
|
1975
|
+
"roof",
|
|
1976
|
+
"roof",
|
|
1977
|
+
0,
|
|
1978
|
+
lv.footprint.map((ring) => prism2({ outer: ring }, ...roofZ)),
|
|
1979
|
+
{ form: "flat" }
|
|
1980
|
+
);
|
|
1981
|
+
}
|
|
1982
|
+
const slabHere = slabRegion(lv.footprint, lv.floors, []).flatMap((r) => lessVoids(r.outer, lv.voids, "slab", []));
|
|
1983
|
+
const over = (p, q) => overlapArea(p, q) > FLOOR_OVERLAP_MIN_UM2;
|
|
1984
|
+
const steps = /* @__PURE__ */ new Map();
|
|
1985
|
+
lv.outdoor.forEach((o, i) => {
|
|
1986
|
+
const earlier = lv.outdoor.slice(0, i).filter((p) => over(p.polygon, o.polygon));
|
|
1987
|
+
const onSlab = slabHere.some((s) => over(s, o.polygon));
|
|
1988
|
+
const floorsUnder = lv.floors.filter((f) => over(f.polygon, o.polygon));
|
|
1989
|
+
const taken = /* @__PURE__ */ new Set([
|
|
1990
|
+
...onSlab ? [0] : [],
|
|
1991
|
+
...floorsUnder.flatMap((f) => [f.lift ?? 0, (f.lift ?? 0) + FLOOR_FINISH_MM * MM3]),
|
|
1992
|
+
...earlier.map((p) => (steps.get(p.id) ?? 0) * FLOOR_LIFT_UM)
|
|
1993
|
+
]);
|
|
1994
|
+
let step = Math.max(onSlab ? 1 : 0, ...earlier.map((p) => 1 + (steps.get(p.id) ?? 0)));
|
|
1995
|
+
while (taken.has(step * FLOOR_LIFT_UM)) step++;
|
|
1996
|
+
steps.set(o.id, step);
|
|
1997
|
+
const lift = step * FLOOR_LIFT_UM;
|
|
1998
|
+
if (lift > 0) {
|
|
1999
|
+
ledger.push({
|
|
2000
|
+
kind: "outdoor",
|
|
2001
|
+
id: o.id,
|
|
2002
|
+
field: "lift_mm",
|
|
2003
|
+
value: lift / MM3,
|
|
2004
|
+
provenance: "derived",
|
|
2005
|
+
rule: "outdoor-overlap-lift"
|
|
2006
|
+
});
|
|
2007
|
+
}
|
|
2008
|
+
if (!defaulted.has("outdoor:thickness")) {
|
|
2009
|
+
defaulted.add("outdoor:thickness");
|
|
2010
|
+
ledger.push({
|
|
2011
|
+
kind: "outdoor",
|
|
2012
|
+
field: "thickness_mm",
|
|
2013
|
+
value: OUTDOOR_MM,
|
|
2014
|
+
provenance: "default",
|
|
2015
|
+
rule: "outdoor-thickness-default"
|
|
2016
|
+
});
|
|
2017
|
+
ledger.push({
|
|
2018
|
+
kind: "outdoor",
|
|
2019
|
+
field: "wash",
|
|
2020
|
+
value: GROUND_WASH,
|
|
2021
|
+
provenance: "default",
|
|
2022
|
+
rule: "outdoor-colour-wash"
|
|
2023
|
+
});
|
|
2024
|
+
}
|
|
2025
|
+
const colour = outdoorColour(o.surface);
|
|
2026
|
+
if (!defaulted.has(`outdoor:${o.surface}`)) {
|
|
2027
|
+
defaulted.add(`outdoor:${o.surface}`);
|
|
2028
|
+
ledger.push({
|
|
2029
|
+
kind: "outdoor",
|
|
2030
|
+
field: `colour(${o.surface})`,
|
|
2031
|
+
value: colour.srgb,
|
|
2032
|
+
provenance: "default",
|
|
2033
|
+
rule: tintOf(o.surface) ? colour.rule : "outdoor-surface-unknown"
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
if (o.rail?.length) {
|
|
2037
|
+
ledger.push({
|
|
2038
|
+
kind: "outdoor",
|
|
2039
|
+
id: o.id,
|
|
2040
|
+
field: "rail",
|
|
2041
|
+
value: "omitted",
|
|
2042
|
+
provenance: "default",
|
|
2043
|
+
rule: "outdoor-rail-omitted"
|
|
2044
|
+
});
|
|
2045
|
+
}
|
|
2046
|
+
node("outdoor", o.id, i, [prism2(o.polygon, e - OUTDOOR_MM * MM3 + lift, e + lift)], {
|
|
2047
|
+
surface: o.surface,
|
|
2048
|
+
colour: colour.srgb,
|
|
2049
|
+
thickness_mm: OUTDOOR_MM,
|
|
2050
|
+
...lift > 0 ? { lift_mm: lift / MM3 } : {}
|
|
2051
|
+
});
|
|
2052
|
+
});
|
|
2053
|
+
lv.fences.forEach((f, i) => {
|
|
2054
|
+
const known = f.style in FENCE_PROFILES;
|
|
2055
|
+
const style = known ? f.style : "picket";
|
|
2056
|
+
const profile = FENCE_PROFILES[style];
|
|
2057
|
+
const height = FENCE_HEIGHT_MM[style];
|
|
2058
|
+
const pieces = fencePieces({ ...f, style }, profile, height);
|
|
2059
|
+
if (pieces.length === 0) {
|
|
2060
|
+
ledger.push({
|
|
2061
|
+
kind: "fence",
|
|
2062
|
+
id: f.id,
|
|
2063
|
+
field: "geometry",
|
|
2064
|
+
value: "omitted",
|
|
2065
|
+
provenance: "derived",
|
|
2066
|
+
rule: "fence-no-run"
|
|
2067
|
+
});
|
|
2068
|
+
return;
|
|
2069
|
+
}
|
|
2070
|
+
if (!defaulted.has(`fence:${f.style}`)) {
|
|
2071
|
+
defaulted.add(`fence:${f.style}`);
|
|
2072
|
+
ledger.push(
|
|
2073
|
+
{
|
|
2074
|
+
kind: "fence",
|
|
2075
|
+
field: `height_mm(${f.style})`,
|
|
2076
|
+
value: height,
|
|
2077
|
+
provenance: "default",
|
|
2078
|
+
rule: known ? "fence-height-default" : "fence-style-unknown"
|
|
2079
|
+
},
|
|
2080
|
+
{
|
|
2081
|
+
kind: "fence",
|
|
2082
|
+
field: `profile(${f.style})`,
|
|
2083
|
+
value: {
|
|
2084
|
+
post_mm: profile.post,
|
|
2085
|
+
// The core's own spacing: a post on every tick it draws (`fencePosts`).
|
|
2086
|
+
post_pitch_mm: CORE_POST_PITCH_MM[style],
|
|
2087
|
+
rails_mm: profile.rails.map((r) => [...r]),
|
|
2088
|
+
...profile.pickets ? { pickets_mm: [...profile.pickets] } : {}
|
|
2089
|
+
},
|
|
2090
|
+
provenance: "default",
|
|
2091
|
+
rule: "fence-profile-default"
|
|
2092
|
+
},
|
|
2093
|
+
{
|
|
2094
|
+
kind: "fence",
|
|
2095
|
+
field: `colour(${f.style})`,
|
|
2096
|
+
value: fenceColour(f.style),
|
|
2097
|
+
provenance: "default",
|
|
2098
|
+
rule: "fence-colour-default"
|
|
2099
|
+
}
|
|
2100
|
+
);
|
|
2101
|
+
}
|
|
2102
|
+
node(
|
|
2103
|
+
"fence",
|
|
2104
|
+
f.id,
|
|
2105
|
+
i,
|
|
2106
|
+
pieces.map((p) => prism2(p.poly, e + p.z[0] * MM3, e + p.z[1] * MM3)),
|
|
2107
|
+
{ style: f.style, colour: fenceColour(f.style), height_mm: height, closed: f.closed }
|
|
2108
|
+
);
|
|
2109
|
+
});
|
|
2110
|
+
return out;
|
|
2111
|
+
}
|
|
2112
|
+
function buildMesh(scene, opts = {}) {
|
|
2113
|
+
const doors = opts.doors ?? "closed";
|
|
2114
|
+
const asked = {
|
|
2115
|
+
kind: "door",
|
|
2116
|
+
field: "pose",
|
|
2117
|
+
value: "plan",
|
|
2118
|
+
provenance: "user-param",
|
|
2119
|
+
rule: "door-pose-plan"
|
|
2120
|
+
};
|
|
2121
|
+
const ledger = [
|
|
2122
|
+
...doors === "closed" ? scene.meta.assumptions : scene.meta.assumptions.map((a) => a.rule === "door-pose-closed" ? asked : a),
|
|
2123
|
+
{ kind: "slab", field: "thickness_mm", value: SLAB_MM, provenance: "default", rule: "slab-default-200" },
|
|
2124
|
+
{ kind: "floor", field: "finish_mm", value: FLOOR_FINISH_MM, provenance: "default", rule: "floor-finish-5" },
|
|
2125
|
+
{
|
|
2126
|
+
kind: "window",
|
|
2127
|
+
field: "frame_mm",
|
|
2128
|
+
value: [FRAME_WIDTH_MM, FRAME_DEPTH_MM],
|
|
2129
|
+
provenance: "default",
|
|
2130
|
+
rule: "window-frame-40x60"
|
|
2131
|
+
},
|
|
2132
|
+
{ kind: "door", field: "leaf_mm", value: LEAF_MM, provenance: "default", rule: "door-leaf-40" },
|
|
2133
|
+
{ kind: "roof", field: "thickness_mm", value: ROOF_MM, provenance: "default", rule: "roof-flat-150" },
|
|
2134
|
+
// Card RM8.3 builds outdoor surfaces and fences (it replaced the two `m1-omits-outdoor-fences`
|
|
2135
|
+
// rows here; their defaults are ledgered per kind and style where they are built). The ground
|
|
2136
|
+
// plane the viewer draws round the building is in no node, so it is said here, in every Mesh3D.
|
|
2137
|
+
{
|
|
2138
|
+
kind: "ground",
|
|
2139
|
+
field: "plane",
|
|
2140
|
+
value: {
|
|
2141
|
+
drawn: "viewer only",
|
|
2142
|
+
level: scene.levels[0]?.level ?? 0,
|
|
2143
|
+
margin_mm: GROUND_PLANE.marginMm,
|
|
2144
|
+
colour: GROUND_PLANE.light,
|
|
2145
|
+
colour_dark: GROUND_PLANE.dark
|
|
2146
|
+
},
|
|
2147
|
+
provenance: "default",
|
|
2148
|
+
rule: "ground-plane-viewer-only"
|
|
2149
|
+
}
|
|
2150
|
+
];
|
|
2151
|
+
const defaulted = /* @__PURE__ */ new Set();
|
|
2152
|
+
const top = scene.levels.length - 1;
|
|
2153
|
+
const nodes = scene.levels.flatMap(
|
|
2154
|
+
(lv, i) => levelNodes(lv, ledger, defaulted, i === top, doors, scene.levels[i - 1], scene.levels[i + 1])
|
|
2155
|
+
);
|
|
2156
|
+
nodes.sort(
|
|
2157
|
+
(a, b) => a.level - b.level || byText(a.kind, b.kind) || byText(a.id, b.id) || byText(a.part ?? "", b.part ?? "")
|
|
2158
|
+
);
|
|
2159
|
+
return { version: 0, kind: "mesh3d", name: scene.meta.name, assumptions: ledger, nodes };
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
export {
|
|
2163
|
+
MIN_CORE,
|
|
2164
|
+
adaptPlan,
|
|
2165
|
+
rectsOf,
|
|
2166
|
+
slabRegion,
|
|
2167
|
+
OPENING_DETAIL,
|
|
2168
|
+
insideOf,
|
|
2169
|
+
FLAT_MM,
|
|
2170
|
+
storeyTrim,
|
|
2171
|
+
stairRisers,
|
|
2172
|
+
stairSolid,
|
|
2173
|
+
STAIR_DETAIL,
|
|
2174
|
+
stairDetail,
|
|
2175
|
+
OUTDOOR_MM,
|
|
2176
|
+
FENCE_HEIGHT_MM,
|
|
2177
|
+
CORE_POST_PITCH_MM,
|
|
2178
|
+
CORE_POSTS_PER_RUN,
|
|
2179
|
+
FENCE_PROFILES,
|
|
2180
|
+
MAX_FENCE_REPEAT,
|
|
2181
|
+
groundColour,
|
|
2182
|
+
outdoorColour,
|
|
2183
|
+
fenceColour,
|
|
2184
|
+
corePostCount,
|
|
2185
|
+
fenceRuns,
|
|
2186
|
+
fencePosts,
|
|
2187
|
+
fencePieces,
|
|
2188
|
+
FURNITURE_HEIGHT_MM,
|
|
2189
|
+
DOOR_POSES,
|
|
2190
|
+
openLeaf,
|
|
2191
|
+
buildMesh
|
|
2192
|
+
};
|