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 { newPoint, newPolygon } = base;
const { driver } = kiri; const { driver } = kiri;
const { CAM } = driver; const { CAM } = driver;
const DEG2RAD = Math.PI / 180;
const RAD2DEG = 180 / Math.PI;
let isAnimate, let isAnimate,
isArrange, isArrange,
@ -609,7 +611,7 @@ CAM.init = function(kiri, api) {
for (let widget of API.widgets.all()) { for (let widget of API.widgets.all()) {
widget.setAxisIndex(isPreview || !isIndexed ? 0 : -index); widget.setAxisIndex(isPreview || !isIndexed ? 0 : -index);
} }
currentIndex = isIndexed && !isPreview ? index * (Math.PI / 180) : 0; currentIndex = isIndexed && !isPreview ? index * DEG2RAD : 0;
updateStock(); updateStock();
}); });
@ -809,7 +811,7 @@ CAM.init = function(kiri, api) {
func.clearPops(); func.clearPops();
alert = api.show.alert("analyzing surfaces...", 1000); alert = api.show.alert("analyzing surfaces...", 1000);
let surfaces = poppedRec.surfaces; let surfaces = poppedRec.surfaces;
CAM.surface_prep(() => { CAM.surface_prep(currentIndex * RAD2DEG, () => {
api.hide.alert(alert); api.hide.alert(alert);
alert = api.show.alert("[esc] cancels surface editing"); alert = api.show.alert("[esc] cancels surface editing");
for (let [wid, arr] of Object.entries(surfaces)) { 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 => { 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; poppedRec.absolute = true;
func.opRender(); func.opRender();
updateStock(); updateStock();

View file

@ -25,10 +25,10 @@ CAM.process = {
kiri.load(api => { kiri.load(api => {
if (kiri.client) { if (kiri.client) {
CAM.surface_prep = function(ondone) { CAM.surface_prep = function(index, ondone) {
kiri.client.sync(); kiri.client.sync();
const settings = api.conf.get(); const settings = api.conf.get();
kiri.client.send("cam_surfaces", { settings }, output => { kiri.client.send("cam_surfaces", { settings, index }, output => {
ondone(output); ondone(output);
}); });
}; };
@ -78,10 +78,11 @@ kiri.load(api => {
} }
if (kiri.worker) { if (kiri.worker) {
CAM.surface_prep = function(widget) { CAM.surface_prep = function(widget, index) {
if (!widget.tool) { if (!widget.tool) {
let tool = widget.tool = new mesh.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) { kiri.worker.cam_surfaces = function(data, send) {
const { settings } = data; const { settings, index } = data;
const widgets = Object.values(kiri.worker.cache); const widgets = Object.values(kiri.worker.cache);
for (let widget of widgets) { 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({}); send.done({});
}; };

View file

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

View file

@ -238,7 +238,7 @@ mesh.tool = class MeshTool {
while (check.length) { while (check.length) {
const face = check.shift(); const face = check.shift();
const froot = face * 6; const froot = face * 6;
if (filterZ !== undefined && norms[froot +2] < filterZ) { if (filterZ !== undefined && norms[froot + 2] < filterZ) {
continue; continue;
} }
const fadj = this.getAdjacentFaces(face); const fadj = this.getAdjacentFaces(face);