stub in coastline moves for contouring

This commit is contained in:
Stewart Allen 2025-12-31 22:59:09 -05:00
commit debe4fb192
3 changed files with 66 additions and 5 deletions

View file

@ -93,7 +93,7 @@ class OpContour extends CamOp {
// we need topo for safe travel moves when roughing and outlining
// not generated when drilling-only. then all z moves use bounds max.
// also generates x and y contouring when selected
let topo = await Topo({
let topo = this.topo = await Topo({
// onupdate: (update, msg) => {
onupdate: (index, total, msg) => {
progress(index / total, msg);
@ -117,7 +117,7 @@ class OpContour extends CamOp {
}
prepare(ops, progress) {
let { op, state, sliceOut, toolStep } = this;
let { op, sliceOut, state, toolStep, topo } = this;
let { settings } = state;
let { process } = settings;
@ -128,7 +128,7 @@ class OpContour extends CamOp {
let depthData = [];
setTool(op.tool, op.rate, process.camFastFeedZ);
setContouring(true, toolStep * 1.5);
setContouring(true, toolStep * 1.5, topo.coastline);
setTolerance(this.tolerance);
let printPoint = newPoint(bounds.min.x, bounds.min.y, zmax);

View file

@ -114,6 +114,7 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
originx = (camOriginCenter ? 0 : -stock.x / 2) + (camOriginOffX || 0),
originy = (camOriginCenter ? 0 : -stock.y / 2) + (camOriginOffY || 0),
origin = newPoint(originx, originy, zSafe),
coastline,
contouring = false,
currentOp,
drillDown = 0,
@ -184,10 +185,17 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
}
}
function setContouring(bool, step) {
function setContouring(bool, step, coast) {
coastline = coast;
contouring = bool;
toolDiamMove = step ?? tool.getStepSize(currentOp.step) * 2;
if (bool) setTravelBoundary();
if (coast) {
for (let poly of coast) {
// poly.points = poly.points.map(pt => toWorkCoords(pt));
}
console.log({ coast_to_work: coast });
}
}
function setSpindle(speed) {
@ -377,6 +385,45 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
.annotate({ slice: p.slice });
}
function coastlineMove(point) {
let from = toWidgetCoords(printPoint);
let to = toWidgetCoords(point);
if (!coastline || from.distTo2D(to) < 0.01) {
return false;
}
let start = { dist: 1, poly: 0, pt: from };
let end = { dist: 1, poly: 1, pt: to };
for (let poly of coastline) {
let { points } = poly;
for (let i=0; i<points.length; i++) {
let pt = points[i];
if (!pt) {
continue;
}
let dist = from.distTo2D(pt);
if (dist < start.dist) {
start.dist = dist;
start.poly = poly;
start.pos = i;
start.mp = pt;
}
dist = to.distTo2D(pt);
if (dist < end.dist) {
end.dist = dist;
end.poly = poly;
end.pos = i;
end.mp = pt;
}
}
}
if (start.poly !== end.poly || start.pos === end.pos) {
return false;
}
let pdist = end.pos - start.pos;
console.log({ can_route: [ start, end ], pdist });
return true;
}
/**
* emit a cut or move operation from the current location to a new location
* @param {Point} point destination for move in widget coordinate space
@ -390,6 +437,7 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
lastOp = currentOp;
// translate widget point into workspace coordinates
let point_in = point;
point = toWorkCoords(point);
let {
@ -461,7 +509,9 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
// contouring logic
if (isMove && contouring) {
if (deltaXY > toolDiamMove) {
if (coastline && deltaXY < toolDiamMove * 5 && coastlineMove(point)) {
// console.log('coastline move');
} else if (deltaXY > toolDiamMove) {
upAndOver = true;
} else if (absDeltaZ < 0.01) {
if (debug) console.log('contour move as cut');

View file

@ -166,6 +166,17 @@ export class Topo {
zFloor: zBottom - 1,
onProgress(pct) { console.log({ pct }); onupdate(pct/100, 100) }
});
gpu.mode = 'tracing';
// create coastline path around part for tip-to-tip travels
// convert shadow/clip poly lines to raster float32 array groups
let paths = POLY.flatten(clipTo).map(poly => poly.points.map(p => [ p.x, p.y ]).flat().toFloat32());
let coastline = await gpu.generateToolpaths({
paths,
step: toolStep / 2,
zFloor: zBottom - 1
});
this.coastline = coastline.paths.map(arr => newPolygon().fromArray([0,...arr]));
console.log({ coastline: this.coastline, clipTo });
gpu.terminate();
let { numScanlines, pointsPerLine, pathData } = output;