add step angle option for lathe (perhaps determine heuristically in the future)

This commit is contained in:
Stewart Allen 2023-02-13 14:46:15 -05:00
commit 47bd68ca0b
6 changed files with 36 additions and 32 deletions

View file

@ -15,6 +15,7 @@ const { base } = root;
const { config, util, polygons, newBounds, newPoint } = base; const { config, util, polygons, newBounds, newPoint } = base;
const POLY = polygons, const POLY = polygons,
XAXIS = new THREE.Vector3(1,0,0),
DEG2RAD = Math.PI / 180, DEG2RAD = Math.PI / 180,
clib = self.ClipperLib, clib = self.ClipperLib,
clip = clib.Clipper, clip = clib.Clipper,
@ -967,6 +968,19 @@ class Polygon {
return [this.first().key, this.last().key, this.length].join('~~'); return [this.first().key, this.last().key, this.length].join('~~');
} }
applyRotations() {
for (let point of this.points) {
if (point.a) {
let p2 = new THREE.Vector3(point.x, point.y, point.z)
.applyAxisAngle(XAXIS, point.a * DEG2RAD);
point.x = p2.x;
point.y = p2.y;
point.z = p2.z;
}
}
return this;
}
/** /**
* set this polygon's winding in alignment with the supplied polygon * set this polygon's winding in alignment with the supplied polygon
*/ */

View file

@ -1339,6 +1339,7 @@ CAM.init = function(kiri, api) {
tool: 'camLatheTool', tool: 'camLatheTool',
spindle: 'camLatheSpindle', spindle: 'camLatheSpindle',
step: 'camLatheOver', step: 'camLatheOver',
angle: 'camLatheAngle',
rate: 'camLatheSpeed', rate: 'camLatheSpeed',
tolerance: 'camTolerance', tolerance: 'camTolerance',
axis: 'X' axis: 'X'
@ -1349,6 +1350,7 @@ CAM.init = function(kiri, api) {
spindle: UC.newInput(LANG.cc_spnd_s, {title:LANG.cc_spnd_l, convert:UC.toInt, show:hasSpindle}), spindle: UC.newInput(LANG.cc_spnd_s, {title:LANG.cc_spnd_l, convert:UC.toInt, show:hasSpindle}),
rate: UC.newInput(LANG.cc_feed_s, {title:LANG.cc_feed_l, convert:UC.toInt, units:true}), rate: UC.newInput(LANG.cc_feed_s, {title:LANG.cc_feed_l, convert:UC.toInt, units:true}),
step: UC.newInput(LANG.cc_sovr_s, {title:LANG.cc_sovr_l, convert:UC.toFloat, bound:UC.bound(0.01,10.0)}), step: UC.newInput(LANG.cc_sovr_s, {title:LANG.cc_sovr_l, convert:UC.toFloat, bound:UC.bound(0.01,10.0)}),
angle: UC.newInput(LANG.cc_sang_s, {title:LANG.cc_sang_l, convert:UC.toFloat, bound:UC.bound(0.01,10.0)}),
tolerance: UC.newInput(LANG.ou_toll_s, {title:LANG.ou_toll_l, convert:UC.toFloat, bound:UC.bound(0,10.0), units:true, round:4}), tolerance: UC.newInput(LANG.ou_toll_s, {title:LANG.ou_toll_l, convert:UC.toFloat, bound:UC.bound(0,10.0), units:true, round:4}),
}; };

View file

@ -857,8 +857,8 @@ class OpLathe extends CamOp {
let { settings } = state; let { settings } = state;
let { setTool, setSpindle, setPrintPoint } = ops; let { setTool, setSpindle, setPrintPoint } = ops;
let { camOut, newLayer, polyEmit, printPoint, lastPoint } = ops; let { camOut, newLayer, printPoint } = ops;
let { bounds, zmax } = ops; let { zmax } = ops;
let toolDiam = new CAM.Tool(settings, op.tool).fluteDiameter(); let toolDiam = new CAM.Tool(settings, op.tool).fluteDiameter();
let stepover = toolDiam * op.step * 2; let stepover = toolDiam * op.step * 2;

View file

@ -47,7 +47,8 @@ class Topo4 {
zMin = min.z + 0.0001, zMin = min.z + 0.0001,
tolerance = op.tolerance, tolerance = op.tolerance,
resolution = tolerance ? tolerance : 1 / Math.sqrt(density / (span.x * span.y)), resolution = tolerance ? tolerance : 1 / Math.sqrt(density / (span.x * span.y)),
step = this.step = (tool.traceOffset() * 2) * op.step; step = this.step = (tool.traceOffset() * 2) * op.step,
angle = this.angle = op.angle || 1;
if (tolerance === 0) { if (tolerance === 0) {
console.log(widget.id, 'topo4 auto tolerance', resolution.round(4)); console.log(widget.id, 'topo4 auto tolerance', resolution.round(4));
@ -108,7 +109,7 @@ class Topo4 {
index++; index++;
} }
slices.push(slice); slices.push(slice);
console.log({ shards, range, step, slices }); // console.log({ shards, range, step, slices });
if (kiri.minions.running > 1) { if (kiri.minions.running > 1) {
return await this.sliceMinions(onupdate); return await this.sliceMinions(onupdate);
@ -265,11 +266,10 @@ class Topo4 {
async latheWorker(onupdate) { async latheWorker(onupdate) {
const { sliced, tool } = this; const { sliced, tool } = this;
const steps = 100; const rota = this.angle * DEG2RAD;
const rota = (360 / steps) * DEG2RAD; const steps = (Math.PI * 2) / rota;
const axis = new THREE.Vector3(1, 0, 0); const axis = new THREE.Vector3(1, 0, 0);
const mrot = new THREE.Matrix4().makeRotationAxis(axis, rota); const mrot = new THREE.Matrix4().makeRotationAxis(axis, rota);
const slices = sliced.map(s => { return { z: s.z, lines: s.shared } }); const slices = sliced.map(s => { return { z: s.z, lines: s.shared } });
const paths = []; const paths = [];
const recs = []; const recs = [];
@ -295,36 +295,21 @@ class Topo4 {
} }
for (let rec of recs) { for (let rec of recs) {
const { angle, degrees, heights } = rec; const { degrees, heights } = rec;
const points = heights.toFloat32(); [...heights].group(3).forEach((a,i) => {
paths[i].camLines[0].push( newPoint(a[0], a[1], a[2]).setA(degrees) );
const poly = newPolygon().setOpen().addPoints( });
[...points].group(3).map((a,i) => {
let p = newPoint(a[0], a[1], a[2]).setA(degrees)
paths[i].camLines[0].push(p);
return p;
})
);
rotatePoints(points, new THREE.Matrix4().makeRotationAxis(axis, angle));
continue;
// const slice = newSlice();
// slice.camLines = [ poly ];
// const rndr = newPolygon().setOpen().addPoints(
// [...points].group(3).map(a => newPoint(a[0], a[1], a[2]))
// );
// slice.output()
// .setLayer("lathe", { line: 0xffff00 })
// .addPoly(rndr);
// paths.push(slice);
} }
for (let slice of paths) { for (let slice of paths) {
const poly = slice.camLines[0];
if (!poly.length) {
continue;
}
slice.camLines[0].push(poly.points[0].clone());
slice.output() slice.output()
.setLayer("lathe", { line: 0xffff00 }) .setLayer("lathe", { line: 0xffff00 })
.addPoly(slice.camLines[0]); .addPoly(poly.clone().applyRotations());
} }
// console.log({ tool, slices, paths }); // console.log({ tool, slices, paths });

View file

@ -505,6 +505,7 @@ const conf = exports({
camLatheTool: 1000, camLatheTool: 1000,
camLatheSpindle: 1000, camLatheSpindle: 1000,
camLatheOver: 0.1, camLatheOver: 0.1,
camLatheAngle: 1,
camLatheSpeed: 500, camLatheSpeed: 500,
camTolerance: 0, camTolerance: 0,
camTraceTool: 1000, camTraceTool: 1000,

View file

@ -444,6 +444,8 @@ self.kiri.lang['en-us'] = {
cc_spnd_l: ["spindle speed in","revolutions / minute"], cc_spnd_l: ["spindle speed in","revolutions / minute"],
cc_sovr_s: "step over", cc_sovr_s: "step over",
cc_sovr_l: ["a fraction of tool diameter between 0 and 1. values greater than 0.49 may result in uncut areas or undesirable artifacts."], cc_sovr_l: ["a fraction of tool diameter between 0 and 1. values greater than 0.49 may result in uncut areas or undesirable artifacts."],
cc_sang_s: "step angle",
cc_sang_l: ["rotation in degrees between lathe axial points"],
cc_sdwn_s: "step down", cc_sdwn_s: "step down",
cc_sdwn_l: ["step down depth","for each pass","in workspace units","0 to disable"], cc_sdwn_l: ["step down depth","for each pass","in workspace units","0 to disable"],
cc_thru_s: "cut thru", cc_thru_s: "cut thru",