fix tab cuts and stock clip to in roughing

This commit is contained in:
Stewart Allen 2025-11-16 13:11:39 -05:00
commit ce444c2b33
4 changed files with 45 additions and 35 deletions

View file

@ -19,6 +19,7 @@ let meshes = {},
speed, speed,
origin, origin,
color = 0, color = 0,
dark = false,
A2R = Math.PI / 180; A2R = Math.PI / 180;
export function animate_clear2(api) { export function animate_clear2(api) {
@ -35,6 +36,7 @@ export function animate_clear2(api) {
export function animate2(api, delay) { export function animate2(api, delay) {
let alert = api.alerts.show("building animation"); let alert = api.alerts.show("building animation");
let settings = api.conf.get(); let settings = api.conf.get();
dark = settings.controller.dark;
client.animate_setup2(settings, data => { client.animate_setup2(settings, data => {
handleUpdate(data); handleUpdate(data);
if (data) { if (data) {
@ -89,7 +91,7 @@ Object.assign(client, {
animate_setup2(settings, ondone) { animate_setup2(settings, ondone) {
initPathMesh(); initPathMesh();
color = settings.controller.dark ? 0x888888 : 0; color = dark ? 0x888888 : 0;
material = material ?? new THREE.MeshPhongMaterial({ material = material ?? new THREE.MeshPhongMaterial({
flatShading: true, flatShading: true,
transparent: false, transparent: false,
@ -113,7 +115,7 @@ function initPathMesh() {
max = 10000, max = 10000,
rot = new THREE.Euler(0,0,0), rot = new THREE.Euler(0,0,0),
geo = new THREE.BufferGeometry(), geo = new THREE.BufferGeometry(),
mat = new THREE.LineBasicMaterial({ color: 0xffff00 }), mat = new THREE.LineBasicMaterial({ color: dark ? 0xffff00 : 0x771100 }),
pos = new Float32Array(max * 6), pos = new Float32Array(max * 6),
lines = new THREE.LineSegments(geo, mat), lines = new THREE.LineSegments(geo, mat),
vec = new THREE.Vector3(0,0,0), vec = new THREE.Vector3(0,0,0),

View file

@ -17,9 +17,10 @@ class OpOutline extends CamOp {
async slice(progress) { async slice(progress) {
let { op, state } = this; let { op, state } = this;
let { settings, widget, slicer, addSlices, tshadow, thruHoles, unsafe, color } = state; let { settings, slicer, addSlices, tshadow, thruHoles, unsafe, color } = state;
let { updateToolDiams, tabs, cutTabs, cutPolys, workarea, zMax, shadowAt } = state; let { updateToolDiams, tabs, cutTabs, cutPolys, workarea, zMax, shadowAt } = state;
let { process, stock } = settings; let { process, stock } = settings;
let { controller } = settings;
if (op.down <= 0) { if (op.down <= 0) {
throw `invalid step down "${op.down}"`; throw `invalid step down "${op.down}"`;
@ -191,7 +192,7 @@ class OpOutline extends CamOp {
tabs.forEach(tab => { tabs.forEach(tab => {
tab.off = POLY.expand([tab.poly], toolDiam / 2).flat(); tab.off = POLY.expand([tab.poly], toolDiam / 2).flat();
}); });
offset = cutTabs(tabs, offset, slice.z); offset = cutTabs(tabs, offset);
} }
if (process.camStockClipTo && stock.x && stock.y && stock.center) { if (process.camStockClipTo && stock.x && stock.y && stock.center) {
@ -208,9 +209,12 @@ class OpOutline extends CamOp {
// project empty up and render // project empty up and render
for (let slice of slices) { for (let slice of slices) {
if (false) slice.output() if (controller.devel) slice.output()
.setLayer("slice", {line: 0xaaaa00}, false) .setLayer("slice", {line: 0xaaaa00}, false)
.addPolys(slice.topPolys()) .addPolys(slice.topPolys())
if (controller.devel) slice.output()
.setLayer("shadow", {line: 0x557799}, false)
.addPolys(slice.shadow)
slice.output() slice.output()
.setLayer(state.layername, {face: color, line: color}) .setLayer(state.layername, {face: color, line: color})
.addPolys(slice.camLines); .addPolys(slice.camLines);

View file

@ -19,7 +19,7 @@ class OpRough extends CamOp {
let { updateToolDiams, thruHoles, tabs, cutTabs, cutPolys } = state; let { updateToolDiams, thruHoles, tabs, cutTabs, cutPolys } = state;
let { ztOff, zMax, shadowAt, isIndexed} = state; let { ztOff, zMax, shadowAt, isIndexed} = state;
let { workarea } = state; let { workarea } = state;
let { process, stock } = settings; let { controller, process, stock } = settings;
if (op.down <= 0) { if (op.down <= 0) {
throw `invalid step down "${op.down}"`; throw `invalid step down "${op.down}"`;
@ -206,20 +206,6 @@ class OpRough extends CamOp {
} }
} }
if (tabs) {
tabs.forEach(tab => {
tab.off = POLY.expand([tab.poly], toolDiam / 2).flat();
});
offset = cutTabs(tabs, offset, slice.z);
}
if (!offset) return;
if (process.camStockClipTo && stock.x && stock.y && stock.center) {
let rect = newPolygon().centerRectangle(stock.center, stock.x, stock.y);
offset = cutPolys([rect], offset, slice.z, true);
}
// elimate double inset on inners // elimate double inset on inners
offset.forEach(op => { offset.forEach(op => {
if (op.inner) { if (op.inner) {
@ -236,24 +222,42 @@ class OpRough extends CamOp {
} }
}); });
if (process.camStockClipTo && stock.x && stock.y && stock.center) {
let rect = newPolygon().centerRectangle(stock.center, stock.x + 0.001, stock.y + 0.001);
offset = cutPolys([rect], offset, slice.z, true);
}
if (tabs) {
tabs.forEach(tab => {
tab.off = POLY.expand([tab.poly], toolDiam / 2).flat();
});
offset = cutTabs(tabs, offset);
}
if (!offset) return;
slice.camLines = offset; slice.camLines = offset;
if (roughLeaveZ) { if (roughLeaveZ) {
// offset roughing in Z as well to minimize // offset roughing in Z as well to minimize tool marks on curved surfaces
// tool marks on curved surfaces
// const roughLeaveZ = 1 * Math.min(roughDown, roughLeave / 2); // const roughLeaveZ = 1 * Math.min(roughDown, roughLeave / 2);
slice.camLines.forEach(p => { for (let poly of slice.camLines) {
p.setZ(p.getZ() + roughLeaveZ); for (let point of poly.points) point.z += roughLeaveZ;
}); }
}
if (controller.devel) {
slice.output()
.setLayer("tabs clip", {line: 0xaa00aa}, true)
.addPolys(tabs.map(tab => tab.off).flat());
slice.output()
.setLayer("slice", {line: 0xaaaa00}, true)
.addPolys(slice.topPolys())
// .setLayer("top shadow", {line: 0x0000aa})
// .addPolys(tshadow)
// .setLayer("rough shadow", {line: 0x00aa00})
// .addPolys(shadow)
.setLayer("shadow clip", {line: 0xaa0000})
.addPolys(shell);
} }
if (false) slice.output()
.setLayer("slice", {line: 0xaaaa00}, true)
.addPolys(slice.topPolys())
// .setLayer("top shadow", {line: 0x0000aa})
// .addPolys(tshadow)
// .setLayer("rough shadow", {line: 0x00aa00})
// .addPolys(shadow)
.setLayer("rough shell", {line: 0xaa0000})
.addPolys(shell);
progress(0.5 + 0.5 * (index / slices.length)); progress(0.5 + 0.5 * (index / slices.length));
}); });

View file

@ -801,7 +801,7 @@ function cutTabs(tabs, offset) {
function cutPolys(polys, offset) { function cutPolys(polys, offset) {
let noff = []; let noff = [];
offset.forEach(op => noff.appendAll(op.cut(POLY.union(polys, 0, true)))); offset.forEach(op => noff.appendAll( op.cut(POLY.union(polys, 0, true), true) ));
return healPolys(noff); return healPolys(noff);
} }