checkpoint cam animation work

This commit is contained in:
Stewart Allen 2020-11-24 11:01:29 -05:00
commit b85607598b
5 changed files with 173 additions and 34 deletions

View file

@ -5,59 +5,132 @@
kiri.loader.push(function() {
let KIRI = self.kiri,
BASE = self.base,
CAM = KIRI.driver.CAM,
PRO = CAM.process,
newPolygon = BASE.newPolygon,
newPoint = BASE.newPoint;
API, WORLD,
meshes = {};
if (KIRI.client)
CAM.animate = function(API) {
KIRI.client.animate(API.conf.get(), data => {
const { ind, pos } = data;
CAM.animate_clear = function(api) {
WORLD = (API = api).const.SPACE.platform.world;
$('layer-animate').innerHTML = '';
Object.keys(meshes).forEach(id => deleteMesh(id));
}
const geo = new THREE.BufferGeometry();
geo.setAttribute('position', new THREE.BufferAttribute(pos, 3));
geo.setIndex(new THREE.BufferAttribute(new Uint16Array(ind), 1));
const mat = new THREE.LineBasicMaterial({
transparent: true,
opacity: 0.75,
color: 0
});
const seg = new THREE.LineSegments(geo, mat);
API.const.SPACE.platform.world.add(seg);
if (KIRI.client)
CAM.animate = function(api) {
WORLD = (API = api).const.SPACE.platform.world;
KIRI.client.animate_setup(API.conf.get(), data => {
checkMeshCommands(data);
const UC = API.uc;
const layer = $('layer-animate');
layer.innerHTML = '';
UC.setGroup(layer);
UC.newRow([
UC.newButton(null,play,{icon:'<i class="fas fa-play-circle"></i>'}),
UC.newButton(null,pause,{icon:'<i class="fas fa-pause-circle"></i>'})
]);
});
};
if (KIRI.client)
KIRI.client.animate = function(settings, ondone) {
send("animate", {settings}, reply => {
ondone(reply);
function checkMeshCommands(data) {
if (!data) {
return;
}
if (data.mesh_add) {
const { id, ind, pos } = data.mesh_add;
addMesh(id, ind, pos);
}
if (data.mesh_del) {
deleteMesh(data.mesh_del);
}
if (data.mesh_move) {
const { id, pos } = data.mesh_move;
const mesh = meshes[id];
mesh.position.x = pos.x;
mesh.position.y = pos.y;
mesh.position.z = pos.z;
}
}
function addMesh(id, ind, pos) {
const geo = new THREE.BufferGeometry();
geo.setAttribute('position', new THREE.BufferAttribute(pos, 3));
geo.setIndex(new THREE.BufferAttribute(new Uint16Array(ind), 1));
const mat = new THREE.LineBasicMaterial({
transparent: true,
opacity: 0.75,
color: 0
});
const mesh = new THREE.LineSegments(geo, mat);
WORLD.add(mesh);
meshes[id] = mesh;
}
function updateMesh(id) {
}
function deleteMesh(id) {
WORLD.remove(meshes[id]);
delete meshes[id];
}
function play() {
KIRI.client.animate({speed: 1}, handleGridUpdate);
}
function pause() {
KIRI.client.animate({speed: 0}, handleGridUpdate);
}
function handleGridUpdate(data) {
checkMeshCommands(data);
}
if (KIRI.client)
KIRI.client.animate_setup = function(settings, ondone) {
send("animate_setup", {settings}, ondone);
};
if (KIRI.client)
KIRI.client.animate = function(data, ondone) {
send("animate", data, ondone);
};
let path, pathIndex, grid, tool, tools, rez;
if (KIRI.worker)
KIRI.worker.animate = function(data, send) {
console.log({current});
KIRI.worker.animate_setup = function(data, send) {
const { settings } = data;
rez = 0.5;
tools = settings.tools;
path = current.print.output.flat();
pathIndex = 0;
const stock = settings.stock;
const center = stock.center;
const step = 1;
// const center = stock.center;
const step = rez;
const stepsX = Math.floor(stock.x / step) + 1;
const stepsY = Math.floor(stock.y / step) + 1;
const { pos, ind } = createGrid(stepsX, stepsY, stock, step);
send.done({ mesh_add: { id: 0, pos, ind } });
};
function createGrid(stepsX, stepsY, size, step) {
const gridPoints = stepsX * stepsY;
const pos = new Float32Array(gridPoints * 3);
const pos = grid = new Float32Array(gridPoints * 3);
const ind = [];
const ox = stock.x / 2;
const oy = stock.y / 2;
const ox = size.x / 2;
const oy = size.y / 2;
// initialize grid points
for (let x=0, ai=0; x<stepsX; x++) {
for (let y=0; y<stepsY; y++) {
pos[ai++] = x * step - ox;
pos[ai++] = y * step - oy;
pos[ai++] = stock.z;
pos[ai++] = size.z;
if (y > 0) ind.appendAll([
(stepsY * x) + (y - 1),
(stepsY * x) + (y )
@ -69,7 +142,41 @@ kiri.loader.push(function() {
}
}
send.done({ pos, ind });
return { pos, ind };
}
if (KIRI.worker)
KIRI.worker.animate = function(data, send) {
if (data.speed) {
let next = path[pathIndex++];
if (next.tool && (!tool || tool.getNumber() !== next.tool)) {
updateTool(next.tool, send);
}
send.data({ mesh_move: { id: tool.getID(), pos: next.point }});
}
send.done();
};
function updateTool(toolnum, send) {
if (tool) {
send.data({ mesh_del: tool.getID() });
}
tool = new CAM.Tool({ tools }, undefined, toolnum);
tool.generateProfile(rez);
const flen = tool.fluteLength() || 30;
// const frad = tool.fluteDiameter() / 2;
const prof = tool.profile;
const { size, pix } = tool.profileDim;
const { pos, ind } = createGrid(pix, pix, {x:size, y:size, z:flen}, rez);
const mid = Math.floor(pix/2);
// deform mesh to fit tool profile
for (let i=0, il=prof.length; i < il; ) {
const dx = mid + prof[i++];
const dy = mid + prof[i++];
const dz = prof[i++];
pos[(dx * pix + dy) * 3 + 2] = -dz;
}
send.data({ mesh_add: { id:tool.getID(), pos, ind }});
}
});

View file

@ -10,6 +10,7 @@
PRO = CAM.process,
newPolygon = BASE.newPolygon,
newPoint = BASE.newPoint,
isAnimate,
isArrange,
isCamMode,
camStock,
@ -34,6 +35,8 @@
api.event.on("view.set", (mode) => {
isArrange = (mode === VIEWS.ARRANGE);
isAnimate = false;
CAM.animate_clear(api);
});
api.event.on("settings.saved", (settings) => {
@ -72,6 +75,7 @@
};
function animate() {
isAnimate = true;
API.widgets.opacity(0.75);
API.hide.slider();
STACKS.clear();
@ -79,6 +83,10 @@
}
function updateStock(args, event) {
if (isAnimate) {
return;
}
STACKS.remove('bounds');
if (isCamMode && isArrange) {
STACKS.clear();

View file

@ -11,8 +11,16 @@
CAM = KIRI.driver.CAM;
class Tool {
constructor(settings, id) {
this.tool = settings.tools.filter(tool => tool.id === id)[0];
constructor(settings, id, number) {
if (number >= 0) {
this.tool = settings.tools.filter(tool => tool.number === number)[0];
} else {
this.tool = settings.tools.filter(tool => tool.id === id)[0];
}
}
getID() {
return this.tool.id;
}
getType() {
@ -95,6 +103,10 @@
}
this.profile = toolOffset;
this.profileDim = {
size: shaft_pix_float,
pix: profile_pix_iter
};
return this;
}
}

View file

@ -872,6 +872,17 @@ th, tr, td, label {
pointer-events: all;
}
#layer-animate {
position: absolute;
left: 15px;
right: 15px;
bottom: 3px;
}
#layer-animate svg {
color: #333;
font-size: 30px;
}
#slider {
display: none;
height: 30px;

View file

@ -382,6 +382,7 @@
<div id="alert-text">alerts<br>alerts<br>alerts</div>
</div>
</div>
<div id="layer-animate" class="f-col a-center"></div>
</div>
<div id="gdpr" class="noshow">
<p>this site uses cookies to preserve application preferences</p>