From 5e6c4b91aab09c9286edc2241d0c9fce6903447a Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Thu, 30 Dec 2021 17:35:10 -0500 Subject: [PATCH] add array grouping and walk order. add new thin fill output method --- src/add/array.js | 14 ++++++++++++++ src/geo/base.js | 34 ++++++++++++++++++++++++++++++++++ src/kiri/print.js | 33 ++++++++++++++++++++++++++++++++- src/kiri/slice.js | 2 +- 4 files changed, 81 insertions(+), 2 deletions(-) diff --git a/src/add/array.js b/src/add/array.js index 33145b12..29bfd3d6 100644 --- a/src/add/array.js +++ b/src/add/array.js @@ -180,6 +180,20 @@ return this.filter(v => isNaN(v)).length > 0; }; + // turn array into arrays of specified size + AP.group = function(size) { + let na = new Array(Math.ceil(this.length / size)); + let nai = 0; + for (let i=0; i { if (!v) return v; diff --git a/src/kiri/print.js b/src/kiri/print.js index a4d22d0c..c8b3fc9f 100644 --- a/src/kiri/print.js +++ b/src/kiri/print.js @@ -834,6 +834,37 @@ }); } + function outputThin(lines) { + let points = lines.group(2).map(grp => { + let [ p1, p2 ] = grp; + return newPoint( + (p1.x + p2.x) / 2, + (p1.y + p2.y) / 2, + (p1.z + p2.z) / 2 + ) + }); + let order = UTIL.orderClosest(points, (p1, p2) => p1.distTo2D(p2)); + if (order.length === 0) { + return; + } + let first = points[0]; + let last = first; + addOutput(preout, first, 0, moveSpeed, extruder); + for (let p of order) { + let dist = last ? last.distTo2D(p) : 0; + if (dist > thinWall) { + retract(); + addOutput(preout, p, 0, moveSpeed, extruder); + } + addOutput(preout, p, 1, fillSpeed, extruder); + last = p; + } + // close a circle + if (last && last.distTo2D(first) <= thinWall) { + addOutput(preout, first, 1, fillSpeed, extruder); + } + } + function outputFills(lines, opt = {}) { if (!lines || lines.length === 0) { return; @@ -1078,7 +1109,7 @@ setType('int'); // output thin fill - outputFills(next.thin_fill, {near: true}); + outputThin(next.thin_fill); // then output solid and sparse fill outputFills(next.fill_lines, {flow: solidWidth}); diff --git a/src/kiri/slice.js b/src/kiri/slice.js index 61bf4f96..4125ac5b 100644 --- a/src/kiri/slice.js +++ b/src/kiri/slice.js @@ -189,7 +189,7 @@ } else { // frop top object passed back by slicePost() let top = new Top(poly.poly); - top.thin_fill = poly.thin_fill.map(p => BASE.newPoint(p.x,p.y,p.z)); + top.thin_fill = poly.thin_fill ? poly.thin_fill.map(p => BASE.newPoint(p.x,p.y,p.z)) : undefined; top.fill_lines = poly.fill_lines; top.fill_off = poly.fill_off; top.last = poly.last;