stub in cam wasm animator function

This commit is contained in:
Stewart Allen 2021-01-15 11:06:52 -05:00
commit 65b01b8a7c
4 changed files with 58 additions and 7 deletions

View file

@ -416,11 +416,10 @@
* @param {Object} [options] object
* @return {Point} last output point
*/
PRO.slicePrintPath = function(slice, startPoint, offset, output, options) {
PRO.slicePrintPath = function(slice, startPoint, offset, output, opt = {}) {
// console.log({slicePrintPath: slice.index, ext:slice.extruder});
let i,
opt = options || {},
preout = [],
scope = this,
settings = this.settings,

View file

@ -435,7 +435,7 @@ self.kiri.loader.push(function() {
function updateMesh(pos, send) {
const prof = tool.profile;
const { size, pix } = tool.profileDim;
const mid = Math.floor(pix/2);
const mid = Math.floor(pix / 2);
const update = new Float32Array(Math.round(prof.length * 0.8));
const rx = Math.floor((pos.x + stock.x / 2 - size / 2 - center.x) / rez);
const ry = Math.floor((pos.y + stock.y / 2 - size / 2 - center.y) / rez);
@ -445,15 +445,15 @@ self.kiri.loader.push(function() {
const dx = mid + prof[i++];
const dy = mid + prof[i++];
const dz = prof[i++];
const gx = rx + dx;
const gy = ry + dy;
if (gx < 0|| gy < 0 || gx > gridX-1 || gy > gridY-1) continue;
if (gx < 0|| gy < 0 || gx > gridX-1 || gy > gridY-1) {
continue;
}
const gi = gx * gridY + gy;
const iz = gi * 3 + 2;
const cz = grid[iz];
const tz = tool.pos.z - dz;
if (tz < cz) {
@ -495,4 +495,29 @@ self.kiri.loader.push(function() {
send.data({ mesh_add: { id:++toolID, pos, ind }});
}
// load renderer code in worker context only
if (KIRI.worker)
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);
});
});

24
wasm/kiri-ani.c Normal file
View file

@ -0,0 +1,24 @@
#include <emscripten.h>
#include <string.h>
typedef unsigned char Uint8;
typedef unsigned short Uint16;
typedef unsigned int Uint32;
extern void reportf(float a, float b);
extern void reporti(int a, int b);
/**
* m = memory base pointer
* im = input memory location (mesh)
* it = input memory location (tool)
* ol = output memory location (mesh-updates)
* returns length of update at output memory location
*/
EMSCRIPTEN_KEEPALIVE
Uint32 updateMesh(unsigned char *m, Uint32 im, Uint32 it, Uint32 ol) {
int rv = m[0] + m[100] + m[200];
m[0] = 123;
reporti(m[100],m[200]);
return rv;
}

View file

@ -1,4 +1,4 @@
all: kiri-sla.wasm kiri-geo.wasm
all: kiri-sla.wasm kiri-geo.wasm kiri-ani.wasm
kiri-sla.wasm: kiri-sla.c
emcc -o kiri-sla.wasm kiri-sla.c -O3 -s ERROR_ON_UNDEFINED_SYMBOLS=0
@ -6,5 +6,8 @@ kiri-sla.wasm: kiri-sla.c
kiri-geo.wasm: kiri-geo.cpp
emcc -o kiri-geo.wasm clipper.cpp kiri-geo.cpp -Oz -s ERROR_ON_UNDEFINED_SYMBOLS=0
kiri-ani.wasm: kiri-ani.c
emcc -o kiri-ani.wasm kiri-ani.c -O3 -s ERROR_ON_UNDEFINED_SYMBOLS=0
clean: *.wasm
rm *.wasm