passing a matrix to a texture in js

mattyo's icon

Hi,

For a project I'm working on, I need to import some images, and have both a matrix and a texture for each image. I've written a little js that creates a dictionary entry for each matrix/texture pair, but I'm failing to successfully pass the matrix successfully to the texture. I think I'm just not grokking matrixcalc().

I would think it would be (pseudocode):

dict.texture.matrixcalc(dict.matrix)

But I clearly don't get it.

Demo patch & js attached. Any help appreciated!

\M

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

save as layers.js:

var layers = {};

// all of this seems to be working fine

function add(name, path){

    if(layers[name]== undefined){

        layers[name] = { matrix: null, texture: null };

        var matrix = new JitterMatrix(4, "char", 320, 240);
            matrix.adapt = 1;
            matrix.name = ("---"+ name + "_matrix");

        var texture = new JitterObject("jit.gl.texture");
            texture.name = ("---" + name + "_tex"); 
            texture.drawto = ("main");

        layers[name].matrix = matrix;
        layers[name].texture = texture; 
    }

    
    layers[name].matrix.importmovie(path)

    push_the_matrix(name); //problem function

    post("\nLayer details: " + JSON.stringify(layers[name]) + "\n");
} 

//I can't really grasp what should be where here 

function push_the_matrix(name){
    var t = layers[name].texture;
    post("\nt=tex: ", t)
    var result = t.matrixcalc(layers[name].matrix);
    if (result) {
        post("\nwinner")
    }
    else{
        post("\nloser")
    }

}

Rob Ramirez's icon

dict.texture.jit_matrix(dict.matrix.name)

mattyo's icon

Thanks for the fish, Rob!

However, as a net might be helpful in the future, let me see if I have this clear...

in my case what specifically works is:

layers[name].texture.jit_matrix(layers[name].matrix.name);

-- "layers[name].texture" is pointing to my texture, so in the above "jit_matrix" is a method of the jit.gl.texture object, yes? So, this is just basically sending the "jit_matrix foo" message to the texture, just as one would in vanilla max, yes?

-- the matrix stored in "(layers[name].matrix.name)" has to be referenced specifically by it's name attribute -- I can't just reference the matrix object itself, yes? (well, if I try, Max crashes, so that should be the answer, but I don't understand why....

Thanks!

\M