alpha mask with jit.gl.slab and javascript

Roland Sproll's icon

Hello all,

I like to use the jit.gl.slab object in javascript for dynamically use alpha masks.

I tried it this way, unfortunately not very successful:

inlets = 2;
outlets = 1;

var tmpmatrix = new JitterMatrix();

var plane = new JitterObject("jit.gl.videoplane","foo");
plane.blend_enable = 1;

var slab = new JitterObject("jit.gl.slab","foo");
slab.file = "cc.alphaglue.jxs";

plane.texture = slab.texture;

function jit_matrix(inname)
{
if(inlet == 1)
{
tmpmatrix = inname;
}
else
{
slab.jit_matrix([inname,tmpmatrix]);
slab.draw();

plane.texture = slab.texture;

// post(slab.file);
}
}

I'm not sure, if the js slab object handles the input of 2 inlets like an array to the jit_matrix method. I'm also not sure, if the initialisation of the js slab object is correct by assigning the "file" attribute to the desired file name. If I post the file attribute Max crashes.

Hopefully somebody can help!
Thanks
Roland

Roland Sproll's icon

After Max also was crashing using a second jit.gl.slab in the patcher window, without any javascript, I found another solution, dropping the slab object, using jit.pack instead:

var plane = new JitterObject("jit.gl.videoplane","poo");
var maskmatrix = new JitterMatrix(4,"char",320,240);
var tmpmatrix = new JitterMatrix(4,"char",320,240);

var pack = new JitterObject("jit.pack");
pack.offset = [1,1];
pack.jump = [1,3];

function jit_matrix(inname)
{
if(inlet == 1)
{
maskmatrix.setinfo(inname);
maskmatrix.frommatrix(inname);
}
else
{
pack.matrixcalc([inname,maskmatrix.name],tmpmatrix);
plane.jit_matrix(tmpmatrix.name);
}
}

Cheers,
Roland.

Roland Sproll's icon

Hm, after making a detour, I'm at this point again, that I need to use jit.gl.slab objects in Javascript. Please, does anybody know how to use jit.gl.slab for alpha masking in Javascript or have a good example, how to handle open gl objects with two inlets in JS?
I tried al lot and have no ideas anymore.
Thanks, Roland.

Rob Ramirez's icon

hi roland.
it's a little tricky, but entirely possible.
the trick is to use the "activeinput" attribute to tell the slab which input will receive the textures or matrices.
after that, you simply use the "jit_matrix" or "jit_gl_texture" messages followed by the matrix or texture name.

i've attached a js and max patch to demonstrate.

4911.slabjs.zip
zip
Roland Sproll's icon

That was exactly what I needed, thanks a lot Rob.

Andrew's icon

Wow, Rob, your patcher and JS are like the Rosetta Stone! Passing a jit_matrix into a named function, ie not jit_matrix(), rendering in JS, slabs in JS are things I've needed and had a hard time finding documentation on.
Thanks!
Andrew