add configurable precision for drill op

This commit is contained in:
bakedpotatolord 2025-05-27 11:19:51 -06:00
commit 212908ada5
5 changed files with 32 additions and 32 deletions

View file

@ -1192,9 +1192,7 @@ CAM.init = function(kiri, api) {
func.hover = func.selectHolesHover;
func.hoverUp = func.selectHolesHoverUp;
let settings = API.conf.get();
const {tool,mark} = poppedRec //TODO: display some visual difference if mark is selected
let diam = new CAM.Tool(settings,tool).fluteDiameter()
const widgets = kiri.api.widgets.all()
@ -1205,7 +1203,7 @@ CAM.init = function(kiri, api) {
* @returns {Mesh} the created mesh
*/
function createHoleMesh(widget,drill){
let {depth,selected} = drill
let {depth,selected, diam} = drill
let color = selected ? 0xFF0000:0x39e366
let geo = new THREE.CylinderGeometry(diam/2,diam/2,depth,20);
const material = new THREE.MeshPhongMaterial( { color } );
@ -1246,7 +1244,7 @@ CAM.init = function(kiri, api) {
})
}else{ // if no widget has cached holes
await CAM.holes( individual ? 0 : diam, async centers => {
await CAM.holes( individual,poppedRec, async centers => {
let shadow = centers.some(c=>c.shadowed)
api.hide.alert(alert)
if(shadow){
@ -1787,10 +1785,10 @@ CAM.init = function(kiri, api) {
dwell: 'camDrillDwell',
lift: 'camDrillLift',
mark: 'camDrillMark',
precision:'camDrillPrecision',
thru: 'camDrillThru',
})
drillOp.inputs = {
}).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}),
@ -1800,8 +1798,9 @@ CAM.init = function(kiri, api) {
lift: UC.newInput(LANG.cd_lift_s, {title:LANG.cd_lift_l, convert:UC.toFloat, units:true, show:() => !poppedRec.mark}),
mark: UC.newBoolean(LANG.cd_mark_s, undefined, {title:LANG.cd_mark_l}),
sep: UC.newBlank({class:"pop-sep"}),
thru: UC.newInput(LANG.cd_dtru_s, {title:LANG.cd_dtru_l, convert:UC.toFloat, units:true}),
sep: UC.newBlank({class:"pop-sep"}),
thru: UC.newInput(LANG.cd_dtru_s, {title:LANG.cd_dtru_l, convert:UC.toFloat, units:true,show:() => !poppedRec.mark}),
precision:UC.newInput(LANG.cd_prcn_s, {title:LANG.cd_prcn_l, convert:UC.toFloat, units:true,show:() => !poppedRec.mark}),
sep: UC.newBlank({class:"pop-sep", }),
actions: UC.newRow([
UC.newButton(LANG.select, ()=>func.selectHoles(true), {title:LANG.cd_seli_l}),
UC.newButton(LANG.cd_sela_s, ()=>func.selectHoles(false), {title:LANG.cd_sela_l})

View file

@ -83,21 +83,16 @@ kiri.load(api => {
};
//0 or less diameter means select all holes
CAM.holes = function(diam,onDone) {
CAM.holes = function(indiv,rec,onDone) {
kiri.client.sync();
const settings = api.conf.get();
const widgets = api.widgets.map();
let prom = new Promise((res,rej)=>{
kiri.client.send("cam_holes", { settings, diam }, output => {
return new Promise((res,rej)=>{
kiri.client.send("cam_holes", { settings, rec, indiv }, output => {
let out = kiri.codec.decode(output)
console.log(out)
onDone(out)
res(out)
});
})
return prom
}
}
@ -163,11 +158,11 @@ kiri.load(api => {
};
kiri.worker.cam_holes = async function(data, send) {
const { settings, diam } = data;
const { settings, indiv, rec } = data;
const widgets = Object.values(kiri.worker.cache);
const fresh = [];
for (let widget of widgets) {
if (await CAM.holes(settings, widget, diam)) {
if (await CAM.holes(settings, widget, indiv, rec)) {
fresh.push(widget);
}
}

View file

@ -444,7 +444,11 @@ CAM.traces = async function(settings, widget, single) {
* @param {number} diam - diameter of the drill bit
* @returns {Array} list of hole centers as objects with `x`, `y`, `z`, `depth`, and `selected` properties.
*/
CAM.holes = async function(settings, widget, diam) {
CAM.holes = async function(settings, widget, individual, rec) {
let {tool,mark,precision} = rec //TODO: display some visual difference if mark is selected
let toolDiam = new CAM.Tool(settings,tool).fluteDiameter()
let diam = individual ? 1 : toolDiam; // sets default diameter when select individual used
let proc = settings.process,
stock = settings.stock || {},
@ -462,23 +466,23 @@ CAM.holes = async function(settings, widget, diam) {
zBottom = isIndexed ? camZBottom : camZBottom - zbOff;
let slicerOpts = {flatoff: 0.01}
let slicerOpts = {flatoff: 0.001}
let slicer = new kiri.cam_slicer(widget,slicerOpts);
let zFlats = Object.keys(slicer.zFlat).map(Number).map(z=>[z]).flat()
let zFlats = Object.keys(slicer.zFlat).map(Number).map(z=>[z,z-0.002]).flat()
let intervals = slicer.interval(1,{
fit: false, off: -0.01, flats: true
})
precision = Math.max( 0, precision )
let intervals = (precision == 0) ? [] : slicer.interval(
precision,
{
fit: false, off: -0.01, flats: true
}
)
let zees = [...zFlats,...intervals]
let indices = [...new Set(zees
.map(kv => parseFloat(kv).round(5))
.filter(z => z !== null)
)]
let individual = (diam <= 0);
diam = individual ? 1 : diam; // sets default diameter when select individual used
let centerDiff = diam * 0.1,
area = (diam/2) * (diam/2) * Math.PI,
circles = [],
@ -494,7 +498,7 @@ CAM.holes = async function(settings, widget, diam) {
for (let slice of slices) {
for(let top of slice.tops){
// console.log("slicing",slice.z,top)
slice.shadow = CAM.shadowAt(widget,slice.z, 0)
slice.shadow = CAM.shadowAt(widget, slice.z, 0)
let inner = top.inner;
if (!inner) { //no holes
continue;
@ -537,7 +541,6 @@ CAM.holes = async function(settings, widget, diam) {
for (let c of circles) {
let overlapping = c.overlapping
.sort((a,b) => b.z - a.z)
let last = overlapping.shift();
while (overlapping.length) {
@ -555,9 +558,9 @@ CAM.holes = async function(settings, widget, diam) {
}
if (last.depth != 0) drills.push(last) //add last circle
}
drills.forEach( h=>{
delete h.overlapping //for encoding
h.diam = toolDiam // for mesh generation
h.selected = (!individual && Math.abs(h.area - area) <= area * 0.05 ); //for same size selection
})

View file

@ -521,6 +521,7 @@ const conf = exports({
camDrillLift: 2,
camDrillMark: false,
camDrillThru: 5,
camDrillPrecision: 1,
camDrillingOn: false,
camRegisterSpeed: 1000,
camRegisterThru: 5,

View file

@ -599,6 +599,8 @@ self.kiri.lang['en-us'] = {
cd_dtru_l: ["additional drill depth below part bottom","overrides global z thru","0 to disable"],
cd_mark_s: "marking",
cd_mark_l: ["only mark holes, do not drill out","the step down setting is used","to determine how deep to mark"],
cd_prcn_s: "precision",
cd_prcn_l: ["distance between slices","to search for holes","in workspace units","lower is slower and","uses more memory","0 = only flats"],
cd_seli_l: ["individually select holes","to drill"],
cd_sela_s: "Select Matching Diameter",