diff --git a/notes.md b/notes.md index 09a30f38..3ac5d9e6 100644 --- a/notes.md +++ b/notes.md @@ -70,6 +70,7 @@ * `B` need to force cut line at synthetic z bottom (midlines, etc) * `B` starting export during animation unleashes chaos +* `F` limit cut depth to flute length of selected tool * `F` add ease-down support to trace op * `F` add linear clearing strategy * `F` add adaptive clearing strategy diff --git a/src/kiri/print.js b/src/kiri/print.js index e134298f..f830fda5 100644 --- a/src/kiri/print.js +++ b/src/kiri/print.js @@ -134,7 +134,8 @@ seq = [], autolayer = true, newlayer = false, - arcdivs = Math.PI / 12; + arcdivs = Math.PI / 12, + hasmoved = false; const output = scope.output = [ seq ]; const beltaxis = { X: "X", Y: "Z", Z: "Y", E: "E", F: "F" }; @@ -211,25 +212,23 @@ function G0G1(g0, line) { const mov = {}; + const axes = {}; line.forEach(function(tok) { let axis = tok.charAt(0); if (morph && belt) { axis = beltaxis[axis]; } + let val = parseFloat(tok.substring(1)); + axes[axis] = val; if (abs) { - pos[axis] = parseFloat(tok.substring(1)); + pos[axis] = val; } else { - mov[axis] = parseFloat(tok.substring(1)); + mov[axis] = val; + pos[axis] += val; } }); - if (!abs) { - for (let [k,v] of Object.entries(mov)) { - pos[k] += v; - } - } - const point = newPoint( factor * pos.X + off.X + xoff.X, factor * pos.Y + off.Y + xoff.Y, @@ -242,7 +241,7 @@ } const retract = (fdm && pos.E < 0) || undefined; - const moving = g0 || (fdm && pos.E <= 0); + const moving = g0 || (fdm && (pos.E <= 0 || !(axes.X || axes.Y || axes.Z))); if (!moving && point.x) bounds.min.x = Math.min(bounds.min.x, point.x); if (!moving && point.x) bounds.max.x = Math.max(bounds.max.x, point.x); @@ -280,6 +279,11 @@ output.push(seq); } + if (!hasmoved && !moving) { + seq.height = seq.Z = pos.Z; + hasmoved = true; + } + // debug extrusion rate if (false && fdm && lastPos) { let dE = (absE ? pos.E - lastPos.E : pos.E);