fix rendering of cnc tool shafts

This commit is contained in:
Stewart Allen 2025-02-27 14:19:03 -05:00
commit b67a823b3b
2 changed files with 9 additions and 8 deletions

View file

@ -640,19 +640,22 @@ kiri.load(() => {
const srad = tool.shaftDiameter() / 2;
const flen = tool.fluteLength() || 15;
const frad = toolRadius = tool.fluteDiameter() / 2;
const tlen = slen + flen; // total tool length
let { cylinder, sphere } = Instance.Manifold;
let mesh;
if (tool.isBallMill()) {
mesh = cylinder(flen + slen - frad * 2, frad, frad, 20, true)
.add(sphere(frad, 20).translate(0, 0, -(flen + slen - frad * 2)/2));
mesh = cylinder(tlen - frad * 2, frad, frad, 20, true)
.add(sphere(frad, 20).translate(0, 0, -(tlen - frad * 2)/2))
.add(cylinder(slen, srad, srad, 20, true).translate(0, 0, flen/2));
} else if (tool.isTaperMill()) {
const trad = Math.max(tool.tipDiameter() / 2, 0.001);
mesh = cylinder(slen, srad, srad, 20, true).translate(0, 0, slen/2)
.add(cylinder(flen, trad, frad, 20, true).translate(0, 0, -flen/2));
} else {
mesh = cylinder(flen + slen, frad, frad, 20, true);
mesh = cylinder(tlen, frad, frad, 20, true)
.add(cylinder(slen, srad, srad, 20, true).translate(0, 0, flen/2));
}
mesh = mesh.translate(0, 0, (flen + slen - stockZ) / 2);
mesh = mesh.translate(0, 0, (tlen - stockZ) / 2);
const raw = mesh.getMesh();
const vertex = raw.vertProperties;
const index = raw.triVerts;

View file

@ -102,8 +102,7 @@ class Tool {
generateProfile(resolution) {
// generate tool profile
let type = this.getType(),
ball = this.isBallMill(),
let ball = this.isBallMill(),
taper = this.isTaperMill(),
tip_diameter = this.tipDiameter(),
shaft_offset = this.fluteLength(),
@ -134,7 +133,6 @@ class Tool {
dist_from_center = Math.sqrt(dx * dx + dy * dy);
if (dist_from_center <= flute_radius_pix_float) {
maxo = Math.max(maxo, dx, dy);
// console.log({x,y,dx,dy,dist:dist_from_center,ln:dbl.length})
// flute offset points
let z_offset = 0;
if (ball) {
@ -147,7 +145,7 @@ class Tool {
toolOffset.push(dx, dy, z_offset);
} else if (shaft_offset && larger_shaft && dist_from_center <= shaft_radius_pix_float) {
// shaft offset points
// toolOffset.push(dx, dy, -shaft_offset);
toolOffset.push(dx, dy, -shaft_offset);
}
}
}