gpujs / gpu.js

GPU Accelerated JavaScript
https://gpu.rocks
MIT License
15.08k stars 650 forks source link

what is the proper gpu.addFunction() returnType for function which returns 3 pairs of numbers (vertices of a triangle)? #688

Open dan-reznik opened 3 years ago

dan-reznik commented 3 years ago

What should the return type for a function which returns 3 vertices of a triangle (pairs of x,y values) be, so it works with GPU.js?

// this works
function transl(p,tr) {
  return [ p[0]+tr[0], p[1]+tr[1] ];
}
gpu.addFunction(transl, { {argumentTypes: { p: 'Array(2)', tr: 'Array(2)' }, returnType: 'Array(2)' });

// I cannot get this function to work
// what should I place on return type on the gpu.addFunction()?
// all I need is a simple array of 3 (x,y) values.
function get_tri(p1,p2,p3, tr) {
  const p1t = transl(p1,tr);
 const p2t = transl(p2,tr);
 const p3t = transl(p3,tr);
 // what should the declared returned type be here?
 return [p1t,p2t,p3t];
}
gpu.addFunction(get_tri,
   { {argumentTypes: { p1: 'Array(2)', p2: 'Array(2)', p3: 'Array(2)' },
      returnType: '???' });