setting up a jit.gl.multiple in JS [solved]

Fedde's icon

Hi, I'm trying to setup a jit.gl.multiple with java script but it only draws me one gridshape. Since documentation is limited and chatgpt is failing I was hoping some of you could help me out? Tnx a bunch!

inlets = 1;

outlets = 1;

var drawto = "mijnContext"; // Name of your existing jit.world context

// Initialize jit.gl.gridshape

var gridshape = new JitterObject("jit.gl.gridshape", drawto);

gridshape.shape = "cube";

gridshape.color = [1, 0, 0, 1]; // Color for visual check

// Initialize jit.gl.multiple

var multiple = new JitterObject("jit.gl.multiple", drawto);

multiple.targetname = gridshape.name; // Reference to the gridshape object

multiple.dim = [25, 1]; // Number of cubes

// Function to update positions and scales

function updateMatrices() {

var positionMatrix = new JitterMatrix(3, "float32", [25, 1]); // Columns, rows

var scaleMatrix = new JitterMatrix(3, "float32", [25, 1]); // Columns, rows

for (var i = 0; i < 25; i++) {

var x = (i % 5 - 2) * 0.3;

var y = (Math.floor(i / 5) - 2) * 0.3;

var z = 0;

positionMatrix.setcell([i, 0], "plane", 0, "val", x);

positionMatrix.setcell([i, 0], "plane", 1, "val", y);

positionMatrix.setcell([i, 0], "plane", 2, "val", z);

scaleMatrix.setcell([i, 0], "plane", 0, "val", 0.1);

scaleMatrix.setcell([i, 0], "plane", 1, "val", 0.1);

scaleMatrix.setcell([i, 0], "plane", 2, "val", 0.1);

}

multiple.position_matrix(positionMatrix.name);

multiple.scale_matrix(scaleMatrix.name);

post("Matrices updated.\n");

}

// Initialize matrices

updateMatrices();

function bang() {

post("Drawing multiple\n");

multiple.draw();

outlet(0, "bang");

post("Render called.\n");

}

function notifydeleted() {

post("Cleaning up resources.\n");

gridshape.freepeer();

multiple.freepeer();

post("Resources cleaned up.\n");

}

Fedde's icon

gridshape.automatic = 0;