fix cam 2d animation

This commit is contained in:
Stewart Allen 2025-07-05 13:30:06 -04:00
commit ee78dd41e7
5 changed files with 142 additions and 131 deletions

View file

@ -2,13 +2,21 @@
// WORKER BACK END ANIMATION CODE for 2D
import { Tool } from './tool.js';
const asPoints = false;
const asLines = false;
let stock, center, grid, gridX, gridY, rez;
let path, pathIndex, tool, tools, last, toolID = 1;
kiri.worker.animate_setup = function(data, send) {
export function init(worker) {
const { dispatch } = worker;
dispatch.animate_setup = function(data, send) {
const { settings } = data;
const { process } = settings;
const print = worker.print;
const print = worker.current.print;
const density = parseInt(settings.controller.animesh) * 1000;
pathIndex = 0;
@ -17,22 +25,10 @@ kiri.worker.animate_setup = function(data, send) {
stock = settings.stock;
rez = 1/Math.sqrt(density/(stock.x * stock.y));
//destructure arcs into path points
path = path.map(o=>
o.arcPoints
? [
...o.arcPoints.map(point=>
({
...o,
point
})
),
o
]
: o
)
.flat();
// destructure arcs into path points
path = path.map(o =>
o.arcPoints ? [ ...o.arcPoints.map(point => ({ ...o, point })), o ] : o
).flat();
const step = rez;
const stepsX = Math.floor(stock.x / step);
@ -59,9 +55,9 @@ kiri.worker.animate_setup = function(data, send) {
send.data({ mesh_add: { id: 0, ind, offset, sab } }, [ ]); // sab not transferrable
send.data({ mesh_move: { id: 0, pos: center } });
send.done();
};
};
kiri.worker.animate = function(data, send) {
dispatch.animate = function(data, send) {
renderPause = data.pause || renderPause;
renderSpeed = data.speed || 0;
if (animating) {
@ -71,13 +67,14 @@ kiri.worker.animate = function(data, send) {
renderDone = false;
animating = renderSpeed > 0;
renderPath(send);
};
};
kiri.worker.animate_cleanup = function(data, send) {
dispatch.animate_cleanup = function(data, send) {
if (animating) {
animateClear = true;
}
};
};
}
function createGrid(stepsX, stepsY, size, step, stock) {
const gridPoints = stepsX * stepsY;
@ -290,7 +287,7 @@ function updateTool(toolobj, send) {
if (tool) {
send.data({ mesh_del: toolID });
}
tool = new CAM.Tool({ tools }, toolobj.getID());
tool = new Tool({ tools }, toolobj.getID());
tool.generateProfile(rez);
const flen = tool.fluteLength() || 15;
const slen = tool.shaftLength() || 15;

View file

@ -30,10 +30,13 @@ let renderSpeed = 0;
let indexCount = 0;
let updates = 0;
kiri.worker.animate_setup2 = function (data, send) {
export function init(worker) {
const { dispatch } = worker;
dispatch.animate_setup2 = function (data, send) {
const { settings } = data;
const { process } = settings;
const print = worker.print;
const print = worker.current.print;
const density = parseInt(settings.controller.animesh) * 1000;
const isIndexed = process.camStockIndexed;
@ -67,9 +70,9 @@ kiri.worker.animate_setup2 = function (data, send) {
}
send.done();
};
};
kiri.worker.animate2 = function (data, send) {
dispatch.animate2 = function (data, send) {
renderPause = data.pause || renderPause;
renderSpeed = data.speed || 0;
if (animating) {
@ -80,13 +83,14 @@ kiri.worker.animate2 = function (data, send) {
animating = renderSpeed > 0;
startTime = startTime || Date.now();
renderPath(send);
};
};
kiri.worker.animate_cleanup2 = function (data, send) {
dispatch.animate_cleanup2 = function (data, send) {
if (animating) {
animateClear = true;
}
};
};
}
function renderPath(send) {
if (renderDone) {

View file

@ -6,6 +6,9 @@ import { cam_prepare } from './prepare.js';
import { cam_export } from './export.js';
import { tool as mesh_tool } from '../../mesh/tool.js';
import { init as init_2d } from './anim-2d-be.js';
import { init as init_3d } from './anim-3d-be.js';
function surface_prep(widget, index) {
if (!widget.tool) {
let tool = widget.tool = new mesh_tool();
@ -20,7 +23,13 @@ function surface_find(widget, faces, radians) {
};
function init(worker) {
worker.cam_surfaces = function(data, send) {
const { dispatch } = worker;
init_2d(worker);
init_3d(worker);
dispatch.cam_surfaces = function(data, send) {
const { settings, index } = data;
const widgets = Object.values(worker.cache);
for (let widget of widgets) {
@ -36,14 +45,14 @@ function init(worker) {
send.done({});
};
worker.cam_surface_find = function(data, send) {
dispatch.cam_surface_find = function(data, send) {
const { id, face, radians } = data;
const widget = worker.cache[id];
const faces = surface_find(widget, [face], radians);
send.done(faces);
}
worker.cam_traces = async function(data, send) {
dispatch.cam_traces = async function(data, send) {
const { settings, single } = data;
const widgets = Object.values(worker.cache);
const fresh = [];
@ -59,7 +68,7 @@ function init(worker) {
} } )));
};
worker.cam_traces_clear = function(data, send) {
dispatch.cam_traces_clear = function(data, send) {
for (let widget of Object.values(worker.cache)) {
delete widget.traces;
delete widget.topo;
@ -67,7 +76,7 @@ function init(worker) {
send.done({});
};
worker.cam_holes = async function(data, send) {
dispatch.cam_holes = async function(data, send) {
const { settings, indiv, rec } = data;
const widgets = Object.values(worker.cache);
const fresh = [];

View file

@ -22,7 +22,7 @@ function extrudeMM(dist, perMM, factor) {
// defer loading until client and worker exist
function init(worker) {
worker.fdm_support_generate = function(data, send) {
worker.dispatch.fdm_support_generate = function(data, send) {
const { settings } = data;
const widgets = Object.values(worker.cache);
const fresh = widgets.filter(widget => FDM.supports(settings, widget));

View file

@ -744,16 +744,17 @@ dispatch.onmessage = self.onmessage = async function(e) {
}
};
self.kiri_worker = {
const worker = self.kiri_worker = {
cache: wcache,
current,
dispatch,
drivers,
version,
minions: minwork
};
// initilize driver mode handlers
CAM.init(dispatch);
FDM.init(dispatch);
CAM.init(worker);
FDM.init(worker);
broker.publish("worker.started", { dispatch, minions: minwork });