add stock indexing support

This commit is contained in:
Stewart Allen 2022-10-28 09:44:05 -04:00
commit 8b5e63d582
3 changed files with 47 additions and 45 deletions

View file

@ -224,9 +224,9 @@ kiri.load(() => {
} }
function replay() { function replay() {
CAM.animate_clear(api); animate_clear(api);
setTimeout(() => { setTimeout(() => {
CAM.animate(api, 50); animate(api, 50);
}, 250); }, 250);
} }
@ -554,31 +554,6 @@ kiri.load(() => {
send.data({ mesh_add: { id:++toolID, ind, sab }}); send.data({ mesh_add: { id:++toolID, ind, sab }});
} }
// load renderer code in worker context only
if (kiri.worker && false)
fetch('/wasm/kiri-ani.wasm')
.then(response => response.arrayBuffer())
.then(bytes => WebAssembly.instantiate(bytes, {
env: {
reportf: (a,b) => { console.log('[f]',a,b) },
reporti: (a,b) => { console.log('[i]',a,b) }
}
}))
.then(results => {
let {module, instance} = results;
let {exports} = instance;
let heap = new Uint8Array(exports.memory.buffer);
let wasm = self.wasm = {
heap,
memory: exports.memory,
updateMesh: exports.updateMesh
};
// heap[0] = 5;
// heap[100] = 6;
// heap[200] = 8;
// let rv = self.wasm.updateMesh(0, 0, 100, 200);
});
}); });
}); });

View file

@ -194,7 +194,15 @@ kiri.load(() => {
mesh.position.x = pos.x; mesh.position.x = pos.x;
mesh.position.y = pos.y; mesh.position.y = pos.y;
mesh.position.z = pos.z; mesh.position.z = pos.z;
space.update(); space.refresh();
}
}
if (data.mesh_index) {
const { id, index } = data.mesh_index;
const mesh = meshes[id];
if (mesh) {
mesh.rotation.x = (Math.PI / 180) * index;
space.refresh();
} }
} }
if (data.mesh_update) { if (data.mesh_update) {
@ -217,9 +225,9 @@ kiri.load(() => {
} }
function replay() { function replay() {
CAM.animate_clear2(api); animate_clear2(api);
setTimeout(() => { setTimeout(() => {
CAM.animate2(api, 50); animate2(api, 50);
}, 250); }, 250);
} }
}); });
@ -330,7 +338,9 @@ kiri.load(() => {
let stock, center, rez; let stock, center, rez;
let path, pathIndex, tool, tools, last; let path, pathIndex, tool, tools, last;
let stockIndexMsg = false;
let stockSlices; let stockSlices;
let stockIndex;
let startTime; let startTime;
let toolID = -1; let toolID = -1;
@ -372,6 +382,7 @@ kiri.load(() => {
last = null; last = null;
animating = false; animating = false;
animateClear = false; animateClear = false;
stockIndex = 0;
indexCount = 0; indexCount = 0;
startTime = 0; startTime = 0;
updates = 0; updates = 0;
@ -542,9 +553,6 @@ kiri.load(() => {
// send latest tool position and progress bar // send latest tool position and progress bar
function renderUpdate(send) { function renderUpdate(send) {
if (toolUpdateMsg) {
send.data(toolUpdateMsg);
}
const updated = [] const updated = []
for (let slice of stockSlices) { for (let slice of stockSlices) {
slice.updateMesh(updated); slice.updateMesh(updated);
@ -552,6 +560,15 @@ kiri.load(() => {
for (let slice of updated) { for (let slice of updated) {
slice.send(send); slice.send(send);
} }
if (toolUpdateMsg) {
send.data(toolUpdateMsg);
}
if (stockIndexMsg) {
for (let slice of stockSlices) {
send.data({ mesh_index: { id: slice.id, index: -stockIndex } });
}
stockIndexMsg = false;
}
send.data({ progress: pathIndex / path.length }); send.data({ progress: pathIndex / path.length });
updates++; updates++;
} }
@ -561,10 +578,19 @@ kiri.load(() => {
const lpos = tool.pos || { x:0, y:0, z:0 }; const lpos = tool.pos || { x:0, y:0, z:0 };
tool.pos = pos; tool.pos = pos;
toolUpdateMsg = { mesh_move: { id: toolID, pos }}; toolUpdateMsg = { mesh_move: { id: toolID, pos }};
const delta = [ pos.x - lpos.x, pos.y - lpos.y, pos.z - lpos.z ]; if (toolMesh.mesh) {
const oldmesh = toolMesh.mesh; toolMesh.mesh.delete();
toolMesh.mesh = toolMesh.mesh.translate(pos.x - lpos.x, pos.y - lpos.y, pos.z - lpos.z); }
oldmesh.delete(); toolMesh.mesh = toolMesh.root.translate(pos.x, pos.y, pos.z);
if (pos.a !== undefined) {
let tmp = toolMesh.mesh.rotate([ pos.a, 0, 0 ]);
toolMesh.mesh.delete();
toolMesh.mesh = tmp;
if (pos.a !== stockIndex) {
stockIndexMsg = true;
stockIndex = pos.a;
}
}
} }
// delete old tool mesh, generate tool mesh, send to client // delete old tool mesh, generate tool mesh, send to client
@ -590,7 +616,7 @@ kiri.load(() => {
} }
mesh = mesh.translate(0, 0, (flen + slen) / 2); mesh = mesh.translate(0, 0, (flen + slen) / 2);
const { vertex, index } = mesh.getMesh({ normal: () => undefined }); const { vertex, index } = mesh.getMesh({ normal: () => undefined });
toolMesh = { mesh, index, vertex }; toolMesh = { root: mesh, index, vertex };
send.data({ mesh_add: { id:--toolID, ind: index, pos: vertex }}); send.data({ mesh_add: { id:--toolID, ind: index, pos: vertex }});
} }

View file

@ -19,27 +19,28 @@ let isAnimate,
camStock, camStock,
camZBottom, camZBottom,
current, current,
flipping,
poppedRec, poppedRec,
hoveredOp, hoveredOp,
API, FDM, SPACE, STACKS, MODES, VIEWS, UI, UC, LANG, MCAM; API, FDM, SPACE, STACKS, MODES, VIEWS, UI, UC, LANG, MCAM;
let zaxis = { x: 0, y: 0, z: 1 }, let zaxis = { x: 0, y: 0, z: 1 },
popOp = {}, popOp = {},
animVer = 1,
seed = Date.now(), seed = Date.now(),
func = { func = {
hover: noop, hover: noop,
hoverUp: noop hoverUp: noop
}, };
flipping;
function animFn(v) { function animFn() {
return [{ return [{
animate: CAM.animate, animate: CAM.animate,
animate_clear: CAM.animate_clear animate_clear: CAM.animate_clear
},{ },{
animate: CAM.animate2, animate: CAM.animate2,
animate_clear: CAM.animate_clear2 animate_clear: CAM.animate_clear2
}][0]; }][animVer];
} }
CAM.restoreTabs = restoreTabs; CAM.restoreTabs = restoreTabs;
@ -79,7 +80,7 @@ CAM.init = function(kiri, api) {
api.event.on("function.export", (mode) => { api.event.on("function.export", (mode) => {
if (isAnimate) { if (isAnimate) {
animFn(0).animate_clear(api); animFn().animate_clear(api);
isAnimate = false; isAnimate = false;
} }
}); });
@ -102,7 +103,7 @@ CAM.init = function(kiri, api) {
api.event.on("view.set", (mode) => { api.event.on("view.set", (mode) => {
isArrange = (mode === VIEWS.ARRANGE); isArrange = (mode === VIEWS.ARRANGE);
isAnimate = false; isAnimate = false;
animFn(0).animate_clear(api); animFn().animate_clear(api);
func.clearPops(); func.clearPops();
$('camops').style.display = isCamMode && isArrange ? 'flex' : ''; $('camops').style.display = isCamMode && isArrange ? 'flex' : '';
}); });
@ -1527,7 +1528,7 @@ function animate() {
API.widgets.opacity(isParsed ? 0 : 0.75); API.widgets.opacity(isParsed ? 0 : 0.75);
API.hide.slider(); API.hide.slider();
STACKS.clear(); STACKS.clear();
animFn(0).animate(API); animFn().animate(API);
} }
function updateStock(args, event) { function updateStock(args, event) {