From 42dfa27e63f3cd7795cbfb8c88f1a2f738b5c99a Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Sun, 15 Nov 2020 01:01:10 -0500 Subject: [PATCH] fix prep render bug (lastEnd) and contour camOut routing --- notes.md | 3 ++- src/mode/cam/prepare.js | 58 +++++++++++++++++++++++------------------ src/mode/fdm/prepare.js | 9 ++++--- 3 files changed, 40 insertions(+), 30 deletions(-) diff --git a/notes.md b/notes.md index abed5eb8..96e702a5 100644 --- a/notes.md +++ b/notes.md @@ -3,7 +3,8 @@ ## 2.3 remaining * adaptive shadow-line generation for small parts collision detection * step down should interpolate top/bottom again -* preview rendering bugs for contouring +* clear voids broken again +* fix contour up and over thru holes * path arrows, retracts, and engages * cap path ends * help dialog diff --git a/src/mode/cam/prepare.js b/src/mode/cam/prepare.js index f88c9e90..48abe384 100644 --- a/src/mode/cam/prepare.js +++ b/src/mode/cam/prepare.js @@ -250,32 +250,38 @@ // new pos for plunge calc deltaXY = 0; } - } else - // for longer moves, check the terrain to see if we need to go up and over - if ((deltaXY > toolDiam || (deltaZ > toolDiam && deltaXY > tolerance)) && (isMove || absDeltaZ >= tolerance)) { - let maxz = getZClearPath( - terrain, - lastPoint.x,// - wmx, - lastPoint.y,// - wmy, - point.x,// - wmx, - point.y,// - wmy, - Math.max(point.z, lastPoint.z), - zadd, - maxToolDiam/2, - zclear - ) + ztOff, - mustGoUp = Math.max(maxz - point.z, maxz - lastPoint.z) >= tolerance, - clearz = maxz; - // up if any point between higher than start/outline, go up - if (mustGoUp) { - clearz = maxz + zclear; - layerPush(lastPoint.clone().setZ(clearz), 0, 0, tool.getNumber()); - } - // move to point above target point - if (mustGoUp || point.z < maxz) { - layerPush(point.clone().setZ(clearz), 0, 0, tool.getNumber()); - // new pos for plunge calc - deltaXY = 0; + } else { + // for longer moves, check the terrain to see if we need to go up and over + const bigXY = (deltaXY > toolDiam); + const bigZ = (deltaZ > toolDiam/2 && deltaXY > tolerance); + const midZ = (absDeltaZ >= tolerance); + if ((bigXY || bigZ) && (isMove || midZ)) { + let maxz = getZClearPath( + terrain, + lastPoint.x, + lastPoint.y, + point.x, + point.y, + Math.max(point.z, lastPoint.z), + zadd, + maxToolDiam/2, + zclear + ) + ztOff, + mustGoUp = Math.max(maxz - point.z, maxz - lastPoint.z) >= tolerance, + clearz = maxz; + // up if any point between higher than start/outline, go up + if (mustGoUp) { + if (bigXY) { + clearz += zclear; + } + layerPush(lastPoint.clone().setZ(clearz), 0, 0, tool.getNumber()); + } + // move to point above target point + if (mustGoUp || point.z < maxz) { + layerPush(point.clone().setZ(clearz), 0, 0, tool.getNumber()); + // new pos for plunge calc + deltaXY = 0; + } } } diff --git a/src/mode/fdm/prepare.js b/src/mode/fdm/prepare.js index 024f5861..09a55035 100644 --- a/src/mode/fdm/prepare.js +++ b/src/mode/fdm/prepare.js @@ -436,6 +436,7 @@ self.worker.print.thinColor = thin; self.worker.print.flatColor = flat; + let lastEnd = null; let lastOut = null; let current = null; @@ -462,7 +463,7 @@ let width = 1; let emits = 0; - level.forEach(out => { + level.forEach((out,oi) => { if (!out.point) { // in cam mode, these are drilling or dwell ops return; @@ -472,7 +473,7 @@ const op = out.point, lp = lastOut.point, moved = (op.x !== lp.x) || (op.y !== lp.y) || (op.z !== lp.z);; if (out.emit) { - if (!lastOut.emit || (ckspeed && out.speed !== lastOut.speed)) { + if (!lastOut.emit || (ckspeed && out.speed !== lastOut.speed) || lastEnd) { current = newPolygon().setOpen(); current.push(lastOut.point); current.color = color(out); @@ -480,13 +481,14 @@ } current.push(out.point); } else { - if (lastOut.emit) { + if (lastOut.emit || lastEnd) { current = newPolygon().setOpen(); current.push(lastOut.point); moves.push(current); } current.push(out.point); } + lastEnd = null; } else { current = newPolygon().setOpen(); current.push(out.point); @@ -503,6 +505,7 @@ if (lastOut.emit && !emits) { pushPrint(lastOut.tool, current) } + lastEnd = lastOut; output .setLayer(opts.other || 'move', moveOpt, opts.moves !== true) .addPolys(moves, { thin: true, z: opts.z });