From e7a050e03e856fc13691f1b9539ddaba8cc7fa76 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Sun, 8 Nov 2020 08:19:05 -0500 Subject: [PATCH] add missing thin wall render --- src/kiri/codec.js | 2 -- src/kiri/main.js | 2 +- src/kiri/print.js | 6 +++--- src/kiri/slice.js | 38 ++++++++++++++++++++++++++------------ src/mode/fdm/client.js | 1 - src/mode/fdm/prepare.js | 3 +++ src/mode/fdm/slice.js | 6 ++++-- 7 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/kiri/codec.js b/src/kiri/codec.js index 261dfc73..48af2178 100644 --- a/src/kiri/codec.js +++ b/src/kiri/codec.js @@ -157,7 +157,6 @@ registerDecoder('top', function(v, state) { let top = KIRI.newTop(decode(v.poly, state)); - // top.traces = decode(v.traces, state); // top.inner = decode(v.inner, state); // // top.thinner = decode(v.thinner, state); @@ -166,7 +165,6 @@ // top.fill_lines = decodePointArray(v.fill_lines, state); // top.fill_sparse = decode(v.fill_sparse, state); // top.polish = decode(v.polish, state); - return top; }); diff --git a/src/kiri/main.js b/src/kiri/main.js index c3c4dd5c..dcc3ba66 100644 --- a/src/kiri/main.js +++ b/src/kiri/main.js @@ -32,7 +32,7 @@ VIEWS = CONF.VIEWS, clone = Object.clone, settings = clone(CONF.template), - settingsDefault = clone(settings), + // settingsDefault = clone(settings), // --------------- Widget = kiri.Widget, newWidget = kiri.newWidget, diff --git a/src/kiri/print.js b/src/kiri/print.js index 8cc1c4f2..b4de9f7f 100644 --- a/src/kiri/print.js +++ b/src/kiri/print.js @@ -614,7 +614,7 @@ function intersectsTop(p1, p2) { let int = false; - POLY.flatten(slice.gatherTopPolys([])).forEach(function(poly) { + POLY.flatten(slice.topPolys().clone(true)).forEach(function(poly) { if (!int) poly.forEachSegment(function(s1, s2) { if (UTIL.intersect(p1,p2,s1,s2,BASE.key.SEGINT)) { int = true; @@ -879,7 +879,7 @@ } } else { // top object - let bounds = POLY.flatten(next.gatherOuter([])); + let bounds = POLY.flatten(next.shellsAtDepth(0)); let dir = -1; // 1 == inside out, -1 == outside-in @@ -888,7 +888,7 @@ outputTraces([].appendAll(next.innerTraces() || [])); // sort perimeter polygon by length to go out-to-in or in-to-out - (next.traces || []).sort(function(a,b) { + (next.shells || []).sort(function(a,b) { return a.perimeter() > b.perimeter() ? dir : -dir; }).forEach(function(poly, index) { outputTraces(poly); diff --git a/src/kiri/slice.js b/src/kiri/slice.js index 165ebbf5..4251e9d0 100644 --- a/src/kiri/slice.js +++ b/src/kiri/slice.js @@ -69,17 +69,14 @@ }; /** - * Appends all outermost trace polygons into a given array - * and returns it. used by Print + * Returns shell polygons of a given depth + * used by Print (FDM) * * @param {Polygon[]} out array to populate * @returns {Polygon[]} array of top polygons */ - Top.prototype.gatherOuter = function(out) { - this.traces.forEach(function(trace) { - if (trace.depth === 0) out.append(trace); - }); - return out; + Top.prototype.shellsAtDepth = function(depth) { + return this.shells.filter(poly => poly.depth === depth); }; /** ****************************************************************** @@ -161,17 +158,34 @@ return this; } - /** - * Create a new top object given a polygon - * - * @param {Polygon} poly to add - */ PRO.addTop = function(poly) { let top = new Top(poly); this.tops.push(top); return top; }; + PRO.findClosestPointTo = function(target) { + let 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; + }; + function newTop(poly) { return new Top(poly); } diff --git a/src/mode/fdm/client.js b/src/mode/fdm/client.js index fd68251a..2adcd0f3 100644 --- a/src/mode/fdm/client.js +++ b/src/mode/fdm/client.js @@ -160,7 +160,6 @@ }); } - FDM.printRender = function(print, options) { let debug = KIRI.api.const.LOCAL; let scope = print, emits, last, diff --git a/src/mode/fdm/prepare.js b/src/mode/fdm/prepare.js index 7286fe90..4f883735 100644 --- a/src/mode/fdm/prepare.js +++ b/src/mode/fdm/prepare.js @@ -7,6 +7,7 @@ let KIRI = self.kiri, BASE = self.base, UTIL = BASE.util, + POLY = BASE.polygons, FDM = KIRI.driver.FDM, newPoint = BASE.newPoint; @@ -368,6 +369,8 @@ layerout = []; lastOut = undefined; } + + console.log({output}); }; })(); diff --git a/src/mode/fdm/slice.js b/src/mode/fdm/slice.js index 84042ab9..f8f4ba11 100644 --- a/src/mode/fdm/slice.js +++ b/src/mode/fdm/slice.js @@ -444,6 +444,10 @@ .setLayer("infill", COLOR.infill) .addPolys(top.fill_sparse, vopt({ offset, height, open: true, outline: true })) + if (top.thin_fill) output + .setLayer("fill", COLOR.fill) + .addLines(top.thin_fill, vopt({ offset, height })); + // emit solid areas // if (isThin && debug) { // output @@ -607,8 +611,6 @@ return; } - const render = slice.output(); - slice.tops.forEach(function(top) { const lines = fillArea(top.fill_off, angle, spacing, null); top.fill_lines.appendAll(lines);