@chanmeng666/archlang-3d 0.5.0 → 0.6.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 +67 -0
- package/README.md +4 -3
- package/THIRD_PARTY_NOTICES +2 -2
- package/dist/browser.d.ts +4 -3
- package/dist/browser.js +603 -10
- package/dist/{camera-DVOiag0F.d.ts → camera-DcyxtBjK.d.ts} +1 -1
- package/dist/{chunk-WCWLYIVD.js → chunk-6WCS4TAT.js} +1 -1
- package/dist/{chunk-4SQ5YKKX.js → chunk-CX6IVI7I.js} +17 -4
- package/dist/{chunk-OWZWBKMI.js → chunk-LMFD5NP4.js} +31 -6
- package/dist/{chunk-EQBMPXB5.js → chunk-TNNJ7CAO.js} +52 -1
- package/dist/{chunk-L2CX7KWM.js → chunk-VXGQYUMN.js} +293 -45
- package/dist/cli.js +5 -5
- package/dist/{facts-BRIFxHL_.d.ts → facts-Dje5wcHh.d.ts} +1 -1
- package/dist/index.d.ts +71 -5
- package/dist/index.js +45 -3
- package/dist/node.d.ts +5 -3
- package/dist/node.js +4 -4
- package/dist/replay.d.ts +22 -2
- package/dist/{strip-Nt7eJ-4E.d.ts → strip-CA-IAT0N.d.ts} +74 -4
- package/dist/viewer.iife.js +504 -499
- package/package.json +3 -3
package/dist/browser.js
CHANGED
|
@@ -9,11 +9,12 @@ import {
|
|
|
9
9
|
replayPayload,
|
|
10
10
|
viewBoxOf,
|
|
11
11
|
viewToolbar
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-CX6IVI7I.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-
|
|
39
|
+
} from "./chunk-TNNJ7CAO.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;
|
|
@@ -142,7 +614,17 @@ function mountReplay(out, p, strip, opts = {}) {
|
|
|
142
614
|
scene.add(fill);
|
|
143
615
|
const nodes = /* @__PURE__ */ new Map();
|
|
144
616
|
const owned = [];
|
|
145
|
-
|
|
617
|
+
const rankOf = new Map(p.events.map((e) => [e.key, e.rank]));
|
|
618
|
+
const { faces, lines: outlines } = wallOutline(
|
|
619
|
+
p.nodes,
|
|
620
|
+
p.nodes.map((n) => rankOf.get(n.key) ?? 0)
|
|
621
|
+
);
|
|
622
|
+
const patched = [];
|
|
623
|
+
for (const [ni, node] of p.nodes.entries()) {
|
|
624
|
+
const outline = outlines[ni];
|
|
625
|
+
const fix = faces[ni];
|
|
626
|
+
const parts = faceParts(node, fix);
|
|
627
|
+
const n = { ...node, positions: parts.positions, indices: parts.base };
|
|
146
628
|
const pos = new Float32Array(n.positions.length);
|
|
147
629
|
let base = Infinity;
|
|
148
630
|
let topY = -Infinity;
|
|
@@ -180,16 +662,21 @@ function mountReplay(out, p, strip, opts = {}) {
|
|
|
180
662
|
// perspective.
|
|
181
663
|
polygonOffset: true,
|
|
182
664
|
polygonOffsetFactor: 1,
|
|
183
|
-
|
|
665
|
+
// A site surface (card RM8.3) lies in the plane of the slab's top and the ground's: pushed
|
|
666
|
+
// back further still, so the slab wins where a lawn runs under the building, and the ground
|
|
667
|
+
// (`GROUND_PLANE`) further than both.
|
|
668
|
+
polygonOffsetUnits: n.kind === "outdoor" ? 8 : flatLaid ? 4 : 1
|
|
184
669
|
});
|
|
185
670
|
owned.push(geo, mat);
|
|
186
|
-
|
|
671
|
+
const mesh = new Mesh(geo, mat);
|
|
672
|
+
g.add(mesh);
|
|
187
673
|
if (n.kind !== "slab" && !glass && edged) {
|
|
188
674
|
const edges = new EdgesGeometry(geo, 30);
|
|
189
675
|
const line = new LineBasicMaterial({ color: new Color(theme.edge) });
|
|
190
676
|
owned.push(edges, line);
|
|
191
677
|
g.add(new LineSegments(edges, line));
|
|
192
678
|
}
|
|
679
|
+
return mesh;
|
|
193
680
|
};
|
|
194
681
|
const attr = new BufferAttribute(pos, 3);
|
|
195
682
|
if (n.groups) {
|
|
@@ -203,6 +690,16 @@ function mountReplay(out, p, strip, opts = {}) {
|
|
|
203
690
|
add(attr, run, slotColour(slot, p.theme, furniture), alpha < 1, alpha, false);
|
|
204
691
|
}
|
|
205
692
|
}
|
|
693
|
+
} else if (n.colour) {
|
|
694
|
+
add(
|
|
695
|
+
attr,
|
|
696
|
+
n.indices,
|
|
697
|
+
siteColour(n.colour, p.theme, THEMES.dark.colors.floor),
|
|
698
|
+
false,
|
|
699
|
+
1,
|
|
700
|
+
true,
|
|
701
|
+
n.kind !== "fence"
|
|
702
|
+
);
|
|
206
703
|
} else if (n.finish) {
|
|
207
704
|
add(attr, n.indices, finishColour(n.finish, p.theme, THEMES.dark.colors.floor), false, 1, true);
|
|
208
705
|
} else if (key2 === "wall") {
|
|
@@ -213,11 +710,41 @@ function mountReplay(out, p, strip, opts = {}) {
|
|
|
213
710
|
const tri = n.indices.slice(i, i + 3);
|
|
214
711
|
(tri.every(atTop) ? cap : body).push(...tri);
|
|
215
712
|
}
|
|
216
|
-
add(attr, body, theme.colors.wall ?? furniture, false, 1, true);
|
|
713
|
+
add(attr, body, theme.colors.wall ?? furniture, false, 1, true, outline === void 0);
|
|
217
714
|
if (cap.length) add(attr, cap, theme.cap, false, 1, true, false);
|
|
218
715
|
} else {
|
|
219
716
|
const glass = key2 === "window:glass";
|
|
220
|
-
add(
|
|
717
|
+
add(
|
|
718
|
+
attr,
|
|
719
|
+
n.indices,
|
|
720
|
+
theme.colors[key2] ?? furniture,
|
|
721
|
+
glass,
|
|
722
|
+
glass ? KIND_PALETTE["window:glass"].alpha : 1,
|
|
723
|
+
true,
|
|
724
|
+
outline === void 0
|
|
725
|
+
);
|
|
726
|
+
}
|
|
727
|
+
if (fix && fix.group >= 0) {
|
|
728
|
+
const colour = theme.colors[key2] ?? furniture;
|
|
729
|
+
patched.push({
|
|
730
|
+
key: n.key,
|
|
731
|
+
...parts.alone.length > 0 ? { alone: add(attr, parts.alone, colour, false, 1, true, false) } : {},
|
|
732
|
+
...parts.joined.length > 0 ? { joined: add(attr, parts.joined, colour, false, 1, true, false) } : {},
|
|
733
|
+
group: fix.group
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
if (outline && outline.length > 0) {
|
|
737
|
+
const at = new Float32Array(outline.length);
|
|
738
|
+
for (let i = 0; i < outline.length; i += 3) {
|
|
739
|
+
at[i] = outline[i] / 1e3;
|
|
740
|
+
at[i + 1] = outline[i + 1] / 1e3 - base;
|
|
741
|
+
at[i + 2] = outline[i + 2] / 1e3;
|
|
742
|
+
}
|
|
743
|
+
const geo = new BufferGeometry();
|
|
744
|
+
geo.setAttribute("position", new BufferAttribute(at, 3));
|
|
745
|
+
const line = new LineBasicMaterial({ color: new Color(theme.edge) });
|
|
746
|
+
owned.push(geo, line);
|
|
747
|
+
g.add(new LineSegments(geo, line));
|
|
221
748
|
}
|
|
222
749
|
g.visible = false;
|
|
223
750
|
scene.add(g);
|
|
@@ -230,6 +757,38 @@ function mountReplay(out, p, strip, opts = {}) {
|
|
|
230
757
|
const lo = new Vector3(...box.lo);
|
|
231
758
|
const hi = new Vector3(...box.hi);
|
|
232
759
|
const top = hi.y + 1e3;
|
|
760
|
+
let ground;
|
|
761
|
+
let groundMat;
|
|
762
|
+
if (p.ground) {
|
|
763
|
+
const y = p.ground.y / 1e3;
|
|
764
|
+
const m = GROUND_PLANE.marginMm;
|
|
765
|
+
const [x0, z0, x1, z1] = [lo.x - m, lo.z - m, hi.x + m, hi.z + m];
|
|
766
|
+
const geo = new BufferGeometry();
|
|
767
|
+
geo.setAttribute(
|
|
768
|
+
"position",
|
|
769
|
+
new BufferAttribute(new Float32Array([x0, y, z0, x0, y, z1, x1, y, z1, x1, y, z0]), 3)
|
|
770
|
+
);
|
|
771
|
+
geo.setIndex([0, 1, 2, 0, 2, 3]);
|
|
772
|
+
const mat = new MeshLambertMaterial({
|
|
773
|
+
color: new Color(p.theme === "light" ? GROUND_PLANE.light : GROUND_PLANE.dark),
|
|
774
|
+
transparent: true,
|
|
775
|
+
opacity: 0,
|
|
776
|
+
depthWrite: true,
|
|
777
|
+
flatShading: true,
|
|
778
|
+
// Twice the slope term every other face takes, not only more units: seen at a slant a quad this
|
|
779
|
+
// size and a lawn in its plane rasterise to depths that differ by more than a few units, and a
|
|
780
|
+
// units-only margin let the ground win over whole lawns (rendered, card RM8.3).
|
|
781
|
+
polygonOffset: true,
|
|
782
|
+
polygonOffsetFactor: 2,
|
|
783
|
+
polygonOffsetUnits: 16
|
|
784
|
+
});
|
|
785
|
+
owned.push(geo, mat);
|
|
786
|
+
ground = new Mesh(geo, mat);
|
|
787
|
+
groundMat = mat;
|
|
788
|
+
ground.renderOrder = -1;
|
|
789
|
+
ground.visible = false;
|
|
790
|
+
scene.add(ground);
|
|
791
|
+
}
|
|
233
792
|
const ortho = new OrthographicCamera(-ow / 2, ow / 2, oh / 2, -oh / 2, 1, top + 1e5);
|
|
234
793
|
ortho.up.set(0, 0, -1);
|
|
235
794
|
ortho.position.set(cx, top + 5e4, cz);
|
|
@@ -301,17 +860,49 @@ function mountReplay(out, p, strip, opts = {}) {
|
|
|
301
860
|
const notify = () => {
|
|
302
861
|
for (const fn of listeners) fn();
|
|
303
862
|
};
|
|
863
|
+
const samples = Math.max(1, Math.min(4, Math.floor(p.supersample ?? 1)));
|
|
864
|
+
function supersampled(cam) {
|
|
865
|
+
const n = samples * samples;
|
|
866
|
+
const sum = new Uint32Array(W * H * 4);
|
|
867
|
+
ctx.globalAlpha = 1;
|
|
868
|
+
for (let j = 0; j < samples; j++) {
|
|
869
|
+
for (let i = 0; i < samples; i++) {
|
|
870
|
+
cam.setViewOffset(W, H, (i + 0.5) / samples - 0.5, (j + 0.5) / samples - 0.5, W, H);
|
|
871
|
+
renderer.render(scene, cam);
|
|
872
|
+
ctx.drawImage(gl, 0, 0);
|
|
873
|
+
const d = ctx.getImageData(0, 0, W, H).data;
|
|
874
|
+
for (let q = 0; q < d.length; q++) sum[q] = sum[q] + d[q];
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
cam.clearViewOffset();
|
|
878
|
+
const mean = ctx.createImageData(W, H);
|
|
879
|
+
for (let q = 0; q < sum.length; q++) mean.data[q] = Math.floor((sum[q] + (n >> 1)) / n);
|
|
880
|
+
ctx.putImageData(mean, 0, 0);
|
|
881
|
+
}
|
|
304
882
|
function draw(t) {
|
|
305
883
|
tNow = t;
|
|
306
884
|
drawn = true;
|
|
307
885
|
if (strip && p.facts) paintStrip(strip, stripAt(p.facts, p.events, Math.min(1, Math.max(0, t))));
|
|
308
886
|
const s = stateAt(p.events, t);
|
|
887
|
+
if (ground && groundMat) {
|
|
888
|
+
ground.visible = s.ground > 0;
|
|
889
|
+
groundMat.opacity = s.ground;
|
|
890
|
+
}
|
|
309
891
|
for (const [key2, { g, flat, base, lift }] of nodes) {
|
|
310
892
|
const st = s.nodes.get(key2);
|
|
311
893
|
g.visible = st?.visible === true && (storeyOf.get(key2) ?? 0) < shown;
|
|
312
894
|
g.scale.y = Math.max(flat, st?.rise ?? 0);
|
|
313
895
|
if (lift !== 0) g.position.y = base + settledLift(lift, s.settle);
|
|
314
896
|
}
|
|
897
|
+
const together = joinedGroups(faces, (i) => {
|
|
898
|
+
const key2 = p.nodes[i]?.key ?? "";
|
|
899
|
+
return nodes.get(key2)?.g.visible === true && (s.nodes.get(key2)?.rise ?? 0) >= 1;
|
|
900
|
+
});
|
|
901
|
+
for (const { group, alone, joined } of patched) {
|
|
902
|
+
const t2 = together.has(group);
|
|
903
|
+
if (alone) alone.visible = !t2;
|
|
904
|
+
if (joined) joined.visible = t2;
|
|
905
|
+
}
|
|
315
906
|
let cam = ortho;
|
|
316
907
|
if (holder === "free" && controls) {
|
|
317
908
|
const dist = persp.position.distanceTo(controls.target);
|
|
@@ -328,9 +919,11 @@ function mountReplay(out, p, strip, opts = {}) {
|
|
|
328
919
|
place(frameCamera(s, fits, frameView), s.settle > 0 ? endRadius : radius);
|
|
329
920
|
cam = persp;
|
|
330
921
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
922
|
+
if (samples === 1) {
|
|
923
|
+
renderer.render(scene, cam);
|
|
924
|
+
ctx.globalAlpha = 1;
|
|
925
|
+
ctx.drawImage(gl, 0, 0);
|
|
926
|
+
} else supersampled(cam);
|
|
334
927
|
if (holder === "replay" && s.svg > 0 && img.complete && img.naturalWidth > 0) {
|
|
335
928
|
const k = Math.min(W / vw, H / vh);
|
|
336
929
|
const dw = vw * k;
|