add CAM 3D engraving and marking with the pocket contouring operation

This commit is contained in:
Stewart Allen 2022-10-10 18:01:43 -04:00
commit b7f8ce5b52
7 changed files with 30 additions and 8 deletions

View file

@ -1144,14 +1144,15 @@ CAM.init = function(kiri, api) {
smooth: 'camPocketSmooth',
refine: 'cmaPocketRefine',
contour: 'camPocketContour',
engrave: 'camPocketEngrave',
outline: 'cmaPocketOutline',
tolerance: 'camTolerance',
}).inputs = {
tool: UC.newSelect(LANG.cc_tool, {}, "tools"),
sep: UC.newBlank({class:"pop-sep"}),
spindle: UC.newInput(LANG.cc_spnd_s, {title:LANG.cc_spnd_l, convert:UC.toInt, show:hasSpindle}),
step: UC.newInput(LANG.cc_sovr_s, {title:LANG.cc_sovr_l, convert:UC.toFloat, bound:UC.bound(0.01,1.0)}),
down: UC.newInput(LANG.cc_sdwn_s, {title:LANG.cc_sdwn_l, convert:UC.toFloat, units:true}),
step: UC.newInput(LANG.cc_sovr_s, {title:LANG.cc_sovr_l, convert:UC.toFloat, bound:UC.bound(0.01,1.0), show:() => !(poppedRec.engrave && poppedRec.contour)}),
down: UC.newInput(LANG.cc_sdwn_s, {title:LANG.cc_sdwn_l, convert:UC.toFloat, units:true, show:() => !(poppedRec.engrave && poppedRec.contour)}),
rate: UC.newInput(LANG.cc_feed_s, {title:LANG.cc_feed_l, convert:UC.toInt, units:true}),
plunge: UC.newInput(LANG.cc_plng_s, {title:LANG.cc_plng_l, convert:UC.toInt, units:true}),
sep: UC.newBlank({class:"pop-sep"}),
@ -1162,6 +1163,7 @@ CAM.init = function(kiri, api) {
sep: UC.newBlank({class:"pop-sep"}),
contour: UC.newBoolean(LANG.cp_cont_s, undefined, {title:LANG.cp_cont_s}),
outline: UC.newBoolean(LANG.cp_outl_s, undefined, {title:LANG.cp_outl_l, show:() => !poppedRec.contour}),
engrave: UC.newBoolean(LANG.cp_engr_s, undefined, {title:LANG.cp_engr_l, show:() => poppedRec.contour}),
sep: UC.newBlank({class:"pop-sep"}),
menu: UC.newRow([
UC.newButton(undefined, func.surfaceAdd, {icon:'<i class="fas fa-plus"></i>'}),

View file

@ -970,6 +970,7 @@ class OpPocket extends CamOp {
let toolDiam = camTool.fluteDiameter();
let toolOver = toolDiam * op.step;
let cutdir = process.camConventional;
let engrave = contour && op.engrave;
if (contour) {
down = 0;
this.topo = new CAM.Topo({
@ -1034,9 +1035,10 @@ class OpPocket extends CamOp {
continue;
}
let slice = newSliceOut(z);
let count = engrave ? 1 : 999;
slice.camTrace = { tool, rate, plunge };
POLY.offset(clip, [ -toolDiam / 2, -toolOver ], {
count:999, outs: slice.camLines = [], flat:true, z
count, outs: slice.camLines = [], flat:true, z
});
if (tabs) {
slice.camLines = cutTabs(tabs, POLY.flatten(slice.camLines, null, true), z);
@ -1045,7 +1047,7 @@ class OpPocket extends CamOp {
}
POLY.setWinding(slice.camLines, cutdir, false);
if (contour) {
slice.camLines = pocket.conform(slice.camLines, op.refine);
slice.camLines = pocket.conform(slice.camLines, op.refine, engrave);
}
slice.output()
.setLayer("pocket", {line: color}, false)
@ -1093,14 +1095,14 @@ class OpPocket extends CamOp {
}
// mold cam output lines to the surface of the topo offset by tool geometry
conform(camLines, refine = 10) {
conform(camLines, refine = 10, engrave) {
const topo = this.topo;
// re-segment polygon to a higher resolution
const hirez = camLines.map(p => p.segment(topo.tolerance * 2));
// walk points and offset from surface taking into account tool geometry
for (let poly of hirez) {
for (let point of poly.points) {
point.z = topo.toolAtXY(point.x, point.y);
point.z = engrave ? topo.zAtXY(point.x, point.y) : topo.toolAtXY(point.x, point.y);
}
}
// walk points noting z deltas and smoothing sawtooth patterns

View file

@ -69,11 +69,19 @@ class Tool {
return this.unitScale() * this.tool.shaft_diam;
}
isBallMill() {
return this.type === "ballmill";
}
isTaperMill() {
return this.type === "tapermill";
}
generateProfile(resolution) {
// generate tool profile
let type = this.getType(),
ball = type === "ballmill",
taper = type === "tapermill",
ball = this.isBallMill(),
taper = this.isTaperMill(),
tip_diameter = this.tipDiameter(),
shaft_offset = this.fluteLength(),
flute_diameter = this.fluteDiameter(),

View file

@ -155,6 +155,12 @@ class Topo {
return toolAtZ(px, py);
};
this.zAtXY = function(px, py) {
px = Math.round(rx * (px - minX));
py = Math.round(ry * (py - minY));
return topo.data[px * stepsy + py] || zMin;
};
function push_point(x,y,z) {
const newP = newPoint(x,y,z);
// todo: merge co-linear, not just co-planar