ldr 0.33.13 → 0.33.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/index.js +185 -112
- package/dist/load-worker.gen.d.ts +1 -1
- package/dist/node/index.js +194 -121
- package/package.json +1 -1
package/dist/node/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/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;
|
|
@@ -802,7 +802,7 @@ function fileStepViews(f) {
|
|
|
802
802
|
viewMemo.set(f, out);
|
|
803
803
|
return out;
|
|
804
804
|
}
|
|
805
|
-
// ../../../../../../../tmp/ldr-build-
|
|
805
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/model.ts
|
|
806
806
|
class ModelLimitError extends Error {
|
|
807
807
|
limit;
|
|
808
808
|
code = "ldr-model-limit";
|
|
@@ -1243,7 +1243,7 @@ function blendedColourHex(code) {
|
|
|
1243
1243
|
const a = LDRAW_EXE_16[code - 256 >> 4], b = LDRAW_EXE_16[code - 256 & 15];
|
|
1244
1244
|
return "#" + [0, 1, 2].map((k) => (a[k] + b[k] >> 1).toString(16).padStart(2, "0")).join("").toUpperCase();
|
|
1245
1245
|
}
|
|
1246
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1246
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/instructions.ts
|
|
1247
1247
|
var MIN_VIS = 0.5;
|
|
1248
1248
|
var REORIENT = 0.35;
|
|
1249
1249
|
var deg = Math.PI / 180;
|
|
@@ -1611,10 +1611,10 @@ function planStepViews(insts, parts, stepOf, nSteps, o = {}) {
|
|
|
1611
1611
|
}
|
|
1612
1612
|
};
|
|
1613
1613
|
}
|
|
1614
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1614
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/render.ts
|
|
1615
1615
|
import * as THREE from "three";
|
|
1616
1616
|
|
|
1617
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1617
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/pack-io.ts
|
|
1618
1618
|
import { decompress } from "fzstd";
|
|
1619
1619
|
async function decompressPack(data) {
|
|
1620
1620
|
const u = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
@@ -1637,7 +1637,7 @@ function decodePack(buf) {
|
|
|
1637
1637
|
return { header, arr, bytes: buf.byteLength, buffer: buf };
|
|
1638
1638
|
}
|
|
1639
1639
|
|
|
1640
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1640
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/cull.ts
|
|
1641
1641
|
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;
|
|
1642
1642
|
var prepCache = new WeakMap;
|
|
1643
1643
|
var lastH = null;
|
|
@@ -1910,6 +1910,10 @@ function seeThrough(H, c) {
|
|
|
1910
1910
|
return c.charCodeAt(0) === 35 && /\/[^:/]*:a\d/.test(c);
|
|
1911
1911
|
}
|
|
1912
1912
|
function cullCore(insts, H, steps) {
|
|
1913
|
+
return cullPass(insts, H, steps, -1) ?? cullPass(insts, H, steps, needE);
|
|
1914
|
+
}
|
|
1915
|
+
var needE = 0;
|
|
1916
|
+
function cullPass(insts, H, steps, eCap) {
|
|
1913
1917
|
const CELL = 40;
|
|
1914
1918
|
const clear = new Map;
|
|
1915
1919
|
const isClear = (c) => {
|
|
@@ -1918,11 +1922,30 @@ function cullCore(insts, H, steps) {
|
|
|
1918
1922
|
clear.set(c, v = seeThrough(H, c));
|
|
1919
1923
|
return v;
|
|
1920
1924
|
};
|
|
1921
|
-
const
|
|
1922
|
-
|
|
1923
|
-
|
|
1925
|
+
const nI = insts.length;
|
|
1926
|
+
let cap = 0, nR = 0;
|
|
1927
|
+
for (let idx = 0, lp = "";idx < nI; idx++) {
|
|
1928
|
+
const part = insts[idx].part;
|
|
1929
|
+
if (part === lp) {
|
|
1930
|
+
cap++;
|
|
1931
|
+
continue;
|
|
1932
|
+
}
|
|
1933
|
+
const p = H.parts[part];
|
|
1934
|
+
if (p && p.mask) {
|
|
1935
|
+
cap++;
|
|
1936
|
+
lp = part;
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
const rx0 = new Float64Array(cap), rx1 = new Float64Array(cap), rz0 = new Float64Array(cap), rz1 = new Float64Array(cap);
|
|
1940
|
+
const rInst = new Int32Array(cap), rInst2 = new Int32Array(cap), rBx = new Float64Array(cap), rBz = new Float64Array(cap);
|
|
1941
|
+
const rPrep = [];
|
|
1942
|
+
const rLv = new Int32Array(cap), rM = new Float64Array(cap * 9);
|
|
1943
|
+
const rFast = new Uint8Array(cap);
|
|
1944
|
+
if (eCap < 0)
|
|
1945
|
+
eCap = cap * 4 + 64;
|
|
1924
1946
|
const cells = new Int3Table(insts.length * 2);
|
|
1925
|
-
const nextE =
|
|
1947
|
+
const nextE = new Int32Array(eCap), rectE = new Int32Array(eCap);
|
|
1948
|
+
let nE = 0, need = 0;
|
|
1926
1949
|
for (let idx = 0;idx < insts.length; idx++) {
|
|
1927
1950
|
const it = insts[idx];
|
|
1928
1951
|
const m = it.m;
|
|
@@ -1949,8 +1972,11 @@ function cullCore(insts, H, steps) {
|
|
|
1949
1972
|
const cx0 = Math.floor(x0 / CELL), cx1 = Math.floor(x1 / CELL), cz0 = Math.floor(z0 / CELL), cz1 = Math.floor(z1 / CELL);
|
|
1950
1973
|
if (!((cx1 - cx0 + 1) * (cz1 - cz0 + 1) <= 65536) || !inRange(lv2, cx0, cz0) || !inRange(lv2, cx1, cz1))
|
|
1951
1974
|
continue;
|
|
1975
|
+
const ux0 = Math.floor((x0 + 5) / CELL), ux1 = Math.floor((x1 - 5) / CELL), uz0 = Math.floor((z0 + 5) / CELL), uz1 = Math.floor((z1 - 5) / CELL);
|
|
1976
|
+
const nc = ux0 <= ux1 && uz0 <= uz1 ? (ux1 - ux0 + 1) * (uz1 - uz0 + 1) : 0;
|
|
1977
|
+
need += nc;
|
|
1952
1978
|
let dup = -1;
|
|
1953
|
-
for (let e = cells.get(lv2,
|
|
1979
|
+
for (let e = ux0 <= ux1 && uz0 <= uz1 ? cells.get(lv2, ux0, uz0) : -1, k = 0;e >= 0 && k < 8; e = nextE[e], k++) {
|
|
1954
1980
|
const q = rectE[e];
|
|
1955
1981
|
if (rx0[q] !== x0 || rx1[q] !== x1 || rz0[q] !== z0 || rz1[q] !== z1 || rPrep[q] !== pp)
|
|
1956
1982
|
continue;
|
|
@@ -1975,28 +2001,45 @@ function cullCore(insts, H, steps) {
|
|
|
1975
2001
|
rInst2[dup] = idx;
|
|
1976
2002
|
continue;
|
|
1977
2003
|
}
|
|
1978
|
-
const ri =
|
|
1979
|
-
rx0
|
|
1980
|
-
rx1
|
|
1981
|
-
rz0
|
|
1982
|
-
rz1
|
|
1983
|
-
rInst
|
|
1984
|
-
rInst2
|
|
2004
|
+
const ri = nR++;
|
|
2005
|
+
rx0[ri] = x0;
|
|
2006
|
+
rx1[ri] = x1;
|
|
2007
|
+
rz0[ri] = z0;
|
|
2008
|
+
rz1[ri] = z1;
|
|
2009
|
+
rInst[ri] = idx;
|
|
2010
|
+
rInst2[ri] = -1;
|
|
1985
2011
|
rPrep.push(pp);
|
|
1986
|
-
rBx
|
|
1987
|
-
rBz
|
|
1988
|
-
rLv
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
2012
|
+
rBx[ri] = b[0];
|
|
2013
|
+
rBz[ri] = b[2];
|
|
2014
|
+
rLv[ri] = lv2;
|
|
2015
|
+
const o = ri * 9;
|
|
2016
|
+
rM[o] = m[0];
|
|
2017
|
+
rM[o + 1] = m[1];
|
|
2018
|
+
rM[o + 2] = m[2];
|
|
2019
|
+
rM[o + 3] = m[3];
|
|
2020
|
+
rM[o + 4] = m[6];
|
|
2021
|
+
rM[o + 5] = m[9];
|
|
2022
|
+
rM[o + 6] = m[5];
|
|
2023
|
+
rM[o + 7] = m[8];
|
|
2024
|
+
rM[o + 8] = m[11];
|
|
2025
|
+
rFast[ri] = pp.full && b[3] - b[0] <= 20 * pp.nx && b[5] - b[2] <= 20 * pp.nz && m[4] === 0 && m[6] === 0 && m[8] === 0 && m[10] === 0 && quarterTurn(m[3], m[5], m[9], m[11]) ? 1 : 0;
|
|
2026
|
+
if (nE + nc > eCap) {
|
|
2027
|
+
nE = eCap + 1;
|
|
2028
|
+
continue;
|
|
2029
|
+
}
|
|
2030
|
+
for (let cx = ux0;cx <= ux1; cx++)
|
|
2031
|
+
for (let cz = uz0;cz <= uz1; cz++) {
|
|
1993
2032
|
if (!inRange(lv2, cx, cz))
|
|
1994
2033
|
continue;
|
|
1995
|
-
const e =
|
|
1996
|
-
rectE
|
|
1997
|
-
nextE
|
|
2034
|
+
const e = nE++;
|
|
2035
|
+
rectE[e] = ri;
|
|
2036
|
+
nextE[e] = cells.put(lv2, cx, cz, e);
|
|
1998
2037
|
}
|
|
1999
2038
|
}
|
|
2039
|
+
if (nE > eCap) {
|
|
2040
|
+
needE = need;
|
|
2041
|
+
return null;
|
|
2042
|
+
}
|
|
2000
2043
|
const SX = [0, 5, -5, 5, -5], SZ = [0, 5, 5, -5, -5];
|
|
2001
2044
|
const covers = (ri, x, y, z) => {
|
|
2002
2045
|
if (!(x - 6 >= rx0[ri] - 0.5 && x + 6 <= rx1[ri] + 0.5 && z - 6 >= rz0[ri] - 0.5 && z + 6 <= rz1[ri] + 0.5))
|
|
@@ -2160,7 +2203,7 @@ function precomputeCull(instances, H, useTex = true) {
|
|
|
2160
2203
|
return cullCore(s.all, H, s.nSteps > 1 ? s.stepOf : undefined);
|
|
2161
2204
|
}
|
|
2162
2205
|
|
|
2163
|
-
// ../../../../../../../tmp/ldr-build-
|
|
2206
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/render.ts
|
|
2164
2207
|
async function loadPack(url) {
|
|
2165
2208
|
const res = await fetch(url);
|
|
2166
2209
|
if (!res.ok)
|
|
@@ -3258,53 +3301,63 @@ function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colo
|
|
|
3258
3301
|
};
|
|
3259
3302
|
const matIdFor = (c, e, k) => e[k] >= 0 ? e[k] : e[k] = matIdOf(matOf(c, k === 1));
|
|
3260
3303
|
const partStud = new Map;
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
const
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3304
|
+
let jAt = 0;
|
|
3305
|
+
const pass1 = (idx) => {
|
|
3306
|
+
let j = jAt;
|
|
3307
|
+
const jEnd = j + 32768;
|
|
3308
|
+
for (;idx < insts.length && j < jEnd; idx++) {
|
|
3309
|
+
const it = insts[idx];
|
|
3310
|
+
const pp = prepPart(H, it.part);
|
|
3311
|
+
if (!pp || !pp.nStuds)
|
|
3312
|
+
continue;
|
|
3313
|
+
const a = it.m;
|
|
3314
|
+
const instE = colEntry(it.color);
|
|
3315
|
+
let ps = partStud.get(pp);
|
|
3316
|
+
if (!ps) {
|
|
3317
|
+
const kid = new Int32Array(pp.nStuds), neg = new Uint8Array(pp.nStuds);
|
|
3318
|
+
for (let si = 0;si < pp.nStuds; si++) {
|
|
3319
|
+
const kn = pp.kind[si];
|
|
3320
|
+
let id = kindIds.get(kn);
|
|
3321
|
+
if (id === undefined) {
|
|
3322
|
+
id = kindNames.length;
|
|
3323
|
+
kindIds.set(kn, id);
|
|
3324
|
+
kindNames.push(kn);
|
|
3325
|
+
}
|
|
3326
|
+
kid[si] = id;
|
|
3327
|
+
neg[si] = det12(pp.studM.subarray(si * 12, si * 12 + 12)) < 0 ? 1 : 0;
|
|
3278
3328
|
}
|
|
3279
|
-
|
|
3280
|
-
|
|
3329
|
+
partStud.set(pp, ps = { kid, neg });
|
|
3330
|
+
}
|
|
3331
|
+
const instNeg = det12(a) < 0 ? 1 : 0;
|
|
3332
|
+
const B = pp.studM;
|
|
3333
|
+
for (let si = 0;si < pp.nStuds; si++, j++) {
|
|
3334
|
+
const o = si * 12, b0 = B[o], b1 = B[o + 1], b2 = B[o + 2];
|
|
3335
|
+
const neg = (instNeg ^ ps.neg[si]) === 1;
|
|
3336
|
+
const km = ps.kid[si] * 2 + (neg ? 1 : 0);
|
|
3337
|
+
const sc = pp.color[si];
|
|
3338
|
+
const mid = sc === "16" ? matIdFor(it.color, instE, neg ? 1 : 0) : matIdFor(sc, colEntry(sc), neg ? 1 : 0);
|
|
3339
|
+
const row = bucketOfKM[mid];
|
|
3340
|
+
let b = row[km];
|
|
3341
|
+
if (b === undefined) {
|
|
3342
|
+
b = bKind.length;
|
|
3343
|
+
row[km] = b;
|
|
3344
|
+
bKind.push(kindNames[ps.kid[si]]);
|
|
3345
|
+
bMat.push(matList[mid]);
|
|
3346
|
+
bAll.push(0);
|
|
3347
|
+
}
|
|
3348
|
+
studBucket[j] = b;
|
|
3349
|
+
bAll[b]++;
|
|
3350
|
+
sx[j] = a[0] + a[3] * b0 + a[4] * b1 + a[5] * b2;
|
|
3351
|
+
sz[j] = a[2] + a[9] * b0 + a[10] * b1 + a[11] * b2;
|
|
3281
3352
|
}
|
|
3282
|
-
partStud.set(pp, ps = { kid, neg });
|
|
3283
|
-
}
|
|
3284
|
-
const instNeg = det12(a) < 0 ? 1 : 0;
|
|
3285
|
-
const B = pp.studM;
|
|
3286
|
-
for (let si = 0;si < pp.nStuds; si++, j++) {
|
|
3287
|
-
if ((j & 32767) === 0 && j)
|
|
3288
|
-
yield;
|
|
3289
|
-
const o = si * 12, b0 = B[o], b1 = B[o + 1], b2 = B[o + 2];
|
|
3290
|
-
const neg = (instNeg ^ ps.neg[si]) === 1;
|
|
3291
|
-
const km = ps.kid[si] * 2 + (neg ? 1 : 0);
|
|
3292
|
-
const sc = pp.color[si];
|
|
3293
|
-
const mid = sc === "16" ? matIdFor(it.color, instE, neg ? 1 : 0) : matIdFor(sc, colEntry(sc), neg ? 1 : 0);
|
|
3294
|
-
const row = bucketOfKM[mid];
|
|
3295
|
-
let b = row[km];
|
|
3296
|
-
if (b === undefined) {
|
|
3297
|
-
b = bKind.length;
|
|
3298
|
-
row[km] = b;
|
|
3299
|
-
bKind.push(kindNames[ps.kid[si]]);
|
|
3300
|
-
bMat.push(matList[mid]);
|
|
3301
|
-
bAll.push(0);
|
|
3302
|
-
}
|
|
3303
|
-
studBucket[j] = b;
|
|
3304
|
-
bAll[b]++;
|
|
3305
|
-
sx[j] = a[0] + a[3] * b0 + a[4] * b1 + a[5] * b2;
|
|
3306
|
-
sz[j] = a[2] + a[9] * b0 + a[10] * b1 + a[11] * b2;
|
|
3307
3353
|
}
|
|
3354
|
+
jAt = j;
|
|
3355
|
+
return idx;
|
|
3356
|
+
};
|
|
3357
|
+
for (let idx = 0;idx < insts.length; ) {
|
|
3358
|
+
if (idx)
|
|
3359
|
+
yield;
|
|
3360
|
+
idx = pass1(idx);
|
|
3308
3361
|
}
|
|
3309
3362
|
yield;
|
|
3310
3363
|
const bIds = bAll.map((n) => new Int32Array(n));
|
|
@@ -3372,42 +3425,51 @@ function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colo
|
|
|
3372
3425
|
let nHid = 0;
|
|
3373
3426
|
{
|
|
3374
3427
|
const w = new Float64Array(12);
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
const
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
if (
|
|
3383
|
-
yield;
|
|
3384
|
-
if (trim && cull.studHidden[j]) {
|
|
3385
|
-
if (sMesh[studCl[j]]) {
|
|
3386
|
-
hidI[nHid] = idx;
|
|
3387
|
-
hidS[nHid] = si;
|
|
3388
|
-
hidC[nHid++] = studCl[j];
|
|
3389
|
-
}
|
|
3390
|
-
continue;
|
|
3391
|
-
}
|
|
3392
|
-
mul12To(it.m, pp.studM, si * 12, w);
|
|
3393
|
-
const sm = sMesh[studCl[j]];
|
|
3394
|
-
if (!sm)
|
|
3428
|
+
jAt = 0;
|
|
3429
|
+
const pass3 = (idx) => {
|
|
3430
|
+
let j = jAt;
|
|
3431
|
+
const jEnd = j + 32768;
|
|
3432
|
+
for (;idx < insts.length && j < jEnd; idx++) {
|
|
3433
|
+
const it = insts[idx];
|
|
3434
|
+
const pp = prepPart(H, it.part);
|
|
3435
|
+
if (!pp || !pp.nStuds)
|
|
3395
3436
|
continue;
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3437
|
+
for (let si = 0;si < pp.nStuds; si++, j++) {
|
|
3438
|
+
if (trim && cull.studHidden[j]) {
|
|
3439
|
+
if (sMesh[studCl[j]]) {
|
|
3440
|
+
hidI[nHid] = idx;
|
|
3441
|
+
hidS[nHid] = si;
|
|
3442
|
+
hidC[nHid++] = studCl[j];
|
|
3443
|
+
}
|
|
3444
|
+
continue;
|
|
3445
|
+
}
|
|
3446
|
+
mul12To(it.m, pp.studM, si * 12, w);
|
|
3447
|
+
const sm = sMesh[studCl[j]];
|
|
3448
|
+
if (!sm)
|
|
3449
|
+
continue;
|
|
3450
|
+
const im = sm.im;
|
|
3451
|
+
const slot = studSlot[j];
|
|
3452
|
+
const sc = pp.color[si];
|
|
3453
|
+
const col = sc === "16" ? it.color : sc;
|
|
3454
|
+
if (sm.slots) {
|
|
3455
|
+
const t = sm.slots;
|
|
3456
|
+
t.own[slot] = steps[idx];
|
|
3457
|
+
t.hide[slot] = cull.studHideStep[j];
|
|
3458
|
+
t.inst[slot] = idx;
|
|
3459
|
+
t.stud[slot] = si;
|
|
3460
|
+
t.col[slot] = colorIndex(col);
|
|
3461
|
+
}
|
|
3462
|
+
writeM4(im.instanceMatrix.array, slot * 16, w);
|
|
3463
|
+
colorOf(col).toArray(im.instanceColor.array, slot * 3);
|
|
3407
3464
|
}
|
|
3408
|
-
writeM4(im.instanceMatrix.array, slot * 16, w);
|
|
3409
|
-
colorOf(col).toArray(im.instanceColor.array, slot * 3);
|
|
3410
3465
|
}
|
|
3466
|
+
jAt = j;
|
|
3467
|
+
return idx;
|
|
3468
|
+
};
|
|
3469
|
+
for (let idx = 0;idx < insts.length; ) {
|
|
3470
|
+
if (idx)
|
|
3471
|
+
yield;
|
|
3472
|
+
idx = pass3(idx);
|
|
3411
3473
|
}
|
|
3412
3474
|
}
|
|
3413
3475
|
if (trim) {
|
|
@@ -3448,11 +3510,20 @@ function hiddenStudSpheres(insts, H, hidI, hidS, hidC, sMesh, k0, k1) {
|
|
|
3448
3510
|
function undersideGroups(ids, insts) {
|
|
3449
3511
|
const by = new Map;
|
|
3450
3512
|
const rest = [];
|
|
3513
|
+
let p4 = NaN, p7 = NaN, p10 = NaN, prev = rest;
|
|
3451
3514
|
for (const id of ids) {
|
|
3452
3515
|
const m = insts[id].m;
|
|
3516
|
+
if (m[4] === p4 && m[7] === p7 && m[10] === p10) {
|
|
3517
|
+
prev.push(id);
|
|
3518
|
+
continue;
|
|
3519
|
+
}
|
|
3520
|
+
p4 = m[4];
|
|
3521
|
+
p7 = m[7];
|
|
3522
|
+
p10 = m[10];
|
|
3453
3523
|
const l = Math.hypot(m[4], m[7], m[10]);
|
|
3454
3524
|
if (!(l > 0.000001)) {
|
|
3455
3525
|
rest.push(id);
|
|
3526
|
+
prev = rest;
|
|
3456
3527
|
continue;
|
|
3457
3528
|
}
|
|
3458
3529
|
const ax = [m[4] / l, m[7] / l, m[10] / l, l];
|
|
@@ -3461,11 +3532,13 @@ function undersideGroups(ids, insts) {
|
|
|
3461
3532
|
if (!g) {
|
|
3462
3533
|
if (by.size >= 12) {
|
|
3463
3534
|
rest.push(id);
|
|
3535
|
+
prev = rest;
|
|
3464
3536
|
continue;
|
|
3465
3537
|
}
|
|
3466
3538
|
by.set(k, g = { ids: [], ax });
|
|
3467
3539
|
}
|
|
3468
3540
|
g.ids.push(id);
|
|
3541
|
+
prev = g.ids;
|
|
3469
3542
|
}
|
|
3470
3543
|
const out = [...by.values()];
|
|
3471
3544
|
if (rest.length)
|
|
@@ -4573,7 +4646,7 @@ async function warmPackGeometry(pack, stop = () => false, sliceMs = 8) {
|
|
|
4573
4646
|
await new Promise((r) => setTimeout(r, 0));
|
|
4574
4647
|
}
|
|
4575
4648
|
}
|
|
4576
|
-
// ../../../../../../../tmp/ldr-build-
|
|
4649
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/scene.ts
|
|
4577
4650
|
import * as THREE2 from "three";
|
|
4578
4651
|
var _box = new THREE2.Box3;
|
|
4579
4652
|
var _m4 = new THREE2.Matrix4;
|
|
@@ -4928,10 +5001,10 @@ function createLdrObjectInner(instances, pack, options, progressive) {
|
|
|
4928
5001
|
return finish();
|
|
4929
5002
|
})();
|
|
4930
5003
|
}
|
|
4931
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5004
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/parts-cdn.ts
|
|
4932
5005
|
import { decompress as decompress2 } from "fzstd";
|
|
4933
5006
|
|
|
4934
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5007
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/embedded.ts
|
|
4935
5008
|
function splitFiles(text, fallback) {
|
|
4936
5009
|
const files = new Map;
|
|
4937
5010
|
let cur = null, saw = false, skip = false;
|
|
@@ -5006,7 +5079,7 @@ function embeddedKeys(text, names, fallback = "main.ldr") {
|
|
|
5006
5079
|
return out;
|
|
5007
5080
|
}
|
|
5008
5081
|
|
|
5009
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5082
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/parts-cdn.ts
|
|
5010
5083
|
var DEFAULT_PARTS_CDN = "https://ldr-demo.vercel.app/cdn/v1/";
|
|
5011
5084
|
var indexCache = new Map;
|
|
5012
5085
|
var shardCache = new Map;
|
|
@@ -5260,10 +5333,10 @@ async function prepareModel(source, o = {}) {
|
|
|
5260
5333
|
return { insts, pack, tier, missing, requests, bytes, cull, timings: { fetchModel: t1 - t0, parse: t2 - t1, parts: t3 - t2, ...cull ? { cull: performance.now() - t3 } : {} } };
|
|
5261
5334
|
}
|
|
5262
5335
|
|
|
5263
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5264
|
-
var load_worker_gen_default = 'var Wt=ArrayBuffer,K=Uint8Array,Se=Uint16Array,Xt=Int16Array;var ke=Int32Array,je=function(e,t,n){if(K.prototype.slice)return K.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 K(n-t);return r.set(e.subarray(t,n)),r},Me=function(e,t,n,r){if(K.prototype.fill)return K.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},Kt=function(e,t,n,r){if(K.prototype.copyWithin)return K.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 Zt=["invalid zstd data","window size too large (>2046MB)","invalid block type","FSE accuracy too high","match distance too far back","unexpected EOF"],Z=function(e,t,n){var r=Error(t||Zt[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,Z);if(!n)throw r;return r},ft=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},Yt=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},Jt=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)Z(0);var u=6-s,f=i==3?4:i,l=ft(e,u,f);u+=f;var a=c?1<<c:s,p=ft(e,u,a)+(c==1&&256),g=p;if(!s){var b=1<<10+(e[5]>>3);g=b+(b>>3)*(e[5]&7)}if(g>2145386496)Z(1);var y=new K((t==1?p||g:t?0:g)+12);return y[0]=1,y[4]=4,y[8]=8,{b:u+a,y:0,l:0,d:l,w:t&&t!=1?t:y.subarray(12),e:g,o:new ke(y.buffer,0,3),u:p,c:o,m:Math.min(131072,g)}}else if((n>>4|e[3]<<20)==25481893)return Yt(e,4)+8;Z(0)},be=function(e){var t=0;for(;1<<t<=e;++t);return t-1},Ae=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)Z(3);var o=1<<s,i=o,c=-1,u=-1,f=-1,l=o,a=new Wt(512+(o<<2)),p=new Xt(a,0,256),g=new Se(a,0,256),b=new Se(a,512,o),y=512+(o<<1),w=new K(a,y,o),x=new K(a,y+o);while(c<255&&i>0){var m=be(i+1),d=r>>3,M=(1<<m+1)-1,U=(e[d]|e[d+1]<<8|e[d+2]<<16)>>(r&7)&M,T=(1<<m)-1,k=M-i-1,D=U&T;if(D<k)r+=m,U=D;else if(r+=m+1,U>T)U-=k;if(p[++c]=--U,U==-1)i+=U,w[--l]=c;else i-=U;if(!U)do{var P=r>>3;u=(e[P]|e[P+1]<<8)>>(r&7)&3,r+=2,c+=u}while(u==3)}if(c>255||i)Z(0);var A=0,v=(o>>1)+(o>>3)+3,E=o-1;for(var z=0;z<=c;++z){var S=p[z];if(S<1){g[z]=-S;continue}for(f=0;f<S;++f){w[A]=z;do A=A+v&E;while(A>=l)}}if(A)Z(0);for(f=0;f<o;++f){var I=g[w[f]]++,X=x[f]=s-be(I);b[f]=(I<<X)-o}return[r+7>>3,{b:s,s:w,n:x,t:b}]},Qt=function(e,t){var n=0,r=-1,s=new K(292),o=e[t],i=s.subarray(0,256),c=s.subarray(256,268),u=new Se(s.buffer,268);if(o<128){var f=Ae(e,t+1,6),l=f[0],a=f[1];t+=o;var p=l<<3,g=e[t];if(!g)Z(0);var b=0,y=0,w=a.b,x=w,m=(++t<<3)-8+be(g);for(;;){if(m-=w,m<p)break;var d=m>>3;if(b+=(e[d]|e[d+1]<<8)>>(m&7)&(1<<w)-1,i[++r]=a.s[b],m-=x,m<p)break;d=m>>3,y+=(e[d]|e[d+1]<<8)>>(m&7)&(1<<x)-1,i[++r]=a.s[y],w=a.n[b],b=a.t[b],x=a.n[y],y=a.t[y]}if(++r>255)Z(0)}else{r=o-127;for(;n<r;n+=2){var M=e[++t];i[n]=M>>4,i[n+1]=M&15}++t}var U=0;for(n=0;n<r;++n){var T=i[n];if(T>11)Z(0);U+=T&&1<<T-1}var k=be(U)+1,D=1<<k,P=D-U;if(P&P-1)Z(0);i[r++]=be(P)+1;for(n=0;n<r;++n){var T=i[n];++c[i[n]=T&&k+1-T]}var A=new K(D<<1),v=A.subarray(0,D),E=A.subarray(D);u[k]=0;for(n=k;n>0;--n){var z=u[n];Me(E,n,z,u[n-1]=z+c[n]*(1<<k-n))}if(u[0]!=D)Z(0);for(n=0;n<r;++n){var S=i[n];if(S){var I=u[S];Me(v,n,I,u[S]=I+(1<<k-S))}}return[t,{n:E,b:k,s:v}]},qt=Ae(new K([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],en=Ae(new K([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],tn=Ae(new K([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],pt=function(e,t){var n=e.length,r=new ke(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Ve=new K(new ke([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),nn=pt(Ve,0),_e=new K(new ke([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),rn=pt(_e,3),we=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)Z(0);var u=0,f=n.b,l=(r<<3)-8+be(o)-f,a=-1;for(;l>c&&a<s;){var p=l>>3,g=(e[p]|e[p+1]<<8|e[p+2]<<16)>>(l&7);u=(u<<f|g)&i,t[++a]=n.s[u],l-=f=n.n[u]}if(l!=c||a+1!=s)Z(0)},sn=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,c=o+i;we(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),we(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),we(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,c),n),we(e.subarray(r),t.subarray(c),n)},on=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,u=(s+=3)+c;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return Me(n,e[s],t.y,t.y+=c),n;return Me(new K(c),e[s])}if(u>e.length)return;if(i==0){if(t.b=u,n)return n.set(e.subarray(s,u),t.y),t.y+=c,n;return je(e,s,u)}if(i==2){var f=e[s],l=f&3,a=f>>2&3,p=f>>4,g=0,b=0;if(l<2)if(a&1)p|=e[++s]<<4|(a&2&&e[++s]<<12);else p=f>>3;else if(b=a,a<2)p|=(e[++s]&63)<<4,g=e[s]>>6|e[++s]<<2;else if(a==2)p|=e[++s]<<4|(e[++s]&3)<<12,g=e[s]>>2|e[++s]<<6;else p|=e[++s]<<4|(e[++s]&63)<<12,g=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var y=n?n.subarray(t.y,t.y+t.m):new K(t.m),w=y.length-p;if(l==0)y.set(e.subarray(s,s+=p),w);else if(l==1)Me(y,e[s++],w);else{var x=t.h;if(l==2){var m=Qt(e,s);g+=s-(s=m[0]),t.h=x=m[1]}else if(!x)Z(0);(b?sn:we)(e.subarray(s,s+=g),y.subarray(w),x)}var d=e[s++];if(d){if(d==255)d=(e[s++]|e[s++]<<8)+32512;else if(d>127)d=d-128<<8|e[s++];var M=e[s++];if(M&3)Z(0);var U=[en,tn,qt];for(var T=2;T>-1;--T){var k=M>>(T<<1)+2&3;if(k==1){var D=new K([0,0,e[s++]]);U[T]={s:D.subarray(2,3),n:D.subarray(0,1),t:new Se(D.buffer,0,1),b:0}}else if(k==2)r=Ae(e,s,9-(T&1)),s=r[0],U[T]=r[1];else if(k==3){if(!t.t)Z(0);U[T]=t.t[T]}}var P=t.t=U,A=P[0],v=P[1],E=P[2],z=e[u-1];if(!z)Z(0);var S=(u<<3)-8+be(z)-E.b,I=S>>3,X=0,re=(e[I]|e[I+1]<<8)>>(S&7)&(1<<E.b)-1;I=(S-=v.b)>>3;var ee=(e[I]|e[I+1]<<8)>>(S&7)&(1<<v.b)-1;I=(S-=A.b)>>3;var ce=(e[I]|e[I+1]<<8)>>(S&7)&(1<<A.b)-1;for(++d;--d;){var fe=E.s[re],ge=E.n[re],se=A.s[ce],ue=A.n[ce],pe=v.s[ee],me=v.n[ee];I=(S-=pe)>>3;var V=1<<pe,h=V+((e[I]|e[I+1]<<8|e[I+2]<<16|e[I+3]<<24)>>>(S&7)&V-1);I=(S-=_e[se])>>3;var F=rn[se]+((e[I]|e[I+1]<<8|e[I+2]<<16)>>(S&7)&(1<<_e[se])-1);I=(S-=Ve[fe])>>3;var L=nn[fe]+((e[I]|e[I+1]<<8|e[I+2]<<16)>>(S&7)&(1<<Ve[fe])-1);if(I=(S-=ge)>>3,re=E.t[re]+((e[I]|e[I+1]<<8)>>(S&7)&(1<<ge)-1),I=(S-=ue)>>3,ce=A.t[ce]+((e[I]|e[I+1]<<8)>>(S&7)&(1<<ue)-1),I=(S-=me)>>3,ee=v.t[ee]+((e[I]|e[I+1]<<8)>>(S&7)&(1<<me)-1),h>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=h-=3;else{var B=h-(L!=0);if(B){if(h=B==3?t.o[0]-1:t.o[B],B>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=h}else h=t.o[0]}for(var T=0;T<L;++T)y[X+T]=y[w+T];X+=L,w+=L;var C=X-h;if(C<0){var R=-C,O=t.e+C;if(R>F)R=F;for(var T=0;T<R;++T)y[X+T]=t.w[O+T];X+=R,F-=R,C=0}for(var T=0;T<F;++T)y[X+T]=y[C+T];X+=F}if(X!=w)while(w<y.length)y[X++]=y[w++];else X=y.length;if(n)t.y+=X;else y=je(y,0,X)}else if(n){if(t.y+=p,w)for(var T=0;T<p;++T)y[T]=y[w+T]}else if(w)y=je(y,w);return t.b=u,y}Z(2)},an=function(e,t){if(e.length==1)return e[0];var n=new K(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 Ee(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=Jt(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=on(e,i,t);if(!c)Z(5);if(t)i.e=i.y;else n.push(c),o+=c.length,Kt(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 ln(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(Ee(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 ln(e))}var ht=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split("/").pop()||"main.ldr").replace(/\\.(zst|gz)$/i,"")||"main.ldr";function Pe(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 Y=(e)=>e.trim().toLowerCase().replace(/\\\\/g,"/").replace(/\\/+/g,"/"),He=/^[A-Za-z][A-Za-z0-9_]*$/,Ge=new Map;function We(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(!Ge.has(r))Ge.set(r,t);return r}function Xe(e){let t=e.charCodeAt(0)|32;if(t>=97&&t<=122&&He.test(e))return We(e);if(/^0x/i.test(e))return parseInt(e,16);return+e}var gt=/^~?\\s*moved\\s+to\\s+(.+)$/i,cn=new Set(["FILE","NOFILE","!DATA","!:","STEP","BFC","ROTSTEP","BUFEXCHG","!TEXMAP"]),un=new Set(["FILE","NOFILE","!DATA"]),vt=1000000000000000,Ct=new Set(["part","subpart","primitive","8_primitive","48_primitive","shortcut","helper"]),fn=new Set(["model","submodel","configuration"]),pn=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function bt(e){let t=pn.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,"");return Ct.has(n)||fn.has(n)?n:void 0}function mn(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 hn(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 u=mn(c);if(!u.length)return null;let f={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:u[0]};if(s>=10)f.a=i[9];if(s===11)f.b=i[10];let l=u.findIndex((a,p)=>p>0&&a.toUpperCase()==="GLOSSMAP");if(l>0&&u[l+1])f.glossmap=u[l+1];if(t)f.next=!0;return f}var gn=(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 bn(e){let t=e.length,n=1,r=(l)=>l===32||l===9,s=()=>{while(n<t&&r(e.charCodeAt(n)))n++;let l=n;while(n<t&&!r(e.charCodeAt(n)))n++;return l<n?e.slice(l,n):null},o=s();if(o===null)return null;let i=Array(12);for(let l=0;l<12;l++){let a=s();if(a===null)return null;let p=+a;if(!Number.isFinite(p))return null;i[l]=p}while(n<t&&r(e.charCodeAt(n)))n++;if(n>=t)return null;let c=e.slice(n),u=/[ \\t]{2,}|\\t/.test(c)?c.split(/\\s+/).join(" "):c,f=Xe(o);if(!Number.isFinite(f))return null;return{t:1,color:f,m:i,file:Y(u)}}var dn=[0,12,6,9,12,12];function dt(e){let t=+e[0];if(!(t>=1&&t<=5&&Number.isInteger(t))||e.length<2)return null;let n=Xe(e[1]),r=dn[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=Y(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 Tt(e,t="main.ldr",n={}){let r=!!n.geometryText,s=new Map,o=null,i="",c,u=null,f=[],l=null,a=()=>{if(!u)return;let m=gn(u.chunks.join("")),d=m[0]===137&&m[1]===80&&m[2]===78&&m[3]===71;(c??=new Map).set(Y(u.name),{name:u.name,bytes:m,...d?{mime:"image/png"}:{}}),u=null},p=!0,g=(m)=>{if(a(),o={name:Y(m),cmds:[]},s.set(o.name,o),!i)i=o.name;f=[],l=null,p=!0},b=!1,y=!1,w=()=>{if(y)return;y=!0,s.clear(),o=null,i=""},x=(m,d)=>{if(l){m.tex=l,l=null;return}let M=f[f.length-1];if(!M)return;if(M.fallback){if(!d)m.fallback=!0}else m.tex=M.map};for(let m of e.split(`\n`)){let d=m.trim();if(!d)continue;if(r&&d.charCodeAt(0)>=50&&d.charCodeAt(0)<=53&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)){if(u||b)continue;if(!o)g(t);let k=d.slice(2).trimStart(),D=k.search(/\\s/),P={t:d.charCodeAt(0)-48,color:Xe(D<0?k:k.slice(0,D)),p:[],src:d};x(P,!1),o.cmds.push(P),p=!1;continue}if(d.charCodeAt(0)===48&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)){let k=2;while(d.charCodeAt(k)===32||d.charCodeAt(k)===9)k++;let D=k;while(D<d.length&&d.charCodeAt(D)!==32&&d.charCodeAt(D)!==9)D++;let P=d.slice(k,D),A=/[^\\x21-\\x7e]/.test(P)?d.slice(k).trim().split(/\\s+/)[0]:P;if(!cn.has(A)&&!(A.length>=4&&A.length<=6&&un.has(A.toUpperCase()))){if(b||u)continue;if(!o)g(t);let v=d.slice(k),E={t:0,text:v};if(P.charCodeAt(0)===33)E.meta=P;if(l=null,p&&!o.org){let S=bt(v);if(S)o.org=S}let z=v.match(gt);if(z&&!o.movedTo){let S=z[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(S))S+=".dat";o.movedTo=Y(S)}o.cmds.push(E);continue}}if(d.charCodeAt(0)===49&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)&&!u&&!b){let k=bn(d);if(k){if(!o)g(t);x(k,!1),o.cmds.push(k),p=!1;continue}}let M=d.split(/\\s+/);if(+M[0]===0){let k=d.slice(1).trim(),D=M.length>1&&M[1].length>=4&&M[1].length<=6?M[1].toUpperCase():M[1];if(D==="FILE"){let v=k.slice(5).trimStart().split("\\r")[0].trim();if(v){w(),b=!1,g(v);continue}}if(D==="NOFILE"){a(),o=null,b=!0;continue}if(D==="!DATA"){w(),a(),o=null,b=!1,u={name:k.slice(5).trim(),chunks:[]};continue}if(b)continue;if(u){if(M[1]==="!:")u.chunks.push(M.slice(2).join(""));continue}if(!o)g(t);let P={t:0,text:k};if(M[1]==="STEP")P.step=!0,f=[],l=null;else if(M[1]==="BFC")P.bfc=M.slice(2).join(" ");else if(M[1]==="ROTSTEP")if(P.meta="ROTSTEP",P.step=!0,f=[],l=null,(M[2]??"").toUpperCase()==="END")P.rotstep={x:0,y:0,z:0,mode:"END"};else{let v=(M[5]??"REL").toUpperCase(),E=(z)=>{let S=Number(z);return Number.isFinite(S)?S:0};P.rotstep={x:E(M[2]),y:E(M[3]),z:E(M[4]),mode:["REL","ABS","ADD"].includes(v)?v:"REL"}}else if(M[1]==="BUFEXCHG"){P.meta="BUFEXCHG";let v=(M[2]??"").toUpperCase();P.bufexchg={op:v==="RETRIEVE"?"RETRIEVE":"STORE",buf:M[3]??"A"}}else if(M[1]?.startsWith("!"))P.meta=M[1];if(p&&!o.org){let v=bt(k);if(v)o.org=v}if(M[1]==="!TEXMAP"){let v=(M[2]??"").toUpperCase();if(l=null,v==="START"||v==="NEXT"){let E=hn(k.replace(/^!TEXMAP\\s+\\S+/i,""),v==="NEXT");if(P.texmap={op:v,...E?{map:E}:{}},E)if((o.texmaps??=[]).push(E),v==="START")f.push({map:E,fallback:!1});else l=E}else if(v==="FALLBACK"){P.texmap={op:v};let E=f[f.length-1];if(E)E.fallback=!0}else if(v==="END")P.texmap={op:v},f.pop()}else if(M[1]==="!:"){l=null;let v=dt(M.slice(2));if(v)x(v,!0),P.geom=v}else l=null;let A=k.match(gt);if(A&&!o.movedTo){let v=A[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(v))v+=".dat";o.movedTo=Y(v)}o.cmds.push(P);continue}if(u||b)continue;if(!o)g(t);let T=dt(M);if(!T){if(/^[2-5][ \\t]/.test(d))p=!1;continue}x(T,!1),o.cmds.push(T),p=!1}return a(),c?{main:i,files:s,data:c}:{main:i,files:s}}var Hn=Math.PI/180;function Lt(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 St(e,t){let[n,r,s,o,i,c,u,f,l,a,p,g]=e,[b,y,w,x,m,d,M,U,T,k,D,P]=t;return[o*b+i*y+c*w+n,u*b+f*y+l*w+r,a*b+p*y+g*w+s,o*x+i*M+c*k,o*m+i*U+c*D,o*d+i*T+c*P,u*x+f*M+l*k,u*m+f*U+l*D,u*d+f*T+l*P,a*x+p*M+g*k,a*m+p*U+g*D,a*d+p*T+g*P]}var Ke=[0,0,0,1,0,0,0,1,0,0,0,1];var yt=new WeakMap,yn=/^(s|8|48)\\//;function Ze(e,t){let n=e.files.get(Y(t));if(!n)return"part";let r=yt.get(n);if(r)return r;if(n.org)r=Ct.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&&yn.test(s.file))?"part":"model";return yt.set(n,r),r}var xt=new WeakMap;function kt(e){let t=xt.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 xt.set(e,t),t}var wt=(e)=>e>16777215?"0x"+e.toString(16).toUpperCase():e<0?Ge.get(e)??String(e):String(e),xn=(e)=>e.t===0?"0 "+e.text:e.t===1?`1 ${wt(e.color)} ${e.m.join(" ")} ${e.file}`:e.src?e.src:`${e.t} ${wt(e.color)} ${e.p.join(" ")}`,Ye=(e,t)=>`${Y(e)}#${t}`;function wn(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:Ye(e.name,t),cmds:n}}function Et(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...wn(e,t).cmds.map(xn)].join(`\n`)+`\n`}function Je(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 Pt(e){let[t,n,r,s,o,i,c,u,f,l,a,p]=e,g=u*p-f*a,b=-(c*p-f*l),y=c*a-u*l,w=s*g+o*b+i*y;if(!Number.isFinite(w)||Math.abs(w)<0.000000000001)return null;let x=1/w,m=[g*x,-(o*p-i*a)*x,(o*f-i*u)*x,b*x,(s*p-i*l)*x,-(s*f-i*c)*x,y*x,-(s*a-o*l)*x,(s*u-o*c)*x];return[-(m[0]*t+m[1]*n+m[2]*r),-(m[3]*t+m[4]*n+m[5]*r),-(m[6]*t+m[7]*n+m[8]*r),...m]}var Mn=(e)=>String(+e.toFixed(6)||0),Mt=(e)=>\'"\'+e.replace(/\\\\/g,"\\\\\\\\").replace(/"/g,"\\\\\\"")+\'"\';function Ft(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!=="PLANAR"?[t.a??360]:[],...t.method==="SPHERICAL"?[t.b??180]:[]].map(Mn).join(" "),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${Mt(t.texture)}${t.glossmap?" GLOSSMAP "+Mt(t.glossmap):""}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${Y(e)}\n0 !TEXMAP END\n`;return{name:`${Y(e)}#tex-${Je(r)}`,source:r}}var An=(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 vn(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),u=Math.sin(n*r),f=Math.cos(n*r);return[c*f,-c*u,i,o*u+s*i*f,o*f-s*i*u,-s*c,s*u-o*i*f,s*f+o*i*u,o*c]}var At=new WeakMap;function It(e){let t=At.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=vn(o.x,o.y,o.z);r=o.mode==="ABS"?{abs:!0,m:i,rotstep:o}:o.mode==="ADD"&&r?{abs:r.abs,m:An(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),At.set(e,n),n}class Qe 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 Cn=(e)=>{for(let t=0;t<12;t++)if(!(Math.abs(e[t])<=vt))return!1;return!0},Rt=999999,Nt=(e)=>e.map((t)=>String(t).padStart(6,"0")).join(".")+"~",Ut=new WeakMap,Bt=new WeakMap;function Tn(e,t){let n=Bt.get(t);if(!n)n={head:[...t.values()].map((o)=>{let i=Ut.get(o)??"",c=i.indexOf("!COLOUR");return c<0?"":"0 "+i.slice(c).trim().replace(/\\s+/g," ")}).filter(Boolean).join(`\n`),parts:new Map},Bt.set(t,n);let r=n.parts.get(e);if(!r){let s=Y(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-${Je(o)}`,source:o},n.parts.set(e,r)}return r}function Ln(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,c=new Map,u=0,f=new Set,l=t.maxInstances??2000000,a=0,p=(b,y)=>{let w=b.name+"#"+y,x=c.get(w);if(!x){let m;x=Object.assign(()=>m??=Et(b,y),{file:b,step:y}),c.set(w,x)}return x},g=(b,y,w,x,m,d,M,U,T=null,k=[],D=[],P=void 0,A=null)=>{let v=b.files.get(y);if(!v||M>r||f.has(v))return;if(++a>l)throw new Qe("model",l);f.add(v);let E=A,z=0,S=M>0?++u:0,I=i&&S?[...k,S]:k,X=i&&S?[...D,w]:D,re=i&&!T?new Map:null,ee=-1,ce=0,fe=(V,h,F,L,B,C,R)=>{if(ee!==z)ee=z,ce=0;let O=re?.get(z+"|"+h);if(O)return O.n++,g(V,V===b?h:V.main,F,L,m+"/"+h,[...B,Rt],M+1,C,[...B,Rt],I,X,R,E);let _=[...B,ce++],N=n.length;g(V,V===b?h:V.main,F,L,m+"/"+h,_,M+1,C,T,I,X,R,E),re?.set(z+"|"+h,{n:1,from:N,to:n.length})},ge=It(v),se=s?kt(v):[],ue=0,pe=(V,h,F,L,B,C,R,O,_)=>{if(T)L=T;if(++a>l)throw new Qe("model",l);let N={part:V,color:h,m:F,step:L[0],steps:L,localStep:B,path:m};if(O)N.colour=O;if(S){if(N.sub=S,i)N.subPath=I,N.subMats=X}if(C)N.embedded=!0;if(R){let H=Ft(V,R);N.texPart=H.name,N.texSource=H.source}else if(_){let H=Tn(V,_);N.colPart=H.name,N.colSource=H.source}let j=ge[B];if(j)N.view=j;return n.push(N),N},me=(V)=>{while(ue<se.length&&se[ue]<=V){let h=se[ue++];pe(Ye(v.name,h),x,w,[...d,h],h,!1,null,P,A).source=p(v,h)}};for(let V of v.cmds){if(V.t===0&&V.step){z++;continue}let h=V;if(h.t>=2||h.t===0&&h.geom&&h.geom.t>=2){me(z);continue}if(h.t===0){if(h.meta==="!COLOUR"){let j=kn(h.text);if(j&&j.code!==16&&j.code!==24)Ut.set(j,h.text),(E=new Map(E??[])).set(j.code,j);continue}if(o&&h.geom?.t===1)h=h.geom;else continue}if(h.t!==1)continue;if(o&&h.fallback)continue;let F=St(w,h.m);if(!Cn(F))continue;let L=h.color===16?x:h.color,B=h.color===16?P:E?.get(h.color),C=[...d,z],R=o?h.tex??U:null,O=R?Pt(h.m):null,_=R&&O?Lt(R,O):null;if(b.files.has(h.file)){if(Ze(b,h.file)==="model"){fe(b,h.file,F,L,C,_,B);continue}pe(h.file,L,F,C,z,!0,_,B,E);continue}let N=t.resolveModel?.(h.file);if(N){fe(N,h.file,F,L,C,_,B);continue}pe(h.file,L,F,C,z,!1,_,B,E)}if(me(1/0),f.delete(v),re){for(let V of re.values())if(V.n>1)for(let h=V.from;h<V.to;h++)n[h].mult??=V.n}};if(Ze(e,e.main)==="part"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...Ke],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return g(e,e.main,Ke,16,e.main,[],0,null),n}function Ot(e,t="main.ldr",n){return Ln(Tt(e,t,{geometryText:!0}),n)}var Sn=new Set(["CHROME","PEARLESCENT","RUBBER","MATTE_METALLIC","METAL","MATERIAL"]);function qe(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 Dt(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=qe(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 kn(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,u=0,f={type:"default"},l=1;while(l<n.length){let a=n[l].toUpperCase(),p=n[l+1];if(a==="CODE")s=p!==void 0&&He.test(p)?We(p):p!==void 0&&/^\\d+$/.test(p)?+p:NaN,l+=2;else if(a==="VALUE"){let g=qe(p);if(g)o=g;l+=2}else if(a==="EDGE")i=qe(p)??p,l+=2;else if(a==="ALPHA")c=+p,l+=2;else if(a==="LUMINANCE")u=+p,l+=2;else if(a==="CHROME")f={type:"chrome"},l+=1;else if(a==="PEARLESCENT")f={type:"pearlescent"},l+=1;else if(a==="RUBBER")f={type:"rubber"},l+=1;else if(a==="MATTE_METALLIC")f={type:"matte_metallic"},l+=1;else if(a==="METAL")f={type:"metal"},l+=1;else if(a==="MATERIAL"){let g=(n[l+1]||"").toUpperCase();if(g==="GLITTER"){let{grain:b,next:y}=Dt(n,l+2);f={type:"glitter",material:b},l=y}else if(g==="SPECKLE"){let{grain:b,next:y}=Dt(n,l+2);f={type:"speckle",material:b},l=y}else if(g==="FABRIC"){let b=(n[l+2]||"").toUpperCase(),y=["VELVET","CANVAS","STRING","FUR"].includes(b)?b.toLowerCase():void 0;f={type:"fabric",kind:y},l+=y?3:2}else l=n.length}else if(Sn.has(a))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(u)?u:0,finish:f}}function En(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 et(e){let t=En(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 Pn(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(Y(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(Y(t),r)}let u=i.trim().replace(/\\s+/g," ");if(u)r.push(u)}return n}var Fn=(e)=>{if(!e.startsWith("1 "))return null;let t=e.split(" ");return t.length>=15?Y(t.slice(14).join(" ")):null};function In(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 zt(e,t,n="main.ldr"){let r=Pn(e,n),s=new Map;for(let o of t){let i=Y(o);if(!r.has(i)||s.has(i))continue;let c=new Set([i]),u=[i];while(u.length)for(let l of r.get(u.pop())){let a=Fn(l);if(a&&r.has(a)&&!c.has(a))c.add(a),u.push(a)}let f=[i,...[...c].filter((l)=>l!==i).sort()].map((l)=>"0 FILE "+(l===i?"":l)+`\n`+r.get(l).join(`\n`)).join(`\n`);s.set(i,`emb/${In(f)}.dat`)}return s}var $t=(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,jt=new WeakMap,tt=null,nt="",rt=null;function st(e,t){if(e===tt&&t===nt)return rt;let n=jt.get(e);if(!n)jt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return tt=e,nt=t,rt=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=[],u=[];s.studs.forEach((g,b)=>{c.push(g[0]),u.push(g[1]);for(let y=0;y<12;y++)i[b*12+y]=g[2+y]});let f=null,l=0,a=0;if(s.mask){l=s.mask[0],a=s.mask[1];let g=s.mask[2];f=new Uint8Array(g.length);for(let b=0;b<g.length;b++)f[b]=g.charCodeAt(b)===49?1:0}let p=!!f;if(f){for(let g=0;g<f.length;g++)if(f[g]!==1){p=!1;break}}return n.set(t,r={nStuds:o,studM:i,kind:c,color:u,mask:f,nx:l,nz:a,full:p}),tt=e,nt=t,rt=r,r}var ye=1073741824;class de{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=de.tagOf(e,t,n),s=this.tag,o=this.t,i=this.mask,c=this.slot(e,t,n);for(;;){let u=s[c];if(u===0)return-1;if(u===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=de.tagOf(e,t,n),o=this.tag,i=this.t,c=this.mask,u=this.slot(e,t,n);for(;;){let f=o[u],l=u<<2;if(f===0)return o[u]=s,i[l]=e,i[l+1]=t,i[l+2]=n,i[l+3]=r,this.size++,-1;if(f===s&&i[l]===e&&i[l+1]===t&&i[l+2]===n){let a=i[l+3];return i[l+3]=r,a}u=u+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 Vt{grp=new de(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=[],u=[];for(let a=0;a<r;a++){let p=e[a],g=t[a],b=n[a],y=(p%20+20)%20,w=(b%20+20)%20,x=this.group(g,y,w);if(x<0)x=s.length,this.grp.put(g,y,w,x),this.lg=x,s.push(0),o.push(p),i.push(p),c.push(b),u.push(b);if(s[x]++,p<o[x])o[x]=p;else if(p>i[x])i[x]=p;if(b<c[x])c[x]=b;else if(b>u[x])u[x]=b}let f=0,l=0;for(let a=0;a<s.length;a++){let p=(i[a]-o[a])/20+1,g=(u[a]-c[a])/20+1,b=p*g;if(this.gX0.push(o[a]),this.gZ0.push(c[a]),this.gNx.push(p),this.gNz.push(g),b<=64*s[a]+1024&&f+b<2147483648)this.gBits.push(f),f+=b;else this.gBits.push(-1),l+=s[a]}this.bits=new Uint8Array(Math.ceil(f/8)),this.rest=new de(l);for(let a=0;a<r;a++){let p=e[a],g=t[a],b=n[a],y=this.group(g,(p%20+20)%20,(b%20+20)%20),w=this.gBits[y];if(w<0){this.rest.put(p,g,b,1);continue}let x=w+(p-this.gX0[y])/20*this.gNz[y]+(b-this.gZ0[y])/20;this.bits[x>>>3]|=1<<(x&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 Rn=(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),xe=(e,t,n)=>e>-ye&&e<ye&&t>-ye&&t<ye&&n>-ye&&n<ye,ve=2147483647;function Bn(e,t){let n=e.colorTable?.[t];if(n)return(n.alpha??255)<255;return t.charCodeAt(0)===35&&/\\/[^:/]*:a\\d/.test(t)}function Dn(e,t,n){let s=new Map,o=(h)=>{let F=s.get(h);if(F===void 0)s.set(h,F=Bn(t,h));return F},i=[],c=[],u=[],f=[],l=[],a=[],p=[],g=[],b=[],y=[],w=[],x=[],m=new de(e.length*2),d=[],M=[];for(let h=0;h<e.length;h++){let F=e[h],L=F.m,B=t.parts[F.part];if(!B||!B.mask||!$t(L)||o(F.color))continue;let C=B.bbox,R=1/0,O=-1/0,_=1/0,N=-1/0;for(let G=0;G<2;G++)for(let W=0;W<2;W++){let J=G?C[3]:C[0],he=W?C[5]:C[2],le=L[0]+L[3]*J+L[5]*he,ne=L[2]+L[9]*J+L[11]*he;if(le<R)R=le;if(le>O)O=le;if(ne<_)_=ne;if(ne>N)N=ne}let j=Math.round((L[1]+C[4])*2),H=st(t,F.part),Q=Math.floor(R/40),ie=Math.floor(O/40),oe=Math.floor(_/40),ae=Math.floor(N/40);if(!((ie-Q+1)*(ae-oe+1)<=65536)||!xe(j,Q,oe)||!xe(j,ie,ae))continue;let q=-1;for(let G=m.get(j,Q,oe),W=0;G>=0&&W<8;G=d[G],W++){let J=M[G];if(i[J]!==R||c[J]!==O||u[J]!==_||f[J]!==N||p[J]!==H)continue;let he=e[l[J]].m,le=!0;for(let ne=0;ne<12;ne++)if(he[ne]!==L[ne]){le=!1;break}if(le){q=J;break}}if(q>=0){let G=n?n[h]:0;if(n&&G<n[l[q]])a[q]=l[q],l[q]=h;else if(a[q]<0||n&&G<n[a[q]])a[q]=h;continue}let te=l.length;i.push(R),c.push(O),u.push(_),f.push(N),l.push(h),a.push(-1),p.push(H),g.push(C[0]),b.push(C[2]),y.push(j),w.push(L[0],L[1],L[2],L[3],L[6],L[9],L[5],L[8],L[11]),x.push(H.full&&C[3]-C[0]<=20*H.nx&&C[5]-C[2]<=20*H.nz&&L[4]===0&&L[6]===0&&L[8]===0&&L[10]===0&&Rn(L[3],L[5],L[9],L[11])?1:0);for(let G=Q;G<=ie;G++)for(let W=oe;W<=ae;W++){if(!xe(j,G,W))continue;let J=M.length;M.push(te),d.push(m.put(j,G,W,J))}}let U=[0,5,-5,5,-5],T=[0,5,5,-5,-5],k=(h,F,L,B)=>{if(!(F-6>=i[h]-0.5&&F+6<=c[h]+0.5&&B-6>=u[h]-0.5&&B+6<=f[h]+0.5))return!1;if(x[h]===1)return!0;let C=h*9,R=p[h],O=g[h],_=b[h],N=F-w[C],j=L-w[C+1],H=B-w[C+2],Q=w[C+3]*N+w[C+4]*j+w[C+5]*H,ie=w[C+6]*N+w[C+7]*j+w[C+8]*H,{nx:oe,nz:ae,mask:q}=R;for(let te=0;te<5;te++){let G=Math.floor((Q+U[te]-O)/20),W=Math.floor((ie+T[te]-_)/20);if(G<0||W<0||G>=oe||W>=ae||q[G*ae+W]!==1)return!1}return!0},D=NaN,P=NaN,A=NaN,v=-1,E=-1,z=(h,F,L,B)=>{let C=Math.round(F*2),R=Math.floor(h/40),O=Math.floor(L/40);if(!xe(C,R,O))return ve;let _=ve;if(!n&&E>=0&&y[E]===C&&(l[E]!==B||a[E]>=0)&&k(E,h,F,L))return 0;if(C!==D||R!==P||O!==A)D=C,P=R,A=O,v=m.get(C,R,O);for(let N=v;N>=0;N=d[N]){let j=M[N],H=l[j];if(H===B&&(H=a[j])<0)continue;if(!k(j,h,F,L))continue;if(!n)return E=j,0;let Q=n[H];if(Q<_)_=Q}return _},S=0;for(let h of e){let F=st(t,h.part);if(F)S+=F.nStuds}let I=new Uint8Array(S),X=new Uint8Array(S),re=0,ee=n?new de(S,4):null,ce=n?null:new Int32Array(S),fe=n?null:new Int32Array(S),ge=n?null:new Int32Array(S),se=0,ue=n?new Int32Array(S).fill(ve):void 0;for(let h=0,F=0;h<e.length;h++){let L=e[h],B=st(t,L.part);if(!B)continue;let C=L.m,R=B.studM,O=C[0],_=C[1],N=C[2],j=C[3],H=C[4],Q=C[5],ie=C[6],oe=C[7],ae=C[8],q=C[9],te=C[10],G=C[11];for(let W=0;W<B.nStuds;W++,F++){let J=W*12,he=R[J+4],le=R[J+7],ne=R[J+10];if(!(Math.abs(ie*he+oe*le+ae*ne-1)<0.001&&Math.abs(j*he+H*le+Q*ne)<0.001&&Math.abs(q*he+te*le+G*ne)<0.001))continue;X[F]=1;let Oe=R[J],ze=R[J+1],$e=R[J+2],ot=O+j*Oe+H*ze+Q*$e,it=_+ie*Oe+oe*ze+ae*$e,at=N+q*Oe+te*ze+G*$e,lt=z(ot,it,at,h);if(lt!==ve){if(I[F]=1,re++,ue)ue[F]=lt}let Ce=Math.round(ot),Te=Math.round(it),Le=Math.round(at);if(!xe(Ce,Te,Le))continue;if(!ee){ce[se]=Ce,fe[se]=Te,ge[se++]=Le;continue}let ct=n[h],ut=ee.get(Ce,Te,Le);if(ut<0||ct<ut)ee.put(Ce,Te,Le,ct)}}let pe=ee?null:new Vt(ce,fe,ge,se),me=new Uint8Array(e.length),V=n?new Int32Array(e.length).fill(ve):void 0;for(let h=0;h<e.length;h++){let F=e[h],L=t.parts[F.part];if(!L||!L.under||!$t(F.m)||o(F.color))continue;let B=L.bbox,C=Math.round((B[3]-B[0])/20),R=Math.round((B[5]-B[2])/20);if(!C||!R||C*R>4096)continue;let O=F.m,_=Math.round(O[1]+B[4]),N=!0,j=0;for(let H=0;H<C&&N;H++)for(let Q=0;Q<R;Q++){let ie=B[0]+10+20*H,oe=B[2]+10+20*Q,ae=O[0]+O[3]*ie+O[5]*oe,q=O[2]+O[9]*ie+O[11]*oe,te=Math.round(ae),G=Math.round(q),W=!xe(te,_,G)?-1:ee?ee.get(te,_,G):pe.has(te,_,G)?1:-1;if(W<0){N=!1;break}if(W>j)j=W}if(N){if(me[h]=1,V)V[h]=j}}return{nStuds:S,studHidden:I,studUp:X,underHidden:me,studsHidden:re,studHideStep:ue,underHideStep:V}}function Nn(e,t,n){let r=(a)=>a.colPart&&t.parts[a.colPart]?a.colPart:n&&a.texPart&&t.parts[a.texPart]?a.texPart:a.part,s=new Map,o=new Map,i=(a)=>{let p=a.colour;if(!p)return String(a.color);let g=o.get(p);if(g!==void 0)return g;let b=t.colorTable?.[a.color],y=b?.hex??t.colors?.[a.color],w=b?et({alpha:b.alpha??255,luminance:b.luminance??0,finish:b.finish??{type:"default"}}):"default:op",x=et(p);if(g=y&&y.toUpperCase()===p.hex.toUpperCase()&&w===x?String(a.color):p.hex.toUpperCase()+"/"+x,g!==String(a.color))s.set(g,p);return o.set(p,g),g},c=e.map((a)=>({part:r(a),color:i(a),m:a.m,steps:a.steps})),u=c.map((a)=>Nt(a.steps)),f=[...new Set(u)].sort(),l=new Map(f.map((a,p)=>[a,p]));return{all:c,stepOf:u.map((a)=>l.get(a)),nSteps:f.length,localColours:s}}function Fe(e,t,n=!0){let r=Nn(e,t,n);return Dn(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Ne="https://ldr-demo.vercel.app/cdn/v1/",Re=new Map,Ie=new Map;function Be(e=Ne,t=fetch){let n=Re.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(()=>Re.delete(e)),Re.set(e,n);return n}var Un=(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"),De=(e,t)=>Un(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>De(n,t)):e&&typeof e==="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,De(r,t)])):e;function On(e,t={}){let n=[],r=0,s={},o={};for(let p of e){let g=p.buffer;if(!g)throw Error("ldr: mergePacks needs packs from decodePack/loadPack");let b=new DataView(g).getUint32(0,!0),y=new Uint8Array(g,4+b),w=r;n.push(y),r+=y.byteLength;let x=(4-r%4)%4;if(x)n.push(new Uint8Array(x)),r+=x;for(let[m,d]of Object.entries(p.header.parts??{}))if(!(m in s))s[m]=De(d,w);for(let[m,d]of Object.entries(p.header.studKinds??{}))if(!(m in o))o[m]=De(d,w)}let i=e[0]?.header??{version:1,weld:!0},c=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),u=(4-(4+c.length)%4)%4,f=4+c.length+u,l=new Uint8Array(f+r);new DataView(l.buffer).setUint32(0,c.length+u,!0),l.set(c,4),l.fill(32,4+c.length,f);let a=f;for(let p of n)l.set(p,a),a+=p.byteLength;return Pe(l.buffer)}async function zn(e,t={}){e=[...e];try{return await _t(e,t)}catch(n){let r=t.cdn??Ne,s=t.fetch??fetch;Re.delete(r);let o=(i,c)=>s(i,{...c,cache:"reload"});try{return await _t(e,{...t,fetch:o})}catch{throw n}}}async function _t(e,t){let n=t.cdn??Ne,r=t.fetch??fetch,s=t.gap??16384,o=await Be(n,r),i=[...new Set([...e].map(Y))],c=[],u=[];for(let m of i){if(Ie.has(n+m))continue;let d=o.parts[m];if(d)u.push({name:m,off:d[0],len:d[1],file:d[2]??0});else c.push(m)}u.sort((m,d)=>m.file-d.file||m.off-d.off);let f=[];for(let m of u){let d=f[f.length-1];if(d&&d.file===m.file&&m.off-d.end<=s)d.end=Math.max(d.end,m.off+m.len),d.items.push(m);else f.push({file:m.file,start:m.off,end:m.off+m.len,items:[m]})}let l=0,a=0,p=0,g=new Map,b=async()=>{while(p<f.length){let m=f[p++],d=g.get(m.file);if(d)d=d.subarray(m.start,m.end);else{let M=await r(new URL(o.archives[m.file],n).href,{headers:{Range:`bytes=${m.start}-${m.end-1}`,"Accept-Encoding":"identity"}});if(!M.ok)throw Error(`ldr: parts CDN ${M.status}`);if(a++,d=new Uint8Array(await M.arrayBuffer()),l+=d.byteLength,M.status===200)g.set(m.file,d),d=d.subarray(m.start,m.end)}for(let M of m.items){let U=Ee(d.subarray(M.off-m.start,M.off-m.start+M.len)),T=U.buffer.slice(U.byteOffset,U.byteOffset+U.byteLength);Ie.set(n+M.name,Pe(T))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,f.length)},b));let y=i.filter((m)=>Ie.has(n+m)).map((m)=>Ie.get(n+m)),w={colors:o.colors,...o.colorTable?{colorTable:o.colorTable}:{}};return{pack:y.length?On(y,w):Pe($n(w)),missing:c,requests:a,bytes:l}}function $n(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 jn(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 Gt(e,t,n){let r=0,s=0,o=!1,i=new Set;for(let c of e){let u=c.embedded?t.get(c.part):Y(c.part),f=u?n.parts[u]:void 0;if(!f)continue;if(f[3]!=null)o=!0,r+=f[3];if(!i.has(u))i.add(u),s+=f[1]}return{bodyTris:r,packBytes:s,known:o}}class Ue 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 Ht(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=Be(t.cdn??Ne,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(A)=>{if(!A.ok)throw Error(`ldr: ${A.status} fetching ${e}`);return mt(await A.arrayBuffer())}),i=performance.now(),c=t.name??(t.text?"main.ldr":ht(e)),u=Ot(o,c,{looseGeometry:!1,callouts:t.callouts}),f=performance.now();t.onParsed?.(u),await s;let l=zt(o,new Set(u.filter((A)=>A.embedded).map((A)=>A.part)),c),a=(A,v)=>t.maxBodyTris!=null&&A>t.maxBodyTris||t.maxPackBytes!=null&&v>t.maxPackBytes,p=t.maxBodyTris!=null||t.maxPackBytes!=null,g=(A)=>new Ue({...A,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes}),b="full";if(p){let A=Gt(u,l,await s);if(a(A.known?A.bodyTris:0,A.packBytes)){if(!t.lowCdn)throw g(A);let v=await Be(t.lowCdn,r).catch(()=>null);if(!v)throw g(A);let E=Gt(u,l,v);if(a(E.known?E.bodyTris:0,E.packBytes))throw g(E);b="low"}}let y=[...u.filter((A)=>!A.embedded).map((A)=>A.part),...l.values()],w=async()=>{let A=await zn(y,b==="low"?{...t,cdn:t.lowCdn}:t);for(let[v,E]of l){let z=A.pack.header.parts[E];if(z)A.pack.header.parts[v]=z}return{...A,packBytes:A.pack.buffer?.byteLength??A.pack.bytes??0,bodyTris:jn(u,A.pack)}},x=await w();if(p&&a(x.bodyTris,x.packBytes)&&b==="full"&&t.lowCdn&&await Be(t.lowCdn,r).then(()=>!0,()=>!1)){b="low";let A=x;x=await w(),x.requests+=A.requests,x.bytes+=A.bytes}if(p&&a(x.bodyTris,x.packBytes))throw g(x);let{pack:m,missing:d,requests:M,bytes:U}=x,T=new Map([...l].map(([A,v])=>[v,A])),k=d.map((A)=>T.get(A)??A),D=performance.now(),P=t.cull?Fe(u,m.header,t.textures!==!1):void 0;return{insts:u,pack:m,tier:b,missing:k,requests:M,bytes:U,cull:P,timings:{fetchModel:i-n,parse:f-i,parts:D-f,...P?{cull:performance.now()-D}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await Ht(n,{...r,cull:!1,onParsed:(l)=>self.postMessage({id:t,insts:l})}),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=Fe(s.insts,s.pack.header,r.textures!==!1),u=performance.now()-i,f=[];for(let l of[c.studHidden,c.studUp,c.underHidden,c.studHideStep,c.underHideStep])if(l)f.push(l.buffer);self.postMessage({id:t,cull:c,ms:u},f)}catch(s){if(s instanceof Ue||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';
|
|
5336
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/load-worker.gen.ts
|
|
5337
|
+
var load_worker_gen_default = 'var en=ArrayBuffer,W=Uint8Array,ze=Uint16Array,tn=Int16Array;var $e=Int32Array,Ye=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},Re=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},nn=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 rn=["invalid zstd data","window size too large (>2046MB)","invalid block type","FSE accuracy too high","match distance too far back","unexpected EOF"],Z=function(e,t,n){var r=Error(t||rn[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,Z);if(!n)throw r;return r},dt=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},sn=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},on=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,u=r>>6;if(r&8)Z(0);var l=6-s,f=i==3?4:i,c=dt(e,l,f);l+=f;var a=u?1<<u:s,p=dt(e,l,a)+(u==1&&256),g=p;if(!s){var h=1<<10+(e[5]>>3);g=h+(h>>3)*(e[5]&7)}if(g>2145386496)Z(1);var b=new W((t==1?p||g:t?0:g)+12);return b[0]=1,b[4]=4,b[8]=8,{b:l+a,y:0,l:0,d:c,w:t&&t!=1?t:b.subarray(12),e:g,o:new $e(b.buffer,0,3),u:p,c:o,m:Math.min(131072,g)}}else if((n>>4|e[3]<<20)==25481893)return sn(e,4)+8;Z(0)},Se=function(e){var t=0;for(;1<<t<=e;++t);return t-1},Be=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)Z(3);var o=1<<s,i=o,u=-1,l=-1,f=-1,c=o,a=new en(512+(o<<2)),p=new tn(a,0,256),g=new ze(a,0,256),h=new ze(a,512,o),b=512+(o<<1),v=new W(a,b,o),x=new W(a,b+o);while(u<255&&i>0){var m=Se(i+1),d=r>>3,y=(1<<m+1)-1,D=(e[d]|e[d+1]<<8|e[d+2]<<16)>>(r&7)&y,C=(1<<m)-1,E=y-i-1,B=D&C;if(B<E)r+=m,D=B;else if(r+=m+1,D>C)D-=E;if(p[++u]=--D,D==-1)i+=D,v[--c]=u;else i-=D;if(!D)do{var k=r>>3;l=(e[k]|e[k+1]<<8)>>(r&7)&3,r+=2,u+=l}while(l==3)}if(u>255||i)Z(0);var w=0,M=(o>>1)+(o>>3)+3,F=o-1;for(var N=0;N<=u;++N){var P=p[N];if(P<1){g[N]=-P;continue}for(f=0;f<P;++f){v[w]=N;do w=w+M&F;while(w>=c)}}if(w)Z(0);for(f=0;f<o;++f){var I=g[v[f]]++,V=x[f]=s-Se(I);h[f]=(I<<V)-o}return[r+7>>3,{b:s,s:v,n:x,t:h}]},an=function(e,t){var n=0,r=-1,s=new W(292),o=e[t],i=s.subarray(0,256),u=s.subarray(256,268),l=new ze(s.buffer,268);if(o<128){var f=Be(e,t+1,6),c=f[0],a=f[1];t+=o;var p=c<<3,g=e[t];if(!g)Z(0);var h=0,b=0,v=a.b,x=v,m=(++t<<3)-8+Se(g);for(;;){if(m-=v,m<p)break;var d=m>>3;if(h+=(e[d]|e[d+1]<<8)>>(m&7)&(1<<v)-1,i[++r]=a.s[h],m-=x,m<p)break;d=m>>3,b+=(e[d]|e[d+1]<<8)>>(m&7)&(1<<x)-1,i[++r]=a.s[b],v=a.n[h],h=a.t[h],x=a.n[b],b=a.t[b]}if(++r>255)Z(0)}else{r=o-127;for(;n<r;n+=2){var y=e[++t];i[n]=y>>4,i[n+1]=y&15}++t}var D=0;for(n=0;n<r;++n){var C=i[n];if(C>11)Z(0);D+=C&&1<<C-1}var E=Se(D)+1,B=1<<E,k=B-D;if(k&k-1)Z(0);i[r++]=Se(k)+1;for(n=0;n<r;++n){var C=i[n];++u[i[n]=C&&E+1-C]}var w=new W(B<<1),M=w.subarray(0,B),F=w.subarray(B);l[E]=0;for(n=E;n>0;--n){var N=l[n];Re(F,n,N,l[n-1]=N+u[n]*(1<<E-n))}if(l[0]!=B)Z(0);for(n=0;n<r;++n){var P=i[n];if(P){var I=l[P];Re(M,n,I,l[P]=I+(1<<E-P))}}return[t,{n:F,b:E,s:M}]},ln=Be(new W([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],cn=Be(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],un=Be(new W([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],yt=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},Je=new W(new $e([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),fn=yt(Je,0),Qe=new W(new $e([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),pn=yt(Qe,3),Ie=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,u=-n.b;if(!o)Z(0);var l=0,f=n.b,c=(r<<3)-8+Se(o)-f,a=-1;for(;c>u&&a<s;){var p=c>>3,g=(e[p]|e[p+1]<<8|e[p+2]<<16)>>(c&7);l=(l<<f|g)&i,t[++a]=n.s[l],c-=f=n.n[l]}if(c!=u||a+1!=s)Z(0)},mn=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,u=o+i;Ie(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),Ie(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),Ie(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,u),n),Ie(e.subarray(r),t.subarray(u),n)},hn=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var u=o>>3|e[s+1]<<5|e[s+2]<<13,l=(s+=3)+u;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return Re(n,e[s],t.y,t.y+=u),n;return Re(new W(u),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+=u,n;return Ye(e,s,l)}if(i==2){var f=e[s],c=f&3,a=f>>2&3,p=f>>4,g=0,h=0;if(c<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,g=e[s]>>6|e[++s]<<2;else if(a==2)p|=e[++s]<<4|(e[++s]&3)<<12,g=e[s]>>2|e[++s]<<6;else p|=e[++s]<<4|(e[++s]&63)<<12,g=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var b=n?n.subarray(t.y,t.y+t.m):new W(t.m),v=b.length-p;if(c==0)b.set(e.subarray(s,s+=p),v);else if(c==1)Re(b,e[s++],v);else{var x=t.h;if(c==2){var m=an(e,s);g+=s-(s=m[0]),t.h=x=m[1]}else if(!x)Z(0);(h?mn:Ie)(e.subarray(s,s+=g),b.subarray(v),x)}var d=e[s++];if(d){if(d==255)d=(e[s++]|e[s++]<<8)+32512;else if(d>127)d=d-128<<8|e[s++];var y=e[s++];if(y&3)Z(0);var D=[cn,un,ln];for(var C=2;C>-1;--C){var E=y>>(C<<1)+2&3;if(E==1){var B=new W([0,0,e[s++]]);D[C]={s:B.subarray(2,3),n:B.subarray(0,1),t:new ze(B.buffer,0,1),b:0}}else if(E==2)r=Be(e,s,9-(C&1)),s=r[0],D[C]=r[1];else if(E==3){if(!t.t)Z(0);D[C]=t.t[C]}}var k=t.t=D,w=k[0],M=k[1],F=k[2],N=e[l-1];if(!N)Z(0);var P=(l<<3)-8+Se(N)-F.b,I=P>>3,V=0,he=(e[I]|e[I+1]<<8)>>(P&7)&(1<<F.b)-1;I=(P-=M.b)>>3;var ce=(e[I]|e[I+1]<<8)>>(P&7)&(1<<M.b)-1;I=(P-=w.b)>>3;var Ae=(e[I]|e[I+1]<<8)>>(P&7)&(1<<w.b)-1;for(++d;--d;){var re=F.s[he],Te=F.n[he],de=w.s[Ae],ve=w.n[Ae],fe=M.s[ce],Le=M.n[ce];I=(P-=fe)>>3;var O=1<<fe,L=O+((e[I]|e[I+1]<<8|e[I+2]<<16|e[I+3]<<24)>>>(P&7)&O-1);I=(P-=Qe[de])>>3;var _=pn[de]+((e[I]|e[I+1]<<8|e[I+2]<<16)>>(P&7)&(1<<Qe[de])-1);I=(P-=Je[re])>>3;var X=fn[re]+((e[I]|e[I+1]<<8|e[I+2]<<16)>>(P&7)&(1<<Je[re])-1);if(I=(P-=Te)>>3,he=F.t[he]+((e[I]|e[I+1]<<8)>>(P&7)&(1<<Te)-1),I=(P-=ve)>>3,Ae=w.t[Ae]+((e[I]|e[I+1]<<8)>>(P&7)&(1<<ve)-1),I=(P-=Le)>>3,ce=M.t[ce]+((e[I]|e[I+1]<<8)>>(P&7)&(1<<Le)-1),L>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=L-=3;else{var q=L-(X!=0);if(q){if(L=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]=L}else L=t.o[0]}for(var C=0;C<X;++C)b[V+C]=b[v+C];V+=X,v+=X;var ee=V-L;if(ee<0){var J=-ee,T=t.e+ee;if(J>_)J=_;for(var C=0;C<J;++C)b[V+C]=t.w[T+C];V+=J,_-=J,ee=0}for(var C=0;C<_;++C)b[V+C]=b[ee+C];V+=_}if(V!=v)while(v<b.length)b[V++]=b[v++];else V=b.length;if(n)t.y+=V;else b=Ye(b,0,V)}else if(n){if(t.y+=p,v)for(var C=0;C<p;++C)b[C]=b[v+C]}else if(v)b=Ye(b,v);return t.b=l,b}Z(2)},gn=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 je(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=on(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 u=hn(e,i,t);if(!u)Z(5);if(t)i.e=i.y;else n.push(u),o+=u.length,nn(i.w,0,u.length),i.w.set(u,i.w.length-u.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return gn(n,o)}async function bn(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(je(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 xt(e){return new TextDecoder().decode(await bn(e))}var wt=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split("/").pop()||"main.ldr").replace(/\\.(zst|gz)$/i,"")||"main.ldr";function Ve(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 Y=(e)=>e.trim().toLowerCase().replace(/\\\\/g,"/").replace(/\\/+/g,"/"),et=/^[A-Za-z][A-Za-z0-9_]*$/,qe=new Map;function tt(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(!qe.has(r))qe.set(r,t);return r}function nt(e){let t=e.charCodeAt(0)|32;if(t>=97&&t<=122&&et.test(e))return tt(e);if(/^0x/i.test(e))return parseInt(e,16);return+e}var Mt=/^~?\\s*moved\\s+to\\s+(.+)$/i,dn=new Set(["FILE","NOFILE","!DATA","!:","STEP","BFC","ROTSTEP","BUFEXCHG","!TEXMAP"]),yn=new Set(["FILE","NOFILE","!DATA"]),kt=1000000000000000,Pt=new Set(["part","subpart","primitive","8_primitive","48_primitive","shortcut","helper"]),xn=new Set(["model","submodel","configuration"]),wn=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function At(e){let t=wn.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,"");return Pt.has(n)||xn.has(n)?n:void 0}function Mn(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 An(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 u=n[2].trim();for(let a=0;a<s;a++)u=u.replace(/^\\S+\\s*/,"");let l=Mn(u);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 c=l.findIndex((a,p)=>p>0&&a.toUpperCase()==="GLOSSMAP");if(c>0&&l[c+1])f.glossmap=l[c+1];if(t)f.next=!0;return f}var vn=(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 Cn(e){let t=e.length,n=1,r=(c)=>c===32||c===9,s=()=>{while(n<t&&r(e.charCodeAt(n)))n++;let c=n;while(n<t&&!r(e.charCodeAt(n)))n++;return c<n?e.slice(c,n):null},o=s();if(o===null)return null;let i=Array(12);for(let c=0;c<12;c++){let a=s();if(a===null)return null;let p=+a;if(!Number.isFinite(p))return null;i[c]=p}while(n<t&&r(e.charCodeAt(n)))n++;if(n>=t)return null;let u=e.slice(n),l=/[ \\t]{2,}|\\t/.test(u)?u.split(/\\s+/).join(" "):u,f=nt(o);if(!Number.isFinite(f))return null;return{t:1,color:f,m:i,file:Y(l)}}var Ln=[0,12,6,9,12,12];function vt(e){let t=+e[0];if(!(t>=1&&t<=5&&Number.isInteger(t))||e.length<2)return null;let n=nt(e[1]),r=Ln[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=Y(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="",u,l=null,f=[],c=null,a=()=>{if(!l)return;let m=vn(l.chunks.join("")),d=m[0]===137&&m[1]===80&&m[2]===78&&m[3]===71;(u??=new Map).set(Y(l.name),{name:l.name,bytes:m,...d?{mime:"image/png"}:{}}),l=null},p=!0,g=(m)=>{if(a(),o={name:Y(m),cmds:[]},s.set(o.name,o),!i)i=o.name;f=[],c=null,p=!0},h=!1,b=!1,v=()=>{if(b)return;b=!0,s.clear(),o=null,i=""},x=(m,d)=>{if(c){m.tex=c,c=null;return}let y=f[f.length-1];if(!y)return;if(y.fallback){if(!d)m.fallback=!0}else m.tex=y.map};for(let m of e.split(`\n`)){let d=m.trim();if(!d)continue;if(r&&d.charCodeAt(0)>=50&&d.charCodeAt(0)<=53&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)){if(l||h)continue;if(!o)g(t);let E=d.slice(2).trimStart(),B=E.search(/\\s/),k={t:d.charCodeAt(0)-48,color:nt(B<0?E:E.slice(0,B)),p:[],src:d};x(k,!1),o.cmds.push(k),p=!1;continue}if(d.charCodeAt(0)===48&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)){let E=2;while(d.charCodeAt(E)===32||d.charCodeAt(E)===9)E++;let B=E;while(B<d.length&&d.charCodeAt(B)!==32&&d.charCodeAt(B)!==9)B++;let k=d.slice(E,B),w=/[^\\x21-\\x7e]/.test(k)?d.slice(E).trim().split(/\\s+/)[0]:k;if(!dn.has(w)&&!(w.length>=4&&w.length<=6&&yn.has(w.toUpperCase()))){if(h||l)continue;if(!o)g(t);let M=d.slice(E),F={t:0,text:M};if(k.charCodeAt(0)===33)F.meta=k;if(c=null,p&&!o.org){let P=At(M);if(P)o.org=P}let N=M.match(Mt);if(N&&!o.movedTo){let P=N[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(P))P+=".dat";o.movedTo=Y(P)}o.cmds.push(F);continue}}if(d.charCodeAt(0)===49&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)&&!l&&!h){let E=Cn(d);if(E){if(!o)g(t);x(E,!1),o.cmds.push(E),p=!1;continue}}let y=d.split(/\\s+/);if(+y[0]===0){let E=d.slice(1).trim(),B=y.length>1&&y[1].length>=4&&y[1].length<=6?y[1].toUpperCase():y[1];if(B==="FILE"){let M=E.slice(5).trimStart().split("\\r")[0].trim();if(M){v(),h=!1,g(M);continue}}if(B==="NOFILE"){a(),o=null,h=!0;continue}if(B==="!DATA"){v(),a(),o=null,h=!1,l={name:E.slice(5).trim(),chunks:[]};continue}if(h)continue;if(l){if(y[1]==="!:")l.chunks.push(y.slice(2).join(""));continue}if(!o)g(t);let k={t:0,text:E};if(y[1]==="STEP")k.step=!0,f=[],c=null;else if(y[1]==="BFC")k.bfc=y.slice(2).join(" ");else if(y[1]==="ROTSTEP")if(k.meta="ROTSTEP",k.step=!0,f=[],c=null,(y[2]??"").toUpperCase()==="END")k.rotstep={x:0,y:0,z:0,mode:"END"};else{let M=(y[5]??"REL").toUpperCase(),F=(N)=>{let P=Number(N);return Number.isFinite(P)?P:0};k.rotstep={x:F(y[2]),y:F(y[3]),z:F(y[4]),mode:["REL","ABS","ADD"].includes(M)?M:"REL"}}else if(y[1]==="BUFEXCHG"){k.meta="BUFEXCHG";let M=(y[2]??"").toUpperCase();k.bufexchg={op:M==="RETRIEVE"?"RETRIEVE":"STORE",buf:y[3]??"A"}}else if(y[1]?.startsWith("!"))k.meta=y[1];if(p&&!o.org){let M=At(E);if(M)o.org=M}if(y[1]==="!TEXMAP"){let M=(y[2]??"").toUpperCase();if(c=null,M==="START"||M==="NEXT"){let F=An(E.replace(/^!TEXMAP\\s+\\S+/i,""),M==="NEXT");if(k.texmap={op:M,...F?{map:F}:{}},F)if((o.texmaps??=[]).push(F),M==="START")f.push({map:F,fallback:!1});else c=F}else if(M==="FALLBACK"){k.texmap={op:M};let F=f[f.length-1];if(F)F.fallback=!0}else if(M==="END")k.texmap={op:M},f.pop()}else if(y[1]==="!:"){c=null;let M=vt(y.slice(2));if(M)x(M,!0),k.geom=M}else c=null;let w=E.match(Mt);if(w&&!o.movedTo){let M=w[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(M))M+=".dat";o.movedTo=Y(M)}o.cmds.push(k);continue}if(l||h)continue;if(!o)g(t);let C=vt(y);if(!C){if(/^[2-5][ \\t]/.test(d))p=!1;continue}x(C,!1),o.cmds.push(C),p=!1}return a(),u?{main:i,files:s,data:u}:{main:i,files:s}}var qn=Math.PI/180;function It(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 Rt(e,t){let[n,r,s,o,i,u,l,f,c,a,p,g]=e,[h,b,v,x,m,d,y,D,C,E,B,k]=t;return[o*h+i*b+u*v+n,l*h+f*b+c*v+r,a*h+p*b+g*v+s,o*x+i*y+u*E,o*m+i*D+u*B,o*d+i*C+u*k,l*x+f*y+c*E,l*m+f*D+c*B,l*d+f*C+c*k,a*x+p*y+g*E,a*m+p*D+g*B,a*d+p*C+g*k]}var rt=[0,0,0,1,0,0,0,1,0,0,0,1];var Ct=new WeakMap,Tn=/^(s|8|48)\\//;function st(e,t){let n=e.files.get(Y(t));if(!n)return"part";let r=Ct.get(n);if(r)return r;if(n.org)r=Pt.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&&Tn.test(s.file))?"part":"model";return Ct.set(n,r),r}var Lt=new WeakMap;function Bt(e){let t=Lt.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 Lt.set(e,t),t}var Tt=(e)=>e>16777215?"0x"+e.toString(16).toUpperCase():e<0?qe.get(e)??String(e):String(e),En=(e)=>e.t===0?"0 "+e.text:e.t===1?`1 ${Tt(e.color)} ${e.m.join(" ")} ${e.file}`:e.src?e.src:`${e.t} ${Tt(e.color)} ${e.p.join(" ")}`,ot=(e,t)=>`${Y(e)}#${t}`;function Sn(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 Dt(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Sn(e,t).cmds.map(En)].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 Ut(e){let[t,n,r,s,o,i,u,l,f,c,a,p]=e,g=l*p-f*a,h=-(u*p-f*c),b=u*a-l*c,v=s*g+o*h+i*b;if(!Number.isFinite(v)||Math.abs(v)<0.000000000001)return null;let x=1/v,m=[g*x,-(o*p-i*a)*x,(o*f-i*l)*x,h*x,(s*p-i*c)*x,-(s*f-i*u)*x,b*x,-(s*a-o*c)*x,(s*l-o*u)*x];return[-(m[0]*t+m[1]*n+m[2]*r),-(m[3]*t+m[4]*n+m[5]*r),-(m[6]*t+m[7]*n+m[8]*r),...m]}var kn=(e)=>String(+e.toFixed(6)||0),Et=(e)=>\'"\'+e.replace(/\\\\/g,"\\\\\\\\").replace(/"/g,"\\\\\\"")+\'"\';function Nt(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!=="PLANAR"?[t.a??360]:[],...t.method==="SPHERICAL"?[t.b??180]:[]].map(kn).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 ${Y(e)}\n0 !TEXMAP END\n`;return{name:`${Y(e)}#tex-${it(r)}`,source:r}}var Pn=(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 Fn(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),u=Math.cos(t*r),l=Math.sin(n*r),f=Math.cos(n*r);return[u*f,-u*l,i,o*l+s*i*f,o*f-s*i*l,-s*u,s*l-o*i*f,s*f+o*i*l,o*u]}var St=new WeakMap;function Ot(e){let t=St.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=Fn(o.x,o.y,o.z);r=o.mode==="ABS"?{abs:!0,m:i,rotstep:o}:o.mode==="ADD"&&r?{abs:r.abs,m:Pn(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),St.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 In=(e)=>{for(let t=0;t<12;t++)if(!(Math.abs(e[t])<=kt))return!1;return!0},zt=999999,Vt=(e)=>e.map((t)=>String(t).padStart(6,"0")).join(".")+"~",_t=new WeakMap,$t=new WeakMap;function Rn(e,t){let n=$t.get(t);if(!n)n={head:[...t.values()].map((o)=>{let i=_t.get(o)??"",u=i.indexOf("!COLOUR");return u<0?"":"0 "+i.slice(u).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=Y(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 Bn(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,u=new Map,l=0,f=new Set,c=t.maxInstances??2000000,a=0,p=(h,b)=>{let v=h.name+"#"+b,x=u.get(v);if(!x){let m;x=Object.assign(()=>m??=Dt(h,b),{file:h,step:b}),u.set(v,x)}return x},g=(h,b,v,x,m,d,y,D,C=null,E=[],B=[],k=void 0,w=null)=>{let M=h.files.get(b);if(!M||y>r||f.has(M))return;if(++a>c)throw new at("model",c);f.add(M);let F=w,N=0,P=y>0?++l:0,I=i&&P?[...E,P]:E,V=i&&P?[...B,v]:B,he=i&&!C?new Map:null,ce=-1,Ae=0,re=(O,L,_,X,q,ee,J)=>{if(ce!==N)ce=N,Ae=0;let T=he?.get(N+"|"+L);if(T)return T.n++,g(O,O===h?L:O.main,_,X,m+"/"+L,[...q,zt],y+1,ee,[...q,zt],I,V,J,F);let R=[...q,Ae++],A=n.length;g(O,O===h?L:O.main,_,X,m+"/"+L,R,y+1,ee,C,I,V,J,F),he?.set(N+"|"+L,{n:1,from:A,to:n.length})},Te=Ot(M),de=s?Bt(M):[],ve=0,fe=(O,L,_,X,q,ee,J,T,R)=>{if(C)X=C;if(++a>c)throw new at("model",c);let A={part:O,color:L,m:_,step:X[0],steps:X,localStep:q,path:m};if(T)A.colour=T;if(P){if(A.sub=P,i)A.subPath=I,A.subMats=V}if(ee)A.embedded=!0;if(J){let S=Nt(O,J);A.texPart=S.name,A.texSource=S.source}else if(R){let S=Rn(O,R);A.colPart=S.name,A.colSource=S.source}let U=Te[q];if(U)A.view=U;return n.push(A),A},Le=(O)=>{while(ve<de.length&&de[ve]<=O){let L=de[ve++];fe(ot(M.name,L),x,v,[...d,L],L,!1,null,k,w).source=p(M,L)}};for(let O of M.cmds){if(O.t===0&&O.step){N++;continue}let L=O;if(L.t>=2||L.t===0&&L.geom&&L.geom.t>=2){Le(N);continue}if(L.t===0){if(L.meta==="!COLOUR"){let U=Un(L.text);if(U&&U.code!==16&&U.code!==24)_t.set(U,L.text),(F=new Map(F??[])).set(U.code,U);continue}if(o&&L.geom?.t===1)L=L.geom;else continue}if(L.t!==1)continue;if(o&&L.fallback)continue;let _=Rt(v,L.m);if(!In(_))continue;let X=L.color===16?x:L.color,q=L.color===16?k:F?.get(L.color),ee=[...d,N],J=o?L.tex??D:null,T=J?Ut(L.m):null,R=J&&T?It(J,T):null;if(h.files.has(L.file)){if(st(h,L.file)==="model"){re(h,L.file,_,X,ee,R,q);continue}fe(L.file,X,_,ee,N,!0,R,q,F);continue}let A=t.resolveModel?.(L.file);if(A){re(A,L.file,_,X,ee,R,q);continue}fe(L.file,X,_,ee,N,!1,R,q,F)}if(Le(1/0),f.delete(M),he){for(let O of he.values())if(O.n>1)for(let L=O.from;L<O.to;L++)n[L].mult??=O.n}};if(st(e,e.main)==="part"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...rt],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return g(e,e.main,rt,16,e.main,[],0,null),n}function Gt(e,t="main.ldr",n){return Bn(Ft(e,t,{geometryText:!0}),n)}var Dn=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 jt(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 Un(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",u=255,l=0,f={type:"default"},c=1;while(c<n.length){let a=n[c].toUpperCase(),p=n[c+1];if(a==="CODE")s=p!==void 0&&et.test(p)?tt(p):p!==void 0&&/^\\d+$/.test(p)?+p:NaN,c+=2;else if(a==="VALUE"){let g=lt(p);if(g)o=g;c+=2}else if(a==="EDGE")i=lt(p)??p,c+=2;else if(a==="ALPHA")u=+p,c+=2;else if(a==="LUMINANCE")l=+p,c+=2;else if(a==="CHROME")f={type:"chrome"},c+=1;else if(a==="PEARLESCENT")f={type:"pearlescent"},c+=1;else if(a==="RUBBER")f={type:"rubber"},c+=1;else if(a==="MATTE_METALLIC")f={type:"matte_metallic"},c+=1;else if(a==="METAL")f={type:"metal"},c+=1;else if(a==="MATERIAL"){let g=(n[c+1]||"").toUpperCase();if(g==="GLITTER"){let{grain:h,next:b}=jt(n,c+2);f={type:"glitter",material:h},c=b}else if(g==="SPECKLE"){let{grain:h,next:b}=jt(n,c+2);f={type:"speckle",material:h},c=b}else if(g==="FABRIC"){let h=(n[c+2]||"").toUpperCase(),b=["VELVET","CANVAS","STRING","FUR"].includes(h)?h.toLowerCase():void 0;f={type:"fabric",kind:b},c+=b?3:2}else c=n.length}else if(Dn.has(a))c+=1;else c+=1}if(Number.isNaN(s)||!o)return null;return{code:s,name:r,hex:o,edge:i,alpha:Number.isFinite(u)?u:255,luminance:Number.isFinite(l)?l:0,finish:f}}function Nn(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,u=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:u,finish:"glitter"}}case"speckle":{let i=e.finish.material,u=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:u,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=Nn(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 On(e,t){let n=new Map,r=null,s=!1,o=!1;for(let i of e.split(/\\r?\\n/)){let u=/^\\s*0\\s+FILE\\s+(\\S[^\\r]*)/i.exec(i);if(u){if(!s)n.clear();s=!0,o=!1,r=[],n.set(Y(u[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(Y(t),r)}let l=i.trim().replace(/\\s+/g," ");if(l)r.push(l)}return n}var zn=(e)=>{if(!e.startsWith("1 "))return null;let t=e.split(" ");return t.length>=15?Y(t.slice(14).join(" ")):null};function $n(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=On(e,n),s=new Map;for(let o of t){let i=Y(o);if(!r.has(i)||s.has(i))continue;let u=new Set([i]),l=[i];while(l.length)for(let c of r.get(l.pop())){let a=zn(c);if(a&&r.has(a)&&!u.has(a))u.add(a),l.push(a)}let f=[i,...[...u].filter((c)=>c!==i).sort()].map((c)=>"0 FILE "+(c===i?"":c)+`\n`+r.get(c).join(`\n`)).join(`\n`);s.set(i,`emb/${$n(f)}.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,Ht=new WeakMap,ut=null,ft="",pt=null;function mt(e,t){if(e===ut&&t===ft)return pt;let n=Ht.get(e);if(!n)Ht.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),u=[],l=[];s.studs.forEach((g,h)=>{u.push(g[0]),l.push(g[1]);for(let b=0;b<12;b++)i[h*12+b]=g[2+b]});let f=null,c=0,a=0;if(s.mask){c=s.mask[0],a=s.mask[1];let g=s.mask[2];f=new Uint8Array(g.length);for(let h=0;h<g.length;h++)f[h]=g.charCodeAt(h)===49?1:0}let p=!!f;if(f){for(let g=0;g<f.length;g++)if(f[g]!==1){p=!1;break}}return n.set(t,r={nStuds:o,studM:i,kind:u,color:l,mask:f,nx:c,nz:a,full:p}),ut=e,ft=t,pt=r,r}var Pe=1073741824;class ke{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=ke.tagOf(e,t,n),s=this.tag,o=this.t,i=this.mask,u=this.slot(e,t,n);for(;;){let l=s[u];if(l===0)return-1;if(l===r){let f=u<<2;if(o[f]===e&&o[f+1]===t&&o[f+2]===n)return o[f+3]}u=u+1&i}}put(e,t,n,r){if((this.size+1)*2>this.tag.length)this.grow();let s=ke.tagOf(e,t,n),o=this.tag,i=this.t,u=this.mask,l=this.slot(e,t,n);for(;;){let f=o[l],c=l<<2;if(f===0)return o[l]=s,i[c]=e,i[c+1]=t,i[c+2]=n,i[c+3]=r,this.size++,-1;if(f===s&&i[c]===e&&i[c+1]===t&&i[c+2]===n){let a=i[c+3];return i[c+3]=r,a}l=l+1&u}}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 Zt{grp=new ke(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=[],u=[],l=[];for(let a=0;a<r;a++){let p=e[a],g=t[a],h=n[a],b=(p%20+20)%20,v=(h%20+20)%20,x=this.group(g,b,v);if(x<0)x=s.length,this.grp.put(g,b,v,x),this.lg=x,s.push(0),o.push(p),i.push(p),u.push(h),l.push(h);if(s[x]++,p<o[x])o[x]=p;else if(p>i[x])i[x]=p;if(h<u[x])u[x]=h;else if(h>l[x])l[x]=h}let f=0,c=0;for(let a=0;a<s.length;a++){let p=(i[a]-o[a])/20+1,g=(l[a]-u[a])/20+1,h=p*g;if(this.gX0.push(o[a]),this.gZ0.push(u[a]),this.gNx.push(p),this.gNz.push(g),h<=64*s[a]+1024&&f+h<2147483648)this.gBits.push(f),f+=h;else this.gBits.push(-1),c+=s[a]}this.bits=new Uint8Array(Math.ceil(f/8)),this.rest=new ke(c);for(let a=0;a<r;a++){let p=e[a],g=t[a],h=n[a],b=this.group(g,(p%20+20)%20,(h%20+20)%20),v=this.gBits[b];if(v<0){this.rest.put(p,g,h,1);continue}let x=v+(p-this.gX0[b])/20*this.gNz[b]+(h-this.gZ0[b])/20;this.bits[x>>>3]|=1<<(x&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 u=s+o*this.gNz[r]+i;return(this.bits[u>>>3]&1<<(u&7))!==0}}var jn=(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>-Pe&&e<Pe&&t>-Pe&&t<Pe&&n>-Pe&&n<Pe,De=2147483647;function Vn(e,t){let n=e.colorTable?.[t];if(n)return(n.alpha??255)<255;return t.charCodeAt(0)===35&&/\\/[^:/]*:a\\d/.test(t)}function _n(e,t,n){return Kt(e,t,n,-1)??Kt(e,t,n,Yt)}var Yt=0;function Kt(e,t,n,r){let o=new Map,i=(T)=>{let R=o.get(T);if(R===void 0)o.set(T,R=Vn(t,T));return R},u=e.length,l=0,f=0;for(let T=0,R="";T<u;T++){let A=e[T].part;if(A===R){l++;continue}let U=t.parts[A];if(U&&U.mask)l++,R=A}let c=new Float64Array(l),a=new Float64Array(l),p=new Float64Array(l),g=new Float64Array(l),h=new Int32Array(l),b=new Int32Array(l),v=new Float64Array(l),x=new Float64Array(l),m=[],d=new Int32Array(l),y=new Float64Array(l*9),D=new Uint8Array(l);if(r<0)r=l*4+64;let C=new ke(e.length*2),E=new Int32Array(r),B=new Int32Array(r),k=0,w=0;for(let T=0;T<e.length;T++){let R=e[T],A=R.m,U=t.parts[R.part];if(!U||!U.mask||!Xt(A)||i(R.color))continue;let S=U.bbox,z=1/0,j=-1/0,te=1/0,H=-1/0;for(let K=0;K<2;K++)for(let le=0;le<2;le++){let ne=K?S[3]:S[0],Ee=le?S[5]:S[2],Me=A[0]+A[3]*ne+A[5]*Ee,be=A[2]+A[9]*ne+A[11]*Ee;if(Me<z)z=Me;if(Me>j)j=Me;if(be<te)te=be;if(be>H)H=be}let G=Math.round((A[1]+S[4])*2),Q=mt(t,R.part),ue=Math.floor(z/40),ye=Math.floor(j/40),xe=Math.floor(te/40),we=Math.floor(H/40);if(!((ye-ue+1)*(we-xe+1)<=65536)||!Fe(G,ue,xe)||!Fe(G,ye,we))continue;let ge=Math.floor((z+5)/40),se=Math.floor((j-5)/40),oe=Math.floor((te+5)/40),ie=Math.floor((H-5)/40),Ce=ge<=se&&oe<=ie?(se-ge+1)*(ie-oe+1):0;w+=Ce;let pe=-1;for(let K=ge<=se&&oe<=ie?C.get(G,ge,oe):-1,le=0;K>=0&&le<8;K=E[K],le++){let ne=B[K];if(c[ne]!==z||a[ne]!==j||p[ne]!==te||g[ne]!==H||m[ne]!==Q)continue;let Ee=e[h[ne]].m,Me=!0;for(let be=0;be<12;be++)if(Ee[be]!==A[be]){Me=!1;break}if(Me){pe=ne;break}}if(pe>=0){let K=n?n[T]:0;if(n&&K<n[h[pe]])b[pe]=h[pe],h[pe]=T;else if(b[pe]<0||n&&K<n[b[pe]])b[pe]=T;continue}let ae=f++;c[ae]=z,a[ae]=j,p[ae]=te,g[ae]=H,h[ae]=T,b[ae]=-1,m.push(Q),v[ae]=S[0],x[ae]=S[2],d[ae]=G;let me=ae*9;if(y[me]=A[0],y[me+1]=A[1],y[me+2]=A[2],y[me+3]=A[3],y[me+4]=A[6],y[me+5]=A[9],y[me+6]=A[5],y[me+7]=A[8],y[me+8]=A[11],D[ae]=Q.full&&S[3]-S[0]<=20*Q.nx&&S[5]-S[2]<=20*Q.nz&&A[4]===0&&A[6]===0&&A[8]===0&&A[10]===0&&jn(A[3],A[5],A[9],A[11])?1:0,k+Ce>r){k=r+1;continue}for(let K=ge;K<=se;K++)for(let le=oe;le<=ie;le++){if(!Fe(G,K,le))continue;let ne=k++;B[ne]=ae,E[ne]=C.put(G,K,le,ne)}}if(k>r)return Yt=w,null;let M=[0,5,-5,5,-5],F=[0,5,5,-5,-5],N=(T,R,A,U)=>{if(!(R-6>=c[T]-0.5&&R+6<=a[T]+0.5&&U-6>=p[T]-0.5&&U+6<=g[T]+0.5))return!1;if(D[T]===1)return!0;let S=T*9,z=m[T],j=v[T],te=x[T],H=R-y[S],G=A-y[S+1],Q=U-y[S+2],ue=y[S+3]*H+y[S+4]*G+y[S+5]*Q,ye=y[S+6]*H+y[S+7]*G+y[S+8]*Q,{nx:xe,nz:we,mask:ge}=z;for(let se=0;se<5;se++){let oe=Math.floor((ue+M[se]-j)/20),ie=Math.floor((ye+F[se]-te)/20);if(oe<0||ie<0||oe>=xe||ie>=we||ge[oe*we+ie]!==1)return!1}return!0},P=NaN,I=NaN,V=NaN,he=-1,ce=-1,Ae=(T,R,A,U)=>{let S=Math.round(R*2),z=Math.floor(T/40),j=Math.floor(A/40);if(!Fe(S,z,j))return De;let te=De;if(!n&&ce>=0&&d[ce]===S&&(h[ce]!==U||b[ce]>=0)&&N(ce,T,R,A))return 0;if(S!==P||z!==I||j!==V)P=S,I=z,V=j,he=C.get(S,z,j);for(let H=he;H>=0;H=E[H]){let G=B[H],Q=h[G];if(Q===U&&(Q=b[G])<0)continue;if(!N(G,T,R,A))continue;if(!n)return ce=G,0;let ue=n[Q];if(ue<te)te=ue}return te},re=0;for(let T of e){let R=mt(t,T.part);if(R)re+=R.nStuds}let Te=new Uint8Array(re),de=new Uint8Array(re),ve=0,fe=n?new ke(re,4):null,Le=n?null:new Int32Array(re),O=n?null:new Int32Array(re),L=n?null:new Int32Array(re),_=0,X=n?new Int32Array(re).fill(De):void 0;for(let T=0,R=0;T<e.length;T++){let A=e[T],U=mt(t,A.part);if(!U)continue;let S=A.m,z=U.studM,j=S[0],te=S[1],H=S[2],G=S[3],Q=S[4],ue=S[5],ye=S[6],xe=S[7],we=S[8],ge=S[9],se=S[10],oe=S[11];for(let ie=0;ie<U.nStuds;ie++,R++){let Ce=ie*12,pe=z[Ce+4],ae=z[Ce+7],me=z[Ce+10];if(!(Math.abs(ye*pe+xe*ae+we*me-1)<0.001&&Math.abs(G*pe+Q*ae+ue*me)<0.001&&Math.abs(ge*pe+se*ae+oe*me)<0.001))continue;de[R]=1;let K=z[Ce],le=z[Ce+1],ne=z[Ce+2],Ee=j+G*K+Q*le+ue*ne,Me=te+ye*K+xe*le+we*ne,be=H+ge*K+se*le+oe*ne,ht=Ae(Ee,Me,be,T);if(ht!==De){if(Te[R]=1,ve++,X)X[R]=ht}let Ue=Math.round(Ee),Ne=Math.round(Me),Oe=Math.round(be);if(!Fe(Ue,Ne,Oe))continue;if(!fe){Le[_]=Ue,O[_]=Ne,L[_++]=Oe;continue}let gt=n[T],bt=fe.get(Ue,Ne,Oe);if(bt<0||gt<bt)fe.put(Ue,Ne,Oe,gt)}}let q=fe?null:new Zt(Le,O,L,_),ee=new Uint8Array(e.length),J=n?new Int32Array(e.length).fill(De):void 0;for(let T=0;T<e.length;T++){let R=e[T],A=t.parts[R.part];if(!A||!A.under||!Xt(R.m)||i(R.color))continue;let U=A.bbox,S=Math.round((U[3]-U[0])/20),z=Math.round((U[5]-U[2])/20);if(!S||!z||S*z>4096)continue;let j=R.m,te=Math.round(j[1]+U[4]),H=!0,G=0;for(let Q=0;Q<S&&H;Q++)for(let ue=0;ue<z;ue++){let ye=U[0]+10+20*Q,xe=U[2]+10+20*ue,we=j[0]+j[3]*ye+j[5]*xe,ge=j[2]+j[9]*ye+j[11]*xe,se=Math.round(we),oe=Math.round(ge),ie=!Fe(se,te,oe)?-1:fe?fe.get(se,te,oe):q.has(se,te,oe)?1:-1;if(ie<0){H=!1;break}if(ie>G)G=ie}if(H){if(ee[T]=1,J)J[T]=G}}return{nStuds:re,studHidden:Te,studUp:de,underHidden:ee,studsHidden:ve,studHideStep:X,underHideStep:J}}function Gn(e,t,n){let r=(a)=>a.colPart&&t.parts[a.colPart]?a.colPart:n&&a.texPart&&t.parts[a.texPart]?a.texPart:a.part,s=new Map,o=new Map,i=(a)=>{let p=a.colour;if(!p)return String(a.color);let g=o.get(p);if(g!==void 0)return g;let h=t.colorTable?.[a.color],b=h?.hex??t.colors?.[a.color],v=h?ct({alpha:h.alpha??255,luminance:h.luminance??0,finish:h.finish??{type:"default"}}):"default:op",x=ct(p);if(g=b&&b.toUpperCase()===p.hex.toUpperCase()&&v===x?String(a.color):p.hex.toUpperCase()+"/"+x,g!==String(a.color))s.set(g,p);return o.set(p,g),g},u=e.map((a)=>({part:r(a),color:i(a),m:a.m,steps:a.steps})),l=u.map((a)=>Vt(a.steps)),f=[...new Set(l)].sort(),c=new Map(f.map((a,p)=>[a,p]));return{all:u,stepOf:l.map((a)=>c.get(a)),nSteps:f.length,localColours:s}}function _e(e,t,n=!0){let r=Gn(e,t,n);return _n(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Ke="https://ldr-demo.vercel.app/cdn/v1/",We=new Map,Ge=new Map;function Xe(e=Ke,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 Wn=(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"),He=(e,t)=>Wn(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>He(n,t)):e&&typeof e==="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,He(r,t)])):e;function Xn(e,t={}){let n=[],r=0,s={},o={};for(let p of e){let g=p.buffer;if(!g)throw Error("ldr: mergePacks needs packs from decodePack/loadPack");let h=new DataView(g).getUint32(0,!0),b=new Uint8Array(g,4+h),v=r;n.push(b),r+=b.byteLength;let x=(4-r%4)%4;if(x)n.push(new Uint8Array(x)),r+=x;for(let[m,d]of Object.entries(p.header.parts??{}))if(!(m in s))s[m]=He(d,v);for(let[m,d]of Object.entries(p.header.studKinds??{}))if(!(m in o))o[m]=He(d,v)}let i=e[0]?.header??{version:1,weld:!0},u=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),l=(4-(4+u.length)%4)%4,f=4+u.length+l,c=new Uint8Array(f+r);new DataView(c.buffer).setUint32(0,u.length+l,!0),c.set(u,4),c.fill(32,4+u.length,f);let a=f;for(let p of n)c.set(p,a),a+=p.byteLength;return Ve(c.buffer)}async function Hn(e,t={}){e=[...e];try{return await Jt(e,t)}catch(n){let r=t.cdn??Ke,s=t.fetch??fetch;We.delete(r);let o=(i,u)=>s(i,{...u,cache:"reload"});try{return await Jt(e,{...t,fetch:o})}catch{throw n}}}async function Jt(e,t){let n=t.cdn??Ke,r=t.fetch??fetch,s=t.gap??16384,o=await Xe(n,r),i=[...new Set([...e].map(Y))],u=[],l=[];for(let m of i){if(Ge.has(n+m))continue;let d=o.parts[m];if(d)l.push({name:m,off:d[0],len:d[1],file:d[2]??0});else u.push(m)}l.sort((m,d)=>m.file-d.file||m.off-d.off);let f=[];for(let m of l){let d=f[f.length-1];if(d&&d.file===m.file&&m.off-d.end<=s)d.end=Math.max(d.end,m.off+m.len),d.items.push(m);else f.push({file:m.file,start:m.off,end:m.off+m.len,items:[m]})}let c=0,a=0,p=0,g=new Map,h=async()=>{while(p<f.length){let m=f[p++],d=g.get(m.file);if(d)d=d.subarray(m.start,m.end);else{let y=await r(new URL(o.archives[m.file],n).href,{headers:{Range:`bytes=${m.start}-${m.end-1}`,"Accept-Encoding":"identity"}});if(!y.ok)throw Error(`ldr: parts CDN ${y.status}`);if(a++,d=new Uint8Array(await y.arrayBuffer()),c+=d.byteLength,y.status===200)g.set(m.file,d),d=d.subarray(m.start,m.end)}for(let y of m.items){let D=je(d.subarray(y.off-m.start,y.off-m.start+y.len)),C=D.buffer.slice(D.byteOffset,D.byteOffset+D.byteLength);Ge.set(n+y.name,Ve(C))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,f.length)},h));let b=i.filter((m)=>Ge.has(n+m)).map((m)=>Ge.get(n+m)),v={colors:o.colors,...o.colorTable?{colorTable:o.colorTable}:{}};return{pack:b.length?Xn(b,v):Ve(Kn(v)),missing:u,requests:a,bytes:c}}function Kn(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 Zn(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 Qt(e,t,n){let r=0,s=0,o=!1,i=new Set;for(let u of e){let l=u.embedded?t.get(u.part):Y(u.part),f=l?n.parts[l]:void 0;if(!f)continue;if(f[3]!=null)o=!0,r+=f[3];if(!i.has(l))i.add(l),s+=f[1]}return{bodyTris:r,packBytes:s,known:o}}class Ze 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 qt(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=Xe(t.cdn??Ke,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(w)=>{if(!w.ok)throw Error(`ldr: ${w.status} fetching ${e}`);return xt(await w.arrayBuffer())}),i=performance.now(),u=t.name??(t.text?"main.ldr":wt(e)),l=Gt(o,u,{looseGeometry:!1,callouts:t.callouts}),f=performance.now();t.onParsed?.(l),await s;let c=Wt(o,new Set(l.filter((w)=>w.embedded).map((w)=>w.part)),u),a=(w,M)=>t.maxBodyTris!=null&&w>t.maxBodyTris||t.maxPackBytes!=null&&M>t.maxPackBytes,p=t.maxBodyTris!=null||t.maxPackBytes!=null,g=(w)=>new Ze({...w,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes}),h="full";if(p){let w=Qt(l,c,await s);if(a(w.known?w.bodyTris:0,w.packBytes)){if(!t.lowCdn)throw g(w);let M=await Xe(t.lowCdn,r).catch(()=>null);if(!M)throw g(w);let F=Qt(l,c,M);if(a(F.known?F.bodyTris:0,F.packBytes))throw g(F);h="low"}}let b=[...l.filter((w)=>!w.embedded).map((w)=>w.part),...c.values()],v=async()=>{let w=await Hn(b,h==="low"?{...t,cdn:t.lowCdn}:t);for(let[M,F]of c){let N=w.pack.header.parts[F];if(N)w.pack.header.parts[M]=N}return{...w,packBytes:w.pack.buffer?.byteLength??w.pack.bytes??0,bodyTris:Zn(l,w.pack)}},x=await v();if(p&&a(x.bodyTris,x.packBytes)&&h==="full"&&t.lowCdn&&await Xe(t.lowCdn,r).then(()=>!0,()=>!1)){h="low";let w=x;x=await v(),x.requests+=w.requests,x.bytes+=w.bytes}if(p&&a(x.bodyTris,x.packBytes))throw g(x);let{pack:m,missing:d,requests:y,bytes:D}=x,C=new Map([...c].map(([w,M])=>[M,w])),E=d.map((w)=>C.get(w)??w),B=performance.now(),k=t.cull?_e(l,m.header,t.textures!==!1):void 0;return{insts:l,pack:m,tier:h,missing:E,requests:y,bytes:D,cull:k,timings:{fetchModel:i-n,parse:f-i,parts:B-f,...k?{cull:performance.now()-B}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await qt(n,{...r,cull:!1,onParsed:(c)=>self.postMessage({id:t,insts:c})}),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(),u=_e(s.insts,s.pack.header,r.textures!==!1),l=performance.now()-i,f=[];for(let c of[u.studHidden,u.studUp,u.underHidden,u.studHideStep,u.underHideStep])if(c)f.push(c.buffer);self.postMessage({id:t,cull:u,ms:l},f)}catch(s){if(s instanceof Ze||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';
|
|
5265
5338
|
|
|
5266
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5339
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/cdn.ts
|
|
5267
5340
|
var worker;
|
|
5268
5341
|
var seq = 0;
|
|
5269
5342
|
var pending = new Map;
|
|
@@ -5377,7 +5450,7 @@ async function loadModel(source, o = {}) {
|
|
|
5377
5450
|
timings: { ...prep.timings, parts: t3 - t0 - prep.timings.fetchModel - prep.timings.parse, build: t4 - t3, total: t4 - t0 }
|
|
5378
5451
|
});
|
|
5379
5452
|
}
|
|
5380
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5453
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/node/library.ts
|
|
5381
5454
|
import { existsSync, readFileSync, statSync } from "fs";
|
|
5382
5455
|
import { join } from "path";
|
|
5383
5456
|
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]];
|
|
@@ -5727,11 +5800,11 @@ class Library {
|
|
|
5727
5800
|
return insts;
|
|
5728
5801
|
}
|
|
5729
5802
|
}
|
|
5730
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5803
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/node/build-pack.ts
|
|
5731
5804
|
import fs3 from "node:fs";
|
|
5732
5805
|
import path3 from "node:path";
|
|
5733
5806
|
|
|
5734
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5807
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/node/resolver.ts
|
|
5735
5808
|
import fs from "node:fs";
|
|
5736
5809
|
import path from "node:path";
|
|
5737
5810
|
var TOP_STUD_RE = /^(stud|studa|stud2|stud2a|stud6|stud6a|stud10|stud15|stud2s|stud2s2|stud-logo\d*|stud2-logo\d*)\.dat$/i;
|
|
@@ -6060,11 +6133,11 @@ function collectDeps(lib, refs) {
|
|
|
6060
6133
|
return out;
|
|
6061
6134
|
}
|
|
6062
6135
|
|
|
6063
|
-
// ../../../../../../../tmp/ldr-build-
|
|
6136
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/node/compile.ts
|
|
6064
6137
|
import fs2 from "node:fs";
|
|
6065
6138
|
import path2 from "node:path";
|
|
6066
6139
|
|
|
6067
|
-
// ../../../../../../../tmp/ldr-build-
|
|
6140
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/node/lod.ts
|
|
6068
6141
|
import { MeshoptSimplifier, MeshoptEncoder } from "meshoptimizer";
|
|
6069
6142
|
await Promise.all([MeshoptSimplifier.ready, MeshoptEncoder.ready]);
|
|
6070
6143
|
function reorderMesh(P, N, C, I) {
|
|
@@ -6370,7 +6443,7 @@ function levelLines(P, I, E, err, always, tol = 0.01) {
|
|
|
6370
6443
|
return out;
|
|
6371
6444
|
}
|
|
6372
6445
|
|
|
6373
|
-
// ../../../../../../../tmp/ldr-build-
|
|
6446
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/node/compile.ts
|
|
6374
6447
|
class BfcState {
|
|
6375
6448
|
accum;
|
|
6376
6449
|
ccw = true;
|
|
@@ -7314,7 +7387,7 @@ function encodePack(parts, studKinds, weld, extra, options = {}) {
|
|
|
7314
7387
|
return Buffer.concat([head, ...chunks.map((c) => new Uint8Array(c.buffer, c.byteOffset, c.byteLength))]);
|
|
7315
7388
|
}
|
|
7316
7389
|
|
|
7317
|
-
// ../../../../../../../tmp/ldr-build-
|
|
7390
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/node/build-pack.ts
|
|
7318
7391
|
function packCompilerOpts(o) {
|
|
7319
7392
|
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 } : {} };
|
|
7320
7393
|
}
|
|
@@ -7386,7 +7459,7 @@ function buildPack(o) {
|
|
|
7386
7459
|
const warnings = [...lib.conflicts].map((n) => `${n}: defined differently by two models; the first definition is used`);
|
|
7387
7460
|
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 } : {} };
|
|
7388
7461
|
}
|
|
7389
|
-
// ../../../../../../../tmp/ldr-build-
|
|
7462
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/node/promote.ts
|
|
7390
7463
|
var GEOM = /^\s*[2-5]\s/;
|
|
7391
7464
|
var REF = /^\s*1\s/;
|
|
7392
7465
|
var FILE = /^\s*0\s+FILE\s+(\S.*?)\s*$/i;
|