Monday 18 May 2009

Useful code for a rainy day.

I stole most of this from the Autodesk Area blog and adapted it. It lets you attach follicles in Maya depending on the level of blue in the given textureNode... To do - attach feathers/scales to objects, fancy controls.. density etc.

proc attachObjectToSurface(string $surface, float $u, float $v )
{
string $follicle = `createNode follicle`;
string $tforms[] = `listTransforms $follicle`;
string $follicleDag = $tforms[0];


connectAttr ($surface + ".worldMatrix[0]") ($follicle + ".inputWorldMatrix");
string $nType = `nodeType $surface`;
if( "nurbsSurface" == $nType ){
connectAttr ($surface + ".local") ($follicle + ".inputSurface");
} else {
connectAttr ($surface + ".outMesh") ($follicle + ".inputMesh");
}
connectAttr ($follicle + ".outTranslate") ($follicleDag + ".translate");
connectAttr ($follicle + ".outRotate") ($follicleDag + ".rotate");
setAttr -lock true ($follicleDag + ".translate");
setAttr -lock true ($follicleDag + ".rotate");
setAttr ($follicle + ".parameterU") $u;
setAttr ($follicle + ".parameterV") $v;

//parent -addObject -shape $obj $follicleDag;
//parent $obj $follicleDag;
}

proc scanSurface()
{
string $selection[]=`ls -sl`;
//string $obj=$selection[0];
string $surface=$selection[0];
float $i;
float $j;
for($i=0; $i<=100; $i++){ for($j=0; $j<=100; $j++){ float $Ucoord=$i/100; print $Ucoord; float $Vcoord=$j/100; print $Vcoord; float $values[]=`colorAtPoint -o RGB -u $Ucoord -v $Vcoord file1`; if($values[2]>=0.75)
{
attachObjectToSurface($surface, $Ucoord, $Vcoord);
}
}}

}