From a661ef618a4b47c6e9c7f9942ba6d5802953efa0 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Thu, 23 Apr 2020 16:19:28 -0400 Subject: [PATCH] synthesize a support widget to encapsulate nozzle and other settings --- js/kiri-driver-fdm.js | 40 +++++++++++++++++++++++++++++++++++++--- js/kiri-print.js | 12 ++++++++++-- js/kiri-slice.js | 21 +++++++++++++++------ js/kiri-widget.js | 1 + js/kiri.js | 2 +- notes.md | 1 - 6 files changed, 64 insertions(+), 13 deletions(-) diff --git a/js/kiri-driver-fdm.js b/js/kiri-driver-fdm.js index 3047ebea..76bb707e 100644 --- a/js/kiri-driver-fdm.js +++ b/js/kiri-driver-fdm.js @@ -393,7 +393,7 @@ let gs_kiri_fdm = exports; * @param {Function} update incremental callback */ function printSetup(print, update) { - let widgets = print.widgets, + let widgets = print.widgets.slice(), settings = fixExtruders(print.settings), device = settings.device, nozzle = device.extruders[0].extNozzle, @@ -542,6 +542,32 @@ let gs_kiri_fdm = exports; bounds.max.y = Math.max(bounds.max.y, bbounds.maxy); } + // synthesize a support widget, if needed + if (process.sliceSupportEnable) { + let swidget = KIRI.newWidget(); + let sslices = swidget.slices = []; + widgets.forEach(function(widget) { + let slices = widget.slices; + while (sslices.length < slices.length) { + let sslice = KIRI.newSlice(slices[sslices.length].z); + sslice.extruder = process.sliceSupportNozzle; + sslices.push(sslice); + } + slices.forEach((slice,index) => { + if (!slice.supports) return; + if (sslices[index].supports) { + sslices[index].supports.appendAll(slice.supports); + } else { + sslices[index].supports = slice.supports; + } + }); + }); + swidget.support = true; + swidget.mesh = { widget: swidget }; // fake for lookup + settings.widget[swidget.id] = { extruder: process.sliceSupportNozzle }; + widgets.push(swidget); + } + let extruders = []; let extcount = 0; @@ -615,7 +641,11 @@ let gs_kiri_fdm = exports; } let mslices = mesh.widget.slices; if (mslices && mslices[layer]) { - slices.push({slice:mslices[layer], offset:mesh.position}); + slices.push({ + slice: mslices[layer], + offset: mesh.position || {x:0, y:0, z:0}, + widget: mesh.widget + }); } } @@ -656,6 +686,7 @@ let gs_kiri_fdm = exports; closest = find.sliceEntry; minidx = find.meshIndex; } + if (!closest) { if (sliceEntry) lastOut = sliceEntry.slice; break; @@ -677,7 +708,10 @@ let gs_kiri_fdm = exports; printPoint.sub(closest.offset), closest.offset, layerout, - { first: closest.slice.index === 0 } + { + first: closest.slice.index === 0, + support: closest.widget.support + } ); lastOut = closest.slice; lastExt = lastOut.ext diff --git a/js/kiri-print.js b/js/kiri-print.js index 6d88e7ad..a2f9a41c 100644 --- a/js/kiri-print.js +++ b/js/kiri-print.js @@ -648,6 +648,7 @@ let gs_kiri_print = exports; origin = startPoint.add(offset), zhop = process.zHopDistance || 0, antiBacklash = process.antiBacklash, + doSupport = opt.support, z = slice.z; // apply first layer extrusion multipliers @@ -867,9 +868,16 @@ let gs_kiri_print = exports; } } - let all = [].appendAll(slice.supports || []).appendAll(slice.tops || []); + let out = []; + if (slice.tops) { + out.appendAll(slice.tops); + }; + if (opt.support && slice.supports) { + out.appendAll(slice.supports); + } + let lastTop = null; - outputOrderClosest(all || [], function(next) { + outputOrderClosest(out, function(next) { if (next instanceof Polygon) { // support polygon next.setZ(z); diff --git a/js/kiri-slice.js b/js/kiri-slice.js index 2872efd9..0f1506b5 100644 --- a/js/kiri-slice.js +++ b/js/kiri-slice.js @@ -1226,12 +1226,21 @@ let gs_kiri_slice = exports; PRO.findClosestPointTo = function(target) { let min, find; - this.tops.forEach(function(top) { - find = top.poly.findClosestPointTo(target); - if (!min || find.distance < min.distance) { - min = find; - } - }); + if (this.tops.length) { + this.tops.forEach(function(top) { + find = top.poly.findClosestPointTo(target); + if (!min || find.distance < min.distance) { + min = find; + } + }); + } else if (this.supports) { + this.supports.forEach(function(poly) { + find = poly.findClosestPointTo(target); + if (!min || find.distance < min.distance) { + min = find; + } + }); + } return min; }; diff --git a/js/kiri-widget.js b/js/kiri-widget.js index 5770cc4e..1a56c6f9 100644 --- a/js/kiri-widget.js +++ b/js/kiri-widget.js @@ -153,6 +153,7 @@ let gs_kiri_widget = exports; progress: 0 }; this.saved = false; + this.support = false; // is synthesized support widget } /** ****************************************************************** diff --git a/js/kiri.js b/js/kiri.js index 0586226b..d98bc1ee 100644 --- a/js/kiri.js +++ b/js/kiri.js @@ -1153,7 +1153,7 @@ self.kiri.copyright = exports.COPYRIGHT; space = space || proc.outputTileSpacing || 1; break; case MODES.FDM: - space = space || (proc.sliceSupportExtra || 0) + 1; + space = space || ((proc.sliceSupportExtra || 0) * 2) + 1; break; } diff --git a/notes.md b/notes.md index ac9ee228..149d4886 100644 --- a/notes.md +++ b/notes.md @@ -14,7 +14,6 @@ # FDM -* `B` check for support / brim intersections on first layer * `F` add separate fill speed control * `F` manual support addition / control * `F` polishing and other non-planar work