add flat render support

This commit is contained in:
Stewart Allen 2020-11-12 09:55:19 -05:00
commit f30e3a0288
4 changed files with 59 additions and 19 deletions

View file

@ -409,12 +409,24 @@
const opts = options || {};
const tools = opts.tools || {};
const thin = opts.thin || false;
const flat = opts.flat;
const thin = opts.thin && !flat;
const ckspeed = opts.speed !== false;
const moveColor = opts.move >= 0 ? opts.move : 0xaaaaaa;
const printColor = opts.print >= 0 ? opts.print : 0x777700;
const layers = [];
const moveOpt = {
face: moveColor,
line: flat ? 1 : moveColor,
opacity: flat ? 0.5 : 1
};
const printOpt = {
face: printColor,
line: flat ? 1 : printColor,
opacity: flat ? 0.5 : 1
};
const maxspd = levels.map(level => {
return level.map(o => o.speed || 0).reduce((a, v) => Math.max(a,v));
}).reduce((a, v) => Math.max(a, v)) + 1;
@ -422,6 +434,7 @@
// for reporting
self.worker.print.maxSpeed = maxspd - 1;
self.worker.print.thinColor = thin;
self.worker.print.flatColor = flat;
let lastOut = null;
let current = null;
@ -490,15 +503,26 @@
pushPrint(lastOut.tool, current)
}
output
.setLayer(opts.other || 'move', moveColor, opts.moves !== true)
.setLayer(opts.other || 'move', moveOpt, opts.moves !== true)
.addPolys(moves, { thin: true, z: opts.z });
Object.values(prints).forEach(array => {
array.forEach(poly => { if (poly.length > 1) output
.setLayer(opts.action || 'print', printColor)
.addPolys([ poly ], thin ? { thin, z: opts.z, color: poly.color } : {
offset: array.width, height, z: opts.z,
color: { face: poly.color, line: poly.color }
})
array.forEach(poly => {
if (poly.appearsClosed()) {
poly.setClosed();
poly.points.pop();
poly.length--;
}
output
.setLayer(opts.action || 'print', printOpt)
.addPolys([ poly ],
thin ? { thin, z: opts.z, color: poly.color } :
flat ? {
flat, z: opts.z, color: poly.color,
outline: true, offset: array.width, open: poly.open } :
{
offset: array.width, height, z: opts.z,
color: { face: poly.color, line: poly.color }
})
});
});

View file

@ -30,7 +30,11 @@
function vopt(opt) {
if (opt) {
if (isFlat) { opt.flat = true; return opt }
if (isFlat) {
opt.flat = true;
opt.outline = true;
return opt
}
if (isThin) return null;
}
return opt;
@ -71,9 +75,17 @@
view = widget.mesh && widget.mesh.newGroup ? widget.mesh.newGroup() : null;
isFlat = false;
isThin = settings.controller.thinRender;
isThin = !isFlat && settings.controller.thinRender;
offset = nozzleSize / 2;
if (isFlat) {
Object.values(COLOR).forEach(color => {
color.flat = true;
color.line = 1
color.opacity = 0.5;
});
};
if (!(sliceHeight > 0 && sliceHeight < 100)) {
return ondone("invalid slice height");
}