Sending messages to JitterObjects


    Jun 11 2013 | 7:01 pm
    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

    • Jun 11 2013 | 10:59 pm
      hi anthony.
      this is not currently possible in JS, but i have enabled this functionality for the next update.
    • Jun 11 2013 | 11:14 pm
      Hey Rob, thanks for your response. Do you know when this update will be released?
    • Jun 12 2013 | 9:24 pm
      *bump*
    • Jun 12 2013 | 11:23 pm
      soon
    • Jun 19 2013 | 7:26 pm
      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.
      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
    • Jun 21 2013 | 4:18 pm
      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();
      }
    • Jun 21 2013 | 6:31 pm
      following should work:
      var pathMatrx = new JitterMatrix(jitpath.outmatrixname);
    • Jun 24 2013 | 3:50 pm
      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?
    • Jun 26 2013 | 4:56 pm
      Any ideas?
    • Jun 26 2013 | 5:36 pm
      as written above, the way to create a JitterMatrix in js from an existing jitter matrix name is:
      var pathMatrx = new JitterMatrix(jitpath.outmatrixname);
    • Jun 26 2013 | 8:34 pm
      Gahhh, sorry about that. My bad...
      I fixed the error, and it looks like I am getting something that makes more sense.
      Thanks!
    • Jul 01 2013 | 3:47 pm
      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...
      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();
      }
    • Jul 01 2013 | 7:26 pm
      you have a typo at line 22: jitpath.intermode = "spline";
    • Jul 01 2013 | 8:32 pm
      DOH!
      I really wish javascript could catch things like that.
      Thanks again, your are an outstanding gentleman.