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 // 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 stock, center, grid, gridX, gridY, rez;
let path, pathIndex, tool, tools, last, toolID = 1; 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 { settings } = data;
const { process } = settings; const { process } = settings;
const print = worker.print; const print = worker.current.print;
const density = parseInt(settings.controller.animesh) * 1000; const density = parseInt(settings.controller.animesh) * 1000;
pathIndex = 0; pathIndex = 0;
@ -17,22 +25,10 @@ kiri.worker.animate_setup = function(data, send) {
stock = settings.stock; stock = settings.stock;
rez = 1/Math.sqrt(density/(stock.x * stock.y)); rez = 1/Math.sqrt(density/(stock.x * stock.y));
// destructure arcs into path points // destructure arcs into path points
path = path.map(o => path = path.map(o =>
o.arcPoints o.arcPoints ? [ ...o.arcPoints.map(point => ({ ...o, point })), o ] : o
? [ ).flat();
...o.arcPoints.map(point=>
({
...o,
point
})
),
o
]
: o
)
.flat();
const step = rez; const step = rez;
const stepsX = Math.floor(stock.x / step); const stepsX = Math.floor(stock.x / step);
@ -61,7 +57,7 @@ kiri.worker.animate_setup = function(data, send) {
send.done(); send.done();
}; };
kiri.worker.animate = function(data, send) { dispatch.animate = function(data, send) {
renderPause = data.pause || renderPause; renderPause = data.pause || renderPause;
renderSpeed = data.speed || 0; renderSpeed = data.speed || 0;
if (animating) { if (animating) {
@ -73,11 +69,12 @@ kiri.worker.animate = function(data, send) {
renderPath(send); renderPath(send);
}; };
kiri.worker.animate_cleanup = function(data, send) { dispatch.animate_cleanup = function(data, send) {
if (animating) { if (animating) {
animateClear = true; animateClear = true;
} }
}; };
}
function createGrid(stepsX, stepsY, size, step, stock) { function createGrid(stepsX, stepsY, size, step, stock) {
const gridPoints = stepsX * stepsY; const gridPoints = stepsX * stepsY;
@ -290,7 +287,7 @@ function updateTool(toolobj, send) {
if (tool) { if (tool) {
send.data({ mesh_del: toolID }); send.data({ mesh_del: toolID });
} }
tool = new CAM.Tool({ tools }, toolobj.getID()); tool = new Tool({ tools }, toolobj.getID());
tool.generateProfile(rez); tool.generateProfile(rez);
const flen = tool.fluteLength() || 15; const flen = tool.fluteLength() || 15;
const slen = tool.shaftLength() || 15; const slen = tool.shaftLength() || 15;

View file

@ -30,10 +30,13 @@ let renderSpeed = 0;
let indexCount = 0; let indexCount = 0;
let updates = 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 { settings } = data;
const { process } = settings; const { process } = settings;
const print = worker.print; const print = worker.current.print;
const density = parseInt(settings.controller.animesh) * 1000; const density = parseInt(settings.controller.animesh) * 1000;
const isIndexed = process.camStockIndexed; const isIndexed = process.camStockIndexed;
@ -69,7 +72,7 @@ kiri.worker.animate_setup2 = function (data, send) {
send.done(); send.done();
}; };
kiri.worker.animate2 = function (data, send) { dispatch.animate2 = function (data, send) {
renderPause = data.pause || renderPause; renderPause = data.pause || renderPause;
renderSpeed = data.speed || 0; renderSpeed = data.speed || 0;
if (animating) { if (animating) {
@ -82,11 +85,12 @@ kiri.worker.animate2 = function (data, send) {
renderPath(send); renderPath(send);
}; };
kiri.worker.animate_cleanup2 = function (data, send) { dispatch.animate_cleanup2 = function (data, send) {
if (animating) { if (animating) {
animateClear = true; animateClear = true;
} }
}; };
}
function renderPath(send) { function renderPath(send) {
if (renderDone) { if (renderDone) {

View file

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

View file

@ -22,7 +22,7 @@ function extrudeMM(dist, perMM, factor) {
// defer loading until client and worker exist // defer loading until client and worker exist
function init(worker) { function init(worker) {
worker.fdm_support_generate = function(data, send) { worker.dispatch.fdm_support_generate = function(data, send) {
const { settings } = data; const { settings } = data;
const widgets = Object.values(worker.cache); const widgets = Object.values(worker.cache);
const fresh = widgets.filter(widget => FDM.supports(settings, widget)); 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, cache: wcache,
current, current,
dispatch,
drivers, drivers,
version, version,
minions: minwork minions: minwork
}; };
// initilize driver mode handlers // initilize driver mode handlers
CAM.init(dispatch); CAM.init(worker);
FDM.init(dispatch); FDM.init(worker);
broker.publish("worker.started", { dispatch, minions: minwork }); broker.publish("worker.started", { dispatch, minions: minwork });