work on pocketing, face selection with indexed A axis

This commit is contained in:
Stewart Allen 2022-11-03 22:42:12 -04:00
commit d7b70c5c53
4 changed files with 38 additions and 28 deletions

View file

@ -11,6 +11,8 @@ const { base, kiri } = root;
const { newPoint, newPolygon } = base;
const { driver } = kiri;
const { CAM } = driver;
const DEG2RAD = Math.PI / 180;
const RAD2DEG = 180 / Math.PI;
let isAnimate,
isArrange,
@ -609,7 +611,7 @@ CAM.init = function(kiri, api) {
for (let widget of API.widgets.all()) {
widget.setAxisIndex(isPreview || !isIndexed ? 0 : -index);
}
currentIndex = isIndexed && !isPreview ? index * (Math.PI / 180) : 0;
currentIndex = isIndexed && !isPreview ? index * DEG2RAD : 0;
updateStock();
});
@ -809,7 +811,7 @@ CAM.init = function(kiri, api) {
func.clearPops();
alert = api.show.alert("analyzing surfaces...", 1000);
let surfaces = poppedRec.surfaces;
CAM.surface_prep(() => {
CAM.surface_prep(currentIndex * RAD2DEG, () => {
api.hide.alert(alert);
alert = api.show.alert("[esc] cancels surface editing");
for (let [wid, arr] of Object.entries(surfaces)) {
@ -1393,7 +1395,7 @@ CAM.init = function(kiri, api) {
}
api.event.on('tool.mesh.face-normal', normal => {
poppedRec.degrees = (Math.atan2(normal.y, normal.z) * (180 / Math.PI)).round(2);
poppedRec.degrees = (Math.atan2(normal.y, normal.z) * RAD2DEG).round(2);
poppedRec.absolute = true;
func.opRender();
updateStock();

View file

@ -25,10 +25,10 @@ CAM.process = {
kiri.load(api => {
if (kiri.client) {
CAM.surface_prep = function(ondone) {
CAM.surface_prep = function(index, ondone) {
kiri.client.sync();
const settings = api.conf.get();
kiri.client.send("cam_surfaces", { settings }, output => {
kiri.client.send("cam_surfaces", { settings, index }, output => {
ondone(output);
});
};
@ -78,10 +78,11 @@ kiri.load(api => {
}
if (kiri.worker) {
CAM.surface_prep = function(widget) {
CAM.surface_prep = function(widget, index) {
if (!widget.tool) {
let tool = widget.tool = new mesh.tool();
tool.index(widget.getVertices().array);
let translate = index ? true : false;
tool.index(widget.getGeoVertices(true, translate));
}
};
@ -91,10 +92,17 @@ kiri.load(api => {
};
kiri.worker.cam_surfaces = function(data, send) {
const { settings } = data;
const { settings, index } = data;
const widgets = Object.values(kiri.worker.cache);
for (let widget of widgets) {
CAM.surface_prep(widget);
if (index) {
widget.setIndexed(1);
widget.setAxisIndex(-index);
} else {
widget.setIndexed(0);
widget.setAxisIndex(0);
}
CAM.surface_prep(widget, index);
}
send.done({});
};

View file

@ -266,22 +266,22 @@ class OpRough extends CamOp {
}
// inset or eliminate thru holes from shadow
// shadow = POLY.flatten(shadow.clone(true), [], true);
// thruHoles.forEach(hole => {
// shadow = shadow.map(p => {
// if (p.isEquivalent(hole)) {
// // eliminate thru holes when roughing voids enabled
// if (op.voids) {
// return undefined;
// }
// let po = POLY.offset([p], -(toolDiam / 2 + roughLeave + 0.01));
// return po ? po[0] : undefined;
// } else {
// return p;
// }
// }).filter(p => p);
// });
// shadow = POLY.nest(shadow);
shadow = POLY.flatten(shadow.clone(true), [], true);
thruHoles.forEach(hole => {
shadow = shadow.map(p => {
if (p.isEquivalent(hole)) {
// eliminate thru holes when roughing voids enabled
// if (op.voids) {
// return undefined;
// }
let po = POLY.offset([p], -(toolDiam / 2 + roughLeave + 0.01));
return po ? po[0] : undefined;
} else {
return p;
}
}).filter(p => p);
});
shadow = POLY.nest(shadow);
if (op.voids) {
for (let s of shadow) s.inner = undefined;
}
@ -1118,8 +1118,8 @@ class OpPocket extends CamOp {
}
}
let surfaces = op.surfaces[widget.id] || [];
// let vert = widget.getGeoVertices(true,true).map(v => v.round(4));
let vert = widget.getVertices().array.map(v => v.round(4));
let vert = widget.getGeoVertices(true,true).map(v => v.round(4));
// let vert = widget.getVertices().array.map(v => v.round(4));
let outline = [];
let faces = CAM.surface_find(widget, surfaces);
let zmin = Infinity;