ldr 0.34.13 → 0.34.14
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/cull.d.ts +4 -2
- package/dist/index.js +102 -63
- package/dist/load-worker.gen.d.ts +1 -1
- package/dist/node/index.js +110 -71
- package/package.json +1 -1
package/dist/node/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/spec.ts
|
|
2
2
|
var norm = (s) => s.trim().toLowerCase().replace(/\\/g, "/").replace(/\/+/g, "/");
|
|
3
3
|
var COLOUR_ID_RE = /^[A-Za-z][A-Za-z0-9_]*$/;
|
|
4
4
|
var namedCodes = new Map;
|
|
@@ -833,7 +833,7 @@ function fileStepViews(f) {
|
|
|
833
833
|
viewMemo.set(f, out);
|
|
834
834
|
return out;
|
|
835
835
|
}
|
|
836
|
-
// ../../../../../../../tmp/ldr-build-
|
|
836
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/model.ts
|
|
837
837
|
class ModelLimitError extends Error {
|
|
838
838
|
limit;
|
|
839
839
|
code = "ldr-model-limit";
|
|
@@ -1283,7 +1283,7 @@ function blendedColourHex(code) {
|
|
|
1283
1283
|
const a = LDRAW_EXE_16[code - 256 >> 4], b = LDRAW_EXE_16[code - 256 & 15];
|
|
1284
1284
|
return "#" + [0, 1, 2].map((k) => (a[k] + b[k] >> 1).toString(16).padStart(2, "0")).join("").toUpperCase();
|
|
1285
1285
|
}
|
|
1286
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1286
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/instructions.ts
|
|
1287
1287
|
var MIN_VIS = 0.5;
|
|
1288
1288
|
var REORIENT = 0.35;
|
|
1289
1289
|
var deg = Math.PI / 180;
|
|
@@ -1651,10 +1651,10 @@ function planStepViews(insts, parts, stepOf, nSteps, o = {}) {
|
|
|
1651
1651
|
}
|
|
1652
1652
|
};
|
|
1653
1653
|
}
|
|
1654
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1654
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/render.ts
|
|
1655
1655
|
import * as THREE2 from "three";
|
|
1656
1656
|
|
|
1657
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1657
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/pack-io.ts
|
|
1658
1658
|
import { decompress } from "fzstd";
|
|
1659
1659
|
async function decompressPack(data) {
|
|
1660
1660
|
const u = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
@@ -1677,7 +1677,7 @@ function decodePack(buf) {
|
|
|
1677
1677
|
return { header, arr, bytes: buf.byteLength, buffer: buf };
|
|
1678
1678
|
}
|
|
1679
1679
|
|
|
1680
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1680
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/stud-decal.ts
|
|
1681
1681
|
import * as THREE from "three";
|
|
1682
1682
|
function studDecalUniforms(near = 0) {
|
|
1683
1683
|
return { center: { value: new THREE.Vector3 }, near: { value: near } };
|
|
@@ -1776,7 +1776,7 @@ roughnessFactor = clamp(roughnessFactor * mix(1.0, sdTop > 0.5 ? 0.85 : 1.1, sdK
|
|
|
1776
1776
|
return d;
|
|
1777
1777
|
}
|
|
1778
1778
|
|
|
1779
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1779
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/cull.ts
|
|
1780
1780
|
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;
|
|
1781
1781
|
var prepCache = new WeakMap;
|
|
1782
1782
|
var lastH = null;
|
|
@@ -1826,7 +1826,7 @@ function prepPart(H, part) {
|
|
|
1826
1826
|
break;
|
|
1827
1827
|
}
|
|
1828
1828
|
}
|
|
1829
|
-
c.set(part, r = { nStuds: n, studM, kind, color, mask, nx, nz, full });
|
|
1829
|
+
c.set(part, r = { nStuds: n, studM, kind, color, mask, nx, nz, full, src: p });
|
|
1830
1830
|
lastH = H;
|
|
1831
1831
|
lastPart = part;
|
|
1832
1832
|
lastPrep = r;
|
|
@@ -2048,24 +2048,33 @@ function seeThrough(H, c) {
|
|
|
2048
2048
|
return (g.alpha ?? 255) < 255;
|
|
2049
2049
|
return c.charCodeAt(0) === 35 && /\/[^:/]*:a\d/.test(c);
|
|
2050
2050
|
}
|
|
2051
|
-
function cullCore(insts, H, steps) {
|
|
2052
|
-
|
|
2051
|
+
function cullCore(insts, H, steps, pps) {
|
|
2052
|
+
if (!pps) {
|
|
2053
|
+
pps = new Array(insts.length);
|
|
2054
|
+
for (let i = 0;i < insts.length; i++)
|
|
2055
|
+
pps[i] = prepPart(H, insts[i].part);
|
|
2056
|
+
}
|
|
2057
|
+
return cullPass(insts, H, steps, -1, pps) ?? cullPass(insts, H, steps, needE, pps);
|
|
2053
2058
|
}
|
|
2054
2059
|
var needE = 0;
|
|
2055
|
-
function cullPass(insts, H, steps, eCap) {
|
|
2060
|
+
function cullPass(insts, H, steps, eCap, pps) {
|
|
2056
2061
|
const CELL = 40;
|
|
2057
2062
|
const clear = new Map;
|
|
2063
|
+
let lastC = null, lastV = false;
|
|
2058
2064
|
const isClear = (c) => {
|
|
2065
|
+
if (c === lastC)
|
|
2066
|
+
return lastV;
|
|
2059
2067
|
let v = clear.get(c);
|
|
2060
2068
|
if (v === undefined)
|
|
2061
2069
|
clear.set(c, v = seeThrough(H, c));
|
|
2070
|
+
lastC = c;
|
|
2071
|
+
lastV = v;
|
|
2062
2072
|
return v;
|
|
2063
2073
|
};
|
|
2064
2074
|
const nI = insts.length;
|
|
2065
2075
|
let cap = 0, nR = 0, nStuds = 0;
|
|
2066
|
-
const pps = new Array(nI);
|
|
2067
2076
|
for (let idx = 0;idx < nI; idx++) {
|
|
2068
|
-
const pp = pps[idx]
|
|
2077
|
+
const pp = pps[idx];
|
|
2069
2078
|
if (pp) {
|
|
2070
2079
|
nStuds += pp.nStuds;
|
|
2071
2080
|
if (pp.mask)
|
|
@@ -2085,9 +2094,10 @@ function cullPass(insts, H, steps, eCap) {
|
|
|
2085
2094
|
for (let idx = 0;idx < insts.length; idx++) {
|
|
2086
2095
|
const it = insts[idx];
|
|
2087
2096
|
const m = it.m;
|
|
2088
|
-
const
|
|
2089
|
-
if (!
|
|
2097
|
+
const pp = pps[idx];
|
|
2098
|
+
if (!pp || !pp.mask || !upright(m) || isClear(it.color))
|
|
2090
2099
|
continue;
|
|
2100
|
+
const p = pp.src;
|
|
2091
2101
|
const b = p.bbox;
|
|
2092
2102
|
let x0 = Infinity, x1 = -Infinity, z0 = Infinity, z1 = -Infinity;
|
|
2093
2103
|
for (let cxi = 0;cxi < 2; cxi++)
|
|
@@ -2104,7 +2114,6 @@ function cullPass(insts, H, steps, eCap) {
|
|
|
2104
2114
|
z1 = wz;
|
|
2105
2115
|
}
|
|
2106
2116
|
const lv2 = Math.round((m[1] + b[4]) * 2);
|
|
2107
|
-
const pp = pps[idx];
|
|
2108
2117
|
const cx0 = Math.floor(x0 / CELL), cx1 = Math.floor(x1 / CELL), cz0 = Math.floor(z0 / CELL), cz1 = Math.floor(z1 / CELL);
|
|
2109
2118
|
if (!((cx1 - cx0 + 1) * (cz1 - cz0 + 1) <= 65536) || !inRange(lv2, cx0, cz0) || !inRange(lv2, cx1, cz1))
|
|
2110
2119
|
continue;
|
|
@@ -2272,7 +2281,8 @@ function cullPass(insts, H, steps, eCap) {
|
|
|
2272
2281
|
const underHideStep = steps ? new Int32Array(insts.length).fill(STEP_NEVER) : undefined;
|
|
2273
2282
|
for (let idx = 0;idx < insts.length; idx++) {
|
|
2274
2283
|
const it = insts[idx];
|
|
2275
|
-
const
|
|
2284
|
+
const pp = pps[idx];
|
|
2285
|
+
const p = pp ? pp.src : null;
|
|
2276
2286
|
if (!p || !p.under || !upright(it.m) || isClear(it.color))
|
|
2277
2287
|
continue;
|
|
2278
2288
|
const b = p.bbox;
|
|
@@ -2358,7 +2368,7 @@ function precomputeCull(instances, H, useTex = true) {
|
|
|
2358
2368
|
return cullCore(s.all, H, s.nSteps > 1 ? s.stepOf : undefined);
|
|
2359
2369
|
}
|
|
2360
2370
|
|
|
2361
|
-
// ../../../../../../../tmp/ldr-build-
|
|
2371
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/render.ts
|
|
2362
2372
|
async function loadPack(url) {
|
|
2363
2373
|
const res = await fetch(url);
|
|
2364
2374
|
if (!res.ok)
|
|
@@ -2882,13 +2892,13 @@ function batchedBoundingBox(bm) {
|
|
|
2882
2892
|
const bb = bm.boundingBox;
|
|
2883
2893
|
return bb && !bb.isEmpty() ? Float32Array.of(bb.min.x, bb.min.y, bb.min.z, bb.max.x, bb.max.y, bb.max.z) : undefined;
|
|
2884
2894
|
}
|
|
2885
|
-
function fillInstances(im, ids, insts, color) {
|
|
2895
|
+
function fillInstances(im, ids, insts, color, cols) {
|
|
2886
2896
|
const M = im.instanceMatrix.array;
|
|
2887
2897
|
const C = new Float32Array(ids.length * 3);
|
|
2888
2898
|
for (let k = 0;k < ids.length; k++) {
|
|
2889
|
-
const
|
|
2899
|
+
const id = ids[k], it = insts[id];
|
|
2890
2900
|
writeM4(M, k * 16, it.m);
|
|
2891
|
-
color(it.color).toArray(C, k * 3);
|
|
2901
|
+
(cols?.[id] ?? color(it.color)).toArray(C, k * 3);
|
|
2892
2902
|
}
|
|
2893
2903
|
im.instanceColor = new THREE2.InstancedBufferAttribute(C, 3);
|
|
2894
2904
|
}
|
|
@@ -3479,7 +3489,7 @@ function studGridGeom(g, n) {
|
|
|
3479
3489
|
m.set(n, out);
|
|
3480
3490
|
return out;
|
|
3481
3491
|
}
|
|
3482
|
-
function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colorIndex, trim = false, grid = 1) {
|
|
3492
|
+
function* buildStudMeshesGen(insts, pps, H, cull, arr, LOD, color, matOf, steps, colorIndex, trim = false, grid = 1) {
|
|
3483
3493
|
const bKind = [], bMat = [];
|
|
3484
3494
|
const bAll = [];
|
|
3485
3495
|
const studBucket = new Uint16Array(cull.nStuds);
|
|
@@ -3512,13 +3522,18 @@ function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colo
|
|
|
3512
3522
|
const pass1 = (idx) => {
|
|
3513
3523
|
let j = jAt;
|
|
3514
3524
|
const jEnd = j + 32768;
|
|
3525
|
+
let pc = null, pe = null, qc = null, qe = null;
|
|
3515
3526
|
for (;idx < insts.length && j < jEnd; idx++) {
|
|
3516
|
-
const
|
|
3517
|
-
const pp = prepPart(H, it.part);
|
|
3527
|
+
const pp = pps[idx];
|
|
3518
3528
|
if (!pp || !pp.nStuds)
|
|
3519
3529
|
continue;
|
|
3530
|
+
const it = insts[idx];
|
|
3520
3531
|
const a = it.m;
|
|
3521
|
-
|
|
3532
|
+
if (it.color !== pc) {
|
|
3533
|
+
pc = it.color;
|
|
3534
|
+
pe = colEntry(pc);
|
|
3535
|
+
}
|
|
3536
|
+
const instE = pe;
|
|
3522
3537
|
let ps = partStud.get(pp);
|
|
3523
3538
|
if (!ps) {
|
|
3524
3539
|
const kid = new Int32Array(pp.nStuds), neg = new Uint8Array(pp.nStuds);
|
|
@@ -3542,7 +3557,7 @@ function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colo
|
|
|
3542
3557
|
const neg = (instNeg ^ ps.neg[si]) === 1;
|
|
3543
3558
|
const km = ps.kid[si] * 2 + (neg ? 1 : 0);
|
|
3544
3559
|
const sc = pp.color[si];
|
|
3545
|
-
const mid = sc === "16" ? matIdFor(it.color, instE, neg ? 1 : 0) : matIdFor(sc, colEntry(sc), neg ? 1 : 0);
|
|
3560
|
+
const mid = sc === "16" ? matIdFor(it.color, instE, neg ? 1 : 0) : matIdFor(sc, sc === qc ? qe : qe = colEntry(qc = sc), neg ? 1 : 0);
|
|
3546
3561
|
const row = bucketOfKM[mid];
|
|
3547
3562
|
let b = row[km];
|
|
3548
3563
|
if (b === undefined) {
|
|
@@ -3636,11 +3651,12 @@ function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colo
|
|
|
3636
3651
|
const pass3 = (idx) => {
|
|
3637
3652
|
let j = jAt;
|
|
3638
3653
|
const jEnd = j + 32768;
|
|
3654
|
+
let pc = null, pv = null;
|
|
3639
3655
|
for (;idx < insts.length && j < jEnd; idx++) {
|
|
3640
|
-
const
|
|
3641
|
-
const pp = prepPart(H, it.part);
|
|
3656
|
+
const pp = pps[idx];
|
|
3642
3657
|
if (!pp || !pp.nStuds)
|
|
3643
3658
|
continue;
|
|
3659
|
+
const it = insts[idx];
|
|
3644
3660
|
for (let si = 0;si < pp.nStuds; si++, j++) {
|
|
3645
3661
|
if (trim && cull.studHidden[j]) {
|
|
3646
3662
|
if (sMesh[studCl[j]]) {
|
|
@@ -3667,7 +3683,11 @@ function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colo
|
|
|
3667
3683
|
t.col[slot] = colorIndex(col);
|
|
3668
3684
|
}
|
|
3669
3685
|
writeM4(im.instanceMatrix.array, slot * 16, w);
|
|
3670
|
-
|
|
3686
|
+
if (col !== pc) {
|
|
3687
|
+
pc = col;
|
|
3688
|
+
pv = colorOf(col);
|
|
3689
|
+
}
|
|
3690
|
+
pv.toArray(im.instanceColor.array, slot * 3);
|
|
3671
3691
|
}
|
|
3672
3692
|
}
|
|
3673
3693
|
jAt = j;
|
|
@@ -3696,24 +3716,39 @@ function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colo
|
|
|
3696
3716
|
}
|
|
3697
3717
|
for (let k0 = 0;k0 < nHid; k0 += 65536) {
|
|
3698
3718
|
yield;
|
|
3699
|
-
hiddenStudSpheres(insts,
|
|
3719
|
+
hiddenStudSpheres(insts, pps, hidI, hidS, hidC, sMesh, k0, Math.min(nHid, k0 + 65536));
|
|
3700
3720
|
}
|
|
3701
3721
|
}
|
|
3702
3722
|
return sMesh;
|
|
3703
3723
|
}
|
|
3704
|
-
function hiddenStudSpheres(insts,
|
|
3705
|
-
const w = new Float64Array(12), A = new Float32Array(16);
|
|
3724
|
+
function hiddenStudSpheres(insts, pps, hidI, hidS, hidC, sMesh, k0, k1) {
|
|
3725
|
+
const w = new Float64Array(12), A = new Float32Array(16 * HID_RUN);
|
|
3726
|
+
let n = 0, cur = -1;
|
|
3706
3727
|
for (let k = k0;k < k1; k++) {
|
|
3707
|
-
const
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3728
|
+
const c = hidC[k];
|
|
3729
|
+
if (c !== cur || n === HID_RUN) {
|
|
3730
|
+
if (n) {
|
|
3731
|
+
const sm = sMesh[cur];
|
|
3732
|
+
sphereUnion(sm.S, A, n);
|
|
3733
|
+
if (sm.B)
|
|
3734
|
+
boxUnion(sm.B, A, n);
|
|
3735
|
+
n = 0;
|
|
3736
|
+
}
|
|
3737
|
+
cur = c;
|
|
3738
|
+
}
|
|
3739
|
+
const i = hidI[k];
|
|
3740
|
+
mul12To(insts[i].m, pps[i].studM, hidS[k] * 12, w);
|
|
3741
|
+
writeM4(A, n * 16, w);
|
|
3742
|
+
n++;
|
|
3743
|
+
}
|
|
3744
|
+
if (n) {
|
|
3745
|
+
const sm = sMesh[cur];
|
|
3746
|
+
sphereUnion(sm.S, A, n);
|
|
3713
3747
|
if (sm.B)
|
|
3714
|
-
boxUnion(sm.B, A,
|
|
3748
|
+
boxUnion(sm.B, A, n);
|
|
3715
3749
|
}
|
|
3716
3750
|
}
|
|
3751
|
+
var HID_RUN = 64;
|
|
3717
3752
|
function undersideGroups(ids, insts) {
|
|
3718
3753
|
const by = new Map;
|
|
3719
3754
|
const rest = [];
|
|
@@ -3823,19 +3858,23 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
3823
3858
|
return m;
|
|
3824
3859
|
};
|
|
3825
3860
|
const byPart = new Map;
|
|
3861
|
+
const pps = new Array(insts.length);
|
|
3862
|
+
const iCol = new Array(insts.length);
|
|
3826
3863
|
const matMemo = new Map;
|
|
3827
3864
|
const bucketMemo = new Map;
|
|
3828
3865
|
const bucketRange = (i0, i1) => {
|
|
3829
3866
|
for (let i = i0;i < i1; i++) {
|
|
3830
3867
|
const it = insts[i];
|
|
3831
|
-
const
|
|
3832
|
-
if (!
|
|
3868
|
+
const pp = pps[i] = prepPart(H, it.part);
|
|
3869
|
+
if (!pp)
|
|
3833
3870
|
continue;
|
|
3871
|
+
const p = pp.src;
|
|
3834
3872
|
const d = det12(it.m), mirror = d < 0;
|
|
3835
3873
|
const code = String(it.color), uncert = !!p.uncert || singular12(it.m, d), role = uncert ? 2 : mirror ? 1 : 0;
|
|
3836
3874
|
let me = matMemo.get(code);
|
|
3837
3875
|
if (!me)
|
|
3838
|
-
matMemo.set(code, me = [undefined, undefined, undefined]);
|
|
3876
|
+
matMemo.set(code, me = [undefined, undefined, undefined, color(code)]);
|
|
3877
|
+
iCol[i] = me[3];
|
|
3839
3878
|
const mat = me[role] ?? (me[role] = materialFor(code, mirror, uncert));
|
|
3840
3879
|
let pm = bucketMemo.get(it.part);
|
|
3841
3880
|
if (!pm)
|
|
@@ -3864,7 +3903,7 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
3864
3903
|
}
|
|
3865
3904
|
yield root;
|
|
3866
3905
|
const steps = P.steps;
|
|
3867
|
-
let cull = P.cull ?? cullCore(insts, H, steps);
|
|
3906
|
+
let cull = P.cull ?? cullCore(insts, H, steps, pps);
|
|
3868
3907
|
mark("culling");
|
|
3869
3908
|
yield root;
|
|
3870
3909
|
const stepBatches = [];
|
|
@@ -3887,7 +3926,7 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
3887
3926
|
insts.forEach((it, i) => {
|
|
3888
3927
|
for (let k = 0;k < 12; k++)
|
|
3889
3928
|
instM[i * 12 + k] = it.m[k];
|
|
3890
|
-
instPP.push(
|
|
3929
|
+
instPP.push(pps[i]);
|
|
3891
3930
|
instCol[i] = colorIndex(it.color);
|
|
3892
3931
|
});
|
|
3893
3932
|
const edgeObjs = [];
|
|
@@ -4080,7 +4119,7 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
4080
4119
|
let bodyIm = null;
|
|
4081
4120
|
const lv0 = [];
|
|
4082
4121
|
const place = (im) => {
|
|
4083
|
-
fillInstances(im, ids, insts, color);
|
|
4122
|
+
fillInstances(im, ids, insts, color, iCol);
|
|
4084
4123
|
instancedBoundingSphere(im);
|
|
4085
4124
|
im.userData.ldrPart = part;
|
|
4086
4125
|
root.add(im);
|
|
@@ -4161,7 +4200,7 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
4161
4200
|
stats.undersHidden += uids.length - vis;
|
|
4162
4201
|
const trimU = !steps && !!P.cullUnder;
|
|
4163
4202
|
const im = newIM(under, mat, trimU ? vis : uids.length);
|
|
4164
|
-
fillInstances(im, trimU ? ord.slice(0, vis) : ord, insts, color);
|
|
4203
|
+
fillInstances(im, trimU ? ord.slice(0, vis) : ord, insts, color, iCol);
|
|
4165
4204
|
im.onBeforeRender = trackVp;
|
|
4166
4205
|
im.userData.ldrUnder = true;
|
|
4167
4206
|
im.userData.ldrPart = part;
|
|
@@ -4298,7 +4337,7 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
4298
4337
|
writeM4(m16, 0, insts[id].m);
|
|
4299
4338
|
tmpM.fromArray(m16);
|
|
4300
4339
|
bm.setMatrixAt(iid, tmpM);
|
|
4301
|
-
tmpC.copy(color(insts[id].color));
|
|
4340
|
+
tmpC.copy(iCol[id] ?? color(insts[id].color));
|
|
4302
4341
|
bm.setColorAt(iid, tmpC);
|
|
4303
4342
|
instGids[iid] = gids;
|
|
4304
4343
|
if (ownArr) {
|
|
@@ -4331,7 +4370,7 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
4331
4370
|
if (!pp.edges && !(wantCond && (pp.condl || pp.condlu)))
|
|
4332
4371
|
continue;
|
|
4333
4372
|
const ghost = newIM(geom(pp.body, arr) || new THREE2.BufferGeometry, mat, ids.length);
|
|
4334
|
-
fillInstances(ghost, ids, insts, color);
|
|
4373
|
+
fillInstances(ghost, ids, insts, color, iCol);
|
|
4335
4374
|
const nL = cl.lines.length, nC = cl.cond.length;
|
|
4336
4375
|
if (pp.edges)
|
|
4337
4376
|
addLines(pp.edges, ghost, cl);
|
|
@@ -4415,7 +4454,7 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
4415
4454
|
writeM4(m16, 0, insts[id].m);
|
|
4416
4455
|
tmpM.fromArray(m16);
|
|
4417
4456
|
ubm.setMatrixAt(iid, tmpM);
|
|
4418
|
-
tmpC.copy(color(insts[id].color));
|
|
4457
|
+
tmpC.copy(iCol[id] ?? color(insts[id].color));
|
|
4419
4458
|
ubm.setColorAt(iid, tmpC);
|
|
4420
4459
|
uInstGids[iid] = gids;
|
|
4421
4460
|
uHid[iid] = hid ? 1 : 0;
|
|
@@ -4453,7 +4492,7 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
4453
4492
|
const ord = [...ids.filter((id) => !cull.underHidden[id]), ...ids.filter((id) => cull.underHidden[id])];
|
|
4454
4493
|
const vis = ids.length - ids.reduce((a, id) => a + cull.underHidden[id], 0);
|
|
4455
4494
|
const ghost = newIM(geom(pp.under, arr) || new THREE2.BufferGeometry, mat, ord.length);
|
|
4456
|
-
fillInstances(ghost, ord, insts, color);
|
|
4495
|
+
fillInstances(ghost, ord, insts, color, iCol);
|
|
4457
4496
|
const nC = ucl.cond.length;
|
|
4458
4497
|
addCond(pp, ghost, ucl, "under");
|
|
4459
4498
|
const lineObjs = ucl.cond.slice(nC);
|
|
@@ -4504,7 +4543,7 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
4504
4543
|
}
|
|
4505
4544
|
}
|
|
4506
4545
|
yield root;
|
|
4507
|
-
const _studGen = buildStudMeshesGen(insts, H, cull, arr, LOD, color, (c, mirror) => materialFor(c, mirror, false), steps, steps && colorIndex, !steps && !!P.cullStuds, G);
|
|
4546
|
+
const _studGen = buildStudMeshesGen(insts, pps, H, cull, arr, LOD, color, (c, mirror) => materialFor(c, mirror, false), steps, steps && colorIndex, !steps && !!P.cullStuds, G);
|
|
4508
4547
|
let _studR = _studGen.next();
|
|
4509
4548
|
while (!_studR.done) {
|
|
4510
4549
|
yield root;
|
|
@@ -4761,10 +4800,10 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
4761
4800
|
return true;
|
|
4762
4801
|
};
|
|
4763
4802
|
const box = new THREE2.Box3;
|
|
4764
|
-
for (
|
|
4765
|
-
if (!
|
|
4803
|
+
for (let i = 0;i < insts.length; i++) {
|
|
4804
|
+
if (!pps[i])
|
|
4766
4805
|
continue;
|
|
4767
|
-
const m =
|
|
4806
|
+
const m = insts[i].m;
|
|
4768
4807
|
if (m[0] < box.min.x)
|
|
4769
4808
|
box.min.x = m[0];
|
|
4770
4809
|
if (m[1] < box.min.y)
|
|
@@ -4896,7 +4935,7 @@ async function warmPackGeometry(pack, stop = () => false, sliceMs = 8) {
|
|
|
4896
4935
|
await new Promise((r) => setTimeout(r, 0));
|
|
4897
4936
|
}
|
|
4898
4937
|
}
|
|
4899
|
-
// ../../../../../../../tmp/ldr-build-
|
|
4938
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/scene.ts
|
|
4900
4939
|
import * as THREE3 from "three";
|
|
4901
4940
|
var _box = new THREE3.Box3;
|
|
4902
4941
|
var _m4 = new THREE3.Matrix4;
|
|
@@ -5300,10 +5339,10 @@ function createLdrObjectInner(instances, pack, options, progressive) {
|
|
|
5300
5339
|
return finish();
|
|
5301
5340
|
})();
|
|
5302
5341
|
}
|
|
5303
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5342
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/parts-cdn.ts
|
|
5304
5343
|
import { decompress as decompress2 } from "fzstd";
|
|
5305
5344
|
|
|
5306
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5345
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/embedded.ts
|
|
5307
5346
|
function splitFiles(text, fallback) {
|
|
5308
5347
|
const files = new Map;
|
|
5309
5348
|
let cur = null, saw = false, skip = false;
|
|
@@ -5381,7 +5420,7 @@ function embeddedKeys(text, names, fallback = "main.ldr") {
|
|
|
5381
5420
|
return out;
|
|
5382
5421
|
}
|
|
5383
5422
|
|
|
5384
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5423
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/parts-cdn.ts
|
|
5385
5424
|
var DEFAULT_PARTS_CDN = "https://ldr-parts-cdn.baconbrix.workers.dev/v1/";
|
|
5386
5425
|
var indexCache = new Map;
|
|
5387
5426
|
var shardCache = new Map;
|
|
@@ -5642,10 +5681,10 @@ async function prepareModel(source, o = {}) {
|
|
|
5642
5681
|
return { insts, pack, tier, missing, requests, bytes, cull, timings: { fetchModel: t1 - t0, parse: t2 - t1, parts: t3 - t2, ...cull ? { cull: performance.now() - t3 } : {} } };
|
|
5643
5682
|
}
|
|
5644
5683
|
|
|
5645
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5646
|
-
var load_worker_gen_default = 'var sn=ArrayBuffer,G=Uint8Array,$e=Uint16Array,on=Int16Array;var je=Int32Array,Je=function(e,t,n){if(G.prototype.slice)return G.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 G(n-t);return r.set(e.subarray(t,n)),r},Be=function(e,t,n,r){if(G.prototype.fill)return G.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},an=function(e,t,n,r){if(G.prototype.copyWithin)return G.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 ln=["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||ln[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,K);if(!n)throw r;return r},yt=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},cn=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},un=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,c=r>>6;if(r&8)K(0);var a=6-s,u=i==3?4:i,l=yt(e,a,u);a+=u;var f=c?1<<c:s,p=yt(e,a,f)+(c==1&&256),d=p;if(!s){var h=1<<10+(e[5]>>3);d=h+(h>>3)*(e[5]&7)}if(d>2145386496)K(1);var m=new G((t==1?p||d:t?0:d)+12);return m[0]=1,m[4]=4,m[8]=8,{b:a+f,y:0,l:0,d:l,w:t&&t!=1?t:m.subarray(12),e:d,o:new je(m.buffer,0,3),u:p,c:o,m:Math.min(131072,d)}}else if((n>>4|e[3]<<20)==25481893)return cn(e,4)+8;K(0)},Ee=function(e){var t=0;for(;1<<t<=e;++t);return t-1},De=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,c=-1,a=-1,u=-1,l=o,f=new sn(512+(o<<2)),p=new on(f,0,256),d=new $e(f,0,256),h=new $e(f,512,o),m=512+(o<<1),w=new G(f,m,o),b=new G(f,m+o);while(c<255&&i>0){var g=Ee(i+1),y=r>>3,A=(1<<g+1)-1,v=(e[y]|e[y+1]<<8|e[y+2]<<16)>>(r&7)&A,M=(1<<g)-1,z=A-i-1,E=v&M;if(E<z)r+=g,v=E;else if(r+=g+1,v>M)v-=z;if(p[++c]=--v,v==-1)i+=v,w[--l]=c;else i-=v;if(!v)do{var D=r>>3;a=(e[D]|e[D+1]<<8)>>(r&7)&3,r+=2,c+=a}while(a==3)}if(c>255||i)K(0);var x=0,U=(o>>1)+(o>>3)+3,k=o-1;for(var I=0;I<=c;++I){var F=p[I];if(F<1){d[I]=-F;continue}for(u=0;u<F;++u){w[x]=I;do x=x+U&k;while(x>=l)}}if(x)K(0);for(u=0;u<o;++u){var C=d[w[u]]++,j=b[u]=s-Ee(C);h[u]=(C<<j)-o}return[r+7>>3,{b:s,s:w,n:b,t:h}]},fn=function(e,t){var n=0,r=-1,s=new G(292),o=e[t],i=s.subarray(0,256),c=s.subarray(256,268),a=new $e(s.buffer,268);if(o<128){var u=De(e,t+1,6),l=u[0],f=u[1];t+=o;var p=l<<3,d=e[t];if(!d)K(0);var h=0,m=0,w=f.b,b=w,g=(++t<<3)-8+Ee(d);for(;;){if(g-=w,g<p)break;var y=g>>3;if(h+=(e[y]|e[y+1]<<8)>>(g&7)&(1<<w)-1,i[++r]=f.s[h],g-=b,g<p)break;y=g>>3,m+=(e[y]|e[y+1]<<8)>>(g&7)&(1<<b)-1,i[++r]=f.s[m],w=f.n[h],h=f.t[h],b=f.n[m],m=f.t[m]}if(++r>255)K(0)}else{r=o-127;for(;n<r;n+=2){var A=e[++t];i[n]=A>>4,i[n+1]=A&15}++t}var v=0;for(n=0;n<r;++n){var M=i[n];if(M>11)K(0);v+=M&&1<<M-1}var z=Ee(v)+1,E=1<<z,D=E-v;if(D&D-1)K(0);i[r++]=Ee(D)+1;for(n=0;n<r;++n){var M=i[n];++c[i[n]=M&&z+1-M]}var x=new G(E<<1),U=x.subarray(0,E),k=x.subarray(E);a[z]=0;for(n=z;n>0;--n){var I=a[n];Be(k,n,I,a[n-1]=I+c[n]*(1<<z-n))}if(a[0]!=E)K(0);for(n=0;n<r;++n){var F=i[n];if(F){var C=a[F];Be(U,n,C,a[F]=C+(1<<z-F))}}return[t,{n:k,b:z,s:U}]},pn=De(new G([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],mn=De(new G([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],hn=De(new G([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],xt=function(e,t){var n=e.length,r=new je(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Qe=new G(new je([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),gn=xt(Qe,0),qe=new G(new je([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),dn=xt(qe,3),Re=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,c=-n.b;if(!o)K(0);var a=0,u=n.b,l=(r<<3)-8+Ee(o)-u,f=-1;for(;l>c&&f<s;){var p=l>>3,d=(e[p]|e[p+1]<<8|e[p+2]<<16)>>(l&7);a=(a<<u|d)&i,t[++f]=n.s[a],l-=u=n.n[a]}if(l!=c||f+1!=s)K(0)},bn=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,c=o+i;Re(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),Re(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),Re(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,c),n),Re(e.subarray(r),t.subarray(c),n)},yn=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var c=o>>3|e[s+1]<<5|e[s+2]<<13,a=(s+=3)+c;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return Be(n,e[s],t.y,t.y+=c),n;return Be(new G(c),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+=c,n;return Je(e,s,a)}if(i==2){var u=e[s],l=u&3,f=u>>2&3,p=u>>4,d=0,h=0;if(l<2)if(f&1)p|=e[++s]<<4|(f&2&&e[++s]<<12);else p=u>>3;else if(h=f,f<2)p|=(e[++s]&63)<<4,d=e[s]>>6|e[++s]<<2;else if(f==2)p|=e[++s]<<4|(e[++s]&3)<<12,d=e[s]>>2|e[++s]<<6;else p|=e[++s]<<4|(e[++s]&63)<<12,d=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var m=n?n.subarray(t.y,t.y+t.m):new G(t.m),w=m.length-p;if(l==0)m.set(e.subarray(s,s+=p),w);else if(l==1)Be(m,e[s++],w);else{var b=t.h;if(l==2){var g=fn(e,s);d+=s-(s=g[0]),t.h=b=g[1]}else if(!b)K(0);(h?bn:Re)(e.subarray(s,s+=d),m.subarray(w),b)}var y=e[s++];if(y){if(y==255)y=(e[s++]|e[s++]<<8)+32512;else if(y>127)y=y-128<<8|e[s++];var A=e[s++];if(A&3)K(0);var v=[mn,hn,pn];for(var M=2;M>-1;--M){var z=A>>(M<<1)+2&3;if(z==1){var E=new G([0,0,e[s++]]);v[M]={s:E.subarray(2,3),n:E.subarray(0,1),t:new $e(E.buffer,0,1),b:0}}else if(z==2)r=De(e,s,9-(M&1)),s=r[0],v[M]=r[1];else if(z==3){if(!t.t)K(0);v[M]=t.t[M]}}var D=t.t=v,x=D[0],U=D[1],k=D[2],I=e[a-1];if(!I)K(0);var F=(a<<3)-8+Ee(I)-k.b,C=F>>3,j=0,de=(e[C]|e[C+1]<<8)>>(F&7)&(1<<k.b)-1;C=(F-=U.b)>>3;var be=(e[C]|e[C+1]<<8)>>(F&7)&(1<<U.b)-1;C=(F-=x.b)>>3;var me=(e[C]|e[C+1]<<8)>>(F&7)&(1<<x.b)-1;for(++y;--y;){var le=k.s[de],Te=k.n[de],Me=x.s[me],Le=x.n[me],ve=U.s[be],ce=U.n[be];C=(F-=ve)>>3;var Ce=1<<ve,ue=Ce+((e[C]|e[C+1]<<8|e[C+2]<<16|e[C+3]<<24)>>>(F&7)&Ce-1);C=(F-=qe[Me])>>3;var O=dn[Me]+((e[C]|e[C+1]<<8|e[C+2]<<16)>>(F&7)&(1<<qe[Me])-1);C=(F-=Qe[le])>>3;var T=gn[le]+((e[C]|e[C+1]<<8|e[C+2]<<16)>>(F&7)&(1<<Qe[le])-1);if(C=(F-=Te)>>3,de=k.t[de]+((e[C]|e[C+1]<<8)>>(F&7)&(1<<Te)-1),C=(F-=Le)>>3,me=x.t[me]+((e[C]|e[C+1]<<8)>>(F&7)&(1<<Le)-1),C=(F-=ce)>>3,be=U.t[be]+((e[C]|e[C+1]<<8)>>(F&7)&(1<<ce)-1),ue>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=ue-=3;else{var Y=ue-(T!=0);if(Y){if(ue=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]=ue}else ue=t.o[0]}for(var M=0;M<T;++M)m[j+M]=m[w+M];j+=T,w+=T;var J=j-ue;if(J<0){var H=-J,oe=t.e+J;if(H>O)H=O;for(var M=0;M<H;++M)m[j+M]=t.w[oe+M];j+=H,O-=H,J=0}for(var M=0;M<O;++M)m[j+M]=m[J+M];j+=O}if(j!=w)while(w<m.length)m[j++]=m[w++];else j=m.length;if(n)t.y+=j;else m=Je(m,0,j)}else if(n){if(t.y+=p,w)for(var M=0;M<p;++M)m[M]=m[w+M]}else if(w)m=Je(m,w);return t.b=a,m}K(2)},xn=function(e,t){if(e.length==1)return e[0];var n=new G(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 Ve(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=un(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 c=yn(e,i,t);if(!c)K(5);if(t)i.e=i.y;else n.push(c),o+=c.length,an(i.w,0,c.length),i.w.set(c,i.w.length-c.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return xn(n,o)}async function wn(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(Ve(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 wt(e){return new TextDecoder().decode(await wn(e))}var At=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split("/").pop()||"main.ldr").replace(/\\.(zst|gz)$/i,"")||"main.ldr";function _e(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,"/"),tt=/^[A-Za-z][A-Za-z0-9_]*$/,et=new Map;function nt(e){let t=e.toLowerCase(),n=2166136261;for(let s=0;s<t.length;s++)n^=t.charCodeAt(s),n=Math.imul(n,16777619);let r=-1-(n>>>0&1073741823);if(!et.has(r))et.set(r,t);return r}function rt(e){let t=e.charCodeAt(0)|32;if(t>=97&&t<=122&&tt.test(e))return nt(e);if(/^0x/i.test(e))return parseInt(e,16);return+e}var Mt=/^~?\\s*moved\\s+to\\s+(.+)$/i,An=new Set(["FILE","NOFILE","!DATA","!:","STEP","BFC","ROTSTEP","BUFEXCHG","!TEXMAP"]),Mn=new Set(["FILE","NOFILE","!DATA"]),Pt=1000000000000000,It=new Set(["part","subpart","primitive","8_primitive","48_primitive","shortcut","helper"]),vn=new Set(["model","submodel","configuration"]),Cn=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function vt(e){let t=Cn.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,"");return It.has(n)||vn.has(n)?n:void 0}function kn(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 Tn(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((f)=>Number.isFinite(f)&&Math.abs(f)<=1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000))return null;if(s>=10&&!(Math.abs(i[9])>=0.000001)||s===11&&!(Math.abs(i[10])>=0.000001))return null;let c=n[2].trim();for(let f=0;f<s;f++)c=c.replace(/^\\S+\\s*/,"");let a=kn(c);if(!a.length)return null;let u={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:a[0]};if(s>=10)u.a=i[9];if(s===11)u.b=i[10];let l=a.findIndex((f,p)=>p>0&&f.toUpperCase()==="GLOSSMAP");if(l>0&&a[l+1])u.glossmap=a[l+1];if(t)u.next=!0;return u}var Ln=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,"");if(t.length%4===1)t=t.slice(0,-1);let 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 Sn(e,t){let n=e.length,r=1,s=(h)=>h===32||h===9,o=()=>{while(r<n&&s(e.charCodeAt(r)))r++;let h=r,m=e.charCodeAt(r),w=m===45;if(w)m=e.charCodeAt(++r);let b=0,g=0;while(m>=48&&m<=57)b=b*10+(m-48),g++,m=e.charCodeAt(++r);if(g>0&&g<=15&&(r>=n||s(m)))return w?-b:b;while(r<n&&!s(e.charCodeAt(r)))r++;return h<r?+e.slice(h,r):NaN};while(r<n&&s(e.charCodeAt(r)))r++;let i=r;if(r>=n)return null;let c=e.charCodeAt(r),a=c===45,u=0,l=0;if(a)c=e.charCodeAt(++r);while(c>=48&&c<=57)u=u*10+(c-48),l++,c=e.charCodeAt(++r);if(l>0&&l<=15&&(r>=n||s(c))){if(a)u=-u}else{while(r<n&&!s(e.charCodeAt(r)))r++;u=rt(e.slice(i,r))}let f=Array(12);for(let h=0;h<12;h++){let m=o();if(!Number.isFinite(m))return null;f[h]=m}while(r<n&&s(e.charCodeAt(r)))r++;if(r>=n)return null;let p=e.slice(r),d=t.get(p);if(d===void 0)d=Z(/[ \\t]{2,}|\\t/.test(p)?p.split(/\\s+/).join(" "):p),t.set(p,d);if(!Number.isFinite(u))return null;return{t:1,color:u,m:f,file:d}}var En=[0,12,6,9,12,12];function Ct(e){let t=+e[0];if(!(t>=1&&t<=5&&Number.isInteger(t))||e.length<2)return null;let n=rt(e[1]),r=En[t];if(!Number.isFinite(n)||e.length<2+r+(t===1?1:0))return null;let s=Array(r);for(let o=0;o<r;o++){let i=+e[2+o];if(!Number.isFinite(i))return null;s[o]=i}if(t===1){let o=Z(e.slice(14).join(" "));return o?{t:1,color:n,m:s,file:o}:null}if(t===2)return{t:2,color:n,p:s};if(t===3)return{t:3,color:n,p:s};if(t===4)return{t:4,color:n,p:s};return{t:5,color:n,p:s}}function Ft(e,t="main.ldr",n={}){let r=!!n.geometryText,s=new Map,o=null,i="",c,a=null,u=[],l=null,f=()=>{if(!a)return;let y=Ln(a.chunks.join("")),A=y[0]===137&&y[1]===80&&y[2]===78&&y[3]===71;(c??=new Map).set(Z(a.name),{name:a.name,bytes:y,...A?{mime:"image/png"}:{}}),a=null},p=new Map,d=!0,h=(y)=>{if(f(),o={name:Z(y),cmds:[]},s.set(o.name,o),!i)i=o.name;u=[],l=null,d=!0},m=!1,w=!1,b=()=>{if(w)return;w=!0,s.clear(),o=null,i=""},g=(y,A)=>{if(l){y.tex=l,l=null;return}let v=u[u.length-1];if(!v)return;if(v.fallback){if(!A)y.fallback=!0}else y.tex=v.map};for(let y of e.split(`\n`)){let A=y.trim();if(!A)continue;if(r&&A.charCodeAt(0)>=50&&A.charCodeAt(0)<=53&&(A.charCodeAt(1)===32||A.charCodeAt(1)===9)){if(a||m)continue;if(!o)h(t);let E=A.slice(2).trimStart(),D=E.search(/\\s/),x={t:A.charCodeAt(0)-48,color:rt(D<0?E:E.slice(0,D)),p:[],src:A};g(x,!1),o.cmds.push(x),d=!1;continue}if(A.charCodeAt(0)===48&&(A.charCodeAt(1)===32||A.charCodeAt(1)===9)){let E=2;while(A.charCodeAt(E)===32||A.charCodeAt(E)===9)E++;let D=E;while(D<A.length&&A.charCodeAt(D)!==32&&A.charCodeAt(D)!==9)D++;let x=A.slice(E,D),U=/[^\\x21-\\x7e]/.test(x)?A.slice(E).trim().split(/\\s+/)[0]:x;if(!An.has(U)&&!(U.length>=4&&U.length<=6&&Mn.has(U.toUpperCase()))){if(m||a)continue;if(!o)h(t);let k=A.slice(E),I={t:0,text:k};if(x.charCodeAt(0)===33)I.meta=x;if(l=null,d&&!o.org){let C=vt(k);if(C)o.org=C}let F=k.match(Mt);if(F&&!o.movedTo){let C=F[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(C))C+=".dat";o.movedTo=Z(C)}o.cmds.push(I);continue}}if(A.charCodeAt(0)===49&&(A.charCodeAt(1)===32||A.charCodeAt(1)===9)&&!a&&!m){let E=Sn(A,p);if(E){if(!o)h(t);g(E,!1),o.cmds.push(E),d=!1;continue}}let v=A.split(/\\s+/);if(+v[0]===0){let E=A.slice(1).trim(),D=v.length>1&&v[1].length>=4&&v[1].length<=6?v[1].toUpperCase():v[1];if(D==="FILE"){let k=E.slice(5).trimStart().split("\\r")[0].trim();if(k){b(),m=!1,h(k);continue}}if(D==="NOFILE"){f(),o=null,m=!0;continue}if(D==="!DATA"){b(),f(),o=null,m=!1,a={name:E.slice(5).trim(),chunks:[]};continue}if(m)continue;if(a){if(v[1]==="!:")a.chunks.push(v.slice(2).join(""));continue}if(!o)h(t);let x={t:0,text:E};if(v[1]==="STEP")x.step=!0,u=[],l=null;else if(v[1]==="BFC")x.bfc=v.slice(2).join(" ");else if(v[1]==="ROTSTEP")if(x.meta="ROTSTEP",x.step=!0,u=[],l=null,(v[2]??"").toUpperCase()==="END")x.rotstep={x:0,y:0,z:0,mode:"END"};else{let k=(v[5]??"REL").toUpperCase(),I=(F)=>{let C=Number(F);return Number.isFinite(C)?C:0};x.rotstep={x:I(v[2]),y:I(v[3]),z:I(v[4]),mode:["REL","ABS","ADD"].includes(k)?k:"REL"}}else if(v[1]==="BUFEXCHG"){x.meta="BUFEXCHG";let k=(v[2]??"").toUpperCase();x.bufexchg={op:k==="RETRIEVE"?"RETRIEVE":"STORE",buf:v[3]??"A"}}else if(v[1]?.startsWith("!"))x.meta=v[1];if(d&&!o.org){let k=vt(E);if(k)o.org=k}if(v[1]==="!TEXMAP"){let k=(v[2]??"").toUpperCase();if(l=null,k==="START"||k==="NEXT"){let I=Tn(E.replace(/^!TEXMAP\\s+\\S+/i,""),k==="NEXT");if(x.texmap={op:k,...I?{map:I}:{}},I)if((o.texmaps??=[]).push(I),k==="START")u.push({map:I,fallback:!1});else l=I}else if(k==="FALLBACK"){x.texmap={op:k};let I=u[u.length-1];if(I)I.fallback=!0}else if(k==="END")x.texmap={op:k},u.pop()}else if(v[1]==="!:"){l=null;let k=Ct(v.slice(2));if(k)g(k,!0),x.geom=k}else l=null;let U=E.match(Mt);if(U&&!o.movedTo){let k=U[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(k))k+=".dat";o.movedTo=Z(k)}o.cmds.push(x);continue}if(a||m)continue;if(!o)h(t);let z=Ct(v);if(!z){if(/^[2-5][ \\t]/.test(A))d=!1;continue}g(z,!1),o.cmds.push(z),d=!1}return f(),c?{main:i,files:s,data:c}:{main:i,files:s}}var sr=Math.PI/180;function Rt(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 Bt(e,t){let[n,r,s,o,i,c,a,u,l,f,p,d]=e,[h,m,w,b,g,y,A,v,M,z,E,D]=t;return[o*h+i*m+c*w+n,a*h+u*m+l*w+r,f*h+p*m+d*w+s,o*b+i*A+c*z,o*g+i*v+c*E,o*y+i*M+c*D,a*b+u*A+l*z,a*g+u*v+l*E,a*y+u*M+l*D,f*b+p*A+d*z,f*g+p*v+d*E,f*y+p*M+d*D]}var Ge=[0,0,0,1,0,0,0,1,0,0,0,1];var kt=new WeakMap,Pn=/^(s|8|48)\\//;function st(e,t){let n=e.files.get(Z(t));if(!n)return"part";let r=kt.get(n);if(r)return r;if(n.org)r=It.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&&Pn.test(s.file))?"part":"model";return kt.set(n,r),r}var Tt=new WeakMap;function Dt(e){let t=Tt.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 Tt.set(e,t),t}var Lt=(e)=>e>16777215?"0x"+e.toString(16).toUpperCase():e<0?et.get(e)??String(e):String(e),In=(e)=>e.t===0?"0 "+e.text:e.t===1?`1 ${Lt(e.color)} ${e.m.join(" ")} ${e.file}`:e.src?e.src:`${e.t} ${Lt(e.color)} ${e.p.join(" ")}`,ot=(e,t)=>`${Z(e)}#${t}`;function Fn(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||o.meta==="!COLOUR"){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:ot(e.name,t),cmds:n}}function Ut(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Fn(e,t).cmds.map(In)].join(`\n`)+`\n`}function it(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 Nt(e){let[t,n,r,s,o,i,c,a,u,l,f,p]=e,d=a*p-u*f,h=-(c*p-u*l),m=c*f-a*l,w=s*d+o*h+i*m;if(!Number.isFinite(w)||Math.abs(w)<0.000000000001)return null;let b=1/w,g=[d*b,-(o*p-i*f)*b,(o*u-i*a)*b,h*b,(s*p-i*l)*b,-(s*u-i*c)*b,m*b,-(s*f-o*l)*b,(s*a-o*c)*b];return[-(g[0]*t+g[1]*n+g[2]*r),-(g[3]*t+g[4]*n+g[5]*r),-(g[6]*t+g[7]*n+g[8]*r),...g]}var Rn=(e)=>String(+e.toFixed(6)||0),St=(e)=>\'"\'+e.replace(/\\\\/g,"\\\\\\\\").replace(/"/g,"\\\\\\"")+\'"\';function Ot(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!=="PLANAR"?[t.a??360]:[],...t.method==="SPHERICAL"?[t.b??180]:[]].map(Rn).join(" "),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${St(t.texture)}${t.glossmap?" GLOSSMAP "+St(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-${it(r)}`,source:r}}var Bn=(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 Dn(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),c=Math.cos(t*r),a=Math.sin(n*r),u=Math.cos(n*r);return[c*u,-c*a,i,o*a+s*i*u,o*u-s*i*a,-s*c,s*a-o*i*u,s*u+o*i*a,o*c]}var Et=new WeakMap;function zt(e){let t=Et.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=Dn(o.x,o.y,o.z);r=o.mode==="ABS"?{abs:!0,m:i,rotstep:o}:o.mode==="ADD"&&r?{abs:r.abs,m:Bn(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),Et.set(e,n),n}class at extends Error{limit;code="ldr-model-limit";constructor(e,t){super(`ldr: ${e} expands past ${t.toLocaleString("en-US")} (see maxInstances)`);this.limit=t;this.name="ModelLimitError"}}var Un=(e)=>{for(let t=0;t<12;t++)if(!(Math.abs(e[t])<=Pt))return!1;return!0},$t=999999,_t=(e)=>e.map((t)=>String(t).padStart(6,"0")).join(".")+"~",Gt=new WeakMap,jt=new WeakMap;function Nn(e,t){let n=jt.get(t);if(!n)n={head:[...t.values()].map((o)=>{let i=Gt.get(o)??"",c=i.indexOf("!COLOUR");return c<0?"":"0 "+i.slice(c).trim().replace(/\\s+/g," ")}).filter(Boolean).join(`\n`),parts:new Map},jt.set(t,n);let r=n.parts.get(e);if(!r){let s=Z(e),o=`0 ldr: ${s} placed in a model\'s !COLOUR scope\n0 BFC CERTIFY CCW\n${n.head}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${s}\n`;r={name:`${s}#col-${it(o)}`,source:o},n.parts.set(e,r)}return r}function On(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,c=new Map,a=0,u=[],l=(w,b)=>{if(w.length)return[...w,b];let g=u[b];if(!g)u[b]=g=[b];return g},f=new Set,p=t.maxInstances??2000000,d=0,h=(w,b)=>{let g=w.name+"#"+b,y=c.get(g);if(!y){let A;y=Object.assign(()=>A??=Ut(w,b),{file:w,step:b}),c.set(g,y)}return y},m=(w,b,g,y,A,v,M,z,E=null,D=[],x=[],U=void 0,k=null)=>{let I=w.files.get(b);if(!I||M>r||f.has(I))return;if(++d>p)throw new at("model",p);f.add(I);let F=k,C=0,j=M>0?++a:0,de=i&&j?[...D,j]:D,be=i&&j?[...x,g]:x,me=i&&!E?new Map:null,le=-1,Te=0,Me=(O,T,Y,J,H,oe,L)=>{if(le!==C)le=C,Te=0;let B=me?.get(C+"|"+T);if(B)return B.n++,m(O,O===w?T:O.main,Y,J,A+"/"+T,[...H,$t],M+1,oe,[...H,$t],de,be,L,F);let P=[...H,Te++],R=n.length;m(O,O===w?T:O.main,Y,J,A+"/"+T,P,M+1,oe,E,de,be,L,F),me?.set(C+"|"+T,{n:1,from:R,to:n.length})},Le=zt(I),ve=s?Dt(I):[],ce=0,Ce=(O,T,Y,J,H,oe,L,B,P)=>{if(E)J=E;if(++d>p)throw new at("model",p);let R={part:O,color:T,m:Y,step:J[0],steps:J,localStep:H,path:A};if(B)R.colour=B;if(j){if(R.sub=j,i)R.subPath=de,R.subMats=be}if(oe)R.embedded=!0;if(L){let N=Ot(O,L);R.texPart=N.name,R.texSource=N.source}else if(P){let N=Nn(O,P);R.colPart=N.name,R.colSource=N.source}let S=Le[H];if(S)R.view=S;return n.push(R),R},ue=(O)=>{while(ce<ve.length&&ve[ce]<=O){let T=ve[ce++];Ce(ot(I.name,T),y,g,l(v,T),T,!1,null,U,k).source=h(I,T)}};for(let O of I.cmds){if(O.t===0&&O.step){C++;continue}let T=O;if(T.t>=2||T.t===0&&T.geom&&T.geom.t>=2){ue(C);continue}if(T.t===0){if(T.meta==="!COLOUR"){let S=$n(T.text);if(S&&S.code!==16&&S.code!==24)Gt.set(S,T.text),(F=new Map(F??[])).set(S.code,S);continue}if(o&&T.geom?.t===1)T=T.geom;else continue}if(T.t!==1)continue;if(o&&T.fallback)continue;let Y=g===Ge?T.m:Bt(g,T.m);if(!Un(Y))continue;let J=T.color===16?y:T.color,H=T.color===16?U:F?.get(T.color),oe=l(v,C),L=o?T.tex??z:null,B=L?Nt(T.m):null,P=L&&B?Rt(L,B):null;if(w.files.has(T.file)){if(st(w,T.file)==="model"){Me(w,T.file,Y,J,oe,P,H);continue}Ce(T.file,J,Y,oe,C,!0,P,H,F);continue}let R=t.resolveModel?.(T.file);if(R){Me(R,T.file,Y,J,oe,P,H);continue}Ce(T.file,J,Y,oe,C,!1,P,H,F)}if(ue(1/0),f.delete(I),me){for(let O of me.values())if(O.n>1)for(let T=O.from;T<O.to;T++)n[T].mult??=O.n}};if(st(e,e.main)==="part"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...Ge],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return m(e,e.main,Ge,16,e.main,[],0,null),n}function Ht(e,t="main.ldr",n){return On(Ft(e,t,{geometryText:!0}),n)}var zn=new Set(["CHROME","PEARLESCENT","RUBBER","MATTE_METALLIC","METAL","MATERIAL"]);function lt(e){if(!e)return null;if(e.startsWith("#")&&/^#[0-9A-Fa-f]{6}$/.test(e))return e.toUpperCase();if(/^0x[0-9A-Fa-f]{6}$/i.test(e))return("#"+e.slice(2)).toUpperCase();return null}function Vt(e,t){let n={value:"#FFFFFF",fraction:0.5};while(t<e.length){let r=e[t].toUpperCase(),s=e[t+1];if(r==="VALUE"){let o=lt(s);if(o)n.value=o;t+=2}else if(r==="ALPHA")n.alpha=+s,t+=2;else if(r==="LUMINANCE")n.luminance=+s,t+=2;else if(r==="FRACTION")n.fraction=+s,t+=2;else if(r==="VFRACTION")n.vfraction=+s,t+=2;else if(r==="SIZE")n.size=+s,t+=2;else if(r==="MINSIZE")n.minsize=+s,t+=2;else if(r==="MAXSIZE")n.maxsize=+s,t+=2;else break}return{grain:n,next:t}}function $n(e){let t=e.indexOf("!COLOUR");if(t<0)return null;let n=e.slice(t+7).trim().split(/\\s+/).filter(Boolean);if(n.length<2)return null;let r=n[0],s=NaN,o="#FF00FF",i="#333333",c=255,a=0,u={type:"default"},l=1;while(l<n.length){let f=n[l].toUpperCase(),p=n[l+1];if(f==="CODE")s=p!==void 0&&tt.test(p)?nt(p):p!==void 0&&/^\\d+$/.test(p)?+p:NaN,l+=2;else if(f==="VALUE"){let d=lt(p);if(d)o=d;l+=2}else if(f==="EDGE")i=lt(p)??p,l+=2;else if(f==="ALPHA")c=+p,l+=2;else if(f==="LUMINANCE")a=+p,l+=2;else if(f==="CHROME")u={type:"chrome"},l+=1;else if(f==="PEARLESCENT")u={type:"pearlescent"},l+=1;else if(f==="RUBBER")u={type:"rubber"},l+=1;else if(f==="MATTE_METALLIC")u={type:"matte_metallic"},l+=1;else if(f==="METAL")u={type:"metal"},l+=1;else if(f==="MATERIAL"){let d=(n[l+1]||"").toUpperCase();if(d==="GLITTER"){let{grain:h,next:m}=Vt(n,l+2);u={type:"glitter",material:h},l=m}else if(d==="SPECKLE"){let{grain:h,next:m}=Vt(n,l+2);u={type:"speckle",material:h},l=m}else if(d==="FABRIC"){let h=(n[l+2]||"").toUpperCase(),m=["VELVET","CANVAS","STRING","FUR"].includes(h)?h.toLowerCase():void 0;u={type:"fabric",kind:m},l+=m?3:2}else l=n.length}else if(zn.has(f))l+=1;else l+=1}if(Number.isNaN(s)||!o)return null;return{code:s,name:r,hex:o,edge:i,alpha:Number.isFinite(c)?c:255,luminance:Number.isFinite(a)?a:0,finish:u}}function jn(e){let t=Math.max(0,Math.min(1,(e.alpha??255)/255)),n=t<1,r=Math.max(0,Math.min(1,(e.luminance??0)/255)),s={opacity:t,transparent:n,depthWrite:!n,emissive:r,clearcoat:0,clearcoatRoughness:0,sheen:0,sheenRoughness:0};switch(e.finish?.type??"default"){case"chrome":return{...s,metalness:1,roughness:0,finish:"chrome"};case"pearlescent":return{...s,metalness:0.25,roughness:0.3,clearcoat:0.5,clearcoatRoughness:0.25,sheen:0.4,sheenRoughness:0.35,finish:"pearlescent"};case"rubber":return{...s,metalness:0,roughness:0.9,finish:"rubber"};case"matte_metallic":return{...s,metalness:0.4,roughness:0.8,finish:"matte_metallic"};case"metal":return{...s,metalness:0.85,roughness:0.2,finish:"metal"};case"glitter":{let i=e.finish.material,c=i.size??(i.minsize!=null&&i.maxsize!=null?(i.minsize+i.maxsize)/2:1);return{...s,metalness:0.35,roughness:0.25,clearcoat:1,clearcoatRoughness:0.08,particleHex:i.value,particleFraction:i.fraction,particleSize:c,finish:"glitter"}}case"speckle":{let i=e.finish.material,c=i.size??(i.minsize!=null&&i.maxsize!=null?(i.minsize+i.maxsize)/2:1);return{...s,metalness:0.2,roughness:0.55,particleHex:i.value,particleFraction:i.fraction,particleSize:c,finish:"speckle"}}case"fabric":return{...s,metalness:0,roughness:0.85,sheen:0.65,sheenRoughness:0.75,finish:"fabric"};default:return{...s,metalness:0,roughness:0.45,finish:"default"}}}function ct(e){let t=jn(e),n=!t.transparent?"op":t.opacity>=0.75?"a200":t.opacity>=0.4?"a128":`a${Math.round(t.opacity*255)}`,r=t.emissive>0?`L${Math.round(t.emissive*16)}`:"",s=`${t.finish}:${n}${r}`;if(t.particleHex)s+=`:${t.particleHex}:${(t.particleFraction??0).toFixed(2)}`;return s}function Vn(e,t){let n=new Map,r=null,s=!1,o=!1;for(let i of e.split(/\\r?\\n/)){let c=/^\\s*0\\s+FILE\\s+(\\S[^\\r]*)/i.exec(i);if(c){if(!s)n.clear();s=!0,o=!1,r=[],n.set(Z(c[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(i)){if(!s&&/!DATA/i.test(i))n.clear(),s=!0;r=null,o=!0;continue}if(!r){if(s||o)continue;r=[],n.set(Z(t),r)}let a=i.trim().replace(/\\s+/g," ");if(a)r.push(a)}return n}var _n=(e)=>{if(!e.startsWith("1 "))return null;let t=e.split(" ");return t.length>=15?Z(t.slice(14).join(" ")):null};function Gn(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 Wt(e,t,n="main.ldr"){let r=[...t],s=new Map;if(!r.length)return s;let o=Vn(e,n);for(let i of r){let c=Z(i);if(!o.has(c)||s.has(c))continue;let a=new Set([c]),u=[c];while(u.length)for(let f of o.get(u.pop())){let p=_n(f);if(p&&o.has(p)&&!a.has(p))a.add(p),u.push(p)}let l=[c,...[...a].filter((f)=>f!==c).sort()].map((f)=>"0 FILE "+(f===c?"":f)+`\n`+o.get(f).join(`\n`)).join(`\n`);s.set(c,`emb/${Gn(l)}.dat`)}return s}var Xt=(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,Kt=new WeakMap,ut=null,ft="",pt=null;function Hn(e,t){if(e===ut&&t===ft)return pt;let n=Kt.get(e);if(!n)Kt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return ut=e,ft=t,pt=r,r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),c=[],a=[];s.studs.forEach((d,h)=>{c.push(d[0]),a.push(d[1]);for(let m=0;m<12;m++)i[h*12+m]=d[2+m]});let u=null,l=0,f=0;if(s.mask){l=s.mask[0],f=s.mask[1];let d=s.mask[2];u=new Uint8Array(d.length);for(let h=0;h<d.length;h++)u[h]=d.charCodeAt(h)===49?1:0}let p=!!u;if(u){for(let d=0;d<u.length;d++)if(u[d]!==1){p=!1;break}}return n.set(t,r={nStuds:o,studM:i,kind:c,color:a,mask:u,nx:l,nz:f,full:p}),ut=e,ft=t,pt=r,r}var Ie=1073741824;class Pe{t;tag;mask;size=0;shift;constructor(e=1024,t=-1){let n=1024;while(n<e*2)n*=2;this.t=new Int32Array(n*4),this.tag=new Uint8Array(n),this.mask=n-1,this.shift=t}slot(e,t,n){let r=this.shift;if(r<0){let o=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return o^=o>>>15,o=Math.imul(o,739982445),o^=o>>>12,o&this.mask}let s=Math.imul(e>>r+2,2654435761)^Math.imul(t,2246822507)^Math.imul(n>>r+2,3266489909);return s^=s>>>15,s=Math.imul(s,739982445),s^=s>>>12,(s<<4|(e>>r&3)<<2|n>>r&3)&this.mask}static tagOf(e,t,n){return Math.imul(e^Math.imul(t,374761393)^Math.imul(n,668265261),2654435761)>>>24|1}get(e,t,n){let r=Pe.tagOf(e,t,n),s=this.tag,o=this.t,i=this.mask,c=this.slot(e,t,n);for(;;){let a=s[c];if(a===0)return-1;if(a===r){let u=c<<2;if(o[u]===e&&o[u+1]===t&&o[u+2]===n)return o[u+3]}c=c+1&i}}put(e,t,n,r){if((this.size+1)*2>this.tag.length)this.grow();let s=Pe.tagOf(e,t,n),o=this.tag,i=this.t,c=this.mask,a=this.slot(e,t,n);for(;;){let u=o[a],l=a<<2;if(u===0)return o[a]=s,i[l]=e,i[l+1]=t,i[l+2]=n,i[l+3]=r,this.size++,-1;if(u===s&&i[l]===e&&i[l+1]===t&&i[l+2]===n){let f=i[l+3];return i[l+3]=r,f}a=a+1&c}}grow(){let e=this.t,t=this.tag,n=t.length*2;this.t=new Int32Array(n*4),this.tag=new Uint8Array(n),this.mask=n-1,this.size=0;for(let r=0;r<t.length;r++)if(t[r]){let s=r<<2;this.put(e[s],e[s+1],e[s+2],e[s+3])}}}class Yt{grp=new Pe(64);gBits=[];gX0=[];gZ0=[];gNz=[];gNx=[];bits;rest;lk=NaN;lpx=NaN;lpz=NaN;lg=-1;group(e,t,n){if(e!==this.lk||t!==this.lpx||n!==this.lpz)this.lk=e,this.lpx=t,this.lpz=n,this.lg=this.grp.get(e,t,n);return this.lg}constructor(e,t,n,r){let s=[],o=[],i=[],c=[],a=[];for(let f=0;f<r;f++){let p=e[f],d=t[f],h=n[f],m=(p%20+20)%20,w=(h%20+20)%20,b=this.group(d,m,w);if(b<0)b=s.length,this.grp.put(d,m,w,b),this.lg=b,s.push(0),o.push(p),i.push(p),c.push(h),a.push(h);if(s[b]++,p<o[b])o[b]=p;else if(p>i[b])i[b]=p;if(h<c[b])c[b]=h;else if(h>a[b])a[b]=h}let u=0,l=0;for(let f=0;f<s.length;f++){let p=(i[f]-o[f])/20+1,d=(a[f]-c[f])/20+1,h=p*d;if(this.gX0.push(o[f]),this.gZ0.push(c[f]),this.gNx.push(p),this.gNz.push(d),h<=64*s[f]+1024&&u+h<2147483648)this.gBits.push(u),u+=h;else this.gBits.push(-1),l+=s[f]}this.bits=new Uint8Array(Math.ceil(u/8)),this.rest=new Pe(l);for(let f=0;f<r;f++){let p=e[f],d=t[f],h=n[f],m=this.group(d,(p%20+20)%20,(h%20+20)%20),w=this.gBits[m];if(w<0){this.rest.put(p,d,h,1);continue}let b=w+(p-this.gX0[m])/20*this.gNz[m]+(h-this.gZ0[m])/20;this.bits[b>>>3]|=1<<(b&7)}}has(e,t,n){let r=this.group(t,(e%20+20)%20,(n%20+20)%20);if(r<0)return!1;let s=this.gBits[r];if(s<0)return this.rest.get(e,t,n)>=0;let o=(e-this.gX0[r])/20,i=(n-this.gZ0[r])/20;if(o<0||i<0||o>=this.gNx[r]||i>=this.gNz[r])return!1;let c=s+o*this.gNz[r]+i;return(this.bits[c>>>3]&1<<(c&7))!==0}}var Wn=(e,t,n,r)=>e===0&&r===0&&(t===1||t===-1)&&(n===1||n===-1)||t===0&&n===0&&(e===1||e===-1)&&(r===1||r===-1),Fe=(e,t,n)=>e>-Ie&&e<Ie&&t>-Ie&&t<Ie&&n>-Ie&&n<Ie,Ue=2147483647;function Xn(e,t){let n=e.colorTable?.[t];if(n)return(n.alpha??255)<255;return t.charCodeAt(0)===35&&/\\/[^:/]*:a\\d/.test(t)}function mt(e,t,n){return Zt(e,t,n,-1)??Zt(e,t,n,Jt)}var Jt=0;function Zt(e,t,n,r){let o=new Map,i=(L)=>{let B=o.get(L);if(B===void 0)o.set(L,B=Xn(t,L));return B},c=e.length,a=0,u=0,l=0,f=Array(c);for(let L=0;L<c;L++){let B=f[L]=Hn(t,e[L].part);if(B){if(l+=B.nStuds,B.mask)a++}}let p=new Float64Array(a),d=new Float64Array(a),h=new Float64Array(a),m=new Float64Array(a),w=new Int32Array(a),b=new Int32Array(a),g=new Float64Array(a),y=new Float64Array(a),A=[],v=new Int32Array(a),M=new Float64Array(a*9),z=new Uint8Array(a);if(r<0)r=a*4+64;let E=new Pe(e.length*2),D=new Int32Array(r),x=new Int32Array(r),U=0,k=0;for(let L=0;L<e.length;L++){let B=e[L],P=B.m,R=t.parts[B.part];if(!R||!R.mask||!Xt(P)||i(B.color))continue;let S=R.bbox,N=1/0,V=-1/0,q=1/0,W=-1/0;for(let X=0;X<2;X++)for(let ie=0;ie<2;ie++){let ee=X?S[3]:S[0],Se=ie?S[5]:S[2],Ae=P[0]+P[3]*ee+P[5]*Se,ge=P[2]+P[9]*ee+P[11]*Se;if(Ae<N)N=Ae;if(Ae>V)V=Ae;if(ge<q)q=ge;if(ge>W)W=ge}let _=Math.round((P[1]+S[4])*2),Q=f[L],ae=Math.floor(N/40),ye=Math.floor(V/40),xe=Math.floor(q/40),we=Math.floor(W/40);if(!((ye-ae+1)*(we-xe+1)<=65536)||!Fe(_,ae,xe)||!Fe(_,ye,we))continue;let he=Math.floor((N+5)/40),te=Math.floor((V-5)/40),ne=Math.floor((q+5)/40),re=Math.floor((W-5)/40),ke=he<=te&&ne<=re?(te-he+1)*(re-ne+1):0;k+=ke;let fe=-1;for(let X=he<=te&&ne<=re?E.get(_,he,ne):-1,ie=0;X>=0&&ie<8;X=D[X],ie++){let ee=x[X];if(p[ee]!==N||d[ee]!==V||h[ee]!==q||m[ee]!==W||A[ee]!==Q)continue;let Se=e[w[ee]].m,Ae=!0;for(let ge=0;ge<12;ge++)if(Se[ge]!==P[ge]){Ae=!1;break}if(Ae){fe=ee;break}}if(fe>=0){let X=n?n[L]:0;if(n&&X<n[w[fe]])b[fe]=w[fe],w[fe]=L;else if(b[fe]<0||n&&X<n[b[fe]])b[fe]=L;continue}let se=u++;p[se]=N,d[se]=V,h[se]=q,m[se]=W,w[se]=L,b[se]=-1,A.push(Q),g[se]=S[0],y[se]=S[2],v[se]=_;let pe=se*9;if(M[pe]=P[0],M[pe+1]=P[1],M[pe+2]=P[2],M[pe+3]=P[3],M[pe+4]=P[6],M[pe+5]=P[9],M[pe+6]=P[5],M[pe+7]=P[8],M[pe+8]=P[11],z[se]=Q.full&&S[3]-S[0]<=20*Q.nx&&S[5]-S[2]<=20*Q.nz&&P[4]===0&&P[6]===0&&P[8]===0&&P[10]===0&&Wn(P[3],P[5],P[9],P[11])?1:0,U+ke>r){U=r+1;continue}for(let X=he;X<=te;X++)for(let ie=ne;ie<=re;ie++){if(!Fe(_,X,ie))continue;let ee=U++;x[ee]=se,D[ee]=E.put(_,X,ie,ee)}}if(U>r)return Jt=k,null;let I=[0,5,-5,5,-5],F=[0,5,5,-5,-5],C=(L,B,P,R)=>{if(!(B-6>=p[L]-0.5&&B+6<=d[L]+0.5&&R-6>=h[L]-0.5&&R+6<=m[L]+0.5))return!1;if(z[L]===1)return!0;let S=L*9,N=A[L],V=g[L],q=y[L],W=B-M[S],_=P-M[S+1],Q=R-M[S+2],ae=M[S+3]*W+M[S+4]*_+M[S+5]*Q,ye=M[S+6]*W+M[S+7]*_+M[S+8]*Q,{nx:xe,nz:we,mask:he}=N;for(let te=0;te<5;te++){let ne=Math.floor((ae+I[te]-V)/20),re=Math.floor((ye+F[te]-q)/20);if(ne<0||re<0||ne>=xe||re>=we||he[ne*we+re]!==1)return!1}return!0},j=NaN,de=NaN,be=NaN,me=-1,le=-1,Te=(L,B,P,R)=>{let S=Math.round(B*2),N=Math.floor(L/40),V=Math.floor(P/40);if(!Fe(S,N,V))return Ue;let q=Ue;if(!n&&le>=0&&v[le]===S&&(w[le]!==R||b[le]>=0)&&C(le,L,B,P))return 0;if(S!==j||N!==de||V!==be)j=S,de=N,be=V,me=E.get(S,N,V);for(let W=me;W>=0;W=D[W]){let _=x[W],Q=w[_];if(Q===R&&(Q=b[_])<0)continue;if(!C(_,L,B,P))continue;if(!n)return le=_,0;let ae=n[Q];if(ae<q)q=ae}return q},Me=new Uint8Array(l),Le=new Uint8Array(l),ve=0,ce=n?new Pe(l,4):null,Ce=n?null:new Int32Array(l),ue=n?null:new Int32Array(l),O=n?null:new Int32Array(l),T=0,Y=n?new Int32Array(l).fill(Ue):void 0;for(let L=0,B=0;L<e.length;L++){let P=e[L],R=f[L];if(!R)continue;let S=P.m,N=R.studM,V=S[0],q=S[1],W=S[2],_=S[3],Q=S[4],ae=S[5],ye=S[6],xe=S[7],we=S[8],he=S[9],te=S[10],ne=S[11];for(let re=0;re<R.nStuds;re++,B++){let ke=re*12,fe=N[ke+4],se=N[ke+7],pe=N[ke+10];if(!(Math.abs(ye*fe+xe*se+we*pe-1)<0.001&&Math.abs(_*fe+Q*se+ae*pe)<0.001&&Math.abs(he*fe+te*se+ne*pe)<0.001))continue;Le[B]=1;let X=N[ke],ie=N[ke+1],ee=N[ke+2],Se=V+_*X+Q*ie+ae*ee,Ae=q+ye*X+xe*ie+we*ee,ge=W+he*X+te*ie+ne*ee,gt=Te(Se,Ae,ge,L);if(gt!==Ue){if(Me[B]=1,ve++,Y)Y[B]=gt}let Ne=Math.round(Se),Oe=Math.round(Ae),ze=Math.round(ge);if(!Fe(Ne,Oe,ze))continue;if(!ce){Ce[T]=Ne,ue[T]=Oe,O[T++]=ze;continue}let dt=n[L],bt=ce.get(Ne,Oe,ze);if(bt<0||dt<bt)ce.put(Ne,Oe,ze,dt)}}let J=ce?null:new Yt(Ce,ue,O,T),H=new Uint8Array(e.length),oe=n?new Int32Array(e.length).fill(Ue):void 0;for(let L=0;L<e.length;L++){let B=e[L],P=t.parts[B.part];if(!P||!P.under||!Xt(B.m)||i(B.color))continue;let R=P.bbox,S=Math.round((R[3]-R[0])/20),N=Math.round((R[5]-R[2])/20);if(!S||!N||S*N>4096)continue;let V=B.m,q=Math.round(V[1]+R[4]),W=!0,_=0;for(let Q=0;Q<S&&W;Q++)for(let ae=0;ae<N;ae++){let ye=R[0]+10+20*Q,xe=R[2]+10+20*ae,we=V[0]+V[3]*ye+V[5]*xe,he=V[2]+V[9]*ye+V[11]*xe,te=Math.round(we),ne=Math.round(he),re=!Fe(te,q,ne)?-1:ce?ce.get(te,q,ne):J.has(te,q,ne)?1:-1;if(re<0){W=!1;break}if(re>_)_=re}if(W){if(H[L]=1,oe)oe[L]=_}}return{nStuds:l,studHidden:Me,studUp:Le,underHidden:H,studsHidden:ve,studHideStep:Y,underHideStep:oe}}function ht(e,t,n){let r=(l)=>l.colPart&&t.parts[l.colPart]?l.colPart:n&&l.texPart&&t.parts[l.texPart]?l.texPart:l.part,s=new Map,o=new Map,i=(l)=>{let f=l.colour;if(!f)return String(l.color);let p=o.get(f);if(p!==void 0)return p;let d=t.colorTable?.[l.color],h=d?.hex??t.colors?.[l.color],m=d?ct({alpha:d.alpha??255,luminance:d.luminance??0,finish:d.finish??{type:"default"}}):"default:op",w=ct(f);if(p=h&&h.toUpperCase()===f.hex.toUpperCase()&&m===w?String(l.color):f.hex.toUpperCase()+"/"+w,p!==String(l.color))s.set(p,f);return o.set(f,p),p},c=e.map((l)=>({part:r(l),color:i(l),m:l.m,steps:l.steps})),{stepOf:a,nSteps:u}=Kn(c);return{all:c,stepOf:a,nSteps:u,localColours:s}}function Kn(e){let t=!0;for(let o=0;o<e.length;o++){let i=e[o].steps;if(i.length!==1){t=!1;break}let c=i[0];if(!(Number.isInteger(c)&&c>=0&&c<1e6)){t=!1;break}}if(t){let o=new Set;for(let a=0;a<e.length;a++)o.add(e[a].steps[0]);let i=[...o].sort((a,u)=>a-u),c=new Map(i.map((a,u)=>[a,u]));return{stepOf:e.map((a)=>c.get(a.steps[0])),nSteps:i.length}}let n=e.map((o)=>_t(o.steps)),r=[...new Set(n)].sort(),s=new Map(r.map((o,i)=>[o,i]));return{stepOf:n.map((o)=>s.get(o)),nSteps:r.length}}function Qt(e,t,n=!0){let r=ht(e,t,n);return mt(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Ze="https://ldr-parts-cdn.baconbrix.workers.dev/v1/",We=new Map,He=new Map;function Xe(e=Ze,t=fetch){let n=We.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(()=>We.delete(e)),We.set(e,n);return n}var Zn=(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"),Ke=(e,t)=>Zn(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>Ke(n,t)):e&&typeof e==="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Ke(r,t)])):e;function Yn(e,t={}){let n=[],r=0,s={},o={};for(let p of e){let d=p.buffer;if(!d)throw Error("ldr: mergePacks needs packs from decodePack/loadPack");let h=new DataView(d).getUint32(0,!0),m=new Uint8Array(d,4+h),w=r;n.push(m),r+=m.byteLength;let b=(4-r%4)%4;if(b)n.push(new Uint8Array(b)),r+=b;for(let[g,y]of Object.entries(p.header.parts??{}))if(!(g in s))s[g]=Ke(y,w);for(let[g,y]of Object.entries(p.header.studKinds??{}))if(!(g in o))o[g]=Ke(y,w)}let i=e[0]?.header??{version:1,weld:!0},c=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),a=(4-(4+c.length)%4)%4,u=4+c.length+a,l=new Uint8Array(u+r);new DataView(l.buffer).setUint32(0,c.length+a,!0),l.set(c,4),l.fill(32,4+c.length,u);let f=u;for(let p of n)l.set(p,f),f+=p.byteLength;return _e(l.buffer)}async function Jn(e,t={}){e=[...e];try{return await qt(e,t)}catch(n){let r=t.cdn??Ze,s=t.fetch??fetch;We.delete(r);let o=(i,c)=>s(i,{...c,cache:"reload"});try{return await qt(e,{...t,fetch:o})}catch{throw n}}}async function qt(e,t){let n=t.cdn??Ze,r=t.fetch??fetch,s=t.gap??16384,o=await Xe(n,r),i=[...new Set([...new Set(e)].map(Z))],c=[],a=[];for(let g of i){if(He.has(n+g))continue;let y=o.parts[g];if(y)a.push({name:g,off:y[0],len:y[1],file:y[2]??0});else c.push(g)}a.sort((g,y)=>g.file-y.file||g.off-y.off);let u=[];for(let g of a){let y=u[u.length-1];if(y&&y.file===g.file&&g.off-y.end<=s)y.end=Math.max(y.end,g.off+g.len),y.items.push(g);else u.push({file:g.file,start:g.off,end:g.off+g.len,items:[g]})}let l=0,f=0,p=0,d=new Map,h=async()=>{while(p<u.length){let g=u[p++],y=d.get(g.file);if(y)y=y.subarray(g.start,g.end);else{let A=await r(new URL(o.archives[g.file],n).href,{headers:{Range:`bytes=${g.start}-${g.end-1}`,"Accept-Encoding":"identity"}});if(!A.ok)throw Error(`ldr: parts CDN ${A.status}`);if(f++,y=new Uint8Array(await A.arrayBuffer()),l+=y.byteLength,A.status===200)d.set(g.file,y),y=y.subarray(g.start,g.end)}for(let A of g.items){let v=Ve(y.subarray(A.off-g.start,A.off-g.start+A.len)),M=v.buffer.slice(v.byteOffset,v.byteOffset+v.byteLength);He.set(n+A.name,_e(M))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,u.length)},h));let m=i.filter((g)=>He.has(n+g)).map((g)=>He.get(n+g)),w={colors:o.colors,...o.colorTable?{colorTable:o.colorTable}:{}};return{pack:m.length?Yn(m,w):_e(Qn(w)),missing:c,requests:f,bytes:l}}function Qn(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},...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 qn(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 en(e,t,n){let r=0,s=0,o=!1,i=new Set,c=new Map;for(let a of e){let u;if(a.embedded)u=t.get(a.part);else if(u=c.get(a.part),u===void 0)c.set(a.part,u=Z(a.part));let l=u?n.parts[u]:void 0;if(!l)continue;if(l[3]!=null)o=!0,r+=l[3];if(!i.has(u))i.add(u),s+=l[1]}return{bodyTris:r,packBytes:s,known:o}}class Ye 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 tn(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=Xe(t.cdn??Ze,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(x)=>{if(!x.ok)throw Error(`ldr: ${x.status} fetching ${e}`);return wt(await x.arrayBuffer())}),i=performance.now(),c=t.name??(t.text?"main.ldr":At(e)),a=Ht(o,c,{looseGeometry:!1,callouts:t.callouts}),u=performance.now();t.onParsed?.(a),await s;let l=Wt(o,new Set(a.filter((x)=>x.embedded).map((x)=>x.part)),c),f=(x,U)=>t.maxBodyTris!=null&&x>t.maxBodyTris||t.maxPackBytes!=null&&U>t.maxPackBytes,p=t.maxBodyTris!=null||t.maxPackBytes!=null,d=(x)=>new Ye({...x,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes}),h="full";if(p){let x=en(a,l,await s);if(f(x.known?x.bodyTris:0,x.packBytes)){if(!t.lowCdn)throw d(x);let U=await Xe(t.lowCdn,r).catch(()=>null);if(!U)throw d(x);let k=en(a,l,U);if(f(k.known?k.bodyTris:0,k.packBytes))throw d(k);h="low"}}let m=[...a.filter((x)=>!x.embedded).map((x)=>x.part),...l.values()],w=async()=>{let x=await Jn(m,h==="low"?{...t,cdn:t.lowCdn}:t);for(let[U,k]of l){let I=x.pack.header.parts[k];if(I)x.pack.header.parts[U]=I}return{...x,packBytes:x.pack.buffer?.byteLength??x.pack.bytes??0,bodyTris:qn(a,x.pack)}},b=await w();if(p&&f(b.bodyTris,b.packBytes)&&h==="full"&&t.lowCdn&&await Xe(t.lowCdn,r).then(()=>!0,()=>!1)){h="low";let x=b;b=await w(),b.requests+=x.requests,b.bytes+=x.bytes}if(p&&f(b.bodyTris,b.packBytes))throw d(b);let{pack:g,missing:y,requests:A,bytes:v}=b,M=new Map([...l].map(([x,U])=>[U,x])),z=y.map((x)=>M.get(x)??x),E=performance.now(),D=t.cull?Qt(a,g.header,t.textures!==!1):void 0;return{insts:a,pack:g,tier:h,missing:z,requests:A,bytes:v,cull:D,timings:{fetchModel:i-n,parse:u-i,parts:E-u,...D?{cull:performance.now()-E}:{}}}}var er=new Set(["part","color","m","step","steps","localStep","path"]);function nn(e){let t=e.length,n=0;for(let h of e){if(typeof h.part!=="string"||typeof h.path!=="string"||typeof h.color!=="number"||typeof h.step!=="number"||typeof h.localStep!=="number"||!Array.isArray(h.m)||h.m.length!==12||!Array.isArray(h.steps))return null;n+=h.steps.length}let r=[],s=new Map,o=(h)=>{let m=s.get(h);if(m===void 0)s.set(h,m=r.length),r.push(h);return m},i=new Uint32Array(t),c=new Uint32Array(t),a=new Float64Array(t*3),u=new Float64Array(t*12),l=new Uint32Array(t+1),f=new Float64Array(n),p=[],d=0;for(let h=0;h<t;h++){let m=e[h];i[h]=o(m.part),c[h]=o(m.path),a[h*3]=m.color,a[h*3+1]=m.step,a[h*3+2]=m.localStep;let w=m.m,b=h*12;for(let A=0;A<12;A++)u[b+A]=w[A];let g=m.steps;for(let A=0;A<g.length;A++)f[d++]=g[A];l[h+1]=d;let y=null;for(let A in m)if(!er.has(A))(y??={})[A]=m[A];if(y)p.push([h,y])}return{n:t,strs:r,part:i,path:c,num:a,m:u,so:l,steps:f,extra:p}}var rn=(e)=>[e.part.buffer,e.path.buffer,e.num.buffer,e.m.buffer,e.so.buffer,e.steps.buffer];self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await tn(n,{...r,cull:!1,onParsed:(f)=>{let p=nn(f);if(p)self.postMessage({id:t,packed:p},rn(p));else self.postMessage({id:t,insts:f})}}),o=s.pack.buffer;if(self.postMessage({id:t,buffer:o,tier:s.tier,missing:s.missing,requests:s.requests,bytes:s.bytes,timings:s.timings},[o]),!r.cull)return;let i=performance.now(),c=ht(s.insts,s.pack.header,r.textures!==!1),a=mt(c.all,s.pack.header,r.stepCull&&c.nSteps>1?c.stepOf:void 0),u=performance.now()-i,l=[];for(let f of[a.studHidden,a.studUp,a.underHidden,a.studHideStep,a.underHideStep])if(f)l.push(f.buffer);self.postMessage({id:t,cull:a,ms:u},l)}catch(s){if(s instanceof Ye||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';
|
|
5684
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/load-worker.gen.ts
|
|
5685
|
+
var load_worker_gen_default = 'var an=ArrayBuffer,W=Uint8Array,Ve=Uint16Array,ln=Int16Array;var _e=Int32Array,qe=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},Ue=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},cn=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 un=["invalid zstd data","window size too large (>2046MB)","invalid block type","FSE accuracy too high","match distance too far back","unexpected EOF"],Y=function(e,t,n){var r=Error(t||un[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,Y);if(!n)throw r;return r},wt=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},fn=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},pn=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,c=r>>6;if(r&8)Y(0);var l=6-s,f=i==3?4:i,u=wt(e,l,f);l+=f;var a=c?1<<c:s,p=wt(e,l,a)+(c==1&&256),d=p;if(!s){var h=1<<10+(e[5]>>3);d=h+(h>>3)*(e[5]&7)}if(d>2145386496)Y(1);var m=new W((t==1?p||d:t?0:d)+12);return m[0]=1,m[4]=4,m[8]=8,{b:l+a,y:0,l:0,d:u,w:t&&t!=1?t:m.subarray(12),e:d,o:new _e(m.buffer,0,3),u:p,c:o,m:Math.min(131072,d)}}else if((n>>4|e[3]<<20)==25481893)return fn(e,4)+8;Y(0)},Ee=function(e){var t=0;for(;1<<t<=e;++t);return t-1},Ne=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)Y(3);var o=1<<s,i=o,c=-1,l=-1,f=-1,u=o,a=new an(512+(o<<2)),p=new ln(a,0,256),d=new Ve(a,0,256),h=new Ve(a,512,o),m=512+(o<<1),A=new W(a,m,o),y=new W(a,m+o);while(c<255&&i>0){var g=Ee(i+1),b=r>>3,w=(1<<g+1)-1,M=(e[b]|e[b+1]<<8|e[b+2]<<16)>>(r&7)&w,T=(1<<g)-1,O=w-i-1,v=M&T;if(v<O)r+=g,M=v;else if(r+=g+1,M>T)M-=O;if(p[++c]=--M,M==-1)i+=M,A[--u]=c;else i-=M;if(!M)do{var B=r>>3;l=(e[B]|e[B+1]<<8)>>(r&7)&3,r+=2,c+=l}while(l==3)}if(c>255||i)Y(0);var x=0,D=(o>>1)+(o>>3)+3,k=o-1;for(var E=0;E<=c;++E){var F=p[E];if(F<1){d[E]=-F;continue}for(f=0;f<F;++f){A[x]=E;do x=x+D&k;while(x>=u)}}if(x)Y(0);for(f=0;f<o;++f){var C=d[A[f]]++,j=y[f]=s-Ee(C);h[f]=(C<<j)-o}return[r+7>>3,{b:s,s:A,n:y,t:h}]},mn=function(e,t){var n=0,r=-1,s=new W(292),o=e[t],i=s.subarray(0,256),c=s.subarray(256,268),l=new Ve(s.buffer,268);if(o<128){var f=Ne(e,t+1,6),u=f[0],a=f[1];t+=o;var p=u<<3,d=e[t];if(!d)Y(0);var h=0,m=0,A=a.b,y=A,g=(++t<<3)-8+Ee(d);for(;;){if(g-=A,g<p)break;var b=g>>3;if(h+=(e[b]|e[b+1]<<8)>>(g&7)&(1<<A)-1,i[++r]=a.s[h],g-=y,g<p)break;b=g>>3,m+=(e[b]|e[b+1]<<8)>>(g&7)&(1<<y)-1,i[++r]=a.s[m],A=a.n[h],h=a.t[h],y=a.n[m],m=a.t[m]}if(++r>255)Y(0)}else{r=o-127;for(;n<r;n+=2){var w=e[++t];i[n]=w>>4,i[n+1]=w&15}++t}var M=0;for(n=0;n<r;++n){var T=i[n];if(T>11)Y(0);M+=T&&1<<T-1}var O=Ee(M)+1,v=1<<O,B=v-M;if(B&B-1)Y(0);i[r++]=Ee(B)+1;for(n=0;n<r;++n){var T=i[n];++c[i[n]=T&&O+1-T]}var x=new W(v<<1),D=x.subarray(0,v),k=x.subarray(v);l[O]=0;for(n=O;n>0;--n){var E=l[n];Ue(k,n,E,l[n-1]=E+c[n]*(1<<O-n))}if(l[0]!=v)Y(0);for(n=0;n<r;++n){var F=i[n];if(F){var C=l[F];Ue(D,n,C,l[F]=C+(1<<O-F))}}return[t,{n:k,b:O,s:D}]},hn=Ne(new W([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],gn=Ne(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],dn=Ne(new W([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],At=function(e,t){var n=e.length,r=new _e(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},et=new W(new _e([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),bn=At(et,0),tt=new W(new _e([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),yn=At(tt,3),De=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,c=-n.b;if(!o)Y(0);var l=0,f=n.b,u=(r<<3)-8+Ee(o)-f,a=-1;for(;u>c&&a<s;){var p=u>>3,d=(e[p]|e[p+1]<<8|e[p+2]<<16)>>(u&7);l=(l<<f|d)&i,t[++a]=n.s[l],u-=f=n.n[l]}if(u!=c||a+1!=s)Y(0)},xn=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,c=o+i;De(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),De(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),De(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,c),n),De(e.subarray(r),t.subarray(c),n)},wn=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var c=o>>3|e[s+1]<<5|e[s+2]<<13,l=(s+=3)+c;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return Ue(n,e[s],t.y,t.y+=c),n;return Ue(new W(c),e[s])}if(l>e.length)return;if(i==0){if(t.b=l,n)return n.set(e.subarray(s,l),t.y),t.y+=c,n;return qe(e,s,l)}if(i==2){var f=e[s],u=f&3,a=f>>2&3,p=f>>4,d=0,h=0;if(u<2)if(a&1)p|=e[++s]<<4|(a&2&&e[++s]<<12);else p=f>>3;else if(h=a,a<2)p|=(e[++s]&63)<<4,d=e[s]>>6|e[++s]<<2;else if(a==2)p|=e[++s]<<4|(e[++s]&3)<<12,d=e[s]>>2|e[++s]<<6;else p|=e[++s]<<4|(e[++s]&63)<<12,d=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var m=n?n.subarray(t.y,t.y+t.m):new W(t.m),A=m.length-p;if(u==0)m.set(e.subarray(s,s+=p),A);else if(u==1)Ue(m,e[s++],A);else{var y=t.h;if(u==2){var g=mn(e,s);d+=s-(s=g[0]),t.h=y=g[1]}else if(!y)Y(0);(h?xn:De)(e.subarray(s,s+=d),m.subarray(A),y)}var b=e[s++];if(b){if(b==255)b=(e[s++]|e[s++]<<8)+32512;else if(b>127)b=b-128<<8|e[s++];var w=e[s++];if(w&3)Y(0);var M=[gn,dn,hn];for(var T=2;T>-1;--T){var O=w>>(T<<1)+2&3;if(O==1){var v=new W([0,0,e[s++]]);M[T]={s:v.subarray(2,3),n:v.subarray(0,1),t:new Ve(v.buffer,0,1),b:0}}else if(O==2)r=Ne(e,s,9-(T&1)),s=r[0],M[T]=r[1];else if(O==3){if(!t.t)Y(0);M[T]=t.t[T]}}var B=t.t=M,x=B[0],D=B[1],k=B[2],E=e[l-1];if(!E)Y(0);var F=(l<<3)-8+Ee(E)-k.b,C=F>>3,j=0,ye=(e[C]|e[C+1]<<8)>>(F&7)&(1<<k.b)-1;C=(F-=D.b)>>3;var xe=(e[C]|e[C+1]<<8)>>(F&7)&(1<<D.b)-1;C=(F-=x.b)>>3;var me=(e[C]|e[C+1]<<8)>>(F&7)&(1<<x.b)-1;for(++b;--b;){var Ce=k.s[ye],Se=k.n[ye],le=x.s[me],Fe=x.n[me],ke=D.s[xe],Te=D.n[xe];C=(F-=ke)>>3;var Le=1<<ke,te=Le+((e[C]|e[C+1]<<8|e[C+2]<<16|e[C+3]<<24)>>>(F&7)&Le-1);C=(F-=tt[le])>>3;var N=yn[le]+((e[C]|e[C+1]<<8|e[C+2]<<16)>>(F&7)&(1<<tt[le])-1);C=(F-=et[Ce])>>3;var S=bn[Ce]+((e[C]|e[C+1]<<8|e[C+2]<<16)>>(F&7)&(1<<et[Ce])-1);if(C=(F-=Se)>>3,ye=k.t[ye]+((e[C]|e[C+1]<<8)>>(F&7)&(1<<Se)-1),C=(F-=Fe)>>3,me=x.t[me]+((e[C]|e[C+1]<<8)>>(F&7)&(1<<Fe)-1),C=(F-=Te)>>3,xe=D.t[xe]+((e[C]|e[C+1]<<8)>>(F&7)&(1<<Te)-1),te>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=te-=3;else{var q=te-(S!=0);if(q){if(te=q==3?t.o[0]-1:t.o[q],q>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=te}else te=t.o[0]}for(var T=0;T<S;++T)m[j+T]=m[A+T];j+=S,A+=S;var V=j-te;if(V<0){var G=-V,ce=t.e+V;if(G>N)G=N;for(var T=0;T<G;++T)m[j+T]=t.w[ce+T];j+=G,N-=G,V=0}for(var T=0;T<N;++T)m[j+T]=m[V+T];j+=N}if(j!=A)while(A<m.length)m[j++]=m[A++];else j=m.length;if(n)t.y+=j;else m=qe(m,0,j)}else if(n){if(t.y+=p,A)for(var T=0;T<p;++T)m[T]=m[A+T]}else if(A)m=qe(m,A);return t.b=l,m}Y(2)},An=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 Ge(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=pn(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 c=wn(e,i,t);if(!c)Y(5);if(t)i.e=i.y;else n.push(c),o+=c.length,cn(i.w,0,c.length),i.w.set(c,i.w.length-c.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return An(n,o)}async function Mn(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(Ge(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 Mt(e){return new TextDecoder().decode(await Mn(e))}var vt=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split("/").pop()||"main.ldr").replace(/\\.(zst|gz)$/i,"")||"main.ldr";function He(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 J=(e)=>e.trim().toLowerCase().replace(/\\\\/g,"/").replace(/\\/+/g,"/"),rt=/^[A-Za-z][A-Za-z0-9_]*$/,nt=new Map;function st(e){let t=e.toLowerCase(),n=2166136261;for(let s=0;s<t.length;s++)n^=t.charCodeAt(s),n=Math.imul(n,16777619);let r=-1-(n>>>0&1073741823);if(!nt.has(r))nt.set(r,t);return r}function ot(e){let t=e.charCodeAt(0)|32;if(t>=97&&t<=122&&rt.test(e))return st(e);if(/^0x/i.test(e))return parseInt(e,16);return+e}var Ct=/^~?\\s*moved\\s+to\\s+(.+)$/i,vn=new Set(["FILE","NOFILE","!DATA","!:","STEP","BFC","ROTSTEP","BUFEXCHG","!TEXMAP"]),Cn=new Set(["FILE","NOFILE","!DATA"]),Ft=1000000000000000,Rt=new Set(["part","subpart","primitive","8_primitive","48_primitive","shortcut","helper"]),kn=new Set(["model","submodel","configuration"]),Tn=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function kt(e){let t=Tn.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,"");return Rt.has(n)||kn.has(n)?n:void 0}function Ln(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 Sn(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((a)=>Number.isFinite(a)&&Math.abs(a)<=1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000))return null;if(s>=10&&!(Math.abs(i[9])>=0.000001)||s===11&&!(Math.abs(i[10])>=0.000001))return null;let c=n[2].trim();for(let a=0;a<s;a++)c=c.replace(/^\\S+\\s*/,"");let l=Ln(c);if(!l.length)return null;let f={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:l[0]};if(s>=10)f.a=i[9];if(s===11)f.b=i[10];let u=l.findIndex((a,p)=>p>0&&a.toUpperCase()==="GLOSSMAP");if(u>0&&l[u+1])f.glossmap=l[u+1];if(t)f.next=!0;return f}var Pn=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,"");if(t.length%4===1)t=t.slice(0,-1);let 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 En(e,t){let n=e.length,r=1,s=(h)=>h===32||h===9,o=()=>{while(r<n&&s(e.charCodeAt(r)))r++;let h=r,m=e.charCodeAt(r),A=m===45;if(A)m=e.charCodeAt(++r);let y=0,g=0;while(m>=48&&m<=57)y=y*10+(m-48),g++,m=e.charCodeAt(++r);if(g>0&&g<=15&&(r>=n||s(m)))return A?-y:y;while(r<n&&!s(e.charCodeAt(r)))r++;return h<r?+e.slice(h,r):NaN};while(r<n&&s(e.charCodeAt(r)))r++;let i=r;if(r>=n)return null;let c=e.charCodeAt(r),l=c===45,f=0,u=0;if(l)c=e.charCodeAt(++r);while(c>=48&&c<=57)f=f*10+(c-48),u++,c=e.charCodeAt(++r);if(u>0&&u<=15&&(r>=n||s(c))){if(l)f=-f}else{while(r<n&&!s(e.charCodeAt(r)))r++;f=ot(e.slice(i,r))}let a=Array(12);for(let h=0;h<12;h++){let m=o();if(!Number.isFinite(m))return null;a[h]=m}while(r<n&&s(e.charCodeAt(r)))r++;if(r>=n)return null;let p=e.slice(r),d=t.get(p);if(d===void 0)d=J(/[ \\t]{2,}|\\t/.test(p)?p.split(/\\s+/).join(" "):p),t.set(p,d);if(!Number.isFinite(f))return null;return{t:1,color:f,m:a,file:d}}var In=[0,12,6,9,12,12];function Tt(e){let t=+e[0];if(!(t>=1&&t<=5&&Number.isInteger(t))||e.length<2)return null;let n=ot(e[1]),r=In[t];if(!Number.isFinite(n)||e.length<2+r+(t===1?1:0))return null;let s=Array(r);for(let o=0;o<r;o++){let i=+e[2+o];if(!Number.isFinite(i))return null;s[o]=i}if(t===1){let o=J(e.slice(14).join(" "));return o?{t:1,color:n,m:s,file:o}:null}if(t===2)return{t:2,color:n,p:s};if(t===3)return{t:3,color:n,p:s};if(t===4)return{t:4,color:n,p:s};return{t:5,color:n,p:s}}function Bt(e,t="main.ldr",n={}){let r=!!n.geometryText,s=new Map,o=null,i="",c,l=null,f=[],u=null,a=()=>{if(!l)return;let b=Pn(l.chunks.join("")),w=b[0]===137&&b[1]===80&&b[2]===78&&b[3]===71;(c??=new Map).set(J(l.name),{name:l.name,bytes:b,...w?{mime:"image/png"}:{}}),l=null},p=new Map,d=!0,h=(b)=>{if(a(),o={name:J(b),cmds:[]},s.set(o.name,o),!i)i=o.name;f=[],u=null,d=!0},m=!1,A=!1,y=()=>{if(A)return;A=!0,s.clear(),o=null,i=""},g=(b,w)=>{if(u){b.tex=u,u=null;return}let M=f[f.length-1];if(!M)return;if(M.fallback){if(!w)b.fallback=!0}else b.tex=M.map};for(let b of e.split(`\n`)){let w=b.trim();if(!w)continue;if(r&&w.charCodeAt(0)>=50&&w.charCodeAt(0)<=53&&(w.charCodeAt(1)===32||w.charCodeAt(1)===9)){if(l||m)continue;if(!o)h(t);let v=w.slice(2).trimStart(),B=v.search(/\\s/),x={t:w.charCodeAt(0)-48,color:ot(B<0?v:v.slice(0,B)),p:[],src:w};g(x,!1),o.cmds.push(x),d=!1;continue}if(w.charCodeAt(0)===48&&(w.charCodeAt(1)===32||w.charCodeAt(1)===9)){let v=2;while(w.charCodeAt(v)===32||w.charCodeAt(v)===9)v++;let B=v;while(B<w.length&&w.charCodeAt(B)!==32&&w.charCodeAt(B)!==9)B++;let x=w.slice(v,B),D=/[^\\x21-\\x7e]/.test(x)?w.slice(v).trim().split(/\\s+/)[0]:x;if(!vn.has(D)&&!(D.length>=4&&D.length<=6&&Cn.has(D.toUpperCase()))){if(m||l)continue;if(!o)h(t);let k=w.slice(v),E={t:0,text:k};if(x.charCodeAt(0)===33)E.meta=x;if(u=null,d&&!o.org){let C=kt(k);if(C)o.org=C}let F=k.match(Ct);if(F&&!o.movedTo){let C=F[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(C))C+=".dat";o.movedTo=J(C)}o.cmds.push(E);continue}}if(w.charCodeAt(0)===49&&(w.charCodeAt(1)===32||w.charCodeAt(1)===9)&&!l&&!m){let v=En(w,p);if(v){if(!o)h(t);g(v,!1),o.cmds.push(v),d=!1;continue}}let M=w.split(/\\s+/);if(+M[0]===0){let v=w.slice(1).trim(),B=M.length>1&&M[1].length>=4&&M[1].length<=6?M[1].toUpperCase():M[1];if(B==="FILE"){let k=v.slice(5).trimStart().split("\\r")[0].trim();if(k){y(),m=!1,h(k);continue}}if(B==="NOFILE"){a(),o=null,m=!0;continue}if(B==="!DATA"){y(),a(),o=null,m=!1,l={name:v.slice(5).trim(),chunks:[]};continue}if(m)continue;if(l){if(M[1]==="!:")l.chunks.push(M.slice(2).join(""));continue}if(!o)h(t);let x={t:0,text:v};if(M[1]==="STEP")x.step=!0,f=[],u=null;else if(M[1]==="BFC")x.bfc=M.slice(2).join(" ");else if(M[1]==="ROTSTEP")if(x.meta="ROTSTEP",x.step=!0,f=[],u=null,(M[2]??"").toUpperCase()==="END")x.rotstep={x:0,y:0,z:0,mode:"END"};else{let k=(M[5]??"REL").toUpperCase(),E=(F)=>{let C=Number(F);return Number.isFinite(C)?C:0};x.rotstep={x:E(M[2]),y:E(M[3]),z:E(M[4]),mode:["REL","ABS","ADD"].includes(k)?k:"REL"}}else if(M[1]==="BUFEXCHG"){x.meta="BUFEXCHG";let k=(M[2]??"").toUpperCase();x.bufexchg={op:k==="RETRIEVE"?"RETRIEVE":"STORE",buf:M[3]??"A"}}else if(M[1]?.startsWith("!"))x.meta=M[1];if(d&&!o.org){let k=kt(v);if(k)o.org=k}if(M[1]==="!TEXMAP"){let k=(M[2]??"").toUpperCase();if(u=null,k==="START"||k==="NEXT"){let E=Sn(v.replace(/^!TEXMAP\\s+\\S+/i,""),k==="NEXT");if(x.texmap={op:k,...E?{map:E}:{}},E)if((o.texmaps??=[]).push(E),k==="START")f.push({map:E,fallback:!1});else u=E}else if(k==="FALLBACK"){x.texmap={op:k};let E=f[f.length-1];if(E)E.fallback=!0}else if(k==="END")x.texmap={op:k},f.pop()}else if(M[1]==="!:"){u=null;let k=Tt(M.slice(2));if(k)g(k,!0),x.geom=k}else u=null;let D=v.match(Ct);if(D&&!o.movedTo){let k=D[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(k))k+=".dat";o.movedTo=J(k)}o.cmds.push(x);continue}if(l||m)continue;if(!o)h(t);let O=Tt(M);if(!O){if(/^[2-5][ \\t]/.test(w))d=!1;continue}g(O,!1),o.cmds.push(O),d=!1}return a(),c?{main:i,files:s,data:c}:{main:i,files:s}}var ir=Math.PI/180;function Dt(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 Ut(e,t){let[n,r,s,o,i,c,l,f,u,a,p,d]=e,[h,m,A,y,g,b,w,M,T,O,v,B]=t;return[o*h+i*m+c*A+n,l*h+f*m+u*A+r,a*h+p*m+d*A+s,o*y+i*w+c*O,o*g+i*M+c*v,o*b+i*T+c*B,l*y+f*w+u*O,l*g+f*M+u*v,l*b+f*T+u*B,a*y+p*w+d*O,a*g+p*M+d*v,a*b+p*T+d*B]}var We=[0,0,0,1,0,0,0,1,0,0,0,1];var Lt=new WeakMap,Fn=/^(s|8|48)\\//;function it(e,t){let n=e.files.get(J(t));if(!n)return"part";let r=Lt.get(n);if(r)return r;if(n.org)r=Rt.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&&Fn.test(s.file))?"part":"model";return Lt.set(n,r),r}var St=new WeakMap;function Nt(e){let t=St.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 St.set(e,t),t}var Pt=(e)=>e>16777215?"0x"+e.toString(16).toUpperCase():e<0?nt.get(e)??String(e):String(e),Rn=(e)=>e.t===0?"0 "+e.text:e.t===1?`1 ${Pt(e.color)} ${e.m.join(" ")} ${e.file}`:e.src?e.src:`${e.t} ${Pt(e.color)} ${e.p.join(" ")}`,at=(e,t)=>`${J(e)}#${t}`;function Bn(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||o.meta==="!COLOUR"){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:at(e.name,t),cmds:n}}function Ot(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Bn(e,t).cmds.map(Rn)].join(`\n`)+`\n`}function lt(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 zt(e){let[t,n,r,s,o,i,c,l,f,u,a,p]=e,d=l*p-f*a,h=-(c*p-f*u),m=c*a-l*u,A=s*d+o*h+i*m;if(!Number.isFinite(A)||Math.abs(A)<0.000000000001)return null;let y=1/A,g=[d*y,-(o*p-i*a)*y,(o*f-i*l)*y,h*y,(s*p-i*u)*y,-(s*f-i*c)*y,m*y,-(s*a-o*u)*y,(s*l-o*c)*y];return[-(g[0]*t+g[1]*n+g[2]*r),-(g[3]*t+g[4]*n+g[5]*r),-(g[6]*t+g[7]*n+g[8]*r),...g]}var Dn=(e)=>String(+e.toFixed(6)||0),Et=(e)=>\'"\'+e.replace(/\\\\/g,"\\\\\\\\").replace(/"/g,"\\\\\\"")+\'"\';function $t(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!=="PLANAR"?[t.a??360]:[],...t.method==="SPHERICAL"?[t.b??180]:[]].map(Dn).join(" "),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${Et(t.texture)}${t.glossmap?" GLOSSMAP "+Et(t.glossmap):""}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${J(e)}\n0 !TEXMAP END\n`;return{name:`${J(e)}#tex-${lt(r)}`,source:r}}var Un=(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 Nn(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),c=Math.cos(t*r),l=Math.sin(n*r),f=Math.cos(n*r);return[c*f,-c*l,i,o*l+s*i*f,o*f-s*i*l,-s*c,s*l-o*i*f,s*f+o*i*l,o*c]}var It=new WeakMap;function jt(e){let t=It.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=Nn(o.x,o.y,o.z);r=o.mode==="ABS"?{abs:!0,m:i,rotstep:o}:o.mode==="ADD"&&r?{abs:r.abs,m:Un(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),It.set(e,n),n}class ct extends Error{limit;code="ldr-model-limit";constructor(e,t){super(`ldr: ${e} expands past ${t.toLocaleString("en-US")} (see maxInstances)`);this.limit=t;this.name="ModelLimitError"}}var On=(e)=>{for(let t=0;t<12;t++)if(!(Math.abs(e[t])<=Ft))return!1;return!0},Vt=999999,Ht=(e)=>e.map((t)=>String(t).padStart(6,"0")).join(".")+"~",Wt=new WeakMap,_t=new WeakMap;function zn(e,t){let n=_t.get(t);if(!n)n={head:[...t.values()].map((o)=>{let i=Wt.get(o)??"",c=i.indexOf("!COLOUR");return c<0?"":"0 "+i.slice(c).trim().replace(/\\s+/g," ")}).filter(Boolean).join(`\n`),parts:new Map},_t.set(t,n);let r=n.parts.get(e);if(!r){let s=J(e),o=`0 ldr: ${s} placed in a model\'s !COLOUR scope\n0 BFC CERTIFY CCW\n${n.head}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${s}\n`;r={name:`${s}#col-${lt(o)}`,source:o},n.parts.set(e,r)}return r}function $n(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,c=new Map,l=0,f=[],u=(A,y)=>{if(A.length)return[...A,y];let g=f[y];if(!g)f[y]=g=[y];return g},a=new Set,p=t.maxInstances??2000000,d=0,h=(A,y)=>{let g=A.name+"#"+y,b=c.get(g);if(!b){let w;b=Object.assign(()=>w??=Ot(A,y),{file:A,step:y}),c.set(g,b)}return b},m=(A,y,g,b,w,M,T,O,v=null,B=[],x=[],D=void 0,k=null)=>{let E=A.files.get(y);if(!E||T>r||a.has(E))return;if(++d>p)throw new ct("model",p);a.add(E);let F=k,C=0,j=T>0?++l:0,ye=i&&j?[...B,j]:B,xe=i&&j?[...x,g]:x,me=i&&!v?new Map:null,Ce=-1,Se=0,le=(N,S,q,V,G,ce,he)=>{if(Ce!==C)Ce=C,Se=0;let ge=me?.get(C+"|"+S);if(ge)return ge.n++,m(N,N===A?S:N.main,q,V,w+"/"+S,[...G,Vt],T+1,ce,[...G,Vt],ye,xe,he,F);let L=[...G,Se++],I=n.length;m(N,N===A?S:N.main,q,V,w+"/"+S,L,T+1,ce,v,ye,xe,he,F),me?.set(C+"|"+S,{n:1,from:I,to:n.length})},Fe=jt(E),ke=s?Nt(E):[],Te=0,Le=(N,S,q,V,G,ce,he,ge,L)=>{if(v)V=v;if(++d>p)throw new ct("model",p);let I={part:N,color:S,m:q,step:V[0],steps:V,localStep:G,path:w};if(ge)I.colour=ge;if(j){if(I.sub=j,i)I.subPath=ye,I.subMats=xe}if(ce)I.embedded=!0;if(he){let z=$t(N,he);I.texPart=z.name,I.texSource=z.source}else if(L){let z=zn(N,L);I.colPart=z.name,I.colSource=z.source}let P=Fe[G];if(P)I.view=P;return n.push(I),I},te=(N)=>{while(Te<ke.length&&ke[Te]<=N){let S=ke[Te++];Le(at(E.name,S),b,g,u(M,S),S,!1,null,D,k).source=h(E,S)}};for(let N of E.cmds){if(N.t===0&&N.step){C++;continue}let S=N;if(S.t>=2||S.t===0&&S.geom&&S.geom.t>=2){te(C);continue}if(S.t===0){if(S.meta==="!COLOUR"){let P=Vn(S.text);if(P&&P.code!==16&&P.code!==24)Wt.set(P,S.text),(F=new Map(F??[])).set(P.code,P);continue}if(o&&S.geom?.t===1)S=S.geom;else continue}if(S.t!==1)continue;if(o&&S.fallback)continue;let q=g===We?S.m:Ut(g,S.m);if(!On(q))continue;let V=S.color===16?b:S.color,G=S.color===16?D:F?.get(S.color),ce=u(M,C),he=o?S.tex??O:null,ge=he?zt(S.m):null,L=he&&ge?Dt(he,ge):null;if(A.files.has(S.file)){if(it(A,S.file)==="model"){le(A,S.file,q,V,ce,L,G);continue}Le(S.file,V,q,ce,C,!0,L,G,F);continue}let I=t.resolveModel?.(S.file);if(I){le(I,S.file,q,V,ce,L,G);continue}Le(S.file,V,q,ce,C,!1,L,G,F)}if(te(1/0),a.delete(E),me){for(let N of me.values())if(N.n>1)for(let S=N.from;S<N.to;S++)n[S].mult??=N.n}};if(it(e,e.main)==="part"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...We],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return m(e,e.main,We,16,e.main,[],0,null),n}function Xt(e,t="main.ldr",n){return $n(Bt(e,t,{geometryText:!0}),n)}var jn=new Set(["CHROME","PEARLESCENT","RUBBER","MATTE_METALLIC","METAL","MATERIAL"]);function ut(e){if(!e)return null;if(e.startsWith("#")&&/^#[0-9A-Fa-f]{6}$/.test(e))return e.toUpperCase();if(/^0x[0-9A-Fa-f]{6}$/i.test(e))return("#"+e.slice(2)).toUpperCase();return null}function Gt(e,t){let n={value:"#FFFFFF",fraction:0.5};while(t<e.length){let r=e[t].toUpperCase(),s=e[t+1];if(r==="VALUE"){let o=ut(s);if(o)n.value=o;t+=2}else if(r==="ALPHA")n.alpha=+s,t+=2;else if(r==="LUMINANCE")n.luminance=+s,t+=2;else if(r==="FRACTION")n.fraction=+s,t+=2;else if(r==="VFRACTION")n.vfraction=+s,t+=2;else if(r==="SIZE")n.size=+s,t+=2;else if(r==="MINSIZE")n.minsize=+s,t+=2;else if(r==="MAXSIZE")n.maxsize=+s,t+=2;else break}return{grain:n,next:t}}function Vn(e){let t=e.indexOf("!COLOUR");if(t<0)return null;let n=e.slice(t+7).trim().split(/\\s+/).filter(Boolean);if(n.length<2)return null;let r=n[0],s=NaN,o="#FF00FF",i="#333333",c=255,l=0,f={type:"default"},u=1;while(u<n.length){let a=n[u].toUpperCase(),p=n[u+1];if(a==="CODE")s=p!==void 0&&rt.test(p)?st(p):p!==void 0&&/^\\d+$/.test(p)?+p:NaN,u+=2;else if(a==="VALUE"){let d=ut(p);if(d)o=d;u+=2}else if(a==="EDGE")i=ut(p)??p,u+=2;else if(a==="ALPHA")c=+p,u+=2;else if(a==="LUMINANCE")l=+p,u+=2;else if(a==="CHROME")f={type:"chrome"},u+=1;else if(a==="PEARLESCENT")f={type:"pearlescent"},u+=1;else if(a==="RUBBER")f={type:"rubber"},u+=1;else if(a==="MATTE_METALLIC")f={type:"matte_metallic"},u+=1;else if(a==="METAL")f={type:"metal"},u+=1;else if(a==="MATERIAL"){let d=(n[u+1]||"").toUpperCase();if(d==="GLITTER"){let{grain:h,next:m}=Gt(n,u+2);f={type:"glitter",material:h},u=m}else if(d==="SPECKLE"){let{grain:h,next:m}=Gt(n,u+2);f={type:"speckle",material:h},u=m}else if(d==="FABRIC"){let h=(n[u+2]||"").toUpperCase(),m=["VELVET","CANVAS","STRING","FUR"].includes(h)?h.toLowerCase():void 0;f={type:"fabric",kind:m},u+=m?3:2}else u=n.length}else if(jn.has(a))u+=1;else u+=1}if(Number.isNaN(s)||!o)return null;return{code:s,name:r,hex:o,edge:i,alpha:Number.isFinite(c)?c:255,luminance:Number.isFinite(l)?l:0,finish:f}}function _n(e){let t=Math.max(0,Math.min(1,(e.alpha??255)/255)),n=t<1,r=Math.max(0,Math.min(1,(e.luminance??0)/255)),s={opacity:t,transparent:n,depthWrite:!n,emissive:r,clearcoat:0,clearcoatRoughness:0,sheen:0,sheenRoughness:0};switch(e.finish?.type??"default"){case"chrome":return{...s,metalness:1,roughness:0,finish:"chrome"};case"pearlescent":return{...s,metalness:0.25,roughness:0.3,clearcoat:0.5,clearcoatRoughness:0.25,sheen:0.4,sheenRoughness:0.35,finish:"pearlescent"};case"rubber":return{...s,metalness:0,roughness:0.9,finish:"rubber"};case"matte_metallic":return{...s,metalness:0.4,roughness:0.8,finish:"matte_metallic"};case"metal":return{...s,metalness:0.85,roughness:0.2,finish:"metal"};case"glitter":{let i=e.finish.material,c=i.size??(i.minsize!=null&&i.maxsize!=null?(i.minsize+i.maxsize)/2:1);return{...s,metalness:0.35,roughness:0.25,clearcoat:1,clearcoatRoughness:0.08,particleHex:i.value,particleFraction:i.fraction,particleSize:c,finish:"glitter"}}case"speckle":{let i=e.finish.material,c=i.size??(i.minsize!=null&&i.maxsize!=null?(i.minsize+i.maxsize)/2:1);return{...s,metalness:0.2,roughness:0.55,particleHex:i.value,particleFraction:i.fraction,particleSize:c,finish:"speckle"}}case"fabric":return{...s,metalness:0,roughness:0.85,sheen:0.65,sheenRoughness:0.75,finish:"fabric"};default:return{...s,metalness:0,roughness:0.45,finish:"default"}}}function ft(e){let t=_n(e),n=!t.transparent?"op":t.opacity>=0.75?"a200":t.opacity>=0.4?"a128":`a${Math.round(t.opacity*255)}`,r=t.emissive>0?`L${Math.round(t.emissive*16)}`:"",s=`${t.finish}:${n}${r}`;if(t.particleHex)s+=`:${t.particleHex}:${(t.particleFraction??0).toFixed(2)}`;return s}function Gn(e,t){let n=new Map,r=null,s=!1,o=!1;for(let i of e.split(/\\r?\\n/)){let c=/^\\s*0\\s+FILE\\s+(\\S[^\\r]*)/i.exec(i);if(c){if(!s)n.clear();s=!0,o=!1,r=[],n.set(J(c[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(i)){if(!s&&/!DATA/i.test(i))n.clear(),s=!0;r=null,o=!0;continue}if(!r){if(s||o)continue;r=[],n.set(J(t),r)}let l=i.trim().replace(/\\s+/g," ");if(l)r.push(l)}return n}var Hn=(e)=>{if(!e.startsWith("1 "))return null;let t=e.split(" ");return t.length>=15?J(t.slice(14).join(" ")):null};function Wn(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 Kt(e,t,n="main.ldr"){let r=[...t],s=new Map;if(!r.length)return s;let o=Gn(e,n);for(let i of r){let c=J(i);if(!o.has(c)||s.has(c))continue;let l=new Set([c]),f=[c];while(f.length)for(let a of o.get(f.pop())){let p=Hn(a);if(p&&o.has(p)&&!l.has(p))l.add(p),f.push(p)}let u=[c,...[...l].filter((a)=>a!==c).sort()].map((a)=>"0 FILE "+(a===c?"":a)+`\n`+o.get(a).join(`\n`)).join(`\n`);s.set(c,`emb/${Wn(u)}.dat`)}return s}var Zt=(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,Yt=new WeakMap,pt=null,mt="",ht=null;function Xn(e,t){if(e===pt&&t===mt)return ht;let n=Yt.get(e);if(!n)Yt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return pt=e,mt=t,ht=r,r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),c=[],l=[];s.studs.forEach((d,h)=>{c.push(d[0]),l.push(d[1]);for(let m=0;m<12;m++)i[h*12+m]=d[2+m]});let f=null,u=0,a=0;if(s.mask){u=s.mask[0],a=s.mask[1];let d=s.mask[2];f=new Uint8Array(d.length);for(let h=0;h<d.length;h++)f[h]=d.charCodeAt(h)===49?1:0}let p=!!f;if(f){for(let d=0;d<f.length;d++)if(f[d]!==1){p=!1;break}}return n.set(t,r={nStuds:o,studM:i,kind:c,color:l,mask:f,nx:u,nz:a,full:p,src:s}),pt=e,mt=t,ht=r,r}var Re=1073741824;class Ie{t;tag;mask;size=0;shift;constructor(e=1024,t=-1){let n=1024;while(n<e*2)n*=2;this.t=new Int32Array(n*4),this.tag=new Uint8Array(n),this.mask=n-1,this.shift=t}slot(e,t,n){let r=this.shift;if(r<0){let o=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return o^=o>>>15,o=Math.imul(o,739982445),o^=o>>>12,o&this.mask}let s=Math.imul(e>>r+2,2654435761)^Math.imul(t,2246822507)^Math.imul(n>>r+2,3266489909);return s^=s>>>15,s=Math.imul(s,739982445),s^=s>>>12,(s<<4|(e>>r&3)<<2|n>>r&3)&this.mask}static tagOf(e,t,n){return Math.imul(e^Math.imul(t,374761393)^Math.imul(n,668265261),2654435761)>>>24|1}get(e,t,n){let r=Ie.tagOf(e,t,n),s=this.tag,o=this.t,i=this.mask,c=this.slot(e,t,n);for(;;){let l=s[c];if(l===0)return-1;if(l===r){let f=c<<2;if(o[f]===e&&o[f+1]===t&&o[f+2]===n)return o[f+3]}c=c+1&i}}put(e,t,n,r){if((this.size+1)*2>this.tag.length)this.grow();let s=Ie.tagOf(e,t,n),o=this.tag,i=this.t,c=this.mask,l=this.slot(e,t,n);for(;;){let f=o[l],u=l<<2;if(f===0)return o[l]=s,i[u]=e,i[u+1]=t,i[u+2]=n,i[u+3]=r,this.size++,-1;if(f===s&&i[u]===e&&i[u+1]===t&&i[u+2]===n){let a=i[u+3];return i[u+3]=r,a}l=l+1&c}}grow(){let e=this.t,t=this.tag,n=t.length*2;this.t=new Int32Array(n*4),this.tag=new Uint8Array(n),this.mask=n-1,this.size=0;for(let r=0;r<t.length;r++)if(t[r]){let s=r<<2;this.put(e[s],e[s+1],e[s+2],e[s+3])}}}class Qt{grp=new Ie(64);gBits=[];gX0=[];gZ0=[];gNz=[];gNx=[];bits;rest;lk=NaN;lpx=NaN;lpz=NaN;lg=-1;group(e,t,n){if(e!==this.lk||t!==this.lpx||n!==this.lpz)this.lk=e,this.lpx=t,this.lpz=n,this.lg=this.grp.get(e,t,n);return this.lg}constructor(e,t,n,r){let s=[],o=[],i=[],c=[],l=[];for(let a=0;a<r;a++){let p=e[a],d=t[a],h=n[a],m=(p%20+20)%20,A=(h%20+20)%20,y=this.group(d,m,A);if(y<0)y=s.length,this.grp.put(d,m,A,y),this.lg=y,s.push(0),o.push(p),i.push(p),c.push(h),l.push(h);if(s[y]++,p<o[y])o[y]=p;else if(p>i[y])i[y]=p;if(h<c[y])c[y]=h;else if(h>l[y])l[y]=h}let f=0,u=0;for(let a=0;a<s.length;a++){let p=(i[a]-o[a])/20+1,d=(l[a]-c[a])/20+1,h=p*d;if(this.gX0.push(o[a]),this.gZ0.push(c[a]),this.gNx.push(p),this.gNz.push(d),h<=64*s[a]+1024&&f+h<2147483648)this.gBits.push(f),f+=h;else this.gBits.push(-1),u+=s[a]}this.bits=new Uint8Array(Math.ceil(f/8)),this.rest=new Ie(u);for(let a=0;a<r;a++){let p=e[a],d=t[a],h=n[a],m=this.group(d,(p%20+20)%20,(h%20+20)%20),A=this.gBits[m];if(A<0){this.rest.put(p,d,h,1);continue}let y=A+(p-this.gX0[m])/20*this.gNz[m]+(h-this.gZ0[m])/20;this.bits[y>>>3]|=1<<(y&7)}}has(e,t,n){let r=this.group(t,(e%20+20)%20,(n%20+20)%20);if(r<0)return!1;let s=this.gBits[r];if(s<0)return this.rest.get(e,t,n)>=0;let o=(e-this.gX0[r])/20,i=(n-this.gZ0[r])/20;if(o<0||i<0||o>=this.gNx[r]||i>=this.gNz[r])return!1;let c=s+o*this.gNz[r]+i;return(this.bits[c>>>3]&1<<(c&7))!==0}}var Kn=(e,t,n,r)=>e===0&&r===0&&(t===1||t===-1)&&(n===1||n===-1)||t===0&&n===0&&(e===1||e===-1)&&(r===1||r===-1),Be=(e,t,n)=>e>-Re&&e<Re&&t>-Re&&t<Re&&n>-Re&&n<Re,Oe=2147483647;function Zn(e,t){let n=e.colorTable?.[t];if(n)return(n.alpha??255)<255;return t.charCodeAt(0)===35&&/\\/[^:/]*:a\\d/.test(t)}function gt(e,t,n,r){if(!r){r=Array(e.length);for(let s=0;s<e.length;s++)r[s]=Xn(t,e[s].part)}return Jt(e,t,n,-1,r)??Jt(e,t,n,qt,r)}var qt=0;function Jt(e,t,n,r,s){let i=new Map,c=null,l=!1,f=(L)=>{if(L===c)return l;let I=i.get(L);if(I===void 0)i.set(L,I=Zn(t,L));return c=L,l=I,I},u=e.length,a=0,p=0,d=0;for(let L=0;L<u;L++){let I=s[L];if(I){if(d+=I.nStuds,I.mask)a++}}let h=new Float64Array(a),m=new Float64Array(a),A=new Float64Array(a),y=new Float64Array(a),g=new Int32Array(a),b=new Int32Array(a),w=new Float64Array(a),M=new Float64Array(a),T=[],O=new Int32Array(a),v=new Float64Array(a*9),B=new Uint8Array(a);if(r<0)r=a*4+64;let x=new Ie(e.length*2),D=new Int32Array(r),k=new Int32Array(r),E=0,F=0;for(let L=0;L<e.length;L++){let I=e[L],P=I.m,z=s[L];if(!z||!z.mask||!Zt(P)||f(I.color))continue;let U=z.src.bbox,Q=1/0,_=-1/0,X=1/0,H=-1/0;for(let Z=0;Z<2;Z++)for(let oe=0;oe<2;oe++){let ee=Z?U[3]:U[0],Pe=oe?U[5]:U[2],ve=P[0]+P[3]*ee+P[5]*Pe,be=P[2]+P[9]*ee+P[11]*Pe;if(ve<Q)Q=ve;if(ve>_)_=ve;if(be<X)X=be;if(be>H)H=be}let K=Math.round((P[1]+U[4])*2),ie=Math.floor(Q/40),we=Math.floor(_/40),Me=Math.floor(X/40),Ae=Math.floor(H/40);if(!((we-ie+1)*(Ae-Me+1)<=65536)||!Be(K,ie,Me)||!Be(K,we,Ae))continue;let de=Math.floor((Q+5)/40),ae=Math.floor((_-5)/40),ne=Math.floor((X+5)/40),re=Math.floor((H-5)/40),ue=de<=ae&&ne<=re?(ae-de+1)*(re-ne+1):0;F+=ue;let fe=-1;for(let Z=de<=ae&&ne<=re?x.get(K,de,ne):-1,oe=0;Z>=0&&oe<8;Z=D[Z],oe++){let ee=k[Z];if(h[ee]!==Q||m[ee]!==_||A[ee]!==X||y[ee]!==H||T[ee]!==z)continue;let Pe=e[g[ee]].m,ve=!0;for(let be=0;be<12;be++)if(Pe[be]!==P[be]){ve=!1;break}if(ve){fe=ee;break}}if(fe>=0){let Z=n?n[L]:0;if(n&&Z<n[g[fe]])b[fe]=g[fe],g[fe]=L;else if(b[fe]<0||n&&Z<n[b[fe]])b[fe]=L;continue}let se=p++;h[se]=Q,m[se]=_,A[se]=X,y[se]=H,g[se]=L,b[se]=-1,T.push(z),w[se]=U[0],M[se]=U[2],O[se]=K;let pe=se*9;if(v[pe]=P[0],v[pe+1]=P[1],v[pe+2]=P[2],v[pe+3]=P[3],v[pe+4]=P[6],v[pe+5]=P[9],v[pe+6]=P[5],v[pe+7]=P[8],v[pe+8]=P[11],B[se]=z.full&&U[3]-U[0]<=20*z.nx&&U[5]-U[2]<=20*z.nz&&P[4]===0&&P[6]===0&&P[8]===0&&P[10]===0&&Kn(P[3],P[5],P[9],P[11])?1:0,E+ue>r){E=r+1;continue}for(let Z=de;Z<=ae;Z++)for(let oe=ne;oe<=re;oe++){if(!Be(K,Z,oe))continue;let ee=E++;k[ee]=se,D[ee]=x.put(K,Z,oe,ee)}}if(E>r)return qt=F,null;let C=[0,5,-5,5,-5],j=[0,5,5,-5,-5],ye=(L,I,P,z)=>{if(!(I-6>=h[L]-0.5&&I+6<=m[L]+0.5&&z-6>=A[L]-0.5&&z+6<=y[L]+0.5))return!1;if(B[L]===1)return!0;let R=L*9,U=T[L],Q=w[L],_=M[L],X=I-v[R],H=P-v[R+1],K=z-v[R+2],ie=v[R+3]*X+v[R+4]*H+v[R+5]*K,we=v[R+6]*X+v[R+7]*H+v[R+8]*K,{nx:Me,nz:Ae,mask:de}=U;for(let ae=0;ae<5;ae++){let ne=Math.floor((ie+C[ae]-Q)/20),re=Math.floor((we+j[ae]-_)/20);if(ne<0||re<0||ne>=Me||re>=Ae||de[ne*Ae+re]!==1)return!1}return!0},xe=NaN,me=NaN,Ce=NaN,Se=-1,le=-1,Fe=(L,I,P,z)=>{let R=Math.round(I*2),U=Math.floor(L/40),Q=Math.floor(P/40);if(!Be(R,U,Q))return Oe;let _=Oe;if(!n&&le>=0&&O[le]===R&&(g[le]!==z||b[le]>=0)&&ye(le,L,I,P))return 0;if(R!==xe||U!==me||Q!==Ce)xe=R,me=U,Ce=Q,Se=x.get(R,U,Q);for(let X=Se;X>=0;X=D[X]){let H=k[X],K=g[H];if(K===z&&(K=b[H])<0)continue;if(!ye(H,L,I,P))continue;if(!n)return le=H,0;let ie=n[K];if(ie<_)_=ie}return _},ke=new Uint8Array(d),Te=new Uint8Array(d),Le=0,te=n?new Ie(d,4):null,N=n?null:new Int32Array(d),S=n?null:new Int32Array(d),q=n?null:new Int32Array(d),V=0,G=n?new Int32Array(d).fill(Oe):void 0;for(let L=0,I=0;L<e.length;L++){let P=e[L],z=s[L];if(!z)continue;let R=P.m,U=z.studM,Q=R[0],_=R[1],X=R[2],H=R[3],K=R[4],ie=R[5],we=R[6],Me=R[7],Ae=R[8],de=R[9],ae=R[10],ne=R[11];for(let re=0;re<z.nStuds;re++,I++){let ue=re*12,fe=U[ue+4],se=U[ue+7],pe=U[ue+10];if(!(Math.abs(we*fe+Me*se+Ae*pe-1)<0.001&&Math.abs(H*fe+K*se+ie*pe)<0.001&&Math.abs(de*fe+ae*se+ne*pe)<0.001))continue;Te[I]=1;let Z=U[ue],oe=U[ue+1],ee=U[ue+2],Pe=Q+H*Z+K*oe+ie*ee,ve=_+we*Z+Me*oe+Ae*ee,be=X+de*Z+ae*oe+ne*ee,bt=Fe(Pe,ve,be,L);if(bt!==Oe){if(ke[I]=1,Le++,G)G[I]=bt}let ze=Math.round(Pe),$e=Math.round(ve),je=Math.round(be);if(!Be(ze,$e,je))continue;if(!te){N[V]=ze,S[V]=$e,q[V++]=je;continue}let yt=n[L],xt=te.get(ze,$e,je);if(xt<0||yt<xt)te.put(ze,$e,je,yt)}}let ce=te?null:new Qt(N,S,q,V),he=new Uint8Array(e.length),ge=n?new Int32Array(e.length).fill(Oe):void 0;for(let L=0;L<e.length;L++){let I=e[L],P=s[L],z=P?P.src:null;if(!z||!z.under||!Zt(I.m)||f(I.color))continue;let R=z.bbox,U=Math.round((R[3]-R[0])/20),Q=Math.round((R[5]-R[2])/20);if(!U||!Q||U*Q>4096)continue;let _=I.m,X=Math.round(_[1]+R[4]),H=!0,K=0;for(let ie=0;ie<U&&H;ie++)for(let we=0;we<Q;we++){let Me=R[0]+10+20*ie,Ae=R[2]+10+20*we,de=_[0]+_[3]*Me+_[5]*Ae,ae=_[2]+_[9]*Me+_[11]*Ae,ne=Math.round(de),re=Math.round(ae),ue=!Be(ne,X,re)?-1:te?te.get(ne,X,re):ce.has(ne,X,re)?1:-1;if(ue<0){H=!1;break}if(ue>K)K=ue}if(H){if(he[L]=1,ge)ge[L]=K}}return{nStuds:d,studHidden:ke,studUp:Te,underHidden:he,studsHidden:Le,studHideStep:G,underHideStep:ge}}function dt(e,t,n){let r=(u)=>u.colPart&&t.parts[u.colPart]?u.colPart:n&&u.texPart&&t.parts[u.texPart]?u.texPart:u.part,s=new Map,o=new Map,i=(u)=>{let a=u.colour;if(!a)return String(u.color);let p=o.get(a);if(p!==void 0)return p;let d=t.colorTable?.[u.color],h=d?.hex??t.colors?.[u.color],m=d?ft({alpha:d.alpha??255,luminance:d.luminance??0,finish:d.finish??{type:"default"}}):"default:op",A=ft(a);if(p=h&&h.toUpperCase()===a.hex.toUpperCase()&&m===A?String(u.color):a.hex.toUpperCase()+"/"+A,p!==String(u.color))s.set(p,a);return o.set(a,p),p},c=e.map((u)=>({part:r(u),color:i(u),m:u.m,steps:u.steps})),{stepOf:l,nSteps:f}=Yn(c);return{all:c,stepOf:l,nSteps:f,localColours:s}}function Yn(e){let t=!0;for(let o=0;o<e.length;o++){let i=e[o].steps;if(i.length!==1){t=!1;break}let c=i[0];if(!(Number.isInteger(c)&&c>=0&&c<1e6)){t=!1;break}}if(t){let o=new Set;for(let l=0;l<e.length;l++)o.add(e[l].steps[0]);let i=[...o].sort((l,f)=>l-f),c=new Map(i.map((l,f)=>[l,f]));return{stepOf:e.map((l)=>c.get(l.steps[0])),nSteps:i.length}}let n=e.map((o)=>Ht(o.steps)),r=[...new Set(n)].sort(),s=new Map(r.map((o,i)=>[o,i]));return{stepOf:n.map((o)=>s.get(o)),nSteps:r.length}}function en(e,t,n=!0){let r=dt(e,t,n);return gt(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Je="https://ldr-parts-cdn.baconbrix.workers.dev/v1/",Ke=new Map,Xe=new Map;function Ze(e=Je,t=fetch){let n=Ke.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(()=>Ke.delete(e)),Ke.set(e,n);return n}var Jn=(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"),Ye=(e,t)=>Jn(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>Ye(n,t)):e&&typeof e==="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Ye(r,t)])):e;function Qn(e,t={}){let n=[],r=0,s={},o={};for(let p of e){let d=p.buffer;if(!d)throw Error("ldr: mergePacks needs packs from decodePack/loadPack");let h=new DataView(d).getUint32(0,!0),m=new Uint8Array(d,4+h),A=r;n.push(m),r+=m.byteLength;let y=(4-r%4)%4;if(y)n.push(new Uint8Array(y)),r+=y;for(let[g,b]of Object.entries(p.header.parts??{}))if(!(g in s))s[g]=Ye(b,A);for(let[g,b]of Object.entries(p.header.studKinds??{}))if(!(g in o))o[g]=Ye(b,A)}let i=e[0]?.header??{version:1,weld:!0},c=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),l=(4-(4+c.length)%4)%4,f=4+c.length+l,u=new Uint8Array(f+r);new DataView(u.buffer).setUint32(0,c.length+l,!0),u.set(c,4),u.fill(32,4+c.length,f);let a=f;for(let p of n)u.set(p,a),a+=p.byteLength;return He(u.buffer)}async function qn(e,t={}){e=[...e];try{return await tn(e,t)}catch(n){let r=t.cdn??Je,s=t.fetch??fetch;Ke.delete(r);let o=(i,c)=>s(i,{...c,cache:"reload"});try{return await tn(e,{...t,fetch:o})}catch{throw n}}}async function tn(e,t){let n=t.cdn??Je,r=t.fetch??fetch,s=t.gap??16384,o=await Ze(n,r),i=[...new Set([...new Set(e)].map(J))],c=[],l=[];for(let g of i){if(Xe.has(n+g))continue;let b=o.parts[g];if(b)l.push({name:g,off:b[0],len:b[1],file:b[2]??0});else c.push(g)}l.sort((g,b)=>g.file-b.file||g.off-b.off);let f=[];for(let g of l){let b=f[f.length-1];if(b&&b.file===g.file&&g.off-b.end<=s)b.end=Math.max(b.end,g.off+g.len),b.items.push(g);else f.push({file:g.file,start:g.off,end:g.off+g.len,items:[g]})}let u=0,a=0,p=0,d=new Map,h=async()=>{while(p<f.length){let g=f[p++],b=d.get(g.file);if(b)b=b.subarray(g.start,g.end);else{let w=await r(new URL(o.archives[g.file],n).href,{headers:{Range:`bytes=${g.start}-${g.end-1}`,"Accept-Encoding":"identity"}});if(!w.ok)throw Error(`ldr: parts CDN ${w.status}`);if(a++,b=new Uint8Array(await w.arrayBuffer()),u+=b.byteLength,w.status===200)d.set(g.file,b),b=b.subarray(g.start,g.end)}for(let w of g.items){let M=Ge(b.subarray(w.off-g.start,w.off-g.start+w.len)),T=M.buffer.slice(M.byteOffset,M.byteOffset+M.byteLength);Xe.set(n+w.name,He(T))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,f.length)},h));let m=i.filter((g)=>Xe.has(n+g)).map((g)=>Xe.get(n+g)),A={colors:o.colors,...o.colorTable?{colorTable:o.colorTable}:{}};return{pack:m.length?Qn(m,A):He(er(A)),missing:c,requests:a,bytes:u}}function er(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},...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 tr(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 nn(e,t,n){let r=0,s=0,o=!1,i=new Set,c=new Map;for(let l of e){let f;if(l.embedded)f=t.get(l.part);else if(f=c.get(l.part),f===void 0)c.set(l.part,f=J(l.part));let u=f?n.parts[f]:void 0;if(!u)continue;if(u[3]!=null)o=!0,r+=u[3];if(!i.has(f))i.add(f),s+=u[1]}return{bodyTris:r,packBytes:s,known:o}}class Qe 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 rn(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=Ze(t.cdn??Je,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(x)=>{if(!x.ok)throw Error(`ldr: ${x.status} fetching ${e}`);return Mt(await x.arrayBuffer())}),i=performance.now(),c=t.name??(t.text?"main.ldr":vt(e)),l=Xt(o,c,{looseGeometry:!1,callouts:t.callouts}),f=performance.now();t.onParsed?.(l),await s;let u=Kt(o,new Set(l.filter((x)=>x.embedded).map((x)=>x.part)),c),a=(x,D)=>t.maxBodyTris!=null&&x>t.maxBodyTris||t.maxPackBytes!=null&&D>t.maxPackBytes,p=t.maxBodyTris!=null||t.maxPackBytes!=null,d=(x)=>new Qe({...x,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes}),h="full";if(p){let x=nn(l,u,await s);if(a(x.known?x.bodyTris:0,x.packBytes)){if(!t.lowCdn)throw d(x);let D=await Ze(t.lowCdn,r).catch(()=>null);if(!D)throw d(x);let k=nn(l,u,D);if(a(k.known?k.bodyTris:0,k.packBytes))throw d(k);h="low"}}let m=[...l.filter((x)=>!x.embedded).map((x)=>x.part),...u.values()],A=async()=>{let x=await qn(m,h==="low"?{...t,cdn:t.lowCdn}:t);for(let[D,k]of u){let E=x.pack.header.parts[k];if(E)x.pack.header.parts[D]=E}return{...x,packBytes:x.pack.buffer?.byteLength??x.pack.bytes??0,bodyTris:tr(l,x.pack)}},y=await A();if(p&&a(y.bodyTris,y.packBytes)&&h==="full"&&t.lowCdn&&await Ze(t.lowCdn,r).then(()=>!0,()=>!1)){h="low";let x=y;y=await A(),y.requests+=x.requests,y.bytes+=x.bytes}if(p&&a(y.bodyTris,y.packBytes))throw d(y);let{pack:g,missing:b,requests:w,bytes:M}=y,T=new Map([...u].map(([x,D])=>[D,x])),O=b.map((x)=>T.get(x)??x),v=performance.now(),B=t.cull?en(l,g.header,t.textures!==!1):void 0;return{insts:l,pack:g,tier:h,missing:O,requests:w,bytes:M,cull:B,timings:{fetchModel:i-n,parse:f-i,parts:v-f,...B?{cull:performance.now()-v}:{}}}}var nr=new Set(["part","color","m","step","steps","localStep","path"]);function sn(e){let t=e.length,n=0;for(let h of e){if(typeof h.part!=="string"||typeof h.path!=="string"||typeof h.color!=="number"||typeof h.step!=="number"||typeof h.localStep!=="number"||!Array.isArray(h.m)||h.m.length!==12||!Array.isArray(h.steps))return null;n+=h.steps.length}let r=[],s=new Map,o=(h)=>{let m=s.get(h);if(m===void 0)s.set(h,m=r.length),r.push(h);return m},i=new Uint32Array(t),c=new Uint32Array(t),l=new Float64Array(t*3),f=new Float64Array(t*12),u=new Uint32Array(t+1),a=new Float64Array(n),p=[],d=0;for(let h=0;h<t;h++){let m=e[h];i[h]=o(m.part),c[h]=o(m.path),l[h*3]=m.color,l[h*3+1]=m.step,l[h*3+2]=m.localStep;let A=m.m,y=h*12;for(let w=0;w<12;w++)f[y+w]=A[w];let g=m.steps;for(let w=0;w<g.length;w++)a[d++]=g[w];u[h+1]=d;let b=null;for(let w in m)if(!nr.has(w))(b??={})[w]=m[w];if(b)p.push([h,b])}return{n:t,strs:r,part:i,path:c,num:l,m:f,so:u,steps:a,extra:p}}var on=(e)=>[e.part.buffer,e.path.buffer,e.num.buffer,e.m.buffer,e.so.buffer,e.steps.buffer];self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await rn(n,{...r,cull:!1,onParsed:(a)=>{let p=sn(a);if(p)self.postMessage({id:t,packed:p},on(p));else self.postMessage({id:t,insts:a})}}),o=s.pack.buffer;if(self.postMessage({id:t,buffer:o,tier:s.tier,missing:s.missing,requests:s.requests,bytes:s.bytes,timings:s.timings},[o]),!r.cull)return;let i=performance.now(),c=dt(s.insts,s.pack.header,r.textures!==!1),l=gt(c.all,s.pack.header,r.stepCull&&c.nSteps>1?c.stepOf:void 0),f=performance.now()-i,u=[];for(let a of[l.studHidden,l.studUp,l.underHidden,l.studHideStep,l.underHideStep])if(a)u.push(a.buffer);self.postMessage({id:t,cull:l,ms:f},u)}catch(s){if(s instanceof Qe||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';
|
|
5647
5686
|
|
|
5648
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5687
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/inst-io.ts
|
|
5649
5688
|
var CORE = new Set(["part", "color", "m", "step", "steps", "localStep", "path"]);
|
|
5650
5689
|
function unpackInstances(p) {
|
|
5651
5690
|
const { n, strs, part, path, num, m, so, steps, extra } = p;
|
|
@@ -5670,7 +5709,7 @@ function unpackInstances(p) {
|
|
|
5670
5709
|
return out;
|
|
5671
5710
|
}
|
|
5672
5711
|
|
|
5673
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5712
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/cdn.ts
|
|
5674
5713
|
var worker;
|
|
5675
5714
|
var seq = 0;
|
|
5676
5715
|
var pending = new Map;
|
|
@@ -5786,7 +5825,7 @@ async function loadModel(source, o = {}) {
|
|
|
5786
5825
|
timings: { ...prep.timings, parts: t3 - t0 - prep.timings.fetchModel - prep.timings.parse, build: t4 - t3, total: t4 - t0 }
|
|
5787
5826
|
});
|
|
5788
5827
|
}
|
|
5789
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5828
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/usdz.ts
|
|
5790
5829
|
var IDENT = [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1];
|
|
5791
5830
|
var MAX_ERR = 8;
|
|
5792
5831
|
var REL_ERR = 0.1;
|
|
@@ -6418,7 +6457,7 @@ function hiddenInstances(n, items, geo, clear, RES = 512) {
|
|
|
6418
6457
|
hidden[k] = seen[k] ? 0 : 1;
|
|
6419
6458
|
return hidden;
|
|
6420
6459
|
}
|
|
6421
|
-
// ../../../../../../../tmp/ldr-build-
|
|
6460
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/node/library.ts
|
|
6422
6461
|
import { existsSync, readFileSync, statSync } from "fs";
|
|
6423
6462
|
import { join } from "path";
|
|
6424
6463
|
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]];
|
|
@@ -6768,11 +6807,11 @@ class Library {
|
|
|
6768
6807
|
return insts;
|
|
6769
6808
|
}
|
|
6770
6809
|
}
|
|
6771
|
-
// ../../../../../../../tmp/ldr-build-
|
|
6810
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/node/build-pack.ts
|
|
6772
6811
|
import fs3 from "node:fs";
|
|
6773
6812
|
import path3 from "node:path";
|
|
6774
6813
|
|
|
6775
|
-
// ../../../../../../../tmp/ldr-build-
|
|
6814
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/node/resolver.ts
|
|
6776
6815
|
import fs from "node:fs";
|
|
6777
6816
|
import path from "node:path";
|
|
6778
6817
|
var TOP_STUD_RE = /^(stud|studa|stud2|stud2a|stud6|stud6a|stud10|stud15|stud2s|stud2s2|stud-logo\d*|stud2-logo\d*)\.dat$/i;
|
|
@@ -7101,11 +7140,11 @@ function collectDeps(lib, refs) {
|
|
|
7101
7140
|
return out;
|
|
7102
7141
|
}
|
|
7103
7142
|
|
|
7104
|
-
// ../../../../../../../tmp/ldr-build-
|
|
7143
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/node/compile.ts
|
|
7105
7144
|
import fs2 from "node:fs";
|
|
7106
7145
|
import path2 from "node:path";
|
|
7107
7146
|
|
|
7108
|
-
// ../../../../../../../tmp/ldr-build-
|
|
7147
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/node/lod.ts
|
|
7109
7148
|
import { MeshoptSimplifier, MeshoptEncoder } from "meshoptimizer";
|
|
7110
7149
|
await Promise.all([MeshoptSimplifier.ready, MeshoptEncoder.ready]);
|
|
7111
7150
|
function reorderMesh(P, N, C, I) {
|
|
@@ -7411,7 +7450,7 @@ function levelLines(P, I, E, err, always, tol = 0.01) {
|
|
|
7411
7450
|
return out;
|
|
7412
7451
|
}
|
|
7413
7452
|
|
|
7414
|
-
// ../../../../../../../tmp/ldr-build-
|
|
7453
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/node/compile.ts
|
|
7415
7454
|
class BfcState {
|
|
7416
7455
|
accum;
|
|
7417
7456
|
ccw = true;
|
|
@@ -8372,7 +8411,7 @@ function encodePack(parts, studKinds, weld, extra, options = {}) {
|
|
|
8372
8411
|
return Buffer.concat([head, ...chunks.map((c) => new Uint8Array(c.buffer, c.byteOffset, c.byteLength))]);
|
|
8373
8412
|
}
|
|
8374
8413
|
|
|
8375
|
-
// ../../../../../../../tmp/ldr-build-
|
|
8414
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/node/build-pack.ts
|
|
8376
8415
|
function packCompilerOpts(o) {
|
|
8377
8416
|
return { studs: o.studs ?? "low", prims: o.primitives ?? "full", weld: o.weld ?? true, separateStuds: true, cond: !!o.cond, tex: !!o.textures, ...o.partWorkLimit ? { workLimit: o.partWorkLimit } : {} };
|
|
8378
8417
|
}
|
|
@@ -8444,7 +8483,7 @@ function buildPack(o) {
|
|
|
8444
8483
|
const warnings = [...lib.conflicts].map((n) => `${n}: defined differently by two models; the first definition is used`);
|
|
8445
8484
|
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 } : {} };
|
|
8446
8485
|
}
|
|
8447
|
-
// ../../../../../../../tmp/ldr-build-
|
|
8486
|
+
// ../../../../../../../tmp/ldr-build-zkQ2hC/src/node/promote.ts
|
|
8448
8487
|
var GEOM = /^\s*[2-5]\s/;
|
|
8449
8488
|
var REF = /^\s*1\s/;
|
|
8450
8489
|
var FILE = /^\s*0\s+FILE\s+(\S.*?)\s*$/i;
|