@chanmeng666/archlang-3d 0.5.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/dist/browser.js CHANGED
@@ -9,11 +9,12 @@ import {
9
9
  replayPayload,
10
10
  viewBoxOf,
11
11
  viewToolbar
12
- } from "./chunk-4SQ5YKKX.js";
12
+ } from "./chunk-FHBR2U5Z.js";
13
13
  import {
14
14
  ELEVATION_RANGE,
15
15
  END_AZIMUTH,
16
16
  END_FOV,
17
+ GROUND_PLANE,
17
18
  KIND_PALETTE,
18
19
  PALETTE,
19
20
  START_FOV,
@@ -28,13 +29,14 @@ import {
28
29
  pivotAbove,
29
30
  presetCamera,
30
31
  settledLift,
32
+ siteColour,
31
33
  slotColour,
32
34
  stateAt,
33
35
  stopCount,
34
36
  stripAt,
35
37
  takenLens,
36
38
  targetBounds
37
- } from "./chunk-EQBMPXB5.js";
39
+ } from "./chunk-TI4RYEOL.js";
38
40
 
39
41
  // src/replay/mount.ts
40
42
  import {
@@ -75,6 +77,476 @@ function paintStrip(el, items) {
75
77
  el.replaceChildren(...nodes);
76
78
  }
77
79
 
80
+ // src/replay/wall-lines.ts
81
+ function takesWallLines(n) {
82
+ return n.kind === "wall" && n.part === void 0 || n.kind === "column";
83
+ }
84
+ var EXACT = 2 ** 26;
85
+ function det(a, b, c, d) {
86
+ if (Math.abs(a) < EXACT && Math.abs(b) < EXACT && Math.abs(c) < EXACT && Math.abs(d) < EXACT) return a * d - b * c;
87
+ const r = BigInt(a) * BigInt(d) - BigInt(b) * BigInt(c);
88
+ return r > 0n ? 1 : r < 0n ? -1 : 0;
89
+ }
90
+ function detKey(a, b, c, d) {
91
+ if (Math.abs(a) < EXACT && Math.abs(b) < EXACT && Math.abs(c) < EXACT && Math.abs(d) < EXACT)
92
+ return String(a * d - b * c);
93
+ return (BigInt(a) * BigInt(d) - BigInt(b) * BigInt(c)).toString();
94
+ }
95
+ function gcd(a, b) {
96
+ let x = Math.abs(a);
97
+ let y = Math.abs(b);
98
+ while (y !== 0) [x, y] = [y, x % y];
99
+ return x;
100
+ }
101
+ function nearlyFlat(p, q, fp, fq) {
102
+ const d = BigInt(p[0]) * BigInt(q[0]) + BigInt(p[1]) * BigInt(q[1]);
103
+ const c = BigInt(p[0]) * BigInt(q[1]) - BigInt(p[1]) * BigInt(q[0]);
104
+ const s = fp * fq > 0 ? d : -d;
105
+ return s > 0n && s * s > 3n * c * c;
106
+ }
107
+ function planLine(x0, z0, x1, z1) {
108
+ let dx = x1 - x0;
109
+ let dz = z1 - z0;
110
+ const g = gcd(dx, dz);
111
+ dx /= g;
112
+ dz /= g;
113
+ if (dx < 0 || dx === 0 && dz < 0) {
114
+ dx = 0 - dx;
115
+ dz = 0 - dz;
116
+ }
117
+ return { dx, dz, key: `${dx},${dz},${detKey(dx, dz, x0, z0)}` };
118
+ }
119
+ var lexLess = (a, b) => {
120
+ for (let i = 0; i < a.length; i++) {
121
+ const d = a[i] - b[i];
122
+ if (d !== 0) return d;
123
+ }
124
+ return 0;
125
+ };
126
+ var sortedKeys = (m) => [...m.keys()].sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
127
+ var sortedUnique = (xs) => {
128
+ const s = [...xs].sort((a, b) => a - b);
129
+ let n = 0;
130
+ for (let i = 0; i < s.length; i++) if (i === 0 || s[i] !== s[n - 1]) s[n++] = s[i];
131
+ s.length = n;
132
+ return s;
133
+ };
134
+ function extent(xs) {
135
+ let lo = Infinity;
136
+ let hi = -Infinity;
137
+ for (const x of xs) {
138
+ if (x < lo) lo = x;
139
+ if (x > hi) hi = x;
140
+ }
141
+ return [lo, hi];
142
+ }
143
+ function lastRaised(nodes, rank) {
144
+ let best = -1;
145
+ for (const n of nodes) {
146
+ if (best < 0) best = n;
147
+ else {
148
+ const rn = rank?.[n] ?? 0;
149
+ const rb = rank?.[best] ?? 0;
150
+ if (rn > rb || rn === rb && n < best) best = n;
151
+ }
152
+ }
153
+ return best;
154
+ }
155
+ function byStorey(nodes) {
156
+ const storeys = /* @__PURE__ */ new Map();
157
+ nodes.forEach((n, i) => {
158
+ if (!takesWallLines(n)) return;
159
+ const level = /^L(-?\d+)\//.exec(n.key)?.[1] ?? "";
160
+ const members = storeys.get(level);
161
+ if (members) members.push(i);
162
+ else storeys.set(level, [i]);
163
+ });
164
+ return sortedKeys(storeys).map((k) => storeys.get(k) ?? []);
165
+ }
166
+ function wallOutline(nodes, rank) {
167
+ const faces = wallFaces(nodes);
168
+ const drawn = nodes.map((n, i) => takesWallLines(n) ? { ...n, ...withFaces(n, faces[i]) } : n);
169
+ return { faces, lines: linesOf(drawn, rank) };
170
+ }
171
+ function linesOf(nodes, rank) {
172
+ const out = nodes.map((n) => takesWallLines(n) ? [] : void 0);
173
+ const segs = nodes.map(() => []);
174
+ for (const members of byStorey(nodes)) storeyLines(nodes, members, segs, rank);
175
+ segs.forEach((list, i) => {
176
+ if (!out[i]) return;
177
+ const sorted = list.map((s) => lexLess(s.slice(0, 3), s.slice(3)) <= 0 ? s : [s[3], s[4], s[5], s[0], s[1], s[2]]).sort(lexLess);
178
+ out[i] = sorted.flat();
179
+ });
180
+ return out;
181
+ }
182
+ function sweep(items, visit) {
183
+ const byStart = items.map((it, i) => [it, i]).sort((a, b) => a[0].t0 - b[0].t0 || a[1] - b[1]);
184
+ const ts = sortedUnique(items.flatMap((e) => [e.t0, e.t1]));
185
+ let next = 0;
186
+ let on = [];
187
+ for (let j = 0; j + 1 < ts.length; j++) {
188
+ const t0 = ts[j];
189
+ const t1 = ts[j + 1];
190
+ if (on.some((e) => e.t1 <= t0)) on = on.filter((e) => e.t1 > t0);
191
+ while (next < byStart.length && byStart[next]?.[0].t0 <= t0) on.push(byStart[next++]?.[0]);
192
+ if (on.length > 0) visit(t0, t1, on);
193
+ }
194
+ }
195
+ function storeyLines(nodes, members, segs, rank) {
196
+ const buckets = /* @__PURE__ */ new Map();
197
+ const lines = /* @__PURE__ */ new Map();
198
+ const dirs = /* @__PURE__ */ new Map();
199
+ const pairs = /* @__PURE__ */ new Map();
200
+ const push = (plane, line, e) => {
201
+ const key = `${plane}|${line}`;
202
+ const b = buckets.get(key);
203
+ if (b) b.edges.push(e);
204
+ else buckets.set(key, { line, plane, edges: [e] });
205
+ };
206
+ const pair = (plane, p, q, node) => {
207
+ const fwd = lexLess(p, q) < 0;
208
+ const [a, b] = fwd ? [p, q] : [q, p];
209
+ const key = `${plane}|${a[0]},${a[1]},${a[2]}|${b[0]},${b[1]},${b[2]}`;
210
+ const was = pairs.get(key);
211
+ if (was) {
212
+ was.net += fwd ? 1 : -1;
213
+ was.nodes.push(node);
214
+ } else pairs.set(key, { a, b, net: fwd ? 1 : -1, nodes: [node] });
215
+ };
216
+ const horizontal = (y, pl, p, q) => {
217
+ const key = `h${y}:${pl.key}`;
218
+ let at = lines.get(key);
219
+ if (!at) {
220
+ at = { kind: "horizontal", y, alongX: pl.dx !== 0, other: /* @__PURE__ */ new Map() };
221
+ lines.set(key, at);
222
+ }
223
+ if (at.kind === "horizontal") {
224
+ for (const r of [p, q]) {
225
+ const [x, , z] = r;
226
+ if (at.alongX) at.other.set(x, z);
227
+ else at.other.set(z, x);
228
+ }
229
+ }
230
+ return key;
231
+ };
232
+ const along = (pl, p) => pl.dx !== 0 ? p[0] : p[2];
233
+ const edge = (t0, t1, node, f) => t0 < t1 ? { t0, t1, k: 1, node, f } : { t0: t1, t1: t0, k: -1, node, f };
234
+ for (const ni of members) {
235
+ const n = nodes[ni];
236
+ const P = (v) => [
237
+ Math.round(n.positions[v * 3]),
238
+ Math.round(n.positions[v * 3 + 1]),
239
+ Math.round(n.positions[v * 3 + 2])
240
+ ];
241
+ for (let i = 0; i + 2 < n.indices.length; i += 3) {
242
+ const tri = [P(n.indices[i]), P(n.indices[i + 1]), P(n.indices[i + 2])];
243
+ const [a, b, c] = tri;
244
+ const ax = a[0];
245
+ const ay = a[1];
246
+ const az = a[2];
247
+ const sides = [
248
+ [a, b],
249
+ [b, c],
250
+ [c, a]
251
+ ];
252
+ if (ay === b[1] && ay === c[1]) {
253
+ if (det(b[0] - ax, b[2] - az, c[0] - ax, c[2] - az) === 0)
254
+ continue;
255
+ const plane2 = `H${ay}`;
256
+ for (const [p, q] of sides) {
257
+ if (p[0] === q[0] && p[2] === q[2]) continue;
258
+ const pl2 = planLine(p[0], p[2], q[0], q[2]);
259
+ push(plane2, horizontal(ay, pl2, p, q), edge(along(pl2, p), along(pl2, q), ni, 0));
260
+ }
261
+ continue;
262
+ }
263
+ const flatInPlan = det(b[0] - ax, b[2] - az, c[0] - ax, c[2] - az) === 0;
264
+ if (!flatInPlan) {
265
+ for (const [p, q] of sides) segs[ni].push([...p, ...q]);
266
+ continue;
267
+ }
268
+ const far = a[0] !== b[0] || a[2] !== b[2] ? b : c;
269
+ if (far[0] === ax && far[2] === az) continue;
270
+ const pl = planLine(ax, az, far[0], far[2]);
271
+ const plane = `V${pl.key}`;
272
+ if (!dirs.has(plane)) dirs.set(plane, [pl.dx, pl.dz]);
273
+ const s = (p) => along(pl, p);
274
+ const turn = det(s(b) - s(a), b[1] - ay, s(c) - s(a), c[1] - ay);
275
+ if (turn === 0) continue;
276
+ const f = turn > 0 ? 1 : -1;
277
+ for (const [p, q] of sides) {
278
+ if (p[0] === q[0] && p[2] === q[2]) {
279
+ if (p[1] === q[1]) continue;
280
+ const key = `v${p[0]},${p[2]}`;
281
+ if (!lines.has(key)) lines.set(key, { kind: "vertical", x: p[0], z: p[2] });
282
+ push(plane, key, edge(p[1], q[1], ni, f));
283
+ } else if (p[1] === q[1]) {
284
+ push(plane, horizontal(p[1], pl, p, q), edge(along(pl, p), along(pl, q), ni, f));
285
+ } else pair(plane, p, q, ni);
286
+ }
287
+ }
288
+ }
289
+ const bounds = /* @__PURE__ */ new Map();
290
+ for (const key of sortedKeys(buckets)) {
291
+ const { line, plane, edges } = buckets.get(key);
292
+ const [e0, e1] = edges;
293
+ if (edges.length === 2 && e1 && e0.t0 === e1.t0 && e0.t1 === e1.t1 && e0.k !== e1.k) continue;
294
+ sweep(edges, (t0, t1, on) => {
295
+ let m = 0;
296
+ for (const e of on) m += e.k;
297
+ if (m === 0) return;
298
+ const nets = /* @__PURE__ */ new Map();
299
+ for (const e of on) nets.set(e.node, (nets.get(e.node) ?? 0) + e.k);
300
+ const by = sortedUnique(on.filter((e) => nets.get(e.node) !== 0).map((e) => e.node));
301
+ const fs = sortedUnique(on.filter((e) => e.k === Math.sign(m)).map((e) => e.f));
302
+ const b = { t0, t1, nodes: by, plane, f: fs.length === 1 ? fs[0] : 0 };
303
+ const list = bounds.get(line);
304
+ if (list) list.push(b);
305
+ else bounds.set(line, [b]);
306
+ });
307
+ }
308
+ for (const line of sortedKeys(bounds)) {
309
+ const list = bounds.get(line);
310
+ const at = lines.get(line);
311
+ const runs = [];
312
+ sweep(list, (t0, t1, on) => {
313
+ if (at.kind === "vertical" && on.length === 2) {
314
+ const [p, q] = on;
315
+ const dp = dirs.get(p.plane);
316
+ const dq = dirs.get(q.plane);
317
+ if (dp && dq && p.f !== 0 && q.f !== 0 && nearlyFlat(dp, dq, p.f, q.f)) return;
318
+ }
319
+ const node = lastRaised(
320
+ on.flatMap((b) => b.nodes),
321
+ rank
322
+ );
323
+ const last = runs[runs.length - 1];
324
+ if (last && last.t1 === t0 && last.node === node) last.t1 = t1;
325
+ else runs.push({ t0, t1, node });
326
+ });
327
+ for (const r of runs) {
328
+ const end = (t) => {
329
+ if (at.kind === "vertical") return [at.x, t, at.z];
330
+ const o = at.other.get(t);
331
+ return at.alongX ? [t, at.y, o] : [o, at.y, t];
332
+ };
333
+ segs[r.node].push([...end(r.t0), ...end(r.t1)]);
334
+ }
335
+ }
336
+ for (const key of sortedKeys(pairs)) {
337
+ const { a, b, net, nodes: by } = pairs.get(key);
338
+ if (net === 0) continue;
339
+ segs[lastRaised(by, rank)].push([...a, ...b]);
340
+ }
341
+ }
342
+ function joinedGroups(fixes, standing) {
343
+ const up = /* @__PURE__ */ new Map();
344
+ fixes.forEach((f, i) => {
345
+ if (f && f.group >= 0) up.set(f.group, (up.get(f.group) ?? true) && standing(i));
346
+ });
347
+ const out = /* @__PURE__ */ new Set();
348
+ for (const [g, v] of up) if (v) out.add(g);
349
+ return out;
350
+ }
351
+ function wallFaces(nodes) {
352
+ const out = nodes.map(
353
+ (n) => takesWallLines(n) ? { hide: [], add: [], alone: [], joined: [], group: -1 } : void 0
354
+ );
355
+ const root = nodes.map((_, i) => i);
356
+ const find = (i) => {
357
+ let r = i;
358
+ while (root[r] !== r) r = root[r];
359
+ while (root[i] !== r) [i, root[i]] = [root[i], r];
360
+ return r;
361
+ };
362
+ const join = (a, b) => {
363
+ const ra = find(a);
364
+ const rb = find(b);
365
+ if (ra < rb) root[rb] = ra;
366
+ else if (rb < ra) root[ra] = rb;
367
+ };
368
+ const shared = /* @__PURE__ */ new Set();
369
+ for (const members of byStorey(nodes)) storeyFaces(nodes, members, out, join, shared);
370
+ out.forEach((f, i) => {
371
+ if (!f) return;
372
+ f.hide.sort((a, b) => a - b);
373
+ if (shared.has(i)) f.group = find(i);
374
+ });
375
+ return out;
376
+ }
377
+ function faceParts(n, fix) {
378
+ if (!fix) return { positions: n.positions, base: [...n.indices], alone: [], joined: [] };
379
+ const hidden = new Set(fix.hide);
380
+ const base = [];
381
+ for (let i = 0; i + 2 < n.indices.length; i += 3) {
382
+ if (!hidden.has(i / 3)) base.push(n.indices[i], n.indices[i + 1], n.indices[i + 2]);
383
+ }
384
+ let v = n.positions.length / 3;
385
+ const run = (flat, to = []) => {
386
+ for (let k = 0; k < flat.length / 3; k++) to.push(v++);
387
+ return to;
388
+ };
389
+ run(fix.add, base);
390
+ const alone = run(fix.alone);
391
+ const joined = run(fix.joined);
392
+ return { positions: n.positions.concat(fix.add, fix.alone, fix.joined), base, alone, joined };
393
+ }
394
+ function withFaces(n, fix, mode = "joined") {
395
+ if (!fix) return { positions: n.positions, indices: n.indices };
396
+ const parts = faceParts(n, fix);
397
+ return { positions: parts.positions, indices: parts.base.concat(mode === "joined" ? parts.joined : parts.alone) };
398
+ }
399
+ function contested(tris) {
400
+ const boxes = tris.map((t) => {
401
+ const [s0, s1] = extent(t.s);
402
+ const [y0, y1] = extent(t.p.map((q) => q[1]));
403
+ return { s0, s1, y0, y1, f: t.f };
404
+ });
405
+ boxes.sort((a, b) => a.s0 - b.s0);
406
+ let up = [];
407
+ let down = [];
408
+ for (const b of boxes) {
409
+ if (up.some((o) => o.s1 <= b.s0)) up = up.filter((o) => o.s1 > b.s0);
410
+ if (down.some((o) => o.s1 <= b.s0)) down = down.filter((o) => o.s1 > b.s0);
411
+ const other = b.f > 0 ? down : up;
412
+ if (other.some((o) => Math.min(o.y1, b.y1) > Math.max(o.y0, b.y0))) return true;
413
+ (b.f > 0 ? up : down).push(b);
414
+ }
415
+ return false;
416
+ }
417
+ function storeyFaces(nodes, members, out, join, shared) {
418
+ const planes = /* @__PURE__ */ new Map();
419
+ for (const ni of members) {
420
+ const n = nodes[ni];
421
+ const P = (v) => [
422
+ Math.round(n.positions[v * 3]),
423
+ Math.round(n.positions[v * 3 + 1]),
424
+ Math.round(n.positions[v * 3 + 2])
425
+ ];
426
+ for (let i = 0; i + 2 < n.indices.length; i += 3) {
427
+ const a = P(n.indices[i]);
428
+ const b = P(n.indices[i + 1]);
429
+ const c = P(n.indices[i + 2]);
430
+ const ax = a[0];
431
+ const ay = a[1];
432
+ const az = a[2];
433
+ if (ay === b[1] && ay === c[1]) continue;
434
+ if (det(b[0] - ax, b[2] - az, c[0] - ax, c[2] - az) !== 0)
435
+ continue;
436
+ const far = a[0] !== b[0] || a[2] !== b[2] ? b : c;
437
+ if (far[0] === ax && far[2] === az) continue;
438
+ const pl = planLine(ax, az, far[0], far[2]);
439
+ const along = (p) => pl.dx !== 0 ? p[0] : p[2];
440
+ const s = [along(a), along(b), along(c)];
441
+ const turn = det(
442
+ s[1] - s[0],
443
+ b[1] - ay,
444
+ s[2] - s[0],
445
+ c[1] - ay
446
+ );
447
+ if (turn === 0) continue;
448
+ const key = `V${pl.key}`;
449
+ const t = { node: ni, tri: i / 3, p: [a, b, c], f: turn > 0 ? 1 : -1, s };
450
+ const plane = planes.get(key);
451
+ if (plane) plane.tris.push(t);
452
+ else planes.set(key, { pl, tris: [t] });
453
+ }
454
+ }
455
+ for (const key of sortedKeys(planes)) {
456
+ const { tris } = planes.get(key);
457
+ if (!contested(tris)) continue;
458
+ const S = sortedUnique(tris.flatMap((t) => t.s));
459
+ const Y = sortedUnique(tris.flatMap((t) => t.p.map((q) => q[1])));
460
+ const where = /* @__PURE__ */ new Map();
461
+ for (const t of tris) for (let k = 0; k < 3; k++) where.set(t.s[k], t.p[k]);
462
+ const sAt = new Map(S.map((s, i) => [s, i]));
463
+ const yAt = new Map(Y.map((y, j) => [y, j]));
464
+ const ny = Y.length - 1;
465
+ const steps = S.map(() => []);
466
+ for (const t of tris) {
467
+ for (let k = 0; k < 3; k++) {
468
+ const p = t.p[k];
469
+ const q = t.p[(k + 1) % 3];
470
+ if (p[0] !== q[0] || p[2] !== q[2] || p[1] === q[1]) continue;
471
+ const i = sAt.get(t.s[k]);
472
+ const lo = Math.min(p[1], q[1]);
473
+ const hi = Math.max(p[1], q[1]);
474
+ steps[i].push([
475
+ t.node,
476
+ yAt.get(lo),
477
+ yAt.get(hi),
478
+ q[1] > p[1] ? 1 : -1
479
+ ]);
480
+ }
481
+ }
482
+ const wind = /* @__PURE__ */ new Map();
483
+ const nonzero = /* @__PURE__ */ new Map();
484
+ let live = [];
485
+ const total = new Int32Array(ny);
486
+ const cell = (to, s0, s1, j, facing) => {
487
+ const y0 = Y[j];
488
+ const y1 = Y[j + 1];
489
+ const at = (s, y) => {
490
+ const q = where.get(s);
491
+ return [q[0], y, q[2]];
492
+ };
493
+ const [p00, p10, p11, p01] = [at(s0, y0), at(s1, y0), at(s1, y1), at(s0, y1)];
494
+ if (facing > 0) to.push(...p00, ...p10, ...p11, ...p00, ...p11, ...p01);
495
+ else to.push(...p00, ...p11, ...p10, ...p00, ...p01, ...p11);
496
+ };
497
+ for (let i = 0; i + 1 < S.length; i++) {
498
+ const here = steps[i];
499
+ for (const [o, j0, j1, d] of here) {
500
+ let w = wind.get(o);
501
+ if (!w) {
502
+ w = new Int32Array(ny);
503
+ wind.set(o, w);
504
+ }
505
+ let nz = nonzero.get(o) ?? 0;
506
+ for (let j = j0; j < j1; j++) {
507
+ const was = w[j];
508
+ const now = was - d;
509
+ w[j] = now;
510
+ total[j] = total[j] - d;
511
+ if (was === 0) nz++;
512
+ else if (now === 0) nz--;
513
+ }
514
+ nonzero.set(o, nz);
515
+ }
516
+ if (here.length > 0) {
517
+ for (const o of [...wind.keys()]) {
518
+ if (nonzero.get(o) === 0) {
519
+ wind.delete(o);
520
+ nonzero.delete(o);
521
+ }
522
+ }
523
+ live = [...wind.keys()].sort((a, b) => a - b);
524
+ }
525
+ const s0 = S[i];
526
+ const s1 = S[i + 1];
527
+ for (let j = 0; j < ny; j++) {
528
+ const over = live.filter((o) => wind.get(o)[j] !== 0);
529
+ if (over.length === 0) continue;
530
+ if (over.length === 1) {
531
+ const o = over[0];
532
+ cell(out[o].add, s0, s1, j, wind.get(o)[j]);
533
+ continue;
534
+ }
535
+ for (const o of over) {
536
+ cell(out[o].alone, s0, s1, j, wind.get(o)[j]);
537
+ shared.add(o);
538
+ join(o, over[0]);
539
+ }
540
+ const sum = total[j];
541
+ if (sum === 0) continue;
542
+ const owner = over.find((o) => Math.sign(wind.get(o)[j]) === Math.sign(sum));
543
+ cell(out[owner].joined, s0, s1, j, sum);
544
+ }
545
+ }
546
+ for (const t of tris) out[t.node].hide.push(t.tri);
547
+ }
548
+ }
549
+
78
550
  // src/replay/mount.ts
79
551
  var KEY_TURN_DEG = 5;
80
552
  var KEY_DOLLY = 0.9;
@@ -98,6 +570,14 @@ var THEMES = {
98
570
  door: "#7aa6c9",
99
571
  "window:frame": "#5d86a8",
100
572
  "window:glass": "#86c5ee",
573
+ // The trim and the balustrade (card RM8.6): a reveal as its frame, a sill and a board as a
574
+ // door, a cased opening's trim as a door, a handrail as a window frame.
575
+ "window:reveal": "#5d86a8",
576
+ "window:sill": "#7aa6c9",
577
+ "window:board": "#7aa6c9",
578
+ "opening:lining": "#7aa6c9",
579
+ "opening:casing": "#7aa6c9",
580
+ "stair:rail": "#3b5b78",
101
581
  "wall:demolish": "#e07a5f",
102
582
  furniture: "#3f6a8f",
103
583
  stair: "#5d86a8"
@@ -142,7 +622,17 @@ function mountReplay(out, p, strip, opts = {}) {
142
622
  scene.add(fill);
143
623
  const nodes = /* @__PURE__ */ new Map();
144
624
  const owned = [];
145
- for (const n of p.nodes) {
625
+ const rankOf = new Map(p.events.map((e) => [e.key, e.rank]));
626
+ const { faces, lines: outlines } = wallOutline(
627
+ p.nodes,
628
+ p.nodes.map((n) => rankOf.get(n.key) ?? 0)
629
+ );
630
+ const patched = [];
631
+ for (const [ni, node] of p.nodes.entries()) {
632
+ const outline = outlines[ni];
633
+ const fix = faces[ni];
634
+ const parts = faceParts(node, fix);
635
+ const n = { ...node, positions: parts.positions, indices: parts.base };
146
636
  const pos = new Float32Array(n.positions.length);
147
637
  let base = Infinity;
148
638
  let topY = -Infinity;
@@ -180,16 +670,21 @@ function mountReplay(out, p, strip, opts = {}) {
180
670
  // perspective.
181
671
  polygonOffset: true,
182
672
  polygonOffsetFactor: 1,
183
- polygonOffsetUnits: flatLaid ? 4 : 1
673
+ // A site surface (card RM8.3) lies in the plane of the slab's top and the ground's: pushed
674
+ // back further still, so the slab wins where a lawn runs under the building, and the ground
675
+ // (`GROUND_PLANE`) further than both.
676
+ polygonOffsetUnits: n.kind === "outdoor" ? 8 : flatLaid ? 4 : 1
184
677
  });
185
678
  owned.push(geo, mat);
186
- g.add(new Mesh(geo, mat));
679
+ const mesh = new Mesh(geo, mat);
680
+ g.add(mesh);
187
681
  if (n.kind !== "slab" && !glass && edged) {
188
682
  const edges = new EdgesGeometry(geo, 30);
189
683
  const line = new LineBasicMaterial({ color: new Color(theme.edge) });
190
684
  owned.push(edges, line);
191
685
  g.add(new LineSegments(edges, line));
192
686
  }
687
+ return mesh;
193
688
  };
194
689
  const attr = new BufferAttribute(pos, 3);
195
690
  if (n.groups) {
@@ -197,12 +692,22 @@ function mountReplay(out, p, strip, opts = {}) {
197
692
  for (const { slot, count } of n.groups) {
198
693
  const run = n.indices.slice(at, at + count);
199
694
  at += count;
200
- if (slot === "body") add(attr, run, theme.colors[key2] ?? furniture, false, 1, false);
695
+ if (slot === "body") add(attr, run, theme.colors[key2] ?? theme.colors[n.kind] ?? furniture, false, 1, false);
201
696
  else {
202
697
  const { alpha } = PALETTE[slot];
203
698
  add(attr, run, slotColour(slot, p.theme, furniture), alpha < 1, alpha, false);
204
699
  }
205
700
  }
701
+ } else if (n.colour) {
702
+ add(
703
+ attr,
704
+ n.indices,
705
+ siteColour(n.colour, p.theme, THEMES.dark.colors.floor),
706
+ false,
707
+ 1,
708
+ true,
709
+ n.kind !== "fence"
710
+ );
206
711
  } else if (n.finish) {
207
712
  add(attr, n.indices, finishColour(n.finish, p.theme, THEMES.dark.colors.floor), false, 1, true);
208
713
  } else if (key2 === "wall") {
@@ -213,11 +718,41 @@ function mountReplay(out, p, strip, opts = {}) {
213
718
  const tri = n.indices.slice(i, i + 3);
214
719
  (tri.every(atTop) ? cap : body).push(...tri);
215
720
  }
216
- add(attr, body, theme.colors.wall ?? furniture, false, 1, true);
721
+ add(attr, body, theme.colors.wall ?? furniture, false, 1, true, outline === void 0);
217
722
  if (cap.length) add(attr, cap, theme.cap, false, 1, true, false);
218
723
  } else {
219
724
  const glass = key2 === "window:glass";
220
- add(attr, n.indices, theme.colors[key2] ?? furniture, glass, glass ? KIND_PALETTE["window:glass"].alpha : 1, true);
725
+ add(
726
+ attr,
727
+ n.indices,
728
+ theme.colors[key2] ?? theme.colors[n.kind] ?? furniture,
729
+ glass,
730
+ glass ? KIND_PALETTE["window:glass"].alpha : 1,
731
+ true,
732
+ outline === void 0
733
+ );
734
+ }
735
+ if (fix && fix.group >= 0) {
736
+ const colour = theme.colors[key2] ?? theme.colors[n.kind] ?? furniture;
737
+ patched.push({
738
+ key: n.key,
739
+ ...parts.alone.length > 0 ? { alone: add(attr, parts.alone, colour, false, 1, true, false) } : {},
740
+ ...parts.joined.length > 0 ? { joined: add(attr, parts.joined, colour, false, 1, true, false) } : {},
741
+ group: fix.group
742
+ });
743
+ }
744
+ if (outline && outline.length > 0) {
745
+ const at = new Float32Array(outline.length);
746
+ for (let i = 0; i < outline.length; i += 3) {
747
+ at[i] = outline[i] / 1e3;
748
+ at[i + 1] = outline[i + 1] / 1e3 - base;
749
+ at[i + 2] = outline[i + 2] / 1e3;
750
+ }
751
+ const geo = new BufferGeometry();
752
+ geo.setAttribute("position", new BufferAttribute(at, 3));
753
+ const line = new LineBasicMaterial({ color: new Color(theme.edge) });
754
+ owned.push(geo, line);
755
+ g.add(new LineSegments(geo, line));
221
756
  }
222
757
  g.visible = false;
223
758
  scene.add(g);
@@ -230,6 +765,38 @@ function mountReplay(out, p, strip, opts = {}) {
230
765
  const lo = new Vector3(...box.lo);
231
766
  const hi = new Vector3(...box.hi);
232
767
  const top = hi.y + 1e3;
768
+ let ground;
769
+ let groundMat;
770
+ if (p.ground) {
771
+ const y = p.ground.y / 1e3;
772
+ const m = GROUND_PLANE.marginMm;
773
+ const [x0, z0, x1, z1] = [lo.x - m, lo.z - m, hi.x + m, hi.z + m];
774
+ const geo = new BufferGeometry();
775
+ geo.setAttribute(
776
+ "position",
777
+ new BufferAttribute(new Float32Array([x0, y, z0, x0, y, z1, x1, y, z1, x1, y, z0]), 3)
778
+ );
779
+ geo.setIndex([0, 1, 2, 0, 2, 3]);
780
+ const mat = new MeshLambertMaterial({
781
+ color: new Color(p.theme === "light" ? GROUND_PLANE.light : GROUND_PLANE.dark),
782
+ transparent: true,
783
+ opacity: 0,
784
+ depthWrite: true,
785
+ flatShading: true,
786
+ // Twice the slope term every other face takes, not only more units: seen at a slant a quad this
787
+ // size and a lawn in its plane rasterise to depths that differ by more than a few units, and a
788
+ // units-only margin let the ground win over whole lawns (rendered, card RM8.3).
789
+ polygonOffset: true,
790
+ polygonOffsetFactor: 2,
791
+ polygonOffsetUnits: 16
792
+ });
793
+ owned.push(geo, mat);
794
+ ground = new Mesh(geo, mat);
795
+ groundMat = mat;
796
+ ground.renderOrder = -1;
797
+ ground.visible = false;
798
+ scene.add(ground);
799
+ }
233
800
  const ortho = new OrthographicCamera(-ow / 2, ow / 2, oh / 2, -oh / 2, 1, top + 1e5);
234
801
  ortho.up.set(0, 0, -1);
235
802
  ortho.position.set(cx, top + 5e4, cz);
@@ -301,17 +868,49 @@ function mountReplay(out, p, strip, opts = {}) {
301
868
  const notify = () => {
302
869
  for (const fn of listeners) fn();
303
870
  };
871
+ const samples = Math.max(1, Math.min(4, Math.floor(p.supersample ?? 1)));
872
+ function supersampled(cam) {
873
+ const n = samples * samples;
874
+ const sum = new Uint32Array(W * H * 4);
875
+ ctx.globalAlpha = 1;
876
+ for (let j = 0; j < samples; j++) {
877
+ for (let i = 0; i < samples; i++) {
878
+ cam.setViewOffset(W, H, (i + 0.5) / samples - 0.5, (j + 0.5) / samples - 0.5, W, H);
879
+ renderer.render(scene, cam);
880
+ ctx.drawImage(gl, 0, 0);
881
+ const d = ctx.getImageData(0, 0, W, H).data;
882
+ for (let q = 0; q < d.length; q++) sum[q] = sum[q] + d[q];
883
+ }
884
+ }
885
+ cam.clearViewOffset();
886
+ const mean = ctx.createImageData(W, H);
887
+ for (let q = 0; q < sum.length; q++) mean.data[q] = Math.floor((sum[q] + (n >> 1)) / n);
888
+ ctx.putImageData(mean, 0, 0);
889
+ }
304
890
  function draw(t) {
305
891
  tNow = t;
306
892
  drawn = true;
307
893
  if (strip && p.facts) paintStrip(strip, stripAt(p.facts, p.events, Math.min(1, Math.max(0, t))));
308
894
  const s = stateAt(p.events, t);
895
+ if (ground && groundMat) {
896
+ ground.visible = s.ground > 0;
897
+ groundMat.opacity = s.ground;
898
+ }
309
899
  for (const [key2, { g, flat, base, lift }] of nodes) {
310
900
  const st = s.nodes.get(key2);
311
901
  g.visible = st?.visible === true && (storeyOf.get(key2) ?? 0) < shown;
312
902
  g.scale.y = Math.max(flat, st?.rise ?? 0);
313
903
  if (lift !== 0) g.position.y = base + settledLift(lift, s.settle);
314
904
  }
905
+ const together = joinedGroups(faces, (i) => {
906
+ const key2 = p.nodes[i]?.key ?? "";
907
+ return nodes.get(key2)?.g.visible === true && (s.nodes.get(key2)?.rise ?? 0) >= 1;
908
+ });
909
+ for (const { group, alone, joined } of patched) {
910
+ const t2 = together.has(group);
911
+ if (alone) alone.visible = !t2;
912
+ if (joined) joined.visible = t2;
913
+ }
315
914
  let cam = ortho;
316
915
  if (holder === "free" && controls) {
317
916
  const dist = persp.position.distanceTo(controls.target);
@@ -328,9 +927,11 @@ function mountReplay(out, p, strip, opts = {}) {
328
927
  place(frameCamera(s, fits, frameView), s.settle > 0 ? endRadius : radius);
329
928
  cam = persp;
330
929
  }
331
- renderer.render(scene, cam);
332
- ctx.globalAlpha = 1;
333
- ctx.drawImage(gl, 0, 0);
930
+ if (samples === 1) {
931
+ renderer.render(scene, cam);
932
+ ctx.globalAlpha = 1;
933
+ ctx.drawImage(gl, 0, 0);
934
+ } else supersampled(cam);
334
935
  if (holder === "replay" && s.svg > 0 && img.complete && img.naturalWidth > 0) {
335
936
  const k = Math.min(W / vw, H / vh);
336
937
  const dw = vw * k;