checkpoint sla work

This commit is contained in:
Stewart Allen 2020-04-14 09:26:59 -04:00
commit c2361b2299
6 changed files with 122 additions and 11 deletions

View file

@ -92,7 +92,44 @@ let gs_kiri_sla = exports;
settings = print.settings, settings = print.settings,
device = settings.device, device = settings.device,
process = settings.process, process = settings.process,
output = print.output; output = print.images = [],
layermax = 0,
width = 2560,
height = 1440,
width2 = width/2,
height2 = height/2;
widgets.forEach(widget => {
layermax = Math.max(widget.slices.length);
});
for (let index=0; index < layermax; index++) {
let layer = new OffscreenCanvas(width,height);
let ctx = layer.getContext('2d');
ctx.fillStyle = 'rgb(200, 0, 0)';
let count = 0;
widgets.forEach(widget => {
let slice = widget.slices[index];
if (slice) {
slice.tops.map(top => top.poly).forEach(poly => {
ctx.beginPath();
poly.forEachPoint((p,i) => {
if (i === 0) {
ctx.moveTo(p.x + width2, p.y + height2);
} else {
ctx.lineTo(p.x + width2, p.y + height2);
}
}, true);
ctx.fill();
count++;
});
}
});
output.push(ctx.getImageData(0,0,width,height));
update(index / layermax);
if (count === 0) break;
}
// in theory sends back pre-gcode print preview data // in theory sends back pre-gcode print preview data
update(1); update(1);
@ -101,17 +138,23 @@ let gs_kiri_sla = exports;
/** /**
* DRIVER PRINT CONTRACT - runs in worker * DRIVER PRINT CONTRACT - runs in worker
* @param {Object} print state object * @param {Object} print state object
* @param {Function} online optional streaming reply * @param {Function} online streaming reply
* @param {Function} ondone last reply
*/ */
function printExport(print, online) { function printExport(print, online, ondone) {
let widgets = print.widgets, let widgets = print.widgets,
settings = print.settings, settings = print.settings,
device = settings.device, device = settings.device,
process = settings.process, process = settings.process,
output = print.output; output = print.output;
print.images.forEach(image => {
online(image.data, [image.data.buffer]);
});
// in theory converts print data from printSetup to gcode // in theory converts print data from printSetup to gcode
return; // online("pex.line");
ondone({width:2560,height:1440});
}; };
// runs in browser main // runs in browser main
@ -148,21 +191,32 @@ let gs_kiri_sla = exports;
} }
// runs in browser main // runs in browser main
function printDownload(API, currentPrint) { function printDownload(API, lines, done) {
if (!currentPrint) {
return API.function.print(printDownload);
}
let filename = "print-"+(new Date().getTime().toString(36)); let filename = "print-"+(new Date().getTime().toString(36));
API.ajax("/kiri/output-sla.html", html => { API.ajax("/kiri/output-sla.html", html => {
API.ui.print.innerHTML = html; API.ui.print.innerHTML = html;
$('print-filename').value = filename; $('print-filename').value = filename;
$('print-layers').value = currentPrint.output.length; $('print-layers').value = lines.length;
$('print-close').onclick = API.modal.hide; $('print-close').onclick = API.modal.hide;
$('print-photons').onclick = download_photons; $('print-photons').onclick = download_photons;
$('print-photon').onclick = download_photon; $('print-photon').onclick = download_photon;
$('print-pws').onclick = download_pws; $('print-pws').onclick = download_pws;
let canvas = $('print-canvas');
let ctx = canvas.getContext('2d');
let img = ctx.createImageData(done.width, done.height);
let range = $('print-range');
range.value = 0;
range.min = 0;
range.max = lines.length;
range.oninput = function() {
console.log(range.value);
lines[range.value].forEach((v,i) => img.data[i] = v);
ctx.putImageData(img,0,0);
};
API.modal.show('print'); API.modal.show('print');
}); });
} }

View file

@ -29,13 +29,26 @@ let gs_kiri_export = exports;
case 'LASER': return exportPrintLaser(currentPrint); case 'LASER': return exportPrintLaser(currentPrint);
case 'FDM': return exportPrintGCODE(currentPrint); case 'FDM': return exportPrintGCODE(currentPrint);
case 'CAM': return exportPrintGCODE(currentPrint); case 'CAM': return exportPrintGCODE(currentPrint);
case 'SLA': return KIRI.driver.SLA.printDownload(API,currentPrint); case 'SLA': return exportPrintSLA(currentPrint);
} }
} else { } else {
API.function.print(exportPrint); API.function.print(exportPrint);
} }
} }
function exportPrintSLA(currentPrint) {
if (currentPrint) {
let lines = [];
currentPrint.export(true, function(line) {
lines.push(line);
}, function(done) {
KIRI.driver.SLA.printDownload(API, lines, done);
});
} else {
API.function.print(exportPrintSLA);
}
}
function exportPrintGCODE(currentPrint) { function exportPrintGCODE(currentPrint) {
if (currentPrint) { if (currentPrint) {
currentPrint.exportGCode(true, function(gcode) { currentPrint.exportGCode(true, function(gcode) {

View file

@ -234,6 +234,25 @@ let gs_kiri_print = exports;
} }
}; };
// more generic. only used by SLA at the moment
PRO.export = function(remote, online, ondone) {
let driver = KIRI.driver[this.settings.mode];
if (!(driver && driver.printExport)) {
console.log({missing_export_driver: mode});
ondone(null);
return;
}
if (remote) {
// executed from kiri.js
KIRI.work.printExport(this.settings, online, ondone);
} else {
// executed from kiri-worker.js
driver.printExport(this, online, ondone);
}
};
PRO.exportGCode = function(remote, ondone, online) { PRO.exportGCode = function(remote, ondone, online) {
let scope = this, let scope = this,
settings = scope.settings, settings = scope.settings,

View file

@ -101,6 +101,18 @@ KIRI.work = {
}); });
}, },
printExport : function(settings, online, ondone) {
let lines = [];
send("printExport", {settings:settings}, function(reply) {
if (reply.line) {
online(reply.line);
}
if (reply.done) {
ondone(reply.done);
}
});
},
printGCode : function(callback) { printGCode : function(callback) {
let gcode = []; let gcode = [];
let start = BASE.util.time(); let start = BASE.util.time();

View file

@ -110,6 +110,14 @@ let dispatch = {
}); });
}, },
printExport: function(data, send) {
currentPrint.export(false, function(line, direct) {
send.data({line}, direct);
}, function(done, direct) {
send.done({done}, direct);
});
},
printGCode: function(data, send) { printGCode: function(data, send) {
currentPrint.exportGCode(false, function(gcode) { currentPrint.exportGCode(false, function(gcode) {
send.done({ send.done({

View file

@ -16,3 +16,8 @@
<tr><th><button id="print-pws">download as .pws</button></th></tr> <tr><th><button id="print-pws">download as .pws</button></th></tr>
</table> </table>
</div> </div>
<div class="print-sel">
<canvas id="print-canvas" width="2560" height="1440"></canvas>
<input id="print-range" type="range" width="100%">
</div>