@chanmeng666/archlang-3d 0.7.0 → 0.8.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 +91 -0
- package/README.md +4 -4
- package/dist/browser.d.ts +3 -5
- package/dist/browser.js +87 -472
- package/dist/{camera-CGIIudHj.d.ts → camera-BAsRq_eC.d.ts} +1 -1
- package/dist/{chunk-GXWLZ2KC.js → chunk-33J3YGNF.js} +392 -29
- package/dist/{chunk-QN4LQTVG.js → chunk-CYSES7C3.js} +128 -44
- package/dist/chunk-JQTG6BDR.js +1127 -0
- package/dist/{chunk-TI4RYEOL.js → chunk-LNIVDMPG.js} +75 -5
- package/dist/{chunk-FHBR2U5Z.js → chunk-VMVKI2WQ.js} +65 -3
- package/dist/{chunk-FVD3DZU2.js → chunk-WOEJKIXN.js} +15 -6
- package/dist/cli.js +12 -6
- package/dist/{facts-3wb9egIT.d.ts → facts-CsO0xtFw.d.ts} +1 -1
- package/dist/index.d.ts +104 -35
- package/dist/index.js +19 -5
- package/dist/node.d.ts +23 -7
- package/dist/node.js +4 -4
- package/dist/{strip-Sdsm54Qw.d.ts → payload-DwiB2P7x.d.ts} +232 -12
- package/dist/replay.d.ts +1 -115
- package/dist/scene3d.schema.json +12 -0
- package/dist/viewer.iife.js +180 -180
- package/package.json +3 -3
|
@@ -0,0 +1,1127 @@
|
|
|
1
|
+
import {
|
|
2
|
+
C16,
|
|
3
|
+
CONTACT_SHADOW,
|
|
4
|
+
S16,
|
|
5
|
+
ease
|
|
6
|
+
} from "./chunk-LNIVDMPG.js";
|
|
7
|
+
|
|
8
|
+
// src/replay/wall-lines.ts
|
|
9
|
+
function takesWallLines(n) {
|
|
10
|
+
return n.kind === "wall" && n.part === void 0 || n.kind === "column";
|
|
11
|
+
}
|
|
12
|
+
var EXACT = 2 ** 26;
|
|
13
|
+
function det(a, b, c, d) {
|
|
14
|
+
if (Math.abs(a) < EXACT && Math.abs(b) < EXACT && Math.abs(c) < EXACT && Math.abs(d) < EXACT) return a * d - b * c;
|
|
15
|
+
const r = BigInt(a) * BigInt(d) - BigInt(b) * BigInt(c);
|
|
16
|
+
return r > 0n ? 1 : r < 0n ? -1 : 0;
|
|
17
|
+
}
|
|
18
|
+
function detKey(a, b, c, d) {
|
|
19
|
+
if (Math.abs(a) < EXACT && Math.abs(b) < EXACT && Math.abs(c) < EXACT && Math.abs(d) < EXACT)
|
|
20
|
+
return String(a * d - b * c);
|
|
21
|
+
return (BigInt(a) * BigInt(d) - BigInt(b) * BigInt(c)).toString();
|
|
22
|
+
}
|
|
23
|
+
function gcd(a, b) {
|
|
24
|
+
let x = Math.abs(a);
|
|
25
|
+
let y = Math.abs(b);
|
|
26
|
+
while (y !== 0) [x, y] = [y, x % y];
|
|
27
|
+
return x;
|
|
28
|
+
}
|
|
29
|
+
function nearlyFlat(p, q, fp, fq) {
|
|
30
|
+
const d = BigInt(p[0]) * BigInt(q[0]) + BigInt(p[1]) * BigInt(q[1]);
|
|
31
|
+
const c = BigInt(p[0]) * BigInt(q[1]) - BigInt(p[1]) * BigInt(q[0]);
|
|
32
|
+
const s = fp * fq > 0 ? d : -d;
|
|
33
|
+
return s > 0n && s * s > 3n * c * c;
|
|
34
|
+
}
|
|
35
|
+
function planLine(x0, z0, x1, z1) {
|
|
36
|
+
let dx = x1 - x0;
|
|
37
|
+
let dz = z1 - z0;
|
|
38
|
+
const g = gcd(dx, dz);
|
|
39
|
+
dx /= g;
|
|
40
|
+
dz /= g;
|
|
41
|
+
if (dx < 0 || dx === 0 && dz < 0) {
|
|
42
|
+
dx = 0 - dx;
|
|
43
|
+
dz = 0 - dz;
|
|
44
|
+
}
|
|
45
|
+
return { dx, dz, key: `${dx},${dz},${detKey(dx, dz, x0, z0)}` };
|
|
46
|
+
}
|
|
47
|
+
var lexLess = (a, b) => {
|
|
48
|
+
for (let i = 0; i < a.length; i++) {
|
|
49
|
+
const d = a[i] - b[i];
|
|
50
|
+
if (d !== 0) return d;
|
|
51
|
+
}
|
|
52
|
+
return 0;
|
|
53
|
+
};
|
|
54
|
+
var sortedKeys = (m) => [...m.keys()].sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
55
|
+
var sortedUnique = (xs) => {
|
|
56
|
+
const s = [...xs].sort((a, b) => a - b);
|
|
57
|
+
let n = 0;
|
|
58
|
+
for (let i = 0; i < s.length; i++) if (i === 0 || s[i] !== s[n - 1]) s[n++] = s[i];
|
|
59
|
+
s.length = n;
|
|
60
|
+
return s;
|
|
61
|
+
};
|
|
62
|
+
function extent(xs) {
|
|
63
|
+
let lo = Infinity;
|
|
64
|
+
let hi = -Infinity;
|
|
65
|
+
for (const x of xs) {
|
|
66
|
+
if (x < lo) lo = x;
|
|
67
|
+
if (x > hi) hi = x;
|
|
68
|
+
}
|
|
69
|
+
return [lo, hi];
|
|
70
|
+
}
|
|
71
|
+
function lastRaised(nodes, rank) {
|
|
72
|
+
let best = -1;
|
|
73
|
+
for (const n of nodes) {
|
|
74
|
+
if (best < 0) best = n;
|
|
75
|
+
else {
|
|
76
|
+
const rn = rank?.[n] ?? 0;
|
|
77
|
+
const rb = rank?.[best] ?? 0;
|
|
78
|
+
if (rn > rb || rn === rb && n < best) best = n;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return best;
|
|
82
|
+
}
|
|
83
|
+
function byStorey(nodes) {
|
|
84
|
+
const storeys = /* @__PURE__ */ new Map();
|
|
85
|
+
nodes.forEach((n, i) => {
|
|
86
|
+
if (!takesWallLines(n)) return;
|
|
87
|
+
const level = /^L(-?\d+)\//.exec(n.key)?.[1] ?? "";
|
|
88
|
+
const members = storeys.get(level);
|
|
89
|
+
if (members) members.push(i);
|
|
90
|
+
else storeys.set(level, [i]);
|
|
91
|
+
});
|
|
92
|
+
return sortedKeys(storeys).map((k) => storeys.get(k) ?? []);
|
|
93
|
+
}
|
|
94
|
+
function wallOutline(nodes, rank) {
|
|
95
|
+
const faces = wallFaces(nodes);
|
|
96
|
+
const drawn = nodes.map((n, i) => takesWallLines(n) ? { ...n, ...withFaces(n, faces[i]) } : n);
|
|
97
|
+
return { faces, lines: linesOf(drawn, rank) };
|
|
98
|
+
}
|
|
99
|
+
function linesOf(nodes, rank) {
|
|
100
|
+
const out = nodes.map((n) => takesWallLines(n) ? [] : void 0);
|
|
101
|
+
const segs = nodes.map(() => []);
|
|
102
|
+
for (const members of byStorey(nodes)) storeyLines(nodes, members, segs, rank);
|
|
103
|
+
segs.forEach((list, i) => {
|
|
104
|
+
if (!out[i]) return;
|
|
105
|
+
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);
|
|
106
|
+
out[i] = sorted.flat();
|
|
107
|
+
});
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
function sweep(items, visit) {
|
|
111
|
+
const byStart = items.map((it, i) => [it, i]).sort((a, b) => a[0].t0 - b[0].t0 || a[1] - b[1]);
|
|
112
|
+
const ts = sortedUnique(items.flatMap((e) => [e.t0, e.t1]));
|
|
113
|
+
let next = 0;
|
|
114
|
+
let on = [];
|
|
115
|
+
for (let j = 0; j + 1 < ts.length; j++) {
|
|
116
|
+
const t0 = ts[j];
|
|
117
|
+
const t1 = ts[j + 1];
|
|
118
|
+
if (on.some((e) => e.t1 <= t0)) on = on.filter((e) => e.t1 > t0);
|
|
119
|
+
while (next < byStart.length && byStart[next]?.[0].t0 <= t0) on.push(byStart[next++]?.[0]);
|
|
120
|
+
if (on.length > 0) visit(t0, t1, on);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function storeyLines(nodes, members, segs, rank) {
|
|
124
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
125
|
+
const lines = /* @__PURE__ */ new Map();
|
|
126
|
+
const dirs = /* @__PURE__ */ new Map();
|
|
127
|
+
const pairs = /* @__PURE__ */ new Map();
|
|
128
|
+
const push = (plane, line, e) => {
|
|
129
|
+
const key = `${plane}|${line}`;
|
|
130
|
+
const b = buckets.get(key);
|
|
131
|
+
if (b) b.edges.push(e);
|
|
132
|
+
else buckets.set(key, { line, plane, edges: [e] });
|
|
133
|
+
};
|
|
134
|
+
const pair = (plane, p, q, node) => {
|
|
135
|
+
const fwd = lexLess(p, q) < 0;
|
|
136
|
+
const [a, b] = fwd ? [p, q] : [q, p];
|
|
137
|
+
const key = `${plane}|${a[0]},${a[1]},${a[2]}|${b[0]},${b[1]},${b[2]}`;
|
|
138
|
+
const was = pairs.get(key);
|
|
139
|
+
if (was) {
|
|
140
|
+
was.net += fwd ? 1 : -1;
|
|
141
|
+
was.nodes.push(node);
|
|
142
|
+
} else pairs.set(key, { a, b, net: fwd ? 1 : -1, nodes: [node] });
|
|
143
|
+
};
|
|
144
|
+
const horizontal = (y, pl, p, q) => {
|
|
145
|
+
const key = `h${y}:${pl.key}`;
|
|
146
|
+
let at = lines.get(key);
|
|
147
|
+
if (!at) {
|
|
148
|
+
at = { kind: "horizontal", y, alongX: pl.dx !== 0, other: /* @__PURE__ */ new Map() };
|
|
149
|
+
lines.set(key, at);
|
|
150
|
+
}
|
|
151
|
+
if (at.kind === "horizontal") {
|
|
152
|
+
for (const r of [p, q]) {
|
|
153
|
+
const [x, , z] = r;
|
|
154
|
+
if (at.alongX) at.other.set(x, z);
|
|
155
|
+
else at.other.set(z, x);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return key;
|
|
159
|
+
};
|
|
160
|
+
const along = (pl, p) => pl.dx !== 0 ? p[0] : p[2];
|
|
161
|
+
const edge = (t0, t1, node, f) => t0 < t1 ? { t0, t1, k: 1, node, f } : { t0: t1, t1: t0, k: -1, node, f };
|
|
162
|
+
for (const ni of members) {
|
|
163
|
+
const n = nodes[ni];
|
|
164
|
+
const P = (v) => [
|
|
165
|
+
Math.round(n.positions[v * 3]),
|
|
166
|
+
Math.round(n.positions[v * 3 + 1]),
|
|
167
|
+
Math.round(n.positions[v * 3 + 2])
|
|
168
|
+
];
|
|
169
|
+
for (let i = 0; i + 2 < n.indices.length; i += 3) {
|
|
170
|
+
const tri = [P(n.indices[i]), P(n.indices[i + 1]), P(n.indices[i + 2])];
|
|
171
|
+
const [a, b, c] = tri;
|
|
172
|
+
const ax = a[0];
|
|
173
|
+
const ay = a[1];
|
|
174
|
+
const az = a[2];
|
|
175
|
+
const sides = [
|
|
176
|
+
[a, b],
|
|
177
|
+
[b, c],
|
|
178
|
+
[c, a]
|
|
179
|
+
];
|
|
180
|
+
if (ay === b[1] && ay === c[1]) {
|
|
181
|
+
if (det(b[0] - ax, b[2] - az, c[0] - ax, c[2] - az) === 0)
|
|
182
|
+
continue;
|
|
183
|
+
const plane2 = `H${ay}`;
|
|
184
|
+
for (const [p, q] of sides) {
|
|
185
|
+
if (p[0] === q[0] && p[2] === q[2]) continue;
|
|
186
|
+
const pl2 = planLine(p[0], p[2], q[0], q[2]);
|
|
187
|
+
push(plane2, horizontal(ay, pl2, p, q), edge(along(pl2, p), along(pl2, q), ni, 0));
|
|
188
|
+
}
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
const flatInPlan = det(b[0] - ax, b[2] - az, c[0] - ax, c[2] - az) === 0;
|
|
192
|
+
if (!flatInPlan) {
|
|
193
|
+
for (const [p, q] of sides) segs[ni].push([...p, ...q]);
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
const far = a[0] !== b[0] || a[2] !== b[2] ? b : c;
|
|
197
|
+
if (far[0] === ax && far[2] === az) continue;
|
|
198
|
+
const pl = planLine(ax, az, far[0], far[2]);
|
|
199
|
+
const plane = `V${pl.key}`;
|
|
200
|
+
if (!dirs.has(plane)) dirs.set(plane, [pl.dx, pl.dz]);
|
|
201
|
+
const s = (p) => along(pl, p);
|
|
202
|
+
const turn = det(s(b) - s(a), b[1] - ay, s(c) - s(a), c[1] - ay);
|
|
203
|
+
if (turn === 0) continue;
|
|
204
|
+
const f = turn > 0 ? 1 : -1;
|
|
205
|
+
for (const [p, q] of sides) {
|
|
206
|
+
if (p[0] === q[0] && p[2] === q[2]) {
|
|
207
|
+
if (p[1] === q[1]) continue;
|
|
208
|
+
const key = `v${p[0]},${p[2]}`;
|
|
209
|
+
if (!lines.has(key)) lines.set(key, { kind: "vertical", x: p[0], z: p[2] });
|
|
210
|
+
push(plane, key, edge(p[1], q[1], ni, f));
|
|
211
|
+
} else if (p[1] === q[1]) {
|
|
212
|
+
push(plane, horizontal(p[1], pl, p, q), edge(along(pl, p), along(pl, q), ni, f));
|
|
213
|
+
} else pair(plane, p, q, ni);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const bounds = /* @__PURE__ */ new Map();
|
|
218
|
+
for (const key of sortedKeys(buckets)) {
|
|
219
|
+
const { line, plane, edges } = buckets.get(key);
|
|
220
|
+
const [e0, e1] = edges;
|
|
221
|
+
if (edges.length === 2 && e1 && e0.t0 === e1.t0 && e0.t1 === e1.t1 && e0.k !== e1.k) continue;
|
|
222
|
+
sweep(edges, (t0, t1, on) => {
|
|
223
|
+
let m = 0;
|
|
224
|
+
for (const e of on) m += e.k;
|
|
225
|
+
if (m === 0) return;
|
|
226
|
+
const nets = /* @__PURE__ */ new Map();
|
|
227
|
+
for (const e of on) nets.set(e.node, (nets.get(e.node) ?? 0) + e.k);
|
|
228
|
+
const by = sortedUnique(on.filter((e) => nets.get(e.node) !== 0).map((e) => e.node));
|
|
229
|
+
const fs = sortedUnique(on.filter((e) => e.k === Math.sign(m)).map((e) => e.f));
|
|
230
|
+
const b = { t0, t1, nodes: by, plane, f: fs.length === 1 ? fs[0] : 0 };
|
|
231
|
+
const list = bounds.get(line);
|
|
232
|
+
if (list) list.push(b);
|
|
233
|
+
else bounds.set(line, [b]);
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
for (const line of sortedKeys(bounds)) {
|
|
237
|
+
const list = bounds.get(line);
|
|
238
|
+
const at = lines.get(line);
|
|
239
|
+
const runs = [];
|
|
240
|
+
sweep(list, (t0, t1, on) => {
|
|
241
|
+
if (at.kind === "vertical" && on.length === 2) {
|
|
242
|
+
const [p, q] = on;
|
|
243
|
+
const dp = dirs.get(p.plane);
|
|
244
|
+
const dq = dirs.get(q.plane);
|
|
245
|
+
if (dp && dq && p.f !== 0 && q.f !== 0 && nearlyFlat(dp, dq, p.f, q.f)) return;
|
|
246
|
+
}
|
|
247
|
+
const node = lastRaised(
|
|
248
|
+
on.flatMap((b) => b.nodes),
|
|
249
|
+
rank
|
|
250
|
+
);
|
|
251
|
+
const last = runs[runs.length - 1];
|
|
252
|
+
if (last && last.t1 === t0 && last.node === node) last.t1 = t1;
|
|
253
|
+
else runs.push({ t0, t1, node });
|
|
254
|
+
});
|
|
255
|
+
for (const r of runs) {
|
|
256
|
+
const end = (t) => {
|
|
257
|
+
if (at.kind === "vertical") return [at.x, t, at.z];
|
|
258
|
+
const o = at.other.get(t);
|
|
259
|
+
return at.alongX ? [t, at.y, o] : [o, at.y, t];
|
|
260
|
+
};
|
|
261
|
+
segs[r.node].push([...end(r.t0), ...end(r.t1)]);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
for (const key of sortedKeys(pairs)) {
|
|
265
|
+
const { a, b, net, nodes: by } = pairs.get(key);
|
|
266
|
+
if (net === 0) continue;
|
|
267
|
+
segs[lastRaised(by, rank)].push([...a, ...b]);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function joinedGroups(fixes, standing) {
|
|
271
|
+
const up = /* @__PURE__ */ new Map();
|
|
272
|
+
fixes.forEach((f, i) => {
|
|
273
|
+
if (f && f.group >= 0) up.set(f.group, (up.get(f.group) ?? true) && standing(i));
|
|
274
|
+
});
|
|
275
|
+
const out = /* @__PURE__ */ new Set();
|
|
276
|
+
for (const [g, v] of up) if (v) out.add(g);
|
|
277
|
+
return out;
|
|
278
|
+
}
|
|
279
|
+
function wallFaces(nodes) {
|
|
280
|
+
const out = nodes.map(
|
|
281
|
+
(n) => takesWallLines(n) ? { hide: [], add: [], alone: [], joined: [], group: -1 } : void 0
|
|
282
|
+
);
|
|
283
|
+
const root = nodes.map((_, i) => i);
|
|
284
|
+
const find = (i) => {
|
|
285
|
+
let r = i;
|
|
286
|
+
while (root[r] !== r) r = root[r];
|
|
287
|
+
while (root[i] !== r) [i, root[i]] = [root[i], r];
|
|
288
|
+
return r;
|
|
289
|
+
};
|
|
290
|
+
const join = (a, b) => {
|
|
291
|
+
const ra = find(a);
|
|
292
|
+
const rb = find(b);
|
|
293
|
+
if (ra < rb) root[rb] = ra;
|
|
294
|
+
else if (rb < ra) root[ra] = rb;
|
|
295
|
+
};
|
|
296
|
+
const shared = /* @__PURE__ */ new Set();
|
|
297
|
+
for (const members of byStorey(nodes)) storeyFaces(nodes, members, out, join, shared);
|
|
298
|
+
out.forEach((f, i) => {
|
|
299
|
+
if (!f) return;
|
|
300
|
+
f.hide.sort((a, b) => a - b);
|
|
301
|
+
if (shared.has(i)) f.group = find(i);
|
|
302
|
+
});
|
|
303
|
+
return out;
|
|
304
|
+
}
|
|
305
|
+
function faceParts(n, fix) {
|
|
306
|
+
if (!fix) return { positions: n.positions, base: [...n.indices], alone: [], joined: [] };
|
|
307
|
+
const hidden = new Set(fix.hide);
|
|
308
|
+
const base = [];
|
|
309
|
+
for (let i = 0; i + 2 < n.indices.length; i += 3) {
|
|
310
|
+
if (!hidden.has(i / 3)) base.push(n.indices[i], n.indices[i + 1], n.indices[i + 2]);
|
|
311
|
+
}
|
|
312
|
+
let v = n.positions.length / 3;
|
|
313
|
+
const run = (flat, to = []) => {
|
|
314
|
+
for (let k = 0; k < flat.length / 3; k++) to.push(v++);
|
|
315
|
+
return to;
|
|
316
|
+
};
|
|
317
|
+
run(fix.add, base);
|
|
318
|
+
const alone = run(fix.alone);
|
|
319
|
+
const joined = run(fix.joined);
|
|
320
|
+
return { positions: n.positions.concat(fix.add, fix.alone, fix.joined), base, alone, joined };
|
|
321
|
+
}
|
|
322
|
+
function withFaces(n, fix, mode = "joined") {
|
|
323
|
+
if (!fix) return { positions: n.positions, indices: n.indices };
|
|
324
|
+
const parts = faceParts(n, fix);
|
|
325
|
+
return { positions: parts.positions, indices: parts.base.concat(mode === "joined" ? parts.joined : parts.alone) };
|
|
326
|
+
}
|
|
327
|
+
function contested(tris) {
|
|
328
|
+
const boxes = tris.map((t) => {
|
|
329
|
+
const [s0, s1] = extent(t.s);
|
|
330
|
+
const [y0, y1] = extent(t.p.map((q) => q[1]));
|
|
331
|
+
return { s0, s1, y0, y1, f: t.f };
|
|
332
|
+
});
|
|
333
|
+
boxes.sort((a, b) => a.s0 - b.s0);
|
|
334
|
+
let up = [];
|
|
335
|
+
let down = [];
|
|
336
|
+
for (const b of boxes) {
|
|
337
|
+
if (up.some((o) => o.s1 <= b.s0)) up = up.filter((o) => o.s1 > b.s0);
|
|
338
|
+
if (down.some((o) => o.s1 <= b.s0)) down = down.filter((o) => o.s1 > b.s0);
|
|
339
|
+
const other = b.f > 0 ? down : up;
|
|
340
|
+
if (other.some((o) => Math.min(o.y1, b.y1) > Math.max(o.y0, b.y0))) return true;
|
|
341
|
+
(b.f > 0 ? up : down).push(b);
|
|
342
|
+
}
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
345
|
+
function storeyFaces(nodes, members, out, join, shared) {
|
|
346
|
+
const planes = /* @__PURE__ */ new Map();
|
|
347
|
+
for (const ni of members) {
|
|
348
|
+
const n = nodes[ni];
|
|
349
|
+
const P = (v) => [
|
|
350
|
+
Math.round(n.positions[v * 3]),
|
|
351
|
+
Math.round(n.positions[v * 3 + 1]),
|
|
352
|
+
Math.round(n.positions[v * 3 + 2])
|
|
353
|
+
];
|
|
354
|
+
for (let i = 0; i + 2 < n.indices.length; i += 3) {
|
|
355
|
+
const a = P(n.indices[i]);
|
|
356
|
+
const b = P(n.indices[i + 1]);
|
|
357
|
+
const c = P(n.indices[i + 2]);
|
|
358
|
+
const ax = a[0];
|
|
359
|
+
const ay = a[1];
|
|
360
|
+
const az = a[2];
|
|
361
|
+
if (ay === b[1] && ay === c[1]) continue;
|
|
362
|
+
if (det(b[0] - ax, b[2] - az, c[0] - ax, c[2] - az) !== 0)
|
|
363
|
+
continue;
|
|
364
|
+
const far = a[0] !== b[0] || a[2] !== b[2] ? b : c;
|
|
365
|
+
if (far[0] === ax && far[2] === az) continue;
|
|
366
|
+
const pl = planLine(ax, az, far[0], far[2]);
|
|
367
|
+
const along = (p) => pl.dx !== 0 ? p[0] : p[2];
|
|
368
|
+
const s = [along(a), along(b), along(c)];
|
|
369
|
+
const turn = det(
|
|
370
|
+
s[1] - s[0],
|
|
371
|
+
b[1] - ay,
|
|
372
|
+
s[2] - s[0],
|
|
373
|
+
c[1] - ay
|
|
374
|
+
);
|
|
375
|
+
if (turn === 0) continue;
|
|
376
|
+
const key = `V${pl.key}`;
|
|
377
|
+
const t = { node: ni, tri: i / 3, p: [a, b, c], f: turn > 0 ? 1 : -1, s };
|
|
378
|
+
const plane = planes.get(key);
|
|
379
|
+
if (plane) plane.tris.push(t);
|
|
380
|
+
else planes.set(key, { pl, tris: [t] });
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
for (const key of sortedKeys(planes)) {
|
|
384
|
+
const { tris } = planes.get(key);
|
|
385
|
+
if (!contested(tris)) continue;
|
|
386
|
+
const S = sortedUnique(tris.flatMap((t) => t.s));
|
|
387
|
+
const Y = sortedUnique(tris.flatMap((t) => t.p.map((q) => q[1])));
|
|
388
|
+
const where = /* @__PURE__ */ new Map();
|
|
389
|
+
for (const t of tris) for (let k = 0; k < 3; k++) where.set(t.s[k], t.p[k]);
|
|
390
|
+
const sAt = new Map(S.map((s, i) => [s, i]));
|
|
391
|
+
const yAt = new Map(Y.map((y, j) => [y, j]));
|
|
392
|
+
const ny = Y.length - 1;
|
|
393
|
+
const steps = S.map(() => []);
|
|
394
|
+
for (const t of tris) {
|
|
395
|
+
for (let k = 0; k < 3; k++) {
|
|
396
|
+
const p = t.p[k];
|
|
397
|
+
const q = t.p[(k + 1) % 3];
|
|
398
|
+
if (p[0] !== q[0] || p[2] !== q[2] || p[1] === q[1]) continue;
|
|
399
|
+
const i = sAt.get(t.s[k]);
|
|
400
|
+
const lo = Math.min(p[1], q[1]);
|
|
401
|
+
const hi = Math.max(p[1], q[1]);
|
|
402
|
+
steps[i].push([
|
|
403
|
+
t.node,
|
|
404
|
+
yAt.get(lo),
|
|
405
|
+
yAt.get(hi),
|
|
406
|
+
q[1] > p[1] ? 1 : -1
|
|
407
|
+
]);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
const wind = /* @__PURE__ */ new Map();
|
|
411
|
+
const nonzero = /* @__PURE__ */ new Map();
|
|
412
|
+
let live = [];
|
|
413
|
+
const total = new Int32Array(ny);
|
|
414
|
+
const cell = (to, s0, s1, j, facing) => {
|
|
415
|
+
const y0 = Y[j];
|
|
416
|
+
const y1 = Y[j + 1];
|
|
417
|
+
const at = (s, y) => {
|
|
418
|
+
const q = where.get(s);
|
|
419
|
+
return [q[0], y, q[2]];
|
|
420
|
+
};
|
|
421
|
+
const [p00, p10, p11, p01] = [at(s0, y0), at(s1, y0), at(s1, y1), at(s0, y1)];
|
|
422
|
+
if (facing > 0) to.push(...p00, ...p10, ...p11, ...p00, ...p11, ...p01);
|
|
423
|
+
else to.push(...p00, ...p11, ...p10, ...p00, ...p01, ...p11);
|
|
424
|
+
};
|
|
425
|
+
for (let i = 0; i + 1 < S.length; i++) {
|
|
426
|
+
const here = steps[i];
|
|
427
|
+
for (const [o, j0, j1, d] of here) {
|
|
428
|
+
let w = wind.get(o);
|
|
429
|
+
if (!w) {
|
|
430
|
+
w = new Int32Array(ny);
|
|
431
|
+
wind.set(o, w);
|
|
432
|
+
}
|
|
433
|
+
let nz = nonzero.get(o) ?? 0;
|
|
434
|
+
for (let j = j0; j < j1; j++) {
|
|
435
|
+
const was = w[j];
|
|
436
|
+
const now = was - d;
|
|
437
|
+
w[j] = now;
|
|
438
|
+
total[j] = total[j] - d;
|
|
439
|
+
if (was === 0) nz++;
|
|
440
|
+
else if (now === 0) nz--;
|
|
441
|
+
}
|
|
442
|
+
nonzero.set(o, nz);
|
|
443
|
+
}
|
|
444
|
+
if (here.length > 0) {
|
|
445
|
+
for (const o of [...wind.keys()]) {
|
|
446
|
+
if (nonzero.get(o) === 0) {
|
|
447
|
+
wind.delete(o);
|
|
448
|
+
nonzero.delete(o);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
live = [...wind.keys()].sort((a, b) => a - b);
|
|
452
|
+
}
|
|
453
|
+
const s0 = S[i];
|
|
454
|
+
const s1 = S[i + 1];
|
|
455
|
+
for (let j = 0; j < ny; j++) {
|
|
456
|
+
const over = live.filter((o) => wind.get(o)[j] !== 0);
|
|
457
|
+
if (over.length === 0) continue;
|
|
458
|
+
if (over.length === 1) {
|
|
459
|
+
const o = over[0];
|
|
460
|
+
cell(out[o].add, s0, s1, j, wind.get(o)[j]);
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
for (const o of over) {
|
|
464
|
+
cell(out[o].alone, s0, s1, j, wind.get(o)[j]);
|
|
465
|
+
shared.add(o);
|
|
466
|
+
join(o, over[0]);
|
|
467
|
+
}
|
|
468
|
+
const sum = total[j];
|
|
469
|
+
if (sum === 0) continue;
|
|
470
|
+
const owner = over.find((o) => Math.sign(wind.get(o)[j]) === Math.sign(sum));
|
|
471
|
+
cell(out[owner].joined, s0, s1, j, sum);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
for (const t of tris) out[t.node].hide.push(t.tri);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// src/replay/shadows.ts
|
|
479
|
+
var cross = (ux, uz, vx, vz) => det(ux, uz, vx, vz);
|
|
480
|
+
var levelOf = (key) => Number(/^L(-?\d+)\//.exec(key)?.[1] ?? 0);
|
|
481
|
+
var whole = (x) => Math.round(x) + 0;
|
|
482
|
+
var lengthOf = (dx, dz) => Math.sqrt(Number(BigInt(dx) * BigInt(dx) + BigInt(dz) * BigInt(dz)));
|
|
483
|
+
function contactFade(ev, u) {
|
|
484
|
+
if (!ev || ev.hidden) return 0;
|
|
485
|
+
const span = ev.riseTo - ev.riseFrom;
|
|
486
|
+
if (span <= 0) return u >= ev.riseTo ? 1 : 0;
|
|
487
|
+
const q = span / 4;
|
|
488
|
+
return ease((u - (ev.riseTo - q)) / q);
|
|
489
|
+
}
|
|
490
|
+
function contains(f, q) {
|
|
491
|
+
const s1 = cross(f.b[0] - f.a[0], f.b[1] - f.a[1], q[0] - f.a[0], q[1] - f.a[1]);
|
|
492
|
+
const s2 = cross(f.c[0] - f.b[0], f.c[1] - f.b[1], q[0] - f.b[0], q[1] - f.b[1]);
|
|
493
|
+
const s3 = cross(f.a[0] - f.c[0], f.a[1] - f.c[1], q[0] - f.c[0], q[1] - f.c[1]);
|
|
494
|
+
return s1 >= 0 && s2 >= 0 && s3 >= 0 || s1 <= 0 && s2 <= 0 && s3 <= 0;
|
|
495
|
+
}
|
|
496
|
+
var CELLS_PER_TRI = 2;
|
|
497
|
+
var CELLS_MAX = 1 << 16;
|
|
498
|
+
function overlaps(t, x0, z0, x1, z1) {
|
|
499
|
+
return Math.max(t.a[0], t.b[0], t.c[0]) >= x0 && Math.min(t.a[0], t.b[0], t.c[0]) <= x1 && Math.max(t.a[1], t.b[1], t.c[1]) >= z0 && Math.min(t.a[1], t.b[1], t.c[1]) <= z1 && !separates(t.a, t.b, t.c, x0, z0, x1, z1) && !separates(t.b, t.c, t.a, x0, z0, x1, z1) && !separates(t.c, t.a, t.b, x0, z0, x1, z1);
|
|
500
|
+
}
|
|
501
|
+
function separates(p, q, r, x0, z0, x1, z1) {
|
|
502
|
+
const ux = q[0] - p[0];
|
|
503
|
+
const uz = q[1] - p[1];
|
|
504
|
+
const side = Math.sign(cross(ux, uz, r[0] - p[0], r[1] - p[1]));
|
|
505
|
+
if (side === 0) return false;
|
|
506
|
+
return side * cross(ux, uz, x0 - p[0], z0 - p[1]) < 0 && side * cross(ux, uz, x1 - p[0], z0 - p[1]) < 0 && side * cross(ux, uz, x1 - p[0], z1 - p[1]) < 0 && side * cross(ux, uz, x0 - p[0], z1 - p[1]) < 0;
|
|
507
|
+
}
|
|
508
|
+
var TriGrid = class {
|
|
509
|
+
/** The grid's corner, its cells' size and their count across and down (µm; read by the tests). */
|
|
510
|
+
x0;
|
|
511
|
+
z0;
|
|
512
|
+
w;
|
|
513
|
+
h;
|
|
514
|
+
kx;
|
|
515
|
+
kz;
|
|
516
|
+
/** Each cell's triangles (a hole where a cell has none). */
|
|
517
|
+
cells;
|
|
518
|
+
constructor(tris) {
|
|
519
|
+
let [x0, z0, x1, z1] = [Infinity, Infinity, -Infinity, -Infinity];
|
|
520
|
+
for (const t of tris)
|
|
521
|
+
for (const p of [t.a, t.b, t.c]) {
|
|
522
|
+
if (p[0] < x0) x0 = p[0];
|
|
523
|
+
if (p[0] > x1) x1 = p[0];
|
|
524
|
+
if (p[1] < z0) z0 = p[1];
|
|
525
|
+
if (p[1] > z1) z1 = p[1];
|
|
526
|
+
}
|
|
527
|
+
this.x0 = x0;
|
|
528
|
+
this.z0 = z0;
|
|
529
|
+
if (tris.length === 0) {
|
|
530
|
+
[this.kx, this.kz, this.w, this.h] = [0, 0, 1, 1];
|
|
531
|
+
this.cells = [];
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
const sx = x1 - x0 + 1;
|
|
535
|
+
const sz = z1 - z0 + 1;
|
|
536
|
+
const target = Math.min(CELLS_MAX, CELLS_PER_TRI * tris.length);
|
|
537
|
+
const s = Math.sqrt(sx * sz / target);
|
|
538
|
+
this.kx = Math.max(1, Math.min(target, Math.ceil(sx / s)));
|
|
539
|
+
this.kz = Math.max(1, Math.min(Math.floor(CELLS_MAX / this.kx), Math.ceil(sz / s)));
|
|
540
|
+
this.w = Math.max(1, Math.ceil(sx / this.kx));
|
|
541
|
+
this.h = Math.max(1, Math.ceil(sz / this.kz));
|
|
542
|
+
this.cells = new Array(this.kx * this.kz);
|
|
543
|
+
for (const t of tris) {
|
|
544
|
+
const i0 = this.col(Math.min(t.a[0], t.b[0], t.c[0]));
|
|
545
|
+
const i1 = this.col(Math.max(t.a[0], t.b[0], t.c[0]));
|
|
546
|
+
const j0 = this.row(Math.min(t.a[1], t.b[1], t.c[1]));
|
|
547
|
+
const j1 = this.row(Math.max(t.a[1], t.b[1], t.c[1]));
|
|
548
|
+
for (let j = j0; j <= j1; j++) {
|
|
549
|
+
const cz0 = this.z0 + j * this.h;
|
|
550
|
+
const cz1 = cz0 + this.h;
|
|
551
|
+
const [lo, hi] = rowExtent(t, cz0, cz1);
|
|
552
|
+
const ilo = this.col(lo);
|
|
553
|
+
const ihi = this.col(hi);
|
|
554
|
+
const to = Math.min(i1, ihi + 1);
|
|
555
|
+
for (let i = Math.max(i0, ilo - 1); i <= to; i++) {
|
|
556
|
+
const cx0 = this.x0 + i * this.w;
|
|
557
|
+
if (!(i > ilo && i < ihi || overlaps(t, cx0, cz0, cx0 + this.w, cz1))) continue;
|
|
558
|
+
const c = j * this.kx + i;
|
|
559
|
+
const list = this.cells[c];
|
|
560
|
+
if (list) list.push(t);
|
|
561
|
+
else this.cells[c] = [t];
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
col(x) {
|
|
567
|
+
return Math.floor((x - this.x0) / this.w);
|
|
568
|
+
}
|
|
569
|
+
row(z) {
|
|
570
|
+
return Math.floor((z - this.z0) / this.h);
|
|
571
|
+
}
|
|
572
|
+
at(q) {
|
|
573
|
+
if (this.kx === 0) return [];
|
|
574
|
+
const i = this.col(q[0]);
|
|
575
|
+
const j = this.row(q[1]);
|
|
576
|
+
if (i < 0 || j < 0 || i >= this.kx || j >= this.kz) return [];
|
|
577
|
+
return this.cells[j * this.kx + i] ?? [];
|
|
578
|
+
}
|
|
579
|
+
/** The triangles in the cells a plan box covers, each once (callers sort what they derive). */
|
|
580
|
+
near(x0, z0, x1, z1) {
|
|
581
|
+
if (this.kx === 0) return [];
|
|
582
|
+
const ci = (v) => Math.max(0, Math.min(this.kx - 1, v));
|
|
583
|
+
const cj = (v) => Math.max(0, Math.min(this.kz - 1, v));
|
|
584
|
+
const seen = /* @__PURE__ */ new Set();
|
|
585
|
+
for (let j = cj(this.row(z0)); j <= cj(this.row(z1)); j++)
|
|
586
|
+
for (let i = ci(this.col(x0)); i <= ci(this.col(x1)); i++)
|
|
587
|
+
for (const t of this.cells[j * this.kx + i] ?? []) seen.add(t);
|
|
588
|
+
return [...seen];
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
function rowExtent(t, z0, z1) {
|
|
592
|
+
let lo = Infinity;
|
|
593
|
+
let hi = -Infinity;
|
|
594
|
+
const take = (x) => {
|
|
595
|
+
if (x < lo) lo = x;
|
|
596
|
+
if (x > hi) hi = x;
|
|
597
|
+
};
|
|
598
|
+
const ps = [t.a, t.b, t.c];
|
|
599
|
+
for (const p of ps) if (p[1] >= z0 && p[1] <= z1) take(p[0]);
|
|
600
|
+
for (let k = 0; k < 3; k++) {
|
|
601
|
+
const p = ps[k];
|
|
602
|
+
const q = ps[(k + 1) % 3];
|
|
603
|
+
if (p[1] === q[1]) continue;
|
|
604
|
+
for (const z of [z0, z1])
|
|
605
|
+
if ((p[1] - z) * (q[1] - z) < 0) take(p[0] + (q[0] - p[0]) * (z - p[1]) / (q[1] - p[1]));
|
|
606
|
+
}
|
|
607
|
+
if (lo > hi) return [Math.min(t.a[0], t.b[0], t.c[0]), Math.max(t.a[0], t.b[0], t.c[0])];
|
|
608
|
+
return [lo, hi];
|
|
609
|
+
}
|
|
610
|
+
function flatFaces(n, up, y, out) {
|
|
611
|
+
const p = n.positions;
|
|
612
|
+
for (let i = 0; i < n.indices.length; i += 3) {
|
|
613
|
+
const [ia, ib, ic] = [n.indices[i], n.indices[i + 1], n.indices[i + 2]];
|
|
614
|
+
const ya = p[ia * 3 + 1];
|
|
615
|
+
if (p[ib * 3 + 1] !== ya || p[ic * 3 + 1] !== ya || y !== void 0 && ya !== y) continue;
|
|
616
|
+
const a = [p[ia * 3], p[ia * 3 + 2]];
|
|
617
|
+
const b = [p[ib * 3], p[ib * 3 + 2]];
|
|
618
|
+
const c = [p[ic * 3], p[ic * 3 + 2]];
|
|
619
|
+
const turn = cross(b[0] - a[0], b[1] - a[1], c[0] - a[0], c[1] - a[1]);
|
|
620
|
+
if (up ? turn < 0 : turn > 0) out.push({ a, b, c, y: ya });
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
function narrowed(segs, band) {
|
|
624
|
+
const groups = /* @__PURE__ */ new Map();
|
|
625
|
+
for (const s of segs) {
|
|
626
|
+
const l = planLine(s.a[0], s.a[1], s.b[0], s.b[1]);
|
|
627
|
+
const key = `${l.dx},${l.dz}`;
|
|
628
|
+
const g = groups.get(key);
|
|
629
|
+
if (g) g.push(s);
|
|
630
|
+
else groups.set(key, [s]);
|
|
631
|
+
}
|
|
632
|
+
const near = /* @__PURE__ */ new Map();
|
|
633
|
+
const along = (s, o) => {
|
|
634
|
+
const dx = s.b[0] - s.a[0];
|
|
635
|
+
const dz = s.b[1] - s.a[1];
|
|
636
|
+
const l2 = dx * dx + dz * dz;
|
|
637
|
+
const ta = ((o.a[0] - s.a[0]) * dx + (o.a[1] - s.a[1]) * dz) / l2;
|
|
638
|
+
const tb = ((o.b[0] - s.a[0]) * dx + (o.b[1] - s.a[1]) * dz) / l2;
|
|
639
|
+
const t0 = Math.max(0, Math.min(ta, tb));
|
|
640
|
+
const t1 = Math.min(1, Math.max(ta, tb));
|
|
641
|
+
return t1 > t0 ? [t0, t1] : void 0;
|
|
642
|
+
};
|
|
643
|
+
const note = (s, o, w) => {
|
|
644
|
+
if (w >= band(s)) return;
|
|
645
|
+
const t = along(s, o);
|
|
646
|
+
if (!t) return;
|
|
647
|
+
const list = near.get(s);
|
|
648
|
+
if (list) list.push({ t0: t[0], t1: t[1], w });
|
|
649
|
+
else near.set(s, [{ t0: t[0], t1: t[1], w }]);
|
|
650
|
+
};
|
|
651
|
+
for (const key of [...groups.keys()].sort()) {
|
|
652
|
+
const g = groups.get(key);
|
|
653
|
+
if (g.length < 2) continue;
|
|
654
|
+
const [dx, dz] = key.split(",").map(Number);
|
|
655
|
+
const len = lengthOf(dx, dz);
|
|
656
|
+
let widest = 0;
|
|
657
|
+
for (const s of g) widest = Math.max(widest, band(s));
|
|
658
|
+
const reach = 2e3 * widest;
|
|
659
|
+
const items = g.map((s) => {
|
|
660
|
+
const [ta, tb] = [(dx * s.a[0] + dz * s.a[1]) / len, (dx * s.b[0] + dz * s.b[1]) / len];
|
|
661
|
+
return { s, off: (dx * s.a[1] - dz * s.a[0]) / len, lo: Math.min(ta, tb), hi: Math.max(ta, tb) };
|
|
662
|
+
}).sort((p, q) => p.lo - q.lo || p.off - q.off);
|
|
663
|
+
let active = [];
|
|
664
|
+
for (const it of items) {
|
|
665
|
+
active = active.filter((o) => o.hi > it.lo);
|
|
666
|
+
for (const o of active) {
|
|
667
|
+
if (Math.abs(o.off - it.off) > reach) continue;
|
|
668
|
+
const [s, t] = [it.s, o.s];
|
|
669
|
+
const fs = frame(s);
|
|
670
|
+
const ft = frame(t);
|
|
671
|
+
if (fs.d[0] * ft.d[0] + fs.d[1] * ft.d[1] >= 0) continue;
|
|
672
|
+
const ex = t.a[0] - s.a[0];
|
|
673
|
+
const ez = t.a[1] - s.a[1];
|
|
674
|
+
if (cross(fs.d[0], fs.d[1], ex, ez) >= 0) continue;
|
|
675
|
+
const c = BigInt(fs.d[0]) * BigInt(ez) - BigInt(fs.d[1]) * BigInt(ex);
|
|
676
|
+
const w = Math.max(0, -Number(c) / fs.len / 2e3);
|
|
677
|
+
note(s, t, w);
|
|
678
|
+
note(t, s, w);
|
|
679
|
+
}
|
|
680
|
+
active.push(it);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
return segs.flatMap((s) => {
|
|
684
|
+
const list = near.get(s);
|
|
685
|
+
if (!list) return [s];
|
|
686
|
+
const own = band(s);
|
|
687
|
+
const ts = [.../* @__PURE__ */ new Set([0, 1, ...list.flatMap((c) => [c.t0, c.t1])])].sort((x, y) => x - y);
|
|
688
|
+
const f = frame(s);
|
|
689
|
+
const at = (t) => t === 0 ? s.a : t === 1 ? s.b : [whole(s.a[0] + f.d[0] * t), whole(s.a[1] + f.d[1] * t)];
|
|
690
|
+
const out = [];
|
|
691
|
+
for (let k = 0; k + 1 < ts.length; k++) {
|
|
692
|
+
const [t0, t1] = [ts[k], ts[k + 1]];
|
|
693
|
+
const m = (t0 + t1) / 2;
|
|
694
|
+
let w = own;
|
|
695
|
+
for (const c of list) if (c.t0 <= m && m <= c.t1 && c.w < w) w = c.w;
|
|
696
|
+
const last = out[out.length - 1];
|
|
697
|
+
const lw = last ? last.w ?? own : void 0;
|
|
698
|
+
if (last && lw === w) last.b = at(t1);
|
|
699
|
+
else out.push({ a: at(t0), b: at(t1), node: s.node, ...w < own ? { w } : {} });
|
|
700
|
+
}
|
|
701
|
+
return out.filter((p) => p.a[0] !== p.b[0] || p.a[1] !== p.b[1]);
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
function outline(tris) {
|
|
705
|
+
const lines = /* @__PURE__ */ new Map();
|
|
706
|
+
for (const { node, p } of tris) {
|
|
707
|
+
for (let j = 0; j < 3; j++) {
|
|
708
|
+
const a = p[j];
|
|
709
|
+
const b = p[(j + 1) % 3];
|
|
710
|
+
if (a[0] === b[0] && a[1] === b[1]) continue;
|
|
711
|
+
const l = planLine(a[0], a[1], b[0], b[1]);
|
|
712
|
+
const alongX = l.dx !== 0;
|
|
713
|
+
const ta = alongX ? a[0] : a[1];
|
|
714
|
+
const tb = alongX ? b[0] : b[1];
|
|
715
|
+
let line = lines.get(l.key);
|
|
716
|
+
if (!line) {
|
|
717
|
+
line = { edges: [], at: /* @__PURE__ */ new Map() };
|
|
718
|
+
lines.set(l.key, line);
|
|
719
|
+
}
|
|
720
|
+
line.at.set(ta, a);
|
|
721
|
+
line.at.set(tb, b);
|
|
722
|
+
line.edges.push(ta < tb ? { t0: ta, t1: tb, k: 1, node } : { t0: tb, t1: ta, k: -1, node });
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
const out = [];
|
|
726
|
+
for (const key of [...lines.keys()].sort()) {
|
|
727
|
+
const line = lines.get(key);
|
|
728
|
+
if (!line) continue;
|
|
729
|
+
const pieces = [];
|
|
730
|
+
sweep(line.edges, (t0, t1, on) => {
|
|
731
|
+
let s = 0;
|
|
732
|
+
let node = Infinity;
|
|
733
|
+
for (const e of on) {
|
|
734
|
+
s += e.k;
|
|
735
|
+
if (e.node < node) node = e.node;
|
|
736
|
+
}
|
|
737
|
+
if (s === 0) return;
|
|
738
|
+
const sign = s > 0 ? 1 : -1;
|
|
739
|
+
const last = pieces[pieces.length - 1];
|
|
740
|
+
if (last && last.t1 === t0 && last.s === sign && last.node === node) last.t1 = t1;
|
|
741
|
+
else pieces.push({ t0, t1, s: sign, node });
|
|
742
|
+
});
|
|
743
|
+
for (const pc of pieces) {
|
|
744
|
+
const a = line.at.get(pc.t0);
|
|
745
|
+
const b = line.at.get(pc.t1);
|
|
746
|
+
out.push(pc.s > 0 ? { a, b, node: pc.node } : { a: b, b: a, node: pc.node });
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
return out;
|
|
750
|
+
}
|
|
751
|
+
function downFaces(n, node, y, out) {
|
|
752
|
+
const p = n.positions;
|
|
753
|
+
for (let i = 0; i < n.indices.length; i += 3) {
|
|
754
|
+
const [ia, ib, ic] = [n.indices[i], n.indices[i + 1], n.indices[i + 2]];
|
|
755
|
+
if (y !== void 0 && (p[ia * 3 + 1] !== y || p[ib * 3 + 1] !== y || p[ic * 3 + 1] !== y)) continue;
|
|
756
|
+
const a = [p[ia * 3], p[ia * 3 + 2]];
|
|
757
|
+
const b = [p[ib * 3], p[ib * 3 + 2]];
|
|
758
|
+
const c = [p[ic * 3], p[ic * 3 + 2]];
|
|
759
|
+
if (cross(b[0] - a[0], b[1] - a[1], c[0] - a[0], c[1] - a[1]) > 0) out.push({ node, p: [a, b, c] });
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
var yRange = (n) => {
|
|
763
|
+
let lo = Infinity;
|
|
764
|
+
let hi = -Infinity;
|
|
765
|
+
for (let i = 1; i < n.positions.length; i += 3) {
|
|
766
|
+
const y = n.positions[i];
|
|
767
|
+
if (y < lo) lo = y;
|
|
768
|
+
if (y > hi) hi = y;
|
|
769
|
+
}
|
|
770
|
+
return [lo, hi];
|
|
771
|
+
};
|
|
772
|
+
var Buf = class {
|
|
773
|
+
positions = [];
|
|
774
|
+
weight = [];
|
|
775
|
+
caster = [];
|
|
776
|
+
indices = [];
|
|
777
|
+
vertex(x, y, z, w, caster) {
|
|
778
|
+
this.positions.push(x, y, z);
|
|
779
|
+
this.weight.push(w);
|
|
780
|
+
this.caster.push(caster);
|
|
781
|
+
return this.weight.length - 1;
|
|
782
|
+
}
|
|
783
|
+
tri(a, b, c) {
|
|
784
|
+
this.indices.push(a, b, c);
|
|
785
|
+
}
|
|
786
|
+
/** A quad `a b c d` as two triangles. */
|
|
787
|
+
quad(a, b, c, d) {
|
|
788
|
+
this.indices.push(a, b, c, a, c, d);
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
function frame(s) {
|
|
792
|
+
const dx = s.b[0] - s.a[0];
|
|
793
|
+
const dz = s.b[1] - s.a[1];
|
|
794
|
+
const len = lengthOf(dx, dz);
|
|
795
|
+
return { d: [dx, dz], len, u: [dx / len, dz / len], n: [dz / len, -dx / len] };
|
|
796
|
+
}
|
|
797
|
+
var scaled = (v, mm) => [
|
|
798
|
+
whole(v[0] * mm * 1e3),
|
|
799
|
+
whole(v[1] * mm * 1e3)
|
|
800
|
+
];
|
|
801
|
+
var plus = (p, o) => [p[0] + o[0], p[1] + o[1]];
|
|
802
|
+
var MAX_FAN = 8;
|
|
803
|
+
function contactShadows(nodes, ground, lines) {
|
|
804
|
+
return contactShadowsWith(nodes, ground, lines, (tris) => new TriGrid(tris));
|
|
805
|
+
}
|
|
806
|
+
function contactShadowsWith(nodes, ground, lines, lookup) {
|
|
807
|
+
const counts = {
|
|
808
|
+
edges: 0,
|
|
809
|
+
convex: 0,
|
|
810
|
+
concave: 0,
|
|
811
|
+
flatJoints: 0,
|
|
812
|
+
dropped: 0,
|
|
813
|
+
furniture: 0,
|
|
814
|
+
fenceSides: 0,
|
|
815
|
+
stairEdges: 0,
|
|
816
|
+
triangles: 0,
|
|
817
|
+
probes: 0,
|
|
818
|
+
tests: 0
|
|
819
|
+
};
|
|
820
|
+
const casters = [];
|
|
821
|
+
const layers = [];
|
|
822
|
+
const levels = [...new Set(nodes.map((n) => levelOf(n.key)))].sort((a, b) => a - b);
|
|
823
|
+
const lowest = levels[0];
|
|
824
|
+
const lift = CONTACT_SHADOW.liftMm * 1e3;
|
|
825
|
+
for (const level of levels) {
|
|
826
|
+
const here = nodes.map((n, i) => [n, i]).filter(([n]) => levelOf(n.key) === level);
|
|
827
|
+
const faces = [];
|
|
828
|
+
for (const [n] of here)
|
|
829
|
+
if (n.kind === "floor" || n.kind === "slab" || n.kind === "outdoor" || n.flat === true)
|
|
830
|
+
flatFaces(n, true, void 0, faces);
|
|
831
|
+
const receivers = lookup(faces);
|
|
832
|
+
const groundY = level === lowest ? ground?.y : void 0;
|
|
833
|
+
const over = (qs) => {
|
|
834
|
+
let best;
|
|
835
|
+
for (const q of qs) {
|
|
836
|
+
counts.probes++;
|
|
837
|
+
let here2 = groundY;
|
|
838
|
+
for (const f of receivers.at(q)) {
|
|
839
|
+
counts.tests++;
|
|
840
|
+
if (here2 !== void 0 && f.y <= here2) continue;
|
|
841
|
+
if (contains(f, q)) here2 = f.y;
|
|
842
|
+
}
|
|
843
|
+
if (here2 !== void 0 && (best === void 0 || here2 > best)) best = here2;
|
|
844
|
+
}
|
|
845
|
+
return best === void 0 ? void 0 : best + lift;
|
|
846
|
+
};
|
|
847
|
+
const foot = new Buf();
|
|
848
|
+
const corner = new Buf();
|
|
849
|
+
const halo = new Buf();
|
|
850
|
+
const band = (s, oa, ob, y, c) => {
|
|
851
|
+
const a = foot.vertex(s.a[0], y, s.a[1], 1, c);
|
|
852
|
+
const b = foot.vertex(s.b[0], y, s.b[1], 1, c);
|
|
853
|
+
const d = foot.vertex(s.b[0] + ob[0], y, s.b[1] + ob[1], 0, c);
|
|
854
|
+
const e = foot.vertex(s.a[0] + oa[0], y, s.a[1] + oa[1], 0, c);
|
|
855
|
+
foot.quad(a, b, d, e);
|
|
856
|
+
};
|
|
857
|
+
const probesOf = (s, oa, ob) => {
|
|
858
|
+
const f = frame(s);
|
|
859
|
+
const mid = [whole((s.a[0] + s.b[0]) / 2), whole((s.a[1] + s.b[1]) / 2)];
|
|
860
|
+
const half = (o) => [whole(o[0] / 2), whole(o[1] / 2)];
|
|
861
|
+
const om = [whole((oa[0] + ob[0]) / 4), whole((oa[1] + ob[1]) / 4)];
|
|
862
|
+
const out = [plus(mid, om)];
|
|
863
|
+
if (f.len > 2e3) {
|
|
864
|
+
out.push(plus(plus(s.a, scaled(f.u, 1)), half(oa)), plus(plus(s.b, scaled(f.u, -1)), half(ob)));
|
|
865
|
+
}
|
|
866
|
+
return out;
|
|
867
|
+
};
|
|
868
|
+
const walls = here.filter(([n]) => n.band !== void 0 && (n.kind === "wall" || n.kind === "column"));
|
|
869
|
+
if (walls.length > 0) {
|
|
870
|
+
const caster = casters.push(walls.map(([n]) => n.key)) - 1;
|
|
871
|
+
let e = Infinity;
|
|
872
|
+
for (const [n] of walls) e = Math.min(e, yRange(n)[0]);
|
|
873
|
+
const tris = [];
|
|
874
|
+
for (const [n, i] of walls) downFaces(n, i, e, tris);
|
|
875
|
+
const solid = lookup(tris.map((t) => ({ a: t.p[0], b: t.p[1], c: t.p[2], y: e, node: t.node })));
|
|
876
|
+
const inSolid = (q) => {
|
|
877
|
+
counts.probes++;
|
|
878
|
+
for (const f of solid.at(q)) {
|
|
879
|
+
counts.tests++;
|
|
880
|
+
if (contains(f, q)) return true;
|
|
881
|
+
}
|
|
882
|
+
return false;
|
|
883
|
+
};
|
|
884
|
+
const cutSegs = outline(tris).flatMap((s) => {
|
|
885
|
+
const f = frame(s);
|
|
886
|
+
const ts = [0, 1];
|
|
887
|
+
const [bx0, bx1] = [Math.min(s.a[0], s.b[0]), Math.max(s.a[0], s.b[0])];
|
|
888
|
+
const [bz0, bz1] = [Math.min(s.a[1], s.b[1]), Math.max(s.a[1], s.b[1])];
|
|
889
|
+
for (const t of solid.near(bx0, bz0, bx1, bz1)) {
|
|
890
|
+
if (t.node === s.node) continue;
|
|
891
|
+
counts.tests++;
|
|
892
|
+
for (const [p, q] of [
|
|
893
|
+
[t.a, t.b],
|
|
894
|
+
[t.b, t.c],
|
|
895
|
+
[t.c, t.a]
|
|
896
|
+
]) {
|
|
897
|
+
const den = f.d[0] * (q[1] - p[1]) - f.d[1] * (q[0] - p[0]);
|
|
898
|
+
if (den === 0) continue;
|
|
899
|
+
const along = ((p[0] - s.a[0]) * (q[1] - p[1]) - (p[1] - s.a[1]) * (q[0] - p[0])) / den;
|
|
900
|
+
const on = ((p[0] - s.a[0]) * f.d[1] - (p[1] - s.a[1]) * f.d[0]) / den;
|
|
901
|
+
if (along > 0 && along < 1 && on >= 0 && on <= 1) ts.push(along);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
ts.sort((x, y) => x - y);
|
|
905
|
+
const at = (t) => t === 0 ? s.a : t === 1 ? s.b : [whole(s.a[0] + f.d[0] * t), whole(s.a[1] + f.d[1] * t)];
|
|
906
|
+
const kept = [];
|
|
907
|
+
let from;
|
|
908
|
+
for (let k = 0; k + 1 < ts.length; k++) {
|
|
909
|
+
const t0 = ts[k];
|
|
910
|
+
const t1 = ts[k + 1];
|
|
911
|
+
if (t1 - t0 <= 0) continue;
|
|
912
|
+
const m = at((t0 + t1) / 2);
|
|
913
|
+
const outside = !inSolid(plus(m, scaled(f.n, 1)));
|
|
914
|
+
if (outside && from === void 0) from = t0;
|
|
915
|
+
if (!outside) {
|
|
916
|
+
counts.dropped++;
|
|
917
|
+
if (from !== void 0) kept.push({ a: at(from), b: at(t0), node: s.node });
|
|
918
|
+
from = void 0;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
if (from !== void 0) kept.push({ a: at(from), b: s.b, node: s.node });
|
|
922
|
+
return kept.filter((k) => k.a[0] !== k.b[0] || k.a[1] !== k.b[1]);
|
|
923
|
+
});
|
|
924
|
+
const bandOf = (s) => s.w ?? nodes[s.node]?.band ?? 0;
|
|
925
|
+
const segs = narrowed(cutSegs, bandOf);
|
|
926
|
+
const pk = (p) => `${p[0]},${p[1]}`;
|
|
927
|
+
const ending = /* @__PURE__ */ new Map();
|
|
928
|
+
const starting = /* @__PURE__ */ new Map();
|
|
929
|
+
for (const s of segs) {
|
|
930
|
+
ending.set(pk(s.b), [...ending.get(pk(s.b)) ?? [], s]);
|
|
931
|
+
starting.set(pk(s.a), [...starting.get(pk(s.a)) ?? [], s]);
|
|
932
|
+
}
|
|
933
|
+
const outerA = /* @__PURE__ */ new Map();
|
|
934
|
+
const outerB = /* @__PURE__ */ new Map();
|
|
935
|
+
for (const s of segs) {
|
|
936
|
+
const o = scaled(frame(s).n, bandOf(s));
|
|
937
|
+
outerA.set(s, o);
|
|
938
|
+
outerB.set(s, o);
|
|
939
|
+
}
|
|
940
|
+
const joints = [];
|
|
941
|
+
for (const key of [...ending.keys()].sort()) {
|
|
942
|
+
const ins = ending.get(key) ?? [];
|
|
943
|
+
const outs = starting.get(key) ?? [];
|
|
944
|
+
if (ins.length !== 1 || outs.length !== 1) continue;
|
|
945
|
+
const si = ins[0];
|
|
946
|
+
const so = outs[0];
|
|
947
|
+
const fi = frame(si);
|
|
948
|
+
const fo = frame(so);
|
|
949
|
+
const turn = cross(fi.d[0], fi.d[1], fo.d[0], fo.d[1]);
|
|
950
|
+
if (nearlyFlat(fi.d, fo.d, 1, 1)) {
|
|
951
|
+
const m = [fi.n[0] + fo.n[0], fi.n[1] + fo.n[1]];
|
|
952
|
+
const k = 1 + fi.n[0] * fo.n[0] + fi.n[1] * fo.n[1];
|
|
953
|
+
outerB.set(si, scaled([m[0] / k, m[1] / k], bandOf(si)));
|
|
954
|
+
outerA.set(so, scaled([m[0] / k, m[1] / k], bandOf(so)));
|
|
955
|
+
if (turn !== 0) counts.flatJoints++;
|
|
956
|
+
continue;
|
|
957
|
+
}
|
|
958
|
+
if (turn !== 0) joints.push({ v: si.b, si, so, turn });
|
|
959
|
+
}
|
|
960
|
+
for (const s of segs) {
|
|
961
|
+
const oa = outerA.get(s);
|
|
962
|
+
const ob = outerB.get(s);
|
|
963
|
+
const y = over(probesOf(s, oa, ob));
|
|
964
|
+
if (y === void 0) continue;
|
|
965
|
+
band(s, oa, ob, y, caster);
|
|
966
|
+
counts.edges++;
|
|
967
|
+
}
|
|
968
|
+
const jambs = [];
|
|
969
|
+
for (const [, i] of walls) {
|
|
970
|
+
const l = lines?.[i] ?? [];
|
|
971
|
+
for (let j = 0; j + 5 < l.length; j += 6)
|
|
972
|
+
if (l[j] === l[j + 3] && l[j + 2] === l[j + 5] && l[j + 1] !== l[j + 4])
|
|
973
|
+
jambs.push([l[j], l[j + 2]]);
|
|
974
|
+
}
|
|
975
|
+
for (const { v, si, so, turn } of joints) {
|
|
976
|
+
const fi = frame(si);
|
|
977
|
+
const fo = frame(so);
|
|
978
|
+
const bi = bandOf(si);
|
|
979
|
+
const bo = bandOf(so);
|
|
980
|
+
if (turn > 0) {
|
|
981
|
+
const dirs = [];
|
|
982
|
+
for (let k = 0; k < 16; k++) {
|
|
983
|
+
const d = [C16[k], S16[k]];
|
|
984
|
+
if (cross(fi.n[0], fi.n[1], d[0], d[1]) > 0 && cross(d[0], d[1], fo.n[0], fo.n[1]) > 0) dirs.push(d);
|
|
985
|
+
}
|
|
986
|
+
dirs.sort((a, b) => -Math.sign(cross(a[0], a[1], b[0], b[1])));
|
|
987
|
+
const ring = [fi.n, ...dirs.slice(0, MAX_FAN - 1), fo.n];
|
|
988
|
+
const rims = ring.map((d, j) => scaled(d, bi + (bo - bi) * j / (ring.length - 1)));
|
|
989
|
+
const y = over(rims.map((o) => plus(v, [whole(o[0] / 2), whole(o[1] / 2)])));
|
|
990
|
+
if (y === void 0) continue;
|
|
991
|
+
const c = foot.vertex(v[0], y, v[1], 1, caster);
|
|
992
|
+
const rim = rims.map((o) => foot.vertex(v[0] + o[0], y, v[1] + o[1], 0, caster));
|
|
993
|
+
for (let j = 0; j + 1 < rim.length; j++) foot.tri(c, rim[j], rim[j + 1]);
|
|
994
|
+
counts.convex++;
|
|
995
|
+
} else {
|
|
996
|
+
const r = Math.max(bi, bo);
|
|
997
|
+
const y0 = over([plus(v, scaled([fi.n[0] + fo.n[0], fi.n[1] + fo.n[1]], r / 2))]);
|
|
998
|
+
if (y0 === void 0) continue;
|
|
999
|
+
const top = Math.min(yRange(nodes[si.node])[1], yRange(nodes[so.node])[1]);
|
|
1000
|
+
if (top <= y0) continue;
|
|
1001
|
+
const strip = (f, mm, back) => {
|
|
1002
|
+
const dir = back ? [-f.d[0], -f.d[1]] : f.d;
|
|
1003
|
+
let reach = Math.min(mm * 1e3, f.len);
|
|
1004
|
+
for (const p of jambs) {
|
|
1005
|
+
const wx = p[0] - v[0];
|
|
1006
|
+
const wz = p[1] - v[1];
|
|
1007
|
+
if (cross(dir[0], dir[1], wx, wz) !== 0) continue;
|
|
1008
|
+
const along = (dir[0] * wx + dir[1] * wz) / f.len;
|
|
1009
|
+
if (along > 0 && along < reach) reach = along;
|
|
1010
|
+
}
|
|
1011
|
+
if (reach <= 0) return;
|
|
1012
|
+
const off = scaled(f.n, CONTACT_SHADOW.liftMm);
|
|
1013
|
+
const step = scaled(back ? [-f.u[0], -f.u[1]] : f.u, reach / 1e3);
|
|
1014
|
+
const x = v[0] + off[0];
|
|
1015
|
+
const z = v[1] + off[1];
|
|
1016
|
+
const a = corner.vertex(x, y0, z, 1, caster);
|
|
1017
|
+
const b = corner.vertex(x, top, z, 1, caster);
|
|
1018
|
+
const c = corner.vertex(x + step[0], top, z + step[1], 0, caster);
|
|
1019
|
+
const d = corner.vertex(x + step[0], y0, z + step[1], 0, caster);
|
|
1020
|
+
corner.quad(a, b, c, d);
|
|
1021
|
+
};
|
|
1022
|
+
strip(fi, bi, true);
|
|
1023
|
+
strip(fo, bo, false);
|
|
1024
|
+
counts.concave++;
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
for (const [n, i] of here) {
|
|
1029
|
+
if (n.kind !== "fence" || n.band === void 0) continue;
|
|
1030
|
+
const caster = casters.push([n.key]) - 1;
|
|
1031
|
+
const ys = [...new Set(n.positions.filter((_, j) => j % 3 === 1))].sort((a, b) => a - b);
|
|
1032
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1033
|
+
for (const y of ys) {
|
|
1034
|
+
const tris = [];
|
|
1035
|
+
downFaces(n, i, y, tris);
|
|
1036
|
+
for (const s of outline(tris)) {
|
|
1037
|
+
if (frame(s).len <= 2 * n.band * 1e3) continue;
|
|
1038
|
+
const key = `${s.a[0]},${s.a[1]},${s.b[0]},${s.b[1]}`;
|
|
1039
|
+
if (seen.has(key)) continue;
|
|
1040
|
+
seen.add(key);
|
|
1041
|
+
const o = scaled(frame(s).n, n.band);
|
|
1042
|
+
const yy = over(probesOf(s, o, o));
|
|
1043
|
+
if (yy === void 0) continue;
|
|
1044
|
+
band(s, o, o, yy, caster);
|
|
1045
|
+
counts.fenceSides++;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
for (const [n, i] of here) {
|
|
1050
|
+
if (n.kind !== "stair" || n.band === void 0) continue;
|
|
1051
|
+
const caster = casters.push([n.key]) - 1;
|
|
1052
|
+
const tris = [];
|
|
1053
|
+
downFaces(n, i, void 0, tris);
|
|
1054
|
+
for (const s of outline(tris)) {
|
|
1055
|
+
const o = scaled(frame(s).n, n.band);
|
|
1056
|
+
const y = over(probesOf(s, o, o));
|
|
1057
|
+
if (y === void 0) continue;
|
|
1058
|
+
band(s, o, o, y, caster);
|
|
1059
|
+
counts.stairEdges++;
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
for (const [n] of here) {
|
|
1063
|
+
if (n.kind !== "furniture" || n.band === void 0 || n.positions.length === 0) continue;
|
|
1064
|
+
let x0 = Infinity;
|
|
1065
|
+
let x1 = -Infinity;
|
|
1066
|
+
let z0 = Infinity;
|
|
1067
|
+
let z1 = -Infinity;
|
|
1068
|
+
for (let j = 0; j < n.positions.length; j += 3) {
|
|
1069
|
+
const x = n.positions[j];
|
|
1070
|
+
const z = n.positions[j + 2];
|
|
1071
|
+
if (x < x0) x0 = x;
|
|
1072
|
+
if (x > x1) x1 = x;
|
|
1073
|
+
if (z < z0) z0 = z;
|
|
1074
|
+
if (z > z1) z1 = z;
|
|
1075
|
+
}
|
|
1076
|
+
const h = n.band * 1e3;
|
|
1077
|
+
const cx = whole((x0 + x1) / 2);
|
|
1078
|
+
const cz = whole((z0 + z1) / 2);
|
|
1079
|
+
const y = over([
|
|
1080
|
+
[cx, cz],
|
|
1081
|
+
[cx, z0 - h / 2],
|
|
1082
|
+
[x1 + h / 2, cz],
|
|
1083
|
+
[cx, z1 + h / 2],
|
|
1084
|
+
[x0 - h / 2, cz]
|
|
1085
|
+
]);
|
|
1086
|
+
if (y === void 0) continue;
|
|
1087
|
+
const caster = casters.push([n.key]) - 1;
|
|
1088
|
+
const inner = [
|
|
1089
|
+
[x0, z0],
|
|
1090
|
+
[x1, z0],
|
|
1091
|
+
[x1, z1],
|
|
1092
|
+
[x0, z1]
|
|
1093
|
+
];
|
|
1094
|
+
const outer = [
|
|
1095
|
+
[x0 - h, z0 - h],
|
|
1096
|
+
[x1 + h, z0 - h],
|
|
1097
|
+
[x1 + h, z1 + h],
|
|
1098
|
+
[x0 - h, z1 + h]
|
|
1099
|
+
];
|
|
1100
|
+
const iv = inner.map((p) => halo.vertex(p[0], y, p[1], 1, caster));
|
|
1101
|
+
const ov = outer.map((p) => halo.vertex(p[0], y, p[1], 0, caster));
|
|
1102
|
+
for (let j = 0; j < 4; j++) {
|
|
1103
|
+
const k = (j + 1) % 4;
|
|
1104
|
+
halo.quad(iv[j], iv[k], ov[k], ov[j]);
|
|
1105
|
+
}
|
|
1106
|
+
counts.furniture++;
|
|
1107
|
+
}
|
|
1108
|
+
for (const [cls, buf] of [
|
|
1109
|
+
["foot", foot],
|
|
1110
|
+
["corner", corner],
|
|
1111
|
+
["halo", halo]
|
|
1112
|
+
]) {
|
|
1113
|
+
if (buf.indices.length === 0) continue;
|
|
1114
|
+
counts.triangles += buf.indices.length / 3;
|
|
1115
|
+
layers.push({ level, cls, ...buf });
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
return { layers, casters, counts };
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
export {
|
|
1122
|
+
wallOutline,
|
|
1123
|
+
joinedGroups,
|
|
1124
|
+
faceParts,
|
|
1125
|
+
contactFade,
|
|
1126
|
+
contactShadows
|
|
1127
|
+
};
|