@margoengine/cad 0.0.0-stage → 1.0.0
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/LICENSE +201 -0
- package/NOTICE +14 -0
- package/README.md +87 -2
- package/dist/cad-NjBidwwm.js +589 -0
- package/dist/cad-async-kUFSo7gb.js +541 -0
- package/dist/cad-async.d.ts +77 -0
- package/dist/cad-async.js +1 -0
- package/dist/cad-parser.d.ts +14 -0
- package/dist/cad-runtime.worker.d.ts +1 -0
- package/dist/cad.d.ts +109 -0
- package/dist/closed-Db7gO_Gy.js +19 -0
- package/dist/closed.d.ts +6 -0
- package/dist/closed.js +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/internal/buffers.d.ts +16 -0
- package/dist/internal/format.d.ts +2 -0
- package/dist/pack.d.ts +72 -0
- package/dist/stage.d.ts +33 -0
- package/dist/stage.js +85 -0
- package/dist/workers/brep-read.d.ts +40 -0
- package/dist/workers/cad-runtime.js +56 -0
- package/package.json +72 -4
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
// @margo/core-built 1.0.0
|
|
2
|
+
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
+
const n=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
|
|
4
|
+
import { Geometry as e, PbrMaterial as t, engineRuntime as __margoRuntime } from "@margoengine/core/extension";
|
|
5
|
+
import { MargoError as r } from "@margoengine/math/errors";
|
|
6
|
+
import { finiteVector as i } from "@margoengine/math/validate";
|
|
7
|
+
//#region ../shared/scene-scope.js
|
|
8
|
+
var a = 0, o = (e, t) => {
|
|
9
|
+
let n = t + a++;
|
|
10
|
+
for (; e.plugins?.has(n);) n += ":";
|
|
11
|
+
return n;
|
|
12
|
+
};
|
|
13
|
+
function s(e) {
|
|
14
|
+
let t;
|
|
15
|
+
if (typeof e?.sceneOf == "function") {
|
|
16
|
+
for (let n of e.plugins?.values() ?? []) if (t = e.sceneOf(n)) break;
|
|
17
|
+
if (!t) {
|
|
18
|
+
let n = {coreRequirement:/*@__PURE__*/__margoCoreRequirement("1.0.0",import.meta.url),
|
|
19
|
+
name: o(e, "scene-scope:"),
|
|
20
|
+
setup() {
|
|
21
|
+
t = e.sceneOf(n);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
e.use(n), e.removePlugin(n.name);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return c(e, t);
|
|
28
|
+
}
|
|
29
|
+
function c(e, t) {
|
|
30
|
+
return {
|
|
31
|
+
scene: t,
|
|
32
|
+
run(n) {
|
|
33
|
+
if (!t) return n();
|
|
34
|
+
let r, i = {coreRequirement:/*@__PURE__*/__margoCoreRequirement("1.0.0",import.meta.url),
|
|
35
|
+
name: o(e, "scene-scope:"),
|
|
36
|
+
setup() {
|
|
37
|
+
r = n();
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
return t.use(i), t.removePlugin(i.name), r;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region ../shared/polygon.js
|
|
46
|
+
var l = (e, t, n) => (t[0] - e[0]) * (n[1] - e[1]) - (t[1] - e[1]) * (n[0] - e[0]), u = (e, t, n) => (Math.abs((t[0] - e[0]) * (n[1] - e[1])) + Math.abs((t[1] - e[1]) * (n[0] - e[0]))) * 2 ** -52 * 4, d = (e, t, n) => {
|
|
47
|
+
let r = l(e, t, n);
|
|
48
|
+
return Math.abs(r) <= u(e, t, n) ? 0 : Math.sign(r);
|
|
49
|
+
};
|
|
50
|
+
function f(e) {
|
|
51
|
+
let t = e[0], n = 0, r = 0, i = 0;
|
|
52
|
+
for (let a = 1; a < e.length - 1; a++) {
|
|
53
|
+
let o = l(t, e[a], e[a + 1]) - r, s = n + o;
|
|
54
|
+
r = s - n - o, n = s, i += u(t, e[a], e[a + 1]);
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
area: n / 2,
|
|
58
|
+
error: i / 2 + Math.abs(n) * 2 ** -52
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function p(e) {
|
|
62
|
+
return f(e).area;
|
|
63
|
+
}
|
|
64
|
+
function m(e, t = 1) {
|
|
65
|
+
if (e && (e.used += t, e.used > e.limit)) throw RangeError("Text total work budget exceeded; use less text");
|
|
66
|
+
}
|
|
67
|
+
function h(e, t, n) {
|
|
68
|
+
let r = !1;
|
|
69
|
+
m(n, e.length);
|
|
70
|
+
for (let n = 0, i = e.length - 1; n < e.length; i = n++) {
|
|
71
|
+
let a = e[n], o = e[i];
|
|
72
|
+
a[1] > t[1] != o[1] > t[1] && t[0] < a[0] + (t[1] - a[1]) * (o[0] - a[0]) / (o[1] - a[1]) && (r = !r);
|
|
73
|
+
}
|
|
74
|
+
return r;
|
|
75
|
+
}
|
|
76
|
+
function g(e, t, n, r) {
|
|
77
|
+
let i = [
|
|
78
|
+
d(e, t, n),
|
|
79
|
+
d(e, t, r),
|
|
80
|
+
d(n, r, e),
|
|
81
|
+
d(n, r, t)
|
|
82
|
+
];
|
|
83
|
+
if (i[0] * i[1] < 0 && i[2] * i[3] < 0) return !0;
|
|
84
|
+
let a = (e, t, n) => e[0] >= Math.min(t[0], n[0]) && e[0] <= Math.max(t[0], n[0]) && e[1] >= Math.min(t[1], n[1]) && e[1] <= Math.max(t[1], n[1]);
|
|
85
|
+
return i[0] === 0 && a(n, e, t) || i[1] === 0 && a(r, e, t) || i[2] === 0 && a(e, n, r) || i[3] === 0 && a(t, n, r);
|
|
86
|
+
}
|
|
87
|
+
function _(e, t = [], { allowTouch: n = !1, workCounter: r } = {}) {
|
|
88
|
+
if (!Array.isArray(t) || t.length > 4096) throw TypeError("Invalid polygon holes; pass at most 4096 holes");
|
|
89
|
+
let a = 0, o = [e, ...t].map((e) => {
|
|
90
|
+
if (!Array.isArray(e) || e.length < 3 || (a += e.length) > 4096) throw RangeError("Polygon requires 3-4096 total contour vertices");
|
|
91
|
+
m(r, e.length * 3);
|
|
92
|
+
let t = e.map((e) => (i(e, 2, "Polygon vertex"), Array.from(e)));
|
|
93
|
+
t.at(-1)[0] === t[0][0] && t.at(-1)[1] === t[0][1] && t.pop();
|
|
94
|
+
for (let e = t.length - 1; e >= 0; e--) {
|
|
95
|
+
let n = t[(e + 1) % t.length];
|
|
96
|
+
t[e][0] === n[0] && t[e][1] === n[1] && t.splice(e, 1);
|
|
97
|
+
}
|
|
98
|
+
if (t.length < 3) throw RangeError("Degenerate polygon contour; use 3 or more points");
|
|
99
|
+
return t;
|
|
100
|
+
}), s = o.flatMap((e, t) => e.map((n, r) => ({
|
|
101
|
+
a: n,
|
|
102
|
+
b: e[(r + 1) % e.length],
|
|
103
|
+
ri: t,
|
|
104
|
+
i: r,
|
|
105
|
+
count: e.length
|
|
106
|
+
})));
|
|
107
|
+
for (let e of o) {
|
|
108
|
+
let { area: t, error: n } = f(e);
|
|
109
|
+
if (Math.abs(t) <= n) throw RangeError("Polygon contour has zero area; move the points apart");
|
|
110
|
+
}
|
|
111
|
+
for (let e = 0; e < s.length; e++) for (let t = e + 1; t < s.length; t++) {
|
|
112
|
+
m(r);
|
|
113
|
+
let i = s[e], a = s[t];
|
|
114
|
+
if (i.ri === a.ri && (Math.abs(i.i - a.i) === 1 || Math.abs(i.i - a.i) === i.count - 1)) {
|
|
115
|
+
let e = i.b[0] === a.a[0] && i.b[1] === a.a[1] ? [
|
|
116
|
+
i.a,
|
|
117
|
+
i.b,
|
|
118
|
+
a.b
|
|
119
|
+
] : [
|
|
120
|
+
a.a,
|
|
121
|
+
a.b,
|
|
122
|
+
i.b
|
|
123
|
+
];
|
|
124
|
+
if (d(...e) === 0 && (e[0][0] - e[1][0]) * (e[2][0] - e[1][0]) + (e[0][1] - e[1][1]) * (e[2][1] - e[1][1]) > 0) throw RangeError("Polygon doubles back along an edge; remove repeated points");
|
|
125
|
+
} else if (g(i.a, i.b, a.a, a.b)) {
|
|
126
|
+
let e = [i.a, i.b].some((e) => [a.a, a.b].some((t) => e[0] === t[0] && e[1] === t[1])), t = d(i.a, i.b, a.a) === 0 && d(i.a, i.b, a.b) === 0, r = Math.abs(i.b[0] - i.a[0]) >= Math.abs(i.b[1] - i.a[1]) ? 0 : 1, o = t && Math.min(Math.max(i.a[r], i.b[r]), Math.max(a.a[r], a.b[r])) > Math.max(Math.min(i.a[r], i.b[r]), Math.min(a.a[r], a.b[r]));
|
|
127
|
+
if (!n || !e || o) throw RangeError("Polygon contours cross or touch; move them apart");
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
for (let e = 1; e < o.length; e++) {
|
|
131
|
+
if (!(n ? o[e].some((e) => h(o[0], e, r)) : h(o[0], o[e][0], r))) throw RangeError("Polygon hole lies outside the contour; move it inside");
|
|
132
|
+
for (let t = 1; t < e; t++) if (h(o[t], o[e][0], r) || h(o[e], o[t][0], r)) throw RangeError("Polygon holes overlap or nest; move the holes apart");
|
|
133
|
+
}
|
|
134
|
+
return o.map((e, t) => p(e) > 0 == (t === 0) ? e : e.reverse());
|
|
135
|
+
}
|
|
136
|
+
function v(e, t = [], { maxVertices: n = 1e6, allowTouch: r = !1, workCounter: i } = {}) {
|
|
137
|
+
if (!Number.isSafeInteger(n) || n < 3) throw RangeError("Invalid triangulation vertex budget; pass a positive integer");
|
|
138
|
+
let a = _(e, t, {
|
|
139
|
+
allowTouch: r,
|
|
140
|
+
workCounter: i
|
|
141
|
+
}), o = a.flatMap((e) => e.map((t, n) => [t, e[(n + 1) % e.length]]));
|
|
142
|
+
m(i, o.length * (3 + Math.ceil(Math.log2(Math.max(1, o.length)))));
|
|
143
|
+
let s = [...new Set(a.flat().map((e) => e[0]))].sort((e, t) => e - t), c = [], u = [];
|
|
144
|
+
function h(e, t, r) {
|
|
145
|
+
if (m(i, 3), d(e, t, r) <= 0) return;
|
|
146
|
+
if (c.length / 2 + 3 > n) throw RangeError("Triangulation vertex budget exceeded; simplify the polygon");
|
|
147
|
+
let a = c.length / 2;
|
|
148
|
+
c.push(...e, ...t, ...r), u.push(a, a + 1, a + 2);
|
|
149
|
+
}
|
|
150
|
+
for (let e = 0; e < s.length - 1; e++) {
|
|
151
|
+
let t = s[e], n = s[e + 1];
|
|
152
|
+
m(i, o.length * (2 + Math.ceil(Math.log2(Math.max(1, o.length)))));
|
|
153
|
+
let r = o.filter(([e, r]) => e[0] !== r[0] && Math.min(e[0], r[0]) <= t && Math.max(e[0], r[0]) >= n).map(([e, t]) => ({ y: (n) => n === e[0] ? e[1] : n === t[0] ? t[1] : e[1] + (n - e[0]) * (t[1] - e[1]) / (t[0] - e[0]) })).sort((e, r) => e.y(t) / 2 + e.y(n) / 2 - (r.y(t) / 2 + r.y(n) / 2));
|
|
154
|
+
if (r.length % 2) throw RangeError("Polygon precision prevents triangulation; simplify the polygon");
|
|
155
|
+
for (let e = 0; e < r.length; e += 2) {
|
|
156
|
+
let i = r[e], a = r[e + 1], o = [t, i.y(t)], s = [n, i.y(n)], c = [n, a.y(n)], l = [t, a.y(t)];
|
|
157
|
+
h(o, s, c), h(o, c, l);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
m(i, o.length * 2 + u.length);
|
|
161
|
+
let g = a.reduce((e, t) => e + p(t), 0), v = u.reduce((e, t, n) => n % 3 ? e : e + l(c.slice(u[n] * 2, u[n] * 2 + 2), c.slice(u[n + 1] * 2, u[n + 1] * 2 + 2), c.slice(u[n + 2] * 2, u[n + 2] * 2 + 2)) / 2, 0);
|
|
162
|
+
if (!u.length || Math.abs(v - g) > Math.max(a.reduce((e, t) => e + f(t).error, 0) * o.length * 8, Math.abs(g) * 1e-10)) throw RangeError("Triangulation does not preserve polygon area; simplify the polygon");
|
|
163
|
+
return {
|
|
164
|
+
positions: c,
|
|
165
|
+
indices: u,
|
|
166
|
+
rings: a,
|
|
167
|
+
area: g
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region ../shared/limits.js
|
|
172
|
+
function y(e, t = 1e5) {
|
|
173
|
+
if (!Number.isSafeInteger(t) || t < 1 || t > 8388608) throw RangeError(`${e} must be an integer from 1 to 8388608`);
|
|
174
|
+
return t;
|
|
175
|
+
}
|
|
176
|
+
function b(e, t, n, r) {
|
|
177
|
+
if (t > n) throw RangeError(`${e} (${t} > ${n}; raise the ${r} option)`);
|
|
178
|
+
}
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region ../shared/crc32.js
|
|
181
|
+
var x;
|
|
182
|
+
function S() {
|
|
183
|
+
x = /* @__PURE__ */ new Int32Array(2048);
|
|
184
|
+
for (let e = 0; e < 256; e++) {
|
|
185
|
+
let t = e;
|
|
186
|
+
for (let e = 0; e < 8; e++) t = t & 1 ? 3988292384 ^ t >>> 1 : t >>> 1;
|
|
187
|
+
x[e] = t;
|
|
188
|
+
}
|
|
189
|
+
for (let e = 0; e < 256; e++) for (let t = 1; t < 8; t++) {
|
|
190
|
+
let n = x[(t - 1) * 256 + e];
|
|
191
|
+
x[t * 256 + e] = n >>> 8 ^ x[n & 255];
|
|
192
|
+
}
|
|
193
|
+
return x;
|
|
194
|
+
}
|
|
195
|
+
function C(e, t = 0) {
|
|
196
|
+
let n = x ?? S(), r = e.length, i = r - (r & 7), a = ~t, o = 0;
|
|
197
|
+
for (; o < i; o += 8) a ^= e[o] | e[o + 1] << 8 | e[o + 2] << 16 | e[o + 3] << 24, a = n[1792 + (a & 255)] ^ n[1536 + (a >>> 8 & 255)] ^ n[1280 + (a >>> 16 & 255)] ^ n[1024 + (a >>> 24)] ^ n[768 + e[o + 4]] ^ n[512 + e[o + 5]] ^ n[256 + e[o + 6]] ^ n[e[o + 7]];
|
|
198
|
+
for (; o < r; o++) a = n[(a ^ e[o]) & 255] ^ a >>> 8;
|
|
199
|
+
return ~a >>> 0;
|
|
200
|
+
}
|
|
201
|
+
//#endregion
|
|
202
|
+
//#region src/cad-parser.ts
|
|
203
|
+
var w = 67108864, T = 1e6, E = 3e6;
|
|
204
|
+
function D(e, t) {
|
|
205
|
+
return /* @__PURE__ */ RangeError(`${e}; ${t === "stl" || t === "obj" ? "export it as GLB" : "tessellate it offline with @margoengine/brep, export it as GLB with @margoengine/exporters"} and load it with @margoengine/gltf/pbr`);
|
|
206
|
+
}
|
|
207
|
+
var O = /* @__PURE__ */ new Float32Array(1), k = new Int32Array(O.buffer);
|
|
208
|
+
function A(e) {
|
|
209
|
+
return O[0] = e === 0 ? 0 : e, k[0];
|
|
210
|
+
}
|
|
211
|
+
function j(e, t) {
|
|
212
|
+
let n = 2166136261;
|
|
213
|
+
for (let r = 0; r < 6; r++) n = Math.imul(n ^ e[t + r], 16777619);
|
|
214
|
+
return n ^ n >>> 15;
|
|
215
|
+
}
|
|
216
|
+
function M(e, t, n) {
|
|
217
|
+
let r = !0;
|
|
218
|
+
for (let t = 0; t < e.length && r; t++) r = Number.isFinite(Math.fround(e[t]));
|
|
219
|
+
if (!e.length || e.length / 3 > 3e6 || e.length % 9 || !r) throw RangeError("CAD requires bounded finite triangles");
|
|
220
|
+
let i = e.length / 3, a = Math.min(i, 1000001), o = new Float64Array(a * 3), s = new Float64Array(a * 3), c = new Uint32Array(i), l = new Int32Array((a + 1) * 6), u = (/* @__PURE__ */ new Int32Array(1024)).fill(-1), d = 0;
|
|
221
|
+
for (let t = 0; t < e.length; t += 9) {
|
|
222
|
+
let r = e[t + 3] - e[t], i = e[t + 4] - e[t + 1], a = e[t + 5] - e[t + 2], f = e[t + 6] - e[t], p = e[t + 7] - e[t + 1], m = e[t + 8] - e[t + 2], h = i * m - a * p, g = a * f - r * m, _ = r * p - i * f, v = Math.hypot(h, g, _), y = v ? h / v : 0, b = v ? g / v : 0, x = v ? _ / v : 1, S = Math.round(y * 1e5), C = Math.round(b * 1e5), w = Math.round(x * 1e5);
|
|
223
|
+
for (let n = t; n < t + 9; n += 3) {
|
|
224
|
+
let t = e[n], r = e[n + 1], i = e[n + 2], a = d * 6;
|
|
225
|
+
l[a] = A(t), l[a + 1] = A(r), l[a + 2] = A(i), l[a + 3] = S, l[a + 4] = C, l[a + 5] = w;
|
|
226
|
+
let f = j(l, a) & u.length - 1, p = u[f];
|
|
227
|
+
for (; p !== -1;) {
|
|
228
|
+
let e = p * 6;
|
|
229
|
+
if (l[e] === l[a] && l[e + 1] === l[a + 1] && l[e + 2] === l[a + 2] && l[e + 3] === S && l[e + 4] === C && l[e + 5] === w) break;
|
|
230
|
+
f = f + 1 & u.length - 1, p = u[f];
|
|
231
|
+
}
|
|
232
|
+
if (p === -1) {
|
|
233
|
+
if (p = d++, p >= 1e6) throw D(`CAD unique vertex limit (over ${T} in one part)`, "obj");
|
|
234
|
+
if (u[f] = p, o[p * 3] = t, o[p * 3 + 1] = r, o[p * 3 + 2] = i, s[p * 3] = y, s[p * 3 + 1] = b, s[p * 3 + 2] = x, (p + 1) * 2 > u.length) {
|
|
235
|
+
u = new Int32Array(u.length * 4).fill(-1);
|
|
236
|
+
for (let e = 0; e <= p; e++) {
|
|
237
|
+
let t = j(l, e * 6) & u.length - 1;
|
|
238
|
+
for (; u[t] !== -1;) t = t + 1 & u.length - 1;
|
|
239
|
+
u[t] = e;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
c[n / 3] = p;
|
|
244
|
+
}
|
|
245
|
+
t % 9e4 == 0 && n?.(.5 + .5 * t / e.length);
|
|
246
|
+
}
|
|
247
|
+
return t(o.subarray(0, d * 3), s.subarray(0, d * 3), c);
|
|
248
|
+
}
|
|
249
|
+
function N(e, t) {
|
|
250
|
+
try {
|
|
251
|
+
return new TextDecoder("utf8", { fatal: !0 }).decode(e);
|
|
252
|
+
} catch {
|
|
253
|
+
throw TypeError(`Invalid ${t}: the file is not UTF-8 text; save it as UTF-8 and load it again.`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function P(e, t, n) {
|
|
257
|
+
let r = [];
|
|
258
|
+
if (e instanceof Uint8Array && e.length >= 84) {
|
|
259
|
+
let r = new DataView(e.buffer, e.byteOffset, e.byteLength), i = r.getUint32(80, !0);
|
|
260
|
+
if (84 + i * 50 === e.length) {
|
|
261
|
+
if (i * 3 > 3e6) throw D(`STL triangle limit (${i} > ${E / 3})`, "stl");
|
|
262
|
+
if (!i) throw RangeError("STL contains no triangles; check that the file has at least one facet.");
|
|
263
|
+
let e = new Float32Array(i * 9);
|
|
264
|
+
for (let t = 0; t < i; t++) {
|
|
265
|
+
for (let n = 0, i = 84 + t * 50 + 12; n < 9; n++) e[t * 9 + n] = r.getFloat32(i + n * 4, !0);
|
|
266
|
+
t % 1e4 == 0 && n?.(.5 * t / i);
|
|
267
|
+
}
|
|
268
|
+
return [{
|
|
269
|
+
name: "STL body",
|
|
270
|
+
geometry: M(e, t, n)
|
|
271
|
+
}];
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
let i = typeof e == "string" ? e : N(e, "STL");
|
|
275
|
+
if (!/^\s*solid\b/.test(i) || !/\bendsolid\b/.test(i)) throw TypeError("Invalid STL: text must start with \"solid\" and end with \"endsolid\"; export the file again as binary or ASCII STL.");
|
|
276
|
+
let a = "[-+]?(?:\\d+\\.?\\d*|\\.\\d+)(?:[eE][-+]?\\d+)?", o = RegExp(`vertex\\s+(${a})\\s+(${a})\\s+(${a})`, "g"), s = [], c = /facet\s+normal/g;
|
|
277
|
+
for (let e; e = c.exec(i);) {
|
|
278
|
+
let t = i.indexOf("endfacet", c.lastIndex);
|
|
279
|
+
if (t < 0) break;
|
|
280
|
+
s.push(i.slice(e.index, t + 8)), c.lastIndex = t + 8;
|
|
281
|
+
}
|
|
282
|
+
if (s.length * 3 > 3e6) throw D(`STL triangle limit (${s.length} > ${E / 3})`, "stl");
|
|
283
|
+
if (!s.length) throw RangeError("STL contains no triangles; check that the file has at least one facet.");
|
|
284
|
+
let l = 0;
|
|
285
|
+
for (let e of s) {
|
|
286
|
+
l++ % 1e4 == 0 && n?.(.5 * l / s.length);
|
|
287
|
+
let t = [...e.matchAll(o)];
|
|
288
|
+
if (t.length !== 3 || !/outer\s+loop/.test(e) || !/endloop/.test(e)) throw TypeError("Invalid STL facet: each facet needs an outer loop with three vertex lines; check or export the file again.");
|
|
289
|
+
for (let e of t) r.push(...e.slice(1).map(Number));
|
|
290
|
+
}
|
|
291
|
+
return [{
|
|
292
|
+
name: i.match(/solid\s+([^\r\n]*)/)?.[1] || "STL body",
|
|
293
|
+
geometry: M(r, t, n)
|
|
294
|
+
}];
|
|
295
|
+
}
|
|
296
|
+
function F(e, t, n, r) {
|
|
297
|
+
let i = y("maxParts", r), a = [], o = [{
|
|
298
|
+
name: "OBJ body",
|
|
299
|
+
positions: []
|
|
300
|
+
}], s = {
|
|
301
|
+
used: 0,
|
|
302
|
+
limit: 1e7
|
|
303
|
+
}, c = o[0], l = 0, u = e.split(/\r?\n/), d = 0;
|
|
304
|
+
for (let e of u) {
|
|
305
|
+
d++ % 1e4 == 0 && n?.(.5 * d / u.length);
|
|
306
|
+
let t = e.replace(/#.*/, "").trim();
|
|
307
|
+
if (!t) continue;
|
|
308
|
+
let [r, ...f] = t.split(/\s+/);
|
|
309
|
+
if (r === "v") {
|
|
310
|
+
let e = f.map(Number);
|
|
311
|
+
if (e.length !== 3 || !e.every((e) => Number.isFinite(Math.fround(e)))) throw RangeError("Invalid OBJ vertex: \"v\" needs three finite numbers in float32 range; fix the line or export the file again.");
|
|
312
|
+
if (a.length >= 1e6) throw D(`OBJ vertex limit (over ${T})`, "obj");
|
|
313
|
+
a.push(e);
|
|
314
|
+
} else if (r === "o" || r === "g") b("OBJ part limit", o.length + 1, i, "maxParts"), c = {
|
|
315
|
+
name: f.join(" ") || "OBJ body",
|
|
316
|
+
positions: []
|
|
317
|
+
}, o.push(c);
|
|
318
|
+
else if (r === "f") {
|
|
319
|
+
if (f.length < 3 || f.length > 4096) throw RangeError("OBJ face needs between 3 and 4096 vertices; split larger faces or export the file again.");
|
|
320
|
+
let e = f.map((e) => {
|
|
321
|
+
if (!/^-?\d+(?:\/(?:-?\d*)?(?:\/-?\d+)?)?$/.test(e)) throw TypeError("Invalid OBJ face: each entry must look like v, v/vt, v//vn or v/vt/vn; export the file again.");
|
|
322
|
+
let t = Number(e.split("/")[0]), n = a[t > 0 ? t - 1 : a.length + t];
|
|
323
|
+
if (!t || !n) throw RangeError("OBJ face index is zero or past the vertices read so far; use 1 to the vertex count, or negative relative indices.");
|
|
324
|
+
return n;
|
|
325
|
+
}), t = e[0], n = e[1], r = e[2], i = [
|
|
326
|
+
(n[1] - t[1]) * (r[2] - t[2]) - (n[2] - t[2]) * (r[1] - t[1]),
|
|
327
|
+
(n[2] - t[2]) * (r[0] - t[0]) - (n[0] - t[0]) * (r[2] - t[2]),
|
|
328
|
+
(n[0] - t[0]) * (r[1] - t[1]) - (n[1] - t[1]) * (r[0] - t[0])
|
|
329
|
+
], o = Math.hypot(...i);
|
|
330
|
+
if (!o) throw RangeError("Degenerate OBJ face has no area; remove the face or export the file again.");
|
|
331
|
+
let u = i.map(Math.abs).indexOf(Math.max(...i.map(Math.abs))), d = (u + 1) % 3, p = (u + 2) % 3;
|
|
332
|
+
if (e.some((e) => Math.abs(i.reduce((n, r, i) => n + r * (e[i] - t[i]), 0)) / o > 1e-5)) throw RangeError("Nonplanar OBJ face: its vertices must lie in one plane; split it into triangles.");
|
|
333
|
+
if (e.length < 5) {
|
|
334
|
+
let a = [[
|
|
335
|
+
t,
|
|
336
|
+
n,
|
|
337
|
+
r
|
|
338
|
+
]];
|
|
339
|
+
if (e.length === 4) {
|
|
340
|
+
let o = e[3], s = (e, t, n) => i[0] * ((t[1] - e[1]) * (n[2] - t[2]) - (t[2] - e[2]) * (n[1] - t[1])) + i[1] * ((t[2] - e[2]) * (n[0] - t[0]) - (t[0] - e[0]) * (n[2] - t[2])) + i[2] * ((t[0] - e[0]) * (n[1] - t[1]) - (t[1] - e[1]) * (n[0] - t[0]));
|
|
341
|
+
if ([
|
|
342
|
+
s(o, t, n),
|
|
343
|
+
s(n, r, o),
|
|
344
|
+
s(r, o, t)
|
|
345
|
+
].filter((e) => e < 0).length > 1) throw RangeError("OBJ quad crosses itself; split it into two triangles");
|
|
346
|
+
a[0] = s(r, o, t) < 0 ? [
|
|
347
|
+
t,
|
|
348
|
+
n,
|
|
349
|
+
o
|
|
350
|
+
] : [
|
|
351
|
+
t,
|
|
352
|
+
n,
|
|
353
|
+
r
|
|
354
|
+
], a.push(s(r, o, t) < 0 ? [
|
|
355
|
+
n,
|
|
356
|
+
r,
|
|
357
|
+
o
|
|
358
|
+
] : [
|
|
359
|
+
t,
|
|
360
|
+
r,
|
|
361
|
+
o
|
|
362
|
+
]);
|
|
363
|
+
}
|
|
364
|
+
for (let [e, t, n] of a) {
|
|
365
|
+
let r = t[0] - e[0], i = t[1] - e[1], a = t[2] - e[2], o = n[0] - e[0], s = n[1] - e[1], u = n[2] - e[2];
|
|
366
|
+
if ((i * u - a * s || a * o - r * u || r * s - i * o) && (c.positions.push(...e, ...t, ...n), (l += 3) > 3e6)) throw D(`OBJ triangle limit (over ${E / 3})`, "obj");
|
|
367
|
+
}
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
let m = v(e.map((e) => [e[d], e[p]]), [], {
|
|
371
|
+
maxVertices: T,
|
|
372
|
+
workCounter: s
|
|
373
|
+
});
|
|
374
|
+
for (let e = 0; e < m.indices.length; e += 3) {
|
|
375
|
+
let n = m.indices.slice(e, e + 3);
|
|
376
|
+
i[u] < 0 && n.reverse();
|
|
377
|
+
for (let e of n) {
|
|
378
|
+
let n = [
|
|
379
|
+
0,
|
|
380
|
+
0,
|
|
381
|
+
0
|
|
382
|
+
];
|
|
383
|
+
if (n[d] = m.positions[e * 2], n[p] = m.positions[e * 2 + 1], n[u] = t[u] - (i[d] * (n[d] - t[d]) + i[p] * (n[p] - t[p])) / i[u], c.positions.push(...n), ++l > 3e6) throw D(`OBJ triangle limit (over ${E / 3})`, "obj");
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
} else if (![
|
|
387
|
+
"vn",
|
|
388
|
+
"vt",
|
|
389
|
+
"s",
|
|
390
|
+
"usemtl",
|
|
391
|
+
"mtllib"
|
|
392
|
+
].includes(r)) throw TypeError(`Unsupported OBJ record ${r.slice(0, 32)}; use only v, vn, vt, f, o, g, s, usemtl and mtllib lines.`);
|
|
393
|
+
}
|
|
394
|
+
return o.filter((e) => e.positions.length).map((e) => ({
|
|
395
|
+
name: e.name,
|
|
396
|
+
geometry: M(e.positions, t)
|
|
397
|
+
}));
|
|
398
|
+
}
|
|
399
|
+
function I(e, t, n, i, a) {
|
|
400
|
+
if (y("maxParts", a), !["stl", "obj"].includes(t)) throw TypeError("parseCADGeometry reads STL and OBJ only; pass format 'stl' or 'obj'.");
|
|
401
|
+
let o = typeof e == "string" ? e : e instanceof ArrayBuffer ? new Uint8Array(e) : new Uint8Array(e.buffer, e.byteOffset, e.byteLength), s = typeof o == "string" ? new TextEncoder().encode(o).length : o.length;
|
|
402
|
+
if (s > 67108864) throw D(`CAD exceeds 64 MiB (${s} > ${w} bytes)`, t);
|
|
403
|
+
let c = t === "stl" ? P(o, n, i) : F(typeof o == "string" ? o : N(o, "OBJ"), n, i, a);
|
|
404
|
+
if (!c.length) throw new r("failed", "CAD file contains no geometry; check that the file holds at least one solid or mesh.");
|
|
405
|
+
return c;
|
|
406
|
+
}
|
|
407
|
+
function L(e) {
|
|
408
|
+
if (e.indices.length > 3e6) throw RangeError(`Deduplication supports at most ${E / 3} triangles per part; split the part or skip deduplication.`);
|
|
409
|
+
let t = new Float32Array(e.indices.length * 6), n = [], r = e.indices, i = e.vertices;
|
|
410
|
+
for (let e = 0; e < r.length; e += 3) {
|
|
411
|
+
let a = 0;
|
|
412
|
+
for (let t = 1; t < 3; t++) {
|
|
413
|
+
let n = r[e + t] * 6, o = r[e + a] * 6;
|
|
414
|
+
for (let e = 0; e < 6; e++) {
|
|
415
|
+
let r = i[n + e] - i[o + e];
|
|
416
|
+
if (r < 0) {
|
|
417
|
+
a = t;
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
if (r > 0) break;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
for (let n = 0; n < 3; n++) {
|
|
424
|
+
let o = r[e + (a + n) % 3] * 6, s = e * 6 + n * 6;
|
|
425
|
+
for (let e = 0; e < 6; e++) t[s + e] = i[o + e] || 0;
|
|
426
|
+
}
|
|
427
|
+
n.push(e / 3);
|
|
428
|
+
}
|
|
429
|
+
n.sort((e, n) => {
|
|
430
|
+
for (let r = 0; r < 18; r++) {
|
|
431
|
+
let i = t[e * 18 + r] - t[n * 18 + r];
|
|
432
|
+
if (i) return i;
|
|
433
|
+
}
|
|
434
|
+
return 0;
|
|
435
|
+
});
|
|
436
|
+
let a = new Float32Array(t.length);
|
|
437
|
+
for (let e = 0; e < n.length; e++) {
|
|
438
|
+
let r = n[e] * 18, i = e * 18;
|
|
439
|
+
for (let e = 0; e < 18; e++) a[i + e] = t[r + e];
|
|
440
|
+
}
|
|
441
|
+
return a;
|
|
442
|
+
}
|
|
443
|
+
function R(e) {
|
|
444
|
+
return C(new Uint8Array(e.buffer, e.byteOffset, e.byteLength));
|
|
445
|
+
}
|
|
446
|
+
//#endregion
|
|
447
|
+
//#region src/cad-async.ts
|
|
448
|
+
var z = [
|
|
449
|
+
"stl",
|
|
450
|
+
"obj",
|
|
451
|
+
"step",
|
|
452
|
+
"iges",
|
|
453
|
+
"sat",
|
|
454
|
+
"xt",
|
|
455
|
+
"jt"
|
|
456
|
+
];
|
|
457
|
+
function B(i, a, o, c = {}) {
|
|
458
|
+
if (c.signal?.throwIfAborted(), !(a instanceof ArrayBuffer) || !a.byteLength || !z.includes(o)) throw TypeError("CAD input must be a non-empty ArrayBuffer with format stl, obj, step, iges, sat, xt or jt; pass the file bytes and one of those formats.");
|
|
459
|
+
if (a.byteLength > 67108864) throw D(`CAD exceeds 64 MiB (${a.byteLength} > ${w} bytes)`, o);
|
|
460
|
+
let l = c.timeoutMs ?? 12e4;
|
|
461
|
+
if (!(l > 0 && l <= 2 ** 31 - 1)) throw RangeError("timeoutMs must be a positive number");
|
|
462
|
+
let { linearDeflection: u } = c;
|
|
463
|
+
if (u !== void 0 && !(typeof u == "number" && u > 0 && u < Infinity)) throw RangeError("linearDeflection must be a positive finite number of meters");
|
|
464
|
+
let { creaseAngle: d = 40 } = c;
|
|
465
|
+
if (!(typeof d == "number" && d >= 0 && d <= 180)) throw RangeError("creaseAngle must be a number of degrees from 0 to 180");
|
|
466
|
+
let f = n(i);
|
|
467
|
+
if (f.disposed) throw new r("disposed", "Engine is disposed; create a new Engine before loading CAD.");
|
|
468
|
+
let { importer: p } = c;
|
|
469
|
+
if (p !== void 0 && typeof p != "function") throw TypeError("importer must be a function");
|
|
470
|
+
if (p && o !== "stl" && o !== "obj") return p(i, a, o, c);
|
|
471
|
+
let m = s(f), h = new URL("./workers/cad-runtime.js?no-inline",
|
|
472
|
+
import.meta.url
|
|
473
|
+
);
|
|
474
|
+
return new Promise((n, i) => {
|
|
475
|
+
let s = new Worker(h), p = [], g = [], _ = /* @__PURE__ */ new Map(), v = (e) => {
|
|
476
|
+
let n = e ?? "#a6b9c8", r = _.get(n);
|
|
477
|
+
return r || _.set(n, r = new t({
|
|
478
|
+
color: n,
|
|
479
|
+
roughness: .4,
|
|
480
|
+
metalness: .3
|
|
481
|
+
})), r;
|
|
482
|
+
}, y, b = setTimeout(() => C(/* @__PURE__ */ RangeError(`CAD import did not finish within ${l} ms (raise the timeoutMs option)`)), l), x = () => {
|
|
483
|
+
clearTimeout(b), s.onmessage = s.onerror = s.onmessageerror = null, s.terminate(), c.signal?.removeEventListener("abort", w);
|
|
484
|
+
}, S = () => {
|
|
485
|
+
for (let e = p.length - 1; e >= 0; e--) p[e].dispose();
|
|
486
|
+
}, C = (e) => {
|
|
487
|
+
x(), S(), i(e);
|
|
488
|
+
}, w = () => C(c.signal?.reason ?? new DOMException("Aborted", "AbortError"));
|
|
489
|
+
c.signal?.addEventListener("abort", w, { once: !0 }), s.onerror = (e) => {
|
|
490
|
+
e.preventDefault?.(), C(new r("failed", `CAD worker failed: ${e.message || "unknown error"}; try loading the file again.`));
|
|
491
|
+
}, s.onmessageerror = () => C(new r("failed", "CAD worker message failed; try loading the file again.")), s.onmessage = (t) => {
|
|
492
|
+
let i = t.data;
|
|
493
|
+
if (!i || typeof i != "object") C(/* @__PURE__ */ TypeError("Invalid CAD worker message"));
|
|
494
|
+
else if (i.error) C(new (i.kind === "RangeError" ? RangeError : i.kind === "TypeError" ? TypeError : Error)(i.error));
|
|
495
|
+
else if (typeof i.progress == "number") try {
|
|
496
|
+
c.onProgress?.(i.progress);
|
|
497
|
+
} catch (e) {
|
|
498
|
+
C(e);
|
|
499
|
+
}
|
|
500
|
+
else try {
|
|
501
|
+
if (c.signal?.throwIfAborted(), f.disposed) throw new r("disposed", "Engine is disposed; create a new Engine before loading CAD.");
|
|
502
|
+
if (i.done) {
|
|
503
|
+
if (!y || !g.length) throw new r("failed", "CAD file contains no geometry; check that the file holds at least one solid or mesh.");
|
|
504
|
+
y.visible = !0, x();
|
|
505
|
+
let e = {
|
|
506
|
+
root: y,
|
|
507
|
+
meshes: g,
|
|
508
|
+
dispose: S
|
|
509
|
+
};
|
|
510
|
+
typeof i.failedFaces == "number" && (e.failedFaces = i.failedFaces), Array.isArray(i.warnings) && (e.warnings = i.warnings), n(e);
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
y || (y = m.run(() => f.createMesh()), y.visible = !1, p.push(y));
|
|
514
|
+
let t = i.part, a = t.reuse === void 0 ? Object.assign(Object.create(e.prototype), {
|
|
515
|
+
vertices: t.vertices,
|
|
516
|
+
indices: t.indices,
|
|
517
|
+
bounds: t.bounds
|
|
518
|
+
}) : g[t.reuse]?.geometry;
|
|
519
|
+
if (!a) throw new r("failed", "CAD worker reused a part that does not exist; try loading the file again.");
|
|
520
|
+
let o = m.run(() => f.createMesh(y));
|
|
521
|
+
p.push(o), o.name = t.name, o.setGeometry(a).setMaterial(v(t.color)), t.transform && o.setPosition(t.transform.position).setQuaternion(t.transform.rotation).setScale(t.transform.scale), g.push(o);
|
|
522
|
+
} catch (e) {
|
|
523
|
+
C(e);
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
try {
|
|
527
|
+
s.postMessage({
|
|
528
|
+
buffer: a,
|
|
529
|
+
format: o,
|
|
530
|
+
smoothing: c.smoothing ?? !0,
|
|
531
|
+
creaseAngle: d,
|
|
532
|
+
maxParts: c.maxParts,
|
|
533
|
+
linearDeflection: u
|
|
534
|
+
}, [a]);
|
|
535
|
+
} catch (e) {
|
|
536
|
+
C(e);
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
//#endregion
|
|
541
|
+
export { E as a, w as i, L as n, I as o, R as r, s, B as t };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { EngineKernel } from '@margoengine/core';
|
|
2
|
+
import type { CADModel } from './cad.js';
|
|
3
|
+
/**
|
|
4
|
+
* A file format `parseCADAsync` and `loadCAD` read: STL and OBJ triangles, or a B-rep file read and meshed by Margo's
|
|
5
|
+
* own kernel (`@margoengine/brep`): STEP (AP203, AP214, AP242), IGES 5.3, ACIS SAT, Parasolid XT (.x_t and .x_b)
|
|
6
|
+
* and JT (ISO 14306, its exact B-rep parts).
|
|
7
|
+
*/
|
|
8
|
+
export type CADFormat = 'stl' | 'obj' | BRepFormat;
|
|
9
|
+
/** The B-rep formats: read with the kernel in the worker, or with a custom `importer`. */
|
|
10
|
+
export type BRepFormat = 'step' | 'iges' | 'sat' | 'xt' | 'jt';
|
|
11
|
+
/**
|
|
12
|
+
* Reads a B-rep file (STEP, IGES, SAT, XT or JT) in place of the bundled kernel worker. It gets the same arguments as
|
|
13
|
+
* {@link parseCADAsync} (the engine, the file's bytes, its format, the import options) and resolves with the model.
|
|
14
|
+
* Every part it creates must belong to `engine`; if it throws or rejects, it must dispose what it created.
|
|
15
|
+
*/
|
|
16
|
+
export type CADImporter = (engine: EngineKernel, buffer: ArrayBuffer, format: BRepFormat, options: CADImportOptions) => Promise<CADModel>;
|
|
17
|
+
/** Options for `parseCADAsync` and `loadCAD`; each one lists its default. */
|
|
18
|
+
export interface CADImportOptions {
|
|
19
|
+
/** Cancels the import (and the download in `loadCAD`); the worker is terminated and the parts created so far are disposed. Default none. */
|
|
20
|
+
signal?: AbortSignal;
|
|
21
|
+
/** Called with 0 to 100 while the file is read. Default none. */
|
|
22
|
+
onProgress?: (percent: number) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Shading normals (default true). B-rep formats: the kernel's exact surface normals, smooth across each curved face
|
|
25
|
+
* and hard at every B-rep edge. STL/OBJ: corners at the same point are welded, and each corner averages the normals of
|
|
26
|
+
* the triangles there that meet its own within `creaseAngle` (weighted by area times corner angle). `false`: one flat
|
|
27
|
+
* normal per triangle.
|
|
28
|
+
*/
|
|
29
|
+
smoothing?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* STL and OBJ with smoothing: the largest angle, in degrees from 0 to 180, at which two triangles at a point share a
|
|
32
|
+
* smooth normal (default 40). Sharper edges stay hard, as in the CAD model: a box keeps its 90 degree edges and a hex
|
|
33
|
+
* nut its 60 degree corners, while a cylinder cut into 9 or more sides shades round. 180 averages every triangle at a
|
|
34
|
+
* point, as earlier versions did. B-rep formats ignore it: their exact surface normals already know every edge.
|
|
35
|
+
*/
|
|
36
|
+
creaseAngle?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Most parts the file may have, each one a core mesh (default 100,000; up to core's 8,388,608 entities): OBJ objects
|
|
39
|
+
* and groups, or B-rep placements (one per placed body and colour).
|
|
40
|
+
*/
|
|
41
|
+
maxParts?: number;
|
|
42
|
+
/**
|
|
43
|
+
* The worker is terminated and the import rejects after this many milliseconds (default 120,000). A very large or
|
|
44
|
+
* malformed B-rep file can take minutes to mesh; a worker that never answers is never waited on.
|
|
45
|
+
*/
|
|
46
|
+
timeoutMs?: number;
|
|
47
|
+
/**
|
|
48
|
+
* B-rep formats only: the largest distance, in meters, that the mesh may stray from the true surface (its chord
|
|
49
|
+
* deflection), the same for every body. Smaller values give finer triangles. Omitted, each body gets 0.001 of its
|
|
50
|
+
* bounding-box diagonal. STL and OBJ are already triangles and ignore it. A custom `importer` receives the value as
|
|
51
|
+
* given.
|
|
52
|
+
*/
|
|
53
|
+
linearDeflection?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Reads the B-rep formats with your own function instead of the kernel (default none: the bundled kernel worker).
|
|
56
|
+
* It is called after the size and option checks, with the same engine, bytes, format and options, and its model is
|
|
57
|
+
* returned as is. STL and OBJ never use it. Use it to plug in a reader the engine does not ship.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* const model = await loadCAD(engine, 'part.step', { importer: (engine, bytes, format, options) => myReader(engine, bytes, options) });
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
importer?: CADImporter;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Imports STL, OBJ, STEP, IGES, SAT, XT or JT bytes in a worker and resolves with the model. The buffer is transferred
|
|
68
|
+
* and detaches. B-rep files are meshed once per body and placed with a transform per use, so repeated parts share
|
|
69
|
+
* one geometry; each placed body gets one mesh per colour. Rejects on `signal` abort, after `timeoutMs`, or if the file
|
|
70
|
+
* is invalid; nothing is left in the engine then.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* const model = await parseCADAsync(engine, bytes, 'step', { onProgress: (percent) => console.log(percent) });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare function parseCADAsync(instance: EngineKernel, buffer: ArrayBuffer, format: CADFormat, options?: CADImportOptions): Promise<CADModel>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as parseCADAsync } from "./cad-async-kUFSo7gb.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { MakeMesh, MeshBuffers } from './internal/buffers.js';
|
|
2
|
+
export declare const maxBytes: number, maxVertices = 1000000, maxIndices = 3000000;
|
|
3
|
+
/** RangeError for a file over a CAD cap (docs/limits.md). The message names the cap and the way past it: a GLB, which
|
|
4
|
+
* @margoengine/gltf/pbr loads without these caps (a B-rep file is tessellated offline with @margoengine/brep and written as GLB with
|
|
5
|
+
* @margoengine/exporters). */
|
|
6
|
+
export declare function capError(limit: string, format: string): RangeError;
|
|
7
|
+
/** `make` builds each part's mesh (core's Geometry on the page, the worker's own buffers there); `maxParts`: most OBJ
|
|
8
|
+
* objects and groups (default 100,000; up to core's 8,388,608 entities). */
|
|
9
|
+
export declare function parseCADGeometry<G extends MeshBuffers>(input: string | ArrayBuffer | ArrayBufferView, format: 'stl' | 'obj', make: MakeMesh<G>, progress?: (value: number) => void, maxParts?: number): Array<{
|
|
10
|
+
name: string;
|
|
11
|
+
geometry: G;
|
|
12
|
+
}>;
|
|
13
|
+
export declare function fingerprint(geometry: Pick<MeshBuffers, 'vertices' | 'indices'>): Float32Array;
|
|
14
|
+
export declare function hash(data: Float32Array): number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|