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

@ -704,6 +704,10 @@
return !this.open; return !this.open;
}; };
PRO.appearsClosed = function() {
return this.first().isEqual(this.last());
};
PRO.setClockwise = function() { PRO.setClockwise = function() {
if (!this.isClockwise()) this.reverse(); if (!this.isClockwise()) this.reverse();
return this; return this;

View file

@ -73,7 +73,7 @@
// return the touching z given topo x,y and a tool profile // return the touching z given topo x,y and a tool profile
function toolTipZ(x,y) { function toolTipZ(x,y) {
let profile = toolOffset, const profile = toolOffset,
sx = stepsx, sx = stepsx,
sy = stepsy, sy = stepsy,
xl = sx - 1, xl = sx - 1,
@ -101,7 +101,7 @@
} }
function push_point(x,y,z) { function push_point(x,y,z) {
let newP = newPoint(x,y,z); const newP = newPoint(x,y,z);
if (lastP && lastP.z === z) { if (lastP && lastP.z === z) {
if (curvesOnly) { if (curvesOnly) {
end_poly(); end_poly();
@ -138,27 +138,27 @@
gridy, gridy,
gridi, // index gridi, // index
gridv, // value gridv, // value
x, y, tv, ltv; i, il, j, jl, x, y, tv, ltv;
// for each Y slice, find z grid value (x/z swapped) // for each Y slice, find z grid value (x/z swapped)
for (let j=0, jl=slices.length; j<jl; j++) { for (j=0, jl=slices.length; j<jl; j++) {
let slice = slices[j], const slice = slices[j];
lines = slice.lines; const lines = slice.lines;
gridy = 0; gridy = 0;
// slices have x/z swapped // slices have x/z swapped
for (y = minY; y < maxY && gridy < stepsy; y += resolution) { for (y = minY; y < maxY && gridy < stepsy; y += resolution) {
gridi = gridx * stepsy + gridy; gridi = gridx * stepsy + gridy;
gridv = data[gridi] || 0; gridv = data[gridi] || 0;
// strategy using raw lines (faster slice, but more lines) // strategy using raw lines (faster slice, but more lines)
for (let i=0, il=lines.length; i<il; i++) { for (i=0, il=lines.length; i<il; i++) {
let line = lines[i], p1 = line.p1, p2 = line.p2; const line = lines[i], p1 = line.p1, p2 = line.p2;
if ( if (
(p1.z > zMin || p2.z > zMin) && // one endpoint above 0 (p1.z > zMin || p2.z > zMin) && // one endpoint above 0
(p1.z > gridv || p2.z > gridv) && // one endpoint above gridv (p1.z > gridv || p2.z > gridv) && // one endpoint above gridv
((p1.y <= y && p2.y >= y) || // one endpoint left ((p1.y <= y && p2.y >= y) || // one endpoint left
(p2.y <= y && p1.y >= y)) // one endpoint right (p2.y <= y && p1.y >= y)) // one endpoint right
) { ) {
let dy = p1.y - p2.y, const dy = p1.y - p2.y,
dz = p1.z - p2.z, dz = p1.z - p2.z,
pct = (p1.y - y) / dy, pct = (p1.y - y) / dy,
nz = p1.z - (dz * pct); nz = p1.z - (dz * pct);

View file

@ -409,12 +409,24 @@
const opts = options || {}; const opts = options || {};
const tools = opts.tools || {}; const tools = opts.tools || {};
const thin = opts.thin || false; const flat = opts.flat;
const thin = opts.thin && !flat;
const ckspeed = opts.speed !== false; const ckspeed = opts.speed !== false;
const moveColor = opts.move >= 0 ? opts.move : 0xaaaaaa; const moveColor = opts.move >= 0 ? opts.move : 0xaaaaaa;
const printColor = opts.print >= 0 ? opts.print : 0x777700; const printColor = opts.print >= 0 ? opts.print : 0x777700;
const layers = []; 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 => { const maxspd = levels.map(level => {
return level.map(o => o.speed || 0).reduce((a, v) => Math.max(a,v)); return level.map(o => o.speed || 0).reduce((a, v) => Math.max(a,v));
}).reduce((a, v) => Math.max(a, v)) + 1; }).reduce((a, v) => Math.max(a, v)) + 1;
@ -422,6 +434,7 @@
// for reporting // for reporting
self.worker.print.maxSpeed = maxspd - 1; self.worker.print.maxSpeed = maxspd - 1;
self.worker.print.thinColor = thin; self.worker.print.thinColor = thin;
self.worker.print.flatColor = flat;
let lastOut = null; let lastOut = null;
let current = null; let current = null;
@ -490,15 +503,26 @@
pushPrint(lastOut.tool, current) pushPrint(lastOut.tool, current)
} }
output output
.setLayer(opts.other || 'move', moveColor, opts.moves !== true) .setLayer(opts.other || 'move', moveOpt, opts.moves !== true)
.addPolys(moves, { thin: true, z: opts.z }); .addPolys(moves, { thin: true, z: opts.z });
Object.values(prints).forEach(array => { Object.values(prints).forEach(array => {
array.forEach(poly => { if (poly.length > 1) output array.forEach(poly => {
.setLayer(opts.action || 'print', printColor) if (poly.appearsClosed()) {
.addPolys([ poly ], thin ? { thin, z: opts.z, color: poly.color } : { poly.setClosed();
offset: array.width, height, z: opts.z, poly.points.pop();
color: { face: poly.color, line: poly.color } 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) { function vopt(opt) {
if (opt) { if (opt) {
if (isFlat) { opt.flat = true; return opt } if (isFlat) {
opt.flat = true;
opt.outline = true;
return opt
}
if (isThin) return null; if (isThin) return null;
} }
return opt; return opt;
@ -71,9 +75,17 @@
view = widget.mesh && widget.mesh.newGroup ? widget.mesh.newGroup() : null; view = widget.mesh && widget.mesh.newGroup ? widget.mesh.newGroup() : null;
isFlat = false; isFlat = false;
isThin = settings.controller.thinRender; isThin = !isFlat && settings.controller.thinRender;
offset = nozzleSize / 2; 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)) { if (!(sliceHeight > 0 && sliceHeight < 100)) {
return ondone("invalid slice height"); return ondone("invalid slice height");
} }