three-slicer-viewer 0.3.1 → 0.3.2

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,188 +0,0 @@
1
- import * as x from "three";
2
- import { OBJLoader as S } from "three/examples/jsm/loaders/OBJLoader.js";
3
- import { PLYLoader as v } from "three/examples/jsm/loaders/PLYLoader.js";
4
- import { AMFLoader as P } from "three/examples/jsm/loaders/AMFLoader.js";
5
- import { p as T } from "./parse_3mf-jEUAw8JM.js";
6
- import { makeParse3mfWorker as B } from "./make_worker.js";
7
- const W = 80, M = 84, _ = 50, $ = (t) => M + t * _;
8
- let g = null, E = !1, b = 0;
9
- const h = /* @__PURE__ */ new Map();
10
- function D() {
11
- if (E || typeof Worker > "u") return null;
12
- if (g) return g;
13
- try {
14
- g = B(), g.onmessage = (t) => {
15
- const { id: r, objects: s, project: o, error: n } = t.data || {}, i = h.get(r);
16
- i && (h.delete(r), n ? i.reject(new Error(n)) : i.resolve({ objects: s, project: o }));
17
- }, g.onerror = () => {
18
- E = !0;
19
- for (const [, t] of h) t.reject(new Error("3MF parse worker failed"));
20
- h.clear(), g = null;
21
- };
22
- } catch {
23
- E = !0, g = null;
24
- }
25
- return g;
26
- }
27
- async function I(t, r) {
28
- const s = D();
29
- if (!s) return T(t, r);
30
- try {
31
- const o = ++b, n = new Promise((i, c) => h.set(o, { resolve: i, reject: c }));
32
- return s.postMessage({ id: o, buffer: t, baseName: r }), await n;
33
- } catch {
34
- return T(t, r);
35
- }
36
- }
37
- const L = ["stl", "obj", "3mf", "amf", "ply"], j = /* @__PURE__ */ new Map();
38
- function H(t, r) {
39
- for (const s of (Array.isArray(t) ? t : String(t).split(",")).map((o) => o.trim().toLowerCase()))
40
- j.set(s, r), L.includes(s) || L.push(s);
41
- }
42
- function O(t) {
43
- const r = t.lastIndexOf(".");
44
- return r < 0 ? "" : t.slice(r + 1).toLowerCase();
45
- }
46
- function R(t) {
47
- const r = new DataView(t);
48
- if (t.byteLength >= M) {
49
- const c = r.getUint32(W, !0);
50
- if (t.byteLength === $(c)) {
51
- const l = new Float32Array(c * 9);
52
- let f = M, u = 0;
53
- for (let y = 0; y < c; y++) {
54
- f += 12;
55
- for (let e = 0; e < 3; e++)
56
- l[u++] = r.getFloat32(f, !0), l[u++] = r.getFloat32(f + 4, !0), l[u++] = r.getFloat32(f + 8, !0), f += 12;
57
- f += 2;
58
- }
59
- return l;
60
- }
61
- }
62
- const s = new TextDecoder().decode(t), o = /vertex\s+([-\d.eE+]+)\s+([-\d.eE+]+)\s+([-\d.eE+]+)/g, n = [];
63
- let i;
64
- for (; i = o.exec(s); ) n.push(+i[1], +i[2], +i[3]);
65
- return n.length < 9 ? null : new Float32Array(n);
66
- }
67
- function k(t, r) {
68
- const s = t?.attributes?.position;
69
- if (!s || s.count < 3) return null;
70
- const o = t.index, n = new x.Vector3(), i = Math.floor((o ? o.count : s.count) / 3), c = new Float32Array(i * 9);
71
- let l = 0;
72
- const f = (u) => {
73
- n.fromBufferAttribute(s, u), r && n.applyMatrix4(r), c[l++] = n.x, c[l++] = n.y, c[l++] = n.z;
74
- };
75
- if (o)
76
- for (let u = 0; u < i * 3; u++) f(o.getX(u));
77
- else
78
- for (let u = 0; u < i * 3; u++) f(u);
79
- return c;
80
- }
81
- function A(t) {
82
- t.updateMatrixWorld(!0);
83
- const r = [];
84
- return t.traverse((s) => {
85
- s.isMesh && s.geometry && r.push({ geometry: s.geometry, matrix: s.matrixWorld });
86
- }), r;
87
- }
88
- function F(t, r, s) {
89
- const o = r.map((l) => k(l.geometry, l.matrix)).filter(Boolean);
90
- if (!o.length) return [];
91
- if (s && o.length > 1)
92
- return o.map((l, f) => ({ name: `${t}#${f + 1}`, modelPos: l }));
93
- if (o.length === 1) return [{ name: t, modelPos: o[0] }];
94
- let n = 0;
95
- for (const l of o) n += l.length;
96
- const i = new Float32Array(n);
97
- let c = 0;
98
- for (const l of o)
99
- i.set(l, c), c += l.length;
100
- return [{ name: t, modelPos: i }];
101
- }
102
- async function V(t, r) {
103
- const s = O(t);
104
- switch (s) {
105
- case "stl": {
106
- const o = R(r);
107
- if (!o) throw new Error("Failed to parse STL");
108
- return [{ name: t, modelPos: o }];
109
- }
110
- case "obj": {
111
- const o = new S().parse(new TextDecoder().decode(r));
112
- return F(t, A(o), !1);
113
- }
114
- case "ply": {
115
- const o = new v().parse(r), n = k(o, null);
116
- if (!n) throw new Error("No PLY geometry");
117
- return [{ name: t, modelPos: n }];
118
- }
119
- case "3mf": {
120
- const { objects: o, project: n } = await I(r, t), i = o.map((c) => ({ name: c.name, modelPos: c.tris, objectid: c.objectid, paint: c.paint, bbox: c.bbox, project: n }));
121
- if (!i.length) throw new Error("No mesh in 3MF");
122
- return i;
123
- }
124
- case "amf": {
125
- const o = new P().parse(r), n = F(t, A(o), !0);
126
- if (!n.length) throw new Error("No mesh in AMF");
127
- return n;
128
- }
129
- default: {
130
- const o = j.get(s);
131
- if (!o) throw new Error(`Unsupported format: .${s}`);
132
- const n = await o(r, t);
133
- if (!n?.length) throw new Error(`No mesh in .${s}`);
134
- return n;
135
- }
136
- }
137
- }
138
- function X(t) {
139
- const r = Math.floor(t.length / 9);
140
- if (r < 2) return null;
141
- const s = 1e4, o = /* @__PURE__ */ new Map(), n = new Int32Array(r * 3);
142
- for (let e = 0; e < r; e++)
143
- for (let a = 0; a < 3; a++) {
144
- const p = e * 9 + a * 3, m = `${Math.round(t[p] * s)},${Math.round(t[p + 1] * s)},${Math.round(t[p + 2] * s)}`;
145
- let d = o.get(m);
146
- d === void 0 && (d = o.size, o.set(m, d)), n[e * 3 + a] = d;
147
- }
148
- const i = new Int32Array(r);
149
- for (let e = 0; e < r; e++) i[e] = e;
150
- const c = (e) => {
151
- for (; i[e] !== e; )
152
- i[e] = i[i[e]], e = i[e];
153
- return e;
154
- }, l = (e, a) => {
155
- e = c(e), a = c(a), e !== a && (i[a] = e);
156
- }, f = /* @__PURE__ */ new Map();
157
- for (let e = 0; e < r; e++)
158
- for (let a = 0; a < 3; a++) {
159
- const p = n[e * 3 + a], m = n[e * 3 + (a + 1) % 3], d = p < m ? p * 4294967296 + m : m * 4294967296 + p, w = f.get(d);
160
- w === void 0 ? f.set(d, e) : l(e, w);
161
- }
162
- const u = /* @__PURE__ */ new Map();
163
- for (let e = 0; e < r; e++) {
164
- const a = c(e);
165
- let p = u.get(a);
166
- p || (p = [], u.set(a, p)), p.push(e);
167
- }
168
- return u.size < 2 ? null : [...u.values()].sort((e, a) => a.length - e.length).map((e) => {
169
- const a = new Float32Array(e.length * 9);
170
- let p = 0;
171
- for (const m of e) {
172
- const d = m * 9;
173
- for (let w = 0; w < 9; w++) a[p++] = t[d + w];
174
- }
175
- return a;
176
- });
177
- }
178
- export {
179
- W as S,
180
- M as a,
181
- _ as b,
182
- L as c,
183
- X as d,
184
- O as f,
185
- V as l,
186
- H as r,
187
- $ as s
188
- };
@@ -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
- };