restore sla slice, preview, export
This commit is contained in:
parent
1c5c8e9cb4
commit
feca4902d1
11 changed files with 77 additions and 541 deletions
|
|
@ -30,7 +30,7 @@
|
|||
case 'LASER': return callExport();
|
||||
case 'FDM': return callExport(options);
|
||||
case 'CAM': return callExport(options);
|
||||
case 'SLA': return exportSLA();
|
||||
case 'SLA': return callExportSLA(options);
|
||||
}
|
||||
} else {
|
||||
API.function.prepare(function() {
|
||||
|
|
@ -40,55 +40,25 @@
|
|||
}
|
||||
|
||||
function callExport(options) {
|
||||
if (isPrepared()) {
|
||||
const gcode = [];
|
||||
KIRI.client.export(API.conf.get(), (line) => {
|
||||
gcode.push(line);
|
||||
}, (output) => {
|
||||
exportGCodeDialog(gcode.join('\n'), output);
|
||||
});
|
||||
} else {
|
||||
API.function.prepare(function() { exportPrint(options) });
|
||||
}
|
||||
const gcode = [];
|
||||
KIRI.client.export(API.conf.get(), (line) => {
|
||||
gcode.push(line);
|
||||
}, (output) => {
|
||||
exportGCodeDialog(gcode.join('\n'), output);
|
||||
});
|
||||
}
|
||||
|
||||
function exportSLADialog(currentPrint) {
|
||||
if (isPrepared()) {
|
||||
if (currentPrint.exported) {
|
||||
KIRI.driver.SLA.printDownload(currentPrint);
|
||||
return;
|
||||
function callExportSLA(options) {
|
||||
const preview = [];
|
||||
KIRI.client.export(API.conf.get(), (line) => {
|
||||
API.show.progress(line.progress, "exporting");
|
||||
if (line.data) {
|
||||
preview.push(line.data);
|
||||
}
|
||||
let lines = [];
|
||||
let times = {};
|
||||
let mark = Date.now();
|
||||
let seq = 1;
|
||||
let segment;
|
||||
currentPrint.export(true, function(line) {
|
||||
if (line.message) {
|
||||
if (segment && segment !== line.message) {
|
||||
let now = Date.now();
|
||||
times[`${seq++}_${segment}`] = now - mark;
|
||||
mark = now;
|
||||
}
|
||||
segment = line.message;
|
||||
}
|
||||
if (line.progress) {
|
||||
API.show.progress(line.progress, "exporting");
|
||||
}
|
||||
if (line.data) {
|
||||
lines.push(line.data);
|
||||
}
|
||||
}, function(done) {
|
||||
currentPrint.exported = true;
|
||||
times[`${seq++}_${segment}`] = Date.now() - mark;
|
||||
console.log(times);
|
||||
API.show.progress(0);
|
||||
currentPrint.sla = { lines, done, API };
|
||||
KIRI.driver.SLA.printDownload(currentPrint);
|
||||
});
|
||||
} else {
|
||||
API.function.prepare(exportSLA);
|
||||
}
|
||||
}, (output) => {
|
||||
API.show.progress(0);
|
||||
KIRI.driver.SLA.printDownload(preview, output, API);
|
||||
});
|
||||
}
|
||||
|
||||
function exportLaserDialog(currentPrint) {
|
||||
|
|
@ -132,7 +102,7 @@
|
|||
});
|
||||
}
|
||||
|
||||
function exportGCodeDialog(gcode, currentPrint) {
|
||||
function exportGCodeDialog(gcode, info) {
|
||||
SDB['kiri-print-seq'] = printSeq++;
|
||||
|
||||
let settings = API.conf.get(),
|
||||
|
|
@ -395,8 +365,8 @@
|
|||
"filename=" + filename +
|
||||
"&target=" + target +
|
||||
"&key=" + apik +
|
||||
"&time=" + Math.round(currentPrint.time) +
|
||||
"&length=" + Math.round(currentPrint.distance) +
|
||||
"&time=" + Math.round(info.time) +
|
||||
"&length=" + Math.round(info.distance) +
|
||||
"&image=" + filename
|
||||
);
|
||||
xhtr.setRequestHeader("Content-Type", "text/plain");
|
||||
|
|
@ -420,9 +390,9 @@
|
|||
let density = $('print-density');
|
||||
$('print-weight').value = (
|
||||
(Math.PI * UTIL.sqr(
|
||||
currentPrint.settings.device.extruders[0].extFilament / 2
|
||||
info.settings.device.extruders[0].extFilament / 2
|
||||
)) *
|
||||
currentPrint.distance *
|
||||
info.distance *
|
||||
(parseFloat(density.value) || 1.25) /
|
||||
1000
|
||||
).toFixed(2);
|
||||
|
|
@ -434,7 +404,7 @@
|
|||
|
||||
function calcTime() {
|
||||
let floor = Math.floor,
|
||||
time = floor(currentPrint.time),
|
||||
time = floor(info.time),
|
||||
hours = floor(time / 3600),
|
||||
newtime = time - hours * 3600,
|
||||
mins = floor(newtime / 60),
|
||||
|
|
@ -454,8 +424,8 @@
|
|||
$('print-filament-head').style.display = fdm ? '' : 'none';
|
||||
$('print-filament-info').style.display = fdm ? '' : 'none';
|
||||
$('print-filename').value = filename;
|
||||
$('print-filesize').value = UTIL.comma(currentPrint.bytes);
|
||||
$('print-filament').value = Math.round(currentPrint.distance);
|
||||
$('print-filesize').value = UTIL.comma(info.bytes);
|
||||
$('print-filament').value = Math.round(info.distance);
|
||||
calcTime();
|
||||
if (fdm) {
|
||||
calcWeight();
|
||||
|
|
|
|||
|
|
@ -1,149 +0,0 @@
|
|||
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
||||
|
||||
"use strict";
|
||||
|
||||
(function() {
|
||||
|
||||
return; // todo remove
|
||||
if (self.kiri.Layer) return;
|
||||
|
||||
const KIRI = self.kiri,
|
||||
POLY = self.base.polygons,
|
||||
shininess = 15,
|
||||
specular = 0x444444,
|
||||
emissive = 0x101010,
|
||||
metalness = 0,
|
||||
roughness = 0.3,
|
||||
newMesh = createPhongMesh;
|
||||
|
||||
KIRI.Layer = Layer;
|
||||
KIRI.newLayer = function() { return new Layer() };
|
||||
|
||||
function Layer(view) { }
|
||||
|
||||
Layer.renderSetup = function() {
|
||||
const API = KIRI.api, UC = API.uc, UI = API.ui;
|
||||
const dyn = UI.dyn = {};
|
||||
const layers = $("layers");
|
||||
UC.setGroup(layers);
|
||||
layers.innerHTML = '';
|
||||
return Layer;
|
||||
};
|
||||
|
||||
Layer.renderSlices = function(slices) {
|
||||
if (slices && slices.length) {
|
||||
slices.forEach(slice => Layer.renderSlice(slice));
|
||||
}
|
||||
return Layer;
|
||||
};
|
||||
|
||||
Layer.renderSlice = function(slice) {
|
||||
let group = new THREE.Group();
|
||||
let render = slice.render;
|
||||
let view = slice.view;
|
||||
|
||||
if (!render) return;
|
||||
|
||||
function addPoly(vertices, poly) {
|
||||
const points = poly.points, len = points.length;
|
||||
for (let i=1; i<len; i++) {
|
||||
const p1 = points[i-1], p2 = points[i];
|
||||
vertices.push(new THREE.Vector3(p1.x, p1.y, p1.z));
|
||||
vertices.push(new THREE.Vector3(p2.x, p2.y, p2.z));
|
||||
}
|
||||
if (!poly.open) {
|
||||
const p1 = points[len - 1], p2 = points[0];
|
||||
vertices.push(new THREE.Vector3(p1.x, p1.y, p1.z));
|
||||
vertices.push(new THREE.Vector3(p2.x, p2.y, p2.z));
|
||||
}
|
||||
}
|
||||
|
||||
const API = KIRI.api, UC = API.uc, UI = API.ui, DYN = UI.dyn;;
|
||||
|
||||
for (const [layer, data] of Object.entries(render.layers)) {
|
||||
if (!DYN[layer]) {
|
||||
DYN[layer] = {
|
||||
group: [],
|
||||
toggle: UC.newBoolean(layer, (abc) => {
|
||||
ctrl.group.forEach(mat => {
|
||||
mat.visible = ctrl.toggle.checked;
|
||||
});
|
||||
})
|
||||
};
|
||||
}
|
||||
const ctrl = DYN[layer];
|
||||
ctrl.toggle.checked = true;
|
||||
|
||||
const { polys, lines, faces, paths } = data;
|
||||
if (polys.length || lines.length) {
|
||||
const mat = new THREE.LineBasicMaterial({ color: data.color.line });
|
||||
const geo = new THREE.Geometry(), vert = geo.vertices;
|
||||
for (let i=0, il=polys.length; i<il; i++) {
|
||||
addPoly(vert, polys[i]);
|
||||
}
|
||||
for (let i=0, il=lines.length; i<il; i++) {
|
||||
const p = lines[i];
|
||||
vert.push(new THREE.Vector3(p.x, p.y, p.z));
|
||||
}
|
||||
if (vert.length) {
|
||||
group.add(new THREE.LineSegments(geo, mat));
|
||||
}
|
||||
ctrl.group.push(mat);
|
||||
}
|
||||
if (faces.length) {
|
||||
const mat = newMesh(data);
|
||||
const geo = new THREE.BufferGeometry();
|
||||
geo.setAttribute('position', new THREE.BufferAttribute(faces, 3));
|
||||
geo.computeFaceNormals();
|
||||
geo.computeVertexNormals();
|
||||
const mesh = new THREE.Mesh(geo, mat);
|
||||
mesh.castShadow = true;
|
||||
mesh.receiveShadow = true;
|
||||
group.add(mesh);
|
||||
ctrl.group.push(mat);
|
||||
}
|
||||
if (paths.length) {
|
||||
const mat = newMesh(data);
|
||||
paths.forEach((path, i) => {
|
||||
const { index, faces, z } = path;
|
||||
const geo = new THREE.BufferGeometry();
|
||||
geo.setAttribute('position', new THREE.BufferAttribute(faces, 3));
|
||||
geo.setIndex(index);
|
||||
geo.computeFaceNormals();
|
||||
geo.computeVertexNormals();
|
||||
const mesh = new THREE.Mesh(geo, mat);
|
||||
mesh.position.z = z;
|
||||
mesh.castShadow = true;
|
||||
mesh.receiveShadow = true;
|
||||
group.add(mesh);
|
||||
});
|
||||
ctrl.group.push(mat);
|
||||
}
|
||||
}
|
||||
|
||||
slice.view.add(group);
|
||||
};
|
||||
|
||||
function createStandardMesh(data) {
|
||||
return new THREE.MeshStandardMaterial({
|
||||
emissive,
|
||||
roughness,
|
||||
metalness,
|
||||
transparent: data.color.opacity != 1,
|
||||
opacity: data.color.opacity,
|
||||
color: data.color.face,
|
||||
side: THREE.DoubleSide
|
||||
});
|
||||
}
|
||||
|
||||
function createPhongMesh(data) {
|
||||
return new THREE.MeshPhongMaterial({
|
||||
shininess,
|
||||
specular,
|
||||
transparent: data.color.opacity != 1,
|
||||
opacity: data.color.opacity,
|
||||
color: data.color.face,
|
||||
side: THREE.DoubleSide
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
|
@ -138,14 +138,18 @@ KIRI.worker = {
|
|||
return send.done()
|
||||
}
|
||||
|
||||
const output = driver.export(current.print, function(line) {
|
||||
send.data({line});
|
||||
let output;
|
||||
driver.export(current.print, function(line, direct) {
|
||||
send.data({line}, direct);
|
||||
}, function(done) {
|
||||
// SLA workaround
|
||||
output = done;
|
||||
});
|
||||
const { bounds, time, lines, bytes, distance } = current.print;
|
||||
const { bounds, time, lines, bytes, distance, settings } = current.print;
|
||||
|
||||
send.done({
|
||||
done: true,
|
||||
output: { bounds, time, lines, bytes, distance }
|
||||
output: output ? output : { bounds, time, lines, bytes, distance, settings }
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue