@chanmeng666/archlang-3d 0.1.2 → 0.3.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.
@@ -1,15 +1,42 @@
1
1
  import {
2
2
  T0_HEIGHT_MM,
3
+ T0_HUNG_FROM_TOP,
4
+ T0_MATERIALS,
5
+ T0_MOUNT_MM,
6
+ assetFor,
3
7
  buildScene3D,
8
+ cutSector,
9
+ degenerateHoles,
4
10
  floorOverlaps,
11
+ insideCut,
12
+ isHandedAsset,
13
+ isHung,
5
14
  mixedHeightJoints,
6
- t0Parts,
7
- wallOwnership
8
- } from "./chunk-PJMKP2ML.js";
15
+ prism,
16
+ rect,
17
+ sectorBand,
18
+ slab2d,
19
+ t0Shells,
20
+ wallOwnership,
21
+ where
22
+ } from "./chunk-PRZXP6FP.js";
23
+ import {
24
+ floorFinish
25
+ } from "./chunk-VPYTRKMK.js";
9
26
 
10
27
  // src/adapter/adapt.ts
11
28
  import * as core from "@chanmeng666/archlang";
12
29
  var MIN_CORE = "1.45.0";
30
+ var hasHanded = (storeys) => storeys.some((s) => s.ir.elements.some((e) => e.kind === "furniture" && isHandedAsset(assetFor(e.category))));
31
+ function mirroredIds(source, world, n) {
32
+ const unknown = Array.from({ length: n }, () => null);
33
+ const planToJson2 = core.planToJson;
34
+ if (typeof planToJson2 !== "function") return unknown;
35
+ const r = planToJson2(source, world ? { world } : {});
36
+ const pages = r.pages ? r.pages.map((p) => p.json) : r.json ? [r.json] : [];
37
+ if (pages.length !== n) return unknown;
38
+ return pages.map((j) => new Set(j.furniture.flatMap((f) => f.mirror === true && f.id !== void 0 ? [f.id] : [])));
39
+ }
13
40
  function adaptPlan(source, opts = {}) {
14
41
  const resolvePlan2 = core.resolvePlan;
15
42
  const hatches = core.hatchKey;
@@ -44,7 +71,8 @@ function adaptPlan(source, opts = {}) {
44
71
  }
45
72
  const scene = buildScene3D(storeys, {
46
73
  coreVersion: opts.coreVersion ?? "unknown",
47
- ...opts.curveTolMm !== void 0 ? { curveTolMm: opts.curveTolMm } : {}
74
+ ...opts.curveTolMm !== void 0 ? { curveTolMm: opts.curveTolMm } : {},
75
+ ...hasHanded(storeys) ? { mirrored: mirroredIds(source, opts.world, storeys.length) } : {}
48
76
  });
49
77
  return {
50
78
  ok: true,
@@ -58,258 +86,6 @@ function adaptPlan(source, opts = {}) {
58
86
  };
59
87
  }
60
88
 
61
- // src/mesh/extrude.ts
62
- import earcut from "earcut";
63
- var area2 = (r) => {
64
- let s = 0;
65
- for (let i = 0; i < r.length; i++) {
66
- const a = r[i];
67
- const b = r[(i + 1) % r.length];
68
- s += a[0] * b[1] - b[0] * a[1];
69
- }
70
- return s;
71
- };
72
- function clean(r) {
73
- const out = [];
74
- for (const p of r) {
75
- const q = out[out.length - 1];
76
- if (!q || q[0] !== p[0] || q[1] !== p[1]) out.push(p);
77
- }
78
- while (out.length > 1 && out[0]?.[0] === out[out.length - 1]?.[0] && out[0]?.[1] === out[out.length - 1]?.[1])
79
- out.pop();
80
- return out.length >= 3 && area2(out) !== 0 ? out : null;
81
- }
82
- var orient = (r, ccw) => area2(r) > 0 === ccw ? r : [...r].reverse();
83
- var degenerateHoles = (poly) => (poly.holes ?? []).filter((h) => clean(h) === null).length;
84
- function where(p, r) {
85
- let c = false;
86
- for (let i = 0, j = r.length - 1; i < r.length; j = i++) {
87
- const a = r[i];
88
- const b = r[j];
89
- const cross = (b[0] - a[0]) * (p[1] - a[1]) - (b[1] - a[1]) * (p[0] - a[0]);
90
- const within = Math.min(a[0], b[0]) <= p[0] && p[0] <= Math.max(a[0], b[0]) && Math.min(a[1], b[1]) <= p[1] && p[1] <= Math.max(a[1], b[1]);
91
- if (cross === 0 && within) return null;
92
- if (a[1] > p[1] !== b[1] > p[1] && p[0] < (b[0] - a[0]) * (p[1] - a[1]) / (b[1] - a[1]) + a[0]) c = !c;
93
- }
94
- return c;
95
- }
96
- function holesApart(outer, holes) {
97
- const strictlyIn = (ps, r) => ps.every((p) => where(p, r) === true);
98
- const strictlyOut = (ps, r) => ps.every((p) => where(p, r) === false);
99
- return holes.every(
100
- (h, i) => strictlyIn(h, outer) && strictlyOut(outer, h) && holes.every((g, j) => j === i || strictlyOut(h, g) && strictlyOut(g, h))
101
- );
102
- }
103
- function prism(poly, z0, z1, splits) {
104
- if (!(z1 > z0)) return null;
105
- const outer = clean(poly.outer);
106
- if (!outer) return null;
107
- const rings = [orient(outer, true)];
108
- for (const h of poly.holes ?? []) {
109
- const c = clean(h);
110
- if (c) rings.push(orient(c, false));
111
- }
112
- if (!holesApart(rings[0], rings.slice(1))) return null;
113
- const flat = [];
114
- const holes = [];
115
- rings.forEach((r, i) => {
116
- if (i > 0) holes.push(flat.length / 2);
117
- for (const p of r) flat.push(p[0], p[1]);
118
- });
119
- const tris = earcut(flat, holes, 2);
120
- const n = flat.length / 2;
121
- const positions = [];
122
- for (const z of [z0, z1])
123
- for (let i = 0; i < n; i++) positions.push(flat[2 * i], z, flat[2 * i + 1]);
124
- const indices = [];
125
- const v = (i) => [
126
- positions[3 * i],
127
- positions[3 * i + 1],
128
- positions[3 * i + 2]
129
- ];
130
- const face = (a, b, c, want) => {
131
- const [A, B, C] = [v(a), v(b), v(c)];
132
- const u = [B[0] - A[0], B[1] - A[1], B[2] - A[2]];
133
- const w = [C[0] - A[0], C[1] - A[1], C[2] - A[2]];
134
- const nrm = [
135
- u[1] * w[2] - u[2] * w[1],
136
- u[2] * w[0] - u[0] * w[2],
137
- u[0] * w[1] - u[1] * w[0]
138
- ];
139
- const dot = nrm[0] * want[0] + nrm[1] * want[1] + nrm[2] * want[2];
140
- if (dot >= 0) indices.push(a, b, c);
141
- else indices.push(a, c, b);
142
- };
143
- for (let t = 0; t < tris.length; t += 3) {
144
- const [a, b, c] = [tris[t], tris[t + 1], tris[t + 2]];
145
- face(n + a, n + b, n + c, [0, 1, 0]);
146
- face(a, b, c, [0, -1, 0]);
147
- }
148
- const column = [];
149
- for (let i = 0; i < n; i++) {
150
- const p = [flat[2 * i], flat[2 * i + 1]];
151
- const hs = splits ? [...new Set(splits(p))].filter((h) => h > z0 && h < z1).sort((x, y) => x - y) : [];
152
- const col = [i];
153
- for (const h of hs) {
154
- col.push(positions.length / 3);
155
- positions.push(p[0], h, p[1]);
156
- }
157
- col.push(n + i);
158
- column.push(col);
159
- }
160
- const height = (v2) => positions[3 * v2 + 1];
161
- let base = 0;
162
- for (const r of rings) {
163
- for (let k = 0; k < r.length; k++) {
164
- const i = base + k;
165
- const j = base + (k + 1) % r.length;
166
- const a = r[k];
167
- const b = r[(k + 1) % r.length];
168
- const out = [b[1] - a[1], 0, -(b[0] - a[0])];
169
- const ci = column[i];
170
- const cj = column[j];
171
- if (ci.length === 2 && cj.length === 2) {
172
- face(i, j, n + j, out);
173
- face(i, n + j, n + i, out);
174
- continue;
175
- }
176
- let u = 0;
177
- let w = 0;
178
- while (u < ci.length - 1 || w < cj.length - 1) {
179
- const hu = u < ci.length - 1 ? height(ci[u + 1]) : Number.POSITIVE_INFINITY;
180
- const hw = w < cj.length - 1 ? height(cj[w + 1]) : Number.POSITIVE_INFINITY;
181
- if (hu <= hw) {
182
- face(ci[u], cj[w], ci[u + 1], out);
183
- u++;
184
- } else {
185
- face(ci[u], cj[w], cj[w + 1], out);
186
- w++;
187
- }
188
- }
189
- }
190
- base += r.length;
191
- }
192
- return { positions, indices };
193
- }
194
- function rect(x0, y0, x1, y1) {
195
- return {
196
- outer: [
197
- [x0, y0],
198
- [x1, y0],
199
- [x1, y1],
200
- [x0, y1]
201
- ]
202
- };
203
- }
204
- function slab2d(a, b, depth) {
205
- const dx = b[0] - a[0];
206
- const dy = b[1] - a[1];
207
- const len = Math.hypot(dx, dy) || 1;
208
- const nx = -dy / len * (depth / 2);
209
- const ny = dx / len * (depth / 2);
210
- const p = (x, y) => [Math.round(x), Math.round(y)];
211
- return {
212
- outer: [p(a[0] + nx, a[1] + ny), p(b[0] + nx, b[1] + ny), p(b[0] - nx, b[1] - ny), p(a[0] - nx, a[1] - ny)]
213
- };
214
- }
215
- function clipToConvex(ring, convex) {
216
- const c = area2(convex) > 0 ? [...convex] : [...convex].reverse();
217
- let out = ring.map((p) => [p[0], p[1]]);
218
- for (let k = 0; k < c.length && out.length > 0; k++) {
219
- const a = c[k];
220
- const b = c[(k + 1) % c.length];
221
- const side = (p) => (b[0] - a[0]) * (p[1] - a[1]) - (b[1] - a[1]) * (p[0] - a[0]);
222
- const input = out;
223
- out = [];
224
- for (let i = 0; i < input.length; i++) {
225
- const p = input[i];
226
- const q = input[(i + 1) % input.length];
227
- const sp = side(p);
228
- const sq = side(q);
229
- if (sp >= 0) out.push(p);
230
- if (sp >= 0 !== sq >= 0) {
231
- const t = sp / (sp - sq);
232
- out.push([p[0] + (q[0] - p[0]) * t, p[1] + (q[1] - p[1]) * t]);
233
- }
234
- }
235
- }
236
- const rounded = clean(out.map((p) => [Math.round(p[0]), Math.round(p[1])]));
237
- return rounded ? { outer: rounded } : null;
238
- }
239
- function insideCut(poly, ring) {
240
- if (poly.outer.every((p) => where(p, ring) !== false)) return poly;
241
- return clipToConvex(ring, poly.outer);
242
- }
243
- var TAU = 2 * Math.PI;
244
- var mod2pi = (x) => (x % TAU + TAU) % TAU;
245
- function cutSector(cut, jambs, centre) {
246
- const ring = clean(cut);
247
- if (!ring || ring.length <= 4) return null;
248
- const n = ring.length;
249
- const turn = ring.map((p, i) => {
250
- const a = ring[(i + n - 1) % n];
251
- const b = ring[(i + 1) % n];
252
- const u2 = [p[0] - a[0], p[1] - a[1]];
253
- const v2 = [b[0] - p[0], b[1] - p[1]];
254
- return Math.abs(
255
- Math.atan2(
256
- u2[0] * v2[1] - u2[1] * v2[0],
257
- u2[0] * v2[0] + u2[1] * v2[1]
258
- )
259
- );
260
- });
261
- const corners = turn.map((t, i) => [t, i]).sort((a, b) => b[0] - a[0] || a[1] - b[1]).slice(0, 4).map(([, i]) => i).sort((a, b) => a - b);
262
- const paths = corners.map((ci, k) => {
263
- const cj = corners[(k + 1) % 4];
264
- return { a: ring[ci], b: ring[cj], edges: (cj - ci + n) % n };
265
- });
266
- const mid = (p) => [(p.a[0] + p.b[0]) / 2, (p.a[1] + p.b[1]) / 2];
267
- const d = (p, q) => Math.hypot(p[0] - q[0], p[1] - q[1]);
268
- let best = null;
269
- for (const [i, j] of [
270
- [0, 2],
271
- [1, 3]
272
- ]) {
273
- const [p, q] = [paths[i], paths[j]];
274
- const arcs = Math.max(
275
- paths[(i + 1) % 4].edges,
276
- paths[(j + 1) % 4].edges
277
- );
278
- const straight = d(mid(p), jambs[0]) + d(mid(q), jambs[1]);
279
- const swapped = d(mid(q), jambs[0]) + d(mid(p), jambs[1]);
280
- const cand = straight <= swapped ? { cost: straight, f0: p, f1: q, arcs } : { cost: swapped, f0: q, f1: p, arcs };
281
- if (!best || cand.cost < best.cost) best = cand;
282
- }
283
- if (!best) return null;
284
- const { f0, f1 } = best;
285
- const u = [f0.b[0] - f0.a[0], f0.b[1] - f0.a[1]];
286
- const v = [f1.b[0] - f1.a[0], f1.b[1] - f1.a[1]];
287
- const den = u[0] * v[1] - u[1] * v[0];
288
- if (Math.abs(den) <= 1e-9 * Math.hypot(...u) * Math.hypot(...v)) return null;
289
- const s = ((f1.a[0] - f0.a[0]) * v[1] - (f1.a[1] - f0.a[1]) * v[0]) / den;
290
- const c = [f0.a[0] + s * u[0], f0.a[1] + s * u[1]];
291
- const m0 = mid(f0);
292
- const m1 = mid(f1);
293
- const r = (d(m0, c) + d(m1, c)) / 2;
294
- const t0 = Math.atan2(m0[1] - c[1], m0[0] - c[0]);
295
- const t1 = Math.atan2(m1[1] - c[1], m1[0] - c[0]);
296
- const tc = Math.atan2(centre[1] - c[1], centre[0] - c[0]);
297
- const ccw = mod2pi(t1 - t0);
298
- const sweep = mod2pi(tc - t0) <= ccw ? ccw : ccw - TAU;
299
- return { c, r, t0, sweep, steps: Math.max(1, best.arcs) };
300
- }
301
- function sectorBand(sector, d0, d1, f0 = 0, f1 = 1) {
302
- const k = Math.max(1, Math.ceil(sector.steps * (f1 - f0)));
303
- const at = (rr, f) => {
304
- const t = sector.t0 + sector.sweep * f;
305
- return [Math.round(sector.c[0] + rr * Math.cos(t)), Math.round(sector.c[1] + rr * Math.sin(t))];
306
- };
307
- const outer = [];
308
- for (let i = 0; i <= k; i++) outer.push(at(sector.r + d1, f0 + (f1 - f0) * i / k));
309
- for (let i = k; i >= 0; i--) outer.push(at(sector.r + d0, f0 + (f1 - f0) * i / k));
310
- return { outer };
311
- }
312
-
313
89
  // src/mesh/slab.ts
314
90
  var rectPolygon = (r) => ({
315
91
  outer: [
@@ -591,12 +367,25 @@ function levelNodes(lv, ledger, defaulted, isTop, doors) {
591
367
  lv.floors.forEach((f, i) => {
592
368
  const pieces = f.polygon.holes?.length ? [f.polygon] : lessVoids(f.polygon.outer, lv.voids, `floor:${f.id}`, ledger);
593
369
  const z0 = e + (f.lift ?? 0);
370
+ const finish = floorFinish(f.uses);
371
+ ledger.push({
372
+ kind: "floor",
373
+ id: f.id,
374
+ field: "finish",
375
+ value: finish,
376
+ provenance: "default",
377
+ rule: "floor-finish-default"
378
+ });
594
379
  node(
595
380
  "floor",
596
381
  f.id,
597
382
  i,
598
383
  pieces.map((p) => prism2(p, z0, z0 + FLOOR_FINISH_MM * MM)),
599
- { ...f.uses?.length ? { uses: f.uses.join(" ") } : {}, ...f.lift ? { lift_mm: f.lift / MM } : {} }
384
+ {
385
+ ...f.uses?.length ? { uses: f.uses.join(" ") } : {},
386
+ ...f.lift ? { lift_mm: f.lift / MM } : {},
387
+ finish
388
+ }
600
389
  );
601
390
  });
602
391
  lv.columns.forEach((c, i) => {
@@ -741,8 +530,9 @@ function levelNodes(lv, ledger, defaulted, isTop, doors) {
741
530
  }
742
531
  });
743
532
  const floorTop = e + FLOOR_FINISH_MM * MM;
533
+ const tallest = lv.walls.reduce((m, w) => Math.max(m, w.height), 0) || lv.storeyHeight;
744
534
  lv.furniture.forEach((f, i) => {
745
- const parts = t0Parts(f);
535
+ const parts = t0Shells(f, floorTop);
746
536
  const family = parts ? f.asset.slice("t0:".length) : void 0;
747
537
  const h = family ? T0_HEIGHT_MM[family] ?? 0 : FURNITURE_HEIGHT_MM[f.category] ?? FURNITURE_DEFAULT_MM;
748
538
  if (!defaulted.has(f.category)) {
@@ -754,6 +544,26 @@ function levelNodes(lv, ledger, defaulted, isTop, doors) {
754
544
  provenance: "default",
755
545
  rule: family ? "furniture-height-t0" : f.category in FURNITURE_HEIGHT_MM ? "furniture-height-family" : "furniture-height-greybox"
756
546
  });
547
+ const mount = family ? T0_MOUNT_MM[family] : void 0;
548
+ if (mount !== void 0) {
549
+ ledger.push({
550
+ kind: "furniture",
551
+ field: `mount_mm(${f.category})`,
552
+ value: mount,
553
+ provenance: "default",
554
+ rule: "furniture-mount-default"
555
+ });
556
+ }
557
+ const slots = family ? T0_MATERIALS[family] : void 0;
558
+ if (slots?.length) {
559
+ ledger.push({
560
+ kind: "furniture",
561
+ field: `material(${f.category})`,
562
+ value: [...slots],
563
+ provenance: "default",
564
+ rule: "furniture-material-default"
565
+ });
566
+ }
757
567
  }
758
568
  const asset = parts ? f.asset : "greybox";
759
569
  if (f.asset !== asset) {
@@ -766,17 +576,50 @@ function levelNodes(lv, ledger, defaulted, isTop, doors) {
766
576
  rule: "furniture-t0-not-quarter-turn"
767
577
  });
768
578
  }
579
+ if (parts && family && isHung(family)) {
580
+ if (T0_HUNG_FROM_TOP.has(family)) {
581
+ const low = Math.min(...parts.shells.flatMap((s) => s ? s.positions.filter((_, k) => k % 3 === 1) : []));
582
+ ledger.push({
583
+ kind: "furniture",
584
+ id: f.id,
585
+ field: "mount_mm",
586
+ value: (low - floorTop) / MM,
587
+ provenance: "default",
588
+ rule: "furniture-mount-from-top"
589
+ });
590
+ }
591
+ if (floorTop + h * MM > e + tallest) {
592
+ ledger.push({
593
+ kind: "furniture",
594
+ id: f.id,
595
+ field: "top_mm",
596
+ value: h,
597
+ provenance: "default",
598
+ rule: "furniture-hung-above-walls"
599
+ });
600
+ }
601
+ } else if (parts && family && floorTop + h * MM > e + tallest) {
602
+ ledger.push({
603
+ kind: "furniture",
604
+ id: f.id,
605
+ field: "top_mm",
606
+ value: h,
607
+ provenance: "default",
608
+ rule: "furniture-above-walls"
609
+ });
610
+ }
769
611
  const [cx, cy] = f.centre;
770
612
  const box = rect(cx - f.size.w / 2, cy - f.size.d / 2, cx + f.size.w / 2, cy + f.size.d / 2);
771
- const shells = parts ? parts.map((p) => prism2(p.polygon, floorTop + p.y0, floorTop + p.y1)) : [prism2(box, floorTop, floorTop + h * MM)];
613
+ if (parts) holesLeftOut += parts.holesDropped;
614
+ const shells = parts ? parts.shells : [prism2(box, floorTop, floorTop + h * MM)];
772
615
  node("furniture", f.id, i, shells, {
773
616
  category: f.category,
774
617
  yaw_deg: f.yawDeg,
775
618
  asset,
776
- ...f.room ? { room: f.room } : {}
619
+ ...f.room ? { room: f.room } : {},
620
+ ...parts && f.mirror ? { mirror: true } : {}
777
621
  });
778
622
  });
779
- const tallest = lv.walls.reduce((m, w) => Math.max(m, w.height), 0) || lv.storeyHeight;
780
623
  const roofZ = [e + tallest, e + tallest + ROOF_MM * MM];
781
624
  lv.roofs.forEach((r, i) => {
782
625
  node("roof", r.id, i, [prism2({ outer: r.ring }, ...roofZ)], { form: r.form });
@@ -842,12 +685,6 @@ function buildMesh(scene, opts = {}) {
842
685
  export {
843
686
  MIN_CORE,
844
687
  adaptPlan,
845
- prism,
846
- slab2d,
847
- clipToConvex,
848
- insideCut,
849
- cutSector,
850
- sectorBand,
851
688
  rectsOf,
852
689
  slabRegion,
853
690
  FURNITURE_HEIGHT_MM,
@@ -1,3 +1,118 @@
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 KIND_PALETTE = {
50
+ slab: m("#bdb6ab", 0.9),
51
+ column: m("#e6e1d8", 0.85),
52
+ wall: m("#f2f0eb", 0.9),
53
+ door: m("#c2a27e", 0.7),
54
+ "window:frame": m("#55534f", 0.5),
55
+ "window:glass": m("#bcd6e0", 0.05, 0, 0.4),
56
+ opening: m("#e6e1d8", 0.85),
57
+ furniture: m("#d6cec1", 0.9),
58
+ roof: m("#9c958a", 0.9),
59
+ "wall:demolish": m("#c8553d", 0.9, 0, 0.3)
60
+ };
61
+ var WALL_CAP_SRGB = "#8f877d";
62
+ var FLOOR_FINISHES = ["timber", "tile", "neutral"];
63
+ var FINISH_PALETTE = {
64
+ timber: m("#cdb596", 0.6),
65
+ tile: m("#e3e1db", 0.35),
66
+ neutral: m("#e8e2d7", 0.9)
67
+ };
68
+ var FLOOR_FINISH_RULES = [
69
+ ["tile", ["bath", "wc", "utility"]],
70
+ ["timber", ["living", "dining", "bedroom", "office", "hall", "circulation"]],
71
+ ["tile", ["kitchen", "entry"]]
72
+ ];
73
+ function floorFinish(uses) {
74
+ for (const [finish, kinds] of FLOOR_FINISH_RULES) if (uses?.some((u) => kinds.includes(u))) return finish;
75
+ return "neutral";
76
+ }
77
+ function linearRgb(hex) {
78
+ const ch = (i) => {
79
+ const c = Number.parseInt(hex.slice(i, i + 2), 16) / 255;
80
+ const v = c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
81
+ return Math.round(v * 1e4) / 1e4;
82
+ };
83
+ return [ch(1), ch(3), ch(5)];
84
+ }
85
+ function slotColour(slot, theme, furniture) {
86
+ const own = PALETTE[slot].srgb;
87
+ if (theme === "light") return own;
88
+ const mix = (i) => {
89
+ const a = Number.parseInt(own.slice(i, i + 2), 16);
90
+ const b = Number.parseInt(furniture.slice(i, i + 2), 16);
91
+ return Math.round(a * 0.4 + b * 0.6).toString(16).padStart(2, "0");
92
+ };
93
+ return `#${mix(1)}${mix(3)}${mix(5)}`;
94
+ }
95
+ function finishColour(finish, theme, floor) {
96
+ const own = FINISH_PALETTE[finish].srgb;
97
+ if (theme === "light") return own;
98
+ const mix = (i) => {
99
+ const a = Number.parseInt(own.slice(i, i + 2), 16);
100
+ const b = Number.parseInt(floor.slice(i, i + 2), 16);
101
+ return Math.round(a * 0.4 + b * 0.6).toString(16).padStart(2, "0");
102
+ };
103
+ return `#${mix(1)}${mix(3)}${mix(5)}`;
104
+ }
105
+ function slotGroups(shells) {
106
+ const by = /* @__PURE__ */ new Map();
107
+ for (const s of shells) {
108
+ const k = s.slot ?? "body";
109
+ const g = by.get(k);
110
+ if (g) g.push(s);
111
+ else by.set(k, [s]);
112
+ }
113
+ return MATERIAL_SLOTS.filter((k) => by.has(k)).map((slot) => ({ slot, shells: by.get(slot) }));
114
+ }
115
+
1
116
  // src/replay/timeline.ts
2
117
  var PHASE = {
3
118
  /** Footprints have all appeared. */
@@ -201,7 +316,7 @@ function stateAt(events, t) {
201
316
  };
202
317
  }
203
318
  function keyFrames(events) {
204
- const first = (s) => events.filter((e) => e.stage === s && !e.hidden).reduce((m, e) => m === void 0 || e.appear < m ? e.appear : m, void 0);
319
+ const first = (s) => events.filter((e) => e.stage === s && !e.hidden).reduce((m3, e) => m3 === void 0 || e.appear < m3 ? e.appear : m3, void 0);
205
320
  const out = [];
206
321
  for (const s of STAGES) {
207
322
  const t = first(s);
@@ -401,8 +516,51 @@ function drawingFrame(viewBox, aspect) {
401
516
  const ow = Math.max(vw, vh * aspect);
402
517
  return { cx: vx + vw / 2, cz: vy + vh / 2, ow, oh: ow / aspect };
403
518
  }
519
+ var PRESET_NAMES = ["iso", "top", "north", "east", "south", "west"];
520
+ var ELEVATION_AZIMUTH = { north: 180, east: 90, south: 0, west: -90 };
521
+ var ELEVATION_RANGE = { min: 0, max: 90 };
522
+ function pivotAbove(position, target, minY) {
523
+ if (target[1] >= minY || position[1] <= minY) return target;
524
+ const s = (position[1] - minY) / (position[1] - target[1]);
525
+ return [position[0] + (target[0] - position[0]) * s, minY, position[2] + (target[2] - position[2]) * s];
526
+ }
527
+ function presetCamera(name, v) {
528
+ if (name === "iso") return frameCamera(stateAt(v.events, 1), v.fits, v.frame);
529
+ const bearing = name === "top" ? { elevation: ELEVATION_RANGE.max, azimuth: ELEVATION_AZIMUTH.south } : { elevation: ELEVATION_RANGE.min, azimuth: ELEVATION_AZIMUTH[name] };
530
+ const fit = fitEndCamera(v.box, { ...bearing, fov: END_FOV, aspect: v.aspect });
531
+ return { target: fit.target, dist: fit.dist, fov: END_FOV, ...bearing };
532
+ }
533
+ function takenLens(f) {
534
+ if (f.fov === END_FOV) return f;
535
+ return { ...f, fov: END_FOV, dist: f.dist * Math.tan(rad(f.fov) / 2) / Math.tan(rad(END_FOV) / 2) };
536
+ }
537
+ var ZOOM = { in: 8, out: 3 };
538
+ function distanceLimits(fits, fov) {
539
+ const whole = fits[fits.length - 1].dist;
540
+ const k = Math.tan(rad(END_FOV) / 2) / Math.tan(rad(fov) / 2);
541
+ return { min: whole * k / ZOOM.in, max: whole * k * ZOOM.out };
542
+ }
543
+ function targetBounds(box) {
544
+ const d = [box.hi[0] - box.lo[0], box.hi[1] - box.lo[1], box.hi[2] - box.lo[2]];
545
+ return {
546
+ centre: [(box.lo[0] + box.hi[0]) / 2, (box.lo[1] + box.hi[1]) / 2, (box.lo[2] + box.hi[2]) / 2],
547
+ radius: Math.hypot(d[0], d[1], d[2]) / 2
548
+ };
549
+ }
404
550
 
405
551
  export {
552
+ MATERIAL_SLOTS,
553
+ PALETTE,
554
+ KIND_PALETTE,
555
+ WALL_CAP_SRGB,
556
+ FLOOR_FINISHES,
557
+ FINISH_PALETTE,
558
+ FLOOR_FINISH_RULES,
559
+ floorFinish,
560
+ linearRgb,
561
+ slotColour,
562
+ finishColour,
563
+ slotGroups,
406
564
  PHASE,
407
565
  FIXTURE_FAMILIES,
408
566
  authoringOrder,
@@ -431,5 +589,14 @@ export {
431
589
  cameraStops,
432
590
  cameraAtStop,
433
591
  frameCamera,
434
- drawingFrame
592
+ drawingFrame,
593
+ PRESET_NAMES,
594
+ ELEVATION_AZIMUTH,
595
+ ELEVATION_RANGE,
596
+ pivotAbove,
597
+ presetCamera,
598
+ takenLens,
599
+ ZOOM,
600
+ distanceLimits,
601
+ targetBounds
435
602
  };