From b735a3abefa91e8ee0d85aba132c133954b76744 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Fri, 26 Dec 2025 21:46:49 -0500 Subject: [PATCH] fix starting offset with multiple widgets --- src/kiri/app/platform.js | 6 +++--- src/kiri/mode/cam/export.js | 1 + src/kiri/mode/cam/prepare.js | 30 +++++++++++++++++++++++++++--- web/kiri/index.html | 2 +- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/kiri/app/platform.js b/src/kiri/app/platform.js index 701c67d6..8523632c 100644 --- a/src/kiri/app/platform.js +++ b/src/kiri/app/platform.js @@ -3,9 +3,9 @@ import { $, h } from '../../moto/webui.js'; import { ajax, js2o } from '../core/utils.js'; import { api } from './api.js'; -import { base } from '../../geo/base.js'; import { COLOR, MODES } from '../core/consts.js'; import { load as file_load } from '../../load/file.js'; +import { newBounds } from '../../geo/bounds.js'; import { Packer } from './pack.js'; import { space } from '../../moto/space.js'; import { THREE } from '../../ext/three.js'; @@ -611,8 +611,8 @@ function positionNewWidget(widget) { x: dim.x / 2, y: dim.y / 2 }; - const bounds = base.newBounds(); - const target = base.newBounds(); + const bounds = newBounds(); + const target = newBounds(); const DEG2RAD = Math.PI / 180; const WIDGETS = api.widgets.all(); // look for best position for new widget that doesn't collide diff --git a/src/kiri/mode/cam/export.js b/src/kiri/mode/cam/export.js index 7dfb657c..b9206f9b 100644 --- a/src/kiri/mode/cam/export.js +++ b/src/kiri/mode/cam/export.js @@ -416,6 +416,7 @@ export function cam_export(print, online) { const isOffset = offset && (offset.x || offset.y || offset.z); // remap points as necessary for origins, offsets, inversions print.output.forEach(layer => { + // console.log(layer); if (!Array.isArray(layer)) { return; } diff --git a/src/kiri/mode/cam/prepare.js b/src/kiri/mode/cam/prepare.js index 8da97d71..e1ecbac2 100644 --- a/src/kiri/mode/cam/prepare.js +++ b/src/kiri/mode/cam/prepare.js @@ -82,7 +82,8 @@ export async function cam_prepare(widgets, settings, update) { // process `prepare` paths for a single widget export async function prepare_one(widget, settings, print, firstPoint, update) { - let { device, process } = settings, + let { device, process, stock: set_stock } = settings, + { center } = set_stock, { alignTop } = settings.controller, { camArcEnabled, camArcResolution, camArcTolerance } = process, { camDepthFirst, camEaseAngle, camEaseDown } = process, @@ -144,6 +145,21 @@ export async function prepare_one(widget, settings, print, firstPoint, update) { if (debug) console.log({ zSafe, wmx, wmy, wmz }); + // function d(o) { + // console.log('<-------------------'); + // for (let [k,v] of Object.entries(o)) console.log(k,v); + // console.log('------------------->'); + // } + + // d({ + // stock, + // sstck: set_stock, + // center, + // origin, + // wmx, + // wmy + // }); + function newLayer(op) { if (layerOut.length || layerOut.mode) { newOutput.push(layerOut); @@ -850,7 +866,15 @@ export async function prepare_one(widget, settings, print, firstPoint, update) { // coming from a previous widget, use previous last point as starting point // make top start offset configurable - printPoint = firstPoint || origin; + if (firstPoint) { + // we're coming from another widget. offset compensated below + printPoint = firstPoint; + // console.log('coming from another widget', { printPoint }); + } else { + // we're the first widget output. offset is center + printPoint = origin.clone().move({ x: center.x, y: center.y }); + // console.log('first widget output', { printPoint }); + } let ops = { addGCode, @@ -910,7 +934,7 @@ export async function prepare_one(widget, settings, print, firstPoint, update) { update((opSum + (progress * weight)) / opTot, message || op.type(), message); }); opSum += weight; - if (tool && printPoint) { + if (tool && printPoint && cop.type !== 'shadow') { newLayer(); if (!isIndex) { layerPush(printPoint.clone().setZ(stockZClear), 0, 0, tool); diff --git a/web/kiri/index.html b/web/kiri/index.html index a06b6b89..c0890b03 100644 --- a/web/kiri/index.html +++ b/web/kiri/index.html @@ -692,7 +692,7 @@
- this project neeeds your support! + this project needs your support!