patch up laser mode

This commit is contained in:
Stewart Allen 2025-07-05 17:54:01 -04:00
commit c5d9442fe6
6 changed files with 57 additions and 45 deletions

View file

@ -78,6 +78,7 @@
},
"scripts": {
"setup": "npm i && cd mods && npm i",
"setup2": "npm run setup && npm run dev -- --dryrun && npm run preinstall2",
"dev": "gs-app-server --debug",
"prod": "gs-app-server",
"prod-dryrun": "gs-app-server --dryrun",

View file

@ -0,0 +1,5 @@
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
export function init() {
// TODO
}

View file

@ -1,11 +1,15 @@
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
import { api } from '../../kiri/api.js';
import { base } from '../../geo/base.js';
import { Packer } from '../../kiri/pack.js';
import { newBounds } from '../../geo/bounds.js';
import { newPoint } from '../../geo/point.js';
import { newPrint } from '../../kiri/print.js';
import { newSlopeFromAngle } from '../../geo/slope.js';
import { polygons as POLY } from '../../geo/polygons.js';
import { render } from '../../kiri/render.js';
import { Slice, newSlice } from '../../kiri/slice.js';
import { slicer } from '../../geo/slicer.js';
import { newSlice } from '../../kiri/slice.js';
const TYPE = {
LASER: 0,
@ -14,23 +18,8 @@ const TYPE = {
WEDM: 3
};
export const driver = {
TYPE,
type: TYPE.LASER,
name: 'Laser',
init,
slice,
prepare,
export: exportLaser,
exportGCode,
exportSVG,
exportDXF,
};
function init() {
api.event.on("settings.saved", settings => {
// TODO
});
function init(worker) {
// console.log({ LASER_INIT: worker });
}
function polyLabel(poly, label) {
@ -121,7 +110,7 @@ function arc(center, rad, s1, s2, out) {
out.push( center.projectOnSlope(s1, rad) );
}
while (ticks-- > 0) {
out.push( center.projectOnSlope(base.newSlopeFromAngle(a1 + off), rad) );
out.push( center.projectOnSlope(newSlopeFromAngle(a1 + off), rad) );
a1 += step * dir;
}
out.push( center.projectOnSlope(s2, rad) );
@ -179,7 +168,7 @@ function addKnifeRadii(poly, tipoff) {
* @param {Function} onupdate (called with % complete and optional message)
* @param {Function} ondone (called when complete with an array of Slice objects)
*/
function slice(settings, widget, onupdate, ondone) {
function laser_slice(settings, widget, onupdate, ondone) {
let proc = settings.process;
let offset = proc.ctSliceKerf || 0;
let color = settings.controller.dark ? 0xbbbbbb : 0;
@ -193,7 +182,7 @@ function slice(settings, widget, onupdate, ondone) {
let points = widget.getPoints();
let indices = [];
base.slice(points, {
slicer.slice(points, {
zMin: bounds.min.z,
zMax: bounds.max.z,
zGen(zopt) {
@ -255,13 +244,14 @@ function slice(settings, widget, onupdate, ondone) {
* @param {Object} print state object
* @param {Function} update incremental callback
*/
async function prepare(widgets, settings, update) {
let device = settings.device,
async function laser_prepare(widgets, settings, update) {
let worker = self.kiri_worker.current,
device = settings.device,
process = settings.process,
print = self.worker.print = newPrint(settings, widgets),
isWire = self.worker.mode === 'WEDM',
isKnife = self.worker.mode === 'DRAG',
isLaser = self.worker.mode === 'LASER',
print = worker.print = newPrint(settings, widgets),
isWire = worker.mode === 'WEDM',
isKnife = worker.mode === 'DRAG',
isLaser = worker.mode === 'LASER',
output = print.output = [],
totalSlices = 0,
slices = 0,
@ -384,7 +374,7 @@ async function prepare(widgets, settings, update) {
// compute tile bounds
for (let tile of tiles) {
let bounds = base.newBounds();
let bounds = newBounds();
tile.forEach(rec => bounds.merge(rec.poly.bounds));
tile.w = bounds.width();
tile.h = bounds.height();
@ -407,7 +397,7 @@ async function prepare(widgets, settings, update) {
y: fit.y - (tp.max.h / 2) - bounds.miny,
z: 0}, true);
}
tile.bounds = base.newBounds();
tile.bounds = newBounds();
for (let { poly } of tile) {
tile.bounds.merge(poly.bounds);
}
@ -468,7 +458,7 @@ async function prepare(widgets, settings, update) {
}, { thin: true, z: ctOutStack ? undefined : 0, action: "cut", moves: process.isKnife });
};
function exportLaser(print, online, ondone) {
function laser_export(print, online, ondone) {
ondone(print.output);
}
@ -505,7 +495,7 @@ function exportElements(settings, output, onpre, onpoly, onpost, onpoint, onlaye
size.w = max.x - min.x;
size.h = max.y - min.y;
let bounds = base.newBounds();
let bounds = newBounds();
if (ctOriginCenter) {
// place origin at geometric center of all points
// regardless of workspace size
@ -855,3 +845,16 @@ function exportDXF(settings, data) {
return lines.join('\n');
};
export const LASER = {
TYPE,
type: TYPE.LASER,
name: 'Laser',
init,
slice: laser_slice,
prepare: laser_prepare,
export: laser_export,
exportGCode,
exportDXF,
exportSVG
};

View file

@ -9,7 +9,7 @@ import { broker } from '../moto/broker.js';
import { codec } from '../kiri/codec.js';
import { util } from '../geo/base.js';
import { newPoint } from '../geo/point.js';
import { polygons } from '../geo/polygons.js';
import { polygons as POLY } from '../geo/polygons.js';
import { newPrint } from '../kiri/print.js';
import { render } from '../kiri/render.js';
import { wasm_ctrl } from '../geo/wasm.js';
@ -18,15 +18,15 @@ import { Widget, newWidget } from '../kiri/widget.js';
import { CAM } from '../kiri-mode/cam/driver-be.js';
import { FDM } from '../kiri-mode/fdm/driver-be.js';
import { LASER } from '../kiri-mode/laser/driver.js';
// const CAM = {};
const { time } = util;
const POLY = polygons;
let debug = (self.debug === true),
drivers = {
CAM,
FDM
FDM,
LASER
},
ccvalue = self.navigator ? self.navigator.hardwareConcurrency || 0 : 0,
concurrent = Math.min(4, self.Worker && ccvalue > 3 ? ccvalue - 1 : 0),
@ -495,17 +495,17 @@ const dispatch = {
send.data({debug});
});
//export in different modes, based on device type
if(mode.toUpperCase() === "LASER"){
// export in different modes, based on device type
if (mode.toUpperCase() === "LASER") {
let FExt = data.settings.device.gcodeFExt.toUpperCase();
if(FExt === "DXF"){
if (FExt === "DXF"){
let dxf = driver.exportDXF(data.settings, current.print.output);
send.data({line:dxf});
}else if(FExt === "SVG"){
} else if(FExt === "SVG") {
let svg = driver.exportSVG(data.settings, current.print.output);
send.data({line:svg});
}else{
//if not svg or dxf, default to gcode
} else {
// if not svg or dxf, default to gcode
let gcode = driver.exportGCode(data.settings, current.print.output);
send.data({line:gcode});
}
@ -756,5 +756,6 @@ const worker = self.kiri_worker = {
// initilize driver mode handlers
CAM.init(worker);
FDM.init(worker);
LASER.init(worker);
broker.publish("worker.started", { dispatch, minions: minwork });

View file

@ -6,7 +6,7 @@ import { client } from './client.js';
import { local } from '../data/local.js';
import { util } from '../geo/base.js';
import { MODES } from './consts.js';
import { driver as laser_driver } from '../kiri-mode/laser/driver.js';
import { LASER as laser_driver } from '../kiri-mode/laser/driver.js';
import { client as sla_client } from '../kiri-mode/sla/client.js';
let printSeq = parseInt(local['kiri-print-seq'] || local['print-seq'] || "0") + 1;

View file

@ -7,10 +7,11 @@ import { local as sdb } from '../data/local.js';
import { space } from '../moto/space.js';
import { LOCAL, SETUP } from './main.js';
import { VIEWS, MODES, SEED } from '../kiri/consts.js';
import { init as initCAM } from '../kiri-mode/cam/client.js';
import { init as initFDM } from '../kiri-mode/fdm/client.js';
import { beta, version } from '../moto/license.js';
import { settings as set_ctrl } from './settings.js';
import { init as initCAM } from '../kiri-mode/cam/client.js';
import { init as initFDM } from '../kiri-mode/fdm/client.js';
import { init as initLaser } from '../kiri-mode/laser/client.js';
let { CAM, SLA, FDM, LASER, DRAG, WJET, WEDM } = MODES,
{ consts, client, catalog, platform, selection } = api,
@ -1364,6 +1365,7 @@ function init_one() {
// run client mode initializations right after UI is bound
initFDM();
initCAM();
initLaser();
// override old style settings two-button menu
ui.settingsSave.onclick = () => {