move gerber render to worker to free up UI thread
This commit is contained in:
parent
619468ee00
commit
edf7a53d4c
5 changed files with 45 additions and 10 deletions
|
|
@ -126,7 +126,7 @@ CAM.init = function(kiri, api) {
|
||||||
let diam = poly.tool?.shape?.diameter;
|
let diam = poly.tool?.shape?.diameter;
|
||||||
if (diam) {
|
if (diam) {
|
||||||
const exp = poly.offset_open(diam, 'round');
|
const exp = poly.offset_open(diam, 'round');
|
||||||
layers.setLayer("open2", {line: 0xff5555}, false).addPolys(exp);
|
layers.setLayer("open-exp", {line: 0xff5555}, false).addPolys(exp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let poly of closed) {
|
for (let poly of closed) {
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
// dep: moto.license
|
// dep: moto.license
|
||||||
// dep: moto.broker
|
// dep: moto.broker
|
||||||
// use: load.png
|
// use: load.png
|
||||||
|
// use: load.gbr
|
||||||
// use: ext.jszip
|
// use: ext.jszip
|
||||||
// use: kiri.render
|
// use: kiri.render
|
||||||
// use: kiri-mode.cam.animate
|
// use: kiri-mode.cam.animate
|
||||||
|
|
@ -606,6 +607,13 @@ kiri.worker = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
gerber2mesh(data, send) {
|
||||||
|
const vertices = load.GBR.toMesh(data, { progress(pct) {
|
||||||
|
send.data({ progress: pct/100 });
|
||||||
|
} } );
|
||||||
|
send.data({ vertices }, [ vertices.buffer ]);
|
||||||
|
},
|
||||||
|
|
||||||
zip(data, send) {
|
zip(data, send) {
|
||||||
let { files } = data;
|
let { files } = data;
|
||||||
let zip = new JSZip();
|
let zip = new JSZip();
|
||||||
|
|
|
||||||
|
|
@ -297,6 +297,17 @@ const client = exports({
|
||||||
}, [ data.png ]);
|
}, [ data.png ]);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
gerber2mesh(data, progress, output) {
|
||||||
|
send('gerber2mesh', data, reply => {
|
||||||
|
if (reply.progress) {
|
||||||
|
progress(reply.progress);
|
||||||
|
}
|
||||||
|
if (reply.vertices) {
|
||||||
|
output(reply.vertices);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
zip(files, progress, output) {
|
zip(files, progress, output) {
|
||||||
send("zip", {files}, reply => {
|
send("zip", {files}, reply => {
|
||||||
if (reply.percent !== undefined) {
|
if (reply.percent !== undefined) {
|
||||||
|
|
|
||||||
|
|
@ -815,13 +815,17 @@ function platformLoadFiles(files, group) {
|
||||||
if (api.conf.get().controller.devel) {
|
if (api.conf.get().controller.devel) {
|
||||||
api.event.emit('cam.parse.gerber', { data: text });
|
api.event.emit('cam.parse.gerber', { data: text });
|
||||||
} else {
|
} else {
|
||||||
let mesh = load.GBR.toMesh(text);
|
kiri.client.gerber2mesh(text, progress => {
|
||||||
let wid = platformLoadWidget(group, mesh, name);
|
api.show.progress(progress, "converting");
|
||||||
if (api.mode.is_cam()) {
|
}, vertices => {
|
||||||
// attach raw illustration
|
api.show.progress(0);
|
||||||
api.event.emit('cam.parse.gerber', { data: text, mesh: wid.mesh });
|
let wid = platformLoadWidget(group, vertices, name);
|
||||||
}
|
if (api.mode.is_cam()) {
|
||||||
}
|
// attach raw illustration
|
||||||
|
api.event.emit('cam.parse.gerber', { data: text, mesh: wid.mesh });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
} else if (is3mf) {
|
} else if (is3mf) {
|
||||||
let odon = function(models) {
|
let odon = function(models) {
|
||||||
let msg = api.show.alert('Adding Objects');
|
let msg = api.show.alert('Adding Objects');
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,12 @@ load.GBR = {
|
||||||
};
|
};
|
||||||
|
|
||||||
function toMesh(text, opt = { z: 1 }) {
|
function toMesh(text, opt = { z: 1 }) {
|
||||||
|
const progress = opt.progress || function(){};
|
||||||
|
|
||||||
// for now ignore open trace lines
|
// for now ignore open trace lines
|
||||||
// future exports should allow a way to represent them for cnc
|
// future exports should allow a way to represent them for cnc
|
||||||
const { open, closed, circs, rects } = parse(text);
|
const { open, closed, circs, rects } = parse(text);
|
||||||
|
progress(5);
|
||||||
|
|
||||||
// for the copper layer:
|
// for the copper layer:
|
||||||
// should produce one top level poly which is the board outline
|
// should produce one top level poly which is the board outline
|
||||||
|
|
@ -29,6 +32,7 @@ function toMesh(text, opt = { z: 1 }) {
|
||||||
|
|
||||||
const flat = [];
|
const flat = [];
|
||||||
for (let n of nest) n.flattenTo(flat, [], true);
|
for (let n of nest) n.flattenTo(flat, [], true);
|
||||||
|
progress(8);
|
||||||
|
|
||||||
const z0 = opt.z || opt.z0 || 1;
|
const z0 = opt.z || opt.z0 || 1;
|
||||||
const z1 = opt.z1 || 0.25;
|
const z1 = opt.z1 || 0.25;
|
||||||
|
|
@ -38,6 +42,7 @@ function toMesh(text, opt = { z: 1 }) {
|
||||||
for (let poly of flat.filter(p => p.depth === 0)) {
|
for (let poly of flat.filter(p => p.depth === 0)) {
|
||||||
top.push(poly.extrude(z0));
|
top.push(poly.extrude(z0));
|
||||||
}
|
}
|
||||||
|
progress(15);
|
||||||
|
|
||||||
// nothing to render
|
// nothing to render
|
||||||
if (top.length === 0) {
|
if (top.length === 0) {
|
||||||
|
|
@ -49,6 +54,7 @@ function toMesh(text, opt = { z: 1 }) {
|
||||||
for (let poly of flat.filter(p => p.depth === 1)) {
|
for (let poly of flat.filter(p => p.depth === 1)) {
|
||||||
mid.push(poly.extrude(z1, z0 - z1));
|
mid.push(poly.extrude(z1, z0 - z1));
|
||||||
}
|
}
|
||||||
|
progress(20);
|
||||||
|
|
||||||
// if no traces, return board
|
// if no traces, return board
|
||||||
if (mid.length === 0) {
|
if (mid.length === 0) {
|
||||||
|
|
@ -63,10 +69,11 @@ function toMesh(text, opt = { z: 1 }) {
|
||||||
|
|
||||||
// union open trace expansions
|
// union open trace expansions
|
||||||
const opn = [];
|
const opn = [];
|
||||||
for (let poly of POLYS.union(open_exp)) {
|
for (let poly of POLYS.union(open_exp, 0, true)) {
|
||||||
const tool = poly.tool;
|
const tool = poly.tool;
|
||||||
opn.push(poly.extrude(z0));
|
opn.push(poly.extrude(z0));
|
||||||
}
|
}
|
||||||
|
progress(25);
|
||||||
|
|
||||||
// inner polys for traces which we add back to the top
|
// inner polys for traces which we add back to the top
|
||||||
// and (optionally) remove from the bottom for making vias
|
// and (optionally) remove from the bottom for making vias
|
||||||
|
|
@ -74,25 +81,30 @@ function toMesh(text, opt = { z: 1 }) {
|
||||||
for (let poly of flat.filter(p => p.depth === 2)) {
|
for (let poly of flat.filter(p => p.depth === 2)) {
|
||||||
low.push(poly.extrude(z1, z0 - z1));
|
low.push(poly.extrude(z1, z0 - z1));
|
||||||
}
|
}
|
||||||
|
progress(30);
|
||||||
|
|
||||||
// convert vertex arrays to csg mesh definitions
|
// convert vertex arrays to csg mesh definitions
|
||||||
const topMesh = CSG.fromPositionArray(top[0]);
|
const topMesh = CSG.fromPositionArray(top[0]);
|
||||||
const midMesh = mid.map(v => CSG.fromPositionArray(v));
|
const midMesh = mid.map(v => CSG.fromPositionArray(v));
|
||||||
|
progress(35);
|
||||||
|
|
||||||
// subtract mid from top
|
// subtract mid from top
|
||||||
let meshOut = CSG.subtract(topMesh, ...midMesh);
|
let meshOut = CSG.subtract(topMesh, ...midMesh);
|
||||||
|
progress(50);
|
||||||
|
|
||||||
if (opn.length) {
|
if (opn.length) {
|
||||||
// add back raised traces (before removing vias)
|
// add back raised traces (before removing vias)
|
||||||
const opnMesh = opn.map(v => CSG.fromPositionArray(v))
|
const opnMesh = opn.map(v => CSG.fromPositionArray(v))
|
||||||
meshOut = CSG.union(meshOut, ...opnMesh);
|
meshOut = CSG.union(meshOut, ...opnMesh);
|
||||||
}
|
}
|
||||||
|
progress(70);
|
||||||
|
|
||||||
if (low.length) {
|
if (low.length) {
|
||||||
// subtract low (vias) from remaining
|
// subtract low (vias) from remaining
|
||||||
const lowMesh = low.map(v => CSG.fromPositionArray(v))
|
const lowMesh = low.map(v => CSG.fromPositionArray(v))
|
||||||
meshOut = CSG.union(meshOut, ...lowMesh);
|
meshOut = CSG.union(meshOut, ...lowMesh);
|
||||||
}
|
}
|
||||||
|
progress(90);
|
||||||
|
|
||||||
return CSG.toPositionArray(meshOut);
|
return CSG.toPositionArray(meshOut);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue