ldr 0.33.12 → 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/cull.d.ts +24 -1
- package/dist/index.js +437 -179
- package/dist/load-worker.gen.d.ts +1 -1
- package/dist/node/index.js +446 -188
- package/dist/render.d.ts +17 -2
- package/package.json +1 -1
package/dist/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;
|
|
@@ -778,7 +778,7 @@ function fileStepViews(f) {
|
|
|
778
778
|
viewMemo.set(f, out);
|
|
779
779
|
return out;
|
|
780
780
|
}
|
|
781
|
-
// ../../../../../../../tmp/ldr-build-
|
|
781
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/model.ts
|
|
782
782
|
class ModelLimitError extends Error {
|
|
783
783
|
limit;
|
|
784
784
|
code = "ldr-model-limit";
|
|
@@ -1219,7 +1219,7 @@ function blendedColourHex(code) {
|
|
|
1219
1219
|
const a = LDRAW_EXE_16[code - 256 >> 4], b = LDRAW_EXE_16[code - 256 & 15];
|
|
1220
1220
|
return "#" + [0, 1, 2].map((k) => (a[k] + b[k] >> 1).toString(16).padStart(2, "0")).join("").toUpperCase();
|
|
1221
1221
|
}
|
|
1222
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1222
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/instructions.ts
|
|
1223
1223
|
var MIN_VIS = 0.5;
|
|
1224
1224
|
var REORIENT = 0.35;
|
|
1225
1225
|
var deg = Math.PI / 180;
|
|
@@ -1587,10 +1587,10 @@ function planStepViews(insts, parts, stepOf, nSteps, o = {}) {
|
|
|
1587
1587
|
}
|
|
1588
1588
|
};
|
|
1589
1589
|
}
|
|
1590
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1590
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/render.ts
|
|
1591
1591
|
import * as THREE from "three";
|
|
1592
1592
|
|
|
1593
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1593
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/pack-io.ts
|
|
1594
1594
|
import { decompress } from "fzstd";
|
|
1595
1595
|
async function decompressPack(data) {
|
|
1596
1596
|
const u = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
@@ -1613,7 +1613,7 @@ function decodePack(buf) {
|
|
|
1613
1613
|
return { header, arr, bytes: buf.byteLength, buffer: buf };
|
|
1614
1614
|
}
|
|
1615
1615
|
|
|
1616
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1616
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/cull.ts
|
|
1617
1617
|
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;
|
|
1618
1618
|
var prepCache = new WeakMap;
|
|
1619
1619
|
var lastH = null;
|
|
@@ -1655,7 +1655,15 @@ function prepPart(H, part) {
|
|
|
1655
1655
|
for (let i = 0;i < bits.length; i++)
|
|
1656
1656
|
mask[i] = bits.charCodeAt(i) === 49 ? 1 : 0;
|
|
1657
1657
|
}
|
|
1658
|
-
|
|
1658
|
+
let full = !!mask;
|
|
1659
|
+
if (mask) {
|
|
1660
|
+
for (let i = 0;i < mask.length; i++)
|
|
1661
|
+
if (mask[i] !== 1) {
|
|
1662
|
+
full = false;
|
|
1663
|
+
break;
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
c.set(part, r = { nStuds: n, studM, kind, color, mask, nx, nz, full });
|
|
1659
1667
|
lastH = H;
|
|
1660
1668
|
lastPart = part;
|
|
1661
1669
|
lastPrep = r;
|
|
@@ -1762,6 +1770,98 @@ class Int3Table {
|
|
|
1762
1770
|
}
|
|
1763
1771
|
}
|
|
1764
1772
|
}
|
|
1773
|
+
|
|
1774
|
+
class StudTopSet {
|
|
1775
|
+
grp = new Int3Table(64);
|
|
1776
|
+
gBits = [];
|
|
1777
|
+
gX0 = [];
|
|
1778
|
+
gZ0 = [];
|
|
1779
|
+
gNz = [];
|
|
1780
|
+
gNx = [];
|
|
1781
|
+
bits;
|
|
1782
|
+
rest;
|
|
1783
|
+
lk = NaN;
|
|
1784
|
+
lpx = NaN;
|
|
1785
|
+
lpz = NaN;
|
|
1786
|
+
lg = -1;
|
|
1787
|
+
group(y, px, pz) {
|
|
1788
|
+
if (y !== this.lk || px !== this.lpx || pz !== this.lpz) {
|
|
1789
|
+
this.lk = y;
|
|
1790
|
+
this.lpx = px;
|
|
1791
|
+
this.lpz = pz;
|
|
1792
|
+
this.lg = this.grp.get(y, px, pz);
|
|
1793
|
+
}
|
|
1794
|
+
return this.lg;
|
|
1795
|
+
}
|
|
1796
|
+
constructor(X, Y, Z, n) {
|
|
1797
|
+
const cnt = [], x0 = [], x1 = [], z0 = [], z1 = [];
|
|
1798
|
+
for (let i = 0;i < n; i++) {
|
|
1799
|
+
const x = X[i], y = Y[i], z = Z[i], px = (x % 20 + 20) % 20, pz = (z % 20 + 20) % 20;
|
|
1800
|
+
let g = this.group(y, px, pz);
|
|
1801
|
+
if (g < 0) {
|
|
1802
|
+
g = cnt.length;
|
|
1803
|
+
this.grp.put(y, px, pz, g);
|
|
1804
|
+
this.lg = g;
|
|
1805
|
+
cnt.push(0);
|
|
1806
|
+
x0.push(x);
|
|
1807
|
+
x1.push(x);
|
|
1808
|
+
z0.push(z);
|
|
1809
|
+
z1.push(z);
|
|
1810
|
+
}
|
|
1811
|
+
cnt[g]++;
|
|
1812
|
+
if (x < x0[g])
|
|
1813
|
+
x0[g] = x;
|
|
1814
|
+
else if (x > x1[g])
|
|
1815
|
+
x1[g] = x;
|
|
1816
|
+
if (z < z0[g])
|
|
1817
|
+
z0[g] = z;
|
|
1818
|
+
else if (z > z1[g])
|
|
1819
|
+
z1[g] = z;
|
|
1820
|
+
}
|
|
1821
|
+
let total = 0, nRest = 0;
|
|
1822
|
+
for (let g = 0;g < cnt.length; g++) {
|
|
1823
|
+
const nx = (x1[g] - x0[g]) / 20 + 1, nz = (z1[g] - z0[g]) / 20 + 1, b = nx * nz;
|
|
1824
|
+
this.gX0.push(x0[g]);
|
|
1825
|
+
this.gZ0.push(z0[g]);
|
|
1826
|
+
this.gNx.push(nx);
|
|
1827
|
+
this.gNz.push(nz);
|
|
1828
|
+
if (b <= 64 * cnt[g] + 1024 && total + b < 2 ** 31) {
|
|
1829
|
+
this.gBits.push(total);
|
|
1830
|
+
total += b;
|
|
1831
|
+
} else {
|
|
1832
|
+
this.gBits.push(-1);
|
|
1833
|
+
nRest += cnt[g];
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
this.bits = new Uint8Array(Math.ceil(total / 8));
|
|
1837
|
+
this.rest = new Int3Table(nRest);
|
|
1838
|
+
for (let i = 0;i < n; i++) {
|
|
1839
|
+
const x = X[i], y = Y[i], z = Z[i];
|
|
1840
|
+
const g = this.group(y, (x % 20 + 20) % 20, (z % 20 + 20) % 20);
|
|
1841
|
+
const o = this.gBits[g];
|
|
1842
|
+
if (o < 0) {
|
|
1843
|
+
this.rest.put(x, y, z, 1);
|
|
1844
|
+
continue;
|
|
1845
|
+
}
|
|
1846
|
+
const k = o + (x - this.gX0[g]) / 20 * this.gNz[g] + (z - this.gZ0[g]) / 20;
|
|
1847
|
+
this.bits[k >>> 3] |= 1 << (k & 7);
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
has(x, y, z) {
|
|
1851
|
+
const g = this.group(y, (x % 20 + 20) % 20, (z % 20 + 20) % 20);
|
|
1852
|
+
if (g < 0)
|
|
1853
|
+
return false;
|
|
1854
|
+
const o = this.gBits[g];
|
|
1855
|
+
if (o < 0)
|
|
1856
|
+
return this.rest.get(x, y, z) >= 0;
|
|
1857
|
+
const a = (x - this.gX0[g]) / 20, c = (z - this.gZ0[g]) / 20;
|
|
1858
|
+
if (a < 0 || c < 0 || a >= this.gNx[g] || c >= this.gNz[g])
|
|
1859
|
+
return false;
|
|
1860
|
+
const k = o + a * this.gNz[g] + c;
|
|
1861
|
+
return (this.bits[k >>> 3] & 1 << (k & 7)) !== 0;
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
var quarterTurn = (a, c, g, i) => a === 0 && i === 0 && (c === 1 || c === -1) && (g === 1 || g === -1) || c === 0 && g === 0 && (a === 1 || a === -1) && (i === 1 || i === -1);
|
|
1765
1865
|
var inRange = (x, y, z) => x > -BIG && x < BIG && y > -BIG && y < BIG && z > -BIG && z < BIG;
|
|
1766
1866
|
var STEP_NEVER = 2147483647;
|
|
1767
1867
|
function forEachStud(insts, H, fn) {
|
|
@@ -1786,6 +1886,10 @@ function seeThrough(H, c) {
|
|
|
1786
1886
|
return c.charCodeAt(0) === 35 && /\/[^:/]*:a\d/.test(c);
|
|
1787
1887
|
}
|
|
1788
1888
|
function cullCore(insts, H, steps) {
|
|
1889
|
+
return cullPass(insts, H, steps, -1) ?? cullPass(insts, H, steps, needE);
|
|
1890
|
+
}
|
|
1891
|
+
var needE = 0;
|
|
1892
|
+
function cullPass(insts, H, steps, eCap) {
|
|
1789
1893
|
const CELL = 40;
|
|
1790
1894
|
const clear = new Map;
|
|
1791
1895
|
const isClear = (c) => {
|
|
@@ -1794,10 +1898,30 @@ function cullCore(insts, H, steps) {
|
|
|
1794
1898
|
clear.set(c, v = seeThrough(H, c));
|
|
1795
1899
|
return v;
|
|
1796
1900
|
};
|
|
1797
|
-
const
|
|
1798
|
-
|
|
1901
|
+
const nI = insts.length;
|
|
1902
|
+
let cap = 0, nR = 0;
|
|
1903
|
+
for (let idx = 0, lp = "";idx < nI; idx++) {
|
|
1904
|
+
const part = insts[idx].part;
|
|
1905
|
+
if (part === lp) {
|
|
1906
|
+
cap++;
|
|
1907
|
+
continue;
|
|
1908
|
+
}
|
|
1909
|
+
const p = H.parts[part];
|
|
1910
|
+
if (p && p.mask) {
|
|
1911
|
+
cap++;
|
|
1912
|
+
lp = part;
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1915
|
+
const rx0 = new Float64Array(cap), rx1 = new Float64Array(cap), rz0 = new Float64Array(cap), rz1 = new Float64Array(cap);
|
|
1916
|
+
const rInst = new Int32Array(cap), rInst2 = new Int32Array(cap), rBx = new Float64Array(cap), rBz = new Float64Array(cap);
|
|
1917
|
+
const rPrep = [];
|
|
1918
|
+
const rLv = new Int32Array(cap), rM = new Float64Array(cap * 9);
|
|
1919
|
+
const rFast = new Uint8Array(cap);
|
|
1920
|
+
if (eCap < 0)
|
|
1921
|
+
eCap = cap * 4 + 64;
|
|
1799
1922
|
const cells = new Int3Table(insts.length * 2);
|
|
1800
|
-
const nextE =
|
|
1923
|
+
const nextE = new Int32Array(eCap), rectE = new Int32Array(eCap);
|
|
1924
|
+
let nE = 0, need = 0;
|
|
1801
1925
|
for (let idx = 0;idx < insts.length; idx++) {
|
|
1802
1926
|
const it = insts[idx];
|
|
1803
1927
|
const m = it.m;
|
|
@@ -1824,8 +1948,11 @@ function cullCore(insts, H, steps) {
|
|
|
1824
1948
|
const cx0 = Math.floor(x0 / CELL), cx1 = Math.floor(x1 / CELL), cz0 = Math.floor(z0 / CELL), cz1 = Math.floor(z1 / CELL);
|
|
1825
1949
|
if (!((cx1 - cx0 + 1) * (cz1 - cz0 + 1) <= 65536) || !inRange(lv2, cx0, cz0) || !inRange(lv2, cx1, cz1))
|
|
1826
1950
|
continue;
|
|
1951
|
+
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);
|
|
1952
|
+
const nc = ux0 <= ux1 && uz0 <= uz1 ? (ux1 - ux0 + 1) * (uz1 - uz0 + 1) : 0;
|
|
1953
|
+
need += nc;
|
|
1827
1954
|
let dup = -1;
|
|
1828
|
-
for (let e = cells.get(lv2,
|
|
1955
|
+
for (let e = ux0 <= ux1 && uz0 <= uz1 ? cells.get(lv2, ux0, uz0) : -1, k = 0;e >= 0 && k < 8; e = nextE[e], k++) {
|
|
1829
1956
|
const q = rectE[e];
|
|
1830
1957
|
if (rx0[q] !== x0 || rx1[q] !== x1 || rz0[q] !== z0 || rz1[q] !== z1 || rPrep[q] !== pp)
|
|
1831
1958
|
continue;
|
|
@@ -1850,31 +1977,51 @@ function cullCore(insts, H, steps) {
|
|
|
1850
1977
|
rInst2[dup] = idx;
|
|
1851
1978
|
continue;
|
|
1852
1979
|
}
|
|
1853
|
-
const ri =
|
|
1854
|
-
rx0
|
|
1855
|
-
rx1
|
|
1856
|
-
rz0
|
|
1857
|
-
rz1
|
|
1858
|
-
rInst
|
|
1859
|
-
rInst2
|
|
1980
|
+
const ri = nR++;
|
|
1981
|
+
rx0[ri] = x0;
|
|
1982
|
+
rx1[ri] = x1;
|
|
1983
|
+
rz0[ri] = z0;
|
|
1984
|
+
rz1[ri] = z1;
|
|
1985
|
+
rInst[ri] = idx;
|
|
1986
|
+
rInst2[ri] = -1;
|
|
1860
1987
|
rPrep.push(pp);
|
|
1861
|
-
rBx
|
|
1862
|
-
rBz
|
|
1863
|
-
rLv
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1988
|
+
rBx[ri] = b[0];
|
|
1989
|
+
rBz[ri] = b[2];
|
|
1990
|
+
rLv[ri] = lv2;
|
|
1991
|
+
const o = ri * 9;
|
|
1992
|
+
rM[o] = m[0];
|
|
1993
|
+
rM[o + 1] = m[1];
|
|
1994
|
+
rM[o + 2] = m[2];
|
|
1995
|
+
rM[o + 3] = m[3];
|
|
1996
|
+
rM[o + 4] = m[6];
|
|
1997
|
+
rM[o + 5] = m[9];
|
|
1998
|
+
rM[o + 6] = m[5];
|
|
1999
|
+
rM[o + 7] = m[8];
|
|
2000
|
+
rM[o + 8] = m[11];
|
|
2001
|
+
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;
|
|
2002
|
+
if (nE + nc > eCap) {
|
|
2003
|
+
nE = eCap + 1;
|
|
2004
|
+
continue;
|
|
2005
|
+
}
|
|
2006
|
+
for (let cx = ux0;cx <= ux1; cx++)
|
|
2007
|
+
for (let cz = uz0;cz <= uz1; cz++) {
|
|
1867
2008
|
if (!inRange(lv2, cx, cz))
|
|
1868
2009
|
continue;
|
|
1869
|
-
const e =
|
|
1870
|
-
rectE
|
|
1871
|
-
nextE
|
|
2010
|
+
const e = nE++;
|
|
2011
|
+
rectE[e] = ri;
|
|
2012
|
+
nextE[e] = cells.put(lv2, cx, cz, e);
|
|
1872
2013
|
}
|
|
1873
2014
|
}
|
|
2015
|
+
if (nE > eCap) {
|
|
2016
|
+
needE = need;
|
|
2017
|
+
return null;
|
|
2018
|
+
}
|
|
1874
2019
|
const SX = [0, 5, -5, 5, -5], SZ = [0, 5, 5, -5, -5];
|
|
1875
2020
|
const covers = (ri, x, y, z) => {
|
|
1876
2021
|
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))
|
|
1877
2022
|
return false;
|
|
2023
|
+
if (rFast[ri] === 1)
|
|
2024
|
+
return true;
|
|
1878
2025
|
const o = ri * 9, pp = rPrep[ri], bx = rBx[ri], bz = rBz[ri];
|
|
1879
2026
|
const dx = x - rM[o], dy = y - rM[o + 1], dz = z - rM[o + 2];
|
|
1880
2027
|
const lx = rM[o + 3] * dx + rM[o + 4] * dy + rM[o + 5] * dz, lz = rM[o + 6] * dx + rM[o + 7] * dy + rM[o + 8] * dz;
|
|
@@ -1925,8 +2072,10 @@ function cullCore(insts, H, steps) {
|
|
|
1925
2072
|
nStuds += pp.nStuds;
|
|
1926
2073
|
}
|
|
1927
2074
|
const studHidden = new Uint8Array(nStuds), studUp = new Uint8Array(nStuds);
|
|
1928
|
-
const tops = new Int3Table(nStuds, 4);
|
|
1929
2075
|
let studsHidden = 0;
|
|
2076
|
+
const tops = steps ? new Int3Table(nStuds, 4) : null;
|
|
2077
|
+
const TX = steps ? null : new Int32Array(nStuds), TY = steps ? null : new Int32Array(nStuds), TZ = steps ? null : new Int32Array(nStuds);
|
|
2078
|
+
let nT = 0;
|
|
1930
2079
|
const studHideStep = steps ? new Int32Array(nStuds).fill(STEP_NEVER) : undefined;
|
|
1931
2080
|
for (let idx = 0, j = 0;idx < insts.length; idx++) {
|
|
1932
2081
|
const it = insts[idx];
|
|
@@ -1953,8 +2102,10 @@ function cullCore(insts, H, steps) {
|
|
|
1953
2102
|
const rx = Math.round(x), ry = Math.round(y), rz = Math.round(z);
|
|
1954
2103
|
if (!inRange(rx, ry, rz))
|
|
1955
2104
|
continue;
|
|
1956
|
-
if (!
|
|
1957
|
-
|
|
2105
|
+
if (!tops) {
|
|
2106
|
+
TX[nT] = rx;
|
|
2107
|
+
TY[nT] = ry;
|
|
2108
|
+
TZ[nT++] = rz;
|
|
1958
2109
|
continue;
|
|
1959
2110
|
}
|
|
1960
2111
|
const st = steps[idx], t = tops.get(rx, ry, rz);
|
|
@@ -1962,6 +2113,7 @@ function cullCore(insts, H, steps) {
|
|
|
1962
2113
|
tops.put(rx, ry, rz, st);
|
|
1963
2114
|
}
|
|
1964
2115
|
}
|
|
2116
|
+
const topSet = tops ? null : new StudTopSet(TX, TY, TZ, nT);
|
|
1965
2117
|
const underHidden = new Uint8Array(insts.length);
|
|
1966
2118
|
const underHideStep = steps ? new Int32Array(insts.length).fill(STEP_NEVER) : undefined;
|
|
1967
2119
|
for (let idx = 0;idx < insts.length; idx++) {
|
|
@@ -1980,7 +2132,7 @@ function cullCore(insts, H, steps) {
|
|
|
1980
2132
|
const lx = b[0] + 10 + 20 * a, lz = b[2] + 10 + 20 * c;
|
|
1981
2133
|
const x = m[0] + m[3] * lx + m[5] * lz, z = m[2] + m[9] * lx + m[11] * lz;
|
|
1982
2134
|
const rx = Math.round(x), rz = Math.round(z);
|
|
1983
|
-
const t = inRange(rx, ry, rz) ? tops.get(rx, ry, rz) : -1;
|
|
2135
|
+
const t = !inRange(rx, ry, rz) ? -1 : tops ? tops.get(rx, ry, rz) : topSet.has(rx, ry, rz) ? 1 : -1;
|
|
1984
2136
|
if (t < 0) {
|
|
1985
2137
|
all = false;
|
|
1986
2138
|
break;
|
|
@@ -2027,7 +2179,7 @@ function precomputeCull(instances, H, useTex = true) {
|
|
|
2027
2179
|
return cullCore(s.all, H, s.nSteps > 1 ? s.stepOf : undefined);
|
|
2028
2180
|
}
|
|
2029
2181
|
|
|
2030
|
-
// ../../../../../../../tmp/ldr-build-
|
|
2182
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/render.ts
|
|
2031
2183
|
async function loadPack(url) {
|
|
2032
2184
|
const res = await fetch(url);
|
|
2033
2185
|
if (!res.ok)
|
|
@@ -2422,54 +2574,16 @@ function newIM(g, mat, n) {
|
|
|
2422
2574
|
im.count = n;
|
|
2423
2575
|
return im;
|
|
2424
2576
|
}
|
|
2425
|
-
function
|
|
2426
|
-
if (vis >= im.instanceMatrix.count || !im.instanceColor)
|
|
2427
|
-
return false;
|
|
2428
|
-
const M = im.instanceMatrix.array.slice(0, vis * 16), C = im.instanceColor.array.slice(0, vis * 3);
|
|
2429
|
-
im.instanceMatrix = new THREE.InstancedBufferAttribute(M, 16);
|
|
2430
|
-
im.instanceColor = new THREE.InstancedBufferAttribute(C, 3);
|
|
2431
|
-
im.count = vis;
|
|
2432
|
-
for (const o of linked) {
|
|
2433
|
-
if (o.isInstancedMesh) {
|
|
2434
|
-
o.instanceMatrix = im.instanceMatrix;
|
|
2435
|
-
o.instanceColor = im.instanceColor;
|
|
2436
|
-
o.count = vis;
|
|
2437
|
-
} else if (o.geometry) {
|
|
2438
|
-
o.geometry.setAttribute("instanceMatrix", im.instanceMatrix);
|
|
2439
|
-
o.geometry.instanceCount = vis;
|
|
2440
|
-
}
|
|
2441
|
-
}
|
|
2442
|
-
return true;
|
|
2443
|
-
}
|
|
2444
|
-
function instancedBoundingSphere(im) {
|
|
2445
|
-
const g = im.geometry;
|
|
2577
|
+
function sphereState(g) {
|
|
2446
2578
|
if (!g.boundingSphere)
|
|
2447
2579
|
g.computeBoundingSphere();
|
|
2448
2580
|
const gs = g.boundingSphere;
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
const
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
cy = py;
|
|
2456
|
-
cz = pz;
|
|
2457
|
-
r = 0;
|
|
2458
|
-
return;
|
|
2459
|
-
}
|
|
2460
|
-
const vx = px - cx, vy = py - cy, vz = pz - cz;
|
|
2461
|
-
const l2 = vx * vx + vy * vy + vz * vz;
|
|
2462
|
-
if (l2 > r * r) {
|
|
2463
|
-
const l = Math.sqrt(l2);
|
|
2464
|
-
const d = (l - r) * 0.5;
|
|
2465
|
-
const f = d / l;
|
|
2466
|
-
cx += vx * f;
|
|
2467
|
-
cy += vy * f;
|
|
2468
|
-
cz += vz * f;
|
|
2469
|
-
r += d;
|
|
2470
|
-
}
|
|
2471
|
-
};
|
|
2472
|
-
for (let i = 0, n = im.count;i < n; i++) {
|
|
2581
|
+
return Float64Array.of(0, 0, 0, -1, gs.center.x, gs.center.y, gs.center.z, gs.radius);
|
|
2582
|
+
}
|
|
2583
|
+
function sphereUnion(S, A, n) {
|
|
2584
|
+
const gx = S[4], gy = S[5], gz = S[6], gr = S[7];
|
|
2585
|
+
let cx = S[0], cy = S[1], cz = S[2], r = S[3];
|
|
2586
|
+
for (let i = 0;i < n; i++) {
|
|
2473
2587
|
const o = i * 16;
|
|
2474
2588
|
const e0 = A[o], e1 = A[o + 1], e2 = A[o + 2], e3 = A[o + 3], e4 = A[o + 4], e5 = A[o + 5], e6 = A[o + 6], e7 = A[o + 7], e8 = A[o + 8], e9 = A[o + 9], e10 = A[o + 10], e11 = A[o + 11];
|
|
2475
2589
|
const w = 1 / (e3 * gx + e7 * gy + e11 * gz + A[o + 15]);
|
|
@@ -2491,30 +2605,65 @@ function instancedBoundingSphere(im) {
|
|
|
2491
2605
|
dx = dx * inv * sr;
|
|
2492
2606
|
dy = dy * inv * sr;
|
|
2493
2607
|
dz = dz * inv * sr;
|
|
2494
|
-
|
|
2495
|
-
|
|
2608
|
+
for (let k = 0;k < 2; k++) {
|
|
2609
|
+
const px = k ? x - dx : x + dx, py = k ? y - dy : y + dy, pz = k ? z - dz : z + dz;
|
|
2610
|
+
if (r < 0) {
|
|
2611
|
+
cx = px;
|
|
2612
|
+
cy = py;
|
|
2613
|
+
cz = pz;
|
|
2614
|
+
r = 0;
|
|
2615
|
+
continue;
|
|
2616
|
+
}
|
|
2617
|
+
const vx = px - cx, vy = py - cy, vz = pz - cz;
|
|
2618
|
+
const l2 = vx * vx + vy * vy + vz * vz;
|
|
2619
|
+
if (l2 > r * r) {
|
|
2620
|
+
const l = Math.sqrt(l2);
|
|
2621
|
+
const d = (l - r) * 0.5;
|
|
2622
|
+
const f = d / l;
|
|
2623
|
+
cx += vx * f;
|
|
2624
|
+
cy += vy * f;
|
|
2625
|
+
cz += vz * f;
|
|
2626
|
+
r += d;
|
|
2627
|
+
}
|
|
2628
|
+
}
|
|
2496
2629
|
}
|
|
2630
|
+
S[0] = cx;
|
|
2631
|
+
S[1] = cy;
|
|
2632
|
+
S[2] = cz;
|
|
2633
|
+
S[3] = r;
|
|
2634
|
+
}
|
|
2635
|
+
function setSphere(im, S) {
|
|
2497
2636
|
const sph = im.boundingSphere ?? new THREE.Sphere;
|
|
2498
|
-
sph.center.set(
|
|
2499
|
-
sph.radius =
|
|
2500
|
-
if (
|
|
2637
|
+
sph.center.set(S[0], S[1], S[2]);
|
|
2638
|
+
sph.radius = S[3];
|
|
2639
|
+
if (S[3] < 0)
|
|
2501
2640
|
sph.makeEmpty();
|
|
2502
2641
|
im.boundingSphere = sph;
|
|
2503
2642
|
return sph;
|
|
2504
2643
|
}
|
|
2644
|
+
function instancedBoundingSphere(im, S = sphereState(im.geometry), set = true) {
|
|
2645
|
+
sphereUnion(S, im.instanceMatrix.array, im.count);
|
|
2646
|
+
return set ? setSphere(im, S) : S;
|
|
2647
|
+
}
|
|
2505
2648
|
function instancedBoundingBox(im) {
|
|
2506
|
-
const
|
|
2649
|
+
const B = boxState(im.geometry);
|
|
2650
|
+
if (!B)
|
|
2651
|
+
return;
|
|
2652
|
+
boxUnion(B, im.instanceMatrix.array, im.instanceMatrix.count);
|
|
2653
|
+
return boxOf(B);
|
|
2654
|
+
}
|
|
2655
|
+
function boxState(g) {
|
|
2507
2656
|
if (!g.boundingBox)
|
|
2508
2657
|
g.computeBoundingBox();
|
|
2509
2658
|
const gb = g.boundingBox;
|
|
2510
2659
|
if (gb.isEmpty())
|
|
2511
|
-
return;
|
|
2512
|
-
const hx = (gb.max.x - gb.min.x) / 2, hy = (gb.max.y - gb.min.y) / 2, hz = (gb.max.z - gb.min.z) / 2
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
let x0 =
|
|
2660
|
+
return null;
|
|
2661
|
+
const hx = (gb.max.x - gb.min.x) / 2, hy = (gb.max.y - gb.min.y) / 2, hz = (gb.max.z - gb.min.z) / 2;
|
|
2662
|
+
return Float64Array.of(Infinity, Infinity, Infinity, -Infinity, -Infinity, -Infinity, hx, hy, hz, gb.min.x + hx, gb.min.y + hy, gb.min.z + hz, 0);
|
|
2663
|
+
}
|
|
2664
|
+
function boxUnion(B, A, n) {
|
|
2665
|
+
const hx = B[6], hy = B[7], hz = B[8], gx = B[9], gy = B[10], gz = B[11];
|
|
2666
|
+
let x0 = B[0], y0 = B[1], z0 = B[2], x1 = B[3], y1 = B[4], z1 = B[5];
|
|
2518
2667
|
for (let i = 0;i < n; i++) {
|
|
2519
2668
|
const o = i * 16;
|
|
2520
2669
|
const cx = A[o] * gx + A[o + 4] * gy + A[o + 8] * gz + A[o + 12], cy = A[o + 1] * gx + A[o + 5] * gy + A[o + 9] * gz + A[o + 13], cz = A[o + 2] * gx + A[o + 6] * gy + A[o + 10] * gz + A[o + 14];
|
|
@@ -2532,8 +2681,15 @@ function instancedBoundingBox(im) {
|
|
|
2532
2681
|
if (cz + ez > z1)
|
|
2533
2682
|
z1 = cz + ez;
|
|
2534
2683
|
}
|
|
2535
|
-
|
|
2684
|
+
B[0] = x0;
|
|
2685
|
+
B[1] = y0;
|
|
2686
|
+
B[2] = z0;
|
|
2687
|
+
B[3] = x1;
|
|
2688
|
+
B[4] = y1;
|
|
2689
|
+
B[5] = z1;
|
|
2690
|
+
B[12] += n;
|
|
2536
2691
|
}
|
|
2692
|
+
var boxOf = (B) => B && B[12] > 0 ? Float32Array.of(B[0], B[1], B[2], B[3], B[4], B[5]) : undefined;
|
|
2537
2693
|
function batchedBoundingBox(bm) {
|
|
2538
2694
|
bm.computeBoundingBox();
|
|
2539
2695
|
const bb = bm.boundingBox;
|
|
@@ -3092,7 +3248,7 @@ function fillBucketIds(bIds, fill, studBucket, j0, j1) {
|
|
|
3092
3248
|
bIds[b][fill[b]++] = j;
|
|
3093
3249
|
}
|
|
3094
3250
|
}
|
|
3095
|
-
function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colorIndex) {
|
|
3251
|
+
function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colorIndex, trim = false) {
|
|
3096
3252
|
const bKind = [], bMat = [];
|
|
3097
3253
|
const bAll = [];
|
|
3098
3254
|
const studBucket = new Uint16Array(cull.nStuds);
|
|
@@ -3121,53 +3277,63 @@ function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colo
|
|
|
3121
3277
|
};
|
|
3122
3278
|
const matIdFor = (c, e, k) => e[k] >= 0 ? e[k] : e[k] = matIdOf(matOf(c, k === 1));
|
|
3123
3279
|
const partStud = new Map;
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
const
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3280
|
+
let jAt = 0;
|
|
3281
|
+
const pass1 = (idx) => {
|
|
3282
|
+
let j = jAt;
|
|
3283
|
+
const jEnd = j + 32768;
|
|
3284
|
+
for (;idx < insts.length && j < jEnd; idx++) {
|
|
3285
|
+
const it = insts[idx];
|
|
3286
|
+
const pp = prepPart(H, it.part);
|
|
3287
|
+
if (!pp || !pp.nStuds)
|
|
3288
|
+
continue;
|
|
3289
|
+
const a = it.m;
|
|
3290
|
+
const instE = colEntry(it.color);
|
|
3291
|
+
let ps = partStud.get(pp);
|
|
3292
|
+
if (!ps) {
|
|
3293
|
+
const kid = new Int32Array(pp.nStuds), neg = new Uint8Array(pp.nStuds);
|
|
3294
|
+
for (let si = 0;si < pp.nStuds; si++) {
|
|
3295
|
+
const kn = pp.kind[si];
|
|
3296
|
+
let id = kindIds.get(kn);
|
|
3297
|
+
if (id === undefined) {
|
|
3298
|
+
id = kindNames.length;
|
|
3299
|
+
kindIds.set(kn, id);
|
|
3300
|
+
kindNames.push(kn);
|
|
3301
|
+
}
|
|
3302
|
+
kid[si] = id;
|
|
3303
|
+
neg[si] = det12(pp.studM.subarray(si * 12, si * 12 + 12)) < 0 ? 1 : 0;
|
|
3141
3304
|
}
|
|
3142
|
-
|
|
3143
|
-
neg[si] = det12(pp.studM.subarray(si * 12, si * 12 + 12)) < 0 ? 1 : 0;
|
|
3305
|
+
partStud.set(pp, ps = { kid, neg });
|
|
3144
3306
|
}
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3307
|
+
const instNeg = det12(a) < 0 ? 1 : 0;
|
|
3308
|
+
const B = pp.studM;
|
|
3309
|
+
for (let si = 0;si < pp.nStuds; si++, j++) {
|
|
3310
|
+
const o = si * 12, b0 = B[o], b1 = B[o + 1], b2 = B[o + 2];
|
|
3311
|
+
const neg = (instNeg ^ ps.neg[si]) === 1;
|
|
3312
|
+
const km = ps.kid[si] * 2 + (neg ? 1 : 0);
|
|
3313
|
+
const sc = pp.color[si];
|
|
3314
|
+
const mid = sc === "16" ? matIdFor(it.color, instE, neg ? 1 : 0) : matIdFor(sc, colEntry(sc), neg ? 1 : 0);
|
|
3315
|
+
const row = bucketOfKM[mid];
|
|
3316
|
+
let b = row[km];
|
|
3317
|
+
if (b === undefined) {
|
|
3318
|
+
b = bKind.length;
|
|
3319
|
+
row[km] = b;
|
|
3320
|
+
bKind.push(kindNames[ps.kid[si]]);
|
|
3321
|
+
bMat.push(matList[mid]);
|
|
3322
|
+
bAll.push(0);
|
|
3323
|
+
}
|
|
3324
|
+
studBucket[j] = b;
|
|
3325
|
+
bAll[b]++;
|
|
3326
|
+
sx[j] = a[0] + a[3] * b0 + a[4] * b1 + a[5] * b2;
|
|
3327
|
+
sz[j] = a[2] + a[9] * b0 + a[10] * b1 + a[11] * b2;
|
|
3165
3328
|
}
|
|
3166
|
-
studBucket[j] = b;
|
|
3167
|
-
bAll[b]++;
|
|
3168
|
-
sx[j] = a[0] + a[3] * b0 + a[4] * b1 + a[5] * b2;
|
|
3169
|
-
sz[j] = a[2] + a[9] * b0 + a[10] * b1 + a[11] * b2;
|
|
3170
3329
|
}
|
|
3330
|
+
jAt = j;
|
|
3331
|
+
return idx;
|
|
3332
|
+
};
|
|
3333
|
+
for (let idx = 0;idx < insts.length; ) {
|
|
3334
|
+
if (idx)
|
|
3335
|
+
yield;
|
|
3336
|
+
idx = pass1(idx);
|
|
3171
3337
|
}
|
|
3172
3338
|
yield;
|
|
3173
3339
|
const bIds = bAll.map((n) => new Int32Array(n));
|
|
@@ -3198,10 +3364,10 @@ function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colo
|
|
|
3198
3364
|
sMesh.push(null);
|
|
3199
3365
|
continue;
|
|
3200
3366
|
}
|
|
3201
|
-
const
|
|
3202
|
-
im
|
|
3203
|
-
|
|
3204
|
-
sMesh.push({ im, kind, vis: v, ...steps ? { slots: { own: new Int32Array(n), hide: new Int32Array(n), inst: new Int32Array(n), stud: new Int16Array(n), col: new Uint16Array(n) } } : {} });
|
|
3367
|
+
const n = trim ? v : c.length;
|
|
3368
|
+
const im = newIM(g, bMat[b], n);
|
|
3369
|
+
im.instanceColor = new THREE.InstancedBufferAttribute(new Float32Array(n * 3), 3);
|
|
3370
|
+
sMesh.push({ im, kind, vis: v, all: c.length, ...steps ? { slots: { own: new Int32Array(n), hide: new Int32Array(n), inst: new Int32Array(n), stud: new Int16Array(n), col: new Uint16Array(n) } } : {} });
|
|
3205
3371
|
}
|
|
3206
3372
|
};
|
|
3207
3373
|
for (let b = 0;b < bKind.length; b++) {
|
|
@@ -3227,48 +3393,113 @@ function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colo
|
|
|
3227
3393
|
return x;
|
|
3228
3394
|
};
|
|
3229
3395
|
yield;
|
|
3396
|
+
let nH = 0;
|
|
3397
|
+
if (trim)
|
|
3398
|
+
for (let j = 0;j < cull.nStuds; j++)
|
|
3399
|
+
nH += cull.studHidden[j];
|
|
3400
|
+
const hidI = new Int32Array(nH), hidS = new Int32Array(nH), hidC = new Int32Array(nH);
|
|
3401
|
+
let nHid = 0;
|
|
3230
3402
|
{
|
|
3231
3403
|
const w = new Float64Array(12);
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
const
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
if (
|
|
3240
|
-
yield;
|
|
3241
|
-
mul12To(it.m, pp.studM, si * 12, w);
|
|
3242
|
-
const sm = sMesh[studCl[j]];
|
|
3243
|
-
if (!sm)
|
|
3404
|
+
jAt = 0;
|
|
3405
|
+
const pass3 = (idx) => {
|
|
3406
|
+
let j = jAt;
|
|
3407
|
+
const jEnd = j + 32768;
|
|
3408
|
+
for (;idx < insts.length && j < jEnd; idx++) {
|
|
3409
|
+
const it = insts[idx];
|
|
3410
|
+
const pp = prepPart(H, it.part);
|
|
3411
|
+
if (!pp || !pp.nStuds)
|
|
3244
3412
|
continue;
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3413
|
+
for (let si = 0;si < pp.nStuds; si++, j++) {
|
|
3414
|
+
if (trim && cull.studHidden[j]) {
|
|
3415
|
+
if (sMesh[studCl[j]]) {
|
|
3416
|
+
hidI[nHid] = idx;
|
|
3417
|
+
hidS[nHid] = si;
|
|
3418
|
+
hidC[nHid++] = studCl[j];
|
|
3419
|
+
}
|
|
3420
|
+
continue;
|
|
3421
|
+
}
|
|
3422
|
+
mul12To(it.m, pp.studM, si * 12, w);
|
|
3423
|
+
const sm = sMesh[studCl[j]];
|
|
3424
|
+
if (!sm)
|
|
3425
|
+
continue;
|
|
3426
|
+
const im = sm.im;
|
|
3427
|
+
const slot = studSlot[j];
|
|
3428
|
+
const sc = pp.color[si];
|
|
3429
|
+
const col = sc === "16" ? it.color : sc;
|
|
3430
|
+
if (sm.slots) {
|
|
3431
|
+
const t = sm.slots;
|
|
3432
|
+
t.own[slot] = steps[idx];
|
|
3433
|
+
t.hide[slot] = cull.studHideStep[j];
|
|
3434
|
+
t.inst[slot] = idx;
|
|
3435
|
+
t.stud[slot] = si;
|
|
3436
|
+
t.col[slot] = colorIndex(col);
|
|
3437
|
+
}
|
|
3438
|
+
writeM4(im.instanceMatrix.array, slot * 16, w);
|
|
3439
|
+
colorOf(col).toArray(im.instanceColor.array, slot * 3);
|
|
3440
|
+
}
|
|
3441
|
+
}
|
|
3442
|
+
jAt = j;
|
|
3443
|
+
return idx;
|
|
3444
|
+
};
|
|
3445
|
+
for (let idx = 0;idx < insts.length; ) {
|
|
3446
|
+
if (idx)
|
|
3447
|
+
yield;
|
|
3448
|
+
idx = pass3(idx);
|
|
3449
|
+
}
|
|
3450
|
+
}
|
|
3451
|
+
if (trim) {
|
|
3452
|
+
for (let c0 = 0;c0 < sMesh.length; c0 += 8) {
|
|
3453
|
+
yield;
|
|
3454
|
+
for (let ci = c0;ci < Math.min(sMesh.length, c0 + 8); ci++) {
|
|
3455
|
+
const sm = sMesh[ci];
|
|
3456
|
+
if (sm) {
|
|
3457
|
+
sm.S = instancedBoundingSphere(sm.im, undefined, false);
|
|
3458
|
+
if (LOD) {
|
|
3459
|
+
sm.B = boxState(sm.im.geometry);
|
|
3460
|
+
if (sm.B)
|
|
3461
|
+
boxUnion(sm.B, sm.im.instanceMatrix.array, sm.im.count);
|
|
3462
|
+
}
|
|
3256
3463
|
}
|
|
3257
|
-
writeM4(im.instanceMatrix.array, slot * 16, w);
|
|
3258
|
-
colorOf(col).toArray(im.instanceColor.array, slot * 3);
|
|
3259
3464
|
}
|
|
3260
3465
|
}
|
|
3466
|
+
for (let k0 = 0;k0 < nHid; k0 += 65536) {
|
|
3467
|
+
yield;
|
|
3468
|
+
hiddenStudSpheres(insts, H, hidI, hidS, hidC, sMesh, k0, Math.min(nHid, k0 + 65536));
|
|
3469
|
+
}
|
|
3261
3470
|
}
|
|
3262
3471
|
return sMesh;
|
|
3263
3472
|
}
|
|
3473
|
+
function hiddenStudSpheres(insts, H, hidI, hidS, hidC, sMesh, k0, k1) {
|
|
3474
|
+
const w = new Float64Array(12), A = new Float32Array(16);
|
|
3475
|
+
for (let k = k0;k < k1; k++) {
|
|
3476
|
+
const it = insts[hidI[k]];
|
|
3477
|
+
const pp = prepPart(H, it.part);
|
|
3478
|
+
const sm = sMesh[hidC[k]];
|
|
3479
|
+
mul12To(it.m, pp.studM, hidS[k] * 12, w);
|
|
3480
|
+
writeM4(A, 0, w);
|
|
3481
|
+
sphereUnion(sm.S, A, 1);
|
|
3482
|
+
if (sm.B)
|
|
3483
|
+
boxUnion(sm.B, A, 1);
|
|
3484
|
+
}
|
|
3485
|
+
}
|
|
3264
3486
|
function undersideGroups(ids, insts) {
|
|
3265
3487
|
const by = new Map;
|
|
3266
3488
|
const rest = [];
|
|
3489
|
+
let p4 = NaN, p7 = NaN, p10 = NaN, prev = rest;
|
|
3267
3490
|
for (const id of ids) {
|
|
3268
3491
|
const m = insts[id].m;
|
|
3492
|
+
if (m[4] === p4 && m[7] === p7 && m[10] === p10) {
|
|
3493
|
+
prev.push(id);
|
|
3494
|
+
continue;
|
|
3495
|
+
}
|
|
3496
|
+
p4 = m[4];
|
|
3497
|
+
p7 = m[7];
|
|
3498
|
+
p10 = m[10];
|
|
3269
3499
|
const l = Math.hypot(m[4], m[7], m[10]);
|
|
3270
3500
|
if (!(l > 0.000001)) {
|
|
3271
3501
|
rest.push(id);
|
|
3502
|
+
prev = rest;
|
|
3272
3503
|
continue;
|
|
3273
3504
|
}
|
|
3274
3505
|
const ax = [m[4] / l, m[7] / l, m[10] / l, l];
|
|
@@ -3277,11 +3508,13 @@ function undersideGroups(ids, insts) {
|
|
|
3277
3508
|
if (!g) {
|
|
3278
3509
|
if (by.size >= 12) {
|
|
3279
3510
|
rest.push(id);
|
|
3511
|
+
prev = rest;
|
|
3280
3512
|
continue;
|
|
3281
3513
|
}
|
|
3282
3514
|
by.set(k, g = { ids: [], ax });
|
|
3283
3515
|
}
|
|
3284
3516
|
g.ids.push(id);
|
|
3517
|
+
prev = g.ids;
|
|
3285
3518
|
}
|
|
3286
3519
|
const out = [...by.values()];
|
|
3287
3520
|
if (rest.length)
|
|
@@ -3694,15 +3927,35 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
3694
3927
|
const vis = uids.length - uids.reduce((a, i) => a + cull.underHidden[i], 0);
|
|
3695
3928
|
stats.undersTotal += uids.length;
|
|
3696
3929
|
stats.undersHidden += uids.length - vis;
|
|
3697
|
-
const
|
|
3698
|
-
|
|
3930
|
+
const trimU = !steps && !!P.cullUnder;
|
|
3931
|
+
const im = newIM(under, mat, trimU ? vis : uids.length);
|
|
3932
|
+
fillInstances(im, trimU ? ord.slice(0, vis) : ord, insts, color);
|
|
3699
3933
|
im.onBeforeRender = trackVp;
|
|
3700
3934
|
im.userData.ldrUnder = true;
|
|
3701
3935
|
im.userData.ldrPart = part;
|
|
3702
|
-
|
|
3936
|
+
let uB;
|
|
3937
|
+
if (trimU) {
|
|
3938
|
+
im.count = vis;
|
|
3939
|
+
const S = instancedBoundingSphere(im, undefined, false), A = new Float32Array(16);
|
|
3940
|
+
if (LOD) {
|
|
3941
|
+
uB = boxState(im.geometry);
|
|
3942
|
+
if (uB)
|
|
3943
|
+
boxUnion(uB, im.instanceMatrix.array, vis);
|
|
3944
|
+
}
|
|
3945
|
+
for (let k = vis;k < ord.length; k++) {
|
|
3946
|
+
writeM4(A, 0, insts[ord[k]].m);
|
|
3947
|
+
sphereUnion(S, A, 1);
|
|
3948
|
+
if (uB)
|
|
3949
|
+
boxUnion(uB, A, 1);
|
|
3950
|
+
}
|
|
3951
|
+
setSphere(im, S);
|
|
3952
|
+
} else
|
|
3953
|
+
instancedBoundingSphere(im);
|
|
3703
3954
|
im.count = P.cullUnder ? vis : uids.length;
|
|
3704
3955
|
root.add(im);
|
|
3705
3956
|
const cl = newCluster(im.boundingSphere, im);
|
|
3957
|
+
if (uB !== undefined)
|
|
3958
|
+
cl.b = boxOf(uB);
|
|
3706
3959
|
cl.lv.push({ objs: [im], err: 0 }, ...lodLevels(p.under, im, mat));
|
|
3707
3960
|
{
|
|
3708
3961
|
const bl = p.body?.lod;
|
|
@@ -3725,7 +3978,7 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
3725
3978
|
if (!o.isInstancedMesh)
|
|
3726
3979
|
o.geometry.instanceCount = im.count;
|
|
3727
3980
|
});
|
|
3728
|
-
const trim =
|
|
3981
|
+
const trim = trimU && vis < uids.length;
|
|
3729
3982
|
if (trim)
|
|
3730
3983
|
trimmed.under = true;
|
|
3731
3984
|
toggles.push({ mesh: countTo(() => objs), all: trim ? vis : uids.length, visible: vis, flag: "under" });
|
|
@@ -4019,7 +4272,7 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
4019
4272
|
}
|
|
4020
4273
|
}
|
|
4021
4274
|
yield root;
|
|
4022
|
-
const _studGen = buildStudMeshesGen(insts, H, cull, arr, LOD, color, (c, mirror) => materialFor(c, mirror, false), steps, steps && colorIndex);
|
|
4275
|
+
const _studGen = buildStudMeshesGen(insts, H, cull, arr, LOD, color, (c, mirror) => materialFor(c, mirror, false), steps, steps && colorIndex, !steps && !!P.cullStuds);
|
|
4023
4276
|
let _studR = _studGen.next();
|
|
4024
4277
|
while (!_studR.done) {
|
|
4025
4278
|
yield root;
|
|
@@ -4043,13 +4296,18 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
4043
4296
|
const im = sm.im;
|
|
4044
4297
|
const kind = sKind[ci];
|
|
4045
4298
|
const k = H.studKinds[kind];
|
|
4046
|
-
const vis = sVis[ci], all =
|
|
4047
|
-
|
|
4299
|
+
const vis = sVis[ci], all = sm.all;
|
|
4300
|
+
if (sm.S)
|
|
4301
|
+
setSphere(im, sm.S);
|
|
4302
|
+
else
|
|
4303
|
+
instancedBoundingSphere(im);
|
|
4048
4304
|
im.count = P.cullStuds ? vis : all;
|
|
4049
4305
|
im.onBeforeRender = trackVp;
|
|
4050
4306
|
im.userData.ldrStud = true;
|
|
4051
4307
|
root.add(im);
|
|
4052
4308
|
const cl = newCluster(im.boundingSphere, im);
|
|
4309
|
+
if (sm.B !== undefined)
|
|
4310
|
+
cl.b = boxOf(sm.B);
|
|
4053
4311
|
cl.studLineLv = 0;
|
|
4054
4312
|
cl.lv.push({ objs: [im], err: 0 });
|
|
4055
4313
|
const discObjs = [];
|
|
@@ -4104,7 +4362,7 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
4104
4362
|
if (!o.isInstancedMesh)
|
|
4105
4363
|
o.geometry.instanceCount = im.count;
|
|
4106
4364
|
});
|
|
4107
|
-
const trim = !steps && P.cullStuds &&
|
|
4365
|
+
const trim = !steps && P.cullStuds && vis < all;
|
|
4108
4366
|
if (trim)
|
|
4109
4367
|
trimmed.studs = true;
|
|
4110
4368
|
toggles.push({ mesh: countTo(() => objs), all: trim ? vis : all, visible: vis, flag: "studs" });
|
|
@@ -4364,7 +4622,7 @@ async function warmPackGeometry(pack, stop = () => false, sliceMs = 8) {
|
|
|
4364
4622
|
await new Promise((r) => setTimeout(r, 0));
|
|
4365
4623
|
}
|
|
4366
4624
|
}
|
|
4367
|
-
// ../../../../../../../tmp/ldr-build-
|
|
4625
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/scene.ts
|
|
4368
4626
|
import * as THREE2 from "three";
|
|
4369
4627
|
var _box = new THREE2.Box3;
|
|
4370
4628
|
var _m4 = new THREE2.Matrix4;
|
|
@@ -4719,10 +4977,10 @@ function createLdrObjectInner(instances, pack, options, progressive) {
|
|
|
4719
4977
|
return finish();
|
|
4720
4978
|
})();
|
|
4721
4979
|
}
|
|
4722
|
-
// ../../../../../../../tmp/ldr-build-
|
|
4980
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/parts-cdn.ts
|
|
4723
4981
|
import { decompress as decompress2 } from "fzstd";
|
|
4724
4982
|
|
|
4725
|
-
// ../../../../../../../tmp/ldr-build-
|
|
4983
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/embedded.ts
|
|
4726
4984
|
function splitFiles(text, fallback) {
|
|
4727
4985
|
const files = new Map;
|
|
4728
4986
|
let cur = null, saw = false, skip = false;
|
|
@@ -4797,7 +5055,7 @@ function embeddedKeys(text, names, fallback = "main.ldr") {
|
|
|
4797
5055
|
return out;
|
|
4798
5056
|
}
|
|
4799
5057
|
|
|
4800
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5058
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/parts-cdn.ts
|
|
4801
5059
|
var DEFAULT_PARTS_CDN = "https://ldr-demo.vercel.app/cdn/v1/";
|
|
4802
5060
|
var indexCache = new Map;
|
|
4803
5061
|
var shardCache = new Map;
|
|
@@ -5051,10 +5309,10 @@ async function prepareModel(source, o = {}) {
|
|
|
5051
5309
|
return { insts, pack, tier, missing, requests, bytes, cull, timings: { fetchModel: t1 - t0, parse: t2 - t1, parts: t3 - t2, ...cull ? { cull: performance.now() - t3 } : {} } };
|
|
5052
5310
|
}
|
|
5053
5311
|
|
|
5054
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5055
|
-
var load_worker_gen_default = 'var zt=ArrayBuffer,Q=Uint8Array,Me=Uint16Array,$t=Int16Array;var Ae=Int32Array,De=function(e,t,n){if(Q.prototype.slice)return Q.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 Q(n-t);return r.set(e.subarray(t,n)),r},he=function(e,t,n,r){if(Q.prototype.fill)return Q.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},jt=function(e,t,n,r){if(Q.prototype.copyWithin)return Q.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 Vt=["invalid zstd data","window size too large (>2046MB)","invalid block type","FSE accuracy too high","match distance too far back","unexpected EOF"],q=function(e,t,n){var r=Error(t||Vt[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,q);if(!n)throw r;return r},ot=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},_t=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},Gt=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)q(0);var u=6-s,f=i==3?4:i,a=ot(e,u,f);u+=f;var l=c?1<<c:s,m=ot(e,u,l)+(c==1&&256),g=m;if(!s){var b=1<<10+(e[5]>>3);g=b+(b>>3)*(e[5]&7)}if(g>2145386496)q(1);var y=new Q((t==1?m||g:t?0:g)+12);return y[0]=1,y[4]=4,y[8]=8,{b:u+l,y:0,l:0,d:a,w:t&&t!=1?t:y.subarray(12),e:g,o:new Ae(y.buffer,0,3),u:m,c:o,m:Math.min(131072,g)}}else if((n>>4|e[3]<<20)==25481893)return _t(e,4)+8;q(0)},ue=function(e){var t=0;for(;1<<t<=e;++t);return t-1},ge=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)q(3);var o=1<<s,i=o,c=-1,u=-1,f=-1,a=o,l=new zt(512+(o<<2)),m=new $t(l,0,256),g=new Me(l,0,256),b=new Me(l,512,o),y=512+(o<<1),A=new Q(l,y,o),v=new Q(l,y+o);while(c<255&&i>0){var p=ue(i+1),h=r>>3,M=(1<<p+1)-1,z=(e[h]|e[h+1]<<8|e[h+2]<<16)>>(r&7)&M,C=(1<<p)-1,L=M-i-1,I=z&C;if(I<L)r+=p,z=I;else if(r+=p+1,z>C)z-=L;if(m[++c]=--z,z==-1)i+=z,A[--a]=c;else i-=z;if(!z)do{var S=r>>3;u=(e[S]|e[S+1]<<8)>>(r&7)&3,r+=2,c+=u}while(u==3)}if(c>255||i)q(0);var w=0,x=(o>>1)+(o>>3)+3,P=o-1;for(var O=0;O<=c;++O){var E=m[O];if(E<1){g[O]=-E;continue}for(f=0;f<E;++f){A[w]=O;do w=w+x&P;while(w>=a)}}if(w)q(0);for(f=0;f<o;++f){var F=g[A[f]]++,X=v[f]=s-ue(F);b[f]=(F<<X)-o}return[r+7>>3,{b:s,s:A,n:v,t:b}]},Ht=function(e,t){var n=0,r=-1,s=new Q(292),o=e[t],i=s.subarray(0,256),c=s.subarray(256,268),u=new Me(s.buffer,268);if(o<128){var f=ge(e,t+1,6),a=f[0],l=f[1];t+=o;var m=a<<3,g=e[t];if(!g)q(0);var b=0,y=0,A=l.b,v=A,p=(++t<<3)-8+ue(g);for(;;){if(p-=A,p<m)break;var h=p>>3;if(b+=(e[h]|e[h+1]<<8)>>(p&7)&(1<<A)-1,i[++r]=l.s[b],p-=v,p<m)break;h=p>>3,y+=(e[h]|e[h+1]<<8)>>(p&7)&(1<<v)-1,i[++r]=l.s[y],A=l.n[b],b=l.t[b],v=l.n[y],y=l.t[y]}if(++r>255)q(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 z=0;for(n=0;n<r;++n){var C=i[n];if(C>11)q(0);z+=C&&1<<C-1}var L=ue(z)+1,I=1<<L,S=I-z;if(S&S-1)q(0);i[r++]=ue(S)+1;for(n=0;n<r;++n){var C=i[n];++c[i[n]=C&&L+1-C]}var w=new Q(I<<1),x=w.subarray(0,I),P=w.subarray(I);u[L]=0;for(n=L;n>0;--n){var O=u[n];he(P,n,O,u[n-1]=O+c[n]*(1<<L-n))}if(u[0]!=I)q(0);for(n=0;n<r;++n){var E=i[n];if(E){var F=u[E];he(x,n,F,u[E]=F+(1<<L-E))}}return[t,{n:P,b:L,s:x}]},Wt=ge(new Q([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],Kt=ge(new Q([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],Xt=ge(new Q([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],it=function(e,t){var n=e.length,r=new Ae(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Ue=new Q(new Ae([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),Zt=it(Ue,0),Oe=new Q(new Ae([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),Yt=it(Oe,3),me=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)q(0);var u=0,f=n.b,a=(r<<3)-8+ue(o)-f,l=-1;for(;a>c&&l<s;){var m=a>>3,g=(e[m]|e[m+1]<<8|e[m+2]<<16)>>(a&7);u=(u<<f|g)&i,t[++l]=n.s[u],a-=f=n.n[u]}if(a!=c||l+1!=s)q(0)},Jt=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,c=o+i;me(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),me(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),me(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,c),n),me(e.subarray(r),t.subarray(c),n)},Qt=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 he(n,e[s],t.y,t.y+=c),n;return he(new Q(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 De(e,s,u)}if(i==2){var f=e[s],a=f&3,l=f>>2&3,m=f>>4,g=0,b=0;if(a<2)if(l&1)m|=e[++s]<<4|(l&2&&e[++s]<<12);else m=f>>3;else if(b=l,l<2)m|=(e[++s]&63)<<4,g=e[s]>>6|e[++s]<<2;else if(l==2)m|=e[++s]<<4|(e[++s]&3)<<12,g=e[s]>>2|e[++s]<<6;else m|=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 Q(t.m),A=y.length-m;if(a==0)y.set(e.subarray(s,s+=m),A);else if(a==1)he(y,e[s++],A);else{var v=t.h;if(a==2){var p=Ht(e,s);g+=s-(s=p[0]),t.h=v=p[1]}else if(!v)q(0);(b?Jt:me)(e.subarray(s,s+=g),y.subarray(A),v)}var h=e[s++];if(h){if(h==255)h=(e[s++]|e[s++]<<8)+32512;else if(h>127)h=h-128<<8|e[s++];var M=e[s++];if(M&3)q(0);var z=[Kt,Xt,Wt];for(var C=2;C>-1;--C){var L=M>>(C<<1)+2&3;if(L==1){var I=new Q([0,0,e[s++]]);z[C]={s:I.subarray(2,3),n:I.subarray(0,1),t:new Me(I.buffer,0,1),b:0}}else if(L==2)r=ge(e,s,9-(C&1)),s=r[0],z[C]=r[1];else if(L==3){if(!t.t)q(0);z[C]=t.t[C]}}var S=t.t=z,w=S[0],x=S[1],P=S[2],O=e[u-1];if(!O)q(0);var E=(u<<3)-8+ue(O)-P.b,F=E>>3,X=0,se=(e[F]|e[F+1]<<8)>>(E&7)&(1<<P.b)-1;F=(E-=x.b)>>3;var oe=(e[F]|e[F+1]<<8)>>(E&7)&(1<<x.b)-1;F=(E-=w.b)>>3;var ae=(e[F]|e[F+1]<<8)>>(E&7)&(1<<w.b)-1;for(++h;--h;){var le=P.s[se],R=P.n[se],U=w.s[ae],B=w.n[ae],G=x.s[oe],k=x.n[oe];F=(E-=G)>>3;var T=1<<G,d=T+((e[F]|e[F+1]<<8|e[F+2]<<16|e[F+3]<<24)>>>(E&7)&T-1);F=(E-=Oe[U])>>3;var j=Yt[U]+((e[F]|e[F+1]<<8|e[F+2]<<16)>>(E&7)&(1<<Oe[U])-1);F=(E-=Ue[le])>>3;var N=Zt[le]+((e[F]|e[F+1]<<8|e[F+2]<<16)>>(E&7)&(1<<Ue[le])-1);if(F=(E-=R)>>3,se=P.t[se]+((e[F]|e[F+1]<<8)>>(E&7)&(1<<R)-1),F=(E-=B)>>3,ae=w.t[ae]+((e[F]|e[F+1]<<8)>>(E&7)&(1<<B)-1),F=(E-=k)>>3,oe=x.t[oe]+((e[F]|e[F+1]<<8)>>(E&7)&(1<<k)-1),d>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=d-=3;else{var D=d-(N!=0);if(D){if(d=D==3?t.o[0]-1:t.o[D],D>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=d}else d=t.o[0]}for(var C=0;C<N;++C)y[X+C]=y[A+C];X+=N,A+=N;var V=X-d;if(V<0){var _=-V,Y=t.e+V;if(_>j)_=j;for(var C=0;C<_;++C)y[X+C]=t.w[Y+C];X+=_,j-=_,V=0}for(var C=0;C<j;++C)y[X+C]=y[V+C];X+=j}if(X!=A)while(A<y.length)y[X++]=y[A++];else X=y.length;if(n)t.y+=X;else y=De(y,0,X)}else if(n){if(t.y+=m,A)for(var C=0;C<m;++C)y[C]=y[A+C]}else if(A)y=De(y,A);return t.b=u,y}q(2)},qt=function(e,t){if(e.length==1)return e[0];var n=new Q(t);for(var r=0,s=0;r<e.length;++r){var o=e[r];n.set(o,s),s+=o.length}return n};function ve(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=Gt(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=Qt(e,i,t);if(!c)q(5);if(t)i.e=i.y;else n.push(c),o+=c.length,jt(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 qt(n,o)}async function en(e){let t=e instanceof Uint8Array?e:new Uint8Array(e),n=(r)=>r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength);if(t[0]===40&&t[1]===181&&t[2]===47&&t[3]===253)return n(ve(t));if(t[0]===31&&t[1]===139)return new Response(new Blob([t]).stream().pipeThrough(new DecompressionStream("gzip"))).arrayBuffer();return n(t)}async function at(e){return new TextDecoder().decode(await en(e))}var lt=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split("/").pop()||"main.ldr").replace(/\\.(zst|gz)$/i,"")||"main.ldr";function Ce(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 ee=(e)=>e.trim().toLowerCase().replace(/\\\\/g,"/").replace(/\\/+/g,"/"),ze=/^[A-Za-z][A-Za-z0-9_]*$/,Ne=new Map;function $e(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(!Ne.has(r))Ne.set(r,t);return r}function je(e){let t=e.charCodeAt(0)|32;if(t>=97&&t<=122&&ze.test(e))return $e(e);if(/^0x/i.test(e))return parseInt(e,16);return+e}var ct=/^~?\\s*moved\\s+to\\s+(.+)$/i,tn=new Set(["FILE","NOFILE","!DATA","!:","STEP","BFC","ROTSTEP","BUFEXCHG","!TEXMAP"]),nn=new Set(["FILE","NOFILE","!DATA"]),bt=1000000000000000,yt=new Set(["part","subpart","primitive","8_primitive","48_primitive","shortcut","helper"]),rn=new Set(["model","submodel","configuration"]),sn=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function ut(e){let t=sn.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,"");return yt.has(n)||rn.has(n)?n:void 0}function on(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((l)=>Number.isFinite(l)&&Math.abs(l)<=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 l=0;l<s;l++)c=c.replace(/^\\S+\\s*/,"");let u=on(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 a=u.findIndex((l,m)=>m>0&&l.toUpperCase()==="GLOSSMAP");if(a>0&&u[a+1])f.glossmap=u[a+1];if(t)f.next=!0;return f}var ln=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,"");if(t.length%4===1)t=t.slice(0,-1);let n=t+"=".repeat((4-t.length%4)%4),r=atob(n),s=new Uint8Array(r.length);for(let o=0;o<r.length;o++)s[o]=r.charCodeAt(o);return s};function cn(e){let t=e.length,n=1,r=(a)=>a===32||a===9,s=()=>{while(n<t&&r(e.charCodeAt(n)))n++;let a=n;while(n<t&&!r(e.charCodeAt(n)))n++;return a<n?e.slice(a,n):null},o=s();if(o===null)return null;let i=Array(12);for(let a=0;a<12;a++){let l=s();if(l===null)return null;let m=+l;if(!Number.isFinite(m))return null;i[a]=m}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=je(o);if(!Number.isFinite(f))return null;return{t:1,color:f,m:i,file:ee(u)}}var un=[0,12,6,9,12,12];function ft(e){let t=+e[0];if(!(t>=1&&t<=5&&Number.isInteger(t))||e.length<2)return null;let n=je(e[1]),r=un[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=ee(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 xt(e,t="main.ldr",n={}){let r=!!n.geometryText,s=new Map,o=null,i="",c,u=null,f=[],a=null,l=()=>{if(!u)return;let p=ln(u.chunks.join("")),h=p[0]===137&&p[1]===80&&p[2]===78&&p[3]===71;(c??=new Map).set(ee(u.name),{name:u.name,bytes:p,...h?{mime:"image/png"}:{}}),u=null},m=!0,g=(p)=>{if(l(),o={name:ee(p),cmds:[]},s.set(o.name,o),!i)i=o.name;f=[],a=null,m=!0},b=!1,y=!1,A=()=>{if(y)return;y=!0,s.clear(),o=null,i=""},v=(p,h)=>{if(a){p.tex=a,a=null;return}let M=f[f.length-1];if(!M)return;if(M.fallback){if(!h)p.fallback=!0}else p.tex=M.map};for(let p of e.split(`\n`)){let h=p.trim();if(!h)continue;if(r&&h.charCodeAt(0)>=50&&h.charCodeAt(0)<=53&&(h.charCodeAt(1)===32||h.charCodeAt(1)===9)){if(u||b)continue;if(!o)g(t);let L=h.slice(2).trimStart(),I=L.search(/\\s/),S={t:h.charCodeAt(0)-48,color:je(I<0?L:L.slice(0,I)),p:[],src:h};v(S,!1),o.cmds.push(S),m=!1;continue}if(h.charCodeAt(0)===48&&(h.charCodeAt(1)===32||h.charCodeAt(1)===9)){let L=2;while(h.charCodeAt(L)===32||h.charCodeAt(L)===9)L++;let I=L;while(I<h.length&&h.charCodeAt(I)!==32&&h.charCodeAt(I)!==9)I++;let S=h.slice(L,I),w=/[^\\x21-\\x7e]/.test(S)?h.slice(L).trim().split(/\\s+/)[0]:S;if(!tn.has(w)&&!(w.length>=4&&w.length<=6&&nn.has(w.toUpperCase()))){if(b||u)continue;if(!o)g(t);let x=h.slice(L),P={t:0,text:x};if(S.charCodeAt(0)===33)P.meta=S;if(a=null,m&&!o.org){let E=ut(x);if(E)o.org=E}let O=x.match(ct);if(O&&!o.movedTo){let E=O[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(E))E+=".dat";o.movedTo=ee(E)}o.cmds.push(P);continue}}if(h.charCodeAt(0)===49&&(h.charCodeAt(1)===32||h.charCodeAt(1)===9)&&!u&&!b){let L=cn(h);if(L){if(!o)g(t);v(L,!1),o.cmds.push(L),m=!1;continue}}let M=h.split(/\\s+/);if(+M[0]===0){let L=h.slice(1).trim(),I=M.length>1&&M[1].length>=4&&M[1].length<=6?M[1].toUpperCase():M[1];if(I==="FILE"){let x=L.slice(5).trimStart().split("\\r")[0].trim();if(x){A(),b=!1,g(x);continue}}if(I==="NOFILE"){l(),o=null,b=!0;continue}if(I==="!DATA"){A(),l(),o=null,b=!1,u={name:L.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 S={t:0,text:L};if(M[1]==="STEP")S.step=!0,f=[],a=null;else if(M[1]==="BFC")S.bfc=M.slice(2).join(" ");else if(M[1]==="ROTSTEP")if(S.meta="ROTSTEP",S.step=!0,f=[],a=null,(M[2]??"").toUpperCase()==="END")S.rotstep={x:0,y:0,z:0,mode:"END"};else{let x=(M[5]??"REL").toUpperCase(),P=(O)=>{let E=Number(O);return Number.isFinite(E)?E:0};S.rotstep={x:P(M[2]),y:P(M[3]),z:P(M[4]),mode:["REL","ABS","ADD"].includes(x)?x:"REL"}}else if(M[1]==="BUFEXCHG"){S.meta="BUFEXCHG";let x=(M[2]??"").toUpperCase();S.bufexchg={op:x==="RETRIEVE"?"RETRIEVE":"STORE",buf:M[3]??"A"}}else if(M[1]?.startsWith("!"))S.meta=M[1];if(m&&!o.org){let x=ut(L);if(x)o.org=x}if(M[1]==="!TEXMAP"){let x=(M[2]??"").toUpperCase();if(a=null,x==="START"||x==="NEXT"){let P=an(L.replace(/^!TEXMAP\\s+\\S+/i,""),x==="NEXT");if(S.texmap={op:x,...P?{map:P}:{}},P)if((o.texmaps??=[]).push(P),x==="START")f.push({map:P,fallback:!1});else a=P}else if(x==="FALLBACK"){S.texmap={op:x};let P=f[f.length-1];if(P)P.fallback=!0}else if(x==="END")S.texmap={op:x},f.pop()}else if(M[1]==="!:"){a=null;let x=ft(M.slice(2));if(x)v(x,!0),S.geom=x}else a=null;let w=L.match(ct);if(w&&!o.movedTo){let x=w[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(x))x+=".dat";o.movedTo=ee(x)}o.cmds.push(S);continue}if(u||b)continue;if(!o)g(t);let C=ft(M);if(!C){if(/^[2-5][ \\t]/.test(h))m=!1;continue}v(C,!1),o.cmds.push(C),m=!1}return l(),c?{main:i,files:s,data:c}:{main:i,files:s}}var On=Math.PI/180;function wt(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 Mt(e,t){let[n,r,s,o,i,c,u,f,a,l,m,g]=e,[b,y,A,v,p,h,M,z,C,L,I,S]=t;return[o*b+i*y+c*A+n,u*b+f*y+a*A+r,l*b+m*y+g*A+s,o*v+i*M+c*L,o*p+i*z+c*I,o*h+i*C+c*S,u*v+f*M+a*L,u*p+f*z+a*I,u*h+f*C+a*S,l*v+m*M+g*L,l*p+m*z+g*I,l*h+m*C+g*S]}var Ve=[0,0,0,1,0,0,0,1,0,0,0,1];var pt=new WeakMap,fn=/^(s|8|48)\\//;function _e(e,t){let n=e.files.get(ee(t));if(!n)return"part";let r=pt.get(n);if(r)return r;if(n.org)r=yt.has(n.org)?"part":"model";else if(n.name===e.main)r="model";else r=n.cmds.some((s)=>s.t>=2||s.t===0&&!!s.geom||s.t===1&&fn.test(s.file))?"part":"model";return pt.set(n,r),r}var mt=new WeakMap;function At(e){let t=mt.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 mt.set(e,t),t}var ht=(e)=>e>16777215?"0x"+e.toString(16).toUpperCase():e<0?Ne.get(e)??String(e):String(e),pn=(e)=>e.t===0?"0 "+e.text:e.t===1?`1 ${ht(e.color)} ${e.m.join(" ")} ${e.file}`:e.src?e.src:`${e.t} ${ht(e.color)} ${e.p.join(" ")}`,Ge=(e,t)=>`${ee(e)}#${t}`;function mn(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:Ge(e.name,t),cmds:n}}function vt(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...mn(e,t).cmds.map(pn)].join(`\n`)+`\n`}function He(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 Ct(e){let[t,n,r,s,o,i,c,u,f,a,l,m]=e,g=u*m-f*l,b=-(c*m-f*a),y=c*l-u*a,A=s*g+o*b+i*y;if(!Number.isFinite(A)||Math.abs(A)<0.000000000001)return null;let v=1/A,p=[g*v,-(o*m-i*l)*v,(o*f-i*u)*v,b*v,(s*m-i*a)*v,-(s*f-i*c)*v,y*v,-(s*l-o*a)*v,(s*u-o*c)*v];return[-(p[0]*t+p[1]*n+p[2]*r),-(p[3]*t+p[4]*n+p[5]*r),-(p[6]*t+p[7]*n+p[8]*r),...p]}var hn=(e)=>String(+e.toFixed(6)||0),gt=(e)=>\'"\'+e.replace(/\\\\/g,"\\\\\\\\").replace(/"/g,"\\\\\\"")+\'"\';function Tt(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!=="PLANAR"?[t.a??360]:[],...t.method==="SPHERICAL"?[t.b??180]:[]].map(hn).join(" "),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${gt(t.texture)}${t.glossmap?" GLOSSMAP "+gt(t.glossmap):""}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${ee(e)}\n0 !TEXMAP END\n`;return{name:`${ee(e)}#tex-${He(r)}`,source:r}}var gn=(e,t)=>{let n=[,,,,,,,,,];for(let r=0;r<3;r++)for(let s=0;s<3;s++)n[r*3+s]=e[r*3]*t[s]+e[r*3+1]*t[3+s]+e[r*3+2]*t[6+s];return n};function dn(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),c=Math.cos(t*r),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 dt=new WeakMap;function Lt(e){let t=dt.get(e);if(t)return t;let n=[],r=null;for(let s of e.cmds){if(s.t!==0||!s.step)continue;let o=s.rotstep;if(o)if(o.mode==="END")r=null;else{let i=dn(o.x,o.y,o.z);r=o.mode==="ABS"?{abs:!0,m:i,rotstep:o}:o.mode==="ADD"&&r?{abs:r.abs,m:gn(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),dt.set(e,n),n}class We 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 bn=(e)=>{for(let t=0;t<12;t++)if(!(Math.abs(e[t])<=bt))return!1;return!0},St=999999,Pt=(e)=>e.map((t)=>String(t).padStart(6,"0")).join(".")+"~",Ft=new WeakMap,Et=new WeakMap;function yn(e,t){let n=Et.get(t);if(!n)n={head:[...t.values()].map((o)=>{let i=Ft.get(o)??"",c=i.indexOf("!COLOUR");return c<0?"":"0 "+i.slice(c).trim().replace(/\\s+/g," ")}).filter(Boolean).join(`\n`),parts:new Map},Et.set(t,n);let r=n.parts.get(e);if(!r){let s=ee(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-${He(o)}`,source:o},n.parts.set(e,r)}return r}function xn(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,a=t.maxInstances??2000000,l=0,m=(b,y)=>{let A=b.name+"#"+y,v=c.get(A);if(!v){let p;v=Object.assign(()=>p??=vt(b,y),{file:b,step:y}),c.set(A,v)}return v},g=(b,y,A,v,p,h,M,z,C=null,L=[],I=[],S=void 0,w=null)=>{let x=b.files.get(y);if(!x||M>r||f.has(x))return;if(++l>a)throw new We("model",a);f.add(x);let P=w,O=0,E=M>0?++u:0,F=i&&E?[...L,E]:L,X=i&&E?[...I,A]:I,se=i&&!C?new Map:null,oe=-1,ae=0,le=(T,d,j,N,D,V,_)=>{if(oe!==O)oe=O,ae=0;let Y=se?.get(O+"|"+d);if(Y)return Y.n++,g(T,T===b?d:T.main,j,N,p+"/"+d,[...D,St],M+1,V,[...D,St],F,X,_,P);let J=[...D,ae++],H=n.length;g(T,T===b?d:T.main,j,N,p+"/"+d,J,M+1,V,C,F,X,_,P),se?.set(O+"|"+d,{n:1,from:H,to:n.length})},R=Lt(x),U=s?At(x):[],B=0,G=(T,d,j,N,D,V,_,Y,J)=>{if(C)N=C;if(++l>a)throw new We("model",a);let H={part:T,color:d,m:j,step:N[0],steps:N,localStep:D,path:p};if(Y)H.colour=Y;if(E){if(H.sub=E,i)H.subPath=F,H.subMats=X}if(V)H.embedded=!0;if(_){let ne=Tt(T,_);H.texPart=ne.name,H.texSource=ne.source}else if(J){let ne=yn(T,J);H.colPart=ne.name,H.colSource=ne.source}let W=R[D];if(W)H.view=W;return n.push(H),H},k=(T)=>{while(B<U.length&&U[B]<=T){let d=U[B++];G(Ge(x.name,d),v,A,[...h,d],d,!1,null,S,w).source=m(x,d)}};for(let T of x.cmds){if(T.t===0&&T.step){O++;continue}let d=T;if(d.t>=2||d.t===0&&d.geom&&d.geom.t>=2){k(O);continue}if(d.t===0){if(d.meta==="!COLOUR"){let W=Mn(d.text);if(W&&W.code!==16&&W.code!==24)Ft.set(W,d.text),(P=new Map(P??[])).set(W.code,W);continue}if(o&&d.geom?.t===1)d=d.geom;else continue}if(d.t!==1)continue;if(o&&d.fallback)continue;let j=Mt(A,d.m);if(!bn(j))continue;let N=d.color===16?v:d.color,D=d.color===16?S:P?.get(d.color),V=[...h,O],_=o?d.tex??z:null,Y=_?Ct(d.m):null,J=_&&Y?wt(_,Y):null;if(b.files.has(d.file)){if(_e(b,d.file)==="model"){le(b,d.file,j,N,V,J,D);continue}G(d.file,N,j,V,O,!0,J,D,P);continue}let H=t.resolveModel?.(d.file);if(H){le(H,d.file,j,N,V,J,D);continue}G(d.file,N,j,V,O,!1,J,D,P)}if(k(1/0),f.delete(x),se){for(let T of se.values())if(T.n>1)for(let d=T.from;d<T.to;d++)n[d].mult??=T.n}};if(_e(e,e.main)==="part"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...Ve],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return g(e,e.main,Ve,16,e.main,[],0,null),n}function Rt(e,t="main.ldr",n){return xn(xt(e,t,{geometryText:!0}),n)}var wn=new Set(["CHROME","PEARLESCENT","RUBBER","MATTE_METALLIC","METAL","MATERIAL"]);function Ke(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 kt(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=Ke(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 Mn(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"},a=1;while(a<n.length){let l=n[a].toUpperCase(),m=n[a+1];if(l==="CODE")s=m!==void 0&&ze.test(m)?$e(m):m!==void 0&&/^\\d+$/.test(m)?+m:NaN,a+=2;else if(l==="VALUE"){let g=Ke(m);if(g)o=g;a+=2}else if(l==="EDGE")i=Ke(m)??m,a+=2;else if(l==="ALPHA")c=+m,a+=2;else if(l==="LUMINANCE")u=+m,a+=2;else if(l==="CHROME")f={type:"chrome"},a+=1;else if(l==="PEARLESCENT")f={type:"pearlescent"},a+=1;else if(l==="RUBBER")f={type:"rubber"},a+=1;else if(l==="MATTE_METALLIC")f={type:"matte_metallic"},a+=1;else if(l==="METAL")f={type:"metal"},a+=1;else if(l==="MATERIAL"){let g=(n[a+1]||"").toUpperCase();if(g==="GLITTER"){let{grain:b,next:y}=kt(n,a+2);f={type:"glitter",material:b},a=y}else if(g==="SPECKLE"){let{grain:b,next:y}=kt(n,a+2);f={type:"speckle",material:b},a=y}else if(g==="FABRIC"){let b=(n[a+2]||"").toUpperCase(),y=["VELVET","CANVAS","STRING","FUR"].includes(b)?b.toLowerCase():void 0;f={type:"fabric",kind:y},a+=y?3:2}else a=n.length}else if(wn.has(l))a+=1;else a+=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 An(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 Xe(e){let t=An(e),n=!t.transparent?"op":t.opacity>=0.75?"a200":t.opacity>=0.4?"a128":`a${Math.round(t.opacity*255)}`,r=t.emissive>0?`L${Math.round(t.emissive*16)}`:"",s=`${t.finish}:${n}${r}`;if(t.particleHex)s+=`:${t.particleHex}:${(t.particleFraction??0).toFixed(2)}`;return s}function vn(e,t){let n=new Map,r=null,s=!1,o=!1;for(let i of e.split(/\\r?\\n/)){let c=/^\\s*0\\s+FILE\\s+(\\S[^\\r]*)/i.exec(i);if(c){if(!s)n.clear();s=!0,o=!1,r=[],n.set(ee(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(ee(t),r)}let u=i.trim().replace(/\\s+/g," ");if(u)r.push(u)}return n}var Cn=(e)=>{if(!e.startsWith("1 "))return null;let t=e.split(" ");return t.length>=15?ee(t.slice(14).join(" ")):null};function Tn(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 It(e,t,n="main.ldr"){let r=vn(e,n),s=new Map;for(let o of t){let i=ee(o);if(!r.has(i)||s.has(i))continue;let c=new Set([i]),u=[i];while(u.length)for(let a of r.get(u.pop())){let l=Cn(a);if(l&&r.has(l)&&!c.has(l))c.add(l),u.push(l)}let f=[i,...[...c].filter((a)=>a!==i).sort()].map((a)=>"0 FILE "+(a===i?"":a)+`\n`+r.get(a).join(`\n`)).join(`\n`);s.set(i,`emb/${Tn(f)}.dat`)}return s}var Bt=(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,Dt=new WeakMap,Ze=null,Ye="",Je=null;function Qe(e,t){if(e===Ze&&t===Ye)return Je;let n=Dt.get(e);if(!n)Dt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return Ze=e,Ye=t,Je=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((m,g)=>{c.push(m[0]),u.push(m[1]);for(let b=0;b<12;b++)i[g*12+b]=m[2+b]});let f=null,a=0,l=0;if(s.mask){a=s.mask[0],l=s.mask[1];let m=s.mask[2];f=new Uint8Array(m.length);for(let g=0;g<m.length;g++)f[g]=m.charCodeAt(g)===49?1:0}return n.set(t,r={nStuds:o,studM:i,kind:c,color:u,mask:f,nx:a,nz:l}),Ze=e,Ye=t,Je=r,r}var fe=1073741824;class be{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=be.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=be.tagOf(e,t,n),o=this.tag,i=this.t,c=this.mask,u=this.slot(e,t,n);for(;;){let f=o[u],a=u<<2;if(f===0)return o[u]=s,i[a]=e,i[a+1]=t,i[a+2]=n,i[a+3]=r,this.size++,-1;if(f===s&&i[a]===e&&i[a+1]===t&&i[a+2]===n){let l=i[a+3];return i[a+3]=r,l}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])}}}var pe=(e,t,n)=>e>-fe&&e<fe&&t>-fe&&t<fe&&n>-fe&&n<fe,de=2147483647;function Ln(e,t){let n=e.colorTable?.[t];if(n)return(n.alpha??255)<255;return t.charCodeAt(0)===35&&/\\/[^:/]*:a\\d/.test(t)}function Sn(e,t,n){let s=new Map,o=(R)=>{let U=s.get(R);if(U===void 0)s.set(R,U=Ln(t,R));return U},i=[],c=[],u=[],f=[],a=[],l=[],m=[],g=[],b=[],y=[],A=[],v=new be(e.length*2),p=[],h=[];for(let R=0;R<e.length;R++){let U=e[R],B=U.m,G=t.parts[U.part];if(!G||!G.mask||!Bt(B)||o(U.color))continue;let k=G.bbox,T=1/0,d=-1/0,j=1/0,N=-1/0;for(let K=0;K<2;K++)for(let Z=0;Z<2;Z++){let te=K?k[3]:k[0],ce=Z?k[5]:k[2],ie=B[0]+B[3]*te+B[5]*ce,re=B[2]+B[9]*te+B[11]*ce;if(ie<T)T=ie;if(ie>d)d=ie;if(re<j)j=re;if(re>N)N=re}let D=Math.round((B[1]+k[4])*2),V=Qe(t,U.part),_=Math.floor(T/40),Y=Math.floor(d/40),J=Math.floor(j/40),H=Math.floor(N/40);if(!((Y-_+1)*(H-J+1)<=65536)||!pe(D,_,J)||!pe(D,Y,H))continue;let W=-1;for(let K=v.get(D,_,J),Z=0;K>=0&&Z<8;K=p[K],Z++){let te=h[K];if(i[te]!==T||c[te]!==d||u[te]!==j||f[te]!==N||m[te]!==V)continue;let ce=e[a[te]].m,ie=!0;for(let re=0;re<12;re++)if(ce[re]!==B[re]){ie=!1;break}if(ie){W=te;break}}if(W>=0){let K=n?n[R]:0;if(n&&K<n[a[W]])l[W]=a[W],a[W]=R;else if(l[W]<0||n&&K<n[l[W]])l[W]=R;continue}let ne=a.length;i.push(T),c.push(d),u.push(j),f.push(N),a.push(R),l.push(-1),m.push(V),g.push(k[0]),b.push(k[2]),y.push(D),A.push(B[0],B[1],B[2],B[3],B[6],B[9],B[5],B[8],B[11]);for(let K=_;K<=Y;K++)for(let Z=J;Z<=H;Z++){if(!pe(D,K,Z))continue;let te=h.length;h.push(ne),p.push(v.put(D,K,Z,te))}}let M=[0,5,-5,5,-5],z=[0,5,5,-5,-5],C=(R,U,B,G)=>{if(!(U-6>=i[R]-0.5&&U+6<=c[R]+0.5&&G-6>=u[R]-0.5&&G+6<=f[R]+0.5))return!1;let k=R*9,T=m[R],d=g[R],j=b[R],N=U-A[k],D=B-A[k+1],V=G-A[k+2],_=A[k+3]*N+A[k+4]*D+A[k+5]*V,Y=A[k+6]*N+A[k+7]*D+A[k+8]*V,{nx:J,nz:H,mask:W}=T;for(let ne=0;ne<5;ne++){let K=Math.floor((_+M[ne]-d)/20),Z=Math.floor((Y+z[ne]-j)/20);if(K<0||Z<0||K>=J||Z>=H||W[K*H+Z]!==1)return!1}return!0},L=NaN,I=NaN,S=NaN,w=-1,x=-1,P=(R,U,B,G)=>{let k=Math.round(U*2),T=Math.floor(R/40),d=Math.floor(B/40);if(!pe(k,T,d))return de;let j=de;if(!n&&x>=0&&y[x]===k&&(a[x]!==G||l[x]>=0)&&C(x,R,U,B))return 0;if(k!==L||T!==I||d!==S)L=k,I=T,S=d,w=v.get(k,T,d);for(let N=w;N>=0;N=p[N]){let D=h[N],V=a[D];if(V===G&&(V=l[D])<0)continue;if(!C(D,R,U,B))continue;if(!n)return x=D,0;let _=n[V];if(_<j)j=_}return j},O=0;for(let R of e){let U=Qe(t,R.part);if(U)O+=U.nStuds}let E=new Uint8Array(O),F=new Uint8Array(O),X=new be(O,4),se=0,oe=n?new Int32Array(O).fill(de):void 0;for(let R=0,U=0;R<e.length;R++){let B=e[R],G=Qe(t,B.part);if(!G)continue;let k=B.m,T=G.studM,d=k[0],j=k[1],N=k[2],D=k[3],V=k[4],_=k[5],Y=k[6],J=k[7],H=k[8],W=k[9],ne=k[10],K=k[11];for(let Z=0;Z<G.nStuds;Z++,U++){let te=Z*12,ce=T[te+4],ie=T[te+7],re=T[te+10];if(!(Math.abs(Y*ce+J*ie+H*re-1)<0.001&&Math.abs(D*ce+V*ie+_*re)<0.001&&Math.abs(W*ce+ne*ie+K*re)<0.001))continue;F[U]=1;let Re=T[te],Ie=T[te+1],Be=T[te+2],qe=d+D*Re+V*Ie+_*Be,et=j+Y*Re+J*Ie+H*Be,tt=N+W*Re+ne*Ie+K*Be,nt=P(qe,et,tt,R);if(nt!==de){if(E[U]=1,se++,oe)oe[U]=nt}let ye=Math.round(qe),xe=Math.round(et),we=Math.round(tt);if(!pe(ye,xe,we))continue;if(!n){X.put(ye,xe,we,1);continue}let rt=n[R],st=X.get(ye,xe,we);if(st<0||rt<st)X.put(ye,xe,we,rt)}}let ae=new Uint8Array(e.length),le=n?new Int32Array(e.length).fill(de):void 0;for(let R=0;R<e.length;R++){let U=e[R],B=t.parts[U.part];if(!B||!B.under||!Bt(U.m)||o(U.color))continue;let G=B.bbox,k=Math.round((G[3]-G[0])/20),T=Math.round((G[5]-G[2])/20);if(!k||!T||k*T>4096)continue;let d=U.m,j=Math.round(d[1]+G[4]),N=!0,D=0;for(let V=0;V<k&&N;V++)for(let _=0;_<T;_++){let Y=G[0]+10+20*V,J=G[2]+10+20*_,H=d[0]+d[3]*Y+d[5]*J,W=d[2]+d[9]*Y+d[11]*J,ne=Math.round(H),K=Math.round(W),Z=pe(ne,j,K)?X.get(ne,j,K):-1;if(Z<0){N=!1;break}if(Z>D)D=Z}if(N){if(ae[R]=1,le)le[R]=D}}return{nStuds:O,studHidden:E,studUp:F,underHidden:ae,studsHidden:se,studHideStep:oe,underHideStep:le}}function En(e,t,n){let r=(l)=>l.colPart&&t.parts[l.colPart]?l.colPart:n&&l.texPart&&t.parts[l.texPart]?l.texPart:l.part,s=new Map,o=new Map,i=(l)=>{let m=l.colour;if(!m)return String(l.color);let g=o.get(m);if(g!==void 0)return g;let b=t.colorTable?.[l.color],y=b?.hex??t.colors?.[l.color],A=b?Xe({alpha:b.alpha??255,luminance:b.luminance??0,finish:b.finish??{type:"default"}}):"default:op",v=Xe(m);if(g=y&&y.toUpperCase()===m.hex.toUpperCase()&&A===v?String(l.color):m.hex.toUpperCase()+"/"+v,g!==String(l.color))s.set(g,m);return o.set(m,g),g},c=e.map((l)=>({part:r(l),color:i(l),m:l.m,steps:l.steps})),u=c.map((l)=>Pt(l.steps)),f=[...new Set(u)].sort(),a=new Map(f.map((l,m)=>[l,m]));return{all:c,stepOf:u.map((l)=>a.get(l)),nSteps:f.length,localColours:s}}function Te(e,t,n=!0){let r=En(e,t,n);return Sn(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Pe="https://ldr-demo.vercel.app/cdn/v1/",Se=new Map,Le=new Map;function Ee(e=Pe,t=fetch){let n=Se.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(()=>Se.delete(e)),Se.set(e,n);return n}var kn=(e)=>Array.isArray(e)&&e.length===3&&typeof e[0]==="number"&&typeof e[1]==="number"&&(e[2]==="f32"||e[2]==="u16"||e[2]==="u8"||e[2]==="u32"),ke=(e,t)=>kn(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>ke(n,t)):e&&typeof e==="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,ke(r,t)])):e;function Pn(e,t={}){let n=[],r=0,s={},o={};for(let m of e){let g=m.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),A=r;n.push(y),r+=y.byteLength;let v=(4-r%4)%4;if(v)n.push(new Uint8Array(v)),r+=v;for(let[p,h]of Object.entries(m.header.parts??{}))if(!(p in s))s[p]=ke(h,A);for(let[p,h]of Object.entries(m.header.studKinds??{}))if(!(p in o))o[p]=ke(h,A)}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,a=new Uint8Array(f+r);new DataView(a.buffer).setUint32(0,c.length+u,!0),a.set(c,4),a.fill(32,4+c.length,f);let l=f;for(let m of n)a.set(m,l),l+=m.byteLength;return Ce(a.buffer)}async function Fn(e,t={}){e=[...e];try{return await Ut(e,t)}catch(n){let r=t.cdn??Pe,s=t.fetch??fetch;Se.delete(r);let o=(i,c)=>s(i,{...c,cache:"reload"});try{return await Ut(e,{...t,fetch:o})}catch{throw n}}}async function Ut(e,t){let n=t.cdn??Pe,r=t.fetch??fetch,s=t.gap??16384,o=await Ee(n,r),i=[...new Set([...e].map(ee))],c=[],u=[];for(let p of i){if(Le.has(n+p))continue;let h=o.parts[p];if(h)u.push({name:p,off:h[0],len:h[1],file:h[2]??0});else c.push(p)}u.sort((p,h)=>p.file-h.file||p.off-h.off);let f=[];for(let p of u){let h=f[f.length-1];if(h&&h.file===p.file&&p.off-h.end<=s)h.end=Math.max(h.end,p.off+p.len),h.items.push(p);else f.push({file:p.file,start:p.off,end:p.off+p.len,items:[p]})}let a=0,l=0,m=0,g=new Map,b=async()=>{while(m<f.length){let p=f[m++],h=g.get(p.file);if(h)h=h.subarray(p.start,p.end);else{let M=await r(new URL(o.archives[p.file],n).href,{headers:{Range:`bytes=${p.start}-${p.end-1}`,"Accept-Encoding":"identity"}});if(!M.ok)throw Error(`ldr: parts CDN ${M.status}`);if(l++,h=new Uint8Array(await M.arrayBuffer()),a+=h.byteLength,M.status===200)g.set(p.file,h),h=h.subarray(p.start,p.end)}for(let M of p.items){let z=ve(h.subarray(M.off-p.start,M.off-p.start+M.len)),C=z.buffer.slice(z.byteOffset,z.byteOffset+z.byteLength);Le.set(n+M.name,Ce(C))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,f.length)},b));let y=i.filter((p)=>Le.has(n+p)).map((p)=>Le.get(n+p)),A={colors:o.colors,...o.colorTable?{colorTable:o.colorTable}:{}};return{pack:y.length?Pn(y,A):Ce(Rn(A)),missing:c,requests:l,bytes:a}}function Rn(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 In(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 Ot(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):ee(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 Fe 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 Nt(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=Ee(t.cdn??Pe,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 at(await w.arrayBuffer())}),i=performance.now(),c=t.name??(t.text?"main.ldr":lt(e)),u=Rt(o,c,{looseGeometry:!1,callouts:t.callouts}),f=performance.now();t.onParsed?.(u),await s;let a=It(o,new Set(u.filter((w)=>w.embedded).map((w)=>w.part)),c),l=(w,x)=>t.maxBodyTris!=null&&w>t.maxBodyTris||t.maxPackBytes!=null&&x>t.maxPackBytes,m=t.maxBodyTris!=null||t.maxPackBytes!=null,g=(w)=>new Fe({...w,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes}),b="full";if(m){let w=Ot(u,a,await s);if(l(w.known?w.bodyTris:0,w.packBytes)){if(!t.lowCdn)throw g(w);let x=await Ee(t.lowCdn,r).catch(()=>null);if(!x)throw g(w);let P=Ot(u,a,x);if(l(P.known?P.bodyTris:0,P.packBytes))throw g(P);b="low"}}let y=[...u.filter((w)=>!w.embedded).map((w)=>w.part),...a.values()],A=async()=>{let w=await Fn(y,b==="low"?{...t,cdn:t.lowCdn}:t);for(let[x,P]of a){let O=w.pack.header.parts[P];if(O)w.pack.header.parts[x]=O}return{...w,packBytes:w.pack.buffer?.byteLength??w.pack.bytes??0,bodyTris:In(u,w.pack)}},v=await A();if(m&&l(v.bodyTris,v.packBytes)&&b==="full"&&t.lowCdn&&await Ee(t.lowCdn,r).then(()=>!0,()=>!1)){b="low";let w=v;v=await A(),v.requests+=w.requests,v.bytes+=w.bytes}if(m&&l(v.bodyTris,v.packBytes))throw g(v);let{pack:p,missing:h,requests:M,bytes:z}=v,C=new Map([...a].map(([w,x])=>[x,w])),L=h.map((w)=>C.get(w)??w),I=performance.now(),S=t.cull?Te(u,p.header,t.textures!==!1):void 0;return{insts:u,pack:p,tier:b,missing:L,requests:M,bytes:z,cull:S,timings:{fetchModel:i-n,parse:f-i,parts:I-f,...S?{cull:performance.now()-I}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await Nt(n,{...r,cull:!1,onParsed:(a)=>self.postMessage({id:t,insts:a})}),o=s.pack.buffer;if(self.postMessage({id:t,buffer:o,tier:s.tier,missing:s.missing,requests:s.requests,bytes:s.bytes,timings:s.timings},[o]),!r.cull)return;let i=performance.now(),c=Te(s.insts,s.pack.header,r.textures!==!1),u=performance.now()-i,f=[];for(let a of[c.studHidden,c.studUp,c.underHidden,c.studHideStep,c.underHideStep])if(a)f.push(a.buffer);self.postMessage({id:t,cull:c,ms:u},f)}catch(s){if(s instanceof Fe||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';
|
|
5312
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/load-worker.gen.ts
|
|
5313
|
+
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';
|
|
5056
5314
|
|
|
5057
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5315
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/cdn.ts
|
|
5058
5316
|
var worker;
|
|
5059
5317
|
var seq = 0;
|
|
5060
5318
|
var pending = new Map;
|