get sla working

This commit is contained in:
Stewart Allen 2025-07-05 18:52:53 -04:00
commit 01b81a101d
11 changed files with 142 additions and 157 deletions

View file

@ -1,11 +1,14 @@
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
export const client = {
import { $ } from '../../moto/webui.js';
import { api } from '../../kiri/api.js';
export const SLA = {
init,
printDownload
};
}
function init(kiri, api) {
export function init() {
api.event.on("mode.set", (mode) => {
if (mode === 'SLA') {
api.ui.func.preview.classList.add('hide');
@ -15,71 +18,66 @@ function init(kiri, api) {
});
}
function printDownload(output, api, names) {
export function printDownload(output, api, names) {
const { file, width, height, layers, volume } = output;
const fileroot = names[0] || "print";
const filename = `${fileroot}-${new Date().getTime().toString(36)}`;
api.modal.show('xsla');
// api.ajax("/kiri/output-sla.html", html => {
// api.ui.print.innerHTML = html;
let settings = api.conf.get(),
process = settings.process,
device = settings.device,
print_sec = (process.slaBaseLayers * process.slaBaseOn) +
(layers - process.slaBaseLayers) * process.slaLayerOn;
let settings = api.conf.get(),
process = settings.process,
device = settings.device,
print_sec = (process.slaBaseLayers * process.slaBaseOn) +
(layers - process.slaBaseLayers) * process.slaLayerOn;
// add peel lift/drop times to total print time
for (let i=0; i<layers; i++) {
let dist = process.slaPeelDist,
lift = process.slaPeelLiftRate,
drop = process.slaPeelDropRate,
off = process.slaLayerOff;
if (i < process.slaBaseLayers) {
dist = process.slaBasePeelDist;
lift = process.slaBasePeelLiftRate;
off = process.slaBaseOff;
}
print_sec += (dist * lift) / 60;
print_sec += (dist * drop) / 60;
print_sec += off;
// add peel lift/drop times to total print time
for (let i = 0; i < layers; i++) {
let dist = process.slaPeelDist,
lift = process.slaPeelLiftRate,
drop = process.slaPeelDropRate,
off = process.slaLayerOff;
if (i < process.slaBaseLayers) {
dist = process.slaBasePeelDist;
lift = process.slaBasePeelLiftRate;
off = process.slaBaseOff;
}
print_sec += (dist * lift) / 60;
print_sec += (dist * drop) / 60;
print_sec += off;
}
let print_min = Math.floor(print_sec/60),
print_hrs = Math.floor(print_min/60),
download = $('print-sla');
let print_min = Math.floor(print_sec / 60),
print_hrs = Math.floor(print_min / 60),
download = $('print-sla');
// add lift/drop time
print_sec -= (print_min * 60);
print_min -= (print_hrs * 60);
print_sec = Math.round(print_sec).toString().padStart(2,'0');
print_min = print_min.toString().padStart(2,'0');
print_hrs = print_hrs.toString().padStart(2,'0');
// add lift/drop time
print_sec -= (print_min * 60);
print_min -= (print_hrs * 60);
print_sec = Math.round(print_sec).toString().padStart(2, '0');
print_min = print_min.toString().padStart(2, '0');
print_hrs = print_hrs.toString().padStart(2, '0');
$('print-filename-sla').value = filename;
$('print-volume').value = (volume/1000).round(2);
$('print-layers').value = layers;
$('print-time').value = `${print_hrs}:${print_min}:${print_sec}`;
$('print-filename-sla').value = filename;
$('print-volume').value = (volume / 1000).round(2);
$('print-layers').value = layers;
$('print-time').value = `${print_hrs}:${print_min}:${print_sec}`;
switch (device.deviceName) {
case 'Anycubic.Photon':
download.innerText += " .photon";
download.onclick = () => { saveFile(api, file, ".photon") };
break;
case 'Anycubic.Photon.S':
download.innerText += " .photons";
download.onclick = () => { saveFile(api, file, ".photons") };
break;
case 'Creality.Halot.Sky':
default:
download.innerText += " .cxdlp";
download.onclick = () => { saveFile(api, file, ".cxdlp") };
break;
}
// api.modal.show('print');
// });
switch (device.deviceName) {
case 'Anycubic.Photon':
download.innerText += " .photon";
download.onclick = () => { saveFile(api, file, ".photon") };
break;
case 'Anycubic.Photon.S':
download.innerText += " .photons";
download.onclick = () => { saveFile(api, file, ".photons") };
break;
case 'Creality.Halot.Sky':
default:
download.innerText += " .cxdlp";
download.onclick = () => { saveFile(api, file, ".cxdlp") };
break;
}
}
function saveFile(api, file, ext) {

View file

@ -1,21 +1,30 @@
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
import { newPrint } from '../../kiri/print.js';
import { sla_slice } from './slice.js';
import { sla_export } from './export.js';
export const driver = {
prepare,
legacy: false
export const SLA = {
init,
legacy: false,
slice: sla_slice,
prepare: sla_prepare,
export: sla_export,
};
if (driver.legacy) {
if (SLA.legacy) {
console.log("SLA Driver in Legacy Mode");
}
function init(worker) {
// console.log({ INIT_SLA: worker });
}
// runs in worker. would usually be in src/mode/sla/prepare.js
// but the SLA driver skips the prepare step because there is no path routing
async function prepare(widgets, settings, update) {
self.worker.print = newPrint(settings, widgets);
if (!driver.wasm) {
async function sla_prepare(widgets, settings, update) {
self.kiri_worker.current.print = newPrint(settings, widgets);
if (!SLA.wasm) {
fetch('/wasm/kiri-sla.wasm')
.then(response => response.arrayBuffer())
.then(bytes => WebAssembly.instantiate(bytes, {
@ -28,7 +37,7 @@ async function prepare(widgets, settings, update) {
let {module, instance} = results;
let {exports} = instance;
let heap = new Uint8Array(exports.memory.buffer);
driver.wasm = {
SLA.wasm = {
heap,
memory: exports.memory,
render: exports.render,
@ -38,5 +47,3 @@ async function prepare(widgets, settings, update) {
}
update(1);
}
export { prepare };

View file

@ -1,14 +1,8 @@
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
import { base } from '../geo/base.js';
import { driver } from '../kiri-mode/sla/driver.js';
import { x_cxdlp } from '../kiri-mode/sla/x_cxdlp.js';
import { x_photon } from '../kiri-mode/sla/x_photon.js';
const { base, kiri } = root
const { driver } = kiri;
const { util } = base;
const { SLA } = driver;
import { CXDLP } from './x_cxdlp.js';
import { photon } from './x_photon.js';
import { SLA } from './driver.js';
/**
* DRIVER CONTRACT - runs in worker
@ -16,7 +10,7 @@ const { SLA } = driver;
* @param {Function} online streaming reply
* @param {Function} ondone last reply
*/
SLA.export = function(print, online, ondone) {
export function sla_export(print, online, ondone) {
let widgets = print.widgets,
settings = print.settings,
device = settings.device,
@ -164,9 +158,6 @@ SLA.export = function(print, online, ondone) {
console.log('print.export', Date.now() - mark);
};
function generateCXDLP(print, conf, progress) {
export function generateCXDLP(print, conf, progress) {
console.log({generateCXDLP: print, conf, progress});
}
export { generateCXDLP, widgets, isPhoton, legacyMode, d, masks, i, render, index, param, exp_func, file, part1, part2, slices, thumb, tdata, x, y, p, r, g, b, v, preview1, pdata, preview2 };

View file

@ -1,20 +1,14 @@
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
import { base } from '../geo/base.js';
import { point } from '../geo/point.js';
import { polygon } from '../geo/polygon.js';
import { polygons } from '../geo/polygons.js';
import { slice } from '../kiri/slice.js';
import { driver } from '../kiri-mode/sla/driver.js';
import { pngjs } from '../ext/pngjs.js';
import { util } from '../../geo/base.js';
import { slicer } from '../../geo/slicer.js';
import { newPolygon } from '../../geo/polygon.js';
import { polygons as POLY } from '../../geo/polygons.js';
import { newSlice, newTop } from '../../kiri/slice.js';
import { doShells, doDiff, projectFlats, projectBridges } from '../fdm/slice.js';
import { PNG } from '../../ext/pngjs.esm.js';
import { SLA } from './driver.js';
const { base, kiri } = root;
const { driver, newSlice, newTop } = kiri;
const { util, newPoint, newPolygon, polygons } = base;
const { SLA } = driver;
const POLY = polygons;
const FDM = driver.FDM.share;
const tracker = util.pwait;
let fill_cache;
@ -26,9 +20,10 @@ let fill_cache;
* @param {Function} onupdate (called with % complete and optional message)
* @param {Function} ondone (called when complete with an array of Slice objects)
*/
SLA.slice = function(settings, widget, onupdate, ondone) {
let { process, device, controller } = settings,
isConcurrent = controller.threaded && kiri.minions.concurrent,
export function sla_slice(settings, widget, onupdate, ondone) {
let { minions } = self.kiri_worker,
{ process, device, controller } = settings,
isConcurrent = controller.threaded && minions.concurrent,
work_total,
work_remain;
@ -66,10 +61,10 @@ SLA.slice = function(settings, widget, onupdate, ondone) {
break;
}
let sws = self.worker.snap.url;
let sws = self.kiri_worker.current.snap.url;
let b64 = atob(sws.substring(sws.indexOf(',') + 1));
let bin = Uint8Array.from(b64, c => c.charCodeAt(0));
let img = new png.PNG();
let img = new PNG();
img.parse(bin, (err, data) => {
SLA.preview = img;
SLA.previewSmall = samplePNG(img, smallDims.x, smallDims.y);
@ -154,14 +149,14 @@ SLA.slice = function(settings, widget, onupdate, ondone) {
work_remain = work_total;
forSlices(slices, 5, (slice,index) => {
if (process.slaShell) {
FDM.doShells(slice, 2, 0, process.slaShell);
doShells(slice, 2, 0, process.slaShell);
} else {
FDM.doShells(slice, 1, 0);
doShells(slice, 1, 0);
}
}, "shells");
forSlices(slices, 10, (slice) => {
if (slice.synth) return;
FDM.doDiff(slice, 0.000001, {
doDiff(slice, 0.000001, {
sla: true,
fakedown: !process.slaOpenBase
});
@ -169,8 +164,8 @@ SLA.slice = function(settings, widget, onupdate, ondone) {
if (solidLayers) {
forSlices(slices, 10, (slice) => {
if (slice.synth) return;
FDM.projectFlats(slice, solidLayers);
FDM.projectBridges(slice, solidLayers);
projectFlats(slice, solidLayers);
projectBridges(slice, solidLayers);
}, "project");
async function doUnionSolid(slice) {
if (slice.synth) return;
@ -179,7 +174,7 @@ SLA.slice = function(settings, widget, onupdate, ondone) {
let trims = slice.solids || [];
traces.appendAll(trims);
// slice.unioned = POLY.setZ(POLY.union(traces, undefined, true), slice.z);
slice.unioned = POLY.setZ(await kiri.minions.union(traces), slice.z);
slice.unioned = POLY.setZ(await minions.union(traces), slice.z);
} else {
slice.unioned = traces;
}
@ -212,7 +207,7 @@ SLA.slice = function(settings, widget, onupdate, ondone) {
let bounds = widget.getBoundingBox();
let points = widget.getPoints();
base.slice(points, {
slicer.slice(points, {
indices: process.indices || process.xray,
union: controller.healMesh,
debug: process.xray,
@ -222,7 +217,7 @@ SLA.slice = function(settings, widget, onupdate, ondone) {
zInc: height,
// slicer function (worker local or minion distributed)
slicer(z, points, opts) {
return (isConcurrent ? kiri.minions.sliceZ : base.sliceZ)(z, points, opts);
return (isConcurrent ? minions.sliceZ : slicer.sliceZ)(z, points, opts);
},
onupdate(v) {
return onupdate(0.0 + v * 0.25);
@ -603,7 +598,7 @@ function fillPolys(slice, settings) {
if (!cached && seq_c !== 1)
for (let x=start_x; x<end_x; x += step_x) {
fill.push(
base.newPolygon().centerRectangle({
newPolygon().centerRectangle({
x: x + step_x/2,
y: 0,
z: slice.z
@ -614,7 +609,7 @@ function fillPolys(slice, settings) {
if (!cached && seq_c !== 3)
for (let y=start_y; y<end_y; y += step_y) {
fill.push(
base.newPolygon().centerRectangle({
newPolygon().centerRectangle({
x: 0,
y: y + step_y/2,
z: slice.z
@ -699,6 +694,3 @@ function samplePNG(png, width, height) {
return {width, height, data:buf, png};
}
export { doupdate, forSlices, onSliceDone, doUnionSolid, doRender, computeSupports, projectSupport, projectPillar, fillPolys, pixAt, averageBlock, samplePNG, POLY, FDM, tracker, smallDims, largeDims, sws, b64, bin, img, height, cap, layers, outer, union, expand, s, slice, i, solidLayers, traces, trims, promises, bounds, points, slices, tops, render, poly, area, ops, mass_per_bear, rem_mass, ord, j, seq, flat, out, rec, num, track, sp, rp, isin, nusize, prec, nextpoint, x, close, p, d, newp, process, seq_i, y, idx, dat, th };

View file

@ -34,7 +34,7 @@ const data_term = 0x0d0a;
// CL-89 3840 x 2400
// CL-133 3840 x 2160
class CXDLP {
export class CXDLP {
constructor() {
Object.assign(this, default_values);
}
@ -447,6 +447,3 @@ if (!self.navigator && self.process && self.process.env) {
} else if (self.navigator) {
self.CXDLP = CXDLP;
}
export { read_string, write_string, scaleMovePoly, writePoly, default_values, data_term, read, len, str, meta, layers, i, size, lines, cksum, out, rec, j, d1, d2, d3, y_start, y_end, x_end, color, output, pos, start, b1, b2, b3, b4, b5, ckpos, array, cxdlp, width2, count, area, points, p, inner, bounds, point, slice, polys, wasm, imagelen, writer, poly, image, x, lastv, y, v, fs, args, file, fpos, view };

View file

@ -1,9 +1,6 @@
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
const { base, kiri } = root;
const { driver } = kiri;
const { util } = base;
const { SLA } = driver;
import { SLA } from './driver.js';
function generatePhoton(print, conf, progress) {
let printset = print.settings,
@ -529,12 +526,9 @@ function polyout(poly, ctx, opt) {
ctx.closePath();
}
self.photon = {
export const photon = {
generatePhoton,
generatePhotons,
renderLayer,
renderLayerWasm
};
export { generatePhoton, generatePhotons, encodeLayers, rleEncode, rleByte, rleDecode, writePhotonImage, renderLayerWasm, scaleMovePoly, writePoly, renderLayer, polyout, printset, d, i, ccl, tcl, converted, count, lineDV, bits, bitsDV, subs, sl, s, view, mask, dv, codedlen, codelen, buflen, filebuf, filedat, printtime, hirez, layerpos, lorez, proppos, proplen, propstart, layers, layerat, sc, l, layer, clo, tlo, j, filePos, index, subindex, data, encoded, maxlen, newColor, bytes, hpos, pos, r, heap, width2, array, area, points, p, inner, bounds, point, slice, polys, wasm, imagelen, writer, poly, image, rlelen, opt, ctx, red };