@chanmeng666/archlang-3d 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { y as ReplayEvent, z as ReplayState } from './strip-Nt7eJ-4E.js';
1
+ import { J as ReplayEvent, Q as ReplayState } from './strip-CA-IAT0N.js';
2
2
 
3
3
  /**
4
4
  * The replay's end camera as plain maths (card A3, look notes round 1): the viewer and the tests
@@ -3571,7 +3571,7 @@ function floorLifts(floors, overlaps) {
3571
3571
  }
3572
3572
 
3573
3573
  // package.json
3574
- var version = "0.5.0";
3574
+ var version = "0.6.0";
3575
3575
 
3576
3576
  // src/scene3d/build.ts
3577
3577
  import * as core2 from "@chanmeng666/archlang";
@@ -5,7 +5,7 @@ import {
5
5
  slotGroups,
6
6
  storeysOf,
7
7
  timeline
8
- } from "./chunk-EQBMPXB5.js";
8
+ } from "./chunk-TNNJ7CAO.js";
9
9
 
10
10
  // src/replay/view-dom.ts
11
11
  var PRESET_LABELS = [
@@ -131,7 +131,7 @@ function viewToolbar(view, opts = {}) {
131
131
  // src/replay/payload.ts
132
132
  var PREVIEW_LEAD = "Same source, plan and 3D preview.";
133
133
  var PREVIEW_LABEL = "Same source, plan and 3D preview. The 3D preview is extruded from the same .arch file by the separate archlang-3d package, and checked against the plan: every 3D element comes from the plan's elements, and every solid is closed.";
134
- var PREVIEW_LIMITS = "3D preview: walls, openings, floors, stairs and furniture in flat colours; no pitched roofs yet, and no sections, elevations or BIM.";
134
+ var PREVIEW_LIMITS = "3D preview: walls, openings, floors, stairs, furniture, outdoor surfaces and fences in flat colours; the ground is a backdrop the viewer draws, not part of the building and not in the file; no pitched roofs or balcony railings yet, and no sections, elevations or BIM.";
135
135
  var PREVIEW_ABOUT_URL = "https://archlang.uk/3d";
136
136
  function viewBoxOf(svg) {
137
137
  const m = /viewBox="([-\d.\s]+)"/.exec(svg);
@@ -168,6 +168,7 @@ function replayPayload(mesh, opts) {
168
168
  }
169
169
  const lift = lifts.get(n.level) ?? 0;
170
170
  const finish = FLOOR_FINISHES.find((f) => f === n.extras.finish);
171
+ const colour = typeof n.extras.colour === "string" ? n.extras.colour : void 0;
171
172
  return {
172
173
  key: n.key,
173
174
  kind: n.kind,
@@ -176,12 +177,24 @@ function replayPayload(mesh, opts) {
176
177
  positions,
177
178
  indices,
178
179
  ...slotted ? { groups: runs } : {},
179
- ...n.kind === "floor" && finish ? { finish } : {}
180
+ ...n.kind === "floor" && finish ? { finish } : {},
181
+ ...(n.kind === "outdoor" || n.kind === "fence") && colour ? { colour } : {}
180
182
  };
181
183
  }),
182
- events: timeline(mesh)
184
+ events: timeline(mesh),
185
+ ...groundOf(mesh)
183
186
  };
184
187
  }
188
+ function groundOf(mesh) {
189
+ const row = mesh.assumptions.find((a) => a.rule === "ground-plane-viewer-only")?.value;
190
+ const lowest = typeof row?.level === "number" ? row.level : storeysOf(mesh)[0];
191
+ const slab = mesh.nodes.find((n) => n.level === lowest && n.kind === "slab" && !n.hidden);
192
+ if (!slab) return {};
193
+ let y = -Infinity;
194
+ for (const s of slab.shells)
195
+ for (let i = 1; i < s.positions.length; i += 3) y = Math.max(y, s.positions[i]);
196
+ return Number.isFinite(y) ? { ground: { y } } : {};
197
+ }
185
198
 
186
199
  export {
187
200
  PRESET_LABELS,
@@ -1,22 +1,26 @@
1
1
  import {
2
2
  ARCHLANG_3D_VERSION,
3
3
  validateScene3D
4
- } from "./chunk-WCWLYIVD.js";
4
+ } from "./chunk-6WCS4TAT.js";
5
5
  import {
6
6
  PREVIEW_LABEL,
7
7
  PREVIEW_LIMITS,
8
8
  VIEW_CONTROLS_LABEL,
9
9
  replayPayload
10
- } from "./chunk-4SQ5YKKX.js";
10
+ } from "./chunk-CX6IVI7I.js";
11
11
  import {
12
+ FENCE_PALETTE,
12
13
  FINISH_PALETTE,
13
14
  FLOOR_FINISHES,
15
+ GROUND_ROUGHNESS,
16
+ GROUND_SPLITS,
17
+ GROUND_TINT,
14
18
  KIND_PALETTE,
15
19
  PALETTE,
16
20
  keyFrames,
17
21
  linearRgb,
18
22
  slotGroups
19
- } from "./chunk-EQBMPXB5.js";
23
+ } from "./chunk-TNNJ7CAO.js";
20
24
 
21
25
  // src/world.ts
22
26
  import { readFileSync, realpathSync, statSync } from "node:fs";
@@ -210,13 +214,25 @@ function seekOnly(html) {
210
214
  '<style>html,body{overflow:hidden}</style><script>window.__replayAutoplay=false</script>\n<script type="application/json"'
211
215
  );
212
216
  }
217
+ var PAYLOAD_OPEN = '<script type="application/json" id="archlang-replay-payload">';
218
+ function withSupersample(html, k = 1) {
219
+ if (!Number.isInteger(k) || k < 1 || k > 4)
220
+ throw new Error(`supersample must be a whole number from 1 to 4 (got ${k})`);
221
+ if (k === 1) return html;
222
+ const at = html.indexOf(PAYLOAD_OPEN);
223
+ const end = at < 0 ? -1 : html.indexOf("</script>", at);
224
+ if (end < 0) throw new Error("the replay page carries no payload to supersample");
225
+ const p = JSON.parse(html.slice(at + PAYLOAD_OPEN.length, end));
226
+ const json = JSON.stringify({ ...p, supersample: k }).replace(/</g, "\\u003c");
227
+ return html.slice(0, at + PAYLOAD_OPEN.length) + json + html.slice(end);
228
+ }
213
229
  async function renderReplay(o) {
214
230
  const fps = o.fps ?? 30;
215
231
  const seconds = o.seconds ?? 15;
216
232
  const frames = Math.round(fps * seconds);
217
233
  const dir = mkdtempSync(join2(tmpdir(), "archlang3d-replay-"));
218
234
  const file = join2(dir, "replay.html");
219
- writeFileSync(file, seekOnly(o.html));
235
+ writeFileSync(file, seekOnly(withSupersample(o.html, o.supersample)));
220
236
  const { chromium } = await import("playwright-core");
221
237
  const browser = await chromium.launch({ args: SWIFTSHADER_ARGS });
222
238
  try {
@@ -339,9 +355,18 @@ function bodyMaterialName(n) {
339
355
  if (n.kind === "floor") return `floor:${FLOOR_FINISHES.find((f) => f === n.extras.finish) ?? "neutral"}`;
340
356
  if (n.kind === "wall" && n.part === "demolish") return "wall:demolish";
341
357
  if (n.kind === "window" && (n.part === "glass" || n.part === "frame")) return `window:${n.part}`;
358
+ if (n.kind === "outdoor") return `outdoor:${String(n.extras.surface)}`;
359
+ if (n.kind === "fence") return `fence:${String(n.extras.style)}`;
342
360
  return n.kind;
343
361
  }
344
- function bodyMaterial(name) {
362
+ function bodyMaterial(name, n) {
363
+ if (n.kind === "outdoor" || n.kind === "fence") {
364
+ const own = n.kind === "fence" ? FENCE_PALETTE[String(n.extras.style)] : GROUND_SPLITS[String(n.extras.surface)];
365
+ const tint = GROUND_TINT[String(n.extras.surface)] ?? "paving";
366
+ const roughness = own?.roughness ?? (n.kind === "fence" ? FENCE_PALETTE.picket.roughness : GROUND_ROUGHNESS[tint]);
367
+ const srgb = typeof n.extras.colour === "string" ? n.extras.colour : KIND_PALETTE.furniture.srgb;
368
+ return { srgb, alpha: 1, metallic: 0, roughness };
369
+ }
345
370
  if (name.startsWith("floor:")) return FINISH_PALETTE[name.slice("floor:".length)];
346
371
  return KIND_PALETTE[name] ?? KIND_PALETTE.furniture;
347
372
  }
@@ -373,7 +398,7 @@ async function writeGlb(mesh, opts = {}) {
373
398
  const key = bodyMaterialName(n);
374
399
  let m = materials.get(key);
375
400
  if (!m) {
376
- const p = bodyMaterial(key);
401
+ const p = bodyMaterial(key, n);
377
402
  m = doc.createMaterial(key).setBaseColorFactor([...linearRgb(p.srgb), p.alpha]).setMetallicFactor(p.metallic).setRoughnessFactor(p.roughness);
378
403
  if (p.alpha < 1) m.setAlphaMode("BLEND");
379
404
  materials.set(key, m);
@@ -78,6 +78,44 @@ function floorFinish(uses) {
78
78
  for (const [finish, kinds] of FLOOR_FINISH_RULES) if (uses?.some((u) => kinds.includes(u))) return finish;
79
79
  return "neutral";
80
80
  }
81
+ var GROUND_TINT = {
82
+ lawn: "lawn",
83
+ planting: "lawn",
84
+ paving: "paving",
85
+ deck: "paving",
86
+ gravel: "paving",
87
+ water: "water",
88
+ driveway: "paving",
89
+ patio: "paving",
90
+ balcony: "paving"
91
+ };
92
+ var GROUND_WASH = 6;
93
+ var SITE_PALETTE = {
94
+ gravel: m("#cbc3b4", 0.95),
95
+ tarmac: m("#8c8984", 0.85)
96
+ };
97
+ var GROUND_SPLITS = {
98
+ planting: PALETTE.foliage,
99
+ deck: PALETTE.wood,
100
+ gravel: SITE_PALETTE.gravel,
101
+ driveway: SITE_PALETTE.tarmac
102
+ };
103
+ var GROUND_ROUGHNESS = { lawn: 0.95, paving: 0.85, water: 0.1 };
104
+ var FENCE_PALETTE = {
105
+ picket: m("#eeebe4", 0.8),
106
+ panel: PALETTE.wood,
107
+ post: PALETTE.wood_dark
108
+ };
109
+ var GROUND_PLANE = { light: "#e2ddd3", dark: "#16293d", marginMm: 6e3 };
110
+ function siteColour(own, theme, toward) {
111
+ if (theme === "light") return own;
112
+ const mix = (i) => {
113
+ const a = Number.parseInt(own.slice(i, i + 2), 16);
114
+ const b = Number.parseInt(toward.slice(i, i + 2), 16);
115
+ return Math.round(a * 0.4 + b * 0.6).toString(16).padStart(2, "0");
116
+ };
117
+ return `#${mix(1)}${mix(3)}${mix(5)}`;
118
+ }
81
119
  function linearRgb(hex) {
82
120
  const ch = (i) => {
83
121
  const c = Number.parseInt(hex.slice(i, i + 2), 16) / 255;
@@ -174,10 +212,14 @@ function groupOf(n) {
174
212
  return 3;
175
213
  case "furniture":
176
214
  return FIXTURE_FAMILIES.has(String(n.extras.category)) ? 0 : 1;
215
+ case "outdoor":
216
+ return 1;
217
+ case "fence":
218
+ return 4;
177
219
  }
178
220
  }
179
221
  var isGhost = (n) => n.part === "demolish";
180
- var isFlat = (n) => n.kind === "slab" || n.kind === "floor";
222
+ var isFlat = (n) => n.kind === "slab" || n.kind === "floor" || n.kind === "outdoor";
181
223
  function authoringOrder(mesh) {
182
224
  return [...mesh.nodes].sort(
183
225
  (a, b) => STAGES.indexOf(a.stage) - STAGES.indexOf(b.stage) || groupOf(a) - groupOf(b) || a.level - b.level || a.order - b.order || (a.key < b.key ? -1 : a.key > b.key ? 1 : 0)
@@ -325,6 +367,7 @@ function stateAt(events, t) {
325
367
  stop,
326
368
  settle,
327
369
  svg,
370
+ ground: u >= PHASE.rise ? 1 - svg : 0,
328
371
  nodes
329
372
  };
330
373
  }
@@ -575,6 +618,14 @@ export {
575
618
  FINISH_PALETTE,
576
619
  FLOOR_FINISH_RULES,
577
620
  floorFinish,
621
+ GROUND_TINT,
622
+ GROUND_WASH,
623
+ SITE_PALETTE,
624
+ GROUND_SPLITS,
625
+ GROUND_ROUGHNESS,
626
+ FENCE_PALETTE,
627
+ GROUND_PLANE,
628
+ siteColour,
578
629
  linearRgb,
579
630
  slotColour,
580
631
  finishColour,