homeclientsportfolioprojectscurriculum vitaetechcontactsitemapdk


Maya Shaders

Mel scripts


Driving object translation with 2D Texture.


This is a small test I did after a question came up on the Highend mailing list. Basically You can connect the output of the colorAtPoint mel command to the translate value of a grid of objects using a small expression.

First create a 10 by 10 grid of nurbs spheres. Make sure that they are numbered 1-100.

The 10 by 10 sphere grid.

The 10 by 10 sphere grid.

Now go into the hypergraph and make a 2D texture (I did a ramp)

Ramp used to displace along Y.

Ramp used to displace along Y.

The expression only looks at the alpha value and I changed the default ramp to a black and white gradient to better see the deformation.

Create the expression.

Create the expression.

Finally create a new expression like this:

$curGrid = `colorAtPoint -o A -su 10 -sv 10 ramp1`;

int $numColumns = 10;
int $numRows = 10;

for ($curRow=1;$curRow <= $numRows;$curRow++){
for ($curColumn=1;$curColumn <= $numColumns;$curColumn++){
int $curNumber = $curColumn+ (($curRow-1)*$numColumns);
setAttr ("nurbsSphere" + $curNumber + ".translateY")

You can use the alpha gain on the texture to change the scale of the displacement.

Drag the time slider to see displacement.

Drag the time slider to see displacement.

One thing to be aware of is that since it is an expression, the deformation will only update when the scene is played forward so you need to play it to see any changes in the 2D texture.

I think that one possible good use for this technique is controlling crowds by using textures to drive set driven keys or blend shapes on simple characters. This way it would be easy to make a flowing wave in a crowd or something similar. You only need to be carefull when placing and numbering the characters so that the simple for loops will access the correct characters.


Download aiColorAtPointExample.mb

Go Back

3/29/2023 - 136053 hits Copyright 1996-2004 Animation Invasion. All rights reserved their respective owners.