Sending messages to JitterObjects

Anthony Palomba's icon

I have been having trouble trying to send messages to JitterObjects.

When I execute the following code...

var jitpath = new JitterObject("jit.path");
jitpath.append(10, 10);
jitpath.append(100, 100);
jitpath.append(200, 10);
jitpath.append(300, 100);
jitpath.calchandles();
jitpath.outputeval();

I get the following error...

js: test.js: Javascript TypeError: jitpath.outputeval is not a function, line 54

Is there something I am missing? Are some messages not supported in JS?

Anthony

Rob Ramirez's icon

hi anthony.
this is not currently possible in JS, but i have enabled this functionality for the next update.

Anthony Palomba's icon

Hey Rob, thanks for your response. Do you know when this update will be released?

Anthony Palomba's icon
Rob Ramirez's icon
Rob Ramirez's icon

here's an example of how you can do this with 6.1.3.
the relevant messages are calc_outmatrix() and calc_evalmatrix().
the relevant attributes are outmatrixname and evalmatrixname.

Max Patch
Copy patch and select New From Clipboard in Max.
outlets =2;
var jitpath = new JitterObject("jit.path");
jitpath.interpmode="spline";
jitpath.append(10, 10);
jitpath.append(100, 100);
jitpath.append(200, 10);
jitpath.append(300, 100);
jitpath.calchandles();
jitpath.calc_evalmatrix();
jitpath.calc_outmatrix();

function bang() {
    for(i=0; i
Anthony Palomba's icon

Hey Rob, glad to see that this made it in to the update. What I am trying to do is transfer the jitpath data to a matrix so that I can use getcell to step through data. How can I do this?

function draw()
{
jitpath.append(10, 10);
jitpath.append(100, 100);
jitpath.append(200, 10);
jitpath.append(300, 100);
jitpath.calchandles();
jitpath.calc_evalmatrix();
jitpath.calc_outmatrix();

//pathMatrx = new JitterObject("jit.matrix", jitpath.outmatrixname); ???

var p1, p2;
for (var k = 0; k < 4; k++) {
p1 = pathMatrx.getcell(0,k);
p2 = pathMatrx.getcell(1,k);

post("line_to", p1," ", p2, "\n");
if(k == 0)
mgfx.move_to(p1, p2);
else
mgfx.line_to(p1, p2);
};

mgfx.stroke();
}

Rob Ramirez's icon

following should work:var pathMatrx = new JitterMatrix(jitpath.outmatrixname);

Anthony Palomba's icon

Hey Rob,

I am still seeing some odd behavior trying to combine jit.path in javascript. Here is my code so far...

var jitpath = new JitterObject("jit.path");
jitpath.intermode = "spline";

function draw()
{
jitpath.append(10, 10);
jitpath.append(100, 100);
jitpath.append(200, 10);
jitpath.append(300, 100);
jitpath.calchandles();
jitpath.calc_evalmatrix();
jitpath.calc_outmatrix();

pathMatrx = new JitterMatrix("jit.matrix", jitpath.outmatrixname);
var matWidth = pathMatrx.dim[0];
var matHeight = pathMatrx.dim[1];
post("dim: " + pathMatrx.dim + "\n");

var p1, p2;

for (var k = 0; k < matWidth; k++) {
p1 = pathMatrx.getcell(0,0);
p2 = pathMatrx.getcell(0,1);

post("point", p1, " ", p2, "\n");
};
}

I get the following output....

u699000680: bad number
warning: attempting to allocate matrix with less than 1 plane
warning: attempting to allocate matrix with less than 1 plane
js: dim: 1,1
js: line_to 0 jsobject 0

Am I missing something?

Anthony Palomba's icon

Any ideas?

Rob Ramirez's icon

as written above, the way to create a JitterMatrix in js from an existing jitter matrix name is:
var pathMatrx = new JitterMatrix(jitpath.outmatrixname);

Anthony Palomba's icon

Gahhh, sorry about that. My bad...
I fixed the error, and it looks like I am getting something that makes more sense.

Thanks!

Anthony Palomba's icon

Hey Rob, I have had a chance to start digging in to this new js jit.path feature. I am seeing some strange behavior I was hoping you could shed some light on.

It looks like I can add points and evaluate the output, but the output does not seem to honor the interpmode specified. I am using spline but the output looks linear. Example patch is below...

Max Patch
Copy patch and select New From Clipboard in Max.

Any ideas?

autowatch = 1;
var width = 500;
var height = 300;

// create a [jit.gl.render] object for drawing into our window:
var glrender = new JitterObject("jit.gl.render","render-ctx");

// use a 2-dimensional projection:
glrender.ortho = 2;
glrender.blend_enable = 1;
glrender.blend = "alphablend";
glrender.depth_enable = 0;
glrender.erase_color = [0,0,0,1]; // set background to black with full erase opacity (no trails):

var mgfx = new MGraphics(width,height);
// init drawing context
mgfx.init();
mgfx.relative_coords = 0;
mgfx.autofill = 0;

var jitpath = new JitterObject("jit.path");
jitpath.intermode = "spline";

var outmatrix = new JitterMatrix(4, "char", width, height);

function bang()
{
drawProcessingScene();
}

function draw()
{
mgfx.rectangle(0, 0, width, height);

jitpath.clear();
jitpath.append(10, 10);
jitpath.append(20, 50);
jitpath.append(100, 100);
jitpath.append(200, 10);
jitpath.append(300, 100);
jitpath.calchandles();
jitpath.calc_evalmatrix();
//jitpath.calc_outmatrix();

var pathMatrx = new JitterMatrix(jitpath.evalmatrixname);
var matWidth = pathMatrx.dim[0];
var matHeight = pathMatrx.dim[1];
post("dim: " + pathMatrx.dim + "\n");

mgfx.set_source_rgba(1, 1, 1, 1);
mgfx.set_line_width(1);

var x, y, cell;
for (var j = 0; j < pathMatrx.dim; j++) {
cell = pathMatrx.getcell(j);
post("x:", cell[0], " y:", cell[1], "\n");

if(j == 0)
mgfx.move_to(cell[0], cell[1]);
else
mgfx.line_to(cell[0], cell[1]);
}

mgfx.stroke();
}

function drawLine() {

mgfx.set_source_rgba(1, 1, 1, 1);
mgfx.set_line_width(1);
mgfx.move_to(10, 10);
mgfx.line_to(100, 100);
mgfx.stroke();

}

function drawProcessingScene()
{
var theImage = null;

draw();

mgfx.identity_matrix();
theImage = new Image(mgfx.pop_group());
mgfx.image_surface_draw(theImage);

theImage.tonamedmatrix(outmatrix.name);
outlet(0, "jit_matrix", outmatrix.name);

gc();

}

Rob Ramirez's icon

you have a typo at line 22: jitpath.intermode = "spline";

Anthony Palomba's icon

DOH!

I really wish javascript could catch things like that.
Thanks again, your are an outstanding gentleman.