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

View file

@ -56,10 +56,11 @@
mode = 0,
point,
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,
bounds = widget.getBoundingBox(),
zmax = hasStock ? settings.stock.z : bounds.max.z,
zmax = hasStock ? stock.z : bounds.max.z,
runbox = {
max: { x:-Infinity, y:-Infinity, z:-Infinity},
min: { x:Infinity, y:Infinity, z:Infinity}

View file

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

View file

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