restore sla slice, preview, export

This commit is contained in:
Stewart Allen 2020-11-08 19:38:02 -05:00
commit feca4902d1
11 changed files with 77 additions and 541 deletions

View file

@ -24,7 +24,7 @@
/**
* @returns {Array} gcode lines
*/
CAM.export = function printExport(print, online) {
CAM.export = function(print, online) {
let widget = print.widgets[0];
if (!widget) return;
@ -80,26 +80,17 @@
},
append;
if (online) {
append = function(line) {
if (line) {
lines++;
bytes += line.length;
output.append(line);
}
if (!line || output.length > 1000) {
online(output.join("\n"));
output = [];
}
};
} else {
append = function(line) {
if (!line) return;
output.append(line);
append = function(line) {
if (line) {
lines++;
bytes += line.length;
output.append(line);
}
}
if (!line || output.length > 1000) {
online(output.join("\n"));
output = [];
}
};
function filterEmit(array, consts) {
if (!array) return;
@ -317,8 +308,6 @@
print.lines = lines;
print.bytes = bytes + lines - 1;
print.bounds = runbox;
return online ? null : output.join("\n");
};
})();

View file

@ -79,26 +79,17 @@
if (v >= 0) pause.push(v);
});
if (online) {
append = function(line) {
if (line) {
lines++;
bytes += line.length;
output.append(line);
}
if (!line || output.length > 1000) {
online(output.join("\n"));
output = [];
}
};
} else {
append = function(line) {
if (!line) return;
output.append(line);
append = function(line) {
if (line) {
lines++;
bytes += line.length;
output.append(line);
}
}
if (!line || output.length > 1000) {
online(output.join("\n"));
output = [];
}
};
function appendSub(line) {
append(print.constReplace(line, subst));
@ -375,8 +366,6 @@
print.lines = lines;
print.bytes = bytes + lines - 1;
print.time = time;
return online ? null : output.join("\n");
};
})();

View file

@ -218,191 +218,6 @@
doRender(slice);
}, "render");
// let polish = spro.polishLayers;
// // experimental polishing
// if (polish) {
// let polish_layer = Math.floor(polish);
// let polish_step = Math.max(polish - polish_layer || 1, 0.25);
// widget.polish = {};
// let px = [];
// let py = [];
// // compute x polishing slices
// SLICER.sliceWidget(widget, {
// height: nozzleSize * polish_step,
// swapX: true,
// swapY: false,
// simple: true
// }, (polish_done => {
// widget.polish.x = polish_done
// .filter(s => s.groups.length)
// .map(s => s.groups)
// .forEach(p => px.appendAll(p));
// }), (polish_update) => {
// // console.log({polish_update});
// });
// // compute y polishing slices
// SLICER.sliceWidget(widget, {
// height: nozzleSize * polish_step,
// swapX: false,
// swapY: true,
// simple: true
// }, (polish_done => {
// widget.polish.y = polish_done
// .filter(s => s.groups.length)
// .map(s => s.groups)
// .forEach(p => py.appendAll(p));
// }), (polish_update) => {
// // console.log({polish_update});
// });
// // apply polishing finishes to layers
// forSlices(1.0, 1.0, (slice) => {
// if (polish_layer >= 2) {
// let sai = (slice.index - polish_layer);
// if (sai % (polish_layer-1) !== 0) {
// return;
// }
// }
// if (slice.index >= polish_layer) {
// let sd = slice;
// for (let i=0; i<polish_layer; i++) {
// sd = sd.down;
// }
// let zb = sd.z;
// let zt = slice.z;
// let pout = [];
// let cont = 0;
// [px, py].forEach(pa => {
//
// let polys = [];
// pa.forEach(p => {
// // rotate and test for self-intersection (points under model)
// p.ensureXY();
// let ox = p._aligned == 'yz' ? 0.1 : 0;
// let oy = p._aligned == 'yz' ? 0 : 0.1;
// p.forEachPoint(pt => {
// let int = p.intersections(
// pt.offset(ox,oy,0),
// pt.offset(ox*10000,oy*10000,0));
// if (int.length > 0) {
// pt._under = true;
// }
// });
// p.restoreXY();
//
// let lastp = undefined;
// let poly = [];
// // look for qualifying segments
// p.forEachSegment((p1, p2) => {
// // eliminate segments that projected up
// // intersect with the polygon (bottom faces)
// if (p1._under || p2._under) {
// return;
// }
// // skip when both below layer range
// if (p1.z < zb && p2.z < zb) {
// return;
// }
// // skip when both above layer range
// if (p1.z > zt && p2.z > zt) {
// return;
// }
// // skip vertical
// if (p1.x === p2.x && p1.y === p2.y) {
// return;
// }
// // skip horizontal
// // if (p1.z === p2.z) {
// // return;
// // }
// // order points lowest to highest
// let swap = false;
// if (p1.z > p2.z) {
// let t = p2;
// p2 = p1;
// p1 = t;
// swap = true;
// }
// let trimlo = false;
// let trimhi = false;
// if (p1.z < zb) {
// trimlo = true;
// }
// if (p2.z > zt) {
// trimhi = true;
// }
// let xaxis = p1.x === p2.x;
// if (xaxis) {
// p1 = BASE.newPoint(p1.y,p1.z,p1.x);
// p2 = BASE.newPoint(p2.y,p2.z,p2.x);
// } else {
// p1 = BASE.newPoint(p1.x,p1.z,p1.y);
// p2 = BASE.newPoint(p2.x,p2.z,p2.y);
// }
// let slope = BASE.newSlope(p1, p2);
// let angle = slope.angle;
// if (angle > 80 && angle < 100) {
// return;
// }
// let len = p1.distTo2D(p2);
// let np1 = p1;
// if (trimlo) {
// let zunder = zb - p1.y;
// let zover = p2.y - zb;
// let zdelt = p2.y - p1.y;
// let pct = zunder / zdelt;
// np1 = p1.follow(slope, len * pct);
// }
// if (trimhi) {
// let zunder = zt - p1.y;
// let zover = p2.y - zt;
// let zdelt = p2.y - p1.y;
// let pct = zover / zdelt;
// p2 = p2.follow(slope.invert(), len * pct);
// }
// p1 = np1;
// if (xaxis) {
// p1 = BASE.newPoint(p1.z,p1.x,p1.y);
// p2 = BASE.newPoint(p2.z,p2.x,p2.y);
// } else {
// p1 = BASE.newPoint(p1.x,p1.z,p1.y);
// p2 = BASE.newPoint(p2.x,p2.z,p2.y);
// }
// if (!lastp) {
// poly.push(p1);
// poly.push(p2);
// } else if (p1.isMergable2D(lastp)) {
// // } else if (p1.isEqual(lastp)) {
// poly.push(p2);
// cont++;
// } else if (poly.length) {
// polys.push(poly);
// poly = [p1, p2];
// }
// lastp = p2;
// });
// if (poly.length) {
// polys.push(poly);
// }
// });
// pout.push(polys);
// polys = [];
// });
//
// if (pout.length && slice.tops.length) {
// slice.tops[0].polish = {
// x: pout[0]
// .map(a => BASE.newPolygon(a).setOpen())
// // .filter(p => p.perimeter() > nozzleSize)
// ,
// y: pout[1]
// .map(a => BASE.newPolygon(a).setOpen())
// // .filter(p => p.perimeter() > nozzleSize)
// };
// }
// }
// });
// }
// report slicing complete
ondone();
}
@ -799,6 +614,10 @@
* 'expand' is used for top offsets in SLA mode
*/
function doDiff(slice, minArea, sla, fakedown) {
if (slice.index === 0 && !fakedown) {
return;
}
const top = slice,
down = slice.down || (fakedown ? newSlice(-1) : null),
topInner = sla ? top.topPolys() : top.topInners(),

View file

@ -19,98 +19,17 @@
});
};
SLA.sliceRender = function(widget) {
// legacy debug
return;
widget.slices.forEach(slice => {
let layers = slice.layers,
outline = layers.outline,
support = layers.support;
if (slice.solids.unioned) {
// console.log('solid', slice.index)
slice.solids.unioned.forEach(poly => {
poly = poly.clone(true);//.move(widget.track.pos);
outline.poly(poly, 0x010101, true);
outline.solid(poly, 0x0099cc);
});
} else if (slice.tops) {
// console.log('top', slice.index)
slice.tops.forEach(top => {
let poly = top.poly;//.clone(true).move(widget.track.pos);
outline.poly(poly, 0x010101, true, false);
outline.solid(poly, 0xfcba03);
});
}
if (slice.supports) {
// console.log('support', slice.index)
slice.supports.forEach(poly => {
//poly = poly.clone(true).move(widget.track.pos);
support.poly(poly, 0x010101, true, false);
support.solid(poly, 0xfcba03);
});
}
slice.renderDiff();
slice.renderSolidOutlines();
outline.renderAll();
support.renderAll();
});
}
SLA.printRender = function(print) {
let widgets = print.widgets,
settings = print.settings,
device = settings.device,
process = settings.process;
for (let index=0; ; index++) {
let layer = KIRI.newLayer(print.group);
let count = 0;
widgets.forEach(widget => {
let slice = widget.slices[index];
if (!slice) {
return;
}
count++;
let polys = slice.solids.unioned;
if (!polys) polys = slice.tops.map(t => t.poly);
if (slice.supports) polys.appendAll(slice.supports);
polys.forEach(poly => {
poly = poly.clone(true).move(widget.track.pos);
layer.poly(poly, 0x777777, true);
layer.solid(poly, 0x0099cc);
});
});
layer.renderSolid();
layer.render();
if (count === 0) {
// TODO fix with contract for exposing layer count
// hack uses expected gcode output array in print object
print.output = print.printView;
return;
}
print.printView.push(layer);
}
}
SLA.printDownload = function(print) {
let { API, lines, done } = print.sla;
let filename = `print-${new Date().getTime().toString(36)}`;
SLA.printDownload = function(preview, output, API) {
const lines = preview;
const { file, width, height } = output;
const filename = `print-${new Date().getTime().toString(36)}`;
API.ajax("/kiri/output-sla.html", html => {
API.ui.print.innerHTML = html;
let printset = print.settings,
process = printset.process,
device = printset.device,
let settings = API.conf.get(),
process = settings.process,
device = settings.device,
print_sec = (process.slaBaseLayers * process.slaBaseOn) +
(lines.length - process.slaBaseLayers) * process.slaLayerOn;
@ -148,17 +67,17 @@
switch (device.deviceName) {
case 'Anycubic.Photon':
download.innerText += " .photon";
download.onclick = () => { saveFile(API, done.file, ".photon") };
download.onclick = () => { saveFile(API, file, ".photon") };
break;
case 'Anycubic.Photon.S':
download.innerText += " .photons";
download.onclick = () => { saveFile(API, done.file, ".photons") };
download.onclick = () => { saveFile(API, file, ".photons") };
break;
}
let canvas = $('print-canvas');
let ctx = canvas.getContext('2d');
let img = ctx.createImageData(done.height, done.width);
let img = ctx.createImageData(height, width);
let imgDV = new DataView(img.data.buffer);
let range = $('print-range');
range.value = 0;

View file

@ -11,7 +11,7 @@
SLA = KIRI.driver.SLA = {
// init, // src/mode/sla/client.js
// slice, // src/mode/sla/slice.js
printSetup,
prepare,
// export, // src/mode/sla/export.js
// printDownload, // src/mode/sla/client.js
legacy: false
@ -19,13 +19,10 @@
if (SLA.legacy) console.log("SLA Driver in Legacy Mode");
/**
* DRIVER PRINT CONTRACT - runs in worker
* @param {Object} print state object
* @param {Function} update incremental callback
*/
function printSetup(print, update) {
// runs in worker. would usually be in src/mode/sla/prepare.js
function prepare(widgets, settings, update) {
self.worker.print = KIRI.newPrint(settings, widgets);
update(1);
};
}
})();

View file

@ -15,7 +15,7 @@
* @param {Function} online streaming reply
* @param {Function} ondone last reply
*/
SLA.printExport = function(print, online, ondone) {
SLA.export = function(print, online, ondone) {
let widgets = print.widgets,
settings = print.settings,
device = settings.device,

View file

@ -6,6 +6,7 @@
let KIRI = self.kiri,
BASE = self.base,
POLY = BASE.polygons,
UTIL = BASE.util,
SLA = KIRI.driver.SLA,
FDM = KIRI.driver.FDM.share,
@ -120,14 +121,12 @@
slices[i-1].up = slices[i];
slices[i].down = slices[i-1];
}
// reset for solids and support projections
// slices.forEach(function(slice) {
// slice.invalidateFill();
// slice.invalidateSolids();
// slice.invalidateSupports();
// slice.isSolidFill = false;
// });
let solidLayers = Math.round(process.slaShell / process.slaSlice);
// setup solid fill
slices.forEach(function(slice) {
slice.solids = [];
});
// compute total work for progress bar
work_total = [
5, // shell
10, // diff
@ -147,7 +146,7 @@
}, "slice");
forSlices(slices, 10, (slice) => {
if (slice.synth) return;
FDM.doDiff(slice, 0.000001, 0.005, true, !process.slaOpenBase);
FDM.doDiff(slice, 0.000001, true, !process.slaOpenBase);
}, "delta");
if (solidLayers) {
forSlices(slices, 10, (slice) => {