index.js
// allocate buffers that we can send into webasm
allocate buffers that we can send into webasm
allocate buffers that we can send into webasm
function initModule(iMesh) {
  mesh = iMesh
  var cellsArr = new Int32Array(mesh.cells.length * 3);
  var ia = 0
  for(var ic = 0; ic < mesh.cells.length; ++ic) {
    var c = mesh.cells[ic]
    cellsArr[ia++] = c[0]
    cellsArr[ia++] = c[1]
    cellsArr[ia++] = c[2]
  }
  var nDataBytes = cellsArr.length * cellsArr.BYTES_PER_ELEMENT;
  cellsHeapPtr = Module._malloc(nDataBytes)
  cellsHeap = new Uint8Array(Module.HEAPU8.buffer, cellsHeapPtr, nDataBytes);
  cellsHeap.set(new Uint8Array(cellsArr.buffer));
  var positionsArr = new Float64Array(mesh.positions.length * 3);
  var ia = 0
  for(var ic = 0; ic < mesh.positions.length; ++ic) {
    var c = mesh.positions[ic]
    positionsArr[ia++] = c[0]
    positionsArr[ia++] = c[1]
    positionsArr[ia++] = c[2]
  }
  var nDataBytes = positionsArr.length * positionsArr.BYTES_PER_ELEMENT;
  positionsHeapPtr = Module._malloc(nDataBytes)
  positionsHeap = new Uint8Array(Module.HEAPU8.buffer, positionsHeapPtr, nDataBytes);
  positionsHeap.set(new Uint8Array(positionsArr.buffer));
  calledInitModule = true
}
function initModule ( iMesh ) { mesh = iMesh var cellsArr = new Int32Array ( mesh . cells . length * 3 ) ; var ia = 0 for ( var ic = 0 ; ic < mesh . cells . length ; ++ ic ) { var c = mesh . cells [ ic ] cellsArr [ ia ++ ] = c [ 0 ] cellsArr [ ia ++ ] = c [ 1 ] cellsArr [ ia ++ ] = c [ 2 ] } var nDataBytes = cellsArr . length * cellsArr . BYTES_PER_ELEMENT ; cellsHeapPtr = Module . _malloc ( nDataBytes ) cellsHeap = new Uint8Array ( Module . HEAPU8 . buffer , cellsHeapPtr , nDataBytes ) ; cellsHeap . set ( new Uint8Array ( cellsArr . buffer ) ) ; var positionsArr = new Float64Array ( mesh . positions . length * 3 ) ; var ia = 0 for ( var ic = 0 ; ic < mesh . positions . length ; ++ ic ) { var c = mesh . positions [ ic ] positionsArr [ ia ++ ] = c [ 0 ] positionsArr [ ia ++ ] = c [ 1 ] positionsArr [ ia ++ ] = c [ 2 ] } var nDataBytes = positionsArr . length * positionsArr . BYTES_PER_ELEMENT ; positionsHeapPtr = Module . _malloc ( nDataBytes ) positionsHeap = new Uint8Array ( Module . HEAPU8 . buffer , positionsHeapPtr , nDataBytes ) ; positionsHeap . set ( new Uint8Array ( positionsArr . buffer ) ) ; calledInitModule = true }
allocate buffers that we can send into webasm
allocate buffers that we can send into webasm