From c1501c7739b3b809593315d827c9d922f265d699 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Mon, 10 Oct 2022 16:08:01 -0400 Subject: [PATCH] add Z refining passes to complement XY smoothing in pocket contours --- src/geo/paths.js | 4 +++- src/kiri-mode/cam/client.js | 2 ++ src/kiri-mode/cam/ops.js | 38 ++++++++++++++++++++++++++++++++++--- src/kiri/conf.js | 1 + web/kiri/lang/en.js | 4 +++- 5 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/geo/paths.js b/src/geo/paths.js index 14f02588..b01a9b8d 100644 --- a/src/geo/paths.js +++ b/src/geo/paths.js @@ -456,7 +456,9 @@ base.paths = { tip2tipEmit, shapeToPath, pointsToPath, - pathTo3D + pathTo3D, + vertexNormal: calc_vertex, + segmentNormal: calc_normal }; }); diff --git a/src/kiri-mode/cam/client.js b/src/kiri-mode/cam/client.js index f5e88edf..c8de7c14 100644 --- a/src/kiri-mode/cam/client.js +++ b/src/kiri-mode/cam/client.js @@ -1142,6 +1142,7 @@ CAM.init = function(kiri, api) { plunge: 'camPocketPlunge', expand: 'camPocketExpand', smooth: 'camPocketSmooth', + refine: 'cmaPocketRefine', contour: 'camPocketContour', outline: 'cmaPocketOutline', tolerance: 'camTolerance', @@ -1155,6 +1156,7 @@ CAM.init = function(kiri, api) { 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}), + refine: UC.newInput(LANG.cp_refi_s, {title:LANG.cp_refi_l, convert:UC.toInt, 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"}), diff --git a/src/kiri-mode/cam/ops.js b/src/kiri-mode/cam/ops.js index 4c5aa4a8..c2ebfe5e 100644 --- a/src/kiri-mode/cam/ops.js +++ b/src/kiri-mode/cam/ops.js @@ -13,7 +13,7 @@ gapp.register("kiri-mode.cam.ops", [], (root, exports) => { const { base, kiri } = root; const { paths, polygons, newPoint, newPolygon, sliceConnect } = base; -const { poly2polyEmit, tip2tipEmit } = paths; +const { poly2polyEmit, tip2tipEmit, segmentNormal, vertexNormal } = paths; const { driver, newSlice } = kiri; const { CAM } = driver; @@ -1045,7 +1045,7 @@ class OpPocket extends CamOp { } POLY.setWinding(slice.camLines, cutdir, false); if (contour) { - slice.camLines = pocket.conform(slice.camLines); + slice.camLines = pocket.conform(slice.camLines, op.refine); } slice.output() .setLayer("pocket", {line: color}, false) @@ -1093,14 +1093,46 @@ class OpPocket extends CamOp { } // mold cam output lines to the surface of the topo offset by tool geometry - conform(camLines) { + conform(camLines, refine = 10) { 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); } } + // walk points noting z deltas and smoothing sawtooth patterns + for (let j=0; j 10 work well for gently contoured geometries with significant Z movement."], cp_cont_s: "contour", cp_cont_l: ["ignore interior voids and features"], cp_outl_s: "outline only",