diff --git a/src/geo/polygon.js b/src/geo/polygon.js index b9b6bd6f..12460823 100644 --- a/src/geo/polygon.js +++ b/src/geo/polygon.js @@ -15,6 +15,7 @@ const { base } = root; const { config, util, polygons, newBounds, newPoint } = base; const POLY = polygons, + XAXIS = new THREE.Vector3(1,0,0), DEG2RAD = Math.PI / 180, clib = self.ClipperLib, clip = clib.Clipper, @@ -967,6 +968,19 @@ class Polygon { 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 */ diff --git a/src/kiri-mode/cam/client.js b/src/kiri-mode/cam/client.js index 8da1a433..1409c5f6 100644 --- a/src/kiri-mode/cam/client.js +++ b/src/kiri-mode/cam/client.js @@ -1339,6 +1339,7 @@ CAM.init = function(kiri, api) { tool: 'camLatheTool', spindle: 'camLatheSpindle', step: 'camLatheOver', + angle: 'camLatheAngle', rate: 'camLatheSpeed', tolerance: 'camTolerance', 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}), 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)}), + 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}), }; diff --git a/src/kiri-mode/cam/ops.js b/src/kiri-mode/cam/ops.js index ee1f4b8c..3eab9125 100644 --- a/src/kiri-mode/cam/ops.js +++ b/src/kiri-mode/cam/ops.js @@ -857,8 +857,8 @@ class OpLathe extends CamOp { let { settings } = state; let { setTool, setSpindle, setPrintPoint } = ops; - let { camOut, newLayer, polyEmit, printPoint, lastPoint } = ops; - let { bounds, zmax } = ops; + let { camOut, newLayer, printPoint } = ops; + let { zmax } = ops; let toolDiam = new CAM.Tool(settings, op.tool).fluteDiameter(); let stepover = toolDiam * op.step * 2; diff --git a/src/kiri-mode/cam/topo4.js b/src/kiri-mode/cam/topo4.js index 8e437889..eb0a48a8 100644 --- a/src/kiri-mode/cam/topo4.js +++ b/src/kiri-mode/cam/topo4.js @@ -47,7 +47,8 @@ class Topo4 { zMin = min.z + 0.0001, tolerance = op.tolerance, 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) { console.log(widget.id, 'topo4 auto tolerance', resolution.round(4)); @@ -108,7 +109,7 @@ class Topo4 { index++; } slices.push(slice); - console.log({ shards, range, step, slices }); + // console.log({ shards, range, step, slices }); if (kiri.minions.running > 1) { return await this.sliceMinions(onupdate); @@ -265,11 +266,10 @@ class Topo4 { async latheWorker(onupdate) { const { sliced, tool } = this; - const steps = 100; - const rota = (360 / steps) * DEG2RAD; + const rota = this.angle * DEG2RAD; + const steps = (Math.PI * 2) / rota; const axis = new THREE.Vector3(1, 0, 0); const mrot = new THREE.Matrix4().makeRotationAxis(axis, rota); - const slices = sliced.map(s => { return { z: s.z, lines: s.shared } }); const paths = []; const recs = []; @@ -295,36 +295,21 @@ class Topo4 { } for (let rec of recs) { - const { angle, degrees, heights } = rec; - const points = heights.toFloat32(); - - 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); + const { degrees, heights } = rec; + [...heights].group(3).forEach((a,i) => { + paths[i].camLines[0].push( newPoint(a[0], a[1], a[2]).setA(degrees) ); + }); } for (let slice of paths) { + const poly = slice.camLines[0]; + if (!poly.length) { + continue; + } + slice.camLines[0].push(poly.points[0].clone()); slice.output() .setLayer("lathe", { line: 0xffff00 }) - .addPoly(slice.camLines[0]); + .addPoly(poly.clone().applyRotations()); } // console.log({ tool, slices, paths }); diff --git a/src/kiri/conf.js b/src/kiri/conf.js index 823b39c9..810bec11 100644 --- a/src/kiri/conf.js +++ b/src/kiri/conf.js @@ -505,6 +505,7 @@ const conf = exports({ camLatheTool: 1000, camLatheSpindle: 1000, camLatheOver: 0.1, + camLatheAngle: 1, camLatheSpeed: 500, camTolerance: 0, camTraceTool: 1000, diff --git a/web/kiri/lang/en.js b/web/kiri/lang/en.js index d24f3da3..eff908c3 100644 --- a/web/kiri/lang/en.js +++ b/web/kiri/lang/en.js @@ -444,6 +444,8 @@ self.kiri.lang['en-us'] = { cc_spnd_l: ["spindle speed in","revolutions / minute"], 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_sang_s: "step angle", + cc_sang_l: ["rotation in degrees between lathe axial points"], cc_sdwn_s: "step down", cc_sdwn_l: ["step down depth","for each pass","in workspace units","0 to disable"], cc_thru_s: "cut thru",