connecting jit.phys.body to jit.gl.gridshape in javascript
i want to generate many jit.gl.gridshape objects which are connected to jit.phys.body objects in javascript.
my code works fine, but since i set the gridshapes position and rotatexyz to the phys.bodies' position and rotatexyz in the bang-function (which is triggered by a qmetro 40), it uses a lot of cpu performance.
i also tried to do a similar patch using jit.phys.multiple and jit.gl.multiple (without javascript). but that's not an alternative for me, cause i want to change the x-, y- and x- scales of the objects on the fly.
can anyone explain how to connect jit.gl.gridshape- to jit.phys.body-objects using javascript only?
thanks for any help!
PS: below is my code which uses a lot of cpu-performance.
var maxo = 250;
var cside = 0.04;
var cube = new Array();
var cubx = new Array();
for(var i=0;i
{
var r = (Math.random()*0.1)-0.05;
cube[i] = new JitterObject("jit.phys.body","orjo-world");
cube[i].shape = "cube";
cube[i].scale = [cside, 0.1, cside];
cube[i].position = [r, r, r];
cube[i].friction = 0;
cube[i].mass = 1;
cube[i].restitution = 0;
cube[i].damping = [0.99,1];
cubx[i] = new JitterObject("jit.gl.gridshape","orjo");
cubx[i].shape = "cube";
cubx[i].shader = "orshade";
cubx[i].lighting_enable = 1;
cubx[i].antialias = 1;
cubx[i].scale = [cside, 0.1, cside];
cubx[i].position = cube[i].position;
}
function bang()
{
for(var i=0;i
{
cubx[i].position = cube[i].position;
cubx[i].rotatexyz = cube[i].rotatexyz;
}
}
function resetit()
{
for(var i=0;i
{
var r = Math.random()*0.1-0.05;
cube[i].position = [r, r, r];
}
}
you can connect a phys.body to a gl.gridshape in javascript by setting the phys.body @targetname to the gl.gridshape @name attribute:pbody.targetname=gshape.name;
Hi Rob, I need the opposite, to connect a gl.gridshape @matrixoutput 1 to a phys.body @shape concave. Tried different ways without success. Any help is appriciated. Thanks!
Hello 2k,
You need to connect the the gl.gridshape @matrixoutput 1 and the phys.body to a gl.gridshape. This patch was made to test a bug some time ago, but shows the configuration. You can work it up in javascript if that's using Rob's info if that's your goal.
Hope this helps.
Thanks. I understand how it works and I have also a patch I'm porting to js. For a reason I don't know I'm not able to matrixcalc the gridshape matrix to the body in js.
Ah, sorry. I misunderstood.
search the Max browser for "js.gl.matrixoutput.maxpat" and open the "process-matrixout.js" file to see how to get the matrixoutput matrix name.
send this matrix name to the phys.body like this "pbody.jit_matrix(gsmatrix.name);"
Thanks Rob, worked perfectly!