fix lathe preview lerp, gpu lathe end point, and index issues
This commit is contained in:
parent
a32b7063a0
commit
ad86c38d97
5 changed files with 37 additions and 48 deletions
|
|
@ -25,12 +25,11 @@ export class OpIndex extends CamOp {
|
|||
}
|
||||
|
||||
prepare(ops, progress) {
|
||||
let { zmax, zsafe, camOut, printPoint } = ops;
|
||||
let { camOut, printPoint, zSafe } = ops;
|
||||
// max point of stock corner radius when rotating (safe z when indexing)
|
||||
let ztop = Math.max(zsafe, zmax);
|
||||
// move above rotating stock
|
||||
camOut(printPoint = printPoint.clone().setZ(ztop), 0);
|
||||
camOut(printPoint = printPoint.clone().setZ(zSafe), 0);
|
||||
// issue rotation command
|
||||
camOut(printPoint = printPoint.clone().setZ(ztop).setA(this.degrees), 0);
|
||||
camOut(printPoint = printPoint.clone().setZ(zSafe).setA(this.degrees), 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,12 +55,14 @@ class OpLathe extends CamOp {
|
|||
|
||||
prepare(ops, progress) {
|
||||
let { op, slices, topo } = this;
|
||||
let { camOut, newLayer, zSafe } = ops;
|
||||
let { camOut, getLastPoint, newLayer, setContouring, setNextIsMove, zSafe } = ops;
|
||||
|
||||
let rez = topo.resolution;
|
||||
|
||||
// start top center, X = 0, Y = 0 closest to 4th axis chuck
|
||||
camOut(newPoint(0, 0, zSafe), 0);
|
||||
camOut(newPoint(0, 0, zSafe).setA(0), 0);
|
||||
setContouring(true);
|
||||
setNextIsMove();
|
||||
|
||||
for (let slice of slices) {
|
||||
// ignore debug slices
|
||||
|
|
@ -68,27 +70,9 @@ class OpLathe extends CamOp {
|
|||
continue;
|
||||
}
|
||||
|
||||
let last;
|
||||
for (let path of slice.camLines) {
|
||||
let latent;
|
||||
path.forEachPoint((point, pidx) => {
|
||||
if (last) {
|
||||
const dz = Math.abs(last.z - point.z);
|
||||
if (dz < rez) {
|
||||
// latent point should still be included in
|
||||
// preview b/c arcs would look like straight lines
|
||||
latent = point.clone();
|
||||
return;
|
||||
}
|
||||
if (latent) {
|
||||
camOut(latent, 1);
|
||||
latent = undefined;
|
||||
}
|
||||
}
|
||||
camOut(last = point.clone(), pidx > 0 ? 1 : 0);
|
||||
}, false);
|
||||
if (latent) {
|
||||
camOut(latent, 1);
|
||||
for (let point of path.points) {
|
||||
camOut(point);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -96,10 +80,8 @@ class OpLathe extends CamOp {
|
|||
}
|
||||
|
||||
// move to safe height and reset A axis
|
||||
let last = ops.lastPoint();
|
||||
let last = getLastPoint();
|
||||
let amax = (Math.round(last.a / 360) * 360).round(2);
|
||||
// camOut(last = last.clone().setZ(zmax), 0);
|
||||
// camOut(last = last.clone().setA(amax), 0);
|
||||
newLayer();
|
||||
ops.addGCode([`G0 Z${zSafe.round(2)}`, `G0 A${amax}`, "G92 A0"]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
|
|||
return tool;
|
||||
}
|
||||
|
||||
function setTool(toolID, feed, plunge) {
|
||||
function setTool(toolID, feed = camFastFeed, plunge = camFastFeedZ) {
|
||||
if (toolID !== lastTool) {
|
||||
tool = new Tool(settings, toolID);
|
||||
toolType = tool.getType();
|
||||
|
|
@ -273,11 +273,13 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
|
|||
function layerPush(point, emit, speed, tool, options) {
|
||||
const { type, center } = options ?? {};
|
||||
if (debug_push && options?.type !== 'lerp') {
|
||||
let rounded = [point.x,point.y,point.z,point.a??0].map(v => v.toFixed(3));
|
||||
if (rounded.filter(v => isNaN(v)).length) console.trace('NaN');
|
||||
console.log(
|
||||
currentOp.type,
|
||||
emit | 0,
|
||||
speed | 0,
|
||||
...[point.x,point.y,point.z,point.a??0].map(v => v.toFixed(3))
|
||||
...rounded
|
||||
);
|
||||
}
|
||||
layerOut.mode = currentOp;
|
||||
|
|
@ -347,6 +349,8 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
|
|||
p.y - wmy,
|
||||
p.z - wmz
|
||||
)
|
||||
.setA(p.a)
|
||||
.annotate({ slice: p.slice });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -355,7 +359,6 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
|
|||
* @param {-1|0|1|2|3} emit ignore, G0, G1, G2, G3
|
||||
* @param {number} opts.shortCut used to convert short moves to cuts
|
||||
* @param {number} opts.factor speed scale factor
|
||||
* @param {Object} opts.center arc center parameter
|
||||
* @return {Point} translated emitted point
|
||||
*/
|
||||
function camOut(point, emit = 1, opts) {
|
||||
|
|
@ -370,7 +373,6 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
|
|||
feed = feedRate,
|
||||
shortCut = toolDiamMove,
|
||||
moveOnly = false,
|
||||
center,
|
||||
} = opts ?? {};
|
||||
let pointA = point.a;
|
||||
let rate = feed * factor;
|
||||
|
|
@ -395,20 +397,25 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
|
|||
|
||||
// carry rotation forward when not overridden
|
||||
if (pointA !== undefined && printPoint.a !== undefined) {
|
||||
let DA = printPoint.a - pointA;
|
||||
let MZ = Math.max(printPoint.z, point.z)
|
||||
let DA = point.a - printPoint.a;
|
||||
let MaxZ = Math.max(printPoint.z, point.z);
|
||||
// find rotary arc length
|
||||
let AL = (Math.abs(DA) / 360) * (2 * Math.PI * MZ);
|
||||
if (AL >= 1) {
|
||||
let arcLen = (Math.abs(DA) / 360) * (2 * Math.PI * MaxZ);
|
||||
let steps = Math.ceil(arcLen);
|
||||
// emit interpolated points between printPoint and point
|
||||
if (steps > 2) {
|
||||
// if (point.a === 0 || printPoint.a === 0) console.log({ from: printPoint.clone(), to: point.clone() });
|
||||
let zStep = (point.z - printPoint.z) / steps;
|
||||
let aStep = DA / steps;
|
||||
let lp = printPoint.clone();
|
||||
newLayer();
|
||||
let lerp = base.util.lerp(printPoint.a, pointA, 1);
|
||||
// create interpolated point set for rendering and animation
|
||||
if (debug) console.log({ DA, MZ, AL }, lerp.length);
|
||||
for (let a of lerp) {
|
||||
let lp = point.clone().setA(a);
|
||||
if (debug) console.log(lp.a, lp.x, lp.y, lp.z);
|
||||
while (--steps > 0) {
|
||||
lp.z += zStep;
|
||||
lp.a += aStep;
|
||||
// if (false)
|
||||
layerPush(
|
||||
lp,
|
||||
lp.clone(),
|
||||
emit,
|
||||
rate,
|
||||
tool,
|
||||
|
|
@ -424,7 +431,6 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
|
|||
deltaZ = point.z - printPoint.z,
|
||||
absDeltaZ = Math.abs(deltaZ),
|
||||
isMove = (emit === 0 || emit === false),
|
||||
isArc = (emit > 1),
|
||||
upAndOver = false;
|
||||
|
||||
// contouring logic
|
||||
|
|
@ -534,8 +540,7 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
|
|||
point,
|
||||
emit,
|
||||
rate,
|
||||
tool,
|
||||
isArc ? { center: toWorkCoords(center) } : undefined
|
||||
tool
|
||||
);
|
||||
|
||||
return point;
|
||||
|
|
@ -834,6 +839,7 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
|
|||
depthOutlinePath,
|
||||
emitDrills,
|
||||
emitTraces,
|
||||
getLastPoint() { return toWidgetCoords(printPoint) },
|
||||
getTool,
|
||||
newLayer,
|
||||
pocket,
|
||||
|
|
@ -875,7 +881,7 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
|
|||
newLayer(cop);
|
||||
setTolerance(0);
|
||||
setNextIsMove();
|
||||
if (cop.tool) setTool(cop.tool, cop.rate ?? feedRate, cop.plunge ?? plungeRate);
|
||||
if (cop.tool) setTool(cop.tool, cop.rate || feedRate, cop.plunge || plungeRate);
|
||||
if (cop.spindle) setSpindle(cop.spindle);
|
||||
// set printPoint in widget coordinate space
|
||||
ops.printPoint = printPoint.clone().move({ x: -wmx, y: -wmy, z: -wmz });
|
||||
|
|
|
|||
|
|
@ -271,7 +271,7 @@ export async function cam_slice(settings, widget, onupdate, ondone) {
|
|||
if (isIndexed) {
|
||||
// preface op list with OpIndex
|
||||
if (activeOps.length === 0 || activeOps[0].type !== 'index') {
|
||||
opList.push(new OPS.index(state, { type: "index", index: 0 }));
|
||||
opList.push(new OPS.index(state, { type: "index", degrees: 0, absolute: true }));
|
||||
opTot += opList.peek().weight();
|
||||
|
||||
}
|
||||
|
|
@ -551,6 +551,7 @@ export function cylinder_poly_find(widget, face) {
|
|||
if (!poly) throw "slicing returned no poly";
|
||||
|
||||
let circular = poly.circularity() > 0.98;
|
||||
// console.log({ zmid, cylVerts, opts, poly, circularity: poly.circularity() });
|
||||
|
||||
//throw error if not circular
|
||||
if (!circular) throw "faces must be circular";
|
||||
|
|
|
|||
|
|
@ -233,6 +233,7 @@ export class Topo {
|
|||
for (let i=0; i<pointsPerLine; i++) {
|
||||
let slice = newSlice(i);
|
||||
let points = rows.map(row => row[i]);
|
||||
points.push(points[0].clone().setA(-360));
|
||||
if (i % 2 === 1) points.reverse();
|
||||
slice.index = i;
|
||||
slice.camLines = [ newPolygon(points).setOpen() ];
|
||||
|
|
|
|||
Loading…
Reference in a new issue