tweak contouring

This commit is contained in:
Stewart Allen 2020-11-14 21:33:46 -05:00
commit ed726c3ca6
4 changed files with 31 additions and 23 deletions

View file

@ -731,12 +731,12 @@
mindist = Infinity; mindist = Infinity;
array.forEach(function(el) { array.forEach(function(el) {
if (el.delete) return; if (el.delete) return;
dist = startPoint.distTo3D(el.first); dist = startPoint.distTo2D(el.first);
if (dist < mindist) { if (dist < mindist) {
found = {el:el, first:el.first, last:el.last}; found = {el:el, first:el.first, last:el.last};
mindist = dist; mindist = dist;
} }
dist = startPoint.distTo3D(el.last); dist = startPoint.distTo2D(el.last);
if (dist < mindist) { if (dist < mindist) {
found = {el:el, first:el.last, last:el.first}; found = {el:el, first:el.last, last:el.first};
mindist = dist; mindist = dist;
@ -744,8 +744,8 @@
}); });
if (found) { if (found) {
found.el.delete = true; found.el.delete = true;
// startPoint = found.last; startPoint = found.last;
startPoint = emitter(found.el, found.first, ++count); emitter(found.el, found.first, ++count);
} else { } else {
break; break;
} }

View file

@ -56,10 +56,11 @@
mode = 0, mode = 0,
point, point,
points = 0, points = 0,
hasStock = spro.camStockOffset || (spro.camStockZ && spro.camStockX && spro.camStockY), stock = settings.stock,
hasStock = spro.camStockOn && stock.x && stock.y && stock.z,
ztOff = hasStock ? spro.camZTopOffset : 0, ztOff = hasStock ? spro.camZTopOffset : 0,
bounds = widget.getBoundingBox(), bounds = widget.getBoundingBox(),
zmax = hasStock ? settings.stock.z : bounds.max.z, zmax = hasStock ? stock.z : bounds.max.z,
runbox = { runbox = {
max: { x:-Infinity, y:-Infinity, z:-Infinity}, max: { x:-Infinity, y:-Infinity, z:-Infinity},
min: { x:Infinity, y:Infinity, z:Infinity} min: { x:Infinity, y:Infinity, z:Infinity}

View file

@ -38,7 +38,7 @@
}, { }, {
thin: true, thin: true,
print: 0, print: 0,
move: 0x003366, move: 0x557799,
speed: false, speed: false,
moves: true, moves: true,
other: "moving", other: "moving",
@ -195,6 +195,7 @@
function layerPush(point, emit, speed, tool) { function layerPush(point, emit, speed, tool) {
layerOut.mode = lastMode; layerOut.mode = lastMode;
addOutput(layerOut, point, emit, speed, tool); addOutput(layerOut, point, emit, speed, tool);
return point;
} }
function camDwell(time) { function camDwell(time) {
@ -216,27 +217,30 @@
cut = 0; cut = 0;
nextIsMove = false; nextIsMove = false;
} }
let rate = feedRate; let rate = feedRate;
// before first point, move cutting head to point above it
// then set that new point as the lastPoint
if (!lastPoint) { if (!lastPoint) {
let above = point.clone().setZ(zmax + zadd); let above = point.clone().setZ(zmax + zadd);
// before first point, move cutting head to point above it lastPoint = layerPush(above, 0, 0, tool.getNumber());
layerPush(above, 0, 0, tool.getNumber());
// then set that as the lastPoint
lastPoint = above;
} }
// measure deltas to last point in XY and Z
let deltaXY = lastPoint.distTo2D(point), let deltaXY = lastPoint.distTo2D(point),
deltaZ = point.z - lastPoint.z, deltaZ = point.z - lastPoint.z,
absDeltaZ = Math.abs(deltaZ), absDeltaZ = Math.abs(deltaZ),
isMove = !cut; isMove = !cut;
// drop points too close together // drop points too close together
if (deltaXY < 0.001 && point.z === lastPoint.z) { if (deltaXY < 0.001 && point.z === lastPoint.z) {
// console.trace(["drop dup",lastPoint,point]); console.trace(["drop dup",lastPoint,point]);
return; return;
} }
// convert short planar moves to cuts
if (isMove && deltaXY <= toolDiamMove) { if (isMove && deltaXY <= toolDiamMove) {
// convert short planar moves to cuts
if (absDeltaZ <= tolerance) { if (absDeltaZ <= tolerance) {
cut = 1; cut = 1;
isMove = false; isMove = false;
@ -246,7 +250,8 @@
// new pos for plunge calc // new pos for plunge calc
deltaXY = 0; deltaXY = 0;
} }
} //else (TODO verify no else here b/c above could change isMove) } 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)) { if ((deltaXY > toolDiam || (deltaZ > toolDiam && deltaXY > tolerance)) && (isMove || absDeltaZ >= tolerance)) {
let maxz = getZClearPath( let maxz = getZClearPath(
terrain, terrain,
@ -261,18 +266,19 @@
) + ztOff, ) + ztOff,
mustGoUp = Math.max(maxz - point.z, maxz - lastPoint.z) >= tolerance, mustGoUp = Math.max(maxz - point.z, maxz - lastPoint.z) >= tolerance,
clearz = maxz; clearz = maxz;
// up if any point between higher than start/outline // up if any point between higher than start/outline, go up
if (mustGoUp) { if (mustGoUp) {
clearz = maxz + zclear; clearz = maxz + zclear;
layerPush(lastPoint.clone().setZ(clearz), 0, 0, tool.getNumber()); layerPush(lastPoint.clone().setZ(clearz), 0, 0, tool.getNumber());
} }
// over to point above where we descend to // move to point above target point
if (mustGoUp || point.z < maxz) { if (mustGoUp || point.z < maxz) {
layerPush(point.clone().setZ(clearz), 0, 0, tool.getNumber()); layerPush(point.clone().setZ(clearz), 0, 0, tool.getNumber());
// new pos for plunge calc // new pos for plunge calc
deltaXY = 0; deltaXY = 0;
} }
} }
// synth new plunge rate // synth new plunge rate
if (deltaZ <= -tolerance) { if (deltaZ <= -tolerance) {
let threshold = Math.min(deltaXY / 2, absDeltaZ), let threshold = Math.min(deltaXY / 2, absDeltaZ),
@ -286,14 +292,13 @@
} }
// todo synthesize move speed from feed / plunge accordingly // todo synthesize move speed from feed / plunge accordingly
layerPush( layerOut.spindle = spindle;
lastPoint = layerPush(
point, point,
cut ? 1 : 0, cut ? 1 : 0,
rate, rate,
tool.getNumber() tool.getNumber()
); );
lastPoint = point;
layerOut.spindle = spindle;
} }
// coming from a previous widget, use previous last point // coming from a previous widget, use previous last point
@ -319,6 +324,7 @@
depthData.layer++; depthData.layer++;
isNewMode = slice.camMode != lastMode; isNewMode = slice.camMode != lastMode;
lastMode = slice.camMode; lastMode = slice.camMode;
// force move at start of each slice
nextIsMove = true; nextIsMove = true;
if (isNewMode) depthData.layer = 0; if (isNewMode) depthData.layer = 0;
@ -404,11 +410,13 @@
} else { } else {
printPoint = tip2tipEmit(polys, printPoint, function(el, point, count) { printPoint = tip2tipEmit(polys, printPoint, function(el, point, count) {
poly = el.poly; poly = el.poly;
if (poly.last() === point) poly.reverse(); if (poly.last() === point) {
poly.reverse();
}
poly.forEachPoint(function(point, pidx) { poly.forEachPoint(function(point, pidx) {
camOut(point.clone(), pidx > 0); camOut(point.clone(), pidx > 0);
}, false); }, false);
return lastPoint; // return lastPoint;
}); });
newLayer(); newLayer();
} }
@ -585,7 +593,6 @@
// replace output single flattened layer with all points // replace output single flattened layer with all points
print.output = newOutput; print.output = newOutput;
return printPoint; return printPoint;
}; };

View file

@ -378,7 +378,6 @@
print.render = FDM.prepareRender(output, progress => { print.render = FDM.prepareRender(output, progress => {
update(0.5 + progress * 0.5); update(0.5 + progress * 0.5);
}, { tools: device.extruders, thin: isThin, flat: isFlat }); }, { tools: device.extruders, thin: isThin, flat: isFlat });
return print.render; return print.render;
}; };
@ -468,6 +467,7 @@
// in cam mode, these are drilling or dwell ops // in cam mode, these are drilling or dwell ops
return; return;
} }
if (lastOut) { if (lastOut) {
const op = out.point, lp = lastOut.point, const op = out.point, lp = lastOut.point,
moved = (op.x !== lp.x) || (op.y !== lp.y) || (op.z !== lp.z);; moved = (op.x !== lp.x) || (op.y !== lp.y) || (op.z !== lp.z);;