Friday, April 17, 2009

Maya rotating cubes

Here's a little script that'll rotate an x,y array of cubes, based on an input textures u,v colors.

A friend of mine showed me this neat effect, and we talked over various ways to do this, I proceeded to try replicating it in Maya; this is what I came up with finally. Basicly a script which does everything needed for the basic effect. It can be improved further for more advanced settings. What it does now is create a grid of cubes along the x and y axis, binds an expression on each cube to drive it's x-rotation by an input textures' color at given u,v coordinate. It's meant to be used with an animated texture to make them rotate over time.

I'll post a clip of how this looks on youtube this weekend.

The (quickly hacked together) basic mel-snippet is as follows :

$p = `polyCube -ch on -o on -cuv 4`;

$countCur = 0;
$mx = 64;
$my = 48;

for($y = 0; $y < $my; $y++)
{
$prevsel = `ls -sl`;

for($x = 0; $x < $mx; $x++)
{
$countCur++;

string $sel[] = `ls -sl`;

float $u = (1.0 / $mx) * $x;
float $v = (1.0 / $my) * $y;
$v = -$v;

$string = ("float $col[] = `colorAtPoint -u "+$u+
" -v "+$v+" "+$animNodeTexName+"`; rotateX =
20.0 * ($col[0]+$col[1]+$col[2]);");

for($sa in $sel)
{
expression -o $sa -s $string;
}

duplicate -rr;
move -r 1 0 0;
}

select $prevsel;

duplicate -rr;
move -r 0 -1 0;
}

No comments: