re-introduce preview mode. optimize preview / export. prevent multiple calls to those modes

This commit is contained in:
Stewart Allen 2020-04-25 21:08:13 -04:00
commit 6ced99522d
6 changed files with 64 additions and 104 deletions

View file

@ -528,21 +528,32 @@ let gs_kiri_sla = exports;
* @param {Function} update incremental callback * @param {Function} update incremental callback
*/ */
function printSetup(print, update) { function printSetup(print, update) {
update(1);
};
/**
* DRIVER PRINT CONTRACT - runs in worker
* @param {Object} print state object
* @param {Function} online streaming reply
* @param {Function} ondone last reply
*/
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.images = [], output = print.output,
images = [],
layermax = 0, layermax = 0,
width = 2560, width = 2560,
height = 1440, height = 1440,
width2 = width/2, width2 = width/2,
height2 = height/2, height2 = height/2,
scaleX = width / device.bedWidth, scaleX = width / device.bedWidth,
scaleY = height / device.bedDepth; scaleY = height / device.bedDepth,
mark = Date.now();
let mark = Date.now();
// find max layer count
widgets.forEach(widget => { widgets.forEach(widget => {
layermax = Math.max(widget.slices.length); layermax = Math.max(widget.slices.length);
}); });
@ -558,6 +569,7 @@ let gs_kiri_sla = exports;
ctx.closePath(); ctx.closePath();
} }
// generate layer 8-bit bitaps using canvas
for (let index=0; index < layermax; index++) { for (let index=0; index < layermax; index++) {
let layer = new OffscreenCanvas(height,width); let layer = new OffscreenCanvas(height,width);
let ctx = layer.getContext('2d'); let ctx = layer.getContext('2d');
@ -588,42 +600,21 @@ let gs_kiri_sla = exports;
} }
}); });
let data = ctx.getImageData(0,0,height,width).data; let data = ctx.getImageData(0,0,height,width).data;
// reduce RGBA to R
let red = new Uint8ClampedArray(data.length / 4); let red = new Uint8ClampedArray(data.length / 4);
for (let i=0; i<red.length; i++) { for (let i=0; i<red.length; i++) {
red[i] = data[i*4]; red[i] = data[i*4];
} }
output.push(red); images.push(red);
update(index / layermax); // transfer images to browser main
online({
progress: (index / layermax) * 0.25,
message: "image_gen",
data: red
});
if (count === 0) break; if (count === 0) break;
} }
update(1);
console.log('print.setup', Date.now() - mark);
};
/**
* DRIVER PRINT CONTRACT - runs in worker
* @param {Object} print state object
* @param {Function} online streaming reply
* @param {Function} ondone last reply
*/
function printExport(print, online, ondone) {
let widgets = print.widgets,
settings = print.settings,
device = settings.device,
process = settings.process,
output = print.output,
mark = Date.now();
print.images.forEach((image,index) => {
online({
progress: (index / print.images.length) * 0.25,
message: "image_xfer",
data: image
});
});
let exp_func; let exp_func;
switch (device.deviceName) { switch (device.deviceName) {
@ -636,9 +627,9 @@ let gs_kiri_sla = exports;
} }
let file = exp_func(print, { let file = exp_func(print, {
width: 2560, width: width,
height: 1440, height: height,
lines: print.images, lines: images,
small: previewSmall.data, small: previewSmall.data,
large: previewLarge.data large: previewLarge.data
}, (progress, message) => { }, (progress, message) => {
@ -646,13 +637,11 @@ let gs_kiri_sla = exports;
}); });
ondone({ ondone({
width: 2560, width: width,
height: 1440, height: height,
file: file file: file
},[file]); },[file]);
// release memory
print.images = null;
console.log('print.export', Date.now() - mark); console.log('print.export', Date.now() - mark);
}; };
@ -729,7 +718,7 @@ let gs_kiri_sla = exports;
if (count === 0) { if (count === 0) {
// TODO fix with contract for exposing layer count // TODO fix with contract for exposing layer count
// hack uses expected gcode output array in print object // hack uses expected gcode output array in print object
print.output = print.printView; // print.output = print.printView;
return; return;
} }

View file

@ -32,19 +32,16 @@ let gs_kiri_export = exports;
case 'SLA': return exportPrintSLA(currentPrint); case 'SLA': return exportPrintSLA(currentPrint);
} }
} else { } else {
switch (API.mode.get()) { API.function.print(exportPrint);
case 'SLA':
API.function.slice(exportPrint);
break;
default:
API.function.print(exportPrint);
break;
}
} }
} }
function exportPrintSLA(currentPrint) { function exportPrintSLA(currentPrint) {
if (currentPrint) { if (currentPrint) {
if (currentPrint.exported) {
KIRI.driver.SLA.printDownload(currentPrint);
return;
}
let lines = []; let lines = [];
let times = {}; let times = {};
let mark = Date.now(); let mark = Date.now();
@ -62,6 +59,7 @@ let gs_kiri_export = exports;
if (line.progress) API.show.progress(line.progress, "exporting"); if (line.progress) API.show.progress(line.progress, "exporting");
if (line.data) lines.push(line.data); if (line.data) lines.push(line.data);
}, function(done) { }, function(done) {
currentPrint.exported = true;
times[`${seq++}_${segment}`] = Date.now() - mark; times[`${seq++}_${segment}`] = Date.now() - mark;
console.log(times); console.log(times);
API.show.progress(0); API.show.progress(0);

View file

@ -314,9 +314,7 @@ var gs_kiri_init = exports;
API.function.slice(); API.function.slice();
break; break;
case cca('p'): // prepare print case cca('p'): // prepare print
if (!API.conf.isSliceSkipped()) { API.function.print();
API.function.print();
}
break; break;
case cca('P'): // position widget case cca('P'): // position widget
positionSelection(); positionSelection();
@ -1278,7 +1276,7 @@ var gs_kiri_init = exports;
expert: UC.newBoolean(LANG.op_xprt_s, booleanSave, {title:LANG.op_xprt_l}), expert: UC.newBoolean(LANG.op_xprt_s, booleanSave, {title:LANG.op_xprt_l}),
compact: UC.newBoolean(LANG.op_comp_s, booleanSave, {title:LANG.op_comp_l}), compact: UC.newBoolean(LANG.op_comp_s, booleanSave, {title:LANG.op_comp_l}),
dark: UC.newBoolean(LANG.op_dark_s, booleanSave, {title:LANG.op_dark_l}), dark: UC.newBoolean(LANG.op_dark_s, booleanSave, {title:LANG.op_dark_l}),
showOrigin: UC.newBoolean(LANG.op_show_s, booleanSave, {title:LANG.op_show_l}), showOrigin: UC.newBoolean(LANG.op_show_s, booleanSave, {title:LANG.op_show_l, modes:GCODE}),
alignTop: UC.newBoolean(LANG.op_alig_s, booleanSave, {title:LANG.op_alig_l, modes:CAM}), alignTop: UC.newBoolean(LANG.op_alig_s, booleanSave, {title:LANG.op_alig_l, modes:CAM}),
autoLayout: UC.newBoolean(LANG.op_auto_s, booleanSave, {title:LANG.op_auto_l}), autoLayout: UC.newBoolean(LANG.op_auto_s, booleanSave, {title:LANG.op_auto_l}),
freeLayout: UC.newBoolean(LANG.op_free_s, booleanSave, {title:LANG.op_free_l, modes:ALL, expert:true}), freeLayout: UC.newBoolean(LANG.op_free_s, booleanSave, {title:LANG.op_free_l, modes:ALL, expert:true}),

View file

@ -60,8 +60,7 @@ self.kiri.copyright = exports.COPYRIGHT;
topZ = 0, topZ = 0,
showFavorites = SDB.getItem('dev-favorites') === 'true', showFavorites = SDB.getItem('dev-favorites') === 'true',
alerts = [], alerts = [],
grouping = false, grouping = false;
skipSliceView = false;
if (SETUP.rm) renderMode = parseInt(SETUP.rm[0]); if (SETUP.rm) renderMode = parseInt(SETUP.rm[0]);
DBUG.enable(); DBUG.enable();
@ -165,8 +164,7 @@ self.kiri.copyright = exports.COPYRIGHT;
update: updateSettings, update: updateSettings,
restore: restoreSettings, restore: restoreSettings,
export: settingsExport, export: settingsExport,
import: settingsImport, import: settingsImport
isSliceSkipped: () => { return skipSliceView }
}, },
color, color,
const: { const: {
@ -648,8 +646,7 @@ self.kiri.copyright = exports.COPYRIGHT;
} }
function preparePrint(callback) { function preparePrint(callback) {
let tpFactor = skipSliceView ? 0.5 : 1, if (viewMode === VIEWS.PREVIEW) return;
tpBase = skipSliceView ? 0.5 : 0;
// kick off slicing it hasn't been done already // kick off slicing it hasn't been done already
for (let i=0; i < WIDGETS.length; i++) { for (let i=0; i < WIDGETS.length; i++) {
@ -674,23 +671,20 @@ self.kiri.copyright = exports.COPYRIGHT;
forAllWidgets(function(widget) { forAllWidgets(function(widget) {
widget.setColor(color.cam_preview); widget.setColor(color.cam_preview);
}); });
} else if (!skipSliceView) { } else {
setOpacity(color.preview_opacity); setOpacity(color.preview_opacity);
} }
currentPrint = kiri.newPrint(settings, WIDGETS); currentPrint = kiri.newPrint(settings, WIDGETS);
currentPrint.setup(true, function(update, status) { currentPrint.setup(true, function(update, status) {
setProgress(tpBase + update * tpFactor, status); setProgress(update, status);
}, function() { }, function() {
if (!currentPrint) { if (!currentPrint) {
return setViewMode(VIEWS.ARRANGE); return setViewMode(VIEWS.ARRANGE);
} }
setProgress(0); setProgress(0);
setOpacity(0);
if (skipSliceView) {
setOpacity(0);
}
currentPrint.render(); currentPrint.render();
@ -749,7 +743,6 @@ self.kiri.copyright = exports.COPYRIGHT;
countdown = WIDGETS.length, countdown = WIDGETS.length,
preserveMax = API.var.layer_max, preserveMax = API.var.layer_max,
preserveLayer = API.var.layer_at, preserveLayer = API.var.layer_at,
tpFactor = skipSliceView ? 0.5 : 1,
totalProgress, totalProgress,
track = {}; track = {};
@ -770,14 +763,12 @@ self.kiri.copyright = exports.COPYRIGHT;
widget.setColor(color.slicing); widget.setColor(color.slicing);
widget.slice(settings, function(sliced, error) { widget.slice(settings, function(sliced, error) {
let mark = UTIL.time(); let mark = UTIL.time();
if (!skipSliceView) { // on done
// on done widget.render(renderMode, MODE === MODES.CAM);
widget.render(renderMode, MODE === MODES.CAM); // clear wireframe
// clear wireframe widget.setWireframe(false, color.wireframe, color.wireframe_opacity);
widget.setWireframe(false, color.wireframe, color.wireframe_opacity); widget.setOpacity(settings.mode === 'CAM' ? color.cam_sliced_opacity : color.sliced_opacity);
widget.setOpacity(settings.mode === 'CAM' ? color.cam_sliced_opacity : color.sliced_opacity); widget.setColor(color.deselected);
widget.setColor(color.deselected);
}
// update UI info // update UI info
if (sliced) { if (sliced) {
// update segment time // update segment time
@ -792,19 +783,11 @@ self.kiri.copyright = exports.COPYRIGHT;
} }
// on the last exit, update ui and call the callback // on the last exit, update ui and call the callback
if (--countdown === 0 || error || errored) { if (--countdown === 0 || error || errored) {
if (skipSliceView) { setProgress(0);
if (!(error || errored)) { showSlices(preserveLayer);
preparePrint(callback); setOpacity(settings.mode === 'CAM' ? color.cam_sliced_opacity : color.sliced_opacity);
} else { if (callback && typeof callback === 'function') {
setProgress(0); callback();
}
} else {
setProgress(0);
showSlices(preserveLayer);
setOpacity(settings.mode === 'CAM' ? color.cam_sliced_opacity : color.sliced_opacity);
if (callback && typeof callback === 'function') {
callback();
}
} }
} }
// update slider window // update slider window
@ -831,7 +814,7 @@ self.kiri.copyright = exports.COPYRIGHT;
forAllWidgets(function(w) { forAllWidgets(function(w) {
totalProgress += (track[w.id] || 0); totalProgress += (track[w.id] || 0);
}); });
setProgress((totalProgress / WIDGETS.length) * tpFactor, msg); setProgress((totalProgress / WIDGETS.length), msg);
}, true); }, true);
}); });
} }
@ -942,7 +925,7 @@ self.kiri.copyright = exports.COPYRIGHT;
y = -camStock.position.y; y = -camStock.position.y;
} }
settings.origin = {x, y, z}; settings.origin = {x, y, z};
if (settings.controller.showOrigin) { if (settings.controller.showOrigin && MODE !== MODES.SLA) {
SPACE.platform.setOrigin(x,y,z); SPACE.platform.setOrigin(x,y,z);
} else { } else {
SPACE.platform.setOrigin(); SPACE.platform.setOrigin();
@ -970,7 +953,6 @@ self.kiri.copyright = exports.COPYRIGHT;
height = parseFloat(dev.bedHeight) height = parseFloat(dev.bedHeight)
); );
SPACE.platform.setGZOff(height/2 - 0.1); SPACE.platform.setGZOff(height/2 - 0.1);
// SPACE.platform.setHidden(width > 500 || depth > 500);
platform.update_origin(); platform.update_origin();
SPACE.scene.freeze(frozen); SPACE.scene.freeze(frozen);
} }
@ -1845,10 +1827,8 @@ self.kiri.copyright = exports.COPYRIGHT;
showModeActive(UI.modeSlice); showModeActive(UI.modeSlice);
break; break;
case VIEWS.PREVIEW: case VIEWS.PREVIEW:
// if (MODE !== MODES.SLA) { showLayerView(true);
showLayerView(true); showModeActive(UI.modePreview);
showModeActive(UI.modePreview);
// }
break; break;
default: default:
DBUG.log("invalid view mode: "+mode); DBUG.log("invalid view mode: "+mode);
@ -1873,7 +1853,6 @@ self.kiri.copyright = exports.COPYRIGHT;
function setExpert(bool) { function setExpert(bool) {
UC.setExpert(UI.expert.checked = control.expert = bool); UC.setExpert(UI.expert.checked = control.expert = bool);
updateSkipSliceView();
} }
function getMode() { function getMode() {
@ -1908,6 +1887,7 @@ self.kiri.copyright = exports.COPYRIGHT;
} }
MODE = MODES[mode]; MODE = MODES[mode];
// updates right-hand menu by enabling/disabling fields // updates right-hand menu by enabling/disabling fields
setViewMode(VIEWS.ARRANGE);
UC.setMode(MODE); UC.setMode(MODE);
API.conf.load(); API.conf.load();
API.conf.save(); API.conf.save();
@ -1919,6 +1899,7 @@ self.kiri.copyright = exports.COPYRIGHT;
UI.modeLASER.setAttribute('class', MODE === MODES.LASER ? 'buton' : ''); UI.modeLASER.setAttribute('class', MODE === MODES.LASER ? 'buton' : '');
UI.mode.style.display = lock ? 'none' : ''; UI.mode.style.display = lock ? 'none' : '';
UI.modeTable.style.display = lock ? 'none' : ''; UI.modeTable.style.display = lock ? 'none' : '';
UI.modelOpacity.style.display = MODE === MODES.SLA ? 'none' : '';
if (camStock) { if (camStock) {
camStock.material.visible = settings.mode === 'CAM'; camStock.material.visible = settings.mode === 'CAM';
} }
@ -1927,19 +1908,12 @@ self.kiri.copyright = exports.COPYRIGHT;
triggerSettingsEvent(); triggerSettingsEvent();
platformUpdateSelected(); platformUpdateSelected();
updateFields(); updateFields();
updateSkipSliceView();
if (settings.device.new) { if (settings.device.new) {
API.show.devices(); API.show.devices();
} }
API.event.emit("mode.set", mode); API.event.emit("mode.set", mode);
} }
function updateSkipSliceView() {
skipSliceView = MODE === MODES.SLA &&
(!LOCAL || settings.controller.expert !== LOCAL);
UI.modePreview.style.display = skipSliceView ? 'none' : '';
}
function currentDeviceName() { function currentDeviceName() {
return settings.filter[getMode()]; return settings.filter[getMode()];
} }

View file

@ -1,7 +1,7 @@
var exports = { var exports = {
COPYRIGHT:"Copyright (C) Stewart Allen <sa@grid.space> - All Rights Reserved", COPYRIGHT:"Copyright (C) Stewart Allen <sa@grid.space> - All Rights Reserved",
LICENSE:"See the license.md file included with the source distribution", LICENSE:"See the license.md file included with the source distribution",
VERSION:"1.9.4" VERSION:"1.9.5"
}; };
if (!module) var module = {}; if (!module) var module = {};
module.exports = exports; module.exports = exports;

View file

@ -633,7 +633,8 @@ var MOTO = window.moto = window.moto || {};
SCENE.remove(current); SCENE.remove(current);
SCENE.add(platform); SCENE.add(platform);
} },
world: WORLD
}, },
view: { view: {