@rulecad/printcheck 0.1.0 → 0.1.1
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/package.json +8 -3
- package/printcheck.d.mts +67 -0
- package/printcheck.mjs +27 -0
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/printcheck",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Is this mesh printable? Bed fit, flat base, overhangs, bridges, breakaway supports and watertightness, for any FDM printer.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"exports":
|
|
6
|
+
"exports": {
|
|
7
|
+
"types": "./printcheck.d.mts",
|
|
8
|
+
"default": "./printcheck.mjs"
|
|
9
|
+
},
|
|
7
10
|
"files": [
|
|
8
11
|
"printcheck.mjs",
|
|
12
|
+
"printcheck.d.mts",
|
|
9
13
|
"README.md",
|
|
10
14
|
"LICENSE"
|
|
11
15
|
],
|
|
@@ -28,5 +32,6 @@
|
|
|
28
32
|
},
|
|
29
33
|
"scripts": {
|
|
30
34
|
"test": "node --test"
|
|
31
|
-
}
|
|
35
|
+
},
|
|
36
|
+
"types": "./printcheck.d.mts"
|
|
32
37
|
}
|
package/printcheck.d.mts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The box around faces.
|
|
3
|
+
* @param {Face[]} polys
|
|
4
|
+
* @returns {{ lo: Point, hi: Point, size: Point }}
|
|
5
|
+
*/
|
|
6
|
+
/** @typedef {[number, number, number]} Point a corner in mm, Z up */
|
|
7
|
+
/** @typedef {Point[]} Face a polygon: three or more corners, counter-clockwise seen from outside */
|
|
8
|
+
/** @typedef {{ bed: number, overhang: number, layer?: number, support_gap?: number, bridge?: number }} Printer mm and degrees */
|
|
9
|
+
/** @typedef {{ level: 'pass' | 'warn' | 'fail', text: string }} Finding */
|
|
10
|
+
export function bounds(polys: any): {
|
|
11
|
+
lo: number[];
|
|
12
|
+
hi: number[];
|
|
13
|
+
size: number[];
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Is it printable? Findings in plain words, each pass, warn or fail.
|
|
17
|
+
* @param {Face[]} polys the model as faces (triangles are fine), Z up, the bed at z = 0
|
|
18
|
+
* @param {Printer} printer the printer's limits
|
|
19
|
+
* @param {{ eps?: number, parts?: { triangles: Face[], role?: 'part' | 'support' }[] }} [options]
|
|
20
|
+
* @returns {Finding[]}
|
|
21
|
+
*/
|
|
22
|
+
export function check(polys: Face[], printer: Printer, { eps, parts }?: {
|
|
23
|
+
eps?: number;
|
|
24
|
+
parts?: {
|
|
25
|
+
triangles: Face[];
|
|
26
|
+
role?: "part" | "support";
|
|
27
|
+
}[];
|
|
28
|
+
}): Finding[];
|
|
29
|
+
/**
|
|
30
|
+
* The widest circle that fits in an underside, measured to its held-up edges (the bridge it makes).
|
|
31
|
+
* @param {Face[]} polys @param {(edge: [Point, Point]) => boolean} [held] @param {Face[]} [under]
|
|
32
|
+
* @returns {number} mm
|
|
33
|
+
*/
|
|
34
|
+
export function widest(polys: Face[], held?: (edge: [Point, Point]) => boolean, under?: Face[]): number;
|
|
35
|
+
/**
|
|
36
|
+
* Open edges, sorted: real gaps, T-junctions (closed) and hairline seams (closed).
|
|
37
|
+
* @param {Face[]} polys @param {number} [eps]
|
|
38
|
+
* @returns {{ gaps: number, tjunctions: number, hairlines: number }}
|
|
39
|
+
*/
|
|
40
|
+
export function seams(polys: Face[], eps?: number): {
|
|
41
|
+
gaps: number;
|
|
42
|
+
tjunctions: number;
|
|
43
|
+
hairlines: number;
|
|
44
|
+
};
|
|
45
|
+
export const HAIRLINE: 0.01;
|
|
46
|
+
/**
|
|
47
|
+
* a corner in mm, Z up
|
|
48
|
+
*/
|
|
49
|
+
export type Point = [number, number, number];
|
|
50
|
+
/**
|
|
51
|
+
* a polygon: three or more corners, counter-clockwise seen from outside
|
|
52
|
+
*/
|
|
53
|
+
export type Face = Point[];
|
|
54
|
+
/**
|
|
55
|
+
* mm and degrees
|
|
56
|
+
*/
|
|
57
|
+
export type Printer = {
|
|
58
|
+
bed: number;
|
|
59
|
+
overhang: number;
|
|
60
|
+
layer?: number;
|
|
61
|
+
support_gap?: number;
|
|
62
|
+
bridge?: number;
|
|
63
|
+
};
|
|
64
|
+
export type Finding = {
|
|
65
|
+
level: "pass" | "warn" | "fail";
|
|
66
|
+
text: string;
|
|
67
|
+
};
|
package/printcheck.mjs
CHANGED
|
@@ -17,6 +17,16 @@ function areaNormal(poly) {
|
|
|
17
17
|
|
|
18
18
|
const OVERHANG_SLACK = 0.5; // degrees
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* The box around faces.
|
|
22
|
+
* @param {Face[]} polys
|
|
23
|
+
* @returns {{ lo: Point, hi: Point, size: Point }}
|
|
24
|
+
*/
|
|
25
|
+
/** @typedef {[number, number, number]} Point a corner in mm, Z up */
|
|
26
|
+
/** @typedef {Point[]} Face a polygon: three or more corners, counter-clockwise seen from outside */
|
|
27
|
+
/** @typedef {{ bed: number, overhang: number, layer?: number, support_gap?: number, bridge?: number }} Printer mm and degrees */
|
|
28
|
+
/** @typedef {{ level: 'pass' | 'warn' | 'fail', text: string }} Finding */
|
|
29
|
+
|
|
20
30
|
export function bounds(polys) {
|
|
21
31
|
const lo = [Infinity, Infinity, Infinity], hi = [-Infinity, -Infinity, -Infinity]; // a loop: spreading big models overflows the stack
|
|
22
32
|
for (const p of polys) for (const v of p) for (let k = 0; k < 3; k++) { if (v[k] < lo[k]) lo[k] = v[k]; if (v[k] > hi[k]) hi[k] = v[k]; }
|
|
@@ -26,6 +36,13 @@ export function bounds(polys) {
|
|
|
26
36
|
// parts ([{ triangles, role }]): when parts print together (a keycap and its inlaid legend), an underside resting on
|
|
27
37
|
// another part isn't an overhang, and each part must be closed on its own (their shared faces are inside the print).
|
|
28
38
|
// printer: the printer's rules, any printer: { bed, overhang (degrees), layer, support_gap?, bridge? } in mm.
|
|
39
|
+
/**
|
|
40
|
+
* Is it printable? Findings in plain words, each pass, warn or fail.
|
|
41
|
+
* @param {Face[]} polys the model as faces (triangles are fine), Z up, the bed at z = 0
|
|
42
|
+
* @param {Printer} printer the printer's limits
|
|
43
|
+
* @param {{ eps?: number, parts?: { triangles: Face[], role?: 'part' | 'support' }[] }} [options]
|
|
44
|
+
* @returns {Finding[]}
|
|
45
|
+
*/
|
|
29
46
|
export function check(polys, printer, { eps = 1e-3, parts = null } = {}) {
|
|
30
47
|
const out = [], f = (level, text) => out.push({ level, text });
|
|
31
48
|
const solids = (parts || []).filter((p) => p.role !== 'support').map((p) => ({ tris: p.triangles, box: bounds(p.triangles) }));
|
|
@@ -114,6 +131,11 @@ export function check(polys, printer, { eps = 1e-3, parts = null } = {}) {
|
|
|
114
131
|
// (held(a, b) -> true), or to the tops of breakaway supports one layer below (under: faces): its diameter in mm, the
|
|
115
132
|
// gap a bridge has to span. null if nothing holds it up.
|
|
116
133
|
// Sampled: points spread over each face, each measured to the held edges of the region's outline and to the supports.
|
|
134
|
+
/**
|
|
135
|
+
* The widest circle that fits in an underside, measured to its held-up edges (the bridge it makes).
|
|
136
|
+
* @param {Face[]} polys @param {(edge: [Point, Point]) => boolean} [held] @param {Face[]} [under]
|
|
137
|
+
* @returns {number} mm
|
|
138
|
+
*/
|
|
117
139
|
export function widest(polys, held = () => true, under = []) {
|
|
118
140
|
const key = (v) => `${v[0].toFixed(3)},${v[1].toFixed(3)}`, count = new Map(), edges = [];
|
|
119
141
|
for (const p of polys) p.forEach((a, i) => { const b = p[(i + 1) % p.length], k = [key(a), key(b)].sort().join('|'); count.set(k, (count.get(k) || 0) + 1); edges.push([k, a, b]); });
|
|
@@ -163,6 +185,11 @@ function pointToTriangle(p, a, b, c) { // Ericson, Real-Time Collision Detection
|
|
|
163
185
|
const den = 1 / (va + vb + vc);
|
|
164
186
|
return at(mix(1 - vb * den - vc * den, vb * den, vc * den));
|
|
165
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Open edges, sorted: real gaps, T-junctions (closed) and hairline seams (closed).
|
|
190
|
+
* @param {Face[]} polys @param {number} [eps]
|
|
191
|
+
* @returns {{ gaps: number, tjunctions: number, hairlines: number }}
|
|
192
|
+
*/
|
|
166
193
|
export function seams(polys, eps = 1e-3) {
|
|
167
194
|
const key = (v) => v.map((c) => Math.round(c / eps)).join(','), segs = [], count = new Map();
|
|
168
195
|
for (const p of polys) p.forEach((a, i) => { const b = p[(i + 1) % p.length]; if (key(a) !== key(b)) { segs.push([a, b]); const k = `${key(a)}|${key(b)}`; count.set(k, (count.get(k) || 0) + 1); } });
|