fix cam 2d animation
This commit is contained in:
parent
0ab2268791
commit
ee78dd41e7
5 changed files with 142 additions and 131 deletions
|
|
@ -2,82 +2,79 @@
|
||||||
|
|
||||||
// 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 { settings } = data;
|
const { dispatch } = worker;
|
||||||
const { process } = settings;
|
|
||||||
const print = worker.print;
|
|
||||||
const density = parseInt(settings.controller.animesh) * 1000;
|
|
||||||
|
|
||||||
pathIndex = 0;
|
dispatch.animate_setup = function(data, send) {
|
||||||
path = print.output.flat();
|
const { settings } = data;
|
||||||
tools = settings.tools;
|
const { process } = settings;
|
||||||
stock = settings.stock;
|
const print = worker.current.print;
|
||||||
rez = 1/Math.sqrt(density/(stock.x * stock.y));
|
const density = parseInt(settings.controller.animesh) * 1000;
|
||||||
|
|
||||||
|
pathIndex = 0;
|
||||||
|
path = print.output.flat();
|
||||||
|
tools = settings.tools;
|
||||||
|
stock = settings.stock;
|
||||||
|
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);
|
||||||
const stepsY = Math.floor(stock.y / step);
|
const stepsY = Math.floor(stock.y / step);
|
||||||
const { pos, ind, sab } = createGrid(stepsX, stepsY, stock, step, true);
|
const { pos, ind, sab } = createGrid(stepsX, stepsY, stock, step, true);
|
||||||
const offset = {
|
const offset = {
|
||||||
x: process.camOriginCenter ? 0 : stock.x / 2,
|
x: process.camOriginCenter ? 0 : stock.x / 2,
|
||||||
y: process.camOriginCenter ? 0 : stock.y / 2,
|
y: process.camOriginCenter ? 0 : stock.y / 2,
|
||||||
z: process.camOriginTop ? -stock.z : 0
|
z: process.camOriginTop ? -stock.z : 0
|
||||||
}
|
}
|
||||||
|
|
||||||
grid = pos;
|
grid = pos;
|
||||||
gridX = stepsX;
|
gridX = stepsX;
|
||||||
gridY = stepsY;
|
gridY = stepsY;
|
||||||
|
|
||||||
tool = null;
|
tool = null;
|
||||||
last = null;
|
last = null;
|
||||||
animating = false;
|
animating = false;
|
||||||
animateClear = false;
|
animateClear = false;
|
||||||
|
|
||||||
center = Object.assign({}, stock.center);
|
center = Object.assign({}, stock.center);
|
||||||
center.z -= stock.z / 2;
|
center.z -= stock.z / 2;
|
||||||
|
|
||||||
send.data({ mesh_add: { id: 0, ind, offset, sab } }, [ ]); // sab not transferrable
|
send.data({ mesh_add: { id: 0, ind, offset, sab } }, [ ]); // sab not transferrable
|
||||||
send.data({ mesh_move: { id: 0, pos: center } });
|
send.data({ mesh_move: { id: 0, pos: center } });
|
||||||
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) {
|
||||||
return send.done();
|
return send.done();
|
||||||
}
|
}
|
||||||
renderSteps = data.steps || 1;
|
renderSteps = data.steps || 1;
|
||||||
renderDone = false;
|
renderDone = false;
|
||||||
animating = renderSpeed > 0;
|
animating = renderSpeed > 0;
|
||||||
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;
|
||||||
|
|
|
||||||
|
|
@ -30,63 +30,67 @@ 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 { settings } = data;
|
const { dispatch } = worker;
|
||||||
const { process } = settings;
|
|
||||||
const print = worker.print;
|
|
||||||
const density = parseInt(settings.controller.animesh) * 1000;
|
|
||||||
const isIndexed = process.camStockIndexed;
|
|
||||||
|
|
||||||
pathIndex = 0;
|
dispatch.animate_setup2 = function (data, send) {
|
||||||
path = print.output.flat();
|
const { settings } = data;
|
||||||
tools = settings.tools;
|
const { process } = settings;
|
||||||
stock = settings.stock;
|
const print = worker.current.print;
|
||||||
rez = 1 / Math.sqrt(density / (stock.x * stock.y));
|
const density = parseInt(settings.controller.animesh) * 1000;
|
||||||
|
const isIndexed = process.camStockIndexed;
|
||||||
|
|
||||||
tool = null;
|
pathIndex = 0;
|
||||||
last = null;
|
path = print.output.flat();
|
||||||
animating = false;
|
tools = settings.tools;
|
||||||
animateClear = false;
|
stock = settings.stock;
|
||||||
stockIndex = 0;
|
rez = 1 / Math.sqrt(density / (stock.x * stock.y));
|
||||||
indexCount = 0;
|
|
||||||
startTime = 0;
|
|
||||||
updates = 0;
|
|
||||||
stockZ = isIndexed ? 0 : stock.z;
|
|
||||||
|
|
||||||
stockSlices = [];
|
tool = null;
|
||||||
const { x, y, z } = stock;
|
last = null;
|
||||||
const sliceCount = parseInt(settings.controller.animesh || 2000) / 100;
|
animating = false;
|
||||||
const sliceWidth = stock.x / sliceCount;
|
animateClear = false;
|
||||||
for (let i = 0; i < sliceCount; i++) {
|
stockIndex = 0;
|
||||||
let xmin = -(x / 2) + (i * sliceWidth) + sliceWidth / 2;
|
indexCount = 0;
|
||||||
let slice = new Stock(sliceWidth, y, z).translate(xmin, 0, 0);
|
startTime = 0;
|
||||||
stockSlices.push(slice);
|
updates = 0;
|
||||||
slice.updateMesh([]);
|
stockZ = isIndexed ? 0 : stock.z;
|
||||||
slice.send(send);
|
|
||||||
// send({ mesh_move: { id: slice.id, pos: { x:0, y:0, z: stock.z/2} } });
|
|
||||||
}
|
|
||||||
|
|
||||||
send.done();
|
stockSlices = [];
|
||||||
};
|
const { x, y, z } = stock;
|
||||||
|
const sliceCount = parseInt(settings.controller.animesh || 2000) / 100;
|
||||||
|
const sliceWidth = stock.x / sliceCount;
|
||||||
|
for (let i = 0; i < sliceCount; i++) {
|
||||||
|
let xmin = -(x / 2) + (i * sliceWidth) + sliceWidth / 2;
|
||||||
|
let slice = new Stock(sliceWidth, y, z).translate(xmin, 0, 0);
|
||||||
|
stockSlices.push(slice);
|
||||||
|
slice.updateMesh([]);
|
||||||
|
slice.send(send);
|
||||||
|
// send({ mesh_move: { id: slice.id, pos: { x:0, y:0, z: stock.z/2} } });
|
||||||
|
}
|
||||||
|
|
||||||
kiri.worker.animate2 = function (data, send) {
|
send.done();
|
||||||
renderPause = data.pause || renderPause;
|
};
|
||||||
renderSpeed = data.speed || 0;
|
|
||||||
if (animating) {
|
|
||||||
return send.done();
|
|
||||||
}
|
|
||||||
renderSteps = data.steps || 1;
|
|
||||||
renderDone = false;
|
|
||||||
animating = renderSpeed > 0;
|
|
||||||
startTime = startTime || Date.now();
|
|
||||||
renderPath(send);
|
|
||||||
};
|
|
||||||
|
|
||||||
kiri.worker.animate_cleanup2 = function (data, send) {
|
dispatch.animate2 = function (data, send) {
|
||||||
if (animating) {
|
renderPause = data.pause || renderPause;
|
||||||
animateClear = true;
|
renderSpeed = data.speed || 0;
|
||||||
}
|
if (animating) {
|
||||||
};
|
return send.done();
|
||||||
|
}
|
||||||
|
renderSteps = data.steps || 1;
|
||||||
|
renderDone = false;
|
||||||
|
animating = renderSpeed > 0;
|
||||||
|
startTime = startTime || Date.now();
|
||||||
|
renderPath(send);
|
||||||
|
};
|
||||||
|
|
||||||
|
dispatch.animate_cleanup2 = function (data, send) {
|
||||||
|
if (animating) {
|
||||||
|
animateClear = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function renderPath(send) {
|
function renderPath(send) {
|
||||||
if (renderDone) {
|
if (renderDone) {
|
||||||
|
|
|
||||||
|
|
@ -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 = [];
|
||||||
|
|
|
||||||
|
|
@ -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));
|
||||||
|
|
|
||||||
|
|
@ -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 });
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue