diff --git a/src/kiri/print.js b/src/kiri/print.js index 2b8f1c92..a7545ce9 100644 --- a/src/kiri/print.js +++ b/src/kiri/print.js @@ -471,7 +471,7 @@ if (options.onfirst) { options.onfirst(point); } - // move from startPoint to point + // move to first output point on poly addOutput(output, point, 0, moveSpeed, tool); first = false; } else { @@ -564,18 +564,134 @@ } function intersectsTop(p1, p2) { + return retractRequired(p1, p2); let int = false; 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; - return int; + return int = true; } }); }); return int; } + // returns true if no path around and retract required + // returns false if routed around or no retract + function retractRequired(p1, p2) { + const dbug = false; + + let ints = []; + let tops = POLY.flatten(slice.topPolys().clone(true)); + for (let poly of tops) { + poly.forEachSegment(function(s1, s2) { + let ip = UTIL.intersect(p1,p2,s1,s2,BASE.key.SEGINT); + if (ip) { + ints.push({ip, poly}); + } + }); + } + + // odd # of intersections ?!? do retraction + if (ints.length && ints.length % 2 !== 0) { + if (dbug === slice.index) console.log(slice.index, {odd_intersects: ints}); + return true; + } + + // sort by distance + ints.sort((a, b) => { + return a.ip.dist - b.ip.dist; + }); + + let valid = ints.length; + + // check pairs. eliminate too close points. + // pairs must intersect same poly or retract. + for (let i=0; i 2) { + if (dbug === slice.index) console.log(slice.index, {complex_route: valid}); + return true; + } + + if (valid) { + // can route around intersected top polys + for (let i=0; ii.ip.dist), + i1, i2, same: i1.poly === i2.poly, + route, + r1, r1d, r1s, r1e, + r2, r2d, r2s, r2e, + isCW}); + + for (let p of route) { + addOutput(preout, p, 0, moveSpeed, extruder); + } + + // output last point + addOutput(preout, i2.ip, 0, moveSpeed, extruder); + } + } + + return false; + } + function outputTraces(poly, opt = {}) { if (!poly) return; if (Array.isArray(poly)) { @@ -631,7 +747,9 @@ onfirst: function(firstPoint) { let from = seedPoint || startPoint; if (from.distTo2D(firstPoint) > retractDist) { - retract(); + if (intersectsTop(from, firstPoint)) { + retract(); + } } seedPoint = null; } diff --git a/src/mode/fdm/client.js b/src/mode/fdm/client.js index b11885d8..046dee70 100644 --- a/src/mode/fdm/client.js +++ b/src/mode/fdm/client.js @@ -119,6 +119,11 @@ clearTimeout(int); } }, 50); + // let slider = $('top-slider'); + // slider.style.display = 'flex'; + // slider.oninput = slider.onchange = (ev) => { + // api.const.STACKS.setFraction(parseInt(ev.target.value)/100); + // }; }); api.event.on("mode.set", mode => { isFdmMode = mode === 'FDM'; diff --git a/src/mode/fdm/prepare.js b/src/mode/fdm/prepare.js index 60e299d7..e2bae31c 100644 --- a/src/mode/fdm/prepare.js +++ b/src/mode/fdm/prepare.js @@ -587,6 +587,8 @@ const headColor = 0x888888; const moveColor = opts.move >= 0 ? opts.move : 0xaaaaaa; const printColor = opts.print >= 0 ? opts.print : 0x777700; + const arrowAll = false; + const arrowSize = arrowAll ? 0.2 : 0.4; const layers = []; const moveOpt = { @@ -613,6 +615,7 @@ let lastOut = null; let current = null; let retracted = false; + let retractz = 0; function color(point) { return FDM.rateToColor(point.speed, maxspd); @@ -648,6 +651,7 @@ if (out.retract) { retracts.push(out.point); retracted = true; + retractz++; } if (!out.point) { // in cam mode, these are drilling or dwell ops @@ -655,7 +659,7 @@ } if (lastOut) { - if (lastOut.emit !== out.emit) { + if (arrowAll || lastOut.emit !== out.emit) { heads.push({p1: lastOut.point, p2: out.point}); } const op = out.point, lp = lastOut.point; @@ -720,8 +724,8 @@ const slope = p2.slopeTo(p1); const s1 = BASE.newSlopeFromAngle(slope.angle + 20); const s2 = BASE.newSlopeFromAngle(slope.angle - 20); - const p3 = points.p2.projectOnSlope(s1, 0.8); - const p4 = points.p2.projectOnSlope(s2, 0.8); + const p3 = points.p2.projectOnSlope(s1, arrowSize); + const p4 = points.p2.projectOnSlope(s2, arrowSize); return newPolygon().addPoints([p2,p3,p4]).setZ(p2.z + 0.01); }), { thin: true, outline: true }); } @@ -753,7 +757,7 @@ update(index / levels.length, output); }); - + console.log({retractz}); return layers; } diff --git a/web/kiri/index.css b/web/kiri/index.css index 2e077c8f..28d25b73 100644 --- a/web/kiri/index.css +++ b/web/kiri/index.css @@ -1244,6 +1244,17 @@ th, tr, td, label { width: 20px; } +#top-slider { + position: absolute; + display: none; + top: 60px; + left: 50px; + right: 50px; +} +#anim-slider { + width: 100%; +} + #alert-area { display: none; justify-content: center; diff --git a/web/kiri/index.html b/web/kiri/index.html index eee7e8bb..fd8dd83b 100644 --- a/web/kiri/index.html +++ b/web/kiri/index.html @@ -461,6 +461,9 @@
alerts
alerts
alerts
+
+ +