partial sla slice render restore

This commit is contained in:
Stewart Allen 2020-11-08 18:39:21 -05:00
commit 1c5c8e9cb4
10 changed files with 170 additions and 125 deletions

View file

@ -47,7 +47,6 @@
localFilterKey ='kiri-gcode-filters', localFilterKey ='kiri-gcode-filters',
localFilters = js2o(SDB.getItem(localFilterKey)) || [], localFilters = js2o(SDB.getItem(localFilterKey)) || [],
// --------------- // ---------------
renderMode = 4,
viewMode = VIEWS.ARRANGE, viewMode = VIEWS.ARRANGE,
layoutOnAdd = true, layoutOnAdd = true,
local = SETUP.local, local = SETUP.local,
@ -59,7 +58,6 @@
alerts = [], alerts = [],
grouping = false; grouping = false;
if (SETUP.rm) renderMode = parseInt(SETUP.rm[0]);
DBUG.enable(); DBUG.enable();
// remove version, preserve other settings // remove version, preserve other settings
@ -227,11 +225,11 @@
feature, feature,
function: { function: {
slice: prepareSlices, slice: prepareSlices,
print: preparePrint, print: preparePreview,
prepare: preparePrint, prepare: preparePreview,
export: function() { KIRI.export(...arguments) }, export: function() { KIRI.export(...arguments) },
cancel: cancelWorker, cancel: cancelWorker,
clear: () => { console.log("api.function.clear unimplemented") } clear: KIRI.client.clear
}, },
hide: { hide: {
alert: function(rec) { alert2cancel(rec) }, alert: function(rec) { alert2cancel(rec) },
@ -655,71 +653,6 @@
showSlices(); showSlices();
} }
function preparePrint(callback) {
if (viewMode === VIEWS.PREVIEW) return;
hideSlider(true);
// kick off slicing it hasn't been done already
for (let i=0; i < WIDGETS.length; i++) {
if (!WIDGETS[i].slices || WIDGETS[i].isModified()) {
prepareSlices(function() {
if (!WIDGETS[i].slices || WIDGETS[i].isModified()) {
alert2("nothing to print");
} else {
preparePrint(callback);
}
});
return;
}
}
let isCam = MODE === MODES.CAM, pMode = getMode();
if (feature.preview) {
setViewMode(VIEWS.PREVIEW);
}
API.conf.save();
API.event.emit('preview.begin', pMode);
if (isCam) {
setOpacity(color.cam_preview_opacity);
forAllWidgets(function(widget) {
widget.setColor(color.cam_preview);
});
} else if (feature.preview) {
setOpacity(color.preview_opacity);
}
KIRI.client.prepare(settings, function(progress, message) {
API.show.progress(progress, message);
}, function (output) {
API.show.progress(0);
if (!isCam) setOpacity(0);
output = KIRI.codec.decode(output);
if (feature.preview && output) {
STACKS.clear();
const stack = STACKS.create('print', SPACE.platform.world)
output.forEach(layer => {
stack.add(layer);
});
}
API.event.emit('print', pMode);
API.event.emit('preview.end', pMode);
if (feature.preview) {
SPACE.update();
updateSliderMax(true);
showSlices();
}
if (typeof(callback) === 'function') {
callback();
}
});
}
function cancelWorker() { function cancelWorker() {
if (KIRI.work.isSlicing()) KIRI.work.restart(); if (KIRI.work.isSlicing()) KIRI.work.restart();
} }
@ -736,11 +669,6 @@
// UI.setMenu.style.display = andmenu ? 'none' : 'flex'; // UI.setMenu.style.display = andmenu ? 'none' : 'flex';
} }
/**
* incrementally slice all meshes then incrementally update them
*
* @param {Function} callback
*/
function prepareSlices(callback) { function prepareSlices(callback) {
if (viewMode == VIEWS.ARRANGE) { if (viewMode == VIEWS.ARRANGE) {
let snap = SPACE.screenshot(); let snap = SPACE.screenshot();
@ -748,7 +676,7 @@
KIRI.work.snap(API.view.snapshot); KIRI.work.snap(API.view.snapshot);
} }
if (MODE === MODES.SLA && !callback) { if (MODE === MODES.SLA && !callback) {
callback = preparePrint; callback = preparePreview;
} }
hideSlider(true); hideSlider(true);
@ -838,6 +766,77 @@
}); });
} }
function preparePreview(callback) {
if (viewMode === VIEWS.PREVIEW) return;
if (viewMode === VIEWS.ARRANGE) {
prepareSlices(() => {
preparePreview(callback);
});
}
hideSlider(true);
// kick off slicing it hasn't been done already
for (let i=0; i < WIDGETS.length; i++) {
if (!WIDGETS[i].slices || WIDGETS[i].isModified()) {
prepareSlices(function() {
if (!WIDGETS[i].slices || WIDGETS[i].isModified()) {
alert2("nothing to print");
} else {
preparePreview(callback);
}
});
return;
}
}
let isCam = MODE === MODES.CAM, pMode = getMode();
if (feature.preview) {
setViewMode(VIEWS.PREVIEW);
}
API.conf.save();
API.event.emit('preview.begin', pMode);
if (isCam) {
setOpacity(color.cam_preview_opacity);
forAllWidgets(function(widget) {
widget.setColor(color.cam_preview);
});
} else if (feature.preview) {
setOpacity(color.preview_opacity);
}
KIRI.client.prepare(settings, function(progress, message) {
API.show.progress(progress, message);
}, function (output) {
API.show.progress(0);
if (!isCam) setOpacity(0);
output = KIRI.codec.decode(output);
if (feature.preview && output) {
STACKS.clear();
const stack = STACKS.create('print', SPACE.platform.world)
output.forEach(layer => {
stack.add(layer);
});
}
API.event.emit('print', pMode);
API.event.emit('preview.end', pMode);
if (feature.preview) {
SPACE.update();
updateSliderMax(true);
showSlices();
}
if (typeof(callback) === 'function') {
callback();
}
});
}
/** ****************************************************************** /** ******************************************************************
* Selection Functions * Selection Functions
******************************************************************* */ ******************************************************************* */

View file

@ -39,7 +39,7 @@
this.settings = settings; this.settings = settings;
this.widgets = widgets; this.widgets = widgets;
this.group = new THREE.Group(); // this.group = new THREE.Group();
this.printView = []; this.printView = [];
this.movesView = []; this.movesView = [];
@ -387,23 +387,23 @@
return out; return out;
} }
PRO.getLayerCount = function() { // PRO.getLayerCount = function() {
return this.output.length; // return this.output.length;
} // }
PRO.hide = function() { // PRO.hide = function() {
this.printView.forEach(function(layer) { // this.printView.forEach(function(layer) {
layer.setVisible(false); // layer.setVisible(false);
}) // })
this.movesView.forEach(function(layer) { // this.movesView.forEach(function(layer) {
layer.setVisible(false); // layer.setVisible(false);
}) // })
}; // };
//
PRO.showLayer = function(index, show, moves) { // PRO.showLayer = function(index, show, moves) {
if (this.printView[index]) this.printView[index].setVisible(show); // if (this.printView[index]) this.printView[index].setVisible(show);
if (this.movesView[index]) this.movesView[index].setVisible(show && moves); // if (this.movesView[index]) this.movesView[index].setVisible(show && moves);
}; // };
/** /**
* @constructor * @constructor

View file

@ -91,7 +91,7 @@
}); });
}); });
if (options && options.outline) { if (options && options.outline) {
this.addPolys(poly.clone()); this.addPolys(polys.clone(true));
} }
} }

View file

@ -110,7 +110,11 @@
const { polys, lines, faces, paths } = data; const { polys, lines, faces, paths } = data;
if (polys.length || lines.length) { if (polys.length || lines.length) {
const mat = new THREE.LineBasicMaterial({ color: data.color.line }); const mat = new THREE.LineBasicMaterial({
transparent: data.color.opacity != 1,
opacity: data.color.opacity,
color: data.color.line
});
const geo = new THREE.Geometry(), vert = geo.vertices; const geo = new THREE.Geometry(), vert = geo.vertices;
for (let i=0, il=polys.length; i<il; i++) { for (let i=0, il=polys.length; i<il; i++) {
addPoly(vert, polys[i]); addPoly(vert, polys[i]);

View file

@ -141,11 +141,11 @@ KIRI.worker = {
const output = driver.export(current.print, function(line) { const output = driver.export(current.print, function(line) {
send.data({line}); send.data({line});
}); });
const { time, lines, bytes, bounds } = current.print; const { bounds, time, lines, bytes, distance } = current.print;
send.done({ send.done({
done: true, done: true,
output: { time, lines, bytes, bounds } output: { bounds, time, lines, bytes, distance }
}); });
}, },

View file

@ -9,7 +9,7 @@
// init, // src/mode/cam/client.js // init, // src/mode/cam/client.js
// slice, // src/mode/cam/slice.js // slice, // src/mode/cam/slice.js
// prepare, // src/mode/cam/prepare.js // prepare, // src/mode/cam/prepare.js
// printExport, // src/mode/cam/export.js // export // src/mode/cam/export.js
}, },
CPRO = CAM.process = { CPRO = CAM.process = {
LEVEL: 1, LEVEL: 1,

View file

@ -13,7 +13,7 @@
// init, // src/mode/fdm/client.js // init, // src/mode/fdm/client.js
// slice, // src/mode/fdm/slice.js // slice, // src/mode/fdm/slice.js
// prepare, // src/mode/fdm/prepare.js // prepare, // src/mode/fdm/prepare.js
// printExport, // src/mode/fdm/export.js // export, // src/mode/fdm/export.js
fixExtruders fixExtruders
}; };

View file

@ -479,6 +479,15 @@
// console.log(slice.index, slice.render.stats); // console.log(slice.index, slice.render.stats);
} }
// shared with SLA driver
FDM.share = {
doShells,
doDiff,
projectFlats,
projectBridges,
doSolidsFill
};
/** /**
* Compute offset shell polygons. For FDM, the first offset is usually half * Compute offset shell polygons. For FDM, the first offset is usually half
* of the nozzle width. Each subsequent offset is a full nozzle width. User * of the nozzle width. Each subsequent offset is a full nozzle width. User
@ -789,11 +798,11 @@
* Used to calculate bridges, flats and then solid projections. * Used to calculate bridges, flats and then solid projections.
* 'expand' is used for top offsets in SLA mode * 'expand' is used for top offsets in SLA mode
*/ */
function doDiff(slice, minArea, sla) { function doDiff(slice, minArea, sla, fakedown) {
const top = slice, const top = slice,
down = slice.down, down = slice.down || (fakedown ? newSlice(-1) : null),
topInner = sla ? top.topPolys() : top.topInners(), topInner = sla ? top.topPolys() : top.topInners(),
downInner = sla ? down.downPolys() : down.topInners(), downInner = sla ? down.topPolys() : down.topInners(),
bridges = top.bridges = [], bridges = top.bridges = [],
flats = down.flats = []; flats = down.flats = [];

View file

@ -10,11 +10,9 @@
const KIRI = self.kiri, const KIRI = self.kiri,
SLA = KIRI.driver.SLA = { SLA = KIRI.driver.SLA = {
// init, // src/mode/sla/client.js // init, // src/mode/sla/client.js
// printRender // src/mode/sla/client.js
// sliceRender, // src/mode/sla/client.js
// slice, // src/mode/sla/slice.js // slice, // src/mode/sla/slice.js
printSetup, printSetup,
// printExport, // src/mode/sla/export.js // export, // src/mode/sla/export.js
// printDownload, // src/mode/sla/client.js // printDownload, // src/mode/sla/client.js
legacy: false legacy: false
}; };

View file

@ -8,6 +8,7 @@
BASE = self.base, BASE = self.base,
UTIL = BASE.util, UTIL = BASE.util,
SLA = KIRI.driver.SLA, SLA = KIRI.driver.SLA,
FDM = KIRI.driver.FDM.share,
SLICER = KIRI.slicer, SLICER = KIRI.slicer,
newTop = KIRI.newTop, newTop = KIRI.newTop,
newSlice = KIRI.newSlice, newSlice = KIRI.newSlice,
@ -120,12 +121,12 @@
slices[i].down = slices[i-1]; slices[i].down = slices[i-1];
} }
// reset for solids and support projections // reset for solids and support projections
slices.forEach(function(slice) { // slices.forEach(function(slice) {
slice.invalidateFill(); // slice.invalidateFill();
slice.invalidateSolids(); // slice.invalidateSolids();
slice.invalidateSupports(); // slice.invalidateSupports();
slice.isSolidFill = false; // slice.isSolidFill = false;
}); // });
let solidLayers = Math.round(process.slaShell / process.slaSlice); let solidLayers = Math.round(process.slaShell / process.slaSlice);
work_total = [ work_total = [
5, // shell 5, // shell
@ -139,34 +140,34 @@
work_remain = work_total; work_remain = work_total;
forSlices(slices, 5, (slice,index) => { forSlices(slices, 5, (slice,index) => {
if (process.slaShell) { if (process.slaShell) {
slice.doShells(2, 0, process.slaShell); FDM.doShells(slice, 2, 0, process.slaShell);
} else { } else {
slice.doShells(1, 0); FDM.doShells(slice, 1, 0);
} }
}, "slice"); }, "slice");
forSlices(slices, 10, (slice) => { forSlices(slices, 10, (slice) => {
if (slice.synth) return; if (slice.synth) return;
slice.doDiff(0.000001, 0.005, !process.slaOpenBase); FDM.doDiff(slice, 0.000001, 0.005, true, !process.slaOpenBase);
}, "delta"); }, "delta");
if (solidLayers) { if (solidLayers) {
forSlices(slices, 10, (slice) => { forSlices(slices, 10, (slice) => {
if (slice.synth) return; if (slice.synth) return;
slice.projectFlats(solidLayers); FDM.projectFlats(slice, solidLayers);
slice.projectBridges(solidLayers); FDM.projectBridges(slice, solidLayers);
}, "project"); }, "project");
forSlices(slices, 10, (slice) => { forSlices(slices, 10, (slice) => {
if (slice.synth) return; if (slice.synth) return;
slice.doSolidsFill(undefined, undefined, 0.001); FDM.doSolidsFill(slice, undefined, undefined, 0.001);
let traces = POLY.nest(POLY.flatten(slice.gatherTraces([]))); let traces = POLY.nest(POLY.flatten(slice.topShells()));
let trims = slice.solids.trimmed || []; let trims = slice.solids || [];
traces.appendAll(trims); traces.appendAll(trims);
let union = POLY.union(traces); let union = POLY.union(traces);
slice.solids.unioned = union; slice.unioned = union;
}, "solid"); }, "solid");
} else { } else {
forSlices(slices, 10, (slice) => { forSlices(slices, 10, (slice) => {
if (slice.synth) return; if (slice.synth) return;
slice.solids.unioned = slice.gatherTopPolys([]); slice.unioned = slice.topPolys();
}, "solid"); }, "solid");
} }
if (process.slaFillDensity && process.slaShell) { if (process.slaFillDensity && process.slaShell) {
@ -181,12 +182,46 @@
doupdate(100 * progress, "support"); doupdate(100 * progress, "support");
}); });
} }
doRender(widget);
ondone(); ondone();
}, function(update) { }, function(update) {
return onupdate(0.0 + update * 0.25); return onupdate(0.0 + update * 0.25);
}); });
}; };
function doRender(widget) {
widget.slices.forEach(slice => {
const render = slice.output();
if (slice.unioned) {
// console.log('solid', slice.index)
slice.unioned.forEach(poly => {
poly = poly.clone(true);//.move(widget.track.pos);
render
.setLayer("layers", { line: 0x010101, face: 0x0099cc, opacity: 0.2 })
.addAreas([poly], { outline: true });
});
} else if (slice.tops) {
// console.log('top', slice.index)
slice.tops.forEach(top => {
let poly = top.poly;//.clone(true).move(widget.track.pos);
render
.setLayer("layers", { line: 0x010101, face: 0xfcba03, opacity: 0.2 })
.addAreas([poly], { outline: true });
});
}
if (slice.supports) {
// console.log('support', slice.index)
slice.supports.forEach(poly => {
render
.setLayer("support", { line: 0x010101, face: 0xfcba03, opacity: 0.2 })
.addAreas([poly], { outline: true });
});
}
});
}
function computeSupports(widget, process, progress) { function computeSupports(widget, process, progress) {
let area = widget.union.reduce((t,p) => { return t + p.areaDeep() }, 0), let area = widget.union.reduce((t,p) => { return t + p.areaDeep() }, 0),
perim = widget.union.reduce((t,p) => { return t + p.perimeter() }, 0), perim = widget.union.reduce((t,p) => { return t + p.perimeter() }, 0),
@ -199,7 +234,7 @@
// compute total "mass" by slice // compute total "mass" by slice
ops.forEach(slice => { ops.forEach(slice => {
slice.mass = slice.solids.unioned.reduce((t,p) => { return t + p.areaDeep() }, 0); slice.mass = slice.unioned.reduce((t,p) => { return t + p.areaDeep() }, 0);
if (slice.up && slice.up.bridges) { if (slice.up && slice.up.bridges) {
slice.bear = slice.up.bridges.reduce((t,p) => { return t + p.areaDeep() }, 0); slice.bear = slice.up.bridges.reduce((t,p) => { return t + p.areaDeep() }, 0);
slice.bear_up = slice.up.bridges; slice.bear_up = slice.up.bridges;
@ -499,7 +534,7 @@
function fillPolys(slice, settings) { function fillPolys(slice, settings) {
let process = settings.process, let process = settings.process,
device = settings.device, device = settings.device,
polys = slice.solids.unioned, polys = slice.unioned,
bounds = settings.bounds, bounds = settings.bounds,
width = bounds.max.x - bounds.min.x, width = bounds.max.x - bounds.min.x,
depth = bounds.max.y - bounds.min.y, depth = bounds.max.y - bounds.min.y,
@ -550,9 +585,9 @@
} }
fill = POLY.trimTo(fill, slice.tops.map(t => t.poly)); fill = POLY.trimTo(fill, slice.tops.map(t => t.poly));
fill = POLY.union(slice.solids.unioned.appendAll(fill)); fill = POLY.union(slice.unioned.appendAll(fill));
slice.solids.unioned = fill; slice.unioned = fill;
} }
function pixAt(png,x,y) { function pixAt(png,x,y) {