weight progress bar for pocket contour ops

This commit is contained in:
Stewart Allen 2022-10-11 10:53:42 -04:00
commit 5f6e381ef9

View file

@ -976,7 +976,7 @@ class OpPocket extends CamOp {
this.topo = new CAM.Topo({ this.topo = new CAM.Topo({
// onupdate: (update, msg) => { // onupdate: (update, msg) => {
onupdate: (index, total, msg) => { onupdate: (index, total, msg) => {
progress(index / total, msg); progress((index / total) * 0.9, msg);
}, },
ondone: (slices) => { }, ondone: (slices) => { },
contour: { contour: {
@ -1055,7 +1055,9 @@ class OpPocket extends CamOp {
} }
POLY.setWinding(slice.camLines, cutdir, false); POLY.setWinding(slice.camLines, cutdir, false);
if (contour) { if (contour) {
slice.camLines = pocket.conform(slice.camLines, op.refine, engrave); slice.camLines = pocket.conform(slice.camLines, op.refine, engrave, pct => {
progress(0.9 + (zpro + zinc * pct) * 0.1, "conform");
});
} }
slice.output() slice.output()
.setLayer("pocket", {line: color}, false) .setLayer("pocket", {line: color}, false)
@ -1063,7 +1065,10 @@ class OpPocket extends CamOp {
if (debug && shadow) slice.output() if (debug && shadow) slice.output()
.setLayer("pocket shadow", {line: 0xff8811}, false) .setLayer("pocket shadow", {line: 0xff8811}, false)
.addPolys(shadow) .addPolys(shadow)
progress(zpro += zinc, "pocket"); if (!contour) {
progress(zpro, "pocket");
}
zpro += zinc;
} }
} }
} }
@ -1103,18 +1108,23 @@ class OpPocket extends CamOp {
} }
// mold cam output lines to the surface of the topo offset by tool geometry // mold cam output lines to the surface of the topo offset by tool geometry
conform(camLines, refine, engrave) { conform(camLines, refine, engrave, progress) {
const topo = this.topo; const topo = this.topo;
// re-segment polygon to a higher resolution // re-segment polygon to a higher resolution
const hirez = refine > 0 ? camLines.map(p => p.segment(topo.tolerance * 2)) : camLines; const hirez = refine > 0 ? camLines.map(p => p.segment(topo.tolerance * 2)) : camLines;
// walk points and offset from surface taking into account tool geometry // walk points and offset from surface taking into account tool geometry
let steps = hirez.length;
let iter = 0;
for (let poly of hirez) { for (let poly of hirez) {
for (let point of poly.points) { for (let point of poly.points) {
point.z = engrave ? topo.zAtXY(point.x, point.y) : topo.toolAtXY(point.x, point.y); point.z = engrave ? topo.zAtXY(point.x, point.y) : topo.toolAtXY(point.x, point.y);
} }
progress((iter++ / steps) * 0.8);
} }
steps = steps * refine;
iter = 0;
// walk points noting z deltas and smoothing sawtooth patterns // walk points noting z deltas and smoothing sawtooth patterns
for (let j=0; j<refine; j++) for (let j=0; j<refine; j++) {
for (let poly of hirez) { for (let poly of hirez) {
const points = poly.points, length = points.length; const points = poly.points, length = points.length;
let sn = []; // segment normals let sn = []; // segment normals
@ -1142,6 +1152,8 @@ class OpPocket extends CamOp {
p1.z = (p0.z + p2.z + p1.z) / 3; p1.z = (p0.z + p2.z + p1.z) / 3;
} }
} }
progress((iter++ / steps) * 0.2 + 0.8);
}
} }
return hirez; return hirez;
} }