three-slicer-viewer 0.3.1 → 0.3.3

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.
@@ -1,300 +0,0 @@
1
- import { unzip as Y, unzipSync as U } from "three/examples/jsm/libs/fflate.module.js";
2
- import { S as W } from "./viewer_defaults-B7UUZ582.js";
3
- function q(t) {
4
- return new Promise((n) => {
5
- let o = !1;
6
- const e = (r) => {
7
- o || (o = !0, n(r));
8
- };
9
- try {
10
- Y(t, (r, i) => e(r ? U(t) : i));
11
- } catch {
12
- e(U(t));
13
- }
14
- });
15
- }
16
- const F = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0];
17
- function K(t, n) {
18
- const o = new Array(12);
19
- for (let e = 0; e < 4; e++)
20
- for (let r = 0; r < 3; r++)
21
- o[e * 3 + r] = t[e * 3] * n[r] + t[e * 3 + 1] * n[3 + r] + t[e * 3 + 2] * n[6 + r] + (e === 3 ? n[9 + r] : 0);
22
- return o;
23
- }
24
- function B(t) {
25
- if (!t) return F;
26
- const n = t.trim().split(/\s+/).map(Number);
27
- return n.length === 12 && n.every(Number.isFinite) ? n : F;
28
- }
29
- const C = {};
30
- function p(t, n) {
31
- const e = (C[n] || (C[n] = new RegExp(`\\b${n}\\s*=\\s*"([^"]*)"`))).exec(t);
32
- return e ? e[1] : null;
33
- }
34
- const D = /<vertex\s+x="([^"]*)"\s+y="([^"]*)"\s+z="([^"]*)"/g, V = /<triangle\s+v1="([^"]*)"\s+v2="([^"]*)"\s+v3="([^"]*)"([^>]*)/g, $ = [
35
- ["paint_color", "color"],
36
- // multi-material: state 1..16 == Extruder1..16
37
- ["paint_supports", "supports"],
38
- // support enforcer/blocker: states 1 and 2
39
- ["paint_seam", "seam"],
40
- // unsupported by the kernel — collected for the warning only
41
- ["paint_fuzzy_skin", "fuzzy"]
42
- // ditto
43
- ];
44
- function G() {
45
- return { color: /* @__PURE__ */ new Map(), supports: /* @__PURE__ */ new Map(), seam: /* @__PURE__ */ new Map(), fuzzy: /* @__PURE__ */ new Map() };
46
- }
47
- function Q(t) {
48
- return !t || $.every(([, n]) => t[n].size === 0);
49
- }
50
- function x(t, n, o) {
51
- for (const [e, r] of $) {
52
- if (!t.includes(e)) continue;
53
- const i = p(t, e);
54
- i && o[r].set(n, i);
55
- }
56
- }
57
- function Z(t) {
58
- const n = [];
59
- D.lastIndex = 0;
60
- let o;
61
- for (; o = D.exec(t); ) n.push(+o[1], +o[2], +o[3]);
62
- if (!n.length)
63
- for (const i of t.match(/<vertex\b[^>]*>/g) || []) n.push(+p(i, "x"), +p(i, "y"), +p(i, "z"));
64
- if (n.length < 9) return null;
65
- const e = [], r = G();
66
- for (V.lastIndex = 0; o = V.exec(t); ) {
67
- const i = e.length / 3;
68
- e.push(+o[1], +o[2], +o[3]), o[4].length > 2 && x(o[4], i, r);
69
- }
70
- if (!e.length)
71
- for (const i of t.match(/<triangle\b[^>]*>/g) || []) {
72
- const s = e.length / 3;
73
- e.push(+p(i, "v1"), +p(i, "v2"), +p(i, "v3")), x(i, s, r);
74
- }
75
- return e.length ? { verts: n, tris: e, paint: r } : null;
76
- }
77
- function tt(t) {
78
- const n = /* @__PURE__ */ new Map(), o = /<object\b([^>]*)>([\s\S]*?)<\/object>/g;
79
- let e;
80
- for (; e = o.exec(t); ) {
81
- const s = p(e[1], "id");
82
- if (!s) continue;
83
- const c = e[2], d = [];
84
- for (const f of c.match(/<component\b[^>]*>/g) || []) {
85
- const u = p(f, "objectid");
86
- u && d.push({ objectid: u, path: p(f, "p:path") || p(f, "path"), transform: B(p(f, "transform")) });
87
- }
88
- n.set(s, d.length ? { components: d } : { mesh: Z(c) });
89
- }
90
- const r = [], i = /<build\b[^>]*>([\s\S]*?)<\/build>/.exec(t);
91
- if (i)
92
- for (const s of i[1].match(/<item\b[^>]*>/g) || []) {
93
- const c = p(s, "objectid");
94
- c && r.push({ objectid: c, path: p(s, "p:path") || p(s, "path"), transform: B(p(s, "transform")) });
95
- }
96
- return { objects: n, items: r };
97
- }
98
- function O(t) {
99
- const n = String(t).replace(/^\/+/, "");
100
- return n.includes("%") ? decodeURIComponent(n) : n;
101
- }
102
- function L(t) {
103
- const n = {};
104
- for (const o of t.match(/<metadata\b[^>]*>/g) || []) {
105
- const e = p(o, "key");
106
- e && (n[e] = p(o, "value") ?? "");
107
- }
108
- return n;
109
- }
110
- function et(t) {
111
- const n = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), e = /<object\b([^>]*)>([\s\S]*?)<\/object>/g;
112
- let r;
113
- for (; r = e.exec(t); ) {
114
- const c = p(r[1], "id");
115
- if (c) {
116
- const d = r[2];
117
- n.set(c, L(d.replace(/<(?:part|volume)\b[\s\S]*?<\/(?:part|volume)>/g, "")));
118
- const f = [];
119
- for (const u of d.match(/<volume\b[\s\S]*?<\/volume>/g) || []) {
120
- const _ = L(u).volume_type, y = _ === "SupportBlocker" ? "blocker" : _ === "SupportEnforcer" ? "enforcer" : null, j = Number(p(u, "firstid")), S = Number(p(u, "lastid"));
121
- y && Number.isInteger(j) && Number.isInteger(S) && j >= 0 && S >= j && f.push({ firstTriangle: j, lastTriangle: S, kind: y });
122
- }
123
- f.length && o.set(c, f);
124
- }
125
- }
126
- const i = [], s = /<plate\b[^>]*>([\s\S]*?)<\/plate>/g;
127
- for (; r = s.exec(t); ) {
128
- const c = r[1], d = L(c.replace(/<model_instance\b[\s\S]*?<\/model_instance>/g, "")), f = [];
129
- for (const u of c.match(/<model_instance\b[\s\S]*?<\/model_instance>/g) || []) {
130
- const _ = L(u).object_id;
131
- _ && f.push(_);
132
- }
133
- i.push({ index: Math.max(0, (Number(d.plater_id) || i.length + 1) - 1), objectIds: f });
134
- }
135
- return { objects: n, plates: i, volumes: o };
136
- }
137
- const nt = Object.freeze({
138
- manualSupportPoints: "prepared-roundtrip",
139
- drainHoles: "preserved-unsupported",
140
- modifierVolumes: "prepared-mask-filtering",
141
- uiEditing: "unavailable"
142
- });
143
- function J(t, n, o, e, r) {
144
- const i = /* @__PURE__ */ new Map();
145
- if (!t?.trim()) return i;
146
- const s = t.trim().split(/\r?\n/), c = new RegExp(`^${n}_format_version=(\\d+)$`).exec(s[0]), d = c ? Number(c[1]) : 0;
147
- for (const f of s.slice(c ? 1 : 0)) {
148
- const u = /^object_id=(\d+)\|(.*)$/.exec(f);
149
- if (!u || i.has(Number(u?.[1]))) continue;
150
- const _ = Number(u[1]), y = u[2].trim() ? u[2].trim().split(/\s+/).map(Number) : [], j = o(d);
151
- if (!j || y.length % j !== 0 || y.some((a) => !Number.isFinite(a))) {
152
- e.push({ code: n === "support_points" ? "SLA_SUPPORT_POINT_COUNT" : "SLA_DRAIN_HOLE_COUNT", object: _ }), i.set(_, []);
153
- continue;
154
- }
155
- const S = [];
156
- for (let a = 0; a < y.length; a += j) S.push(r(y.slice(a, a + j), d));
157
- i.set(_, S);
158
- }
159
- return i;
160
- }
161
- function X(t, n) {
162
- const [o, e, r] = n;
163
- return [o * t[0] + e * t[3] + r * t[6] + t[9], o * t[1] + e * t[4] + r * t[7] + t[10], o * t[2] + e * t[5] + r * t[8] + t[11]];
164
- }
165
- function ot(t, n) {
166
- const [o, e, r] = n, i = [o * t[0] + e * t[3] + r * t[6], o * t[1] + e * t[4] + r * t[7], o * t[2] + e * t[5] + r * t[8]], s = Math.hypot(...i);
167
- return s ? i.map((c) => c / s) : i;
168
- }
169
- function st(t, n) {
170
- const o = (s) => {
171
- const c = t.get(s);
172
- return c ? n.decode(c) : null;
173
- }, e = {
174
- settings: null,
175
- // Metadata/project_settings.config — the flattened preset (raw upstream strings)
176
- objectMeta: /* @__PURE__ */ new Map(),
177
- // 3mf object id -> per-object metadata (name, extruder, per-object overrides)
178
- plates: [],
179
- // [{index, objectIds}]
180
- hasLayerHeightProfile: !1,
181
- hasCustomGcodePerLayer: !1,
182
- volumeMeta: /* @__PURE__ */ new Map(),
183
- sla: { capabilities: { ...nt }, issues: [], supportPoints: /* @__PURE__ */ new Map(), drainHoles: /* @__PURE__ */ new Map() }
184
- }, r = o("Metadata/project_settings.config");
185
- if (r)
186
- try {
187
- e.settings = JSON.parse(r);
188
- } catch {
189
- e.settings = null;
190
- }
191
- const i = o("Metadata/model_settings.config");
192
- if (i) {
193
- const s = et(i);
194
- e.objectMeta = s.objects, e.plates = s.plates, e.volumeMeta = s.volumes;
195
- }
196
- return e.sla.supportPoints = J(
197
- o("Metadata/Slic3r_PE_sla_support_points.txt"),
198
- "support_points",
199
- (s) => s === 0 ? 3 : s === 1 ? 5 : 0,
200
- e.sla.issues,
201
- (s, c) => ({
202
- position: s.slice(0, 3),
203
- radius: c === 0 ? W : s[3],
204
- type: c === 0 || s[4] === 2 ? "manual" : s[4] === 1 ? "island" : "slope"
205
- })
206
- ), e.sla.drainHoles = J(
207
- o("Metadata/Slic3r_PE_sla_drain_holes.txt"),
208
- "drain_holes",
209
- (s) => s === 1 ? 8 : 0,
210
- e.sla.issues,
211
- (s) => {
212
- const c = Math.hypot(s[3], s[4], s[5]), d = c ? s.slice(3, 6).map((f) => f / c) : s.slice(3, 6);
213
- return { position: s.slice(0, 3).map((f, u) => f + d[u]), normal: d, radius: s[6], height: s[7] - 1 };
214
- }
215
- ), e.hasLayerHeightProfile = !!o("Metadata/layer_heights_profile.txt")?.trim(), e.hasCustomGcodePerLayer = !!o("Metadata/custom_gcode_per_layer.xml")?.trim(), e;
216
- }
217
- async function ct(t, n = "model") {
218
- const o = ArrayBuffer.isView(t) ? new Uint8Array(t.buffer, t.byteOffset, t.byteLength) : new Uint8Array(t), e = await q(o), r = /* @__PURE__ */ new Map();
219
- for (const a of Object.keys(e)) r.set(O(a), e[a]);
220
- const i = new TextDecoder(), s = /* @__PURE__ */ new Map(), c = (a) => {
221
- const w = O(a);
222
- if (s.has(w)) return s.get(w);
223
- const l = r.get(w), M = l ? tt(i.decode(l)) : null;
224
- return s.set(w, M), M;
225
- };
226
- let d = "3D/3dmodel.model";
227
- const f = r.get("_rels/.rels");
228
- if (f) {
229
- for (const a of i.decode(f).match(/<Relationship\b[^>]*>/g) || [])
230
- if ((p(a, "Type") || "").endsWith("/3dmodel")) {
231
- d = O(p(a, "Target"));
232
- break;
233
- }
234
- }
235
- const u = c(d);
236
- if (!u) throw new Error(`3MF root model not found: ${d}`);
237
- const _ = [], y = st(r, i), j = (a, w, l, M, P, N) => {
238
- if (N > 16) return;
239
- const T = c(w)?.objects.get(a);
240
- if (!T) return;
241
- if (T.components) {
242
- for (const b of T.components) j(b.objectid, b.path || w, K(b.transform, l), M, P, N + 1);
243
- return;
244
- }
245
- if (!T.mesh) return;
246
- const { verts: z, tris: I, paint: A } = T.mesh, E = M.length / 9;
247
- for (let b = 0; b < I.length; b++) {
248
- const m = I[b] * 3, g = z[m], h = z[m + 1], v = z[m + 2];
249
- M.push(
250
- g * l[0] + h * l[3] + v * l[6] + l[9],
251
- g * l[1] + h * l[4] + v * l[7] + l[10],
252
- g * l[2] + h * l[5] + v * l[8] + l[11]
253
- );
254
- }
255
- if (A) for (const [, b] of $)
256
- for (const [m, g] of A[b]) P[b].set(E + m, g);
257
- }, S = u.items.length ? u.items : [...u.objects.keys()].filter((a) => u.objects.get(a).mesh).map((a) => ({ objectid: a, path: d, transform: F }));
258
- return S.forEach((a, w) => {
259
- const l = [], M = G();
260
- if (j(a.objectid, a.path || d, a.transform, l, M, 0), l.length < 9) return;
261
- let P = new Float32Array(l);
262
- const N = [], R = y.volumeMeta.get(a.objectid) || [];
263
- if (R.length) {
264
- const m = /* @__PURE__ */ new Set();
265
- for (let g = 0; g < R.length; g++) {
266
- const h = R[g], v = h.firstTriangle * 9, H = Math.min(l.length, (h.lastTriangle + 1) * 9);
267
- if (!(v >= H)) {
268
- for (let k = h.firstTriangle; k <= h.lastTriangle; k++) m.add(k);
269
- N.push({ id: `${a.objectid}:modifier:${g}`, kind: h.kind, tris: new Float32Array(l.slice(v, H)) });
270
- }
271
- }
272
- if (m.size) {
273
- const g = [];
274
- for (let h = 0; h < l.length / 9; h++) m.has(h) || g.push(...l.slice(h * 9, h * 9 + 9));
275
- P = new Float32Array(g);
276
- }
277
- }
278
- const T = (y.sla.supportPoints.get(w + 1) || []).map((m) => ({ ...m, position: X(a.transform, m.position) })), z = (y.sla.drainHoles.get(w + 1) || []).map((m) => ({
279
- ...m,
280
- position: X(a.transform, m.position),
281
- normal: ot(a.transform, m.normal)
282
- }));
283
- let I = 1 / 0, A = 1 / 0, E = -1 / 0, b = -1 / 0;
284
- for (let m = 0; m < P.length; m += 3) {
285
- const g = P[m], h = P[m + 1];
286
- g < I && (I = g), g > E && (E = g), h < A && (A = h), h > b && (b = h);
287
- }
288
- _.push({
289
- name: S.length > 1 ? `${n}#${w + 1}` : n,
290
- tris: P,
291
- objectid: a.objectid,
292
- paint: Q(M) ? null : M,
293
- sla: { supportPoints: T, drainHoles: z, modifierVolumes: N },
294
- bbox: { minX: I, minY: A, maxX: E, maxY: b }
295
- });
296
- }), { objects: _, project: y };
297
- }
298
- export {
299
- ct as p
300
- };