ldr 0.21.0 → 0.23.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/dist/cli.js +11 -11
- package/dist/index.js +79 -26
- package/dist/load-worker.gen.d.ts +1 -1
- package/dist/node/index.js +87 -34
- package/dist/render.d.ts +1 -1
- package/dist/scene.d.ts +2 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
// ../../../../../../../tmp/ldr-build-
|
|
3
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/cli.ts
|
|
4
4
|
import fs4 from "node:fs";
|
|
5
5
|
import zlib from "node:zlib";
|
|
6
6
|
|
|
7
|
-
// ../../../../../../../tmp/ldr-build-
|
|
7
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/node/build-pack.ts
|
|
8
8
|
import fs3 from "node:fs";
|
|
9
9
|
import path3 from "node:path";
|
|
10
10
|
|
|
11
|
-
// ../../../../../../../tmp/ldr-build-
|
|
11
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/node/resolver.ts
|
|
12
12
|
import fs from "node:fs";
|
|
13
13
|
import path from "node:path";
|
|
14
14
|
|
|
15
|
-
// ../../../../../../../tmp/ldr-build-
|
|
15
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/spec.ts
|
|
16
16
|
var norm = (s) => s.trim().toLowerCase().replace(/\\/g, "/").replace(/\/+/g, "/");
|
|
17
17
|
function parseColor(tok) {
|
|
18
18
|
if (/^0x/i.test(tok))
|
|
@@ -705,7 +705,7 @@ function fileStepViews(f) {
|
|
|
705
705
|
return out;
|
|
706
706
|
}
|
|
707
707
|
|
|
708
|
-
// ../../../../../../../tmp/ldr-build-
|
|
708
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/model.ts
|
|
709
709
|
var CALLOUT_END = 999999;
|
|
710
710
|
var stepKey = (steps) => steps.map((x) => String(x).padStart(6, "0")).join(".") + "~";
|
|
711
711
|
function flatten(doc, opts = {}) {
|
|
@@ -1055,7 +1055,7 @@ function parseLDConfig(text) {
|
|
|
1055
1055
|
return out;
|
|
1056
1056
|
}
|
|
1057
1057
|
|
|
1058
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1058
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/node/resolver.ts
|
|
1059
1059
|
var TOP_STUD_RE = /^(stud|studa|stud2|stud2a|stud6|stud6a|stud10|stud15|stud2s|stud2s2|stud-logo\d*|stud2-logo\d*)\.dat$/i;
|
|
1060
1060
|
var UNDER_STUD_RE = /^(stud3|stud3a|stud4.*|stud12|stud16.*|stud18a)\.dat$/i;
|
|
1061
1061
|
var norm2 = (ref) => ref.trim().replace(/\\/g, "/").toLowerCase();
|
|
@@ -1325,11 +1325,11 @@ function collectDeps(lib, refs) {
|
|
|
1325
1325
|
return out;
|
|
1326
1326
|
}
|
|
1327
1327
|
|
|
1328
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1328
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/node/compile.ts
|
|
1329
1329
|
import fs2 from "node:fs";
|
|
1330
1330
|
import path2 from "node:path";
|
|
1331
1331
|
|
|
1332
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1332
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/node/lod.ts
|
|
1333
1333
|
import { MeshoptSimplifier, MeshoptEncoder } from "meshoptimizer";
|
|
1334
1334
|
await Promise.all([MeshoptSimplifier.ready, MeshoptEncoder.ready]);
|
|
1335
1335
|
function reorderMesh(P, N, C, I) {
|
|
@@ -1521,7 +1521,7 @@ function lodChain(P, C, I) {
|
|
|
1521
1521
|
return out;
|
|
1522
1522
|
}
|
|
1523
1523
|
|
|
1524
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1524
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/node/compile.ts
|
|
1525
1525
|
function loadColors(root) {
|
|
1526
1526
|
const map = new Map;
|
|
1527
1527
|
for (const l of fs2.readFileSync(path2.join(root, "LDConfig.ldr"), "latin1").split(/\r?\n/)) {
|
|
@@ -2104,7 +2104,7 @@ function encodePack(parts, studKinds, weld, extra, options = {}) {
|
|
|
2104
2104
|
return Buffer.concat([head, ...chunks.map((c) => new Uint8Array(c.buffer, c.byteOffset, c.byteLength))]);
|
|
2105
2105
|
}
|
|
2106
2106
|
|
|
2107
|
-
// ../../../../../../../tmp/ldr-build-
|
|
2107
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/node/build-pack.ts
|
|
2108
2108
|
function buildPack(o) {
|
|
2109
2109
|
const lib = new Library(o.ldrawRoot);
|
|
2110
2110
|
const refs = new Map;
|
|
@@ -2172,7 +2172,7 @@ function buildPack(o) {
|
|
|
2172
2172
|
return { data: encodePack(parts, kinds, comp.opts.weld, extra, { texture, lod: o.lod !== false, reorder: !!o.reorder }), parts: parts.size, studKinds: kinds.size, missing: [...missing], ...warnings.length ? { warnings } : {} };
|
|
2173
2173
|
}
|
|
2174
2174
|
|
|
2175
|
-
// ../../../../../../../tmp/ldr-build-
|
|
2175
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/cli.ts
|
|
2176
2176
|
var HELP = `ldr pack — build a parts pack for the ldr three.js renderer
|
|
2177
2177
|
|
|
2178
2178
|
Usage:
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/spec.ts
|
|
2
2
|
var norm = (s) => s.trim().toLowerCase().replace(/\\/g, "/").replace(/\/+/g, "/");
|
|
3
3
|
function parseColor(tok) {
|
|
4
4
|
if (/^0x/i.test(tok))
|
|
@@ -689,7 +689,7 @@ function fileStepViews(f) {
|
|
|
689
689
|
viewMemo.set(f, out);
|
|
690
690
|
return out;
|
|
691
691
|
}
|
|
692
|
-
// ../../../../../../../tmp/ldr-build-
|
|
692
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/model.ts
|
|
693
693
|
var CALLOUT_END = 999999;
|
|
694
694
|
var stepKey = (steps) => steps.map((x) => String(x).padStart(6, "0")).join(".") + "~";
|
|
695
695
|
function flatten(doc, opts = {}) {
|
|
@@ -1038,7 +1038,7 @@ function parseLDConfig(text) {
|
|
|
1038
1038
|
}
|
|
1039
1039
|
return out;
|
|
1040
1040
|
}
|
|
1041
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1041
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/instructions.ts
|
|
1042
1042
|
var MIN_VIS = 0.5;
|
|
1043
1043
|
var REORIENT = 0.35;
|
|
1044
1044
|
var deg = Math.PI / 180;
|
|
@@ -1406,10 +1406,10 @@ function planStepViews(insts, parts, stepOf, nSteps, o = {}) {
|
|
|
1406
1406
|
}
|
|
1407
1407
|
};
|
|
1408
1408
|
}
|
|
1409
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1409
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/render.ts
|
|
1410
1410
|
import * as THREE from "three";
|
|
1411
1411
|
|
|
1412
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1412
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/pack-io.ts
|
|
1413
1413
|
import { decompress } from "fzstd";
|
|
1414
1414
|
async function decompressPack(data) {
|
|
1415
1415
|
const u = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
@@ -1432,7 +1432,7 @@ function decodePack(buf) {
|
|
|
1432
1432
|
return { header, arr, bytes: buf.byteLength, buffer: buf };
|
|
1433
1433
|
}
|
|
1434
1434
|
|
|
1435
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1435
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/cull.ts
|
|
1436
1436
|
var upright = (m, o = 0) => Math.abs(m[o + 7] - 1) < 0.001 && Math.abs(m[o + 4]) < 0.001 && Math.abs(m[o + 10]) < 0.001;
|
|
1437
1437
|
var prepCache = new WeakMap;
|
|
1438
1438
|
function prepPart(H, part) {
|
|
@@ -1749,7 +1749,7 @@ function precomputeCull(instances, H, useTex = true) {
|
|
|
1749
1749
|
return cullCore(s.all, H, s.nSteps > 1 ? s.stepOf : undefined);
|
|
1750
1750
|
}
|
|
1751
1751
|
|
|
1752
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1752
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/render.ts
|
|
1753
1753
|
async function loadPack(url) {
|
|
1754
1754
|
const res = await fetch(url);
|
|
1755
1755
|
if (!res.ok)
|
|
@@ -2248,6 +2248,33 @@ function gridClusters(n, x, z, k) {
|
|
|
2248
2248
|
}
|
|
2249
2249
|
return out;
|
|
2250
2250
|
}
|
|
2251
|
+
var _studDisc = null;
|
|
2252
|
+
function studDiscGeom() {
|
|
2253
|
+
if (_studDisc)
|
|
2254
|
+
return _studDisc;
|
|
2255
|
+
const y = -4, r = 6;
|
|
2256
|
+
const pos = new Float32Array([-r, y, -r, r, y, -r, r, y, r, -r, y, -r, r, y, r, -r, y, r]);
|
|
2257
|
+
const nrm = new Float32Array(18);
|
|
2258
|
+
for (let i = 0;i < 6; i++) {
|
|
2259
|
+
nrm[i * 3] = 0;
|
|
2260
|
+
nrm[i * 3 + 1] = -1;
|
|
2261
|
+
nrm[i * 3 + 2] = 0;
|
|
2262
|
+
}
|
|
2263
|
+
const col = new Uint8Array(24);
|
|
2264
|
+
for (let i = 0;i < 6; i++) {
|
|
2265
|
+
col[i * 4] = 255;
|
|
2266
|
+
col[i * 4 + 1] = 255;
|
|
2267
|
+
col[i * 4 + 2] = 255;
|
|
2268
|
+
col[i * 4 + 3] = 0;
|
|
2269
|
+
}
|
|
2270
|
+
const g = new THREE.BufferGeometry;
|
|
2271
|
+
g.setAttribute("position", new THREE.Float16BufferAttribute(toF16(pos), 3));
|
|
2272
|
+
g.setAttribute("normal", new THREE.BufferAttribute(toI8(nrm), 3, true));
|
|
2273
|
+
g.setAttribute("ldrColor", new THREE.BufferAttribute(col, 4, true));
|
|
2274
|
+
g.computeBoundingSphere();
|
|
2275
|
+
g.computeBoundingBox();
|
|
2276
|
+
return _studDisc = g;
|
|
2277
|
+
}
|
|
2251
2278
|
|
|
2252
2279
|
class LdrLodRoot extends THREE.LOD {
|
|
2253
2280
|
clusters = [];
|
|
@@ -2422,7 +2449,9 @@ function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colo
|
|
|
2422
2449
|
bKind.forEach((kind, b) => {
|
|
2423
2450
|
const g = geom(H.studKinds[kind].body, arr);
|
|
2424
2451
|
const ids = bIds[b];
|
|
2425
|
-
|
|
2452
|
+
const studTris = g ? (g.getIndex() ? g.getIndex().count : g.getAttribute("position").count) / 3 : 24;
|
|
2453
|
+
const kStud = LOD ? Math.max(256, Math.min(4096, Math.round(65536 / Math.max(1, studTris)))) : Infinity;
|
|
2454
|
+
for (const c of gridClusters(ids.length, (i) => sx[ids[i]], (i) => sz[ids[i]], kStud)) {
|
|
2426
2455
|
const ci = sMesh.length;
|
|
2427
2456
|
let v = 0;
|
|
2428
2457
|
for (const i of c)
|
|
@@ -3098,6 +3127,7 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
3098
3127
|
const sKind = sMesh.map((x) => x?.kind ?? "");
|
|
3099
3128
|
const sVis = sMesh.map((x) => x?.vis ?? 0);
|
|
3100
3129
|
const STUD_ERR = 12;
|
|
3130
|
+
const STUD_DISC_ERR = 2;
|
|
3101
3131
|
let _coopS = 0;
|
|
3102
3132
|
for (let ci = 0;ci < sMesh.length; ci++) {
|
|
3103
3133
|
const sm = sMesh[ci];
|
|
@@ -3115,14 +3145,28 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
3115
3145
|
im.userData.ldrStud = true;
|
|
3116
3146
|
root.add(im);
|
|
3117
3147
|
const cl = newCluster(im.boundingSphere);
|
|
3148
|
+
cl.studEdge0 = true;
|
|
3118
3149
|
cl.lv.push({ objs: [im], err: 0 });
|
|
3119
|
-
|
|
3150
|
+
const discObjs = [];
|
|
3151
|
+
if (LOD) {
|
|
3152
|
+
const disc = new THREE.InstancedMesh(studDiscGeom(), im.material, 0);
|
|
3153
|
+
disc.userData = { ldrStud: true, ldrLod: true };
|
|
3154
|
+
disc.instanceMatrix = im.instanceMatrix;
|
|
3155
|
+
disc.count = im.count;
|
|
3156
|
+
disc.instanceColor = im.instanceColor;
|
|
3157
|
+
disc.boundingSphere = im.boundingSphere;
|
|
3158
|
+
disc.visible = false;
|
|
3159
|
+
disc.onBeforeRender = trackVp;
|
|
3160
|
+
root.add(disc);
|
|
3161
|
+
discObjs.push(disc);
|
|
3162
|
+
cl.lv.push({ objs: [disc], err: STUD_DISC_ERR });
|
|
3120
3163
|
cl.lv.push({ objs: [], err: STUD_ERR });
|
|
3164
|
+
}
|
|
3121
3165
|
if (EDGES && k.edges)
|
|
3122
3166
|
addLines(k.edges, im, cl);
|
|
3123
3167
|
if (P.condStuds !== false)
|
|
3124
3168
|
addCond(k, im, cl);
|
|
3125
|
-
const objs = [im, ...cl.lines, ...cl.cond];
|
|
3169
|
+
const objs = [im, ...discObjs, ...cl.lines, ...cl.cond];
|
|
3126
3170
|
objs.forEach((o) => {
|
|
3127
3171
|
if (!o.isInstancedMesh)
|
|
3128
3172
|
o.geometry.instanceCount = im.count;
|
|
@@ -3146,7 +3190,7 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
3146
3190
|
for (const o of l.objs)
|
|
3147
3191
|
o.visible = i === c.cur;
|
|
3148
3192
|
});
|
|
3149
|
-
const lineVis = edgesOn && c.edgeOk && c.cur >= 0 && (c.cur === 0 || !LOD || (c.setMergedLevel ? true : c.lv[c.cur].objs.length > 0));
|
|
3193
|
+
const lineVis = edgesOn && c.edgeOk && c.cur >= 0 && (c.studEdge0 ? c.cur === 0 : c.cur === 0 || !LOD || (c.setMergedLevel ? true : c.lv[c.cur].objs.length > 0));
|
|
3150
3194
|
for (const o of c.lines)
|
|
3151
3195
|
o.visible = lineVis;
|
|
3152
3196
|
for (const o of c.cond)
|
|
@@ -3371,7 +3415,7 @@ async function warmPackGeometry(pack, stop = () => false, sliceMs = 8) {
|
|
|
3371
3415
|
await new Promise((r) => setTimeout(r, 0));
|
|
3372
3416
|
}
|
|
3373
3417
|
}
|
|
3374
|
-
// ../../../../../../../tmp/ldr-build-
|
|
3418
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/scene.ts
|
|
3375
3419
|
import * as THREE2 from "three";
|
|
3376
3420
|
function colorFn(src, pack, fallback) {
|
|
3377
3421
|
const table = new Map;
|
|
@@ -3588,10 +3632,10 @@ function createLdrObjectInner(instances, pack, options, progressive) {
|
|
|
3588
3632
|
return finish();
|
|
3589
3633
|
})();
|
|
3590
3634
|
}
|
|
3591
|
-
// ../../../../../../../tmp/ldr-build-
|
|
3635
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/parts-cdn.ts
|
|
3592
3636
|
import { decompress as decompress2 } from "fzstd";
|
|
3593
3637
|
|
|
3594
|
-
// ../../../../../../../tmp/ldr-build-
|
|
3638
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/embedded.ts
|
|
3595
3639
|
function splitFiles(text, fallback) {
|
|
3596
3640
|
const files = new Map;
|
|
3597
3641
|
let cur = null, saw = false;
|
|
@@ -3663,7 +3707,7 @@ function embeddedKeys(text, names, fallback = "main.ldr") {
|
|
|
3663
3707
|
return out;
|
|
3664
3708
|
}
|
|
3665
3709
|
|
|
3666
|
-
// ../../../../../../../tmp/ldr-build-
|
|
3710
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/parts-cdn.ts
|
|
3667
3711
|
var DEFAULT_PARTS_CDN = "https://ldr-demo.vercel.app/cdn/v1/";
|
|
3668
3712
|
var indexCache = new Map;
|
|
3669
3713
|
var shardCache = new Map;
|
|
@@ -3762,18 +3806,27 @@ async function loadPartsOnce(names, o) {
|
|
|
3762
3806
|
} else
|
|
3763
3807
|
groups.push({ file: t.file, start: t.off, end: t.off + t.len, items: [t] });
|
|
3764
3808
|
}
|
|
3765
|
-
let bytes = 0;
|
|
3809
|
+
let bytes = 0, requests = 0;
|
|
3766
3810
|
let next = 0;
|
|
3811
|
+
const full = new Map;
|
|
3767
3812
|
const worker = async () => {
|
|
3768
3813
|
while (next < groups.length) {
|
|
3769
3814
|
const g = groups[next++];
|
|
3770
|
-
|
|
3771
|
-
if (
|
|
3772
|
-
throw new Error(`ldr: parts CDN ${r.status}`);
|
|
3773
|
-
let buf = new Uint8Array(await r.arrayBuffer());
|
|
3774
|
-
if (r.status === 200)
|
|
3815
|
+
let buf = full.get(g.file);
|
|
3816
|
+
if (buf)
|
|
3775
3817
|
buf = buf.subarray(g.start, g.end);
|
|
3776
|
-
|
|
3818
|
+
else {
|
|
3819
|
+
const r = await f(new URL(idx.archives[g.file], cdn).href, { headers: { Range: `bytes=${g.start}-${g.end - 1}`, "Accept-Encoding": "identity" } });
|
|
3820
|
+
if (!r.ok)
|
|
3821
|
+
throw new Error(`ldr: parts CDN ${r.status}`);
|
|
3822
|
+
requests++;
|
|
3823
|
+
buf = new Uint8Array(await r.arrayBuffer());
|
|
3824
|
+
bytes += buf.byteLength;
|
|
3825
|
+
if (r.status === 200) {
|
|
3826
|
+
full.set(g.file, buf);
|
|
3827
|
+
buf = buf.subarray(g.start, g.end);
|
|
3828
|
+
}
|
|
3829
|
+
}
|
|
3777
3830
|
for (const t of g.items) {
|
|
3778
3831
|
const raw = decompress2(buf.subarray(t.off - g.start, t.off - g.start + t.len));
|
|
3779
3832
|
const ab = raw.buffer.slice(raw.byteOffset, raw.byteOffset + raw.byteLength);
|
|
@@ -3784,7 +3837,7 @@ async function loadPartsOnce(names, o) {
|
|
|
3784
3837
|
await Promise.all(Array.from({ length: Math.min(o.concurrency ?? 24, groups.length) }, worker));
|
|
3785
3838
|
const shards = want.filter((n) => shardCache.has(cdn + n)).map((n) => shardCache.get(cdn + n));
|
|
3786
3839
|
const pack = shards.length ? mergePacks(shards, { colors: idx.colors }) : decodePack(emptyPack(idx.colors));
|
|
3787
|
-
return { pack, missing, requests
|
|
3840
|
+
return { pack, missing, requests, bytes };
|
|
3788
3841
|
}
|
|
3789
3842
|
function emptyPack(colors) {
|
|
3790
3843
|
const h = new TextEncoder().encode(JSON.stringify({ version: 1, weld: true, parts: {}, studKinds: {}, colors }));
|
|
@@ -3886,10 +3939,10 @@ async function prepareModel(source, o = {}) {
|
|
|
3886
3939
|
return { insts, pack, missing, requests, bytes, cull, timings: { fetchModel: t1 - t0, parse: t2 - t1, parts: t3 - t2, ...cull ? { cull: performance.now() - t3 } : {} } };
|
|
3887
3940
|
}
|
|
3888
3941
|
|
|
3889
|
-
// ../../../../../../../tmp/ldr-build-
|
|
3890
|
-
var load_worker_gen_default = 'var bt=ArrayBuffer,W=Uint8Array,de=Uint16Array,yt=Int16Array;var be=Int32Array,Ee=function(e,t,n){if(W.prototype.slice)return W.prototype.slice.call(e,t,n);if(t==null||t<0)t=0;if(n==null||n>e.length)n=e.length;var r=new W(n-t);return r.set(e.subarray(t,n)),r},ce=function(e,t,n,r){if(W.prototype.fill)return W.prototype.fill.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;for(;n<r;++n)e[n]=t;return e},xt=function(e,t,n,r){if(W.prototype.copyWithin)return W.prototype.copyWithin.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;while(n<r)e[t++]=e[n++]};var wt=["invalid zstd data","window size too large (>2046MB)","invalid block type","FSE accuracy too high","match distance too far back","unexpected EOF"],K=function(e,t,n){var r=Error(t||wt[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,K);if(!n)throw r;return r},je=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},At=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},Mt=function(e,t){var n=e[0]|e[1]<<8|e[2]<<16;if(n==3126568&&e[3]==253){var r=e[4],s=r>>5&1,o=r>>2&1,i=r&3,l=r>>6;if(r&8)K(0);var a=6-s,c=i==3?4:i,f=je(e,a,c);a+=c;var m=l?1<<l:s,h=je(e,a,m)+(l==1&&256),x=h;if(!s){var T=1<<10+(e[5]>>3);x=T+(T>>3)*(e[5]&7)}if(x>2145386496)K(1);var u=new W((t==1?h||x:t?0:x)+12);return u[0]=1,u[4]=4,u[8]=8,{b:a+m,y:0,l:0,d:f,w:t&&t!=1?t:u.subarray(12),e:x,o:new be(u.buffer,0,3),u:h,c:o,m:Math.min(131072,x)}}else if((n>>4|e[3]<<20)==25481893)return At(e,4)+8;K(0)},re=function(e){var t=0;for(;1<<t<=e;++t);return t-1},ue=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)K(3);var o=1<<s,i=o,l=-1,a=-1,c=-1,f=o,m=new bt(512+(o<<2)),h=new yt(m,0,256),x=new de(m,0,256),T=new de(m,512,o),u=512+(o<<1),b=new W(m,u,o),S=new W(m,u+o);while(l<255&&i>0){var d=re(i+1),g=r>>3,p=(1<<d+1)-1,B=(e[g]|e[g+1]<<8|e[g+2]<<16)>>(r&7)&p,y=(1<<d)-1,v=p-i-1,E=B&y;if(E<v)r+=d,B=E;else if(r+=d+1,B>y)B-=v;if(h[++l]=--B,B==-1)i+=B,b[--f]=l;else i-=B;if(!B)do{var D=r>>3;a=(e[D]|e[D+1]<<8)>>(r&7)&3,r+=2,l+=a}while(a==3)}if(l>255||i)K(0);var C=0,U=(o>>1)+(o>>3)+3,X=o-1;for(var H=0;H<=l;++H){var M=h[H];if(M<1){x[H]=-M;continue}for(c=0;c<M;++c){b[C]=H;do C=C+U&X;while(C>=f)}}if(C)K(0);for(c=0;c<o;++c){var A=x[b[c]]++,L=S[c]=s-re(A);T[c]=(A<<L)-o}return[r+7>>3,{b:s,s:b,n:S,t:T}]},vt=function(e,t){var n=0,r=-1,s=new W(292),o=e[t],i=s.subarray(0,256),l=s.subarray(256,268),a=new de(s.buffer,268);if(o<128){var c=ue(e,t+1,6),f=c[0],m=c[1];t+=o;var h=f<<3,x=e[t];if(!x)K(0);var T=0,u=0,b=m.b,S=b,d=(++t<<3)-8+re(x);for(;;){if(d-=b,d<h)break;var g=d>>3;if(T+=(e[g]|e[g+1]<<8)>>(d&7)&(1<<b)-1,i[++r]=m.s[T],d-=S,d<h)break;g=d>>3,u+=(e[g]|e[g+1]<<8)>>(d&7)&(1<<S)-1,i[++r]=m.s[u],b=m.n[T],T=m.t[T],S=m.n[u],u=m.t[u]}if(++r>255)K(0)}else{r=o-127;for(;n<r;n+=2){var p=e[++t];i[n]=p>>4,i[n+1]=p&15}++t}var B=0;for(n=0;n<r;++n){var y=i[n];if(y>11)K(0);B+=y&&1<<y-1}var v=re(B)+1,E=1<<v,D=E-B;if(D&D-1)K(0);i[r++]=re(D)+1;for(n=0;n<r;++n){var y=i[n];++l[i[n]=y&&v+1-y]}var C=new W(E<<1),U=C.subarray(0,E),X=C.subarray(E);a[v]=0;for(n=v;n>0;--n){var H=a[n];ce(X,n,H,a[n-1]=H+l[n]*(1<<v-n))}if(a[0]!=E)K(0);for(n=0;n<r;++n){var M=i[n];if(M){var A=a[M];ce(U,n,A,a[M]=A+(1<<v-M))}}return[t,{n:X,b:v,s:U}]},Tt=ue(new W([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],Ct=ue(new W([33,20,196,24,99,140,33,132,16,66,8,33,132,16,66,8,33,68,68,68,68,68,68,68,68,36,9]),0,6)[1],Et=ue(new W([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],Ve=function(e,t){var n=e.length,r=new be(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Se=new W(new be([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),St=Ve(Se,0),Pe=new W(new be([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),Pt=Ve(Pe,3),le=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,l=-n.b;if(!o)K(0);var a=0,c=n.b,f=(r<<3)-8+re(o)-c,m=-1;for(;f>l&&m<s;){var h=f>>3,x=(e[h]|e[h+1]<<8|e[h+2]<<16)>>(f&7);a=(a<<c|x)&i,t[++m]=n.s[a],f-=c=n.n[a]}if(f!=l||m+1!=s)K(0)},Lt=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,l=o+i;le(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),le(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),le(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,l),n),le(e.subarray(r),t.subarray(l),n)},kt=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var l=o>>3|e[s+1]<<5|e[s+2]<<13,a=(s+=3)+l;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return ce(n,e[s],t.y,t.y+=l),n;return ce(new W(l),e[s])}if(a>e.length)return;if(i==0){if(t.b=a,n)return n.set(e.subarray(s,a),t.y),t.y+=l,n;return Ee(e,s,a)}if(i==2){var c=e[s],f=c&3,m=c>>2&3,h=c>>4,x=0,T=0;if(f<2)if(m&1)h|=e[++s]<<4|(m&2&&e[++s]<<12);else h=c>>3;else if(T=m,m<2)h|=(e[++s]&63)<<4,x=e[s]>>6|e[++s]<<2;else if(m==2)h|=e[++s]<<4|(e[++s]&3)<<12,x=e[s]>>2|e[++s]<<6;else h|=e[++s]<<4|(e[++s]&63)<<12,x=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var u=n?n.subarray(t.y,t.y+t.m):new W(t.m),b=u.length-h;if(f==0)u.set(e.subarray(s,s+=h),b);else if(f==1)ce(u,e[s++],b);else{var S=t.h;if(f==2){var d=vt(e,s);x+=s-(s=d[0]),t.h=S=d[1]}else if(!S)K(0);(T?Lt:le)(e.subarray(s,s+=x),u.subarray(b),S)}var g=e[s++];if(g){if(g==255)g=(e[s++]|e[s++]<<8)+32512;else if(g>127)g=g-128<<8|e[s++];var p=e[s++];if(p&3)K(0);var B=[Ct,Et,Tt];for(var y=2;y>-1;--y){var v=p>>(y<<1)+2&3;if(v==1){var E=new W([0,0,e[s++]]);B[y]={s:E.subarray(2,3),n:E.subarray(0,1),t:new de(E.buffer,0,1),b:0}}else if(v==2)r=ue(e,s,9-(y&1)),s=r[0],B[y]=r[1];else if(v==3){if(!t.t)K(0);B[y]=t.t[y]}}var D=t.t=B,C=D[0],U=D[1],X=D[2],H=e[a-1];if(!H)K(0);var M=(a<<3)-8+re(H)-X.b,A=M>>3,L=0,V=(e[A]|e[A+1]<<8)>>(M&7)&(1<<X.b)-1;A=(M-=U.b)>>3;var k=(e[A]|e[A+1]<<8)>>(M&7)&(1<<U.b)-1;A=(M-=C.b)>>3;var N=(e[A]|e[A+1]<<8)>>(M&7)&(1<<C.b)-1;for(++g;--g;){var P=X.s[V],w=X.n[V],O=C.s[N],F=C.n[N],R=U.s[k],z=U.n[k];A=(M-=R)>>3;var j=1<<R,I=j+((e[A]|e[A+1]<<8|e[A+2]<<16|e[A+3]<<24)>>>(M&7)&j-1);A=(M-=Pe[O])>>3;var G=Pt[O]+((e[A]|e[A+1]<<8|e[A+2]<<16)>>(M&7)&(1<<Pe[O])-1);A=(M-=Se[P])>>3;var _=St[P]+((e[A]|e[A+1]<<8|e[A+2]<<16)>>(M&7)&(1<<Se[P])-1);if(A=(M-=w)>>3,V=X.t[V]+((e[A]|e[A+1]<<8)>>(M&7)&(1<<w)-1),A=(M-=F)>>3,N=C.t[N]+((e[A]|e[A+1]<<8)>>(M&7)&(1<<F)-1),A=(M-=z)>>3,k=U.t[k]+((e[A]|e[A+1]<<8)>>(M&7)&(1<<z)-1),I>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=I-=3;else{var Y=I-(_!=0);if(Y){if(I=Y==3?t.o[0]-1:t.o[Y],Y>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=I}else I=t.o[0]}for(var y=0;y<_;++y)u[L+y]=u[b+y];L+=_,b+=_;var q=L-I;if(q<0){var J=-q,ee=t.e+q;if(J>G)J=G;for(var y=0;y<J;++y)u[L+y]=t.w[ee+y];L+=J,G-=J,q=0}for(var y=0;y<G;++y)u[L+y]=u[q+y];L+=G}if(L!=b)while(b<u.length)u[L++]=u[b++];else L=u.length;if(n)t.y+=L;else u=Ee(u,0,L)}else if(n){if(t.y+=h,b)for(var y=0;y<h;++y)u[y]=u[b+y]}else if(b)u=Ee(u,b);return t.b=a,u}K(2)},Bt=function(e,t){if(e.length==1)return e[0];var n=new W(t);for(var r=0,s=0;r<e.length;++r){var o=e[r];n.set(o,s),s+=o.length}return n};function ye(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=Mt(e,r||t);if(typeof i=="object"){if(r){if(t=null,i.w.length==i.u)n.push(t=i.w),o+=i.u}else n.push(t),i.e=0;for(;!i.l;){var l=kt(e,i,t);if(!l)K(5);if(t)i.e=i.y;else n.push(l),o+=l.length,xt(i.w,0,l.length),i.w.set(l,i.w.length-l.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return Bt(n,o)}async function It(e){let t=e instanceof Uint8Array?e:new Uint8Array(e),n=(r)=>r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength);if(t[0]===40&&t[1]===181&&t[2]===47&&t[3]===253)return n(ye(t));if(t[0]===31&&t[1]===139)return new Response(new Blob([t]).stream().pipeThrough(new DecompressionStream("gzip"))).arrayBuffer();return n(t)}async function He(e){return new TextDecoder().decode(await It(e))}var Ge=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split("/").pop()||"main.ldr").replace(/\\.(zst|gz)$/i,"")||"main.ldr";function xe(e){let t=new DataView(e).getUint32(0,!0),n=JSON.parse(new TextDecoder().decode(new Uint8Array(e,4,t))),r=4+t;return{header:n,arr:(o)=>o&&(o[2]==="f32"?new Float32Array(e,r+o[0],o[1]):o[2]==="u16"?new Uint16Array(e,r+o[0],o[1]):o[2]==="u8"?new Uint8Array(e,r+o[0],o[1]):new Uint32Array(e,r+o[0],o[1])),bytes:e.byteLength,buffer:e}}var Z=(e)=>e.trim().toLowerCase().replace(/\\\\/g,"/").replace(/\\/+/g,"/");function Le(e){if(/^0x/i.test(e))return parseInt(e,16);return+e}var _e=/^~?\\s*moved\\s+to\\s+(.+)$/i,Ft=new Set(["FILE","NOFILE","!DATA","!:","STEP","BFC","ROTSTEP","BUFEXCHG","!TEXMAP"]),Qe=new Set(["part","subpart","primitive","8_primitive","48_primitive","shortcut","helper"]),Rt=new Set(["model","submodel","configuration"]),Dt=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function We(e){let t=Dt.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,"");return Qe.has(n)||Rt.has(n)?n:void 0}function Ut(e){let t=[],n=0;while(n<e.length){while(e[n]===" "||e[n]==="\\t")n++;if(n>=e.length)break;if(e[n]===\'"\'){let r="";n++;while(n<e.length&&e[n]!==\'"\'){if(e[n]==="\\\\"&&n+1<e.length)n++;r+=e[n++]}n++,t.push(r)}else{let r=n;while(r<e.length&&e[r]!==" "&&e[r]!=="\\t")r++;t.push(e.slice(n,r)),n=r}}return t}function zt(e,t=!1){let n=/^\\s*(\\S+)\\s+(.*)$/.exec(e);if(!n)return null;let r=n[1].toUpperCase(),s=r==="PLANAR"?9:r==="CYLINDRICAL"?10:r==="SPHERICAL"?11:0;if(!s)return null;let o=n[2].trim().split(/\\s+/);if(o.length<s+1)return null;let i=o.slice(0,s).map(Number);if(!i.every(Number.isFinite))return null;let l=n[2].trim();for(let m=0;m<s;m++)l=l.replace(/^\\S+\\s*/,"");let a=Ut(l);if(!a.length)return null;let c={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:a[0]};if(s>=10)c.a=i[9];if(s===11)c.b=i[10];let f=a.findIndex((m,h)=>h>0&&m.toUpperCase()==="GLOSSMAP");if(f>0&&a[f+1])c.glossmap=a[f+1];if(t)c.next=!0;return c}var Ot=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,""),n=t+"=".repeat((4-t.length%4)%4),r=atob(n),s=new Uint8Array(r.length);for(let o=0;o<r.length;o++)s[o]=r.charCodeAt(o);return s};function Nt(e){let t=e.length,n=1,r=(c)=>c===32||c===9,s=()=>{while(n<t&&r(e.charCodeAt(n)))n++;let c=n;while(n<t&&!r(e.charCodeAt(n)))n++;return c<n?e.slice(c,n):null},o=s();if(o===null)return null;let i=Array(12);for(let c=0;c<12;c++){let f=s();if(f===null)return null;i[c]=+f}while(n<t&&r(e.charCodeAt(n)))n++;if(n>=t)return null;let l=e.slice(n),a=/[ \\t]{2,}|\\t/.test(l)?l.split(/\\s+/).join(" "):l;return{t:1,color:Le(o),m:i,file:Z(a)}}function Ke(e){let t=+e[0];if(!(t>=1&&t<=5)||e.length<2)return null;let n=Le(e[1]),r=e.slice(2).map(Number);if(t===1)return{t:1,color:n,m:r.slice(0,12),file:Z(e.slice(14).join(" "))};if(t===2)return{t:2,color:n,p:r.slice(0,6)};if(t===3)return{t:3,color:n,p:r.slice(0,9)};if(t===4)return{t:4,color:n,p:r.slice(0,12)};return{t:5,color:n,p:r.slice(0,12)}}function et(e,t="main.ldr",n={}){let r=!!n.geometryText,s=new Map,o=null,i="",l,a=null,c=[],f=null,m=()=>{if(!a)return;let d=Ot(a.chunks.join("")),g=d[0]===137&&d[1]===80&&d[2]===78&&d[3]===71;(l??=new Map).set(Z(a.name),{name:a.name,bytes:d,...g?{mime:"image/png"}:{}}),a=null},h=!0,x=(d)=>{if(m(),o={name:Z(d),cmds:[]},s.set(o.name,o),!i)i=o.name;c=[],f=null,h=!0},T=!1,u=!1,b=()=>{if(u)return;u=!0,s.clear(),o=null,i=""},S=(d,g)=>{if(f){d.tex=f,f=null;return}let p=c[c.length-1];if(!p)return;if(p.fallback){if(!g)d.fallback=!0}else d.tex=p.map};for(let d of e.split(`\n`)){let g=d.trim();if(!g)continue;if(r&&g.charCodeAt(0)>=50&&g.charCodeAt(0)<=53&&(g.charCodeAt(1)===32||g.charCodeAt(1)===9)){if(a||T)continue;if(!o)x(t);let v=g.slice(2).trimStart(),E=v.search(/\\s/),D={t:g.charCodeAt(0)-48,color:Le(E<0?v:v.slice(0,E)),p:[],src:g};S(D,!1),o.cmds.push(D),h=!1;continue}if(g.charCodeAt(0)===48&&(g.charCodeAt(1)===32||g.charCodeAt(1)===9)){let v=2;while(g.charCodeAt(v)===32||g.charCodeAt(v)===9)v++;let E=v;while(E<g.length&&g.charCodeAt(E)!==32&&g.charCodeAt(E)!==9)E++;let D=g.slice(v,E);if(!Ft.has(D)){if(T||a)continue;if(!o)x(t);let C=g.slice(v),U={t:0,text:C};if(D.charCodeAt(0)===33)U.meta=D;if(f=null,h&&!o.org){let H=We(C);if(H)o.org=H}let X=C.match(_e);if(X&&!o.movedTo){let H=X[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(H))H+=".dat";o.movedTo=Z(H)}o.cmds.push(U);continue}}if(g.charCodeAt(0)===49&&(g.charCodeAt(1)===32||g.charCodeAt(1)===9)&&!a&&!T){let v=Nt(g);if(v){if(!o)x(t);S(v,!1),o.cmds.push(v),h=!1;continue}}let p=g.split(/\\s+/);if(+p[0]===0){let v=g.slice(1).trim();if(p[1]==="FILE"){b(),T=!1,x(v.slice(5));continue}if(p[1]==="NOFILE"){m(),o=null,T=!0;continue}if(p[1]==="!DATA"){b(),m(),o=null,T=!1,a={name:v.slice(5).trim(),chunks:[]};continue}if(T)continue;if(a){if(p[1]==="!:")a.chunks.push(p.slice(2).join(""));continue}if(!o)x(t);let E={t:0,text:v};if(p[1]==="STEP")E.step=!0,c=[],f=null;else if(p[1]==="BFC")E.bfc=p.slice(2).join(" ");else if(p[1]==="ROTSTEP")if(E.meta="ROTSTEP",E.step=!0,c=[],f=null,(p[2]??"").toUpperCase()==="END")E.rotstep={x:0,y:0,z:0,mode:"END"};else{let C=(p[5]??"REL").toUpperCase();E.rotstep={x:+p[2]||0,y:+p[3]||0,z:+p[4]||0,mode:["REL","ABS","ADD"].includes(C)?C:"REL"}}else if(p[1]==="BUFEXCHG"){E.meta="BUFEXCHG";let C=(p[2]??"").toUpperCase();E.bufexchg={op:C==="RETRIEVE"?"RETRIEVE":"STORE",buf:p[3]??"A"}}else if(p[1]?.startsWith("!"))E.meta=p[1];if(h&&!o.org){let C=We(v);if(C)o.org=C}if(p[1]==="!TEXMAP"){let C=(p[2]??"").toUpperCase();if(f=null,C==="START"||C==="NEXT"){let U=zt(v.replace(/^!TEXMAP\\s+\\S+/i,""),C==="NEXT");if(E.texmap={op:C,...U?{map:U}:{}},U)if((o.texmaps??=[]).push(U),C==="START")c.push({map:U,fallback:!1});else f=U}else if(C==="FALLBACK"){E.texmap={op:C};let U=c[c.length-1];if(U)U.fallback=!0}else if(C==="END")E.texmap={op:C},c.pop()}else if(p[1]==="!:"){f=null;let C=Ke(p.slice(2));if(C)S(C,!0),E.geom=C}else f=null;let D=v.match(_e);if(D&&!o.movedTo){let C=D[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(C))C+=".dat";o.movedTo=Z(C)}o.cmds.push(E);continue}if(a||T)continue;if(!o)x(t);let y=Ke(p);if(!y)continue;S(y,!1),o.cmds.push(y),h=!1}return m(),l?{main:i,files:s,data:l}:{main:i,files:s}}var cn=Math.PI/180;function tt(e,t){let n=(r)=>[t[3]*r[0]+t[4]*r[1]+t[5]*r[2]+t[0],t[6]*r[0]+t[7]*r[1]+t[8]*r[2]+t[1],t[9]*r[0]+t[10]*r[1]+t[11]*r[2]+t[2]];return{...e,p1:n(e.p1),p2:n(e.p2),p3:n(e.p3)}}function nt(e,t){let[n,r,s,o,i,l,a,c,f,m,h,x]=e,[T,u,b,S,d,g,p,B,y,v,E,D]=t;return[o*T+i*u+l*b+n,a*T+c*u+f*b+r,m*T+h*u+x*b+s,o*S+i*p+l*v,o*d+i*B+l*E,o*g+i*y+l*D,a*S+c*p+f*v,a*d+c*B+f*E,a*g+c*y+f*D,m*S+h*p+x*v,m*d+h*B+x*E,m*g+h*y+x*D]}var ke=[0,0,0,1,0,0,0,1,0,0,0,1];var Xe=new WeakMap,$t=/^(s|8|48)\\//;function Be(e,t){let n=e.files.get(Z(t));if(!n)return"part";let r=Xe.get(n);if(r)return r;if(n.org)r=Qe.has(n.org)?"part":"model";else if(n.name===e.main)r="model";else r=n.cmds.some((s)=>s.t>=2||s.t===0&&!!s.geom||s.t===1&&$t.test(s.file))?"part":"model";return Xe.set(n,r),r}var Ze=new WeakMap;function rt(e){let t=Ze.get(e);if(t)return t;t=[];let n=0;for(let r of e.cmds){if(r.t===0&&r.step){n++;continue}if((r.t>=2||r.t===0&&r.geom&&r.geom.t>=2)&&t[t.length-1]!==n)t.push(n)}return Ze.set(e,t),t}var Ye=(e)=>e>16777215?"0x"+e.toString(16).toUpperCase():String(e),jt=(e)=>e.t===0?"0 "+e.text:e.t===1?`1 ${Ye(e.color)} ${e.m.join(" ")} ${e.file}`:e.src?e.src:`${e.t} ${Ye(e.color)} ${e.p.join(" ")}`,Ie=(e,t)=>`${Z(e)}#${t}`;function Vt(e,t){let n=[],r=0,s=(o)=>!!o&&o.t===0&&o.texmap?.op==="NEXT";for(let o of e.cmds){if(o.t===0){if(o.step){r++;continue}if(o.bfc!==void 0){n.push(o);continue}if(r!==t)continue;if(o.texmap)n.push(o);else if(o.geom){if(o.geom.t>=2)n.push(o);else if(s(n[n.length-1]))n.pop()}continue}if(r!==t)continue;if(o.t===1){if(s(n[n.length-1]))n.pop();continue}n.push(o)}return{name:Ie(e.name,t),cmds:n}}function st(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Vt(e,t).cmds.map(jt)].join(`\n`)+`\n`}function Ht(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,"0")}function ot(e){let[t,n,r,s,o,i,l,a,c,f,m,h]=e,x=a*h-c*m,T=-(l*h-c*f),u=l*m-a*f,b=s*x+o*T+i*u;if(!Number.isFinite(b)||Math.abs(b)<0.000000000001)return null;let S=1/b,d=[x*S,-(o*h-i*m)*S,(o*c-i*a)*S,T*S,(s*h-i*f)*S,-(s*c-i*l)*S,u*S,-(s*m-o*f)*S,(s*a-o*l)*S];return[-(d[0]*t+d[1]*n+d[2]*r),-(d[3]*t+d[4]*n+d[5]*r),-(d[6]*t+d[7]*n+d[8]*r),...d]}var Gt=(e)=>String(+e.toFixed(6)||0),Je=(e)=>\'"\'+e.replace(/\\\\/g,"\\\\\\\\").replace(/"/g,"\\\\\\"")+\'"\';function it(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!=="PLANAR"?[t.a??360]:[],...t.method==="SPHERICAL"?[t.b??180]:[]].map(Gt).join(" "),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${Je(t.texture)}${t.glossmap?" GLOSSMAP "+Je(t.glossmap):""}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${Z(e)}\n0 !TEXMAP END\n`;return{name:`${Z(e)}#tex-${Ht(r)}`,source:r}}var _t=(e,t)=>{let n=[,,,,,,,,,];for(let r=0;r<3;r++)for(let s=0;s<3;s++)n[r*3+s]=e[r*3]*t[s]+e[r*3+1]*t[3+s]+e[r*3+2]*t[6+s];return n};function Wt(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),l=Math.cos(t*r),a=Math.sin(n*r),c=Math.cos(n*r);return[l*c,-l*a,i,o*a+s*i*c,o*c-s*i*a,-s*l,s*a-o*i*c,s*c+o*i*a,o*l]}var qe=new WeakMap;function at(e){let t=qe.get(e);if(t)return t;let n=[],r=null;for(let s of e.cmds){if(s.t!==0||!s.step)continue;let o=s.rotstep;if(o)if(o.mode==="END")r=null;else{let i=Wt(o.x,o.y,o.z);r=o.mode==="ABS"?{abs:!0,m:i,rotstep:o}:o.mode==="ADD"&&r?{abs:r.abs,m:_t(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),qe.set(e,n),n}var lt=999999,ct=(e)=>e.map((t)=>String(t).padStart(6,"0")).join(".")+"~";function Kt(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,l=new Map,a=0,c=(m,h)=>{let x=m.name+"#"+h,T=l.get(x);if(!T){let u;T=Object.assign(()=>u??=st(m,h),{file:m,step:h}),l.set(x,T)}return T},f=(m,h,x,T,u,b,S,d,g=null,p=[],B=[])=>{let y=m.files.get(h);if(!y||S>r)return;let v=0,E=S>0?++a:0,D=i&&E?[...p,E]:p,C=i&&E?[...B,x]:B,U=i&&!g?new Map:null,X=-1,H=0,M=(P,w,O,F,R,z)=>{if(X!==v)X=v,H=0;let j=U?.get(v+"|"+w);if(j)return j.n++,f(P,P===m?w:P.main,O,F,u+"/"+w,[...R,lt],S+1,z,[...R,lt],D,C);let I=[...R,H++],G=n.length;f(P,P===m?w:P.main,O,F,u+"/"+w,I,S+1,z,g,D,C),U?.set(v+"|"+w,{n:1,from:G,to:n.length})},A=at(y),L=s?rt(y):[],V=0,k=(P,w,O,F,R,z,j)=>{if(g)F=g;let I={part:P,color:w,m:O,step:F[0],steps:F,localStep:R,path:u};if(E){if(I.sub=E,i)I.subPath=D,I.subMats=C}if(z)I.embedded=!0;if(j){let _=it(P,j);I.texPart=_.name,I.texSource=_.source}let G=A[R];if(G)I.view=G;return n.push(I),I},N=(P)=>{while(V<L.length&&L[V]<=P){let w=L[V++];k(Ie(y.name,w),T,x,[...b,w],w,!1,null).source=c(y,w)}};for(let P of y.cmds){if(P.t===0&&P.step){v++;continue}let w=P;if(w.t>=2||w.t===0&&w.geom&&w.geom.t>=2){N(v);continue}if(w.t===0)if(o&&w.geom?.t===1)w=w.geom;else continue;if(w.t!==1)continue;if(o&&w.fallback)continue;let O=w.color===16?T:w.color,F=nt(x,w.m),R=[...b,v],z=o?w.tex??d:null,j=z?ot(w.m):null,I=z&&j?tt(z,j):null;if(m.files.has(w.file)){if(Be(m,w.file)==="model"){M(m,w.file,F,O,R,I);continue}k(w.file,O,F,R,v,!0,I);continue}let G=t.resolveModel?.(w.file);if(G){M(G,w.file,F,O,R,I);continue}k(w.file,O,F,R,v,!1,I)}if(N(1/0),U){for(let P of U.values())if(P.n>1)for(let w=P.from;w<P.to;w++)n[w].mult??=P.n}};if(Be(e,e.main)==="part"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...ke],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return f(e,e.main,ke,16,e.main,[],0,null),n}function ut(e,t="main.ldr",n){return Kt(et(e,t,{geometryText:!0}),n)}function Xt(e,t){let n=new Map,r=null,s=!1;for(let o of e.split(/\\r?\\n/)){let i=/^\\s*0\\s+FILE\\s+(.+)$/i.exec(o);if(i){if(!s)n.clear();s=!0,r=[],n.set(Z(i[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(o)){if(!s)n.clear();s=!0,r=null;continue}if(!r){if(s)continue;r=[],n.set(Z(t),r)}let l=o.trim().replace(/\\s+/g," ");if(l)r.push(l)}return n}var Zt=(e)=>{if(!e.startsWith("1 "))return null;let t=e.split(" ");return t.length>=15?Z(t.slice(14).join(" ")):null};function Yt(e){let t=2166136261,n=1523705862;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);t=Math.imul(t^s,16777619),n=Math.imul(n^s,16777629)^n>>>15}return(t>>>0).toString(16).padStart(8,"0")+(n>>>0).toString(16).padStart(8,"0")}function ft(e,t,n="main.ldr"){let r=Xt(e,n),s=new Map;for(let o of t){let i=Z(o);if(!r.has(i)||s.has(i))continue;let l=new Set([i]),a=[i];while(a.length)for(let f of r.get(a.pop())){let m=Zt(f);if(m&&r.has(m)&&!l.has(m))l.add(m),a.push(m)}let c=[i,...[...l].filter((f)=>f!==i).sort()].map((f)=>"0 FILE "+(f===i?"":f)+`\n`+r.get(f).join(`\n`)).join(`\n`);s.set(i,`emb/${Yt(c)}.dat`)}return s}var pt=(e,t=0)=>Math.abs(e[t+7]-1)<0.001&&Math.abs(e[t+4])<0.001&&Math.abs(e[t+10])<0.001,mt=new WeakMap;function Fe(e,t){let n=mt.get(e);if(!n)mt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),l=[],a=[];s.studs.forEach((h,x)=>{l.push(h[0]),a.push(h[1]);for(let T=0;T<12;T++)i[x*12+T]=h[2+T]});let c=null,f=0,m=0;if(s.mask){f=s.mask[0],m=s.mask[1];let h=s.mask[2];c=new Uint8Array(h.length);for(let x=0;x<h.length;x++)c[x]=h.charCodeAt(x)===49?1:0}return n.set(t,r={nStuds:o,studM:i,kind:l,color:a,mask:c,nx:f,nz:m}),r}var ie=1073741824;class Re{a;b;c;vals;used;mask;size=0;constructor(e=1024){let t=1024;while(t<e*2)t*=2;this.a=new Int32Array(t),this.b=new Int32Array(t),this.c=new Int32Array(t),this.vals=new Int32Array(t),this.used=new Uint8Array(t),this.mask=t-1}slot(e,t,n){let r=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return r^=r>>>15,r=Math.imul(r,739982445),r^=r>>>12,r&this.mask}get(e,t,n){let r=this.slot(e,t,n),s=this.used,o=this.a,i=this.b,l=this.c;for(;;){if(!s[r])return-1;if(o[r]===e&&i[r]===t&&l[r]===n)return this.vals[r];r=r+1&this.mask}}put(e,t,n,r){if((this.size+1)*2>this.used.length)this.grow();let s=this.slot(e,t,n),o=this.used,i=this.a,l=this.b,a=this.c;for(;;){if(!o[s])return o[s]=1,i[s]=e,l[s]=t,a[s]=n,this.vals[s]=r,this.size++,-1;if(i[s]===e&&l[s]===t&&a[s]===n){let c=this.vals[s];return this.vals[s]=r,c}s=s+1&this.mask}}grow(){let{a:e,b:t,c:n,vals:r,used:s}=this,o=s.length*2;this.a=new Int32Array(o),this.b=new Int32Array(o),this.c=new Int32Array(o),this.vals=new Int32Array(o),this.used=new Uint8Array(o),this.mask=o-1,this.size=0;for(let i=0;i<s.length;i++)if(s[i])this.put(e[i],t[i],n[i],r[i])}}var we=(e,t,n)=>e>-ie&&e<ie&&t>-ie&&t<ie&&n>-ie&&n<ie,fe=2147483647;function Jt(e,t,n){let s=[],o=[],i=[],l=[],a=[],c=[],f=[],m=[],h=new Re(e.length*2),x=[],T=[];for(let M=0;M<e.length;M++){let A=e[M],L=A.m,V=t.parts[A.part];if(!V||!V.mask||!pt(L))continue;let k=V.bbox,N=1/0,P=-1/0,w=1/0,O=-1/0;for(let z=0;z<2;z++)for(let j=0;j<2;j++){let I=z?k[3]:k[0],G=j?k[5]:k[2],_=L[0]+L[3]*I+L[5]*G,Y=L[2]+L[9]*I+L[11]*G;if(_<N)N=_;if(_>P)P=_;if(Y<w)w=Y;if(Y>O)O=Y}let F=a.length;s.push(N),o.push(P),i.push(w),l.push(O),a.push(M),c.push(Fe(t,A.part)),f.push(k[0]),m.push(k[2]);let R=Math.round((L[1]+k[4])*2);for(let z=Math.floor(N/40);z<=Math.floor(P/40);z++)for(let j=Math.floor(w/40);j<=Math.floor(O/40);j++){if(!we(R,z,j))continue;let I=T.length;T.push(F),x.push(h.put(R,z,j,I))}}let u=[0,5,-5,5,-5],b=[0,5,5,-5,-5],S=NaN,d=NaN,g=NaN,p=-1,B=(M,A,L,V)=>{let k=Math.round(A*2),N=Math.floor(M/40),P=Math.floor(L/40);if(!we(k,N,P))return fe;let w=fe;if(k!==S||N!==d||P!==g)S=k,d=N,g=P,p=h.get(k,N,P);for(let O=p;O>=0;O=x[O]){let F=T[O];if(a[F]===V||!(M-6>=s[F]-0.5&&M+6<=o[F]+0.5&&L-6>=i[F]-0.5&&L+6<=l[F]+0.5))continue;let R=e[a[F]].m,z=c[F],j=f[F],I=m[F],G=M-R[0],_=A-R[1],Y=L-R[2],q=R[3]*G+R[6]*_+R[9]*Y,J=R[5]*G+R[8]*_+R[11]*Y,{nx:ee,nz:se,mask:ae}=z,oe=!0;for(let Q=0;Q<5;Q++){let te=Math.floor((q+u[Q]-j)/20),ne=Math.floor((J+b[Q]-I)/20);if(te<0||ne<0||te>=ee||ne>=se||ae[te*se+ne]!==1){oe=!1;break}}if(oe){if(!n)return 0;let Q=n[a[F]];if(Q<w)w=Q}}return w},y=0;for(let M of e){let A=Fe(t,M.part);if(A)y+=A.nStuds}let v=new Uint8Array(y),E=new Uint8Array(y),D=new Re(y),C=0,U=n?new Int32Array(y).fill(fe):void 0;for(let M=0,A=0;M<e.length;M++){let L=e[M],V=Fe(t,L.part);if(!V)continue;let k=L.m,N=V.studM,P=k[0],w=k[1],O=k[2],F=k[3],R=k[4],z=k[5],j=k[6],I=k[7],G=k[8],_=k[9],Y=k[10],q=k[11];for(let J=0;J<V.nStuds;J++,A++){let ee=J*12,se=N[ee+4],ae=N[ee+7],oe=N[ee+10];if(!(Math.abs(j*se+I*ae+G*oe-1)<0.001&&Math.abs(F*se+R*ae+z*oe)<0.001&&Math.abs(_*se+Y*ae+q*oe)<0.001))continue;E[A]=1;let Q=N[ee],te=N[ee+1],ne=N[ee+2],De=P+F*Q+R*te+z*ne,Ue=w+j*Q+I*te+G*ne,ze=O+_*Q+Y*te+q*ne,Oe=B(De,Ue,ze,M);if(Oe!==fe){if(v[A]=1,C++,U)U[A]=Oe}let me=Math.round(De),he=Math.round(Ue),ge=Math.round(ze);if(!we(me,he,ge))continue;if(!n){D.put(me,he,ge,1);continue}let Ne=n[M],$e=D.get(me,he,ge);if($e<0||Ne<$e)D.put(me,he,ge,Ne)}}let X=new Uint8Array(e.length),H=n?new Int32Array(e.length).fill(fe):void 0;for(let M=0;M<e.length;M++){let A=e[M],L=t.parts[A.part];if(!L||!L.under||!pt(A.m))continue;let V=L.bbox,k=Math.round((V[3]-V[0])/20),N=Math.round((V[5]-V[2])/20);if(!k||!N||k*N>4096)continue;let P=A.m,w=!0,O=0;for(let F=0;F<k&&w;F++)for(let R=0;R<N;R++){let z=V[0]+10+20*F,j=V[2]+10+20*R,I=P[0]+P[3]*z+P[5]*j,G=P[2]+P[9]*z+P[11]*j,_=Math.round(I),Y=Math.round(P[1]+V[4]),q=Math.round(G),J=we(_,Y,q)?D.get(_,Y,q):-1;if(J<0){w=!1;break}if(J>O)O=J}if(w){if(X[M]=1,H)H[M]=O}}return{nStuds:y,studHidden:v,studUp:E,underHidden:X,studsHidden:C,studHideStep:U,underHideStep:H}}function qt(e,t,n){let r=(a)=>n&&a.texPart&&t.parts[a.texPart]?a.texPart:a.part,s=e.map((a)=>({part:r(a),color:String(a.color),m:a.m,steps:a.steps})),o=s.map((a)=>ct(a.steps)),i=[...new Set(o)].sort(),l=new Map(i.map((a,c)=>[a,c]));return{all:s,stepOf:o.map((a)=>l.get(a)),nSteps:i.length}}function Ae(e,t,n=!0){let r=qt(e,t,n);return Jt(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Ce="https://ldr-demo.vercel.app/cdn/v1/",ve=new Map,Me=new Map;function gt(e=Ce,t=fetch){let n=ve.get(e);if(!n)n=t(e+"parts.json").then((r)=>{if(!r.ok)throw Error(`ldr: parts CDN index ${r.status} (${e}parts.json)`);return r.json()}),n.catch(()=>ve.delete(e)),ve.set(e,n);return n}var Qt=(e)=>Array.isArray(e)&&e.length===3&&typeof e[0]==="number"&&typeof e[1]==="number"&&(e[2]==="f32"||e[2]==="u16"||e[2]==="u8"||e[2]==="u32"),Te=(e,t)=>Qt(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>Te(n,t)):e&&typeof e==="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Te(r,t)])):e;function en(e,t={}){let n=[],r=0,s={},o={};for(let h of e){let x=h.buffer;if(!x)throw Error("ldr: mergePacks needs packs from decodePack/loadPack");let T=new DataView(x).getUint32(0,!0),u=new Uint8Array(x,4+T),b=r;n.push(u),r+=u.byteLength;let S=(4-r%4)%4;if(S)n.push(new Uint8Array(S)),r+=S;for(let[d,g]of Object.entries(h.header.parts??{}))if(!(d in s))s[d]=Te(g,b);for(let[d,g]of Object.entries(h.header.studKinds??{}))if(!(d in o))o[d]=Te(g,b)}let i=e[0]?.header??{version:1,weld:!0},l=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),a=(4-(4+l.length)%4)%4,c=4+l.length+a,f=new Uint8Array(c+r);new DataView(f.buffer).setUint32(0,l.length+a,!0),f.set(l,4),f.fill(32,4+l.length,c);let m=c;for(let h of n)f.set(h,m),m+=h.byteLength;return xe(f.buffer)}async function tn(e,t={}){e=[...e];try{return await ht(e,t)}catch(n){let r=t.cdn??Ce,s=t.fetch??fetch;ve.delete(r);let o=(i,l)=>s(i,{...l,cache:"reload"});try{return await ht(e,{...t,fetch:o})}catch{throw n}}}async function ht(e,t){let n=t.cdn??Ce,r=t.fetch??fetch,s=t.gap??16384,o=await gt(n,r),i=[...new Set([...e].map(Z))],l=[],a=[];for(let u of i){if(Me.has(n+u))continue;let b=o.parts[u];if(b)a.push({name:u,off:b[0],len:b[1],file:b[2]??0});else l.push(u)}a.sort((u,b)=>u.file-b.file||u.off-b.off);let c=[];for(let u of a){let b=c[c.length-1];if(b&&b.file===u.file&&u.off-b.end<=s)b.end=Math.max(b.end,u.off+u.len),b.items.push(u);else c.push({file:u.file,start:u.off,end:u.off+u.len,items:[u]})}let f=0,m=0,h=async()=>{while(m<c.length){let u=c[m++],b=await r(new URL(o.archives[u.file],n).href,{headers:{Range:`bytes=${u.start}-${u.end-1}`}});if(!b.ok)throw Error(`ldr: parts CDN ${b.status}`);let S=new Uint8Array(await b.arrayBuffer());if(b.status===200)S=S.subarray(u.start,u.end);f+=S.byteLength;for(let d of u.items){let g=ye(S.subarray(d.off-u.start,d.off-u.start+d.len)),p=g.buffer.slice(g.byteOffset,g.byteOffset+g.byteLength);Me.set(n+d.name,xe(p))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,c.length)},h));let x=i.filter((u)=>Me.has(n+u)).map((u)=>Me.get(n+u));return{pack:x.length?en(x,{colors:o.colors}):xe(nn(o.colors)),missing:l,requests:c.length,bytes:f}}function nn(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},colors:e})),n=(4-(4+t.length)%4)%4,r=new Uint8Array(4+t.length+n).fill(32);return new DataView(r.buffer).setUint32(0,t.length+n,!0),r.set(t,4),r.buffer}function rn(e,t){let n=t.header.parts;if(!n)return 0;let r=0;for(let s of e){let o=n[s.part]?.body?.tris;if(o)r+=o}return r}function sn(e,t,n){let r=0,s=0,o=!1,i=new Set;for(let l of e){let a=l.embedded?t.get(l.part):Z(l.part),c=a?n.parts[a]:void 0;if(!c)continue;if(c[3]!=null)o=!0,r+=c[3];if(!i.has(a))i.add(a),s+=c[1]}return{bodyTris:r,packBytes:s,known:o}}class pe extends Error{code="ldr-budget";bodyTris;packBytes;maxBodyTris;maxPackBytes;constructor(e){let t=[e.maxBodyTris!=null&&e.bodyTris>e.maxBodyTris?`${e.bodyTris} triangles (limit ${e.maxBodyTris})`:"",e.maxPackBytes!=null&&e.packBytes>e.maxPackBytes?`${(e.packBytes/1e6).toFixed(1)} MB parts pack (limit ${(e.maxPackBytes/1e6).toFixed(0)} MB)`:""].filter(Boolean).join(", ");super(`ldr: model exceeds device budget: ${t}`);this.name="BudgetError",this.bodyTris=e.bodyTris,this.packBytes=e.packBytes,this.maxBodyTris=e.maxBodyTris,this.maxPackBytes=e.maxPackBytes}}async function dt(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=gt(t.cdn??Ce,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(p)=>{if(!p.ok)throw Error(`ldr: ${p.status} fetching ${e}`);return He(await p.arrayBuffer())}),i=performance.now(),l=t.name??(t.text?"main.ldr":Ge(e)),a=ut(o,l,{looseGeometry:!1,callouts:t.callouts}),c=performance.now();t.onParsed?.(a),await s;let f=ft(o,new Set(a.filter((p)=>p.embedded).map((p)=>p.part)),l),m=(p,B)=>t.maxBodyTris!=null&&p>t.maxBodyTris||t.maxPackBytes!=null&&B>t.maxPackBytes;if(t.maxBodyTris!=null||t.maxPackBytes!=null){let p=sn(a,f,await s);if(m(p.known?p.bodyTris:0,p.packBytes))throw new pe({bodyTris:p.bodyTris,packBytes:p.packBytes,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes})}let{pack:h,missing:x,requests:T,bytes:u}=await tn([...a.filter((p)=>!p.embedded).map((p)=>p.part),...f.values()],t),b=new Map([...f].map(([p,B])=>[B,p])),S=x.map((p)=>b.get(p)??p);for(let[p,B]of f){let y=h.header.parts[B];if(y)h.header.parts[p]=y}let d=performance.now();if(t.maxBodyTris!=null||t.maxPackBytes!=null){let p=h.buffer?.byteLength??h.bytes??0,B=rn(a,h);if(m(B,p))throw new pe({bodyTris:B,packBytes:p,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes})}let g=t.cull?Ae(a,h.header,t.textures!==!1):void 0;return{insts:a,pack:h,missing:S,requests:T,bytes:u,cull:g,timings:{fetchModel:i-n,parse:c-i,parts:d-c,...g?{cull:performance.now()-d}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await dt(n,{...r,cull:!1,onParsed:(f)=>self.postMessage({id:t,insts:f})}),o=s.pack.buffer;if(self.postMessage({id:t,buffer:o,missing:s.missing,requests:s.requests,bytes:s.bytes,timings:s.timings},[o]),!r.cull)return;let i=performance.now(),l=Ae(s.insts,s.pack.header,r.textures!==!1),a=performance.now()-i,c=[];for(let f of[l.studHidden,l.studUp,l.underHidden,l.studHideStep,l.underHideStep])if(f)c.push(f.buffer);self.postMessage({id:t,cull:l,ms:a},c)}catch(s){if(s instanceof pe||s?.code==="ldr-budget")self.postMessage({id:t,phase:"error",error:String(s?.message??s),budget:{bodyTris:s.bodyTris,packBytes:s.packBytes,maxBodyTris:s.maxBodyTris,maxPackBytes:s.maxPackBytes}});else self.postMessage({id:t,phase:"error",error:String(s?.message??s)})}};\n';
|
|
3942
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/load-worker.gen.ts
|
|
3943
|
+
var load_worker_gen_default = 'var bt=ArrayBuffer,W=Uint8Array,de=Uint16Array,yt=Int16Array;var be=Int32Array,Ee=function(e,t,n){if(W.prototype.slice)return W.prototype.slice.call(e,t,n);if(t==null||t<0)t=0;if(n==null||n>e.length)n=e.length;var r=new W(n-t);return r.set(e.subarray(t,n)),r},ce=function(e,t,n,r){if(W.prototype.fill)return W.prototype.fill.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;for(;n<r;++n)e[n]=t;return e},xt=function(e,t,n,r){if(W.prototype.copyWithin)return W.prototype.copyWithin.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;while(n<r)e[t++]=e[n++]};var wt=["invalid zstd data","window size too large (>2046MB)","invalid block type","FSE accuracy too high","match distance too far back","unexpected EOF"],K=function(e,t,n){var r=Error(t||wt[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,K);if(!n)throw r;return r},je=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},At=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},Mt=function(e,t){var n=e[0]|e[1]<<8|e[2]<<16;if(n==3126568&&e[3]==253){var r=e[4],s=r>>5&1,o=r>>2&1,i=r&3,l=r>>6;if(r&8)K(0);var a=6-s,c=i==3?4:i,f=je(e,a,c);a+=c;var m=l?1<<l:s,g=je(e,a,m)+(l==1&&256),y=g;if(!s){var v=1<<10+(e[5]>>3);y=v+(v>>3)*(e[5]&7)}if(y>2145386496)K(1);var x=new W((t==1?g||y:t?0:y)+12);return x[0]=1,x[4]=4,x[8]=8,{b:a+m,y:0,l:0,d:f,w:t&&t!=1?t:x.subarray(12),e:y,o:new be(x.buffer,0,3),u:g,c:o,m:Math.min(131072,y)}}else if((n>>4|e[3]<<20)==25481893)return At(e,4)+8;K(0)},re=function(e){var t=0;for(;1<<t<=e;++t);return t-1},ue=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)K(3);var o=1<<s,i=o,l=-1,a=-1,c=-1,f=o,m=new bt(512+(o<<2)),g=new yt(m,0,256),y=new de(m,0,256),v=new de(m,512,o),x=512+(o<<1),S=new W(m,x,o),h=new W(m,x+o);while(l<255&&i>0){var u=re(i+1),d=r>>3,p=(1<<u+1)-1,L=(e[d]|e[d+1]<<8|e[d+2]<<16)>>(r&7)&p,b=(1<<u)-1,T=p-i-1,E=L&b;if(E<T)r+=u,L=E;else if(r+=u+1,L>b)L-=T;if(g[++l]=--L,L==-1)i+=L,S[--f]=l;else i-=L;if(!L)do{var D=r>>3;a=(e[D]|e[D+1]<<8)>>(r&7)&3,r+=2,l+=a}while(a==3)}if(l>255||i)K(0);var C=0,U=(o>>1)+(o>>3)+3,X=o-1;for(var H=0;H<=l;++H){var M=g[H];if(M<1){y[H]=-M;continue}for(c=0;c<M;++c){S[C]=H;do C=C+U&X;while(C>=f)}}if(C)K(0);for(c=0;c<o;++c){var A=y[S[c]]++,k=h[c]=s-re(A);v[c]=(A<<k)-o}return[r+7>>3,{b:s,s:S,n:h,t:v}]},vt=function(e,t){var n=0,r=-1,s=new W(292),o=e[t],i=s.subarray(0,256),l=s.subarray(256,268),a=new de(s.buffer,268);if(o<128){var c=ue(e,t+1,6),f=c[0],m=c[1];t+=o;var g=f<<3,y=e[t];if(!y)K(0);var v=0,x=0,S=m.b,h=S,u=(++t<<3)-8+re(y);for(;;){if(u-=S,u<g)break;var d=u>>3;if(v+=(e[d]|e[d+1]<<8)>>(u&7)&(1<<S)-1,i[++r]=m.s[v],u-=h,u<g)break;d=u>>3,x+=(e[d]|e[d+1]<<8)>>(u&7)&(1<<h)-1,i[++r]=m.s[x],S=m.n[v],v=m.t[v],h=m.n[x],x=m.t[x]}if(++r>255)K(0)}else{r=o-127;for(;n<r;n+=2){var p=e[++t];i[n]=p>>4,i[n+1]=p&15}++t}var L=0;for(n=0;n<r;++n){var b=i[n];if(b>11)K(0);L+=b&&1<<b-1}var T=re(L)+1,E=1<<T,D=E-L;if(D&D-1)K(0);i[r++]=re(D)+1;for(n=0;n<r;++n){var b=i[n];++l[i[n]=b&&T+1-b]}var C=new W(E<<1),U=C.subarray(0,E),X=C.subarray(E);a[T]=0;for(n=T;n>0;--n){var H=a[n];ce(X,n,H,a[n-1]=H+l[n]*(1<<T-n))}if(a[0]!=E)K(0);for(n=0;n<r;++n){var M=i[n];if(M){var A=a[M];ce(U,n,A,a[M]=A+(1<<T-M))}}return[t,{n:X,b:T,s:U}]},Tt=ue(new W([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],Ct=ue(new W([33,20,196,24,99,140,33,132,16,66,8,33,132,16,66,8,33,68,68,68,68,68,68,68,68,36,9]),0,6)[1],Et=ue(new W([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],Ve=function(e,t){var n=e.length,r=new be(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Se=new W(new be([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),St=Ve(Se,0),Pe=new W(new be([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),Pt=Ve(Pe,3),le=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,l=-n.b;if(!o)K(0);var a=0,c=n.b,f=(r<<3)-8+re(o)-c,m=-1;for(;f>l&&m<s;){var g=f>>3,y=(e[g]|e[g+1]<<8|e[g+2]<<16)>>(f&7);a=(a<<c|y)&i,t[++m]=n.s[a],f-=c=n.n[a]}if(f!=l||m+1!=s)K(0)},Lt=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,l=o+i;le(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),le(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),le(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,l),n),le(e.subarray(r),t.subarray(l),n)},kt=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var l=o>>3|e[s+1]<<5|e[s+2]<<13,a=(s+=3)+l;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return ce(n,e[s],t.y,t.y+=l),n;return ce(new W(l),e[s])}if(a>e.length)return;if(i==0){if(t.b=a,n)return n.set(e.subarray(s,a),t.y),t.y+=l,n;return Ee(e,s,a)}if(i==2){var c=e[s],f=c&3,m=c>>2&3,g=c>>4,y=0,v=0;if(f<2)if(m&1)g|=e[++s]<<4|(m&2&&e[++s]<<12);else g=c>>3;else if(v=m,m<2)g|=(e[++s]&63)<<4,y=e[s]>>6|e[++s]<<2;else if(m==2)g|=e[++s]<<4|(e[++s]&3)<<12,y=e[s]>>2|e[++s]<<6;else g|=e[++s]<<4|(e[++s]&63)<<12,y=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var x=n?n.subarray(t.y,t.y+t.m):new W(t.m),S=x.length-g;if(f==0)x.set(e.subarray(s,s+=g),S);else if(f==1)ce(x,e[s++],S);else{var h=t.h;if(f==2){var u=vt(e,s);y+=s-(s=u[0]),t.h=h=u[1]}else if(!h)K(0);(v?Lt:le)(e.subarray(s,s+=y),x.subarray(S),h)}var d=e[s++];if(d){if(d==255)d=(e[s++]|e[s++]<<8)+32512;else if(d>127)d=d-128<<8|e[s++];var p=e[s++];if(p&3)K(0);var L=[Ct,Et,Tt];for(var b=2;b>-1;--b){var T=p>>(b<<1)+2&3;if(T==1){var E=new W([0,0,e[s++]]);L[b]={s:E.subarray(2,3),n:E.subarray(0,1),t:new de(E.buffer,0,1),b:0}}else if(T==2)r=ue(e,s,9-(b&1)),s=r[0],L[b]=r[1];else if(T==3){if(!t.t)K(0);L[b]=t.t[b]}}var D=t.t=L,C=D[0],U=D[1],X=D[2],H=e[a-1];if(!H)K(0);var M=(a<<3)-8+re(H)-X.b,A=M>>3,k=0,V=(e[A]|e[A+1]<<8)>>(M&7)&(1<<X.b)-1;A=(M-=U.b)>>3;var B=(e[A]|e[A+1]<<8)>>(M&7)&(1<<U.b)-1;A=(M-=C.b)>>3;var N=(e[A]|e[A+1]<<8)>>(M&7)&(1<<C.b)-1;for(++d;--d;){var P=X.s[V],w=X.n[V],O=C.s[N],F=C.n[N],R=U.s[B],z=U.n[B];A=(M-=R)>>3;var j=1<<R,I=j+((e[A]|e[A+1]<<8|e[A+2]<<16|e[A+3]<<24)>>>(M&7)&j-1);A=(M-=Pe[O])>>3;var G=Pt[O]+((e[A]|e[A+1]<<8|e[A+2]<<16)>>(M&7)&(1<<Pe[O])-1);A=(M-=Se[P])>>3;var _=St[P]+((e[A]|e[A+1]<<8|e[A+2]<<16)>>(M&7)&(1<<Se[P])-1);if(A=(M-=w)>>3,V=X.t[V]+((e[A]|e[A+1]<<8)>>(M&7)&(1<<w)-1),A=(M-=F)>>3,N=C.t[N]+((e[A]|e[A+1]<<8)>>(M&7)&(1<<F)-1),A=(M-=z)>>3,B=U.t[B]+((e[A]|e[A+1]<<8)>>(M&7)&(1<<z)-1),I>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=I-=3;else{var Y=I-(_!=0);if(Y){if(I=Y==3?t.o[0]-1:t.o[Y],Y>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=I}else I=t.o[0]}for(var b=0;b<_;++b)x[k+b]=x[S+b];k+=_,S+=_;var q=k-I;if(q<0){var J=-q,ee=t.e+q;if(J>G)J=G;for(var b=0;b<J;++b)x[k+b]=t.w[ee+b];k+=J,G-=J,q=0}for(var b=0;b<G;++b)x[k+b]=x[q+b];k+=G}if(k!=S)while(S<x.length)x[k++]=x[S++];else k=x.length;if(n)t.y+=k;else x=Ee(x,0,k)}else if(n){if(t.y+=g,S)for(var b=0;b<g;++b)x[b]=x[S+b]}else if(S)x=Ee(x,S);return t.b=a,x}K(2)},Bt=function(e,t){if(e.length==1)return e[0];var n=new W(t);for(var r=0,s=0;r<e.length;++r){var o=e[r];n.set(o,s),s+=o.length}return n};function ye(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=Mt(e,r||t);if(typeof i=="object"){if(r){if(t=null,i.w.length==i.u)n.push(t=i.w),o+=i.u}else n.push(t),i.e=0;for(;!i.l;){var l=kt(e,i,t);if(!l)K(5);if(t)i.e=i.y;else n.push(l),o+=l.length,xt(i.w,0,l.length),i.w.set(l,i.w.length-l.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return Bt(n,o)}async function It(e){let t=e instanceof Uint8Array?e:new Uint8Array(e),n=(r)=>r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength);if(t[0]===40&&t[1]===181&&t[2]===47&&t[3]===253)return n(ye(t));if(t[0]===31&&t[1]===139)return new Response(new Blob([t]).stream().pipeThrough(new DecompressionStream("gzip"))).arrayBuffer();return n(t)}async function He(e){return new TextDecoder().decode(await It(e))}var Ge=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split("/").pop()||"main.ldr").replace(/\\.(zst|gz)$/i,"")||"main.ldr";function xe(e){let t=new DataView(e).getUint32(0,!0),n=JSON.parse(new TextDecoder().decode(new Uint8Array(e,4,t))),r=4+t;return{header:n,arr:(o)=>o&&(o[2]==="f32"?new Float32Array(e,r+o[0],o[1]):o[2]==="u16"?new Uint16Array(e,r+o[0],o[1]):o[2]==="u8"?new Uint8Array(e,r+o[0],o[1]):new Uint32Array(e,r+o[0],o[1])),bytes:e.byteLength,buffer:e}}var Z=(e)=>e.trim().toLowerCase().replace(/\\\\/g,"/").replace(/\\/+/g,"/");function Le(e){if(/^0x/i.test(e))return parseInt(e,16);return+e}var _e=/^~?\\s*moved\\s+to\\s+(.+)$/i,Ft=new Set(["FILE","NOFILE","!DATA","!:","STEP","BFC","ROTSTEP","BUFEXCHG","!TEXMAP"]),Qe=new Set(["part","subpart","primitive","8_primitive","48_primitive","shortcut","helper"]),Rt=new Set(["model","submodel","configuration"]),Dt=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function We(e){let t=Dt.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,"");return Qe.has(n)||Rt.has(n)?n:void 0}function Ut(e){let t=[],n=0;while(n<e.length){while(e[n]===" "||e[n]==="\\t")n++;if(n>=e.length)break;if(e[n]===\'"\'){let r="";n++;while(n<e.length&&e[n]!==\'"\'){if(e[n]==="\\\\"&&n+1<e.length)n++;r+=e[n++]}n++,t.push(r)}else{let r=n;while(r<e.length&&e[r]!==" "&&e[r]!=="\\t")r++;t.push(e.slice(n,r)),n=r}}return t}function zt(e,t=!1){let n=/^\\s*(\\S+)\\s+(.*)$/.exec(e);if(!n)return null;let r=n[1].toUpperCase(),s=r==="PLANAR"?9:r==="CYLINDRICAL"?10:r==="SPHERICAL"?11:0;if(!s)return null;let o=n[2].trim().split(/\\s+/);if(o.length<s+1)return null;let i=o.slice(0,s).map(Number);if(!i.every(Number.isFinite))return null;let l=n[2].trim();for(let m=0;m<s;m++)l=l.replace(/^\\S+\\s*/,"");let a=Ut(l);if(!a.length)return null;let c={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:a[0]};if(s>=10)c.a=i[9];if(s===11)c.b=i[10];let f=a.findIndex((m,g)=>g>0&&m.toUpperCase()==="GLOSSMAP");if(f>0&&a[f+1])c.glossmap=a[f+1];if(t)c.next=!0;return c}var Ot=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,""),n=t+"=".repeat((4-t.length%4)%4),r=atob(n),s=new Uint8Array(r.length);for(let o=0;o<r.length;o++)s[o]=r.charCodeAt(o);return s};function Nt(e){let t=e.length,n=1,r=(c)=>c===32||c===9,s=()=>{while(n<t&&r(e.charCodeAt(n)))n++;let c=n;while(n<t&&!r(e.charCodeAt(n)))n++;return c<n?e.slice(c,n):null},o=s();if(o===null)return null;let i=Array(12);for(let c=0;c<12;c++){let f=s();if(f===null)return null;i[c]=+f}while(n<t&&r(e.charCodeAt(n)))n++;if(n>=t)return null;let l=e.slice(n),a=/[ \\t]{2,}|\\t/.test(l)?l.split(/\\s+/).join(" "):l;return{t:1,color:Le(o),m:i,file:Z(a)}}function Ke(e){let t=+e[0];if(!(t>=1&&t<=5)||e.length<2)return null;let n=Le(e[1]),r=e.slice(2).map(Number);if(t===1)return{t:1,color:n,m:r.slice(0,12),file:Z(e.slice(14).join(" "))};if(t===2)return{t:2,color:n,p:r.slice(0,6)};if(t===3)return{t:3,color:n,p:r.slice(0,9)};if(t===4)return{t:4,color:n,p:r.slice(0,12)};return{t:5,color:n,p:r.slice(0,12)}}function et(e,t="main.ldr",n={}){let r=!!n.geometryText,s=new Map,o=null,i="",l,a=null,c=[],f=null,m=()=>{if(!a)return;let u=Ot(a.chunks.join("")),d=u[0]===137&&u[1]===80&&u[2]===78&&u[3]===71;(l??=new Map).set(Z(a.name),{name:a.name,bytes:u,...d?{mime:"image/png"}:{}}),a=null},g=!0,y=(u)=>{if(m(),o={name:Z(u),cmds:[]},s.set(o.name,o),!i)i=o.name;c=[],f=null,g=!0},v=!1,x=!1,S=()=>{if(x)return;x=!0,s.clear(),o=null,i=""},h=(u,d)=>{if(f){u.tex=f,f=null;return}let p=c[c.length-1];if(!p)return;if(p.fallback){if(!d)u.fallback=!0}else u.tex=p.map};for(let u of e.split(`\n`)){let d=u.trim();if(!d)continue;if(r&&d.charCodeAt(0)>=50&&d.charCodeAt(0)<=53&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)){if(a||v)continue;if(!o)y(t);let T=d.slice(2).trimStart(),E=T.search(/\\s/),D={t:d.charCodeAt(0)-48,color:Le(E<0?T:T.slice(0,E)),p:[],src:d};h(D,!1),o.cmds.push(D),g=!1;continue}if(d.charCodeAt(0)===48&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)){let T=2;while(d.charCodeAt(T)===32||d.charCodeAt(T)===9)T++;let E=T;while(E<d.length&&d.charCodeAt(E)!==32&&d.charCodeAt(E)!==9)E++;let D=d.slice(T,E);if(!Ft.has(D)){if(v||a)continue;if(!o)y(t);let C=d.slice(T),U={t:0,text:C};if(D.charCodeAt(0)===33)U.meta=D;if(f=null,g&&!o.org){let H=We(C);if(H)o.org=H}let X=C.match(_e);if(X&&!o.movedTo){let H=X[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(H))H+=".dat";o.movedTo=Z(H)}o.cmds.push(U);continue}}if(d.charCodeAt(0)===49&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)&&!a&&!v){let T=Nt(d);if(T){if(!o)y(t);h(T,!1),o.cmds.push(T),g=!1;continue}}let p=d.split(/\\s+/);if(+p[0]===0){let T=d.slice(1).trim();if(p[1]==="FILE"){S(),v=!1,y(T.slice(5));continue}if(p[1]==="NOFILE"){m(),o=null,v=!0;continue}if(p[1]==="!DATA"){S(),m(),o=null,v=!1,a={name:T.slice(5).trim(),chunks:[]};continue}if(v)continue;if(a){if(p[1]==="!:")a.chunks.push(p.slice(2).join(""));continue}if(!o)y(t);let E={t:0,text:T};if(p[1]==="STEP")E.step=!0,c=[],f=null;else if(p[1]==="BFC")E.bfc=p.slice(2).join(" ");else if(p[1]==="ROTSTEP")if(E.meta="ROTSTEP",E.step=!0,c=[],f=null,(p[2]??"").toUpperCase()==="END")E.rotstep={x:0,y:0,z:0,mode:"END"};else{let C=(p[5]??"REL").toUpperCase();E.rotstep={x:+p[2]||0,y:+p[3]||0,z:+p[4]||0,mode:["REL","ABS","ADD"].includes(C)?C:"REL"}}else if(p[1]==="BUFEXCHG"){E.meta="BUFEXCHG";let C=(p[2]??"").toUpperCase();E.bufexchg={op:C==="RETRIEVE"?"RETRIEVE":"STORE",buf:p[3]??"A"}}else if(p[1]?.startsWith("!"))E.meta=p[1];if(g&&!o.org){let C=We(T);if(C)o.org=C}if(p[1]==="!TEXMAP"){let C=(p[2]??"").toUpperCase();if(f=null,C==="START"||C==="NEXT"){let U=zt(T.replace(/^!TEXMAP\\s+\\S+/i,""),C==="NEXT");if(E.texmap={op:C,...U?{map:U}:{}},U)if((o.texmaps??=[]).push(U),C==="START")c.push({map:U,fallback:!1});else f=U}else if(C==="FALLBACK"){E.texmap={op:C};let U=c[c.length-1];if(U)U.fallback=!0}else if(C==="END")E.texmap={op:C},c.pop()}else if(p[1]==="!:"){f=null;let C=Ke(p.slice(2));if(C)h(C,!0),E.geom=C}else f=null;let D=T.match(_e);if(D&&!o.movedTo){let C=D[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(C))C+=".dat";o.movedTo=Z(C)}o.cmds.push(E);continue}if(a||v)continue;if(!o)y(t);let b=Ke(p);if(!b)continue;h(b,!1),o.cmds.push(b),g=!1}return m(),l?{main:i,files:s,data:l}:{main:i,files:s}}var cn=Math.PI/180;function tt(e,t){let n=(r)=>[t[3]*r[0]+t[4]*r[1]+t[5]*r[2]+t[0],t[6]*r[0]+t[7]*r[1]+t[8]*r[2]+t[1],t[9]*r[0]+t[10]*r[1]+t[11]*r[2]+t[2]];return{...e,p1:n(e.p1),p2:n(e.p2),p3:n(e.p3)}}function nt(e,t){let[n,r,s,o,i,l,a,c,f,m,g,y]=e,[v,x,S,h,u,d,p,L,b,T,E,D]=t;return[o*v+i*x+l*S+n,a*v+c*x+f*S+r,m*v+g*x+y*S+s,o*h+i*p+l*T,o*u+i*L+l*E,o*d+i*b+l*D,a*h+c*p+f*T,a*u+c*L+f*E,a*d+c*b+f*D,m*h+g*p+y*T,m*u+g*L+y*E,m*d+g*b+y*D]}var ke=[0,0,0,1,0,0,0,1,0,0,0,1];var Xe=new WeakMap,$t=/^(s|8|48)\\//;function Be(e,t){let n=e.files.get(Z(t));if(!n)return"part";let r=Xe.get(n);if(r)return r;if(n.org)r=Qe.has(n.org)?"part":"model";else if(n.name===e.main)r="model";else r=n.cmds.some((s)=>s.t>=2||s.t===0&&!!s.geom||s.t===1&&$t.test(s.file))?"part":"model";return Xe.set(n,r),r}var Ze=new WeakMap;function rt(e){let t=Ze.get(e);if(t)return t;t=[];let n=0;for(let r of e.cmds){if(r.t===0&&r.step){n++;continue}if((r.t>=2||r.t===0&&r.geom&&r.geom.t>=2)&&t[t.length-1]!==n)t.push(n)}return Ze.set(e,t),t}var Ye=(e)=>e>16777215?"0x"+e.toString(16).toUpperCase():String(e),jt=(e)=>e.t===0?"0 "+e.text:e.t===1?`1 ${Ye(e.color)} ${e.m.join(" ")} ${e.file}`:e.src?e.src:`${e.t} ${Ye(e.color)} ${e.p.join(" ")}`,Ie=(e,t)=>`${Z(e)}#${t}`;function Vt(e,t){let n=[],r=0,s=(o)=>!!o&&o.t===0&&o.texmap?.op==="NEXT";for(let o of e.cmds){if(o.t===0){if(o.step){r++;continue}if(o.bfc!==void 0){n.push(o);continue}if(r!==t)continue;if(o.texmap)n.push(o);else if(o.geom){if(o.geom.t>=2)n.push(o);else if(s(n[n.length-1]))n.pop()}continue}if(r!==t)continue;if(o.t===1){if(s(n[n.length-1]))n.pop();continue}n.push(o)}return{name:Ie(e.name,t),cmds:n}}function st(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Vt(e,t).cmds.map(jt)].join(`\n`)+`\n`}function Ht(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,"0")}function ot(e){let[t,n,r,s,o,i,l,a,c,f,m,g]=e,y=a*g-c*m,v=-(l*g-c*f),x=l*m-a*f,S=s*y+o*v+i*x;if(!Number.isFinite(S)||Math.abs(S)<0.000000000001)return null;let h=1/S,u=[y*h,-(o*g-i*m)*h,(o*c-i*a)*h,v*h,(s*g-i*f)*h,-(s*c-i*l)*h,x*h,-(s*m-o*f)*h,(s*a-o*l)*h];return[-(u[0]*t+u[1]*n+u[2]*r),-(u[3]*t+u[4]*n+u[5]*r),-(u[6]*t+u[7]*n+u[8]*r),...u]}var Gt=(e)=>String(+e.toFixed(6)||0),Je=(e)=>\'"\'+e.replace(/\\\\/g,"\\\\\\\\").replace(/"/g,"\\\\\\"")+\'"\';function it(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!=="PLANAR"?[t.a??360]:[],...t.method==="SPHERICAL"?[t.b??180]:[]].map(Gt).join(" "),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${Je(t.texture)}${t.glossmap?" GLOSSMAP "+Je(t.glossmap):""}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${Z(e)}\n0 !TEXMAP END\n`;return{name:`${Z(e)}#tex-${Ht(r)}`,source:r}}var _t=(e,t)=>{let n=[,,,,,,,,,];for(let r=0;r<3;r++)for(let s=0;s<3;s++)n[r*3+s]=e[r*3]*t[s]+e[r*3+1]*t[3+s]+e[r*3+2]*t[6+s];return n};function Wt(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),l=Math.cos(t*r),a=Math.sin(n*r),c=Math.cos(n*r);return[l*c,-l*a,i,o*a+s*i*c,o*c-s*i*a,-s*l,s*a-o*i*c,s*c+o*i*a,o*l]}var qe=new WeakMap;function at(e){let t=qe.get(e);if(t)return t;let n=[],r=null;for(let s of e.cmds){if(s.t!==0||!s.step)continue;let o=s.rotstep;if(o)if(o.mode==="END")r=null;else{let i=Wt(o.x,o.y,o.z);r=o.mode==="ABS"?{abs:!0,m:i,rotstep:o}:o.mode==="ADD"&&r?{abs:r.abs,m:_t(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),qe.set(e,n),n}var lt=999999,ct=(e)=>e.map((t)=>String(t).padStart(6,"0")).join(".")+"~";function Kt(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,l=new Map,a=0,c=(m,g)=>{let y=m.name+"#"+g,v=l.get(y);if(!v){let x;v=Object.assign(()=>x??=st(m,g),{file:m,step:g}),l.set(y,v)}return v},f=(m,g,y,v,x,S,h,u,d=null,p=[],L=[])=>{let b=m.files.get(g);if(!b||h>r)return;let T=0,E=h>0?++a:0,D=i&&E?[...p,E]:p,C=i&&E?[...L,y]:L,U=i&&!d?new Map:null,X=-1,H=0,M=(P,w,O,F,R,z)=>{if(X!==T)X=T,H=0;let j=U?.get(T+"|"+w);if(j)return j.n++,f(P,P===m?w:P.main,O,F,x+"/"+w,[...R,lt],h+1,z,[...R,lt],D,C);let I=[...R,H++],G=n.length;f(P,P===m?w:P.main,O,F,x+"/"+w,I,h+1,z,d,D,C),U?.set(T+"|"+w,{n:1,from:G,to:n.length})},A=at(b),k=s?rt(b):[],V=0,B=(P,w,O,F,R,z,j)=>{if(d)F=d;let I={part:P,color:w,m:O,step:F[0],steps:F,localStep:R,path:x};if(E){if(I.sub=E,i)I.subPath=D,I.subMats=C}if(z)I.embedded=!0;if(j){let _=it(P,j);I.texPart=_.name,I.texSource=_.source}let G=A[R];if(G)I.view=G;return n.push(I),I},N=(P)=>{while(V<k.length&&k[V]<=P){let w=k[V++];B(Ie(b.name,w),v,y,[...S,w],w,!1,null).source=c(b,w)}};for(let P of b.cmds){if(P.t===0&&P.step){T++;continue}let w=P;if(w.t>=2||w.t===0&&w.geom&&w.geom.t>=2){N(T);continue}if(w.t===0)if(o&&w.geom?.t===1)w=w.geom;else continue;if(w.t!==1)continue;if(o&&w.fallback)continue;let O=w.color===16?v:w.color,F=nt(y,w.m),R=[...S,T],z=o?w.tex??u:null,j=z?ot(w.m):null,I=z&&j?tt(z,j):null;if(m.files.has(w.file)){if(Be(m,w.file)==="model"){M(m,w.file,F,O,R,I);continue}B(w.file,O,F,R,T,!0,I);continue}let G=t.resolveModel?.(w.file);if(G){M(G,w.file,F,O,R,I);continue}B(w.file,O,F,R,T,!1,I)}if(N(1/0),U){for(let P of U.values())if(P.n>1)for(let w=P.from;w<P.to;w++)n[w].mult??=P.n}};if(Be(e,e.main)==="part"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...ke],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return f(e,e.main,ke,16,e.main,[],0,null),n}function ut(e,t="main.ldr",n){return Kt(et(e,t,{geometryText:!0}),n)}function Xt(e,t){let n=new Map,r=null,s=!1;for(let o of e.split(/\\r?\\n/)){let i=/^\\s*0\\s+FILE\\s+(.+)$/i.exec(o);if(i){if(!s)n.clear();s=!0,r=[],n.set(Z(i[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(o)){if(!s)n.clear();s=!0,r=null;continue}if(!r){if(s)continue;r=[],n.set(Z(t),r)}let l=o.trim().replace(/\\s+/g," ");if(l)r.push(l)}return n}var Zt=(e)=>{if(!e.startsWith("1 "))return null;let t=e.split(" ");return t.length>=15?Z(t.slice(14).join(" ")):null};function Yt(e){let t=2166136261,n=1523705862;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);t=Math.imul(t^s,16777619),n=Math.imul(n^s,16777629)^n>>>15}return(t>>>0).toString(16).padStart(8,"0")+(n>>>0).toString(16).padStart(8,"0")}function ft(e,t,n="main.ldr"){let r=Xt(e,n),s=new Map;for(let o of t){let i=Z(o);if(!r.has(i)||s.has(i))continue;let l=new Set([i]),a=[i];while(a.length)for(let f of r.get(a.pop())){let m=Zt(f);if(m&&r.has(m)&&!l.has(m))l.add(m),a.push(m)}let c=[i,...[...l].filter((f)=>f!==i).sort()].map((f)=>"0 FILE "+(f===i?"":f)+`\n`+r.get(f).join(`\n`)).join(`\n`);s.set(i,`emb/${Yt(c)}.dat`)}return s}var pt=(e,t=0)=>Math.abs(e[t+7]-1)<0.001&&Math.abs(e[t+4])<0.001&&Math.abs(e[t+10])<0.001,mt=new WeakMap;function Fe(e,t){let n=mt.get(e);if(!n)mt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),l=[],a=[];s.studs.forEach((g,y)=>{l.push(g[0]),a.push(g[1]);for(let v=0;v<12;v++)i[y*12+v]=g[2+v]});let c=null,f=0,m=0;if(s.mask){f=s.mask[0],m=s.mask[1];let g=s.mask[2];c=new Uint8Array(g.length);for(let y=0;y<g.length;y++)c[y]=g.charCodeAt(y)===49?1:0}return n.set(t,r={nStuds:o,studM:i,kind:l,color:a,mask:c,nx:f,nz:m}),r}var ie=1073741824;class Re{a;b;c;vals;used;mask;size=0;constructor(e=1024){let t=1024;while(t<e*2)t*=2;this.a=new Int32Array(t),this.b=new Int32Array(t),this.c=new Int32Array(t),this.vals=new Int32Array(t),this.used=new Uint8Array(t),this.mask=t-1}slot(e,t,n){let r=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return r^=r>>>15,r=Math.imul(r,739982445),r^=r>>>12,r&this.mask}get(e,t,n){let r=this.slot(e,t,n),s=this.used,o=this.a,i=this.b,l=this.c;for(;;){if(!s[r])return-1;if(o[r]===e&&i[r]===t&&l[r]===n)return this.vals[r];r=r+1&this.mask}}put(e,t,n,r){if((this.size+1)*2>this.used.length)this.grow();let s=this.slot(e,t,n),o=this.used,i=this.a,l=this.b,a=this.c;for(;;){if(!o[s])return o[s]=1,i[s]=e,l[s]=t,a[s]=n,this.vals[s]=r,this.size++,-1;if(i[s]===e&&l[s]===t&&a[s]===n){let c=this.vals[s];return this.vals[s]=r,c}s=s+1&this.mask}}grow(){let{a:e,b:t,c:n,vals:r,used:s}=this,o=s.length*2;this.a=new Int32Array(o),this.b=new Int32Array(o),this.c=new Int32Array(o),this.vals=new Int32Array(o),this.used=new Uint8Array(o),this.mask=o-1,this.size=0;for(let i=0;i<s.length;i++)if(s[i])this.put(e[i],t[i],n[i],r[i])}}var we=(e,t,n)=>e>-ie&&e<ie&&t>-ie&&t<ie&&n>-ie&&n<ie,fe=2147483647;function Jt(e,t,n){let s=[],o=[],i=[],l=[],a=[],c=[],f=[],m=[],g=new Re(e.length*2),y=[],v=[];for(let M=0;M<e.length;M++){let A=e[M],k=A.m,V=t.parts[A.part];if(!V||!V.mask||!pt(k))continue;let B=V.bbox,N=1/0,P=-1/0,w=1/0,O=-1/0;for(let z=0;z<2;z++)for(let j=0;j<2;j++){let I=z?B[3]:B[0],G=j?B[5]:B[2],_=k[0]+k[3]*I+k[5]*G,Y=k[2]+k[9]*I+k[11]*G;if(_<N)N=_;if(_>P)P=_;if(Y<w)w=Y;if(Y>O)O=Y}let F=a.length;s.push(N),o.push(P),i.push(w),l.push(O),a.push(M),c.push(Fe(t,A.part)),f.push(B[0]),m.push(B[2]);let R=Math.round((k[1]+B[4])*2);for(let z=Math.floor(N/40);z<=Math.floor(P/40);z++)for(let j=Math.floor(w/40);j<=Math.floor(O/40);j++){if(!we(R,z,j))continue;let I=v.length;v.push(F),y.push(g.put(R,z,j,I))}}let x=[0,5,-5,5,-5],S=[0,5,5,-5,-5],h=NaN,u=NaN,d=NaN,p=-1,L=(M,A,k,V)=>{let B=Math.round(A*2),N=Math.floor(M/40),P=Math.floor(k/40);if(!we(B,N,P))return fe;let w=fe;if(B!==h||N!==u||P!==d)h=B,u=N,d=P,p=g.get(B,N,P);for(let O=p;O>=0;O=y[O]){let F=v[O];if(a[F]===V||!(M-6>=s[F]-0.5&&M+6<=o[F]+0.5&&k-6>=i[F]-0.5&&k+6<=l[F]+0.5))continue;let R=e[a[F]].m,z=c[F],j=f[F],I=m[F],G=M-R[0],_=A-R[1],Y=k-R[2],q=R[3]*G+R[6]*_+R[9]*Y,J=R[5]*G+R[8]*_+R[11]*Y,{nx:ee,nz:se,mask:ae}=z,oe=!0;for(let Q=0;Q<5;Q++){let te=Math.floor((q+x[Q]-j)/20),ne=Math.floor((J+S[Q]-I)/20);if(te<0||ne<0||te>=ee||ne>=se||ae[te*se+ne]!==1){oe=!1;break}}if(oe){if(!n)return 0;let Q=n[a[F]];if(Q<w)w=Q}}return w},b=0;for(let M of e){let A=Fe(t,M.part);if(A)b+=A.nStuds}let T=new Uint8Array(b),E=new Uint8Array(b),D=new Re(b),C=0,U=n?new Int32Array(b).fill(fe):void 0;for(let M=0,A=0;M<e.length;M++){let k=e[M],V=Fe(t,k.part);if(!V)continue;let B=k.m,N=V.studM,P=B[0],w=B[1],O=B[2],F=B[3],R=B[4],z=B[5],j=B[6],I=B[7],G=B[8],_=B[9],Y=B[10],q=B[11];for(let J=0;J<V.nStuds;J++,A++){let ee=J*12,se=N[ee+4],ae=N[ee+7],oe=N[ee+10];if(!(Math.abs(j*se+I*ae+G*oe-1)<0.001&&Math.abs(F*se+R*ae+z*oe)<0.001&&Math.abs(_*se+Y*ae+q*oe)<0.001))continue;E[A]=1;let Q=N[ee],te=N[ee+1],ne=N[ee+2],De=P+F*Q+R*te+z*ne,Ue=w+j*Q+I*te+G*ne,ze=O+_*Q+Y*te+q*ne,Oe=L(De,Ue,ze,M);if(Oe!==fe){if(T[A]=1,C++,U)U[A]=Oe}let me=Math.round(De),he=Math.round(Ue),ge=Math.round(ze);if(!we(me,he,ge))continue;if(!n){D.put(me,he,ge,1);continue}let Ne=n[M],$e=D.get(me,he,ge);if($e<0||Ne<$e)D.put(me,he,ge,Ne)}}let X=new Uint8Array(e.length),H=n?new Int32Array(e.length).fill(fe):void 0;for(let M=0;M<e.length;M++){let A=e[M],k=t.parts[A.part];if(!k||!k.under||!pt(A.m))continue;let V=k.bbox,B=Math.round((V[3]-V[0])/20),N=Math.round((V[5]-V[2])/20);if(!B||!N||B*N>4096)continue;let P=A.m,w=!0,O=0;for(let F=0;F<B&&w;F++)for(let R=0;R<N;R++){let z=V[0]+10+20*F,j=V[2]+10+20*R,I=P[0]+P[3]*z+P[5]*j,G=P[2]+P[9]*z+P[11]*j,_=Math.round(I),Y=Math.round(P[1]+V[4]),q=Math.round(G),J=we(_,Y,q)?D.get(_,Y,q):-1;if(J<0){w=!1;break}if(J>O)O=J}if(w){if(X[M]=1,H)H[M]=O}}return{nStuds:b,studHidden:T,studUp:E,underHidden:X,studsHidden:C,studHideStep:U,underHideStep:H}}function qt(e,t,n){let r=(a)=>n&&a.texPart&&t.parts[a.texPart]?a.texPart:a.part,s=e.map((a)=>({part:r(a),color:String(a.color),m:a.m,steps:a.steps})),o=s.map((a)=>ct(a.steps)),i=[...new Set(o)].sort(),l=new Map(i.map((a,c)=>[a,c]));return{all:s,stepOf:o.map((a)=>l.get(a)),nSteps:i.length}}function Ae(e,t,n=!0){let r=qt(e,t,n);return Jt(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Ce="https://ldr-demo.vercel.app/cdn/v1/",ve=new Map,Me=new Map;function gt(e=Ce,t=fetch){let n=ve.get(e);if(!n)n=t(e+"parts.json").then((r)=>{if(!r.ok)throw Error(`ldr: parts CDN index ${r.status} (${e}parts.json)`);return r.json()}),n.catch(()=>ve.delete(e)),ve.set(e,n);return n}var Qt=(e)=>Array.isArray(e)&&e.length===3&&typeof e[0]==="number"&&typeof e[1]==="number"&&(e[2]==="f32"||e[2]==="u16"||e[2]==="u8"||e[2]==="u32"),Te=(e,t)=>Qt(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>Te(n,t)):e&&typeof e==="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Te(r,t)])):e;function en(e,t={}){let n=[],r=0,s={},o={};for(let g of e){let y=g.buffer;if(!y)throw Error("ldr: mergePacks needs packs from decodePack/loadPack");let v=new DataView(y).getUint32(0,!0),x=new Uint8Array(y,4+v),S=r;n.push(x),r+=x.byteLength;let h=(4-r%4)%4;if(h)n.push(new Uint8Array(h)),r+=h;for(let[u,d]of Object.entries(g.header.parts??{}))if(!(u in s))s[u]=Te(d,S);for(let[u,d]of Object.entries(g.header.studKinds??{}))if(!(u in o))o[u]=Te(d,S)}let i=e[0]?.header??{version:1,weld:!0},l=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),a=(4-(4+l.length)%4)%4,c=4+l.length+a,f=new Uint8Array(c+r);new DataView(f.buffer).setUint32(0,l.length+a,!0),f.set(l,4),f.fill(32,4+l.length,c);let m=c;for(let g of n)f.set(g,m),m+=g.byteLength;return xe(f.buffer)}async function tn(e,t={}){e=[...e];try{return await ht(e,t)}catch(n){let r=t.cdn??Ce,s=t.fetch??fetch;ve.delete(r);let o=(i,l)=>s(i,{...l,cache:"reload"});try{return await ht(e,{...t,fetch:o})}catch{throw n}}}async function ht(e,t){let n=t.cdn??Ce,r=t.fetch??fetch,s=t.gap??16384,o=await gt(n,r),i=[...new Set([...e].map(Z))],l=[],a=[];for(let h of i){if(Me.has(n+h))continue;let u=o.parts[h];if(u)a.push({name:h,off:u[0],len:u[1],file:u[2]??0});else l.push(h)}a.sort((h,u)=>h.file-u.file||h.off-u.off);let c=[];for(let h of a){let u=c[c.length-1];if(u&&u.file===h.file&&h.off-u.end<=s)u.end=Math.max(u.end,h.off+h.len),u.items.push(h);else c.push({file:h.file,start:h.off,end:h.off+h.len,items:[h]})}let f=0,m=0,g=0,y=new Map,v=async()=>{while(g<c.length){let h=c[g++],u=y.get(h.file);if(u)u=u.subarray(h.start,h.end);else{let d=await r(new URL(o.archives[h.file],n).href,{headers:{Range:`bytes=${h.start}-${h.end-1}`,"Accept-Encoding":"identity"}});if(!d.ok)throw Error(`ldr: parts CDN ${d.status}`);if(m++,u=new Uint8Array(await d.arrayBuffer()),f+=u.byteLength,d.status===200)y.set(h.file,u),u=u.subarray(h.start,h.end)}for(let d of h.items){let p=ye(u.subarray(d.off-h.start,d.off-h.start+d.len)),L=p.buffer.slice(p.byteOffset,p.byteOffset+p.byteLength);Me.set(n+d.name,xe(L))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,c.length)},v));let x=i.filter((h)=>Me.has(n+h)).map((h)=>Me.get(n+h));return{pack:x.length?en(x,{colors:o.colors}):xe(nn(o.colors)),missing:l,requests:m,bytes:f}}function nn(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},colors:e})),n=(4-(4+t.length)%4)%4,r=new Uint8Array(4+t.length+n).fill(32);return new DataView(r.buffer).setUint32(0,t.length+n,!0),r.set(t,4),r.buffer}function rn(e,t){let n=t.header.parts;if(!n)return 0;let r=0;for(let s of e){let o=n[s.part]?.body?.tris;if(o)r+=o}return r}function sn(e,t,n){let r=0,s=0,o=!1,i=new Set;for(let l of e){let a=l.embedded?t.get(l.part):Z(l.part),c=a?n.parts[a]:void 0;if(!c)continue;if(c[3]!=null)o=!0,r+=c[3];if(!i.has(a))i.add(a),s+=c[1]}return{bodyTris:r,packBytes:s,known:o}}class pe extends Error{code="ldr-budget";bodyTris;packBytes;maxBodyTris;maxPackBytes;constructor(e){let t=[e.maxBodyTris!=null&&e.bodyTris>e.maxBodyTris?`${e.bodyTris} triangles (limit ${e.maxBodyTris})`:"",e.maxPackBytes!=null&&e.packBytes>e.maxPackBytes?`${(e.packBytes/1e6).toFixed(1)} MB parts pack (limit ${(e.maxPackBytes/1e6).toFixed(0)} MB)`:""].filter(Boolean).join(", ");super(`ldr: model exceeds device budget: ${t}`);this.name="BudgetError",this.bodyTris=e.bodyTris,this.packBytes=e.packBytes,this.maxBodyTris=e.maxBodyTris,this.maxPackBytes=e.maxPackBytes}}async function dt(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=gt(t.cdn??Ce,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(p)=>{if(!p.ok)throw Error(`ldr: ${p.status} fetching ${e}`);return He(await p.arrayBuffer())}),i=performance.now(),l=t.name??(t.text?"main.ldr":Ge(e)),a=ut(o,l,{looseGeometry:!1,callouts:t.callouts}),c=performance.now();t.onParsed?.(a),await s;let f=ft(o,new Set(a.filter((p)=>p.embedded).map((p)=>p.part)),l),m=(p,L)=>t.maxBodyTris!=null&&p>t.maxBodyTris||t.maxPackBytes!=null&&L>t.maxPackBytes;if(t.maxBodyTris!=null||t.maxPackBytes!=null){let p=sn(a,f,await s);if(m(p.known?p.bodyTris:0,p.packBytes))throw new pe({bodyTris:p.bodyTris,packBytes:p.packBytes,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes})}let{pack:g,missing:y,requests:v,bytes:x}=await tn([...a.filter((p)=>!p.embedded).map((p)=>p.part),...f.values()],t),S=new Map([...f].map(([p,L])=>[L,p])),h=y.map((p)=>S.get(p)??p);for(let[p,L]of f){let b=g.header.parts[L];if(b)g.header.parts[p]=b}let u=performance.now();if(t.maxBodyTris!=null||t.maxPackBytes!=null){let p=g.buffer?.byteLength??g.bytes??0,L=rn(a,g);if(m(L,p))throw new pe({bodyTris:L,packBytes:p,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes})}let d=t.cull?Ae(a,g.header,t.textures!==!1):void 0;return{insts:a,pack:g,missing:h,requests:v,bytes:x,cull:d,timings:{fetchModel:i-n,parse:c-i,parts:u-c,...d?{cull:performance.now()-u}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await dt(n,{...r,cull:!1,onParsed:(f)=>self.postMessage({id:t,insts:f})}),o=s.pack.buffer;if(self.postMessage({id:t,buffer:o,missing:s.missing,requests:s.requests,bytes:s.bytes,timings:s.timings},[o]),!r.cull)return;let i=performance.now(),l=Ae(s.insts,s.pack.header,r.textures!==!1),a=performance.now()-i,c=[];for(let f of[l.studHidden,l.studUp,l.underHidden,l.studHideStep,l.underHideStep])if(f)c.push(f.buffer);self.postMessage({id:t,cull:l,ms:a},c)}catch(s){if(s instanceof pe||s?.code==="ldr-budget")self.postMessage({id:t,phase:"error",error:String(s?.message??s),budget:{bodyTris:s.bodyTris,packBytes:s.packBytes,maxBodyTris:s.maxBodyTris,maxPackBytes:s.maxPackBytes}});else self.postMessage({id:t,phase:"error",error:String(s?.message??s)})}};\n';
|
|
3891
3944
|
|
|
3892
|
-
// ../../../../../../../tmp/ldr-build-
|
|
3945
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/cdn.ts
|
|
3893
3946
|
var worker;
|
|
3894
3947
|
var seq = 0;
|
|
3895
3948
|
var pending = new Map;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "var bt=ArrayBuffer,W=Uint8Array,de=Uint16Array,yt=Int16Array;var be=Int32Array,Ee=function(e,t,n){if(W.prototype.slice)return W.prototype.slice.call(e,t,n);if(t==null||t<0)t=0;if(n==null||n>e.length)n=e.length;var r=new W(n-t);return r.set(e.subarray(t,n)),r},ce=function(e,t,n,r){if(W.prototype.fill)return W.prototype.fill.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;for(;n<r;++n)e[n]=t;return e},xt=function(e,t,n,r){if(W.prototype.copyWithin)return W.prototype.copyWithin.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;while(n<r)e[t++]=e[n++]};var wt=[\"invalid zstd data\",\"window size too large (>2046MB)\",\"invalid block type\",\"FSE accuracy too high\",\"match distance too far back\",\"unexpected EOF\"],K=function(e,t,n){var r=Error(t||wt[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,K);if(!n)throw r;return r},je=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},At=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},Mt=function(e,t){var n=e[0]|e[1]<<8|e[2]<<16;if(n==3126568&&e[3]==253){var r=e[4],s=r>>5&1,o=r>>2&1,i=r&3,l=r>>6;if(r&8)K(0);var a=6-s,c=i==3?4:i,f=je(e,a,c);a+=c;var m=l?1<<l:s,h=je(e,a,m)+(l==1&&256),x=h;if(!s){var T=1<<10+(e[5]>>3);x=T+(T>>3)*(e[5]&7)}if(x>2145386496)K(1);var u=new W((t==1?h||x:t?0:x)+12);return u[0]=1,u[4]=4,u[8]=8,{b:a+m,y:0,l:0,d:f,w:t&&t!=1?t:u.subarray(12),e:x,o:new be(u.buffer,0,3),u:h,c:o,m:Math.min(131072,x)}}else if((n>>4|e[3]<<20)==25481893)return At(e,4)+8;K(0)},re=function(e){var t=0;for(;1<<t<=e;++t);return t-1},ue=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)K(3);var o=1<<s,i=o,l=-1,a=-1,c=-1,f=o,m=new bt(512+(o<<2)),h=new yt(m,0,256),x=new de(m,0,256),T=new de(m,512,o),u=512+(o<<1),b=new W(m,u,o),S=new W(m,u+o);while(l<255&&i>0){var d=re(i+1),g=r>>3,p=(1<<d+1)-1,B=(e[g]|e[g+1]<<8|e[g+2]<<16)>>(r&7)&p,y=(1<<d)-1,v=p-i-1,E=B&y;if(E<v)r+=d,B=E;else if(r+=d+1,B>y)B-=v;if(h[++l]=--B,B==-1)i+=B,b[--f]=l;else i-=B;if(!B)do{var D=r>>3;a=(e[D]|e[D+1]<<8)>>(r&7)&3,r+=2,l+=a}while(a==3)}if(l>255||i)K(0);var C=0,U=(o>>1)+(o>>3)+3,X=o-1;for(var H=0;H<=l;++H){var M=h[H];if(M<1){x[H]=-M;continue}for(c=0;c<M;++c){b[C]=H;do C=C+U&X;while(C>=f)}}if(C)K(0);for(c=0;c<o;++c){var A=x[b[c]]++,L=S[c]=s-re(A);T[c]=(A<<L)-o}return[r+7>>3,{b:s,s:b,n:S,t:T}]},vt=function(e,t){var n=0,r=-1,s=new W(292),o=e[t],i=s.subarray(0,256),l=s.subarray(256,268),a=new de(s.buffer,268);if(o<128){var c=ue(e,t+1,6),f=c[0],m=c[1];t+=o;var h=f<<3,x=e[t];if(!x)K(0);var T=0,u=0,b=m.b,S=b,d=(++t<<3)-8+re(x);for(;;){if(d-=b,d<h)break;var g=d>>3;if(T+=(e[g]|e[g+1]<<8)>>(d&7)&(1<<b)-1,i[++r]=m.s[T],d-=S,d<h)break;g=d>>3,u+=(e[g]|e[g+1]<<8)>>(d&7)&(1<<S)-1,i[++r]=m.s[u],b=m.n[T],T=m.t[T],S=m.n[u],u=m.t[u]}if(++r>255)K(0)}else{r=o-127;for(;n<r;n+=2){var p=e[++t];i[n]=p>>4,i[n+1]=p&15}++t}var B=0;for(n=0;n<r;++n){var y=i[n];if(y>11)K(0);B+=y&&1<<y-1}var v=re(B)+1,E=1<<v,D=E-B;if(D&D-1)K(0);i[r++]=re(D)+1;for(n=0;n<r;++n){var y=i[n];++l[i[n]=y&&v+1-y]}var C=new W(E<<1),U=C.subarray(0,E),X=C.subarray(E);a[v]=0;for(n=v;n>0;--n){var H=a[n];ce(X,n,H,a[n-1]=H+l[n]*(1<<v-n))}if(a[0]!=E)K(0);for(n=0;n<r;++n){var M=i[n];if(M){var A=a[M];ce(U,n,A,a[M]=A+(1<<v-M))}}return[t,{n:X,b:v,s:U}]},Tt=ue(new W([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],Ct=ue(new W([33,20,196,24,99,140,33,132,16,66,8,33,132,16,66,8,33,68,68,68,68,68,68,68,68,36,9]),0,6)[1],Et=ue(new W([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],Ve=function(e,t){var n=e.length,r=new be(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Se=new W(new be([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),St=Ve(Se,0),Pe=new W(new be([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),Pt=Ve(Pe,3),le=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,l=-n.b;if(!o)K(0);var a=0,c=n.b,f=(r<<3)-8+re(o)-c,m=-1;for(;f>l&&m<s;){var h=f>>3,x=(e[h]|e[h+1]<<8|e[h+2]<<16)>>(f&7);a=(a<<c|x)&i,t[++m]=n.s[a],f-=c=n.n[a]}if(f!=l||m+1!=s)K(0)},Lt=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,l=o+i;le(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),le(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),le(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,l),n),le(e.subarray(r),t.subarray(l),n)},kt=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var l=o>>3|e[s+1]<<5|e[s+2]<<13,a=(s+=3)+l;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return ce(n,e[s],t.y,t.y+=l),n;return ce(new W(l),e[s])}if(a>e.length)return;if(i==0){if(t.b=a,n)return n.set(e.subarray(s,a),t.y),t.y+=l,n;return Ee(e,s,a)}if(i==2){var c=e[s],f=c&3,m=c>>2&3,h=c>>4,x=0,T=0;if(f<2)if(m&1)h|=e[++s]<<4|(m&2&&e[++s]<<12);else h=c>>3;else if(T=m,m<2)h|=(e[++s]&63)<<4,x=e[s]>>6|e[++s]<<2;else if(m==2)h|=e[++s]<<4|(e[++s]&3)<<12,x=e[s]>>2|e[++s]<<6;else h|=e[++s]<<4|(e[++s]&63)<<12,x=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var u=n?n.subarray(t.y,t.y+t.m):new W(t.m),b=u.length-h;if(f==0)u.set(e.subarray(s,s+=h),b);else if(f==1)ce(u,e[s++],b);else{var S=t.h;if(f==2){var d=vt(e,s);x+=s-(s=d[0]),t.h=S=d[1]}else if(!S)K(0);(T?Lt:le)(e.subarray(s,s+=x),u.subarray(b),S)}var g=e[s++];if(g){if(g==255)g=(e[s++]|e[s++]<<8)+32512;else if(g>127)g=g-128<<8|e[s++];var p=e[s++];if(p&3)K(0);var B=[Ct,Et,Tt];for(var y=2;y>-1;--y){var v=p>>(y<<1)+2&3;if(v==1){var E=new W([0,0,e[s++]]);B[y]={s:E.subarray(2,3),n:E.subarray(0,1),t:new de(E.buffer,0,1),b:0}}else if(v==2)r=ue(e,s,9-(y&1)),s=r[0],B[y]=r[1];else if(v==3){if(!t.t)K(0);B[y]=t.t[y]}}var D=t.t=B,C=D[0],U=D[1],X=D[2],H=e[a-1];if(!H)K(0);var M=(a<<3)-8+re(H)-X.b,A=M>>3,L=0,V=(e[A]|e[A+1]<<8)>>(M&7)&(1<<X.b)-1;A=(M-=U.b)>>3;var k=(e[A]|e[A+1]<<8)>>(M&7)&(1<<U.b)-1;A=(M-=C.b)>>3;var N=(e[A]|e[A+1]<<8)>>(M&7)&(1<<C.b)-1;for(++g;--g;){var P=X.s[V],w=X.n[V],O=C.s[N],F=C.n[N],R=U.s[k],z=U.n[k];A=(M-=R)>>3;var j=1<<R,I=j+((e[A]|e[A+1]<<8|e[A+2]<<16|e[A+3]<<24)>>>(M&7)&j-1);A=(M-=Pe[O])>>3;var G=Pt[O]+((e[A]|e[A+1]<<8|e[A+2]<<16)>>(M&7)&(1<<Pe[O])-1);A=(M-=Se[P])>>3;var _=St[P]+((e[A]|e[A+1]<<8|e[A+2]<<16)>>(M&7)&(1<<Se[P])-1);if(A=(M-=w)>>3,V=X.t[V]+((e[A]|e[A+1]<<8)>>(M&7)&(1<<w)-1),A=(M-=F)>>3,N=C.t[N]+((e[A]|e[A+1]<<8)>>(M&7)&(1<<F)-1),A=(M-=z)>>3,k=U.t[k]+((e[A]|e[A+1]<<8)>>(M&7)&(1<<z)-1),I>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=I-=3;else{var Y=I-(_!=0);if(Y){if(I=Y==3?t.o[0]-1:t.o[Y],Y>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=I}else I=t.o[0]}for(var y=0;y<_;++y)u[L+y]=u[b+y];L+=_,b+=_;var q=L-I;if(q<0){var J=-q,ee=t.e+q;if(J>G)J=G;for(var y=0;y<J;++y)u[L+y]=t.w[ee+y];L+=J,G-=J,q=0}for(var y=0;y<G;++y)u[L+y]=u[q+y];L+=G}if(L!=b)while(b<u.length)u[L++]=u[b++];else L=u.length;if(n)t.y+=L;else u=Ee(u,0,L)}else if(n){if(t.y+=h,b)for(var y=0;y<h;++y)u[y]=u[b+y]}else if(b)u=Ee(u,b);return t.b=a,u}K(2)},Bt=function(e,t){if(e.length==1)return e[0];var n=new W(t);for(var r=0,s=0;r<e.length;++r){var o=e[r];n.set(o,s),s+=o.length}return n};function ye(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=Mt(e,r||t);if(typeof i==\"object\"){if(r){if(t=null,i.w.length==i.u)n.push(t=i.w),o+=i.u}else n.push(t),i.e=0;for(;!i.l;){var l=kt(e,i,t);if(!l)K(5);if(t)i.e=i.y;else n.push(l),o+=l.length,xt(i.w,0,l.length),i.w.set(l,i.w.length-l.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return Bt(n,o)}async function It(e){let t=e instanceof Uint8Array?e:new Uint8Array(e),n=(r)=>r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength);if(t[0]===40&&t[1]===181&&t[2]===47&&t[3]===253)return n(ye(t));if(t[0]===31&&t[1]===139)return new Response(new Blob([t]).stream().pipeThrough(new DecompressionStream(\"gzip\"))).arrayBuffer();return n(t)}async function He(e){return new TextDecoder().decode(await It(e))}var Ge=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split(\"/\").pop()||\"main.ldr\").replace(/\\.(zst|gz)$/i,\"\")||\"main.ldr\";function xe(e){let t=new DataView(e).getUint32(0,!0),n=JSON.parse(new TextDecoder().decode(new Uint8Array(e,4,t))),r=4+t;return{header:n,arr:(o)=>o&&(o[2]===\"f32\"?new Float32Array(e,r+o[0],o[1]):o[2]===\"u16\"?new Uint16Array(e,r+o[0],o[1]):o[2]===\"u8\"?new Uint8Array(e,r+o[0],o[1]):new Uint32Array(e,r+o[0],o[1])),bytes:e.byteLength,buffer:e}}var Z=(e)=>e.trim().toLowerCase().replace(/\\\\/g,\"/\").replace(/\\/+/g,\"/\");function Le(e){if(/^0x/i.test(e))return parseInt(e,16);return+e}var _e=/^~?\\s*moved\\s+to\\s+(.+)$/i,Ft=new Set([\"FILE\",\"NOFILE\",\"!DATA\",\"!:\",\"STEP\",\"BFC\",\"ROTSTEP\",\"BUFEXCHG\",\"!TEXMAP\"]),Qe=new Set([\"part\",\"subpart\",\"primitive\",\"8_primitive\",\"48_primitive\",\"shortcut\",\"helper\"]),Rt=new Set([\"model\",\"submodel\",\"configuration\"]),Dt=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function We(e){let t=Dt.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,\"\");return Qe.has(n)||Rt.has(n)?n:void 0}function Ut(e){let t=[],n=0;while(n<e.length){while(e[n]===\" \"||e[n]===\"\\t\")n++;if(n>=e.length)break;if(e[n]==='\"'){let r=\"\";n++;while(n<e.length&&e[n]!=='\"'){if(e[n]===\"\\\\\"&&n+1<e.length)n++;r+=e[n++]}n++,t.push(r)}else{let r=n;while(r<e.length&&e[r]!==\" \"&&e[r]!==\"\\t\")r++;t.push(e.slice(n,r)),n=r}}return t}function zt(e,t=!1){let n=/^\\s*(\\S+)\\s+(.*)$/.exec(e);if(!n)return null;let r=n[1].toUpperCase(),s=r===\"PLANAR\"?9:r===\"CYLINDRICAL\"?10:r===\"SPHERICAL\"?11:0;if(!s)return null;let o=n[2].trim().split(/\\s+/);if(o.length<s+1)return null;let i=o.slice(0,s).map(Number);if(!i.every(Number.isFinite))return null;let l=n[2].trim();for(let m=0;m<s;m++)l=l.replace(/^\\S+\\s*/,\"\");let a=Ut(l);if(!a.length)return null;let c={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:a[0]};if(s>=10)c.a=i[9];if(s===11)c.b=i[10];let f=a.findIndex((m,h)=>h>0&&m.toUpperCase()===\"GLOSSMAP\");if(f>0&&a[f+1])c.glossmap=a[f+1];if(t)c.next=!0;return c}var Ot=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,\"\"),n=t+\"=\".repeat((4-t.length%4)%4),r=atob(n),s=new Uint8Array(r.length);for(let o=0;o<r.length;o++)s[o]=r.charCodeAt(o);return s};function Nt(e){let t=e.length,n=1,r=(c)=>c===32||c===9,s=()=>{while(n<t&&r(e.charCodeAt(n)))n++;let c=n;while(n<t&&!r(e.charCodeAt(n)))n++;return c<n?e.slice(c,n):null},o=s();if(o===null)return null;let i=Array(12);for(let c=0;c<12;c++){let f=s();if(f===null)return null;i[c]=+f}while(n<t&&r(e.charCodeAt(n)))n++;if(n>=t)return null;let l=e.slice(n),a=/[ \\t]{2,}|\\t/.test(l)?l.split(/\\s+/).join(\" \"):l;return{t:1,color:Le(o),m:i,file:Z(a)}}function Ke(e){let t=+e[0];if(!(t>=1&&t<=5)||e.length<2)return null;let n=Le(e[1]),r=e.slice(2).map(Number);if(t===1)return{t:1,color:n,m:r.slice(0,12),file:Z(e.slice(14).join(\" \"))};if(t===2)return{t:2,color:n,p:r.slice(0,6)};if(t===3)return{t:3,color:n,p:r.slice(0,9)};if(t===4)return{t:4,color:n,p:r.slice(0,12)};return{t:5,color:n,p:r.slice(0,12)}}function et(e,t=\"main.ldr\",n={}){let r=!!n.geometryText,s=new Map,o=null,i=\"\",l,a=null,c=[],f=null,m=()=>{if(!a)return;let d=Ot(a.chunks.join(\"\")),g=d[0]===137&&d[1]===80&&d[2]===78&&d[3]===71;(l??=new Map).set(Z(a.name),{name:a.name,bytes:d,...g?{mime:\"image/png\"}:{}}),a=null},h=!0,x=(d)=>{if(m(),o={name:Z(d),cmds:[]},s.set(o.name,o),!i)i=o.name;c=[],f=null,h=!0},T=!1,u=!1,b=()=>{if(u)return;u=!0,s.clear(),o=null,i=\"\"},S=(d,g)=>{if(f){d.tex=f,f=null;return}let p=c[c.length-1];if(!p)return;if(p.fallback){if(!g)d.fallback=!0}else d.tex=p.map};for(let d of e.split(`\n`)){let g=d.trim();if(!g)continue;if(r&&g.charCodeAt(0)>=50&&g.charCodeAt(0)<=53&&(g.charCodeAt(1)===32||g.charCodeAt(1)===9)){if(a||T)continue;if(!o)x(t);let v=g.slice(2).trimStart(),E=v.search(/\\s/),D={t:g.charCodeAt(0)-48,color:Le(E<0?v:v.slice(0,E)),p:[],src:g};S(D,!1),o.cmds.push(D),h=!1;continue}if(g.charCodeAt(0)===48&&(g.charCodeAt(1)===32||g.charCodeAt(1)===9)){let v=2;while(g.charCodeAt(v)===32||g.charCodeAt(v)===9)v++;let E=v;while(E<g.length&&g.charCodeAt(E)!==32&&g.charCodeAt(E)!==9)E++;let D=g.slice(v,E);if(!Ft.has(D)){if(T||a)continue;if(!o)x(t);let C=g.slice(v),U={t:0,text:C};if(D.charCodeAt(0)===33)U.meta=D;if(f=null,h&&!o.org){let H=We(C);if(H)o.org=H}let X=C.match(_e);if(X&&!o.movedTo){let H=X[1].trim().replace(/\\\\/g,\"/\");if(!/\\.(dat|ldr|mpd)$/i.test(H))H+=\".dat\";o.movedTo=Z(H)}o.cmds.push(U);continue}}if(g.charCodeAt(0)===49&&(g.charCodeAt(1)===32||g.charCodeAt(1)===9)&&!a&&!T){let v=Nt(g);if(v){if(!o)x(t);S(v,!1),o.cmds.push(v),h=!1;continue}}let p=g.split(/\\s+/);if(+p[0]===0){let v=g.slice(1).trim();if(p[1]===\"FILE\"){b(),T=!1,x(v.slice(5));continue}if(p[1]===\"NOFILE\"){m(),o=null,T=!0;continue}if(p[1]===\"!DATA\"){b(),m(),o=null,T=!1,a={name:v.slice(5).trim(),chunks:[]};continue}if(T)continue;if(a){if(p[1]===\"!:\")a.chunks.push(p.slice(2).join(\"\"));continue}if(!o)x(t);let E={t:0,text:v};if(p[1]===\"STEP\")E.step=!0,c=[],f=null;else if(p[1]===\"BFC\")E.bfc=p.slice(2).join(\" \");else if(p[1]===\"ROTSTEP\")if(E.meta=\"ROTSTEP\",E.step=!0,c=[],f=null,(p[2]??\"\").toUpperCase()===\"END\")E.rotstep={x:0,y:0,z:0,mode:\"END\"};else{let C=(p[5]??\"REL\").toUpperCase();E.rotstep={x:+p[2]||0,y:+p[3]||0,z:+p[4]||0,mode:[\"REL\",\"ABS\",\"ADD\"].includes(C)?C:\"REL\"}}else if(p[1]===\"BUFEXCHG\"){E.meta=\"BUFEXCHG\";let C=(p[2]??\"\").toUpperCase();E.bufexchg={op:C===\"RETRIEVE\"?\"RETRIEVE\":\"STORE\",buf:p[3]??\"A\"}}else if(p[1]?.startsWith(\"!\"))E.meta=p[1];if(h&&!o.org){let C=We(v);if(C)o.org=C}if(p[1]===\"!TEXMAP\"){let C=(p[2]??\"\").toUpperCase();if(f=null,C===\"START\"||C===\"NEXT\"){let U=zt(v.replace(/^!TEXMAP\\s+\\S+/i,\"\"),C===\"NEXT\");if(E.texmap={op:C,...U?{map:U}:{}},U)if((o.texmaps??=[]).push(U),C===\"START\")c.push({map:U,fallback:!1});else f=U}else if(C===\"FALLBACK\"){E.texmap={op:C};let U=c[c.length-1];if(U)U.fallback=!0}else if(C===\"END\")E.texmap={op:C},c.pop()}else if(p[1]===\"!:\"){f=null;let C=Ke(p.slice(2));if(C)S(C,!0),E.geom=C}else f=null;let D=v.match(_e);if(D&&!o.movedTo){let C=D[1].trim().replace(/\\\\/g,\"/\");if(!/\\.(dat|ldr|mpd)$/i.test(C))C+=\".dat\";o.movedTo=Z(C)}o.cmds.push(E);continue}if(a||T)continue;if(!o)x(t);let y=Ke(p);if(!y)continue;S(y,!1),o.cmds.push(y),h=!1}return m(),l?{main:i,files:s,data:l}:{main:i,files:s}}var cn=Math.PI/180;function tt(e,t){let n=(r)=>[t[3]*r[0]+t[4]*r[1]+t[5]*r[2]+t[0],t[6]*r[0]+t[7]*r[1]+t[8]*r[2]+t[1],t[9]*r[0]+t[10]*r[1]+t[11]*r[2]+t[2]];return{...e,p1:n(e.p1),p2:n(e.p2),p3:n(e.p3)}}function nt(e,t){let[n,r,s,o,i,l,a,c,f,m,h,x]=e,[T,u,b,S,d,g,p,B,y,v,E,D]=t;return[o*T+i*u+l*b+n,a*T+c*u+f*b+r,m*T+h*u+x*b+s,o*S+i*p+l*v,o*d+i*B+l*E,o*g+i*y+l*D,a*S+c*p+f*v,a*d+c*B+f*E,a*g+c*y+f*D,m*S+h*p+x*v,m*d+h*B+x*E,m*g+h*y+x*D]}var ke=[0,0,0,1,0,0,0,1,0,0,0,1];var Xe=new WeakMap,$t=/^(s|8|48)\\//;function Be(e,t){let n=e.files.get(Z(t));if(!n)return\"part\";let r=Xe.get(n);if(r)return r;if(n.org)r=Qe.has(n.org)?\"part\":\"model\";else if(n.name===e.main)r=\"model\";else r=n.cmds.some((s)=>s.t>=2||s.t===0&&!!s.geom||s.t===1&&$t.test(s.file))?\"part\":\"model\";return Xe.set(n,r),r}var Ze=new WeakMap;function rt(e){let t=Ze.get(e);if(t)return t;t=[];let n=0;for(let r of e.cmds){if(r.t===0&&r.step){n++;continue}if((r.t>=2||r.t===0&&r.geom&&r.geom.t>=2)&&t[t.length-1]!==n)t.push(n)}return Ze.set(e,t),t}var Ye=(e)=>e>16777215?\"0x\"+e.toString(16).toUpperCase():String(e),jt=(e)=>e.t===0?\"0 \"+e.text:e.t===1?`1 ${Ye(e.color)} ${e.m.join(\" \")} ${e.file}`:e.src?e.src:`${e.t} ${Ye(e.color)} ${e.p.join(\" \")}`,Ie=(e,t)=>`${Z(e)}#${t}`;function Vt(e,t){let n=[],r=0,s=(o)=>!!o&&o.t===0&&o.texmap?.op===\"NEXT\";for(let o of e.cmds){if(o.t===0){if(o.step){r++;continue}if(o.bfc!==void 0){n.push(o);continue}if(r!==t)continue;if(o.texmap)n.push(o);else if(o.geom){if(o.geom.t>=2)n.push(o);else if(s(n[n.length-1]))n.pop()}continue}if(r!==t)continue;if(o.t===1){if(s(n[n.length-1]))n.pop();continue}n.push(o)}return{name:Ie(e.name,t),cmds:n}}function st(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Vt(e,t).cmds.map(jt)].join(`\n`)+`\n`}function Ht(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,\"0\")}function ot(e){let[t,n,r,s,o,i,l,a,c,f,m,h]=e,x=a*h-c*m,T=-(l*h-c*f),u=l*m-a*f,b=s*x+o*T+i*u;if(!Number.isFinite(b)||Math.abs(b)<0.000000000001)return null;let S=1/b,d=[x*S,-(o*h-i*m)*S,(o*c-i*a)*S,T*S,(s*h-i*f)*S,-(s*c-i*l)*S,u*S,-(s*m-o*f)*S,(s*a-o*l)*S];return[-(d[0]*t+d[1]*n+d[2]*r),-(d[3]*t+d[4]*n+d[5]*r),-(d[6]*t+d[7]*n+d[8]*r),...d]}var Gt=(e)=>String(+e.toFixed(6)||0),Je=(e)=>'\"'+e.replace(/\\\\/g,\"\\\\\\\\\").replace(/\"/g,\"\\\\\\\"\")+'\"';function it(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!==\"PLANAR\"?[t.a??360]:[],...t.method===\"SPHERICAL\"?[t.b??180]:[]].map(Gt).join(\" \"),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${Je(t.texture)}${t.glossmap?\" GLOSSMAP \"+Je(t.glossmap):\"\"}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${Z(e)}\n0 !TEXMAP END\n`;return{name:`${Z(e)}#tex-${Ht(r)}`,source:r}}var _t=(e,t)=>{let n=[,,,,,,,,,];for(let r=0;r<3;r++)for(let s=0;s<3;s++)n[r*3+s]=e[r*3]*t[s]+e[r*3+1]*t[3+s]+e[r*3+2]*t[6+s];return n};function Wt(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),l=Math.cos(t*r),a=Math.sin(n*r),c=Math.cos(n*r);return[l*c,-l*a,i,o*a+s*i*c,o*c-s*i*a,-s*l,s*a-o*i*c,s*c+o*i*a,o*l]}var qe=new WeakMap;function at(e){let t=qe.get(e);if(t)return t;let n=[],r=null;for(let s of e.cmds){if(s.t!==0||!s.step)continue;let o=s.rotstep;if(o)if(o.mode===\"END\")r=null;else{let i=Wt(o.x,o.y,o.z);r=o.mode===\"ABS\"?{abs:!0,m:i,rotstep:o}:o.mode===\"ADD\"&&r?{abs:r.abs,m:_t(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),qe.set(e,n),n}var lt=999999,ct=(e)=>e.map((t)=>String(t).padStart(6,\"0\")).join(\".\")+\"~\";function Kt(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,l=new Map,a=0,c=(m,h)=>{let x=m.name+\"#\"+h,T=l.get(x);if(!T){let u;T=Object.assign(()=>u??=st(m,h),{file:m,step:h}),l.set(x,T)}return T},f=(m,h,x,T,u,b,S,d,g=null,p=[],B=[])=>{let y=m.files.get(h);if(!y||S>r)return;let v=0,E=S>0?++a:0,D=i&&E?[...p,E]:p,C=i&&E?[...B,x]:B,U=i&&!g?new Map:null,X=-1,H=0,M=(P,w,O,F,R,z)=>{if(X!==v)X=v,H=0;let j=U?.get(v+\"|\"+w);if(j)return j.n++,f(P,P===m?w:P.main,O,F,u+\"/\"+w,[...R,lt],S+1,z,[...R,lt],D,C);let I=[...R,H++],G=n.length;f(P,P===m?w:P.main,O,F,u+\"/\"+w,I,S+1,z,g,D,C),U?.set(v+\"|\"+w,{n:1,from:G,to:n.length})},A=at(y),L=s?rt(y):[],V=0,k=(P,w,O,F,R,z,j)=>{if(g)F=g;let I={part:P,color:w,m:O,step:F[0],steps:F,localStep:R,path:u};if(E){if(I.sub=E,i)I.subPath=D,I.subMats=C}if(z)I.embedded=!0;if(j){let _=it(P,j);I.texPart=_.name,I.texSource=_.source}let G=A[R];if(G)I.view=G;return n.push(I),I},N=(P)=>{while(V<L.length&&L[V]<=P){let w=L[V++];k(Ie(y.name,w),T,x,[...b,w],w,!1,null).source=c(y,w)}};for(let P of y.cmds){if(P.t===0&&P.step){v++;continue}let w=P;if(w.t>=2||w.t===0&&w.geom&&w.geom.t>=2){N(v);continue}if(w.t===0)if(o&&w.geom?.t===1)w=w.geom;else continue;if(w.t!==1)continue;if(o&&w.fallback)continue;let O=w.color===16?T:w.color,F=nt(x,w.m),R=[...b,v],z=o?w.tex??d:null,j=z?ot(w.m):null,I=z&&j?tt(z,j):null;if(m.files.has(w.file)){if(Be(m,w.file)===\"model\"){M(m,w.file,F,O,R,I);continue}k(w.file,O,F,R,v,!0,I);continue}let G=t.resolveModel?.(w.file);if(G){M(G,w.file,F,O,R,I);continue}k(w.file,O,F,R,v,!1,I)}if(N(1/0),U){for(let P of U.values())if(P.n>1)for(let w=P.from;w<P.to;w++)n[w].mult??=P.n}};if(Be(e,e.main)===\"part\"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...ke],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return f(e,e.main,ke,16,e.main,[],0,null),n}function ut(e,t=\"main.ldr\",n){return Kt(et(e,t,{geometryText:!0}),n)}function Xt(e,t){let n=new Map,r=null,s=!1;for(let o of e.split(/\\r?\\n/)){let i=/^\\s*0\\s+FILE\\s+(.+)$/i.exec(o);if(i){if(!s)n.clear();s=!0,r=[],n.set(Z(i[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(o)){if(!s)n.clear();s=!0,r=null;continue}if(!r){if(s)continue;r=[],n.set(Z(t),r)}let l=o.trim().replace(/\\s+/g,\" \");if(l)r.push(l)}return n}var Zt=(e)=>{if(!e.startsWith(\"1 \"))return null;let t=e.split(\" \");return t.length>=15?Z(t.slice(14).join(\" \")):null};function Yt(e){let t=2166136261,n=1523705862;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);t=Math.imul(t^s,16777619),n=Math.imul(n^s,16777629)^n>>>15}return(t>>>0).toString(16).padStart(8,\"0\")+(n>>>0).toString(16).padStart(8,\"0\")}function ft(e,t,n=\"main.ldr\"){let r=Xt(e,n),s=new Map;for(let o of t){let i=Z(o);if(!r.has(i)||s.has(i))continue;let l=new Set([i]),a=[i];while(a.length)for(let f of r.get(a.pop())){let m=Zt(f);if(m&&r.has(m)&&!l.has(m))l.add(m),a.push(m)}let c=[i,...[...l].filter((f)=>f!==i).sort()].map((f)=>\"0 FILE \"+(f===i?\"\":f)+`\n`+r.get(f).join(`\n`)).join(`\n`);s.set(i,`emb/${Yt(c)}.dat`)}return s}var pt=(e,t=0)=>Math.abs(e[t+7]-1)<0.001&&Math.abs(e[t+4])<0.001&&Math.abs(e[t+10])<0.001,mt=new WeakMap;function Fe(e,t){let n=mt.get(e);if(!n)mt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),l=[],a=[];s.studs.forEach((h,x)=>{l.push(h[0]),a.push(h[1]);for(let T=0;T<12;T++)i[x*12+T]=h[2+T]});let c=null,f=0,m=0;if(s.mask){f=s.mask[0],m=s.mask[1];let h=s.mask[2];c=new Uint8Array(h.length);for(let x=0;x<h.length;x++)c[x]=h.charCodeAt(x)===49?1:0}return n.set(t,r={nStuds:o,studM:i,kind:l,color:a,mask:c,nx:f,nz:m}),r}var ie=1073741824;class Re{a;b;c;vals;used;mask;size=0;constructor(e=1024){let t=1024;while(t<e*2)t*=2;this.a=new Int32Array(t),this.b=new Int32Array(t),this.c=new Int32Array(t),this.vals=new Int32Array(t),this.used=new Uint8Array(t),this.mask=t-1}slot(e,t,n){let r=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return r^=r>>>15,r=Math.imul(r,739982445),r^=r>>>12,r&this.mask}get(e,t,n){let r=this.slot(e,t,n),s=this.used,o=this.a,i=this.b,l=this.c;for(;;){if(!s[r])return-1;if(o[r]===e&&i[r]===t&&l[r]===n)return this.vals[r];r=r+1&this.mask}}put(e,t,n,r){if((this.size+1)*2>this.used.length)this.grow();let s=this.slot(e,t,n),o=this.used,i=this.a,l=this.b,a=this.c;for(;;){if(!o[s])return o[s]=1,i[s]=e,l[s]=t,a[s]=n,this.vals[s]=r,this.size++,-1;if(i[s]===e&&l[s]===t&&a[s]===n){let c=this.vals[s];return this.vals[s]=r,c}s=s+1&this.mask}}grow(){let{a:e,b:t,c:n,vals:r,used:s}=this,o=s.length*2;this.a=new Int32Array(o),this.b=new Int32Array(o),this.c=new Int32Array(o),this.vals=new Int32Array(o),this.used=new Uint8Array(o),this.mask=o-1,this.size=0;for(let i=0;i<s.length;i++)if(s[i])this.put(e[i],t[i],n[i],r[i])}}var we=(e,t,n)=>e>-ie&&e<ie&&t>-ie&&t<ie&&n>-ie&&n<ie,fe=2147483647;function Jt(e,t,n){let s=[],o=[],i=[],l=[],a=[],c=[],f=[],m=[],h=new Re(e.length*2),x=[],T=[];for(let M=0;M<e.length;M++){let A=e[M],L=A.m,V=t.parts[A.part];if(!V||!V.mask||!pt(L))continue;let k=V.bbox,N=1/0,P=-1/0,w=1/0,O=-1/0;for(let z=0;z<2;z++)for(let j=0;j<2;j++){let I=z?k[3]:k[0],G=j?k[5]:k[2],_=L[0]+L[3]*I+L[5]*G,Y=L[2]+L[9]*I+L[11]*G;if(_<N)N=_;if(_>P)P=_;if(Y<w)w=Y;if(Y>O)O=Y}let F=a.length;s.push(N),o.push(P),i.push(w),l.push(O),a.push(M),c.push(Fe(t,A.part)),f.push(k[0]),m.push(k[2]);let R=Math.round((L[1]+k[4])*2);for(let z=Math.floor(N/40);z<=Math.floor(P/40);z++)for(let j=Math.floor(w/40);j<=Math.floor(O/40);j++){if(!we(R,z,j))continue;let I=T.length;T.push(F),x.push(h.put(R,z,j,I))}}let u=[0,5,-5,5,-5],b=[0,5,5,-5,-5],S=NaN,d=NaN,g=NaN,p=-1,B=(M,A,L,V)=>{let k=Math.round(A*2),N=Math.floor(M/40),P=Math.floor(L/40);if(!we(k,N,P))return fe;let w=fe;if(k!==S||N!==d||P!==g)S=k,d=N,g=P,p=h.get(k,N,P);for(let O=p;O>=0;O=x[O]){let F=T[O];if(a[F]===V||!(M-6>=s[F]-0.5&&M+6<=o[F]+0.5&&L-6>=i[F]-0.5&&L+6<=l[F]+0.5))continue;let R=e[a[F]].m,z=c[F],j=f[F],I=m[F],G=M-R[0],_=A-R[1],Y=L-R[2],q=R[3]*G+R[6]*_+R[9]*Y,J=R[5]*G+R[8]*_+R[11]*Y,{nx:ee,nz:se,mask:ae}=z,oe=!0;for(let Q=0;Q<5;Q++){let te=Math.floor((q+u[Q]-j)/20),ne=Math.floor((J+b[Q]-I)/20);if(te<0||ne<0||te>=ee||ne>=se||ae[te*se+ne]!==1){oe=!1;break}}if(oe){if(!n)return 0;let Q=n[a[F]];if(Q<w)w=Q}}return w},y=0;for(let M of e){let A=Fe(t,M.part);if(A)y+=A.nStuds}let v=new Uint8Array(y),E=new Uint8Array(y),D=new Re(y),C=0,U=n?new Int32Array(y).fill(fe):void 0;for(let M=0,A=0;M<e.length;M++){let L=e[M],V=Fe(t,L.part);if(!V)continue;let k=L.m,N=V.studM,P=k[0],w=k[1],O=k[2],F=k[3],R=k[4],z=k[5],j=k[6],I=k[7],G=k[8],_=k[9],Y=k[10],q=k[11];for(let J=0;J<V.nStuds;J++,A++){let ee=J*12,se=N[ee+4],ae=N[ee+7],oe=N[ee+10];if(!(Math.abs(j*se+I*ae+G*oe-1)<0.001&&Math.abs(F*se+R*ae+z*oe)<0.001&&Math.abs(_*se+Y*ae+q*oe)<0.001))continue;E[A]=1;let Q=N[ee],te=N[ee+1],ne=N[ee+2],De=P+F*Q+R*te+z*ne,Ue=w+j*Q+I*te+G*ne,ze=O+_*Q+Y*te+q*ne,Oe=B(De,Ue,ze,M);if(Oe!==fe){if(v[A]=1,C++,U)U[A]=Oe}let me=Math.round(De),he=Math.round(Ue),ge=Math.round(ze);if(!we(me,he,ge))continue;if(!n){D.put(me,he,ge,1);continue}let Ne=n[M],$e=D.get(me,he,ge);if($e<0||Ne<$e)D.put(me,he,ge,Ne)}}let X=new Uint8Array(e.length),H=n?new Int32Array(e.length).fill(fe):void 0;for(let M=0;M<e.length;M++){let A=e[M],L=t.parts[A.part];if(!L||!L.under||!pt(A.m))continue;let V=L.bbox,k=Math.round((V[3]-V[0])/20),N=Math.round((V[5]-V[2])/20);if(!k||!N||k*N>4096)continue;let P=A.m,w=!0,O=0;for(let F=0;F<k&&w;F++)for(let R=0;R<N;R++){let z=V[0]+10+20*F,j=V[2]+10+20*R,I=P[0]+P[3]*z+P[5]*j,G=P[2]+P[9]*z+P[11]*j,_=Math.round(I),Y=Math.round(P[1]+V[4]),q=Math.round(G),J=we(_,Y,q)?D.get(_,Y,q):-1;if(J<0){w=!1;break}if(J>O)O=J}if(w){if(X[M]=1,H)H[M]=O}}return{nStuds:y,studHidden:v,studUp:E,underHidden:X,studsHidden:C,studHideStep:U,underHideStep:H}}function qt(e,t,n){let r=(a)=>n&&a.texPart&&t.parts[a.texPart]?a.texPart:a.part,s=e.map((a)=>({part:r(a),color:String(a.color),m:a.m,steps:a.steps})),o=s.map((a)=>ct(a.steps)),i=[...new Set(o)].sort(),l=new Map(i.map((a,c)=>[a,c]));return{all:s,stepOf:o.map((a)=>l.get(a)),nSteps:i.length}}function Ae(e,t,n=!0){let r=qt(e,t,n);return Jt(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Ce=\"https://ldr-demo.vercel.app/cdn/v1/\",ve=new Map,Me=new Map;function gt(e=Ce,t=fetch){let n=ve.get(e);if(!n)n=t(e+\"parts.json\").then((r)=>{if(!r.ok)throw Error(`ldr: parts CDN index ${r.status} (${e}parts.json)`);return r.json()}),n.catch(()=>ve.delete(e)),ve.set(e,n);return n}var Qt=(e)=>Array.isArray(e)&&e.length===3&&typeof e[0]===\"number\"&&typeof e[1]===\"number\"&&(e[2]===\"f32\"||e[2]===\"u16\"||e[2]===\"u8\"||e[2]===\"u32\"),Te=(e,t)=>Qt(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>Te(n,t)):e&&typeof e===\"object\"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Te(r,t)])):e;function en(e,t={}){let n=[],r=0,s={},o={};for(let h of e){let x=h.buffer;if(!x)throw Error(\"ldr: mergePacks needs packs from decodePack/loadPack\");let T=new DataView(x).getUint32(0,!0),u=new Uint8Array(x,4+T),b=r;n.push(u),r+=u.byteLength;let S=(4-r%4)%4;if(S)n.push(new Uint8Array(S)),r+=S;for(let[d,g]of Object.entries(h.header.parts??{}))if(!(d in s))s[d]=Te(g,b);for(let[d,g]of Object.entries(h.header.studKinds??{}))if(!(d in o))o[d]=Te(g,b)}let i=e[0]?.header??{version:1,weld:!0},l=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),a=(4-(4+l.length)%4)%4,c=4+l.length+a,f=new Uint8Array(c+r);new DataView(f.buffer).setUint32(0,l.length+a,!0),f.set(l,4),f.fill(32,4+l.length,c);let m=c;for(let h of n)f.set(h,m),m+=h.byteLength;return xe(f.buffer)}async function tn(e,t={}){e=[...e];try{return await ht(e,t)}catch(n){let r=t.cdn??Ce,s=t.fetch??fetch;ve.delete(r);let o=(i,l)=>s(i,{...l,cache:\"reload\"});try{return await ht(e,{...t,fetch:o})}catch{throw n}}}async function ht(e,t){let n=t.cdn??Ce,r=t.fetch??fetch,s=t.gap??16384,o=await gt(n,r),i=[...new Set([...e].map(Z))],l=[],a=[];for(let u of i){if(Me.has(n+u))continue;let b=o.parts[u];if(b)a.push({name:u,off:b[0],len:b[1],file:b[2]??0});else l.push(u)}a.sort((u,b)=>u.file-b.file||u.off-b.off);let c=[];for(let u of a){let b=c[c.length-1];if(b&&b.file===u.file&&u.off-b.end<=s)b.end=Math.max(b.end,u.off+u.len),b.items.push(u);else c.push({file:u.file,start:u.off,end:u.off+u.len,items:[u]})}let f=0,m=0,h=async()=>{while(m<c.length){let u=c[m++],b=await r(new URL(o.archives[u.file],n).href,{headers:{Range:`bytes=${u.start}-${u.end-1}`}});if(!b.ok)throw Error(`ldr: parts CDN ${b.status}`);let S=new Uint8Array(await b.arrayBuffer());if(b.status===200)S=S.subarray(u.start,u.end);f+=S.byteLength;for(let d of u.items){let g=ye(S.subarray(d.off-u.start,d.off-u.start+d.len)),p=g.buffer.slice(g.byteOffset,g.byteOffset+g.byteLength);Me.set(n+d.name,xe(p))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,c.length)},h));let x=i.filter((u)=>Me.has(n+u)).map((u)=>Me.get(n+u));return{pack:x.length?en(x,{colors:o.colors}):xe(nn(o.colors)),missing:l,requests:c.length,bytes:f}}function nn(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},colors:e})),n=(4-(4+t.length)%4)%4,r=new Uint8Array(4+t.length+n).fill(32);return new DataView(r.buffer).setUint32(0,t.length+n,!0),r.set(t,4),r.buffer}function rn(e,t){let n=t.header.parts;if(!n)return 0;let r=0;for(let s of e){let o=n[s.part]?.body?.tris;if(o)r+=o}return r}function sn(e,t,n){let r=0,s=0,o=!1,i=new Set;for(let l of e){let a=l.embedded?t.get(l.part):Z(l.part),c=a?n.parts[a]:void 0;if(!c)continue;if(c[3]!=null)o=!0,r+=c[3];if(!i.has(a))i.add(a),s+=c[1]}return{bodyTris:r,packBytes:s,known:o}}class pe extends Error{code=\"ldr-budget\";bodyTris;packBytes;maxBodyTris;maxPackBytes;constructor(e){let t=[e.maxBodyTris!=null&&e.bodyTris>e.maxBodyTris?`${e.bodyTris} triangles (limit ${e.maxBodyTris})`:\"\",e.maxPackBytes!=null&&e.packBytes>e.maxPackBytes?`${(e.packBytes/1e6).toFixed(1)} MB parts pack (limit ${(e.maxPackBytes/1e6).toFixed(0)} MB)`:\"\"].filter(Boolean).join(\", \");super(`ldr: model exceeds device budget: ${t}`);this.name=\"BudgetError\",this.bodyTris=e.bodyTris,this.packBytes=e.packBytes,this.maxBodyTris=e.maxBodyTris,this.maxPackBytes=e.maxPackBytes}}async function dt(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=gt(t.cdn??Ce,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(p)=>{if(!p.ok)throw Error(`ldr: ${p.status} fetching ${e}`);return He(await p.arrayBuffer())}),i=performance.now(),l=t.name??(t.text?\"main.ldr\":Ge(e)),a=ut(o,l,{looseGeometry:!1,callouts:t.callouts}),c=performance.now();t.onParsed?.(a),await s;let f=ft(o,new Set(a.filter((p)=>p.embedded).map((p)=>p.part)),l),m=(p,B)=>t.maxBodyTris!=null&&p>t.maxBodyTris||t.maxPackBytes!=null&&B>t.maxPackBytes;if(t.maxBodyTris!=null||t.maxPackBytes!=null){let p=sn(a,f,await s);if(m(p.known?p.bodyTris:0,p.packBytes))throw new pe({bodyTris:p.bodyTris,packBytes:p.packBytes,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes})}let{pack:h,missing:x,requests:T,bytes:u}=await tn([...a.filter((p)=>!p.embedded).map((p)=>p.part),...f.values()],t),b=new Map([...f].map(([p,B])=>[B,p])),S=x.map((p)=>b.get(p)??p);for(let[p,B]of f){let y=h.header.parts[B];if(y)h.header.parts[p]=y}let d=performance.now();if(t.maxBodyTris!=null||t.maxPackBytes!=null){let p=h.buffer?.byteLength??h.bytes??0,B=rn(a,h);if(m(B,p))throw new pe({bodyTris:B,packBytes:p,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes})}let g=t.cull?Ae(a,h.header,t.textures!==!1):void 0;return{insts:a,pack:h,missing:S,requests:T,bytes:u,cull:g,timings:{fetchModel:i-n,parse:c-i,parts:d-c,...g?{cull:performance.now()-d}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await dt(n,{...r,cull:!1,onParsed:(f)=>self.postMessage({id:t,insts:f})}),o=s.pack.buffer;if(self.postMessage({id:t,buffer:o,missing:s.missing,requests:s.requests,bytes:s.bytes,timings:s.timings},[o]),!r.cull)return;let i=performance.now(),l=Ae(s.insts,s.pack.header,r.textures!==!1),a=performance.now()-i,c=[];for(let f of[l.studHidden,l.studUp,l.underHidden,l.studHideStep,l.underHideStep])if(f)c.push(f.buffer);self.postMessage({id:t,cull:l,ms:a},c)}catch(s){if(s instanceof pe||s?.code===\"ldr-budget\")self.postMessage({id:t,phase:\"error\",error:String(s?.message??s),budget:{bodyTris:s.bodyTris,packBytes:s.packBytes,maxBodyTris:s.maxBodyTris,maxPackBytes:s.maxPackBytes}});else self.postMessage({id:t,phase:\"error\",error:String(s?.message??s)})}};\n";
|
|
1
|
+
declare const _default: "var bt=ArrayBuffer,W=Uint8Array,de=Uint16Array,yt=Int16Array;var be=Int32Array,Ee=function(e,t,n){if(W.prototype.slice)return W.prototype.slice.call(e,t,n);if(t==null||t<0)t=0;if(n==null||n>e.length)n=e.length;var r=new W(n-t);return r.set(e.subarray(t,n)),r},ce=function(e,t,n,r){if(W.prototype.fill)return W.prototype.fill.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;for(;n<r;++n)e[n]=t;return e},xt=function(e,t,n,r){if(W.prototype.copyWithin)return W.prototype.copyWithin.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;while(n<r)e[t++]=e[n++]};var wt=[\"invalid zstd data\",\"window size too large (>2046MB)\",\"invalid block type\",\"FSE accuracy too high\",\"match distance too far back\",\"unexpected EOF\"],K=function(e,t,n){var r=Error(t||wt[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,K);if(!n)throw r;return r},je=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},At=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},Mt=function(e,t){var n=e[0]|e[1]<<8|e[2]<<16;if(n==3126568&&e[3]==253){var r=e[4],s=r>>5&1,o=r>>2&1,i=r&3,l=r>>6;if(r&8)K(0);var a=6-s,c=i==3?4:i,f=je(e,a,c);a+=c;var m=l?1<<l:s,g=je(e,a,m)+(l==1&&256),y=g;if(!s){var v=1<<10+(e[5]>>3);y=v+(v>>3)*(e[5]&7)}if(y>2145386496)K(1);var x=new W((t==1?g||y:t?0:y)+12);return x[0]=1,x[4]=4,x[8]=8,{b:a+m,y:0,l:0,d:f,w:t&&t!=1?t:x.subarray(12),e:y,o:new be(x.buffer,0,3),u:g,c:o,m:Math.min(131072,y)}}else if((n>>4|e[3]<<20)==25481893)return At(e,4)+8;K(0)},re=function(e){var t=0;for(;1<<t<=e;++t);return t-1},ue=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)K(3);var o=1<<s,i=o,l=-1,a=-1,c=-1,f=o,m=new bt(512+(o<<2)),g=new yt(m,0,256),y=new de(m,0,256),v=new de(m,512,o),x=512+(o<<1),S=new W(m,x,o),h=new W(m,x+o);while(l<255&&i>0){var u=re(i+1),d=r>>3,p=(1<<u+1)-1,L=(e[d]|e[d+1]<<8|e[d+2]<<16)>>(r&7)&p,b=(1<<u)-1,T=p-i-1,E=L&b;if(E<T)r+=u,L=E;else if(r+=u+1,L>b)L-=T;if(g[++l]=--L,L==-1)i+=L,S[--f]=l;else i-=L;if(!L)do{var D=r>>3;a=(e[D]|e[D+1]<<8)>>(r&7)&3,r+=2,l+=a}while(a==3)}if(l>255||i)K(0);var C=0,U=(o>>1)+(o>>3)+3,X=o-1;for(var H=0;H<=l;++H){var M=g[H];if(M<1){y[H]=-M;continue}for(c=0;c<M;++c){S[C]=H;do C=C+U&X;while(C>=f)}}if(C)K(0);for(c=0;c<o;++c){var A=y[S[c]]++,k=h[c]=s-re(A);v[c]=(A<<k)-o}return[r+7>>3,{b:s,s:S,n:h,t:v}]},vt=function(e,t){var n=0,r=-1,s=new W(292),o=e[t],i=s.subarray(0,256),l=s.subarray(256,268),a=new de(s.buffer,268);if(o<128){var c=ue(e,t+1,6),f=c[0],m=c[1];t+=o;var g=f<<3,y=e[t];if(!y)K(0);var v=0,x=0,S=m.b,h=S,u=(++t<<3)-8+re(y);for(;;){if(u-=S,u<g)break;var d=u>>3;if(v+=(e[d]|e[d+1]<<8)>>(u&7)&(1<<S)-1,i[++r]=m.s[v],u-=h,u<g)break;d=u>>3,x+=(e[d]|e[d+1]<<8)>>(u&7)&(1<<h)-1,i[++r]=m.s[x],S=m.n[v],v=m.t[v],h=m.n[x],x=m.t[x]}if(++r>255)K(0)}else{r=o-127;for(;n<r;n+=2){var p=e[++t];i[n]=p>>4,i[n+1]=p&15}++t}var L=0;for(n=0;n<r;++n){var b=i[n];if(b>11)K(0);L+=b&&1<<b-1}var T=re(L)+1,E=1<<T,D=E-L;if(D&D-1)K(0);i[r++]=re(D)+1;for(n=0;n<r;++n){var b=i[n];++l[i[n]=b&&T+1-b]}var C=new W(E<<1),U=C.subarray(0,E),X=C.subarray(E);a[T]=0;for(n=T;n>0;--n){var H=a[n];ce(X,n,H,a[n-1]=H+l[n]*(1<<T-n))}if(a[0]!=E)K(0);for(n=0;n<r;++n){var M=i[n];if(M){var A=a[M];ce(U,n,A,a[M]=A+(1<<T-M))}}return[t,{n:X,b:T,s:U}]},Tt=ue(new W([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],Ct=ue(new W([33,20,196,24,99,140,33,132,16,66,8,33,132,16,66,8,33,68,68,68,68,68,68,68,68,36,9]),0,6)[1],Et=ue(new W([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],Ve=function(e,t){var n=e.length,r=new be(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Se=new W(new be([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),St=Ve(Se,0),Pe=new W(new be([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),Pt=Ve(Pe,3),le=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,l=-n.b;if(!o)K(0);var a=0,c=n.b,f=(r<<3)-8+re(o)-c,m=-1;for(;f>l&&m<s;){var g=f>>3,y=(e[g]|e[g+1]<<8|e[g+2]<<16)>>(f&7);a=(a<<c|y)&i,t[++m]=n.s[a],f-=c=n.n[a]}if(f!=l||m+1!=s)K(0)},Lt=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,l=o+i;le(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),le(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),le(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,l),n),le(e.subarray(r),t.subarray(l),n)},kt=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var l=o>>3|e[s+1]<<5|e[s+2]<<13,a=(s+=3)+l;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return ce(n,e[s],t.y,t.y+=l),n;return ce(new W(l),e[s])}if(a>e.length)return;if(i==0){if(t.b=a,n)return n.set(e.subarray(s,a),t.y),t.y+=l,n;return Ee(e,s,a)}if(i==2){var c=e[s],f=c&3,m=c>>2&3,g=c>>4,y=0,v=0;if(f<2)if(m&1)g|=e[++s]<<4|(m&2&&e[++s]<<12);else g=c>>3;else if(v=m,m<2)g|=(e[++s]&63)<<4,y=e[s]>>6|e[++s]<<2;else if(m==2)g|=e[++s]<<4|(e[++s]&3)<<12,y=e[s]>>2|e[++s]<<6;else g|=e[++s]<<4|(e[++s]&63)<<12,y=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var x=n?n.subarray(t.y,t.y+t.m):new W(t.m),S=x.length-g;if(f==0)x.set(e.subarray(s,s+=g),S);else if(f==1)ce(x,e[s++],S);else{var h=t.h;if(f==2){var u=vt(e,s);y+=s-(s=u[0]),t.h=h=u[1]}else if(!h)K(0);(v?Lt:le)(e.subarray(s,s+=y),x.subarray(S),h)}var d=e[s++];if(d){if(d==255)d=(e[s++]|e[s++]<<8)+32512;else if(d>127)d=d-128<<8|e[s++];var p=e[s++];if(p&3)K(0);var L=[Ct,Et,Tt];for(var b=2;b>-1;--b){var T=p>>(b<<1)+2&3;if(T==1){var E=new W([0,0,e[s++]]);L[b]={s:E.subarray(2,3),n:E.subarray(0,1),t:new de(E.buffer,0,1),b:0}}else if(T==2)r=ue(e,s,9-(b&1)),s=r[0],L[b]=r[1];else if(T==3){if(!t.t)K(0);L[b]=t.t[b]}}var D=t.t=L,C=D[0],U=D[1],X=D[2],H=e[a-1];if(!H)K(0);var M=(a<<3)-8+re(H)-X.b,A=M>>3,k=0,V=(e[A]|e[A+1]<<8)>>(M&7)&(1<<X.b)-1;A=(M-=U.b)>>3;var B=(e[A]|e[A+1]<<8)>>(M&7)&(1<<U.b)-1;A=(M-=C.b)>>3;var N=(e[A]|e[A+1]<<8)>>(M&7)&(1<<C.b)-1;for(++d;--d;){var P=X.s[V],w=X.n[V],O=C.s[N],F=C.n[N],R=U.s[B],z=U.n[B];A=(M-=R)>>3;var j=1<<R,I=j+((e[A]|e[A+1]<<8|e[A+2]<<16|e[A+3]<<24)>>>(M&7)&j-1);A=(M-=Pe[O])>>3;var G=Pt[O]+((e[A]|e[A+1]<<8|e[A+2]<<16)>>(M&7)&(1<<Pe[O])-1);A=(M-=Se[P])>>3;var _=St[P]+((e[A]|e[A+1]<<8|e[A+2]<<16)>>(M&7)&(1<<Se[P])-1);if(A=(M-=w)>>3,V=X.t[V]+((e[A]|e[A+1]<<8)>>(M&7)&(1<<w)-1),A=(M-=F)>>3,N=C.t[N]+((e[A]|e[A+1]<<8)>>(M&7)&(1<<F)-1),A=(M-=z)>>3,B=U.t[B]+((e[A]|e[A+1]<<8)>>(M&7)&(1<<z)-1),I>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=I-=3;else{var Y=I-(_!=0);if(Y){if(I=Y==3?t.o[0]-1:t.o[Y],Y>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=I}else I=t.o[0]}for(var b=0;b<_;++b)x[k+b]=x[S+b];k+=_,S+=_;var q=k-I;if(q<0){var J=-q,ee=t.e+q;if(J>G)J=G;for(var b=0;b<J;++b)x[k+b]=t.w[ee+b];k+=J,G-=J,q=0}for(var b=0;b<G;++b)x[k+b]=x[q+b];k+=G}if(k!=S)while(S<x.length)x[k++]=x[S++];else k=x.length;if(n)t.y+=k;else x=Ee(x,0,k)}else if(n){if(t.y+=g,S)for(var b=0;b<g;++b)x[b]=x[S+b]}else if(S)x=Ee(x,S);return t.b=a,x}K(2)},Bt=function(e,t){if(e.length==1)return e[0];var n=new W(t);for(var r=0,s=0;r<e.length;++r){var o=e[r];n.set(o,s),s+=o.length}return n};function ye(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=Mt(e,r||t);if(typeof i==\"object\"){if(r){if(t=null,i.w.length==i.u)n.push(t=i.w),o+=i.u}else n.push(t),i.e=0;for(;!i.l;){var l=kt(e,i,t);if(!l)K(5);if(t)i.e=i.y;else n.push(l),o+=l.length,xt(i.w,0,l.length),i.w.set(l,i.w.length-l.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return Bt(n,o)}async function It(e){let t=e instanceof Uint8Array?e:new Uint8Array(e),n=(r)=>r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength);if(t[0]===40&&t[1]===181&&t[2]===47&&t[3]===253)return n(ye(t));if(t[0]===31&&t[1]===139)return new Response(new Blob([t]).stream().pipeThrough(new DecompressionStream(\"gzip\"))).arrayBuffer();return n(t)}async function He(e){return new TextDecoder().decode(await It(e))}var Ge=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split(\"/\").pop()||\"main.ldr\").replace(/\\.(zst|gz)$/i,\"\")||\"main.ldr\";function xe(e){let t=new DataView(e).getUint32(0,!0),n=JSON.parse(new TextDecoder().decode(new Uint8Array(e,4,t))),r=4+t;return{header:n,arr:(o)=>o&&(o[2]===\"f32\"?new Float32Array(e,r+o[0],o[1]):o[2]===\"u16\"?new Uint16Array(e,r+o[0],o[1]):o[2]===\"u8\"?new Uint8Array(e,r+o[0],o[1]):new Uint32Array(e,r+o[0],o[1])),bytes:e.byteLength,buffer:e}}var Z=(e)=>e.trim().toLowerCase().replace(/\\\\/g,\"/\").replace(/\\/+/g,\"/\");function Le(e){if(/^0x/i.test(e))return parseInt(e,16);return+e}var _e=/^~?\\s*moved\\s+to\\s+(.+)$/i,Ft=new Set([\"FILE\",\"NOFILE\",\"!DATA\",\"!:\",\"STEP\",\"BFC\",\"ROTSTEP\",\"BUFEXCHG\",\"!TEXMAP\"]),Qe=new Set([\"part\",\"subpart\",\"primitive\",\"8_primitive\",\"48_primitive\",\"shortcut\",\"helper\"]),Rt=new Set([\"model\",\"submodel\",\"configuration\"]),Dt=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function We(e){let t=Dt.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,\"\");return Qe.has(n)||Rt.has(n)?n:void 0}function Ut(e){let t=[],n=0;while(n<e.length){while(e[n]===\" \"||e[n]===\"\\t\")n++;if(n>=e.length)break;if(e[n]==='\"'){let r=\"\";n++;while(n<e.length&&e[n]!=='\"'){if(e[n]===\"\\\\\"&&n+1<e.length)n++;r+=e[n++]}n++,t.push(r)}else{let r=n;while(r<e.length&&e[r]!==\" \"&&e[r]!==\"\\t\")r++;t.push(e.slice(n,r)),n=r}}return t}function zt(e,t=!1){let n=/^\\s*(\\S+)\\s+(.*)$/.exec(e);if(!n)return null;let r=n[1].toUpperCase(),s=r===\"PLANAR\"?9:r===\"CYLINDRICAL\"?10:r===\"SPHERICAL\"?11:0;if(!s)return null;let o=n[2].trim().split(/\\s+/);if(o.length<s+1)return null;let i=o.slice(0,s).map(Number);if(!i.every(Number.isFinite))return null;let l=n[2].trim();for(let m=0;m<s;m++)l=l.replace(/^\\S+\\s*/,\"\");let a=Ut(l);if(!a.length)return null;let c={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:a[0]};if(s>=10)c.a=i[9];if(s===11)c.b=i[10];let f=a.findIndex((m,g)=>g>0&&m.toUpperCase()===\"GLOSSMAP\");if(f>0&&a[f+1])c.glossmap=a[f+1];if(t)c.next=!0;return c}var Ot=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,\"\"),n=t+\"=\".repeat((4-t.length%4)%4),r=atob(n),s=new Uint8Array(r.length);for(let o=0;o<r.length;o++)s[o]=r.charCodeAt(o);return s};function Nt(e){let t=e.length,n=1,r=(c)=>c===32||c===9,s=()=>{while(n<t&&r(e.charCodeAt(n)))n++;let c=n;while(n<t&&!r(e.charCodeAt(n)))n++;return c<n?e.slice(c,n):null},o=s();if(o===null)return null;let i=Array(12);for(let c=0;c<12;c++){let f=s();if(f===null)return null;i[c]=+f}while(n<t&&r(e.charCodeAt(n)))n++;if(n>=t)return null;let l=e.slice(n),a=/[ \\t]{2,}|\\t/.test(l)?l.split(/\\s+/).join(\" \"):l;return{t:1,color:Le(o),m:i,file:Z(a)}}function Ke(e){let t=+e[0];if(!(t>=1&&t<=5)||e.length<2)return null;let n=Le(e[1]),r=e.slice(2).map(Number);if(t===1)return{t:1,color:n,m:r.slice(0,12),file:Z(e.slice(14).join(\" \"))};if(t===2)return{t:2,color:n,p:r.slice(0,6)};if(t===3)return{t:3,color:n,p:r.slice(0,9)};if(t===4)return{t:4,color:n,p:r.slice(0,12)};return{t:5,color:n,p:r.slice(0,12)}}function et(e,t=\"main.ldr\",n={}){let r=!!n.geometryText,s=new Map,o=null,i=\"\",l,a=null,c=[],f=null,m=()=>{if(!a)return;let u=Ot(a.chunks.join(\"\")),d=u[0]===137&&u[1]===80&&u[2]===78&&u[3]===71;(l??=new Map).set(Z(a.name),{name:a.name,bytes:u,...d?{mime:\"image/png\"}:{}}),a=null},g=!0,y=(u)=>{if(m(),o={name:Z(u),cmds:[]},s.set(o.name,o),!i)i=o.name;c=[],f=null,g=!0},v=!1,x=!1,S=()=>{if(x)return;x=!0,s.clear(),o=null,i=\"\"},h=(u,d)=>{if(f){u.tex=f,f=null;return}let p=c[c.length-1];if(!p)return;if(p.fallback){if(!d)u.fallback=!0}else u.tex=p.map};for(let u of e.split(`\n`)){let d=u.trim();if(!d)continue;if(r&&d.charCodeAt(0)>=50&&d.charCodeAt(0)<=53&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)){if(a||v)continue;if(!o)y(t);let T=d.slice(2).trimStart(),E=T.search(/\\s/),D={t:d.charCodeAt(0)-48,color:Le(E<0?T:T.slice(0,E)),p:[],src:d};h(D,!1),o.cmds.push(D),g=!1;continue}if(d.charCodeAt(0)===48&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)){let T=2;while(d.charCodeAt(T)===32||d.charCodeAt(T)===9)T++;let E=T;while(E<d.length&&d.charCodeAt(E)!==32&&d.charCodeAt(E)!==9)E++;let D=d.slice(T,E);if(!Ft.has(D)){if(v||a)continue;if(!o)y(t);let C=d.slice(T),U={t:0,text:C};if(D.charCodeAt(0)===33)U.meta=D;if(f=null,g&&!o.org){let H=We(C);if(H)o.org=H}let X=C.match(_e);if(X&&!o.movedTo){let H=X[1].trim().replace(/\\\\/g,\"/\");if(!/\\.(dat|ldr|mpd)$/i.test(H))H+=\".dat\";o.movedTo=Z(H)}o.cmds.push(U);continue}}if(d.charCodeAt(0)===49&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)&&!a&&!v){let T=Nt(d);if(T){if(!o)y(t);h(T,!1),o.cmds.push(T),g=!1;continue}}let p=d.split(/\\s+/);if(+p[0]===0){let T=d.slice(1).trim();if(p[1]===\"FILE\"){S(),v=!1,y(T.slice(5));continue}if(p[1]===\"NOFILE\"){m(),o=null,v=!0;continue}if(p[1]===\"!DATA\"){S(),m(),o=null,v=!1,a={name:T.slice(5).trim(),chunks:[]};continue}if(v)continue;if(a){if(p[1]===\"!:\")a.chunks.push(p.slice(2).join(\"\"));continue}if(!o)y(t);let E={t:0,text:T};if(p[1]===\"STEP\")E.step=!0,c=[],f=null;else if(p[1]===\"BFC\")E.bfc=p.slice(2).join(\" \");else if(p[1]===\"ROTSTEP\")if(E.meta=\"ROTSTEP\",E.step=!0,c=[],f=null,(p[2]??\"\").toUpperCase()===\"END\")E.rotstep={x:0,y:0,z:0,mode:\"END\"};else{let C=(p[5]??\"REL\").toUpperCase();E.rotstep={x:+p[2]||0,y:+p[3]||0,z:+p[4]||0,mode:[\"REL\",\"ABS\",\"ADD\"].includes(C)?C:\"REL\"}}else if(p[1]===\"BUFEXCHG\"){E.meta=\"BUFEXCHG\";let C=(p[2]??\"\").toUpperCase();E.bufexchg={op:C===\"RETRIEVE\"?\"RETRIEVE\":\"STORE\",buf:p[3]??\"A\"}}else if(p[1]?.startsWith(\"!\"))E.meta=p[1];if(g&&!o.org){let C=We(T);if(C)o.org=C}if(p[1]===\"!TEXMAP\"){let C=(p[2]??\"\").toUpperCase();if(f=null,C===\"START\"||C===\"NEXT\"){let U=zt(T.replace(/^!TEXMAP\\s+\\S+/i,\"\"),C===\"NEXT\");if(E.texmap={op:C,...U?{map:U}:{}},U)if((o.texmaps??=[]).push(U),C===\"START\")c.push({map:U,fallback:!1});else f=U}else if(C===\"FALLBACK\"){E.texmap={op:C};let U=c[c.length-1];if(U)U.fallback=!0}else if(C===\"END\")E.texmap={op:C},c.pop()}else if(p[1]===\"!:\"){f=null;let C=Ke(p.slice(2));if(C)h(C,!0),E.geom=C}else f=null;let D=T.match(_e);if(D&&!o.movedTo){let C=D[1].trim().replace(/\\\\/g,\"/\");if(!/\\.(dat|ldr|mpd)$/i.test(C))C+=\".dat\";o.movedTo=Z(C)}o.cmds.push(E);continue}if(a||v)continue;if(!o)y(t);let b=Ke(p);if(!b)continue;h(b,!1),o.cmds.push(b),g=!1}return m(),l?{main:i,files:s,data:l}:{main:i,files:s}}var cn=Math.PI/180;function tt(e,t){let n=(r)=>[t[3]*r[0]+t[4]*r[1]+t[5]*r[2]+t[0],t[6]*r[0]+t[7]*r[1]+t[8]*r[2]+t[1],t[9]*r[0]+t[10]*r[1]+t[11]*r[2]+t[2]];return{...e,p1:n(e.p1),p2:n(e.p2),p3:n(e.p3)}}function nt(e,t){let[n,r,s,o,i,l,a,c,f,m,g,y]=e,[v,x,S,h,u,d,p,L,b,T,E,D]=t;return[o*v+i*x+l*S+n,a*v+c*x+f*S+r,m*v+g*x+y*S+s,o*h+i*p+l*T,o*u+i*L+l*E,o*d+i*b+l*D,a*h+c*p+f*T,a*u+c*L+f*E,a*d+c*b+f*D,m*h+g*p+y*T,m*u+g*L+y*E,m*d+g*b+y*D]}var ke=[0,0,0,1,0,0,0,1,0,0,0,1];var Xe=new WeakMap,$t=/^(s|8|48)\\//;function Be(e,t){let n=e.files.get(Z(t));if(!n)return\"part\";let r=Xe.get(n);if(r)return r;if(n.org)r=Qe.has(n.org)?\"part\":\"model\";else if(n.name===e.main)r=\"model\";else r=n.cmds.some((s)=>s.t>=2||s.t===0&&!!s.geom||s.t===1&&$t.test(s.file))?\"part\":\"model\";return Xe.set(n,r),r}var Ze=new WeakMap;function rt(e){let t=Ze.get(e);if(t)return t;t=[];let n=0;for(let r of e.cmds){if(r.t===0&&r.step){n++;continue}if((r.t>=2||r.t===0&&r.geom&&r.geom.t>=2)&&t[t.length-1]!==n)t.push(n)}return Ze.set(e,t),t}var Ye=(e)=>e>16777215?\"0x\"+e.toString(16).toUpperCase():String(e),jt=(e)=>e.t===0?\"0 \"+e.text:e.t===1?`1 ${Ye(e.color)} ${e.m.join(\" \")} ${e.file}`:e.src?e.src:`${e.t} ${Ye(e.color)} ${e.p.join(\" \")}`,Ie=(e,t)=>`${Z(e)}#${t}`;function Vt(e,t){let n=[],r=0,s=(o)=>!!o&&o.t===0&&o.texmap?.op===\"NEXT\";for(let o of e.cmds){if(o.t===0){if(o.step){r++;continue}if(o.bfc!==void 0){n.push(o);continue}if(r!==t)continue;if(o.texmap)n.push(o);else if(o.geom){if(o.geom.t>=2)n.push(o);else if(s(n[n.length-1]))n.pop()}continue}if(r!==t)continue;if(o.t===1){if(s(n[n.length-1]))n.pop();continue}n.push(o)}return{name:Ie(e.name,t),cmds:n}}function st(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Vt(e,t).cmds.map(jt)].join(`\n`)+`\n`}function Ht(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,\"0\")}function ot(e){let[t,n,r,s,o,i,l,a,c,f,m,g]=e,y=a*g-c*m,v=-(l*g-c*f),x=l*m-a*f,S=s*y+o*v+i*x;if(!Number.isFinite(S)||Math.abs(S)<0.000000000001)return null;let h=1/S,u=[y*h,-(o*g-i*m)*h,(o*c-i*a)*h,v*h,(s*g-i*f)*h,-(s*c-i*l)*h,x*h,-(s*m-o*f)*h,(s*a-o*l)*h];return[-(u[0]*t+u[1]*n+u[2]*r),-(u[3]*t+u[4]*n+u[5]*r),-(u[6]*t+u[7]*n+u[8]*r),...u]}var Gt=(e)=>String(+e.toFixed(6)||0),Je=(e)=>'\"'+e.replace(/\\\\/g,\"\\\\\\\\\").replace(/\"/g,\"\\\\\\\"\")+'\"';function it(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!==\"PLANAR\"?[t.a??360]:[],...t.method===\"SPHERICAL\"?[t.b??180]:[]].map(Gt).join(\" \"),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${Je(t.texture)}${t.glossmap?\" GLOSSMAP \"+Je(t.glossmap):\"\"}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${Z(e)}\n0 !TEXMAP END\n`;return{name:`${Z(e)}#tex-${Ht(r)}`,source:r}}var _t=(e,t)=>{let n=[,,,,,,,,,];for(let r=0;r<3;r++)for(let s=0;s<3;s++)n[r*3+s]=e[r*3]*t[s]+e[r*3+1]*t[3+s]+e[r*3+2]*t[6+s];return n};function Wt(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),l=Math.cos(t*r),a=Math.sin(n*r),c=Math.cos(n*r);return[l*c,-l*a,i,o*a+s*i*c,o*c-s*i*a,-s*l,s*a-o*i*c,s*c+o*i*a,o*l]}var qe=new WeakMap;function at(e){let t=qe.get(e);if(t)return t;let n=[],r=null;for(let s of e.cmds){if(s.t!==0||!s.step)continue;let o=s.rotstep;if(o)if(o.mode===\"END\")r=null;else{let i=Wt(o.x,o.y,o.z);r=o.mode===\"ABS\"?{abs:!0,m:i,rotstep:o}:o.mode===\"ADD\"&&r?{abs:r.abs,m:_t(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),qe.set(e,n),n}var lt=999999,ct=(e)=>e.map((t)=>String(t).padStart(6,\"0\")).join(\".\")+\"~\";function Kt(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,l=new Map,a=0,c=(m,g)=>{let y=m.name+\"#\"+g,v=l.get(y);if(!v){let x;v=Object.assign(()=>x??=st(m,g),{file:m,step:g}),l.set(y,v)}return v},f=(m,g,y,v,x,S,h,u,d=null,p=[],L=[])=>{let b=m.files.get(g);if(!b||h>r)return;let T=0,E=h>0?++a:0,D=i&&E?[...p,E]:p,C=i&&E?[...L,y]:L,U=i&&!d?new Map:null,X=-1,H=0,M=(P,w,O,F,R,z)=>{if(X!==T)X=T,H=0;let j=U?.get(T+\"|\"+w);if(j)return j.n++,f(P,P===m?w:P.main,O,F,x+\"/\"+w,[...R,lt],h+1,z,[...R,lt],D,C);let I=[...R,H++],G=n.length;f(P,P===m?w:P.main,O,F,x+\"/\"+w,I,h+1,z,d,D,C),U?.set(T+\"|\"+w,{n:1,from:G,to:n.length})},A=at(b),k=s?rt(b):[],V=0,B=(P,w,O,F,R,z,j)=>{if(d)F=d;let I={part:P,color:w,m:O,step:F[0],steps:F,localStep:R,path:x};if(E){if(I.sub=E,i)I.subPath=D,I.subMats=C}if(z)I.embedded=!0;if(j){let _=it(P,j);I.texPart=_.name,I.texSource=_.source}let G=A[R];if(G)I.view=G;return n.push(I),I},N=(P)=>{while(V<k.length&&k[V]<=P){let w=k[V++];B(Ie(b.name,w),v,y,[...S,w],w,!1,null).source=c(b,w)}};for(let P of b.cmds){if(P.t===0&&P.step){T++;continue}let w=P;if(w.t>=2||w.t===0&&w.geom&&w.geom.t>=2){N(T);continue}if(w.t===0)if(o&&w.geom?.t===1)w=w.geom;else continue;if(w.t!==1)continue;if(o&&w.fallback)continue;let O=w.color===16?v:w.color,F=nt(y,w.m),R=[...S,T],z=o?w.tex??u:null,j=z?ot(w.m):null,I=z&&j?tt(z,j):null;if(m.files.has(w.file)){if(Be(m,w.file)===\"model\"){M(m,w.file,F,O,R,I);continue}B(w.file,O,F,R,T,!0,I);continue}let G=t.resolveModel?.(w.file);if(G){M(G,w.file,F,O,R,I);continue}B(w.file,O,F,R,T,!1,I)}if(N(1/0),U){for(let P of U.values())if(P.n>1)for(let w=P.from;w<P.to;w++)n[w].mult??=P.n}};if(Be(e,e.main)===\"part\"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...ke],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return f(e,e.main,ke,16,e.main,[],0,null),n}function ut(e,t=\"main.ldr\",n){return Kt(et(e,t,{geometryText:!0}),n)}function Xt(e,t){let n=new Map,r=null,s=!1;for(let o of e.split(/\\r?\\n/)){let i=/^\\s*0\\s+FILE\\s+(.+)$/i.exec(o);if(i){if(!s)n.clear();s=!0,r=[],n.set(Z(i[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(o)){if(!s)n.clear();s=!0,r=null;continue}if(!r){if(s)continue;r=[],n.set(Z(t),r)}let l=o.trim().replace(/\\s+/g,\" \");if(l)r.push(l)}return n}var Zt=(e)=>{if(!e.startsWith(\"1 \"))return null;let t=e.split(\" \");return t.length>=15?Z(t.slice(14).join(\" \")):null};function Yt(e){let t=2166136261,n=1523705862;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);t=Math.imul(t^s,16777619),n=Math.imul(n^s,16777629)^n>>>15}return(t>>>0).toString(16).padStart(8,\"0\")+(n>>>0).toString(16).padStart(8,\"0\")}function ft(e,t,n=\"main.ldr\"){let r=Xt(e,n),s=new Map;for(let o of t){let i=Z(o);if(!r.has(i)||s.has(i))continue;let l=new Set([i]),a=[i];while(a.length)for(let f of r.get(a.pop())){let m=Zt(f);if(m&&r.has(m)&&!l.has(m))l.add(m),a.push(m)}let c=[i,...[...l].filter((f)=>f!==i).sort()].map((f)=>\"0 FILE \"+(f===i?\"\":f)+`\n`+r.get(f).join(`\n`)).join(`\n`);s.set(i,`emb/${Yt(c)}.dat`)}return s}var pt=(e,t=0)=>Math.abs(e[t+7]-1)<0.001&&Math.abs(e[t+4])<0.001&&Math.abs(e[t+10])<0.001,mt=new WeakMap;function Fe(e,t){let n=mt.get(e);if(!n)mt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),l=[],a=[];s.studs.forEach((g,y)=>{l.push(g[0]),a.push(g[1]);for(let v=0;v<12;v++)i[y*12+v]=g[2+v]});let c=null,f=0,m=0;if(s.mask){f=s.mask[0],m=s.mask[1];let g=s.mask[2];c=new Uint8Array(g.length);for(let y=0;y<g.length;y++)c[y]=g.charCodeAt(y)===49?1:0}return n.set(t,r={nStuds:o,studM:i,kind:l,color:a,mask:c,nx:f,nz:m}),r}var ie=1073741824;class Re{a;b;c;vals;used;mask;size=0;constructor(e=1024){let t=1024;while(t<e*2)t*=2;this.a=new Int32Array(t),this.b=new Int32Array(t),this.c=new Int32Array(t),this.vals=new Int32Array(t),this.used=new Uint8Array(t),this.mask=t-1}slot(e,t,n){let r=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return r^=r>>>15,r=Math.imul(r,739982445),r^=r>>>12,r&this.mask}get(e,t,n){let r=this.slot(e,t,n),s=this.used,o=this.a,i=this.b,l=this.c;for(;;){if(!s[r])return-1;if(o[r]===e&&i[r]===t&&l[r]===n)return this.vals[r];r=r+1&this.mask}}put(e,t,n,r){if((this.size+1)*2>this.used.length)this.grow();let s=this.slot(e,t,n),o=this.used,i=this.a,l=this.b,a=this.c;for(;;){if(!o[s])return o[s]=1,i[s]=e,l[s]=t,a[s]=n,this.vals[s]=r,this.size++,-1;if(i[s]===e&&l[s]===t&&a[s]===n){let c=this.vals[s];return this.vals[s]=r,c}s=s+1&this.mask}}grow(){let{a:e,b:t,c:n,vals:r,used:s}=this,o=s.length*2;this.a=new Int32Array(o),this.b=new Int32Array(o),this.c=new Int32Array(o),this.vals=new Int32Array(o),this.used=new Uint8Array(o),this.mask=o-1,this.size=0;for(let i=0;i<s.length;i++)if(s[i])this.put(e[i],t[i],n[i],r[i])}}var we=(e,t,n)=>e>-ie&&e<ie&&t>-ie&&t<ie&&n>-ie&&n<ie,fe=2147483647;function Jt(e,t,n){let s=[],o=[],i=[],l=[],a=[],c=[],f=[],m=[],g=new Re(e.length*2),y=[],v=[];for(let M=0;M<e.length;M++){let A=e[M],k=A.m,V=t.parts[A.part];if(!V||!V.mask||!pt(k))continue;let B=V.bbox,N=1/0,P=-1/0,w=1/0,O=-1/0;for(let z=0;z<2;z++)for(let j=0;j<2;j++){let I=z?B[3]:B[0],G=j?B[5]:B[2],_=k[0]+k[3]*I+k[5]*G,Y=k[2]+k[9]*I+k[11]*G;if(_<N)N=_;if(_>P)P=_;if(Y<w)w=Y;if(Y>O)O=Y}let F=a.length;s.push(N),o.push(P),i.push(w),l.push(O),a.push(M),c.push(Fe(t,A.part)),f.push(B[0]),m.push(B[2]);let R=Math.round((k[1]+B[4])*2);for(let z=Math.floor(N/40);z<=Math.floor(P/40);z++)for(let j=Math.floor(w/40);j<=Math.floor(O/40);j++){if(!we(R,z,j))continue;let I=v.length;v.push(F),y.push(g.put(R,z,j,I))}}let x=[0,5,-5,5,-5],S=[0,5,5,-5,-5],h=NaN,u=NaN,d=NaN,p=-1,L=(M,A,k,V)=>{let B=Math.round(A*2),N=Math.floor(M/40),P=Math.floor(k/40);if(!we(B,N,P))return fe;let w=fe;if(B!==h||N!==u||P!==d)h=B,u=N,d=P,p=g.get(B,N,P);for(let O=p;O>=0;O=y[O]){let F=v[O];if(a[F]===V||!(M-6>=s[F]-0.5&&M+6<=o[F]+0.5&&k-6>=i[F]-0.5&&k+6<=l[F]+0.5))continue;let R=e[a[F]].m,z=c[F],j=f[F],I=m[F],G=M-R[0],_=A-R[1],Y=k-R[2],q=R[3]*G+R[6]*_+R[9]*Y,J=R[5]*G+R[8]*_+R[11]*Y,{nx:ee,nz:se,mask:ae}=z,oe=!0;for(let Q=0;Q<5;Q++){let te=Math.floor((q+x[Q]-j)/20),ne=Math.floor((J+S[Q]-I)/20);if(te<0||ne<0||te>=ee||ne>=se||ae[te*se+ne]!==1){oe=!1;break}}if(oe){if(!n)return 0;let Q=n[a[F]];if(Q<w)w=Q}}return w},b=0;for(let M of e){let A=Fe(t,M.part);if(A)b+=A.nStuds}let T=new Uint8Array(b),E=new Uint8Array(b),D=new Re(b),C=0,U=n?new Int32Array(b).fill(fe):void 0;for(let M=0,A=0;M<e.length;M++){let k=e[M],V=Fe(t,k.part);if(!V)continue;let B=k.m,N=V.studM,P=B[0],w=B[1],O=B[2],F=B[3],R=B[4],z=B[5],j=B[6],I=B[7],G=B[8],_=B[9],Y=B[10],q=B[11];for(let J=0;J<V.nStuds;J++,A++){let ee=J*12,se=N[ee+4],ae=N[ee+7],oe=N[ee+10];if(!(Math.abs(j*se+I*ae+G*oe-1)<0.001&&Math.abs(F*se+R*ae+z*oe)<0.001&&Math.abs(_*se+Y*ae+q*oe)<0.001))continue;E[A]=1;let Q=N[ee],te=N[ee+1],ne=N[ee+2],De=P+F*Q+R*te+z*ne,Ue=w+j*Q+I*te+G*ne,ze=O+_*Q+Y*te+q*ne,Oe=L(De,Ue,ze,M);if(Oe!==fe){if(T[A]=1,C++,U)U[A]=Oe}let me=Math.round(De),he=Math.round(Ue),ge=Math.round(ze);if(!we(me,he,ge))continue;if(!n){D.put(me,he,ge,1);continue}let Ne=n[M],$e=D.get(me,he,ge);if($e<0||Ne<$e)D.put(me,he,ge,Ne)}}let X=new Uint8Array(e.length),H=n?new Int32Array(e.length).fill(fe):void 0;for(let M=0;M<e.length;M++){let A=e[M],k=t.parts[A.part];if(!k||!k.under||!pt(A.m))continue;let V=k.bbox,B=Math.round((V[3]-V[0])/20),N=Math.round((V[5]-V[2])/20);if(!B||!N||B*N>4096)continue;let P=A.m,w=!0,O=0;for(let F=0;F<B&&w;F++)for(let R=0;R<N;R++){let z=V[0]+10+20*F,j=V[2]+10+20*R,I=P[0]+P[3]*z+P[5]*j,G=P[2]+P[9]*z+P[11]*j,_=Math.round(I),Y=Math.round(P[1]+V[4]),q=Math.round(G),J=we(_,Y,q)?D.get(_,Y,q):-1;if(J<0){w=!1;break}if(J>O)O=J}if(w){if(X[M]=1,H)H[M]=O}}return{nStuds:b,studHidden:T,studUp:E,underHidden:X,studsHidden:C,studHideStep:U,underHideStep:H}}function qt(e,t,n){let r=(a)=>n&&a.texPart&&t.parts[a.texPart]?a.texPart:a.part,s=e.map((a)=>({part:r(a),color:String(a.color),m:a.m,steps:a.steps})),o=s.map((a)=>ct(a.steps)),i=[...new Set(o)].sort(),l=new Map(i.map((a,c)=>[a,c]));return{all:s,stepOf:o.map((a)=>l.get(a)),nSteps:i.length}}function Ae(e,t,n=!0){let r=qt(e,t,n);return Jt(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Ce=\"https://ldr-demo.vercel.app/cdn/v1/\",ve=new Map,Me=new Map;function gt(e=Ce,t=fetch){let n=ve.get(e);if(!n)n=t(e+\"parts.json\").then((r)=>{if(!r.ok)throw Error(`ldr: parts CDN index ${r.status} (${e}parts.json)`);return r.json()}),n.catch(()=>ve.delete(e)),ve.set(e,n);return n}var Qt=(e)=>Array.isArray(e)&&e.length===3&&typeof e[0]===\"number\"&&typeof e[1]===\"number\"&&(e[2]===\"f32\"||e[2]===\"u16\"||e[2]===\"u8\"||e[2]===\"u32\"),Te=(e,t)=>Qt(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>Te(n,t)):e&&typeof e===\"object\"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Te(r,t)])):e;function en(e,t={}){let n=[],r=0,s={},o={};for(let g of e){let y=g.buffer;if(!y)throw Error(\"ldr: mergePacks needs packs from decodePack/loadPack\");let v=new DataView(y).getUint32(0,!0),x=new Uint8Array(y,4+v),S=r;n.push(x),r+=x.byteLength;let h=(4-r%4)%4;if(h)n.push(new Uint8Array(h)),r+=h;for(let[u,d]of Object.entries(g.header.parts??{}))if(!(u in s))s[u]=Te(d,S);for(let[u,d]of Object.entries(g.header.studKinds??{}))if(!(u in o))o[u]=Te(d,S)}let i=e[0]?.header??{version:1,weld:!0},l=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),a=(4-(4+l.length)%4)%4,c=4+l.length+a,f=new Uint8Array(c+r);new DataView(f.buffer).setUint32(0,l.length+a,!0),f.set(l,4),f.fill(32,4+l.length,c);let m=c;for(let g of n)f.set(g,m),m+=g.byteLength;return xe(f.buffer)}async function tn(e,t={}){e=[...e];try{return await ht(e,t)}catch(n){let r=t.cdn??Ce,s=t.fetch??fetch;ve.delete(r);let o=(i,l)=>s(i,{...l,cache:\"reload\"});try{return await ht(e,{...t,fetch:o})}catch{throw n}}}async function ht(e,t){let n=t.cdn??Ce,r=t.fetch??fetch,s=t.gap??16384,o=await gt(n,r),i=[...new Set([...e].map(Z))],l=[],a=[];for(let h of i){if(Me.has(n+h))continue;let u=o.parts[h];if(u)a.push({name:h,off:u[0],len:u[1],file:u[2]??0});else l.push(h)}a.sort((h,u)=>h.file-u.file||h.off-u.off);let c=[];for(let h of a){let u=c[c.length-1];if(u&&u.file===h.file&&h.off-u.end<=s)u.end=Math.max(u.end,h.off+h.len),u.items.push(h);else c.push({file:h.file,start:h.off,end:h.off+h.len,items:[h]})}let f=0,m=0,g=0,y=new Map,v=async()=>{while(g<c.length){let h=c[g++],u=y.get(h.file);if(u)u=u.subarray(h.start,h.end);else{let d=await r(new URL(o.archives[h.file],n).href,{headers:{Range:`bytes=${h.start}-${h.end-1}`,\"Accept-Encoding\":\"identity\"}});if(!d.ok)throw Error(`ldr: parts CDN ${d.status}`);if(m++,u=new Uint8Array(await d.arrayBuffer()),f+=u.byteLength,d.status===200)y.set(h.file,u),u=u.subarray(h.start,h.end)}for(let d of h.items){let p=ye(u.subarray(d.off-h.start,d.off-h.start+d.len)),L=p.buffer.slice(p.byteOffset,p.byteOffset+p.byteLength);Me.set(n+d.name,xe(L))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,c.length)},v));let x=i.filter((h)=>Me.has(n+h)).map((h)=>Me.get(n+h));return{pack:x.length?en(x,{colors:o.colors}):xe(nn(o.colors)),missing:l,requests:m,bytes:f}}function nn(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},colors:e})),n=(4-(4+t.length)%4)%4,r=new Uint8Array(4+t.length+n).fill(32);return new DataView(r.buffer).setUint32(0,t.length+n,!0),r.set(t,4),r.buffer}function rn(e,t){let n=t.header.parts;if(!n)return 0;let r=0;for(let s of e){let o=n[s.part]?.body?.tris;if(o)r+=o}return r}function sn(e,t,n){let r=0,s=0,o=!1,i=new Set;for(let l of e){let a=l.embedded?t.get(l.part):Z(l.part),c=a?n.parts[a]:void 0;if(!c)continue;if(c[3]!=null)o=!0,r+=c[3];if(!i.has(a))i.add(a),s+=c[1]}return{bodyTris:r,packBytes:s,known:o}}class pe extends Error{code=\"ldr-budget\";bodyTris;packBytes;maxBodyTris;maxPackBytes;constructor(e){let t=[e.maxBodyTris!=null&&e.bodyTris>e.maxBodyTris?`${e.bodyTris} triangles (limit ${e.maxBodyTris})`:\"\",e.maxPackBytes!=null&&e.packBytes>e.maxPackBytes?`${(e.packBytes/1e6).toFixed(1)} MB parts pack (limit ${(e.maxPackBytes/1e6).toFixed(0)} MB)`:\"\"].filter(Boolean).join(\", \");super(`ldr: model exceeds device budget: ${t}`);this.name=\"BudgetError\",this.bodyTris=e.bodyTris,this.packBytes=e.packBytes,this.maxBodyTris=e.maxBodyTris,this.maxPackBytes=e.maxPackBytes}}async function dt(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=gt(t.cdn??Ce,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(p)=>{if(!p.ok)throw Error(`ldr: ${p.status} fetching ${e}`);return He(await p.arrayBuffer())}),i=performance.now(),l=t.name??(t.text?\"main.ldr\":Ge(e)),a=ut(o,l,{looseGeometry:!1,callouts:t.callouts}),c=performance.now();t.onParsed?.(a),await s;let f=ft(o,new Set(a.filter((p)=>p.embedded).map((p)=>p.part)),l),m=(p,L)=>t.maxBodyTris!=null&&p>t.maxBodyTris||t.maxPackBytes!=null&&L>t.maxPackBytes;if(t.maxBodyTris!=null||t.maxPackBytes!=null){let p=sn(a,f,await s);if(m(p.known?p.bodyTris:0,p.packBytes))throw new pe({bodyTris:p.bodyTris,packBytes:p.packBytes,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes})}let{pack:g,missing:y,requests:v,bytes:x}=await tn([...a.filter((p)=>!p.embedded).map((p)=>p.part),...f.values()],t),S=new Map([...f].map(([p,L])=>[L,p])),h=y.map((p)=>S.get(p)??p);for(let[p,L]of f){let b=g.header.parts[L];if(b)g.header.parts[p]=b}let u=performance.now();if(t.maxBodyTris!=null||t.maxPackBytes!=null){let p=g.buffer?.byteLength??g.bytes??0,L=rn(a,g);if(m(L,p))throw new pe({bodyTris:L,packBytes:p,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes})}let d=t.cull?Ae(a,g.header,t.textures!==!1):void 0;return{insts:a,pack:g,missing:h,requests:v,bytes:x,cull:d,timings:{fetchModel:i-n,parse:c-i,parts:u-c,...d?{cull:performance.now()-u}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await dt(n,{...r,cull:!1,onParsed:(f)=>self.postMessage({id:t,insts:f})}),o=s.pack.buffer;if(self.postMessage({id:t,buffer:o,missing:s.missing,requests:s.requests,bytes:s.bytes,timings:s.timings},[o]),!r.cull)return;let i=performance.now(),l=Ae(s.insts,s.pack.header,r.textures!==!1),a=performance.now()-i,c=[];for(let f of[l.studHidden,l.studUp,l.underHidden,l.studHideStep,l.underHideStep])if(f)c.push(f.buffer);self.postMessage({id:t,cull:l,ms:a},c)}catch(s){if(s instanceof pe||s?.code===\"ldr-budget\")self.postMessage({id:t,phase:\"error\",error:String(s?.message??s),budget:{bodyTris:s.bodyTris,packBytes:s.packBytes,maxBodyTris:s.maxBodyTris,maxPackBytes:s.maxPackBytes}});else self.postMessage({id:t,phase:\"error\",error:String(s?.message??s)})}};\n";
|
|
2
2
|
export default _default;
|
package/dist/node/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/spec.ts
|
|
2
2
|
var norm = (s) => s.trim().toLowerCase().replace(/\\/g, "/").replace(/\/+/g, "/");
|
|
3
3
|
function parseColor(tok) {
|
|
4
4
|
if (/^0x/i.test(tok))
|
|
@@ -690,7 +690,7 @@ function fileStepViews(f) {
|
|
|
690
690
|
viewMemo.set(f, out);
|
|
691
691
|
return out;
|
|
692
692
|
}
|
|
693
|
-
// ../../../../../../../tmp/ldr-build-
|
|
693
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/model.ts
|
|
694
694
|
var CALLOUT_END = 999999;
|
|
695
695
|
var stepKey = (steps) => steps.map((x) => String(x).padStart(6, "0")).join(".") + "~";
|
|
696
696
|
function flatten(doc, opts = {}) {
|
|
@@ -1039,7 +1039,7 @@ function parseLDConfig(text) {
|
|
|
1039
1039
|
}
|
|
1040
1040
|
return out;
|
|
1041
1041
|
}
|
|
1042
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1042
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/instructions.ts
|
|
1043
1043
|
var MIN_VIS = 0.5;
|
|
1044
1044
|
var REORIENT = 0.35;
|
|
1045
1045
|
var deg = Math.PI / 180;
|
|
@@ -1407,10 +1407,10 @@ function planStepViews(insts, parts, stepOf, nSteps, o = {}) {
|
|
|
1407
1407
|
}
|
|
1408
1408
|
};
|
|
1409
1409
|
}
|
|
1410
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1410
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/render.ts
|
|
1411
1411
|
import * as THREE from "three";
|
|
1412
1412
|
|
|
1413
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1413
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/pack-io.ts
|
|
1414
1414
|
import { decompress } from "fzstd";
|
|
1415
1415
|
async function decompressPack(data) {
|
|
1416
1416
|
const u = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
@@ -1433,7 +1433,7 @@ function decodePack(buf) {
|
|
|
1433
1433
|
return { header, arr, bytes: buf.byteLength, buffer: buf };
|
|
1434
1434
|
}
|
|
1435
1435
|
|
|
1436
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1436
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/cull.ts
|
|
1437
1437
|
var upright = (m, o = 0) => Math.abs(m[o + 7] - 1) < 0.001 && Math.abs(m[o + 4]) < 0.001 && Math.abs(m[o + 10]) < 0.001;
|
|
1438
1438
|
var prepCache = new WeakMap;
|
|
1439
1439
|
function prepPart(H, part) {
|
|
@@ -1750,7 +1750,7 @@ function precomputeCull(instances, H, useTex = true) {
|
|
|
1750
1750
|
return cullCore(s.all, H, s.nSteps > 1 ? s.stepOf : undefined);
|
|
1751
1751
|
}
|
|
1752
1752
|
|
|
1753
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1753
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/render.ts
|
|
1754
1754
|
async function loadPack(url) {
|
|
1755
1755
|
const res = await fetch(url);
|
|
1756
1756
|
if (!res.ok)
|
|
@@ -2249,6 +2249,33 @@ function gridClusters(n, x, z, k) {
|
|
|
2249
2249
|
}
|
|
2250
2250
|
return out;
|
|
2251
2251
|
}
|
|
2252
|
+
var _studDisc = null;
|
|
2253
|
+
function studDiscGeom() {
|
|
2254
|
+
if (_studDisc)
|
|
2255
|
+
return _studDisc;
|
|
2256
|
+
const y = -4, r = 6;
|
|
2257
|
+
const pos = new Float32Array([-r, y, -r, r, y, -r, r, y, r, -r, y, -r, r, y, r, -r, y, r]);
|
|
2258
|
+
const nrm = new Float32Array(18);
|
|
2259
|
+
for (let i = 0;i < 6; i++) {
|
|
2260
|
+
nrm[i * 3] = 0;
|
|
2261
|
+
nrm[i * 3 + 1] = -1;
|
|
2262
|
+
nrm[i * 3 + 2] = 0;
|
|
2263
|
+
}
|
|
2264
|
+
const col = new Uint8Array(24);
|
|
2265
|
+
for (let i = 0;i < 6; i++) {
|
|
2266
|
+
col[i * 4] = 255;
|
|
2267
|
+
col[i * 4 + 1] = 255;
|
|
2268
|
+
col[i * 4 + 2] = 255;
|
|
2269
|
+
col[i * 4 + 3] = 0;
|
|
2270
|
+
}
|
|
2271
|
+
const g = new THREE.BufferGeometry;
|
|
2272
|
+
g.setAttribute("position", new THREE.Float16BufferAttribute(toF16(pos), 3));
|
|
2273
|
+
g.setAttribute("normal", new THREE.BufferAttribute(toI8(nrm), 3, true));
|
|
2274
|
+
g.setAttribute("ldrColor", new THREE.BufferAttribute(col, 4, true));
|
|
2275
|
+
g.computeBoundingSphere();
|
|
2276
|
+
g.computeBoundingBox();
|
|
2277
|
+
return _studDisc = g;
|
|
2278
|
+
}
|
|
2252
2279
|
|
|
2253
2280
|
class LdrLodRoot extends THREE.LOD {
|
|
2254
2281
|
clusters = [];
|
|
@@ -2423,7 +2450,9 @@ function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colo
|
|
|
2423
2450
|
bKind.forEach((kind, b) => {
|
|
2424
2451
|
const g = geom(H.studKinds[kind].body, arr);
|
|
2425
2452
|
const ids = bIds[b];
|
|
2426
|
-
|
|
2453
|
+
const studTris = g ? (g.getIndex() ? g.getIndex().count : g.getAttribute("position").count) / 3 : 24;
|
|
2454
|
+
const kStud = LOD ? Math.max(256, Math.min(4096, Math.round(65536 / Math.max(1, studTris)))) : Infinity;
|
|
2455
|
+
for (const c of gridClusters(ids.length, (i) => sx[ids[i]], (i) => sz[ids[i]], kStud)) {
|
|
2427
2456
|
const ci = sMesh.length;
|
|
2428
2457
|
let v = 0;
|
|
2429
2458
|
for (const i of c)
|
|
@@ -3099,6 +3128,7 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
3099
3128
|
const sKind = sMesh.map((x) => x?.kind ?? "");
|
|
3100
3129
|
const sVis = sMesh.map((x) => x?.vis ?? 0);
|
|
3101
3130
|
const STUD_ERR = 12;
|
|
3131
|
+
const STUD_DISC_ERR = 2;
|
|
3102
3132
|
let _coopS = 0;
|
|
3103
3133
|
for (let ci = 0;ci < sMesh.length; ci++) {
|
|
3104
3134
|
const sm = sMesh[ci];
|
|
@@ -3116,14 +3146,28 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
3116
3146
|
im.userData.ldrStud = true;
|
|
3117
3147
|
root.add(im);
|
|
3118
3148
|
const cl = newCluster(im.boundingSphere);
|
|
3149
|
+
cl.studEdge0 = true;
|
|
3119
3150
|
cl.lv.push({ objs: [im], err: 0 });
|
|
3120
|
-
|
|
3151
|
+
const discObjs = [];
|
|
3152
|
+
if (LOD) {
|
|
3153
|
+
const disc = new THREE.InstancedMesh(studDiscGeom(), im.material, 0);
|
|
3154
|
+
disc.userData = { ldrStud: true, ldrLod: true };
|
|
3155
|
+
disc.instanceMatrix = im.instanceMatrix;
|
|
3156
|
+
disc.count = im.count;
|
|
3157
|
+
disc.instanceColor = im.instanceColor;
|
|
3158
|
+
disc.boundingSphere = im.boundingSphere;
|
|
3159
|
+
disc.visible = false;
|
|
3160
|
+
disc.onBeforeRender = trackVp;
|
|
3161
|
+
root.add(disc);
|
|
3162
|
+
discObjs.push(disc);
|
|
3163
|
+
cl.lv.push({ objs: [disc], err: STUD_DISC_ERR });
|
|
3121
3164
|
cl.lv.push({ objs: [], err: STUD_ERR });
|
|
3165
|
+
}
|
|
3122
3166
|
if (EDGES && k.edges)
|
|
3123
3167
|
addLines(k.edges, im, cl);
|
|
3124
3168
|
if (P.condStuds !== false)
|
|
3125
3169
|
addCond(k, im, cl);
|
|
3126
|
-
const objs = [im, ...cl.lines, ...cl.cond];
|
|
3170
|
+
const objs = [im, ...discObjs, ...cl.lines, ...cl.cond];
|
|
3127
3171
|
objs.forEach((o) => {
|
|
3128
3172
|
if (!o.isInstancedMesh)
|
|
3129
3173
|
o.geometry.instanceCount = im.count;
|
|
@@ -3147,7 +3191,7 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
3147
3191
|
for (const o of l.objs)
|
|
3148
3192
|
o.visible = i === c.cur;
|
|
3149
3193
|
});
|
|
3150
|
-
const lineVis = edgesOn && c.edgeOk && c.cur >= 0 && (c.cur === 0 || !LOD || (c.setMergedLevel ? true : c.lv[c.cur].objs.length > 0));
|
|
3194
|
+
const lineVis = edgesOn && c.edgeOk && c.cur >= 0 && (c.studEdge0 ? c.cur === 0 : c.cur === 0 || !LOD || (c.setMergedLevel ? true : c.lv[c.cur].objs.length > 0));
|
|
3151
3195
|
for (const o of c.lines)
|
|
3152
3196
|
o.visible = lineVis;
|
|
3153
3197
|
for (const o of c.cond)
|
|
@@ -3372,7 +3416,7 @@ async function warmPackGeometry(pack, stop = () => false, sliceMs = 8) {
|
|
|
3372
3416
|
await new Promise((r) => setTimeout(r, 0));
|
|
3373
3417
|
}
|
|
3374
3418
|
}
|
|
3375
|
-
// ../../../../../../../tmp/ldr-build-
|
|
3419
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/scene.ts
|
|
3376
3420
|
import * as THREE2 from "three";
|
|
3377
3421
|
function colorFn(src, pack, fallback) {
|
|
3378
3422
|
const table = new Map;
|
|
@@ -3589,10 +3633,10 @@ function createLdrObjectInner(instances, pack, options, progressive) {
|
|
|
3589
3633
|
return finish();
|
|
3590
3634
|
})();
|
|
3591
3635
|
}
|
|
3592
|
-
// ../../../../../../../tmp/ldr-build-
|
|
3636
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/parts-cdn.ts
|
|
3593
3637
|
import { decompress as decompress2 } from "fzstd";
|
|
3594
3638
|
|
|
3595
|
-
// ../../../../../../../tmp/ldr-build-
|
|
3639
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/embedded.ts
|
|
3596
3640
|
function splitFiles(text, fallback) {
|
|
3597
3641
|
const files = new Map;
|
|
3598
3642
|
let cur = null, saw = false;
|
|
@@ -3664,7 +3708,7 @@ function embeddedKeys(text, names, fallback = "main.ldr") {
|
|
|
3664
3708
|
return out;
|
|
3665
3709
|
}
|
|
3666
3710
|
|
|
3667
|
-
// ../../../../../../../tmp/ldr-build-
|
|
3711
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/parts-cdn.ts
|
|
3668
3712
|
var DEFAULT_PARTS_CDN = "https://ldr-demo.vercel.app/cdn/v1/";
|
|
3669
3713
|
var indexCache = new Map;
|
|
3670
3714
|
var shardCache = new Map;
|
|
@@ -3763,18 +3807,27 @@ async function loadPartsOnce(names, o) {
|
|
|
3763
3807
|
} else
|
|
3764
3808
|
groups.push({ file: t.file, start: t.off, end: t.off + t.len, items: [t] });
|
|
3765
3809
|
}
|
|
3766
|
-
let bytes = 0;
|
|
3810
|
+
let bytes = 0, requests = 0;
|
|
3767
3811
|
let next = 0;
|
|
3812
|
+
const full = new Map;
|
|
3768
3813
|
const worker = async () => {
|
|
3769
3814
|
while (next < groups.length) {
|
|
3770
3815
|
const g = groups[next++];
|
|
3771
|
-
|
|
3772
|
-
if (
|
|
3773
|
-
throw new Error(`ldr: parts CDN ${r.status}`);
|
|
3774
|
-
let buf = new Uint8Array(await r.arrayBuffer());
|
|
3775
|
-
if (r.status === 200)
|
|
3816
|
+
let buf = full.get(g.file);
|
|
3817
|
+
if (buf)
|
|
3776
3818
|
buf = buf.subarray(g.start, g.end);
|
|
3777
|
-
|
|
3819
|
+
else {
|
|
3820
|
+
const r = await f(new URL(idx.archives[g.file], cdn).href, { headers: { Range: `bytes=${g.start}-${g.end - 1}`, "Accept-Encoding": "identity" } });
|
|
3821
|
+
if (!r.ok)
|
|
3822
|
+
throw new Error(`ldr: parts CDN ${r.status}`);
|
|
3823
|
+
requests++;
|
|
3824
|
+
buf = new Uint8Array(await r.arrayBuffer());
|
|
3825
|
+
bytes += buf.byteLength;
|
|
3826
|
+
if (r.status === 200) {
|
|
3827
|
+
full.set(g.file, buf);
|
|
3828
|
+
buf = buf.subarray(g.start, g.end);
|
|
3829
|
+
}
|
|
3830
|
+
}
|
|
3778
3831
|
for (const t of g.items) {
|
|
3779
3832
|
const raw = decompress2(buf.subarray(t.off - g.start, t.off - g.start + t.len));
|
|
3780
3833
|
const ab = raw.buffer.slice(raw.byteOffset, raw.byteOffset + raw.byteLength);
|
|
@@ -3785,7 +3838,7 @@ async function loadPartsOnce(names, o) {
|
|
|
3785
3838
|
await Promise.all(Array.from({ length: Math.min(o.concurrency ?? 24, groups.length) }, worker));
|
|
3786
3839
|
const shards = want.filter((n) => shardCache.has(cdn + n)).map((n) => shardCache.get(cdn + n));
|
|
3787
3840
|
const pack = shards.length ? mergePacks(shards, { colors: idx.colors }) : decodePack(emptyPack(idx.colors));
|
|
3788
|
-
return { pack, missing, requests
|
|
3841
|
+
return { pack, missing, requests, bytes };
|
|
3789
3842
|
}
|
|
3790
3843
|
function emptyPack(colors) {
|
|
3791
3844
|
const h = new TextEncoder().encode(JSON.stringify({ version: 1, weld: true, parts: {}, studKinds: {}, colors }));
|
|
@@ -3887,10 +3940,10 @@ async function prepareModel(source, o = {}) {
|
|
|
3887
3940
|
return { insts, pack, missing, requests, bytes, cull, timings: { fetchModel: t1 - t0, parse: t2 - t1, parts: t3 - t2, ...cull ? { cull: performance.now() - t3 } : {} } };
|
|
3888
3941
|
}
|
|
3889
3942
|
|
|
3890
|
-
// ../../../../../../../tmp/ldr-build-
|
|
3891
|
-
var load_worker_gen_default = 'var bt=ArrayBuffer,W=Uint8Array,de=Uint16Array,yt=Int16Array;var be=Int32Array,Ee=function(e,t,n){if(W.prototype.slice)return W.prototype.slice.call(e,t,n);if(t==null||t<0)t=0;if(n==null||n>e.length)n=e.length;var r=new W(n-t);return r.set(e.subarray(t,n)),r},ce=function(e,t,n,r){if(W.prototype.fill)return W.prototype.fill.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;for(;n<r;++n)e[n]=t;return e},xt=function(e,t,n,r){if(W.prototype.copyWithin)return W.prototype.copyWithin.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;while(n<r)e[t++]=e[n++]};var wt=["invalid zstd data","window size too large (>2046MB)","invalid block type","FSE accuracy too high","match distance too far back","unexpected EOF"],K=function(e,t,n){var r=Error(t||wt[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,K);if(!n)throw r;return r},je=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},At=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},Mt=function(e,t){var n=e[0]|e[1]<<8|e[2]<<16;if(n==3126568&&e[3]==253){var r=e[4],s=r>>5&1,o=r>>2&1,i=r&3,l=r>>6;if(r&8)K(0);var a=6-s,c=i==3?4:i,f=je(e,a,c);a+=c;var m=l?1<<l:s,h=je(e,a,m)+(l==1&&256),x=h;if(!s){var T=1<<10+(e[5]>>3);x=T+(T>>3)*(e[5]&7)}if(x>2145386496)K(1);var u=new W((t==1?h||x:t?0:x)+12);return u[0]=1,u[4]=4,u[8]=8,{b:a+m,y:0,l:0,d:f,w:t&&t!=1?t:u.subarray(12),e:x,o:new be(u.buffer,0,3),u:h,c:o,m:Math.min(131072,x)}}else if((n>>4|e[3]<<20)==25481893)return At(e,4)+8;K(0)},re=function(e){var t=0;for(;1<<t<=e;++t);return t-1},ue=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)K(3);var o=1<<s,i=o,l=-1,a=-1,c=-1,f=o,m=new bt(512+(o<<2)),h=new yt(m,0,256),x=new de(m,0,256),T=new de(m,512,o),u=512+(o<<1),b=new W(m,u,o),S=new W(m,u+o);while(l<255&&i>0){var d=re(i+1),g=r>>3,p=(1<<d+1)-1,B=(e[g]|e[g+1]<<8|e[g+2]<<16)>>(r&7)&p,y=(1<<d)-1,v=p-i-1,E=B&y;if(E<v)r+=d,B=E;else if(r+=d+1,B>y)B-=v;if(h[++l]=--B,B==-1)i+=B,b[--f]=l;else i-=B;if(!B)do{var D=r>>3;a=(e[D]|e[D+1]<<8)>>(r&7)&3,r+=2,l+=a}while(a==3)}if(l>255||i)K(0);var C=0,U=(o>>1)+(o>>3)+3,X=o-1;for(var H=0;H<=l;++H){var M=h[H];if(M<1){x[H]=-M;continue}for(c=0;c<M;++c){b[C]=H;do C=C+U&X;while(C>=f)}}if(C)K(0);for(c=0;c<o;++c){var A=x[b[c]]++,L=S[c]=s-re(A);T[c]=(A<<L)-o}return[r+7>>3,{b:s,s:b,n:S,t:T}]},vt=function(e,t){var n=0,r=-1,s=new W(292),o=e[t],i=s.subarray(0,256),l=s.subarray(256,268),a=new de(s.buffer,268);if(o<128){var c=ue(e,t+1,6),f=c[0],m=c[1];t+=o;var h=f<<3,x=e[t];if(!x)K(0);var T=0,u=0,b=m.b,S=b,d=(++t<<3)-8+re(x);for(;;){if(d-=b,d<h)break;var g=d>>3;if(T+=(e[g]|e[g+1]<<8)>>(d&7)&(1<<b)-1,i[++r]=m.s[T],d-=S,d<h)break;g=d>>3,u+=(e[g]|e[g+1]<<8)>>(d&7)&(1<<S)-1,i[++r]=m.s[u],b=m.n[T],T=m.t[T],S=m.n[u],u=m.t[u]}if(++r>255)K(0)}else{r=o-127;for(;n<r;n+=2){var p=e[++t];i[n]=p>>4,i[n+1]=p&15}++t}var B=0;for(n=0;n<r;++n){var y=i[n];if(y>11)K(0);B+=y&&1<<y-1}var v=re(B)+1,E=1<<v,D=E-B;if(D&D-1)K(0);i[r++]=re(D)+1;for(n=0;n<r;++n){var y=i[n];++l[i[n]=y&&v+1-y]}var C=new W(E<<1),U=C.subarray(0,E),X=C.subarray(E);a[v]=0;for(n=v;n>0;--n){var H=a[n];ce(X,n,H,a[n-1]=H+l[n]*(1<<v-n))}if(a[0]!=E)K(0);for(n=0;n<r;++n){var M=i[n];if(M){var A=a[M];ce(U,n,A,a[M]=A+(1<<v-M))}}return[t,{n:X,b:v,s:U}]},Tt=ue(new W([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],Ct=ue(new W([33,20,196,24,99,140,33,132,16,66,8,33,132,16,66,8,33,68,68,68,68,68,68,68,68,36,9]),0,6)[1],Et=ue(new W([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],Ve=function(e,t){var n=e.length,r=new be(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Se=new W(new be([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),St=Ve(Se,0),Pe=new W(new be([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),Pt=Ve(Pe,3),le=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,l=-n.b;if(!o)K(0);var a=0,c=n.b,f=(r<<3)-8+re(o)-c,m=-1;for(;f>l&&m<s;){var h=f>>3,x=(e[h]|e[h+1]<<8|e[h+2]<<16)>>(f&7);a=(a<<c|x)&i,t[++m]=n.s[a],f-=c=n.n[a]}if(f!=l||m+1!=s)K(0)},Lt=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,l=o+i;le(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),le(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),le(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,l),n),le(e.subarray(r),t.subarray(l),n)},kt=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var l=o>>3|e[s+1]<<5|e[s+2]<<13,a=(s+=3)+l;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return ce(n,e[s],t.y,t.y+=l),n;return ce(new W(l),e[s])}if(a>e.length)return;if(i==0){if(t.b=a,n)return n.set(e.subarray(s,a),t.y),t.y+=l,n;return Ee(e,s,a)}if(i==2){var c=e[s],f=c&3,m=c>>2&3,h=c>>4,x=0,T=0;if(f<2)if(m&1)h|=e[++s]<<4|(m&2&&e[++s]<<12);else h=c>>3;else if(T=m,m<2)h|=(e[++s]&63)<<4,x=e[s]>>6|e[++s]<<2;else if(m==2)h|=e[++s]<<4|(e[++s]&3)<<12,x=e[s]>>2|e[++s]<<6;else h|=e[++s]<<4|(e[++s]&63)<<12,x=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var u=n?n.subarray(t.y,t.y+t.m):new W(t.m),b=u.length-h;if(f==0)u.set(e.subarray(s,s+=h),b);else if(f==1)ce(u,e[s++],b);else{var S=t.h;if(f==2){var d=vt(e,s);x+=s-(s=d[0]),t.h=S=d[1]}else if(!S)K(0);(T?Lt:le)(e.subarray(s,s+=x),u.subarray(b),S)}var g=e[s++];if(g){if(g==255)g=(e[s++]|e[s++]<<8)+32512;else if(g>127)g=g-128<<8|e[s++];var p=e[s++];if(p&3)K(0);var B=[Ct,Et,Tt];for(var y=2;y>-1;--y){var v=p>>(y<<1)+2&3;if(v==1){var E=new W([0,0,e[s++]]);B[y]={s:E.subarray(2,3),n:E.subarray(0,1),t:new de(E.buffer,0,1),b:0}}else if(v==2)r=ue(e,s,9-(y&1)),s=r[0],B[y]=r[1];else if(v==3){if(!t.t)K(0);B[y]=t.t[y]}}var D=t.t=B,C=D[0],U=D[1],X=D[2],H=e[a-1];if(!H)K(0);var M=(a<<3)-8+re(H)-X.b,A=M>>3,L=0,V=(e[A]|e[A+1]<<8)>>(M&7)&(1<<X.b)-1;A=(M-=U.b)>>3;var k=(e[A]|e[A+1]<<8)>>(M&7)&(1<<U.b)-1;A=(M-=C.b)>>3;var N=(e[A]|e[A+1]<<8)>>(M&7)&(1<<C.b)-1;for(++g;--g;){var P=X.s[V],w=X.n[V],O=C.s[N],F=C.n[N],R=U.s[k],z=U.n[k];A=(M-=R)>>3;var j=1<<R,I=j+((e[A]|e[A+1]<<8|e[A+2]<<16|e[A+3]<<24)>>>(M&7)&j-1);A=(M-=Pe[O])>>3;var G=Pt[O]+((e[A]|e[A+1]<<8|e[A+2]<<16)>>(M&7)&(1<<Pe[O])-1);A=(M-=Se[P])>>3;var _=St[P]+((e[A]|e[A+1]<<8|e[A+2]<<16)>>(M&7)&(1<<Se[P])-1);if(A=(M-=w)>>3,V=X.t[V]+((e[A]|e[A+1]<<8)>>(M&7)&(1<<w)-1),A=(M-=F)>>3,N=C.t[N]+((e[A]|e[A+1]<<8)>>(M&7)&(1<<F)-1),A=(M-=z)>>3,k=U.t[k]+((e[A]|e[A+1]<<8)>>(M&7)&(1<<z)-1),I>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=I-=3;else{var Y=I-(_!=0);if(Y){if(I=Y==3?t.o[0]-1:t.o[Y],Y>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=I}else I=t.o[0]}for(var y=0;y<_;++y)u[L+y]=u[b+y];L+=_,b+=_;var q=L-I;if(q<0){var J=-q,ee=t.e+q;if(J>G)J=G;for(var y=0;y<J;++y)u[L+y]=t.w[ee+y];L+=J,G-=J,q=0}for(var y=0;y<G;++y)u[L+y]=u[q+y];L+=G}if(L!=b)while(b<u.length)u[L++]=u[b++];else L=u.length;if(n)t.y+=L;else u=Ee(u,0,L)}else if(n){if(t.y+=h,b)for(var y=0;y<h;++y)u[y]=u[b+y]}else if(b)u=Ee(u,b);return t.b=a,u}K(2)},Bt=function(e,t){if(e.length==1)return e[0];var n=new W(t);for(var r=0,s=0;r<e.length;++r){var o=e[r];n.set(o,s),s+=o.length}return n};function ye(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=Mt(e,r||t);if(typeof i=="object"){if(r){if(t=null,i.w.length==i.u)n.push(t=i.w),o+=i.u}else n.push(t),i.e=0;for(;!i.l;){var l=kt(e,i,t);if(!l)K(5);if(t)i.e=i.y;else n.push(l),o+=l.length,xt(i.w,0,l.length),i.w.set(l,i.w.length-l.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return Bt(n,o)}async function It(e){let t=e instanceof Uint8Array?e:new Uint8Array(e),n=(r)=>r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength);if(t[0]===40&&t[1]===181&&t[2]===47&&t[3]===253)return n(ye(t));if(t[0]===31&&t[1]===139)return new Response(new Blob([t]).stream().pipeThrough(new DecompressionStream("gzip"))).arrayBuffer();return n(t)}async function He(e){return new TextDecoder().decode(await It(e))}var Ge=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split("/").pop()||"main.ldr").replace(/\\.(zst|gz)$/i,"")||"main.ldr";function xe(e){let t=new DataView(e).getUint32(0,!0),n=JSON.parse(new TextDecoder().decode(new Uint8Array(e,4,t))),r=4+t;return{header:n,arr:(o)=>o&&(o[2]==="f32"?new Float32Array(e,r+o[0],o[1]):o[2]==="u16"?new Uint16Array(e,r+o[0],o[1]):o[2]==="u8"?new Uint8Array(e,r+o[0],o[1]):new Uint32Array(e,r+o[0],o[1])),bytes:e.byteLength,buffer:e}}var Z=(e)=>e.trim().toLowerCase().replace(/\\\\/g,"/").replace(/\\/+/g,"/");function Le(e){if(/^0x/i.test(e))return parseInt(e,16);return+e}var _e=/^~?\\s*moved\\s+to\\s+(.+)$/i,Ft=new Set(["FILE","NOFILE","!DATA","!:","STEP","BFC","ROTSTEP","BUFEXCHG","!TEXMAP"]),Qe=new Set(["part","subpart","primitive","8_primitive","48_primitive","shortcut","helper"]),Rt=new Set(["model","submodel","configuration"]),Dt=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function We(e){let t=Dt.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,"");return Qe.has(n)||Rt.has(n)?n:void 0}function Ut(e){let t=[],n=0;while(n<e.length){while(e[n]===" "||e[n]==="\\t")n++;if(n>=e.length)break;if(e[n]===\'"\'){let r="";n++;while(n<e.length&&e[n]!==\'"\'){if(e[n]==="\\\\"&&n+1<e.length)n++;r+=e[n++]}n++,t.push(r)}else{let r=n;while(r<e.length&&e[r]!==" "&&e[r]!=="\\t")r++;t.push(e.slice(n,r)),n=r}}return t}function zt(e,t=!1){let n=/^\\s*(\\S+)\\s+(.*)$/.exec(e);if(!n)return null;let r=n[1].toUpperCase(),s=r==="PLANAR"?9:r==="CYLINDRICAL"?10:r==="SPHERICAL"?11:0;if(!s)return null;let o=n[2].trim().split(/\\s+/);if(o.length<s+1)return null;let i=o.slice(0,s).map(Number);if(!i.every(Number.isFinite))return null;let l=n[2].trim();for(let m=0;m<s;m++)l=l.replace(/^\\S+\\s*/,"");let a=Ut(l);if(!a.length)return null;let c={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:a[0]};if(s>=10)c.a=i[9];if(s===11)c.b=i[10];let f=a.findIndex((m,h)=>h>0&&m.toUpperCase()==="GLOSSMAP");if(f>0&&a[f+1])c.glossmap=a[f+1];if(t)c.next=!0;return c}var Ot=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,""),n=t+"=".repeat((4-t.length%4)%4),r=atob(n),s=new Uint8Array(r.length);for(let o=0;o<r.length;o++)s[o]=r.charCodeAt(o);return s};function Nt(e){let t=e.length,n=1,r=(c)=>c===32||c===9,s=()=>{while(n<t&&r(e.charCodeAt(n)))n++;let c=n;while(n<t&&!r(e.charCodeAt(n)))n++;return c<n?e.slice(c,n):null},o=s();if(o===null)return null;let i=Array(12);for(let c=0;c<12;c++){let f=s();if(f===null)return null;i[c]=+f}while(n<t&&r(e.charCodeAt(n)))n++;if(n>=t)return null;let l=e.slice(n),a=/[ \\t]{2,}|\\t/.test(l)?l.split(/\\s+/).join(" "):l;return{t:1,color:Le(o),m:i,file:Z(a)}}function Ke(e){let t=+e[0];if(!(t>=1&&t<=5)||e.length<2)return null;let n=Le(e[1]),r=e.slice(2).map(Number);if(t===1)return{t:1,color:n,m:r.slice(0,12),file:Z(e.slice(14).join(" "))};if(t===2)return{t:2,color:n,p:r.slice(0,6)};if(t===3)return{t:3,color:n,p:r.slice(0,9)};if(t===4)return{t:4,color:n,p:r.slice(0,12)};return{t:5,color:n,p:r.slice(0,12)}}function et(e,t="main.ldr",n={}){let r=!!n.geometryText,s=new Map,o=null,i="",l,a=null,c=[],f=null,m=()=>{if(!a)return;let d=Ot(a.chunks.join("")),g=d[0]===137&&d[1]===80&&d[2]===78&&d[3]===71;(l??=new Map).set(Z(a.name),{name:a.name,bytes:d,...g?{mime:"image/png"}:{}}),a=null},h=!0,x=(d)=>{if(m(),o={name:Z(d),cmds:[]},s.set(o.name,o),!i)i=o.name;c=[],f=null,h=!0},T=!1,u=!1,b=()=>{if(u)return;u=!0,s.clear(),o=null,i=""},S=(d,g)=>{if(f){d.tex=f,f=null;return}let p=c[c.length-1];if(!p)return;if(p.fallback){if(!g)d.fallback=!0}else d.tex=p.map};for(let d of e.split(`\n`)){let g=d.trim();if(!g)continue;if(r&&g.charCodeAt(0)>=50&&g.charCodeAt(0)<=53&&(g.charCodeAt(1)===32||g.charCodeAt(1)===9)){if(a||T)continue;if(!o)x(t);let v=g.slice(2).trimStart(),E=v.search(/\\s/),D={t:g.charCodeAt(0)-48,color:Le(E<0?v:v.slice(0,E)),p:[],src:g};S(D,!1),o.cmds.push(D),h=!1;continue}if(g.charCodeAt(0)===48&&(g.charCodeAt(1)===32||g.charCodeAt(1)===9)){let v=2;while(g.charCodeAt(v)===32||g.charCodeAt(v)===9)v++;let E=v;while(E<g.length&&g.charCodeAt(E)!==32&&g.charCodeAt(E)!==9)E++;let D=g.slice(v,E);if(!Ft.has(D)){if(T||a)continue;if(!o)x(t);let C=g.slice(v),U={t:0,text:C};if(D.charCodeAt(0)===33)U.meta=D;if(f=null,h&&!o.org){let H=We(C);if(H)o.org=H}let X=C.match(_e);if(X&&!o.movedTo){let H=X[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(H))H+=".dat";o.movedTo=Z(H)}o.cmds.push(U);continue}}if(g.charCodeAt(0)===49&&(g.charCodeAt(1)===32||g.charCodeAt(1)===9)&&!a&&!T){let v=Nt(g);if(v){if(!o)x(t);S(v,!1),o.cmds.push(v),h=!1;continue}}let p=g.split(/\\s+/);if(+p[0]===0){let v=g.slice(1).trim();if(p[1]==="FILE"){b(),T=!1,x(v.slice(5));continue}if(p[1]==="NOFILE"){m(),o=null,T=!0;continue}if(p[1]==="!DATA"){b(),m(),o=null,T=!1,a={name:v.slice(5).trim(),chunks:[]};continue}if(T)continue;if(a){if(p[1]==="!:")a.chunks.push(p.slice(2).join(""));continue}if(!o)x(t);let E={t:0,text:v};if(p[1]==="STEP")E.step=!0,c=[],f=null;else if(p[1]==="BFC")E.bfc=p.slice(2).join(" ");else if(p[1]==="ROTSTEP")if(E.meta="ROTSTEP",E.step=!0,c=[],f=null,(p[2]??"").toUpperCase()==="END")E.rotstep={x:0,y:0,z:0,mode:"END"};else{let C=(p[5]??"REL").toUpperCase();E.rotstep={x:+p[2]||0,y:+p[3]||0,z:+p[4]||0,mode:["REL","ABS","ADD"].includes(C)?C:"REL"}}else if(p[1]==="BUFEXCHG"){E.meta="BUFEXCHG";let C=(p[2]??"").toUpperCase();E.bufexchg={op:C==="RETRIEVE"?"RETRIEVE":"STORE",buf:p[3]??"A"}}else if(p[1]?.startsWith("!"))E.meta=p[1];if(h&&!o.org){let C=We(v);if(C)o.org=C}if(p[1]==="!TEXMAP"){let C=(p[2]??"").toUpperCase();if(f=null,C==="START"||C==="NEXT"){let U=zt(v.replace(/^!TEXMAP\\s+\\S+/i,""),C==="NEXT");if(E.texmap={op:C,...U?{map:U}:{}},U)if((o.texmaps??=[]).push(U),C==="START")c.push({map:U,fallback:!1});else f=U}else if(C==="FALLBACK"){E.texmap={op:C};let U=c[c.length-1];if(U)U.fallback=!0}else if(C==="END")E.texmap={op:C},c.pop()}else if(p[1]==="!:"){f=null;let C=Ke(p.slice(2));if(C)S(C,!0),E.geom=C}else f=null;let D=v.match(_e);if(D&&!o.movedTo){let C=D[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(C))C+=".dat";o.movedTo=Z(C)}o.cmds.push(E);continue}if(a||T)continue;if(!o)x(t);let y=Ke(p);if(!y)continue;S(y,!1),o.cmds.push(y),h=!1}return m(),l?{main:i,files:s,data:l}:{main:i,files:s}}var cn=Math.PI/180;function tt(e,t){let n=(r)=>[t[3]*r[0]+t[4]*r[1]+t[5]*r[2]+t[0],t[6]*r[0]+t[7]*r[1]+t[8]*r[2]+t[1],t[9]*r[0]+t[10]*r[1]+t[11]*r[2]+t[2]];return{...e,p1:n(e.p1),p2:n(e.p2),p3:n(e.p3)}}function nt(e,t){let[n,r,s,o,i,l,a,c,f,m,h,x]=e,[T,u,b,S,d,g,p,B,y,v,E,D]=t;return[o*T+i*u+l*b+n,a*T+c*u+f*b+r,m*T+h*u+x*b+s,o*S+i*p+l*v,o*d+i*B+l*E,o*g+i*y+l*D,a*S+c*p+f*v,a*d+c*B+f*E,a*g+c*y+f*D,m*S+h*p+x*v,m*d+h*B+x*E,m*g+h*y+x*D]}var ke=[0,0,0,1,0,0,0,1,0,0,0,1];var Xe=new WeakMap,$t=/^(s|8|48)\\//;function Be(e,t){let n=e.files.get(Z(t));if(!n)return"part";let r=Xe.get(n);if(r)return r;if(n.org)r=Qe.has(n.org)?"part":"model";else if(n.name===e.main)r="model";else r=n.cmds.some((s)=>s.t>=2||s.t===0&&!!s.geom||s.t===1&&$t.test(s.file))?"part":"model";return Xe.set(n,r),r}var Ze=new WeakMap;function rt(e){let t=Ze.get(e);if(t)return t;t=[];let n=0;for(let r of e.cmds){if(r.t===0&&r.step){n++;continue}if((r.t>=2||r.t===0&&r.geom&&r.geom.t>=2)&&t[t.length-1]!==n)t.push(n)}return Ze.set(e,t),t}var Ye=(e)=>e>16777215?"0x"+e.toString(16).toUpperCase():String(e),jt=(e)=>e.t===0?"0 "+e.text:e.t===1?`1 ${Ye(e.color)} ${e.m.join(" ")} ${e.file}`:e.src?e.src:`${e.t} ${Ye(e.color)} ${e.p.join(" ")}`,Ie=(e,t)=>`${Z(e)}#${t}`;function Vt(e,t){let n=[],r=0,s=(o)=>!!o&&o.t===0&&o.texmap?.op==="NEXT";for(let o of e.cmds){if(o.t===0){if(o.step){r++;continue}if(o.bfc!==void 0){n.push(o);continue}if(r!==t)continue;if(o.texmap)n.push(o);else if(o.geom){if(o.geom.t>=2)n.push(o);else if(s(n[n.length-1]))n.pop()}continue}if(r!==t)continue;if(o.t===1){if(s(n[n.length-1]))n.pop();continue}n.push(o)}return{name:Ie(e.name,t),cmds:n}}function st(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Vt(e,t).cmds.map(jt)].join(`\n`)+`\n`}function Ht(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,"0")}function ot(e){let[t,n,r,s,o,i,l,a,c,f,m,h]=e,x=a*h-c*m,T=-(l*h-c*f),u=l*m-a*f,b=s*x+o*T+i*u;if(!Number.isFinite(b)||Math.abs(b)<0.000000000001)return null;let S=1/b,d=[x*S,-(o*h-i*m)*S,(o*c-i*a)*S,T*S,(s*h-i*f)*S,-(s*c-i*l)*S,u*S,-(s*m-o*f)*S,(s*a-o*l)*S];return[-(d[0]*t+d[1]*n+d[2]*r),-(d[3]*t+d[4]*n+d[5]*r),-(d[6]*t+d[7]*n+d[8]*r),...d]}var Gt=(e)=>String(+e.toFixed(6)||0),Je=(e)=>\'"\'+e.replace(/\\\\/g,"\\\\\\\\").replace(/"/g,"\\\\\\"")+\'"\';function it(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!=="PLANAR"?[t.a??360]:[],...t.method==="SPHERICAL"?[t.b??180]:[]].map(Gt).join(" "),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${Je(t.texture)}${t.glossmap?" GLOSSMAP "+Je(t.glossmap):""}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${Z(e)}\n0 !TEXMAP END\n`;return{name:`${Z(e)}#tex-${Ht(r)}`,source:r}}var _t=(e,t)=>{let n=[,,,,,,,,,];for(let r=0;r<3;r++)for(let s=0;s<3;s++)n[r*3+s]=e[r*3]*t[s]+e[r*3+1]*t[3+s]+e[r*3+2]*t[6+s];return n};function Wt(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),l=Math.cos(t*r),a=Math.sin(n*r),c=Math.cos(n*r);return[l*c,-l*a,i,o*a+s*i*c,o*c-s*i*a,-s*l,s*a-o*i*c,s*c+o*i*a,o*l]}var qe=new WeakMap;function at(e){let t=qe.get(e);if(t)return t;let n=[],r=null;for(let s of e.cmds){if(s.t!==0||!s.step)continue;let o=s.rotstep;if(o)if(o.mode==="END")r=null;else{let i=Wt(o.x,o.y,o.z);r=o.mode==="ABS"?{abs:!0,m:i,rotstep:o}:o.mode==="ADD"&&r?{abs:r.abs,m:_t(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),qe.set(e,n),n}var lt=999999,ct=(e)=>e.map((t)=>String(t).padStart(6,"0")).join(".")+"~";function Kt(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,l=new Map,a=0,c=(m,h)=>{let x=m.name+"#"+h,T=l.get(x);if(!T){let u;T=Object.assign(()=>u??=st(m,h),{file:m,step:h}),l.set(x,T)}return T},f=(m,h,x,T,u,b,S,d,g=null,p=[],B=[])=>{let y=m.files.get(h);if(!y||S>r)return;let v=0,E=S>0?++a:0,D=i&&E?[...p,E]:p,C=i&&E?[...B,x]:B,U=i&&!g?new Map:null,X=-1,H=0,M=(P,w,O,F,R,z)=>{if(X!==v)X=v,H=0;let j=U?.get(v+"|"+w);if(j)return j.n++,f(P,P===m?w:P.main,O,F,u+"/"+w,[...R,lt],S+1,z,[...R,lt],D,C);let I=[...R,H++],G=n.length;f(P,P===m?w:P.main,O,F,u+"/"+w,I,S+1,z,g,D,C),U?.set(v+"|"+w,{n:1,from:G,to:n.length})},A=at(y),L=s?rt(y):[],V=0,k=(P,w,O,F,R,z,j)=>{if(g)F=g;let I={part:P,color:w,m:O,step:F[0],steps:F,localStep:R,path:u};if(E){if(I.sub=E,i)I.subPath=D,I.subMats=C}if(z)I.embedded=!0;if(j){let _=it(P,j);I.texPart=_.name,I.texSource=_.source}let G=A[R];if(G)I.view=G;return n.push(I),I},N=(P)=>{while(V<L.length&&L[V]<=P){let w=L[V++];k(Ie(y.name,w),T,x,[...b,w],w,!1,null).source=c(y,w)}};for(let P of y.cmds){if(P.t===0&&P.step){v++;continue}let w=P;if(w.t>=2||w.t===0&&w.geom&&w.geom.t>=2){N(v);continue}if(w.t===0)if(o&&w.geom?.t===1)w=w.geom;else continue;if(w.t!==1)continue;if(o&&w.fallback)continue;let O=w.color===16?T:w.color,F=nt(x,w.m),R=[...b,v],z=o?w.tex??d:null,j=z?ot(w.m):null,I=z&&j?tt(z,j):null;if(m.files.has(w.file)){if(Be(m,w.file)==="model"){M(m,w.file,F,O,R,I);continue}k(w.file,O,F,R,v,!0,I);continue}let G=t.resolveModel?.(w.file);if(G){M(G,w.file,F,O,R,I);continue}k(w.file,O,F,R,v,!1,I)}if(N(1/0),U){for(let P of U.values())if(P.n>1)for(let w=P.from;w<P.to;w++)n[w].mult??=P.n}};if(Be(e,e.main)==="part"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...ke],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return f(e,e.main,ke,16,e.main,[],0,null),n}function ut(e,t="main.ldr",n){return Kt(et(e,t,{geometryText:!0}),n)}function Xt(e,t){let n=new Map,r=null,s=!1;for(let o of e.split(/\\r?\\n/)){let i=/^\\s*0\\s+FILE\\s+(.+)$/i.exec(o);if(i){if(!s)n.clear();s=!0,r=[],n.set(Z(i[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(o)){if(!s)n.clear();s=!0,r=null;continue}if(!r){if(s)continue;r=[],n.set(Z(t),r)}let l=o.trim().replace(/\\s+/g," ");if(l)r.push(l)}return n}var Zt=(e)=>{if(!e.startsWith("1 "))return null;let t=e.split(" ");return t.length>=15?Z(t.slice(14).join(" ")):null};function Yt(e){let t=2166136261,n=1523705862;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);t=Math.imul(t^s,16777619),n=Math.imul(n^s,16777629)^n>>>15}return(t>>>0).toString(16).padStart(8,"0")+(n>>>0).toString(16).padStart(8,"0")}function ft(e,t,n="main.ldr"){let r=Xt(e,n),s=new Map;for(let o of t){let i=Z(o);if(!r.has(i)||s.has(i))continue;let l=new Set([i]),a=[i];while(a.length)for(let f of r.get(a.pop())){let m=Zt(f);if(m&&r.has(m)&&!l.has(m))l.add(m),a.push(m)}let c=[i,...[...l].filter((f)=>f!==i).sort()].map((f)=>"0 FILE "+(f===i?"":f)+`\n`+r.get(f).join(`\n`)).join(`\n`);s.set(i,`emb/${Yt(c)}.dat`)}return s}var pt=(e,t=0)=>Math.abs(e[t+7]-1)<0.001&&Math.abs(e[t+4])<0.001&&Math.abs(e[t+10])<0.001,mt=new WeakMap;function Fe(e,t){let n=mt.get(e);if(!n)mt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),l=[],a=[];s.studs.forEach((h,x)=>{l.push(h[0]),a.push(h[1]);for(let T=0;T<12;T++)i[x*12+T]=h[2+T]});let c=null,f=0,m=0;if(s.mask){f=s.mask[0],m=s.mask[1];let h=s.mask[2];c=new Uint8Array(h.length);for(let x=0;x<h.length;x++)c[x]=h.charCodeAt(x)===49?1:0}return n.set(t,r={nStuds:o,studM:i,kind:l,color:a,mask:c,nx:f,nz:m}),r}var ie=1073741824;class Re{a;b;c;vals;used;mask;size=0;constructor(e=1024){let t=1024;while(t<e*2)t*=2;this.a=new Int32Array(t),this.b=new Int32Array(t),this.c=new Int32Array(t),this.vals=new Int32Array(t),this.used=new Uint8Array(t),this.mask=t-1}slot(e,t,n){let r=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return r^=r>>>15,r=Math.imul(r,739982445),r^=r>>>12,r&this.mask}get(e,t,n){let r=this.slot(e,t,n),s=this.used,o=this.a,i=this.b,l=this.c;for(;;){if(!s[r])return-1;if(o[r]===e&&i[r]===t&&l[r]===n)return this.vals[r];r=r+1&this.mask}}put(e,t,n,r){if((this.size+1)*2>this.used.length)this.grow();let s=this.slot(e,t,n),o=this.used,i=this.a,l=this.b,a=this.c;for(;;){if(!o[s])return o[s]=1,i[s]=e,l[s]=t,a[s]=n,this.vals[s]=r,this.size++,-1;if(i[s]===e&&l[s]===t&&a[s]===n){let c=this.vals[s];return this.vals[s]=r,c}s=s+1&this.mask}}grow(){let{a:e,b:t,c:n,vals:r,used:s}=this,o=s.length*2;this.a=new Int32Array(o),this.b=new Int32Array(o),this.c=new Int32Array(o),this.vals=new Int32Array(o),this.used=new Uint8Array(o),this.mask=o-1,this.size=0;for(let i=0;i<s.length;i++)if(s[i])this.put(e[i],t[i],n[i],r[i])}}var we=(e,t,n)=>e>-ie&&e<ie&&t>-ie&&t<ie&&n>-ie&&n<ie,fe=2147483647;function Jt(e,t,n){let s=[],o=[],i=[],l=[],a=[],c=[],f=[],m=[],h=new Re(e.length*2),x=[],T=[];for(let M=0;M<e.length;M++){let A=e[M],L=A.m,V=t.parts[A.part];if(!V||!V.mask||!pt(L))continue;let k=V.bbox,N=1/0,P=-1/0,w=1/0,O=-1/0;for(let z=0;z<2;z++)for(let j=0;j<2;j++){let I=z?k[3]:k[0],G=j?k[5]:k[2],_=L[0]+L[3]*I+L[5]*G,Y=L[2]+L[9]*I+L[11]*G;if(_<N)N=_;if(_>P)P=_;if(Y<w)w=Y;if(Y>O)O=Y}let F=a.length;s.push(N),o.push(P),i.push(w),l.push(O),a.push(M),c.push(Fe(t,A.part)),f.push(k[0]),m.push(k[2]);let R=Math.round((L[1]+k[4])*2);for(let z=Math.floor(N/40);z<=Math.floor(P/40);z++)for(let j=Math.floor(w/40);j<=Math.floor(O/40);j++){if(!we(R,z,j))continue;let I=T.length;T.push(F),x.push(h.put(R,z,j,I))}}let u=[0,5,-5,5,-5],b=[0,5,5,-5,-5],S=NaN,d=NaN,g=NaN,p=-1,B=(M,A,L,V)=>{let k=Math.round(A*2),N=Math.floor(M/40),P=Math.floor(L/40);if(!we(k,N,P))return fe;let w=fe;if(k!==S||N!==d||P!==g)S=k,d=N,g=P,p=h.get(k,N,P);for(let O=p;O>=0;O=x[O]){let F=T[O];if(a[F]===V||!(M-6>=s[F]-0.5&&M+6<=o[F]+0.5&&L-6>=i[F]-0.5&&L+6<=l[F]+0.5))continue;let R=e[a[F]].m,z=c[F],j=f[F],I=m[F],G=M-R[0],_=A-R[1],Y=L-R[2],q=R[3]*G+R[6]*_+R[9]*Y,J=R[5]*G+R[8]*_+R[11]*Y,{nx:ee,nz:se,mask:ae}=z,oe=!0;for(let Q=0;Q<5;Q++){let te=Math.floor((q+u[Q]-j)/20),ne=Math.floor((J+b[Q]-I)/20);if(te<0||ne<0||te>=ee||ne>=se||ae[te*se+ne]!==1){oe=!1;break}}if(oe){if(!n)return 0;let Q=n[a[F]];if(Q<w)w=Q}}return w},y=0;for(let M of e){let A=Fe(t,M.part);if(A)y+=A.nStuds}let v=new Uint8Array(y),E=new Uint8Array(y),D=new Re(y),C=0,U=n?new Int32Array(y).fill(fe):void 0;for(let M=0,A=0;M<e.length;M++){let L=e[M],V=Fe(t,L.part);if(!V)continue;let k=L.m,N=V.studM,P=k[0],w=k[1],O=k[2],F=k[3],R=k[4],z=k[5],j=k[6],I=k[7],G=k[8],_=k[9],Y=k[10],q=k[11];for(let J=0;J<V.nStuds;J++,A++){let ee=J*12,se=N[ee+4],ae=N[ee+7],oe=N[ee+10];if(!(Math.abs(j*se+I*ae+G*oe-1)<0.001&&Math.abs(F*se+R*ae+z*oe)<0.001&&Math.abs(_*se+Y*ae+q*oe)<0.001))continue;E[A]=1;let Q=N[ee],te=N[ee+1],ne=N[ee+2],De=P+F*Q+R*te+z*ne,Ue=w+j*Q+I*te+G*ne,ze=O+_*Q+Y*te+q*ne,Oe=B(De,Ue,ze,M);if(Oe!==fe){if(v[A]=1,C++,U)U[A]=Oe}let me=Math.round(De),he=Math.round(Ue),ge=Math.round(ze);if(!we(me,he,ge))continue;if(!n){D.put(me,he,ge,1);continue}let Ne=n[M],$e=D.get(me,he,ge);if($e<0||Ne<$e)D.put(me,he,ge,Ne)}}let X=new Uint8Array(e.length),H=n?new Int32Array(e.length).fill(fe):void 0;for(let M=0;M<e.length;M++){let A=e[M],L=t.parts[A.part];if(!L||!L.under||!pt(A.m))continue;let V=L.bbox,k=Math.round((V[3]-V[0])/20),N=Math.round((V[5]-V[2])/20);if(!k||!N||k*N>4096)continue;let P=A.m,w=!0,O=0;for(let F=0;F<k&&w;F++)for(let R=0;R<N;R++){let z=V[0]+10+20*F,j=V[2]+10+20*R,I=P[0]+P[3]*z+P[5]*j,G=P[2]+P[9]*z+P[11]*j,_=Math.round(I),Y=Math.round(P[1]+V[4]),q=Math.round(G),J=we(_,Y,q)?D.get(_,Y,q):-1;if(J<0){w=!1;break}if(J>O)O=J}if(w){if(X[M]=1,H)H[M]=O}}return{nStuds:y,studHidden:v,studUp:E,underHidden:X,studsHidden:C,studHideStep:U,underHideStep:H}}function qt(e,t,n){let r=(a)=>n&&a.texPart&&t.parts[a.texPart]?a.texPart:a.part,s=e.map((a)=>({part:r(a),color:String(a.color),m:a.m,steps:a.steps})),o=s.map((a)=>ct(a.steps)),i=[...new Set(o)].sort(),l=new Map(i.map((a,c)=>[a,c]));return{all:s,stepOf:o.map((a)=>l.get(a)),nSteps:i.length}}function Ae(e,t,n=!0){let r=qt(e,t,n);return Jt(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Ce="https://ldr-demo.vercel.app/cdn/v1/",ve=new Map,Me=new Map;function gt(e=Ce,t=fetch){let n=ve.get(e);if(!n)n=t(e+"parts.json").then((r)=>{if(!r.ok)throw Error(`ldr: parts CDN index ${r.status} (${e}parts.json)`);return r.json()}),n.catch(()=>ve.delete(e)),ve.set(e,n);return n}var Qt=(e)=>Array.isArray(e)&&e.length===3&&typeof e[0]==="number"&&typeof e[1]==="number"&&(e[2]==="f32"||e[2]==="u16"||e[2]==="u8"||e[2]==="u32"),Te=(e,t)=>Qt(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>Te(n,t)):e&&typeof e==="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Te(r,t)])):e;function en(e,t={}){let n=[],r=0,s={},o={};for(let h of e){let x=h.buffer;if(!x)throw Error("ldr: mergePacks needs packs from decodePack/loadPack");let T=new DataView(x).getUint32(0,!0),u=new Uint8Array(x,4+T),b=r;n.push(u),r+=u.byteLength;let S=(4-r%4)%4;if(S)n.push(new Uint8Array(S)),r+=S;for(let[d,g]of Object.entries(h.header.parts??{}))if(!(d in s))s[d]=Te(g,b);for(let[d,g]of Object.entries(h.header.studKinds??{}))if(!(d in o))o[d]=Te(g,b)}let i=e[0]?.header??{version:1,weld:!0},l=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),a=(4-(4+l.length)%4)%4,c=4+l.length+a,f=new Uint8Array(c+r);new DataView(f.buffer).setUint32(0,l.length+a,!0),f.set(l,4),f.fill(32,4+l.length,c);let m=c;for(let h of n)f.set(h,m),m+=h.byteLength;return xe(f.buffer)}async function tn(e,t={}){e=[...e];try{return await ht(e,t)}catch(n){let r=t.cdn??Ce,s=t.fetch??fetch;ve.delete(r);let o=(i,l)=>s(i,{...l,cache:"reload"});try{return await ht(e,{...t,fetch:o})}catch{throw n}}}async function ht(e,t){let n=t.cdn??Ce,r=t.fetch??fetch,s=t.gap??16384,o=await gt(n,r),i=[...new Set([...e].map(Z))],l=[],a=[];for(let u of i){if(Me.has(n+u))continue;let b=o.parts[u];if(b)a.push({name:u,off:b[0],len:b[1],file:b[2]??0});else l.push(u)}a.sort((u,b)=>u.file-b.file||u.off-b.off);let c=[];for(let u of a){let b=c[c.length-1];if(b&&b.file===u.file&&u.off-b.end<=s)b.end=Math.max(b.end,u.off+u.len),b.items.push(u);else c.push({file:u.file,start:u.off,end:u.off+u.len,items:[u]})}let f=0,m=0,h=async()=>{while(m<c.length){let u=c[m++],b=await r(new URL(o.archives[u.file],n).href,{headers:{Range:`bytes=${u.start}-${u.end-1}`}});if(!b.ok)throw Error(`ldr: parts CDN ${b.status}`);let S=new Uint8Array(await b.arrayBuffer());if(b.status===200)S=S.subarray(u.start,u.end);f+=S.byteLength;for(let d of u.items){let g=ye(S.subarray(d.off-u.start,d.off-u.start+d.len)),p=g.buffer.slice(g.byteOffset,g.byteOffset+g.byteLength);Me.set(n+d.name,xe(p))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,c.length)},h));let x=i.filter((u)=>Me.has(n+u)).map((u)=>Me.get(n+u));return{pack:x.length?en(x,{colors:o.colors}):xe(nn(o.colors)),missing:l,requests:c.length,bytes:f}}function nn(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},colors:e})),n=(4-(4+t.length)%4)%4,r=new Uint8Array(4+t.length+n).fill(32);return new DataView(r.buffer).setUint32(0,t.length+n,!0),r.set(t,4),r.buffer}function rn(e,t){let n=t.header.parts;if(!n)return 0;let r=0;for(let s of e){let o=n[s.part]?.body?.tris;if(o)r+=o}return r}function sn(e,t,n){let r=0,s=0,o=!1,i=new Set;for(let l of e){let a=l.embedded?t.get(l.part):Z(l.part),c=a?n.parts[a]:void 0;if(!c)continue;if(c[3]!=null)o=!0,r+=c[3];if(!i.has(a))i.add(a),s+=c[1]}return{bodyTris:r,packBytes:s,known:o}}class pe extends Error{code="ldr-budget";bodyTris;packBytes;maxBodyTris;maxPackBytes;constructor(e){let t=[e.maxBodyTris!=null&&e.bodyTris>e.maxBodyTris?`${e.bodyTris} triangles (limit ${e.maxBodyTris})`:"",e.maxPackBytes!=null&&e.packBytes>e.maxPackBytes?`${(e.packBytes/1e6).toFixed(1)} MB parts pack (limit ${(e.maxPackBytes/1e6).toFixed(0)} MB)`:""].filter(Boolean).join(", ");super(`ldr: model exceeds device budget: ${t}`);this.name="BudgetError",this.bodyTris=e.bodyTris,this.packBytes=e.packBytes,this.maxBodyTris=e.maxBodyTris,this.maxPackBytes=e.maxPackBytes}}async function dt(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=gt(t.cdn??Ce,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(p)=>{if(!p.ok)throw Error(`ldr: ${p.status} fetching ${e}`);return He(await p.arrayBuffer())}),i=performance.now(),l=t.name??(t.text?"main.ldr":Ge(e)),a=ut(o,l,{looseGeometry:!1,callouts:t.callouts}),c=performance.now();t.onParsed?.(a),await s;let f=ft(o,new Set(a.filter((p)=>p.embedded).map((p)=>p.part)),l),m=(p,B)=>t.maxBodyTris!=null&&p>t.maxBodyTris||t.maxPackBytes!=null&&B>t.maxPackBytes;if(t.maxBodyTris!=null||t.maxPackBytes!=null){let p=sn(a,f,await s);if(m(p.known?p.bodyTris:0,p.packBytes))throw new pe({bodyTris:p.bodyTris,packBytes:p.packBytes,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes})}let{pack:h,missing:x,requests:T,bytes:u}=await tn([...a.filter((p)=>!p.embedded).map((p)=>p.part),...f.values()],t),b=new Map([...f].map(([p,B])=>[B,p])),S=x.map((p)=>b.get(p)??p);for(let[p,B]of f){let y=h.header.parts[B];if(y)h.header.parts[p]=y}let d=performance.now();if(t.maxBodyTris!=null||t.maxPackBytes!=null){let p=h.buffer?.byteLength??h.bytes??0,B=rn(a,h);if(m(B,p))throw new pe({bodyTris:B,packBytes:p,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes})}let g=t.cull?Ae(a,h.header,t.textures!==!1):void 0;return{insts:a,pack:h,missing:S,requests:T,bytes:u,cull:g,timings:{fetchModel:i-n,parse:c-i,parts:d-c,...g?{cull:performance.now()-d}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await dt(n,{...r,cull:!1,onParsed:(f)=>self.postMessage({id:t,insts:f})}),o=s.pack.buffer;if(self.postMessage({id:t,buffer:o,missing:s.missing,requests:s.requests,bytes:s.bytes,timings:s.timings},[o]),!r.cull)return;let i=performance.now(),l=Ae(s.insts,s.pack.header,r.textures!==!1),a=performance.now()-i,c=[];for(let f of[l.studHidden,l.studUp,l.underHidden,l.studHideStep,l.underHideStep])if(f)c.push(f.buffer);self.postMessage({id:t,cull:l,ms:a},c)}catch(s){if(s instanceof pe||s?.code==="ldr-budget")self.postMessage({id:t,phase:"error",error:String(s?.message??s),budget:{bodyTris:s.bodyTris,packBytes:s.packBytes,maxBodyTris:s.maxBodyTris,maxPackBytes:s.maxPackBytes}});else self.postMessage({id:t,phase:"error",error:String(s?.message??s)})}};\n';
|
|
3943
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/load-worker.gen.ts
|
|
3944
|
+
var load_worker_gen_default = 'var bt=ArrayBuffer,W=Uint8Array,de=Uint16Array,yt=Int16Array;var be=Int32Array,Ee=function(e,t,n){if(W.prototype.slice)return W.prototype.slice.call(e,t,n);if(t==null||t<0)t=0;if(n==null||n>e.length)n=e.length;var r=new W(n-t);return r.set(e.subarray(t,n)),r},ce=function(e,t,n,r){if(W.prototype.fill)return W.prototype.fill.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;for(;n<r;++n)e[n]=t;return e},xt=function(e,t,n,r){if(W.prototype.copyWithin)return W.prototype.copyWithin.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;while(n<r)e[t++]=e[n++]};var wt=["invalid zstd data","window size too large (>2046MB)","invalid block type","FSE accuracy too high","match distance too far back","unexpected EOF"],K=function(e,t,n){var r=Error(t||wt[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,K);if(!n)throw r;return r},je=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},At=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},Mt=function(e,t){var n=e[0]|e[1]<<8|e[2]<<16;if(n==3126568&&e[3]==253){var r=e[4],s=r>>5&1,o=r>>2&1,i=r&3,l=r>>6;if(r&8)K(0);var a=6-s,c=i==3?4:i,f=je(e,a,c);a+=c;var m=l?1<<l:s,g=je(e,a,m)+(l==1&&256),y=g;if(!s){var v=1<<10+(e[5]>>3);y=v+(v>>3)*(e[5]&7)}if(y>2145386496)K(1);var x=new W((t==1?g||y:t?0:y)+12);return x[0]=1,x[4]=4,x[8]=8,{b:a+m,y:0,l:0,d:f,w:t&&t!=1?t:x.subarray(12),e:y,o:new be(x.buffer,0,3),u:g,c:o,m:Math.min(131072,y)}}else if((n>>4|e[3]<<20)==25481893)return At(e,4)+8;K(0)},re=function(e){var t=0;for(;1<<t<=e;++t);return t-1},ue=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)K(3);var o=1<<s,i=o,l=-1,a=-1,c=-1,f=o,m=new bt(512+(o<<2)),g=new yt(m,0,256),y=new de(m,0,256),v=new de(m,512,o),x=512+(o<<1),S=new W(m,x,o),h=new W(m,x+o);while(l<255&&i>0){var u=re(i+1),d=r>>3,p=(1<<u+1)-1,L=(e[d]|e[d+1]<<8|e[d+2]<<16)>>(r&7)&p,b=(1<<u)-1,T=p-i-1,E=L&b;if(E<T)r+=u,L=E;else if(r+=u+1,L>b)L-=T;if(g[++l]=--L,L==-1)i+=L,S[--f]=l;else i-=L;if(!L)do{var D=r>>3;a=(e[D]|e[D+1]<<8)>>(r&7)&3,r+=2,l+=a}while(a==3)}if(l>255||i)K(0);var C=0,U=(o>>1)+(o>>3)+3,X=o-1;for(var H=0;H<=l;++H){var M=g[H];if(M<1){y[H]=-M;continue}for(c=0;c<M;++c){S[C]=H;do C=C+U&X;while(C>=f)}}if(C)K(0);for(c=0;c<o;++c){var A=y[S[c]]++,k=h[c]=s-re(A);v[c]=(A<<k)-o}return[r+7>>3,{b:s,s:S,n:h,t:v}]},vt=function(e,t){var n=0,r=-1,s=new W(292),o=e[t],i=s.subarray(0,256),l=s.subarray(256,268),a=new de(s.buffer,268);if(o<128){var c=ue(e,t+1,6),f=c[0],m=c[1];t+=o;var g=f<<3,y=e[t];if(!y)K(0);var v=0,x=0,S=m.b,h=S,u=(++t<<3)-8+re(y);for(;;){if(u-=S,u<g)break;var d=u>>3;if(v+=(e[d]|e[d+1]<<8)>>(u&7)&(1<<S)-1,i[++r]=m.s[v],u-=h,u<g)break;d=u>>3,x+=(e[d]|e[d+1]<<8)>>(u&7)&(1<<h)-1,i[++r]=m.s[x],S=m.n[v],v=m.t[v],h=m.n[x],x=m.t[x]}if(++r>255)K(0)}else{r=o-127;for(;n<r;n+=2){var p=e[++t];i[n]=p>>4,i[n+1]=p&15}++t}var L=0;for(n=0;n<r;++n){var b=i[n];if(b>11)K(0);L+=b&&1<<b-1}var T=re(L)+1,E=1<<T,D=E-L;if(D&D-1)K(0);i[r++]=re(D)+1;for(n=0;n<r;++n){var b=i[n];++l[i[n]=b&&T+1-b]}var C=new W(E<<1),U=C.subarray(0,E),X=C.subarray(E);a[T]=0;for(n=T;n>0;--n){var H=a[n];ce(X,n,H,a[n-1]=H+l[n]*(1<<T-n))}if(a[0]!=E)K(0);for(n=0;n<r;++n){var M=i[n];if(M){var A=a[M];ce(U,n,A,a[M]=A+(1<<T-M))}}return[t,{n:X,b:T,s:U}]},Tt=ue(new W([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],Ct=ue(new W([33,20,196,24,99,140,33,132,16,66,8,33,132,16,66,8,33,68,68,68,68,68,68,68,68,36,9]),0,6)[1],Et=ue(new W([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],Ve=function(e,t){var n=e.length,r=new be(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Se=new W(new be([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),St=Ve(Se,0),Pe=new W(new be([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),Pt=Ve(Pe,3),le=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,l=-n.b;if(!o)K(0);var a=0,c=n.b,f=(r<<3)-8+re(o)-c,m=-1;for(;f>l&&m<s;){var g=f>>3,y=(e[g]|e[g+1]<<8|e[g+2]<<16)>>(f&7);a=(a<<c|y)&i,t[++m]=n.s[a],f-=c=n.n[a]}if(f!=l||m+1!=s)K(0)},Lt=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,l=o+i;le(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),le(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),le(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,l),n),le(e.subarray(r),t.subarray(l),n)},kt=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var l=o>>3|e[s+1]<<5|e[s+2]<<13,a=(s+=3)+l;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return ce(n,e[s],t.y,t.y+=l),n;return ce(new W(l),e[s])}if(a>e.length)return;if(i==0){if(t.b=a,n)return n.set(e.subarray(s,a),t.y),t.y+=l,n;return Ee(e,s,a)}if(i==2){var c=e[s],f=c&3,m=c>>2&3,g=c>>4,y=0,v=0;if(f<2)if(m&1)g|=e[++s]<<4|(m&2&&e[++s]<<12);else g=c>>3;else if(v=m,m<2)g|=(e[++s]&63)<<4,y=e[s]>>6|e[++s]<<2;else if(m==2)g|=e[++s]<<4|(e[++s]&3)<<12,y=e[s]>>2|e[++s]<<6;else g|=e[++s]<<4|(e[++s]&63)<<12,y=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var x=n?n.subarray(t.y,t.y+t.m):new W(t.m),S=x.length-g;if(f==0)x.set(e.subarray(s,s+=g),S);else if(f==1)ce(x,e[s++],S);else{var h=t.h;if(f==2){var u=vt(e,s);y+=s-(s=u[0]),t.h=h=u[1]}else if(!h)K(0);(v?Lt:le)(e.subarray(s,s+=y),x.subarray(S),h)}var d=e[s++];if(d){if(d==255)d=(e[s++]|e[s++]<<8)+32512;else if(d>127)d=d-128<<8|e[s++];var p=e[s++];if(p&3)K(0);var L=[Ct,Et,Tt];for(var b=2;b>-1;--b){var T=p>>(b<<1)+2&3;if(T==1){var E=new W([0,0,e[s++]]);L[b]={s:E.subarray(2,3),n:E.subarray(0,1),t:new de(E.buffer,0,1),b:0}}else if(T==2)r=ue(e,s,9-(b&1)),s=r[0],L[b]=r[1];else if(T==3){if(!t.t)K(0);L[b]=t.t[b]}}var D=t.t=L,C=D[0],U=D[1],X=D[2],H=e[a-1];if(!H)K(0);var M=(a<<3)-8+re(H)-X.b,A=M>>3,k=0,V=(e[A]|e[A+1]<<8)>>(M&7)&(1<<X.b)-1;A=(M-=U.b)>>3;var B=(e[A]|e[A+1]<<8)>>(M&7)&(1<<U.b)-1;A=(M-=C.b)>>3;var N=(e[A]|e[A+1]<<8)>>(M&7)&(1<<C.b)-1;for(++d;--d;){var P=X.s[V],w=X.n[V],O=C.s[N],F=C.n[N],R=U.s[B],z=U.n[B];A=(M-=R)>>3;var j=1<<R,I=j+((e[A]|e[A+1]<<8|e[A+2]<<16|e[A+3]<<24)>>>(M&7)&j-1);A=(M-=Pe[O])>>3;var G=Pt[O]+((e[A]|e[A+1]<<8|e[A+2]<<16)>>(M&7)&(1<<Pe[O])-1);A=(M-=Se[P])>>3;var _=St[P]+((e[A]|e[A+1]<<8|e[A+2]<<16)>>(M&7)&(1<<Se[P])-1);if(A=(M-=w)>>3,V=X.t[V]+((e[A]|e[A+1]<<8)>>(M&7)&(1<<w)-1),A=(M-=F)>>3,N=C.t[N]+((e[A]|e[A+1]<<8)>>(M&7)&(1<<F)-1),A=(M-=z)>>3,B=U.t[B]+((e[A]|e[A+1]<<8)>>(M&7)&(1<<z)-1),I>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=I-=3;else{var Y=I-(_!=0);if(Y){if(I=Y==3?t.o[0]-1:t.o[Y],Y>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=I}else I=t.o[0]}for(var b=0;b<_;++b)x[k+b]=x[S+b];k+=_,S+=_;var q=k-I;if(q<0){var J=-q,ee=t.e+q;if(J>G)J=G;for(var b=0;b<J;++b)x[k+b]=t.w[ee+b];k+=J,G-=J,q=0}for(var b=0;b<G;++b)x[k+b]=x[q+b];k+=G}if(k!=S)while(S<x.length)x[k++]=x[S++];else k=x.length;if(n)t.y+=k;else x=Ee(x,0,k)}else if(n){if(t.y+=g,S)for(var b=0;b<g;++b)x[b]=x[S+b]}else if(S)x=Ee(x,S);return t.b=a,x}K(2)},Bt=function(e,t){if(e.length==1)return e[0];var n=new W(t);for(var r=0,s=0;r<e.length;++r){var o=e[r];n.set(o,s),s+=o.length}return n};function ye(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=Mt(e,r||t);if(typeof i=="object"){if(r){if(t=null,i.w.length==i.u)n.push(t=i.w),o+=i.u}else n.push(t),i.e=0;for(;!i.l;){var l=kt(e,i,t);if(!l)K(5);if(t)i.e=i.y;else n.push(l),o+=l.length,xt(i.w,0,l.length),i.w.set(l,i.w.length-l.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return Bt(n,o)}async function It(e){let t=e instanceof Uint8Array?e:new Uint8Array(e),n=(r)=>r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength);if(t[0]===40&&t[1]===181&&t[2]===47&&t[3]===253)return n(ye(t));if(t[0]===31&&t[1]===139)return new Response(new Blob([t]).stream().pipeThrough(new DecompressionStream("gzip"))).arrayBuffer();return n(t)}async function He(e){return new TextDecoder().decode(await It(e))}var Ge=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split("/").pop()||"main.ldr").replace(/\\.(zst|gz)$/i,"")||"main.ldr";function xe(e){let t=new DataView(e).getUint32(0,!0),n=JSON.parse(new TextDecoder().decode(new Uint8Array(e,4,t))),r=4+t;return{header:n,arr:(o)=>o&&(o[2]==="f32"?new Float32Array(e,r+o[0],o[1]):o[2]==="u16"?new Uint16Array(e,r+o[0],o[1]):o[2]==="u8"?new Uint8Array(e,r+o[0],o[1]):new Uint32Array(e,r+o[0],o[1])),bytes:e.byteLength,buffer:e}}var Z=(e)=>e.trim().toLowerCase().replace(/\\\\/g,"/").replace(/\\/+/g,"/");function Le(e){if(/^0x/i.test(e))return parseInt(e,16);return+e}var _e=/^~?\\s*moved\\s+to\\s+(.+)$/i,Ft=new Set(["FILE","NOFILE","!DATA","!:","STEP","BFC","ROTSTEP","BUFEXCHG","!TEXMAP"]),Qe=new Set(["part","subpart","primitive","8_primitive","48_primitive","shortcut","helper"]),Rt=new Set(["model","submodel","configuration"]),Dt=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function We(e){let t=Dt.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,"");return Qe.has(n)||Rt.has(n)?n:void 0}function Ut(e){let t=[],n=0;while(n<e.length){while(e[n]===" "||e[n]==="\\t")n++;if(n>=e.length)break;if(e[n]===\'"\'){let r="";n++;while(n<e.length&&e[n]!==\'"\'){if(e[n]==="\\\\"&&n+1<e.length)n++;r+=e[n++]}n++,t.push(r)}else{let r=n;while(r<e.length&&e[r]!==" "&&e[r]!=="\\t")r++;t.push(e.slice(n,r)),n=r}}return t}function zt(e,t=!1){let n=/^\\s*(\\S+)\\s+(.*)$/.exec(e);if(!n)return null;let r=n[1].toUpperCase(),s=r==="PLANAR"?9:r==="CYLINDRICAL"?10:r==="SPHERICAL"?11:0;if(!s)return null;let o=n[2].trim().split(/\\s+/);if(o.length<s+1)return null;let i=o.slice(0,s).map(Number);if(!i.every(Number.isFinite))return null;let l=n[2].trim();for(let m=0;m<s;m++)l=l.replace(/^\\S+\\s*/,"");let a=Ut(l);if(!a.length)return null;let c={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:a[0]};if(s>=10)c.a=i[9];if(s===11)c.b=i[10];let f=a.findIndex((m,g)=>g>0&&m.toUpperCase()==="GLOSSMAP");if(f>0&&a[f+1])c.glossmap=a[f+1];if(t)c.next=!0;return c}var Ot=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,""),n=t+"=".repeat((4-t.length%4)%4),r=atob(n),s=new Uint8Array(r.length);for(let o=0;o<r.length;o++)s[o]=r.charCodeAt(o);return s};function Nt(e){let t=e.length,n=1,r=(c)=>c===32||c===9,s=()=>{while(n<t&&r(e.charCodeAt(n)))n++;let c=n;while(n<t&&!r(e.charCodeAt(n)))n++;return c<n?e.slice(c,n):null},o=s();if(o===null)return null;let i=Array(12);for(let c=0;c<12;c++){let f=s();if(f===null)return null;i[c]=+f}while(n<t&&r(e.charCodeAt(n)))n++;if(n>=t)return null;let l=e.slice(n),a=/[ \\t]{2,}|\\t/.test(l)?l.split(/\\s+/).join(" "):l;return{t:1,color:Le(o),m:i,file:Z(a)}}function Ke(e){let t=+e[0];if(!(t>=1&&t<=5)||e.length<2)return null;let n=Le(e[1]),r=e.slice(2).map(Number);if(t===1)return{t:1,color:n,m:r.slice(0,12),file:Z(e.slice(14).join(" "))};if(t===2)return{t:2,color:n,p:r.slice(0,6)};if(t===3)return{t:3,color:n,p:r.slice(0,9)};if(t===4)return{t:4,color:n,p:r.slice(0,12)};return{t:5,color:n,p:r.slice(0,12)}}function et(e,t="main.ldr",n={}){let r=!!n.geometryText,s=new Map,o=null,i="",l,a=null,c=[],f=null,m=()=>{if(!a)return;let u=Ot(a.chunks.join("")),d=u[0]===137&&u[1]===80&&u[2]===78&&u[3]===71;(l??=new Map).set(Z(a.name),{name:a.name,bytes:u,...d?{mime:"image/png"}:{}}),a=null},g=!0,y=(u)=>{if(m(),o={name:Z(u),cmds:[]},s.set(o.name,o),!i)i=o.name;c=[],f=null,g=!0},v=!1,x=!1,S=()=>{if(x)return;x=!0,s.clear(),o=null,i=""},h=(u,d)=>{if(f){u.tex=f,f=null;return}let p=c[c.length-1];if(!p)return;if(p.fallback){if(!d)u.fallback=!0}else u.tex=p.map};for(let u of e.split(`\n`)){let d=u.trim();if(!d)continue;if(r&&d.charCodeAt(0)>=50&&d.charCodeAt(0)<=53&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)){if(a||v)continue;if(!o)y(t);let T=d.slice(2).trimStart(),E=T.search(/\\s/),D={t:d.charCodeAt(0)-48,color:Le(E<0?T:T.slice(0,E)),p:[],src:d};h(D,!1),o.cmds.push(D),g=!1;continue}if(d.charCodeAt(0)===48&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)){let T=2;while(d.charCodeAt(T)===32||d.charCodeAt(T)===9)T++;let E=T;while(E<d.length&&d.charCodeAt(E)!==32&&d.charCodeAt(E)!==9)E++;let D=d.slice(T,E);if(!Ft.has(D)){if(v||a)continue;if(!o)y(t);let C=d.slice(T),U={t:0,text:C};if(D.charCodeAt(0)===33)U.meta=D;if(f=null,g&&!o.org){let H=We(C);if(H)o.org=H}let X=C.match(_e);if(X&&!o.movedTo){let H=X[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(H))H+=".dat";o.movedTo=Z(H)}o.cmds.push(U);continue}}if(d.charCodeAt(0)===49&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)&&!a&&!v){let T=Nt(d);if(T){if(!o)y(t);h(T,!1),o.cmds.push(T),g=!1;continue}}let p=d.split(/\\s+/);if(+p[0]===0){let T=d.slice(1).trim();if(p[1]==="FILE"){S(),v=!1,y(T.slice(5));continue}if(p[1]==="NOFILE"){m(),o=null,v=!0;continue}if(p[1]==="!DATA"){S(),m(),o=null,v=!1,a={name:T.slice(5).trim(),chunks:[]};continue}if(v)continue;if(a){if(p[1]==="!:")a.chunks.push(p.slice(2).join(""));continue}if(!o)y(t);let E={t:0,text:T};if(p[1]==="STEP")E.step=!0,c=[],f=null;else if(p[1]==="BFC")E.bfc=p.slice(2).join(" ");else if(p[1]==="ROTSTEP")if(E.meta="ROTSTEP",E.step=!0,c=[],f=null,(p[2]??"").toUpperCase()==="END")E.rotstep={x:0,y:0,z:0,mode:"END"};else{let C=(p[5]??"REL").toUpperCase();E.rotstep={x:+p[2]||0,y:+p[3]||0,z:+p[4]||0,mode:["REL","ABS","ADD"].includes(C)?C:"REL"}}else if(p[1]==="BUFEXCHG"){E.meta="BUFEXCHG";let C=(p[2]??"").toUpperCase();E.bufexchg={op:C==="RETRIEVE"?"RETRIEVE":"STORE",buf:p[3]??"A"}}else if(p[1]?.startsWith("!"))E.meta=p[1];if(g&&!o.org){let C=We(T);if(C)o.org=C}if(p[1]==="!TEXMAP"){let C=(p[2]??"").toUpperCase();if(f=null,C==="START"||C==="NEXT"){let U=zt(T.replace(/^!TEXMAP\\s+\\S+/i,""),C==="NEXT");if(E.texmap={op:C,...U?{map:U}:{}},U)if((o.texmaps??=[]).push(U),C==="START")c.push({map:U,fallback:!1});else f=U}else if(C==="FALLBACK"){E.texmap={op:C};let U=c[c.length-1];if(U)U.fallback=!0}else if(C==="END")E.texmap={op:C},c.pop()}else if(p[1]==="!:"){f=null;let C=Ke(p.slice(2));if(C)h(C,!0),E.geom=C}else f=null;let D=T.match(_e);if(D&&!o.movedTo){let C=D[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(C))C+=".dat";o.movedTo=Z(C)}o.cmds.push(E);continue}if(a||v)continue;if(!o)y(t);let b=Ke(p);if(!b)continue;h(b,!1),o.cmds.push(b),g=!1}return m(),l?{main:i,files:s,data:l}:{main:i,files:s}}var cn=Math.PI/180;function tt(e,t){let n=(r)=>[t[3]*r[0]+t[4]*r[1]+t[5]*r[2]+t[0],t[6]*r[0]+t[7]*r[1]+t[8]*r[2]+t[1],t[9]*r[0]+t[10]*r[1]+t[11]*r[2]+t[2]];return{...e,p1:n(e.p1),p2:n(e.p2),p3:n(e.p3)}}function nt(e,t){let[n,r,s,o,i,l,a,c,f,m,g,y]=e,[v,x,S,h,u,d,p,L,b,T,E,D]=t;return[o*v+i*x+l*S+n,a*v+c*x+f*S+r,m*v+g*x+y*S+s,o*h+i*p+l*T,o*u+i*L+l*E,o*d+i*b+l*D,a*h+c*p+f*T,a*u+c*L+f*E,a*d+c*b+f*D,m*h+g*p+y*T,m*u+g*L+y*E,m*d+g*b+y*D]}var ke=[0,0,0,1,0,0,0,1,0,0,0,1];var Xe=new WeakMap,$t=/^(s|8|48)\\//;function Be(e,t){let n=e.files.get(Z(t));if(!n)return"part";let r=Xe.get(n);if(r)return r;if(n.org)r=Qe.has(n.org)?"part":"model";else if(n.name===e.main)r="model";else r=n.cmds.some((s)=>s.t>=2||s.t===0&&!!s.geom||s.t===1&&$t.test(s.file))?"part":"model";return Xe.set(n,r),r}var Ze=new WeakMap;function rt(e){let t=Ze.get(e);if(t)return t;t=[];let n=0;for(let r of e.cmds){if(r.t===0&&r.step){n++;continue}if((r.t>=2||r.t===0&&r.geom&&r.geom.t>=2)&&t[t.length-1]!==n)t.push(n)}return Ze.set(e,t),t}var Ye=(e)=>e>16777215?"0x"+e.toString(16).toUpperCase():String(e),jt=(e)=>e.t===0?"0 "+e.text:e.t===1?`1 ${Ye(e.color)} ${e.m.join(" ")} ${e.file}`:e.src?e.src:`${e.t} ${Ye(e.color)} ${e.p.join(" ")}`,Ie=(e,t)=>`${Z(e)}#${t}`;function Vt(e,t){let n=[],r=0,s=(o)=>!!o&&o.t===0&&o.texmap?.op==="NEXT";for(let o of e.cmds){if(o.t===0){if(o.step){r++;continue}if(o.bfc!==void 0){n.push(o);continue}if(r!==t)continue;if(o.texmap)n.push(o);else if(o.geom){if(o.geom.t>=2)n.push(o);else if(s(n[n.length-1]))n.pop()}continue}if(r!==t)continue;if(o.t===1){if(s(n[n.length-1]))n.pop();continue}n.push(o)}return{name:Ie(e.name,t),cmds:n}}function st(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Vt(e,t).cmds.map(jt)].join(`\n`)+`\n`}function Ht(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,"0")}function ot(e){let[t,n,r,s,o,i,l,a,c,f,m,g]=e,y=a*g-c*m,v=-(l*g-c*f),x=l*m-a*f,S=s*y+o*v+i*x;if(!Number.isFinite(S)||Math.abs(S)<0.000000000001)return null;let h=1/S,u=[y*h,-(o*g-i*m)*h,(o*c-i*a)*h,v*h,(s*g-i*f)*h,-(s*c-i*l)*h,x*h,-(s*m-o*f)*h,(s*a-o*l)*h];return[-(u[0]*t+u[1]*n+u[2]*r),-(u[3]*t+u[4]*n+u[5]*r),-(u[6]*t+u[7]*n+u[8]*r),...u]}var Gt=(e)=>String(+e.toFixed(6)||0),Je=(e)=>\'"\'+e.replace(/\\\\/g,"\\\\\\\\").replace(/"/g,"\\\\\\"")+\'"\';function it(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!=="PLANAR"?[t.a??360]:[],...t.method==="SPHERICAL"?[t.b??180]:[]].map(Gt).join(" "),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${Je(t.texture)}${t.glossmap?" GLOSSMAP "+Je(t.glossmap):""}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${Z(e)}\n0 !TEXMAP END\n`;return{name:`${Z(e)}#tex-${Ht(r)}`,source:r}}var _t=(e,t)=>{let n=[,,,,,,,,,];for(let r=0;r<3;r++)for(let s=0;s<3;s++)n[r*3+s]=e[r*3]*t[s]+e[r*3+1]*t[3+s]+e[r*3+2]*t[6+s];return n};function Wt(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),l=Math.cos(t*r),a=Math.sin(n*r),c=Math.cos(n*r);return[l*c,-l*a,i,o*a+s*i*c,o*c-s*i*a,-s*l,s*a-o*i*c,s*c+o*i*a,o*l]}var qe=new WeakMap;function at(e){let t=qe.get(e);if(t)return t;let n=[],r=null;for(let s of e.cmds){if(s.t!==0||!s.step)continue;let o=s.rotstep;if(o)if(o.mode==="END")r=null;else{let i=Wt(o.x,o.y,o.z);r=o.mode==="ABS"?{abs:!0,m:i,rotstep:o}:o.mode==="ADD"&&r?{abs:r.abs,m:_t(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),qe.set(e,n),n}var lt=999999,ct=(e)=>e.map((t)=>String(t).padStart(6,"0")).join(".")+"~";function Kt(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,l=new Map,a=0,c=(m,g)=>{let y=m.name+"#"+g,v=l.get(y);if(!v){let x;v=Object.assign(()=>x??=st(m,g),{file:m,step:g}),l.set(y,v)}return v},f=(m,g,y,v,x,S,h,u,d=null,p=[],L=[])=>{let b=m.files.get(g);if(!b||h>r)return;let T=0,E=h>0?++a:0,D=i&&E?[...p,E]:p,C=i&&E?[...L,y]:L,U=i&&!d?new Map:null,X=-1,H=0,M=(P,w,O,F,R,z)=>{if(X!==T)X=T,H=0;let j=U?.get(T+"|"+w);if(j)return j.n++,f(P,P===m?w:P.main,O,F,x+"/"+w,[...R,lt],h+1,z,[...R,lt],D,C);let I=[...R,H++],G=n.length;f(P,P===m?w:P.main,O,F,x+"/"+w,I,h+1,z,d,D,C),U?.set(T+"|"+w,{n:1,from:G,to:n.length})},A=at(b),k=s?rt(b):[],V=0,B=(P,w,O,F,R,z,j)=>{if(d)F=d;let I={part:P,color:w,m:O,step:F[0],steps:F,localStep:R,path:x};if(E){if(I.sub=E,i)I.subPath=D,I.subMats=C}if(z)I.embedded=!0;if(j){let _=it(P,j);I.texPart=_.name,I.texSource=_.source}let G=A[R];if(G)I.view=G;return n.push(I),I},N=(P)=>{while(V<k.length&&k[V]<=P){let w=k[V++];B(Ie(b.name,w),v,y,[...S,w],w,!1,null).source=c(b,w)}};for(let P of b.cmds){if(P.t===0&&P.step){T++;continue}let w=P;if(w.t>=2||w.t===0&&w.geom&&w.geom.t>=2){N(T);continue}if(w.t===0)if(o&&w.geom?.t===1)w=w.geom;else continue;if(w.t!==1)continue;if(o&&w.fallback)continue;let O=w.color===16?v:w.color,F=nt(y,w.m),R=[...S,T],z=o?w.tex??u:null,j=z?ot(w.m):null,I=z&&j?tt(z,j):null;if(m.files.has(w.file)){if(Be(m,w.file)==="model"){M(m,w.file,F,O,R,I);continue}B(w.file,O,F,R,T,!0,I);continue}let G=t.resolveModel?.(w.file);if(G){M(G,w.file,F,O,R,I);continue}B(w.file,O,F,R,T,!1,I)}if(N(1/0),U){for(let P of U.values())if(P.n>1)for(let w=P.from;w<P.to;w++)n[w].mult??=P.n}};if(Be(e,e.main)==="part"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...ke],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return f(e,e.main,ke,16,e.main,[],0,null),n}function ut(e,t="main.ldr",n){return Kt(et(e,t,{geometryText:!0}),n)}function Xt(e,t){let n=new Map,r=null,s=!1;for(let o of e.split(/\\r?\\n/)){let i=/^\\s*0\\s+FILE\\s+(.+)$/i.exec(o);if(i){if(!s)n.clear();s=!0,r=[],n.set(Z(i[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(o)){if(!s)n.clear();s=!0,r=null;continue}if(!r){if(s)continue;r=[],n.set(Z(t),r)}let l=o.trim().replace(/\\s+/g," ");if(l)r.push(l)}return n}var Zt=(e)=>{if(!e.startsWith("1 "))return null;let t=e.split(" ");return t.length>=15?Z(t.slice(14).join(" ")):null};function Yt(e){let t=2166136261,n=1523705862;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);t=Math.imul(t^s,16777619),n=Math.imul(n^s,16777629)^n>>>15}return(t>>>0).toString(16).padStart(8,"0")+(n>>>0).toString(16).padStart(8,"0")}function ft(e,t,n="main.ldr"){let r=Xt(e,n),s=new Map;for(let o of t){let i=Z(o);if(!r.has(i)||s.has(i))continue;let l=new Set([i]),a=[i];while(a.length)for(let f of r.get(a.pop())){let m=Zt(f);if(m&&r.has(m)&&!l.has(m))l.add(m),a.push(m)}let c=[i,...[...l].filter((f)=>f!==i).sort()].map((f)=>"0 FILE "+(f===i?"":f)+`\n`+r.get(f).join(`\n`)).join(`\n`);s.set(i,`emb/${Yt(c)}.dat`)}return s}var pt=(e,t=0)=>Math.abs(e[t+7]-1)<0.001&&Math.abs(e[t+4])<0.001&&Math.abs(e[t+10])<0.001,mt=new WeakMap;function Fe(e,t){let n=mt.get(e);if(!n)mt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),l=[],a=[];s.studs.forEach((g,y)=>{l.push(g[0]),a.push(g[1]);for(let v=0;v<12;v++)i[y*12+v]=g[2+v]});let c=null,f=0,m=0;if(s.mask){f=s.mask[0],m=s.mask[1];let g=s.mask[2];c=new Uint8Array(g.length);for(let y=0;y<g.length;y++)c[y]=g.charCodeAt(y)===49?1:0}return n.set(t,r={nStuds:o,studM:i,kind:l,color:a,mask:c,nx:f,nz:m}),r}var ie=1073741824;class Re{a;b;c;vals;used;mask;size=0;constructor(e=1024){let t=1024;while(t<e*2)t*=2;this.a=new Int32Array(t),this.b=new Int32Array(t),this.c=new Int32Array(t),this.vals=new Int32Array(t),this.used=new Uint8Array(t),this.mask=t-1}slot(e,t,n){let r=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return r^=r>>>15,r=Math.imul(r,739982445),r^=r>>>12,r&this.mask}get(e,t,n){let r=this.slot(e,t,n),s=this.used,o=this.a,i=this.b,l=this.c;for(;;){if(!s[r])return-1;if(o[r]===e&&i[r]===t&&l[r]===n)return this.vals[r];r=r+1&this.mask}}put(e,t,n,r){if((this.size+1)*2>this.used.length)this.grow();let s=this.slot(e,t,n),o=this.used,i=this.a,l=this.b,a=this.c;for(;;){if(!o[s])return o[s]=1,i[s]=e,l[s]=t,a[s]=n,this.vals[s]=r,this.size++,-1;if(i[s]===e&&l[s]===t&&a[s]===n){let c=this.vals[s];return this.vals[s]=r,c}s=s+1&this.mask}}grow(){let{a:e,b:t,c:n,vals:r,used:s}=this,o=s.length*2;this.a=new Int32Array(o),this.b=new Int32Array(o),this.c=new Int32Array(o),this.vals=new Int32Array(o),this.used=new Uint8Array(o),this.mask=o-1,this.size=0;for(let i=0;i<s.length;i++)if(s[i])this.put(e[i],t[i],n[i],r[i])}}var we=(e,t,n)=>e>-ie&&e<ie&&t>-ie&&t<ie&&n>-ie&&n<ie,fe=2147483647;function Jt(e,t,n){let s=[],o=[],i=[],l=[],a=[],c=[],f=[],m=[],g=new Re(e.length*2),y=[],v=[];for(let M=0;M<e.length;M++){let A=e[M],k=A.m,V=t.parts[A.part];if(!V||!V.mask||!pt(k))continue;let B=V.bbox,N=1/0,P=-1/0,w=1/0,O=-1/0;for(let z=0;z<2;z++)for(let j=0;j<2;j++){let I=z?B[3]:B[0],G=j?B[5]:B[2],_=k[0]+k[3]*I+k[5]*G,Y=k[2]+k[9]*I+k[11]*G;if(_<N)N=_;if(_>P)P=_;if(Y<w)w=Y;if(Y>O)O=Y}let F=a.length;s.push(N),o.push(P),i.push(w),l.push(O),a.push(M),c.push(Fe(t,A.part)),f.push(B[0]),m.push(B[2]);let R=Math.round((k[1]+B[4])*2);for(let z=Math.floor(N/40);z<=Math.floor(P/40);z++)for(let j=Math.floor(w/40);j<=Math.floor(O/40);j++){if(!we(R,z,j))continue;let I=v.length;v.push(F),y.push(g.put(R,z,j,I))}}let x=[0,5,-5,5,-5],S=[0,5,5,-5,-5],h=NaN,u=NaN,d=NaN,p=-1,L=(M,A,k,V)=>{let B=Math.round(A*2),N=Math.floor(M/40),P=Math.floor(k/40);if(!we(B,N,P))return fe;let w=fe;if(B!==h||N!==u||P!==d)h=B,u=N,d=P,p=g.get(B,N,P);for(let O=p;O>=0;O=y[O]){let F=v[O];if(a[F]===V||!(M-6>=s[F]-0.5&&M+6<=o[F]+0.5&&k-6>=i[F]-0.5&&k+6<=l[F]+0.5))continue;let R=e[a[F]].m,z=c[F],j=f[F],I=m[F],G=M-R[0],_=A-R[1],Y=k-R[2],q=R[3]*G+R[6]*_+R[9]*Y,J=R[5]*G+R[8]*_+R[11]*Y,{nx:ee,nz:se,mask:ae}=z,oe=!0;for(let Q=0;Q<5;Q++){let te=Math.floor((q+x[Q]-j)/20),ne=Math.floor((J+S[Q]-I)/20);if(te<0||ne<0||te>=ee||ne>=se||ae[te*se+ne]!==1){oe=!1;break}}if(oe){if(!n)return 0;let Q=n[a[F]];if(Q<w)w=Q}}return w},b=0;for(let M of e){let A=Fe(t,M.part);if(A)b+=A.nStuds}let T=new Uint8Array(b),E=new Uint8Array(b),D=new Re(b),C=0,U=n?new Int32Array(b).fill(fe):void 0;for(let M=0,A=0;M<e.length;M++){let k=e[M],V=Fe(t,k.part);if(!V)continue;let B=k.m,N=V.studM,P=B[0],w=B[1],O=B[2],F=B[3],R=B[4],z=B[5],j=B[6],I=B[7],G=B[8],_=B[9],Y=B[10],q=B[11];for(let J=0;J<V.nStuds;J++,A++){let ee=J*12,se=N[ee+4],ae=N[ee+7],oe=N[ee+10];if(!(Math.abs(j*se+I*ae+G*oe-1)<0.001&&Math.abs(F*se+R*ae+z*oe)<0.001&&Math.abs(_*se+Y*ae+q*oe)<0.001))continue;E[A]=1;let Q=N[ee],te=N[ee+1],ne=N[ee+2],De=P+F*Q+R*te+z*ne,Ue=w+j*Q+I*te+G*ne,ze=O+_*Q+Y*te+q*ne,Oe=L(De,Ue,ze,M);if(Oe!==fe){if(T[A]=1,C++,U)U[A]=Oe}let me=Math.round(De),he=Math.round(Ue),ge=Math.round(ze);if(!we(me,he,ge))continue;if(!n){D.put(me,he,ge,1);continue}let Ne=n[M],$e=D.get(me,he,ge);if($e<0||Ne<$e)D.put(me,he,ge,Ne)}}let X=new Uint8Array(e.length),H=n?new Int32Array(e.length).fill(fe):void 0;for(let M=0;M<e.length;M++){let A=e[M],k=t.parts[A.part];if(!k||!k.under||!pt(A.m))continue;let V=k.bbox,B=Math.round((V[3]-V[0])/20),N=Math.round((V[5]-V[2])/20);if(!B||!N||B*N>4096)continue;let P=A.m,w=!0,O=0;for(let F=0;F<B&&w;F++)for(let R=0;R<N;R++){let z=V[0]+10+20*F,j=V[2]+10+20*R,I=P[0]+P[3]*z+P[5]*j,G=P[2]+P[9]*z+P[11]*j,_=Math.round(I),Y=Math.round(P[1]+V[4]),q=Math.round(G),J=we(_,Y,q)?D.get(_,Y,q):-1;if(J<0){w=!1;break}if(J>O)O=J}if(w){if(X[M]=1,H)H[M]=O}}return{nStuds:b,studHidden:T,studUp:E,underHidden:X,studsHidden:C,studHideStep:U,underHideStep:H}}function qt(e,t,n){let r=(a)=>n&&a.texPart&&t.parts[a.texPart]?a.texPart:a.part,s=e.map((a)=>({part:r(a),color:String(a.color),m:a.m,steps:a.steps})),o=s.map((a)=>ct(a.steps)),i=[...new Set(o)].sort(),l=new Map(i.map((a,c)=>[a,c]));return{all:s,stepOf:o.map((a)=>l.get(a)),nSteps:i.length}}function Ae(e,t,n=!0){let r=qt(e,t,n);return Jt(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Ce="https://ldr-demo.vercel.app/cdn/v1/",ve=new Map,Me=new Map;function gt(e=Ce,t=fetch){let n=ve.get(e);if(!n)n=t(e+"parts.json").then((r)=>{if(!r.ok)throw Error(`ldr: parts CDN index ${r.status} (${e}parts.json)`);return r.json()}),n.catch(()=>ve.delete(e)),ve.set(e,n);return n}var Qt=(e)=>Array.isArray(e)&&e.length===3&&typeof e[0]==="number"&&typeof e[1]==="number"&&(e[2]==="f32"||e[2]==="u16"||e[2]==="u8"||e[2]==="u32"),Te=(e,t)=>Qt(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>Te(n,t)):e&&typeof e==="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Te(r,t)])):e;function en(e,t={}){let n=[],r=0,s={},o={};for(let g of e){let y=g.buffer;if(!y)throw Error("ldr: mergePacks needs packs from decodePack/loadPack");let v=new DataView(y).getUint32(0,!0),x=new Uint8Array(y,4+v),S=r;n.push(x),r+=x.byteLength;let h=(4-r%4)%4;if(h)n.push(new Uint8Array(h)),r+=h;for(let[u,d]of Object.entries(g.header.parts??{}))if(!(u in s))s[u]=Te(d,S);for(let[u,d]of Object.entries(g.header.studKinds??{}))if(!(u in o))o[u]=Te(d,S)}let i=e[0]?.header??{version:1,weld:!0},l=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),a=(4-(4+l.length)%4)%4,c=4+l.length+a,f=new Uint8Array(c+r);new DataView(f.buffer).setUint32(0,l.length+a,!0),f.set(l,4),f.fill(32,4+l.length,c);let m=c;for(let g of n)f.set(g,m),m+=g.byteLength;return xe(f.buffer)}async function tn(e,t={}){e=[...e];try{return await ht(e,t)}catch(n){let r=t.cdn??Ce,s=t.fetch??fetch;ve.delete(r);let o=(i,l)=>s(i,{...l,cache:"reload"});try{return await ht(e,{...t,fetch:o})}catch{throw n}}}async function ht(e,t){let n=t.cdn??Ce,r=t.fetch??fetch,s=t.gap??16384,o=await gt(n,r),i=[...new Set([...e].map(Z))],l=[],a=[];for(let h of i){if(Me.has(n+h))continue;let u=o.parts[h];if(u)a.push({name:h,off:u[0],len:u[1],file:u[2]??0});else l.push(h)}a.sort((h,u)=>h.file-u.file||h.off-u.off);let c=[];for(let h of a){let u=c[c.length-1];if(u&&u.file===h.file&&h.off-u.end<=s)u.end=Math.max(u.end,h.off+h.len),u.items.push(h);else c.push({file:h.file,start:h.off,end:h.off+h.len,items:[h]})}let f=0,m=0,g=0,y=new Map,v=async()=>{while(g<c.length){let h=c[g++],u=y.get(h.file);if(u)u=u.subarray(h.start,h.end);else{let d=await r(new URL(o.archives[h.file],n).href,{headers:{Range:`bytes=${h.start}-${h.end-1}`,"Accept-Encoding":"identity"}});if(!d.ok)throw Error(`ldr: parts CDN ${d.status}`);if(m++,u=new Uint8Array(await d.arrayBuffer()),f+=u.byteLength,d.status===200)y.set(h.file,u),u=u.subarray(h.start,h.end)}for(let d of h.items){let p=ye(u.subarray(d.off-h.start,d.off-h.start+d.len)),L=p.buffer.slice(p.byteOffset,p.byteOffset+p.byteLength);Me.set(n+d.name,xe(L))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,c.length)},v));let x=i.filter((h)=>Me.has(n+h)).map((h)=>Me.get(n+h));return{pack:x.length?en(x,{colors:o.colors}):xe(nn(o.colors)),missing:l,requests:m,bytes:f}}function nn(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},colors:e})),n=(4-(4+t.length)%4)%4,r=new Uint8Array(4+t.length+n).fill(32);return new DataView(r.buffer).setUint32(0,t.length+n,!0),r.set(t,4),r.buffer}function rn(e,t){let n=t.header.parts;if(!n)return 0;let r=0;for(let s of e){let o=n[s.part]?.body?.tris;if(o)r+=o}return r}function sn(e,t,n){let r=0,s=0,o=!1,i=new Set;for(let l of e){let a=l.embedded?t.get(l.part):Z(l.part),c=a?n.parts[a]:void 0;if(!c)continue;if(c[3]!=null)o=!0,r+=c[3];if(!i.has(a))i.add(a),s+=c[1]}return{bodyTris:r,packBytes:s,known:o}}class pe extends Error{code="ldr-budget";bodyTris;packBytes;maxBodyTris;maxPackBytes;constructor(e){let t=[e.maxBodyTris!=null&&e.bodyTris>e.maxBodyTris?`${e.bodyTris} triangles (limit ${e.maxBodyTris})`:"",e.maxPackBytes!=null&&e.packBytes>e.maxPackBytes?`${(e.packBytes/1e6).toFixed(1)} MB parts pack (limit ${(e.maxPackBytes/1e6).toFixed(0)} MB)`:""].filter(Boolean).join(", ");super(`ldr: model exceeds device budget: ${t}`);this.name="BudgetError",this.bodyTris=e.bodyTris,this.packBytes=e.packBytes,this.maxBodyTris=e.maxBodyTris,this.maxPackBytes=e.maxPackBytes}}async function dt(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=gt(t.cdn??Ce,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(p)=>{if(!p.ok)throw Error(`ldr: ${p.status} fetching ${e}`);return He(await p.arrayBuffer())}),i=performance.now(),l=t.name??(t.text?"main.ldr":Ge(e)),a=ut(o,l,{looseGeometry:!1,callouts:t.callouts}),c=performance.now();t.onParsed?.(a),await s;let f=ft(o,new Set(a.filter((p)=>p.embedded).map((p)=>p.part)),l),m=(p,L)=>t.maxBodyTris!=null&&p>t.maxBodyTris||t.maxPackBytes!=null&&L>t.maxPackBytes;if(t.maxBodyTris!=null||t.maxPackBytes!=null){let p=sn(a,f,await s);if(m(p.known?p.bodyTris:0,p.packBytes))throw new pe({bodyTris:p.bodyTris,packBytes:p.packBytes,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes})}let{pack:g,missing:y,requests:v,bytes:x}=await tn([...a.filter((p)=>!p.embedded).map((p)=>p.part),...f.values()],t),S=new Map([...f].map(([p,L])=>[L,p])),h=y.map((p)=>S.get(p)??p);for(let[p,L]of f){let b=g.header.parts[L];if(b)g.header.parts[p]=b}let u=performance.now();if(t.maxBodyTris!=null||t.maxPackBytes!=null){let p=g.buffer?.byteLength??g.bytes??0,L=rn(a,g);if(m(L,p))throw new pe({bodyTris:L,packBytes:p,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes})}let d=t.cull?Ae(a,g.header,t.textures!==!1):void 0;return{insts:a,pack:g,missing:h,requests:v,bytes:x,cull:d,timings:{fetchModel:i-n,parse:c-i,parts:u-c,...d?{cull:performance.now()-u}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await dt(n,{...r,cull:!1,onParsed:(f)=>self.postMessage({id:t,insts:f})}),o=s.pack.buffer;if(self.postMessage({id:t,buffer:o,missing:s.missing,requests:s.requests,bytes:s.bytes,timings:s.timings},[o]),!r.cull)return;let i=performance.now(),l=Ae(s.insts,s.pack.header,r.textures!==!1),a=performance.now()-i,c=[];for(let f of[l.studHidden,l.studUp,l.underHidden,l.studHideStep,l.underHideStep])if(f)c.push(f.buffer);self.postMessage({id:t,cull:l,ms:a},c)}catch(s){if(s instanceof pe||s?.code==="ldr-budget")self.postMessage({id:t,phase:"error",error:String(s?.message??s),budget:{bodyTris:s.bodyTris,packBytes:s.packBytes,maxBodyTris:s.maxBodyTris,maxPackBytes:s.maxPackBytes}});else self.postMessage({id:t,phase:"error",error:String(s?.message??s)})}};\n';
|
|
3892
3945
|
|
|
3893
|
-
// ../../../../../../../tmp/ldr-build-
|
|
3946
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/cdn.ts
|
|
3894
3947
|
var worker;
|
|
3895
3948
|
var seq = 0;
|
|
3896
3949
|
var pending = new Map;
|
|
@@ -4003,7 +4056,7 @@ async function loadModel(source, o = {}) {
|
|
|
4003
4056
|
timings: { ...prep.timings, parts: t3 - t0 - prep.timings.fetchModel - prep.timings.parse, build: t4 - t3, total: t4 - t0 }
|
|
4004
4057
|
});
|
|
4005
4058
|
}
|
|
4006
|
-
// ../../../../../../../tmp/ldr-build-
|
|
4059
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/node/library.ts
|
|
4007
4060
|
import { existsSync, readFileSync } from "fs";
|
|
4008
4061
|
import { join } from "path";
|
|
4009
4062
|
var xf = (m, x, y, z) => [m[3] * x + m[4] * y + m[5] * z + m[0], m[6] * x + m[7] * y + m[8] * z + m[1], m[9] * x + m[10] * y + m[11] * z + m[2]];
|
|
@@ -4254,11 +4307,11 @@ class Library {
|
|
|
4254
4307
|
return insts;
|
|
4255
4308
|
}
|
|
4256
4309
|
}
|
|
4257
|
-
// ../../../../../../../tmp/ldr-build-
|
|
4310
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/node/build-pack.ts
|
|
4258
4311
|
import fs3 from "node:fs";
|
|
4259
4312
|
import path3 from "node:path";
|
|
4260
4313
|
|
|
4261
|
-
// ../../../../../../../tmp/ldr-build-
|
|
4314
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/node/resolver.ts
|
|
4262
4315
|
import fs from "node:fs";
|
|
4263
4316
|
import path from "node:path";
|
|
4264
4317
|
var TOP_STUD_RE = /^(stud|studa|stud2|stud2a|stud6|stud6a|stud10|stud15|stud2s|stud2s2|stud-logo\d*|stud2-logo\d*)\.dat$/i;
|
|
@@ -4530,11 +4583,11 @@ function collectDeps(lib, refs) {
|
|
|
4530
4583
|
return out;
|
|
4531
4584
|
}
|
|
4532
4585
|
|
|
4533
|
-
// ../../../../../../../tmp/ldr-build-
|
|
4586
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/node/compile.ts
|
|
4534
4587
|
import fs2 from "node:fs";
|
|
4535
4588
|
import path2 from "node:path";
|
|
4536
4589
|
|
|
4537
|
-
// ../../../../../../../tmp/ldr-build-
|
|
4590
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/node/lod.ts
|
|
4538
4591
|
import { MeshoptSimplifier, MeshoptEncoder } from "meshoptimizer";
|
|
4539
4592
|
await Promise.all([MeshoptSimplifier.ready, MeshoptEncoder.ready]);
|
|
4540
4593
|
function reorderMesh(P, N, C, I) {
|
|
@@ -4726,7 +4779,7 @@ function lodChain(P, C, I) {
|
|
|
4726
4779
|
return out;
|
|
4727
4780
|
}
|
|
4728
4781
|
|
|
4729
|
-
// ../../../../../../../tmp/ldr-build-
|
|
4782
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/node/compile.ts
|
|
4730
4783
|
function loadColors(root) {
|
|
4731
4784
|
const map = new Map;
|
|
4732
4785
|
for (const l of fs2.readFileSync(path2.join(root, "LDConfig.ldr"), "latin1").split(/\r?\n/)) {
|
|
@@ -5309,7 +5362,7 @@ function encodePack(parts, studKinds, weld, extra, options = {}) {
|
|
|
5309
5362
|
return Buffer.concat([head, ...chunks.map((c) => new Uint8Array(c.buffer, c.byteOffset, c.byteLength))]);
|
|
5310
5363
|
}
|
|
5311
5364
|
|
|
5312
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5365
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/node/build-pack.ts
|
|
5313
5366
|
function buildPack(o) {
|
|
5314
5367
|
const lib = new Library2(o.ldrawRoot);
|
|
5315
5368
|
const refs = new Map;
|
|
@@ -5376,7 +5429,7 @@ function buildPack(o) {
|
|
|
5376
5429
|
const warnings = [...lib.conflicts].map((n) => `${n}: defined differently by two models; the first definition is used`);
|
|
5377
5430
|
return { data: encodePack(parts, kinds, comp.opts.weld, extra, { texture, lod: o.lod !== false, reorder: !!o.reorder }), parts: parts.size, studKinds: kinds.size, missing: [...missing], ...warnings.length ? { warnings } : {} };
|
|
5378
5431
|
}
|
|
5379
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5432
|
+
// ../../../../../../../tmp/ldr-build-ogMgu7/src/node/promote.ts
|
|
5380
5433
|
var GEOM = /^\s*[2-5]\s/;
|
|
5381
5434
|
var REF = /^\s*1\s/;
|
|
5382
5435
|
var FILE = /^\s*0\s+FILE\s+(.+?)\s*$/i;
|
package/dist/render.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type LdrParams = {
|
|
|
15
15
|
condStuds?: boolean;
|
|
16
16
|
/** Draw textured (!TEXMAP) parts with their PNGs when the pack carries them (pack v2 "tex", `ldr pack --textures`). Default true. */
|
|
17
17
|
tex?: boolean;
|
|
18
|
-
/** Distance LOD: spatial clusters per part, simplified meshes from `lod` packs, studs dropped
|
|
18
|
+
/** Distance LOD: spatial clusters per part, simplified meshes from `lod` packs, studs as full → flat disc → dropped, edges hidden once sub-pixel. Default true. */
|
|
19
19
|
lod?: boolean;
|
|
20
20
|
/** LOD: max screen-space error in pixels (default 0.5). */
|
|
21
21
|
lodPx?: number;
|
package/dist/scene.d.ts
CHANGED
|
@@ -38,8 +38,8 @@ export interface LdrObjectOptions {
|
|
|
38
38
|
step?: number;
|
|
39
39
|
/** Distance LOD, re-selected for each camera you render with. Default true. Batches are split into spatial clusters (so off-screen
|
|
40
40
|
* ones are frustum-culled); each cluster draws the coarsest simplified mesh (from `lod` packs, the `buildPack` default) whose error
|
|
41
|
-
* stays under `lodPx`,
|
|
42
|
-
* Datsville 100k on an M4 Pro: 22 -> 4.3 ms per frame (57 -> 6.2 ms with edges); <=1.5% of pixels differ without edges
|
|
41
|
+
* stays under `lodPx`, swaps studs to a flat disc then drops them once under `lodPx`, and hides edge lines where a stud spans under
|
|
42
|
+
* `lodEdgePx`. Datsville 100k on an M4 Pro: 22 -> 4.3 ms per frame (57 -> 6.2 ms with edges); <=1.5% of pixels differ without edges. */
|
|
43
43
|
lod?: boolean;
|
|
44
44
|
/** LOD: max screen-space error in pixels. Default 0.5. */
|
|
45
45
|
lodPx?: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ldr",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "High-performance LEGO (LDraw) rendering for three.js: instanced parts packs, hidden stud/tube culling, low-detail studs, indexed edges, build steps.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Evan Bacon",
|