diff --git a/src/kiri-mode/cam/client.js b/src/kiri-mode/cam/client.js
index 6b39c8ea..f5e88edf 100644
--- a/src/kiri-mode/cam/client.js
+++ b/src/kiri-mode/cam/client.js
@@ -1134,31 +1134,33 @@ CAM.init = function(kiri, api) {
};
createPopOp('pocket', {
- spindle: 'camPocketSpindle',
- tool: 'camPocketTool',
- step: 'camPocketOver',
- down: 'camPocketDown',
- rate: 'camPocketSpeed',
- plunge: 'camPocketPlunge',
- expand: 'camPocketExpand',
- smooth: 'camPocketSmooth',
- contour: 'camPocketContour',
- outline: 'cmaPocketOutline'
+ spindle: 'camPocketSpindle',
+ tool: 'camPocketTool',
+ step: 'camPocketOver',
+ down: 'camPocketDown',
+ rate: 'camPocketSpeed',
+ plunge: 'camPocketPlunge',
+ expand: 'camPocketExpand',
+ smooth: 'camPocketSmooth',
+ contour: 'camPocketContour',
+ 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}),
- 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"}),
- expand: UC.newInput(LANG.cp_xpnd_s, {title:LANG.cp_xpnd_l, convert:UC.toFloat, units:true, show:() => !poppedRec.contour}),
- smooth: UC.newInput(LANG.cp_smoo_s, {title:LANG.cp_smoo_l, convert:UC.toFloat, units:true}),
- 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}),
- sep: UC.newBlank({class:"pop-sep"}),
+ 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}),
+ 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"}),
+ expand: UC.newInput(LANG.cp_xpnd_s, {title:LANG.cp_xpnd_l, convert:UC.toFloat, units:true, show:() => !poppedRec.contour}),
+ smooth: UC.newInput(LANG.cp_smoo_s, {title:LANG.cp_smoo_l, convert:UC.toFloat, units:true}),
+ tolerance: UC.newInput(LANG.ou_toll_s, {title:LANG.ou_toll_l, convert:UC.toFloat, bound:UC.bound(0,10.0), units:true, round:4, show:() => poppedRec.contour}),
+ 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}),
+ sep: UC.newBlank({class:"pop-sep"}),
menu: UC.newRow([
UC.newButton(undefined, func.surfaceAdd, {icon:''}),
UC.newButton(undefined, func.surfaceDone, {icon:''}),
diff --git a/src/kiri-mode/cam/ops.js b/src/kiri-mode/cam/ops.js
index 992ff651..36d81a89 100644
--- a/src/kiri-mode/cam/ops.js
+++ b/src/kiri-mode/cam/ops.js
@@ -957,32 +957,31 @@ class OpPocket extends CamOp {
}
slice(progress) {
- const debug = false;
+ const pocket = this;
+ const debug = true;
let { op, state } = this;
- let { tool, rate, down, plunge, expand, contour, smooth } = op;
+ let { tool, rate, down, plunge, expand, contour, smooth, tolerance } = op;
let { settings, widget, sliceAll, zMax, zTop, zThru, tabs, color } = state;
let { updateToolDiams, cutTabs, cutPolys, healPolys, shadowAt } = state;
let { process, stock } = settings;
// generate tracing offsets from chosen features
let sliceOut = this.sliceOut = [];
- let toolDiam = new CAM.Tool(settings, tool).fluteDiameter();
+ let camTool = new CAM.Tool(settings, tool);
+ let toolDiam = camTool.fluteDiameter();
let toolOver = toolDiam * op.step;
let cutdir = process.camConventional;
if (contour) {
down = 0;
- let topo = new CAM.Topo({
+ this.topo = new CAM.Topo({
// onupdate: (update, msg) => {
onupdate: (index, total, msg) => {
progress(index / total, msg);
},
- ondone: (slices) => {
- this.sliceOut = slices;
- sliceAll.appendAll(slices);
- },
+ ondone: (slices) => { },
contour: {
- tolerance: 0,
+ tool,
+ tolerance,
inside: true,
- tool: tool,
axis: "-"
},
state: state
@@ -1027,7 +1026,7 @@ class OpPocket extends CamOp {
} else {
shadow = shadowAt(z);
if (smooth) {
- shadow = POLY.offset(POLY.offset(shadow, smooth), -smooth);
+ shadow = POLY.setZ(POLY.offset(POLY.offset(shadow, smooth), -smooth), z);
}
POLY.subtract([ poly ], shadow, clip);
}
@@ -1045,6 +1044,9 @@ class OpPocket extends CamOp {
slice.camLines = POLY.flatten(slice.camLines, null, true);
}
POLY.setWinding(slice.camLines, cutdir, false);
+ if (contour) {
+ pocket.conform(slice.camLines);
+ }
slice.output()
.setLayer("pocket", {line: color}, false)
.addPolys(slice.camLines)
@@ -1090,12 +1092,24 @@ class OpPocket extends CamOp {
}
}
+ // mold cam output lines to the surface of the topo offset by tool geometry
+ conform(camLines) {
+ const topo = this.topo;
+ let repo = 10;
+ for (let poly of camLines) {
+ for (let point of poly.points) {
+ point.z = topo.toolAtXY(point.x, point.y);
+ }
+ }
+ }
+
prepare(ops, progress) {
let { op, state, sliceOut } = this;
let { setTool, setSpindle } = ops;
setTool(op.tool, op.rate);
setSpindle(op.spindle);
+
let i=0, l=sliceOut.length;
for (let slice of sliceOut.filter(s => s.camLines)) {
ops.emitTrace(slice);
diff --git a/src/kiri-mode/cam/topo.js b/src/kiri-mode/cam/topo.js
index 131b3798..e2379a60 100644
--- a/src/kiri-mode/cam/topo.js
+++ b/src/kiri-mode/cam/topo.js
@@ -146,6 +146,15 @@ class Topo {
return Math.max(mz, 0);
}
+ // export z probe function
+ const rx = stepsx / boundsX;
+ const ry = stepsx / boundsX;
+ this.toolAtXY = function(px, py) {
+ px = Math.round(rx * (px - minX));
+ py = Math.round(ry * (py - minY));
+ return toolAtZ(px, py);
+ };
+
function push_point(x,y,z) {
const newP = newPoint(x,y,z);
// todo: merge co-linear, not just co-planar