make register op part-based

This commit is contained in:
bakedpotatolord 2025-06-24 21:34:26 -06:00
commit c3c474185a
5 changed files with 68 additions and 63 deletions

View file

@ -111,6 +111,7 @@
"camTraceBottom": false, "camTraceBottom": false,
"cmaPocketOutline": false, "cmaPocketOutline": false,
"camRegisterThru": 5, "camRegisterThru": 5,
"camRegisterOffset": 10,
"camFlatness": 0, "camFlatness": 0,
"camContourBridge": 10, "camContourBridge": 10,
"camForceZMax": false, "camForceZMax": false,

View file

@ -1814,7 +1814,8 @@ CAM.init = function(kiri, api) {
dwell: 'camDrillDwell', dwell: 'camDrillDwell',
lift: 'camDrillLift', lift: 'camDrillLift',
feed: 'camRegisterSpeed', feed: 'camRegisterSpeed',
thru: 'camRegisterThru' offset: 'camRegisterOffset',
thru: 'camRegisterThru',
}).inputs = { }).inputs = {
tool: UC.newSelect(LANG.cc_tool, {}, "tools"), tool: UC.newSelect(LANG.cc_tool, {}, "tools"),
axis: UC.newSelect(LANG.cd_axis, {}, "regaxis"), axis: UC.newSelect(LANG.cd_axis, {}, "regaxis"),
@ -1828,6 +1829,7 @@ CAM.init = function(kiri, api) {
dwell: UC.newInput(LANG.cd_dwll_s, {title:LANG.cd_dwll_l, convert:UC.toFloat, show:() => poppedRec.axis !== '-'}), dwell: UC.newInput(LANG.cd_dwll_s, {title:LANG.cd_dwll_l, convert:UC.toFloat, show:() => poppedRec.axis !== '-'}),
lift: UC.newInput(LANG.cd_lift_s, {title:LANG.cd_lift_l, convert:UC.toFloat, units:true, show:() => poppedRec.axis !== '-'}), lift: UC.newInput(LANG.cd_lift_s, {title:LANG.cd_lift_l, convert:UC.toFloat, units:true, show:() => poppedRec.axis !== '-'}),
sep: UC.newBlank({class:"pop-sep"}), sep: UC.newBlank({class:"pop-sep"}),
offset: UC.newInput(LANG.cd_rego_s, {title:LANG.cd_rego_l, convert:UC.toFloat, units:true, }),
thru: UC.newInput(LANG.cd_thru_s, {title:LANG.cd_thru_l, convert:UC.toFloat, units:true}), thru: UC.newInput(LANG.cd_thru_s, {title:LANG.cd_thru_l, convert:UC.toFloat, units:true}),
}; };

View file

@ -1583,95 +1583,91 @@ class OpRegister extends CamOp {
updateToolDiams(tool.fluteDiameter()); updateToolDiams(tool.fluteDiameter());
let { stock } = settings, let { stock } = settings,
tz = widget.track.pos.z, toolZ = widget.track.pos.z,
lx = bounds.min.x, boundMinX = bounds.min.x,
hx = bounds.max.x, boundMaxX = bounds.max.x,
ly = bounds.min.y, boundMinY = bounds.min.y,
hy = bounds.max.y, boundMaxY = bounds.max.y,
o3 = tool.fluteDiameter() * 2, toolOffset = tool.fluteDiameter() * 2,
mx = (lx + hx) / 2, centerX = (boundMinX + boundMaxX) / 2,
my = (ly + hy) / 2, centerY = (boundMinY + boundMaxY) / 2,
mz = op.thru || zThru || 0, cutDepth = op.thru || zThru || 0,
dx = (stock.x - (hx - lx)) / 4, pathPoints = [],
dy = (stock.y - (hy - ly)) / 4, stockToSurfaceOffset = stock.z - bounds.max.z,
dz = stock.z, startZ = bounds.max.z + stockToSurfaceOffset + toolZ,
points = [], endZ = toolZ - cutDepth,
wo = stock.z - bounds.max.z, cutOffset = op.offset;
z1 = bounds.max.z + wo + tz,
z2 = tz - mz;
if (!(stock.x && stock.y && stock.z)) { if (!(stock.x && stock.y && stock.z)) {
return; return;
} }
switch (op.axis) { switch (op.axis.toLowerCase()) {
case "X":
case "x": case "x":
if (op.points == 3) { if (op.points == 3) {
points.push(newPoint(lx - dx, my, 0)); pathPoints.push(newPoint(boundMinX - cutOffset, centerY, 0));
points.push(newPoint(hx + dx, my - o3, 0)); pathPoints.push(newPoint(boundMaxX + cutOffset, centerY - toolOffset, 0));
points.push(newPoint(hx + dx, my + o3, 0)); pathPoints.push(newPoint(boundMaxX + cutOffset, centerY + toolOffset, 0));
} else { } else {
points.push(newPoint(lx - dx, my, 0)); pathPoints.push(newPoint(boundMinX - cutOffset, centerY, 0));
points.push(newPoint(hx + dx, my, 0)); pathPoints.push(newPoint(boundMaxX + cutOffset, centerY, 0));
} }
break; break;
case "Y":
case "y": case "y":
if (op.points == 3) { if (op.points == 3) {
points.push(newPoint(mx, ly - dy, 0)); pathPoints.push(newPoint(centerX, boundMinY - cutOffset, 0));
points.push(newPoint(mx - o3, hy + dy, 0)); pathPoints.push(newPoint(centerX - toolOffset, boundMaxY + cutOffset, 0));
points.push(newPoint(mx + o3, hy + dy, 0)); pathPoints.push(newPoint(centerX + toolOffset, boundMaxY + cutOffset, 0));
} else { } else {
points.push(newPoint(mx, ly - dy, 0)); pathPoints.push(newPoint(centerX, boundMinY - cutOffset, 0));
points.push(newPoint(mx, hy + dy, 0)); pathPoints.push(newPoint(centerX, boundMaxY + cutOffset, 0));
} }
break; break;
case "-": case "-":
let o2 = o3 / 2, let halfOffset = toolOffset / 2,
x0 = lx - dx, loopMinX = boundMinX - cutOffset,
x1 = hx + dx, loopMaxX = boundMaxX + cutOffset,
y0 = ly - dy - o2, loopMinY = boundMinY - cutOffset - halfOffset,
y1 = hy + dy + o2, loopMaxY = boundMaxY + cutOffset + halfOffset,
x4 = (x1 - x0 - o2) / 4, deltaX = (loopMaxX - loopMinX - halfOffset) / 4,
y4 = (y1 - y0 - o2 * 3) / 4, deltaY = (loopMaxY - loopMinY - halfOffset * 3) / 4,
poly, cp, cz; poly, currentPoint, currentZ;
function start(z) { function start(z) {
cz = z; currentZ = z;
cp = {x:x0 + o2 * 0.5, y:y0 + o2 * 1.5}; currentPoint = { x: loopMinX + halfOffset * 0.5, y: loopMinY + halfOffset * 1.5 };
poly = newPolygon().add(cp.x, cp.y, z); poly = newPolygon().add(currentPoint.x, currentPoint.y, z);
} }
function move(dx, dy) { function move(dx, dy) {
cp.x += dx; currentPoint.x += dx;
cp.y += dy; currentPoint.y += dy;
poly.add(cp.x, cp.y, cz); poly.add(currentPoint.x, currentPoint.y, currentZ);
} }
function rept(count, tv, fn) { function rept(count, step, fn) {
while (count-- > 0) { while (count-- > 0) {
fn(tv, count === 0); fn(step, count === 0);
tv = -tv; step = -step;
} }
} }
for (let z of base.util.lerp(z1, z2, op.down)) { for (let z of base.util.lerp(startZ, endZ, op.down)) {
let slice = newSlice(z); let slice = newSlice(z);
addSlices(slice); addSlices(slice);
sliceOut.push(slice); sliceOut.push(slice);
start(z); start(z);
rept(4, o2, oy => { rept(4, halfOffset, oy => {
move(0, -oy); move(0, -oy);
move(x4, 0); move(deltaX, 0);
}); });
rept(4, o2, ox => { rept(4, halfOffset, ox => {
move(ox, 0); move(ox, 0);
move(0, y4); move(0, deltaY);
}); });
rept(4, o2, oy => { rept(4, halfOffset, oy => {
move(0, oy); move(0, oy);
move(-x4, 0); move(-deltaX, 0);
}); });
rept(4, o2, ox => { rept(4, halfOffset, ox => {
move(-ox, 0); move(-ox, 0);
move(0, -y4); move(0, -deltaY);
}); });
poly.points.pop(); poly.points.pop();
slice.camTrace = { tool: tool.getID(), rate: op.feed, plunge: op.rate }; slice.camTrace = { tool: tool.getID(), rate: op.feed, plunge: op.rate };
@ -1683,12 +1679,12 @@ class OpRegister extends CamOp {
break; break;
} }
if (points.length) { if (pathPoints.length) {
let slice = newSlice(0,null), polys = []; let slice = newSlice(0,null), polys = [];
points.forEach(point => { pathPoints.forEach(point => {
polys.push(newPolygon() polys.push(newPolygon()
.append(point.clone().setZ(z1)) .append(point.clone().setZ(startZ))
.append(point.clone().setZ(z2))); .append(point.clone().setZ(endZ)));
}); });
slice.camLines = polys; slice.camLines = polys;
slice.output() slice.output()

View file

@ -526,6 +526,7 @@ const conf = exports({
camDrillingOn: false, camDrillingOn: false,
camRegisterSpeed: 1000, camRegisterSpeed: 1000,
camRegisterThru: 5, camRegisterThru: 5,
camRegisterOffset: 10,
camFlipAxis: "X", camFlipAxis: "X",
camFlipOther: "", camFlipOther: "",
camLaserEnable: ["M321"], camLaserEnable: ["M321"],

View file

@ -591,8 +591,6 @@ self.kiri.lang['en-us'] = {
cd_dwll_l: ["dwell time","between plunges in","in milliseconds"], cd_dwll_l: ["dwell time","between plunges in","in milliseconds"],
cd_lift_s: "drill lift", cd_lift_s: "drill lift",
cd_lift_l: ["lift between plunges","after dwell period","in workspace units","0 to disable"], cd_lift_l: ["lift between plunges","after dwell period","in workspace units","0 to disable"],
cd_regi_s: "register",
cd_regi_l: ["drill registration holes","for double-sided parts","independent of enable","drilling but uses same","tool and settings"],
cd_thru_s: "z extend", cd_thru_s: "z extend",
cd_thru_l: ["extend downward cut through stock","in workspace units"], cd_thru_l: ["extend downward cut through stock","in workspace units"],
cd_dtru_s: "drill through", cd_dtru_s: "drill through",
@ -608,6 +606,13 @@ self.kiri.lang['en-us'] = {
cd_sela_s: "Select Matching Diameter", cd_sela_s: "Select Matching Diameter",
cd_sela_l: ["select all holes that", "match selected tool diameter"], cd_sela_l: ["select all holes that", "match selected tool diameter"],
//CNC Registration
cd_regi_s: "register",
cd_regi_l: ["drill registration holes","for double-sided parts","independent of enable","drilling but uses same","tool and settings"],
cd_rego_s: "part offset",
cd_rego_l: ["offset of hole center","from part bounding box","in workspace units"],
// CNC FLIP // CNC FLIP
cf_menu: "flip", cf_menu: "flip",
cf_nvrt_s: "z bottom", cf_nvrt_s: "z bottom",