three-slicer-viewer 0.4.0 → 0.4.1
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/README.md +7 -0
- package/dist/index.js +2886 -2861
- package/dist/model_loaders-kvOxEvFT.js +230 -0
- package/dist/model_loaders.js +14 -9
- package/dist/parse_3mf-6PLUgcZp.js +951 -0
- package/dist/parse_3mf.worker.js +101 -39
- package/package.json +5 -1
- package/src/settings/toggle_eval.js +112 -6
- package/types/loaders.d.ts +23 -1
- package/types/toggle.d.ts +6 -0
- package/types/workers.d.ts +10 -0
- package/dist/model_loaders-Dk9rqXFb.js +0 -196
- package/dist/parse_3mf-CpbA-6Iq.js +0 -666
|
@@ -0,0 +1,951 @@
|
|
|
1
|
+
import { inflateSync as Vt, unzip as Jt, unzipSync as Ot } from "three/examples/jsm/libs/fflate.module.js";
|
|
2
|
+
import { S as Ht } from "./viewer_defaults-B7UUZ582.js";
|
|
3
|
+
const Nt = [
|
|
4
|
+
1,
|
|
5
|
+
10,
|
|
6
|
+
100,
|
|
7
|
+
1e3,
|
|
8
|
+
1e4,
|
|
9
|
+
1e5,
|
|
10
|
+
1e6,
|
|
11
|
+
1e7,
|
|
12
|
+
1e8,
|
|
13
|
+
1e9,
|
|
14
|
+
1e10,
|
|
15
|
+
1e11,
|
|
16
|
+
1e12,
|
|
17
|
+
1e13,
|
|
18
|
+
1e14,
|
|
19
|
+
1e15,
|
|
20
|
+
1e16,
|
|
21
|
+
1e17,
|
|
22
|
+
1e18,
|
|
23
|
+
1e19,
|
|
24
|
+
1e20,
|
|
25
|
+
1e21,
|
|
26
|
+
1e22
|
|
27
|
+
], Kt = new TextDecoder(), U = (t, e, r) => Kt.decode(t.subarray(e, r));
|
|
28
|
+
function G(t, e, r) {
|
|
29
|
+
let o = e, n = !1;
|
|
30
|
+
o < r && (t[o] === 45 || t[o] === 43) && (n = t[o] === 45, o++);
|
|
31
|
+
let i = 0, a = -1, l = 0;
|
|
32
|
+
for (; o < r; o++) {
|
|
33
|
+
const f = t[o];
|
|
34
|
+
if (f >= 48 && f <= 57)
|
|
35
|
+
i = i * 10 + (f - 48), l++, a >= 0 && a++;
|
|
36
|
+
else if (f === 46 && a < 0) a = 0;
|
|
37
|
+
else return Number(U(t, e, r));
|
|
38
|
+
}
|
|
39
|
+
if (!l || i > 9007199254740991 || a > 22) return Number(U(t, e, r));
|
|
40
|
+
let s = i;
|
|
41
|
+
return a > 0 && (s = i / Nt[a]), n ? -s : s;
|
|
42
|
+
}
|
|
43
|
+
let F = 0;
|
|
44
|
+
function Q(t, e) {
|
|
45
|
+
let r = e, o = !1, n = t[r];
|
|
46
|
+
(n === 45 || n === 43) && (o = n === 45, n = t[++r]);
|
|
47
|
+
let i = 0, a = -1, l = 0;
|
|
48
|
+
for (; ; n = t[++r])
|
|
49
|
+
if (n >= 48 && n <= 57)
|
|
50
|
+
i = i * 10 + (n - 48), l++, a >= 0 && a++;
|
|
51
|
+
else if (n === 46 && a < 0) a = 0;
|
|
52
|
+
else break;
|
|
53
|
+
if (n !== 34) {
|
|
54
|
+
const f = t.indexOf(34, r);
|
|
55
|
+
return F = f + 1, Number(U(t, e, f));
|
|
56
|
+
}
|
|
57
|
+
if (F = r + 1, !l || i > 9007199254740991 || a > 22) return Number(U(t, e, r));
|
|
58
|
+
let s = i;
|
|
59
|
+
return a > 0 && (s = i / Nt[a]), o ? -s : s;
|
|
60
|
+
}
|
|
61
|
+
const ct = (t, e, r) => t[e] === 32 && t[e + 1] === r && t[e + 2] === 61 && t[e + 3] === 34, lt = (t, e, r) => t[e] === 32 && t[e + 1] === 118 && t[e + 2] === r && t[e + 3] === 61 && t[e + 4] === 34, Z = (t) => t === 32 || t === 10 || t === 13 || t === 9, B = (t, e, r, o) => {
|
|
62
|
+
if (r - e !== o.length) return !1;
|
|
63
|
+
for (let n = 0; n < o.length; n++) if (t[e + n] !== o.charCodeAt(n)) return !1;
|
|
64
|
+
return !0;
|
|
65
|
+
};
|
|
66
|
+
function Y(t, e, r) {
|
|
67
|
+
const o = t.length;
|
|
68
|
+
for (; e < o; ) {
|
|
69
|
+
let n = t[e];
|
|
70
|
+
for (; Z(n); ) n = t[++e];
|
|
71
|
+
if (n === 62) return e + 1;
|
|
72
|
+
if (n === 47) {
|
|
73
|
+
e++;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
const i = e;
|
|
77
|
+
for (; e < o && t[e] !== 61 && t[e] !== 62 && !Z(t[e]); ) e++;
|
|
78
|
+
const a = e;
|
|
79
|
+
for (; Z(t[e]); ) e++;
|
|
80
|
+
if (t[e] !== 61) continue;
|
|
81
|
+
for (e++; Z(t[e]); ) e++;
|
|
82
|
+
const l = t[e];
|
|
83
|
+
if (l !== 34 && l !== 39) continue;
|
|
84
|
+
const s = e + 1, f = t.indexOf(l, s);
|
|
85
|
+
if (f < 0) return o;
|
|
86
|
+
l === 34 && r(i, a, s, f), e = f + 1;
|
|
87
|
+
}
|
|
88
|
+
return o;
|
|
89
|
+
}
|
|
90
|
+
const St = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0];
|
|
91
|
+
function Bt(t) {
|
|
92
|
+
if (!t) return St;
|
|
93
|
+
const e = t.trim().split(/\s+/).map(Number);
|
|
94
|
+
return e.length === 12 && e.every(Number.isFinite) ? e : St;
|
|
95
|
+
}
|
|
96
|
+
const pt = [
|
|
97
|
+
["paint_color", "color"],
|
|
98
|
+
// multi-material: state 1..16 == Extruder1..16
|
|
99
|
+
["paint_supports", "supports"],
|
|
100
|
+
// support enforcer/blocker: states 1 and 2
|
|
101
|
+
["paint_seam", "seam"],
|
|
102
|
+
// unsupported by the kernel — collected for the warning only
|
|
103
|
+
["paint_fuzzy_skin", "fuzzy"]
|
|
104
|
+
// ditto
|
|
105
|
+
], Wt = Object.fromEntries(pt);
|
|
106
|
+
function kt() {
|
|
107
|
+
return { color: /* @__PURE__ */ new Map(), supports: /* @__PURE__ */ new Map(), seam: /* @__PURE__ */ new Map(), fuzzy: /* @__PURE__ */ new Map() };
|
|
108
|
+
}
|
|
109
|
+
function Yt(t) {
|
|
110
|
+
return !t || pt.every(([, e]) => t[e].size === 0);
|
|
111
|
+
}
|
|
112
|
+
class It {
|
|
113
|
+
constructor() {
|
|
114
|
+
this.data = new Float64Array(1024), this.length = 0;
|
|
115
|
+
}
|
|
116
|
+
push3(e, r, o) {
|
|
117
|
+
if (this.length + 3 > this.data.length) {
|
|
118
|
+
const n = new Float64Array(this.data.length * 2);
|
|
119
|
+
n.set(this.data), this.data = n;
|
|
120
|
+
}
|
|
121
|
+
this.data[this.length] = e, this.data[this.length + 1] = r, this.data[this.length + 2] = o, this.length += 3;
|
|
122
|
+
}
|
|
123
|
+
view() {
|
|
124
|
+
return this.data.subarray(0, this.length);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function et(t, e = null) {
|
|
128
|
+
const r = /* @__PURE__ */ new Map(), o = [];
|
|
129
|
+
let n = e, i = 0, a = 0, l = 0, s = 0, f = 0, c = 0, u = 0, p = null, m = null, g = null, w = null, S = null;
|
|
130
|
+
const I = () => {
|
|
131
|
+
if (n.id)
|
|
132
|
+
if (n.components.length) r.set(n.id, { components: n.components });
|
|
133
|
+
else {
|
|
134
|
+
let d = null;
|
|
135
|
+
n.verts.length >= 9 && n.tris.length && (d = { verts: n.verts.view(), tris: n.tris.view(), paint: n.paint }), r.set(n.id, { mesh: d });
|
|
136
|
+
}
|
|
137
|
+
n = null;
|
|
138
|
+
}, A = () => ({ objectid: p, path: m || g, transform: Bt(w) }), T = (d, O, E, j) => {
|
|
139
|
+
B(t, d, O, "objectid") ? p = U(t, E, j) : B(t, d, O, "p:path") ? m = U(t, E, j) : B(t, d, O, "path") ? g = U(t, E, j) : B(t, d, O, "transform") && (w = U(t, E, j));
|
|
140
|
+
}, v = (d, O, E, j) => {
|
|
141
|
+
if (O - d !== 1) return;
|
|
142
|
+
const R = t[d];
|
|
143
|
+
R === 120 ? a = G(t, E, j) : R === 121 ? l = G(t, E, j) : R === 122 && (s = G(t, E, j));
|
|
144
|
+
}, x = (d, O, E, j) => {
|
|
145
|
+
if (O - d === 2 && t[d] === 118) {
|
|
146
|
+
const R = t[d + 1];
|
|
147
|
+
R === 49 ? f = G(t, E, j) : R === 50 ? c = G(t, E, j) : R === 51 && (u = G(t, E, j));
|
|
148
|
+
} else if (t[d] === 112 && O - d > 6) {
|
|
149
|
+
const R = Wt[U(t, d, O)];
|
|
150
|
+
R && j > E && (S ??= []).push(R, U(t, E, j));
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
let y = null;
|
|
154
|
+
const k = (d, O, E, j) => {
|
|
155
|
+
B(t, d, O, "id") && (y = U(t, E, j));
|
|
156
|
+
}, $ = t.length;
|
|
157
|
+
let N = 0;
|
|
158
|
+
for (; N = t.indexOf(60, N), !(N < 0); ) {
|
|
159
|
+
let d = N + 1;
|
|
160
|
+
const O = t[d] === 47;
|
|
161
|
+
O && d++;
|
|
162
|
+
const E = t[d];
|
|
163
|
+
if (E === 33 || E === 63) {
|
|
164
|
+
if (t[d + 1] === 45 && t[d + 2] === 45) {
|
|
165
|
+
let R = d + 3;
|
|
166
|
+
for (; (R = t.indexOf(45, R)) >= 0 && !(t[R + 1] === 45 && t[R + 2] === 62); ) R++;
|
|
167
|
+
N = $, R >= 0 && (N = R + 3);
|
|
168
|
+
} else N = t.indexOf(62, d) + 1 || $;
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
let j = d;
|
|
172
|
+
for (; j < $ && !Z(t[j]) && t[j] !== 62 && t[j] !== 47; ) j++;
|
|
173
|
+
if (O) {
|
|
174
|
+
n && B(t, d, j, "object") ? I() : i === 1 && B(t, d, j, "build") && (i = 2), N = t.indexOf(62, j) + 1 || $;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (n) {
|
|
178
|
+
if (B(t, d, j, "vertex")) {
|
|
179
|
+
if (ct(t, j, 120) && (a = Q(t, j + 4), ct(t, F, 121) && (l = Q(t, F + 4), ct(t, F, 122) && (s = Q(t, F + 4), t[F] === 47 && t[F + 1] === 62)))) {
|
|
180
|
+
N = F + 2, n.id && n.verts.push3(a, l, s);
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
a = 0, l = 0, s = 0, N = Y(t, j, v), n.id && n.verts.push3(a, l, s);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (B(t, d, j, "triangle")) {
|
|
187
|
+
f = 0, c = 0, u = 0, S = null;
|
|
188
|
+
let R = j;
|
|
189
|
+
if (lt(t, j, 49)) {
|
|
190
|
+
const K = Q(t, j + 5);
|
|
191
|
+
if (lt(t, F, 50)) {
|
|
192
|
+
const st = Q(t, F + 5);
|
|
193
|
+
if (lt(t, F, 51)) {
|
|
194
|
+
const at = Q(t, F + 5);
|
|
195
|
+
f = K, c = st, u = at, R = F;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (R !== j && t[R] === 47 && t[R + 1] === 62 ? N = R + 2 : N = Y(t, R, x), !n.id) continue;
|
|
200
|
+
const nt = n.tris.length / 3;
|
|
201
|
+
if (n.tris.push3(f, c, u), S) for (let K = 0; K < S.length; K += 2) n.paint[S[K]].set(nt, S[K + 1]);
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
if (B(t, d, j, "component")) {
|
|
205
|
+
p = null, m = null, g = null, w = null, N = Y(t, j, T), p && n.components.push(A());
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
} else if (B(t, d, j, "object")) {
|
|
209
|
+
y = null, N = Y(t, j, k), n = { id: y, components: [], verts: new It(), tris: new It(), paint: kt() }, t[N - 2] === 47 && I();
|
|
210
|
+
continue;
|
|
211
|
+
} else if (i === 0 && B(t, d, j, "build")) {
|
|
212
|
+
N = Y(t, j, () => {
|
|
213
|
+
}), i = 1, t[N - 2] === 47 && (i = 2);
|
|
214
|
+
continue;
|
|
215
|
+
} else if (i === 1 && B(t, d, j, "item")) {
|
|
216
|
+
p = null, m = null, g = null, w = null, N = Y(t, j, T), p && o.push(A());
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
N = t.indexOf(62, j) + 1 || $;
|
|
220
|
+
}
|
|
221
|
+
return { objects: r, items: o, openObject: n };
|
|
222
|
+
}
|
|
223
|
+
function qt(t) {
|
|
224
|
+
const e = ft(t);
|
|
225
|
+
return e.advance(t.length), e.finish();
|
|
226
|
+
}
|
|
227
|
+
function ft(t) {
|
|
228
|
+
const e = /* @__PURE__ */ new Map(), r = [];
|
|
229
|
+
let o = null, n = 0, i = null, a = null, l = null, s = null, f = null, c = 0, u = -1;
|
|
230
|
+
const p = () => ({ objectid: i, path: a || l, transform: Bt(s) }), m = (I, A, T, v) => {
|
|
231
|
+
B(t, I, A, "objectid") ? i = U(t, T, v) : B(t, I, A, "p:path") ? a = U(t, T, v) : B(t, I, A, "path") ? l = U(t, T, v) : B(t, I, A, "transform") && (s = U(t, T, v));
|
|
232
|
+
}, g = (I, A, T, v) => {
|
|
233
|
+
B(t, I, A, "id") && (f = U(t, T, v));
|
|
234
|
+
};
|
|
235
|
+
function w(I) {
|
|
236
|
+
const A = [], T = t.subarray(0, I), v = (x) => {
|
|
237
|
+
if (o.id) {
|
|
238
|
+
const y = { id: o.id, start: o.start, end: x, components: o.components, hasMesh: o.hasMesh && !o.components.length };
|
|
239
|
+
e.set(o.id, y), A.push(y);
|
|
240
|
+
}
|
|
241
|
+
o = null;
|
|
242
|
+
};
|
|
243
|
+
for (; ; ) {
|
|
244
|
+
if (u >= 0) {
|
|
245
|
+
let O = T.indexOf(106, u);
|
|
246
|
+
for (; O >= 0 && !(t[O - 4] === 60 && t[O - 3] === 47 && t[O - 2] === 111 && t[O - 1] === 98); ) O = T.indexOf(106, O + 1);
|
|
247
|
+
if (O < 0)
|
|
248
|
+
return u = Math.max(u, I - 4), A;
|
|
249
|
+
c = O - 4, u = -1;
|
|
250
|
+
}
|
|
251
|
+
const x = T.indexOf(60, c);
|
|
252
|
+
if (x < 0)
|
|
253
|
+
return c = I, A;
|
|
254
|
+
const y = T.indexOf(62, x);
|
|
255
|
+
if (y < 0)
|
|
256
|
+
return c = x, A;
|
|
257
|
+
let k = x + 1;
|
|
258
|
+
const $ = t[k] === 47;
|
|
259
|
+
$ && k++;
|
|
260
|
+
const N = t[k];
|
|
261
|
+
if (N === 33 || N === 63) {
|
|
262
|
+
if (t[k + 1] === 45 && t[k + 2] === 45) {
|
|
263
|
+
let O = k + 3;
|
|
264
|
+
for (; (O = T.indexOf(45, O)) >= 0 && !(t[O + 1] === 45 && t[O + 2] === 62); ) O++;
|
|
265
|
+
if (O < 0 || O + 3 > I)
|
|
266
|
+
return c = x, A;
|
|
267
|
+
c = O + 3;
|
|
268
|
+
} else c = y + 1;
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
let d = k;
|
|
272
|
+
for (; d < y && !Z(t[d]) && t[d] !== 62 && t[d] !== 47; ) d++;
|
|
273
|
+
if (c = y + 1, $) {
|
|
274
|
+
o && B(t, k, d, "object") ? v(c) : n === 1 && B(t, k, d, "build") && (n = 2);
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
o ? B(t, k, d, "mesh") ? (o.hasMesh = !0, u = c) : B(t, k, d, "component") && (i = null, a = null, l = null, s = null, Y(t, d, m), i && o.components.push(p())) : B(t, k, d, "object") ? (f = null, Y(t, d, g), o = { id: f, start: x, components: [], hasMesh: !1 }, t[y - 1] === 47 && v(c)) : n === 0 && B(t, k, d, "build") ? (n = 1, t[y - 1] === 47 && (n = 2)) : n === 1 && B(t, k, d, "item") && (i = null, a = null, l = null, s = null, Y(t, d, m), i && r.push(p()));
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return { advance: w, open: () => o, finish: () => ({ objects: e, items: r }) };
|
|
281
|
+
}
|
|
282
|
+
const Xt = new TextDecoder(), q = (t, e) => t[e] | t[e + 1] << 8, X = (t, e) => (t[e] | t[e + 1] << 8 | t[e + 2] << 16 | t[e + 3] << 24) >>> 0, Lt = 65557, dt = 30;
|
|
283
|
+
function yt(t, e, r) {
|
|
284
|
+
const o = [];
|
|
285
|
+
for (let n = 0; n < r; n++) {
|
|
286
|
+
if (X(t, e) !== 33639248) return null;
|
|
287
|
+
const i = q(t, e + 8), a = q(t, e + 10), l = X(t, e + 20), s = X(t, e + 24), f = q(t, e + 28), c = q(t, e + 30), u = q(t, e + 32), p = X(t, e + 42);
|
|
288
|
+
if (i & 1 || l === 4294967295 || s === 4294967295 || p === 4294967295 || a !== 0 && a !== 8) return null;
|
|
289
|
+
o.push({ name: Xt.decode(t.subarray(e + 46, e + 46 + f)), method: a, compressedSize: l, size: s, local: p }), e += 46 + f + c + u;
|
|
290
|
+
}
|
|
291
|
+
return o;
|
|
292
|
+
}
|
|
293
|
+
function Et(t) {
|
|
294
|
+
for (let e = t.length - 22; e >= 0; e--) {
|
|
295
|
+
if (X(t, e) !== 101010256) continue;
|
|
296
|
+
const r = q(t, e + 10), o = X(t, e + 16);
|
|
297
|
+
return r === 65535 || o === 4294967295 ? null : { at: e, count: r, directoryStart: o };
|
|
298
|
+
}
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
function vt(t, e) {
|
|
302
|
+
return X(t, 0) !== 67324752 ? null : e + dt + q(t, 26) + q(t, 28);
|
|
303
|
+
}
|
|
304
|
+
function Gt(t) {
|
|
305
|
+
const e = Et(t.subarray(Math.max(0, t.length - Lt)));
|
|
306
|
+
if (!e) return null;
|
|
307
|
+
const r = yt(t, e.directoryStart, e.count);
|
|
308
|
+
if (!r) return null;
|
|
309
|
+
const o = /* @__PURE__ */ new Map();
|
|
310
|
+
for (const n of r) {
|
|
311
|
+
const i = vt(t.subarray(n.local, n.local + dt), n.local);
|
|
312
|
+
if (i === null) return null;
|
|
313
|
+
o.set(n.name, { method: n.method, compressedSize: n.compressedSize, size: n.size, dataStart: i });
|
|
314
|
+
}
|
|
315
|
+
return o;
|
|
316
|
+
}
|
|
317
|
+
async function Qt(t) {
|
|
318
|
+
const e = async (c, u) => new Uint8Array(await t.slice(c, u).arrayBuffer()), r = Math.max(0, t.size - Lt), o = await e(r, t.size), n = Et(o);
|
|
319
|
+
if (!n) return null;
|
|
320
|
+
let i = o, a = n.directoryStart - r;
|
|
321
|
+
a < 0 && (i = await e(n.directoryStart, r + n.at), a = 0);
|
|
322
|
+
const l = yt(i, a, n.count);
|
|
323
|
+
if (!l) return null;
|
|
324
|
+
const s = await Promise.all(l.map((c) => e(c.local, c.local + dt))), f = /* @__PURE__ */ new Map();
|
|
325
|
+
return l.forEach((c, u) => {
|
|
326
|
+
const p = vt(s[u], c.local);
|
|
327
|
+
p !== null && f.set(c.name, { method: c.method, compressedSize: c.compressedSize, size: c.size, dataStart: p });
|
|
328
|
+
}), f.size !== l.length ? null : f;
|
|
329
|
+
}
|
|
330
|
+
const bt = (t) => typeof Blob < "u" && t instanceof Blob ? t.stream() : new Blob([t]).stream(), Pt = async (t) => typeof Blob < "u" && t instanceof Blob ? new Uint8Array(await t.arrayBuffer()) : t;
|
|
331
|
+
function Zt(t, e) {
|
|
332
|
+
return t.subarray(e.dataStart, e.dataStart + e.compressedSize);
|
|
333
|
+
}
|
|
334
|
+
async function mt(t, e) {
|
|
335
|
+
if (e.method === 0) return (await Pt(t)).slice();
|
|
336
|
+
if (typeof DecompressionStream == "function" && typeof Response == "function") {
|
|
337
|
+
const r = bt(t).pipeThrough(new DecompressionStream("deflate-raw"));
|
|
338
|
+
return new Uint8Array(await new Response(r).arrayBuffer());
|
|
339
|
+
}
|
|
340
|
+
return Vt(await Pt(t), { out: new Uint8Array(e.size) });
|
|
341
|
+
}
|
|
342
|
+
function te(t, e) {
|
|
343
|
+
let r = new Uint8Array(t.size), o = 0;
|
|
344
|
+
return {
|
|
345
|
+
push(n) {
|
|
346
|
+
if (o + n.length > r.length) {
|
|
347
|
+
const i = new Uint8Array(Math.max(r.length * 2, o + n.length));
|
|
348
|
+
i.set(r.subarray(0, o)), r = i;
|
|
349
|
+
}
|
|
350
|
+
r.set(n, o), o += n.length, e(r, o);
|
|
351
|
+
},
|
|
352
|
+
finish() {
|
|
353
|
+
return o !== r.length ? r.slice(0, o) : r;
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
async function ee(t, e, r, o = 1 << 20) {
|
|
358
|
+
if (e.method === 0 || typeof DecompressionStream != "function") {
|
|
359
|
+
r(await mt(t, e));
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
const n = bt(t).pipeThrough(new DecompressionStream("deflate-raw")).getReader();
|
|
363
|
+
let i = new Uint8Array(o), a = 0;
|
|
364
|
+
for (; ; ) {
|
|
365
|
+
const { done: l, value: s } = await n.read();
|
|
366
|
+
if (l) break;
|
|
367
|
+
let f = 0;
|
|
368
|
+
for (; f < s.length; ) {
|
|
369
|
+
const c = Math.min(s.length - f, i.length - a);
|
|
370
|
+
i.set(s.subarray(f, f + c), a), a += c, f += c, a === i.length && (r(i), i = new Uint8Array(o), a = 0);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
a && r(i.subarray(0, a));
|
|
374
|
+
}
|
|
375
|
+
async function ne(t, e, r) {
|
|
376
|
+
const o = te(e, r);
|
|
377
|
+
return await ee(t, e, (n) => o.push(n)), o.finish();
|
|
378
|
+
}
|
|
379
|
+
function oe(t) {
|
|
380
|
+
const e = t.length, r = new Float32Array(e);
|
|
381
|
+
for (let u = 0; u < e; u += 3)
|
|
382
|
+
r[u] = t[u], r[u + 1] = t[u + 2], r[u + 2] = -t[u + 1];
|
|
383
|
+
let o = 1 / 0, n = 1 / 0, i = 1 / 0, a = -1 / 0, l = -1 / 0, s = -1 / 0;
|
|
384
|
+
for (let u = 0; u < e; u += 3)
|
|
385
|
+
o = Math.min(o, r[u]), a = Math.max(a, r[u]), n = Math.min(n, r[u + 1]), l = Math.max(l, r[u + 1]), i = Math.min(i, r[u + 2]), s = Math.max(s, r[u + 2]);
|
|
386
|
+
const f = (o + a) / 2, c = (i + s) / 2;
|
|
387
|
+
for (let u = 0; u < e; u += 3)
|
|
388
|
+
r[u] -= f, r[u + 1] -= n, r[u + 2] -= c;
|
|
389
|
+
return { localPos: r, size: { w: a - o, d: s - i, h: l - n } };
|
|
390
|
+
}
|
|
391
|
+
function re(t) {
|
|
392
|
+
const e = [1 / 0, 1 / 0, 1 / 0], r = [-1 / 0, -1 / 0, -1 / 0];
|
|
393
|
+
for (let o = 0; o < t.length; o += 3)
|
|
394
|
+
for (let n = 0; n < 3; n++) {
|
|
395
|
+
const i = t[o + n];
|
|
396
|
+
i < e[n] && (e[n] = i), i > r[n] && (r[n] = i);
|
|
397
|
+
}
|
|
398
|
+
return { min: e, max: r };
|
|
399
|
+
}
|
|
400
|
+
function ie(t, e) {
|
|
401
|
+
const r = [0, 0, 0];
|
|
402
|
+
if (!(e.max[0] < e.min[0] || e.max[1] < e.min[1] || e.max[2] < e.min[2])) for (let i = 0; i < 3; i++) r[i] = (e.min[i] + e.max[i]) * 0.5;
|
|
403
|
+
let n = 0;
|
|
404
|
+
for (let i = 0; i < t.length; i += 3) {
|
|
405
|
+
const a = r[0] - t[i], l = r[1] - t[i + 1], s = r[2] - t[i + 2];
|
|
406
|
+
n = Math.max(n, a * a + l * l + s * s);
|
|
407
|
+
}
|
|
408
|
+
return { center: r, radius: Math.sqrt(n) };
|
|
409
|
+
}
|
|
410
|
+
function se(t) {
|
|
411
|
+
const { localPos: e, size: r } = oe(t), o = re(e);
|
|
412
|
+
return { localPos: e, size: r, bounds: o, sphere: ie(e, o) };
|
|
413
|
+
}
|
|
414
|
+
function ae(t) {
|
|
415
|
+
return new Promise((e) => {
|
|
416
|
+
let r = !1;
|
|
417
|
+
const o = (n) => {
|
|
418
|
+
r || (r = !0, e(n));
|
|
419
|
+
};
|
|
420
|
+
try {
|
|
421
|
+
Jt(t, (n, i) => {
|
|
422
|
+
o(n ? Ot(t) : i);
|
|
423
|
+
});
|
|
424
|
+
} catch {
|
|
425
|
+
o(Ot(t));
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
const ht = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0];
|
|
430
|
+
function Dt(t, e) {
|
|
431
|
+
const r = new Array(12);
|
|
432
|
+
for (let o = 0; o < 4; o++)
|
|
433
|
+
for (let n = 0; n < 3; n++) {
|
|
434
|
+
let i = 0;
|
|
435
|
+
o === 3 && (i = e[9 + n]), r[o * 3 + n] = t[o * 3] * e[n] + t[o * 3 + 1] * e[3 + n] + t[o * 3 + 2] * e[6 + n] + i;
|
|
436
|
+
}
|
|
437
|
+
return r;
|
|
438
|
+
}
|
|
439
|
+
const xt = {};
|
|
440
|
+
function H(t, e) {
|
|
441
|
+
return (xt[e] || (xt[e] = new RegExp(`\\b${e}\\s*=\\s*"([^"]*)"`))).exec(t)?.[1] ?? null;
|
|
442
|
+
}
|
|
443
|
+
function V(t) {
|
|
444
|
+
const e = String(t).replace(/^\/+/, "");
|
|
445
|
+
return e.includes("%") ? decodeURIComponent(e) : e;
|
|
446
|
+
}
|
|
447
|
+
function ot(t) {
|
|
448
|
+
const e = {};
|
|
449
|
+
for (const r of t.match(/<metadata\b[^>]*>/g) || []) {
|
|
450
|
+
const o = H(r, "key");
|
|
451
|
+
o && (e[o] = H(r, "value") ?? "");
|
|
452
|
+
}
|
|
453
|
+
return e;
|
|
454
|
+
}
|
|
455
|
+
const zt = { support_enforcer: "enforcer", support_blocker: "blocker" };
|
|
456
|
+
function ce(t) {
|
|
457
|
+
const e = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), n = /<object\b([^>]*)>([\s\S]*?)<\/object>/g;
|
|
458
|
+
let i;
|
|
459
|
+
for (; i = n.exec(t); ) {
|
|
460
|
+
const s = H(i[1], "id");
|
|
461
|
+
if (s) {
|
|
462
|
+
const f = i[2];
|
|
463
|
+
e.set(s, ot(f.replace(/<(?:part|volume)\b[\s\S]*?<\/(?:part|volume)>/g, "")));
|
|
464
|
+
const c = [];
|
|
465
|
+
for (const p of f.match(/<volume\b[\s\S]*?<\/volume>/g) || []) {
|
|
466
|
+
const m = ot(p).volume_type, g = m === "SupportBlocker" ? "blocker" : m === "SupportEnforcer" ? "enforcer" : null, w = Number(H(p, "firstid")), S = Number(H(p, "lastid"));
|
|
467
|
+
g && Number.isInteger(w) && Number.isInteger(S) && w >= 0 && S >= w && c.push({ firstTriangle: w, lastTriangle: S, kind: g });
|
|
468
|
+
}
|
|
469
|
+
c.length && r.set(s, c);
|
|
470
|
+
const u = (f.match(/<part\b[\s\S]*?<\/part>/g) || []).map((p) => ({
|
|
471
|
+
id: H(p, "id"),
|
|
472
|
+
subtype: H(p, "subtype"),
|
|
473
|
+
faces: Number(H(p.replace(/^<part\b[^>]*>/, ""), "face_count"))
|
|
474
|
+
}));
|
|
475
|
+
if (u.some((p) => zt[p.subtype]) && u.every((p) => p.id && Number.isInteger(p.faces) && p.faces >= 0)) {
|
|
476
|
+
const p = [];
|
|
477
|
+
let m = 0;
|
|
478
|
+
for (const g of u) {
|
|
479
|
+
const w = zt[g.subtype];
|
|
480
|
+
w && g.faces && p.push({ firstTriangle: m, lastTriangle: m + g.faces - 1, kind: w }), m += g.faces;
|
|
481
|
+
}
|
|
482
|
+
o.set(s, { partIds: u.map((g) => g.id), records: p });
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
const a = [], l = /<plate\b[^>]*>([\s\S]*?)<\/plate>/g;
|
|
487
|
+
for (; i = l.exec(t); ) {
|
|
488
|
+
const s = i[1], f = ot(s.replace(/<model_instance\b[\s\S]*?<\/model_instance>/g, "")), c = [];
|
|
489
|
+
for (const u of s.match(/<model_instance\b[\s\S]*?<\/model_instance>/g) || []) {
|
|
490
|
+
const p = ot(u).object_id;
|
|
491
|
+
p && c.push(p);
|
|
492
|
+
}
|
|
493
|
+
a.push({ index: Math.max(0, (Number(f.plater_id) || a.length + 1) - 1), objectIds: c, gcodeFile: f.gcode_file || null });
|
|
494
|
+
}
|
|
495
|
+
return { objects: e, plates: a, volumes: r, partVolumes: o };
|
|
496
|
+
}
|
|
497
|
+
const le = Object.freeze({
|
|
498
|
+
manualSupportPoints: "prepared-roundtrip",
|
|
499
|
+
drainHoles: "preserved-unsupported",
|
|
500
|
+
modifierVolumes: "prepared-mask-filtering",
|
|
501
|
+
uiEditing: "unavailable"
|
|
502
|
+
});
|
|
503
|
+
function At(t, e, r, o, n) {
|
|
504
|
+
const i = /* @__PURE__ */ new Map();
|
|
505
|
+
if (!t?.trim()) return i;
|
|
506
|
+
const a = t.trim().split(/\r?\n/), l = new RegExp(`^${e}_format_version=(\\d+)$`).exec(a[0]), s = l ? Number(l[1]) : 0;
|
|
507
|
+
for (const f of a.slice(l ? 1 : 0)) {
|
|
508
|
+
const c = /^object_id=(\d+)\|(.*)$/.exec(f);
|
|
509
|
+
if (!c || i.has(Number(c?.[1]))) continue;
|
|
510
|
+
const u = Number(c[1]), p = c[2].trim() ? c[2].trim().split(/\s+/).map(Number) : [], m = r(s);
|
|
511
|
+
if (!m || p.length % m !== 0 || p.some((w) => !Number.isFinite(w))) {
|
|
512
|
+
o.push({ code: e === "support_points" ? "SLA_SUPPORT_POINT_COUNT" : "SLA_DRAIN_HOLE_COUNT", object: u }), i.set(u, []);
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
const g = [];
|
|
516
|
+
for (let w = 0; w < p.length; w += m) g.push(n(p.slice(w, w + m), s));
|
|
517
|
+
i.set(u, g);
|
|
518
|
+
}
|
|
519
|
+
return i;
|
|
520
|
+
}
|
|
521
|
+
function Tt(t, e) {
|
|
522
|
+
const [r, o, n] = e;
|
|
523
|
+
return [r * t[0] + o * t[3] + n * t[6] + t[9], r * t[1] + o * t[4] + n * t[7] + t[10], r * t[2] + o * t[5] + n * t[8] + t[11]];
|
|
524
|
+
}
|
|
525
|
+
function fe(t, e) {
|
|
526
|
+
const [r, o, n] = e, i = [r * t[0] + o * t[3] + n * t[6], r * t[1] + o * t[4] + n * t[7], r * t[2] + o * t[5] + n * t[8]], a = Math.hypot(...i);
|
|
527
|
+
return a ? i.map((l) => l / a) : i;
|
|
528
|
+
}
|
|
529
|
+
function ue(t, e) {
|
|
530
|
+
const r = (s) => {
|
|
531
|
+
const f = t.get(s);
|
|
532
|
+
return f ? e.decode(f) : null;
|
|
533
|
+
}, o = {
|
|
534
|
+
settings: null,
|
|
535
|
+
// Metadata/project_settings.config — the flattened preset (raw upstream strings)
|
|
536
|
+
objectMeta: /* @__PURE__ */ new Map(),
|
|
537
|
+
// 3mf object id -> per-object metadata (name, extruder, per-object overrides)
|
|
538
|
+
plates: [],
|
|
539
|
+
// [{index, objectIds}]
|
|
540
|
+
hasLayerHeightProfile: !1,
|
|
541
|
+
hasCustomGcodePerLayer: !1,
|
|
542
|
+
volumeMeta: /* @__PURE__ */ new Map(),
|
|
543
|
+
partVolumeMeta: /* @__PURE__ */ new Map(),
|
|
544
|
+
sla: { capabilities: { ...le }, issues: [], supportPoints: /* @__PURE__ */ new Map(), drainHoles: /* @__PURE__ */ new Map() },
|
|
545
|
+
viewerSettings: null,
|
|
546
|
+
// Metadata/three_slicer_settings.json — this package's own member (write_3mf.js)
|
|
547
|
+
plateSettings: null,
|
|
548
|
+
// ...its two halves: global viewer knobs, and per-plate overrides keyed by plate index
|
|
549
|
+
plateCount: null,
|
|
550
|
+
// ...and the plate count it was saved with (empty plates hold no <plate> record)
|
|
551
|
+
gcodePlates: null
|
|
552
|
+
// a .gcode.3mf's sliced plates: [{index, gcode}] (write_3mf.js writeGcode3MF), else null
|
|
553
|
+
}, n = r("Metadata/project_settings.config");
|
|
554
|
+
if (n)
|
|
555
|
+
try {
|
|
556
|
+
o.settings = JSON.parse(n);
|
|
557
|
+
} catch {
|
|
558
|
+
o.settings = null;
|
|
559
|
+
}
|
|
560
|
+
const i = r("Metadata/three_slicer_settings.json");
|
|
561
|
+
if (i) {
|
|
562
|
+
let s = null;
|
|
563
|
+
try {
|
|
564
|
+
s = JSON.parse(i);
|
|
565
|
+
} catch {
|
|
566
|
+
s = null;
|
|
567
|
+
}
|
|
568
|
+
const f = (c) => c && typeof c == "object" && !Array.isArray(c);
|
|
569
|
+
if (f(s)) {
|
|
570
|
+
f(s.viewer) && Object.keys(s.viewer).length && (o.viewerSettings = s.viewer);
|
|
571
|
+
let c = [];
|
|
572
|
+
f(s.plates) && (c = Object.entries(s.plates));
|
|
573
|
+
const u = c.filter(([p, m]) => /^\d+$/.test(p) && f(m) && Object.keys(m).length);
|
|
574
|
+
u.length && (o.plateSettings = Object.fromEntries(u.map(([p, m]) => [Number(p), m]))), Number.isInteger(s.plateCount) && s.plateCount >= 1 && (o.plateCount = s.plateCount);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
const a = r("Metadata/model_settings.config");
|
|
578
|
+
if (a) {
|
|
579
|
+
const s = ce(a);
|
|
580
|
+
o.objectMeta = s.objects, o.plates = s.plates, o.volumeMeta = s.volumes, o.partVolumeMeta = s.partVolumes;
|
|
581
|
+
}
|
|
582
|
+
const l = o.plates.map((s) => ({ index: s.index, gcode: s.gcodeFile && r(V(s.gcodeFile)) })).filter((s) => s.gcode);
|
|
583
|
+
return l.length && (o.gcodePlates = l), o.sla.supportPoints = At(
|
|
584
|
+
r("Metadata/Slic3r_PE_sla_support_points.txt"),
|
|
585
|
+
"support_points",
|
|
586
|
+
(s) => s === 0 ? 3 : s === 1 ? 5 : 0,
|
|
587
|
+
o.sla.issues,
|
|
588
|
+
(s, f) => ({
|
|
589
|
+
position: s.slice(0, 3),
|
|
590
|
+
radius: f === 0 ? Ht : s[3],
|
|
591
|
+
type: f === 0 || s[4] === 2 ? "manual" : s[4] === 1 ? "island" : "slope"
|
|
592
|
+
})
|
|
593
|
+
), o.sla.drainHoles = At(
|
|
594
|
+
r("Metadata/Slic3r_PE_sla_drain_holes.txt"),
|
|
595
|
+
"drain_holes",
|
|
596
|
+
(s) => s === 1 ? 8 : 0,
|
|
597
|
+
o.sla.issues,
|
|
598
|
+
(s) => {
|
|
599
|
+
const f = Math.hypot(s[3], s[4], s[5]), c = f ? s.slice(3, 6).map((u) => u / f) : s.slice(3, 6);
|
|
600
|
+
return { position: s.slice(0, 3).map((u, p) => u + c[p]), normal: c, radius: s[6], height: s[7] - 1 };
|
|
601
|
+
}
|
|
602
|
+
), o.hasLayerHeightProfile = !!r("Metadata/layer_heights_profile.txt")?.trim(), o.hasCustomGcodePerLayer = !!r("Metadata/custom_gcode_per_layer.xml")?.trim(), o;
|
|
603
|
+
}
|
|
604
|
+
const it = Symbol("part not in job");
|
|
605
|
+
function pe(t) {
|
|
606
|
+
return {
|
|
607
|
+
get(e) {
|
|
608
|
+
const r = t.get(e);
|
|
609
|
+
if (!r) throw it;
|
|
610
|
+
return r;
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
function ut(t, e, r, o, n, i) {
|
|
615
|
+
if (o > 16) return;
|
|
616
|
+
const a = n(e)?.objects.get(t);
|
|
617
|
+
if (a) {
|
|
618
|
+
if (a.components) {
|
|
619
|
+
for (const l of a.components) ut(l.objectid, l.path || e, Dt(l.transform, r), o + 1, n, i);
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
a.mesh && i(a.mesh, r);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
function gt(t, e) {
|
|
626
|
+
let r = 0;
|
|
627
|
+
for (const a of t) ut(a.objectid, a.path, a.xf, a.depth, e, (l) => {
|
|
628
|
+
r += l.tris.length * 3;
|
|
629
|
+
});
|
|
630
|
+
const o = new Float32Array(r), n = kt();
|
|
631
|
+
let i = 0;
|
|
632
|
+
for (const a of t) ut(a.objectid, a.path, a.xf, a.depth, e, ({ verts: l, tris: s, paint: f }, c) => {
|
|
633
|
+
const u = i / 9;
|
|
634
|
+
for (let p = 0; p < s.length; p++) {
|
|
635
|
+
const m = s[p] * 3, g = l[m], w = l[m + 1], S = l[m + 2];
|
|
636
|
+
o[i] = g * c[0] + w * c[3] + S * c[6] + c[9], o[i + 1] = g * c[1] + w * c[4] + S * c[7] + c[10], o[i + 2] = g * c[2] + w * c[5] + S * c[8] + c[11], i += 3;
|
|
637
|
+
}
|
|
638
|
+
for (const [, p] of pt)
|
|
639
|
+
for (const [m, g] of f[p]) n[p].set(u + m, g);
|
|
640
|
+
});
|
|
641
|
+
return { sink: o, paintSink: n };
|
|
642
|
+
}
|
|
643
|
+
function wt({ sink: t, paintSink: e }, r, o) {
|
|
644
|
+
if (t.length < 9) return null;
|
|
645
|
+
let n = t;
|
|
646
|
+
const i = [];
|
|
647
|
+
if (r.length) {
|
|
648
|
+
const p = /* @__PURE__ */ new Set();
|
|
649
|
+
for (let m = 0; m < r.length; m++) {
|
|
650
|
+
const g = r[m], w = g.firstTriangle * 9, S = Math.min(t.length, (g.lastTriangle + 1) * 9);
|
|
651
|
+
if (!(w >= S)) {
|
|
652
|
+
for (let I = g.firstTriangle; I <= g.lastTriangle; I++) p.add(I);
|
|
653
|
+
i.push({ volume: m, kind: g.kind, tris: t.slice(w, S) });
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
if (p.size) {
|
|
657
|
+
const m = new Float32Array(t.length - [...p].filter((w) => w < t.length / 9).length * 9);
|
|
658
|
+
let g = 0;
|
|
659
|
+
for (let w = 0; w < t.length / 9; w++)
|
|
660
|
+
p.has(w) || (m.set(t.subarray(w * 9, w * 9 + 9), g), g += 9);
|
|
661
|
+
n = m;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
let a = 1 / 0, l = 1 / 0, s = -1 / 0, f = -1 / 0;
|
|
665
|
+
for (let p = 0; p < n.length; p += 3) {
|
|
666
|
+
const m = n[p], g = n[p + 1];
|
|
667
|
+
m < a && (a = m), m > s && (s = m), g < l && (l = g), g > f && (f = g);
|
|
668
|
+
}
|
|
669
|
+
let c = e;
|
|
670
|
+
Yt(e) && (c = null);
|
|
671
|
+
const u = { tris: n, paint: c, modifiers: i, bbox: { minX: a, minY: l, maxX: s, maxY: f } };
|
|
672
|
+
return o && (u.baked = se(n)), u;
|
|
673
|
+
}
|
|
674
|
+
async function de(t) {
|
|
675
|
+
const e = await Ut(t.members);
|
|
676
|
+
return { items: Ct(t, e) };
|
|
677
|
+
}
|
|
678
|
+
async function Ut(t) {
|
|
679
|
+
const e = /* @__PURE__ */ new Map();
|
|
680
|
+
return await Promise.all(t.map(async (r) => {
|
|
681
|
+
const o = et(await mt(r.data, r.entry));
|
|
682
|
+
r.partial && (o.objects = pe(o.objects)), e.set(r.path, o);
|
|
683
|
+
})), e;
|
|
684
|
+
}
|
|
685
|
+
function Ct(t, e) {
|
|
686
|
+
const r = new Set(t.names), o = (n) => {
|
|
687
|
+
const i = V(n);
|
|
688
|
+
if (e.has(i)) return e.get(i);
|
|
689
|
+
if (r.has(i)) throw it;
|
|
690
|
+
return null;
|
|
691
|
+
};
|
|
692
|
+
return t.items.map((n) => {
|
|
693
|
+
try {
|
|
694
|
+
return { index: n.index, built: wt(gt(n.refs, o), n.volumeRecords, t.bake) };
|
|
695
|
+
} catch (i) {
|
|
696
|
+
if (i === it) return { index: n.index, local: !0 };
|
|
697
|
+
throw i;
|
|
698
|
+
}
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
function Oe() {
|
|
702
|
+
return { objects: /* @__PURE__ */ new Map(), ready: /* @__PURE__ */ new Map(), open: /* @__PURE__ */ new Map() };
|
|
703
|
+
}
|
|
704
|
+
const me = (t) => t.length === 12 && t.every((e, r) => e === ht[r]);
|
|
705
|
+
function Se(t, e, { bake: r = !1, objectId: o = null, complete: n = !0 } = {}) {
|
|
706
|
+
const i = () => ({ objects: e.objects });
|
|
707
|
+
let a = null;
|
|
708
|
+
o !== null && (a = e.open.get(o) ?? null, e.open.delete(o));
|
|
709
|
+
const l = et(t, a);
|
|
710
|
+
o !== null && !n && l.openObject && e.open.set(o, l.openObject);
|
|
711
|
+
for (const [s, f] of l.objects)
|
|
712
|
+
e.objects.set(s, f), f.mesh && e.ready.set(s, wt(gt([{ objectid: s, path: "", xf: ht, depth: 0 }], i), [], r));
|
|
713
|
+
}
|
|
714
|
+
const he = 1 << 20;
|
|
715
|
+
async function Ie(t, e) {
|
|
716
|
+
const r = await Ut(t.members), o = r.get(t.keptPath)?.objects;
|
|
717
|
+
r.set(t.keptPath, {
|
|
718
|
+
items: [],
|
|
719
|
+
objects: {
|
|
720
|
+
get(l) {
|
|
721
|
+
const s = e?.objects.get(l);
|
|
722
|
+
if (s) return s;
|
|
723
|
+
if (o) return o.get(l);
|
|
724
|
+
throw it;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
});
|
|
728
|
+
const n = [], i = [];
|
|
729
|
+
for (const l of t.items) {
|
|
730
|
+
const [s] = l.refs;
|
|
731
|
+
l.refs.length === 1 && V(s.path) === t.keptPath && me(s.xf) && !l.volumeRecords.length && e?.ready.has(s.objectid) ? (n.push({ index: l.index, built: e.ready.get(s.objectid), prebuilt: !0 }), e.ready.delete(s.objectid)) : i.push(l);
|
|
732
|
+
}
|
|
733
|
+
const a = [...n, ...Ct({ ...t, items: i }, r)];
|
|
734
|
+
return e.ready.clear(), { items: a };
|
|
735
|
+
}
|
|
736
|
+
async function ge(t, e, r, o, n) {
|
|
737
|
+
const i = /* @__PURE__ */ new Map(), a = new Array(r.size).fill(0), l = [], s = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Set();
|
|
738
|
+
let c = null, u = null;
|
|
739
|
+
const p = () => {
|
|
740
|
+
let S = 0;
|
|
741
|
+
for (let I = 1; I < r.size; I++) a[I] < a[S] && (S = I);
|
|
742
|
+
return S;
|
|
743
|
+
}, m = (S, I, A, T, v) => {
|
|
744
|
+
a[I] += T - A, l.push(r.scan(I, c.slice(A, T), { bake: o, objectId: S.id, complete: v }).catch(() => {
|
|
745
|
+
f.add(S.id), i.delete(S.id);
|
|
746
|
+
}));
|
|
747
|
+
}, w = await (r.inflate ?? ne)(t, e, (S, I) => {
|
|
748
|
+
S !== c && (c = S, u = ft(S));
|
|
749
|
+
for (const x of u.advance(I)) {
|
|
750
|
+
if (i.has(x.id) || f.has(x.id)) continue;
|
|
751
|
+
const y = s.get(x.id);
|
|
752
|
+
if (y) {
|
|
753
|
+
s.delete(x.id), i.set(x.id, y.slot), m(x, y.slot, y.sent, x.end, !0);
|
|
754
|
+
continue;
|
|
755
|
+
}
|
|
756
|
+
if (!x.hasMesh) continue;
|
|
757
|
+
const k = p();
|
|
758
|
+
i.set(x.id, k), m(x, k, x.start, x.end, !0);
|
|
759
|
+
}
|
|
760
|
+
const A = u.open();
|
|
761
|
+
if (!A?.id || !A.hasMesh || f.has(A.id)) return;
|
|
762
|
+
let T = s.get(A.id);
|
|
763
|
+
if (!T) {
|
|
764
|
+
if (I - A.start < n) return;
|
|
765
|
+
T = { slot: p(), sent: A.start }, s.set(A.id, T);
|
|
766
|
+
}
|
|
767
|
+
const v = S.subarray(0, I).lastIndexOf(62) + 1;
|
|
768
|
+
v - T.sent < n || (m(A, T.slot, T.sent, v, !1), T.sent = v);
|
|
769
|
+
});
|
|
770
|
+
return c !== w && (u = ft(w), u.advance(w.length)), { rootBytes: w, root: u.finish(), keptOn: i, scans: Promise.all(l) };
|
|
771
|
+
}
|
|
772
|
+
const Ft = (t) => Promise.all(t.map(de)), rt = (t) => typeof Blob < "u" && t instanceof Blob;
|
|
773
|
+
async function we(t) {
|
|
774
|
+
let e = null;
|
|
775
|
+
if (rt(t) ? e = await Qt(t) : e = Gt(t), !e) {
|
|
776
|
+
const i = /* @__PURE__ */ new Map();
|
|
777
|
+
let a = t;
|
|
778
|
+
rt(t) && (a = new Uint8Array(await t.arrayBuffer()));
|
|
779
|
+
const l = await ae(a);
|
|
780
|
+
for (const s of Object.keys(l)) i.set(V(s), l[s]);
|
|
781
|
+
return { names: [...i.keys()], entry: () => null, read: async (s) => i.get(s) ?? null, compressed: async () => null };
|
|
782
|
+
}
|
|
783
|
+
const r = /* @__PURE__ */ new Map();
|
|
784
|
+
for (const [i, a] of e) r.set(V(i), a);
|
|
785
|
+
const o = (i) => rt(t) ? t.slice(i.dataStart, i.dataStart + i.compressedSize) : Zt(t, i), n = /* @__PURE__ */ new Map();
|
|
786
|
+
return {
|
|
787
|
+
names: [...r.keys()],
|
|
788
|
+
entry: (i) => r.get(i) ?? null,
|
|
789
|
+
compressed: (i) => {
|
|
790
|
+
const a = r.get(i);
|
|
791
|
+
return a ? o(a) : null;
|
|
792
|
+
},
|
|
793
|
+
read: (i) => {
|
|
794
|
+
const a = r.get(i);
|
|
795
|
+
return a ? (n.has(i) || n.set(i, mt(o(a), a)), n.get(i)) : Promise.resolve(null);
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
const Rt = (t) => t.toLowerCase().endsWith(".model");
|
|
800
|
+
async function Pe(t, e = "model", { runJobs: r = Ft, bake: o = !1, pool: n = null, pieceBytes: i = he } = {}) {
|
|
801
|
+
try {
|
|
802
|
+
return await je(t, e, { runJobs: r, bake: o, pool: n, pieceBytes: i });
|
|
803
|
+
} finally {
|
|
804
|
+
n?.release();
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
async function je(t, e, { runJobs: r, bake: o, pool: n, pieceBytes: i }) {
|
|
808
|
+
let a = t;
|
|
809
|
+
ArrayBuffer.isView(t) ? a = new Uint8Array(t.buffer, t.byteOffset, t.byteLength) : rt(t) || (a = new Uint8Array(t));
|
|
810
|
+
const l = await we(a), s = new TextDecoder(), f = /* @__PURE__ */ new Map();
|
|
811
|
+
await Promise.all(l.names.filter((h) => !Rt(h)).map(async (h) => f.set(h, await l.read(h))));
|
|
812
|
+
let c = "3D/3dmodel.model";
|
|
813
|
+
const u = f.get("_rels/.rels");
|
|
814
|
+
if (u) {
|
|
815
|
+
for (const h of s.decode(u).match(/<Relationship\b[^>]*>/g) || [])
|
|
816
|
+
if ((H(h, "Type") || "").endsWith("/3dmodel")) {
|
|
817
|
+
c = V(H(h, "Target"));
|
|
818
|
+
break;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
const p = ue(f, s);
|
|
822
|
+
let m = null, g = null, w = /* @__PURE__ */ new Map(), S = Promise.resolve(), I = null;
|
|
823
|
+
const A = l.entry(c), T = r === Ft && !n;
|
|
824
|
+
if (n?.size > 1 && A ? { rootBytes: m, root: g, keptOn: w, scans: S } = await ge(l.compressed(c), A, n, o, i) : (m = await l.read(c), m && T ? g = I = et(m) : g = m && qt(m)), !g && p.gcodePlates) return { objects: [], project: p };
|
|
825
|
+
if (!g) throw new Error(`3MF root model not found: ${c}`);
|
|
826
|
+
const v = () => I ??= et(m);
|
|
827
|
+
let x = g.items;
|
|
828
|
+
if (!x.length) {
|
|
829
|
+
const h = v();
|
|
830
|
+
x = [...h.objects.keys()].filter((_) => h.objects.get(_).mesh).map((_) => ({ objectid: _, path: c, transform: ht }));
|
|
831
|
+
}
|
|
832
|
+
const y = (h) => {
|
|
833
|
+
const _ = /* @__PURE__ */ new Set(), M = (P, z) => {
|
|
834
|
+
if (z > 16 || _.has(P)) return;
|
|
835
|
+
const D = g.objects.get(P);
|
|
836
|
+
if (D) {
|
|
837
|
+
_.add(P);
|
|
838
|
+
for (const J of D.components) (!J.path || V(J.path) === c) && M(J.objectid, z + 1);
|
|
839
|
+
}
|
|
840
|
+
};
|
|
841
|
+
for (const P of h) V(P.path) === c && M(P.objectid, P.depth);
|
|
842
|
+
return _;
|
|
843
|
+
}, k = "\0root-object:", $ = [], N = /* @__PURE__ */ new Map(), d = [], O = [], E = (h) => {
|
|
844
|
+
const _ = p.volumeMeta.get(h);
|
|
845
|
+
if (_) return _;
|
|
846
|
+
const M = p.partVolumeMeta.get(h), P = g.objects.get(h)?.components ?? [];
|
|
847
|
+
return !M || P.length !== M.partIds.length ? [] : P.every((z, D) => z.objectid === M.partIds[D]) ? M.records : [];
|
|
848
|
+
}, j = (h) => {
|
|
849
|
+
const _ = x[h];
|
|
850
|
+
return { index: h, refs: [{ objectid: _.objectid, path: _.path || c, xf: _.transform, depth: 0 }], volumeRecords: E(_.objectid) };
|
|
851
|
+
};
|
|
852
|
+
x.forEach((h, _) => {
|
|
853
|
+
const M = h.path || c, P = E(h.objectid);
|
|
854
|
+
let z = [{ objectid: h.objectid, path: M, xf: h.transform, depth: 0 }];
|
|
855
|
+
if (V(M) === c) {
|
|
856
|
+
const L = g.objects.get(h.objectid);
|
|
857
|
+
L?.components?.length && (z = L.components.map((C) => ({ objectid: C.objectid, path: C.path || M, xf: Dt(C.transform, h.transform), depth: 1 })));
|
|
858
|
+
}
|
|
859
|
+
const D = [...new Set(z.map((L) => V(L.path)))].filter((L) => L !== c);
|
|
860
|
+
if (D.some((L) => !l.entry(L))) {
|
|
861
|
+
d.push(j(_));
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
864
|
+
if (w.size && !D.length) {
|
|
865
|
+
const L = [...y(z)], C = L.filter((W) => w.has(W)).map((W) => w.get(W));
|
|
866
|
+
if (C.length) {
|
|
867
|
+
const W = C[0], Mt = O[W] ??= { items: [], spans: /* @__PURE__ */ new Set() };
|
|
868
|
+
Mt.items.push({ index: _, refs: z, volumeRecords: P });
|
|
869
|
+
for (const _t of L) w.get(_t) !== W && Mt.spans.add(_t);
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
let J = [];
|
|
874
|
+
if (T || (J = [...y(z)].map((L) => k + L)), z.some((L) => V(L.path) === c) && !J.length) {
|
|
875
|
+
d.push(j(_));
|
|
876
|
+
return;
|
|
877
|
+
}
|
|
878
|
+
const tt = [...D, ...J];
|
|
879
|
+
let b = tt.map((L) => N.get(L)).find(Boolean);
|
|
880
|
+
b || (b = { parts: /* @__PURE__ */ new Set(), items: [] }, $.push(b));
|
|
881
|
+
for (const L of tt) {
|
|
882
|
+
const C = N.get(L);
|
|
883
|
+
if (C && C !== b) {
|
|
884
|
+
for (const W of C.parts)
|
|
885
|
+
b.parts.add(W), N.set(W, b);
|
|
886
|
+
b.items.push(...C.items), $.splice($.indexOf(C), 1);
|
|
887
|
+
}
|
|
888
|
+
b.parts.add(L), N.set(L, b);
|
|
889
|
+
}
|
|
890
|
+
b.items.push({ index: _, refs: z, volumeRecords: P });
|
|
891
|
+
});
|
|
892
|
+
const R = new Array(x.length).fill(null), nt = (h) => {
|
|
893
|
+
const _ = [...h].map((z) => g.objects.get(z)).filter(Boolean).sort((z, D) => z.start - D.start), M = new Uint8Array(_.reduce((z, D) => z + D.end - D.start, 0));
|
|
894
|
+
let P = 0;
|
|
895
|
+
for (const z of _)
|
|
896
|
+
M.set(m.subarray(z.start, z.end), P), P += z.end - z.start;
|
|
897
|
+
return { path: c, data: M, entry: { method: 0, size: M.length }, partial: !0 };
|
|
898
|
+
}, K = await Promise.all($.map(async (h) => {
|
|
899
|
+
const _ = [], M = [];
|
|
900
|
+
for (const P of h.parts) {
|
|
901
|
+
if (P.startsWith(k)) {
|
|
902
|
+
M.push(P.slice(k.length));
|
|
903
|
+
continue;
|
|
904
|
+
}
|
|
905
|
+
const z = l.entry(P), D = new Uint8Array(await new Blob([l.compressed(P)]).arrayBuffer());
|
|
906
|
+
_.push({ path: P, data: D, entry: { method: z.method, size: z.size } });
|
|
907
|
+
}
|
|
908
|
+
return M.length && _.push(nt(M)), { members: _, names: l.names, items: h.items, bake: o };
|
|
909
|
+
}));
|
|
910
|
+
K.sort((h, _) => _.members.reduce((M, P) => M + P.data.length, 0) - h.members.reduce((M, P) => M + P.data.length, 0)), await S;
|
|
911
|
+
const st = O.map((h, _) => {
|
|
912
|
+
if (!h) return null;
|
|
913
|
+
for (const P of h.items) for (const z of y(P.refs)) w.get(z) !== _ && h.spans.add(z);
|
|
914
|
+
const M = [];
|
|
915
|
+
return h.spans.size && M.push(nt(h.spans)), n.build(_, { members: M, names: l.names, items: h.items, bake: o, keptPath: c }).catch(() => ({ items: h.items.map((P) => ({ index: P.index, local: !0 })) }));
|
|
916
|
+
}).filter(Boolean), [at, $t] = await Promise.all([r(K), Promise.all(st)]);
|
|
917
|
+
for (const h of [...at, ...$t])
|
|
918
|
+
for (const _ of h.items)
|
|
919
|
+
_.local ? d.push(j(_.index)) : R[_.index] = _.built;
|
|
920
|
+
if (d.length) {
|
|
921
|
+
const h = /* @__PURE__ */ new Map([[c, v()]]);
|
|
922
|
+
for (const M of l.names) Rt(M) && M !== c && h.set(M, et(await l.read(M)));
|
|
923
|
+
const _ = (M) => h.get(V(M)) ?? null;
|
|
924
|
+
for (const M of d) R[M.index] = wt(gt(M.refs, _), M.volumeRecords, o);
|
|
925
|
+
}
|
|
926
|
+
const jt = [];
|
|
927
|
+
return x.forEach((h, _) => {
|
|
928
|
+
const M = R[_];
|
|
929
|
+
if (!M) return;
|
|
930
|
+
const P = (p.sla.supportPoints.get(_ + 1) || []).map((b) => ({ ...b, position: Tt(h.transform, b.position) })), z = (p.sla.drainHoles.get(_ + 1) || []).map((b) => ({
|
|
931
|
+
...b,
|
|
932
|
+
position: Tt(h.transform, b.position),
|
|
933
|
+
normal: fe(h.transform, b.normal)
|
|
934
|
+
})), D = M.modifiers.map(({ volume: b, kind: L, tris: C }) => ({ id: `${h.objectid}:modifier:${b}`, kind: L, tris: C }));
|
|
935
|
+
let J = e;
|
|
936
|
+
x.length > 1 && (J = `${e}#${_ + 1}`);
|
|
937
|
+
const tt = { name: J, tris: M.tris, objectid: h.objectid, paint: M.paint, sla: { supportPoints: P, drainHoles: z, modifierVolumes: D }, bbox: M.bbox };
|
|
938
|
+
M.baked && (tt.baked = M.baked), jt.push(tt);
|
|
939
|
+
}), { objects: jt, project: p };
|
|
940
|
+
}
|
|
941
|
+
export {
|
|
942
|
+
de as a,
|
|
943
|
+
te as b,
|
|
944
|
+
Oe as c,
|
|
945
|
+
se as d,
|
|
946
|
+
re as e,
|
|
947
|
+
ee as i,
|
|
948
|
+
Pe as p,
|
|
949
|
+
Ie as r,
|
|
950
|
+
Se as s
|
|
951
|
+
};
|