From b46798422232ed891018415885bd50084b61cfdd Mon Sep 17 00:00:00 2001 From: bakedpotatolord Date: Sat, 19 Jul 2025 16:17:36 -0600 Subject: [PATCH] add CAM helical clockwise, reverse, and entry params --- src/cli/kiri-cam-process.json | 4 ++ src/kiri/core/conf.js | 4 ++ src/kiri/mode/cam/cl-ops.js | 11 ++++- src/kiri/mode/cam/op-helical.js | 74 ++++++++++++++++++++++++++++++--- web/kiri/lang/en.js | 9 +++- 5 files changed, 94 insertions(+), 8 deletions(-) diff --git a/src/cli/kiri-cam-process.json b/src/cli/kiri-cam-process.json index 4b4db740..5969b96a 100644 --- a/src/cli/kiri-cam-process.json +++ b/src/cli/kiri-cam-process.json @@ -65,6 +65,10 @@ "camHelicalForceStartAngle": false, "camHelicalStartAngle": 0, "camHelicalOffsetOverride": 0, + "camHelicalEntry": false, + "camHelicalEntryOffset":0, + "camHelicalReverse": false, + "camHelicalClockwise": true, "camFlipAxis": "X", "camFlipOther": "", "camTabsWidth": 20, diff --git a/src/kiri/core/conf.js b/src/kiri/core/conf.js index 9bfd8cc3..698ba8b1 100644 --- a/src/kiri/core/conf.js +++ b/src/kiri/core/conf.js @@ -529,6 +529,10 @@ export const conf = { camHelicalForceStartAngle: false, camHelicalStartAngle: 0, camHelicalOffsetOverride: 0, + camHelicalEntry: false, + camHelicalEntryOffset:0, + camHelicalReverse: false, + camHelicalClockwise: true, camFlipAxis: "X", camFlipOther: "", camLaserEnable: ["M321"], diff --git a/src/kiri/mode/cam/cl-ops.js b/src/kiri/mode/cam/cl-ops.js index b4541f53..a7851652 100644 --- a/src/kiri/mode/cam/cl-ops.js +++ b/src/kiri/mode/cam/cl-ops.js @@ -535,6 +535,10 @@ export function createPopOps() { finish: 'camHelicalBottomFinish', startAng:'camHelicalStartAngle', offOver: 'camHelicalOffsetOverride', + entry: 'camHelicalEntry', + entryOffset: 'camHelicalEntryOffset', + reverse: 'camHelicalReverse', + clockwise:'camHelicalClockwise', thru: 'camHelicalThru', forceStartAng:'camHelicalForceStartAngle', fromTop: 'camHelicalFromStockTop', @@ -549,7 +553,12 @@ export function createPopOps() { startAng: UC.newInput(LANG.ch_stra_s, {title:LANG.ch_stra_l, convert:UC.toDegsFloat, bound:UC.bound(-360,360),show:() => env.poppedRec.forceStartAng}), offOver: UC.newInput(LANG.cc_offd_s, {title:LANG.cc_offd_l, convert:UC.toFloat, units:true, bound:UC.bound(0,Infinity)}), sep: UC.newBlank({class:"pop-sep"}), - finish: UC.newBoolean(LANG.ch_fini_s,undefined, { title:LANG.ch_fini_l }), + entry: UC.newBoolean(LANG.ch_entr_s,undefined, {title:LANG.ch_entr_l}), + entryOffset: UC.newInput(LANG.ch_ento_s, {title:LANG.ch_ento_l, convert:UC.toFloat, units:true, show:() => env.poppedRec.entry}), + reverse: UC.newBoolean(LANG.ch_rvrs_s,undefined, {title:LANG.ch_rvrs_l}), + clockwise:UC.newBoolean(LANG.ch_clkw_s,undefined, {title:LANG.ch_clkw_l}), + sep: UC.newBlank({class:"pop-sep"}), + finish: UC.newBoolean(LANG.ch_fini_s,undefined, { title:LANG.ch_fini_l ,show: ()=>!env.poppedRec.reverse}), forceStartAng: UC.newBoolean(LANG.ch_fsta_s, undefined, {title:LANG.ch_fsta_l }), fromTop: UC.newBoolean(LANG.cd_ftop_s,undefined, {title:LANG.cd_ftop_l}), sep: UC.newBlank({class:"pop-sep"}), diff --git a/src/kiri/mode/cam/op-helical.js b/src/kiri/mode/cam/op-helical.js index fb89bb19..5c6423cc 100644 --- a/src/kiri/mode/cam/op-helical.js +++ b/src/kiri/mode/cam/op-helical.js @@ -24,6 +24,11 @@ export class OpHelical extends CamOp { down, thru, finish, + + clockwise, + reverse, + entry, + entryOffset, } = op; let {stock} = settings @@ -59,7 +64,7 @@ export class OpHelical extends CamOp { let radAdd, zBottom = zmin - thru, - clockwise = true, + numSegs = faces.length / 2, poly = newPolygon().setOpen(); @@ -122,7 +127,8 @@ export class OpHelical extends CamOp { let toBottom = currentZ - zBottom, ofFull = toBottom / down, ofCircle = ofFull * (2 * Math.PI), - finalAngle = startAngle + ofCircle, + cwMultiplier = clockwise ? -1 : 1, + finalAngle = startAngle + (ofCircle*cwMultiplier), finalEnd = center .clone() .setZ(zBottom) @@ -134,19 +140,75 @@ export class OpHelical extends CamOp { ) ); - // console.log({down,toBottom,ofFull,ofCircle,finalAngle,finalEnd}); + console.log({down,toBottom,ofFull,ofCircle,startAngle,finalAngle,finalEnd}); //circle down to final point poly.addPoints( arcToPath(startPoint.setZ(currentZ), finalEnd, numSegs , { - clockwise: !clockwise, + clockwise, radius, center, }) ); - //if settings dictate, do a full circle at the bottom - if(finish){ + //if starting at the bottom, reverse poly + if (reverse){ + poly.reverse(); + } + + if ( entry ){ + //get first z of poly to use for entry + let firstZ = poly.first().z; + + //create new pointArray + let entry =[newPoint(0,0,0)]; + //add center point + let entryCenter = center.clone().setZ(firstZ) + + console.log({firstZ,entry,}) + + //if doing a curved enter, add more + + if ( entryOffset > 0 ){ + if(entryOffset > radius){ + + console.error("entryOffset must be less than radius of helix"); + }else{ + //calculate entry center + let lineOut = radius - entryOffset; + let centerOffset = (entryOffset**2 + 2*entryOffset*lineOut) / (2*(entryOffset + lineOut)); + //add entry points + entry.push(... + newPoint(0,-lineOut,0), + arcToPath( + newPoint(0,-lineOut,0), + newPoint(radius,0,0), + 128, + { + clockwise:false, + radius:lineOut, + center:newPoint(centerOffset,0,0) + } + ), + newPoint(radius,0,0), + ) + } + + } + //for each point + entry = entry.map(p => { + //rotate by start angle + // add to hole center + // TODO: there's totally a way to do this with a matrix + p.y *= clockwise ? 1 : -1 + p.rotate(startAngle) + return p.add(entryCenter) + }) + //append to start of poly + poly = newPolygon().setOpen().addPoints(entry).addPoints(poly.points); + } + //if doing a finish pass, do a full circle at the bottom + if(finish && !reverse){ poly.addPoints( arcToPath(finalEnd, finalEnd, numSegs, { clockwise, diff --git a/web/kiri/lang/en.js b/web/kiri/lang/en.js index 92515ff5..5ffa31b1 100644 --- a/web/kiri/lang/en.js +++ b/web/kiri/lang/en.js @@ -619,7 +619,14 @@ self.lang['en-us'] = { ch_selc_l: ["select a cylinder face", "inner holes that are too small","will be ignored."], ch_fini_s: "bottom finish pass", ch_fini_l: ["trace a circle at bottom of helix","used for hole clearing"], - + ch_entr_s: "enter from center", + ch_entr_l: ["start cut from center of cylinder","gently arcing in horisontaly", "instead of plunging"], + ch_ento_s: "center entry offset", + ch_ento_l: ["offset from path for curved entry","usually thread depth if threadmilling","in workspace units","0 for a linear entry"], + ch_rvrs_s: "reverse", + ch_rvrs_l: ["reverse helical z-axis direction","low-Z to high-Z when checked","useful for thread milling","not recomended for other operations"], + ch_clkw_s: "clockwise", + ch_clkw_l: ["reverse helical rotation around cylinder","clockwise when checked"], // CNC FLIP cf_menu: "flip",