diff --git a/src/kiri/mode/cam/op-lathe.js b/src/kiri/mode/cam/op-lathe.js index b1b5349a..275b6906 100644 --- a/src/kiri/mode/cam/op-lathe.js +++ b/src/kiri/mode/cam/op-lathe.js @@ -2,7 +2,7 @@ import { CamOp } from './op.js'; import { Tool } from './tool.js'; -import { Topo4 } from './topo4.js'; +import { generate as topo4_generate } from './topo4.js'; import { newPoint } from '../../../geo/point.js'; function createFilter(op) { @@ -39,7 +39,7 @@ class OpLathe extends CamOp { let { addSlices } = state; let filter = createFilter(op); - this.topo = await Topo4({ + this.topo = await topo4_generate({ op, state, onupdate: (pct, msg) => { diff --git a/src/kiri/mode/cam/topo3.js b/src/kiri/mode/cam/topo3.js index 4116ac21..d45ae043 100644 --- a/src/kiri/mode/cam/topo3.js +++ b/src/kiri/mode/cam/topo3.js @@ -11,7 +11,7 @@ import { Tool } from './tool.js'; const RAD2DEG = 180 / Math.PI; const DEG2RAD = Math.PI / 180; -class Topo { +export class Topo { constructor() { } async generate(opt = {}) { diff --git a/src/kiri/mode/cam/topo4.js b/src/kiri/mode/cam/topo4.js index 2a430dce..7a4c39c6 100644 --- a/src/kiri/mode/cam/topo4.js +++ b/src/kiri/mode/cam/topo4.js @@ -17,7 +17,7 @@ function scale(fn, factor = 1, base = 0) { } } -class Topo { +export class Topo { constructor() { } async generate(opt = {}) { @@ -296,7 +296,7 @@ class Topo { } async latheWorker(onupdate) { - const { sliced, tool, zoff, leave } = this; + const { sliced, tool, zoff, leave, linear } = this; const rota = this.angle * DEG2RAD; const steps = (Math.PI * 2) / rota; @@ -319,19 +319,32 @@ class Topo { onupdate(count / steps); } - count = recs[0].heights.length / 3; + count = linear ? recs.length : recs[0].heights.length / 3; + // count = recs[0].heights.length / 3; while (count-- > 0) { let slice = newSlice(count); slice.camLines = [ newPolygon().setOpen() ]; paths.push(slice); } - for (let rec of recs) { - const { degrees, heights } = rec; - [...heights].group(3).forEach((a,i) => { - // progress each path 360 degrees to prevent A rolling backwards - paths[i].camLines[0].push( newPoint(a[0], a[1], a[2] + leave).setA(degrees + i * -360) ); + if (linear) { + recs.forEach((rec,i) => { + const { degrees, heights } = rec; + [...heights].group(3).forEach((a) => { + paths[i].camLines[0].push( newPoint(a[0], a[1], a[2] + leave).setA(degrees) ); + }); + if (i % 2 === 1) { + paths[i].camLines[0].reverse(); + } }); + } else { + for (let rec of recs) { + const { degrees, heights } = rec; + [...heights].group(3).forEach((a,i) => { + // progress each path 360 degrees to prevent A rolling backwards + paths[i].camLines[0].push( newPoint(a[0], a[1], a[2] + leave).setA(degrees + i * -360) ); + }); + } } for (let slice of paths) { @@ -395,8 +408,6 @@ class Topo { await Promise.all(promises); recs.sort((a, b) => { return b.angle - a.angle }); - // let linear = true; - count = linear ? recs.length : recs[0].heights.length / 3; while (count-- > 0) { let slice = newSlice(count); @@ -468,6 +479,6 @@ export function rotatePoints(lines, rot) { new THREE.BufferAttribute(lines, 3).applyMatrix4(rot); } -export function Topo4(opt) { +export async function generate(opt) { return new Topo().generate(opt); }; diff --git a/src/kiri/run/minion.js b/src/kiri/run/minion.js index 6d97d0c4..ae1c2920 100644 --- a/src/kiri/run/minion.js +++ b/src/kiri/run/minion.js @@ -15,7 +15,7 @@ import { sliceZ, sliceConnect } from '../../geo/slicer.js'; import { Slicer as cam_slicer } from '../mode/cam/slicer.js'; import { Slicer as topo_slicer } from '../mode/cam/slicer_topo.js'; import { Probe, Trace, raster_slice } from '../mode/cam/topo3.js'; -import { Topo4, rotatePoints } from '../mode/cam/topo4.js'; +import { Topo as Topo4, rotatePoints } from '../mode/cam/topo4.js'; import { wasm_ctrl } from '../../geo/wasm.js'; const clib = self.ClipperLib; @@ -54,9 +54,13 @@ function debug() { // console.log(`[${name}]`, ...arguments); } +let invalid = 0; const funcs = self.minion = { invalid(data, seq, cmd) { - console.error({ invalid_minion_command: cmd, data }); + if (invalid++ < 20) { + // prevent flooding console and killing session + console.error({ invalid_minion_command: cmd, data }); + } reply({ seq, error: `invalid command (${cmd})` }); },