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

@ -103,10 +103,10 @@
* `F` maintain several part orientations + op chains in a single profile * `F` maintain several part orientations + op chains in a single profile
* `P` improve parser - do not require spaced tokens and support implied G0 / G1 * `P` improve parser - do not require spaced tokens and support implied G0 / G1
* `P` inner corner arc moves * `P` outer corner arc moves
* `P` log Z interpolation for contour XYZ moves * `P` log Z interpolation for contour XYZ moves
* `P` option to start with the smallest poly by area on layer change * `P` option to start with the smallest poly by area on layer change
* `P` refactor slicing engine to use common core in geo * `P` refactor slicing engine to add minion threading
* `P` decrease cutting speed when entire tool is engaged (start of roughing, rest machining) * `P` decrease cutting speed when entire tool is engaged (start of roughing, rest machining)
* `P` port arc code from FDM export to CAM export * `P` port arc code from FDM export to CAM export
* `P` redo all path route / planning in prepare to account for terrain before camOut * `P` redo all path route / planning in prepare to account for terrain before camOut

View file

@ -6,21 +6,22 @@ Full docs @ https://docs.grid.space/projects/kiri-moto
# Release 3.8 # Release 3.8
* update server-side sample module code * update server-side sample module code
* add new fdm parameters, range overrides
* various fixes and improvements to CAM indexing * various fixes and improvements to CAM indexing
* various fixes and improvements to gcode variables * various fixes and improvements to gcode variables
* CAM move to save Z between ops, refresh spindle speed
* improve gcode arc import decoding * improve gcode arc import decoding
* improve trace line selection with zoom adaptive thresholds * removed auto-decimation on object import
* CAM add origin offset optional parameters * FDM slicing memory reduction from team lychee
* remove auto-decimation on object import * FDM add new parameters, range overrides
* FDM fix raft line fill strategy * FDM fix raft line fill strategy
* slicing memory reduction from team lychee * CAM improve trace line selection with zoom adaptive thresholds
* option to control first output point order * CAM option to control first output point order
* CAM move to save Z between ops, refresh spindle speed
* CAM add origin offset optional parameters
* CAM add control to omit initial tool change * CAM add control to omit initial tool change
* CAM fix vertical face selection and step over defaults * CAM fix vertical face selection and step over defaults
* CAM fix multi-part object import / grouping * CAM fix multi-part object import / grouping
* CAM fix tracing nested polyline offset ordering * CAM fix tracing nested polyline offset ordering
* CAM refactor of contouring yields 2x - 20x speedup
- refactor object/group storage model in Mesh:Tool - refactor object/group storage model in Mesh:Tool
- add omit pocket to rough and outline - add omit pocket to rough and outline

View file

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

View file

@ -75,6 +75,12 @@ kiri.load(api => {
ondone(ids); ondone(ids);
}); });
}; };
CAM.traces_clear = function(ondone) {
kiri.client.send("cam_traces_clear", {}, () => {
// console.log({clear_traces: true});
});
};
} }
if (kiri.worker) { if (kiri.worker) {
@ -114,15 +120,28 @@ kiri.load(api => {
send.done(faces); send.done(faces);
} }
kiri.worker.cam_traces = function(data, send) { kiri.worker.cam_traces = async function(data, send) {
const { settings, single } = data; const { settings, single } = data;
const widgets = Object.values(kiri.worker.cache); 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 { send.done(kiri.codec.encode(fresh.map(widget => { return {
id: widget.id, id: widget.id,
traces: widget.traces, 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 { } else {
poly = [ poly ]; poly = [ poly ];
} }
for (let pi of poly) for (let pi of POLY.flatten(poly, [], true))
if (down) { if (down) {
let zto = pi.getZ() - thru; let zto = pi.getZ() - thru;
if (zThru && similar(zto,0)) { 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) { if (widget.traces && widget.trace_single === single) {
// do no work if cached // do no work if cached
return false; return false;
@ -365,12 +365,13 @@ CAM.traces = function(settings, widget, single) {
let z = poly.getZ(); let z = poly.getZ();
for (let i=0, il=traces.length; i<il; i++) { for (let i=0, il=traces.length; i<il; i++) {
let trace = traces[i]; let trace = traces[i];
let dz = Math.abs(z - trace.getZ());
// only compare polys farther apart in Z // only compare polys farther apart in Z
if (Math.abs(z - trace.getZ()) > 0.01) { if (dz < 0.01) {
continue; continue;
} }
// do not add duplicates // do not add duplicates
if (traces[i].isEquivalent(poly)) { if (traces[i].isEquivalent(poly) && dz < 1) {
return; return;
} }
} }
@ -378,9 +379,9 @@ CAM.traces = function(settings, widget, single) {
}); });
}; };
let opts = { each: oneach, over: false, flatoff: 0, edges: true, openok: true }; let opts = { each: oneach, over: false, flatoff: 0, edges: true, openok: true };
slicer.slice(indices, opts); await slicer.slice(indices, opts);
opts.over = true; opts.over = true;
slicer.slice(indices, opts); await slicer.slice(indices, opts);
widget.traces = traces; widget.traces = traces;
widget.trace_single = single; widget.trace_single = single;
return true; return true;

View file

@ -647,11 +647,15 @@ kiri.worker = {
} }
}; };
function is_async(fn) {
return fn.constructor.name === "AsyncFunction";
}
dispatch.send = (msg, direct) => { dispatch.send = (msg, direct) => {
self.postMessage(msg, direct); self.postMessage(msg, direct);
}; };
dispatch.onmessage = self.onmessage = function(e) { dispatch.onmessage = self.onmessage = async function(e) {
let time_recv = time(), let time_recv = time(),
msg = e.data || {}, msg = e.data || {},
run = dispatch[msg.task], run = dispatch[msg.task],
@ -683,7 +687,7 @@ dispatch.onmessage = self.onmessage = function(e) {
if (run) { if (run) {
try { try {
let time_xfer = (time_recv - msg.time), let time_xfer = (time_recv - msg.time),
output = run(msg.data, send), output = is_async(run) ? await run(msg.data, send) : run(msg.data, send),
time_send = time(), time_send = time(),
time_proc = time_send - time_recv; time_proc = time_send - time_recv;