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