relax drill circularity for lower poly. add ; bc no ts syntax
This commit is contained in:
parent
ae2a669c4c
commit
35660d39cf
3 changed files with 28 additions and 26 deletions
|
|
@ -1115,7 +1115,7 @@ self.kiri.load(api => {
|
||||||
]),
|
]),
|
||||||
h.div({ class: "var-row f-grow" }, [
|
h.div({ class: "var-row f-grow" }, [
|
||||||
h.label('active'),
|
h.label('active'),
|
||||||
h.input({ id: "bbl_file_active", class: "t-left", readonly })
|
h.input({ id: "bbl_file_active", class: "t-left", style: "width: 20ch; max-width: 20ch", readonly })
|
||||||
]),
|
]),
|
||||||
h.div({ class: "pop-sep" }),
|
h.div({ class: "pop-sep" }),
|
||||||
h.div({ class: "f-row gap3 f-grow" }, [
|
h.div({ class: "f-row gap3 f-grow" }, [
|
||||||
|
|
|
||||||
|
|
@ -652,7 +652,7 @@ export class Polygon {
|
||||||
td += d;
|
td += d;
|
||||||
if (ap.length === 1 && td >= pe1) {
|
if (ap.length === 1 && td >= pe1) {
|
||||||
ap.push(np);
|
ap.push(np);
|
||||||
} else if (ap.length === 2 && td >= pe2) {
|
} else if (ap.length === 2 && (td >= pe2 || i >= l)) {
|
||||||
ap.push(np);
|
ap.push(np);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ export async function cam_slice(settings, widget, onupdate, ondone) {
|
||||||
bottom_z, bottom_cut
|
bottom_z, bottom_cut
|
||||||
}, 3);
|
}, 3);
|
||||||
|
|
||||||
console.log({ track, bounds, stock, workarea });
|
// console.log({ track, bounds, stock, workarea });
|
||||||
|
|
||||||
return structuredClone(workarea);
|
return structuredClone(workarea);
|
||||||
};
|
};
|
||||||
|
|
@ -660,9 +660,9 @@ export async function holes(settings, widget, individual, rec, onProgress) {
|
||||||
// keeps the z bottom relative to the part when z align changes
|
// keeps the z bottom relative to the part when z align changes
|
||||||
zBottom = isIndexed ? camZBottom : camZBottom - zbOff;
|
zBottom = isIndexed ? camZBottom : camZBottom - zbOff;
|
||||||
|
|
||||||
let slicerOpts = { flatoff: 0.001 }
|
let slicerOpts = { flatoff: 0.001 };
|
||||||
let slicer = new cam_slicer(widget, slicerOpts);
|
let slicer = new cam_slicer(widget, slicerOpts);
|
||||||
let zFlats = Object.keys(slicer.zFlat).map(Number).map(z => [z, z - 0.002]).flat()
|
let zFlats = Object.keys(slicer.zFlat).map(Number).map(z => [z, z - 0.002]).flat();
|
||||||
|
|
||||||
precision = Math.max(0, precision)
|
precision = Math.max(0, precision)
|
||||||
let intervals = (precision == 0) ? [] : slicer.interval(
|
let intervals = (precision == 0) ? [] : slicer.interval(
|
||||||
|
|
@ -672,11 +672,11 @@ export async function holes(settings, widget, individual, rec, onProgress) {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
let zees = [...zFlats, ...intervals]
|
let zees = [...zFlats, ...intervals];
|
||||||
let indices = [...new Set(zees
|
let indices = [...new Set(zees
|
||||||
.map(kv => parseFloat(kv).round(5))
|
.map(kv => parseFloat(kv).round(5))
|
||||||
.filter(z => z !== null)
|
.filter(z => z !== null)
|
||||||
)]
|
)];
|
||||||
let centerDiff = diam * 0.1,
|
let centerDiff = diam * 0.1,
|
||||||
area = (diam / 2) * (diam / 2) * Math.PI,
|
area = (diam / 2) * (diam / 2) * Math.PI,
|
||||||
circles = [],
|
circles = [],
|
||||||
|
|
@ -692,19 +692,20 @@ export async function holes(settings, widget, individual, rec, onProgress) {
|
||||||
for (let [i, slice] of slices.entries()) {
|
for (let [i, slice] of slices.entries()) {
|
||||||
for (let top of slice.tops) {
|
for (let top of slice.tops) {
|
||||||
// console.log("slicing",slice.z,top)
|
// console.log("slicing",slice.z,top)
|
||||||
slice.shadow = computeShadowAt(widget, slice.z, 0)
|
slice.shadow = computeShadowAt(widget, slice.z, 0);
|
||||||
let inner = top.inner;
|
let inner = top.inner;
|
||||||
if (!inner) { //no holes
|
if (!inner) { //no holes
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (let poly of inner) {
|
for (let poly of inner) {
|
||||||
if (poly.points.length < 7) continue;
|
if (poly.points.length < 7) continue;
|
||||||
|
|
||||||
let center = poly.calcCircleCenter();
|
let center = poly.calcCircleCenter();
|
||||||
center.area = poly.area();
|
center.area = poly.area();
|
||||||
center.overlapping = [center]
|
center.overlapping = [center];
|
||||||
center.depth = 0;
|
center.depth = 0;
|
||||||
// console.log("center",center)
|
// console.log("center",center)
|
||||||
if (poly.circularity() < 0.985) {
|
if (poly.circularity() < 0.98) {
|
||||||
// if not circular, don't add to holes
|
// if not circular, don't add to holes
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -715,7 +716,7 @@ export async function holes(settings, widget, individual, rec, onProgress) {
|
||||||
}
|
}
|
||||||
let overlap = false;
|
let overlap = false;
|
||||||
for (let [i, circle] of circles.entries()) {
|
for (let [i, circle] of circles.entries()) {
|
||||||
let dist = circle.distTo2D(center)
|
let dist = circle.distTo2D(center);
|
||||||
|
|
||||||
// //if on the same xy point,
|
// //if on the same xy point,
|
||||||
if (dist <= centerDiff) {
|
if (dist <= centerDiff) {
|
||||||
|
|
@ -729,19 +730,19 @@ export async function holes(settings, widget, individual, rec, onProgress) {
|
||||||
if (!overlap) circles.push(center);
|
if (!overlap) circles.push(center);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onProgress(0.5 + (i / slices.length * 0.25), "recognize circles")
|
onProgress(0.5 + (i / slices.length * 0.25), "recognize circles");
|
||||||
}
|
}
|
||||||
|
|
||||||
let drills = []
|
let drills = [];
|
||||||
|
|
||||||
for (let [i, c] of circles.entries()) {
|
for (let [i, c] of circles.entries()) {
|
||||||
let overlapping = c.overlapping
|
let overlapping = c.overlapping;
|
||||||
|
|
||||||
let last = overlapping.shift();
|
let last = overlapping.shift();
|
||||||
while (overlapping.length) {
|
while (overlapping.length) {
|
||||||
let circ = overlapping.shift();
|
let circ = overlapping.shift();
|
||||||
let aveArea = (circ.area + last.area) / 2;
|
let aveArea = (circ.area + last.area) / 2;
|
||||||
let areaDelta = Math.abs(circ.area - last.area)
|
let areaDelta = Math.abs(circ.area - last.area);
|
||||||
if (areaDelta < aveArea * 0.05) { // if area delta less than 5% of average area
|
if (areaDelta < aveArea * 0.05) { // if area delta less than 5% of average area
|
||||||
//keep top circle selected
|
//keep top circle selected
|
||||||
last.depth = last.z - circ.z;
|
last.depth = last.z - circ.z;
|
||||||
|
|
@ -751,24 +752,25 @@ export async function holes(settings, widget, individual, rec, onProgress) {
|
||||||
last = circ;
|
last = circ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (last.depth != 0) drills.push(last) //add last circle
|
if (last.depth != 0) drills.push(last); // add last circle
|
||||||
onProgress(0.75 + (i / circles.length * 0.25), "assemble holes")
|
onProgress(0.75 + (i / circles.length * 0.25), "assemble holes");
|
||||||
}
|
}
|
||||||
drills.forEach(h => {
|
drills.forEach(h => {
|
||||||
if (rec.fromTop) {
|
if (rec.fromTop) {
|
||||||
// set z top if selected
|
// set z top if selected
|
||||||
h.depth += wztop - h.z
|
h.depth += wztop - h.z;
|
||||||
h.z = wztop
|
h.z = wztop;
|
||||||
}
|
}
|
||||||
delete h.overlapping //for encoding
|
delete h.overlapping; //for encoding
|
||||||
h.diam = toolDiam // for mesh generation
|
h.diam = toolDiam; // for mesh generation
|
||||||
h.selected = (!individual && Math.abs(h.area - area) <= area * 0.05); //for same size selection
|
h.selected = (!individual && Math.abs(h.area - area) <= area * 0.05); // for same size selection
|
||||||
})
|
})
|
||||||
|
|
||||||
// console.log("unfiltered circles",circles)
|
console.log("unfiltered circles",circles);
|
||||||
// console.log("drills",drills)
|
console.log("drills",drills);
|
||||||
drills = drills.filter(drill => drill.depth > 0)
|
|
||||||
widget.shadowedDrills = shadowedDrills
|
drills = drills.filter(drill => drill.depth > 0);
|
||||||
|
widget.shadowedDrills = shadowedDrills;
|
||||||
widget.drills = drills;
|
widget.drills = drills;
|
||||||
return drills;
|
return drills;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue