three-slicer-viewer 0.3.2 → 0.3.4
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/TOOLPATH_SPEC.md +8 -1
- package/VIEWER.md +24 -0
- package/data/config-schema-lean.json +1 -1
- package/dist/components.js +47 -43
- package/dist/gcode_parse.js +154 -111
- package/dist/index.js +4409 -4069
- package/dist/{model_loaders-DxlFNFOu.js → model_loaders-Dk9rqXFb.js} +27 -27
- package/dist/model_loaders.js +2 -2
- package/dist/parse_3mf-CpbA-6Iq.js +666 -0
- package/dist/parse_3mf.worker.js +67 -5
- package/dist/sl1_encode.worker.js +1 -1
- package/dist/sl1_write-B6nWmCUu.js +313 -0
- package/dist/sla_slice.worker.js +1 -1
- package/dist/toolpath.js +303 -177
- package/package.json +6 -1
- package/src/core/paint_tools.js +8 -0
- package/src/settings/bed_frame.js +28 -0
- package/src/settings/index.js +1 -0
- package/src/settings/kernel_setting_keys.js +79 -0
- package/src/settings/settings_core.js +194 -8
- package/types/gcode.d.ts +13 -0
- package/types/paint.d.ts +7 -0
- package/types/settings.d.ts +14 -1
- package/types/toolpath.d.ts +6 -0
- package/types/viewer.d.ts +1 -1
- package/dist/parse_3mf-BZISF3eW.js +0 -327
- package/dist/sl1_write-BovHbg3k.js +0 -303
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
import { unzip as Y, unzipSync as H } 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((o) => {
|
|
5
|
-
let s = !1;
|
|
6
|
-
const e = (r) => {
|
|
7
|
-
s || (s = !0, o(r));
|
|
8
|
-
};
|
|
9
|
-
try {
|
|
10
|
-
Y(t, (r, i) => e(r ? H(t) : i));
|
|
11
|
-
} catch {
|
|
12
|
-
e(H(t));
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
const L = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0];
|
|
17
|
-
function K(t, o) {
|
|
18
|
-
const s = new Array(12);
|
|
19
|
-
for (let e = 0; e < 4; e++)
|
|
20
|
-
for (let r = 0; r < 3; r++)
|
|
21
|
-
s[e * 3 + r] = t[e * 3] * o[r] + t[e * 3 + 1] * o[3 + r] + t[e * 3 + 2] * o[6 + r] + (e === 3 ? o[9 + r] : 0);
|
|
22
|
-
return s;
|
|
23
|
-
}
|
|
24
|
-
function U(t) {
|
|
25
|
-
if (!t) return L;
|
|
26
|
-
const o = t.trim().split(/\s+/).map(Number);
|
|
27
|
-
return o.length === 12 && o.every(Number.isFinite) ? o : L;
|
|
28
|
-
}
|
|
29
|
-
const x = {};
|
|
30
|
-
function f(t, o) {
|
|
31
|
-
const e = (x[o] || (x[o] = new RegExp(`\\b${o}\\s*=\\s*"([^"]*)"`))).exec(t);
|
|
32
|
-
return e ? e[1] : null;
|
|
33
|
-
}
|
|
34
|
-
const B = /<vertex\s+x="([^"]*)"\s+y="([^"]*)"\s+z="([^"]*)"/g, D = /<triangle\s+v1="([^"]*)"\s+v2="([^"]*)"\s+v3="([^"]*)"([^>]*)/g, C = [
|
|
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 || C.every(([, o]) => t[o].size === 0);
|
|
49
|
-
}
|
|
50
|
-
function J(t, o, s) {
|
|
51
|
-
for (const [e, r] of C) {
|
|
52
|
-
if (!t.includes(e)) continue;
|
|
53
|
-
const i = f(t, e);
|
|
54
|
-
i && s[r].set(o, i);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
function Z(t) {
|
|
58
|
-
const o = [];
|
|
59
|
-
B.lastIndex = 0;
|
|
60
|
-
let s;
|
|
61
|
-
for (; s = B.exec(t); ) o.push(+s[1], +s[2], +s[3]);
|
|
62
|
-
if (!o.length)
|
|
63
|
-
for (const i of t.match(/<vertex\b[^>]*>/g) || []) o.push(+f(i, "x"), +f(i, "y"), +f(i, "z"));
|
|
64
|
-
if (o.length < 9) return null;
|
|
65
|
-
const e = [], r = G();
|
|
66
|
-
for (D.lastIndex = 0; s = D.exec(t); ) {
|
|
67
|
-
const i = e.length / 3;
|
|
68
|
-
e.push(+s[1], +s[2], +s[3]), s[4].length > 2 && J(s[4], i, r);
|
|
69
|
-
}
|
|
70
|
-
if (!e.length)
|
|
71
|
-
for (const i of t.match(/<triangle\b[^>]*>/g) || []) {
|
|
72
|
-
const p = e.length / 3;
|
|
73
|
-
e.push(+f(i, "v1"), +f(i, "v2"), +f(i, "v3")), J(i, p, r);
|
|
74
|
-
}
|
|
75
|
-
return e.length ? { verts: o, tris: e, paint: r } : null;
|
|
76
|
-
}
|
|
77
|
-
function tt(t) {
|
|
78
|
-
const o = /* @__PURE__ */ new Map(), s = /<object\b([^>]*)>([\s\S]*?)<\/object>/g;
|
|
79
|
-
let e;
|
|
80
|
-
for (; e = s.exec(t); ) {
|
|
81
|
-
const p = f(e[1], "id");
|
|
82
|
-
if (!p) continue;
|
|
83
|
-
const u = e[2], n = [];
|
|
84
|
-
for (const a of u.match(/<component\b[^>]*>/g) || []) {
|
|
85
|
-
const c = f(a, "objectid");
|
|
86
|
-
c && n.push({ objectid: c, path: f(a, "p:path") || f(a, "path"), transform: U(f(a, "transform")) });
|
|
87
|
-
}
|
|
88
|
-
o.set(p, n.length ? { components: n } : { mesh: Z(u) });
|
|
89
|
-
}
|
|
90
|
-
const r = [], i = /<build\b[^>]*>([\s\S]*?)<\/build>/.exec(t);
|
|
91
|
-
if (i)
|
|
92
|
-
for (const p of i[1].match(/<item\b[^>]*>/g) || []) {
|
|
93
|
-
const u = f(p, "objectid");
|
|
94
|
-
u && r.push({ objectid: u, path: f(p, "p:path") || f(p, "path"), transform: U(f(p, "transform")) });
|
|
95
|
-
}
|
|
96
|
-
return { objects: o, items: r };
|
|
97
|
-
}
|
|
98
|
-
function k(t) {
|
|
99
|
-
const o = String(t).replace(/^\/+/, "");
|
|
100
|
-
return o.includes("%") ? decodeURIComponent(o) : o;
|
|
101
|
-
}
|
|
102
|
-
function R(t) {
|
|
103
|
-
const o = {};
|
|
104
|
-
for (const s of t.match(/<metadata\b[^>]*>/g) || []) {
|
|
105
|
-
const e = f(s, "key");
|
|
106
|
-
e && (o[e] = f(s, "value") ?? "");
|
|
107
|
-
}
|
|
108
|
-
return o;
|
|
109
|
-
}
|
|
110
|
-
function et(t) {
|
|
111
|
-
const o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), e = /<object\b([^>]*)>([\s\S]*?)<\/object>/g;
|
|
112
|
-
let r;
|
|
113
|
-
for (; r = e.exec(t); ) {
|
|
114
|
-
const u = f(r[1], "id");
|
|
115
|
-
if (u) {
|
|
116
|
-
const n = r[2];
|
|
117
|
-
o.set(u, R(n.replace(/<(?:part|volume)\b[\s\S]*?<\/(?:part|volume)>/g, "")));
|
|
118
|
-
const a = [];
|
|
119
|
-
for (const c of n.match(/<volume\b[\s\S]*?<\/volume>/g) || []) {
|
|
120
|
-
const d = R(c).volume_type, y = d === "SupportBlocker" ? "blocker" : d === "SupportEnforcer" ? "enforcer" : null, _ = Number(f(c, "firstid")), S = Number(f(c, "lastid"));
|
|
121
|
-
y && Number.isInteger(_) && Number.isInteger(S) && _ >= 0 && S >= _ && a.push({ firstTriangle: _, lastTriangle: S, kind: y });
|
|
122
|
-
}
|
|
123
|
-
a.length && s.set(u, a);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
const i = [], p = /<plate\b[^>]*>([\s\S]*?)<\/plate>/g;
|
|
127
|
-
for (; r = p.exec(t); ) {
|
|
128
|
-
const u = r[1], n = R(u.replace(/<model_instance\b[\s\S]*?<\/model_instance>/g, "")), a = [];
|
|
129
|
-
for (const c of u.match(/<model_instance\b[\s\S]*?<\/model_instance>/g) || []) {
|
|
130
|
-
const d = R(c).object_id;
|
|
131
|
-
d && a.push(d);
|
|
132
|
-
}
|
|
133
|
-
i.push({ index: Math.max(0, (Number(n.plater_id) || i.length + 1) - 1), objectIds: a, gcodeFile: n.gcode_file || null });
|
|
134
|
-
}
|
|
135
|
-
return { objects: o, plates: i, volumes: s };
|
|
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 V(t, o, s, e, r) {
|
|
144
|
-
const i = /* @__PURE__ */ new Map();
|
|
145
|
-
if (!t?.trim()) return i;
|
|
146
|
-
const p = t.trim().split(/\r?\n/), u = new RegExp(`^${o}_format_version=(\\d+)$`).exec(p[0]), n = u ? Number(u[1]) : 0;
|
|
147
|
-
for (const a of p.slice(u ? 1 : 0)) {
|
|
148
|
-
const c = /^object_id=(\d+)\|(.*)$/.exec(a);
|
|
149
|
-
if (!c || i.has(Number(c?.[1]))) continue;
|
|
150
|
-
const d = Number(c[1]), y = c[2].trim() ? c[2].trim().split(/\s+/).map(Number) : [], _ = s(n);
|
|
151
|
-
if (!_ || y.length % _ !== 0 || y.some((l) => !Number.isFinite(l))) {
|
|
152
|
-
e.push({ code: o === "support_points" ? "SLA_SUPPORT_POINT_COUNT" : "SLA_DRAIN_HOLE_COUNT", object: d }), i.set(d, []);
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
const S = [];
|
|
156
|
-
for (let l = 0; l < y.length; l += _) S.push(r(y.slice(l, l + _), n));
|
|
157
|
-
i.set(d, S);
|
|
158
|
-
}
|
|
159
|
-
return i;
|
|
160
|
-
}
|
|
161
|
-
function X(t, o) {
|
|
162
|
-
const [s, e, r] = o;
|
|
163
|
-
return [s * t[0] + e * t[3] + r * t[6] + t[9], s * t[1] + e * t[4] + r * t[7] + t[10], s * t[2] + e * t[5] + r * t[8] + t[11]];
|
|
164
|
-
}
|
|
165
|
-
function ot(t, o) {
|
|
166
|
-
const [s, e, r] = o, i = [s * t[0] + e * t[3] + r * t[6], s * t[1] + e * t[4] + r * t[7], s * t[2] + e * t[5] + r * t[8]], p = Math.hypot(...i);
|
|
167
|
-
return p ? i.map((u) => u / p) : i;
|
|
168
|
-
}
|
|
169
|
-
function st(t, o) {
|
|
170
|
-
const s = (n) => {
|
|
171
|
-
const a = t.get(n);
|
|
172
|
-
return a ? o.decode(a) : 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
|
-
viewerSettings: null,
|
|
185
|
-
// Metadata/three_slicer_settings.json — this package's own member (write_3mf.js)
|
|
186
|
-
plateSettings: null,
|
|
187
|
-
// ...its two halves: global viewer knobs, and per-plate overrides keyed by plate index
|
|
188
|
-
plateCount: null,
|
|
189
|
-
// ...and the plate count it was saved with (empty plates hold no <plate> record)
|
|
190
|
-
gcodePlates: null
|
|
191
|
-
// a .gcode.3mf's sliced plates: [{index, gcode}] (write_3mf.js writeGcode3MF), else null
|
|
192
|
-
}, r = s("Metadata/project_settings.config");
|
|
193
|
-
if (r)
|
|
194
|
-
try {
|
|
195
|
-
e.settings = JSON.parse(r);
|
|
196
|
-
} catch {
|
|
197
|
-
e.settings = null;
|
|
198
|
-
}
|
|
199
|
-
const i = s("Metadata/three_slicer_settings.json");
|
|
200
|
-
if (i) {
|
|
201
|
-
let n = null;
|
|
202
|
-
try {
|
|
203
|
-
n = JSON.parse(i);
|
|
204
|
-
} catch {
|
|
205
|
-
n = null;
|
|
206
|
-
}
|
|
207
|
-
const a = (c) => c && typeof c == "object" && !Array.isArray(c);
|
|
208
|
-
if (a(n)) {
|
|
209
|
-
a(n.viewer) && Object.keys(n.viewer).length && (e.viewerSettings = n.viewer);
|
|
210
|
-
let c = [];
|
|
211
|
-
a(n.plates) && (c = Object.entries(n.plates));
|
|
212
|
-
const d = c.filter(([y, _]) => /^\d+$/.test(y) && a(_) && Object.keys(_).length);
|
|
213
|
-
d.length && (e.plateSettings = Object.fromEntries(d.map(([y, _]) => [Number(y), _]))), Number.isInteger(n.plateCount) && n.plateCount >= 1 && (e.plateCount = n.plateCount);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
const p = s("Metadata/model_settings.config");
|
|
217
|
-
if (p) {
|
|
218
|
-
const n = et(p);
|
|
219
|
-
e.objectMeta = n.objects, e.plates = n.plates, e.volumeMeta = n.volumes;
|
|
220
|
-
}
|
|
221
|
-
const u = e.plates.map((n) => ({ index: n.index, gcode: n.gcodeFile && s(k(n.gcodeFile)) })).filter((n) => n.gcode);
|
|
222
|
-
return u.length && (e.gcodePlates = u), e.sla.supportPoints = V(
|
|
223
|
-
s("Metadata/Slic3r_PE_sla_support_points.txt"),
|
|
224
|
-
"support_points",
|
|
225
|
-
(n) => n === 0 ? 3 : n === 1 ? 5 : 0,
|
|
226
|
-
e.sla.issues,
|
|
227
|
-
(n, a) => ({
|
|
228
|
-
position: n.slice(0, 3),
|
|
229
|
-
radius: a === 0 ? W : n[3],
|
|
230
|
-
type: a === 0 || n[4] === 2 ? "manual" : n[4] === 1 ? "island" : "slope"
|
|
231
|
-
})
|
|
232
|
-
), e.sla.drainHoles = V(
|
|
233
|
-
s("Metadata/Slic3r_PE_sla_drain_holes.txt"),
|
|
234
|
-
"drain_holes",
|
|
235
|
-
(n) => n === 1 ? 8 : 0,
|
|
236
|
-
e.sla.issues,
|
|
237
|
-
(n) => {
|
|
238
|
-
const a = Math.hypot(n[3], n[4], n[5]), c = a ? n.slice(3, 6).map((d) => d / a) : n.slice(3, 6);
|
|
239
|
-
return { position: n.slice(0, 3).map((d, y) => d + c[y]), normal: c, radius: n[6], height: n[7] - 1 };
|
|
240
|
-
}
|
|
241
|
-
), e.hasLayerHeightProfile = !!s("Metadata/layer_heights_profile.txt")?.trim(), e.hasCustomGcodePerLayer = !!s("Metadata/custom_gcode_per_layer.xml")?.trim(), e;
|
|
242
|
-
}
|
|
243
|
-
async function ct(t, o = "model") {
|
|
244
|
-
const s = ArrayBuffer.isView(t) ? new Uint8Array(t.buffer, t.byteOffset, t.byteLength) : new Uint8Array(t), e = await q(s), r = /* @__PURE__ */ new Map();
|
|
245
|
-
for (const l of Object.keys(e)) r.set(k(l), e[l]);
|
|
246
|
-
const i = new TextDecoder(), p = /* @__PURE__ */ new Map(), u = (l) => {
|
|
247
|
-
const w = k(l);
|
|
248
|
-
if (p.has(w)) return p.get(w);
|
|
249
|
-
const m = r.get(w), M = m ? tt(i.decode(m)) : null;
|
|
250
|
-
return p.set(w, M), M;
|
|
251
|
-
};
|
|
252
|
-
let n = "3D/3dmodel.model";
|
|
253
|
-
const a = r.get("_rels/.rels");
|
|
254
|
-
if (a) {
|
|
255
|
-
for (const l of i.decode(a).match(/<Relationship\b[^>]*>/g) || [])
|
|
256
|
-
if ((f(l, "Type") || "").endsWith("/3dmodel")) {
|
|
257
|
-
n = k(f(l, "Target"));
|
|
258
|
-
break;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
const c = st(r, i), d = u(n);
|
|
262
|
-
if (!d && c.gcodePlates) return { objects: [], project: c };
|
|
263
|
-
if (!d) throw new Error(`3MF root model not found: ${n}`);
|
|
264
|
-
const y = [], _ = (l, w, m, M, P, N) => {
|
|
265
|
-
if (N > 16) return;
|
|
266
|
-
const T = u(w)?.objects.get(l);
|
|
267
|
-
if (!T) return;
|
|
268
|
-
if (T.components) {
|
|
269
|
-
for (const j of T.components) _(j.objectid, j.path || w, K(j.transform, m), M, P, N + 1);
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
if (!T.mesh) return;
|
|
273
|
-
const { verts: E, tris: I, paint: v } = T.mesh, z = M.length / 9;
|
|
274
|
-
for (let j = 0; j < I.length; j++) {
|
|
275
|
-
const h = I[j] * 3, b = E[h], g = E[h + 1], A = E[h + 2];
|
|
276
|
-
M.push(
|
|
277
|
-
b * m[0] + g * m[3] + A * m[6] + m[9],
|
|
278
|
-
b * m[1] + g * m[4] + A * m[7] + m[10],
|
|
279
|
-
b * m[2] + g * m[5] + A * m[8] + m[11]
|
|
280
|
-
);
|
|
281
|
-
}
|
|
282
|
-
if (v) for (const [, j] of C)
|
|
283
|
-
for (const [h, b] of v[j]) P[j].set(z + h, b);
|
|
284
|
-
}, S = d.items.length ? d.items : [...d.objects.keys()].filter((l) => d.objects.get(l).mesh).map((l) => ({ objectid: l, path: n, transform: L }));
|
|
285
|
-
return S.forEach((l, w) => {
|
|
286
|
-
const m = [], M = G();
|
|
287
|
-
if (_(l.objectid, l.path || n, l.transform, m, M, 0), m.length < 9) return;
|
|
288
|
-
let P = new Float32Array(m);
|
|
289
|
-
const N = [], O = c.volumeMeta.get(l.objectid) || [];
|
|
290
|
-
if (O.length) {
|
|
291
|
-
const h = /* @__PURE__ */ new Set();
|
|
292
|
-
for (let b = 0; b < O.length; b++) {
|
|
293
|
-
const g = O[b], A = g.firstTriangle * 9, $ = Math.min(m.length, (g.lastTriangle + 1) * 9);
|
|
294
|
-
if (!(A >= $)) {
|
|
295
|
-
for (let F = g.firstTriangle; F <= g.lastTriangle; F++) h.add(F);
|
|
296
|
-
N.push({ id: `${l.objectid}:modifier:${b}`, kind: g.kind, tris: new Float32Array(m.slice(A, $)) });
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
if (h.size) {
|
|
300
|
-
const b = [];
|
|
301
|
-
for (let g = 0; g < m.length / 9; g++) h.has(g) || b.push(...m.slice(g * 9, g * 9 + 9));
|
|
302
|
-
P = new Float32Array(b);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
const T = (c.sla.supportPoints.get(w + 1) || []).map((h) => ({ ...h, position: X(l.transform, h.position) })), E = (c.sla.drainHoles.get(w + 1) || []).map((h) => ({
|
|
306
|
-
...h,
|
|
307
|
-
position: X(l.transform, h.position),
|
|
308
|
-
normal: ot(l.transform, h.normal)
|
|
309
|
-
}));
|
|
310
|
-
let I = 1 / 0, v = 1 / 0, z = -1 / 0, j = -1 / 0;
|
|
311
|
-
for (let h = 0; h < P.length; h += 3) {
|
|
312
|
-
const b = P[h], g = P[h + 1];
|
|
313
|
-
b < I && (I = b), b > z && (z = b), g < v && (v = g), g > j && (j = g);
|
|
314
|
-
}
|
|
315
|
-
y.push({
|
|
316
|
-
name: S.length > 1 ? `${o}#${w + 1}` : o,
|
|
317
|
-
tris: P,
|
|
318
|
-
objectid: l.objectid,
|
|
319
|
-
paint: Q(M) ? null : M,
|
|
320
|
-
sla: { supportPoints: T, drainHoles: E, modifierVolumes: N },
|
|
321
|
-
bbox: { minX: I, minY: v, maxX: z, maxY: j }
|
|
322
|
-
});
|
|
323
|
-
}), { objects: y, project: c };
|
|
324
|
-
}
|
|
325
|
-
export {
|
|
326
|
-
ct as p
|
|
327
|
-
};
|
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
import { strToU8 as V, zipSync as z, zlibSync as j } from "three/examples/jsm/libs/fflate.module.js";
|
|
2
|
-
import { S as A, r as X, R as C } from "./toolpath_encoding-BuYs95qZ.js";
|
|
3
|
-
let M = !0;
|
|
4
|
-
function ft(t) {
|
|
5
|
-
M = !!t;
|
|
6
|
-
}
|
|
7
|
-
const Y = {
|
|
8
|
-
info: (...t) => {
|
|
9
|
-
M && console.info(...t);
|
|
10
|
-
},
|
|
11
|
-
warn: (...t) => {
|
|
12
|
-
M && console.warn(...t);
|
|
13
|
-
},
|
|
14
|
-
error: (...t) => {
|
|
15
|
-
M && console.error(...t);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
function G(t) {
|
|
19
|
-
const e = [];
|
|
20
|
-
let n = null;
|
|
21
|
-
for (let r = 0; r < t.length; r += A) {
|
|
22
|
-
const a = t[r], f = t[r + 1], c = t[r + 4], s = t[r + 5];
|
|
23
|
-
n && Math.abs(n.lx - a) < 1e-6 && Math.abs(n.ly - f) < 1e-6 ? (n.pts.push(c, s), n.lx = c, n.ly = s) : (n = { pts: [a, f, c, s], lx: c, ly: s }, e.push(n));
|
|
24
|
-
}
|
|
25
|
-
return e.map((r) => r.pts);
|
|
26
|
-
}
|
|
27
|
-
function L(t, e, n, r, a, f) {
|
|
28
|
-
const c = new Array(n).fill(null);
|
|
29
|
-
for (const l of t) {
|
|
30
|
-
const i = l.length / 2;
|
|
31
|
-
for (let o = 0; o < i; o++) {
|
|
32
|
-
const d = (o + 1) % i;
|
|
33
|
-
let u = r(l[o * 2], l[o * 2 + 1]), p = a(l[o * 2], l[o * 2 + 1]), x = r(l[d * 2], l[d * 2 + 1]), w = a(l[d * 2], l[d * 2 + 1]);
|
|
34
|
-
if (p === w) continue;
|
|
35
|
-
if (p > w) {
|
|
36
|
-
const y = u;
|
|
37
|
-
u = x, x = y;
|
|
38
|
-
const _ = p;
|
|
39
|
-
p = w, w = _;
|
|
40
|
-
}
|
|
41
|
-
const b = Math.max(0, Math.ceil(p - 0.5));
|
|
42
|
-
if (b >= n || w < 0.5) continue;
|
|
43
|
-
const m = { x: u + (b + 0.5 - p) / (w - p) * (x - u), dx: (x - u) / (w - p), yEnd: w };
|
|
44
|
-
(c[b] ??= []).push(m);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const s = [];
|
|
48
|
-
for (let l = 0; l < n; l++) {
|
|
49
|
-
const i = l + 0.5;
|
|
50
|
-
c[l] && s.push(...c[l]);
|
|
51
|
-
for (let o = s.length - 1; o >= 0; o--) s[o].yEnd <= i && s.splice(o, 1);
|
|
52
|
-
s.sort((o, d) => o.x - d.x);
|
|
53
|
-
for (let o = 0; o + 1 < s.length; o += 2) {
|
|
54
|
-
const d = Math.max(0, Math.ceil(s[o].x - 0.5)), u = Math.min(e - 1, Math.floor(s[o + 1].x - 0.5));
|
|
55
|
-
u >= d && f(l, d, u);
|
|
56
|
-
}
|
|
57
|
-
for (const o of s) o.x += o.dx;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function W(t, e, n = 1) {
|
|
61
|
-
const { px: r, py: a } = e, f = G(t), c = new Uint8Array(r * a);
|
|
62
|
-
if (n <= 1)
|
|
63
|
-
return L(
|
|
64
|
-
f,
|
|
65
|
-
r,
|
|
66
|
-
a,
|
|
67
|
-
(i, o) => e.map(i, o)[0],
|
|
68
|
-
(i, o) => e.map(i, o)[1],
|
|
69
|
-
(i, o, d) => {
|
|
70
|
-
c.fill(255, i * r + o, i * r + d + 1);
|
|
71
|
-
}
|
|
72
|
-
), c;
|
|
73
|
-
const s = new Uint16Array(r * a);
|
|
74
|
-
L(
|
|
75
|
-
f,
|
|
76
|
-
r * n,
|
|
77
|
-
a * n,
|
|
78
|
-
(i, o) => e.map(i, o)[0] * n,
|
|
79
|
-
(i, o) => e.map(i, o)[1] * n,
|
|
80
|
-
(i, o, d) => {
|
|
81
|
-
const u = i / n | 0;
|
|
82
|
-
for (let p = o; p <= d; p++) s[u * r + (p / n | 0)]++;
|
|
83
|
-
}
|
|
84
|
-
);
|
|
85
|
-
const l = n * n;
|
|
86
|
-
for (let i = 0; i < s.length; i++) c[i] = Math.round(s[i] * 255 / l);
|
|
87
|
-
return c;
|
|
88
|
-
}
|
|
89
|
-
const H = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]), Z = (() => {
|
|
90
|
-
const t = new Uint32Array(256);
|
|
91
|
-
for (let e = 0; e < 256; e++) {
|
|
92
|
-
let n = e;
|
|
93
|
-
for (let r = 0; r < 8; r++) n = n & 1 ? 3988292384 ^ n >>> 1 : n >>> 1;
|
|
94
|
-
t[e] = n >>> 0;
|
|
95
|
-
}
|
|
96
|
-
return t;
|
|
97
|
-
})(), q = (t) => {
|
|
98
|
-
let e = 4294967295;
|
|
99
|
-
for (let n = 0; n < t.length; n++) e = Z[(e ^ t[n]) & 255] ^ e >>> 8;
|
|
100
|
-
return (e ^ 4294967295) >>> 0;
|
|
101
|
-
}, F = (t, e) => {
|
|
102
|
-
const n = new Uint8Array(12 + e.length), r = new DataView(n.buffer);
|
|
103
|
-
r.setUint32(0, e.length);
|
|
104
|
-
for (let f = 0; f < 4; f++) n[4 + f] = t.charCodeAt(f);
|
|
105
|
-
n.set(e, 8);
|
|
106
|
-
const a = n.subarray(4, 8 + e.length);
|
|
107
|
-
return r.setUint32(8 + e.length, q(a)), n;
|
|
108
|
-
}, J = async (t) => {
|
|
109
|
-
const e = new CompressionStream("deflate"), n = [], r = (async () => {
|
|
110
|
-
const l = e.readable.getReader();
|
|
111
|
-
for (; ; ) {
|
|
112
|
-
const { value: i, done: o } = await l.read();
|
|
113
|
-
if (o) break;
|
|
114
|
-
n.push(i);
|
|
115
|
-
}
|
|
116
|
-
})(), a = e.writable.getWriter();
|
|
117
|
-
await a.write(t), await a.close(), await r;
|
|
118
|
-
let f = 0;
|
|
119
|
-
for (const l of n) f += l.length;
|
|
120
|
-
const c = new Uint8Array(f);
|
|
121
|
-
let s = 0;
|
|
122
|
-
for (const l of n)
|
|
123
|
-
c.set(l, s), s += l.length;
|
|
124
|
-
return c;
|
|
125
|
-
};
|
|
126
|
-
async function K(t, e, n, r = {}) {
|
|
127
|
-
if (t.length !== e * n) throw new Error(`gray8: ${t.length} bytes for ${e}x${n}`);
|
|
128
|
-
const a = new Uint8Array(13), f = new DataView(a.buffer);
|
|
129
|
-
f.setUint32(0, e), f.setUint32(4, n), a[8] = 8, a[9] = 0;
|
|
130
|
-
const c = new Uint8Array(n * (1 + e));
|
|
131
|
-
for (let u = 0; u < n; u++) c.set(t.subarray(u * e, (u + 1) * e), u * (1 + e) + 1);
|
|
132
|
-
const s = typeof CompressionStream < "u" ? await J(c) : r.deflate ? r.deflate(c) : (() => {
|
|
133
|
-
throw new Error("gray8: no CompressionStream and no deflate fallback injected");
|
|
134
|
-
})(), l = [H, F("IHDR", a), F("IDAT", s), F("IEND", new Uint8Array(0))];
|
|
135
|
-
let i = 0;
|
|
136
|
-
for (const u of l) i += u.length;
|
|
137
|
-
const o = new Uint8Array(i);
|
|
138
|
-
let d = 0;
|
|
139
|
-
for (const u of l)
|
|
140
|
-
o.set(u, d), d += u.length;
|
|
141
|
-
return o;
|
|
142
|
-
}
|
|
143
|
-
function Q(t) {
|
|
144
|
-
const e = Number(t.display_width) > 0 ? Number(t.display_width) : 120.96, n = Number(t.display_height) > 0 ? Number(t.display_height) : 68.04, r = Number(t.display_pixels_x) > 0 ? Math.round(Number(t.display_pixels_x)) : 2560, a = Number(t.display_pixels_y) > 0 ? Math.round(Number(t.display_pixels_y)) : 1440, f = t.display_mirror_x !== !1, c = t.display_mirror_y === !0, s = (t.display_orientation ?? "portrait") !== "landscape", l = r / e, i = a / n, o = (u) => (f ? e / 2 - u : u + e / 2) * l, d = (u) => (c ? n / 2 - u : u + n / 2) * i;
|
|
145
|
-
return s ? {
|
|
146
|
-
px: a,
|
|
147
|
-
py: r,
|
|
148
|
-
mirrorX: f,
|
|
149
|
-
portrait: s,
|
|
150
|
-
// canvas columns run along the display's y axis, rows along the (mirrored) x axis
|
|
151
|
-
map: (u, p) => [d(p), o(u)]
|
|
152
|
-
} : {
|
|
153
|
-
px: r,
|
|
154
|
-
py: a,
|
|
155
|
-
mirrorX: f,
|
|
156
|
-
portrait: s,
|
|
157
|
-
map: (u, p) => [o(u), d(p)]
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
function tt(t, e, n) {
|
|
161
|
-
const r = e.length / 8;
|
|
162
|
-
if (!r) return 0;
|
|
163
|
-
let a = 0;
|
|
164
|
-
t.beginPath();
|
|
165
|
-
let f = NaN, c = NaN;
|
|
166
|
-
for (let s = 0; s < r; s++) {
|
|
167
|
-
const l = e[s * A], i = e[s * A + 1], o = e[s * A + 4], d = e[s * A + 5];
|
|
168
|
-
(l !== f || i !== c) && (t.moveTo(...n.map(l, i)), a++), t.lineTo(...n.map(o, d)), f = o, c = d;
|
|
169
|
-
}
|
|
170
|
-
return t.fill("evenodd"), a;
|
|
171
|
-
}
|
|
172
|
-
const et = (t) => String(t ?? "");
|
|
173
|
-
function nt({ params: t, stats: e, jobName: n, timestamp: r }) {
|
|
174
|
-
const a = String(t.material_print_speed ?? "fast"), f = {
|
|
175
|
-
action: "print",
|
|
176
|
-
jobDir: n,
|
|
177
|
-
expTime: t.exposure_time,
|
|
178
|
-
expTimeFirst: t.initial_exposure_time,
|
|
179
|
-
expUserProfile: a === "slow" ? 1 : a === "fast" ? 0 : 2,
|
|
180
|
-
fileCreationTimestamp: r ?? "",
|
|
181
|
-
hollow: t.hollowing_enable ? 1 : 0,
|
|
182
|
-
layerHeight: t.layer_height,
|
|
183
|
-
materialName: t.sla_material_settings_id ?? "",
|
|
184
|
-
numFade: t.faded_layers,
|
|
185
|
-
numFast: e.layers,
|
|
186
|
-
numSlow: 0,
|
|
187
|
-
printProfile: t.sla_print_settings_id ?? "",
|
|
188
|
-
printTime: Number(e.time_estimate ?? 0).toFixed(6),
|
|
189
|
-
printerModel: t.printer_model ?? "",
|
|
190
|
-
printerProfile: t.printer_settings_id ?? "",
|
|
191
|
-
printerVariant: t.printer_variant ?? "",
|
|
192
|
-
prusaSlicerVersion: "three-slicer",
|
|
193
|
-
usedMaterial: Number(e.resin_ml ?? 0).toFixed(6)
|
|
194
|
-
};
|
|
195
|
-
return Object.keys(f).sort().map((c) => `${c} = ${et(f[c])}`).join(`
|
|
196
|
-
`) + `
|
|
197
|
-
`;
|
|
198
|
-
}
|
|
199
|
-
const B = (t, e) => `${t}${String(e).padStart(5, "0")}.png`, ot = "Metadata/threeslicer_roles.bin", rt = "Metadata/threeslicer_scene.bin";
|
|
200
|
-
function st({ modelSTL: t, supportMesh: e, padMesh: n, lift: r = 0 }) {
|
|
201
|
-
const a = t instanceof Uint8Array ? t : new Uint8Array(t ?? 0), f = e instanceof Float32Array ? e : new Float32Array(e ?? 0), c = n instanceof Float32Array ? n : new Float32Array(n ?? 0), s = new Uint8Array(12 + a.length + 4 + f.length * 4 + 4 + c.length * 4), l = new DataView(s.buffer);
|
|
202
|
-
s.set([84, 83, 83, 49], 0), l.setFloat32(4, r, !0);
|
|
203
|
-
let i = 8;
|
|
204
|
-
l.setUint32(i, a.length, !0), i += 4, s.set(a, i), i += a.length;
|
|
205
|
-
for (const o of [f, c]) {
|
|
206
|
-
l.setUint32(i, o.length, !0), i += 4;
|
|
207
|
-
for (let d = 0; d < o.length; d++)
|
|
208
|
-
l.setFloat32(i, o[d], !0), i += 4;
|
|
209
|
-
}
|
|
210
|
-
return s;
|
|
211
|
-
}
|
|
212
|
-
function it(t) {
|
|
213
|
-
const e = t.map(({ paths: c }) => {
|
|
214
|
-
const s = [];
|
|
215
|
-
for (let l = 0; l + A - 1 < c.length; l += A) {
|
|
216
|
-
const i = X(c[l + 3]);
|
|
217
|
-
if (i === C.SUPPORT || i === C.RAFT) for (let o = 0; o < A; o++) s.push(c[l + o]);
|
|
218
|
-
}
|
|
219
|
-
return s;
|
|
220
|
-
}), n = 8 + e.reduce((c, s) => c + 4 + s.length * 4, 0), r = new Uint8Array(n), a = new DataView(r.buffer);
|
|
221
|
-
r.set([84, 83, 82, 49], 0), a.setUint32(4, e.length, !0);
|
|
222
|
-
let f = 8;
|
|
223
|
-
for (const c of e) {
|
|
224
|
-
a.setUint32(f, c.length, !0), f += 4;
|
|
225
|
-
for (const s of c)
|
|
226
|
-
a.setFloat32(f, s, !0), f += 4;
|
|
227
|
-
}
|
|
228
|
-
return r;
|
|
229
|
-
}
|
|
230
|
-
function lt({ layers: t, params: e, makeWorker: n, workerCount: r, onProgress: a, aa: f = 1 }) {
|
|
231
|
-
return new Promise((c, s) => {
|
|
232
|
-
const l = new Array(t.length), i = new Array(r).fill(0);
|
|
233
|
-
let o = 0, d = !1;
|
|
234
|
-
const u = [], p = (x) => {
|
|
235
|
-
d = !0, u.forEach((w) => w.terminate()), s(x);
|
|
236
|
-
};
|
|
237
|
-
for (let x = 0; x < r; x++) {
|
|
238
|
-
const w = [], b = [];
|
|
239
|
-
for (let y = x; y < t.length; y += r)
|
|
240
|
-
w.push(y), b.push(t[y].paths);
|
|
241
|
-
const m = n();
|
|
242
|
-
u.push(m), m.onerror = (y) => p(new Error("SL1 encode worker: " + (y?.message || "failed"))), m.onmessage = ({ data: y }) => {
|
|
243
|
-
if (!d) {
|
|
244
|
-
if (y.progress != null) {
|
|
245
|
-
i[x] = y.progress, a?.(i.reduce((_, U) => _ + U, 0), t.length);
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
y.indices.forEach((_, U) => {
|
|
249
|
-
l[_] = y.pngs[U];
|
|
250
|
-
}), m.terminate(), ++o === r && c(l);
|
|
251
|
-
}
|
|
252
|
-
}, m.postMessage({ indices: w, paths: b, params: e, aa: f });
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
async function ut({ layers: t, params: e, stats: n, jobName: r = "plate", timestamp: a, makeCanvas: f, onProgress: c, scene: s = null, makeWorker: l = null, workerCount: i = 0, aa: o = 1, gpuRaster: d = null }) {
|
|
257
|
-
const u = f ?? null, p = Q(e), x = {}, w = l && typeof Worker < "u" && t.length > 1 ? {
|
|
258
|
-
makeWorker: l,
|
|
259
|
-
workerCount: Math.max(1, Math.min(i > 0 ? i : 4, t.length))
|
|
260
|
-
} : null, b = () => performance.now(), m = { canvas: 0, clear: 0, draw: 0, encode: 0, read: 0 }, y = (h, g) => {
|
|
261
|
-
const v = b();
|
|
262
|
-
return m[h] += v - g, v;
|
|
263
|
-
};
|
|
264
|
-
let _ = 0, U = 0;
|
|
265
|
-
const P = async (h) => {
|
|
266
|
-
let g = b();
|
|
267
|
-
if (!u) {
|
|
268
|
-
const I = d ? await d(t[h].paths, p, o, t[h], h) : W(t[h].paths, p, o);
|
|
269
|
-
g = y("draw", g);
|
|
270
|
-
const D = await K(I, p.px, p.py, { deflate: j });
|
|
271
|
-
return y("encode", g), _ += D.length, D;
|
|
272
|
-
}
|
|
273
|
-
const v = u(p.px, p.py), $ = v.getContext("2d");
|
|
274
|
-
g = y("canvas", g), $.fillStyle = "#000", $.fillRect(0, 0, p.px, p.py), g = y("clear", g), $.fillStyle = "#fff", U += tt($, t[h].paths, p), g = y("draw", g);
|
|
275
|
-
const O = await v.convertToBlob({ type: "image/png" });
|
|
276
|
-
g = y("encode", g);
|
|
277
|
-
const T = new Uint8Array(await O.arrayBuffer());
|
|
278
|
-
return y("read", g), _ += T.length, T;
|
|
279
|
-
}, N = b();
|
|
280
|
-
if (w) {
|
|
281
|
-
const h = await lt({ layers: t, params: e, onProgress: c, aa: o, ...w });
|
|
282
|
-
for (let g = 0; g < t.length; g++)
|
|
283
|
-
x[B(r, g)] = [h[g], { level: 0 }], _ += h[g].length;
|
|
284
|
-
} else
|
|
285
|
-
for (let h = 0; h < t.length; h++)
|
|
286
|
-
x[B(r, h)] = [await P(h), { level: 0 }], h & 31 || c?.(h, t.length);
|
|
287
|
-
const E = b();
|
|
288
|
-
x["config.ini"] = V(nt({ params: e, stats: n, jobName: r, timestamp: a })), x[ot] = [it(t), { level: 6 }], s && (x[rt] = [st(s), { level: 6 }]);
|
|
289
|
-
const k = b(), R = z(x), S = (h) => h.toFixed(0);
|
|
290
|
-
return Y.info(`[vp-prof] sl1 build: ${t.length} layers ${p.px}x${p.py},` + (w ? ` raster ${S(E - N)}ms (${w.workerCount} workers),` : ` ${U} loops, raster ${S(E - N)}ms (canvas ${S(m.canvas)} + clear ${S(m.clear)} + draw ${S(m.draw)} + encode ${S(m.encode)} + read ${S(m.read)}),`) + ` sidecar ${S(k - E)}ms, zip ${S(b() - k)}ms -> ${(R.byteLength / 1e6).toFixed(1)}MB (png ${(_ / 1e6).toFixed(1)}MB)`), R;
|
|
291
|
-
}
|
|
292
|
-
export {
|
|
293
|
-
rt as S,
|
|
294
|
-
ot as a,
|
|
295
|
-
G as b,
|
|
296
|
-
ft as c,
|
|
297
|
-
tt as d,
|
|
298
|
-
K as e,
|
|
299
|
-
Y as l,
|
|
300
|
-
ut as m,
|
|
301
|
-
W as r,
|
|
302
|
-
Q as s
|
|
303
|
-
};
|