add proper shell output ordering with next closest algorithm

This commit is contained in:
Stewart Allen 2025-09-21 21:20:36 -04:00
commit 813ae0d9e6
2 changed files with 42 additions and 17 deletions

View file

@ -205,7 +205,6 @@ function thin_type_3(params) {
remain, remain,
traces, traces,
brute: false, brute: false,
showMedialAxis: false,
showChainIntersect: false showChainIntersect: false
}); });
@ -234,8 +233,7 @@ function thin_type_3(params) {
// create shell depth annotation that will survive serialization // create shell depth annotation that will survive serialization
top.thin_sort = traces.map(a => a.shell); top.thin_sort = traces.map(a => a.shell);
console.log({ this: (self.kiri_minion?.name ?? self.kiri_worker), traces }); // console.log({ this: (self.kiri_minion?.name ?? self.kiri_worker), traces });
return { traces, last: remain }; return { traces, last: remain };
} }
@ -244,7 +242,6 @@ function trace_noodle(noodle, noodleWidth, minR, midR, maxR, opt = {}) {
let { let {
brute, brute,
showInset, showInset,
showMedialAxis,
showChainIntersect, showChainIntersect,
minArea = midR * midR, minArea = midR * midR,
shellStep = 1 / 30, // diameter step as % of nozzle shellStep = 1 / 30, // diameter step as % of nozzle

View file

@ -1089,21 +1089,49 @@ function slicePrintPath(print, slice, startPoint, offset, output, opt = {}) {
} }
} }
function outputAdaptiveWalls(thin, sort, opt = {}) { function minThinDist(np, trace) {
return Math.min(
Math.hypot(np.x - trace[0].x, np.y - trace[0].y),
Math.hypot(np.x - trace.peek().x, np.y - trace.peek().y),
);
}
function outputAdaptiveWalls(thin, sort) {
// restore thin shell order annotation and sort on it // restore thin shell order annotation and sort on it
thin.forEach((a,i) => a.shell = sort[i]); thin.forEach((a,i) => a.shell = sort[i] * shellOrder);
thin.sort((a,b) => (a.shell - b.shell) * shellOrder); thin.forEach(t => t.shell = t.shell < 0 ? Math.abs(t.shell) + 0.5 : t.shell);
// perform nearest poly to poly algorithm on shells thin.sort((a,b) => a.shell - b.shell);
let np; let np;
for (let trace of thin) // perform nearest poly to poly algorithm on shells
for (let pt of trace) { for (;;) {
let { lastPoint, lastEmit } = print; let min = { dist: Infinity };
let { x, y, r } = pt; for (let trace of thin) {
np = new Point(x, y, z); if (!min.trace) {
if (lastPoint && lastPoint.distTo2D(np) > retractDist) { min.trace = trace;
print.addOutput(preout, np, 0, moveSpeed); } else if (np && min.trace.shell === trace.shell) {
} else { let dist = minThinDist(np, trace);
print.addOutput(preout, np, ((r * 2) / nozzleSize) * shellMult, printSpeed); if (dist < min.dist) min = { dist, trace };
}
}
if (!min.trace) {
return;
}
let { trace } = min;
let fp = trace[0];
let lp = trace.peek();
// reverse trace if far end closer
if (np && Math.hypot(np.x - lp.x, np.y - lp.y) < Math.hypot(np.x - fp.x, np.y - fp.y)) {
trace.reverse();
}
// remove emitted trace
thin = thin.filter(t => t !== trace);
for (let pt of trace) {
np = new Point(pt.x, pt.y, z);
if (pt === trace[0]) {
print.addOutput(preout, np, 0, moveSpeed);
} else {
print.addOutput(preout, np, ((pt.r * 2) / nozzleSize) * shellMult, printSpeed);
}
} }
} }
} }