fix topo4 and linear lathe with workers
This commit is contained in:
parent
41ecf2951f
commit
f314e3b40c
4 changed files with 31 additions and 16 deletions
|
|
@ -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) => {
|
||||
|
|
|
|||
|
|
@ -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 = {}) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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})` });
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue