reduce memory footprint of sla mode
This commit is contained in:
parent
1c84425132
commit
1589a63ec0
4 changed files with 37 additions and 21 deletions
|
|
@ -203,6 +203,8 @@ let gs_kiri_sla = exports;
|
||||||
scaleX = width / device.bedWidth,
|
scaleX = width / device.bedWidth,
|
||||||
scaleY = height / device.bedDepth;
|
scaleY = height / device.bedDepth;
|
||||||
|
|
||||||
|
let mark = Date.now();
|
||||||
|
|
||||||
widgets.forEach(widget => {
|
widgets.forEach(widget => {
|
||||||
layermax = Math.max(widget.slices.length);
|
layermax = Math.max(widget.slices.length);
|
||||||
});
|
});
|
||||||
|
|
@ -243,12 +245,19 @@ let gs_kiri_sla = exports;
|
||||||
console.log({no_slice_at: index})
|
console.log({no_slice_at: index})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
output.push(ctx.getImageData(0,0,height,width));
|
let data = ctx.getImageData(0,0,height,width).data;
|
||||||
|
let red = new Uint8ClampedArray(data.length / 4);
|
||||||
|
for (let i=0; i<red.length; i++) {
|
||||||
|
red[i] = data[i*4];
|
||||||
|
}
|
||||||
|
output.push(red);
|
||||||
update(index / layermax);
|
update(index / layermax);
|
||||||
if (count === 0) break;
|
if (count === 0) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
update(1);
|
update(1);
|
||||||
|
|
||||||
|
console.log('print.setup', Date.now() - mark);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -262,13 +271,14 @@ 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.output,
|
||||||
|
mark = Date.now();
|
||||||
|
|
||||||
print.images.forEach((image,index) => {
|
print.images.forEach((image,index) => {
|
||||||
online({
|
online({
|
||||||
progress: (index / print.images.length) * 0.25,
|
progress: (index / print.images.length) * 0.25,
|
||||||
message: "image_xfer",
|
message: "image_xfer",
|
||||||
data: image.data
|
data: image
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -286,7 +296,7 @@ let gs_kiri_sla = exports;
|
||||||
let file = exp_func(print, {
|
let file = exp_func(print, {
|
||||||
width: 2560,
|
width: 2560,
|
||||||
height: 1440,
|
height: 1440,
|
||||||
lines: print.images.map(i => i.data),
|
lines: print.images,
|
||||||
small: previewSmall.data,
|
small: previewSmall.data,
|
||||||
large: previewLarge.data
|
large: previewLarge.data
|
||||||
}, (progress, message) => {
|
}, (progress, message) => {
|
||||||
|
|
@ -301,6 +311,7 @@ let gs_kiri_sla = exports;
|
||||||
|
|
||||||
// release memory
|
// release memory
|
||||||
print.images = null;
|
print.images = null;
|
||||||
|
console.log('print.export', Date.now() - mark);
|
||||||
};
|
};
|
||||||
|
|
||||||
// runs in browser main
|
// runs in browser main
|
||||||
|
|
@ -383,15 +394,14 @@ let gs_kiri_sla = exports;
|
||||||
let ctx = canvas.getContext('2d');
|
let ctx = canvas.getContext('2d');
|
||||||
let img = ctx.createImageData(done.height, done.width);
|
let img = ctx.createImageData(done.height, done.width);
|
||||||
let imgDV = new DataView(img.data.buffer);
|
let imgDV = new DataView(img.data.buffer);
|
||||||
|
|
||||||
let range = $('print-range');
|
let range = $('print-range');
|
||||||
range.value = 0;
|
range.value = 0;
|
||||||
range.min = 0;
|
range.min = 0;
|
||||||
range.max = lines.length - 1;
|
range.max = lines.length - 1;
|
||||||
range.oninput = function() {
|
range.oninput = function() {
|
||||||
let lineDV = new DataView(lines[range.value].buffer);
|
let lineDV = new DataView(lines[range.value].buffer);
|
||||||
for (let i=0; i<lineDV.byteLength; i+=4) {
|
for (let i=0; i<lineDV.byteLength; i++) {
|
||||||
imgDV.setUint32(i, lineDV.getUint32(i));
|
imgDV.setUint32(i*4, lineDV.getUint8(i));
|
||||||
}
|
}
|
||||||
ctx.putImageData(img,0,0);
|
ctx.putImageData(img,0,0);
|
||||||
$('print-layer').innerText = range.value.padStart(4,'0');
|
$('print-layer').innerText = range.value.padStart(4,'0');
|
||||||
|
|
@ -426,17 +436,12 @@ let gs_kiri_sla = exports;
|
||||||
for (let i=0; i<subcount; i++) {
|
for (let i=0; i<subcount; i++) {
|
||||||
masks.push((1 << (8 - i * d)) - 1);
|
masks.push((1 << (8 - i * d)) - 1);
|
||||||
}
|
}
|
||||||
// let d = 8 / subcount;
|
|
||||||
// let m = (1 << d) - 1;
|
|
||||||
// for (let i=0; i<subcount; i++) {
|
|
||||||
// masks.push(m << (i * d));
|
|
||||||
// }
|
|
||||||
let ccl = 0;
|
let ccl = 0;
|
||||||
let tcl = conf.lines.length * subcount;
|
let tcl = conf.lines.length * subcount;
|
||||||
let converted = conf.lines.map((line, index) => {
|
let converted = conf.lines.map((line, index) => {
|
||||||
let count = line.length / 4;
|
let count = line.length;
|
||||||
let lineDV = new DataView(line.buffer);
|
let lineDV = new DataView(line.buffer);
|
||||||
let bits = new Uint8Array(line.length / 4), bits2;
|
let bits = new Uint8Array(line.length), bits2;
|
||||||
let bitsDV = new DataView(bits.buffer), bitsDV2;
|
let bitsDV = new DataView(bits.buffer), bitsDV2;
|
||||||
let subs = [{ data: bits, view: bitsDV }];
|
let subs = [{ data: bits, view: bitsDV }];
|
||||||
for (let sl=1; sl<subcount; sl++) {
|
for (let sl=1; sl<subcount; sl++) {
|
||||||
|
|
@ -449,10 +454,10 @@ let gs_kiri_sla = exports;
|
||||||
let view = subs[s].view;
|
let view = subs[s].view;
|
||||||
let mask = masks[s];
|
let mask = masks[s];
|
||||||
for (let i = 0; i < count; i++) {
|
for (let i = 0; i < count; i++) {
|
||||||
let dv = lineDV.getUint8(i * 4);
|
let dv = lineDV.getUint8(i);
|
||||||
view.setUint8(i, (dv / subcount) & mask ? 1 : 0);
|
view.setUint8(i, (dv / subcount) & mask ? 1 : 0);
|
||||||
}
|
}
|
||||||
progress((ccl++/tcl) * 0.4, "layer_convert");
|
progress((ccl++/tcl) * 0.4, `layer_convert`);
|
||||||
}
|
}
|
||||||
return { subs };
|
return { subs };
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,14 @@ let gs_kiri_export = exports;
|
||||||
case 'SLA': return exportPrintSLA(currentPrint);
|
case 'SLA': return exportPrintSLA(currentPrint);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
API.function.print(exportPrint);
|
switch (API.mode.get()) {
|
||||||
|
case 'SLA':
|
||||||
|
API.function.slice(exportPrint);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
API.function.print(exportPrint);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,8 +78,6 @@ let dispatch = {
|
||||||
send.data({send_end: time()});
|
send.data({send_end: time()});
|
||||||
}
|
}
|
||||||
send.done({done: true});
|
send.done({done: true});
|
||||||
// cache results for future printing
|
|
||||||
// cache[data.id] = widget;
|
|
||||||
}, function(update, msg) {
|
}, function(update, msg) {
|
||||||
now = util.time();
|
now = util.time();
|
||||||
if (now - last < 10 && update < 0.99) return;
|
if (now - last < 10 && update < 0.99) return;
|
||||||
|
|
@ -140,6 +138,7 @@ let dispatch = {
|
||||||
},
|
},
|
||||||
|
|
||||||
clear: function(data, send) {
|
clear: function(data, send) {
|
||||||
|
currentSnap = null;
|
||||||
currentPrint = null;
|
currentPrint = null;
|
||||||
if (!data.id) {
|
if (!data.id) {
|
||||||
cache = {};
|
cache = {};
|
||||||
|
|
|
||||||
|
|
@ -679,9 +679,12 @@ self.kiri.copyright = exports.COPYRIGHT;
|
||||||
|
|
||||||
currentPrint = kiri.newPrint(settings, WIDGETS);
|
currentPrint = kiri.newPrint(settings, WIDGETS);
|
||||||
currentPrint.setup(true, function(update, status) {
|
currentPrint.setup(true, function(update, status) {
|
||||||
// on update
|
|
||||||
setProgress(tpBase + update * tpFactor, status);
|
setProgress(tpBase + update * tpFactor, status);
|
||||||
}, function() {
|
}, function() {
|
||||||
|
if (!currentPrint) {
|
||||||
|
return setViewMode(VIEWS.ARRANGE);
|
||||||
|
}
|
||||||
|
|
||||||
setProgress(0);
|
setProgress(0);
|
||||||
|
|
||||||
if (skipSliceView) {
|
if (skipSliceView) {
|
||||||
|
|
@ -788,12 +791,14 @@ 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) {
|
||||||
setProgress(0);
|
|
||||||
if (skipSliceView) {
|
if (skipSliceView) {
|
||||||
if (!(error || errored)) {
|
if (!(error || errored)) {
|
||||||
preparePrint(callback);
|
preparePrint(callback);
|
||||||
|
} else {
|
||||||
|
setProgress(0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
setProgress(0);
|
||||||
showSlices(preserveLayer);
|
showSlices(preserveLayer);
|
||||||
setOpacity(settings.mode === 'CAM' ? color.cam_sliced_opacity : color.sliced_opacity);
|
setOpacity(settings.mode === 'CAM' ? color.cam_sliced_opacity : color.sliced_opacity);
|
||||||
if (callback && typeof callback === 'function') {
|
if (callback && typeof callback === 'function') {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue