From 3a715a24fe9ed813864b96aee25f94bc73647fad Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Wed, 4 Mar 2020 21:47:05 -0500 Subject: [PATCH] switch polish from line segments to polys --- js/kiri-driver-fdm.js | 71 ++++++++++++++++++++++++------------------- js/kiri-print.js | 22 +++++++++----- js/kiri-slice.js | 12 ++++++-- 3 files changed, 62 insertions(+), 43 deletions(-) diff --git a/js/kiri-driver-fdm.js b/js/kiri-driver-fdm.js index ee333d5f..9486f403 100644 --- a/js/kiri-driver-fdm.js +++ b/js/kiri-driver-fdm.js @@ -164,8 +164,8 @@ var gs_kiri_fdm = exports; let polish = spro.layerPolishing; // experimental polishing if (polish) { - let px, py; widget.polish = {}; + let pa = []; // compute x polishing slices SLICER.sliceWidget(widget, { height: sdev.nozzleSize, @@ -173,29 +173,28 @@ var gs_kiri_fdm = exports; swapY: false, simple: true }, (polish_done => { - px = widget.polish.x = polish_done + widget.polish.x = polish_done .filter(s => s.groups.length) - .map(s => s.groups); + .map(s => s.groups) + .forEach(p => pa.appendAll(p)); }), (polish_update) => { // console.log({polish_update}); }); // compute y polishing slices - SLICER.sliceWidget(widget, { - height: sdev.nozzleSize, - swapX: false, - swapY: true, - simple: true - }, (polish_done => { - py = widget.polish.y = polish_done - .filter(s => s.groups.length) - .map(s => s.groups); - }), (polish_update) => { - // console.log({polish_update}); - }); + // SLICER.sliceWidget(widget, { + // height: sdev.nozzleSize, + // swapX: false, + // swapY: true, + // simple: true + // }, (polish_done => { + // widget.polish.y = polish_done + // .filter(s => s.groups.length) + // .map(s => s.groups) + // .forEach(p => pa.appendAll(p)); + // }), (polish_update) => { + // // console.log({polish_update}); + // }); // apply polishing finishes to layers - let pa = []; - px.forEach(p => pa.appendAll(p)); - py.forEach(p => pa.appendAll(p)); forSlices(1.0, 1.0, slice => { if (slice.index >= polish) { let sd = slice; @@ -204,11 +203,11 @@ var gs_kiri_fdm = exports; } let zb = sd.z; let zt = slice.z; - let lines = []; - let lastp; - let equal = 0; - let points = 0; + let polys = []; + let cont = 0; pa.forEach(p => { + let lastp = undefined; + let poly = []; p.forEachSegment((p1, p2) => { // return when both below if (p1.z < zb && p2.z < zb) { @@ -246,7 +245,7 @@ var gs_kiri_fdm = exports; } let slope = BASE.newSlope(p1, p2); let angle = Math.abs(slope.angle); - if (angle > 20 && angle < 160) { + if (angle > 40 && angle < 140) { return; } let len = p1.distTo2D(p2); @@ -273,19 +272,27 @@ var gs_kiri_fdm = exports; p1 = BASE.newPoint(p1.x,p1.z,p1.y); p2 = BASE.newPoint(p2.x,p2.z,p2.y); } - p1.index = p2.index = 1; - if (lastp && p1.isEqual(lastp)) { - equal++; + if (!lastp) { + poly.push(p1); + poly.push(p2); + } else if (p1.isEqual(lastp)) { + poly.push(p2); + cont++; + } else if (poly.length) { + polys.push(poly); + poly = [p1, p2]; } - lines.push(p1); - lines.push(lastp = p2); - points++; + lastp = p2; }); + if (poly.length) { + polys.push(poly); + } }); - if (lines.length && slice.tops.length) { - slice.tops[0].polish = lines; + if (polys.length && slice.tops.length) { + slice.tops[0].polish = polys + .map(a => BASE.newPolygon(a).setOpen()) + .filter(p => p.perimeter() > sdev.nozzleSize); } - console.log(slice.z,equal,points); } }); } diff --git a/js/kiri-print.js b/js/kiri-print.js index 3402eee3..8680adea 100644 --- a/js/kiri-print.js +++ b/js/kiri-print.js @@ -299,6 +299,10 @@ var gs_kiri_print = exports; } }; + function pref(a,b) { + return a !== undefined ? a : b; + } + // hsv values all = 0 to 1 function hsv2rgb(hsv) { var seg = Math.floor(hsv.h * 6); @@ -463,7 +467,7 @@ var gs_kiri_print = exports; var options = options || {}, process = this.settings.process, shortDist = process.outputShortDistance, - shellMult = options.extrude || process.outputShellMult, + shellMult = pref(options.extrude, process.outputShellMult), printSpeed = options.rate || process.outputFeedrate, moveSpeed = process.outputSeekrate, minSpeed = process.outputMinSpeed, @@ -567,11 +571,11 @@ var gs_kiri_print = exports; return int; } - function outputTraces(poly, bounds) { + function outputTraces(poly, extrude) { if (!poly) return; if (Array.isArray(poly)) { outputOrderClosest(poly, function(next) { - outputTraces(next, bounds); + outputTraces(next, extrude); }, null); } else { var finishShell = poly.depth === 0 && !firstLayer; @@ -580,7 +584,7 @@ var gs_kiri_print = exports; accel: finishShell, wipe: process.outputWipeDistance || 0, coast: firstLayer ? 0 : coastDist, - extrude: shellMult, + extrude: pref(extrude, shellMult), onfirst: function(firstPoint) { if (startPoint.distTo2D(firstPoint) > retractDist) { retract(); @@ -775,18 +779,18 @@ var gs_kiri_print = exports; // output inner polygons if (dir === 1) - outputTraces([].appendAll(next.innerTraces() || []), bounds); + outputTraces([].appendAll(next.innerTraces() || [])); // sort perimeter polygon by length to go out-to-in or in-to-out (next.traces || []).sort(function(a,b) { return a.perimeter() > b.perimeter() ? dir : -dir; }).forEach(function(poly, index) { - outputTraces(poly, bounds); + outputTraces(poly); }); // output inner polygons if (dir === -1) - outputTraces([].appendAll(next.innerTraces() || []), bounds); + outputTraces([].appendAll(next.innerTraces() || [])); // then output solid and sparse fill outputFills(next.fill_lines); @@ -801,7 +805,9 @@ var gs_kiri_print = exports; // produce polishing paths when present if (slice.tops.length) { let polish = slice.tops[0].polish; - outputFills(polish, {fast: true, fill:0}); + if (polish) { + outputTraces(polish, 0); + } } // offset print points diff --git a/js/kiri-slice.js b/js/kiri-slice.js index 9de9402d..31b32c28 100644 --- a/js/kiri-slice.js +++ b/js/kiri-slice.js @@ -549,7 +549,12 @@ var gs_kiri_slice = exports; layer = layers.trace; break; } - if (top.traces) layer.poly(top.traces, trace_color, true, null); + if (top.traces) { + layer.poly(top.traces, trace_color, true, null); + } + if (top.polish) { + layer.poly(top.polish, 0x880000, true, null); + } }); layer.render(); @@ -618,8 +623,9 @@ var gs_kiri_slice = exports; layer.clear(); this.tops.forEach(function(top) { - if (top.fill_lines) layer.lines(top.fill_lines, fill_color); - if (top.polish) layer.lines(top.polish, 0x880000); + if (top.fill_lines) { + layer.lines(top.fill_lines, fill_color); + } }); layer.render();