@chanmeng666/archlang-3d 0.3.0 → 0.5.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.
@@ -46,6 +46,7 @@ var PALETTE = {
46
46
  soil: m("#5f4b3b", 1),
47
47
  water: m("#a3c6d0", 0.1, 0, 0.7)
48
48
  };
49
+ var STAIR_MATERIAL = "wood";
49
50
  var KIND_PALETTE = {
50
51
  slab: m("#bdb6ab", 0.9),
51
52
  column: m("#e6e1d8", 0.85),
@@ -56,7 +57,10 @@ var KIND_PALETTE = {
56
57
  opening: m("#e6e1d8", 0.85),
57
58
  furniture: m("#d6cec1", 0.9),
58
59
  roof: m("#9c958a", 0.9),
59
- "wall:demolish": m("#c8553d", 0.9, 0, 0.3)
60
+ "wall:demolish": m("#c8553d", 0.9, 0, 0.3),
61
+ // A stair (card X3): the core gives it no material, so the ledgered default (`STAIR_MATERIAL`,
62
+ // `stair-material-default`): that slot's own entry, never a second copy of its colour.
63
+ stair: PALETTE[STAIR_MATERIAL]
60
64
  };
61
65
  var WALL_CAP_SRGB = "#8f877d";
62
66
  var FLOOR_FINISHES = ["timber", "tile", "neutral"];
@@ -127,7 +131,7 @@ var PHASE = {
127
131
  tilted: 0.78,
128
132
  /** Every wall has risen; fixtures rise from here. */
129
133
  wallsUp: 0.84,
130
- /** Everything has risen. */
134
+ /** Everything has risen; several storeys combined settle from here to the end (`stateAt`). */
131
135
  done: 0.96
132
136
  };
133
137
  var FIXTURE_FAMILIES = /* @__PURE__ */ new Set([
@@ -160,6 +164,8 @@ function groupOf(n) {
160
164
  return n.extras.category === "exterior" ? 1 : 2;
161
165
  case "roof":
162
166
  return 3;
167
+ case "stair":
168
+ return 3;
163
169
  case "door":
164
170
  return 0;
165
171
  case "window":
@@ -305,16 +311,24 @@ function stateAt(events, t) {
305
311
  const b = starts[k];
306
312
  if (u > a) stop = k - 1 + (b > a ? ease((u - a) / (b - a)) : 1);
307
313
  }
314
+ let settle = 0;
315
+ if (ends.length > 1) {
316
+ const from = settleFrom(ends);
317
+ settle = from < 1 ? ease((u - from) / (1 - from)) : u >= 1 ? 1 : 0;
318
+ if (settle > 0) stop = ends.length - 1 + settle;
319
+ }
308
320
  return {
309
321
  // The tilt is done by the first stop, so every stop sees the end orbit its camera was fitted for
310
322
  // (one storey: `first` is 1 and the tilt keeps PHASE's own timing).
311
323
  tilt: ease((u - PHASE.rise) / (Math.min(PHASE.tilted, first) - PHASE.rise)),
312
324
  dolly: ease((u - PHASE.rise) / (first - PHASE.rise)),
313
325
  stop,
326
+ settle,
314
327
  svg,
315
328
  nodes
316
329
  };
317
330
  }
331
+ var settleFrom = (ends) => Math.max(PHASE.done, ...ends);
318
332
  function keyFrames(events) {
319
333
  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);
320
334
  const out = [];
@@ -456,7 +470,7 @@ function boxOfNodes(nodes, opts = {}) {
456
470
  const hi = [-Infinity, -Infinity, -Infinity];
457
471
  const standing = opts.ghosts ? nodes : nodes.filter((n) => n.part !== "demolish");
458
472
  for (const n of standing.length > 0 ? standing : nodes) {
459
- const lift = n.lift ?? 0;
473
+ const lift = opts.settle === void 0 ? n.lift ?? 0 : settledLift(n.lift, opts.settle);
460
474
  for (let i = 0; i < n.positions.length; i += 3) {
461
475
  const p = [
462
476
  n.positions[i] / 1e3,
@@ -471,13 +485,16 @@ function boxOfNodes(nodes, opts = {}) {
471
485
  }
472
486
  return { lo, hi };
473
487
  }
488
+ var settledLift = (lift, settle) => (lift ?? 0) * (1 - settle);
489
+ var stopCount = (events) => Math.max(1, ...events.map((e) => (e.storey ?? 0) + 1));
474
490
  var START_FOV = 1.5;
475
491
  function cameraStops(nodes, events, o) {
476
492
  const storeyOf = new Map(events.map((e) => [e.key, e.storey ?? 0]));
477
- const stops = Math.max(1, ...events.map((e) => (e.storey ?? 0) + 1));
493
+ const stops = stopCount(events);
478
494
  const fits = [];
479
495
  for (let k = 0; k < stops; k++)
480
496
  fits.push(fitEndCamera(boxOfNodes(nodes.filter((n) => (storeyOf.get(n.key) ?? 0) <= k)), o));
497
+ if (stops > 1) fits.push(fitEndCamera(boxOfNodes(nodes, { settle: 1 }), o));
481
498
  return fits;
482
499
  }
483
500
  function cameraAtStop(fits, stop) {
@@ -551,6 +568,7 @@ function targetBounds(box) {
551
568
  export {
552
569
  MATERIAL_SLOTS,
553
570
  PALETTE,
571
+ STAIR_MATERIAL,
554
572
  KIND_PALETTE,
555
573
  WALL_CAP_SRGB,
556
574
  FLOOR_FINISHES,
@@ -585,6 +603,8 @@ export {
585
603
  END_AZIMUTH,
586
604
  endElevation,
587
605
  boxOfNodes,
606
+ settledLift,
607
+ stopCount,
588
608
  START_FOV,
589
609
  cameraStops,
590
610
  cameraAtStop,
@@ -19,14 +19,15 @@ import {
19
19
  t0Shells,
20
20
  wallOwnership,
21
21
  where
22
- } from "./chunk-PRZXP6FP.js";
22
+ } from "./chunk-WCWLYIVD.js";
23
23
  import {
24
+ STAIR_MATERIAL,
24
25
  floorFinish
25
- } from "./chunk-VPYTRKMK.js";
26
+ } from "./chunk-EQBMPXB5.js";
26
27
 
27
28
  // src/adapter/adapt.ts
28
29
  import * as core from "@chanmeng666/archlang";
29
- var MIN_CORE = "1.45.0";
30
+ var MIN_CORE = "1.57.0";
30
31
  var hasHanded = (storeys) => storeys.some((s) => s.ir.elements.some((e) => e.kind === "furniture" && isHandedAsset(assetFor(e.category))));
31
32
  function mirroredIds(source, world, n) {
32
33
  const unknown = Array.from({ length: n }, () => null);
@@ -169,6 +170,141 @@ function slabRegion(footprint, floors, ledger) {
169
170
  }
170
171
  return out;
171
172
  }
173
+ var PROBE_MIN = 2;
174
+ var PROBE_OFF = 1;
175
+ function meets(a, b, c, d) {
176
+ const rx = b[0] - a[0];
177
+ const ry = b[1] - a[1];
178
+ const sx = d[0] - c[0];
179
+ const sy = d[1] - c[1];
180
+ const qx = c[0] - a[0];
181
+ const qy = c[1] - a[1];
182
+ const den = rx * sy - ry * sx;
183
+ if (den !== 0) {
184
+ const t = (qx * sy - qy * sx) / den;
185
+ const u = (qx * ry - qy * rx) / den;
186
+ return t >= 0 && t <= 1 && u >= 0 && u <= 1 ? [t] : [];
187
+ }
188
+ if (qx * ry - qy * rx !== 0) return [];
189
+ const rr = rx * rx + ry * ry;
190
+ return [qx * rx + qy * ry, (d[0] - a[0]) * rx + (d[1] - a[1]) * ry].map((x) => x / rr).filter((t) => t > 0 && t < 1);
191
+ }
192
+ function stretches(a, b, cutters) {
193
+ const len = Math.hypot(b[0] - a[0], b[1] - a[1]);
194
+ const ts = [0, 1, ...cutters.flatMap(([c, d]) => meets(a, b, c, d))].sort((x, y) => x - y);
195
+ const out = [];
196
+ for (let i = 1; i < ts.length; i++) {
197
+ const t0 = ts[i - 1];
198
+ const t1 = ts[i];
199
+ if ((t1 - t0) * len < PROBE_MIN) continue;
200
+ const t = (t0 + t1) / 2;
201
+ out.push([a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t]);
202
+ }
203
+ return out;
204
+ }
205
+ var edgesOf = (r) => r.map((p, i) => [p, r[(i + 1) % r.length]]);
206
+ function coveredBy(ring, region) {
207
+ if (region.length === 0 || ring.length < 3) return false;
208
+ const inRegion = (p) => region.some((s) => where(p, s.outer) !== false && !(s.holes ?? []).some((h) => where(p, h) === true));
209
+ const ringEdges = edgesOf(ring);
210
+ const regionEdges = region.flatMap((s) => [s.outer, ...s.holes ?? []].flatMap(edgesOf));
211
+ for (const [a, b] of ringEdges) {
212
+ if (!inRegion(a)) return false;
213
+ if (!stretches(a, b, regionEdges).every(inRegion)) return false;
214
+ }
215
+ for (const [a, b] of regionEdges) {
216
+ const len = Math.hypot(b[0] - a[0], b[1] - a[1]);
217
+ if (len === 0) continue;
218
+ const nx = -(b[1] - a[1]) / len * PROBE_OFF;
219
+ const ny = (b[0] - a[0]) / len * PROBE_OFF;
220
+ for (const m of stretches(a, b, ringEdges)) {
221
+ if (where(m, ring) !== true) continue;
222
+ if (!inRegion([m[0] + nx, m[1] + ny]) || !inRegion([m[0] - nx, m[1] - ny])) return false;
223
+ }
224
+ }
225
+ return true;
226
+ }
227
+
228
+ // src/mesh/stair.ts
229
+ function stairRisers(flights) {
230
+ return flights.reduce((n, f) => n + f.treads + 1, 0);
231
+ }
232
+ function runCoordinate(f, d) {
233
+ const [x, y] = f.at;
234
+ switch (f.foot) {
235
+ case "bottom":
236
+ return y + f.size.h - d;
237
+ case "top":
238
+ return y + d;
239
+ case "right":
240
+ return x + f.size.w - d;
241
+ case "left":
242
+ return x + d;
243
+ }
244
+ }
245
+ var alongY = (foot) => foot === "top" || foot === "bottom";
246
+ function sideways(section, c0, c1, runAlongY) {
247
+ const up = prism({ outer: section }, c0, c1);
248
+ if (!up) return null;
249
+ const positions = [];
250
+ for (let i = 0; i < up.positions.length; i += 3) {
251
+ const [u, h, v] = [up.positions[i], up.positions[i + 1], up.positions[i + 2]];
252
+ if (runAlongY) positions.push(h, v, u);
253
+ else positions.push(u, v, h);
254
+ }
255
+ const indices = [...up.indices];
256
+ if (!runAlongY) {
257
+ for (let t = 0; t < indices.length; t += 3) {
258
+ const b = indices[t + 1];
259
+ indices[t + 1] = indices[t + 2];
260
+ indices[t + 2] = b;
261
+ }
262
+ }
263
+ return { positions, indices };
264
+ }
265
+ function stairSolid(stair, z0, rise) {
266
+ const flights = stair.flights;
267
+ if (!flights?.length || !(rise > 0)) return null;
268
+ const R = stairRisers(flights);
269
+ const riserTop = (k) => z0 + Math.round(rise * k / R);
270
+ const shells = [];
271
+ const landingTops = [];
272
+ let dropped = 0;
273
+ let climbed = 0;
274
+ flights.forEach((f, i) => {
275
+ const n = f.treads;
276
+ const yRun = alongY(f.foot);
277
+ const run = yRun ? f.size.h : f.size.w;
278
+ const [lo, extent] = yRun ? [f.at[0], f.size.w] : [f.at[1], f.size.h];
279
+ const width = Math.min(stair.width, extent);
280
+ const c0 = lo + Math.round((extent - width) / 2);
281
+ const c1 = c0 + width;
282
+ const at = (t) => runCoordinate(f, Math.round(run * t / n));
283
+ const section = [[at(0), z0]];
284
+ for (let t = 0; t < n; t++) {
285
+ const h = riserTop(climbed + t + 1);
286
+ section.push([at(t), h], [at(t + 1), h]);
287
+ }
288
+ section.push([at(n), z0]);
289
+ const s = sideways(section, c0, c1, yRun);
290
+ if (s) shells.push(s);
291
+ else dropped++;
292
+ climbed += n + 1;
293
+ const landing = stair.landings?.[i];
294
+ if (landing && i < flights.length - 1) {
295
+ const top = riserTop(climbed);
296
+ landingTops.push(top);
297
+ const box = prism(
298
+ rect(landing.at[0], landing.at[1], landing.at[0] + landing.size.w, landing.at[1] + landing.size.h),
299
+ z0,
300
+ top
301
+ );
302
+ if (box) shells.push(box);
303
+ else dropped++;
304
+ }
305
+ });
306
+ return { shells, risers: R, landingTops, top: riserTop(R - 1), dropped };
307
+ }
172
308
 
173
309
  // src/mesh/build.ts
174
310
  var MM = 1e3;
@@ -214,7 +350,8 @@ var STAGE = {
214
350
  door: "openings",
215
351
  window: "openings",
216
352
  opening: "openings",
217
- furniture: "fixtures"
353
+ furniture: "fixtures",
354
+ stair: "walls"
218
355
  };
219
356
  var byText = (a, b) => a < b ? -1 : a > b ? 1 : 0;
220
357
  function along(a, b, d) {
@@ -311,7 +448,7 @@ function leafThroughWall(leaf, walls) {
311
448
  }
312
449
  return false;
313
450
  }
314
- function levelNodes(lv, ledger, defaulted, isTop, doors) {
451
+ function levelNodes(lv, ledger, defaulted, isTop, doors, below, above) {
315
452
  const e = lv.elevation;
316
453
  const out = [];
317
454
  let holesLeftOut = 0;
@@ -388,13 +525,123 @@ function levelNodes(lv, ledger, defaulted, isTop, doors) {
388
525
  }
389
526
  );
390
527
  });
528
+ const ceiling = above ? above.elevation - SLAB_MM * MM - e : 0;
529
+ const slabAbove = above && ceiling > 0 ? slabRegion(above.footprint, above.floors, []).flatMap((r) => lessVoids(r.outer, above.voids, "slab", [])) : [];
530
+ const stopped = (height, rings) => height > ceiling && ceiling > 0 && rings.every((r) => coveredBy(r, slabAbove));
531
+ const stopLedger = (kind, id) => {
532
+ ledger.push({
533
+ kind,
534
+ id,
535
+ field: `top_mm(L${lv.level})`,
536
+ value: ceiling / MM,
537
+ provenance: "derived",
538
+ rule: "stops-under-slab-above"
539
+ });
540
+ };
391
541
  lv.columns.forEach((c, i) => {
392
- node("column", c.id, i, [
393
- prism2(rect(c.at[0], c.at[1], c.at[0] + c.size.w, c.at[1] + c.size.h), e, e + lv.storeyHeight)
394
- ]);
542
+ const box = rect(c.at[0], c.at[1], c.at[0] + c.size.w, c.at[1] + c.size.h);
543
+ const stop = stopped(lv.storeyHeight, [box.outer]);
544
+ if (stop) stopLedger("column", c.id);
545
+ node("column", c.id, i, [prism2(box, e, e + (stop ? ceiling : lv.storeyHeight))]);
546
+ });
547
+ const climbs = [];
548
+ lv.stairs.forEach((s, i) => {
549
+ if (s.dir === "up") {
550
+ climbs.push({ s, order: i, rise: above ? above.elevation - e : lv.storeyHeight, from: "own" });
551
+ if (!above) {
552
+ ledger.push({
553
+ kind: "stair",
554
+ id: s.id,
555
+ field: "rise_mm",
556
+ value: lv.storeyHeight / MM,
557
+ provenance: "default",
558
+ rule: "stair-rise-storey-height"
559
+ });
560
+ }
561
+ } else if (!below) {
562
+ ledger.push({
563
+ kind: "stair",
564
+ id: s.id,
565
+ field: "geometry",
566
+ value: "omitted",
567
+ provenance: "default",
568
+ rule: "stair-down-no-storey-below"
569
+ });
570
+ }
571
+ });
572
+ (above?.stairs ?? []).forEach((s, i) => {
573
+ const partnered = lv.stairs.some((t) => t.id === s.id && t.dir === "up");
574
+ if (s.dir === "down" && !partnered && above)
575
+ climbs.push({ s, order: lv.stairs.length + i, rise: above.elevation - e, from: "above" });
395
576
  });
577
+ const stairFloor = e + FLOOR_FINISH_MM * MM;
578
+ for (const { s, order, rise, from } of climbs) {
579
+ const solid = stairSolid(s, stairFloor, rise);
580
+ if (!solid) {
581
+ ledger.push({
582
+ kind: "stair",
583
+ id: s.id,
584
+ field: "geometry",
585
+ value: "omitted",
586
+ provenance: "default",
587
+ rule: s.flights?.length ? "stair-rise-not-positive" : "stair-no-flights"
588
+ });
589
+ continue;
590
+ }
591
+ if (!defaulted.has("stair:defaults")) {
592
+ defaulted.add("stair:defaults");
593
+ ledger.push(
594
+ {
595
+ kind: "stair",
596
+ field: "material",
597
+ value: STAIR_MATERIAL,
598
+ provenance: "default",
599
+ rule: "stair-material-default"
600
+ },
601
+ { kind: "stair", field: "form", value: "solid", provenance: "default", rule: "stair-solid-default" }
602
+ );
603
+ }
604
+ ledger.push({
605
+ kind: "stair",
606
+ id: s.id,
607
+ field: "risers",
608
+ value: solid.risers,
609
+ provenance: "derived",
610
+ rule: "stair-risers-from-treads"
611
+ });
612
+ node("stair", s.id, order, [...solid.shells, ...Array.from({ length: solid.dropped }, () => null)], {
613
+ dir: s.dir,
614
+ width_mm: s.width / MM,
615
+ flights: s.flights?.length ?? 0,
616
+ risers: solid.risers,
617
+ rise_mm: rise / MM,
618
+ ...from === "above" ? { from_storey_above: true } : {}
619
+ });
620
+ }
396
621
  const openings = new Map(lv.openings.map((o) => [o.id, o]));
397
- const hostHeight = new Map(lv.walls.map((w) => [w.id, w.height]));
622
+ const wallHeight = new Map(
623
+ lv.walls.map((w) => {
624
+ const cut = w.cuts.flatMap((id) => {
625
+ const o = openings.get(id);
626
+ return o ? [o] : [];
627
+ });
628
+ const stop = stopped(w.height, [...w.body.map((p) => p.outer), ...cut.map((o) => o.cut)]);
629
+ if (!stop) return [w.id, w.height];
630
+ stopLedger("wall", w.id);
631
+ for (const o of cut.filter((x) => x.head > ceiling)) {
632
+ ledger.push({
633
+ kind: o.kind,
634
+ id: o.id,
635
+ field: `head_mm(L${lv.level})`,
636
+ value: ceiling / MM,
637
+ provenance: "derived",
638
+ rule: "head-at-slab-above"
639
+ });
640
+ }
641
+ return [w.id, ceiling];
642
+ })
643
+ );
644
+ const hostHeight = wallHeight;
398
645
  const splitAt = /* @__PURE__ */ new Map();
399
646
  for (const o of lv.openings) {
400
647
  const h = hostHeight.get(o.host);
@@ -407,13 +654,14 @@ function levelNodes(lv, ledger, defaulted, isTop, doors) {
407
654
  }
408
655
  const splits = (p) => (splitAt.get(`${p[0]},${p[1]}`) ?? []).map((h) => e + h);
409
656
  lv.walls.forEach((w, i) => {
410
- const top = e + w.height;
657
+ const height = wallHeight.get(w.id) ?? w.height;
658
+ const top = e + height;
411
659
  const shells = w.body.map((p) => prism2(p, e, top, splits));
412
660
  for (const id of w.cuts) {
413
661
  const o = openings.get(id);
414
662
  if (!o) continue;
415
- if (o.sill > 0) shells.push(prism2({ outer: o.cut }, e, e + Math.min(o.sill, w.height)));
416
- if (o.head < w.height) shells.push(prism2({ outer: o.cut }, e + o.head, top));
663
+ if (o.sill > 0) shells.push(prism2({ outer: o.cut }, e, e + Math.min(o.sill, height)));
664
+ if (o.head < height) shells.push(prism2({ outer: o.cut }, e + o.head, top));
417
665
  }
418
666
  node("wall", w.id, i, shells, {
419
667
  ...w.category ? { category: w.category } : {},
@@ -531,6 +779,7 @@ function levelNodes(lv, ledger, defaulted, isTop, doors) {
531
779
  });
532
780
  const floorTop = e + FLOOR_FINISH_MM * MM;
533
781
  const tallest = lv.walls.reduce((m, w) => Math.max(m, w.height), 0) || lv.storeyHeight;
782
+ const tallestBuilt = lv.walls.reduce((m, w) => Math.max(m, wallHeight.get(w.id) ?? w.height), 0) || lv.storeyHeight;
534
783
  lv.furniture.forEach((f, i) => {
535
784
  const parts = t0Shells(f, floorTop);
536
785
  const family = parts ? f.asset.slice("t0:".length) : void 0;
@@ -588,7 +837,7 @@ function levelNodes(lv, ledger, defaulted, isTop, doors) {
588
837
  rule: "furniture-mount-from-top"
589
838
  });
590
839
  }
591
- if (floorTop + h * MM > e + tallest) {
840
+ if (floorTop + h * MM > e + tallestBuilt) {
592
841
  ledger.push({
593
842
  kind: "furniture",
594
843
  id: f.id,
@@ -598,7 +847,7 @@ function levelNodes(lv, ledger, defaulted, isTop, doors) {
598
847
  rule: "furniture-hung-above-walls"
599
848
  });
600
849
  }
601
- } else if (parts && family && floorTop + h * MM > e + tallest) {
850
+ } else if (parts && family && floorTop + h * MM > e + tallestBuilt) {
602
851
  ledger.push({
603
852
  kind: "furniture",
604
853
  id: f.id,
@@ -665,17 +914,22 @@ function buildMesh(scene, opts = {}) {
665
914
  },
666
915
  { kind: "door", field: "leaf_mm", value: LEAF_MM, provenance: "default", rule: "door-leaf-40" },
667
916
  { kind: "roof", field: "thickness_mm", value: ROOF_MM, provenance: "default", rule: "roof-flat-150" },
668
- {
669
- kind: "stair",
670
- field: "geometry",
671
- value: "omitted",
672
- provenance: "default",
673
- rule: "m1-omits-stairs-outdoor-fences"
674
- }
917
+ // Narrowed by card X3 (was `m1-omits-stairs-outdoor-fences`, kind `stair`): stairs are built.
918
+ ...["outdoor", "fence"].map(
919
+ (kind) => ({
920
+ kind,
921
+ field: "geometry",
922
+ value: "omitted",
923
+ provenance: "default",
924
+ rule: "m1-omits-outdoor-fences"
925
+ })
926
+ )
675
927
  ];
676
928
  const defaulted = /* @__PURE__ */ new Set();
677
929
  const top = scene.levels.length - 1;
678
- const nodes = scene.levels.flatMap((lv, i) => levelNodes(lv, ledger, defaulted, i === top, doors));
930
+ const nodes = scene.levels.flatMap(
931
+ (lv, i) => levelNodes(lv, ledger, defaulted, i === top, doors, scene.levels[i - 1], scene.levels[i + 1])
932
+ );
679
933
  nodes.sort(
680
934
  (a, b) => a.level - b.level || byText(a.kind, b.kind) || byText(a.id, b.id) || byText(a.part ?? "", b.part ?? "")
681
935
  );
@@ -687,6 +941,8 @@ export {
687
941
  adaptPlan,
688
942
  rectsOf,
689
943
  slabRegion,
944
+ stairRisers,
945
+ stairSolid,
690
946
  FURNITURE_HEIGHT_MM,
691
947
  DOOR_POSES,
692
948
  openLeaf,