@chanmeng666/archlang-3d 0.8.0 → 0.9.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 +50 -0
- package/README.md +19 -0
- package/THIRD_PARTY_NOTICES +1 -1
- package/dist/browser.d.ts +4 -3
- package/dist/browser.js +14 -11
- package/dist/{camera-BAsRq_eC.d.ts → camera-BqK_JhhV.d.ts} +1 -1
- package/dist/{chunk-MCASL4MM.js → chunk-4WHBM4NV.js} +22 -147
- package/dist/{chunk-VMVKI2WQ.js → chunk-6EAHOIL6.js} +7 -5
- package/dist/chunk-7FYCBISZ.js +4992 -0
- package/dist/chunk-E65Z5S4K.js +225 -0
- package/dist/{chunk-LNIVDMPG.js → chunk-EL4456GB.js} +1 -273
- package/dist/chunk-ISFIFLC7.js +25 -0
- package/dist/chunk-ONUOWO37.js +251 -0
- package/dist/chunk-P2BDEK2Q.js +6 -0
- package/dist/{chunk-MXKKNJPU.js → chunk-PKFGND2A.js} +174 -26
- package/dist/{chunk-B4PZWWSP.js → chunk-TFXNKG6J.js} +2301 -284
- package/dist/cli.js +13 -8
- package/dist/{facts-CsO0xtFw.d.ts → facts-DGA14BcU.d.ts} +1 -1
- package/dist/glb-BxaVYFWv.d.ts +37 -0
- package/dist/glb.d.ts +3 -0
- package/dist/glb.js +18 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +58 -54
- package/dist/node.d.ts +7 -38
- package/dist/node.js +16 -12
- package/dist/payload-CKSLN1CG.d.ts +358 -0
- package/dist/replay.d.ts +2 -1
- package/dist/{payload-DwiB2P7x.d.ts → types-BQ7xE4YH.d.ts} +3 -358
- package/dist/viewer.iife.js +176 -176
- package/package.json +8 -2
- package/dist/chunk-WARUDAOQ.js +0 -2276
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
// src/materials.ts
|
|
2
|
+
var MATERIAL_SLOTS = [
|
|
3
|
+
"body",
|
|
4
|
+
"wood",
|
|
5
|
+
"wood_dark",
|
|
6
|
+
"fabric",
|
|
7
|
+
"cushion",
|
|
8
|
+
"linen",
|
|
9
|
+
"wool",
|
|
10
|
+
"ceramic",
|
|
11
|
+
"stone",
|
|
12
|
+
"metal",
|
|
13
|
+
"glass",
|
|
14
|
+
"appliance",
|
|
15
|
+
"screen",
|
|
16
|
+
"paint",
|
|
17
|
+
"rubber",
|
|
18
|
+
"foliage",
|
|
19
|
+
"bark",
|
|
20
|
+
"soil",
|
|
21
|
+
"water"
|
|
22
|
+
];
|
|
23
|
+
var m = (srgb, roughness, metallic = 0, alpha = 1) => ({
|
|
24
|
+
srgb,
|
|
25
|
+
alpha,
|
|
26
|
+
metallic,
|
|
27
|
+
roughness
|
|
28
|
+
});
|
|
29
|
+
var PALETTE = {
|
|
30
|
+
wood: m("#c6a785", 0.75),
|
|
31
|
+
wood_dark: m("#7b5b44", 0.7),
|
|
32
|
+
fabric: m("#968f85", 0.95),
|
|
33
|
+
cushion: m("#bfb7ab", 0.95),
|
|
34
|
+
linen: m("#f3efe7", 0.9),
|
|
35
|
+
wool: m("#a7ac98", 1),
|
|
36
|
+
ceramic: m("#f6f4f0", 0.25),
|
|
37
|
+
stone: m("#d8d4cc", 0.45),
|
|
38
|
+
metal: m("#aeb2b4", 0.35, 1),
|
|
39
|
+
glass: m("#c9dee6", 0.05, 0, 0.35),
|
|
40
|
+
appliance: m("#dcdcd8", 0.35),
|
|
41
|
+
screen: m("#2e3033", 0.2),
|
|
42
|
+
paint: m("#a9b1a2", 0.6),
|
|
43
|
+
rubber: m("#3b3b3b", 0.9),
|
|
44
|
+
foliage: m("#8c9b78", 0.9),
|
|
45
|
+
bark: m("#6f5b49", 0.9),
|
|
46
|
+
soil: m("#5f4b3b", 1),
|
|
47
|
+
water: m("#a3c6d0", 0.1, 0, 0.7)
|
|
48
|
+
};
|
|
49
|
+
var STAIR_MATERIAL = "wood";
|
|
50
|
+
var STAIR_RAIL_MATERIAL = "wood_dark";
|
|
51
|
+
var DOOR_OAK = m("#c2a27e", 0.7);
|
|
52
|
+
var FRAME_BRONZE = m("#55534f", 0.5);
|
|
53
|
+
var KIND_PALETTE = {
|
|
54
|
+
slab: m("#bdb6ab", 0.9),
|
|
55
|
+
column: m("#e6e1d8", 0.85),
|
|
56
|
+
wall: m("#f2f0eb", 0.9),
|
|
57
|
+
door: DOOR_OAK,
|
|
58
|
+
"window:frame": FRAME_BRONZE,
|
|
59
|
+
"window:glass": m("#bcd6e0", 0.05, 0, 0.4),
|
|
60
|
+
// The trim (card RM8.6): a window's reveal in its frame's bronze, its exterior sill in the pale
|
|
61
|
+
// stone and its interior board in the oak of the palette; a cased opening's lining and casing in
|
|
62
|
+
// the doors' oak (a door's own lining and casing are `door`). Drafting defaults, ledgered once per
|
|
63
|
+
// Mesh3D as `trim-material-default` from `TRIM_MATERIAL`.
|
|
64
|
+
"window:reveal": FRAME_BRONZE,
|
|
65
|
+
"window:sill": PALETTE.stone,
|
|
66
|
+
"window:board": PALETTE.wood,
|
|
67
|
+
"opening:lining": DOOR_OAK,
|
|
68
|
+
"opening:casing": DOOR_OAK,
|
|
69
|
+
opening: m("#e6e1d8", 0.85),
|
|
70
|
+
furniture: m("#d6cec1", 0.9),
|
|
71
|
+
roof: m("#9c958a", 0.9),
|
|
72
|
+
"wall:demolish": m("#c8553d", 0.9, 0, 0.3),
|
|
73
|
+
// A stair (card X3): the core gives it no material, so the ledgered default (`STAIR_MATERIAL`,
|
|
74
|
+
// `stair-material-default`): that slot's own entry, never a second copy of its colour.
|
|
75
|
+
stair: PALETTE[STAIR_MATERIAL],
|
|
76
|
+
"stair:rail": PALETTE[STAIR_RAIL_MATERIAL]
|
|
77
|
+
};
|
|
78
|
+
var TRIM_MATERIAL = {
|
|
79
|
+
"door:lining": { material: "door", srgb: KIND_PALETTE.door.srgb },
|
|
80
|
+
"door:casing": { material: "door", srgb: KIND_PALETTE.door.srgb },
|
|
81
|
+
"opening:lining": { material: "opening:lining", srgb: KIND_PALETTE["opening:lining"].srgb },
|
|
82
|
+
"opening:casing": { material: "opening:casing", srgb: KIND_PALETTE["opening:casing"].srgb },
|
|
83
|
+
"window:reveal": { material: "window:reveal", srgb: KIND_PALETTE["window:reveal"].srgb },
|
|
84
|
+
"window:sill": { material: "window:sill", srgb: KIND_PALETTE["window:sill"].srgb },
|
|
85
|
+
"window:board": { material: "window:board", srgb: KIND_PALETTE["window:board"].srgb }
|
|
86
|
+
};
|
|
87
|
+
var WALL_CAP_SRGB = "#8f877d";
|
|
88
|
+
var FLOOR_FINISHES = [
|
|
89
|
+
"timber",
|
|
90
|
+
"tile",
|
|
91
|
+
"neutral",
|
|
92
|
+
"carpeting",
|
|
93
|
+
"stone",
|
|
94
|
+
"deck",
|
|
95
|
+
"paving",
|
|
96
|
+
"concrete"
|
|
97
|
+
];
|
|
98
|
+
var FINISH_PALETTE = {
|
|
99
|
+
timber: m("#cdb596", 0.6),
|
|
100
|
+
tile: m("#e3e1db", 0.35),
|
|
101
|
+
neutral: m("#e8e2d7", 0.9),
|
|
102
|
+
carpeting: PALETTE.wool,
|
|
103
|
+
stone: PALETTE.stone,
|
|
104
|
+
deck: PALETTE.wood,
|
|
105
|
+
paving: m("#ab9f87", 0.85),
|
|
106
|
+
concrete: m("#c9c5be", 0.6)
|
|
107
|
+
};
|
|
108
|
+
var FLOOR_WORD_FINISH = {
|
|
109
|
+
tile: "tile",
|
|
110
|
+
paving: "paving",
|
|
111
|
+
deck: "deck",
|
|
112
|
+
concrete: "concrete",
|
|
113
|
+
timber: "timber",
|
|
114
|
+
carpeting: "carpeting",
|
|
115
|
+
stone: "stone"
|
|
116
|
+
};
|
|
117
|
+
function wordFinish(word) {
|
|
118
|
+
return word !== void 0 && Object.hasOwn(FLOOR_WORD_FINISH, word) ? FLOOR_WORD_FINISH[word] : void 0;
|
|
119
|
+
}
|
|
120
|
+
var FLOOR_FINISH_RULES = [
|
|
121
|
+
["tile", ["bath", "wc", "utility"]],
|
|
122
|
+
["timber", ["living", "dining", "bedroom", "office", "hall", "circulation"]],
|
|
123
|
+
["tile", ["kitchen", "entry"]]
|
|
124
|
+
];
|
|
125
|
+
function floorFinish(uses) {
|
|
126
|
+
for (const [finish, kinds] of FLOOR_FINISH_RULES) if (uses?.some((u) => kinds.includes(u))) return finish;
|
|
127
|
+
return "neutral";
|
|
128
|
+
}
|
|
129
|
+
var GROUND_TINT = {
|
|
130
|
+
lawn: "lawn",
|
|
131
|
+
planting: "lawn",
|
|
132
|
+
paving: "paving",
|
|
133
|
+
deck: "paving",
|
|
134
|
+
gravel: "paving",
|
|
135
|
+
water: "water",
|
|
136
|
+
driveway: "paving",
|
|
137
|
+
patio: "paving",
|
|
138
|
+
balcony: "paving",
|
|
139
|
+
sand: "paving",
|
|
140
|
+
soil: "paving"
|
|
141
|
+
};
|
|
142
|
+
var GROUND_WASH = 6;
|
|
143
|
+
var SITE_PALETTE = {
|
|
144
|
+
gravel: m("#cbc3b4", 0.95),
|
|
145
|
+
tarmac: m("#8c8984", 0.85),
|
|
146
|
+
sand: m("#dcc9a3", 0.95)
|
|
147
|
+
};
|
|
148
|
+
var GROUND_SPLITS = {
|
|
149
|
+
planting: PALETTE.foliage,
|
|
150
|
+
deck: PALETTE.wood,
|
|
151
|
+
gravel: SITE_PALETTE.gravel,
|
|
152
|
+
driveway: SITE_PALETTE.tarmac,
|
|
153
|
+
sand: SITE_PALETTE.sand,
|
|
154
|
+
soil: PALETTE.soil
|
|
155
|
+
};
|
|
156
|
+
var GROUND_ROUGHNESS = { lawn: 0.95, paving: 0.85, water: 0.1 };
|
|
157
|
+
var FENCE_PALETTE = {
|
|
158
|
+
picket: m("#eeebe4", 0.8),
|
|
159
|
+
panel: PALETTE.wood,
|
|
160
|
+
post: PALETTE.wood_dark
|
|
161
|
+
};
|
|
162
|
+
var GROUND_PLANE = { light: "#e2ddd3", dark: "#16293d", marginMm: 6e3 };
|
|
163
|
+
var CONTACT_SHADOW = {
|
|
164
|
+
wall: { of: 0.75, minMm: 80, maxMm: 200 },
|
|
165
|
+
furniture: { of: 0.12, minMm: 30, maxMm: 120 },
|
|
166
|
+
fence: { of: 1.5, minMm: 40, maxMm: 120 },
|
|
167
|
+
stairThicknessMm: 100,
|
|
168
|
+
alpha: { floor: 0.2, corner: 0.12, furniture: 0.18 },
|
|
169
|
+
alphaDark: { floor: 0.3, corner: 0.18, furniture: 0.27 },
|
|
170
|
+
liftMm: 1
|
|
171
|
+
};
|
|
172
|
+
function contactBandMm(rule, size) {
|
|
173
|
+
return Math.min(rule.maxMm, Math.max(rule.minMm, Math.round(rule.of * size)));
|
|
174
|
+
}
|
|
175
|
+
function siteColour(own, theme, toward) {
|
|
176
|
+
if (theme === "light") return own;
|
|
177
|
+
const mix = (i) => {
|
|
178
|
+
const a = Number.parseInt(own.slice(i, i + 2), 16);
|
|
179
|
+
const b = Number.parseInt(toward.slice(i, i + 2), 16);
|
|
180
|
+
return Math.round(a * 0.4 + b * 0.6).toString(16).padStart(2, "0");
|
|
181
|
+
};
|
|
182
|
+
return `#${mix(1)}${mix(3)}${mix(5)}`;
|
|
183
|
+
}
|
|
184
|
+
function linearRgb(hex) {
|
|
185
|
+
const ch = (i) => {
|
|
186
|
+
const c = Number.parseInt(hex.slice(i, i + 2), 16) / 255;
|
|
187
|
+
const v = c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
|
188
|
+
return Math.round(v * 1e4) / 1e4;
|
|
189
|
+
};
|
|
190
|
+
return [ch(1), ch(3), ch(5)];
|
|
191
|
+
}
|
|
192
|
+
function slotColour(slot, theme, furniture) {
|
|
193
|
+
const own = PALETTE[slot].srgb;
|
|
194
|
+
if (theme === "light") return own;
|
|
195
|
+
const mix = (i) => {
|
|
196
|
+
const a = Number.parseInt(own.slice(i, i + 2), 16);
|
|
197
|
+
const b = Number.parseInt(furniture.slice(i, i + 2), 16);
|
|
198
|
+
return Math.round(a * 0.4 + b * 0.6).toString(16).padStart(2, "0");
|
|
199
|
+
};
|
|
200
|
+
return `#${mix(1)}${mix(3)}${mix(5)}`;
|
|
201
|
+
}
|
|
202
|
+
function finishColour(finish, theme, floor) {
|
|
203
|
+
const own = FINISH_PALETTE[finish].srgb;
|
|
204
|
+
if (theme === "light") return own;
|
|
205
|
+
const mix = (i) => {
|
|
206
|
+
const a = Number.parseInt(own.slice(i, i + 2), 16);
|
|
207
|
+
const b = Number.parseInt(floor.slice(i, i + 2), 16);
|
|
208
|
+
return Math.round(a * 0.4 + b * 0.6).toString(16).padStart(2, "0");
|
|
209
|
+
};
|
|
210
|
+
return `#${mix(1)}${mix(3)}${mix(5)}`;
|
|
211
|
+
}
|
|
212
|
+
function slotGroups(shells) {
|
|
213
|
+
const by = /* @__PURE__ */ new Map();
|
|
214
|
+
for (const s of shells) {
|
|
215
|
+
const k = s.slot ?? "body";
|
|
216
|
+
const g = by.get(k);
|
|
217
|
+
if (g) g.push(s);
|
|
218
|
+
else by.set(k, [s]);
|
|
219
|
+
}
|
|
220
|
+
return MATERIAL_SLOTS.filter((k) => by.has(k)).map((slot) => ({ slot, shells: by.get(slot) }));
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export {
|
|
224
|
+
MATERIAL_SLOTS,
|
|
225
|
+
PALETTE,
|
|
226
|
+
STAIR_MATERIAL,
|
|
227
|
+
STAIR_RAIL_MATERIAL,
|
|
228
|
+
KIND_PALETTE,
|
|
229
|
+
TRIM_MATERIAL,
|
|
230
|
+
WALL_CAP_SRGB,
|
|
231
|
+
FLOOR_FINISHES,
|
|
232
|
+
FINISH_PALETTE,
|
|
233
|
+
FLOOR_WORD_FINISH,
|
|
234
|
+
wordFinish,
|
|
235
|
+
FLOOR_FINISH_RULES,
|
|
236
|
+
floorFinish,
|
|
237
|
+
GROUND_TINT,
|
|
238
|
+
GROUND_WASH,
|
|
239
|
+
SITE_PALETTE,
|
|
240
|
+
GROUND_SPLITS,
|
|
241
|
+
GROUND_ROUGHNESS,
|
|
242
|
+
FENCE_PALETTE,
|
|
243
|
+
GROUND_PLANE,
|
|
244
|
+
CONTACT_SHADOW,
|
|
245
|
+
contactBandMm,
|
|
246
|
+
siteColour,
|
|
247
|
+
linearRgb,
|
|
248
|
+
slotColour,
|
|
249
|
+
finishColour,
|
|
250
|
+
slotGroups
|
|
251
|
+
};
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
C16,
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
S16
|
|
4
|
+
} from "./chunk-ISFIFLC7.js";
|
|
5
|
+
import {
|
|
5
6
|
ease
|
|
6
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-EL4456GB.js";
|
|
8
|
+
import {
|
|
9
|
+
CONTACT_SHADOW
|
|
10
|
+
} from "./chunk-ONUOWO37.js";
|
|
7
11
|
|
|
8
12
|
// src/replay/wall-lines.ts
|
|
9
13
|
function takesWallLines(n) {
|
|
@@ -493,13 +497,27 @@ function contains(f, q) {
|
|
|
493
497
|
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
498
|
return s1 >= 0 && s2 >= 0 && s3 >= 0 || s1 <= 0 && s2 <= 0 && s3 <= 0;
|
|
495
499
|
}
|
|
496
|
-
var
|
|
500
|
+
var CELLS_PER_TRI = 2;
|
|
501
|
+
var CELLS_MAX = 1 << 16;
|
|
502
|
+
function overlaps(t, x0, z0, x1, z1) {
|
|
503
|
+
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);
|
|
504
|
+
}
|
|
505
|
+
function separates(p, q, r, x0, z0, x1, z1) {
|
|
506
|
+
const ux = q[0] - p[0];
|
|
507
|
+
const uz = q[1] - p[1];
|
|
508
|
+
const side = Math.sign(cross(ux, uz, r[0] - p[0], r[1] - p[1]));
|
|
509
|
+
if (side === 0) return false;
|
|
510
|
+
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;
|
|
511
|
+
}
|
|
497
512
|
var TriGrid = class {
|
|
513
|
+
/** The grid's corner, its cells' size and their count across and down (µm; read by the tests). */
|
|
498
514
|
x0;
|
|
499
515
|
z0;
|
|
500
516
|
w;
|
|
501
517
|
h;
|
|
502
|
-
|
|
518
|
+
kx;
|
|
519
|
+
kz;
|
|
520
|
+
/** Each cell's triangles (a hole where a cell has none). */
|
|
503
521
|
cells;
|
|
504
522
|
constructor(tris) {
|
|
505
523
|
let [x0, z0, x1, z1] = [Infinity, Infinity, -Infinity, -Infinity];
|
|
@@ -510,18 +528,43 @@ var TriGrid = class {
|
|
|
510
528
|
if (p[1] < z0) z0 = p[1];
|
|
511
529
|
if (p[1] > z1) z1 = p[1];
|
|
512
530
|
}
|
|
513
|
-
this.k = tris.length === 0 ? 0 : Math.max(1, Math.min(GRID_MAX, Math.ceil(Math.sqrt(tris.length))));
|
|
514
531
|
this.x0 = x0;
|
|
515
532
|
this.z0 = z0;
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
533
|
+
if (tris.length === 0) {
|
|
534
|
+
[this.kx, this.kz, this.w, this.h] = [0, 0, 1, 1];
|
|
535
|
+
this.cells = [];
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
const sx = x1 - x0 + 1;
|
|
539
|
+
const sz = z1 - z0 + 1;
|
|
540
|
+
const target = Math.min(CELLS_MAX, CELLS_PER_TRI * tris.length);
|
|
541
|
+
const s = Math.sqrt(sx * sz / target);
|
|
542
|
+
this.kx = Math.max(1, Math.min(target, Math.ceil(sx / s)));
|
|
543
|
+
this.kz = Math.max(1, Math.min(Math.floor(CELLS_MAX / this.kx), Math.ceil(sz / s)));
|
|
544
|
+
this.w = Math.max(1, Math.ceil(sx / this.kx));
|
|
545
|
+
this.h = Math.max(1, Math.ceil(sz / this.kz));
|
|
546
|
+
this.cells = new Array(this.kx * this.kz);
|
|
519
547
|
for (const t of tris) {
|
|
520
|
-
const
|
|
521
|
-
const
|
|
522
|
-
const
|
|
523
|
-
const
|
|
524
|
-
for (let j = j0; j <= j1; j++)
|
|
548
|
+
const i0 = this.col(Math.min(t.a[0], t.b[0], t.c[0]));
|
|
549
|
+
const i1 = this.col(Math.max(t.a[0], t.b[0], t.c[0]));
|
|
550
|
+
const j0 = this.row(Math.min(t.a[1], t.b[1], t.c[1]));
|
|
551
|
+
const j1 = this.row(Math.max(t.a[1], t.b[1], t.c[1]));
|
|
552
|
+
for (let j = j0; j <= j1; j++) {
|
|
553
|
+
const cz0 = this.z0 + j * this.h;
|
|
554
|
+
const cz1 = cz0 + this.h;
|
|
555
|
+
const [lo, hi] = rowExtent(t, cz0, cz1);
|
|
556
|
+
const ilo = this.col(lo);
|
|
557
|
+
const ihi = this.col(hi);
|
|
558
|
+
const to = Math.min(i1, ihi + 1);
|
|
559
|
+
for (let i = Math.max(i0, ilo - 1); i <= to; i++) {
|
|
560
|
+
const cx0 = this.x0 + i * this.w;
|
|
561
|
+
if (!(i > ilo && i < ihi || overlaps(t, cx0, cz0, cx0 + this.w, cz1))) continue;
|
|
562
|
+
const c = j * this.kx + i;
|
|
563
|
+
const list = this.cells[c];
|
|
564
|
+
if (list) list.push(t);
|
|
565
|
+
else this.cells[c] = [t];
|
|
566
|
+
}
|
|
567
|
+
}
|
|
525
568
|
}
|
|
526
569
|
}
|
|
527
570
|
col(x) {
|
|
@@ -531,23 +574,43 @@ var TriGrid = class {
|
|
|
531
574
|
return Math.floor((z - this.z0) / this.h);
|
|
532
575
|
}
|
|
533
576
|
at(q) {
|
|
534
|
-
if (this.
|
|
577
|
+
if (this.kx === 0) return [];
|
|
535
578
|
const i = this.col(q[0]);
|
|
536
579
|
const j = this.row(q[1]);
|
|
537
|
-
if (i < 0 || j < 0 || i >= this.
|
|
538
|
-
return this.cells[j * this.
|
|
580
|
+
if (i < 0 || j < 0 || i >= this.kx || j >= this.kz) return [];
|
|
581
|
+
return this.cells[j * this.kx + i] ?? [];
|
|
539
582
|
}
|
|
540
583
|
/** The triangles in the cells a plan box covers, each once (callers sort what they derive). */
|
|
541
584
|
near(x0, z0, x1, z1) {
|
|
542
|
-
if (this.
|
|
543
|
-
const
|
|
585
|
+
if (this.kx === 0) return [];
|
|
586
|
+
const ci = (v) => Math.max(0, Math.min(this.kx - 1, v));
|
|
587
|
+
const cj = (v) => Math.max(0, Math.min(this.kz - 1, v));
|
|
544
588
|
const seen = /* @__PURE__ */ new Set();
|
|
545
|
-
for (let j =
|
|
546
|
-
for (let i =
|
|
547
|
-
for (const t of this.cells[j * this.
|
|
589
|
+
for (let j = cj(this.row(z0)); j <= cj(this.row(z1)); j++)
|
|
590
|
+
for (let i = ci(this.col(x0)); i <= ci(this.col(x1)); i++)
|
|
591
|
+
for (const t of this.cells[j * this.kx + i] ?? []) seen.add(t);
|
|
548
592
|
return [...seen];
|
|
549
593
|
}
|
|
550
594
|
};
|
|
595
|
+
function rowExtent(t, z0, z1) {
|
|
596
|
+
let lo = Infinity;
|
|
597
|
+
let hi = -Infinity;
|
|
598
|
+
const take = (x) => {
|
|
599
|
+
if (x < lo) lo = x;
|
|
600
|
+
if (x > hi) hi = x;
|
|
601
|
+
};
|
|
602
|
+
const ps = [t.a, t.b, t.c];
|
|
603
|
+
for (const p of ps) if (p[1] >= z0 && p[1] <= z1) take(p[0]);
|
|
604
|
+
for (let k = 0; k < 3; k++) {
|
|
605
|
+
const p = ps[k];
|
|
606
|
+
const q = ps[(k + 1) % 3];
|
|
607
|
+
if (p[1] === q[1]) continue;
|
|
608
|
+
for (const z of [z0, z1])
|
|
609
|
+
if ((p[1] - z) * (q[1] - z) < 0) take(p[0] + (q[0] - p[0]) * (z - p[1]) / (q[1] - p[1]));
|
|
610
|
+
}
|
|
611
|
+
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])];
|
|
612
|
+
return [lo, hi];
|
|
613
|
+
}
|
|
551
614
|
function flatFaces(n, up, y, out) {
|
|
552
615
|
const p = n.positions;
|
|
553
616
|
for (let i = 0; i < n.indices.length; i += 3) {
|
|
@@ -561,6 +624,87 @@ function flatFaces(n, up, y, out) {
|
|
|
561
624
|
if (up ? turn < 0 : turn > 0) out.push({ a, b, c, y: ya });
|
|
562
625
|
}
|
|
563
626
|
}
|
|
627
|
+
function narrowed(segs, band) {
|
|
628
|
+
const groups = /* @__PURE__ */ new Map();
|
|
629
|
+
for (const s of segs) {
|
|
630
|
+
const l = planLine(s.a[0], s.a[1], s.b[0], s.b[1]);
|
|
631
|
+
const key = `${l.dx},${l.dz}`;
|
|
632
|
+
const g = groups.get(key);
|
|
633
|
+
if (g) g.push(s);
|
|
634
|
+
else groups.set(key, [s]);
|
|
635
|
+
}
|
|
636
|
+
const near = /* @__PURE__ */ new Map();
|
|
637
|
+
const along = (s, o) => {
|
|
638
|
+
const dx = s.b[0] - s.a[0];
|
|
639
|
+
const dz = s.b[1] - s.a[1];
|
|
640
|
+
const l2 = dx * dx + dz * dz;
|
|
641
|
+
const ta = ((o.a[0] - s.a[0]) * dx + (o.a[1] - s.a[1]) * dz) / l2;
|
|
642
|
+
const tb = ((o.b[0] - s.a[0]) * dx + (o.b[1] - s.a[1]) * dz) / l2;
|
|
643
|
+
const t0 = Math.max(0, Math.min(ta, tb));
|
|
644
|
+
const t1 = Math.min(1, Math.max(ta, tb));
|
|
645
|
+
return t1 > t0 ? [t0, t1] : void 0;
|
|
646
|
+
};
|
|
647
|
+
const note = (s, o, w) => {
|
|
648
|
+
if (w >= band(s)) return;
|
|
649
|
+
const t = along(s, o);
|
|
650
|
+
if (!t) return;
|
|
651
|
+
const list = near.get(s);
|
|
652
|
+
if (list) list.push({ t0: t[0], t1: t[1], w });
|
|
653
|
+
else near.set(s, [{ t0: t[0], t1: t[1], w }]);
|
|
654
|
+
};
|
|
655
|
+
for (const key of [...groups.keys()].sort()) {
|
|
656
|
+
const g = groups.get(key);
|
|
657
|
+
if (g.length < 2) continue;
|
|
658
|
+
const [dx, dz] = key.split(",").map(Number);
|
|
659
|
+
const len = lengthOf(dx, dz);
|
|
660
|
+
let widest = 0;
|
|
661
|
+
for (const s of g) widest = Math.max(widest, band(s));
|
|
662
|
+
const reach = 2e3 * widest;
|
|
663
|
+
const items = g.map((s) => {
|
|
664
|
+
const [ta, tb] = [(dx * s.a[0] + dz * s.a[1]) / len, (dx * s.b[0] + dz * s.b[1]) / len];
|
|
665
|
+
return { s, off: (dx * s.a[1] - dz * s.a[0]) / len, lo: Math.min(ta, tb), hi: Math.max(ta, tb) };
|
|
666
|
+
}).sort((p, q) => p.lo - q.lo || p.off - q.off);
|
|
667
|
+
let active = [];
|
|
668
|
+
for (const it of items) {
|
|
669
|
+
active = active.filter((o) => o.hi > it.lo);
|
|
670
|
+
for (const o of active) {
|
|
671
|
+
if (Math.abs(o.off - it.off) > reach) continue;
|
|
672
|
+
const [s, t] = [it.s, o.s];
|
|
673
|
+
const fs = frame(s);
|
|
674
|
+
const ft = frame(t);
|
|
675
|
+
if (fs.d[0] * ft.d[0] + fs.d[1] * ft.d[1] >= 0) continue;
|
|
676
|
+
const ex = t.a[0] - s.a[0];
|
|
677
|
+
const ez = t.a[1] - s.a[1];
|
|
678
|
+
if (cross(fs.d[0], fs.d[1], ex, ez) >= 0) continue;
|
|
679
|
+
const c = BigInt(fs.d[0]) * BigInt(ez) - BigInt(fs.d[1]) * BigInt(ex);
|
|
680
|
+
const w = Math.max(0, -Number(c) / fs.len / 2e3);
|
|
681
|
+
note(s, t, w);
|
|
682
|
+
note(t, s, w);
|
|
683
|
+
}
|
|
684
|
+
active.push(it);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
return segs.flatMap((s) => {
|
|
688
|
+
const list = near.get(s);
|
|
689
|
+
if (!list) return [s];
|
|
690
|
+
const own = band(s);
|
|
691
|
+
const ts = [.../* @__PURE__ */ new Set([0, 1, ...list.flatMap((c) => [c.t0, c.t1])])].sort((x, y) => x - y);
|
|
692
|
+
const f = frame(s);
|
|
693
|
+
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)];
|
|
694
|
+
const out = [];
|
|
695
|
+
for (let k = 0; k + 1 < ts.length; k++) {
|
|
696
|
+
const [t0, t1] = [ts[k], ts[k + 1]];
|
|
697
|
+
const m = (t0 + t1) / 2;
|
|
698
|
+
let w = own;
|
|
699
|
+
for (const c of list) if (c.t0 <= m && m <= c.t1 && c.w < w) w = c.w;
|
|
700
|
+
const last = out[out.length - 1];
|
|
701
|
+
const lw = last ? last.w ?? own : void 0;
|
|
702
|
+
if (last && lw === w) last.b = at(t1);
|
|
703
|
+
else out.push({ a: at(t0), b: at(t1), node: s.node, ...w < own ? { w } : {} });
|
|
704
|
+
}
|
|
705
|
+
return out.filter((p) => p.a[0] !== p.b[0] || p.a[1] !== p.b[1]);
|
|
706
|
+
});
|
|
707
|
+
}
|
|
564
708
|
function outline(tris) {
|
|
565
709
|
const lines = /* @__PURE__ */ new Map();
|
|
566
710
|
for (const { node, p } of tris) {
|
|
@@ -661,6 +805,9 @@ var scaled = (v, mm) => [
|
|
|
661
805
|
var plus = (p, o) => [p[0] + o[0], p[1] + o[1]];
|
|
662
806
|
var MAX_FAN = 8;
|
|
663
807
|
function contactShadows(nodes, ground, lines) {
|
|
808
|
+
return contactShadowsWith(nodes, ground, lines, (tris) => new TriGrid(tris));
|
|
809
|
+
}
|
|
810
|
+
function contactShadowsWith(nodes, ground, lines, lookup) {
|
|
664
811
|
const counts = {
|
|
665
812
|
edges: 0,
|
|
666
813
|
convex: 0,
|
|
@@ -685,7 +832,7 @@ function contactShadows(nodes, ground, lines) {
|
|
|
685
832
|
for (const [n] of here)
|
|
686
833
|
if (n.kind === "floor" || n.kind === "slab" || n.kind === "outdoor" || n.flat === true)
|
|
687
834
|
flatFaces(n, true, void 0, faces);
|
|
688
|
-
const receivers =
|
|
835
|
+
const receivers = lookup(faces);
|
|
689
836
|
const groundY = level === lowest ? ground?.y : void 0;
|
|
690
837
|
const over = (qs) => {
|
|
691
838
|
let best;
|
|
@@ -729,7 +876,7 @@ function contactShadows(nodes, ground, lines) {
|
|
|
729
876
|
for (const [n] of walls) e = Math.min(e, yRange(n)[0]);
|
|
730
877
|
const tris = [];
|
|
731
878
|
for (const [n, i] of walls) downFaces(n, i, e, tris);
|
|
732
|
-
const solid =
|
|
879
|
+
const solid = lookup(tris.map((t) => ({ a: t.p[0], b: t.p[1], c: t.p[2], y: e, node: t.node })));
|
|
733
880
|
const inSolid = (q) => {
|
|
734
881
|
counts.probes++;
|
|
735
882
|
for (const f of solid.at(q)) {
|
|
@@ -738,7 +885,7 @@ function contactShadows(nodes, ground, lines) {
|
|
|
738
885
|
}
|
|
739
886
|
return false;
|
|
740
887
|
};
|
|
741
|
-
const
|
|
888
|
+
const cutSegs = outline(tris).flatMap((s) => {
|
|
742
889
|
const f = frame(s);
|
|
743
890
|
const ts = [0, 1];
|
|
744
891
|
const [bx0, bx1] = [Math.min(s.a[0], s.b[0]), Math.max(s.a[0], s.b[0])];
|
|
@@ -778,7 +925,8 @@ function contactShadows(nodes, ground, lines) {
|
|
|
778
925
|
if (from !== void 0) kept.push({ a: at(from), b: s.b, node: s.node });
|
|
779
926
|
return kept.filter((k) => k.a[0] !== k.b[0] || k.a[1] !== k.b[1]);
|
|
780
927
|
});
|
|
781
|
-
const bandOf = (s) => nodes[s.node]?.band ?? 0;
|
|
928
|
+
const bandOf = (s) => s.w ?? nodes[s.node]?.band ?? 0;
|
|
929
|
+
const segs = narrowed(cutSegs, bandOf);
|
|
782
930
|
const pk = (p) => `${p[0]},${p[1]}`;
|
|
783
931
|
const ending = /* @__PURE__ */ new Map();
|
|
784
932
|
const starting = /* @__PURE__ */ new Map();
|