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/node/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/spec.ts
|
|
2
2
|
var norm = (s) => s.trim().toLowerCase().replace(/\\/g, "/").replace(/\/+/g, "/");
|
|
3
3
|
var COLOUR_ID_RE = /^[A-Za-z][A-Za-z0-9_]*$/;
|
|
4
4
|
var namedCodes = new Map;
|
|
@@ -802,7 +802,7 @@ function fileStepViews(f) {
|
|
|
802
802
|
viewMemo.set(f, out);
|
|
803
803
|
return out;
|
|
804
804
|
}
|
|
805
|
-
// ../../../../../../../tmp/ldr-build-
|
|
805
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/model.ts
|
|
806
806
|
class ModelLimitError extends Error {
|
|
807
807
|
limit;
|
|
808
808
|
code = "ldr-model-limit";
|
|
@@ -1243,7 +1243,7 @@ function blendedColourHex(code) {
|
|
|
1243
1243
|
const a = LDRAW_EXE_16[code - 256 >> 4], b = LDRAW_EXE_16[code - 256 & 15];
|
|
1244
1244
|
return "#" + [0, 1, 2].map((k) => (a[k] + b[k] >> 1).toString(16).padStart(2, "0")).join("").toUpperCase();
|
|
1245
1245
|
}
|
|
1246
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1246
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/instructions.ts
|
|
1247
1247
|
var MIN_VIS = 0.5;
|
|
1248
1248
|
var REORIENT = 0.35;
|
|
1249
1249
|
var deg = Math.PI / 180;
|
|
@@ -1611,10 +1611,10 @@ function planStepViews(insts, parts, stepOf, nSteps, o = {}) {
|
|
|
1611
1611
|
}
|
|
1612
1612
|
};
|
|
1613
1613
|
}
|
|
1614
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1614
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/render.ts
|
|
1615
1615
|
import * as THREE from "three";
|
|
1616
1616
|
|
|
1617
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1617
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/pack-io.ts
|
|
1618
1618
|
import { decompress } from "fzstd";
|
|
1619
1619
|
async function decompressPack(data) {
|
|
1620
1620
|
const u = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
@@ -1637,7 +1637,7 @@ function decodePack(buf) {
|
|
|
1637
1637
|
return { header, arr, bytes: buf.byteLength, buffer: buf };
|
|
1638
1638
|
}
|
|
1639
1639
|
|
|
1640
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1640
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/cull.ts
|
|
1641
1641
|
var upright = (m, o = 0) => Math.abs(m[o + 7] - 1) < 0.001 && Math.abs(m[o + 4]) < 0.001 && Math.abs(m[o + 10]) < 0.001;
|
|
1642
1642
|
var prepCache = new WeakMap;
|
|
1643
1643
|
var lastH = null;
|
|
@@ -1679,7 +1679,15 @@ function prepPart(H, part) {
|
|
|
1679
1679
|
for (let i = 0;i < bits.length; i++)
|
|
1680
1680
|
mask[i] = bits.charCodeAt(i) === 49 ? 1 : 0;
|
|
1681
1681
|
}
|
|
1682
|
-
|
|
1682
|
+
let full = !!mask;
|
|
1683
|
+
if (mask) {
|
|
1684
|
+
for (let i = 0;i < mask.length; i++)
|
|
1685
|
+
if (mask[i] !== 1) {
|
|
1686
|
+
full = false;
|
|
1687
|
+
break;
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
c.set(part, r = { nStuds: n, studM, kind, color, mask, nx, nz, full });
|
|
1683
1691
|
lastH = H;
|
|
1684
1692
|
lastPart = part;
|
|
1685
1693
|
lastPrep = r;
|
|
@@ -1786,6 +1794,98 @@ class Int3Table {
|
|
|
1786
1794
|
}
|
|
1787
1795
|
}
|
|
1788
1796
|
}
|
|
1797
|
+
|
|
1798
|
+
class StudTopSet {
|
|
1799
|
+
grp = new Int3Table(64);
|
|
1800
|
+
gBits = [];
|
|
1801
|
+
gX0 = [];
|
|
1802
|
+
gZ0 = [];
|
|
1803
|
+
gNz = [];
|
|
1804
|
+
gNx = [];
|
|
1805
|
+
bits;
|
|
1806
|
+
rest;
|
|
1807
|
+
lk = NaN;
|
|
1808
|
+
lpx = NaN;
|
|
1809
|
+
lpz = NaN;
|
|
1810
|
+
lg = -1;
|
|
1811
|
+
group(y, px, pz) {
|
|
1812
|
+
if (y !== this.lk || px !== this.lpx || pz !== this.lpz) {
|
|
1813
|
+
this.lk = y;
|
|
1814
|
+
this.lpx = px;
|
|
1815
|
+
this.lpz = pz;
|
|
1816
|
+
this.lg = this.grp.get(y, px, pz);
|
|
1817
|
+
}
|
|
1818
|
+
return this.lg;
|
|
1819
|
+
}
|
|
1820
|
+
constructor(X, Y, Z, n) {
|
|
1821
|
+
const cnt = [], x0 = [], x1 = [], z0 = [], z1 = [];
|
|
1822
|
+
for (let i = 0;i < n; i++) {
|
|
1823
|
+
const x = X[i], y = Y[i], z = Z[i], px = (x % 20 + 20) % 20, pz = (z % 20 + 20) % 20;
|
|
1824
|
+
let g = this.group(y, px, pz);
|
|
1825
|
+
if (g < 0) {
|
|
1826
|
+
g = cnt.length;
|
|
1827
|
+
this.grp.put(y, px, pz, g);
|
|
1828
|
+
this.lg = g;
|
|
1829
|
+
cnt.push(0);
|
|
1830
|
+
x0.push(x);
|
|
1831
|
+
x1.push(x);
|
|
1832
|
+
z0.push(z);
|
|
1833
|
+
z1.push(z);
|
|
1834
|
+
}
|
|
1835
|
+
cnt[g]++;
|
|
1836
|
+
if (x < x0[g])
|
|
1837
|
+
x0[g] = x;
|
|
1838
|
+
else if (x > x1[g])
|
|
1839
|
+
x1[g] = x;
|
|
1840
|
+
if (z < z0[g])
|
|
1841
|
+
z0[g] = z;
|
|
1842
|
+
else if (z > z1[g])
|
|
1843
|
+
z1[g] = z;
|
|
1844
|
+
}
|
|
1845
|
+
let total = 0, nRest = 0;
|
|
1846
|
+
for (let g = 0;g < cnt.length; g++) {
|
|
1847
|
+
const nx = (x1[g] - x0[g]) / 20 + 1, nz = (z1[g] - z0[g]) / 20 + 1, b = nx * nz;
|
|
1848
|
+
this.gX0.push(x0[g]);
|
|
1849
|
+
this.gZ0.push(z0[g]);
|
|
1850
|
+
this.gNx.push(nx);
|
|
1851
|
+
this.gNz.push(nz);
|
|
1852
|
+
if (b <= 64 * cnt[g] + 1024 && total + b < 2 ** 31) {
|
|
1853
|
+
this.gBits.push(total);
|
|
1854
|
+
total += b;
|
|
1855
|
+
} else {
|
|
1856
|
+
this.gBits.push(-1);
|
|
1857
|
+
nRest += cnt[g];
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
this.bits = new Uint8Array(Math.ceil(total / 8));
|
|
1861
|
+
this.rest = new Int3Table(nRest);
|
|
1862
|
+
for (let i = 0;i < n; i++) {
|
|
1863
|
+
const x = X[i], y = Y[i], z = Z[i];
|
|
1864
|
+
const g = this.group(y, (x % 20 + 20) % 20, (z % 20 + 20) % 20);
|
|
1865
|
+
const o = this.gBits[g];
|
|
1866
|
+
if (o < 0) {
|
|
1867
|
+
this.rest.put(x, y, z, 1);
|
|
1868
|
+
continue;
|
|
1869
|
+
}
|
|
1870
|
+
const k = o + (x - this.gX0[g]) / 20 * this.gNz[g] + (z - this.gZ0[g]) / 20;
|
|
1871
|
+
this.bits[k >>> 3] |= 1 << (k & 7);
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
has(x, y, z) {
|
|
1875
|
+
const g = this.group(y, (x % 20 + 20) % 20, (z % 20 + 20) % 20);
|
|
1876
|
+
if (g < 0)
|
|
1877
|
+
return false;
|
|
1878
|
+
const o = this.gBits[g];
|
|
1879
|
+
if (o < 0)
|
|
1880
|
+
return this.rest.get(x, y, z) >= 0;
|
|
1881
|
+
const a = (x - this.gX0[g]) / 20, c = (z - this.gZ0[g]) / 20;
|
|
1882
|
+
if (a < 0 || c < 0 || a >= this.gNx[g] || c >= this.gNz[g])
|
|
1883
|
+
return false;
|
|
1884
|
+
const k = o + a * this.gNz[g] + c;
|
|
1885
|
+
return (this.bits[k >>> 3] & 1 << (k & 7)) !== 0;
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
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);
|
|
1789
1889
|
var inRange = (x, y, z) => x > -BIG && x < BIG && y > -BIG && y < BIG && z > -BIG && z < BIG;
|
|
1790
1890
|
var STEP_NEVER = 2147483647;
|
|
1791
1891
|
function forEachStud(insts, H, fn) {
|
|
@@ -1810,6 +1910,10 @@ function seeThrough(H, c) {
|
|
|
1810
1910
|
return c.charCodeAt(0) === 35 && /\/[^:/]*:a\d/.test(c);
|
|
1811
1911
|
}
|
|
1812
1912
|
function cullCore(insts, H, steps) {
|
|
1913
|
+
return cullPass(insts, H, steps, -1) ?? cullPass(insts, H, steps, needE);
|
|
1914
|
+
}
|
|
1915
|
+
var needE = 0;
|
|
1916
|
+
function cullPass(insts, H, steps, eCap) {
|
|
1813
1917
|
const CELL = 40;
|
|
1814
1918
|
const clear = new Map;
|
|
1815
1919
|
const isClear = (c) => {
|
|
@@ -1818,10 +1922,30 @@ function cullCore(insts, H, steps) {
|
|
|
1818
1922
|
clear.set(c, v = seeThrough(H, c));
|
|
1819
1923
|
return v;
|
|
1820
1924
|
};
|
|
1821
|
-
const
|
|
1822
|
-
|
|
1925
|
+
const nI = insts.length;
|
|
1926
|
+
let cap = 0, nR = 0;
|
|
1927
|
+
for (let idx = 0, lp = "";idx < nI; idx++) {
|
|
1928
|
+
const part = insts[idx].part;
|
|
1929
|
+
if (part === lp) {
|
|
1930
|
+
cap++;
|
|
1931
|
+
continue;
|
|
1932
|
+
}
|
|
1933
|
+
const p = H.parts[part];
|
|
1934
|
+
if (p && p.mask) {
|
|
1935
|
+
cap++;
|
|
1936
|
+
lp = part;
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
const rx0 = new Float64Array(cap), rx1 = new Float64Array(cap), rz0 = new Float64Array(cap), rz1 = new Float64Array(cap);
|
|
1940
|
+
const rInst = new Int32Array(cap), rInst2 = new Int32Array(cap), rBx = new Float64Array(cap), rBz = new Float64Array(cap);
|
|
1941
|
+
const rPrep = [];
|
|
1942
|
+
const rLv = new Int32Array(cap), rM = new Float64Array(cap * 9);
|
|
1943
|
+
const rFast = new Uint8Array(cap);
|
|
1944
|
+
if (eCap < 0)
|
|
1945
|
+
eCap = cap * 4 + 64;
|
|
1823
1946
|
const cells = new Int3Table(insts.length * 2);
|
|
1824
|
-
const nextE =
|
|
1947
|
+
const nextE = new Int32Array(eCap), rectE = new Int32Array(eCap);
|
|
1948
|
+
let nE = 0, need = 0;
|
|
1825
1949
|
for (let idx = 0;idx < insts.length; idx++) {
|
|
1826
1950
|
const it = insts[idx];
|
|
1827
1951
|
const m = it.m;
|
|
@@ -1848,8 +1972,11 @@ function cullCore(insts, H, steps) {
|
|
|
1848
1972
|
const cx0 = Math.floor(x0 / CELL), cx1 = Math.floor(x1 / CELL), cz0 = Math.floor(z0 / CELL), cz1 = Math.floor(z1 / CELL);
|
|
1849
1973
|
if (!((cx1 - cx0 + 1) * (cz1 - cz0 + 1) <= 65536) || !inRange(lv2, cx0, cz0) || !inRange(lv2, cx1, cz1))
|
|
1850
1974
|
continue;
|
|
1975
|
+
const ux0 = Math.floor((x0 + 5) / CELL), ux1 = Math.floor((x1 - 5) / CELL), uz0 = Math.floor((z0 + 5) / CELL), uz1 = Math.floor((z1 - 5) / CELL);
|
|
1976
|
+
const nc = ux0 <= ux1 && uz0 <= uz1 ? (ux1 - ux0 + 1) * (uz1 - uz0 + 1) : 0;
|
|
1977
|
+
need += nc;
|
|
1851
1978
|
let dup = -1;
|
|
1852
|
-
for (let e = cells.get(lv2,
|
|
1979
|
+
for (let e = ux0 <= ux1 && uz0 <= uz1 ? cells.get(lv2, ux0, uz0) : -1, k = 0;e >= 0 && k < 8; e = nextE[e], k++) {
|
|
1853
1980
|
const q = rectE[e];
|
|
1854
1981
|
if (rx0[q] !== x0 || rx1[q] !== x1 || rz0[q] !== z0 || rz1[q] !== z1 || rPrep[q] !== pp)
|
|
1855
1982
|
continue;
|
|
@@ -1874,31 +2001,51 @@ function cullCore(insts, H, steps) {
|
|
|
1874
2001
|
rInst2[dup] = idx;
|
|
1875
2002
|
continue;
|
|
1876
2003
|
}
|
|
1877
|
-
const ri =
|
|
1878
|
-
rx0
|
|
1879
|
-
rx1
|
|
1880
|
-
rz0
|
|
1881
|
-
rz1
|
|
1882
|
-
rInst
|
|
1883
|
-
rInst2
|
|
2004
|
+
const ri = nR++;
|
|
2005
|
+
rx0[ri] = x0;
|
|
2006
|
+
rx1[ri] = x1;
|
|
2007
|
+
rz0[ri] = z0;
|
|
2008
|
+
rz1[ri] = z1;
|
|
2009
|
+
rInst[ri] = idx;
|
|
2010
|
+
rInst2[ri] = -1;
|
|
1884
2011
|
rPrep.push(pp);
|
|
1885
|
-
rBx
|
|
1886
|
-
rBz
|
|
1887
|
-
rLv
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
2012
|
+
rBx[ri] = b[0];
|
|
2013
|
+
rBz[ri] = b[2];
|
|
2014
|
+
rLv[ri] = lv2;
|
|
2015
|
+
const o = ri * 9;
|
|
2016
|
+
rM[o] = m[0];
|
|
2017
|
+
rM[o + 1] = m[1];
|
|
2018
|
+
rM[o + 2] = m[2];
|
|
2019
|
+
rM[o + 3] = m[3];
|
|
2020
|
+
rM[o + 4] = m[6];
|
|
2021
|
+
rM[o + 5] = m[9];
|
|
2022
|
+
rM[o + 6] = m[5];
|
|
2023
|
+
rM[o + 7] = m[8];
|
|
2024
|
+
rM[o + 8] = m[11];
|
|
2025
|
+
rFast[ri] = pp.full && b[3] - b[0] <= 20 * pp.nx && b[5] - b[2] <= 20 * pp.nz && m[4] === 0 && m[6] === 0 && m[8] === 0 && m[10] === 0 && quarterTurn(m[3], m[5], m[9], m[11]) ? 1 : 0;
|
|
2026
|
+
if (nE + nc > eCap) {
|
|
2027
|
+
nE = eCap + 1;
|
|
2028
|
+
continue;
|
|
2029
|
+
}
|
|
2030
|
+
for (let cx = ux0;cx <= ux1; cx++)
|
|
2031
|
+
for (let cz = uz0;cz <= uz1; cz++) {
|
|
1891
2032
|
if (!inRange(lv2, cx, cz))
|
|
1892
2033
|
continue;
|
|
1893
|
-
const e =
|
|
1894
|
-
rectE
|
|
1895
|
-
nextE
|
|
2034
|
+
const e = nE++;
|
|
2035
|
+
rectE[e] = ri;
|
|
2036
|
+
nextE[e] = cells.put(lv2, cx, cz, e);
|
|
1896
2037
|
}
|
|
1897
2038
|
}
|
|
2039
|
+
if (nE > eCap) {
|
|
2040
|
+
needE = need;
|
|
2041
|
+
return null;
|
|
2042
|
+
}
|
|
1898
2043
|
const SX = [0, 5, -5, 5, -5], SZ = [0, 5, 5, -5, -5];
|
|
1899
2044
|
const covers = (ri, x, y, z) => {
|
|
1900
2045
|
if (!(x - 6 >= rx0[ri] - 0.5 && x + 6 <= rx1[ri] + 0.5 && z - 6 >= rz0[ri] - 0.5 && z + 6 <= rz1[ri] + 0.5))
|
|
1901
2046
|
return false;
|
|
2047
|
+
if (rFast[ri] === 1)
|
|
2048
|
+
return true;
|
|
1902
2049
|
const o = ri * 9, pp = rPrep[ri], bx = rBx[ri], bz = rBz[ri];
|
|
1903
2050
|
const dx = x - rM[o], dy = y - rM[o + 1], dz = z - rM[o + 2];
|
|
1904
2051
|
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;
|
|
@@ -1949,8 +2096,10 @@ function cullCore(insts, H, steps) {
|
|
|
1949
2096
|
nStuds += pp.nStuds;
|
|
1950
2097
|
}
|
|
1951
2098
|
const studHidden = new Uint8Array(nStuds), studUp = new Uint8Array(nStuds);
|
|
1952
|
-
const tops = new Int3Table(nStuds, 4);
|
|
1953
2099
|
let studsHidden = 0;
|
|
2100
|
+
const tops = steps ? new Int3Table(nStuds, 4) : null;
|
|
2101
|
+
const TX = steps ? null : new Int32Array(nStuds), TY = steps ? null : new Int32Array(nStuds), TZ = steps ? null : new Int32Array(nStuds);
|
|
2102
|
+
let nT = 0;
|
|
1954
2103
|
const studHideStep = steps ? new Int32Array(nStuds).fill(STEP_NEVER) : undefined;
|
|
1955
2104
|
for (let idx = 0, j = 0;idx < insts.length; idx++) {
|
|
1956
2105
|
const it = insts[idx];
|
|
@@ -1977,8 +2126,10 @@ function cullCore(insts, H, steps) {
|
|
|
1977
2126
|
const rx = Math.round(x), ry = Math.round(y), rz = Math.round(z);
|
|
1978
2127
|
if (!inRange(rx, ry, rz))
|
|
1979
2128
|
continue;
|
|
1980
|
-
if (!
|
|
1981
|
-
|
|
2129
|
+
if (!tops) {
|
|
2130
|
+
TX[nT] = rx;
|
|
2131
|
+
TY[nT] = ry;
|
|
2132
|
+
TZ[nT++] = rz;
|
|
1982
2133
|
continue;
|
|
1983
2134
|
}
|
|
1984
2135
|
const st = steps[idx], t = tops.get(rx, ry, rz);
|
|
@@ -1986,6 +2137,7 @@ function cullCore(insts, H, steps) {
|
|
|
1986
2137
|
tops.put(rx, ry, rz, st);
|
|
1987
2138
|
}
|
|
1988
2139
|
}
|
|
2140
|
+
const topSet = tops ? null : new StudTopSet(TX, TY, TZ, nT);
|
|
1989
2141
|
const underHidden = new Uint8Array(insts.length);
|
|
1990
2142
|
const underHideStep = steps ? new Int32Array(insts.length).fill(STEP_NEVER) : undefined;
|
|
1991
2143
|
for (let idx = 0;idx < insts.length; idx++) {
|
|
@@ -2004,7 +2156,7 @@ function cullCore(insts, H, steps) {
|
|
|
2004
2156
|
const lx = b[0] + 10 + 20 * a, lz = b[2] + 10 + 20 * c;
|
|
2005
2157
|
const x = m[0] + m[3] * lx + m[5] * lz, z = m[2] + m[9] * lx + m[11] * lz;
|
|
2006
2158
|
const rx = Math.round(x), rz = Math.round(z);
|
|
2007
|
-
const t = inRange(rx, ry, rz) ? tops.get(rx, ry, rz) : -1;
|
|
2159
|
+
const t = !inRange(rx, ry, rz) ? -1 : tops ? tops.get(rx, ry, rz) : topSet.has(rx, ry, rz) ? 1 : -1;
|
|
2008
2160
|
if (t < 0) {
|
|
2009
2161
|
all = false;
|
|
2010
2162
|
break;
|
|
@@ -2051,7 +2203,7 @@ function precomputeCull(instances, H, useTex = true) {
|
|
|
2051
2203
|
return cullCore(s.all, H, s.nSteps > 1 ? s.stepOf : undefined);
|
|
2052
2204
|
}
|
|
2053
2205
|
|
|
2054
|
-
// ../../../../../../../tmp/ldr-build-
|
|
2206
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/render.ts
|
|
2055
2207
|
async function loadPack(url) {
|
|
2056
2208
|
const res = await fetch(url);
|
|
2057
2209
|
if (!res.ok)
|
|
@@ -2446,54 +2598,16 @@ function newIM(g, mat, n) {
|
|
|
2446
2598
|
im.count = n;
|
|
2447
2599
|
return im;
|
|
2448
2600
|
}
|
|
2449
|
-
function
|
|
2450
|
-
if (vis >= im.instanceMatrix.count || !im.instanceColor)
|
|
2451
|
-
return false;
|
|
2452
|
-
const M = im.instanceMatrix.array.slice(0, vis * 16), C = im.instanceColor.array.slice(0, vis * 3);
|
|
2453
|
-
im.instanceMatrix = new THREE.InstancedBufferAttribute(M, 16);
|
|
2454
|
-
im.instanceColor = new THREE.InstancedBufferAttribute(C, 3);
|
|
2455
|
-
im.count = vis;
|
|
2456
|
-
for (const o of linked) {
|
|
2457
|
-
if (o.isInstancedMesh) {
|
|
2458
|
-
o.instanceMatrix = im.instanceMatrix;
|
|
2459
|
-
o.instanceColor = im.instanceColor;
|
|
2460
|
-
o.count = vis;
|
|
2461
|
-
} else if (o.geometry) {
|
|
2462
|
-
o.geometry.setAttribute("instanceMatrix", im.instanceMatrix);
|
|
2463
|
-
o.geometry.instanceCount = vis;
|
|
2464
|
-
}
|
|
2465
|
-
}
|
|
2466
|
-
return true;
|
|
2467
|
-
}
|
|
2468
|
-
function instancedBoundingSphere(im) {
|
|
2469
|
-
const g = im.geometry;
|
|
2601
|
+
function sphereState(g) {
|
|
2470
2602
|
if (!g.boundingSphere)
|
|
2471
2603
|
g.computeBoundingSphere();
|
|
2472
2604
|
const gs = g.boundingSphere;
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
const
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
cy = py;
|
|
2480
|
-
cz = pz;
|
|
2481
|
-
r = 0;
|
|
2482
|
-
return;
|
|
2483
|
-
}
|
|
2484
|
-
const vx = px - cx, vy = py - cy, vz = pz - cz;
|
|
2485
|
-
const l2 = vx * vx + vy * vy + vz * vz;
|
|
2486
|
-
if (l2 > r * r) {
|
|
2487
|
-
const l = Math.sqrt(l2);
|
|
2488
|
-
const d = (l - r) * 0.5;
|
|
2489
|
-
const f = d / l;
|
|
2490
|
-
cx += vx * f;
|
|
2491
|
-
cy += vy * f;
|
|
2492
|
-
cz += vz * f;
|
|
2493
|
-
r += d;
|
|
2494
|
-
}
|
|
2495
|
-
};
|
|
2496
|
-
for (let i = 0, n = im.count;i < n; i++) {
|
|
2605
|
+
return Float64Array.of(0, 0, 0, -1, gs.center.x, gs.center.y, gs.center.z, gs.radius);
|
|
2606
|
+
}
|
|
2607
|
+
function sphereUnion(S, A, n) {
|
|
2608
|
+
const gx = S[4], gy = S[5], gz = S[6], gr = S[7];
|
|
2609
|
+
let cx = S[0], cy = S[1], cz = S[2], r = S[3];
|
|
2610
|
+
for (let i = 0;i < n; i++) {
|
|
2497
2611
|
const o = i * 16;
|
|
2498
2612
|
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];
|
|
2499
2613
|
const w = 1 / (e3 * gx + e7 * gy + e11 * gz + A[o + 15]);
|
|
@@ -2515,30 +2629,65 @@ function instancedBoundingSphere(im) {
|
|
|
2515
2629
|
dx = dx * inv * sr;
|
|
2516
2630
|
dy = dy * inv * sr;
|
|
2517
2631
|
dz = dz * inv * sr;
|
|
2518
|
-
|
|
2519
|
-
|
|
2632
|
+
for (let k = 0;k < 2; k++) {
|
|
2633
|
+
const px = k ? x - dx : x + dx, py = k ? y - dy : y + dy, pz = k ? z - dz : z + dz;
|
|
2634
|
+
if (r < 0) {
|
|
2635
|
+
cx = px;
|
|
2636
|
+
cy = py;
|
|
2637
|
+
cz = pz;
|
|
2638
|
+
r = 0;
|
|
2639
|
+
continue;
|
|
2640
|
+
}
|
|
2641
|
+
const vx = px - cx, vy = py - cy, vz = pz - cz;
|
|
2642
|
+
const l2 = vx * vx + vy * vy + vz * vz;
|
|
2643
|
+
if (l2 > r * r) {
|
|
2644
|
+
const l = Math.sqrt(l2);
|
|
2645
|
+
const d = (l - r) * 0.5;
|
|
2646
|
+
const f = d / l;
|
|
2647
|
+
cx += vx * f;
|
|
2648
|
+
cy += vy * f;
|
|
2649
|
+
cz += vz * f;
|
|
2650
|
+
r += d;
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2520
2653
|
}
|
|
2654
|
+
S[0] = cx;
|
|
2655
|
+
S[1] = cy;
|
|
2656
|
+
S[2] = cz;
|
|
2657
|
+
S[3] = r;
|
|
2658
|
+
}
|
|
2659
|
+
function setSphere(im, S) {
|
|
2521
2660
|
const sph = im.boundingSphere ?? new THREE.Sphere;
|
|
2522
|
-
sph.center.set(
|
|
2523
|
-
sph.radius =
|
|
2524
|
-
if (
|
|
2661
|
+
sph.center.set(S[0], S[1], S[2]);
|
|
2662
|
+
sph.radius = S[3];
|
|
2663
|
+
if (S[3] < 0)
|
|
2525
2664
|
sph.makeEmpty();
|
|
2526
2665
|
im.boundingSphere = sph;
|
|
2527
2666
|
return sph;
|
|
2528
2667
|
}
|
|
2668
|
+
function instancedBoundingSphere(im, S = sphereState(im.geometry), set = true) {
|
|
2669
|
+
sphereUnion(S, im.instanceMatrix.array, im.count);
|
|
2670
|
+
return set ? setSphere(im, S) : S;
|
|
2671
|
+
}
|
|
2529
2672
|
function instancedBoundingBox(im) {
|
|
2530
|
-
const
|
|
2673
|
+
const B = boxState(im.geometry);
|
|
2674
|
+
if (!B)
|
|
2675
|
+
return;
|
|
2676
|
+
boxUnion(B, im.instanceMatrix.array, im.instanceMatrix.count);
|
|
2677
|
+
return boxOf(B);
|
|
2678
|
+
}
|
|
2679
|
+
function boxState(g) {
|
|
2531
2680
|
if (!g.boundingBox)
|
|
2532
2681
|
g.computeBoundingBox();
|
|
2533
2682
|
const gb = g.boundingBox;
|
|
2534
2683
|
if (gb.isEmpty())
|
|
2535
|
-
return;
|
|
2536
|
-
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
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
let x0 =
|
|
2684
|
+
return null;
|
|
2685
|
+
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;
|
|
2686
|
+
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);
|
|
2687
|
+
}
|
|
2688
|
+
function boxUnion(B, A, n) {
|
|
2689
|
+
const hx = B[6], hy = B[7], hz = B[8], gx = B[9], gy = B[10], gz = B[11];
|
|
2690
|
+
let x0 = B[0], y0 = B[1], z0 = B[2], x1 = B[3], y1 = B[4], z1 = B[5];
|
|
2542
2691
|
for (let i = 0;i < n; i++) {
|
|
2543
2692
|
const o = i * 16;
|
|
2544
2693
|
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];
|
|
@@ -2556,8 +2705,15 @@ function instancedBoundingBox(im) {
|
|
|
2556
2705
|
if (cz + ez > z1)
|
|
2557
2706
|
z1 = cz + ez;
|
|
2558
2707
|
}
|
|
2559
|
-
|
|
2708
|
+
B[0] = x0;
|
|
2709
|
+
B[1] = y0;
|
|
2710
|
+
B[2] = z0;
|
|
2711
|
+
B[3] = x1;
|
|
2712
|
+
B[4] = y1;
|
|
2713
|
+
B[5] = z1;
|
|
2714
|
+
B[12] += n;
|
|
2560
2715
|
}
|
|
2716
|
+
var boxOf = (B) => B && B[12] > 0 ? Float32Array.of(B[0], B[1], B[2], B[3], B[4], B[5]) : undefined;
|
|
2561
2717
|
function batchedBoundingBox(bm) {
|
|
2562
2718
|
bm.computeBoundingBox();
|
|
2563
2719
|
const bb = bm.boundingBox;
|
|
@@ -3116,7 +3272,7 @@ function fillBucketIds(bIds, fill, studBucket, j0, j1) {
|
|
|
3116
3272
|
bIds[b][fill[b]++] = j;
|
|
3117
3273
|
}
|
|
3118
3274
|
}
|
|
3119
|
-
function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colorIndex) {
|
|
3275
|
+
function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colorIndex, trim = false) {
|
|
3120
3276
|
const bKind = [], bMat = [];
|
|
3121
3277
|
const bAll = [];
|
|
3122
3278
|
const studBucket = new Uint16Array(cull.nStuds);
|
|
@@ -3145,53 +3301,63 @@ function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colo
|
|
|
3145
3301
|
};
|
|
3146
3302
|
const matIdFor = (c, e, k) => e[k] >= 0 ? e[k] : e[k] = matIdOf(matOf(c, k === 1));
|
|
3147
3303
|
const partStud = new Map;
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
const
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3304
|
+
let jAt = 0;
|
|
3305
|
+
const pass1 = (idx) => {
|
|
3306
|
+
let j = jAt;
|
|
3307
|
+
const jEnd = j + 32768;
|
|
3308
|
+
for (;idx < insts.length && j < jEnd; idx++) {
|
|
3309
|
+
const it = insts[idx];
|
|
3310
|
+
const pp = prepPart(H, it.part);
|
|
3311
|
+
if (!pp || !pp.nStuds)
|
|
3312
|
+
continue;
|
|
3313
|
+
const a = it.m;
|
|
3314
|
+
const instE = colEntry(it.color);
|
|
3315
|
+
let ps = partStud.get(pp);
|
|
3316
|
+
if (!ps) {
|
|
3317
|
+
const kid = new Int32Array(pp.nStuds), neg = new Uint8Array(pp.nStuds);
|
|
3318
|
+
for (let si = 0;si < pp.nStuds; si++) {
|
|
3319
|
+
const kn = pp.kind[si];
|
|
3320
|
+
let id = kindIds.get(kn);
|
|
3321
|
+
if (id === undefined) {
|
|
3322
|
+
id = kindNames.length;
|
|
3323
|
+
kindIds.set(kn, id);
|
|
3324
|
+
kindNames.push(kn);
|
|
3325
|
+
}
|
|
3326
|
+
kid[si] = id;
|
|
3327
|
+
neg[si] = det12(pp.studM.subarray(si * 12, si * 12 + 12)) < 0 ? 1 : 0;
|
|
3165
3328
|
}
|
|
3166
|
-
|
|
3167
|
-
|
|
3329
|
+
partStud.set(pp, ps = { kid, neg });
|
|
3330
|
+
}
|
|
3331
|
+
const instNeg = det12(a) < 0 ? 1 : 0;
|
|
3332
|
+
const B = pp.studM;
|
|
3333
|
+
for (let si = 0;si < pp.nStuds; si++, j++) {
|
|
3334
|
+
const o = si * 12, b0 = B[o], b1 = B[o + 1], b2 = B[o + 2];
|
|
3335
|
+
const neg = (instNeg ^ ps.neg[si]) === 1;
|
|
3336
|
+
const km = ps.kid[si] * 2 + (neg ? 1 : 0);
|
|
3337
|
+
const sc = pp.color[si];
|
|
3338
|
+
const mid = sc === "16" ? matIdFor(it.color, instE, neg ? 1 : 0) : matIdFor(sc, colEntry(sc), neg ? 1 : 0);
|
|
3339
|
+
const row = bucketOfKM[mid];
|
|
3340
|
+
let b = row[km];
|
|
3341
|
+
if (b === undefined) {
|
|
3342
|
+
b = bKind.length;
|
|
3343
|
+
row[km] = b;
|
|
3344
|
+
bKind.push(kindNames[ps.kid[si]]);
|
|
3345
|
+
bMat.push(matList[mid]);
|
|
3346
|
+
bAll.push(0);
|
|
3347
|
+
}
|
|
3348
|
+
studBucket[j] = b;
|
|
3349
|
+
bAll[b]++;
|
|
3350
|
+
sx[j] = a[0] + a[3] * b0 + a[4] * b1 + a[5] * b2;
|
|
3351
|
+
sz[j] = a[2] + a[9] * b0 + a[10] * b1 + a[11] * b2;
|
|
3168
3352
|
}
|
|
3169
|
-
partStud.set(pp, ps = { kid, neg });
|
|
3170
|
-
}
|
|
3171
|
-
const instNeg = det12(a) < 0 ? 1 : 0;
|
|
3172
|
-
const B = pp.studM;
|
|
3173
|
-
for (let si = 0;si < pp.nStuds; si++, j++) {
|
|
3174
|
-
if ((j & 32767) === 0 && j)
|
|
3175
|
-
yield;
|
|
3176
|
-
const o = si * 12, b0 = B[o], b1 = B[o + 1], b2 = B[o + 2];
|
|
3177
|
-
const neg = (instNeg ^ ps.neg[si]) === 1;
|
|
3178
|
-
const km = ps.kid[si] * 2 + (neg ? 1 : 0);
|
|
3179
|
-
const sc = pp.color[si];
|
|
3180
|
-
const mid = sc === "16" ? matIdFor(it.color, instE, neg ? 1 : 0) : matIdFor(sc, colEntry(sc), neg ? 1 : 0);
|
|
3181
|
-
const row = bucketOfKM[mid];
|
|
3182
|
-
let b = row[km];
|
|
3183
|
-
if (b === undefined) {
|
|
3184
|
-
b = bKind.length;
|
|
3185
|
-
row[km] = b;
|
|
3186
|
-
bKind.push(kindNames[ps.kid[si]]);
|
|
3187
|
-
bMat.push(matList[mid]);
|
|
3188
|
-
bAll.push(0);
|
|
3189
|
-
}
|
|
3190
|
-
studBucket[j] = b;
|
|
3191
|
-
bAll[b]++;
|
|
3192
|
-
sx[j] = a[0] + a[3] * b0 + a[4] * b1 + a[5] * b2;
|
|
3193
|
-
sz[j] = a[2] + a[9] * b0 + a[10] * b1 + a[11] * b2;
|
|
3194
3353
|
}
|
|
3354
|
+
jAt = j;
|
|
3355
|
+
return idx;
|
|
3356
|
+
};
|
|
3357
|
+
for (let idx = 0;idx < insts.length; ) {
|
|
3358
|
+
if (idx)
|
|
3359
|
+
yield;
|
|
3360
|
+
idx = pass1(idx);
|
|
3195
3361
|
}
|
|
3196
3362
|
yield;
|
|
3197
3363
|
const bIds = bAll.map((n) => new Int32Array(n));
|
|
@@ -3222,10 +3388,10 @@ function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colo
|
|
|
3222
3388
|
sMesh.push(null);
|
|
3223
3389
|
continue;
|
|
3224
3390
|
}
|
|
3225
|
-
const
|
|
3226
|
-
im
|
|
3227
|
-
|
|
3228
|
-
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) } } : {} });
|
|
3391
|
+
const n = trim ? v : c.length;
|
|
3392
|
+
const im = newIM(g, bMat[b], n);
|
|
3393
|
+
im.instanceColor = new THREE.InstancedBufferAttribute(new Float32Array(n * 3), 3);
|
|
3394
|
+
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) } } : {} });
|
|
3229
3395
|
}
|
|
3230
3396
|
};
|
|
3231
3397
|
for (let b = 0;b < bKind.length; b++) {
|
|
@@ -3251,48 +3417,113 @@ function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colo
|
|
|
3251
3417
|
return x;
|
|
3252
3418
|
};
|
|
3253
3419
|
yield;
|
|
3420
|
+
let nH = 0;
|
|
3421
|
+
if (trim)
|
|
3422
|
+
for (let j = 0;j < cull.nStuds; j++)
|
|
3423
|
+
nH += cull.studHidden[j];
|
|
3424
|
+
const hidI = new Int32Array(nH), hidS = new Int32Array(nH), hidC = new Int32Array(nH);
|
|
3425
|
+
let nHid = 0;
|
|
3254
3426
|
{
|
|
3255
3427
|
const w = new Float64Array(12);
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
const
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
if (
|
|
3264
|
-
yield;
|
|
3265
|
-
mul12To(it.m, pp.studM, si * 12, w);
|
|
3266
|
-
const sm = sMesh[studCl[j]];
|
|
3267
|
-
if (!sm)
|
|
3428
|
+
jAt = 0;
|
|
3429
|
+
const pass3 = (idx) => {
|
|
3430
|
+
let j = jAt;
|
|
3431
|
+
const jEnd = j + 32768;
|
|
3432
|
+
for (;idx < insts.length && j < jEnd; idx++) {
|
|
3433
|
+
const it = insts[idx];
|
|
3434
|
+
const pp = prepPart(H, it.part);
|
|
3435
|
+
if (!pp || !pp.nStuds)
|
|
3268
3436
|
continue;
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3437
|
+
for (let si = 0;si < pp.nStuds; si++, j++) {
|
|
3438
|
+
if (trim && cull.studHidden[j]) {
|
|
3439
|
+
if (sMesh[studCl[j]]) {
|
|
3440
|
+
hidI[nHid] = idx;
|
|
3441
|
+
hidS[nHid] = si;
|
|
3442
|
+
hidC[nHid++] = studCl[j];
|
|
3443
|
+
}
|
|
3444
|
+
continue;
|
|
3445
|
+
}
|
|
3446
|
+
mul12To(it.m, pp.studM, si * 12, w);
|
|
3447
|
+
const sm = sMesh[studCl[j]];
|
|
3448
|
+
if (!sm)
|
|
3449
|
+
continue;
|
|
3450
|
+
const im = sm.im;
|
|
3451
|
+
const slot = studSlot[j];
|
|
3452
|
+
const sc = pp.color[si];
|
|
3453
|
+
const col = sc === "16" ? it.color : sc;
|
|
3454
|
+
if (sm.slots) {
|
|
3455
|
+
const t = sm.slots;
|
|
3456
|
+
t.own[slot] = steps[idx];
|
|
3457
|
+
t.hide[slot] = cull.studHideStep[j];
|
|
3458
|
+
t.inst[slot] = idx;
|
|
3459
|
+
t.stud[slot] = si;
|
|
3460
|
+
t.col[slot] = colorIndex(col);
|
|
3461
|
+
}
|
|
3462
|
+
writeM4(im.instanceMatrix.array, slot * 16, w);
|
|
3463
|
+
colorOf(col).toArray(im.instanceColor.array, slot * 3);
|
|
3280
3464
|
}
|
|
3281
|
-
writeM4(im.instanceMatrix.array, slot * 16, w);
|
|
3282
|
-
colorOf(col).toArray(im.instanceColor.array, slot * 3);
|
|
3283
3465
|
}
|
|
3466
|
+
jAt = j;
|
|
3467
|
+
return idx;
|
|
3468
|
+
};
|
|
3469
|
+
for (let idx = 0;idx < insts.length; ) {
|
|
3470
|
+
if (idx)
|
|
3471
|
+
yield;
|
|
3472
|
+
idx = pass3(idx);
|
|
3473
|
+
}
|
|
3474
|
+
}
|
|
3475
|
+
if (trim) {
|
|
3476
|
+
for (let c0 = 0;c0 < sMesh.length; c0 += 8) {
|
|
3477
|
+
yield;
|
|
3478
|
+
for (let ci = c0;ci < Math.min(sMesh.length, c0 + 8); ci++) {
|
|
3479
|
+
const sm = sMesh[ci];
|
|
3480
|
+
if (sm) {
|
|
3481
|
+
sm.S = instancedBoundingSphere(sm.im, undefined, false);
|
|
3482
|
+
if (LOD) {
|
|
3483
|
+
sm.B = boxState(sm.im.geometry);
|
|
3484
|
+
if (sm.B)
|
|
3485
|
+
boxUnion(sm.B, sm.im.instanceMatrix.array, sm.im.count);
|
|
3486
|
+
}
|
|
3487
|
+
}
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
3490
|
+
for (let k0 = 0;k0 < nHid; k0 += 65536) {
|
|
3491
|
+
yield;
|
|
3492
|
+
hiddenStudSpheres(insts, H, hidI, hidS, hidC, sMesh, k0, Math.min(nHid, k0 + 65536));
|
|
3284
3493
|
}
|
|
3285
3494
|
}
|
|
3286
3495
|
return sMesh;
|
|
3287
3496
|
}
|
|
3497
|
+
function hiddenStudSpheres(insts, H, hidI, hidS, hidC, sMesh, k0, k1) {
|
|
3498
|
+
const w = new Float64Array(12), A = new Float32Array(16);
|
|
3499
|
+
for (let k = k0;k < k1; k++) {
|
|
3500
|
+
const it = insts[hidI[k]];
|
|
3501
|
+
const pp = prepPart(H, it.part);
|
|
3502
|
+
const sm = sMesh[hidC[k]];
|
|
3503
|
+
mul12To(it.m, pp.studM, hidS[k] * 12, w);
|
|
3504
|
+
writeM4(A, 0, w);
|
|
3505
|
+
sphereUnion(sm.S, A, 1);
|
|
3506
|
+
if (sm.B)
|
|
3507
|
+
boxUnion(sm.B, A, 1);
|
|
3508
|
+
}
|
|
3509
|
+
}
|
|
3288
3510
|
function undersideGroups(ids, insts) {
|
|
3289
3511
|
const by = new Map;
|
|
3290
3512
|
const rest = [];
|
|
3513
|
+
let p4 = NaN, p7 = NaN, p10 = NaN, prev = rest;
|
|
3291
3514
|
for (const id of ids) {
|
|
3292
3515
|
const m = insts[id].m;
|
|
3516
|
+
if (m[4] === p4 && m[7] === p7 && m[10] === p10) {
|
|
3517
|
+
prev.push(id);
|
|
3518
|
+
continue;
|
|
3519
|
+
}
|
|
3520
|
+
p4 = m[4];
|
|
3521
|
+
p7 = m[7];
|
|
3522
|
+
p10 = m[10];
|
|
3293
3523
|
const l = Math.hypot(m[4], m[7], m[10]);
|
|
3294
3524
|
if (!(l > 0.000001)) {
|
|
3295
3525
|
rest.push(id);
|
|
3526
|
+
prev = rest;
|
|
3296
3527
|
continue;
|
|
3297
3528
|
}
|
|
3298
3529
|
const ax = [m[4] / l, m[7] / l, m[10] / l, l];
|
|
@@ -3301,11 +3532,13 @@ function undersideGroups(ids, insts) {
|
|
|
3301
3532
|
if (!g) {
|
|
3302
3533
|
if (by.size >= 12) {
|
|
3303
3534
|
rest.push(id);
|
|
3535
|
+
prev = rest;
|
|
3304
3536
|
continue;
|
|
3305
3537
|
}
|
|
3306
3538
|
by.set(k, g = { ids: [], ax });
|
|
3307
3539
|
}
|
|
3308
3540
|
g.ids.push(id);
|
|
3541
|
+
prev = g.ids;
|
|
3309
3542
|
}
|
|
3310
3543
|
const out = [...by.values()];
|
|
3311
3544
|
if (rest.length)
|
|
@@ -3718,15 +3951,35 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
3718
3951
|
const vis = uids.length - uids.reduce((a, i) => a + cull.underHidden[i], 0);
|
|
3719
3952
|
stats.undersTotal += uids.length;
|
|
3720
3953
|
stats.undersHidden += uids.length - vis;
|
|
3721
|
-
const
|
|
3722
|
-
|
|
3954
|
+
const trimU = !steps && !!P.cullUnder;
|
|
3955
|
+
const im = newIM(under, mat, trimU ? vis : uids.length);
|
|
3956
|
+
fillInstances(im, trimU ? ord.slice(0, vis) : ord, insts, color);
|
|
3723
3957
|
im.onBeforeRender = trackVp;
|
|
3724
3958
|
im.userData.ldrUnder = true;
|
|
3725
3959
|
im.userData.ldrPart = part;
|
|
3726
|
-
|
|
3960
|
+
let uB;
|
|
3961
|
+
if (trimU) {
|
|
3962
|
+
im.count = vis;
|
|
3963
|
+
const S = instancedBoundingSphere(im, undefined, false), A = new Float32Array(16);
|
|
3964
|
+
if (LOD) {
|
|
3965
|
+
uB = boxState(im.geometry);
|
|
3966
|
+
if (uB)
|
|
3967
|
+
boxUnion(uB, im.instanceMatrix.array, vis);
|
|
3968
|
+
}
|
|
3969
|
+
for (let k = vis;k < ord.length; k++) {
|
|
3970
|
+
writeM4(A, 0, insts[ord[k]].m);
|
|
3971
|
+
sphereUnion(S, A, 1);
|
|
3972
|
+
if (uB)
|
|
3973
|
+
boxUnion(uB, A, 1);
|
|
3974
|
+
}
|
|
3975
|
+
setSphere(im, S);
|
|
3976
|
+
} else
|
|
3977
|
+
instancedBoundingSphere(im);
|
|
3727
3978
|
im.count = P.cullUnder ? vis : uids.length;
|
|
3728
3979
|
root.add(im);
|
|
3729
3980
|
const cl = newCluster(im.boundingSphere, im);
|
|
3981
|
+
if (uB !== undefined)
|
|
3982
|
+
cl.b = boxOf(uB);
|
|
3730
3983
|
cl.lv.push({ objs: [im], err: 0 }, ...lodLevels(p.under, im, mat));
|
|
3731
3984
|
{
|
|
3732
3985
|
const bl = p.body?.lod;
|
|
@@ -3749,7 +4002,7 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
3749
4002
|
if (!o.isInstancedMesh)
|
|
3750
4003
|
o.geometry.instanceCount = im.count;
|
|
3751
4004
|
});
|
|
3752
|
-
const trim =
|
|
4005
|
+
const trim = trimU && vis < uids.length;
|
|
3753
4006
|
if (trim)
|
|
3754
4007
|
trimmed.under = true;
|
|
3755
4008
|
toggles.push({ mesh: countTo(() => objs), all: trim ? vis : uids.length, visible: vis, flag: "under" });
|
|
@@ -4043,7 +4296,7 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
4043
4296
|
}
|
|
4044
4297
|
}
|
|
4045
4298
|
yield root;
|
|
4046
|
-
const _studGen = buildStudMeshesGen(insts, H, cull, arr, LOD, color, (c, mirror) => materialFor(c, mirror, false), steps, steps && colorIndex);
|
|
4299
|
+
const _studGen = buildStudMeshesGen(insts, H, cull, arr, LOD, color, (c, mirror) => materialFor(c, mirror, false), steps, steps && colorIndex, !steps && !!P.cullStuds);
|
|
4047
4300
|
let _studR = _studGen.next();
|
|
4048
4301
|
while (!_studR.done) {
|
|
4049
4302
|
yield root;
|
|
@@ -4067,13 +4320,18 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
4067
4320
|
const im = sm.im;
|
|
4068
4321
|
const kind = sKind[ci];
|
|
4069
4322
|
const k = H.studKinds[kind];
|
|
4070
|
-
const vis = sVis[ci], all =
|
|
4071
|
-
|
|
4323
|
+
const vis = sVis[ci], all = sm.all;
|
|
4324
|
+
if (sm.S)
|
|
4325
|
+
setSphere(im, sm.S);
|
|
4326
|
+
else
|
|
4327
|
+
instancedBoundingSphere(im);
|
|
4072
4328
|
im.count = P.cullStuds ? vis : all;
|
|
4073
4329
|
im.onBeforeRender = trackVp;
|
|
4074
4330
|
im.userData.ldrStud = true;
|
|
4075
4331
|
root.add(im);
|
|
4076
4332
|
const cl = newCluster(im.boundingSphere, im);
|
|
4333
|
+
if (sm.B !== undefined)
|
|
4334
|
+
cl.b = boxOf(sm.B);
|
|
4077
4335
|
cl.studLineLv = 0;
|
|
4078
4336
|
cl.lv.push({ objs: [im], err: 0 });
|
|
4079
4337
|
const discObjs = [];
|
|
@@ -4128,7 +4386,7 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
4128
4386
|
if (!o.isInstancedMesh)
|
|
4129
4387
|
o.geometry.instanceCount = im.count;
|
|
4130
4388
|
});
|
|
4131
|
-
const trim = !steps && P.cullStuds &&
|
|
4389
|
+
const trim = !steps && P.cullStuds && vis < all;
|
|
4132
4390
|
if (trim)
|
|
4133
4391
|
trimmed.studs = true;
|
|
4134
4392
|
toggles.push({ mesh: countTo(() => objs), all: trim ? vis : all, visible: vis, flag: "studs" });
|
|
@@ -4388,7 +4646,7 @@ async function warmPackGeometry(pack, stop = () => false, sliceMs = 8) {
|
|
|
4388
4646
|
await new Promise((r) => setTimeout(r, 0));
|
|
4389
4647
|
}
|
|
4390
4648
|
}
|
|
4391
|
-
// ../../../../../../../tmp/ldr-build-
|
|
4649
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/scene.ts
|
|
4392
4650
|
import * as THREE2 from "three";
|
|
4393
4651
|
var _box = new THREE2.Box3;
|
|
4394
4652
|
var _m4 = new THREE2.Matrix4;
|
|
@@ -4743,10 +5001,10 @@ function createLdrObjectInner(instances, pack, options, progressive) {
|
|
|
4743
5001
|
return finish();
|
|
4744
5002
|
})();
|
|
4745
5003
|
}
|
|
4746
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5004
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/parts-cdn.ts
|
|
4747
5005
|
import { decompress as decompress2 } from "fzstd";
|
|
4748
5006
|
|
|
4749
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5007
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/embedded.ts
|
|
4750
5008
|
function splitFiles(text, fallback) {
|
|
4751
5009
|
const files = new Map;
|
|
4752
5010
|
let cur = null, saw = false, skip = false;
|
|
@@ -4821,7 +5079,7 @@ function embeddedKeys(text, names, fallback = "main.ldr") {
|
|
|
4821
5079
|
return out;
|
|
4822
5080
|
}
|
|
4823
5081
|
|
|
4824
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5082
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/parts-cdn.ts
|
|
4825
5083
|
var DEFAULT_PARTS_CDN = "https://ldr-demo.vercel.app/cdn/v1/";
|
|
4826
5084
|
var indexCache = new Map;
|
|
4827
5085
|
var shardCache = new Map;
|
|
@@ -5075,10 +5333,10 @@ async function prepareModel(source, o = {}) {
|
|
|
5075
5333
|
return { insts, pack, tier, missing, requests, bytes, cull, timings: { fetchModel: t1 - t0, parse: t2 - t1, parts: t3 - t2, ...cull ? { cull: performance.now() - t3 } : {} } };
|
|
5076
5334
|
}
|
|
5077
5335
|
|
|
5078
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5079
|
-
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';
|
|
5336
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/load-worker.gen.ts
|
|
5337
|
+
var load_worker_gen_default = 'var en=ArrayBuffer,W=Uint8Array,ze=Uint16Array,tn=Int16Array;var $e=Int32Array,Ye=function(e,t,n){if(W.prototype.slice)return W.prototype.slice.call(e,t,n);if(t==null||t<0)t=0;if(n==null||n>e.length)n=e.length;var r=new W(n-t);return r.set(e.subarray(t,n)),r},Re=function(e,t,n,r){if(W.prototype.fill)return W.prototype.fill.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;for(;n<r;++n)e[n]=t;return e},nn=function(e,t,n,r){if(W.prototype.copyWithin)return W.prototype.copyWithin.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;while(n<r)e[t++]=e[n++]};var rn=["invalid zstd data","window size too large (>2046MB)","invalid block type","FSE accuracy too high","match distance too far back","unexpected EOF"],Z=function(e,t,n){var r=Error(t||rn[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,Z);if(!n)throw r;return r},dt=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},sn=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},on=function(e,t){var n=e[0]|e[1]<<8|e[2]<<16;if(n==3126568&&e[3]==253){var r=e[4],s=r>>5&1,o=r>>2&1,i=r&3,u=r>>6;if(r&8)Z(0);var l=6-s,f=i==3?4:i,c=dt(e,l,f);l+=f;var a=u?1<<u:s,p=dt(e,l,a)+(u==1&&256),g=p;if(!s){var h=1<<10+(e[5]>>3);g=h+(h>>3)*(e[5]&7)}if(g>2145386496)Z(1);var b=new W((t==1?p||g:t?0:g)+12);return b[0]=1,b[4]=4,b[8]=8,{b:l+a,y:0,l:0,d:c,w:t&&t!=1?t:b.subarray(12),e:g,o:new $e(b.buffer,0,3),u:p,c:o,m:Math.min(131072,g)}}else if((n>>4|e[3]<<20)==25481893)return sn(e,4)+8;Z(0)},Se=function(e){var t=0;for(;1<<t<=e;++t);return t-1},Be=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)Z(3);var o=1<<s,i=o,u=-1,l=-1,f=-1,c=o,a=new en(512+(o<<2)),p=new tn(a,0,256),g=new ze(a,0,256),h=new ze(a,512,o),b=512+(o<<1),v=new W(a,b,o),x=new W(a,b+o);while(u<255&&i>0){var m=Se(i+1),d=r>>3,y=(1<<m+1)-1,D=(e[d]|e[d+1]<<8|e[d+2]<<16)>>(r&7)&y,C=(1<<m)-1,E=y-i-1,B=D&C;if(B<E)r+=m,D=B;else if(r+=m+1,D>C)D-=E;if(p[++u]=--D,D==-1)i+=D,v[--c]=u;else i-=D;if(!D)do{var k=r>>3;l=(e[k]|e[k+1]<<8)>>(r&7)&3,r+=2,u+=l}while(l==3)}if(u>255||i)Z(0);var w=0,M=(o>>1)+(o>>3)+3,F=o-1;for(var N=0;N<=u;++N){var P=p[N];if(P<1){g[N]=-P;continue}for(f=0;f<P;++f){v[w]=N;do w=w+M&F;while(w>=c)}}if(w)Z(0);for(f=0;f<o;++f){var I=g[v[f]]++,V=x[f]=s-Se(I);h[f]=(I<<V)-o}return[r+7>>3,{b:s,s:v,n:x,t:h}]},an=function(e,t){var n=0,r=-1,s=new W(292),o=e[t],i=s.subarray(0,256),u=s.subarray(256,268),l=new ze(s.buffer,268);if(o<128){var f=Be(e,t+1,6),c=f[0],a=f[1];t+=o;var p=c<<3,g=e[t];if(!g)Z(0);var h=0,b=0,v=a.b,x=v,m=(++t<<3)-8+Se(g);for(;;){if(m-=v,m<p)break;var d=m>>3;if(h+=(e[d]|e[d+1]<<8)>>(m&7)&(1<<v)-1,i[++r]=a.s[h],m-=x,m<p)break;d=m>>3,b+=(e[d]|e[d+1]<<8)>>(m&7)&(1<<x)-1,i[++r]=a.s[b],v=a.n[h],h=a.t[h],x=a.n[b],b=a.t[b]}if(++r>255)Z(0)}else{r=o-127;for(;n<r;n+=2){var y=e[++t];i[n]=y>>4,i[n+1]=y&15}++t}var D=0;for(n=0;n<r;++n){var C=i[n];if(C>11)Z(0);D+=C&&1<<C-1}var E=Se(D)+1,B=1<<E,k=B-D;if(k&k-1)Z(0);i[r++]=Se(k)+1;for(n=0;n<r;++n){var C=i[n];++u[i[n]=C&&E+1-C]}var w=new W(B<<1),M=w.subarray(0,B),F=w.subarray(B);l[E]=0;for(n=E;n>0;--n){var N=l[n];Re(F,n,N,l[n-1]=N+u[n]*(1<<E-n))}if(l[0]!=B)Z(0);for(n=0;n<r;++n){var P=i[n];if(P){var I=l[P];Re(M,n,I,l[P]=I+(1<<E-P))}}return[t,{n:F,b:E,s:M}]},ln=Be(new W([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],cn=Be(new W([33,20,196,24,99,140,33,132,16,66,8,33,132,16,66,8,33,68,68,68,68,68,68,68,68,36,9]),0,6)[1],un=Be(new W([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],yt=function(e,t){var n=e.length,r=new $e(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Je=new W(new $e([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),fn=yt(Je,0),Qe=new W(new $e([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),pn=yt(Qe,3),Ie=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,u=-n.b;if(!o)Z(0);var l=0,f=n.b,c=(r<<3)-8+Se(o)-f,a=-1;for(;c>u&&a<s;){var p=c>>3,g=(e[p]|e[p+1]<<8|e[p+2]<<16)>>(c&7);l=(l<<f|g)&i,t[++a]=n.s[l],c-=f=n.n[l]}if(c!=u||a+1!=s)Z(0)},mn=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,u=o+i;Ie(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),Ie(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),Ie(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,u),n),Ie(e.subarray(r),t.subarray(u),n)},hn=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var u=o>>3|e[s+1]<<5|e[s+2]<<13,l=(s+=3)+u;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return Re(n,e[s],t.y,t.y+=u),n;return Re(new W(u),e[s])}if(l>e.length)return;if(i==0){if(t.b=l,n)return n.set(e.subarray(s,l),t.y),t.y+=u,n;return Ye(e,s,l)}if(i==2){var f=e[s],c=f&3,a=f>>2&3,p=f>>4,g=0,h=0;if(c<2)if(a&1)p|=e[++s]<<4|(a&2&&e[++s]<<12);else p=f>>3;else if(h=a,a<2)p|=(e[++s]&63)<<4,g=e[s]>>6|e[++s]<<2;else if(a==2)p|=e[++s]<<4|(e[++s]&3)<<12,g=e[s]>>2|e[++s]<<6;else p|=e[++s]<<4|(e[++s]&63)<<12,g=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var b=n?n.subarray(t.y,t.y+t.m):new W(t.m),v=b.length-p;if(c==0)b.set(e.subarray(s,s+=p),v);else if(c==1)Re(b,e[s++],v);else{var x=t.h;if(c==2){var m=an(e,s);g+=s-(s=m[0]),t.h=x=m[1]}else if(!x)Z(0);(h?mn:Ie)(e.subarray(s,s+=g),b.subarray(v),x)}var d=e[s++];if(d){if(d==255)d=(e[s++]|e[s++]<<8)+32512;else if(d>127)d=d-128<<8|e[s++];var y=e[s++];if(y&3)Z(0);var D=[cn,un,ln];for(var C=2;C>-1;--C){var E=y>>(C<<1)+2&3;if(E==1){var B=new W([0,0,e[s++]]);D[C]={s:B.subarray(2,3),n:B.subarray(0,1),t:new ze(B.buffer,0,1),b:0}}else if(E==2)r=Be(e,s,9-(C&1)),s=r[0],D[C]=r[1];else if(E==3){if(!t.t)Z(0);D[C]=t.t[C]}}var k=t.t=D,w=k[0],M=k[1],F=k[2],N=e[l-1];if(!N)Z(0);var P=(l<<3)-8+Se(N)-F.b,I=P>>3,V=0,he=(e[I]|e[I+1]<<8)>>(P&7)&(1<<F.b)-1;I=(P-=M.b)>>3;var ce=(e[I]|e[I+1]<<8)>>(P&7)&(1<<M.b)-1;I=(P-=w.b)>>3;var Ae=(e[I]|e[I+1]<<8)>>(P&7)&(1<<w.b)-1;for(++d;--d;){var re=F.s[he],Te=F.n[he],de=w.s[Ae],ve=w.n[Ae],fe=M.s[ce],Le=M.n[ce];I=(P-=fe)>>3;var O=1<<fe,L=O+((e[I]|e[I+1]<<8|e[I+2]<<16|e[I+3]<<24)>>>(P&7)&O-1);I=(P-=Qe[de])>>3;var _=pn[de]+((e[I]|e[I+1]<<8|e[I+2]<<16)>>(P&7)&(1<<Qe[de])-1);I=(P-=Je[re])>>3;var X=fn[re]+((e[I]|e[I+1]<<8|e[I+2]<<16)>>(P&7)&(1<<Je[re])-1);if(I=(P-=Te)>>3,he=F.t[he]+((e[I]|e[I+1]<<8)>>(P&7)&(1<<Te)-1),I=(P-=ve)>>3,Ae=w.t[Ae]+((e[I]|e[I+1]<<8)>>(P&7)&(1<<ve)-1),I=(P-=Le)>>3,ce=M.t[ce]+((e[I]|e[I+1]<<8)>>(P&7)&(1<<Le)-1),L>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=L-=3;else{var q=L-(X!=0);if(q){if(L=q==3?t.o[0]-1:t.o[q],q>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=L}else L=t.o[0]}for(var C=0;C<X;++C)b[V+C]=b[v+C];V+=X,v+=X;var ee=V-L;if(ee<0){var J=-ee,T=t.e+ee;if(J>_)J=_;for(var C=0;C<J;++C)b[V+C]=t.w[T+C];V+=J,_-=J,ee=0}for(var C=0;C<_;++C)b[V+C]=b[ee+C];V+=_}if(V!=v)while(v<b.length)b[V++]=b[v++];else V=b.length;if(n)t.y+=V;else b=Ye(b,0,V)}else if(n){if(t.y+=p,v)for(var C=0;C<p;++C)b[C]=b[v+C]}else if(v)b=Ye(b,v);return t.b=l,b}Z(2)},gn=function(e,t){if(e.length==1)return e[0];var n=new W(t);for(var r=0,s=0;r<e.length;++r){var o=e[r];n.set(o,s),s+=o.length}return n};function je(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=on(e,r||t);if(typeof i=="object"){if(r){if(t=null,i.w.length==i.u)n.push(t=i.w),o+=i.u}else n.push(t),i.e=0;for(;!i.l;){var u=hn(e,i,t);if(!u)Z(5);if(t)i.e=i.y;else n.push(u),o+=u.length,nn(i.w,0,u.length),i.w.set(u,i.w.length-u.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return gn(n,o)}async function bn(e){let t=e instanceof Uint8Array?e:new Uint8Array(e),n=(r)=>r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength);if(t[0]===40&&t[1]===181&&t[2]===47&&t[3]===253)return n(je(t));if(t[0]===31&&t[1]===139)return new Response(new Blob([t]).stream().pipeThrough(new DecompressionStream("gzip"))).arrayBuffer();return n(t)}async function xt(e){return new TextDecoder().decode(await bn(e))}var wt=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split("/").pop()||"main.ldr").replace(/\\.(zst|gz)$/i,"")||"main.ldr";function Ve(e){let t=new DataView(e).getUint32(0,!0),n=JSON.parse(new TextDecoder().decode(new Uint8Array(e,4,t))),r=4+t;return{header:n,arr:(o)=>o&&(o[2]==="f32"?new Float32Array(e,r+o[0],o[1]):o[2]==="u16"?new Uint16Array(e,r+o[0],o[1]):o[2]==="u8"?new Uint8Array(e,r+o[0],o[1]):new Uint32Array(e,r+o[0],o[1])),bytes:e.byteLength,buffer:e}}var Y=(e)=>e.trim().toLowerCase().replace(/\\\\/g,"/").replace(/\\/+/g,"/"),et=/^[A-Za-z][A-Za-z0-9_]*$/,qe=new Map;function tt(e){let t=e.toLowerCase(),n=2166136261;for(let s=0;s<t.length;s++)n^=t.charCodeAt(s),n=Math.imul(n,16777619);let r=-1-(n>>>0&1073741823);if(!qe.has(r))qe.set(r,t);return r}function nt(e){let t=e.charCodeAt(0)|32;if(t>=97&&t<=122&&et.test(e))return tt(e);if(/^0x/i.test(e))return parseInt(e,16);return+e}var Mt=/^~?\\s*moved\\s+to\\s+(.+)$/i,dn=new Set(["FILE","NOFILE","!DATA","!:","STEP","BFC","ROTSTEP","BUFEXCHG","!TEXMAP"]),yn=new Set(["FILE","NOFILE","!DATA"]),kt=1000000000000000,Pt=new Set(["part","subpart","primitive","8_primitive","48_primitive","shortcut","helper"]),xn=new Set(["model","submodel","configuration"]),wn=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function At(e){let t=wn.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,"");return Pt.has(n)||xn.has(n)?n:void 0}function Mn(e){let t=[],n=0;while(n<e.length){while(e[n]===" "||e[n]==="\\t")n++;if(n>=e.length)break;if(e[n]===\'"\'){let r="";n++;while(n<e.length&&e[n]!==\'"\'){if(e[n]==="\\\\"&&n+1<e.length)n++;r+=e[n++]}n++,t.push(r)}else{let r=n;while(r<e.length&&e[r]!==" "&&e[r]!=="\\t")r++;t.push(e.slice(n,r)),n=r}}return t}function An(e,t=!1){let n=/^\\s*(\\S+)\\s+(.*)$/.exec(e);if(!n)return null;let r=n[1].toUpperCase(),s=r==="PLANAR"?9:r==="CYLINDRICAL"?10:r==="SPHERICAL"?11:0;if(!s)return null;let o=n[2].trim().split(/\\s+/);if(o.length<s+1)return null;let i=o.slice(0,s).map(Number);if(!i.every((a)=>Number.isFinite(a)&&Math.abs(a)<=1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000))return null;if(s>=10&&!(Math.abs(i[9])>=0.000001)||s===11&&!(Math.abs(i[10])>=0.000001))return null;let u=n[2].trim();for(let a=0;a<s;a++)u=u.replace(/^\\S+\\s*/,"");let l=Mn(u);if(!l.length)return null;let f={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:l[0]};if(s>=10)f.a=i[9];if(s===11)f.b=i[10];let c=l.findIndex((a,p)=>p>0&&a.toUpperCase()==="GLOSSMAP");if(c>0&&l[c+1])f.glossmap=l[c+1];if(t)f.next=!0;return f}var vn=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,"");if(t.length%4===1)t=t.slice(0,-1);let n=t+"=".repeat((4-t.length%4)%4),r=atob(n),s=new Uint8Array(r.length);for(let o=0;o<r.length;o++)s[o]=r.charCodeAt(o);return s};function Cn(e){let t=e.length,n=1,r=(c)=>c===32||c===9,s=()=>{while(n<t&&r(e.charCodeAt(n)))n++;let c=n;while(n<t&&!r(e.charCodeAt(n)))n++;return c<n?e.slice(c,n):null},o=s();if(o===null)return null;let i=Array(12);for(let c=0;c<12;c++){let a=s();if(a===null)return null;let p=+a;if(!Number.isFinite(p))return null;i[c]=p}while(n<t&&r(e.charCodeAt(n)))n++;if(n>=t)return null;let u=e.slice(n),l=/[ \\t]{2,}|\\t/.test(u)?u.split(/\\s+/).join(" "):u,f=nt(o);if(!Number.isFinite(f))return null;return{t:1,color:f,m:i,file:Y(l)}}var Ln=[0,12,6,9,12,12];function vt(e){let t=+e[0];if(!(t>=1&&t<=5&&Number.isInteger(t))||e.length<2)return null;let n=nt(e[1]),r=Ln[t];if(!Number.isFinite(n)||e.length<2+r+(t===1?1:0))return null;let s=Array(r);for(let o=0;o<r;o++){let i=+e[2+o];if(!Number.isFinite(i))return null;s[o]=i}if(t===1){let o=Y(e.slice(14).join(" "));return o?{t:1,color:n,m:s,file:o}:null}if(t===2)return{t:2,color:n,p:s};if(t===3)return{t:3,color:n,p:s};if(t===4)return{t:4,color:n,p:s};return{t:5,color:n,p:s}}function Ft(e,t="main.ldr",n={}){let r=!!n.geometryText,s=new Map,o=null,i="",u,l=null,f=[],c=null,a=()=>{if(!l)return;let m=vn(l.chunks.join("")),d=m[0]===137&&m[1]===80&&m[2]===78&&m[3]===71;(u??=new Map).set(Y(l.name),{name:l.name,bytes:m,...d?{mime:"image/png"}:{}}),l=null},p=!0,g=(m)=>{if(a(),o={name:Y(m),cmds:[]},s.set(o.name,o),!i)i=o.name;f=[],c=null,p=!0},h=!1,b=!1,v=()=>{if(b)return;b=!0,s.clear(),o=null,i=""},x=(m,d)=>{if(c){m.tex=c,c=null;return}let y=f[f.length-1];if(!y)return;if(y.fallback){if(!d)m.fallback=!0}else m.tex=y.map};for(let m of e.split(`\n`)){let d=m.trim();if(!d)continue;if(r&&d.charCodeAt(0)>=50&&d.charCodeAt(0)<=53&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)){if(l||h)continue;if(!o)g(t);let E=d.slice(2).trimStart(),B=E.search(/\\s/),k={t:d.charCodeAt(0)-48,color:nt(B<0?E:E.slice(0,B)),p:[],src:d};x(k,!1),o.cmds.push(k),p=!1;continue}if(d.charCodeAt(0)===48&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)){let E=2;while(d.charCodeAt(E)===32||d.charCodeAt(E)===9)E++;let B=E;while(B<d.length&&d.charCodeAt(B)!==32&&d.charCodeAt(B)!==9)B++;let k=d.slice(E,B),w=/[^\\x21-\\x7e]/.test(k)?d.slice(E).trim().split(/\\s+/)[0]:k;if(!dn.has(w)&&!(w.length>=4&&w.length<=6&&yn.has(w.toUpperCase()))){if(h||l)continue;if(!o)g(t);let M=d.slice(E),F={t:0,text:M};if(k.charCodeAt(0)===33)F.meta=k;if(c=null,p&&!o.org){let P=At(M);if(P)o.org=P}let N=M.match(Mt);if(N&&!o.movedTo){let P=N[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(P))P+=".dat";o.movedTo=Y(P)}o.cmds.push(F);continue}}if(d.charCodeAt(0)===49&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)&&!l&&!h){let E=Cn(d);if(E){if(!o)g(t);x(E,!1),o.cmds.push(E),p=!1;continue}}let y=d.split(/\\s+/);if(+y[0]===0){let E=d.slice(1).trim(),B=y.length>1&&y[1].length>=4&&y[1].length<=6?y[1].toUpperCase():y[1];if(B==="FILE"){let M=E.slice(5).trimStart().split("\\r")[0].trim();if(M){v(),h=!1,g(M);continue}}if(B==="NOFILE"){a(),o=null,h=!0;continue}if(B==="!DATA"){v(),a(),o=null,h=!1,l={name:E.slice(5).trim(),chunks:[]};continue}if(h)continue;if(l){if(y[1]==="!:")l.chunks.push(y.slice(2).join(""));continue}if(!o)g(t);let k={t:0,text:E};if(y[1]==="STEP")k.step=!0,f=[],c=null;else if(y[1]==="BFC")k.bfc=y.slice(2).join(" ");else if(y[1]==="ROTSTEP")if(k.meta="ROTSTEP",k.step=!0,f=[],c=null,(y[2]??"").toUpperCase()==="END")k.rotstep={x:0,y:0,z:0,mode:"END"};else{let M=(y[5]??"REL").toUpperCase(),F=(N)=>{let P=Number(N);return Number.isFinite(P)?P:0};k.rotstep={x:F(y[2]),y:F(y[3]),z:F(y[4]),mode:["REL","ABS","ADD"].includes(M)?M:"REL"}}else if(y[1]==="BUFEXCHG"){k.meta="BUFEXCHG";let M=(y[2]??"").toUpperCase();k.bufexchg={op:M==="RETRIEVE"?"RETRIEVE":"STORE",buf:y[3]??"A"}}else if(y[1]?.startsWith("!"))k.meta=y[1];if(p&&!o.org){let M=At(E);if(M)o.org=M}if(y[1]==="!TEXMAP"){let M=(y[2]??"").toUpperCase();if(c=null,M==="START"||M==="NEXT"){let F=An(E.replace(/^!TEXMAP\\s+\\S+/i,""),M==="NEXT");if(k.texmap={op:M,...F?{map:F}:{}},F)if((o.texmaps??=[]).push(F),M==="START")f.push({map:F,fallback:!1});else c=F}else if(M==="FALLBACK"){k.texmap={op:M};let F=f[f.length-1];if(F)F.fallback=!0}else if(M==="END")k.texmap={op:M},f.pop()}else if(y[1]==="!:"){c=null;let M=vt(y.slice(2));if(M)x(M,!0),k.geom=M}else c=null;let w=E.match(Mt);if(w&&!o.movedTo){let M=w[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(M))M+=".dat";o.movedTo=Y(M)}o.cmds.push(k);continue}if(l||h)continue;if(!o)g(t);let C=vt(y);if(!C){if(/^[2-5][ \\t]/.test(d))p=!1;continue}x(C,!1),o.cmds.push(C),p=!1}return a(),u?{main:i,files:s,data:u}:{main:i,files:s}}var qn=Math.PI/180;function It(e,t){let n=(r)=>[t[3]*r[0]+t[4]*r[1]+t[5]*r[2]+t[0],t[6]*r[0]+t[7]*r[1]+t[8]*r[2]+t[1],t[9]*r[0]+t[10]*r[1]+t[11]*r[2]+t[2]];return{...e,p1:n(e.p1),p2:n(e.p2),p3:n(e.p3)}}function Rt(e,t){let[n,r,s,o,i,u,l,f,c,a,p,g]=e,[h,b,v,x,m,d,y,D,C,E,B,k]=t;return[o*h+i*b+u*v+n,l*h+f*b+c*v+r,a*h+p*b+g*v+s,o*x+i*y+u*E,o*m+i*D+u*B,o*d+i*C+u*k,l*x+f*y+c*E,l*m+f*D+c*B,l*d+f*C+c*k,a*x+p*y+g*E,a*m+p*D+g*B,a*d+p*C+g*k]}var rt=[0,0,0,1,0,0,0,1,0,0,0,1];var Ct=new WeakMap,Tn=/^(s|8|48)\\//;function st(e,t){let n=e.files.get(Y(t));if(!n)return"part";let r=Ct.get(n);if(r)return r;if(n.org)r=Pt.has(n.org)?"part":"model";else if(n.name===e.main)r="model";else r=n.cmds.some((s)=>s.t>=2||s.t===0&&!!s.geom||s.t===1&&Tn.test(s.file))?"part":"model";return Ct.set(n,r),r}var Lt=new WeakMap;function Bt(e){let t=Lt.get(e);if(t)return t;t=[];let n=0;for(let r of e.cmds){if(r.t===0&&r.step){n++;continue}if((r.t>=2||r.t===0&&r.geom&&r.geom.t>=2)&&t[t.length-1]!==n)t.push(n)}return Lt.set(e,t),t}var Tt=(e)=>e>16777215?"0x"+e.toString(16).toUpperCase():e<0?qe.get(e)??String(e):String(e),En=(e)=>e.t===0?"0 "+e.text:e.t===1?`1 ${Tt(e.color)} ${e.m.join(" ")} ${e.file}`:e.src?e.src:`${e.t} ${Tt(e.color)} ${e.p.join(" ")}`,ot=(e,t)=>`${Y(e)}#${t}`;function Sn(e,t){let n=[],r=0,s=(o)=>!!o&&o.t===0&&o.texmap?.op==="NEXT";for(let o of e.cmds){if(o.t===0){if(o.step){r++;continue}if(o.bfc!==void 0||o.meta==="!COLOUR"){n.push(o);continue}if(r!==t)continue;if(o.texmap)n.push(o);else if(o.geom){if(o.geom.t>=2)n.push(o);else if(s(n[n.length-1]))n.pop()}continue}if(r!==t)continue;if(o.t===1){if(s(n[n.length-1]))n.pop();continue}n.push(o)}return{name:ot(e.name,t),cmds:n}}function Dt(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Sn(e,t).cmds.map(En)].join(`\n`)+`\n`}function it(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,"0")}function Ut(e){let[t,n,r,s,o,i,u,l,f,c,a,p]=e,g=l*p-f*a,h=-(u*p-f*c),b=u*a-l*c,v=s*g+o*h+i*b;if(!Number.isFinite(v)||Math.abs(v)<0.000000000001)return null;let x=1/v,m=[g*x,-(o*p-i*a)*x,(o*f-i*l)*x,h*x,(s*p-i*c)*x,-(s*f-i*u)*x,b*x,-(s*a-o*c)*x,(s*l-o*u)*x];return[-(m[0]*t+m[1]*n+m[2]*r),-(m[3]*t+m[4]*n+m[5]*r),-(m[6]*t+m[7]*n+m[8]*r),...m]}var kn=(e)=>String(+e.toFixed(6)||0),Et=(e)=>\'"\'+e.replace(/\\\\/g,"\\\\\\\\").replace(/"/g,"\\\\\\"")+\'"\';function Nt(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!=="PLANAR"?[t.a??360]:[],...t.method==="SPHERICAL"?[t.b??180]:[]].map(kn).join(" "),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${Et(t.texture)}${t.glossmap?" GLOSSMAP "+Et(t.glossmap):""}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${Y(e)}\n0 !TEXMAP END\n`;return{name:`${Y(e)}#tex-${it(r)}`,source:r}}var Pn=(e,t)=>{let n=[,,,,,,,,,];for(let r=0;r<3;r++)for(let s=0;s<3;s++)n[r*3+s]=e[r*3]*t[s]+e[r*3+1]*t[3+s]+e[r*3+2]*t[6+s];return n};function Fn(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),u=Math.cos(t*r),l=Math.sin(n*r),f=Math.cos(n*r);return[u*f,-u*l,i,o*l+s*i*f,o*f-s*i*l,-s*u,s*l-o*i*f,s*f+o*i*l,o*u]}var St=new WeakMap;function Ot(e){let t=St.get(e);if(t)return t;let n=[],r=null;for(let s of e.cmds){if(s.t!==0||!s.step)continue;let o=s.rotstep;if(o)if(o.mode==="END")r=null;else{let i=Fn(o.x,o.y,o.z);r=o.mode==="ABS"?{abs:!0,m:i,rotstep:o}:o.mode==="ADD"&&r?{abs:r.abs,m:Pn(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),St.set(e,n),n}class at extends Error{limit;code="ldr-model-limit";constructor(e,t){super(`ldr: ${e} expands past ${t.toLocaleString("en-US")} (see maxInstances)`);this.limit=t;this.name="ModelLimitError"}}var In=(e)=>{for(let t=0;t<12;t++)if(!(Math.abs(e[t])<=kt))return!1;return!0},zt=999999,Vt=(e)=>e.map((t)=>String(t).padStart(6,"0")).join(".")+"~",_t=new WeakMap,$t=new WeakMap;function Rn(e,t){let n=$t.get(t);if(!n)n={head:[...t.values()].map((o)=>{let i=_t.get(o)??"",u=i.indexOf("!COLOUR");return u<0?"":"0 "+i.slice(u).trim().replace(/\\s+/g," ")}).filter(Boolean).join(`\n`),parts:new Map},$t.set(t,n);let r=n.parts.get(e);if(!r){let s=Y(e),o=`0 ldr: ${s} placed in a model\'s !COLOUR scope\n0 BFC CERTIFY CCW\n${n.head}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${s}\n`;r={name:`${s}#col-${it(o)}`,source:o},n.parts.set(e,r)}return r}function Bn(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,u=new Map,l=0,f=new Set,c=t.maxInstances??2000000,a=0,p=(h,b)=>{let v=h.name+"#"+b,x=u.get(v);if(!x){let m;x=Object.assign(()=>m??=Dt(h,b),{file:h,step:b}),u.set(v,x)}return x},g=(h,b,v,x,m,d,y,D,C=null,E=[],B=[],k=void 0,w=null)=>{let M=h.files.get(b);if(!M||y>r||f.has(M))return;if(++a>c)throw new at("model",c);f.add(M);let F=w,N=0,P=y>0?++l:0,I=i&&P?[...E,P]:E,V=i&&P?[...B,v]:B,he=i&&!C?new Map:null,ce=-1,Ae=0,re=(O,L,_,X,q,ee,J)=>{if(ce!==N)ce=N,Ae=0;let T=he?.get(N+"|"+L);if(T)return T.n++,g(O,O===h?L:O.main,_,X,m+"/"+L,[...q,zt],y+1,ee,[...q,zt],I,V,J,F);let R=[...q,Ae++],A=n.length;g(O,O===h?L:O.main,_,X,m+"/"+L,R,y+1,ee,C,I,V,J,F),he?.set(N+"|"+L,{n:1,from:A,to:n.length})},Te=Ot(M),de=s?Bt(M):[],ve=0,fe=(O,L,_,X,q,ee,J,T,R)=>{if(C)X=C;if(++a>c)throw new at("model",c);let A={part:O,color:L,m:_,step:X[0],steps:X,localStep:q,path:m};if(T)A.colour=T;if(P){if(A.sub=P,i)A.subPath=I,A.subMats=V}if(ee)A.embedded=!0;if(J){let S=Nt(O,J);A.texPart=S.name,A.texSource=S.source}else if(R){let S=Rn(O,R);A.colPart=S.name,A.colSource=S.source}let U=Te[q];if(U)A.view=U;return n.push(A),A},Le=(O)=>{while(ve<de.length&&de[ve]<=O){let L=de[ve++];fe(ot(M.name,L),x,v,[...d,L],L,!1,null,k,w).source=p(M,L)}};for(let O of M.cmds){if(O.t===0&&O.step){N++;continue}let L=O;if(L.t>=2||L.t===0&&L.geom&&L.geom.t>=2){Le(N);continue}if(L.t===0){if(L.meta==="!COLOUR"){let U=Un(L.text);if(U&&U.code!==16&&U.code!==24)_t.set(U,L.text),(F=new Map(F??[])).set(U.code,U);continue}if(o&&L.geom?.t===1)L=L.geom;else continue}if(L.t!==1)continue;if(o&&L.fallback)continue;let _=Rt(v,L.m);if(!In(_))continue;let X=L.color===16?x:L.color,q=L.color===16?k:F?.get(L.color),ee=[...d,N],J=o?L.tex??D:null,T=J?Ut(L.m):null,R=J&&T?It(J,T):null;if(h.files.has(L.file)){if(st(h,L.file)==="model"){re(h,L.file,_,X,ee,R,q);continue}fe(L.file,X,_,ee,N,!0,R,q,F);continue}let A=t.resolveModel?.(L.file);if(A){re(A,L.file,_,X,ee,R,q);continue}fe(L.file,X,_,ee,N,!1,R,q,F)}if(Le(1/0),f.delete(M),he){for(let O of he.values())if(O.n>1)for(let L=O.from;L<O.to;L++)n[L].mult??=O.n}};if(st(e,e.main)==="part"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...rt],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return g(e,e.main,rt,16,e.main,[],0,null),n}function Gt(e,t="main.ldr",n){return Bn(Ft(e,t,{geometryText:!0}),n)}var Dn=new Set(["CHROME","PEARLESCENT","RUBBER","MATTE_METALLIC","METAL","MATERIAL"]);function lt(e){if(!e)return null;if(e.startsWith("#")&&/^#[0-9A-Fa-f]{6}$/.test(e))return e.toUpperCase();if(/^0x[0-9A-Fa-f]{6}$/i.test(e))return("#"+e.slice(2)).toUpperCase();return null}function jt(e,t){let n={value:"#FFFFFF",fraction:0.5};while(t<e.length){let r=e[t].toUpperCase(),s=e[t+1];if(r==="VALUE"){let o=lt(s);if(o)n.value=o;t+=2}else if(r==="ALPHA")n.alpha=+s,t+=2;else if(r==="LUMINANCE")n.luminance=+s,t+=2;else if(r==="FRACTION")n.fraction=+s,t+=2;else if(r==="VFRACTION")n.vfraction=+s,t+=2;else if(r==="SIZE")n.size=+s,t+=2;else if(r==="MINSIZE")n.minsize=+s,t+=2;else if(r==="MAXSIZE")n.maxsize=+s,t+=2;else break}return{grain:n,next:t}}function Un(e){let t=e.indexOf("!COLOUR");if(t<0)return null;let n=e.slice(t+7).trim().split(/\\s+/).filter(Boolean);if(n.length<2)return null;let r=n[0],s=NaN,o="#FF00FF",i="#333333",u=255,l=0,f={type:"default"},c=1;while(c<n.length){let a=n[c].toUpperCase(),p=n[c+1];if(a==="CODE")s=p!==void 0&&et.test(p)?tt(p):p!==void 0&&/^\\d+$/.test(p)?+p:NaN,c+=2;else if(a==="VALUE"){let g=lt(p);if(g)o=g;c+=2}else if(a==="EDGE")i=lt(p)??p,c+=2;else if(a==="ALPHA")u=+p,c+=2;else if(a==="LUMINANCE")l=+p,c+=2;else if(a==="CHROME")f={type:"chrome"},c+=1;else if(a==="PEARLESCENT")f={type:"pearlescent"},c+=1;else if(a==="RUBBER")f={type:"rubber"},c+=1;else if(a==="MATTE_METALLIC")f={type:"matte_metallic"},c+=1;else if(a==="METAL")f={type:"metal"},c+=1;else if(a==="MATERIAL"){let g=(n[c+1]||"").toUpperCase();if(g==="GLITTER"){let{grain:h,next:b}=jt(n,c+2);f={type:"glitter",material:h},c=b}else if(g==="SPECKLE"){let{grain:h,next:b}=jt(n,c+2);f={type:"speckle",material:h},c=b}else if(g==="FABRIC"){let h=(n[c+2]||"").toUpperCase(),b=["VELVET","CANVAS","STRING","FUR"].includes(h)?h.toLowerCase():void 0;f={type:"fabric",kind:b},c+=b?3:2}else c=n.length}else if(Dn.has(a))c+=1;else c+=1}if(Number.isNaN(s)||!o)return null;return{code:s,name:r,hex:o,edge:i,alpha:Number.isFinite(u)?u:255,luminance:Number.isFinite(l)?l:0,finish:f}}function Nn(e){let t=Math.max(0,Math.min(1,(e.alpha??255)/255)),n=t<1,r=Math.max(0,Math.min(1,(e.luminance??0)/255)),s={opacity:t,transparent:n,depthWrite:!n,emissive:r,clearcoat:0,clearcoatRoughness:0,sheen:0,sheenRoughness:0};switch(e.finish?.type??"default"){case"chrome":return{...s,metalness:1,roughness:0,finish:"chrome"};case"pearlescent":return{...s,metalness:0.25,roughness:0.3,clearcoat:0.5,clearcoatRoughness:0.25,sheen:0.4,sheenRoughness:0.35,finish:"pearlescent"};case"rubber":return{...s,metalness:0,roughness:0.9,finish:"rubber"};case"matte_metallic":return{...s,metalness:0.4,roughness:0.8,finish:"matte_metallic"};case"metal":return{...s,metalness:0.85,roughness:0.2,finish:"metal"};case"glitter":{let i=e.finish.material,u=i.size??(i.minsize!=null&&i.maxsize!=null?(i.minsize+i.maxsize)/2:1);return{...s,metalness:0.35,roughness:0.25,clearcoat:1,clearcoatRoughness:0.08,particleHex:i.value,particleFraction:i.fraction,particleSize:u,finish:"glitter"}}case"speckle":{let i=e.finish.material,u=i.size??(i.minsize!=null&&i.maxsize!=null?(i.minsize+i.maxsize)/2:1);return{...s,metalness:0.2,roughness:0.55,particleHex:i.value,particleFraction:i.fraction,particleSize:u,finish:"speckle"}}case"fabric":return{...s,metalness:0,roughness:0.85,sheen:0.65,sheenRoughness:0.75,finish:"fabric"};default:return{...s,metalness:0,roughness:0.45,finish:"default"}}}function ct(e){let t=Nn(e),n=!t.transparent?"op":t.opacity>=0.75?"a200":t.opacity>=0.4?"a128":`a${Math.round(t.opacity*255)}`,r=t.emissive>0?`L${Math.round(t.emissive*16)}`:"",s=`${t.finish}:${n}${r}`;if(t.particleHex)s+=`:${t.particleHex}:${(t.particleFraction??0).toFixed(2)}`;return s}function On(e,t){let n=new Map,r=null,s=!1,o=!1;for(let i of e.split(/\\r?\\n/)){let u=/^\\s*0\\s+FILE\\s+(\\S[^\\r]*)/i.exec(i);if(u){if(!s)n.clear();s=!0,o=!1,r=[],n.set(Y(u[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(i)){if(!s&&/!DATA/i.test(i))n.clear(),s=!0;r=null,o=!0;continue}if(!r){if(s||o)continue;r=[],n.set(Y(t),r)}let l=i.trim().replace(/\\s+/g," ");if(l)r.push(l)}return n}var zn=(e)=>{if(!e.startsWith("1 "))return null;let t=e.split(" ");return t.length>=15?Y(t.slice(14).join(" ")):null};function $n(e){let t=2166136261,n=1523705862;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);t=Math.imul(t^s,16777619),n=Math.imul(n^s,16777629)^n>>>15}return(t>>>0).toString(16).padStart(8,"0")+(n>>>0).toString(16).padStart(8,"0")}function Wt(e,t,n="main.ldr"){let r=On(e,n),s=new Map;for(let o of t){let i=Y(o);if(!r.has(i)||s.has(i))continue;let u=new Set([i]),l=[i];while(l.length)for(let c of r.get(l.pop())){let a=zn(c);if(a&&r.has(a)&&!u.has(a))u.add(a),l.push(a)}let f=[i,...[...u].filter((c)=>c!==i).sort()].map((c)=>"0 FILE "+(c===i?"":c)+`\n`+r.get(c).join(`\n`)).join(`\n`);s.set(i,`emb/${$n(f)}.dat`)}return s}var Xt=(e,t=0)=>Math.abs(e[t+7]-1)<0.001&&Math.abs(e[t+4])<0.001&&Math.abs(e[t+10])<0.001,Ht=new WeakMap,ut=null,ft="",pt=null;function mt(e,t){if(e===ut&&t===ft)return pt;let n=Ht.get(e);if(!n)Ht.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return ut=e,ft=t,pt=r,r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),u=[],l=[];s.studs.forEach((g,h)=>{u.push(g[0]),l.push(g[1]);for(let b=0;b<12;b++)i[h*12+b]=g[2+b]});let f=null,c=0,a=0;if(s.mask){c=s.mask[0],a=s.mask[1];let g=s.mask[2];f=new Uint8Array(g.length);for(let h=0;h<g.length;h++)f[h]=g.charCodeAt(h)===49?1:0}let p=!!f;if(f){for(let g=0;g<f.length;g++)if(f[g]!==1){p=!1;break}}return n.set(t,r={nStuds:o,studM:i,kind:u,color:l,mask:f,nx:c,nz:a,full:p}),ut=e,ft=t,pt=r,r}var Pe=1073741824;class ke{t;tag;mask;size=0;shift;constructor(e=1024,t=-1){let n=1024;while(n<e*2)n*=2;this.t=new Int32Array(n*4),this.tag=new Uint8Array(n),this.mask=n-1,this.shift=t}slot(e,t,n){let r=this.shift;if(r<0){let o=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return o^=o>>>15,o=Math.imul(o,739982445),o^=o>>>12,o&this.mask}let s=Math.imul(e>>r+2,2654435761)^Math.imul(t,2246822507)^Math.imul(n>>r+2,3266489909);return s^=s>>>15,s=Math.imul(s,739982445),s^=s>>>12,(s<<4|(e>>r&3)<<2|n>>r&3)&this.mask}static tagOf(e,t,n){return Math.imul(e^Math.imul(t,374761393)^Math.imul(n,668265261),2654435761)>>>24|1}get(e,t,n){let r=ke.tagOf(e,t,n),s=this.tag,o=this.t,i=this.mask,u=this.slot(e,t,n);for(;;){let l=s[u];if(l===0)return-1;if(l===r){let f=u<<2;if(o[f]===e&&o[f+1]===t&&o[f+2]===n)return o[f+3]}u=u+1&i}}put(e,t,n,r){if((this.size+1)*2>this.tag.length)this.grow();let s=ke.tagOf(e,t,n),o=this.tag,i=this.t,u=this.mask,l=this.slot(e,t,n);for(;;){let f=o[l],c=l<<2;if(f===0)return o[l]=s,i[c]=e,i[c+1]=t,i[c+2]=n,i[c+3]=r,this.size++,-1;if(f===s&&i[c]===e&&i[c+1]===t&&i[c+2]===n){let a=i[c+3];return i[c+3]=r,a}l=l+1&u}}grow(){let e=this.t,t=this.tag,n=t.length*2;this.t=new Int32Array(n*4),this.tag=new Uint8Array(n),this.mask=n-1,this.size=0;for(let r=0;r<t.length;r++)if(t[r]){let s=r<<2;this.put(e[s],e[s+1],e[s+2],e[s+3])}}}class Zt{grp=new ke(64);gBits=[];gX0=[];gZ0=[];gNz=[];gNx=[];bits;rest;lk=NaN;lpx=NaN;lpz=NaN;lg=-1;group(e,t,n){if(e!==this.lk||t!==this.lpx||n!==this.lpz)this.lk=e,this.lpx=t,this.lpz=n,this.lg=this.grp.get(e,t,n);return this.lg}constructor(e,t,n,r){let s=[],o=[],i=[],u=[],l=[];for(let a=0;a<r;a++){let p=e[a],g=t[a],h=n[a],b=(p%20+20)%20,v=(h%20+20)%20,x=this.group(g,b,v);if(x<0)x=s.length,this.grp.put(g,b,v,x),this.lg=x,s.push(0),o.push(p),i.push(p),u.push(h),l.push(h);if(s[x]++,p<o[x])o[x]=p;else if(p>i[x])i[x]=p;if(h<u[x])u[x]=h;else if(h>l[x])l[x]=h}let f=0,c=0;for(let a=0;a<s.length;a++){let p=(i[a]-o[a])/20+1,g=(l[a]-u[a])/20+1,h=p*g;if(this.gX0.push(o[a]),this.gZ0.push(u[a]),this.gNx.push(p),this.gNz.push(g),h<=64*s[a]+1024&&f+h<2147483648)this.gBits.push(f),f+=h;else this.gBits.push(-1),c+=s[a]}this.bits=new Uint8Array(Math.ceil(f/8)),this.rest=new ke(c);for(let a=0;a<r;a++){let p=e[a],g=t[a],h=n[a],b=this.group(g,(p%20+20)%20,(h%20+20)%20),v=this.gBits[b];if(v<0){this.rest.put(p,g,h,1);continue}let x=v+(p-this.gX0[b])/20*this.gNz[b]+(h-this.gZ0[b])/20;this.bits[x>>>3]|=1<<(x&7)}}has(e,t,n){let r=this.group(t,(e%20+20)%20,(n%20+20)%20);if(r<0)return!1;let s=this.gBits[r];if(s<0)return this.rest.get(e,t,n)>=0;let o=(e-this.gX0[r])/20,i=(n-this.gZ0[r])/20;if(o<0||i<0||o>=this.gNx[r]||i>=this.gNz[r])return!1;let u=s+o*this.gNz[r]+i;return(this.bits[u>>>3]&1<<(u&7))!==0}}var jn=(e,t,n,r)=>e===0&&r===0&&(t===1||t===-1)&&(n===1||n===-1)||t===0&&n===0&&(e===1||e===-1)&&(r===1||r===-1),Fe=(e,t,n)=>e>-Pe&&e<Pe&&t>-Pe&&t<Pe&&n>-Pe&&n<Pe,De=2147483647;function Vn(e,t){let n=e.colorTable?.[t];if(n)return(n.alpha??255)<255;return t.charCodeAt(0)===35&&/\\/[^:/]*:a\\d/.test(t)}function _n(e,t,n){return Kt(e,t,n,-1)??Kt(e,t,n,Yt)}var Yt=0;function Kt(e,t,n,r){let o=new Map,i=(T)=>{let R=o.get(T);if(R===void 0)o.set(T,R=Vn(t,T));return R},u=e.length,l=0,f=0;for(let T=0,R="";T<u;T++){let A=e[T].part;if(A===R){l++;continue}let U=t.parts[A];if(U&&U.mask)l++,R=A}let c=new Float64Array(l),a=new Float64Array(l),p=new Float64Array(l),g=new Float64Array(l),h=new Int32Array(l),b=new Int32Array(l),v=new Float64Array(l),x=new Float64Array(l),m=[],d=new Int32Array(l),y=new Float64Array(l*9),D=new Uint8Array(l);if(r<0)r=l*4+64;let C=new ke(e.length*2),E=new Int32Array(r),B=new Int32Array(r),k=0,w=0;for(let T=0;T<e.length;T++){let R=e[T],A=R.m,U=t.parts[R.part];if(!U||!U.mask||!Xt(A)||i(R.color))continue;let S=U.bbox,z=1/0,j=-1/0,te=1/0,H=-1/0;for(let K=0;K<2;K++)for(let le=0;le<2;le++){let ne=K?S[3]:S[0],Ee=le?S[5]:S[2],Me=A[0]+A[3]*ne+A[5]*Ee,be=A[2]+A[9]*ne+A[11]*Ee;if(Me<z)z=Me;if(Me>j)j=Me;if(be<te)te=be;if(be>H)H=be}let G=Math.round((A[1]+S[4])*2),Q=mt(t,R.part),ue=Math.floor(z/40),ye=Math.floor(j/40),xe=Math.floor(te/40),we=Math.floor(H/40);if(!((ye-ue+1)*(we-xe+1)<=65536)||!Fe(G,ue,xe)||!Fe(G,ye,we))continue;let ge=Math.floor((z+5)/40),se=Math.floor((j-5)/40),oe=Math.floor((te+5)/40),ie=Math.floor((H-5)/40),Ce=ge<=se&&oe<=ie?(se-ge+1)*(ie-oe+1):0;w+=Ce;let pe=-1;for(let K=ge<=se&&oe<=ie?C.get(G,ge,oe):-1,le=0;K>=0&&le<8;K=E[K],le++){let ne=B[K];if(c[ne]!==z||a[ne]!==j||p[ne]!==te||g[ne]!==H||m[ne]!==Q)continue;let Ee=e[h[ne]].m,Me=!0;for(let be=0;be<12;be++)if(Ee[be]!==A[be]){Me=!1;break}if(Me){pe=ne;break}}if(pe>=0){let K=n?n[T]:0;if(n&&K<n[h[pe]])b[pe]=h[pe],h[pe]=T;else if(b[pe]<0||n&&K<n[b[pe]])b[pe]=T;continue}let ae=f++;c[ae]=z,a[ae]=j,p[ae]=te,g[ae]=H,h[ae]=T,b[ae]=-1,m.push(Q),v[ae]=S[0],x[ae]=S[2],d[ae]=G;let me=ae*9;if(y[me]=A[0],y[me+1]=A[1],y[me+2]=A[2],y[me+3]=A[3],y[me+4]=A[6],y[me+5]=A[9],y[me+6]=A[5],y[me+7]=A[8],y[me+8]=A[11],D[ae]=Q.full&&S[3]-S[0]<=20*Q.nx&&S[5]-S[2]<=20*Q.nz&&A[4]===0&&A[6]===0&&A[8]===0&&A[10]===0&&jn(A[3],A[5],A[9],A[11])?1:0,k+Ce>r){k=r+1;continue}for(let K=ge;K<=se;K++)for(let le=oe;le<=ie;le++){if(!Fe(G,K,le))continue;let ne=k++;B[ne]=ae,E[ne]=C.put(G,K,le,ne)}}if(k>r)return Yt=w,null;let M=[0,5,-5,5,-5],F=[0,5,5,-5,-5],N=(T,R,A,U)=>{if(!(R-6>=c[T]-0.5&&R+6<=a[T]+0.5&&U-6>=p[T]-0.5&&U+6<=g[T]+0.5))return!1;if(D[T]===1)return!0;let S=T*9,z=m[T],j=v[T],te=x[T],H=R-y[S],G=A-y[S+1],Q=U-y[S+2],ue=y[S+3]*H+y[S+4]*G+y[S+5]*Q,ye=y[S+6]*H+y[S+7]*G+y[S+8]*Q,{nx:xe,nz:we,mask:ge}=z;for(let se=0;se<5;se++){let oe=Math.floor((ue+M[se]-j)/20),ie=Math.floor((ye+F[se]-te)/20);if(oe<0||ie<0||oe>=xe||ie>=we||ge[oe*we+ie]!==1)return!1}return!0},P=NaN,I=NaN,V=NaN,he=-1,ce=-1,Ae=(T,R,A,U)=>{let S=Math.round(R*2),z=Math.floor(T/40),j=Math.floor(A/40);if(!Fe(S,z,j))return De;let te=De;if(!n&&ce>=0&&d[ce]===S&&(h[ce]!==U||b[ce]>=0)&&N(ce,T,R,A))return 0;if(S!==P||z!==I||j!==V)P=S,I=z,V=j,he=C.get(S,z,j);for(let H=he;H>=0;H=E[H]){let G=B[H],Q=h[G];if(Q===U&&(Q=b[G])<0)continue;if(!N(G,T,R,A))continue;if(!n)return ce=G,0;let ue=n[Q];if(ue<te)te=ue}return te},re=0;for(let T of e){let R=mt(t,T.part);if(R)re+=R.nStuds}let Te=new Uint8Array(re),de=new Uint8Array(re),ve=0,fe=n?new ke(re,4):null,Le=n?null:new Int32Array(re),O=n?null:new Int32Array(re),L=n?null:new Int32Array(re),_=0,X=n?new Int32Array(re).fill(De):void 0;for(let T=0,R=0;T<e.length;T++){let A=e[T],U=mt(t,A.part);if(!U)continue;let S=A.m,z=U.studM,j=S[0],te=S[1],H=S[2],G=S[3],Q=S[4],ue=S[5],ye=S[6],xe=S[7],we=S[8],ge=S[9],se=S[10],oe=S[11];for(let ie=0;ie<U.nStuds;ie++,R++){let Ce=ie*12,pe=z[Ce+4],ae=z[Ce+7],me=z[Ce+10];if(!(Math.abs(ye*pe+xe*ae+we*me-1)<0.001&&Math.abs(G*pe+Q*ae+ue*me)<0.001&&Math.abs(ge*pe+se*ae+oe*me)<0.001))continue;de[R]=1;let K=z[Ce],le=z[Ce+1],ne=z[Ce+2],Ee=j+G*K+Q*le+ue*ne,Me=te+ye*K+xe*le+we*ne,be=H+ge*K+se*le+oe*ne,ht=Ae(Ee,Me,be,T);if(ht!==De){if(Te[R]=1,ve++,X)X[R]=ht}let Ue=Math.round(Ee),Ne=Math.round(Me),Oe=Math.round(be);if(!Fe(Ue,Ne,Oe))continue;if(!fe){Le[_]=Ue,O[_]=Ne,L[_++]=Oe;continue}let gt=n[T],bt=fe.get(Ue,Ne,Oe);if(bt<0||gt<bt)fe.put(Ue,Ne,Oe,gt)}}let q=fe?null:new Zt(Le,O,L,_),ee=new Uint8Array(e.length),J=n?new Int32Array(e.length).fill(De):void 0;for(let T=0;T<e.length;T++){let R=e[T],A=t.parts[R.part];if(!A||!A.under||!Xt(R.m)||i(R.color))continue;let U=A.bbox,S=Math.round((U[3]-U[0])/20),z=Math.round((U[5]-U[2])/20);if(!S||!z||S*z>4096)continue;let j=R.m,te=Math.round(j[1]+U[4]),H=!0,G=0;for(let Q=0;Q<S&&H;Q++)for(let ue=0;ue<z;ue++){let ye=U[0]+10+20*Q,xe=U[2]+10+20*ue,we=j[0]+j[3]*ye+j[5]*xe,ge=j[2]+j[9]*ye+j[11]*xe,se=Math.round(we),oe=Math.round(ge),ie=!Fe(se,te,oe)?-1:fe?fe.get(se,te,oe):q.has(se,te,oe)?1:-1;if(ie<0){H=!1;break}if(ie>G)G=ie}if(H){if(ee[T]=1,J)J[T]=G}}return{nStuds:re,studHidden:Te,studUp:de,underHidden:ee,studsHidden:ve,studHideStep:X,underHideStep:J}}function Gn(e,t,n){let r=(a)=>a.colPart&&t.parts[a.colPart]?a.colPart:n&&a.texPart&&t.parts[a.texPart]?a.texPart:a.part,s=new Map,o=new Map,i=(a)=>{let p=a.colour;if(!p)return String(a.color);let g=o.get(p);if(g!==void 0)return g;let h=t.colorTable?.[a.color],b=h?.hex??t.colors?.[a.color],v=h?ct({alpha:h.alpha??255,luminance:h.luminance??0,finish:h.finish??{type:"default"}}):"default:op",x=ct(p);if(g=b&&b.toUpperCase()===p.hex.toUpperCase()&&v===x?String(a.color):p.hex.toUpperCase()+"/"+x,g!==String(a.color))s.set(g,p);return o.set(p,g),g},u=e.map((a)=>({part:r(a),color:i(a),m:a.m,steps:a.steps})),l=u.map((a)=>Vt(a.steps)),f=[...new Set(l)].sort(),c=new Map(f.map((a,p)=>[a,p]));return{all:u,stepOf:l.map((a)=>c.get(a)),nSteps:f.length,localColours:s}}function _e(e,t,n=!0){let r=Gn(e,t,n);return _n(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Ke="https://ldr-demo.vercel.app/cdn/v1/",We=new Map,Ge=new Map;function Xe(e=Ke,t=fetch){let n=We.get(e);if(!n)n=t(e+"parts.json").then((r)=>{if(!r.ok)throw Error(`ldr: parts CDN index ${r.status} (${e}parts.json)`);return r.json()}),n.catch(()=>We.delete(e)),We.set(e,n);return n}var Wn=(e)=>Array.isArray(e)&&e.length===3&&typeof e[0]==="number"&&typeof e[1]==="number"&&(e[2]==="f32"||e[2]==="u16"||e[2]==="u8"||e[2]==="u32"),He=(e,t)=>Wn(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>He(n,t)):e&&typeof e==="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,He(r,t)])):e;function Xn(e,t={}){let n=[],r=0,s={},o={};for(let p of e){let g=p.buffer;if(!g)throw Error("ldr: mergePacks needs packs from decodePack/loadPack");let h=new DataView(g).getUint32(0,!0),b=new Uint8Array(g,4+h),v=r;n.push(b),r+=b.byteLength;let x=(4-r%4)%4;if(x)n.push(new Uint8Array(x)),r+=x;for(let[m,d]of Object.entries(p.header.parts??{}))if(!(m in s))s[m]=He(d,v);for(let[m,d]of Object.entries(p.header.studKinds??{}))if(!(m in o))o[m]=He(d,v)}let i=e[0]?.header??{version:1,weld:!0},u=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),l=(4-(4+u.length)%4)%4,f=4+u.length+l,c=new Uint8Array(f+r);new DataView(c.buffer).setUint32(0,u.length+l,!0),c.set(u,4),c.fill(32,4+u.length,f);let a=f;for(let p of n)c.set(p,a),a+=p.byteLength;return Ve(c.buffer)}async function Hn(e,t={}){e=[...e];try{return await Jt(e,t)}catch(n){let r=t.cdn??Ke,s=t.fetch??fetch;We.delete(r);let o=(i,u)=>s(i,{...u,cache:"reload"});try{return await Jt(e,{...t,fetch:o})}catch{throw n}}}async function Jt(e,t){let n=t.cdn??Ke,r=t.fetch??fetch,s=t.gap??16384,o=await Xe(n,r),i=[...new Set([...e].map(Y))],u=[],l=[];for(let m of i){if(Ge.has(n+m))continue;let d=o.parts[m];if(d)l.push({name:m,off:d[0],len:d[1],file:d[2]??0});else u.push(m)}l.sort((m,d)=>m.file-d.file||m.off-d.off);let f=[];for(let m of l){let d=f[f.length-1];if(d&&d.file===m.file&&m.off-d.end<=s)d.end=Math.max(d.end,m.off+m.len),d.items.push(m);else f.push({file:m.file,start:m.off,end:m.off+m.len,items:[m]})}let c=0,a=0,p=0,g=new Map,h=async()=>{while(p<f.length){let m=f[p++],d=g.get(m.file);if(d)d=d.subarray(m.start,m.end);else{let y=await r(new URL(o.archives[m.file],n).href,{headers:{Range:`bytes=${m.start}-${m.end-1}`,"Accept-Encoding":"identity"}});if(!y.ok)throw Error(`ldr: parts CDN ${y.status}`);if(a++,d=new Uint8Array(await y.arrayBuffer()),c+=d.byteLength,y.status===200)g.set(m.file,d),d=d.subarray(m.start,m.end)}for(let y of m.items){let D=je(d.subarray(y.off-m.start,y.off-m.start+y.len)),C=D.buffer.slice(D.byteOffset,D.byteOffset+D.byteLength);Ge.set(n+y.name,Ve(C))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,f.length)},h));let b=i.filter((m)=>Ge.has(n+m)).map((m)=>Ge.get(n+m)),v={colors:o.colors,...o.colorTable?{colorTable:o.colorTable}:{}};return{pack:b.length?Xn(b,v):Ve(Kn(v)),missing:u,requests:a,bytes:c}}function Kn(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},...e})),n=(4-(4+t.length)%4)%4,r=new Uint8Array(4+t.length+n).fill(32);return new DataView(r.buffer).setUint32(0,t.length+n,!0),r.set(t,4),r.buffer}function Zn(e,t){let n=t.header.parts;if(!n)return 0;let r=0;for(let s of e){let o=n[s.part]?.body?.tris;if(o)r+=o}return r}function Qt(e,t,n){let r=0,s=0,o=!1,i=new Set;for(let u of e){let l=u.embedded?t.get(u.part):Y(u.part),f=l?n.parts[l]:void 0;if(!f)continue;if(f[3]!=null)o=!0,r+=f[3];if(!i.has(l))i.add(l),s+=f[1]}return{bodyTris:r,packBytes:s,known:o}}class Ze extends Error{code="ldr-budget";bodyTris;packBytes;maxBodyTris;maxPackBytes;constructor(e){let t=[e.maxBodyTris!=null&&e.bodyTris>e.maxBodyTris?`${e.bodyTris} triangles (limit ${e.maxBodyTris})`:"",e.maxPackBytes!=null&&e.packBytes>e.maxPackBytes?`${(e.packBytes/1e6).toFixed(1)} MB parts pack (limit ${(e.maxPackBytes/1e6).toFixed(0)} MB)`:""].filter(Boolean).join(", ");super(`ldr: model exceeds device budget: ${t}`);this.name="BudgetError",this.bodyTris=e.bodyTris,this.packBytes=e.packBytes,this.maxBodyTris=e.maxBodyTris,this.maxPackBytes=e.maxPackBytes}}async function qt(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=Xe(t.cdn??Ke,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(w)=>{if(!w.ok)throw Error(`ldr: ${w.status} fetching ${e}`);return xt(await w.arrayBuffer())}),i=performance.now(),u=t.name??(t.text?"main.ldr":wt(e)),l=Gt(o,u,{looseGeometry:!1,callouts:t.callouts}),f=performance.now();t.onParsed?.(l),await s;let c=Wt(o,new Set(l.filter((w)=>w.embedded).map((w)=>w.part)),u),a=(w,M)=>t.maxBodyTris!=null&&w>t.maxBodyTris||t.maxPackBytes!=null&&M>t.maxPackBytes,p=t.maxBodyTris!=null||t.maxPackBytes!=null,g=(w)=>new Ze({...w,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes}),h="full";if(p){let w=Qt(l,c,await s);if(a(w.known?w.bodyTris:0,w.packBytes)){if(!t.lowCdn)throw g(w);let M=await Xe(t.lowCdn,r).catch(()=>null);if(!M)throw g(w);let F=Qt(l,c,M);if(a(F.known?F.bodyTris:0,F.packBytes))throw g(F);h="low"}}let b=[...l.filter((w)=>!w.embedded).map((w)=>w.part),...c.values()],v=async()=>{let w=await Hn(b,h==="low"?{...t,cdn:t.lowCdn}:t);for(let[M,F]of c){let N=w.pack.header.parts[F];if(N)w.pack.header.parts[M]=N}return{...w,packBytes:w.pack.buffer?.byteLength??w.pack.bytes??0,bodyTris:Zn(l,w.pack)}},x=await v();if(p&&a(x.bodyTris,x.packBytes)&&h==="full"&&t.lowCdn&&await Xe(t.lowCdn,r).then(()=>!0,()=>!1)){h="low";let w=x;x=await v(),x.requests+=w.requests,x.bytes+=w.bytes}if(p&&a(x.bodyTris,x.packBytes))throw g(x);let{pack:m,missing:d,requests:y,bytes:D}=x,C=new Map([...c].map(([w,M])=>[M,w])),E=d.map((w)=>C.get(w)??w),B=performance.now(),k=t.cull?_e(l,m.header,t.textures!==!1):void 0;return{insts:l,pack:m,tier:h,missing:E,requests:y,bytes:D,cull:k,timings:{fetchModel:i-n,parse:f-i,parts:B-f,...k?{cull:performance.now()-B}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await qt(n,{...r,cull:!1,onParsed:(c)=>self.postMessage({id:t,insts:c})}),o=s.pack.buffer;if(self.postMessage({id:t,buffer:o,tier:s.tier,missing:s.missing,requests:s.requests,bytes:s.bytes,timings:s.timings},[o]),!r.cull)return;let i=performance.now(),u=_e(s.insts,s.pack.header,r.textures!==!1),l=performance.now()-i,f=[];for(let c of[u.studHidden,u.studUp,u.underHidden,u.studHideStep,u.underHideStep])if(c)f.push(c.buffer);self.postMessage({id:t,cull:u,ms:l},f)}catch(s){if(s instanceof Ze||s?.code==="ldr-budget")self.postMessage({id:t,phase:"error",error:String(s?.message??s),budget:{bodyTris:s.bodyTris,packBytes:s.packBytes,maxBodyTris:s.maxBodyTris,maxPackBytes:s.maxPackBytes}});else self.postMessage({id:t,phase:"error",error:String(s?.message??s)})}};\n';
|
|
5080
5338
|
|
|
5081
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5339
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/cdn.ts
|
|
5082
5340
|
var worker;
|
|
5083
5341
|
var seq = 0;
|
|
5084
5342
|
var pending = new Map;
|
|
@@ -5192,7 +5450,7 @@ async function loadModel(source, o = {}) {
|
|
|
5192
5450
|
timings: { ...prep.timings, parts: t3 - t0 - prep.timings.fetchModel - prep.timings.parse, build: t4 - t3, total: t4 - t0 }
|
|
5193
5451
|
});
|
|
5194
5452
|
}
|
|
5195
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5453
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/node/library.ts
|
|
5196
5454
|
import { existsSync, readFileSync, statSync } from "fs";
|
|
5197
5455
|
import { join } from "path";
|
|
5198
5456
|
var xf = (m, x, y, z) => [m[3] * x + m[4] * y + m[5] * z + m[0], m[6] * x + m[7] * y + m[8] * z + m[1], m[9] * x + m[10] * y + m[11] * z + m[2]];
|
|
@@ -5542,11 +5800,11 @@ class Library {
|
|
|
5542
5800
|
return insts;
|
|
5543
5801
|
}
|
|
5544
5802
|
}
|
|
5545
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5803
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/node/build-pack.ts
|
|
5546
5804
|
import fs3 from "node:fs";
|
|
5547
5805
|
import path3 from "node:path";
|
|
5548
5806
|
|
|
5549
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5807
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/node/resolver.ts
|
|
5550
5808
|
import fs from "node:fs";
|
|
5551
5809
|
import path from "node:path";
|
|
5552
5810
|
var TOP_STUD_RE = /^(stud|studa|stud2|stud2a|stud6|stud6a|stud10|stud15|stud2s|stud2s2|stud-logo\d*|stud2-logo\d*)\.dat$/i;
|
|
@@ -5875,11 +6133,11 @@ function collectDeps(lib, refs) {
|
|
|
5875
6133
|
return out;
|
|
5876
6134
|
}
|
|
5877
6135
|
|
|
5878
|
-
// ../../../../../../../tmp/ldr-build-
|
|
6136
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/node/compile.ts
|
|
5879
6137
|
import fs2 from "node:fs";
|
|
5880
6138
|
import path2 from "node:path";
|
|
5881
6139
|
|
|
5882
|
-
// ../../../../../../../tmp/ldr-build-
|
|
6140
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/node/lod.ts
|
|
5883
6141
|
import { MeshoptSimplifier, MeshoptEncoder } from "meshoptimizer";
|
|
5884
6142
|
await Promise.all([MeshoptSimplifier.ready, MeshoptEncoder.ready]);
|
|
5885
6143
|
function reorderMesh(P, N, C, I) {
|
|
@@ -6185,7 +6443,7 @@ function levelLines(P, I, E, err, always, tol = 0.01) {
|
|
|
6185
6443
|
return out;
|
|
6186
6444
|
}
|
|
6187
6445
|
|
|
6188
|
-
// ../../../../../../../tmp/ldr-build-
|
|
6446
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/node/compile.ts
|
|
6189
6447
|
class BfcState {
|
|
6190
6448
|
accum;
|
|
6191
6449
|
ccw = true;
|
|
@@ -7129,7 +7387,7 @@ function encodePack(parts, studKinds, weld, extra, options = {}) {
|
|
|
7129
7387
|
return Buffer.concat([head, ...chunks.map((c) => new Uint8Array(c.buffer, c.byteOffset, c.byteLength))]);
|
|
7130
7388
|
}
|
|
7131
7389
|
|
|
7132
|
-
// ../../../../../../../tmp/ldr-build-
|
|
7390
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/node/build-pack.ts
|
|
7133
7391
|
function packCompilerOpts(o) {
|
|
7134
7392
|
return { studs: o.studs ?? "low", prims: o.primitives ?? "full", weld: o.weld ?? true, separateStuds: true, cond: !!o.cond, tex: !!o.textures, ...o.partWorkLimit ? { workLimit: o.partWorkLimit } : {} };
|
|
7135
7393
|
}
|
|
@@ -7201,7 +7459,7 @@ function buildPack(o) {
|
|
|
7201
7459
|
const warnings = [...lib.conflicts].map((n) => `${n}: defined differently by two models; the first definition is used`);
|
|
7202
7460
|
return { data: encodePack(parts, kinds, comp.opts.weld, extra, { texture, lod: o.lod !== false, reorder: !!o.reorder }), parts: parts.size, studKinds: kinds.size, missing: [...missing], ...warnings.length ? { warnings } : {} };
|
|
7203
7461
|
}
|
|
7204
|
-
// ../../../../../../../tmp/ldr-build-
|
|
7462
|
+
// ../../../../../../../tmp/ldr-build-TOtjq4/src/node/promote.ts
|
|
7205
7463
|
var GEOM = /^\s*[2-5]\s/;
|
|
7206
7464
|
var REF = /^\s*1\s/;
|
|
7207
7465
|
var FILE = /^\s*0\s+FILE\s+(\S.*?)\s*$/i;
|