@chanmeng666/archlang-3d 0.0.0-stage → 0.1.1
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 +46 -0
- package/LICENSE +22 -0
- package/README.md +84 -2
- package/THIRD_PARTY_NOTICES +975 -0
- package/dist/browser.d.ts +29 -0
- package/dist/browser.js +249 -0
- package/dist/chunk-4SDXG6GW.js +857 -0
- package/dist/chunk-54YVSAVZ.js +54 -0
- package/dist/chunk-CIC5LCVH.js +950 -0
- package/dist/chunk-CTFMM64C.js +435 -0
- package/dist/chunk-YCMINRJA.js +495 -0
- package/dist/cli.js +705 -0
- package/dist/facts-DMBpeo-q.d.ts +29 -0
- package/dist/index.d.ts +475 -0
- package/dist/index.js +130 -0
- package/dist/node.d.ts +130 -0
- package/dist/node.js +60 -0
- package/dist/replay.d.ts +62 -0
- package/dist/scene3d.schema.json +578 -0
- package/dist/strip-BMxWrvYD.d.ts +433 -0
- package/dist/viewer.iife.js +4220 -0
- package/package.json +82 -4
|
@@ -0,0 +1,950 @@
|
|
|
1
|
+
// src/mesh/t0.ts
|
|
2
|
+
var T0_FAMILIES = {
|
|
3
|
+
bed: ["bed"],
|
|
4
|
+
sofa: ["sofa", "couch"],
|
|
5
|
+
table: ["table", "dining_table"],
|
|
6
|
+
rug: ["rug", "carpet"],
|
|
7
|
+
wardrobe: ["wardrobe", "robe", "closet"],
|
|
8
|
+
fridge: ["fridge", "refrigerator"],
|
|
9
|
+
counter: ["counter", "worktop"],
|
|
10
|
+
kitchen_sink: ["kitchen_sink"],
|
|
11
|
+
stove: ["stove", "hob", "cooktop"],
|
|
12
|
+
shower: ["shower"],
|
|
13
|
+
wc: ["wc", "toilet"],
|
|
14
|
+
basin: ["basin", "lavatory"]
|
|
15
|
+
};
|
|
16
|
+
var FAMILY_OF = new Map(
|
|
17
|
+
Object.entries(T0_FAMILIES).flatMap(([f, names]) => names.map((n) => [n, f]))
|
|
18
|
+
);
|
|
19
|
+
var assetFor = (category) => {
|
|
20
|
+
const f = FAMILY_OF.get(category);
|
|
21
|
+
return f ? `t0:${f}` : "greybox";
|
|
22
|
+
};
|
|
23
|
+
var T0_HEIGHT_MM = {
|
|
24
|
+
bed: 1e3,
|
|
25
|
+
sofa: 800,
|
|
26
|
+
table: 750,
|
|
27
|
+
rug: 15,
|
|
28
|
+
wardrobe: 2100,
|
|
29
|
+
fridge: 1800,
|
|
30
|
+
counter: 900,
|
|
31
|
+
kitchen_sink: 900,
|
|
32
|
+
stove: 910,
|
|
33
|
+
shower: 60,
|
|
34
|
+
wc: 800,
|
|
35
|
+
basin: 850
|
|
36
|
+
};
|
|
37
|
+
var clamp = (x, lo, hi) => Math.max(lo, Math.min(hi, x));
|
|
38
|
+
var box = (x0, x1, z0, z1, y0, y1) => ({
|
|
39
|
+
x0,
|
|
40
|
+
x1,
|
|
41
|
+
z0,
|
|
42
|
+
z1,
|
|
43
|
+
y0,
|
|
44
|
+
y1
|
|
45
|
+
});
|
|
46
|
+
function cabinet(W, D, hole) {
|
|
47
|
+
const [hw, hd] = [W / 2, D / 2];
|
|
48
|
+
const top = 900;
|
|
49
|
+
return [
|
|
50
|
+
box(-hw, hw, -hd, hd - 60, 0, 100),
|
|
51
|
+
box(-hw, hw, -hd, hd - 20, 100, hole ? 700 : top - 30),
|
|
52
|
+
...hole ? [{ ...box(-hw, hw, -hd, hd, 700, top), holes: hole }] : [box(-hw, hw, -hd, hd, top - 30, top)]
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
var GENERATORS = {
|
|
56
|
+
bed(W, D) {
|
|
57
|
+
const [hw, hd] = [W / 2, D / 2];
|
|
58
|
+
const hb = clamp(D * 0.04, 20, 80);
|
|
59
|
+
const head = -hd + hb;
|
|
60
|
+
const n = W >= 1200 ? 2 : 1;
|
|
61
|
+
const gap = 60;
|
|
62
|
+
const pw = (W - 60 - (n + 1) * gap) / n;
|
|
63
|
+
const pd = clamp(D * 0.18, 100, 350);
|
|
64
|
+
return [
|
|
65
|
+
box(-hw, hw, -hd, head, 0, 1e3),
|
|
66
|
+
box(-hw, hw, head, hd, 0, 300),
|
|
67
|
+
box(-hw + 30, hw - 30, head, hd - 30, 300, 520),
|
|
68
|
+
...Array.from({ length: n }, (_, k) => {
|
|
69
|
+
const x0 = -hw + 30 + gap + k * (pw + gap);
|
|
70
|
+
return box(x0, x0 + pw, head + 60, head + 60 + pd, 520, 620);
|
|
71
|
+
})
|
|
72
|
+
];
|
|
73
|
+
},
|
|
74
|
+
sofa(W, D) {
|
|
75
|
+
const [hw, hd] = [W / 2, D / 2];
|
|
76
|
+
const arm = clamp(W * 0.08, 60, Math.min(250, W * 0.2));
|
|
77
|
+
const back = clamp(D * 0.22, 60, Math.min(250, D * 0.3));
|
|
78
|
+
return [
|
|
79
|
+
box(-hw, -hw + arm, -hd, hd, 0, 600),
|
|
80
|
+
box(hw - arm, hw, -hd, hd, 0, 600),
|
|
81
|
+
box(-hw + arm, hw - arm, -hd, -hd + back, 0, 800),
|
|
82
|
+
box(-hw + arm, hw - arm, -hd + back, hd, 0, 280),
|
|
83
|
+
box(-hw + arm + 10, hw - arm - 10, -hd + back, hd - 20, 280, 420)
|
|
84
|
+
];
|
|
85
|
+
},
|
|
86
|
+
table(W, D) {
|
|
87
|
+
const [hw, hd] = [W / 2, D / 2];
|
|
88
|
+
const leg = clamp(Math.min(W, D) * 0.06, 20, 60);
|
|
89
|
+
const ins = clamp(Math.min(W, D) * 0.04, 0, 40);
|
|
90
|
+
const legs = [-1, 1].flatMap(
|
|
91
|
+
(sx) => [-1, 1].map((sz) => {
|
|
92
|
+
const x = sx < 0 ? -hw + ins : hw - ins - leg;
|
|
93
|
+
const z = sz < 0 ? -hd + ins : hd - ins - leg;
|
|
94
|
+
return box(x, x + leg, z, z + leg, 0, 720);
|
|
95
|
+
})
|
|
96
|
+
);
|
|
97
|
+
return [box(-hw, hw, -hd, hd, 720, 750), ...legs];
|
|
98
|
+
},
|
|
99
|
+
rug: (W, D) => [box(-W / 2, W / 2, -D / 2, D / 2, 0, 15)],
|
|
100
|
+
wardrobe(W, D) {
|
|
101
|
+
const [hw, hd] = [W / 2, D / 2];
|
|
102
|
+
const n = Math.max(1, Math.round(W / 600));
|
|
103
|
+
const each = W / n;
|
|
104
|
+
const doors = Array.from(
|
|
105
|
+
{ length: n },
|
|
106
|
+
(_, k) => box(-hw + k * each + 2, -hw + (k + 1) * each - 2, hd - 20, hd, 20, 2080)
|
|
107
|
+
);
|
|
108
|
+
return [box(-hw, hw, -hd, hd - 20, 0, 2100), ...doors];
|
|
109
|
+
},
|
|
110
|
+
fridge(W, D) {
|
|
111
|
+
const [hw, hd] = [W / 2, D / 2];
|
|
112
|
+
return [
|
|
113
|
+
box(-hw, hw, -hd, hd - 30, 0, 1800),
|
|
114
|
+
box(-hw + 5, hw - 5, hd - 30, hd, 10, 1190),
|
|
115
|
+
box(-hw + 5, hw - 5, hd - 30, hd, 1210, 1790)
|
|
116
|
+
];
|
|
117
|
+
},
|
|
118
|
+
counter: (W, D) => cabinet(W, D),
|
|
119
|
+
kitchen_sink(W, D) {
|
|
120
|
+
const ix = W / 2 - clamp(W * 0.15, 40, 120);
|
|
121
|
+
const iz = D / 2 - clamp(D * 0.2, 40, 120);
|
|
122
|
+
return cabinet(W, D, [{ x0: -ix, x1: ix, z0: -iz, z1: iz }]);
|
|
123
|
+
},
|
|
124
|
+
stove(W, D) {
|
|
125
|
+
const r = Math.min(W, D) * 0.12;
|
|
126
|
+
const burners = [-1, 1].flatMap(
|
|
127
|
+
(sx) => [-1, 1].map((sz) => ({
|
|
128
|
+
...box(sx * W * 0.22 - r, sx * W * 0.22 + r, sz * D * 0.2 - r, sz * D * 0.2 + r, 900, 910),
|
|
129
|
+
round: true
|
|
130
|
+
}))
|
|
131
|
+
);
|
|
132
|
+
return [...cabinet(W, D), ...burners];
|
|
133
|
+
},
|
|
134
|
+
shower(W, D) {
|
|
135
|
+
const [hw, hd] = [W / 2, D / 2];
|
|
136
|
+
const rim = clamp(Math.min(W, D) * 0.06, 10, 50);
|
|
137
|
+
return [
|
|
138
|
+
box(-hw, hw, -hd, hd, 0, 30),
|
|
139
|
+
{ ...box(-hw, hw, -hd, hd, 30, 60), holes: [{ x0: -hw + rim, x1: hw - rim, z0: -hd + rim, z1: hd - rim }] }
|
|
140
|
+
];
|
|
141
|
+
},
|
|
142
|
+
wc(W, D) {
|
|
143
|
+
const [hw, hd] = [W / 2, D / 2];
|
|
144
|
+
const tank = clamp(D * 0.26, 40, 200);
|
|
145
|
+
return [
|
|
146
|
+
box(-hw, hw, -hd, -hd + tank, 380, 800),
|
|
147
|
+
{ ...box(-hw * 0.6, hw * 0.6, -hd + tank * 0.5, hd - D * 0.15, 0, 380), round: true },
|
|
148
|
+
{ ...box(-hw, hw, -hd + tank * 0.8, hd, 300, 400), round: true }
|
|
149
|
+
];
|
|
150
|
+
},
|
|
151
|
+
basin(W, D) {
|
|
152
|
+
const [hw, hd] = [W / 2, D / 2];
|
|
153
|
+
return [
|
|
154
|
+
box(-hw + 20, hw - 20, -hd, hd - 40, 0, 780),
|
|
155
|
+
{
|
|
156
|
+
...box(-hw, hw, -hd, hd, 780, 850),
|
|
157
|
+
holes: [{ x0: -hw * 0.6, x1: hw * 0.6, z0: -hd + D * 0.25, z1: hd - D * 0.15, round: true }]
|
|
158
|
+
}
|
|
159
|
+
];
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
var C16 = [
|
|
163
|
+
1,
|
|
164
|
+
0.9238795325112867,
|
|
165
|
+
Math.SQRT1_2,
|
|
166
|
+
0.3826834323650898,
|
|
167
|
+
0,
|
|
168
|
+
-0.3826834323650898,
|
|
169
|
+
-Math.SQRT1_2,
|
|
170
|
+
-0.9238795325112867,
|
|
171
|
+
-1,
|
|
172
|
+
-0.9238795325112867,
|
|
173
|
+
-Math.SQRT1_2,
|
|
174
|
+
-0.3826834323650898,
|
|
175
|
+
0,
|
|
176
|
+
0.3826834323650898,
|
|
177
|
+
Math.SQRT1_2,
|
|
178
|
+
0.9238795325112867
|
|
179
|
+
];
|
|
180
|
+
var S16 = C16.map((_, k) => C16[(k + 12) % 16]);
|
|
181
|
+
function outline(p) {
|
|
182
|
+
const um2 = (v) => Math.round(v * 1e3);
|
|
183
|
+
if (!p.round) {
|
|
184
|
+
return [
|
|
185
|
+
[um2(p.x0), um2(p.z0)],
|
|
186
|
+
[um2(p.x1), um2(p.z0)],
|
|
187
|
+
[um2(p.x1), um2(p.z1)],
|
|
188
|
+
[um2(p.x0), um2(p.z1)]
|
|
189
|
+
];
|
|
190
|
+
}
|
|
191
|
+
const [cx, cz, rx, rz] = [(p.x0 + p.x1) / 2, (p.z0 + p.z1) / 2, (p.x1 - p.x0) / 2, (p.z1 - p.z0) / 2];
|
|
192
|
+
return C16.map((c, k) => [um2(cx + rx * c), um2(cz + rz * S16[k])]);
|
|
193
|
+
}
|
|
194
|
+
function quarter(rotateDeg) {
|
|
195
|
+
const r = (rotateDeg % 360 + 360) % 360;
|
|
196
|
+
return r === 0 ? [1, 0] : r === 90 ? [0, 1] : r === 180 ? [-1, 0] : r === 270 ? [0, -1] : null;
|
|
197
|
+
}
|
|
198
|
+
function t0Parts(f) {
|
|
199
|
+
const family = f.asset.startsWith("t0:") ? f.asset.slice(3) : void 0;
|
|
200
|
+
const gen = family ? GENERATORS[family] : void 0;
|
|
201
|
+
const cs = quarter(-f.yawDeg);
|
|
202
|
+
if (!gen || !cs) return null;
|
|
203
|
+
const [c, s] = cs;
|
|
204
|
+
const turned = s !== 0;
|
|
205
|
+
const W = (turned ? f.size.d : f.size.w) / 1e3;
|
|
206
|
+
const D = (turned ? f.size.w : f.size.d) / 1e3;
|
|
207
|
+
const [cx, cy] = f.centre;
|
|
208
|
+
const place = (r) => r.map(([x, z]) => [cx + x * c - z * s, cy + x * s + z * c]);
|
|
209
|
+
return gen(W, D).map((p) => ({
|
|
210
|
+
polygon: {
|
|
211
|
+
outer: place(outline(p)),
|
|
212
|
+
...p.holes?.length ? { holes: p.holes.map((h) => place(outline(h))) } : {}
|
|
213
|
+
},
|
|
214
|
+
y0: Math.round(p.y0 * 1e3),
|
|
215
|
+
y1: Math.round(p.y1 * 1e3)
|
|
216
|
+
}));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// src/units.ts
|
|
220
|
+
function um(mm) {
|
|
221
|
+
const v = mm * 1e3;
|
|
222
|
+
const r = v < 0 ? -Math.round(-v) : Math.round(v);
|
|
223
|
+
return r === 0 ? 0 : r;
|
|
224
|
+
}
|
|
225
|
+
function umPoint(p) {
|
|
226
|
+
return [um(p.x), um(p.y)];
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// src/walls/ownership.ts
|
|
230
|
+
import * as core from "@chanmeng666/archlang";
|
|
231
|
+
import { joinWallSet, loopsToPolygons } from "@chanmeng666/archlang";
|
|
232
|
+
function signedArea(r) {
|
|
233
|
+
let s = 0;
|
|
234
|
+
for (let i = 0; i < r.length; i++) {
|
|
235
|
+
const a = r[i];
|
|
236
|
+
const b = r[(i + 1) % r.length];
|
|
237
|
+
s += a.x * b.y - b.x * a.y;
|
|
238
|
+
}
|
|
239
|
+
return s / 2;
|
|
240
|
+
}
|
|
241
|
+
function inRing(p, r) {
|
|
242
|
+
let c = false;
|
|
243
|
+
for (let i = 0, j = r.length - 1; i < r.length; j = i++) {
|
|
244
|
+
const a = r[i];
|
|
245
|
+
const b = r[j];
|
|
246
|
+
if (a.y > p.y !== b.y > p.y && p.x < (b.x - a.x) * (p.y - a.y) / (b.y - a.y) + a.x) c = !c;
|
|
247
|
+
}
|
|
248
|
+
return c;
|
|
249
|
+
}
|
|
250
|
+
function piecesOf(rings) {
|
|
251
|
+
if (rings.length === 0) return [];
|
|
252
|
+
const largest = rings.reduce((a, b) => Math.abs(signedArea(b)) > Math.abs(signedArea(a)) ? b : a);
|
|
253
|
+
const outerSign = Math.sign(signedArea(largest));
|
|
254
|
+
const outers = rings.filter((r) => Math.sign(signedArea(r)) === outerSign);
|
|
255
|
+
const holes = rings.filter((r) => Math.sign(signedArea(r)) !== outerSign);
|
|
256
|
+
return outers.map((outer) => ({ outer, holes: holes.filter((h) => inRing(h[0], outer)) }));
|
|
257
|
+
}
|
|
258
|
+
var pieceArea = (p) => Math.abs(signedArea(p.outer)) - p.holes.reduce((s, h) => s + Math.abs(signedArea(h)), 0);
|
|
259
|
+
function wallOwnership(walls, tessellate = loopsToPolygons) {
|
|
260
|
+
if (walls.length === 0) return { owned: [], fillArea: 0, cuts: [], outline: [] };
|
|
261
|
+
const groups = [...new Set(walls.map((w) => core.hatchKey(core.hatchOf(w))))];
|
|
262
|
+
const faces = walls.map((_, i) => String(i));
|
|
263
|
+
const solid = walls.map((w) => ({ ...w, openings: [] }));
|
|
264
|
+
const index = new Map(solid.map((w, i) => [w, i]));
|
|
265
|
+
const joined = joinWallSet(solid, groups, { faceOf: (w) => String(index.get(w)), faces });
|
|
266
|
+
const slotted = new Map(walls.map((w, i) => [w, i]));
|
|
267
|
+
const withCuts = joinWallSet(walls, groups, { faceOf: (w) => String(slotted.get(w)), faces });
|
|
268
|
+
const fillArea = (joined?.result.fills ?? []).reduce(
|
|
269
|
+
(s, f) => s + tessellate(f.loops).reduce((t, r) => t + signedArea(r), 0),
|
|
270
|
+
0
|
|
271
|
+
);
|
|
272
|
+
const byFace = (fills) => {
|
|
273
|
+
const m = /* @__PURE__ */ new Map();
|
|
274
|
+
for (const sf of fills) m.set(Number(sf.face), [...m.get(Number(sf.face)) ?? [], ...tessellate(sf.loops)]);
|
|
275
|
+
return m;
|
|
276
|
+
};
|
|
277
|
+
const rings = byFace(joined?.result.split?.fills ?? []);
|
|
278
|
+
const bodies = byFace(withCuts?.result.split?.fills ?? []);
|
|
279
|
+
const owned = walls.map((wall2, i) => {
|
|
280
|
+
const pieces = piecesOf(rings.get(i) ?? []);
|
|
281
|
+
return {
|
|
282
|
+
index: i,
|
|
283
|
+
wall: wall2,
|
|
284
|
+
pieces,
|
|
285
|
+
body: piecesOf(bodies.get(i) ?? []),
|
|
286
|
+
area: pieces.reduce((s, p) => s + pieceArea(p), 0)
|
|
287
|
+
};
|
|
288
|
+
});
|
|
289
|
+
const outlineRings = tessellate(joined?.result.outline ?? []);
|
|
290
|
+
const outline2 = piecesOf(outlineRings).map((p) => p.outer);
|
|
291
|
+
return { owned, fillArea: Math.abs(fillArea), cuts: withCuts?.cuts ?? [], outline: outline2 };
|
|
292
|
+
}
|
|
293
|
+
function segDist(p, a, b) {
|
|
294
|
+
const dx = b.x - a.x;
|
|
295
|
+
const dy = b.y - a.y;
|
|
296
|
+
const len2 = dx * dx + dy * dy;
|
|
297
|
+
const t = len2 === 0 ? 0 : Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / len2));
|
|
298
|
+
return Math.hypot(p.x - (a.x + t * dx), p.y - (a.y + t * dy));
|
|
299
|
+
}
|
|
300
|
+
var ringsOf = (p) => [p.outer, ...p.holes];
|
|
301
|
+
var TOUCH_TOL_MM = 0.02;
|
|
302
|
+
function piecesTouch(a, b, tol = TOUCH_TOL_MM) {
|
|
303
|
+
const near = (p, rs) => rs.some((r) => r.some((q, i) => segDist(p, q, r[(i + 1) % r.length]) <= tol));
|
|
304
|
+
return ringsOf(a).some((r) => r.some((p) => near(p, ringsOf(b)))) || ringsOf(b).some((r) => r.some((p) => near(p, ringsOf(a))));
|
|
305
|
+
}
|
|
306
|
+
var NOTCH_MIN_MM2 = 1;
|
|
307
|
+
function mixedHeightJoints(own) {
|
|
308
|
+
const out = [];
|
|
309
|
+
const { owned } = own;
|
|
310
|
+
const solo = /* @__PURE__ */ new Map();
|
|
311
|
+
const soloArea = (w) => {
|
|
312
|
+
const v = solo.get(w.index) ?? wallOwnership([w.wall]).owned[0]?.area ?? 0;
|
|
313
|
+
solo.set(w.index, v);
|
|
314
|
+
return v;
|
|
315
|
+
};
|
|
316
|
+
for (let i = 0; i < owned.length; i++) {
|
|
317
|
+
for (let j = i + 1; j < owned.length; j++) {
|
|
318
|
+
const a = owned[i];
|
|
319
|
+
const b = owned[j];
|
|
320
|
+
if (a.wall.height === b.wall.height) continue;
|
|
321
|
+
if (!a.pieces.some((p) => b.pieces.some((q) => piecesTouch(p, q)))) continue;
|
|
322
|
+
const [lower, taller] = a.wall.height < b.wall.height ? [a, b] : [b, a];
|
|
323
|
+
const pair = wallOwnership(a.index < b.index ? [a.wall, b.wall] : [b.wall, a.wall]);
|
|
324
|
+
const kept = pair.owned.find((o) => o.wall === taller.wall)?.area ?? 0;
|
|
325
|
+
const lost = soloArea(taller) - kept;
|
|
326
|
+
if (!(lost > NOTCH_MIN_MM2)) continue;
|
|
327
|
+
out.push({
|
|
328
|
+
code: "W3D_MIXED_HEIGHT_JOINT",
|
|
329
|
+
owner: { id: lower.wall.id, height: lower.wall.height },
|
|
330
|
+
notched: { id: taller.wall.id, height: taller.wall.height },
|
|
331
|
+
lostMm2: Math.round(lost),
|
|
332
|
+
message: `Wall ${lower.wall.id} (${lower.wall.height} mm high) owns ${Math.round(lost)} mm\xB2 of the taller wall ${taller.wall.id}'s footprint (${taller.wall.height} mm), so the taller wall is notched where they meet.`
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return out;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// src/scene3d/overlap.ts
|
|
340
|
+
import earcut from "earcut";
|
|
341
|
+
var FLOOR_OVERLAP_MIN_UM2 = 1e8;
|
|
342
|
+
var FLOOR_LIFT_UM = 500;
|
|
343
|
+
function triangles(p) {
|
|
344
|
+
const rings = [p.outer, ...p.holes ?? []];
|
|
345
|
+
const flat = [];
|
|
346
|
+
const holes = [];
|
|
347
|
+
rings.forEach((r, i) => {
|
|
348
|
+
if (i > 0) holes.push(flat.length / 2);
|
|
349
|
+
for (const q of r) flat.push(q[0], q[1]);
|
|
350
|
+
});
|
|
351
|
+
const ix = earcut(flat, holes, 2);
|
|
352
|
+
const pt2 = (i) => [flat[2 * i], flat[2 * i + 1]];
|
|
353
|
+
const out = [];
|
|
354
|
+
for (let t = 0; t < ix.length; t += 3)
|
|
355
|
+
out.push([pt2(ix[t]), pt2(ix[t + 1]), pt2(ix[t + 2])]);
|
|
356
|
+
return out;
|
|
357
|
+
}
|
|
358
|
+
var cross = (o, a, b) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);
|
|
359
|
+
var areaOf = (r) => {
|
|
360
|
+
let s = 0;
|
|
361
|
+
for (let i = 0; i < r.length; i++) s += cross([0, 0], r[i], r[(i + 1) % r.length]);
|
|
362
|
+
return Math.abs(s) / 2;
|
|
363
|
+
};
|
|
364
|
+
function triOverlap(a, b) {
|
|
365
|
+
const clip = cross(b[0], b[1], b[2]) > 0 ? b : [b[0], b[2], b[1]];
|
|
366
|
+
let poly = a.map((p) => [p[0], p[1]]);
|
|
367
|
+
for (let k = 0; k < 3 && poly.length > 0; k++) {
|
|
368
|
+
const e0 = clip[k];
|
|
369
|
+
const e1 = clip[(k + 1) % 3];
|
|
370
|
+
const input = poly;
|
|
371
|
+
poly = [];
|
|
372
|
+
for (let i = 0; i < input.length; i++) {
|
|
373
|
+
const p = input[i];
|
|
374
|
+
const q = input[(i + 1) % input.length];
|
|
375
|
+
const sp = cross(e0, e1, p);
|
|
376
|
+
const sq = cross(e0, e1, q);
|
|
377
|
+
if (sp >= 0) poly.push(p);
|
|
378
|
+
if (sp >= 0 !== sq >= 0) {
|
|
379
|
+
const t = sp / (sp - sq);
|
|
380
|
+
poly.push([
|
|
381
|
+
p[0] + (q[0] - p[0]) * t,
|
|
382
|
+
p[1] + (q[1] - p[1]) * t
|
|
383
|
+
]);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return poly.length >= 3 ? areaOf(poly) : 0;
|
|
388
|
+
}
|
|
389
|
+
var bboxOf = (ps) => [
|
|
390
|
+
Math.min(...ps.map((p) => p[0])),
|
|
391
|
+
Math.min(...ps.map((p) => p[1])),
|
|
392
|
+
Math.max(...ps.map((p) => p[0])),
|
|
393
|
+
Math.max(...ps.map((p) => p[1]))
|
|
394
|
+
];
|
|
395
|
+
var apart = (a, b) => a[2] <= b[0] || b[2] <= a[0] || a[3] <= b[1] || b[3] <= a[1];
|
|
396
|
+
function overlapArea(p, q) {
|
|
397
|
+
if (apart(bboxOf(p.outer), bboxOf(q.outer))) return 0;
|
|
398
|
+
const tq = triangles(q).map((t) => [t, bboxOf(t)]);
|
|
399
|
+
let s = 0;
|
|
400
|
+
for (const t of triangles(p)) {
|
|
401
|
+
const bt = bboxOf(t);
|
|
402
|
+
for (const [u, bu] of tq) if (!apart(bt, bu)) s += triOverlap(t, u);
|
|
403
|
+
}
|
|
404
|
+
return s;
|
|
405
|
+
}
|
|
406
|
+
function floorOverlaps(floors) {
|
|
407
|
+
const out = [];
|
|
408
|
+
for (let j = 1; j < floors.length; j++) {
|
|
409
|
+
for (let i = 0; i < j; i++) {
|
|
410
|
+
const [a, b] = [floors[i], floors[j]];
|
|
411
|
+
const area = overlapArea(a.polygon, b.polygon);
|
|
412
|
+
if (!(area > FLOOR_OVERLAP_MIN_UM2)) continue;
|
|
413
|
+
const mm2 = Math.round(area / 1e6);
|
|
414
|
+
out.push({
|
|
415
|
+
code: "W3D_FLOOR_OVERLAP",
|
|
416
|
+
rooms: [a.id, b.id],
|
|
417
|
+
areaMm2: mm2,
|
|
418
|
+
message: `Rooms ${a.id} and ${b.id} overlap by ${mm2} mm\xB2; ${b.id}'s floor is lifted 0.5 mm above ${a.id}'s so the two never draw in the same plane.`
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
return out;
|
|
423
|
+
}
|
|
424
|
+
function floorLifts(floors, overlaps) {
|
|
425
|
+
const steps = /* @__PURE__ */ new Map();
|
|
426
|
+
for (const f of floors) {
|
|
427
|
+
const below = overlaps.filter((o) => o.rooms[1] === f.id).map((o) => steps.get(o.rooms[0]) ?? 0);
|
|
428
|
+
steps.set(f.id, below.length > 0 ? 1 + Math.max(...below) : 0);
|
|
429
|
+
}
|
|
430
|
+
return new Map([...steps].filter(([, s]) => s > 0).map(([id2, s]) => [id2, s * FLOOR_LIFT_UM]));
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// package.json
|
|
434
|
+
var version = "0.1.1";
|
|
435
|
+
|
|
436
|
+
// src/scene3d/build.ts
|
|
437
|
+
import {
|
|
438
|
+
doorLeaves,
|
|
439
|
+
doorSwing
|
|
440
|
+
} from "@chanmeng666/archlang";
|
|
441
|
+
|
|
442
|
+
// src/curves.ts
|
|
443
|
+
var DEFAULT_CURVE_TOL_MM = 2;
|
|
444
|
+
var MIN_CHORDS = 4;
|
|
445
|
+
var MAX_CHORDS = 720;
|
|
446
|
+
function chordCount(r, sweep, tol) {
|
|
447
|
+
const step = tol >= r ? Math.PI / 2 : 2 * Math.acos(1 - tol / r);
|
|
448
|
+
return Math.min(MAX_CHORDS, Math.max(MIN_CHORDS, Math.ceil(Math.abs(sweep) / step)));
|
|
449
|
+
}
|
|
450
|
+
function arcPoints(arc, tol) {
|
|
451
|
+
const n = chordCount(arc.r, arc.sweep, tol);
|
|
452
|
+
const out = [arc.a];
|
|
453
|
+
for (let i = 1; i < n; i++) {
|
|
454
|
+
const t = arc.start + arc.sweep * i / n;
|
|
455
|
+
out.push({ x: arc.center.x + arc.r * Math.cos(t), y: arc.center.y + arc.r * Math.sin(t) });
|
|
456
|
+
}
|
|
457
|
+
return out;
|
|
458
|
+
}
|
|
459
|
+
function tessellateLoops(loops, tol = DEFAULT_CURVE_TOL_MM) {
|
|
460
|
+
return loops.map((loop) => loop.flatMap((e) => e.t === "line" ? [e.a] : arcPoints(e.arc, tol)));
|
|
461
|
+
}
|
|
462
|
+
function circleRing(c, r, tol = DEFAULT_CURVE_TOL_MM) {
|
|
463
|
+
const n = chordCount(r, 2 * Math.PI, tol);
|
|
464
|
+
return Array.from({ length: n }, (_, i) => {
|
|
465
|
+
const t = 2 * Math.PI * i / n;
|
|
466
|
+
return { x: c.x + r * Math.cos(t), y: c.y + r * Math.sin(t) };
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// src/scene3d/build.ts
|
|
471
|
+
var ARCHLANG_3D_VERSION = version;
|
|
472
|
+
var ring = (r) => r.map(umPoint);
|
|
473
|
+
var source = (e) => e.span ? { kind: e.kind, id: e.id, span: [e.span.start, e.span.end] } : { kind: e.kind, id: e.id };
|
|
474
|
+
var rectRing = (at, size) => [
|
|
475
|
+
{ x: at.x, y: at.y },
|
|
476
|
+
{ x: at.x + size.w, y: at.y },
|
|
477
|
+
{ x: at.x + size.w, y: at.y + size.h },
|
|
478
|
+
{ x: at.x, y: at.y + size.h }
|
|
479
|
+
];
|
|
480
|
+
var polygon = (outer, holes = []) => holes.length > 0 ? { outer: ring(outer), holes: holes.map(ring) } : { outer: ring(outer) };
|
|
481
|
+
var box2 = (e) => ({
|
|
482
|
+
id: e.id,
|
|
483
|
+
source: source(e),
|
|
484
|
+
at: umPoint(e.at),
|
|
485
|
+
size: { w: um(e.size.w), h: um(e.size.h) }
|
|
486
|
+
});
|
|
487
|
+
function floorOf(r, tol) {
|
|
488
|
+
const outer = r.circle ? circleRing(r.circle.c, r.circle.r, tol) : r.poly ?? rectRing(r.at, r.size);
|
|
489
|
+
return { id: r.id, source: source(r), polygon: polygon(outer), ...r.uses?.length ? { uses: [...r.uses] } : {} };
|
|
490
|
+
}
|
|
491
|
+
function furnitureOf(f) {
|
|
492
|
+
const rotate = f.rotate ?? 0;
|
|
493
|
+
return {
|
|
494
|
+
id: f.id,
|
|
495
|
+
source: source(f),
|
|
496
|
+
category: f.category,
|
|
497
|
+
...f.room ? { room: f.room } : {},
|
|
498
|
+
centre: umPoint({ x: f.at.x + f.size.w / 2, y: f.at.y + f.size.h / 2 }),
|
|
499
|
+
size: { w: um(f.size.w), d: um(f.size.h) },
|
|
500
|
+
yawDeg: rotate === 0 ? 0 : -rotate,
|
|
501
|
+
asset: assetFor(f.category)
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
function outdoorOf(o) {
|
|
505
|
+
return {
|
|
506
|
+
id: o.id,
|
|
507
|
+
source: source(o),
|
|
508
|
+
surface: o.surface,
|
|
509
|
+
polygon: polygon(o.poly ?? rectRing(o.at, o.size)),
|
|
510
|
+
...o.rail?.length ? { rail: [...o.rail] } : {}
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
var fenceOf = (f) => ({
|
|
514
|
+
id: f.id,
|
|
515
|
+
source: source(f),
|
|
516
|
+
style: f.style,
|
|
517
|
+
points: f.points.map(umPoint),
|
|
518
|
+
closed: f.closed
|
|
519
|
+
});
|
|
520
|
+
var stairOf = (s) => ({
|
|
521
|
+
id: s.id,
|
|
522
|
+
source: source(s),
|
|
523
|
+
box: box2(s),
|
|
524
|
+
dir: s.dir,
|
|
525
|
+
width: um(s.width)
|
|
526
|
+
});
|
|
527
|
+
function wallsAndOpenings(ir, byId, tol) {
|
|
528
|
+
const own = wallOwnership(ir.walls, (loops) => tessellateLoops(loops, tol));
|
|
529
|
+
const cutsOf = /* @__PURE__ */ new Map();
|
|
530
|
+
const openings = [];
|
|
531
|
+
for (const cut of own.cuts) {
|
|
532
|
+
const host = ir.walls[cut.wall];
|
|
533
|
+
const op = cut.opening;
|
|
534
|
+
const id2 = op.ownerId;
|
|
535
|
+
if (!host || !id2) continue;
|
|
536
|
+
const el = byId.get(id2);
|
|
537
|
+
const kind = op.kind ?? (el?.kind === "door" || el?.kind === "window" || el?.kind === "opening" ? el.kind : "opening");
|
|
538
|
+
const outer = tessellateLoops([cut.loop], tol)[0] ?? [];
|
|
539
|
+
const sill = op.sill;
|
|
540
|
+
const head = op.head ?? (el && "head" in el ? el.head : void 0);
|
|
541
|
+
if (sill === void 0 || head === void 0) continue;
|
|
542
|
+
const door = el?.kind === "door" ? el : void 0;
|
|
543
|
+
const hosted = el;
|
|
544
|
+
const jambs = jambsOf(op.at, op.width, hosted?.host ?? null);
|
|
545
|
+
const leaves = door ? doorLeaves(door).map((l) => [umPoint(l.hinge), umPoint(l.farJamb), umPoint(l.leafEnd)]) : [];
|
|
546
|
+
openings.push({
|
|
547
|
+
id: id2,
|
|
548
|
+
source: el ? source(el) : { kind, id: id2 },
|
|
549
|
+
kind,
|
|
550
|
+
...door?.doorKind ? { doorKind: door.doorKind } : door ? { doorKind: "hinged" } : {},
|
|
551
|
+
host: host.id,
|
|
552
|
+
cut: ring(outer),
|
|
553
|
+
centre: umPoint(op.at),
|
|
554
|
+
jambs,
|
|
555
|
+
...leaves.length > 0 ? { leaves } : {},
|
|
556
|
+
width: um(op.width),
|
|
557
|
+
sill: um(sill),
|
|
558
|
+
head: um(head),
|
|
559
|
+
...door ? { hinge: door.hinge, swing: door.swing } : {},
|
|
560
|
+
...door?.slide ? { slide: door.slide } : {}
|
|
561
|
+
});
|
|
562
|
+
cutsOf.set(cut.wall, [...cutsOf.get(cut.wall) ?? [], id2]);
|
|
563
|
+
}
|
|
564
|
+
const walls = own.owned.map((o) => ({
|
|
565
|
+
id: o.wall.id,
|
|
566
|
+
source: source(o.wall),
|
|
567
|
+
category: o.wall.category,
|
|
568
|
+
material: o.wall.material,
|
|
569
|
+
footprint: o.pieces.map((p) => polygon(p.outer, p.holes)),
|
|
570
|
+
body: o.body.map((p) => polygon(p.outer, p.holes)),
|
|
571
|
+
height: um(o.wall.height),
|
|
572
|
+
thickness: um(o.wall.thickness),
|
|
573
|
+
cuts: cutsOf.get(o.index) ?? []
|
|
574
|
+
}));
|
|
575
|
+
return { walls, openings, footprint: own.outline.map(ring) };
|
|
576
|
+
}
|
|
577
|
+
function demolishedOf(ir, standing, ledger, tol) {
|
|
578
|
+
const gone = (ir.drawn?.walls ?? []).filter((w) => w.status === "demolish");
|
|
579
|
+
if (gone.length === 0) return [];
|
|
580
|
+
const own = wallOwnership([...ir.walls, ...gone], (loops) => tessellateLoops(loops, tol));
|
|
581
|
+
return own.owned.slice(ir.walls.length).flatMap((o) => {
|
|
582
|
+
const pieces = o.pieces.map((p) => polygon(p.outer, p.holes));
|
|
583
|
+
if (pieces.length === 0) return [];
|
|
584
|
+
const overlap = pieces.reduce(
|
|
585
|
+
(s, p) => s + standing.reduce((t, w) => t + w.footprint.reduce((u, q) => u + overlapArea(p, q), 0), 0),
|
|
586
|
+
0
|
|
587
|
+
);
|
|
588
|
+
if (overlap > FLOOR_OVERLAP_MIN_UM2) {
|
|
589
|
+
ledger.push({
|
|
590
|
+
kind: "wall",
|
|
591
|
+
id: o.wall.id,
|
|
592
|
+
field: "status",
|
|
593
|
+
value: `ghost overlaps a thinner standing wall by ${Math.round(overlap / 1e6)} mm\xB2`,
|
|
594
|
+
provenance: "default",
|
|
595
|
+
rule: "wall-demolish-overlap"
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
return [
|
|
599
|
+
{
|
|
600
|
+
id: o.wall.id,
|
|
601
|
+
source: source(o.wall),
|
|
602
|
+
category: o.wall.category,
|
|
603
|
+
material: o.wall.material,
|
|
604
|
+
footprint: pieces,
|
|
605
|
+
body: pieces,
|
|
606
|
+
height: um(o.wall.height),
|
|
607
|
+
thickness: um(o.wall.thickness),
|
|
608
|
+
cuts: []
|
|
609
|
+
}
|
|
610
|
+
];
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
function jambsOf(at, width, host) {
|
|
614
|
+
const s = host ? doorSwing({ at, width, hinge: "left", swing: "in", host }) : null;
|
|
615
|
+
return s ? [umPoint(s.hinge), umPoint(s.farJamb)] : [umPoint(at), umPoint(at)];
|
|
616
|
+
}
|
|
617
|
+
function levelOf(s, ledger, tol) {
|
|
618
|
+
const { ir } = s;
|
|
619
|
+
const els = ir.elements;
|
|
620
|
+
const byId = new Map(els.map((e) => [e.id, e]));
|
|
621
|
+
const of = (k) => els.filter((e) => e.kind === k);
|
|
622
|
+
const { walls, openings, footprint } = wallsAndOpenings(ir, byId, tol);
|
|
623
|
+
const demolished = demolishedOf(ir, walls, ledger, tol);
|
|
624
|
+
for (const w of demolished) {
|
|
625
|
+
ledger.push({
|
|
626
|
+
kind: "wall",
|
|
627
|
+
id: w.id,
|
|
628
|
+
field: "status",
|
|
629
|
+
value: "demolish",
|
|
630
|
+
provenance: "authored",
|
|
631
|
+
rule: "wall-demolish-ghost"
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
const rooms = of("room").map((r) => floorOf(r, tol));
|
|
635
|
+
const lifts = floorLifts(rooms, floorOverlaps(rooms));
|
|
636
|
+
const floors = rooms.map((f) => {
|
|
637
|
+
const lift = lifts.get(f.id);
|
|
638
|
+
if (lift === void 0) return f;
|
|
639
|
+
ledger.push({
|
|
640
|
+
kind: "floor",
|
|
641
|
+
id: f.id,
|
|
642
|
+
field: "lift_mm",
|
|
643
|
+
value: lift / 1e3,
|
|
644
|
+
provenance: "derived",
|
|
645
|
+
rule: "floor-overlap-lift"
|
|
646
|
+
});
|
|
647
|
+
return { ...f, lift };
|
|
648
|
+
});
|
|
649
|
+
const roofs = of("roof").map((r) => ({
|
|
650
|
+
id: r.id,
|
|
651
|
+
source: source(r),
|
|
652
|
+
form: "flat",
|
|
653
|
+
ring: ring(r.ring),
|
|
654
|
+
provenance: "default"
|
|
655
|
+
}));
|
|
656
|
+
for (const r of roofs) {
|
|
657
|
+
ledger.push({
|
|
658
|
+
kind: "roof",
|
|
659
|
+
id: r.id,
|
|
660
|
+
field: "form",
|
|
661
|
+
value: "flat",
|
|
662
|
+
provenance: "default",
|
|
663
|
+
rule: "roof-default-flat"
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
for (const k of ["elevator", "escalator"]) {
|
|
667
|
+
for (const e of of(k)) {
|
|
668
|
+
ledger.push({
|
|
669
|
+
kind: k,
|
|
670
|
+
id: e.id,
|
|
671
|
+
field: "geometry",
|
|
672
|
+
value: "omitted",
|
|
673
|
+
provenance: "default",
|
|
674
|
+
rule: "v0-omits-vertical-transport"
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
return {
|
|
679
|
+
level: s.level,
|
|
680
|
+
...s.name ? { name: s.name } : {},
|
|
681
|
+
elevation: um(ir.elevation),
|
|
682
|
+
storeyHeight: um(ir.storeyHeight),
|
|
683
|
+
footprint,
|
|
684
|
+
floors,
|
|
685
|
+
walls,
|
|
686
|
+
...demolished.length > 0 ? { demolished } : {},
|
|
687
|
+
openings,
|
|
688
|
+
furniture: of("furniture").map(furnitureOf),
|
|
689
|
+
stairs: of("stair").map(stairOf),
|
|
690
|
+
voids: of("void").map(box2),
|
|
691
|
+
columns: of("column").map(box2),
|
|
692
|
+
outdoor: of("outdoor").map(outdoorOf),
|
|
693
|
+
fences: of("fence").map(fenceOf),
|
|
694
|
+
roofs
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
function buildScene3D(storeys, opts) {
|
|
698
|
+
const first = storeys[0];
|
|
699
|
+
if (!first) throw new Error("buildScene3D needs at least one storey");
|
|
700
|
+
const tol = opts.curveTolMm ?? DEFAULT_CURVE_TOL_MM;
|
|
701
|
+
const ledger = [
|
|
702
|
+
{ kind: "door", field: "pose", value: "closed", provenance: "default", rule: "door-pose-closed" },
|
|
703
|
+
{
|
|
704
|
+
kind: "curve",
|
|
705
|
+
field: "tolerance_mm",
|
|
706
|
+
value: tol,
|
|
707
|
+
provenance: opts.curveTolMm === void 0 ? "default" : "user-param",
|
|
708
|
+
rule: "curve-tol"
|
|
709
|
+
}
|
|
710
|
+
];
|
|
711
|
+
const levels = storeys.map((s) => levelOf(s, ledger, tol));
|
|
712
|
+
return {
|
|
713
|
+
version: 0,
|
|
714
|
+
kind: "scene3d",
|
|
715
|
+
meta: {
|
|
716
|
+
name: first.ir.name,
|
|
717
|
+
units: "mm",
|
|
718
|
+
tool: { archlang3d: ARCHLANG_3D_VERSION, archlang: opts.coreVersion },
|
|
719
|
+
north: typeof first.ir.north === "object" ? first.ir.north.deg : first.ir.north,
|
|
720
|
+
...first.ir.siteBoundary ? { siteBoundary: ring(first.ir.siteBoundary) } : {},
|
|
721
|
+
params: { curveTolMm: tol },
|
|
722
|
+
assumptions: ledger
|
|
723
|
+
},
|
|
724
|
+
levels
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
// src/scene3d/validate.ts
|
|
729
|
+
var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
730
|
+
var fail = (out, path, message) => {
|
|
731
|
+
out.push({ path, message });
|
|
732
|
+
};
|
|
733
|
+
var integer = (v, p, out) => {
|
|
734
|
+
if (!Number.isInteger(v)) fail(out, p, "must be an integer (micrometres)");
|
|
735
|
+
};
|
|
736
|
+
var number = (v, p, out) => {
|
|
737
|
+
if (typeof v !== "number" || !Number.isFinite(v)) fail(out, p, "must be a finite number");
|
|
738
|
+
};
|
|
739
|
+
var string = (v, p, out) => {
|
|
740
|
+
if (typeof v !== "string") fail(out, p, "must be a string");
|
|
741
|
+
};
|
|
742
|
+
var id = (v, p, out) => {
|
|
743
|
+
if (typeof v !== "string" || v.length === 0) fail(out, p, "must be a non-empty string");
|
|
744
|
+
};
|
|
745
|
+
var boolean = (v, p, out) => {
|
|
746
|
+
if (typeof v !== "boolean") fail(out, p, "must be a boolean");
|
|
747
|
+
};
|
|
748
|
+
var any = () => {
|
|
749
|
+
};
|
|
750
|
+
var record = (v, p, out) => {
|
|
751
|
+
if (!isObj(v)) fail(out, p, "must be an object");
|
|
752
|
+
};
|
|
753
|
+
var oneOf = (...values) => (v, p, out) => {
|
|
754
|
+
if (!values.includes(v)) fail(out, p, `must be one of ${values.map((x) => JSON.stringify(x)).join(", ")}`);
|
|
755
|
+
};
|
|
756
|
+
var either = (...checks) => (v, p, out) => {
|
|
757
|
+
const ok = checks.some((c) => {
|
|
758
|
+
const tmp = [];
|
|
759
|
+
c(v, p, tmp);
|
|
760
|
+
return tmp.length === 0;
|
|
761
|
+
});
|
|
762
|
+
if (!ok) fail(out, p, "matches none of the allowed forms");
|
|
763
|
+
};
|
|
764
|
+
var array = (item, min = 0, max = Number.POSITIVE_INFINITY) => (v, p, out) => {
|
|
765
|
+
if (!Array.isArray(v)) return fail(out, p, "must be an array");
|
|
766
|
+
if (v.length < min) fail(out, p, `must have at least ${min} items`);
|
|
767
|
+
if (v.length > max) fail(out, p, `must have at most ${max} items`);
|
|
768
|
+
v.forEach((x, i) => {
|
|
769
|
+
item(x, `${p}/${i}`, out);
|
|
770
|
+
});
|
|
771
|
+
};
|
|
772
|
+
var object = (required, optional = {}) => (v, p, out) => {
|
|
773
|
+
if (!isObj(v)) return fail(out, p, "must be an object");
|
|
774
|
+
for (const [k, c] of Object.entries(required)) {
|
|
775
|
+
if (!(k in v)) fail(out, `${p}/${k}`, "is required");
|
|
776
|
+
else c(v[k], `${p}/${k}`, out);
|
|
777
|
+
}
|
|
778
|
+
for (const [k, c] of Object.entries(optional)) if (k in v) c(v[k], `${p}/${k}`, out);
|
|
779
|
+
for (const k of Object.keys(v)) {
|
|
780
|
+
if (!(k in required) && !(k in optional)) fail(out, `${p}/${k}`, "is not a Scene3D field");
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
var pt = array(integer, 2, 2);
|
|
784
|
+
var ring2 = array(pt, 3);
|
|
785
|
+
var polygon2 = object({ outer: ring2 }, { holes: array(ring2) });
|
|
786
|
+
var provenance = oneOf("authored", "derived", "default", "user-param");
|
|
787
|
+
var source2 = object({ kind: string, id: string }, { span: array(integer, 2, 2) });
|
|
788
|
+
var sized = (a, b) => object({ [a]: integer, [b]: integer });
|
|
789
|
+
var box3 = object({ id, source: source2, at: pt, size: sized("w", "h") });
|
|
790
|
+
var wall = object(
|
|
791
|
+
{
|
|
792
|
+
id,
|
|
793
|
+
source: source2,
|
|
794
|
+
footprint: array(polygon2),
|
|
795
|
+
body: array(polygon2),
|
|
796
|
+
height: integer,
|
|
797
|
+
thickness: integer,
|
|
798
|
+
cuts: array(string)
|
|
799
|
+
},
|
|
800
|
+
{ category: string, material: string }
|
|
801
|
+
);
|
|
802
|
+
var LEVEL_COLLECTIONS = {
|
|
803
|
+
floors: array(object({ id, source: source2, polygon: polygon2 }, { uses: array(string), lift: integer })),
|
|
804
|
+
walls: array(wall),
|
|
805
|
+
openings: array(
|
|
806
|
+
object(
|
|
807
|
+
{
|
|
808
|
+
id,
|
|
809
|
+
source: source2,
|
|
810
|
+
kind: oneOf("door", "window", "opening"),
|
|
811
|
+
host: string,
|
|
812
|
+
cut: ring2,
|
|
813
|
+
centre: pt,
|
|
814
|
+
jambs: array(pt, 2, 2),
|
|
815
|
+
width: integer,
|
|
816
|
+
sill: integer,
|
|
817
|
+
head: integer
|
|
818
|
+
},
|
|
819
|
+
{
|
|
820
|
+
doorKind: oneOf("hinged", "sliding", "barn", "bifold", "pocket", "garage", "double"),
|
|
821
|
+
leaves: array(array(pt, 2, 3)),
|
|
822
|
+
hinge: oneOf("left", "right"),
|
|
823
|
+
swing: oneOf("in", "out"),
|
|
824
|
+
slide: oneOf("left", "right")
|
|
825
|
+
}
|
|
826
|
+
)
|
|
827
|
+
),
|
|
828
|
+
furniture: array(
|
|
829
|
+
object(
|
|
830
|
+
{ id, source: source2, category: string, centre: pt, size: sized("w", "d"), yawDeg: integer, asset: string },
|
|
831
|
+
{ room: string }
|
|
832
|
+
)
|
|
833
|
+
),
|
|
834
|
+
stairs: array(object({ id, source: source2, box: box3, dir: oneOf("up", "down"), width: integer })),
|
|
835
|
+
voids: array(box3),
|
|
836
|
+
columns: array(box3),
|
|
837
|
+
outdoor: array(object({ id, source: source2, surface: string, polygon: polygon2 }, { rail: array(string) })),
|
|
838
|
+
fences: array(object({ id, source: source2, style: string, points: array(pt, 2), closed: boolean })),
|
|
839
|
+
roofs: array(object({ id, source: source2, form: oneOf("flat"), ring: ring2, provenance }))
|
|
840
|
+
};
|
|
841
|
+
var level = object(
|
|
842
|
+
{ level: integer, elevation: integer, storeyHeight: integer, footprint: array(ring2), ...LEVEL_COLLECTIONS },
|
|
843
|
+
{ name: string, demolished: array(wall) }
|
|
844
|
+
);
|
|
845
|
+
var scene = object({
|
|
846
|
+
version: oneOf(0),
|
|
847
|
+
kind: oneOf("scene3d"),
|
|
848
|
+
meta: object(
|
|
849
|
+
{
|
|
850
|
+
name: string,
|
|
851
|
+
units: oneOf("mm"),
|
|
852
|
+
tool: object({ archlang3d: string, archlang: string }),
|
|
853
|
+
assumptions: array(object({ kind: string, field: string, value: any, provenance, rule: string }, { id: string }))
|
|
854
|
+
},
|
|
855
|
+
{ north: either(oneOf("up", "down", "left", "right"), number), siteBoundary: ring2, params: record }
|
|
856
|
+
),
|
|
857
|
+
levels: array(level, 1)
|
|
858
|
+
});
|
|
859
|
+
function references(v, out) {
|
|
860
|
+
const levels = Array.isArray(v.levels) ? v.levels : [];
|
|
861
|
+
levels.forEach((lv, li) => {
|
|
862
|
+
if (!isObj(lv)) return;
|
|
863
|
+
const ids = (k) => (Array.isArray(lv[k]) ? lv[k] : []).map((e) => isObj(e) ? String(e.id) : "");
|
|
864
|
+
for (const k of [...Object.keys(LEVEL_COLLECTIONS), "demolished"]) {
|
|
865
|
+
const seen = /* @__PURE__ */ new Set();
|
|
866
|
+
ids(k).forEach((x, i) => {
|
|
867
|
+
if (seen.has(x)) fail(out, `/levels/${li}/${k}/${i}/id`, `duplicates id "${x}" in ${k}`);
|
|
868
|
+
seen.add(x);
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
const walls = new Set(ids("walls"));
|
|
872
|
+
for (const [i, x] of ids("demolished").entries()) {
|
|
873
|
+
if (walls.has(x)) fail(out, `/levels/${li}/demolished/${i}/id`, `names a standing wall too ("${x}")`);
|
|
874
|
+
}
|
|
875
|
+
const openings = new Set(ids("openings"));
|
|
876
|
+
(Array.isArray(lv.openings) ? lv.openings : []).forEach((o, i) => {
|
|
877
|
+
if (isObj(o) && !walls.has(String(o.host))) {
|
|
878
|
+
fail(out, `/levels/${li}/openings/${i}/host`, `names no wall of this level ("${String(o.host)}")`);
|
|
879
|
+
}
|
|
880
|
+
});
|
|
881
|
+
(Array.isArray(lv.demolished) ? lv.demolished : []).forEach((w, i) => {
|
|
882
|
+
if (isObj(w) && Array.isArray(w.cuts) && w.cuts.length > 0)
|
|
883
|
+
fail(out, `/levels/${li}/demolished/${i}/cuts`, "a demolished wall hosts nothing");
|
|
884
|
+
});
|
|
885
|
+
(Array.isArray(lv.walls) ? lv.walls : []).forEach((w, i) => {
|
|
886
|
+
if (!isObj(w) || !Array.isArray(w.cuts)) return;
|
|
887
|
+
w.cuts.forEach((c, j) => {
|
|
888
|
+
if (!openings.has(String(c)))
|
|
889
|
+
fail(out, `/levels/${li}/walls/${i}/cuts/${j}`, `names no opening ("${String(c)}")`);
|
|
890
|
+
});
|
|
891
|
+
});
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
function validateScene3D(v) {
|
|
895
|
+
const out = [];
|
|
896
|
+
scene(v, "", out);
|
|
897
|
+
if (isObj(v)) references(v, out);
|
|
898
|
+
return out;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
// src/replay/facts.ts
|
|
902
|
+
import { describe, lint } from "@chanmeng666/archlang";
|
|
903
|
+
var round2 = (x) => Math.round(x * 100) / 100;
|
|
904
|
+
function replayFacts(source3, opts) {
|
|
905
|
+
const view = opts.view ?? "all";
|
|
906
|
+
const shown = view === "all" ? [...opts.storeys] : opts.storeys.slice(view - 1, view);
|
|
907
|
+
if (shown.length === 0) return void 0;
|
|
908
|
+
const d = describe(source3, opts.world ? { world: opts.world } : {});
|
|
909
|
+
if (!d.ok) return void 0;
|
|
910
|
+
const byLevel = d.levels ? d.levels.map((l) => [l.level, l.totals]) : shown.map((n) => [n, d.totals]);
|
|
911
|
+
const pick = shown.map((n) => byLevel.find(([l]) => l === n)?.[1]);
|
|
912
|
+
if (pick.some((t) => t === void 0)) return void 0;
|
|
913
|
+
const totals = pick;
|
|
914
|
+
const sum = (f) => totals.reduce((a, t) => a + f(t), 0);
|
|
915
|
+
const nets = totals.map((t) => t.net_floor_area_m2);
|
|
916
|
+
const warnings = lint(source3, opts.world ? { world: opts.world } : {}).filter(
|
|
917
|
+
(x) => x.severity === "warning" && (x.level === void 0 || shown.includes(x.level))
|
|
918
|
+
).length;
|
|
919
|
+
return {
|
|
920
|
+
...view === "all" && shown.length > 1 ? { storeys: shown.length } : {},
|
|
921
|
+
rooms: sum((t) => t.rooms),
|
|
922
|
+
doors: sum((t) => t.doors),
|
|
923
|
+
windows: sum((t) => t.windows),
|
|
924
|
+
areaCentre: round2(sum((t) => t.floor_area_m2)),
|
|
925
|
+
...nets.every((n) => n !== void 0) ? { areaNet: round2(nets.reduce((a, n) => a + n, 0)) } : {},
|
|
926
|
+
warnings
|
|
927
|
+
};
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
export {
|
|
931
|
+
T0_FAMILIES,
|
|
932
|
+
assetFor,
|
|
933
|
+
T0_HEIGHT_MM,
|
|
934
|
+
t0Parts,
|
|
935
|
+
um,
|
|
936
|
+
umPoint,
|
|
937
|
+
piecesOf,
|
|
938
|
+
wallOwnership,
|
|
939
|
+
piecesTouch,
|
|
940
|
+
mixedHeightJoints,
|
|
941
|
+
FLOOR_OVERLAP_MIN_UM2,
|
|
942
|
+
FLOOR_LIFT_UM,
|
|
943
|
+
overlapArea,
|
|
944
|
+
floorOverlaps,
|
|
945
|
+
floorLifts,
|
|
946
|
+
ARCHLANG_3D_VERSION,
|
|
947
|
+
buildScene3D,
|
|
948
|
+
validateScene3D,
|
|
949
|
+
replayFacts
|
|
950
|
+
};
|