ldr 0.33.11 → 0.33.13
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 +35 -8
- package/dist/index.js +394 -162
- package/dist/load-worker.gen.d.ts +1 -1
- package/dist/node/index.js +402 -170
- package/dist/render.d.ts +17 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1
|
+
// ../../../../../../../tmp/ldr-build-DCpOVo/src/spec.ts
|
|
2
2
|
var norm = (s) => s.trim().toLowerCase().replace(/\\/g, "/").replace(/\/+/g, "/");
|
|
3
3
|
var COLOUR_ID_RE = /^[A-Za-z][A-Za-z0-9_]*$/;
|
|
4
4
|
var namedCodes = new Map;
|
|
@@ -778,7 +778,7 @@ function fileStepViews(f) {
|
|
|
778
778
|
viewMemo.set(f, out);
|
|
779
779
|
return out;
|
|
780
780
|
}
|
|
781
|
-
// ../../../../../../../tmp/ldr-build-
|
|
781
|
+
// ../../../../../../../tmp/ldr-build-DCpOVo/src/model.ts
|
|
782
782
|
class ModelLimitError extends Error {
|
|
783
783
|
limit;
|
|
784
784
|
code = "ldr-model-limit";
|
|
@@ -1219,7 +1219,7 @@ function blendedColourHex(code) {
|
|
|
1219
1219
|
const a = LDRAW_EXE_16[code - 256 >> 4], b = LDRAW_EXE_16[code - 256 & 15];
|
|
1220
1220
|
return "#" + [0, 1, 2].map((k) => (a[k] + b[k] >> 1).toString(16).padStart(2, "0")).join("").toUpperCase();
|
|
1221
1221
|
}
|
|
1222
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1222
|
+
// ../../../../../../../tmp/ldr-build-DCpOVo/src/instructions.ts
|
|
1223
1223
|
var MIN_VIS = 0.5;
|
|
1224
1224
|
var REORIENT = 0.35;
|
|
1225
1225
|
var deg = Math.PI / 180;
|
|
@@ -1587,10 +1587,10 @@ function planStepViews(insts, parts, stepOf, nSteps, o = {}) {
|
|
|
1587
1587
|
}
|
|
1588
1588
|
};
|
|
1589
1589
|
}
|
|
1590
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1590
|
+
// ../../../../../../../tmp/ldr-build-DCpOVo/src/render.ts
|
|
1591
1591
|
import * as THREE from "three";
|
|
1592
1592
|
|
|
1593
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1593
|
+
// ../../../../../../../tmp/ldr-build-DCpOVo/src/pack-io.ts
|
|
1594
1594
|
import { decompress } from "fzstd";
|
|
1595
1595
|
async function decompressPack(data) {
|
|
1596
1596
|
const u = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
@@ -1613,16 +1613,25 @@ function decodePack(buf) {
|
|
|
1613
1613
|
return { header, arr, bytes: buf.byteLength, buffer: buf };
|
|
1614
1614
|
}
|
|
1615
1615
|
|
|
1616
|
-
// ../../../../../../../tmp/ldr-build-
|
|
1616
|
+
// ../../../../../../../tmp/ldr-build-DCpOVo/src/cull.ts
|
|
1617
1617
|
var upright = (m, o = 0) => Math.abs(m[o + 7] - 1) < 0.001 && Math.abs(m[o + 4]) < 0.001 && Math.abs(m[o + 10]) < 0.001;
|
|
1618
1618
|
var prepCache = new WeakMap;
|
|
1619
|
+
var lastH = null;
|
|
1620
|
+
var lastPart = "";
|
|
1621
|
+
var lastPrep = null;
|
|
1619
1622
|
function prepPart(H, part) {
|
|
1623
|
+
if (H === lastH && part === lastPart)
|
|
1624
|
+
return lastPrep;
|
|
1620
1625
|
let c = prepCache.get(H);
|
|
1621
1626
|
if (!c)
|
|
1622
1627
|
prepCache.set(H, c = new Map);
|
|
1623
1628
|
let r = c.get(part);
|
|
1624
|
-
if (r !== undefined)
|
|
1629
|
+
if (r !== undefined) {
|
|
1630
|
+
lastH = H;
|
|
1631
|
+
lastPart = part;
|
|
1632
|
+
lastPrep = r;
|
|
1625
1633
|
return r;
|
|
1634
|
+
}
|
|
1626
1635
|
const p = H.parts[part];
|
|
1627
1636
|
if (!p) {
|
|
1628
1637
|
c.set(part, null);
|
|
@@ -1646,7 +1655,18 @@ function prepPart(H, part) {
|
|
|
1646
1655
|
for (let i = 0;i < bits.length; i++)
|
|
1647
1656
|
mask[i] = bits.charCodeAt(i) === 49 ? 1 : 0;
|
|
1648
1657
|
}
|
|
1649
|
-
|
|
1658
|
+
let full = !!mask;
|
|
1659
|
+
if (mask) {
|
|
1660
|
+
for (let i = 0;i < mask.length; i++)
|
|
1661
|
+
if (mask[i] !== 1) {
|
|
1662
|
+
full = false;
|
|
1663
|
+
break;
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
c.set(part, r = { nStuds: n, studM, kind, color, mask, nx, nz, full });
|
|
1667
|
+
lastH = H;
|
|
1668
|
+
lastPart = part;
|
|
1669
|
+
lastPrep = r;
|
|
1650
1670
|
return r;
|
|
1651
1671
|
}
|
|
1652
1672
|
function mul12To(a, b, bo, w, ao = 0) {
|
|
@@ -1663,80 +1683,185 @@ var singular12 = (m, d = det12(m)) => d * d <= 0.000000000000000001 * (m[3] * m[
|
|
|
1663
1683
|
var BIG = 1073741824;
|
|
1664
1684
|
|
|
1665
1685
|
class Int3Table {
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
c;
|
|
1669
|
-
vals;
|
|
1670
|
-
used;
|
|
1686
|
+
t;
|
|
1687
|
+
tag;
|
|
1671
1688
|
mask;
|
|
1672
1689
|
size = 0;
|
|
1673
|
-
|
|
1690
|
+
shift;
|
|
1691
|
+
constructor(cap = 1024, shift = -1) {
|
|
1674
1692
|
let n = 1024;
|
|
1675
1693
|
while (n < cap * 2)
|
|
1676
1694
|
n *= 2;
|
|
1677
|
-
this.
|
|
1678
|
-
this.
|
|
1679
|
-
this.c = new Int32Array(n);
|
|
1680
|
-
this.vals = new Int32Array(n);
|
|
1681
|
-
this.used = new Uint8Array(n);
|
|
1695
|
+
this.t = new Int32Array(n * 4);
|
|
1696
|
+
this.tag = new Uint8Array(n);
|
|
1682
1697
|
this.mask = n - 1;
|
|
1698
|
+
this.shift = shift;
|
|
1683
1699
|
}
|
|
1684
1700
|
slot(x, y, z) {
|
|
1685
|
-
|
|
1701
|
+
const s = this.shift;
|
|
1702
|
+
if (s < 0) {
|
|
1703
|
+
let h = Math.imul(x, 2654435761) ^ Math.imul(y, 2246822507) ^ Math.imul(z, 3266489909);
|
|
1704
|
+
h ^= h >>> 15;
|
|
1705
|
+
h = Math.imul(h, 739982445);
|
|
1706
|
+
h ^= h >>> 12;
|
|
1707
|
+
return h & this.mask;
|
|
1708
|
+
}
|
|
1709
|
+
let h = Math.imul(x >> s + 2, 2654435761) ^ Math.imul(y, 2246822507) ^ Math.imul(z >> s + 2, 3266489909);
|
|
1686
1710
|
h ^= h >>> 15;
|
|
1687
1711
|
h = Math.imul(h, 739982445);
|
|
1688
1712
|
h ^= h >>> 12;
|
|
1689
|
-
return h & this.mask;
|
|
1713
|
+
return (h << 4 | (x >> s & 3) << 2 | z >> s & 3) & this.mask;
|
|
1714
|
+
}
|
|
1715
|
+
static tagOf(x, y, z) {
|
|
1716
|
+
const g = Math.imul(x ^ Math.imul(y, 374761393) ^ Math.imul(z, 668265261), 2654435761);
|
|
1717
|
+
return g >>> 24 | 1;
|
|
1690
1718
|
}
|
|
1691
1719
|
get(x, y, z) {
|
|
1720
|
+
const g = Int3Table.tagOf(x, y, z), G = this.tag, T = this.t, M = this.mask;
|
|
1692
1721
|
let i = this.slot(x, y, z);
|
|
1693
|
-
const U = this.used, A = this.a, B = this.b, C = this.c;
|
|
1694
1722
|
for (;; ) {
|
|
1695
|
-
|
|
1723
|
+
const q = G[i];
|
|
1724
|
+
if (q === 0)
|
|
1696
1725
|
return -1;
|
|
1697
|
-
if (
|
|
1698
|
-
|
|
1699
|
-
|
|
1726
|
+
if (q === g) {
|
|
1727
|
+
const o = i << 2;
|
|
1728
|
+
if (T[o] === x && T[o + 1] === y && T[o + 2] === z)
|
|
1729
|
+
return T[o + 3];
|
|
1730
|
+
}
|
|
1731
|
+
i = i + 1 & M;
|
|
1700
1732
|
}
|
|
1701
1733
|
}
|
|
1702
1734
|
put(x, y, z, v) {
|
|
1703
|
-
if ((this.size + 1) * 2 > this.
|
|
1735
|
+
if ((this.size + 1) * 2 > this.tag.length)
|
|
1704
1736
|
this.grow();
|
|
1737
|
+
const g = Int3Table.tagOf(x, y, z), G = this.tag, T = this.t, M = this.mask;
|
|
1705
1738
|
let i = this.slot(x, y, z);
|
|
1706
|
-
const U = this.used, A = this.a, B = this.b, C = this.c;
|
|
1707
1739
|
for (;; ) {
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1740
|
+
const q = G[i];
|
|
1741
|
+
const o = i << 2;
|
|
1742
|
+
if (q === 0) {
|
|
1743
|
+
G[i] = g;
|
|
1744
|
+
T[o] = x;
|
|
1745
|
+
T[o + 1] = y;
|
|
1746
|
+
T[o + 2] = z;
|
|
1747
|
+
T[o + 3] = v;
|
|
1714
1748
|
this.size++;
|
|
1715
1749
|
return -1;
|
|
1716
1750
|
}
|
|
1717
|
-
if (
|
|
1718
|
-
const
|
|
1719
|
-
|
|
1720
|
-
return
|
|
1751
|
+
if (q === g && T[o] === x && T[o + 1] === y && T[o + 2] === z) {
|
|
1752
|
+
const w = T[o + 3];
|
|
1753
|
+
T[o + 3] = v;
|
|
1754
|
+
return w;
|
|
1721
1755
|
}
|
|
1722
|
-
i = i + 1 &
|
|
1756
|
+
i = i + 1 & M;
|
|
1723
1757
|
}
|
|
1724
1758
|
}
|
|
1725
1759
|
grow() {
|
|
1726
|
-
const
|
|
1727
|
-
const n =
|
|
1728
|
-
this.
|
|
1729
|
-
this.
|
|
1730
|
-
this.c = new Int32Array(n);
|
|
1731
|
-
this.vals = new Int32Array(n);
|
|
1732
|
-
this.used = new Uint8Array(n);
|
|
1760
|
+
const T = this.t, G = this.tag;
|
|
1761
|
+
const n = G.length * 2;
|
|
1762
|
+
this.t = new Int32Array(n * 4);
|
|
1763
|
+
this.tag = new Uint8Array(n);
|
|
1733
1764
|
this.mask = n - 1;
|
|
1734
1765
|
this.size = 0;
|
|
1735
|
-
for (let i = 0;i <
|
|
1736
|
-
if (
|
|
1737
|
-
|
|
1766
|
+
for (let i = 0;i < G.length; i++)
|
|
1767
|
+
if (G[i]) {
|
|
1768
|
+
const o = i << 2;
|
|
1769
|
+
this.put(T[o], T[o + 1], T[o + 2], T[o + 3]);
|
|
1770
|
+
}
|
|
1738
1771
|
}
|
|
1739
1772
|
}
|
|
1773
|
+
|
|
1774
|
+
class StudTopSet {
|
|
1775
|
+
grp = new Int3Table(64);
|
|
1776
|
+
gBits = [];
|
|
1777
|
+
gX0 = [];
|
|
1778
|
+
gZ0 = [];
|
|
1779
|
+
gNz = [];
|
|
1780
|
+
gNx = [];
|
|
1781
|
+
bits;
|
|
1782
|
+
rest;
|
|
1783
|
+
lk = NaN;
|
|
1784
|
+
lpx = NaN;
|
|
1785
|
+
lpz = NaN;
|
|
1786
|
+
lg = -1;
|
|
1787
|
+
group(y, px, pz) {
|
|
1788
|
+
if (y !== this.lk || px !== this.lpx || pz !== this.lpz) {
|
|
1789
|
+
this.lk = y;
|
|
1790
|
+
this.lpx = px;
|
|
1791
|
+
this.lpz = pz;
|
|
1792
|
+
this.lg = this.grp.get(y, px, pz);
|
|
1793
|
+
}
|
|
1794
|
+
return this.lg;
|
|
1795
|
+
}
|
|
1796
|
+
constructor(X, Y, Z, n) {
|
|
1797
|
+
const cnt = [], x0 = [], x1 = [], z0 = [], z1 = [];
|
|
1798
|
+
for (let i = 0;i < n; i++) {
|
|
1799
|
+
const x = X[i], y = Y[i], z = Z[i], px = (x % 20 + 20) % 20, pz = (z % 20 + 20) % 20;
|
|
1800
|
+
let g = this.group(y, px, pz);
|
|
1801
|
+
if (g < 0) {
|
|
1802
|
+
g = cnt.length;
|
|
1803
|
+
this.grp.put(y, px, pz, g);
|
|
1804
|
+
this.lg = g;
|
|
1805
|
+
cnt.push(0);
|
|
1806
|
+
x0.push(x);
|
|
1807
|
+
x1.push(x);
|
|
1808
|
+
z0.push(z);
|
|
1809
|
+
z1.push(z);
|
|
1810
|
+
}
|
|
1811
|
+
cnt[g]++;
|
|
1812
|
+
if (x < x0[g])
|
|
1813
|
+
x0[g] = x;
|
|
1814
|
+
else if (x > x1[g])
|
|
1815
|
+
x1[g] = x;
|
|
1816
|
+
if (z < z0[g])
|
|
1817
|
+
z0[g] = z;
|
|
1818
|
+
else if (z > z1[g])
|
|
1819
|
+
z1[g] = z;
|
|
1820
|
+
}
|
|
1821
|
+
let total = 0, nRest = 0;
|
|
1822
|
+
for (let g = 0;g < cnt.length; g++) {
|
|
1823
|
+
const nx = (x1[g] - x0[g]) / 20 + 1, nz = (z1[g] - z0[g]) / 20 + 1, b = nx * nz;
|
|
1824
|
+
this.gX0.push(x0[g]);
|
|
1825
|
+
this.gZ0.push(z0[g]);
|
|
1826
|
+
this.gNx.push(nx);
|
|
1827
|
+
this.gNz.push(nz);
|
|
1828
|
+
if (b <= 64 * cnt[g] + 1024 && total + b < 2 ** 31) {
|
|
1829
|
+
this.gBits.push(total);
|
|
1830
|
+
total += b;
|
|
1831
|
+
} else {
|
|
1832
|
+
this.gBits.push(-1);
|
|
1833
|
+
nRest += cnt[g];
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
this.bits = new Uint8Array(Math.ceil(total / 8));
|
|
1837
|
+
this.rest = new Int3Table(nRest);
|
|
1838
|
+
for (let i = 0;i < n; i++) {
|
|
1839
|
+
const x = X[i], y = Y[i], z = Z[i];
|
|
1840
|
+
const g = this.group(y, (x % 20 + 20) % 20, (z % 20 + 20) % 20);
|
|
1841
|
+
const o = this.gBits[g];
|
|
1842
|
+
if (o < 0) {
|
|
1843
|
+
this.rest.put(x, y, z, 1);
|
|
1844
|
+
continue;
|
|
1845
|
+
}
|
|
1846
|
+
const k = o + (x - this.gX0[g]) / 20 * this.gNz[g] + (z - this.gZ0[g]) / 20;
|
|
1847
|
+
this.bits[k >>> 3] |= 1 << (k & 7);
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
has(x, y, z) {
|
|
1851
|
+
const g = this.group(y, (x % 20 + 20) % 20, (z % 20 + 20) % 20);
|
|
1852
|
+
if (g < 0)
|
|
1853
|
+
return false;
|
|
1854
|
+
const o = this.gBits[g];
|
|
1855
|
+
if (o < 0)
|
|
1856
|
+
return this.rest.get(x, y, z) >= 0;
|
|
1857
|
+
const a = (x - this.gX0[g]) / 20, c = (z - this.gZ0[g]) / 20;
|
|
1858
|
+
if (a < 0 || c < 0 || a >= this.gNx[g] || c >= this.gNz[g])
|
|
1859
|
+
return false;
|
|
1860
|
+
const k = o + a * this.gNz[g] + c;
|
|
1861
|
+
return (this.bits[k >>> 3] & 1 << (k & 7)) !== 0;
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
var quarterTurn = (a, c, g, i) => a === 0 && i === 0 && (c === 1 || c === -1) && (g === 1 || g === -1) || c === 0 && g === 0 && (a === 1 || a === -1) && (i === 1 || i === -1);
|
|
1740
1865
|
var inRange = (x, y, z) => x > -BIG && x < BIG && y > -BIG && y < BIG && z > -BIG && z < BIG;
|
|
1741
1866
|
var STEP_NEVER = 2147483647;
|
|
1742
1867
|
function forEachStud(insts, H, fn) {
|
|
@@ -1770,6 +1895,8 @@ function cullCore(insts, H, steps) {
|
|
|
1770
1895
|
return v;
|
|
1771
1896
|
};
|
|
1772
1897
|
const rx0 = [], rx1 = [], rz0 = [], rz1 = [], rInst = [], rInst2 = [], rPrep = [], rBx = [], rBz = [];
|
|
1898
|
+
const rLv = [], rM = [];
|
|
1899
|
+
const rFast = [];
|
|
1773
1900
|
const cells = new Int3Table(insts.length * 2);
|
|
1774
1901
|
const nextE = [], rectE = [];
|
|
1775
1902
|
for (let idx = 0;idx < insts.length; idx++) {
|
|
@@ -1834,6 +1961,9 @@ function cullCore(insts, H, steps) {
|
|
|
1834
1961
|
rPrep.push(pp);
|
|
1835
1962
|
rBx.push(b[0]);
|
|
1836
1963
|
rBz.push(b[2]);
|
|
1964
|
+
rLv.push(lv2);
|
|
1965
|
+
rM.push(m[0], m[1], m[2], m[3], m[6], m[9], m[5], m[8], m[11]);
|
|
1966
|
+
rFast.push(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);
|
|
1837
1967
|
for (let cx = cx0;cx <= cx1; cx++)
|
|
1838
1968
|
for (let cz = cz0;cz <= cz1; cz++) {
|
|
1839
1969
|
if (!inRange(lv2, cx, cz))
|
|
@@ -1844,12 +1974,31 @@ function cullCore(insts, H, steps) {
|
|
|
1844
1974
|
}
|
|
1845
1975
|
}
|
|
1846
1976
|
const SX = [0, 5, -5, 5, -5], SZ = [0, 5, 5, -5, -5];
|
|
1977
|
+
const covers = (ri, x, y, z) => {
|
|
1978
|
+
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))
|
|
1979
|
+
return false;
|
|
1980
|
+
if (rFast[ri] === 1)
|
|
1981
|
+
return true;
|
|
1982
|
+
const o = ri * 9, pp = rPrep[ri], bx = rBx[ri], bz = rBz[ri];
|
|
1983
|
+
const dx = x - rM[o], dy = y - rM[o + 1], dz = z - rM[o + 2];
|
|
1984
|
+
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;
|
|
1985
|
+
const { nx, nz, mask: bits } = pp;
|
|
1986
|
+
for (let s = 0;s < 5; s++) {
|
|
1987
|
+
const ca = Math.floor((lx + SX[s] - bx) / 20), cb = Math.floor((lz + SZ[s] - bz) / 20);
|
|
1988
|
+
if (ca < 0 || cb < 0 || ca >= nx || cb >= nz || bits[ca * nz + cb] !== 1)
|
|
1989
|
+
return false;
|
|
1990
|
+
}
|
|
1991
|
+
return true;
|
|
1992
|
+
};
|
|
1847
1993
|
let kl = NaN, kx = NaN, kz = NaN, ke = -1;
|
|
1994
|
+
let lastRi = -1;
|
|
1848
1995
|
const coverStep = (x, y, z, self) => {
|
|
1849
1996
|
const l2 = Math.round(y * 2), gx = Math.floor(x / CELL), gz = Math.floor(z / CELL);
|
|
1850
1997
|
if (!inRange(l2, gx, gz))
|
|
1851
1998
|
return STEP_NEVER;
|
|
1852
1999
|
let best = STEP_NEVER;
|
|
2000
|
+
if (!steps && lastRi >= 0 && rLv[lastRi] === l2 && (rInst[lastRi] !== self || rInst2[lastRi] >= 0) && covers(lastRi, x, y, z))
|
|
2001
|
+
return 0;
|
|
1853
2002
|
if (l2 !== kl || gx !== kx || gz !== kz) {
|
|
1854
2003
|
kl = l2;
|
|
1855
2004
|
kx = gx;
|
|
@@ -1861,29 +2010,15 @@ function cullCore(insts, H, steps) {
|
|
|
1861
2010
|
let by = rInst[ri];
|
|
1862
2011
|
if (by === self && (by = rInst2[ri]) < 0)
|
|
1863
2012
|
continue;
|
|
1864
|
-
if (!(
|
|
2013
|
+
if (!covers(ri, x, y, z))
|
|
1865
2014
|
continue;
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
const dx = x - m[0], dy = y - m[1], dz = z - m[2];
|
|
1870
|
-
const lx = m[3] * dx + m[6] * dy + m[9] * dz, lz = m[5] * dx + m[8] * dy + m[11] * dz;
|
|
1871
|
-
const { nx, nz, mask: bits } = pp;
|
|
1872
|
-
let ok = true;
|
|
1873
|
-
for (let s = 0;s < 5; s++) {
|
|
1874
|
-
const ca = Math.floor((lx + SX[s] - bx) / 20), cb = Math.floor((lz + SZ[s] - bz) / 20);
|
|
1875
|
-
if (ca < 0 || cb < 0 || ca >= nx || cb >= nz || bits[ca * nz + cb] !== 1) {
|
|
1876
|
-
ok = false;
|
|
1877
|
-
break;
|
|
1878
|
-
}
|
|
1879
|
-
}
|
|
1880
|
-
if (ok) {
|
|
1881
|
-
if (!steps)
|
|
1882
|
-
return 0;
|
|
1883
|
-
const st = steps[by];
|
|
1884
|
-
if (st < best)
|
|
1885
|
-
best = st;
|
|
2015
|
+
if (!steps) {
|
|
2016
|
+
lastRi = ri;
|
|
2017
|
+
return 0;
|
|
1886
2018
|
}
|
|
2019
|
+
const st = steps[by];
|
|
2020
|
+
if (st < best)
|
|
2021
|
+
best = st;
|
|
1887
2022
|
}
|
|
1888
2023
|
return best;
|
|
1889
2024
|
};
|
|
@@ -1894,8 +2029,10 @@ function cullCore(insts, H, steps) {
|
|
|
1894
2029
|
nStuds += pp.nStuds;
|
|
1895
2030
|
}
|
|
1896
2031
|
const studHidden = new Uint8Array(nStuds), studUp = new Uint8Array(nStuds);
|
|
1897
|
-
const tops = new Int3Table(nStuds);
|
|
1898
2032
|
let studsHidden = 0;
|
|
2033
|
+
const tops = steps ? new Int3Table(nStuds, 4) : null;
|
|
2034
|
+
const TX = steps ? null : new Int32Array(nStuds), TY = steps ? null : new Int32Array(nStuds), TZ = steps ? null : new Int32Array(nStuds);
|
|
2035
|
+
let nT = 0;
|
|
1899
2036
|
const studHideStep = steps ? new Int32Array(nStuds).fill(STEP_NEVER) : undefined;
|
|
1900
2037
|
for (let idx = 0, j = 0;idx < insts.length; idx++) {
|
|
1901
2038
|
const it = insts[idx];
|
|
@@ -1922,8 +2059,10 @@ function cullCore(insts, H, steps) {
|
|
|
1922
2059
|
const rx = Math.round(x), ry = Math.round(y), rz = Math.round(z);
|
|
1923
2060
|
if (!inRange(rx, ry, rz))
|
|
1924
2061
|
continue;
|
|
1925
|
-
if (!
|
|
1926
|
-
|
|
2062
|
+
if (!tops) {
|
|
2063
|
+
TX[nT] = rx;
|
|
2064
|
+
TY[nT] = ry;
|
|
2065
|
+
TZ[nT++] = rz;
|
|
1927
2066
|
continue;
|
|
1928
2067
|
}
|
|
1929
2068
|
const st = steps[idx], t = tops.get(rx, ry, rz);
|
|
@@ -1931,6 +2070,7 @@ function cullCore(insts, H, steps) {
|
|
|
1931
2070
|
tops.put(rx, ry, rz, st);
|
|
1932
2071
|
}
|
|
1933
2072
|
}
|
|
2073
|
+
const topSet = tops ? null : new StudTopSet(TX, TY, TZ, nT);
|
|
1934
2074
|
const underHidden = new Uint8Array(insts.length);
|
|
1935
2075
|
const underHideStep = steps ? new Int32Array(insts.length).fill(STEP_NEVER) : undefined;
|
|
1936
2076
|
for (let idx = 0;idx < insts.length; idx++) {
|
|
@@ -1942,14 +2082,14 @@ function cullCore(insts, H, steps) {
|
|
|
1942
2082
|
const nx = Math.round((b[3] - b[0]) / 20), nz = Math.round((b[5] - b[2]) / 20);
|
|
1943
2083
|
if (!nx || !nz || nx * nz > 4096)
|
|
1944
2084
|
continue;
|
|
1945
|
-
const m = it.m;
|
|
2085
|
+
const m = it.m, ry = Math.round(m[1] + b[4]);
|
|
1946
2086
|
let all = true, at = 0;
|
|
1947
2087
|
for (let a = 0;a < nx && all; a++)
|
|
1948
2088
|
for (let c = 0;c < nz; c++) {
|
|
1949
2089
|
const lx = b[0] + 10 + 20 * a, lz = b[2] + 10 + 20 * c;
|
|
1950
2090
|
const x = m[0] + m[3] * lx + m[5] * lz, z = m[2] + m[9] * lx + m[11] * lz;
|
|
1951
|
-
const rx = Math.round(x),
|
|
1952
|
-
const t = inRange(rx, ry, rz) ? tops.get(rx, ry, rz) : -1;
|
|
2091
|
+
const rx = Math.round(x), rz = Math.round(z);
|
|
2092
|
+
const t = !inRange(rx, ry, rz) ? -1 : tops ? tops.get(rx, ry, rz) : topSet.has(rx, ry, rz) ? 1 : -1;
|
|
1953
2093
|
if (t < 0) {
|
|
1954
2094
|
all = false;
|
|
1955
2095
|
break;
|
|
@@ -1996,7 +2136,7 @@ function precomputeCull(instances, H, useTex = true) {
|
|
|
1996
2136
|
return cullCore(s.all, H, s.nSteps > 1 ? s.stepOf : undefined);
|
|
1997
2137
|
}
|
|
1998
2138
|
|
|
1999
|
-
// ../../../../../../../tmp/ldr-build-
|
|
2139
|
+
// ../../../../../../../tmp/ldr-build-DCpOVo/src/render.ts
|
|
2000
2140
|
async function loadPack(url) {
|
|
2001
2141
|
const res = await fetch(url);
|
|
2002
2142
|
if (!res.ok)
|
|
@@ -2391,54 +2531,16 @@ function newIM(g, mat, n) {
|
|
|
2391
2531
|
im.count = n;
|
|
2392
2532
|
return im;
|
|
2393
2533
|
}
|
|
2394
|
-
function
|
|
2395
|
-
if (vis >= im.instanceMatrix.count || !im.instanceColor)
|
|
2396
|
-
return false;
|
|
2397
|
-
const M = im.instanceMatrix.array.slice(0, vis * 16), C = im.instanceColor.array.slice(0, vis * 3);
|
|
2398
|
-
im.instanceMatrix = new THREE.InstancedBufferAttribute(M, 16);
|
|
2399
|
-
im.instanceColor = new THREE.InstancedBufferAttribute(C, 3);
|
|
2400
|
-
im.count = vis;
|
|
2401
|
-
for (const o of linked) {
|
|
2402
|
-
if (o.isInstancedMesh) {
|
|
2403
|
-
o.instanceMatrix = im.instanceMatrix;
|
|
2404
|
-
o.instanceColor = im.instanceColor;
|
|
2405
|
-
o.count = vis;
|
|
2406
|
-
} else if (o.geometry) {
|
|
2407
|
-
o.geometry.setAttribute("instanceMatrix", im.instanceMatrix);
|
|
2408
|
-
o.geometry.instanceCount = vis;
|
|
2409
|
-
}
|
|
2410
|
-
}
|
|
2411
|
-
return true;
|
|
2412
|
-
}
|
|
2413
|
-
function instancedBoundingSphere(im) {
|
|
2414
|
-
const g = im.geometry;
|
|
2534
|
+
function sphereState(g) {
|
|
2415
2535
|
if (!g.boundingSphere)
|
|
2416
2536
|
g.computeBoundingSphere();
|
|
2417
2537
|
const gs = g.boundingSphere;
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
const
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
cy = py;
|
|
2425
|
-
cz = pz;
|
|
2426
|
-
r = 0;
|
|
2427
|
-
return;
|
|
2428
|
-
}
|
|
2429
|
-
const vx = px - cx, vy = py - cy, vz = pz - cz;
|
|
2430
|
-
const l2 = vx * vx + vy * vy + vz * vz;
|
|
2431
|
-
if (l2 > r * r) {
|
|
2432
|
-
const l = Math.sqrt(l2);
|
|
2433
|
-
const d = (l - r) * 0.5;
|
|
2434
|
-
const f = d / l;
|
|
2435
|
-
cx += vx * f;
|
|
2436
|
-
cy += vy * f;
|
|
2437
|
-
cz += vz * f;
|
|
2438
|
-
r += d;
|
|
2439
|
-
}
|
|
2440
|
-
};
|
|
2441
|
-
for (let i = 0, n = im.count;i < n; i++) {
|
|
2538
|
+
return Float64Array.of(0, 0, 0, -1, gs.center.x, gs.center.y, gs.center.z, gs.radius);
|
|
2539
|
+
}
|
|
2540
|
+
function sphereUnion(S, A, n) {
|
|
2541
|
+
const gx = S[4], gy = S[5], gz = S[6], gr = S[7];
|
|
2542
|
+
let cx = S[0], cy = S[1], cz = S[2], r = S[3];
|
|
2543
|
+
for (let i = 0;i < n; i++) {
|
|
2442
2544
|
const o = i * 16;
|
|
2443
2545
|
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];
|
|
2444
2546
|
const w = 1 / (e3 * gx + e7 * gy + e11 * gz + A[o + 15]);
|
|
@@ -2460,30 +2562,65 @@ function instancedBoundingSphere(im) {
|
|
|
2460
2562
|
dx = dx * inv * sr;
|
|
2461
2563
|
dy = dy * inv * sr;
|
|
2462
2564
|
dz = dz * inv * sr;
|
|
2463
|
-
|
|
2464
|
-
|
|
2565
|
+
for (let k = 0;k < 2; k++) {
|
|
2566
|
+
const px = k ? x - dx : x + dx, py = k ? y - dy : y + dy, pz = k ? z - dz : z + dz;
|
|
2567
|
+
if (r < 0) {
|
|
2568
|
+
cx = px;
|
|
2569
|
+
cy = py;
|
|
2570
|
+
cz = pz;
|
|
2571
|
+
r = 0;
|
|
2572
|
+
continue;
|
|
2573
|
+
}
|
|
2574
|
+
const vx = px - cx, vy = py - cy, vz = pz - cz;
|
|
2575
|
+
const l2 = vx * vx + vy * vy + vz * vz;
|
|
2576
|
+
if (l2 > r * r) {
|
|
2577
|
+
const l = Math.sqrt(l2);
|
|
2578
|
+
const d = (l - r) * 0.5;
|
|
2579
|
+
const f = d / l;
|
|
2580
|
+
cx += vx * f;
|
|
2581
|
+
cy += vy * f;
|
|
2582
|
+
cz += vz * f;
|
|
2583
|
+
r += d;
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2465
2586
|
}
|
|
2587
|
+
S[0] = cx;
|
|
2588
|
+
S[1] = cy;
|
|
2589
|
+
S[2] = cz;
|
|
2590
|
+
S[3] = r;
|
|
2591
|
+
}
|
|
2592
|
+
function setSphere(im, S) {
|
|
2466
2593
|
const sph = im.boundingSphere ?? new THREE.Sphere;
|
|
2467
|
-
sph.center.set(
|
|
2468
|
-
sph.radius =
|
|
2469
|
-
if (
|
|
2594
|
+
sph.center.set(S[0], S[1], S[2]);
|
|
2595
|
+
sph.radius = S[3];
|
|
2596
|
+
if (S[3] < 0)
|
|
2470
2597
|
sph.makeEmpty();
|
|
2471
2598
|
im.boundingSphere = sph;
|
|
2472
2599
|
return sph;
|
|
2473
2600
|
}
|
|
2601
|
+
function instancedBoundingSphere(im, S = sphereState(im.geometry), set = true) {
|
|
2602
|
+
sphereUnion(S, im.instanceMatrix.array, im.count);
|
|
2603
|
+
return set ? setSphere(im, S) : S;
|
|
2604
|
+
}
|
|
2474
2605
|
function instancedBoundingBox(im) {
|
|
2475
|
-
const
|
|
2606
|
+
const B = boxState(im.geometry);
|
|
2607
|
+
if (!B)
|
|
2608
|
+
return;
|
|
2609
|
+
boxUnion(B, im.instanceMatrix.array, im.instanceMatrix.count);
|
|
2610
|
+
return boxOf(B);
|
|
2611
|
+
}
|
|
2612
|
+
function boxState(g) {
|
|
2476
2613
|
if (!g.boundingBox)
|
|
2477
2614
|
g.computeBoundingBox();
|
|
2478
2615
|
const gb = g.boundingBox;
|
|
2479
2616
|
if (gb.isEmpty())
|
|
2480
|
-
return;
|
|
2481
|
-
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
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
let x0 =
|
|
2617
|
+
return null;
|
|
2618
|
+
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;
|
|
2619
|
+
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);
|
|
2620
|
+
}
|
|
2621
|
+
function boxUnion(B, A, n) {
|
|
2622
|
+
const hx = B[6], hy = B[7], hz = B[8], gx = B[9], gy = B[10], gz = B[11];
|
|
2623
|
+
let x0 = B[0], y0 = B[1], z0 = B[2], x1 = B[3], y1 = B[4], z1 = B[5];
|
|
2487
2624
|
for (let i = 0;i < n; i++) {
|
|
2488
2625
|
const o = i * 16;
|
|
2489
2626
|
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];
|
|
@@ -2501,8 +2638,15 @@ function instancedBoundingBox(im) {
|
|
|
2501
2638
|
if (cz + ez > z1)
|
|
2502
2639
|
z1 = cz + ez;
|
|
2503
2640
|
}
|
|
2504
|
-
|
|
2641
|
+
B[0] = x0;
|
|
2642
|
+
B[1] = y0;
|
|
2643
|
+
B[2] = z0;
|
|
2644
|
+
B[3] = x1;
|
|
2645
|
+
B[4] = y1;
|
|
2646
|
+
B[5] = z1;
|
|
2647
|
+
B[12] += n;
|
|
2505
2648
|
}
|
|
2649
|
+
var boxOf = (B) => B && B[12] > 0 ? Float32Array.of(B[0], B[1], B[2], B[3], B[4], B[5]) : undefined;
|
|
2506
2650
|
function batchedBoundingBox(bm) {
|
|
2507
2651
|
bm.computeBoundingBox();
|
|
2508
2652
|
const bb = bm.boundingBox;
|
|
@@ -3061,7 +3205,7 @@ function fillBucketIds(bIds, fill, studBucket, j0, j1) {
|
|
|
3061
3205
|
bIds[b][fill[b]++] = j;
|
|
3062
3206
|
}
|
|
3063
3207
|
}
|
|
3064
|
-
function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colorIndex) {
|
|
3208
|
+
function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colorIndex, trim = false) {
|
|
3065
3209
|
const bKind = [], bMat = [];
|
|
3066
3210
|
const bAll = [];
|
|
3067
3211
|
const studBucket = new Uint16Array(cull.nStuds);
|
|
@@ -3167,10 +3311,10 @@ function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colo
|
|
|
3167
3311
|
sMesh.push(null);
|
|
3168
3312
|
continue;
|
|
3169
3313
|
}
|
|
3170
|
-
const
|
|
3171
|
-
im
|
|
3172
|
-
|
|
3173
|
-
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) } } : {} });
|
|
3314
|
+
const n = trim ? v : c.length;
|
|
3315
|
+
const im = newIM(g, bMat[b], n);
|
|
3316
|
+
im.instanceColor = new THREE.InstancedBufferAttribute(new Float32Array(n * 3), 3);
|
|
3317
|
+
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) } } : {} });
|
|
3174
3318
|
}
|
|
3175
3319
|
};
|
|
3176
3320
|
for (let b = 0;b < bKind.length; b++) {
|
|
@@ -3196,6 +3340,12 @@ function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colo
|
|
|
3196
3340
|
return x;
|
|
3197
3341
|
};
|
|
3198
3342
|
yield;
|
|
3343
|
+
let nH = 0;
|
|
3344
|
+
if (trim)
|
|
3345
|
+
for (let j = 0;j < cull.nStuds; j++)
|
|
3346
|
+
nH += cull.studHidden[j];
|
|
3347
|
+
const hidI = new Int32Array(nH), hidS = new Int32Array(nH), hidC = new Int32Array(nH);
|
|
3348
|
+
let nHid = 0;
|
|
3199
3349
|
{
|
|
3200
3350
|
const w = new Float64Array(12);
|
|
3201
3351
|
let j = 0;
|
|
@@ -3207,6 +3357,14 @@ function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colo
|
|
|
3207
3357
|
for (let si = 0;si < pp.nStuds; si++, j++) {
|
|
3208
3358
|
if ((j & 32767) === 0 && j)
|
|
3209
3359
|
yield;
|
|
3360
|
+
if (trim && cull.studHidden[j]) {
|
|
3361
|
+
if (sMesh[studCl[j]]) {
|
|
3362
|
+
hidI[nHid] = idx;
|
|
3363
|
+
hidS[nHid] = si;
|
|
3364
|
+
hidC[nHid++] = studCl[j];
|
|
3365
|
+
}
|
|
3366
|
+
continue;
|
|
3367
|
+
}
|
|
3210
3368
|
mul12To(it.m, pp.studM, si * 12, w);
|
|
3211
3369
|
const sm = sMesh[studCl[j]];
|
|
3212
3370
|
if (!sm)
|
|
@@ -3228,8 +3386,41 @@ function* buildStudMeshesGen(insts, H, cull, arr, LOD, color, matOf, steps, colo
|
|
|
3228
3386
|
}
|
|
3229
3387
|
}
|
|
3230
3388
|
}
|
|
3389
|
+
if (trim) {
|
|
3390
|
+
for (let c0 = 0;c0 < sMesh.length; c0 += 8) {
|
|
3391
|
+
yield;
|
|
3392
|
+
for (let ci = c0;ci < Math.min(sMesh.length, c0 + 8); ci++) {
|
|
3393
|
+
const sm = sMesh[ci];
|
|
3394
|
+
if (sm) {
|
|
3395
|
+
sm.S = instancedBoundingSphere(sm.im, undefined, false);
|
|
3396
|
+
if (LOD) {
|
|
3397
|
+
sm.B = boxState(sm.im.geometry);
|
|
3398
|
+
if (sm.B)
|
|
3399
|
+
boxUnion(sm.B, sm.im.instanceMatrix.array, sm.im.count);
|
|
3400
|
+
}
|
|
3401
|
+
}
|
|
3402
|
+
}
|
|
3403
|
+
}
|
|
3404
|
+
for (let k0 = 0;k0 < nHid; k0 += 65536) {
|
|
3405
|
+
yield;
|
|
3406
|
+
hiddenStudSpheres(insts, H, hidI, hidS, hidC, sMesh, k0, Math.min(nHid, k0 + 65536));
|
|
3407
|
+
}
|
|
3408
|
+
}
|
|
3231
3409
|
return sMesh;
|
|
3232
3410
|
}
|
|
3411
|
+
function hiddenStudSpheres(insts, H, hidI, hidS, hidC, sMesh, k0, k1) {
|
|
3412
|
+
const w = new Float64Array(12), A = new Float32Array(16);
|
|
3413
|
+
for (let k = k0;k < k1; k++) {
|
|
3414
|
+
const it = insts[hidI[k]];
|
|
3415
|
+
const pp = prepPart(H, it.part);
|
|
3416
|
+
const sm = sMesh[hidC[k]];
|
|
3417
|
+
mul12To(it.m, pp.studM, hidS[k] * 12, w);
|
|
3418
|
+
writeM4(A, 0, w);
|
|
3419
|
+
sphereUnion(sm.S, A, 1);
|
|
3420
|
+
if (sm.B)
|
|
3421
|
+
boxUnion(sm.B, A, 1);
|
|
3422
|
+
}
|
|
3423
|
+
}
|
|
3233
3424
|
function undersideGroups(ids, insts) {
|
|
3234
3425
|
const by = new Map;
|
|
3235
3426
|
const rest = [];
|
|
@@ -3327,6 +3518,8 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
3327
3518
|
return m;
|
|
3328
3519
|
};
|
|
3329
3520
|
const byPart = new Map;
|
|
3521
|
+
const matMemo = new Map;
|
|
3522
|
+
const bucketMemo = new Map;
|
|
3330
3523
|
const bucketRange = (i0, i1) => {
|
|
3331
3524
|
for (let i = i0;i < i1; i++) {
|
|
3332
3525
|
const it = insts[i];
|
|
@@ -3334,13 +3527,27 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
3334
3527
|
if (!p)
|
|
3335
3528
|
continue;
|
|
3336
3529
|
const d = det12(it.m), mirror = d < 0;
|
|
3337
|
-
const
|
|
3338
|
-
|
|
3339
|
-
|
|
3530
|
+
const code = String(it.color), uncert = !!p.uncert || singular12(it.m, d), role = uncert ? 2 : mirror ? 1 : 0;
|
|
3531
|
+
let me = matMemo.get(code);
|
|
3532
|
+
if (!me)
|
|
3533
|
+
matMemo.set(code, me = [undefined, undefined, undefined]);
|
|
3534
|
+
const mat = me[role] ?? (me[role] = materialFor(code, mirror, uncert));
|
|
3535
|
+
let pm = bucketMemo.get(it.part);
|
|
3536
|
+
if (!pm)
|
|
3537
|
+
bucketMemo.set(it.part, pm = new Map);
|
|
3538
|
+
let pb = pm.get(mat);
|
|
3539
|
+
if (!pb)
|
|
3540
|
+
pm.set(mat, pb = [undefined, undefined]);
|
|
3541
|
+
let b = pb[mirror ? 1 : 0];
|
|
3340
3542
|
if (!b) {
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3543
|
+
const k = it.part + "\x00" + mat.uuid + (mirror ? "\x00m" : "");
|
|
3544
|
+
b = byPart.get(k);
|
|
3545
|
+
if (!b) {
|
|
3546
|
+
if (p.uncert)
|
|
3547
|
+
nUncert++;
|
|
3548
|
+
byPart.set(k, b = { part: it.part, mirror, ids: [], mat });
|
|
3549
|
+
}
|
|
3550
|
+
pb[mirror ? 1 : 0] = b;
|
|
3344
3551
|
}
|
|
3345
3552
|
b.ids.push(i);
|
|
3346
3553
|
}
|
|
@@ -3647,15 +3854,35 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
3647
3854
|
const vis = uids.length - uids.reduce((a, i) => a + cull.underHidden[i], 0);
|
|
3648
3855
|
stats.undersTotal += uids.length;
|
|
3649
3856
|
stats.undersHidden += uids.length - vis;
|
|
3650
|
-
const
|
|
3651
|
-
|
|
3857
|
+
const trimU = !steps && !!P.cullUnder;
|
|
3858
|
+
const im = newIM(under, mat, trimU ? vis : uids.length);
|
|
3859
|
+
fillInstances(im, trimU ? ord.slice(0, vis) : ord, insts, color);
|
|
3652
3860
|
im.onBeforeRender = trackVp;
|
|
3653
3861
|
im.userData.ldrUnder = true;
|
|
3654
3862
|
im.userData.ldrPart = part;
|
|
3655
|
-
|
|
3863
|
+
let uB;
|
|
3864
|
+
if (trimU) {
|
|
3865
|
+
im.count = vis;
|
|
3866
|
+
const S = instancedBoundingSphere(im, undefined, false), A = new Float32Array(16);
|
|
3867
|
+
if (LOD) {
|
|
3868
|
+
uB = boxState(im.geometry);
|
|
3869
|
+
if (uB)
|
|
3870
|
+
boxUnion(uB, im.instanceMatrix.array, vis);
|
|
3871
|
+
}
|
|
3872
|
+
for (let k = vis;k < ord.length; k++) {
|
|
3873
|
+
writeM4(A, 0, insts[ord[k]].m);
|
|
3874
|
+
sphereUnion(S, A, 1);
|
|
3875
|
+
if (uB)
|
|
3876
|
+
boxUnion(uB, A, 1);
|
|
3877
|
+
}
|
|
3878
|
+
setSphere(im, S);
|
|
3879
|
+
} else
|
|
3880
|
+
instancedBoundingSphere(im);
|
|
3656
3881
|
im.count = P.cullUnder ? vis : uids.length;
|
|
3657
3882
|
root.add(im);
|
|
3658
3883
|
const cl = newCluster(im.boundingSphere, im);
|
|
3884
|
+
if (uB !== undefined)
|
|
3885
|
+
cl.b = boxOf(uB);
|
|
3659
3886
|
cl.lv.push({ objs: [im], err: 0 }, ...lodLevels(p.under, im, mat));
|
|
3660
3887
|
{
|
|
3661
3888
|
const bl = p.body?.lod;
|
|
@@ -3678,7 +3905,7 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
3678
3905
|
if (!o.isInstancedMesh)
|
|
3679
3906
|
o.geometry.instanceCount = im.count;
|
|
3680
3907
|
});
|
|
3681
|
-
const trim =
|
|
3908
|
+
const trim = trimU && vis < uids.length;
|
|
3682
3909
|
if (trim)
|
|
3683
3910
|
trimmed.under = true;
|
|
3684
3911
|
toggles.push({ mesh: countTo(() => objs), all: trim ? vis : uids.length, visible: vis, flag: "under" });
|
|
@@ -3972,7 +4199,7 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
3972
4199
|
}
|
|
3973
4200
|
}
|
|
3974
4201
|
yield root;
|
|
3975
|
-
const _studGen = buildStudMeshesGen(insts, H, cull, arr, LOD, color, (c, mirror) => materialFor(c, mirror, false), steps, steps && colorIndex);
|
|
4202
|
+
const _studGen = buildStudMeshesGen(insts, H, cull, arr, LOD, color, (c, mirror) => materialFor(c, mirror, false), steps, steps && colorIndex, !steps && !!P.cullStuds);
|
|
3976
4203
|
let _studR = _studGen.next();
|
|
3977
4204
|
while (!_studR.done) {
|
|
3978
4205
|
yield root;
|
|
@@ -3996,13 +4223,18 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
3996
4223
|
const im = sm.im;
|
|
3997
4224
|
const kind = sKind[ci];
|
|
3998
4225
|
const k = H.studKinds[kind];
|
|
3999
|
-
const vis = sVis[ci], all =
|
|
4000
|
-
|
|
4226
|
+
const vis = sVis[ci], all = sm.all;
|
|
4227
|
+
if (sm.S)
|
|
4228
|
+
setSphere(im, sm.S);
|
|
4229
|
+
else
|
|
4230
|
+
instancedBoundingSphere(im);
|
|
4001
4231
|
im.count = P.cullStuds ? vis : all;
|
|
4002
4232
|
im.onBeforeRender = trackVp;
|
|
4003
4233
|
im.userData.ldrStud = true;
|
|
4004
4234
|
root.add(im);
|
|
4005
4235
|
const cl = newCluster(im.boundingSphere, im);
|
|
4236
|
+
if (sm.B !== undefined)
|
|
4237
|
+
cl.b = boxOf(sm.B);
|
|
4006
4238
|
cl.studLineLv = 0;
|
|
4007
4239
|
cl.lv.push({ objs: [im], err: 0 });
|
|
4008
4240
|
const discObjs = [];
|
|
@@ -4057,7 +4289,7 @@ function* buildLdrSceneGen(insts, pack, P, color, mark) {
|
|
|
4057
4289
|
if (!o.isInstancedMesh)
|
|
4058
4290
|
o.geometry.instanceCount = im.count;
|
|
4059
4291
|
});
|
|
4060
|
-
const trim = !steps && P.cullStuds &&
|
|
4292
|
+
const trim = !steps && P.cullStuds && vis < all;
|
|
4061
4293
|
if (trim)
|
|
4062
4294
|
trimmed.studs = true;
|
|
4063
4295
|
toggles.push({ mesh: countTo(() => objs), all: trim ? vis : all, visible: vis, flag: "studs" });
|
|
@@ -4317,7 +4549,7 @@ async function warmPackGeometry(pack, stop = () => false, sliceMs = 8) {
|
|
|
4317
4549
|
await new Promise((r) => setTimeout(r, 0));
|
|
4318
4550
|
}
|
|
4319
4551
|
}
|
|
4320
|
-
// ../../../../../../../tmp/ldr-build-
|
|
4552
|
+
// ../../../../../../../tmp/ldr-build-DCpOVo/src/scene.ts
|
|
4321
4553
|
import * as THREE2 from "three";
|
|
4322
4554
|
var _box = new THREE2.Box3;
|
|
4323
4555
|
var _m4 = new THREE2.Matrix4;
|
|
@@ -4672,10 +4904,10 @@ function createLdrObjectInner(instances, pack, options, progressive) {
|
|
|
4672
4904
|
return finish();
|
|
4673
4905
|
})();
|
|
4674
4906
|
}
|
|
4675
|
-
// ../../../../../../../tmp/ldr-build-
|
|
4907
|
+
// ../../../../../../../tmp/ldr-build-DCpOVo/src/parts-cdn.ts
|
|
4676
4908
|
import { decompress as decompress2 } from "fzstd";
|
|
4677
4909
|
|
|
4678
|
-
// ../../../../../../../tmp/ldr-build-
|
|
4910
|
+
// ../../../../../../../tmp/ldr-build-DCpOVo/src/embedded.ts
|
|
4679
4911
|
function splitFiles(text, fallback) {
|
|
4680
4912
|
const files = new Map;
|
|
4681
4913
|
let cur = null, saw = false, skip = false;
|
|
@@ -4750,7 +4982,7 @@ function embeddedKeys(text, names, fallback = "main.ldr") {
|
|
|
4750
4982
|
return out;
|
|
4751
4983
|
}
|
|
4752
4984
|
|
|
4753
|
-
// ../../../../../../../tmp/ldr-build-
|
|
4985
|
+
// ../../../../../../../tmp/ldr-build-DCpOVo/src/parts-cdn.ts
|
|
4754
4986
|
var DEFAULT_PARTS_CDN = "https://ldr-demo.vercel.app/cdn/v1/";
|
|
4755
4987
|
var indexCache = new Map;
|
|
4756
4988
|
var shardCache = new Map;
|
|
@@ -5004,10 +5236,10 @@ async function prepareModel(source, o = {}) {
|
|
|
5004
5236
|
return { insts, pack, tier, missing, requests, bytes, cull, timings: { fetchModel: t1 - t0, parse: t2 - t1, parts: t3 - t2, ...cull ? { cull: performance.now() - t3 } : {} } };
|
|
5005
5237
|
}
|
|
5006
5238
|
|
|
5007
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5008
|
-
var load_worker_gen_default = 'var Ft=ArrayBuffer,ee=Uint8Array,we=Uint16Array,Rt=Int16Array;var Me=Int32Array,Ie=function(e,t,n){if(ee.prototype.slice)return ee.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 ee(n-t);return r.set(e.subarray(t,n)),r},he=function(e,t,n,r){if(ee.prototype.fill)return ee.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},Bt=function(e,t,n,r){if(ee.prototype.copyWithin)return ee.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 Dt=["invalid zstd data","window size too large (>2046MB)","invalid block type","FSE accuracy too high","match distance too far back","unexpected EOF"],te=function(e,t,n){var r=Error(t||Dt[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,te);if(!n)throw r;return r},Qe=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},Ut=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},Ot=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)te(0);var u=6-s,f=i==3?4:i,a=Qe(e,u,f);u+=f;var l=c?1<<c:s,m=Qe(e,u,l)+(c==1&&256),g=m;if(!s){var d=1<<10+(e[5]>>3);g=d+(d>>3)*(e[5]&7)}if(g>2145386496)te(1);var b=new ee((t==1?m||g:t?0:g)+12);return b[0]=1,b[4]=4,b[8]=8,{b:u+l,y:0,l:0,d:a,w:t&&t!=1?t:b.subarray(12),e:g,o:new Me(b.buffer,0,3),u:m,c:o,m:Math.min(131072,g)}}else if((n>>4|e[3]<<20)==25481893)return Ut(e,4)+8;te(0)},le=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)te(3);var o=1<<s,i=o,c=-1,u=-1,f=-1,a=o,l=new Ft(512+(o<<2)),m=new Rt(l,0,256),g=new we(l,0,256),d=new we(l,512,o),b=512+(o<<1),C=new ee(l,b,o),A=new ee(l,b+o);while(c<255&&i>0){var p=le(i+1),h=r>>3,M=(1<<p+1)-1,D=(e[h]|e[h+1]<<8|e[h+2]<<16)>>(r&7)&M,v=(1<<p)-1,L=M-i-1,R=D&v;if(R<L)r+=p,D=R;else if(r+=p+1,D>v)D-=L;if(m[++c]=--D,D==-1)i+=D,C[--a]=c;else i-=D;if(!D)do{var T=r>>3;u=(e[T]|e[T+1]<<8)>>(r&7)&3,r+=2,c+=u}while(u==3)}if(c>255||i)te(0);var x=0,w=(o>>1)+(o>>3)+3,E=o-1;for(var z=0;z<=c;++z){var k=m[z];if(k<1){g[z]=-k;continue}for(f=0;f<k;++f){C[x]=z;do x=x+w&E;while(x>=a)}}if(x)te(0);for(f=0;f<o;++f){var P=g[C[f]]++,Y=A[f]=s-le(P);d[f]=(P<<Y)-o}return[r+7>>3,{b:s,s:C,n:A,t:d}]},Nt=function(e,t){var n=0,r=-1,s=new ee(292),o=e[t],i=s.subarray(0,256),c=s.subarray(256,268),u=new we(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)te(0);var d=0,b=0,C=l.b,A=C,p=(++t<<3)-8+le(g);for(;;){if(p-=C,p<m)break;var h=p>>3;if(d+=(e[h]|e[h+1]<<8)>>(p&7)&(1<<C)-1,i[++r]=l.s[d],p-=A,p<m)break;h=p>>3,b+=(e[h]|e[h+1]<<8)>>(p&7)&(1<<A)-1,i[++r]=l.s[b],C=l.n[d],d=l.t[d],A=l.n[b],b=l.t[b]}if(++r>255)te(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 D=0;for(n=0;n<r;++n){var v=i[n];if(v>11)te(0);D+=v&&1<<v-1}var L=le(D)+1,R=1<<L,T=R-D;if(T&T-1)te(0);i[r++]=le(T)+1;for(n=0;n<r;++n){var v=i[n];++c[i[n]=v&&L+1-v]}var x=new ee(R<<1),w=x.subarray(0,R),E=x.subarray(R);u[L]=0;for(n=L;n>0;--n){var z=u[n];he(E,n,z,u[n-1]=z+c[n]*(1<<L-n))}if(u[0]!=R)te(0);for(n=0;n<r;++n){var k=i[n];if(k){var P=u[k];he(w,n,P,u[k]=P+(1<<L-k))}}return[t,{n:E,b:L,s:w}]},zt=ge(new ee([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],$t=ge(new ee([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],jt=ge(new ee([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],qe=function(e,t){var n=e.length,r=new Me(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Fe=new ee(new Me([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),Vt=qe(Fe,0),Re=new ee(new Me([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),_t=qe(Re,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)te(0);var u=0,f=n.b,a=(r<<3)-8+le(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)te(0)},Ht=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)},Gt=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 ee(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 Ie(e,s,u)}if(i==2){var f=e[s],a=f&3,l=f>>2&3,m=f>>4,g=0,d=0;if(a<2)if(l&1)m|=e[++s]<<4|(l&2&&e[++s]<<12);else m=f>>3;else if(d=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 b=n?n.subarray(t.y,t.y+t.m):new ee(t.m),C=b.length-m;if(a==0)b.set(e.subarray(s,s+=m),C);else if(a==1)he(b,e[s++],C);else{var A=t.h;if(a==2){var p=Nt(e,s);g+=s-(s=p[0]),t.h=A=p[1]}else if(!A)te(0);(d?Ht:me)(e.subarray(s,s+=g),b.subarray(C),A)}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)te(0);var D=[$t,jt,zt];for(var v=2;v>-1;--v){var L=M>>(v<<1)+2&3;if(L==1){var R=new ee([0,0,e[s++]]);D[v]={s:R.subarray(2,3),n:R.subarray(0,1),t:new we(R.buffer,0,1),b:0}}else if(L==2)r=ge(e,s,9-(v&1)),s=r[0],D[v]=r[1];else if(L==3){if(!t.t)te(0);D[v]=t.t[v]}}var T=t.t=D,x=T[0],w=T[1],E=T[2],z=e[u-1];if(!z)te(0);var k=(u<<3)-8+le(z)-E.b,P=k>>3,Y=0,I=(e[P]|e[P+1]<<8)>>(k&7)&(1<<E.b)-1;P=(k-=w.b)>>3;var j=(e[P]|e[P+1]<<8)>>(k&7)&(1<<w.b)-1;P=(k-=x.b)>>3;var H=(e[P]|e[P+1]<<8)>>(k&7)&(1<<x.b)-1;for(++h;--h;){var Z=E.s[I],O=E.n[I],G=x.s[H],K=x.n[H],J=w.s[j],Q=w.n[j];P=(k-=J)>>3;var S=1<<J,y=S+((e[P]|e[P+1]<<8|e[P+2]<<16|e[P+3]<<24)>>>(k&7)&S-1);P=(k-=Re[G])>>3;var B=_t[G]+((e[P]|e[P+1]<<8|e[P+2]<<16)>>(k&7)&(1<<Re[G])-1);P=(k-=Fe[Z])>>3;var _=Vt[Z]+((e[P]|e[P+1]<<8|e[P+2]<<16)>>(k&7)&(1<<Fe[Z])-1);if(P=(k-=O)>>3,I=E.t[I]+((e[P]|e[P+1]<<8)>>(k&7)&(1<<O)-1),P=(k-=K)>>3,H=x.t[H]+((e[P]|e[P+1]<<8)>>(k&7)&(1<<K)-1),P=(k-=Q)>>3,j=w.t[j]+((e[P]|e[P+1]<<8)>>(k&7)&(1<<Q)-1),y>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=y-=3;else{var W=y-(_!=0);if(W){if(y=W==3?t.o[0]-1:t.o[W],W>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=y}else y=t.o[0]}for(var v=0;v<_;++v)b[Y+v]=b[C+v];Y+=_,C+=_;var X=Y-y;if(X<0){var N=-X,q=t.e+X;if(N>B)N=B;for(var v=0;v<N;++v)b[Y+v]=t.w[q+v];Y+=N,B-=N,X=0}for(var v=0;v<B;++v)b[Y+v]=b[X+v];Y+=B}if(Y!=C)while(C<b.length)b[Y++]=b[C++];else Y=b.length;if(n)t.y+=Y;else b=Ie(b,0,Y)}else if(n){if(t.y+=m,C)for(var v=0;v<m;++v)b[v]=b[C+v]}else if(C)b=Ie(b,C);return t.b=u,b}te(2)},Wt=function(e,t){if(e.length==1)return e[0];var n=new ee(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 Ae(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=Ot(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=Gt(e,i,t);if(!c)te(5);if(t)i.e=i.y;else n.push(c),o+=c.length,Bt(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 Wt(n,o)}async function Kt(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(Ae(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 et(e){return new TextDecoder().decode(await Kt(e))}var tt=(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 ne=(e)=>e.trim().toLowerCase().replace(/\\\\/g,"/").replace(/\\/+/g,"/"),De=/^[A-Za-z][A-Za-z0-9_]*$/,Be=new Map;function Ue(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(!Be.has(r))Be.set(r,t);return r}function Oe(e){let t=e.charCodeAt(0)|32;if(t>=97&&t<=122&&De.test(e))return Ue(e);if(/^0x/i.test(e))return parseInt(e,16);return+e}var nt=/^~?\\s*moved\\s+to\\s+(.+)$/i,Xt=new Set(["FILE","NOFILE","!DATA","!:","STEP","BFC","ROTSTEP","BUFEXCHG","!TEXMAP"]),Zt=new Set(["FILE","NOFILE","!DATA"]),ut=1000000000000000,ft=new Set(["part","subpart","primitive","8_primitive","48_primitive","shortcut","helper"]),Yt=new Set(["model","submodel","configuration"]),Jt=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function rt(e){let t=Jt.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,"");return ft.has(n)||Yt.has(n)?n:void 0}function Qt(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 qt(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=Qt(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 en=(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 tn(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=Oe(o);if(!Number.isFinite(f))return null;return{t:1,color:f,m:i,file:ne(u)}}var nn=[0,12,6,9,12,12];function st(e){let t=+e[0];if(!(t>=1&&t<=5&&Number.isInteger(t))||e.length<2)return null;let n=Oe(e[1]),r=nn[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=ne(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 pt(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=en(u.chunks.join("")),h=p[0]===137&&p[1]===80&&p[2]===78&&p[3]===71;(c??=new Map).set(ne(u.name),{name:u.name,bytes:p,...h?{mime:"image/png"}:{}}),u=null},m=!0,g=(p)=>{if(l(),o={name:ne(p),cmds:[]},s.set(o.name,o),!i)i=o.name;f=[],a=null,m=!0},d=!1,b=!1,C=()=>{if(b)return;b=!0,s.clear(),o=null,i=""},A=(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||d)continue;if(!o)g(t);let L=h.slice(2).trimStart(),R=L.search(/\\s/),T={t:h.charCodeAt(0)-48,color:Oe(R<0?L:L.slice(0,R)),p:[],src:h};A(T,!1),o.cmds.push(T),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 R=L;while(R<h.length&&h.charCodeAt(R)!==32&&h.charCodeAt(R)!==9)R++;let T=h.slice(L,R),x=/[^\\x21-\\x7e]/.test(T)?h.slice(L).trim().split(/\\s+/)[0]:T;if(!Xt.has(x)&&!(x.length>=4&&x.length<=6&&Zt.has(x.toUpperCase()))){if(d||u)continue;if(!o)g(t);let w=h.slice(L),E={t:0,text:w};if(T.charCodeAt(0)===33)E.meta=T;if(a=null,m&&!o.org){let k=rt(w);if(k)o.org=k}let z=w.match(nt);if(z&&!o.movedTo){let k=z[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(k))k+=".dat";o.movedTo=ne(k)}o.cmds.push(E);continue}}if(h.charCodeAt(0)===49&&(h.charCodeAt(1)===32||h.charCodeAt(1)===9)&&!u&&!d){let L=tn(h);if(L){if(!o)g(t);A(L,!1),o.cmds.push(L),m=!1;continue}}let M=h.split(/\\s+/);if(+M[0]===0){let L=h.slice(1).trim(),R=M.length>1&&M[1].length>=4&&M[1].length<=6?M[1].toUpperCase():M[1];if(R==="FILE"){let w=L.slice(5).trimStart().split("\\r")[0].trim();if(w){C(),d=!1,g(w);continue}}if(R==="NOFILE"){l(),o=null,d=!0;continue}if(R==="!DATA"){C(),l(),o=null,d=!1,u={name:L.slice(5).trim(),chunks:[]};continue}if(d)continue;if(u){if(M[1]==="!:")u.chunks.push(M.slice(2).join(""));continue}if(!o)g(t);let T={t:0,text:L};if(M[1]==="STEP")T.step=!0,f=[],a=null;else if(M[1]==="BFC")T.bfc=M.slice(2).join(" ");else if(M[1]==="ROTSTEP")if(T.meta="ROTSTEP",T.step=!0,f=[],a=null,(M[2]??"").toUpperCase()==="END")T.rotstep={x:0,y:0,z:0,mode:"END"};else{let w=(M[5]??"REL").toUpperCase(),E=(z)=>{let k=Number(z);return Number.isFinite(k)?k:0};T.rotstep={x:E(M[2]),y:E(M[3]),z:E(M[4]),mode:["REL","ABS","ADD"].includes(w)?w:"REL"}}else if(M[1]==="BUFEXCHG"){T.meta="BUFEXCHG";let w=(M[2]??"").toUpperCase();T.bufexchg={op:w==="RETRIEVE"?"RETRIEVE":"STORE",buf:M[3]??"A"}}else if(M[1]?.startsWith("!"))T.meta=M[1];if(m&&!o.org){let w=rt(L);if(w)o.org=w}if(M[1]==="!TEXMAP"){let w=(M[2]??"").toUpperCase();if(a=null,w==="START"||w==="NEXT"){let E=qt(L.replace(/^!TEXMAP\\s+\\S+/i,""),w==="NEXT");if(T.texmap={op:w,...E?{map:E}:{}},E)if((o.texmaps??=[]).push(E),w==="START")f.push({map:E,fallback:!1});else a=E}else if(w==="FALLBACK"){T.texmap={op:w};let E=f[f.length-1];if(E)E.fallback=!0}else if(w==="END")T.texmap={op:w},f.pop()}else if(M[1]==="!:"){a=null;let w=st(M.slice(2));if(w)A(w,!0),T.geom=w}else a=null;let x=L.match(nt);if(x&&!o.movedTo){let w=x[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(w))w+=".dat";o.movedTo=ne(w)}o.cmds.push(T);continue}if(u||d)continue;if(!o)g(t);let v=st(M);if(!v){if(/^[2-5][ \\t]/.test(h))m=!1;continue}A(v,!1),o.cmds.push(v),m=!1}return l(),c?{main:i,files:s,data:c}:{main:i,files:s}}var Pn=Math.PI/180;function mt(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 ht(e,t){let[n,r,s,o,i,c,u,f,a,l,m,g]=e,[d,b,C,A,p,h,M,D,v,L,R,T]=t;return[o*d+i*b+c*C+n,u*d+f*b+a*C+r,l*d+m*b+g*C+s,o*A+i*M+c*L,o*p+i*D+c*R,o*h+i*v+c*T,u*A+f*M+a*L,u*p+f*D+a*R,u*h+f*v+a*T,l*A+m*M+g*L,l*p+m*D+g*R,l*h+m*v+g*T]}var Ne=[0,0,0,1,0,0,0,1,0,0,0,1];var ot=new WeakMap,rn=/^(s|8|48)\\//;function ze(e,t){let n=e.files.get(ne(t));if(!n)return"part";let r=ot.get(n);if(r)return r;if(n.org)r=ft.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&&rn.test(s.file))?"part":"model";return ot.set(n,r),r}var it=new WeakMap;function gt(e){let t=it.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 it.set(e,t),t}var at=(e)=>e>16777215?"0x"+e.toString(16).toUpperCase():e<0?Be.get(e)??String(e):String(e),sn=(e)=>e.t===0?"0 "+e.text:e.t===1?`1 ${at(e.color)} ${e.m.join(" ")} ${e.file}`:e.src?e.src:`${e.t} ${at(e.color)} ${e.p.join(" ")}`,$e=(e,t)=>`${ne(e)}#${t}`;function on(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:$e(e.name,t),cmds:n}}function dt(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...on(e,t).cmds.map(sn)].join(`\n`)+`\n`}function je(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,"0")}function bt(e){let[t,n,r,s,o,i,c,u,f,a,l,m]=e,g=u*m-f*l,d=-(c*m-f*a),b=c*l-u*a,C=s*g+o*d+i*b;if(!Number.isFinite(C)||Math.abs(C)<0.000000000001)return null;let A=1/C,p=[g*A,-(o*m-i*l)*A,(o*f-i*u)*A,d*A,(s*m-i*a)*A,-(s*f-i*c)*A,b*A,-(s*l-o*a)*A,(s*u-o*c)*A];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 an=(e)=>String(+e.toFixed(6)||0),lt=(e)=>\'"\'+e.replace(/\\\\/g,"\\\\\\\\").replace(/"/g,"\\\\\\"")+\'"\';function yt(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!=="PLANAR"?[t.a??360]:[],...t.method==="SPHERICAL"?[t.b??180]:[]].map(an).join(" "),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${lt(t.texture)}${t.glossmap?" GLOSSMAP "+lt(t.glossmap):""}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${ne(e)}\n0 !TEXMAP END\n`;return{name:`${ne(e)}#tex-${je(r)}`,source:r}}var ln=(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 cn(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 ct=new WeakMap;function xt(e){let t=ct.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=cn(o.x,o.y,o.z);r=o.mode==="ABS"?{abs:!0,m:i,rotstep:o}:o.mode==="ADD"&&r?{abs:r.abs,m:ln(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),ct.set(e,n),n}class Ve extends Error{limit;code="ldr-model-limit";constructor(e,t){super(`ldr: ${e} expands past ${t.toLocaleString("en-US")} (see maxInstances)`);this.limit=t;this.name="ModelLimitError"}}var un=(e)=>{for(let t=0;t<12;t++)if(!(Math.abs(e[t])<=ut))return!1;return!0},wt=999999,vt=(e)=>e.map((t)=>String(t).padStart(6,"0")).join(".")+"~",Ct=new WeakMap,Mt=new WeakMap;function fn(e,t){let n=Mt.get(t);if(!n)n={head:[...t.values()].map((o)=>{let i=Ct.get(o)??"",c=i.indexOf("!COLOUR");return c<0?"":"0 "+i.slice(c).trim().replace(/\\s+/g," ")}).filter(Boolean).join(`\n`),parts:new Map},Mt.set(t,n);let r=n.parts.get(e);if(!r){let s=ne(e),o=`0 ldr: ${s} placed in a model\'s !COLOUR scope\n0 BFC CERTIFY CCW\n${n.head}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${s}\n`;r={name:`${s}#col-${je(o)}`,source:o},n.parts.set(e,r)}return r}function pn(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=(d,b)=>{let C=d.name+"#"+b,A=c.get(C);if(!A){let p;A=Object.assign(()=>p??=dt(d,b),{file:d,step:b}),c.set(C,A)}return A},g=(d,b,C,A,p,h,M,D,v=null,L=[],R=[],T=void 0,x=null)=>{let w=d.files.get(b);if(!w||M>r||f.has(w))return;if(++l>a)throw new Ve("model",a);f.add(w);let E=x,z=0,k=M>0?++u:0,P=i&&k?[...L,k]:L,Y=i&&k?[...R,C]:R,I=i&&!v?new Map:null,j=-1,H=0,Z=(S,y,B,_,W,X,N)=>{if(j!==z)j=z,H=0;let q=I?.get(z+"|"+y);if(q)return q.n++,g(S,S===d?y:S.main,B,_,p+"/"+y,[...W,wt],M+1,X,[...W,wt],P,Y,N,E);let U=[...W,H++],F=n.length;g(S,S===d?y:S.main,B,_,p+"/"+y,U,M+1,X,v,P,Y,N,E),I?.set(z+"|"+y,{n:1,from:F,to:n.length})},O=xt(w),G=s?gt(w):[],K=0,J=(S,y,B,_,W,X,N,q,U)=>{if(v)_=v;if(++l>a)throw new Ve("model",a);let F={part:S,color:y,m:B,step:_[0],steps:_,localStep:W,path:p};if(q)F.colour=q;if(k){if(F.sub=k,i)F.subPath=P,F.subMats=Y}if(X)F.embedded=!0;if(N){let re=yt(S,N);F.texPart=re.name,F.texSource=re.source}else if(U){let re=fn(S,U);F.colPart=re.name,F.colSource=re.source}let V=O[W];if(V)F.view=V;return n.push(F),F},Q=(S)=>{while(K<G.length&&G[K]<=S){let y=G[K++];J($e(w.name,y),A,C,[...h,y],y,!1,null,T,x).source=m(w,y)}};for(let S of w.cmds){if(S.t===0&&S.step){z++;continue}let y=S;if(y.t>=2||y.t===0&&y.geom&&y.geom.t>=2){Q(z);continue}if(y.t===0){if(y.meta==="!COLOUR"){let V=hn(y.text);if(V&&V.code!==16&&V.code!==24)Ct.set(V,y.text),(E=new Map(E??[])).set(V.code,V);continue}if(o&&y.geom?.t===1)y=y.geom;else continue}if(y.t!==1)continue;if(o&&y.fallback)continue;let B=ht(C,y.m);if(!un(B))continue;let _=y.color===16?A:y.color,W=y.color===16?T:E?.get(y.color),X=[...h,z],N=o?y.tex??D:null,q=N?bt(y.m):null,U=N&&q?mt(N,q):null;if(d.files.has(y.file)){if(ze(d,y.file)==="model"){Z(d,y.file,B,_,X,U,W);continue}J(y.file,_,B,X,z,!0,U,W,E);continue}let F=t.resolveModel?.(y.file);if(F){Z(F,y.file,B,_,X,U,W);continue}J(y.file,_,B,X,z,!1,U,W,E)}if(Q(1/0),f.delete(w),I){for(let S of I.values())if(S.n>1)for(let y=S.from;y<S.to;y++)n[y].mult??=S.n}};if(ze(e,e.main)==="part"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...Ne],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return g(e,e.main,Ne,16,e.main,[],0,null),n}function Tt(e,t="main.ldr",n){return pn(pt(e,t,{geometryText:!0}),n)}var mn=new Set(["CHROME","PEARLESCENT","RUBBER","MATTE_METALLIC","METAL","MATERIAL"]);function _e(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 At(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=_e(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 hn(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&&De.test(m)?Ue(m):m!==void 0&&/^\\d+$/.test(m)?+m:NaN,a+=2;else if(l==="VALUE"){let g=_e(m);if(g)o=g;a+=2}else if(l==="EDGE")i=_e(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:d,next:b}=At(n,a+2);f={type:"glitter",material:d},a=b}else if(g==="SPECKLE"){let{grain:d,next:b}=At(n,a+2);f={type:"speckle",material:d},a=b}else if(g==="FABRIC"){let d=(n[a+2]||"").toUpperCase(),b=["VELVET","CANVAS","STRING","FUR"].includes(d)?d.toLowerCase():void 0;f={type:"fabric",kind:b},a+=b?3:2}else a=n.length}else if(mn.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 gn(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 He(e){let t=gn(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 dn(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(ne(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(ne(t),r)}let u=i.trim().replace(/\\s+/g," ");if(u)r.push(u)}return n}var bn=(e)=>{if(!e.startsWith("1 "))return null;let t=e.split(" ");return t.length>=15?ne(t.slice(14).join(" ")):null};function yn(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 Lt(e,t,n="main.ldr"){let r=dn(e,n),s=new Map;for(let o of t){let i=ne(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=bn(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/${yn(f)}.dat`)}return s}var St=(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,Et=new WeakMap;function Ge(e,t){let n=Et.get(e);if(!n)Et.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),c=[],u=[];s.studs.forEach((m,g)=>{c.push(m[0]),u.push(m[1]);for(let d=0;d<12;d++)i[g*12+d]=m[2+d]});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}),r}var fe=1073741824;class We{a;b;c;vals;used;mask;size=0;constructor(e=1024){let t=1024;while(t<e*2)t*=2;this.a=new Int32Array(t),this.b=new Int32Array(t),this.c=new Int32Array(t),this.vals=new Int32Array(t),this.used=new Uint8Array(t),this.mask=t-1}slot(e,t,n){let r=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return r^=r>>>15,r=Math.imul(r,739982445),r^=r>>>12,r&this.mask}get(e,t,n){let r=this.slot(e,t,n),s=this.used,o=this.a,i=this.b,c=this.c;for(;;){if(!s[r])return-1;if(o[r]===e&&i[r]===t&&c[r]===n)return this.vals[r];r=r+1&this.mask}}put(e,t,n,r){if((this.size+1)*2>this.used.length)this.grow();let s=this.slot(e,t,n),o=this.used,i=this.a,c=this.b,u=this.c;for(;;){if(!o[s])return o[s]=1,i[s]=e,c[s]=t,u[s]=n,this.vals[s]=r,this.size++,-1;if(i[s]===e&&c[s]===t&&u[s]===n){let f=this.vals[s];return this.vals[s]=r,f}s=s+1&this.mask}}grow(){let{a:e,b:t,c:n,vals:r,used:s}=this,o=s.length*2;this.a=new Int32Array(o),this.b=new Int32Array(o),this.c=new Int32Array(o),this.vals=new Int32Array(o),this.used=new Uint8Array(o),this.mask=o-1,this.size=0;for(let i=0;i<s.length;i++)if(s[i])this.put(e[i],t[i],n[i],r[i])}}var pe=(e,t,n)=>e>-fe&&e<fe&&t>-fe&&t<fe&&n>-fe&&n<fe,de=2147483647;function xn(e,t){let n=e.colorTable?.[t];if(n)return(n.alpha??255)<255;return t.charCodeAt(0)===35&&/\\/[^:/]*:a\\d/.test(t)}function wn(e,t,n){let s=new Map,o=(I)=>{let j=s.get(I);if(j===void 0)s.set(I,j=xn(t,I));return j},i=[],c=[],u=[],f=[],a=[],l=[],m=[],g=[],d=[],b=new We(e.length*2),C=[],A=[];for(let I=0;I<e.length;I++){let j=e[I],H=j.m,Z=t.parts[j.part];if(!Z||!Z.mask||!St(H)||o(j.color))continue;let O=Z.bbox,G=1/0,K=-1/0,J=1/0,Q=-1/0;for(let U=0;U<2;U++)for(let F=0;F<2;F++){let V=U?O[3]:O[0],re=F?O[5]:O[2],oe=H[0]+H[3]*V+H[5]*re,se=H[2]+H[9]*V+H[11]*re;if(oe<G)G=oe;if(oe>K)K=oe;if(se<J)J=se;if(se>Q)Q=se}let S=Math.round((H[1]+O[4])*2),y=Ge(t,j.part),B=Math.floor(G/40),_=Math.floor(K/40),W=Math.floor(J/40),X=Math.floor(Q/40);if(!((_-B+1)*(X-W+1)<=65536)||!pe(S,B,W)||!pe(S,_,X))continue;let N=-1;for(let U=b.get(S,B,W),F=0;U>=0&&F<8;U=C[U],F++){let V=A[U];if(i[V]!==G||c[V]!==K||u[V]!==J||f[V]!==Q||m[V]!==y)continue;let re=e[a[V]].m,oe=!0;for(let se=0;se<12;se++)if(re[se]!==H[se]){oe=!1;break}if(oe){N=V;break}}if(N>=0){let U=n?n[I]:0;if(n&&U<n[a[N]])l[N]=a[N],a[N]=I;else if(l[N]<0||n&&U<n[l[N]])l[N]=I;continue}let q=a.length;i.push(G),c.push(K),u.push(J),f.push(Q),a.push(I),l.push(-1),m.push(y),g.push(O[0]),d.push(O[2]);for(let U=B;U<=_;U++)for(let F=W;F<=X;F++){if(!pe(S,U,F))continue;let V=A.length;A.push(q),C.push(b.put(S,U,F,V))}}let p=[0,5,-5,5,-5],h=[0,5,5,-5,-5],M=NaN,D=NaN,v=NaN,L=-1,R=(I,j,H,Z)=>{let O=Math.round(j*2),G=Math.floor(I/40),K=Math.floor(H/40);if(!pe(O,G,K))return de;let J=de;if(O!==M||G!==D||K!==v)M=O,D=G,v=K,L=b.get(O,G,K);for(let Q=L;Q>=0;Q=C[Q]){let S=A[Q],y=a[S];if(y===Z&&(y=l[S])<0)continue;if(!(I-6>=i[S]-0.5&&I+6<=c[S]+0.5&&H-6>=u[S]-0.5&&H+6<=f[S]+0.5))continue;let B=e[a[S]].m,_=m[S],W=g[S],X=d[S],N=I-B[0],q=j-B[1],U=H-B[2],F=B[3]*N+B[6]*q+B[9]*U,V=B[5]*N+B[8]*q+B[11]*U,{nx:re,nz:oe,mask:se}=_,ce=!0;for(let ie=0;ie<5;ie++){let ae=Math.floor((F+p[ie]-W)/20),ue=Math.floor((V+h[ie]-X)/20);if(ae<0||ue<0||ae>=re||ue>=oe||se[ae*oe+ue]!==1){ce=!1;break}}if(ce){if(!n)return 0;let ie=n[y];if(ie<J)J=ie}}return J},T=0;for(let I of e){let j=Ge(t,I.part);if(j)T+=j.nStuds}let x=new Uint8Array(T),w=new Uint8Array(T),E=new We(T),z=0,k=n?new Int32Array(T).fill(de):void 0;for(let I=0,j=0;I<e.length;I++){let H=e[I],Z=Ge(t,H.part);if(!Z)continue;let O=H.m,G=Z.studM,K=O[0],J=O[1],Q=O[2],S=O[3],y=O[4],B=O[5],_=O[6],W=O[7],X=O[8],N=O[9],q=O[10],U=O[11];for(let F=0;F<Z.nStuds;F++,j++){let V=F*12,re=G[V+4],oe=G[V+7],se=G[V+10];if(!(Math.abs(_*re+W*oe+X*se-1)<0.001&&Math.abs(S*re+y*oe+B*se)<0.001&&Math.abs(N*re+q*oe+U*se)<0.001))continue;w[j]=1;let ce=G[V],ie=G[V+1],ae=G[V+2],ue=K+S*ce+y*ie+B*ae,Ke=J+_*ce+W*ie+X*ae,Xe=Q+N*ce+q*ie+U*ae,Ze=R(ue,Ke,Xe,I);if(Ze!==de){if(x[j]=1,z++,k)k[j]=Ze}let be=Math.round(ue),ye=Math.round(Ke),xe=Math.round(Xe);if(!pe(be,ye,xe))continue;if(!n){E.put(be,ye,xe,1);continue}let Ye=n[I],Je=E.get(be,ye,xe);if(Je<0||Ye<Je)E.put(be,ye,xe,Ye)}}let P=new Uint8Array(e.length),Y=n?new Int32Array(e.length).fill(de):void 0;for(let I=0;I<e.length;I++){let j=e[I],H=t.parts[j.part];if(!H||!H.under||!St(j.m)||o(j.color))continue;let Z=H.bbox,O=Math.round((Z[3]-Z[0])/20),G=Math.round((Z[5]-Z[2])/20);if(!O||!G||O*G>4096)continue;let K=j.m,J=!0,Q=0;for(let S=0;S<O&&J;S++)for(let y=0;y<G;y++){let B=Z[0]+10+20*S,_=Z[2]+10+20*y,W=K[0]+K[3]*B+K[5]*_,X=K[2]+K[9]*B+K[11]*_,N=Math.round(W),q=Math.round(K[1]+Z[4]),U=Math.round(X),F=pe(N,q,U)?E.get(N,q,U):-1;if(F<0){J=!1;break}if(F>Q)Q=F}if(J){if(P[I]=1,Y)Y[I]=Q}}return{nStuds:T,studHidden:x,studUp:w,underHidden:P,studsHidden:z,studHideStep:k,underHideStep:Y}}function Mn(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 d=t.colorTable?.[l.color],b=d?.hex??t.colors?.[l.color],C=d?He({alpha:d.alpha??255,luminance:d.luminance??0,finish:d.finish??{type:"default"}}):"default:op",A=He(m);if(g=b&&b.toUpperCase()===m.hex.toUpperCase()&&C===A?String(l.color):m.hex.toUpperCase()+"/"+A,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)=>vt(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 Ce(e,t,n=!0){let r=Mn(e,t,n);return wn(r.all,t,r.nSteps>1?r.stepOf:void 0)}var ke="https://ldr-demo.vercel.app/cdn/v1/",Le=new Map,Te=new Map;function Se(e=ke,t=fetch){let n=Le.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(()=>Le.delete(e)),Le.set(e,n);return n}var An=(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"),Ee=(e,t)=>An(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>Ee(n,t)):e&&typeof e==="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Ee(r,t)])):e;function vn(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 d=new DataView(g).getUint32(0,!0),b=new Uint8Array(g,4+d),C=r;n.push(b),r+=b.byteLength;let A=(4-r%4)%4;if(A)n.push(new Uint8Array(A)),r+=A;for(let[p,h]of Object.entries(m.header.parts??{}))if(!(p in s))s[p]=Ee(h,C);for(let[p,h]of Object.entries(m.header.studKinds??{}))if(!(p in o))o[p]=Ee(h,C)}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 ve(a.buffer)}async function Cn(e,t={}){e=[...e];try{return await kt(e,t)}catch(n){let r=t.cdn??ke,s=t.fetch??fetch;Le.delete(r);let o=(i,c)=>s(i,{...c,cache:"reload"});try{return await kt(e,{...t,fetch:o})}catch{throw n}}}async function kt(e,t){let n=t.cdn??ke,r=t.fetch??fetch,s=t.gap??16384,o=await Se(n,r),i=[...new Set([...e].map(ne))],c=[],u=[];for(let p of i){if(Te.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,d=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 D=Ae(h.subarray(M.off-p.start,M.off-p.start+M.len)),v=D.buffer.slice(D.byteOffset,D.byteOffset+D.byteLength);Te.set(n+M.name,ve(v))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,f.length)},d));let b=i.filter((p)=>Te.has(n+p)).map((p)=>Te.get(n+p)),C={colors:o.colors,...o.colorTable?{colorTable:o.colorTable}:{}};return{pack:b.length?vn(b,C):ve(Tn(C)),missing:c,requests:l,bytes:a}}function Tn(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 Ln(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 Pt(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):ne(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 Pe extends Error{code="ldr-budget";bodyTris;packBytes;maxBodyTris;maxPackBytes;constructor(e){let t=[e.maxBodyTris!=null&&e.bodyTris>e.maxBodyTris?`${e.bodyTris} triangles (limit ${e.maxBodyTris})`:"",e.maxPackBytes!=null&&e.packBytes>e.maxPackBytes?`${(e.packBytes/1e6).toFixed(1)} MB parts pack (limit ${(e.maxPackBytes/1e6).toFixed(0)} MB)`:""].filter(Boolean).join(", ");super(`ldr: model exceeds device budget: ${t}`);this.name="BudgetError",this.bodyTris=e.bodyTris,this.packBytes=e.packBytes,this.maxBodyTris=e.maxBodyTris,this.maxPackBytes=e.maxPackBytes}}async function It(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=Se(t.cdn??ke,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(x)=>{if(!x.ok)throw Error(`ldr: ${x.status} fetching ${e}`);return et(await x.arrayBuffer())}),i=performance.now(),c=t.name??(t.text?"main.ldr":tt(e)),u=Tt(o,c,{looseGeometry:!1,callouts:t.callouts}),f=performance.now();t.onParsed?.(u),await s;let a=Lt(o,new Set(u.filter((x)=>x.embedded).map((x)=>x.part)),c),l=(x,w)=>t.maxBodyTris!=null&&x>t.maxBodyTris||t.maxPackBytes!=null&&w>t.maxPackBytes,m=t.maxBodyTris!=null||t.maxPackBytes!=null,g=(x)=>new Pe({...x,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes}),d="full";if(m){let x=Pt(u,a,await s);if(l(x.known?x.bodyTris:0,x.packBytes)){if(!t.lowCdn)throw g(x);let w=await Se(t.lowCdn,r).catch(()=>null);if(!w)throw g(x);let E=Pt(u,a,w);if(l(E.known?E.bodyTris:0,E.packBytes))throw g(E);d="low"}}let b=[...u.filter((x)=>!x.embedded).map((x)=>x.part),...a.values()],C=async()=>{let x=await Cn(b,d==="low"?{...t,cdn:t.lowCdn}:t);for(let[w,E]of a){let z=x.pack.header.parts[E];if(z)x.pack.header.parts[w]=z}return{...x,packBytes:x.pack.buffer?.byteLength??x.pack.bytes??0,bodyTris:Ln(u,x.pack)}},A=await C();if(m&&l(A.bodyTris,A.packBytes)&&d==="full"&&t.lowCdn&&await Se(t.lowCdn,r).then(()=>!0,()=>!1)){d="low";let x=A;A=await C(),A.requests+=x.requests,A.bytes+=x.bytes}if(m&&l(A.bodyTris,A.packBytes))throw g(A);let{pack:p,missing:h,requests:M,bytes:D}=A,v=new Map([...a].map(([x,w])=>[w,x])),L=h.map((x)=>v.get(x)??x),R=performance.now(),T=t.cull?Ce(u,p.header,t.textures!==!1):void 0;return{insts:u,pack:p,tier:d,missing:L,requests:M,bytes:D,cull:T,timings:{fetchModel:i-n,parse:f-i,parts:R-f,...T?{cull:performance.now()-R}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await It(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=Ce(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 Pe||s?.code==="ldr-budget")self.postMessage({id:t,phase:"error",error:String(s?.message??s),budget:{bodyTris:s.bodyTris,packBytes:s.packBytes,maxBodyTris:s.maxBodyTris,maxPackBytes:s.maxPackBytes}});else self.postMessage({id:t,phase:"error",error:String(s?.message??s)})}};\n';
|
|
5239
|
+
// ../../../../../../../tmp/ldr-build-DCpOVo/src/load-worker.gen.ts
|
|
5240
|
+
var load_worker_gen_default = 'var Wt=ArrayBuffer,K=Uint8Array,Se=Uint16Array,Xt=Int16Array;var ke=Int32Array,je=function(e,t,n){if(K.prototype.slice)return K.prototype.slice.call(e,t,n);if(t==null||t<0)t=0;if(n==null||n>e.length)n=e.length;var r=new K(n-t);return r.set(e.subarray(t,n)),r},Me=function(e,t,n,r){if(K.prototype.fill)return K.prototype.fill.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;for(;n<r;++n)e[n]=t;return e},Kt=function(e,t,n,r){if(K.prototype.copyWithin)return K.prototype.copyWithin.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;while(n<r)e[t++]=e[n++]};var Zt=["invalid zstd data","window size too large (>2046MB)","invalid block type","FSE accuracy too high","match distance too far back","unexpected EOF"],Z=function(e,t,n){var r=Error(t||Zt[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,Z);if(!n)throw r;return r},ft=function(e,t,n){var r=0,s=0;for(;r<n;++r)s|=e[t++]<<(r<<3);return s},Yt=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},Jt=function(e,t){var n=e[0]|e[1]<<8|e[2]<<16;if(n==3126568&&e[3]==253){var r=e[4],s=r>>5&1,o=r>>2&1,i=r&3,c=r>>6;if(r&8)Z(0);var u=6-s,f=i==3?4:i,l=ft(e,u,f);u+=f;var a=c?1<<c:s,p=ft(e,u,a)+(c==1&&256),g=p;if(!s){var b=1<<10+(e[5]>>3);g=b+(b>>3)*(e[5]&7)}if(g>2145386496)Z(1);var y=new K((t==1?p||g:t?0:g)+12);return y[0]=1,y[4]=4,y[8]=8,{b:u+a,y:0,l:0,d:l,w:t&&t!=1?t:y.subarray(12),e:g,o:new ke(y.buffer,0,3),u:p,c:o,m:Math.min(131072,g)}}else if((n>>4|e[3]<<20)==25481893)return Yt(e,4)+8;Z(0)},be=function(e){var t=0;for(;1<<t<=e;++t);return t-1},Ae=function(e,t,n){var r=(t<<3)+4,s=(e[t]&15)+5;if(s>n)Z(3);var o=1<<s,i=o,c=-1,u=-1,f=-1,l=o,a=new Wt(512+(o<<2)),p=new Xt(a,0,256),g=new Se(a,0,256),b=new Se(a,512,o),y=512+(o<<1),w=new K(a,y,o),x=new K(a,y+o);while(c<255&&i>0){var m=be(i+1),d=r>>3,M=(1<<m+1)-1,U=(e[d]|e[d+1]<<8|e[d+2]<<16)>>(r&7)&M,T=(1<<m)-1,k=M-i-1,D=U&T;if(D<k)r+=m,U=D;else if(r+=m+1,U>T)U-=k;if(p[++c]=--U,U==-1)i+=U,w[--l]=c;else i-=U;if(!U)do{var P=r>>3;u=(e[P]|e[P+1]<<8)>>(r&7)&3,r+=2,c+=u}while(u==3)}if(c>255||i)Z(0);var A=0,v=(o>>1)+(o>>3)+3,E=o-1;for(var z=0;z<=c;++z){var S=p[z];if(S<1){g[z]=-S;continue}for(f=0;f<S;++f){w[A]=z;do A=A+v&E;while(A>=l)}}if(A)Z(0);for(f=0;f<o;++f){var I=g[w[f]]++,X=x[f]=s-be(I);b[f]=(I<<X)-o}return[r+7>>3,{b:s,s:w,n:x,t:b}]},Qt=function(e,t){var n=0,r=-1,s=new K(292),o=e[t],i=s.subarray(0,256),c=s.subarray(256,268),u=new Se(s.buffer,268);if(o<128){var f=Ae(e,t+1,6),l=f[0],a=f[1];t+=o;var p=l<<3,g=e[t];if(!g)Z(0);var b=0,y=0,w=a.b,x=w,m=(++t<<3)-8+be(g);for(;;){if(m-=w,m<p)break;var d=m>>3;if(b+=(e[d]|e[d+1]<<8)>>(m&7)&(1<<w)-1,i[++r]=a.s[b],m-=x,m<p)break;d=m>>3,y+=(e[d]|e[d+1]<<8)>>(m&7)&(1<<x)-1,i[++r]=a.s[y],w=a.n[b],b=a.t[b],x=a.n[y],y=a.t[y]}if(++r>255)Z(0)}else{r=o-127;for(;n<r;n+=2){var M=e[++t];i[n]=M>>4,i[n+1]=M&15}++t}var U=0;for(n=0;n<r;++n){var T=i[n];if(T>11)Z(0);U+=T&&1<<T-1}var k=be(U)+1,D=1<<k,P=D-U;if(P&P-1)Z(0);i[r++]=be(P)+1;for(n=0;n<r;++n){var T=i[n];++c[i[n]=T&&k+1-T]}var A=new K(D<<1),v=A.subarray(0,D),E=A.subarray(D);u[k]=0;for(n=k;n>0;--n){var z=u[n];Me(E,n,z,u[n-1]=z+c[n]*(1<<k-n))}if(u[0]!=D)Z(0);for(n=0;n<r;++n){var S=i[n];if(S){var I=u[S];Me(v,n,I,u[S]=I+(1<<k-S))}}return[t,{n:E,b:k,s:v}]},qt=Ae(new K([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],en=Ae(new K([33,20,196,24,99,140,33,132,16,66,8,33,132,16,66,8,33,68,68,68,68,68,68,68,68,36,9]),0,6)[1],tn=Ae(new K([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],pt=function(e,t){var n=e.length,r=new ke(n);for(var s=0;s<n;++s)r[s]=t,t+=1<<e[s];return r},Ve=new K(new ke([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),nn=pt(Ve,0),_e=new K(new ke([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),rn=pt(_e,3),we=function(e,t,n){var r=e.length,s=t.length,o=e[r-1],i=(1<<n.b)-1,c=-n.b;if(!o)Z(0);var u=0,f=n.b,l=(r<<3)-8+be(o)-f,a=-1;for(;l>c&&a<s;){var p=l>>3,g=(e[p]|e[p+1]<<8|e[p+2]<<16)>>(l&7);u=(u<<f|g)&i,t[++a]=n.s[u],l-=f=n.n[u]}if(l!=c||a+1!=s)Z(0)},sn=function(e,t,n){var r=6,s=t.length,o=s+3>>2,i=o<<1,c=o+i;we(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,o),n),we(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(o,i),n),we(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,c),n),we(e.subarray(r),t.subarray(c),n)},on=function(e,t,n){var r,s=t.b,o=e[s],i=o>>1&3;t.l=o&1;var c=o>>3|e[s+1]<<5|e[s+2]<<13,u=(s+=3)+c;if(i==1){if(s>=e.length)return;if(t.b=s+1,n)return Me(n,e[s],t.y,t.y+=c),n;return Me(new K(c),e[s])}if(u>e.length)return;if(i==0){if(t.b=u,n)return n.set(e.subarray(s,u),t.y),t.y+=c,n;return je(e,s,u)}if(i==2){var f=e[s],l=f&3,a=f>>2&3,p=f>>4,g=0,b=0;if(l<2)if(a&1)p|=e[++s]<<4|(a&2&&e[++s]<<12);else p=f>>3;else if(b=a,a<2)p|=(e[++s]&63)<<4,g=e[s]>>6|e[++s]<<2;else if(a==2)p|=e[++s]<<4|(e[++s]&3)<<12,g=e[s]>>2|e[++s]<<6;else p|=e[++s]<<4|(e[++s]&63)<<12,g=e[s]>>6|e[++s]<<2|e[++s]<<10;++s;var y=n?n.subarray(t.y,t.y+t.m):new K(t.m),w=y.length-p;if(l==0)y.set(e.subarray(s,s+=p),w);else if(l==1)Me(y,e[s++],w);else{var x=t.h;if(l==2){var m=Qt(e,s);g+=s-(s=m[0]),t.h=x=m[1]}else if(!x)Z(0);(b?sn:we)(e.subarray(s,s+=g),y.subarray(w),x)}var d=e[s++];if(d){if(d==255)d=(e[s++]|e[s++]<<8)+32512;else if(d>127)d=d-128<<8|e[s++];var M=e[s++];if(M&3)Z(0);var U=[en,tn,qt];for(var T=2;T>-1;--T){var k=M>>(T<<1)+2&3;if(k==1){var D=new K([0,0,e[s++]]);U[T]={s:D.subarray(2,3),n:D.subarray(0,1),t:new Se(D.buffer,0,1),b:0}}else if(k==2)r=Ae(e,s,9-(T&1)),s=r[0],U[T]=r[1];else if(k==3){if(!t.t)Z(0);U[T]=t.t[T]}}var P=t.t=U,A=P[0],v=P[1],E=P[2],z=e[u-1];if(!z)Z(0);var S=(u<<3)-8+be(z)-E.b,I=S>>3,X=0,re=(e[I]|e[I+1]<<8)>>(S&7)&(1<<E.b)-1;I=(S-=v.b)>>3;var ee=(e[I]|e[I+1]<<8)>>(S&7)&(1<<v.b)-1;I=(S-=A.b)>>3;var ce=(e[I]|e[I+1]<<8)>>(S&7)&(1<<A.b)-1;for(++d;--d;){var fe=E.s[re],ge=E.n[re],se=A.s[ce],ue=A.n[ce],pe=v.s[ee],me=v.n[ee];I=(S-=pe)>>3;var V=1<<pe,h=V+((e[I]|e[I+1]<<8|e[I+2]<<16|e[I+3]<<24)>>>(S&7)&V-1);I=(S-=_e[se])>>3;var F=rn[se]+((e[I]|e[I+1]<<8|e[I+2]<<16)>>(S&7)&(1<<_e[se])-1);I=(S-=Ve[fe])>>3;var L=nn[fe]+((e[I]|e[I+1]<<8|e[I+2]<<16)>>(S&7)&(1<<Ve[fe])-1);if(I=(S-=ge)>>3,re=E.t[re]+((e[I]|e[I+1]<<8)>>(S&7)&(1<<ge)-1),I=(S-=ue)>>3,ce=A.t[ce]+((e[I]|e[I+1]<<8)>>(S&7)&(1<<ue)-1),I=(S-=me)>>3,ee=v.t[ee]+((e[I]|e[I+1]<<8)>>(S&7)&(1<<me)-1),h>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=h-=3;else{var B=h-(L!=0);if(B){if(h=B==3?t.o[0]-1:t.o[B],B>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=h}else h=t.o[0]}for(var T=0;T<L;++T)y[X+T]=y[w+T];X+=L,w+=L;var C=X-h;if(C<0){var R=-C,O=t.e+C;if(R>F)R=F;for(var T=0;T<R;++T)y[X+T]=t.w[O+T];X+=R,F-=R,C=0}for(var T=0;T<F;++T)y[X+T]=y[C+T];X+=F}if(X!=w)while(w<y.length)y[X++]=y[w++];else X=y.length;if(n)t.y+=X;else y=je(y,0,X)}else if(n){if(t.y+=p,w)for(var T=0;T<p;++T)y[T]=y[w+T]}else if(w)y=je(y,w);return t.b=u,y}Z(2)},an=function(e,t){if(e.length==1)return e[0];var n=new K(t);for(var r=0,s=0;r<e.length;++r){var o=e[r];n.set(o,s),s+=o.length}return n};function Ee(e,t){var n=[],r=+!t,s=0,o=0;for(;e.length;){var i=Jt(e,r||t);if(typeof i=="object"){if(r){if(t=null,i.w.length==i.u)n.push(t=i.w),o+=i.u}else n.push(t),i.e=0;for(;!i.l;){var c=on(e,i,t);if(!c)Z(5);if(t)i.e=i.y;else n.push(c),o+=c.length,Kt(i.w,0,c.length),i.w.set(c,i.w.length-c.length)}s=i.b+i.c*4}else s=i;e=e.subarray(s)}return an(n,o)}async function ln(e){let t=e instanceof Uint8Array?e:new Uint8Array(e),n=(r)=>r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength);if(t[0]===40&&t[1]===181&&t[2]===47&&t[3]===253)return n(Ee(t));if(t[0]===31&&t[1]===139)return new Response(new Blob([t]).stream().pipeThrough(new DecompressionStream("gzip"))).arrayBuffer();return n(t)}async function mt(e){return new TextDecoder().decode(await ln(e))}var ht=(e)=>decodeURIComponent(e.split(/[?#]/)[0].split("/").pop()||"main.ldr").replace(/\\.(zst|gz)$/i,"")||"main.ldr";function Pe(e){let t=new DataView(e).getUint32(0,!0),n=JSON.parse(new TextDecoder().decode(new Uint8Array(e,4,t))),r=4+t;return{header:n,arr:(o)=>o&&(o[2]==="f32"?new Float32Array(e,r+o[0],o[1]):o[2]==="u16"?new Uint16Array(e,r+o[0],o[1]):o[2]==="u8"?new Uint8Array(e,r+o[0],o[1]):new Uint32Array(e,r+o[0],o[1])),bytes:e.byteLength,buffer:e}}var Y=(e)=>e.trim().toLowerCase().replace(/\\\\/g,"/").replace(/\\/+/g,"/"),He=/^[A-Za-z][A-Za-z0-9_]*$/,Ge=new Map;function We(e){let t=e.toLowerCase(),n=2166136261;for(let s=0;s<t.length;s++)n^=t.charCodeAt(s),n=Math.imul(n,16777619);let r=-1-(n>>>0&1073741823);if(!Ge.has(r))Ge.set(r,t);return r}function Xe(e){let t=e.charCodeAt(0)|32;if(t>=97&&t<=122&&He.test(e))return We(e);if(/^0x/i.test(e))return parseInt(e,16);return+e}var gt=/^~?\\s*moved\\s+to\\s+(.+)$/i,cn=new Set(["FILE","NOFILE","!DATA","!:","STEP","BFC","ROTSTEP","BUFEXCHG","!TEXMAP"]),un=new Set(["FILE","NOFILE","!DATA"]),vt=1000000000000000,Ct=new Set(["part","subpart","primitive","8_primitive","48_primitive","shortcut","helper"]),fn=new Set(["model","submodel","configuration"]),pn=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function bt(e){let t=pn.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,"");return Ct.has(n)||fn.has(n)?n:void 0}function mn(e){let t=[],n=0;while(n<e.length){while(e[n]===" "||e[n]==="\\t")n++;if(n>=e.length)break;if(e[n]===\'"\'){let r="";n++;while(n<e.length&&e[n]!==\'"\'){if(e[n]==="\\\\"&&n+1<e.length)n++;r+=e[n++]}n++,t.push(r)}else{let r=n;while(r<e.length&&e[r]!==" "&&e[r]!=="\\t")r++;t.push(e.slice(n,r)),n=r}}return t}function hn(e,t=!1){let n=/^\\s*(\\S+)\\s+(.*)$/.exec(e);if(!n)return null;let r=n[1].toUpperCase(),s=r==="PLANAR"?9:r==="CYLINDRICAL"?10:r==="SPHERICAL"?11:0;if(!s)return null;let o=n[2].trim().split(/\\s+/);if(o.length<s+1)return null;let i=o.slice(0,s).map(Number);if(!i.every((a)=>Number.isFinite(a)&&Math.abs(a)<=1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000))return null;if(s>=10&&!(Math.abs(i[9])>=0.000001)||s===11&&!(Math.abs(i[10])>=0.000001))return null;let c=n[2].trim();for(let a=0;a<s;a++)c=c.replace(/^\\S+\\s*/,"");let u=mn(c);if(!u.length)return null;let f={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:u[0]};if(s>=10)f.a=i[9];if(s===11)f.b=i[10];let l=u.findIndex((a,p)=>p>0&&a.toUpperCase()==="GLOSSMAP");if(l>0&&u[l+1])f.glossmap=u[l+1];if(t)f.next=!0;return f}var gn=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,"");if(t.length%4===1)t=t.slice(0,-1);let n=t+"=".repeat((4-t.length%4)%4),r=atob(n),s=new Uint8Array(r.length);for(let o=0;o<r.length;o++)s[o]=r.charCodeAt(o);return s};function bn(e){let t=e.length,n=1,r=(l)=>l===32||l===9,s=()=>{while(n<t&&r(e.charCodeAt(n)))n++;let l=n;while(n<t&&!r(e.charCodeAt(n)))n++;return l<n?e.slice(l,n):null},o=s();if(o===null)return null;let i=Array(12);for(let l=0;l<12;l++){let a=s();if(a===null)return null;let p=+a;if(!Number.isFinite(p))return null;i[l]=p}while(n<t&&r(e.charCodeAt(n)))n++;if(n>=t)return null;let c=e.slice(n),u=/[ \\t]{2,}|\\t/.test(c)?c.split(/\\s+/).join(" "):c,f=Xe(o);if(!Number.isFinite(f))return null;return{t:1,color:f,m:i,file:Y(u)}}var dn=[0,12,6,9,12,12];function dt(e){let t=+e[0];if(!(t>=1&&t<=5&&Number.isInteger(t))||e.length<2)return null;let n=Xe(e[1]),r=dn[t];if(!Number.isFinite(n)||e.length<2+r+(t===1?1:0))return null;let s=Array(r);for(let o=0;o<r;o++){let i=+e[2+o];if(!Number.isFinite(i))return null;s[o]=i}if(t===1){let o=Y(e.slice(14).join(" "));return o?{t:1,color:n,m:s,file:o}:null}if(t===2)return{t:2,color:n,p:s};if(t===3)return{t:3,color:n,p:s};if(t===4)return{t:4,color:n,p:s};return{t:5,color:n,p:s}}function Tt(e,t="main.ldr",n={}){let r=!!n.geometryText,s=new Map,o=null,i="",c,u=null,f=[],l=null,a=()=>{if(!u)return;let m=gn(u.chunks.join("")),d=m[0]===137&&m[1]===80&&m[2]===78&&m[3]===71;(c??=new Map).set(Y(u.name),{name:u.name,bytes:m,...d?{mime:"image/png"}:{}}),u=null},p=!0,g=(m)=>{if(a(),o={name:Y(m),cmds:[]},s.set(o.name,o),!i)i=o.name;f=[],l=null,p=!0},b=!1,y=!1,w=()=>{if(y)return;y=!0,s.clear(),o=null,i=""},x=(m,d)=>{if(l){m.tex=l,l=null;return}let M=f[f.length-1];if(!M)return;if(M.fallback){if(!d)m.fallback=!0}else m.tex=M.map};for(let m of e.split(`\n`)){let d=m.trim();if(!d)continue;if(r&&d.charCodeAt(0)>=50&&d.charCodeAt(0)<=53&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)){if(u||b)continue;if(!o)g(t);let k=d.slice(2).trimStart(),D=k.search(/\\s/),P={t:d.charCodeAt(0)-48,color:Xe(D<0?k:k.slice(0,D)),p:[],src:d};x(P,!1),o.cmds.push(P),p=!1;continue}if(d.charCodeAt(0)===48&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)){let k=2;while(d.charCodeAt(k)===32||d.charCodeAt(k)===9)k++;let D=k;while(D<d.length&&d.charCodeAt(D)!==32&&d.charCodeAt(D)!==9)D++;let P=d.slice(k,D),A=/[^\\x21-\\x7e]/.test(P)?d.slice(k).trim().split(/\\s+/)[0]:P;if(!cn.has(A)&&!(A.length>=4&&A.length<=6&&un.has(A.toUpperCase()))){if(b||u)continue;if(!o)g(t);let v=d.slice(k),E={t:0,text:v};if(P.charCodeAt(0)===33)E.meta=P;if(l=null,p&&!o.org){let S=bt(v);if(S)o.org=S}let z=v.match(gt);if(z&&!o.movedTo){let S=z[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(S))S+=".dat";o.movedTo=Y(S)}o.cmds.push(E);continue}}if(d.charCodeAt(0)===49&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)&&!u&&!b){let k=bn(d);if(k){if(!o)g(t);x(k,!1),o.cmds.push(k),p=!1;continue}}let M=d.split(/\\s+/);if(+M[0]===0){let k=d.slice(1).trim(),D=M.length>1&&M[1].length>=4&&M[1].length<=6?M[1].toUpperCase():M[1];if(D==="FILE"){let v=k.slice(5).trimStart().split("\\r")[0].trim();if(v){w(),b=!1,g(v);continue}}if(D==="NOFILE"){a(),o=null,b=!0;continue}if(D==="!DATA"){w(),a(),o=null,b=!1,u={name:k.slice(5).trim(),chunks:[]};continue}if(b)continue;if(u){if(M[1]==="!:")u.chunks.push(M.slice(2).join(""));continue}if(!o)g(t);let P={t:0,text:k};if(M[1]==="STEP")P.step=!0,f=[],l=null;else if(M[1]==="BFC")P.bfc=M.slice(2).join(" ");else if(M[1]==="ROTSTEP")if(P.meta="ROTSTEP",P.step=!0,f=[],l=null,(M[2]??"").toUpperCase()==="END")P.rotstep={x:0,y:0,z:0,mode:"END"};else{let v=(M[5]??"REL").toUpperCase(),E=(z)=>{let S=Number(z);return Number.isFinite(S)?S:0};P.rotstep={x:E(M[2]),y:E(M[3]),z:E(M[4]),mode:["REL","ABS","ADD"].includes(v)?v:"REL"}}else if(M[1]==="BUFEXCHG"){P.meta="BUFEXCHG";let v=(M[2]??"").toUpperCase();P.bufexchg={op:v==="RETRIEVE"?"RETRIEVE":"STORE",buf:M[3]??"A"}}else if(M[1]?.startsWith("!"))P.meta=M[1];if(p&&!o.org){let v=bt(k);if(v)o.org=v}if(M[1]==="!TEXMAP"){let v=(M[2]??"").toUpperCase();if(l=null,v==="START"||v==="NEXT"){let E=hn(k.replace(/^!TEXMAP\\s+\\S+/i,""),v==="NEXT");if(P.texmap={op:v,...E?{map:E}:{}},E)if((o.texmaps??=[]).push(E),v==="START")f.push({map:E,fallback:!1});else l=E}else if(v==="FALLBACK"){P.texmap={op:v};let E=f[f.length-1];if(E)E.fallback=!0}else if(v==="END")P.texmap={op:v},f.pop()}else if(M[1]==="!:"){l=null;let v=dt(M.slice(2));if(v)x(v,!0),P.geom=v}else l=null;let A=k.match(gt);if(A&&!o.movedTo){let v=A[1].trim().replace(/\\\\/g,"/");if(!/\\.(dat|ldr|mpd)$/i.test(v))v+=".dat";o.movedTo=Y(v)}o.cmds.push(P);continue}if(u||b)continue;if(!o)g(t);let T=dt(M);if(!T){if(/^[2-5][ \\t]/.test(d))p=!1;continue}x(T,!1),o.cmds.push(T),p=!1}return a(),c?{main:i,files:s,data:c}:{main:i,files:s}}var Hn=Math.PI/180;function Lt(e,t){let n=(r)=>[t[3]*r[0]+t[4]*r[1]+t[5]*r[2]+t[0],t[6]*r[0]+t[7]*r[1]+t[8]*r[2]+t[1],t[9]*r[0]+t[10]*r[1]+t[11]*r[2]+t[2]];return{...e,p1:n(e.p1),p2:n(e.p2),p3:n(e.p3)}}function St(e,t){let[n,r,s,o,i,c,u,f,l,a,p,g]=e,[b,y,w,x,m,d,M,U,T,k,D,P]=t;return[o*b+i*y+c*w+n,u*b+f*y+l*w+r,a*b+p*y+g*w+s,o*x+i*M+c*k,o*m+i*U+c*D,o*d+i*T+c*P,u*x+f*M+l*k,u*m+f*U+l*D,u*d+f*T+l*P,a*x+p*M+g*k,a*m+p*U+g*D,a*d+p*T+g*P]}var Ke=[0,0,0,1,0,0,0,1,0,0,0,1];var yt=new WeakMap,yn=/^(s|8|48)\\//;function Ze(e,t){let n=e.files.get(Y(t));if(!n)return"part";let r=yt.get(n);if(r)return r;if(n.org)r=Ct.has(n.org)?"part":"model";else if(n.name===e.main)r="model";else r=n.cmds.some((s)=>s.t>=2||s.t===0&&!!s.geom||s.t===1&&yn.test(s.file))?"part":"model";return yt.set(n,r),r}var xt=new WeakMap;function kt(e){let t=xt.get(e);if(t)return t;t=[];let n=0;for(let r of e.cmds){if(r.t===0&&r.step){n++;continue}if((r.t>=2||r.t===0&&r.geom&&r.geom.t>=2)&&t[t.length-1]!==n)t.push(n)}return xt.set(e,t),t}var wt=(e)=>e>16777215?"0x"+e.toString(16).toUpperCase():e<0?Ge.get(e)??String(e):String(e),xn=(e)=>e.t===0?"0 "+e.text:e.t===1?`1 ${wt(e.color)} ${e.m.join(" ")} ${e.file}`:e.src?e.src:`${e.t} ${wt(e.color)} ${e.p.join(" ")}`,Ye=(e,t)=>`${Y(e)}#${t}`;function wn(e,t){let n=[],r=0,s=(o)=>!!o&&o.t===0&&o.texmap?.op==="NEXT";for(let o of e.cmds){if(o.t===0){if(o.step){r++;continue}if(o.bfc!==void 0||o.meta==="!COLOUR"){n.push(o);continue}if(r!==t)continue;if(o.texmap)n.push(o);else if(o.geom){if(o.geom.t>=2)n.push(o);else if(s(n[n.length-1]))n.pop()}continue}if(r!==t)continue;if(o.t===1){if(s(n[n.length-1]))n.pop();continue}n.push(o)}return{name:Ye(e.name,t),cmds:n}}function Et(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...wn(e,t).cmds.map(xn)].join(`\n`)+`\n`}function Je(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,"0")}function Pt(e){let[t,n,r,s,o,i,c,u,f,l,a,p]=e,g=u*p-f*a,b=-(c*p-f*l),y=c*a-u*l,w=s*g+o*b+i*y;if(!Number.isFinite(w)||Math.abs(w)<0.000000000001)return null;let x=1/w,m=[g*x,-(o*p-i*a)*x,(o*f-i*u)*x,b*x,(s*p-i*l)*x,-(s*f-i*c)*x,y*x,-(s*a-o*l)*x,(s*u-o*c)*x];return[-(m[0]*t+m[1]*n+m[2]*r),-(m[3]*t+m[4]*n+m[5]*r),-(m[6]*t+m[7]*n+m[8]*r),...m]}var Mn=(e)=>String(+e.toFixed(6)||0),Mt=(e)=>\'"\'+e.replace(/\\\\/g,"\\\\\\\\").replace(/"/g,"\\\\\\"")+\'"\';function Ft(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!=="PLANAR"?[t.a??360]:[],...t.method==="SPHERICAL"?[t.b??180]:[]].map(Mn).join(" "),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${Mt(t.texture)}${t.glossmap?" GLOSSMAP "+Mt(t.glossmap):""}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${Y(e)}\n0 !TEXMAP END\n`;return{name:`${Y(e)}#tex-${Je(r)}`,source:r}}var An=(e,t)=>{let n=[,,,,,,,,,];for(let r=0;r<3;r++)for(let s=0;s<3;s++)n[r*3+s]=e[r*3]*t[s]+e[r*3+1]*t[3+s]+e[r*3+2]*t[6+s];return n};function vn(e,t,n){let r=Math.PI/180,s=Math.sin(e*r),o=Math.cos(e*r),i=Math.sin(t*r),c=Math.cos(t*r),u=Math.sin(n*r),f=Math.cos(n*r);return[c*f,-c*u,i,o*u+s*i*f,o*f-s*i*u,-s*c,s*u-o*i*f,s*f+o*i*u,o*c]}var At=new WeakMap;function It(e){let t=At.get(e);if(t)return t;let n=[],r=null;for(let s of e.cmds){if(s.t!==0||!s.step)continue;let o=s.rotstep;if(o)if(o.mode==="END")r=null;else{let i=vn(o.x,o.y,o.z);r=o.mode==="ABS"?{abs:!0,m:i,rotstep:o}:o.mode==="ADD"&&r?{abs:r.abs,m:An(r.m,i),rotstep:o}:{abs:!1,m:i,rotstep:o}}n.push(r)}return n.push(r),At.set(e,n),n}class Qe extends Error{limit;code="ldr-model-limit";constructor(e,t){super(`ldr: ${e} expands past ${t.toLocaleString("en-US")} (see maxInstances)`);this.limit=t;this.name="ModelLimitError"}}var Cn=(e)=>{for(let t=0;t<12;t++)if(!(Math.abs(e[t])<=vt))return!1;return!0},Rt=999999,Nt=(e)=>e.map((t)=>String(t).padStart(6,"0")).join(".")+"~",Ut=new WeakMap,Bt=new WeakMap;function Tn(e,t){let n=Bt.get(t);if(!n)n={head:[...t.values()].map((o)=>{let i=Ut.get(o)??"",c=i.indexOf("!COLOUR");return c<0?"":"0 "+i.slice(c).trim().replace(/\\s+/g," ")}).filter(Boolean).join(`\n`),parts:new Map},Bt.set(t,n);let r=n.parts.get(e);if(!r){let s=Y(e),o=`0 ldr: ${s} placed in a model\'s !COLOUR scope\n0 BFC CERTIFY CCW\n${n.head}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${s}\n`;r={name:`${s}#col-${Je(o)}`,source:o},n.parts.set(e,r)}return r}function Ln(e,t={}){let n=[],r=t.maxDepth??64,s=t.looseGeometry!==!1,o=!!t.textures,i=!!t.callouts,c=new Map,u=0,f=new Set,l=t.maxInstances??2000000,a=0,p=(b,y)=>{let w=b.name+"#"+y,x=c.get(w);if(!x){let m;x=Object.assign(()=>m??=Et(b,y),{file:b,step:y}),c.set(w,x)}return x},g=(b,y,w,x,m,d,M,U,T=null,k=[],D=[],P=void 0,A=null)=>{let v=b.files.get(y);if(!v||M>r||f.has(v))return;if(++a>l)throw new Qe("model",l);f.add(v);let E=A,z=0,S=M>0?++u:0,I=i&&S?[...k,S]:k,X=i&&S?[...D,w]:D,re=i&&!T?new Map:null,ee=-1,ce=0,fe=(V,h,F,L,B,C,R)=>{if(ee!==z)ee=z,ce=0;let O=re?.get(z+"|"+h);if(O)return O.n++,g(V,V===b?h:V.main,F,L,m+"/"+h,[...B,Rt],M+1,C,[...B,Rt],I,X,R,E);let _=[...B,ce++],N=n.length;g(V,V===b?h:V.main,F,L,m+"/"+h,_,M+1,C,T,I,X,R,E),re?.set(z+"|"+h,{n:1,from:N,to:n.length})},ge=It(v),se=s?kt(v):[],ue=0,pe=(V,h,F,L,B,C,R,O,_)=>{if(T)L=T;if(++a>l)throw new Qe("model",l);let N={part:V,color:h,m:F,step:L[0],steps:L,localStep:B,path:m};if(O)N.colour=O;if(S){if(N.sub=S,i)N.subPath=I,N.subMats=X}if(C)N.embedded=!0;if(R){let H=Ft(V,R);N.texPart=H.name,N.texSource=H.source}else if(_){let H=Tn(V,_);N.colPart=H.name,N.colSource=H.source}let j=ge[B];if(j)N.view=j;return n.push(N),N},me=(V)=>{while(ue<se.length&&se[ue]<=V){let h=se[ue++];pe(Ye(v.name,h),x,w,[...d,h],h,!1,null,P,A).source=p(v,h)}};for(let V of v.cmds){if(V.t===0&&V.step){z++;continue}let h=V;if(h.t>=2||h.t===0&&h.geom&&h.geom.t>=2){me(z);continue}if(h.t===0){if(h.meta==="!COLOUR"){let j=kn(h.text);if(j&&j.code!==16&&j.code!==24)Ut.set(j,h.text),(E=new Map(E??[])).set(j.code,j);continue}if(o&&h.geom?.t===1)h=h.geom;else continue}if(h.t!==1)continue;if(o&&h.fallback)continue;let F=St(w,h.m);if(!Cn(F))continue;let L=h.color===16?x:h.color,B=h.color===16?P:E?.get(h.color),C=[...d,z],R=o?h.tex??U:null,O=R?Pt(h.m):null,_=R&&O?Lt(R,O):null;if(b.files.has(h.file)){if(Ze(b,h.file)==="model"){fe(b,h.file,F,L,C,_,B);continue}pe(h.file,L,F,C,z,!0,_,B,E);continue}let N=t.resolveModel?.(h.file);if(N){fe(N,h.file,F,L,C,_,B);continue}pe(h.file,L,F,C,z,!1,_,B,E)}if(me(1/0),f.delete(v),re){for(let V of re.values())if(V.n>1)for(let h=V.from;h<V.to;h++)n[h].mult??=V.n}};if(Ze(e,e.main)==="part"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...Ke],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return g(e,e.main,Ke,16,e.main,[],0,null),n}function Ot(e,t="main.ldr",n){return Ln(Tt(e,t,{geometryText:!0}),n)}var Sn=new Set(["CHROME","PEARLESCENT","RUBBER","MATTE_METALLIC","METAL","MATERIAL"]);function qe(e){if(!e)return null;if(e.startsWith("#")&&/^#[0-9A-Fa-f]{6}$/.test(e))return e.toUpperCase();if(/^0x[0-9A-Fa-f]{6}$/i.test(e))return("#"+e.slice(2)).toUpperCase();return null}function Dt(e,t){let n={value:"#FFFFFF",fraction:0.5};while(t<e.length){let r=e[t].toUpperCase(),s=e[t+1];if(r==="VALUE"){let o=qe(s);if(o)n.value=o;t+=2}else if(r==="ALPHA")n.alpha=+s,t+=2;else if(r==="LUMINANCE")n.luminance=+s,t+=2;else if(r==="FRACTION")n.fraction=+s,t+=2;else if(r==="VFRACTION")n.vfraction=+s,t+=2;else if(r==="SIZE")n.size=+s,t+=2;else if(r==="MINSIZE")n.minsize=+s,t+=2;else if(r==="MAXSIZE")n.maxsize=+s,t+=2;else break}return{grain:n,next:t}}function kn(e){let t=e.indexOf("!COLOUR");if(t<0)return null;let n=e.slice(t+7).trim().split(/\\s+/).filter(Boolean);if(n.length<2)return null;let r=n[0],s=NaN,o="#FF00FF",i="#333333",c=255,u=0,f={type:"default"},l=1;while(l<n.length){let a=n[l].toUpperCase(),p=n[l+1];if(a==="CODE")s=p!==void 0&&He.test(p)?We(p):p!==void 0&&/^\\d+$/.test(p)?+p:NaN,l+=2;else if(a==="VALUE"){let g=qe(p);if(g)o=g;l+=2}else if(a==="EDGE")i=qe(p)??p,l+=2;else if(a==="ALPHA")c=+p,l+=2;else if(a==="LUMINANCE")u=+p,l+=2;else if(a==="CHROME")f={type:"chrome"},l+=1;else if(a==="PEARLESCENT")f={type:"pearlescent"},l+=1;else if(a==="RUBBER")f={type:"rubber"},l+=1;else if(a==="MATTE_METALLIC")f={type:"matte_metallic"},l+=1;else if(a==="METAL")f={type:"metal"},l+=1;else if(a==="MATERIAL"){let g=(n[l+1]||"").toUpperCase();if(g==="GLITTER"){let{grain:b,next:y}=Dt(n,l+2);f={type:"glitter",material:b},l=y}else if(g==="SPECKLE"){let{grain:b,next:y}=Dt(n,l+2);f={type:"speckle",material:b},l=y}else if(g==="FABRIC"){let b=(n[l+2]||"").toUpperCase(),y=["VELVET","CANVAS","STRING","FUR"].includes(b)?b.toLowerCase():void 0;f={type:"fabric",kind:y},l+=y?3:2}else l=n.length}else if(Sn.has(a))l+=1;else l+=1}if(Number.isNaN(s)||!o)return null;return{code:s,name:r,hex:o,edge:i,alpha:Number.isFinite(c)?c:255,luminance:Number.isFinite(u)?u:0,finish:f}}function En(e){let t=Math.max(0,Math.min(1,(e.alpha??255)/255)),n=t<1,r=Math.max(0,Math.min(1,(e.luminance??0)/255)),s={opacity:t,transparent:n,depthWrite:!n,emissive:r,clearcoat:0,clearcoatRoughness:0,sheen:0,sheenRoughness:0};switch(e.finish?.type??"default"){case"chrome":return{...s,metalness:1,roughness:0,finish:"chrome"};case"pearlescent":return{...s,metalness:0.25,roughness:0.3,clearcoat:0.5,clearcoatRoughness:0.25,sheen:0.4,sheenRoughness:0.35,finish:"pearlescent"};case"rubber":return{...s,metalness:0,roughness:0.9,finish:"rubber"};case"matte_metallic":return{...s,metalness:0.4,roughness:0.8,finish:"matte_metallic"};case"metal":return{...s,metalness:0.85,roughness:0.2,finish:"metal"};case"glitter":{let i=e.finish.material,c=i.size??(i.minsize!=null&&i.maxsize!=null?(i.minsize+i.maxsize)/2:1);return{...s,metalness:0.35,roughness:0.25,clearcoat:1,clearcoatRoughness:0.08,particleHex:i.value,particleFraction:i.fraction,particleSize:c,finish:"glitter"}}case"speckle":{let i=e.finish.material,c=i.size??(i.minsize!=null&&i.maxsize!=null?(i.minsize+i.maxsize)/2:1);return{...s,metalness:0.2,roughness:0.55,particleHex:i.value,particleFraction:i.fraction,particleSize:c,finish:"speckle"}}case"fabric":return{...s,metalness:0,roughness:0.85,sheen:0.65,sheenRoughness:0.75,finish:"fabric"};default:return{...s,metalness:0,roughness:0.45,finish:"default"}}}function et(e){let t=En(e),n=!t.transparent?"op":t.opacity>=0.75?"a200":t.opacity>=0.4?"a128":`a${Math.round(t.opacity*255)}`,r=t.emissive>0?`L${Math.round(t.emissive*16)}`:"",s=`${t.finish}:${n}${r}`;if(t.particleHex)s+=`:${t.particleHex}:${(t.particleFraction??0).toFixed(2)}`;return s}function Pn(e,t){let n=new Map,r=null,s=!1,o=!1;for(let i of e.split(/\\r?\\n/)){let c=/^\\s*0\\s+FILE\\s+(\\S[^\\r]*)/i.exec(i);if(c){if(!s)n.clear();s=!0,o=!1,r=[],n.set(Y(c[1]),r);continue}if(/^\\s*0\\s+(NOFILE|!DATA)(\\s|$)/i.test(i)){if(!s&&/!DATA/i.test(i))n.clear(),s=!0;r=null,o=!0;continue}if(!r){if(s||o)continue;r=[],n.set(Y(t),r)}let u=i.trim().replace(/\\s+/g," ");if(u)r.push(u)}return n}var Fn=(e)=>{if(!e.startsWith("1 "))return null;let t=e.split(" ");return t.length>=15?Y(t.slice(14).join(" ")):null};function In(e){let t=2166136261,n=1523705862;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);t=Math.imul(t^s,16777619),n=Math.imul(n^s,16777629)^n>>>15}return(t>>>0).toString(16).padStart(8,"0")+(n>>>0).toString(16).padStart(8,"0")}function zt(e,t,n="main.ldr"){let r=Pn(e,n),s=new Map;for(let o of t){let i=Y(o);if(!r.has(i)||s.has(i))continue;let c=new Set([i]),u=[i];while(u.length)for(let l of r.get(u.pop())){let a=Fn(l);if(a&&r.has(a)&&!c.has(a))c.add(a),u.push(a)}let f=[i,...[...c].filter((l)=>l!==i).sort()].map((l)=>"0 FILE "+(l===i?"":l)+`\n`+r.get(l).join(`\n`)).join(`\n`);s.set(i,`emb/${In(f)}.dat`)}return s}var $t=(e,t=0)=>Math.abs(e[t+7]-1)<0.001&&Math.abs(e[t+4])<0.001&&Math.abs(e[t+10])<0.001,jt=new WeakMap,tt=null,nt="",rt=null;function st(e,t){if(e===tt&&t===nt)return rt;let n=jt.get(e);if(!n)jt.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return tt=e,nt=t,rt=r,r;let s=e.parts[t];if(!s)return n.set(t,null),null;let o=s.studs.length,i=new Float64Array(o*12),c=[],u=[];s.studs.forEach((g,b)=>{c.push(g[0]),u.push(g[1]);for(let y=0;y<12;y++)i[b*12+y]=g[2+y]});let f=null,l=0,a=0;if(s.mask){l=s.mask[0],a=s.mask[1];let g=s.mask[2];f=new Uint8Array(g.length);for(let b=0;b<g.length;b++)f[b]=g.charCodeAt(b)===49?1:0}let p=!!f;if(f){for(let g=0;g<f.length;g++)if(f[g]!==1){p=!1;break}}return n.set(t,r={nStuds:o,studM:i,kind:c,color:u,mask:f,nx:l,nz:a,full:p}),tt=e,nt=t,rt=r,r}var ye=1073741824;class de{t;tag;mask;size=0;shift;constructor(e=1024,t=-1){let n=1024;while(n<e*2)n*=2;this.t=new Int32Array(n*4),this.tag=new Uint8Array(n),this.mask=n-1,this.shift=t}slot(e,t,n){let r=this.shift;if(r<0){let o=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return o^=o>>>15,o=Math.imul(o,739982445),o^=o>>>12,o&this.mask}let s=Math.imul(e>>r+2,2654435761)^Math.imul(t,2246822507)^Math.imul(n>>r+2,3266489909);return s^=s>>>15,s=Math.imul(s,739982445),s^=s>>>12,(s<<4|(e>>r&3)<<2|n>>r&3)&this.mask}static tagOf(e,t,n){return Math.imul(e^Math.imul(t,374761393)^Math.imul(n,668265261),2654435761)>>>24|1}get(e,t,n){let r=de.tagOf(e,t,n),s=this.tag,o=this.t,i=this.mask,c=this.slot(e,t,n);for(;;){let u=s[c];if(u===0)return-1;if(u===r){let f=c<<2;if(o[f]===e&&o[f+1]===t&&o[f+2]===n)return o[f+3]}c=c+1&i}}put(e,t,n,r){if((this.size+1)*2>this.tag.length)this.grow();let s=de.tagOf(e,t,n),o=this.tag,i=this.t,c=this.mask,u=this.slot(e,t,n);for(;;){let f=o[u],l=u<<2;if(f===0)return o[u]=s,i[l]=e,i[l+1]=t,i[l+2]=n,i[l+3]=r,this.size++,-1;if(f===s&&i[l]===e&&i[l+1]===t&&i[l+2]===n){let a=i[l+3];return i[l+3]=r,a}u=u+1&c}}grow(){let e=this.t,t=this.tag,n=t.length*2;this.t=new Int32Array(n*4),this.tag=new Uint8Array(n),this.mask=n-1,this.size=0;for(let r=0;r<t.length;r++)if(t[r]){let s=r<<2;this.put(e[s],e[s+1],e[s+2],e[s+3])}}}class Vt{grp=new de(64);gBits=[];gX0=[];gZ0=[];gNz=[];gNx=[];bits;rest;lk=NaN;lpx=NaN;lpz=NaN;lg=-1;group(e,t,n){if(e!==this.lk||t!==this.lpx||n!==this.lpz)this.lk=e,this.lpx=t,this.lpz=n,this.lg=this.grp.get(e,t,n);return this.lg}constructor(e,t,n,r){let s=[],o=[],i=[],c=[],u=[];for(let a=0;a<r;a++){let p=e[a],g=t[a],b=n[a],y=(p%20+20)%20,w=(b%20+20)%20,x=this.group(g,y,w);if(x<0)x=s.length,this.grp.put(g,y,w,x),this.lg=x,s.push(0),o.push(p),i.push(p),c.push(b),u.push(b);if(s[x]++,p<o[x])o[x]=p;else if(p>i[x])i[x]=p;if(b<c[x])c[x]=b;else if(b>u[x])u[x]=b}let f=0,l=0;for(let a=0;a<s.length;a++){let p=(i[a]-o[a])/20+1,g=(u[a]-c[a])/20+1,b=p*g;if(this.gX0.push(o[a]),this.gZ0.push(c[a]),this.gNx.push(p),this.gNz.push(g),b<=64*s[a]+1024&&f+b<2147483648)this.gBits.push(f),f+=b;else this.gBits.push(-1),l+=s[a]}this.bits=new Uint8Array(Math.ceil(f/8)),this.rest=new de(l);for(let a=0;a<r;a++){let p=e[a],g=t[a],b=n[a],y=this.group(g,(p%20+20)%20,(b%20+20)%20),w=this.gBits[y];if(w<0){this.rest.put(p,g,b,1);continue}let x=w+(p-this.gX0[y])/20*this.gNz[y]+(b-this.gZ0[y])/20;this.bits[x>>>3]|=1<<(x&7)}}has(e,t,n){let r=this.group(t,(e%20+20)%20,(n%20+20)%20);if(r<0)return!1;let s=this.gBits[r];if(s<0)return this.rest.get(e,t,n)>=0;let o=(e-this.gX0[r])/20,i=(n-this.gZ0[r])/20;if(o<0||i<0||o>=this.gNx[r]||i>=this.gNz[r])return!1;let c=s+o*this.gNz[r]+i;return(this.bits[c>>>3]&1<<(c&7))!==0}}var Rn=(e,t,n,r)=>e===0&&r===0&&(t===1||t===-1)&&(n===1||n===-1)||t===0&&n===0&&(e===1||e===-1)&&(r===1||r===-1),xe=(e,t,n)=>e>-ye&&e<ye&&t>-ye&&t<ye&&n>-ye&&n<ye,ve=2147483647;function Bn(e,t){let n=e.colorTable?.[t];if(n)return(n.alpha??255)<255;return t.charCodeAt(0)===35&&/\\/[^:/]*:a\\d/.test(t)}function Dn(e,t,n){let s=new Map,o=(h)=>{let F=s.get(h);if(F===void 0)s.set(h,F=Bn(t,h));return F},i=[],c=[],u=[],f=[],l=[],a=[],p=[],g=[],b=[],y=[],w=[],x=[],m=new de(e.length*2),d=[],M=[];for(let h=0;h<e.length;h++){let F=e[h],L=F.m,B=t.parts[F.part];if(!B||!B.mask||!$t(L)||o(F.color))continue;let C=B.bbox,R=1/0,O=-1/0,_=1/0,N=-1/0;for(let G=0;G<2;G++)for(let W=0;W<2;W++){let J=G?C[3]:C[0],he=W?C[5]:C[2],le=L[0]+L[3]*J+L[5]*he,ne=L[2]+L[9]*J+L[11]*he;if(le<R)R=le;if(le>O)O=le;if(ne<_)_=ne;if(ne>N)N=ne}let j=Math.round((L[1]+C[4])*2),H=st(t,F.part),Q=Math.floor(R/40),ie=Math.floor(O/40),oe=Math.floor(_/40),ae=Math.floor(N/40);if(!((ie-Q+1)*(ae-oe+1)<=65536)||!xe(j,Q,oe)||!xe(j,ie,ae))continue;let q=-1;for(let G=m.get(j,Q,oe),W=0;G>=0&&W<8;G=d[G],W++){let J=M[G];if(i[J]!==R||c[J]!==O||u[J]!==_||f[J]!==N||p[J]!==H)continue;let he=e[l[J]].m,le=!0;for(let ne=0;ne<12;ne++)if(he[ne]!==L[ne]){le=!1;break}if(le){q=J;break}}if(q>=0){let G=n?n[h]:0;if(n&&G<n[l[q]])a[q]=l[q],l[q]=h;else if(a[q]<0||n&&G<n[a[q]])a[q]=h;continue}let te=l.length;i.push(R),c.push(O),u.push(_),f.push(N),l.push(h),a.push(-1),p.push(H),g.push(C[0]),b.push(C[2]),y.push(j),w.push(L[0],L[1],L[2],L[3],L[6],L[9],L[5],L[8],L[11]),x.push(H.full&&C[3]-C[0]<=20*H.nx&&C[5]-C[2]<=20*H.nz&&L[4]===0&&L[6]===0&&L[8]===0&&L[10]===0&&Rn(L[3],L[5],L[9],L[11])?1:0);for(let G=Q;G<=ie;G++)for(let W=oe;W<=ae;W++){if(!xe(j,G,W))continue;let J=M.length;M.push(te),d.push(m.put(j,G,W,J))}}let U=[0,5,-5,5,-5],T=[0,5,5,-5,-5],k=(h,F,L,B)=>{if(!(F-6>=i[h]-0.5&&F+6<=c[h]+0.5&&B-6>=u[h]-0.5&&B+6<=f[h]+0.5))return!1;if(x[h]===1)return!0;let C=h*9,R=p[h],O=g[h],_=b[h],N=F-w[C],j=L-w[C+1],H=B-w[C+2],Q=w[C+3]*N+w[C+4]*j+w[C+5]*H,ie=w[C+6]*N+w[C+7]*j+w[C+8]*H,{nx:oe,nz:ae,mask:q}=R;for(let te=0;te<5;te++){let G=Math.floor((Q+U[te]-O)/20),W=Math.floor((ie+T[te]-_)/20);if(G<0||W<0||G>=oe||W>=ae||q[G*ae+W]!==1)return!1}return!0},D=NaN,P=NaN,A=NaN,v=-1,E=-1,z=(h,F,L,B)=>{let C=Math.round(F*2),R=Math.floor(h/40),O=Math.floor(L/40);if(!xe(C,R,O))return ve;let _=ve;if(!n&&E>=0&&y[E]===C&&(l[E]!==B||a[E]>=0)&&k(E,h,F,L))return 0;if(C!==D||R!==P||O!==A)D=C,P=R,A=O,v=m.get(C,R,O);for(let N=v;N>=0;N=d[N]){let j=M[N],H=l[j];if(H===B&&(H=a[j])<0)continue;if(!k(j,h,F,L))continue;if(!n)return E=j,0;let Q=n[H];if(Q<_)_=Q}return _},S=0;for(let h of e){let F=st(t,h.part);if(F)S+=F.nStuds}let I=new Uint8Array(S),X=new Uint8Array(S),re=0,ee=n?new de(S,4):null,ce=n?null:new Int32Array(S),fe=n?null:new Int32Array(S),ge=n?null:new Int32Array(S),se=0,ue=n?new Int32Array(S).fill(ve):void 0;for(let h=0,F=0;h<e.length;h++){let L=e[h],B=st(t,L.part);if(!B)continue;let C=L.m,R=B.studM,O=C[0],_=C[1],N=C[2],j=C[3],H=C[4],Q=C[5],ie=C[6],oe=C[7],ae=C[8],q=C[9],te=C[10],G=C[11];for(let W=0;W<B.nStuds;W++,F++){let J=W*12,he=R[J+4],le=R[J+7],ne=R[J+10];if(!(Math.abs(ie*he+oe*le+ae*ne-1)<0.001&&Math.abs(j*he+H*le+Q*ne)<0.001&&Math.abs(q*he+te*le+G*ne)<0.001))continue;X[F]=1;let Oe=R[J],ze=R[J+1],$e=R[J+2],ot=O+j*Oe+H*ze+Q*$e,it=_+ie*Oe+oe*ze+ae*$e,at=N+q*Oe+te*ze+G*$e,lt=z(ot,it,at,h);if(lt!==ve){if(I[F]=1,re++,ue)ue[F]=lt}let Ce=Math.round(ot),Te=Math.round(it),Le=Math.round(at);if(!xe(Ce,Te,Le))continue;if(!ee){ce[se]=Ce,fe[se]=Te,ge[se++]=Le;continue}let ct=n[h],ut=ee.get(Ce,Te,Le);if(ut<0||ct<ut)ee.put(Ce,Te,Le,ct)}}let pe=ee?null:new Vt(ce,fe,ge,se),me=new Uint8Array(e.length),V=n?new Int32Array(e.length).fill(ve):void 0;for(let h=0;h<e.length;h++){let F=e[h],L=t.parts[F.part];if(!L||!L.under||!$t(F.m)||o(F.color))continue;let B=L.bbox,C=Math.round((B[3]-B[0])/20),R=Math.round((B[5]-B[2])/20);if(!C||!R||C*R>4096)continue;let O=F.m,_=Math.round(O[1]+B[4]),N=!0,j=0;for(let H=0;H<C&&N;H++)for(let Q=0;Q<R;Q++){let ie=B[0]+10+20*H,oe=B[2]+10+20*Q,ae=O[0]+O[3]*ie+O[5]*oe,q=O[2]+O[9]*ie+O[11]*oe,te=Math.round(ae),G=Math.round(q),W=!xe(te,_,G)?-1:ee?ee.get(te,_,G):pe.has(te,_,G)?1:-1;if(W<0){N=!1;break}if(W>j)j=W}if(N){if(me[h]=1,V)V[h]=j}}return{nStuds:S,studHidden:I,studUp:X,underHidden:me,studsHidden:re,studHideStep:ue,underHideStep:V}}function Nn(e,t,n){let r=(a)=>a.colPart&&t.parts[a.colPart]?a.colPart:n&&a.texPart&&t.parts[a.texPart]?a.texPart:a.part,s=new Map,o=new Map,i=(a)=>{let p=a.colour;if(!p)return String(a.color);let g=o.get(p);if(g!==void 0)return g;let b=t.colorTable?.[a.color],y=b?.hex??t.colors?.[a.color],w=b?et({alpha:b.alpha??255,luminance:b.luminance??0,finish:b.finish??{type:"default"}}):"default:op",x=et(p);if(g=y&&y.toUpperCase()===p.hex.toUpperCase()&&w===x?String(a.color):p.hex.toUpperCase()+"/"+x,g!==String(a.color))s.set(g,p);return o.set(p,g),g},c=e.map((a)=>({part:r(a),color:i(a),m:a.m,steps:a.steps})),u=c.map((a)=>Nt(a.steps)),f=[...new Set(u)].sort(),l=new Map(f.map((a,p)=>[a,p]));return{all:c,stepOf:u.map((a)=>l.get(a)),nSteps:f.length,localColours:s}}function Fe(e,t,n=!0){let r=Nn(e,t,n);return Dn(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Ne="https://ldr-demo.vercel.app/cdn/v1/",Re=new Map,Ie=new Map;function Be(e=Ne,t=fetch){let n=Re.get(e);if(!n)n=t(e+"parts.json").then((r)=>{if(!r.ok)throw Error(`ldr: parts CDN index ${r.status} (${e}parts.json)`);return r.json()}),n.catch(()=>Re.delete(e)),Re.set(e,n);return n}var Un=(e)=>Array.isArray(e)&&e.length===3&&typeof e[0]==="number"&&typeof e[1]==="number"&&(e[2]==="f32"||e[2]==="u16"||e[2]==="u8"||e[2]==="u32"),De=(e,t)=>Un(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>De(n,t)):e&&typeof e==="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,De(r,t)])):e;function On(e,t={}){let n=[],r=0,s={},o={};for(let p of e){let g=p.buffer;if(!g)throw Error("ldr: mergePacks needs packs from decodePack/loadPack");let b=new DataView(g).getUint32(0,!0),y=new Uint8Array(g,4+b),w=r;n.push(y),r+=y.byteLength;let x=(4-r%4)%4;if(x)n.push(new Uint8Array(x)),r+=x;for(let[m,d]of Object.entries(p.header.parts??{}))if(!(m in s))s[m]=De(d,w);for(let[m,d]of Object.entries(p.header.studKinds??{}))if(!(m in o))o[m]=De(d,w)}let i=e[0]?.header??{version:1,weld:!0},c=new TextEncoder().encode(JSON.stringify({...i,parts:s,studKinds:o,...t})),u=(4-(4+c.length)%4)%4,f=4+c.length+u,l=new Uint8Array(f+r);new DataView(l.buffer).setUint32(0,c.length+u,!0),l.set(c,4),l.fill(32,4+c.length,f);let a=f;for(let p of n)l.set(p,a),a+=p.byteLength;return Pe(l.buffer)}async function zn(e,t={}){e=[...e];try{return await _t(e,t)}catch(n){let r=t.cdn??Ne,s=t.fetch??fetch;Re.delete(r);let o=(i,c)=>s(i,{...c,cache:"reload"});try{return await _t(e,{...t,fetch:o})}catch{throw n}}}async function _t(e,t){let n=t.cdn??Ne,r=t.fetch??fetch,s=t.gap??16384,o=await Be(n,r),i=[...new Set([...e].map(Y))],c=[],u=[];for(let m of i){if(Ie.has(n+m))continue;let d=o.parts[m];if(d)u.push({name:m,off:d[0],len:d[1],file:d[2]??0});else c.push(m)}u.sort((m,d)=>m.file-d.file||m.off-d.off);let f=[];for(let m of u){let d=f[f.length-1];if(d&&d.file===m.file&&m.off-d.end<=s)d.end=Math.max(d.end,m.off+m.len),d.items.push(m);else f.push({file:m.file,start:m.off,end:m.off+m.len,items:[m]})}let l=0,a=0,p=0,g=new Map,b=async()=>{while(p<f.length){let m=f[p++],d=g.get(m.file);if(d)d=d.subarray(m.start,m.end);else{let M=await r(new URL(o.archives[m.file],n).href,{headers:{Range:`bytes=${m.start}-${m.end-1}`,"Accept-Encoding":"identity"}});if(!M.ok)throw Error(`ldr: parts CDN ${M.status}`);if(a++,d=new Uint8Array(await M.arrayBuffer()),l+=d.byteLength,M.status===200)g.set(m.file,d),d=d.subarray(m.start,m.end)}for(let M of m.items){let U=Ee(d.subarray(M.off-m.start,M.off-m.start+M.len)),T=U.buffer.slice(U.byteOffset,U.byteOffset+U.byteLength);Ie.set(n+M.name,Pe(T))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,f.length)},b));let y=i.filter((m)=>Ie.has(n+m)).map((m)=>Ie.get(n+m)),w={colors:o.colors,...o.colorTable?{colorTable:o.colorTable}:{}};return{pack:y.length?On(y,w):Pe($n(w)),missing:c,requests:a,bytes:l}}function $n(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},...e})),n=(4-(4+t.length)%4)%4,r=new Uint8Array(4+t.length+n).fill(32);return new DataView(r.buffer).setUint32(0,t.length+n,!0),r.set(t,4),r.buffer}function jn(e,t){let n=t.header.parts;if(!n)return 0;let r=0;for(let s of e){let o=n[s.part]?.body?.tris;if(o)r+=o}return r}function Gt(e,t,n){let r=0,s=0,o=!1,i=new Set;for(let c of e){let u=c.embedded?t.get(c.part):Y(c.part),f=u?n.parts[u]:void 0;if(!f)continue;if(f[3]!=null)o=!0,r+=f[3];if(!i.has(u))i.add(u),s+=f[1]}return{bodyTris:r,packBytes:s,known:o}}class Ue extends Error{code="ldr-budget";bodyTris;packBytes;maxBodyTris;maxPackBytes;constructor(e){let t=[e.maxBodyTris!=null&&e.bodyTris>e.maxBodyTris?`${e.bodyTris} triangles (limit ${e.maxBodyTris})`:"",e.maxPackBytes!=null&&e.packBytes>e.maxPackBytes?`${(e.packBytes/1e6).toFixed(1)} MB parts pack (limit ${(e.maxPackBytes/1e6).toFixed(0)} MB)`:""].filter(Boolean).join(", ");super(`ldr: model exceeds device budget: ${t}`);this.name="BudgetError",this.bodyTris=e.bodyTris,this.packBytes=e.packBytes,this.maxBodyTris=e.maxBodyTris,this.maxPackBytes=e.maxPackBytes}}async function Ht(e,t={}){let n=performance.now(),r=t.fetch??fetch,s=Be(t.cdn??Ne,r);s.catch(()=>{});let o=t.text?e:await r(e).then(async(A)=>{if(!A.ok)throw Error(`ldr: ${A.status} fetching ${e}`);return mt(await A.arrayBuffer())}),i=performance.now(),c=t.name??(t.text?"main.ldr":ht(e)),u=Ot(o,c,{looseGeometry:!1,callouts:t.callouts}),f=performance.now();t.onParsed?.(u),await s;let l=zt(o,new Set(u.filter((A)=>A.embedded).map((A)=>A.part)),c),a=(A,v)=>t.maxBodyTris!=null&&A>t.maxBodyTris||t.maxPackBytes!=null&&v>t.maxPackBytes,p=t.maxBodyTris!=null||t.maxPackBytes!=null,g=(A)=>new Ue({...A,maxBodyTris:t.maxBodyTris,maxPackBytes:t.maxPackBytes}),b="full";if(p){let A=Gt(u,l,await s);if(a(A.known?A.bodyTris:0,A.packBytes)){if(!t.lowCdn)throw g(A);let v=await Be(t.lowCdn,r).catch(()=>null);if(!v)throw g(A);let E=Gt(u,l,v);if(a(E.known?E.bodyTris:0,E.packBytes))throw g(E);b="low"}}let y=[...u.filter((A)=>!A.embedded).map((A)=>A.part),...l.values()],w=async()=>{let A=await zn(y,b==="low"?{...t,cdn:t.lowCdn}:t);for(let[v,E]of l){let z=A.pack.header.parts[E];if(z)A.pack.header.parts[v]=z}return{...A,packBytes:A.pack.buffer?.byteLength??A.pack.bytes??0,bodyTris:jn(u,A.pack)}},x=await w();if(p&&a(x.bodyTris,x.packBytes)&&b==="full"&&t.lowCdn&&await Be(t.lowCdn,r).then(()=>!0,()=>!1)){b="low";let A=x;x=await w(),x.requests+=A.requests,x.bytes+=A.bytes}if(p&&a(x.bodyTris,x.packBytes))throw g(x);let{pack:m,missing:d,requests:M,bytes:U}=x,T=new Map([...l].map(([A,v])=>[v,A])),k=d.map((A)=>T.get(A)??A),D=performance.now(),P=t.cull?Fe(u,m.header,t.textures!==!1):void 0;return{insts:u,pack:m,tier:b,missing:k,requests:M,bytes:U,cull:P,timings:{fetchModel:i-n,parse:f-i,parts:D-f,...P?{cull:performance.now()-D}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let s=await Ht(n,{...r,cull:!1,onParsed:(l)=>self.postMessage({id:t,insts:l})}),o=s.pack.buffer;if(self.postMessage({id:t,buffer:o,tier:s.tier,missing:s.missing,requests:s.requests,bytes:s.bytes,timings:s.timings},[o]),!r.cull)return;let i=performance.now(),c=Fe(s.insts,s.pack.header,r.textures!==!1),u=performance.now()-i,f=[];for(let l of[c.studHidden,c.studUp,c.underHidden,c.studHideStep,c.underHideStep])if(l)f.push(l.buffer);self.postMessage({id:t,cull:c,ms:u},f)}catch(s){if(s instanceof Ue||s?.code==="ldr-budget")self.postMessage({id:t,phase:"error",error:String(s?.message??s),budget:{bodyTris:s.bodyTris,packBytes:s.packBytes,maxBodyTris:s.maxBodyTris,maxPackBytes:s.maxPackBytes}});else self.postMessage({id:t,phase:"error",error:String(s?.message??s)})}};\n';
|
|
5009
5241
|
|
|
5010
|
-
// ../../../../../../../tmp/ldr-build-
|
|
5242
|
+
// ../../../../../../../tmp/ldr-build-DCpOVo/src/cdn.ts
|
|
5011
5243
|
var worker;
|
|
5012
5244
|
var seq = 0;
|
|
5013
5245
|
var pending = new Map;
|