morping matrices - ctl-matrices

frank desben's icon

hello all,

i use jit.gl.nurbs and distort them with the ctlmatrix matrix command.

i put matrices of the dimension 5*5 in the ctlmatrix.

and i interpolate between random control-matrixes
for that i use [line] and setcell to independly interpolate the cells between random numbers.
this is (although the matrix is quite small) computationally demanding as i change all the values for the ctl-matrices with a [metro 30] all the time.

i was wonering whether there's an efficient way to randomly morph a matrix - constantly change it's values independly.

or is there a more efficent way to distort the nurbs in general ?

help is very much appreciated
thanks a lot
frank

Rob Ramirez's icon

jit.slide?

seejayjames's icon

frank desben wrote on Fri, 27 March 2009 14:45hello all,

i use jit.gl.nurbs and distort them with the ctlmatrix matrix command.

i put matrices of the dimension 5*5 in the ctlmatrix.

and i interpolate between random control-matrixes
for that i use [line] and setcell to independly interpolate the cells between random numbers.
this is (although the matrix is quite small) computationally demanding as i change all the values for the ctl-matrices with a [metro 30] all the time.

Not sure about the optimization question, but one thought: if you use jit.spill to put your ctlmatrix into a list (like a multislider), then you can use the very powerful [pattr] to interpolate between entire sets of ctl-points, rather than the [line] and setcell for each. You won't have the same kind of individual control, but it could make certain morphing effects much easier. Use a [preset] and set @pattrstorage of it to the pattrstorage you're using. Then you can interpolate between stored slots/presets (here's where [line] or [mtr] can also be very handy). Just use jit.fill after the multislider to get the list back into matrix form, to go to the jit.gl.nurbs. (pattr does not support matrices directly.)

Also for lots more cool generative ctlmatrices, look into jit.bfg if you haven't already. This function is amazing and can save lots of work, and can generate all kinds of interesting functions with little work. Hook up a [counter] to the offset X offset Y commands (or a separate counter for each) and the matrix will "flow along" automatically through its functions.

You might also try jit.gl.mesh with these ctlmatrices as the vertex matrix, that also works great, and may be more optimized. Perhaps the jit.gl.nurbs does a lot more calculations than jit.gl.mesh, I'm not sure but I imagine so as there's lots of interpolation required.

Possibly these ideas will slow things down even more, but they sure are cool...

Federaik's icon

if you want to interpolate two matrices i think jit.xfade is a good object to do that

Jean-Francois Charles's icon

It's more efficient to do all your processing in "matrix" domain (than to transform to list and use pattr for instance). Stay with matrices, and try as far as possible to not treat individual cells nor transform them into lists.
For morphing, I like [jit.slide], although you don't have the same control as with [jit.xfade] or something of your own with [jit.op].
Feel free to send a small patch to show what you are doing. You may get more answers.
Jean-François.

seejayjames's icon

-->
It's more efficient to do all your processing in "matrix" domain (than to transform to list and use pattr for instance). Stay with matrices, and try as far as possible to not treat individual cells nor transform them into lists.
-->

That's good to know, I figured it would be less efficient, but thought it would be useful for pattr. After thinking about it a little, though, using a jit.matrixset and jit.xfade between two stored matrices seems like it would give similar results to interpolating between pattrstorage slots, and using a lookup table instead of a straight [line] to the xfade could simulate the interpolation types available in pattr. You could also use an integer [line] to access the lookup table, or a counter, etc.

frank desben's icon

hi all,
thank you for all you very helpful advices!

jit.slide has the problem that i can conly go from one matrix to another - if i generate random matrices and then morph between them you can actually see when the endpoint is reached and a new morph begins.

i actually use the pattr object to morph between matrices i have saved - that works very well - if i want to go directly to one matrix! but for the individual cell morphing it's not so good.

jit.bfg is a good hint, perhaps i should do it with jit.expr - i have to think whether i can come up with a good formular that does what I try to do - but thanks for the idea to go in that direction.

i think i'll give jit.expr a try now.

thanks again, best frank

Andrew Benson's icon

Here is a basic pattrstorage-like interpolator for 3 matrix inputs. The big trick is normalizing the weights. I also included a subpatch that does perpixel weighted interpolations using a matrix input, but I think it's probably overkill. There are a number of tricks similar to this in the tutorial "A Noisy Matrix" I wrote a couple of years back:https://cycling74.com/story/2006/6/29/15148/4131

Let me know if that helps.

Andrew B.

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

frank desben's icon

hi andrew,
thanks for the tip

unfortunately i get an error message when i paste to max - does it work for you (to copy the code below)?
thanks

frank

Rob Ramirez's icon

andrew's code works fine. are you on max 5?