Using JS and GEN for 3D Math for Jitter visuals
Is it possible (and practical and efficient) to use GEN to do 3D Math (transformations) and call it via Javascript?
Currently, I'm using the sylvester javascript library to serve this function. (see http://sylvester.jcoglan.com/) - I include it by copying it to the jsextensions folder.
And it works great, except that once I begin doing many transformations using many instances generated by jit.gl.multiple, things slow down and the 3d transforms are the reason for the slowdown (as far as I can tell).
Here's just a sample of how I am using the Sylvester library.
this is a truncated js snippet:
var rightVector = codeObj.rightVector.multiply(-20.*Math.sin((p + 1) * time / 1000));
var downVector = codeObj.downVector.multiply(-30.*Math.sin((p + 1) * time / 1000));
var forwardVector = codeObj.forwardVector.multiply(-90.+codeObj.forwardAccumulation);
var resultVector=rightVector.add(downVector.add(forwardVector));
...
myglobal.primitivePositionMatrix.setcell(myglobal.primitiveCount, "val", resultVector.elements[0],resultVector.elements[1],resultVector.elements[2]);
Could someone show me how I would be able to use a GEN object to serve my purposes and call it via javascript? I assume that I would have to pass a message from the js script and receive a message back from GEN? Or is there another way?
If I'm not being clear, please let me know.
Thanks!
Nic
Hi,
@Wesley can you post an example for get/set param from gen inside JS.
Like :
A [jit.gen] file composed with [param a 0. 1. 2.] in a .genjit file ....& want to pass value to [param a]
I tried somethings like :
var gen = new JitterObject("jit.gen")
gen.gen = "coords";
gen.param = "2 2 2"; and another things but without success [of course i modify the coords.genjit file].
Thanks for your advise.
You can do:
gen.param("a", [0.5, 0, 0]);