three-slicer-viewer 0.3.3 → 0.3.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/TOOLPATH_SPEC.md +8 -1
- package/data/config-schema-lean.json +1 -1
- package/dist/gcode_parse.js +149 -110
- package/dist/index.js +4547 -4304
- 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 +274 -220
- package/package.json +1 -1
- package/src/settings/bed_frame.js +28 -0
- package/src/settings/index.js +1 -0
- package/src/settings/kernel_setting_keys.js +51 -0
- package/src/settings/settings_core.js +253 -60
- package/types/gcode.d.ts +13 -0
- package/types/settings.d.ts +14 -1
- package/types/toolpath.d.ts +6 -0
- package/dist/sl1_write-BovHbg3k.js +0 -303
|
@@ -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
|
-
};
|