checkpoint new print rendering

This commit is contained in:
Stewart Allen 2020-11-08 10:55:36 -05:00
commit 37e32ebedf
10 changed files with 300 additions and 229 deletions

View file

@ -22,144 +22,6 @@
});
}
/**
* DRIVER SLICE RENDER CONTRACT
*
* @param {Object} widget to render
* @param {number} mode to use to select colors
*/
FDM.sliceRender = function(widget) {
return KIRI.Layer.renderSetup().renderSlices(widget.slices);
let slices = widget.slices;
let settings = widget.settings;
let extnum = widget.getExtruder(settings);
let extarr = settings.device.extruders || [];
let extinfo = extarr[extnum || 0];
let extoff = (extinfo.extNozzle || 0.4) / 2;
let thin = settings.controller.thinRender && settings.mode === 'FDM';
if (!slices) return;
// render outline
slices.forEach(function(s) {
let layers = s.layers;
let tops = s.tops;
let outline = layers.outline;
let shells = layers.trace;
let solids = layers.fill;
let sparse = layers.sparse;
let support = layers.support;
let outsolid = layers.solid;
let outbridge = layers.bridge;
let outflat = layers.flat;
outline.clear();
shells.clear();
solids.clear();
sparse.clear();
support.clear();
outsolid.clear();
outbridge.clear();
outflat.clear();
outline.setTransparent(true);
shells.setTransparent(false);
solids.setTransparent(false);
sparse.setTransparent(false);
support.setTransparent(false);
outsolid.setTransparent(true);
outbridge.setTransparent(true);
outflat.setTransparent(true);
tops.forEach(function(top) {
// outline
outline.poly(top.poly, 0xdddddd, true, false);
outline.solid(top.poly, thin ? 0xdddddd : 0xcccccc);
if (top.inner) outline.poly(top.inner, 0xdddddd, true);
// if (top.thinner) outline.poly(top.thinner, 0x559999, true, null);
// shells
if (thin) {
shells.poly(top.traces, 0x77bbcc, true);
} else {
shells.noodle(top.traces, extoff, 0x88aadd, 0x77bbcc);
}
if (top.polish) {
shells.poly(top.polish.x, 0x880000, true);
shells.poly(top.polish.y, 0x880000, true);
}
// solid fill
if (thin) {
solids.lines(top.thin_fill, 0x77bbcc);
solids.lines(top.fill_lines, 0x77bbcc);
} else {
solids.noodle_lines(top.thin_fill, extoff, 0x88aadd, 0x77bbcc, s.z);
solids.noodle_lines(top.fill_lines, extoff, 0x88aadd, 0x77bbcc, s.z);
}
// sparse fill
if (top.fill_sparse) {
top.fill_sparse.forEach(function(poly) {
if (thin) {
// todo cull polys with single point before this
if (poly.length > 1) poly.render(sparse, 0x0, false, true);
} else {
sparse.noodle_open(poly, extoff, 0x88aadd, 0x77bbcc, s.z);
}
});
}
// support
if (s.supports) {
if (thin) {
s.supports.forEach(function(poly) {
support.poly(poly, 0xffaadd, true);
support.lines(poly.fills, 0xffaadd);
});
} else {
support.noodle(s.supports, extoff, 0xeeaadd, 0x77bbcc);
s.supports.forEach(function(poly) {
support.noodle_lines(poly.fills, extoff, 0xeeaadd, 0x77bbcc, s.z);
});
}
}
});
// solid outlines
let trimmed = s.solids.trimmed;
if (trimmed) trimmed.forEach(function(poly) {
poly.setZ(s.z + 0.025);
outsolid.poly(poly, 0x00cc00, true, false);
outsolid.solid(poly, 0x00dd00);
});
// diff bridges
if (s.bridges) s.bridges.forEach(function (poly) {
poly.setZ(s.z + 0.05);
outbridge.poly(poly, 0x0099ee, true, false);
outbridge.solid(poly, 0x00aaff);
});
// diff flats
if (s.flats) s.flats.forEach(function (poly) {
poly.setZ(s.z + 0.05);
outflat.poly(poly, 0xee0099, true, false);
outflat.solid(poly, 0xff00aa);
});
outline.renderAll();
shells.renderAll();
solids.renderAll();
sparse.renderAll();
support.renderAll();
outsolid.renderAll();
outbridge.renderAll();
outflat.renderAll();
});
}
FDM.printRender = function(print, options) {
let debug = KIRI.api.const.LOCAL;
let scope = print, emits, last,

View file

@ -9,7 +9,8 @@
UTIL = BASE.util,
POLY = BASE.polygons,
FDM = KIRI.driver.FDM,
newPoint = BASE.newPoint;
newPoint = BASE.newPoint,
newPolygon = BASE.newPolygon;
/**
* DRIVER PRINT CONTRACT
@ -24,7 +25,7 @@
nozzle = device.extruders[0].extNozzle,
process = settings.process,
mode = settings.mode,
output = print.output,
output = [],
bounds = settings.bounds,
printPoint = newPoint(0,0,0),
firstLayerHeight = process.firstSliceHeight || process.sliceHeight,
@ -229,7 +230,7 @@
pos = {x:blokpos.x, y:blokpos.y, z:0},
rec = {
extruder: i,
poly: BASE.newPolygon().centerSpiral(pos, blok.x, blok.y, noz*2, 3)
poly: newPolygon().centerSpiral(pos, blok.x, blok.y, noz*2, 3)
};
blokpos.x += walkpos.x;
blokpos.y += walkpos.y;
@ -370,7 +371,63 @@
lastOut = undefined;
}
console.log({output});
print.output = render(output, progress => {
// console.log({render: progress});
}, device.extruders);
};
function render(output, update, tools) {
const layers = [];
output.forEach((level, index) => {
update(index / output.length);
const prints = {};
const moves = [];
const pushPrint = (tool, poly) => {
let array = prints[tool] = prints[tool] || [];
array.width = tools[tool].extNozzle / 2;
array.push(poly);
};
let lastOut = null;
let current = null;
let height = level.height / 2;
let width = 1;
level.forEach(out => {
if (lastOut) {
if (out.emit) {
if (!lastOut.emit) {
current = newPolygon().setOpen();
current.push(lastOut.point);
pushPrint(out.tool, current);
}
current.push(out.point);
} else {
if (lastOut.emit) {
current = newPolygon().setOpen();
current.push(lastOut.point);
moves.push(current);
}
current.push(out.point);
}
} else {
current = newPolygon().setOpen();
current.push(out.point);
if (out.emit) {
pushPrint(out.tool, current);
} else {
moves.push(current);
}
}
lastOut = out;
});
const out = new KIRI.Render();
layers.push(out);
out.setLayer('move', 0xaaaaaa).addPolys(moves);
Object.values(prints).forEach(array => {
out.setLayer('print', 0x888800).addPolys(array, { offset: array.width, height })
})
});
return layers;
}
})();