@chanmeng666/archlang-3d 0.5.0 → 0.7.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 +102 -0
- package/README.md +4 -3
- package/THIRD_PARTY_NOTICES +2 -2
- package/dist/browser.d.ts +4 -3
- package/dist/browser.js +612 -11
- package/dist/{camera-DVOiag0F.d.ts → camera-CGIIudHj.d.ts} +1 -1
- package/dist/{chunk-4SQ5YKKX.js → chunk-FHBR2U5Z.js} +17 -4
- package/dist/{chunk-OWZWBKMI.js → chunk-FVD3DZU2.js} +34 -7
- package/dist/{chunk-WCWLYIVD.js → chunk-GXWLZ2KC.js} +61 -9
- package/dist/chunk-QN4LQTVG.js +2192 -0
- package/dist/{chunk-EQBMPXB5.js → chunk-TI4RYEOL.js} +80 -5
- package/dist/cli.js +5 -5
- package/dist/{facts-BRIFxHL_.d.ts → facts-3wb9egIT.d.ts} +1 -1
- package/dist/index.d.ts +308 -7
- package/dist/index.js +62 -4
- package/dist/node.d.ts +5 -3
- package/dist/node.js +4 -4
- package/dist/replay.d.ts +22 -2
- package/dist/{strip-Nt7eJ-4E.d.ts → strip-Sdsm54Qw.d.ts} +118 -4
- package/dist/viewer.iife.js +504 -499
- package/package.json +3 -3
- package/dist/chunk-L2CX7KWM.js +0 -950
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
slotGroups,
|
|
6
6
|
storeysOf,
|
|
7
7
|
timeline
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-TI4RYEOL.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
|
|
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-
|
|
4
|
+
} from "./chunk-GXWLZ2KC.js";
|
|
5
5
|
import {
|
|
6
6
|
PREVIEW_LABEL,
|
|
7
7
|
PREVIEW_LIMITS,
|
|
8
8
|
VIEW_CONTROLS_LABEL,
|
|
9
9
|
replayPayload
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-FHBR2U5Z.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-
|
|
23
|
+
} from "./chunk-TI4RYEOL.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 {
|
|
@@ -338,10 +354,21 @@ var GLB_GENERATOR = `archlang-3d ${ARCHLANG_3D_VERSION}`;
|
|
|
338
354
|
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
|
-
if (n.kind === "window" &&
|
|
357
|
+
if (n.kind === "window" && n.part && `window:${n.part}` in KIND_PALETTE) return `window:${n.part}`;
|
|
358
|
+
if ((n.kind === "opening" || n.kind === "stair") && n.part && `${n.kind}:${n.part}` in KIND_PALETTE)
|
|
359
|
+
return `${n.kind}:${n.part}`;
|
|
360
|
+
if (n.kind === "outdoor") return `outdoor:${String(n.extras.surface)}`;
|
|
361
|
+
if (n.kind === "fence") return `fence:${String(n.extras.style)}`;
|
|
342
362
|
return n.kind;
|
|
343
363
|
}
|
|
344
|
-
function bodyMaterial(name) {
|
|
364
|
+
function bodyMaterial(name, n) {
|
|
365
|
+
if (n.kind === "outdoor" || n.kind === "fence") {
|
|
366
|
+
const own = n.kind === "fence" ? FENCE_PALETTE[String(n.extras.style)] : GROUND_SPLITS[String(n.extras.surface)];
|
|
367
|
+
const tint = GROUND_TINT[String(n.extras.surface)] ?? "paving";
|
|
368
|
+
const roughness = own?.roughness ?? (n.kind === "fence" ? FENCE_PALETTE.picket.roughness : GROUND_ROUGHNESS[tint]);
|
|
369
|
+
const srgb = typeof n.extras.colour === "string" ? n.extras.colour : KIND_PALETTE.furniture.srgb;
|
|
370
|
+
return { srgb, alpha: 1, metallic: 0, roughness };
|
|
371
|
+
}
|
|
345
372
|
if (name.startsWith("floor:")) return FINISH_PALETTE[name.slice("floor:".length)];
|
|
346
373
|
return KIND_PALETTE[name] ?? KIND_PALETTE.furniture;
|
|
347
374
|
}
|
|
@@ -373,7 +400,7 @@ async function writeGlb(mesh, opts = {}) {
|
|
|
373
400
|
const key = bodyMaterialName(n);
|
|
374
401
|
let m = materials.get(key);
|
|
375
402
|
if (!m) {
|
|
376
|
-
const p = bodyMaterial(key);
|
|
403
|
+
const p = bodyMaterial(key, n);
|
|
377
404
|
m = doc.createMaterial(key).setBaseColorFactor([...linearRgb(p.srgb), p.alpha]).setMetallicFactor(p.metallic).setRoughnessFactor(p.roughness);
|
|
378
405
|
if (p.alpha < 1) m.setAlphaMode("BLEND");
|
|
379
406
|
materials.set(key, m);
|
|
@@ -371,13 +371,7 @@ var HEMI = [
|
|
|
371
371
|
[1, 0.132]
|
|
372
372
|
];
|
|
373
373
|
function dome(mat, cx, cz, rx, rz, y0, y1, table) {
|
|
374
|
-
|
|
375
|
-
return table.map(([t, f], k) => {
|
|
376
|
-
const hi = k === table.length - 1 ? y1 : y0 + (y1 - y0) * t;
|
|
377
|
-
const p = P(mat, cx - rx * f, cx + rx * f, cz - rz * f, cz + rz * f, lo, hi, { round: true });
|
|
378
|
-
lo = hi;
|
|
379
|
-
return p;
|
|
380
|
-
});
|
|
374
|
+
return [P(mat, cx - rx, cx + rx, cz - rz, cz + rz, y0, y1, { round: true, loft: table })];
|
|
381
375
|
}
|
|
382
376
|
function cabinet(W, D, opts = {}) {
|
|
383
377
|
const [hw, hd] = [W / 2, D / 2];
|
|
@@ -3260,9 +3254,12 @@ function sectionRing(u0, u1, v0, v1, shape = {}) {
|
|
|
3260
3254
|
}
|
|
3261
3255
|
function partShell(p, dropped) {
|
|
3262
3256
|
if (p.axis && p.holes?.length) throw new Error("a sideways T0 part takes no holes");
|
|
3257
|
+
if (p.loft && (p.axis || p.holes?.length || p.profile)) throw new Error("a lofted T0 part is vertical and plain");
|
|
3263
3258
|
if (!(um(p.x0) < um(p.x1) && um(p.y0) < um(p.y1) && um(p.z0) < um(p.z1))) return null;
|
|
3264
3259
|
let s;
|
|
3265
|
-
if (
|
|
3260
|
+
if (p.loft) {
|
|
3261
|
+
s = loftShell(p, p.loft);
|
|
3262
|
+
} else if (!p.axis) {
|
|
3266
3263
|
const outer = sectionRing(p.x0, p.x1, p.z0, p.z1, p);
|
|
3267
3264
|
const holes = (p.holes ?? []).map((h) => sectionRing(h.x0, h.x1, h.z0, h.z1, h));
|
|
3268
3265
|
const poly = { outer, ...holes.length ? { holes } : {} };
|
|
@@ -3298,6 +3295,61 @@ function partShell(p, dropped) {
|
|
|
3298
3295
|
if (s && p.mat && p.mat !== "body") s.slot = p.mat;
|
|
3299
3296
|
return s;
|
|
3300
3297
|
}
|
|
3298
|
+
function loftShell(p, table) {
|
|
3299
|
+
if (table.length === 0) return null;
|
|
3300
|
+
const [cx, cz, rx, rz] = [(p.x0 + p.x1) / 2, (p.z0 + p.z1) / 2, (p.x1 - p.x0) / 2, (p.z1 - p.z0) / 2];
|
|
3301
|
+
const shape = { ...p.round ? { round: true } : {}, ...p.radius ? { radius: p.radius } : {} };
|
|
3302
|
+
const levels = [
|
|
3303
|
+
[um(p.y0), table[0][1]],
|
|
3304
|
+
...table.map(([t, f], k) => [
|
|
3305
|
+
k === table.length - 1 ? um(p.y1) : um(p.y0 + (p.y1 - p.y0) * t),
|
|
3306
|
+
f
|
|
3307
|
+
])
|
|
3308
|
+
];
|
|
3309
|
+
const rings = levels.map(([, f]) => sectionRing(cx - rx * f, cx + rx * f, cz - rz * f, cz + rz * f, shape));
|
|
3310
|
+
const n = rings[0]?.length ?? 0;
|
|
3311
|
+
if (n < 3 || rings.some((r) => r.length !== n)) return null;
|
|
3312
|
+
for (let k = 1; k < levels.length; k++)
|
|
3313
|
+
if (!(levels[k][0] > levels[k - 1][0])) return null;
|
|
3314
|
+
const positions = [];
|
|
3315
|
+
rings.forEach((r, k) => {
|
|
3316
|
+
for (const [x, z] of r) positions.push(x, levels[k][0], z);
|
|
3317
|
+
});
|
|
3318
|
+
const [ax, az] = [um(cx), um(cz)];
|
|
3319
|
+
const indices = [];
|
|
3320
|
+
const at = (i) => [
|
|
3321
|
+
positions[3 * i],
|
|
3322
|
+
positions[3 * i + 1],
|
|
3323
|
+
positions[3 * i + 2]
|
|
3324
|
+
];
|
|
3325
|
+
const face = (a, b, c, want) => {
|
|
3326
|
+
const [A, B, C] = [at(a), at(b), at(c)];
|
|
3327
|
+
const u = [B[0] - A[0], B[1] - A[1], B[2] - A[2]];
|
|
3328
|
+
const w = [C[0] - A[0], C[1] - A[1], C[2] - A[2]];
|
|
3329
|
+
const nx = u[1] * w[2] - u[2] * w[1];
|
|
3330
|
+
const ny = u[2] * w[0] - u[0] * w[2];
|
|
3331
|
+
const nz = u[0] * w[1] - u[1] * w[0];
|
|
3332
|
+
if (nx * want[0] + ny * want[1] + nz * want[2] >= 0) indices.push(a, b, c);
|
|
3333
|
+
else indices.push(a, c, b);
|
|
3334
|
+
};
|
|
3335
|
+
const last = rings.length - 1;
|
|
3336
|
+
for (let i = 1; i < n - 1; i++) {
|
|
3337
|
+
face(0, i, i + 1, [0, -1, 0]);
|
|
3338
|
+
face(last * n, last * n + i, last * n + i + 1, [0, 1, 0]);
|
|
3339
|
+
}
|
|
3340
|
+
for (let k = 0; k < last; k++) {
|
|
3341
|
+
for (let i = 0; i < n; i++) {
|
|
3342
|
+
const j = (i + 1) % n;
|
|
3343
|
+
const [a, b, c, d] = [k * n + i, k * n + j, (k + 1) * n + j, (k + 1) * n + i];
|
|
3344
|
+
const m = [a, b, c, d].map(at);
|
|
3345
|
+
const mx = m.reduce((s, q) => s + q[0], 0) / 4 - ax;
|
|
3346
|
+
const mz = m.reduce((s, q) => s + q[2], 0) / 4 - az;
|
|
3347
|
+
face(a, b, c, [mx, 0, mz]);
|
|
3348
|
+
face(a, c, d, [mx, 0, mz]);
|
|
3349
|
+
}
|
|
3350
|
+
}
|
|
3351
|
+
return { positions, indices };
|
|
3352
|
+
}
|
|
3301
3353
|
var MIN_PART_MM = 1;
|
|
3302
3354
|
function t0LocalParts(family, W, D) {
|
|
3303
3355
|
const gen = GENERATORS[family];
|
|
@@ -3571,7 +3623,7 @@ function floorLifts(floors, overlaps) {
|
|
|
3571
3623
|
}
|
|
3572
3624
|
|
|
3573
3625
|
// package.json
|
|
3574
|
-
var version = "0.
|
|
3626
|
+
var version = "0.7.0";
|
|
3575
3627
|
|
|
3576
3628
|
// src/scene3d/build.ts
|
|
3577
3629
|
import * as core2 from "@chanmeng666/archlang";
|