From 8da355efbc4094e71a4491efeb3d2613cac2e3e2 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Thu, 16 Apr 2020 19:14:19 -0400 Subject: [PATCH] move file export to workers --- js/kiri-driver-sla.js | 94 ++++++++++++++++++++++++++----------------- js/kiri-export.js | 4 +- 2 files changed, 59 insertions(+), 39 deletions(-) diff --git a/js/kiri-driver-sla.js b/js/kiri-driver-sla.js index 4ea576be..e6c62220 100644 --- a/js/kiri-driver-sla.js +++ b/js/kiri-driver-sla.js @@ -187,18 +187,37 @@ let gs_kiri_sla = exports; process = settings.process, output = print.output; - print.images.forEach(image => { - online(image.data, [image.data.buffer]); + print.images.forEach((image,index) => { + // online(image.data, [image.data.buffer]); + online({progress: (index/print.images.length)/2, data: image.data}); }); + + let exp_func; + + switch (device.deviceName) { + case 'Anycubic.Photon': + exp_func = generatePhoton; + break; + case 'Anycubic.Photon.S': + exp_func = generatePhotons; + break; + } + + let file = exp_func(print, { + width: 2560, + height: 1440, + lines: print.images.map(i => i.data), + small: previewSmall.data, + large: previewLarge.data + }, progress => { + online({progress: progress/2 + 0.5}); + }); + ondone({ width:2560, height:1440, - small:previewSmall.data, - large:previewLarge.data - },[ - previewSmall.data.buffer, - previewLarge.data.buffer - ]); + file:file + },[file]); }; // runs in browser main @@ -218,7 +237,6 @@ let gs_kiri_sla = exports; if (!slice) { return; } - // let polys = slice.gatherTraces([]); let polys = slice.solids.unioned; polys.forEach(poly => { layer.poly(poly, 0x888888, true, false); @@ -267,11 +285,11 @@ let gs_kiri_sla = exports; switch (device.deviceName) { case 'Anycubic.Photon': download.innerText += " .photon"; - download.onclick = () => { download_photon(print) }; + download.onclick = () => { saveFile(API, done.file, ".photon") }; break; case 'Anycubic.Photon.S': download.innerText += " .photons"; - download.onclick = () => { download_photons(print) }; + download.onclick = () => { saveFile(API, done.file, ".photons") }; break; } @@ -298,18 +316,25 @@ let gs_kiri_sla = exports; }); } - function download_photon(print) { + function saveFile(API, file, ext) { + saveAs( + new Blob([file], { type: "application/octet-stream" }), + $('print-filename').value + ext); + API.modal.hide(); + } + + function generatePhoton(print, conf, progress) { let printset = print.settings, process = printset.process, device = printset.device, - width = print.sla.done.width, - height = print.sla.done.height, - layerCount = print.sla.lines.length, + width = conf.width, + height = conf.height, + layerCount = conf.lines.length, layerBytes = width * height, - small = print.sla.done.small, - large = print.sla.done.large; + small = conf.small, + large = conf.large; - let converted = print.sla.lines.map((line, index) => { + let converted = conf.lines.map((line, index) => { let count = line.length / 4; let bits = new Uint8Array(line.length / 4); let bitsDV = new DataView(bits.buffer); @@ -319,6 +344,7 @@ let gs_kiri_sla = exports; // defeat anti-aliasing for the moment bitsDV.setUint8(i, lineDV.getUint8(i * 4) > 0 ? 1 : 0); } + progress(index / conf.lines.length); return { subs: [{ exposureTime: process.slaLayerOn, @@ -400,39 +426,36 @@ let gs_kiri_sla = exports; for (let j=0; j { + let converted = conf.lines.map((line, index) => { let count = line.length / 4; let bits = new Uint8Array(line.length / 4); let bitsDV = new DataView(bits.buffer); @@ -442,6 +465,7 @@ let gs_kiri_sla = exports; // defeat anti-aliasing for the moment bitsDV.setUint8(i, lineDV.getUint8(i * 4) > 0 ? 1 : 0); } + progress(index / conf.lines.length); return { subs: [{ exposureTime: process.slaLayerOn, @@ -491,16 +515,10 @@ let gs_kiri_sla = exports; filedat.setUint8(filePos + j, sublayer[j], false); } filePos += numbytes; + progress((i / layerCount) / 2 + 0.5); } - saveAs( - new Blob([filebuf], { type: "application/octet-stream" }), - $('print-filename').value + ".photons"); - - print.sla.API.modal.hide(); - } - - function download_pws() { + return filebuf; } function encodeLayers(input, type) { diff --git a/js/kiri-export.js b/js/kiri-export.js index d59fe028..6d75ae3e 100644 --- a/js/kiri-export.js +++ b/js/kiri-export.js @@ -40,8 +40,10 @@ let gs_kiri_export = exports; if (currentPrint) { let lines = []; currentPrint.export(true, function(line) { - lines.push(line); + if (line.progress) API.show.progress(line.progress, "exporting"); + if (line.data) lines.push(line.data); }, function(done) { + API.show.progress(0); currentPrint.sla = { lines, done, API }; KIRI.driver.SLA.printDownload(currentPrint); });