CAM fix nested traces and new async slicer call. added async worker support

This commit is contained in:
Stewart Allen 2023-01-15 00:45:52 -05:00
commit 57f77d459b
7 changed files with 47 additions and 20 deletions

View file

@ -232,7 +232,7 @@ CAM.init = function(kiri, api) {
], () => {
if (!isCamMode) return;
for (let op of current.process.ops) {
if (op.type === 'trace') {
if (op.type === 'trace' && !flipping) {
op.areas = {};
}
}
@ -720,6 +720,8 @@ CAM.init = function(kiri, api) {
if (axis === 'Y') {
API.selection.rotate(0, Math.PI, 0);
}
// clear traces cache
CAM.traces_clear();
flipping = false;
process.ops = op2;
process.op2 = ops;

View file

@ -75,6 +75,12 @@ kiri.load(api => {
ondone(ids);
});
};
CAM.traces_clear = function(ondone) {
kiri.client.send("cam_traces_clear", {}, () => {
// console.log({clear_traces: true});
});
};
}
if (kiri.worker) {
@ -114,15 +120,28 @@ kiri.load(api => {
send.done(faces);
}
kiri.worker.cam_traces = function(data, send) {
kiri.worker.cam_traces = async function(data, send) {
const { settings, single } = data;
const widgets = Object.values(kiri.worker.cache);
const fresh = widgets.filter(widget => CAM.traces(settings, widget, single));
const fresh = [];
for (let widget of widgets) {
if (await CAM.traces(settings, widget, single)) {
fresh.push(widget);
}
}
// const fresh = widgets.filter(widget => CAM.traces(settings, widget, single));
send.done(kiri.codec.encode(fresh.map(widget => { return {
id: widget.id,
traces: widget.traces,
} } )));
};
kiri.worker.cam_traces_clear = function(data, send) {
for (let widget of Object.values(kiri.worker.cache)) {
delete widget.traces;
}
send.done({});
};
}
});

View file

@ -974,7 +974,7 @@ class OpTrace extends CamOp {
} else {
poly = [ poly ];
}
for (let pi of poly)
for (let pi of POLY.flatten(poly, [], true))
if (down) {
let zto = pi.getZ() - thru;
if (zThru && similar(zto,0)) {

View file

@ -331,7 +331,7 @@ CAM.addDogbones = function(poly, dist, reverse) {
}
};
CAM.traces = function(settings, widget, single) {
CAM.traces = async function(settings, widget, single) {
if (widget.traces && widget.trace_single === single) {
// do no work if cached
return false;
@ -365,12 +365,13 @@ CAM.traces = function(settings, widget, single) {
let z = poly.getZ();
for (let i=0, il=traces.length; i<il; i++) {
let trace = traces[i];
let dz = Math.abs(z - trace.getZ());
// only compare polys farther apart in Z
if (Math.abs(z - trace.getZ()) > 0.01) {
if (dz < 0.01) {
continue;
}
// do not add duplicates
if (traces[i].isEquivalent(poly)) {
if (traces[i].isEquivalent(poly) && dz < 1) {
return;
}
}
@ -378,9 +379,9 @@ CAM.traces = function(settings, widget, single) {
});
};
let opts = { each: oneach, over: false, flatoff: 0, edges: true, openok: true };
slicer.slice(indices, opts);
await slicer.slice(indices, opts);
opts.over = true;
slicer.slice(indices, opts);
await slicer.slice(indices, opts);
widget.traces = traces;
widget.trace_single = single;
return true;