three-slicer-viewer 0.2.5
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/COMPONENTS.md +44 -0
- package/LICENSE +21 -0
- package/README.md +77 -0
- package/THIRD-PARTY-NOTICES.md +19 -0
- package/TOOLPATH_SPEC.md +173 -0
- package/VIEWER.md +423 -0
- package/data/config-schema-lean.json +1 -0
- package/data/preset-keys.json +1 -0
- package/data/ui-tree-keys.json +1 -0
- package/dist/components.js +206 -0
- package/dist/gcode_parse.js +190 -0
- package/dist/index.js +6416 -0
- package/dist/make_worker.js +26 -0
- package/dist/model_loaders.js +183 -0
- package/dist/parse_3mf-CQ5rAX6P.js +299 -0
- package/dist/parse_3mf.worker.js +10 -0
- package/dist/sl1_encode.worker.js +10 -0
- package/dist/sl1_write-CvrNejbW.js +302 -0
- package/dist/sla_reconstruct-CXkYhux2.js +176 -0
- package/dist/sla_reconstruct.worker.js +24 -0
- package/dist/sla_slice.worker.js +73 -0
- package/dist/toolpath.js +408 -0
- package/package.json +83 -0
- package/src/data.js +2 -0
- package/src/settings/data.js +6 -0
- package/src/settings/index.js +2 -0
- package/src/settings/kernel_setting_keys.js +132 -0
- package/src/settings/preset_file.js +99 -0
- package/src/settings/settings_core.js +638 -0
- package/src/settings/toggle_eval.js +90 -0
- package/types/components.d.ts +39 -0
- package/types/data.d.ts +3 -0
- package/types/gcode.d.ts +29 -0
- package/types/index.d.ts +7 -0
- package/types/loaders.d.ts +33 -0
- package/types/settings-keys.d.ts +1855 -0
- package/types/settings.d.ts +173 -0
- package/types/toggle.d.ts +30 -0
- package/types/toolpath.d.ts +138 -0
- package/types/viewer.d.ts +256 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Worker factories for this package's own workers — this file is NOT bundled; the build copies it verbatim into
|
|
2
|
+
// dist/. For consumer bundlers (Vite/webpack) to recognise a worker as a chunk, the static
|
|
3
|
+
// `new Worker(new URL('literal', import.meta.url))` pattern must survive in a file the consumer sees. Every URL
|
|
4
|
+
// here is dist-relative: each worker is a lib entry of this package's build and lands beside this file.
|
|
5
|
+
// The SLICER worker is not here — it belongs to the AGPL package, which keeps its own make_worker.js.
|
|
6
|
+
// 3MF parsing worker. Unlike the slicer worker this one points INTO dist/ — the viewer's `src/` is not published
|
|
7
|
+
// (packages/package.json `files` ships `viewer/dist` only), so the worker is a lib entry of the viewer's own build
|
|
8
|
+
// and lands beside this file. The static `new Worker(new URL(…))` pattern is what matters either way.
|
|
9
|
+
export function makeParse3mfWorker() {
|
|
10
|
+
return new Worker(new URL('./parse_3mf.worker.js', import.meta.url), { type: 'module' })
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// SL1 mesh-reconstruction workers — same dist-relative story as the 3mf parser above. The pipeline is N slice
|
|
14
|
+
// producers (PNG -> occupancy) feeding one nets consumer; see sla_slice.worker.js for why it splits there.
|
|
15
|
+
export function makeSlaReconstructWorker() {
|
|
16
|
+
return new Worker(new URL('./sla_reconstruct.worker.js', import.meta.url), { type: 'module' })
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function makeSlaSliceWorker() {
|
|
20
|
+
return new Worker(new URL('./sla_slice.worker.js', import.meta.url), { type: 'module' })
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// SL1 export encoder — the write-side counterpart of the slice workers above, same dist-relative story.
|
|
24
|
+
export function makeSl1EncodeWorker() {
|
|
25
|
+
return new Worker(new URL('./sl1_encode.worker.js', import.meta.url), { type: 'module' })
|
|
26
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import * as L from "three";
|
|
2
|
+
import { OBJLoader as T } 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 E } from "./parse_3mf-CQ5rAX6P.js";
|
|
6
|
+
import { makeParse3mfWorker as W } from "./make_worker.js";
|
|
7
|
+
let w = null, M = !1, $ = 0;
|
|
8
|
+
const h = /* @__PURE__ */ new Map();
|
|
9
|
+
function b() {
|
|
10
|
+
if (M || typeof Worker > "u") return null;
|
|
11
|
+
if (w) return w;
|
|
12
|
+
try {
|
|
13
|
+
w = W(), w.onmessage = (t) => {
|
|
14
|
+
const { id: r, objects: s, project: o, error: n } = t.data || {}, i = h.get(r);
|
|
15
|
+
i && (h.delete(r), n ? i.reject(new Error(n)) : i.resolve({ objects: s, project: o }));
|
|
16
|
+
}, w.onerror = () => {
|
|
17
|
+
M = !0;
|
|
18
|
+
for (const [, t] of h) t.reject(new Error("3MF parse worker failed"));
|
|
19
|
+
h.clear(), w = null;
|
|
20
|
+
};
|
|
21
|
+
} catch {
|
|
22
|
+
M = !0, w = null;
|
|
23
|
+
}
|
|
24
|
+
return w;
|
|
25
|
+
}
|
|
26
|
+
async function B(t, r) {
|
|
27
|
+
const s = b();
|
|
28
|
+
if (!s) return E(t, r);
|
|
29
|
+
try {
|
|
30
|
+
const o = ++$, n = new Promise((i, c) => h.set(o, { resolve: i, reject: c }));
|
|
31
|
+
return s.postMessage({ id: o, buffer: t, baseName: r }), await n;
|
|
32
|
+
} catch {
|
|
33
|
+
return E(t, r);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const j = ["stl", "obj", "3mf", "amf", "ply"], x = /* @__PURE__ */ new Map();
|
|
37
|
+
function R(t, r) {
|
|
38
|
+
for (const s of (Array.isArray(t) ? t : String(t).split(",")).map((o) => o.trim().toLowerCase()))
|
|
39
|
+
x.set(s, r), j.includes(s) || j.push(s);
|
|
40
|
+
}
|
|
41
|
+
function C(t) {
|
|
42
|
+
const r = t.lastIndexOf(".");
|
|
43
|
+
return r < 0 ? "" : t.slice(r + 1).toLowerCase();
|
|
44
|
+
}
|
|
45
|
+
function D(t) {
|
|
46
|
+
const r = new DataView(t);
|
|
47
|
+
if (t.byteLength >= 84) {
|
|
48
|
+
const c = r.getUint32(80, !0);
|
|
49
|
+
if (t.byteLength === 84 + c * 50) {
|
|
50
|
+
const a = new Float32Array(c * 9);
|
|
51
|
+
let f = 84, u = 0;
|
|
52
|
+
for (let y = 0; y < c; y++) {
|
|
53
|
+
f += 12;
|
|
54
|
+
for (let e = 0; e < 3; e++)
|
|
55
|
+
a[u++] = r.getFloat32(f, !0), a[u++] = r.getFloat32(f + 4, !0), a[u++] = r.getFloat32(f + 8, !0), f += 12;
|
|
56
|
+
f += 2;
|
|
57
|
+
}
|
|
58
|
+
return a;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const s = new TextDecoder().decode(t), o = /vertex\s+([-\d.eE+]+)\s+([-\d.eE+]+)\s+([-\d.eE+]+)/g, n = [];
|
|
62
|
+
let i;
|
|
63
|
+
for (; i = o.exec(s); ) n.push(+i[1], +i[2], +i[3]);
|
|
64
|
+
return n.length < 9 ? null : new Float32Array(n);
|
|
65
|
+
}
|
|
66
|
+
function A(t, r) {
|
|
67
|
+
const s = t?.attributes?.position;
|
|
68
|
+
if (!s || s.count < 3) return null;
|
|
69
|
+
const o = t.index, n = new L.Vector3(), i = Math.floor((o ? o.count : s.count) / 3), c = new Float32Array(i * 9);
|
|
70
|
+
let a = 0;
|
|
71
|
+
const f = (u) => {
|
|
72
|
+
n.fromBufferAttribute(s, u), r && n.applyMatrix4(r), c[a++] = n.x, c[a++] = n.y, c[a++] = n.z;
|
|
73
|
+
};
|
|
74
|
+
if (o)
|
|
75
|
+
for (let u = 0; u < i * 3; u++) f(o.getX(u));
|
|
76
|
+
else
|
|
77
|
+
for (let u = 0; u < i * 3; u++) f(u);
|
|
78
|
+
return c;
|
|
79
|
+
}
|
|
80
|
+
function F(t) {
|
|
81
|
+
t.updateMatrixWorld(!0);
|
|
82
|
+
const r = [];
|
|
83
|
+
return t.traverse((s) => {
|
|
84
|
+
s.isMesh && s.geometry && r.push({ geometry: s.geometry, matrix: s.matrixWorld });
|
|
85
|
+
}), r;
|
|
86
|
+
}
|
|
87
|
+
function k(t, r, s) {
|
|
88
|
+
const o = r.map((a) => A(a.geometry, a.matrix)).filter(Boolean);
|
|
89
|
+
if (!o.length) return [];
|
|
90
|
+
if (s && o.length > 1)
|
|
91
|
+
return o.map((a, f) => ({ name: `${t}#${f + 1}`, modelPos: a }));
|
|
92
|
+
if (o.length === 1) return [{ name: t, modelPos: o[0] }];
|
|
93
|
+
let n = 0;
|
|
94
|
+
for (const a of o) n += a.length;
|
|
95
|
+
const i = new Float32Array(n);
|
|
96
|
+
let c = 0;
|
|
97
|
+
for (const a of o)
|
|
98
|
+
i.set(a, c), c += a.length;
|
|
99
|
+
return [{ name: t, modelPos: i }];
|
|
100
|
+
}
|
|
101
|
+
async function U(t, r) {
|
|
102
|
+
const s = C(t);
|
|
103
|
+
switch (s) {
|
|
104
|
+
case "stl": {
|
|
105
|
+
const o = D(r);
|
|
106
|
+
if (!o) throw new Error("Failed to parse STL");
|
|
107
|
+
return [{ name: t, modelPos: o }];
|
|
108
|
+
}
|
|
109
|
+
case "obj": {
|
|
110
|
+
const o = new T().parse(new TextDecoder().decode(r));
|
|
111
|
+
return k(t, F(o), !1);
|
|
112
|
+
}
|
|
113
|
+
case "ply": {
|
|
114
|
+
const o = new v().parse(r), n = A(o, null);
|
|
115
|
+
if (!n) throw new Error("No PLY geometry");
|
|
116
|
+
return [{ name: t, modelPos: n }];
|
|
117
|
+
}
|
|
118
|
+
case "3mf": {
|
|
119
|
+
const { objects: o, project: n } = await B(r, t), i = o.map((c) => ({ name: c.name, modelPos: c.tris, objectid: c.objectid, paint: c.paint, bbox: c.bbox, project: n }));
|
|
120
|
+
if (!i.length) throw new Error("No mesh in 3MF");
|
|
121
|
+
return i;
|
|
122
|
+
}
|
|
123
|
+
case "amf": {
|
|
124
|
+
const o = new P().parse(r), n = k(t, F(o), !0);
|
|
125
|
+
if (!n.length) throw new Error("No mesh in AMF");
|
|
126
|
+
return n;
|
|
127
|
+
}
|
|
128
|
+
default: {
|
|
129
|
+
const o = x.get(s);
|
|
130
|
+
if (!o) throw new Error(`Unsupported format: .${s}`);
|
|
131
|
+
const n = await o(r, t);
|
|
132
|
+
if (!n?.length) throw new Error(`No mesh in .${s}`);
|
|
133
|
+
return n;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function V(t) {
|
|
138
|
+
const r = Math.floor(t.length / 9);
|
|
139
|
+
if (r < 2) return null;
|
|
140
|
+
const s = 1e4, o = /* @__PURE__ */ new Map(), n = new Int32Array(r * 3);
|
|
141
|
+
for (let e = 0; e < r; e++)
|
|
142
|
+
for (let l = 0; l < 3; l++) {
|
|
143
|
+
const p = e * 9 + l * 3, m = `${Math.round(t[p] * s)},${Math.round(t[p + 1] * s)},${Math.round(t[p + 2] * s)}`;
|
|
144
|
+
let d = o.get(m);
|
|
145
|
+
d === void 0 && (d = o.size, o.set(m, d)), n[e * 3 + l] = d;
|
|
146
|
+
}
|
|
147
|
+
const i = new Int32Array(r);
|
|
148
|
+
for (let e = 0; e < r; e++) i[e] = e;
|
|
149
|
+
const c = (e) => {
|
|
150
|
+
for (; i[e] !== e; )
|
|
151
|
+
i[e] = i[i[e]], e = i[e];
|
|
152
|
+
return e;
|
|
153
|
+
}, a = (e, l) => {
|
|
154
|
+
e = c(e), l = c(l), e !== l && (i[l] = e);
|
|
155
|
+
}, f = /* @__PURE__ */ new Map();
|
|
156
|
+
for (let e = 0; e < r; e++)
|
|
157
|
+
for (let l = 0; l < 3; l++) {
|
|
158
|
+
const p = n[e * 3 + l], m = n[e * 3 + (l + 1) % 3], d = p < m ? p * 4294967296 + m : m * 4294967296 + p, g = f.get(d);
|
|
159
|
+
g === void 0 ? f.set(d, e) : a(e, g);
|
|
160
|
+
}
|
|
161
|
+
const u = /* @__PURE__ */ new Map();
|
|
162
|
+
for (let e = 0; e < r; e++) {
|
|
163
|
+
const l = c(e);
|
|
164
|
+
let p = u.get(l);
|
|
165
|
+
p || (p = [], u.set(l, p)), p.push(e);
|
|
166
|
+
}
|
|
167
|
+
return u.size < 2 ? null : [...u.values()].sort((e, l) => l.length - e.length).map((e) => {
|
|
168
|
+
const l = new Float32Array(e.length * 9);
|
|
169
|
+
let p = 0;
|
|
170
|
+
for (const m of e) {
|
|
171
|
+
const d = m * 9;
|
|
172
|
+
for (let g = 0; g < 9; g++) l[p++] = t[d + g];
|
|
173
|
+
}
|
|
174
|
+
return l;
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
export {
|
|
178
|
+
j as SUPPORTED_EXT,
|
|
179
|
+
C as fileExt,
|
|
180
|
+
U as loadModel,
|
|
181
|
+
R as registerLoader,
|
|
182
|
+
V as splitConnectedComponents
|
|
183
|
+
};
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { unzip as Y, unzipSync as B } from "three/examples/jsm/libs/fflate.module.js";
|
|
2
|
+
function W(t) {
|
|
3
|
+
return new Promise((n) => {
|
|
4
|
+
let o = !1;
|
|
5
|
+
const e = (r) => {
|
|
6
|
+
o || (o = !0, n(r));
|
|
7
|
+
};
|
|
8
|
+
try {
|
|
9
|
+
Y(t, (r, i) => e(r ? B(t) : i));
|
|
10
|
+
} catch {
|
|
11
|
+
e(B(t));
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
const F = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0];
|
|
16
|
+
function q(t, n) {
|
|
17
|
+
const o = new Array(12);
|
|
18
|
+
for (let e = 0; e < 4; e++)
|
|
19
|
+
for (let r = 0; r < 3; r++)
|
|
20
|
+
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);
|
|
21
|
+
return o;
|
|
22
|
+
}
|
|
23
|
+
function C(t) {
|
|
24
|
+
if (!t) return F;
|
|
25
|
+
const n = t.trim().split(/\s+/).map(Number);
|
|
26
|
+
return n.length === 12 && n.every(Number.isFinite) ? n : F;
|
|
27
|
+
}
|
|
28
|
+
const U = {};
|
|
29
|
+
function p(t, n) {
|
|
30
|
+
const e = (U[n] || (U[n] = new RegExp(`\\b${n}\\s*=\\s*"([^"]*)"`))).exec(t);
|
|
31
|
+
return e ? e[1] : null;
|
|
32
|
+
}
|
|
33
|
+
const D = /<vertex\s+x="([^"]*)"\s+y="([^"]*)"\s+z="([^"]*)"/g, V = /<triangle\s+v1="([^"]*)"\s+v2="([^"]*)"\s+v3="([^"]*)"([^>]*)/g, $ = [
|
|
34
|
+
["paint_color", "color"],
|
|
35
|
+
// multi-material: state 1..16 == Extruder1..16
|
|
36
|
+
["paint_supports", "supports"],
|
|
37
|
+
// support enforcer/blocker: states 1 and 2
|
|
38
|
+
["paint_seam", "seam"],
|
|
39
|
+
// unsupported by the kernel — collected for the warning only
|
|
40
|
+
["paint_fuzzy_skin", "fuzzy"]
|
|
41
|
+
// ditto
|
|
42
|
+
];
|
|
43
|
+
function G() {
|
|
44
|
+
return { color: /* @__PURE__ */ new Map(), supports: /* @__PURE__ */ new Map(), seam: /* @__PURE__ */ new Map(), fuzzy: /* @__PURE__ */ new Map() };
|
|
45
|
+
}
|
|
46
|
+
function K(t) {
|
|
47
|
+
return !t || $.every(([, n]) => t[n].size === 0);
|
|
48
|
+
}
|
|
49
|
+
function x(t, n, o) {
|
|
50
|
+
for (const [e, r] of $) {
|
|
51
|
+
if (!t.includes(e)) continue;
|
|
52
|
+
const i = p(t, e);
|
|
53
|
+
i && o[r].set(n, i);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function Q(t) {
|
|
57
|
+
const n = [];
|
|
58
|
+
D.lastIndex = 0;
|
|
59
|
+
let o;
|
|
60
|
+
for (; o = D.exec(t); ) n.push(+o[1], +o[2], +o[3]);
|
|
61
|
+
if (!n.length)
|
|
62
|
+
for (const i of t.match(/<vertex\b[^>]*>/g) || []) n.push(+p(i, "x"), +p(i, "y"), +p(i, "z"));
|
|
63
|
+
if (n.length < 9) return null;
|
|
64
|
+
const e = [], r = G();
|
|
65
|
+
for (V.lastIndex = 0; o = V.exec(t); ) {
|
|
66
|
+
const i = e.length / 3;
|
|
67
|
+
e.push(+o[1], +o[2], +o[3]), o[4].length > 2 && x(o[4], i, r);
|
|
68
|
+
}
|
|
69
|
+
if (!e.length)
|
|
70
|
+
for (const i of t.match(/<triangle\b[^>]*>/g) || []) {
|
|
71
|
+
const s = e.length / 3;
|
|
72
|
+
e.push(+p(i, "v1"), +p(i, "v2"), +p(i, "v3")), x(i, s, r);
|
|
73
|
+
}
|
|
74
|
+
return e.length ? { verts: n, tris: e, paint: r } : null;
|
|
75
|
+
}
|
|
76
|
+
function Z(t) {
|
|
77
|
+
const n = /* @__PURE__ */ new Map(), o = /<object\b([^>]*)>([\s\S]*?)<\/object>/g;
|
|
78
|
+
let e;
|
|
79
|
+
for (; e = o.exec(t); ) {
|
|
80
|
+
const s = p(e[1], "id");
|
|
81
|
+
if (!s) continue;
|
|
82
|
+
const c = e[2], d = [];
|
|
83
|
+
for (const f of c.match(/<component\b[^>]*>/g) || []) {
|
|
84
|
+
const u = p(f, "objectid");
|
|
85
|
+
u && d.push({ objectid: u, path: p(f, "p:path") || p(f, "path"), transform: C(p(f, "transform")) });
|
|
86
|
+
}
|
|
87
|
+
n.set(s, d.length ? { components: d } : { mesh: Q(c) });
|
|
88
|
+
}
|
|
89
|
+
const r = [], i = /<build\b[^>]*>([\s\S]*?)<\/build>/.exec(t);
|
|
90
|
+
if (i)
|
|
91
|
+
for (const s of i[1].match(/<item\b[^>]*>/g) || []) {
|
|
92
|
+
const c = p(s, "objectid");
|
|
93
|
+
c && r.push({ objectid: c, path: p(s, "p:path") || p(s, "path"), transform: C(p(s, "transform")) });
|
|
94
|
+
}
|
|
95
|
+
return { objects: n, items: r };
|
|
96
|
+
}
|
|
97
|
+
function O(t) {
|
|
98
|
+
const n = String(t).replace(/^\/+/, "");
|
|
99
|
+
return n.includes("%") ? decodeURIComponent(n) : n;
|
|
100
|
+
}
|
|
101
|
+
function k(t) {
|
|
102
|
+
const n = {};
|
|
103
|
+
for (const o of t.match(/<metadata\b[^>]*>/g) || []) {
|
|
104
|
+
const e = p(o, "key");
|
|
105
|
+
e && (n[e] = p(o, "value") ?? "");
|
|
106
|
+
}
|
|
107
|
+
return n;
|
|
108
|
+
}
|
|
109
|
+
function tt(t) {
|
|
110
|
+
const n = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), e = /<object\b([^>]*)>([\s\S]*?)<\/object>/g;
|
|
111
|
+
let r;
|
|
112
|
+
for (; r = e.exec(t); ) {
|
|
113
|
+
const c = p(r[1], "id");
|
|
114
|
+
if (c) {
|
|
115
|
+
const d = r[2];
|
|
116
|
+
n.set(c, k(d.replace(/<(?:part|volume)\b[\s\S]*?<\/(?:part|volume)>/g, "")));
|
|
117
|
+
const f = [];
|
|
118
|
+
for (const u of d.match(/<volume\b[\s\S]*?<\/volume>/g) || []) {
|
|
119
|
+
const _ = k(u).volume_type, y = _ === "SupportBlocker" ? "blocker" : _ === "SupportEnforcer" ? "enforcer" : null, j = Number(p(u, "firstid")), S = Number(p(u, "lastid"));
|
|
120
|
+
y && Number.isInteger(j) && Number.isInteger(S) && j >= 0 && S >= j && f.push({ firstTriangle: j, lastTriangle: S, kind: y });
|
|
121
|
+
}
|
|
122
|
+
f.length && o.set(c, f);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const i = [], s = /<plate\b[^>]*>([\s\S]*?)<\/plate>/g;
|
|
126
|
+
for (; r = s.exec(t); ) {
|
|
127
|
+
const c = r[1], d = k(c.replace(/<model_instance\b[\s\S]*?<\/model_instance>/g, "")), f = [];
|
|
128
|
+
for (const u of c.match(/<model_instance\b[\s\S]*?<\/model_instance>/g) || []) {
|
|
129
|
+
const _ = k(u).object_id;
|
|
130
|
+
_ && f.push(_);
|
|
131
|
+
}
|
|
132
|
+
i.push({ index: Math.max(0, (Number(d.plater_id) || i.length + 1) - 1), objectIds: f });
|
|
133
|
+
}
|
|
134
|
+
return { objects: n, plates: i, volumes: o };
|
|
135
|
+
}
|
|
136
|
+
const et = Object.freeze({
|
|
137
|
+
manualSupportPoints: "prepared-roundtrip",
|
|
138
|
+
drainHoles: "preserved-unsupported",
|
|
139
|
+
modifierVolumes: "prepared-mask-filtering",
|
|
140
|
+
uiEditing: "unavailable"
|
|
141
|
+
});
|
|
142
|
+
function J(t, n, o, e, r) {
|
|
143
|
+
const i = /* @__PURE__ */ new Map();
|
|
144
|
+
if (!t?.trim()) return i;
|
|
145
|
+
const s = t.trim().split(/\r?\n/), c = new RegExp(`^${n}_format_version=(\\d+)$`).exec(s[0]), d = c ? Number(c[1]) : 0;
|
|
146
|
+
for (const f of s.slice(c ? 1 : 0)) {
|
|
147
|
+
const u = /^object_id=(\d+)\|(.*)$/.exec(f);
|
|
148
|
+
if (!u || i.has(Number(u?.[1]))) continue;
|
|
149
|
+
const _ = Number(u[1]), y = u[2].trim() ? u[2].trim().split(/\s+/).map(Number) : [], j = o(d);
|
|
150
|
+
if (!j || y.length % j !== 0 || y.some((a) => !Number.isFinite(a))) {
|
|
151
|
+
e.push({ code: n === "support_points" ? "SLA_SUPPORT_POINT_COUNT" : "SLA_DRAIN_HOLE_COUNT", object: _ }), i.set(_, []);
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const S = [];
|
|
155
|
+
for (let a = 0; a < y.length; a += j) S.push(r(y.slice(a, a + j), d));
|
|
156
|
+
i.set(_, S);
|
|
157
|
+
}
|
|
158
|
+
return i;
|
|
159
|
+
}
|
|
160
|
+
function X(t, n) {
|
|
161
|
+
const [o, e, r] = n;
|
|
162
|
+
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]];
|
|
163
|
+
}
|
|
164
|
+
function nt(t, n) {
|
|
165
|
+
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);
|
|
166
|
+
return s ? i.map((c) => c / s) : i;
|
|
167
|
+
}
|
|
168
|
+
function ot(t, n) {
|
|
169
|
+
const o = (s) => {
|
|
170
|
+
const c = t.get(s);
|
|
171
|
+
return c ? n.decode(c) : null;
|
|
172
|
+
}, e = {
|
|
173
|
+
settings: null,
|
|
174
|
+
// Metadata/project_settings.config — the flattened preset (raw upstream strings)
|
|
175
|
+
objectMeta: /* @__PURE__ */ new Map(),
|
|
176
|
+
// 3mf object id -> per-object metadata (name, extruder, per-object overrides)
|
|
177
|
+
plates: [],
|
|
178
|
+
// [{index, objectIds}]
|
|
179
|
+
hasLayerHeightProfile: !1,
|
|
180
|
+
hasCustomGcodePerLayer: !1,
|
|
181
|
+
volumeMeta: /* @__PURE__ */ new Map(),
|
|
182
|
+
sla: { capabilities: { ...et }, issues: [], supportPoints: /* @__PURE__ */ new Map(), drainHoles: /* @__PURE__ */ new Map() }
|
|
183
|
+
}, r = o("Metadata/project_settings.config");
|
|
184
|
+
if (r)
|
|
185
|
+
try {
|
|
186
|
+
e.settings = JSON.parse(r);
|
|
187
|
+
} catch {
|
|
188
|
+
e.settings = null;
|
|
189
|
+
}
|
|
190
|
+
const i = o("Metadata/model_settings.config");
|
|
191
|
+
if (i) {
|
|
192
|
+
const s = tt(i);
|
|
193
|
+
e.objectMeta = s.objects, e.plates = s.plates, e.volumeMeta = s.volumes;
|
|
194
|
+
}
|
|
195
|
+
return e.sla.supportPoints = J(
|
|
196
|
+
o("Metadata/Slic3r_PE_sla_support_points.txt"),
|
|
197
|
+
"support_points",
|
|
198
|
+
(s) => s === 0 ? 3 : s === 1 ? 5 : 0,
|
|
199
|
+
e.sla.issues,
|
|
200
|
+
(s, c) => ({
|
|
201
|
+
position: s.slice(0, 3),
|
|
202
|
+
radius: c === 0 ? 0.4 : s[3],
|
|
203
|
+
type: c === 0 || s[4] === 2 ? "manual" : s[4] === 1 ? "island" : "slope"
|
|
204
|
+
})
|
|
205
|
+
), e.sla.drainHoles = J(
|
|
206
|
+
o("Metadata/Slic3r_PE_sla_drain_holes.txt"),
|
|
207
|
+
"drain_holes",
|
|
208
|
+
(s) => s === 1 ? 8 : 0,
|
|
209
|
+
e.sla.issues,
|
|
210
|
+
(s) => {
|
|
211
|
+
const c = Math.hypot(s[3], s[4], s[5]), d = c ? s.slice(3, 6).map((f) => f / c) : s.slice(3, 6);
|
|
212
|
+
return { position: s.slice(0, 3).map((f, u) => f + d[u]), normal: d, radius: s[6], height: s[7] - 1 };
|
|
213
|
+
}
|
|
214
|
+
), e.hasLayerHeightProfile = !!o("Metadata/layer_heights_profile.txt")?.trim(), e.hasCustomGcodePerLayer = !!o("Metadata/custom_gcode_per_layer.xml")?.trim(), e;
|
|
215
|
+
}
|
|
216
|
+
async function rt(t, n = "model") {
|
|
217
|
+
const o = ArrayBuffer.isView(t) ? new Uint8Array(t.buffer, t.byteOffset, t.byteLength) : new Uint8Array(t), e = await W(o), r = /* @__PURE__ */ new Map();
|
|
218
|
+
for (const a of Object.keys(e)) r.set(O(a), e[a]);
|
|
219
|
+
const i = new TextDecoder(), s = /* @__PURE__ */ new Map(), c = (a) => {
|
|
220
|
+
const w = O(a);
|
|
221
|
+
if (s.has(w)) return s.get(w);
|
|
222
|
+
const l = r.get(w), M = l ? Z(i.decode(l)) : null;
|
|
223
|
+
return s.set(w, M), M;
|
|
224
|
+
};
|
|
225
|
+
let d = "3D/3dmodel.model";
|
|
226
|
+
const f = r.get("_rels/.rels");
|
|
227
|
+
if (f) {
|
|
228
|
+
for (const a of i.decode(f).match(/<Relationship\b[^>]*>/g) || [])
|
|
229
|
+
if ((p(a, "Type") || "").endsWith("/3dmodel")) {
|
|
230
|
+
d = O(p(a, "Target"));
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const u = c(d);
|
|
235
|
+
if (!u) throw new Error(`3MF root model not found: ${d}`);
|
|
236
|
+
const _ = [], y = ot(r, i), j = (a, w, l, M, P, N) => {
|
|
237
|
+
if (N > 16) return;
|
|
238
|
+
const T = c(w)?.objects.get(a);
|
|
239
|
+
if (!T) return;
|
|
240
|
+
if (T.components) {
|
|
241
|
+
for (const b of T.components) j(b.objectid, b.path || w, q(b.transform, l), M, P, N + 1);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
if (!T.mesh) return;
|
|
245
|
+
const { verts: z, tris: I, paint: v } = T.mesh, E = M.length / 9;
|
|
246
|
+
for (let b = 0; b < I.length; b++) {
|
|
247
|
+
const m = I[b] * 3, g = z[m], h = z[m + 1], A = z[m + 2];
|
|
248
|
+
M.push(
|
|
249
|
+
g * l[0] + h * l[3] + A * l[6] + l[9],
|
|
250
|
+
g * l[1] + h * l[4] + A * l[7] + l[10],
|
|
251
|
+
g * l[2] + h * l[5] + A * l[8] + l[11]
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
if (v) for (const [, b] of $)
|
|
255
|
+
for (const [m, g] of v[b]) P[b].set(E + m, g);
|
|
256
|
+
}, S = u.items.length ? u.items : [...u.objects.keys()].filter((a) => u.objects.get(a).mesh).map((a) => ({ objectid: a, path: d, transform: F }));
|
|
257
|
+
return S.forEach((a, w) => {
|
|
258
|
+
const l = [], M = G();
|
|
259
|
+
if (j(a.objectid, a.path || d, a.transform, l, M, 0), l.length < 9) return;
|
|
260
|
+
let P = new Float32Array(l);
|
|
261
|
+
const N = [], R = y.volumeMeta.get(a.objectid) || [];
|
|
262
|
+
if (R.length) {
|
|
263
|
+
const m = /* @__PURE__ */ new Set();
|
|
264
|
+
for (let g = 0; g < R.length; g++) {
|
|
265
|
+
const h = R[g], A = h.firstTriangle * 9, H = Math.min(l.length, (h.lastTriangle + 1) * 9);
|
|
266
|
+
if (!(A >= H)) {
|
|
267
|
+
for (let L = h.firstTriangle; L <= h.lastTriangle; L++) m.add(L);
|
|
268
|
+
N.push({ id: `${a.objectid}:modifier:${g}`, kind: h.kind, tris: new Float32Array(l.slice(A, H)) });
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (m.size) {
|
|
272
|
+
const g = [];
|
|
273
|
+
for (let h = 0; h < l.length / 9; h++) m.has(h) || g.push(...l.slice(h * 9, h * 9 + 9));
|
|
274
|
+
P = new Float32Array(g);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
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) => ({
|
|
278
|
+
...m,
|
|
279
|
+
position: X(a.transform, m.position),
|
|
280
|
+
normal: nt(a.transform, m.normal)
|
|
281
|
+
}));
|
|
282
|
+
let I = 1 / 0, v = 1 / 0, E = -1 / 0, b = -1 / 0;
|
|
283
|
+
for (let m = 0; m < P.length; m += 3) {
|
|
284
|
+
const g = P[m], h = P[m + 1];
|
|
285
|
+
g < I && (I = g), g > E && (E = g), h < v && (v = h), h > b && (b = h);
|
|
286
|
+
}
|
|
287
|
+
_.push({
|
|
288
|
+
name: S.length > 1 ? `${n}#${w + 1}` : n,
|
|
289
|
+
tris: P,
|
|
290
|
+
objectid: a.objectid,
|
|
291
|
+
paint: K(M) ? null : M,
|
|
292
|
+
sla: { supportPoints: T, drainHoles: z, modifierVolumes: N },
|
|
293
|
+
bbox: { minX: I, minY: v, maxX: E, maxY: b }
|
|
294
|
+
});
|
|
295
|
+
}), { objects: _, project: y };
|
|
296
|
+
}
|
|
297
|
+
export {
|
|
298
|
+
rt as p
|
|
299
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { p as f } from "./parse_3mf-CQ5rAX6P.js";
|
|
2
|
+
self.onmessage = async (a) => {
|
|
3
|
+
const { id: s, buffer: r, baseName: t } = a.data || {};
|
|
4
|
+
try {
|
|
5
|
+
const { objects: e, project: o } = await f(r, t);
|
|
6
|
+
self.postMessage({ id: s, objects: e, project: o }, e.map((c) => c.tris.buffer));
|
|
7
|
+
} catch (e) {
|
|
8
|
+
self.postMessage({ id: s, error: e && e.message || String(e) });
|
|
9
|
+
}
|
|
10
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { zlibSync as p } from "three/examples/jsm/libs/fflate.module.js";
|
|
2
|
+
import { s as m, r as l, e as g } from "./sl1_write-CvrNejbW.js";
|
|
3
|
+
self.onmessage = async ({ data: { indices: r, paths: o, params: t, aa: f } }) => {
|
|
4
|
+
const a = m(t), e = [];
|
|
5
|
+
for (let s = 0; s < r.length; s++) {
|
|
6
|
+
const n = l(o[s], a, f || 1);
|
|
7
|
+
e.push(await g(n, a.px, a.py, { deflate: p })), (s & 7) === 7 && self.postMessage({ progress: s + 1 });
|
|
8
|
+
}
|
|
9
|
+
self.postMessage({ indices: r, pngs: e }, e.map((s) => s.buffer));
|
|
10
|
+
};
|