Wednesday, July 13, 2011

Rig Setup

So this is probably among some of the first script I wrote, pretty basic laying the rig out by creating locators for each joint, creating lines in between locators to signal joint structure, and then creating spherical displays for the user to grab and position in place of their characters joints.

For this I wrote two simple utilities; one for drawing lines between selected objects and another for creating displays on top of and control selected objects.

I'll post this one here now, and the other utility up later today, and then hopefully the entire rig setup.


////////////////////////////////////////////////
//DRAW LINE
//by SL
//
//This will draw a line inbetween multiple objects in order of //their selection.
//It will also attach the CVs to what was selected in order.
//automatic naming, eg: [$characterName_$part_drawLine]




proc drawLine(string $characterName, string $part)
{
//define variables
string $characterName;
string $part;
string $sel[] = `ls -sl`;
int $selSize = size($sel);
vector $Current;
int $counter;
vector $points[];
string $linePoints;

//put selected points into vector array
for ($counter = 0; $counter < $selSize; $counter++)
{
$points[$counter] = `xform -q -ws -t $sel[$counter]`;
}

//selection cleared, make a string from stored vectors
for ($counter = 0; ($counter + 1) < $selSize; $counter++)
{
vector $Current = $points[$counter];
if ($counter == 0)
{
$linePoints = ("-p " + ($Current.x) + " " + ($Current.y) + " " + ($Current.z) + " ");
}
$linePoints = $linePoints + ("-p " + ($Current.x) + " " + ($Current.y) + " " + ($Current.z) + " ");
}


string $crvName = ($characterName + "_cnst_" + $part + "_drawLine");
string $crv = `eval ("curve -d 1 " + $linePoints + "-n " + $crvName + ";")`;


for ($counter = 0; $counter < $selSize; $counter++)
{
connectAttr -f ($sel[$counter] + ".t") ($crv + ".cv[" + $counter + "]");
}
}




So the way this works is I'm gathering world vector positions of the objects and then assembling them into a string in which I will run an  eval  command. The assembled string flags each point to put a CV. The result of the eval command is the name of the string we just created. Then after the curve has been created, in order to connect all the CVs to the objects, we must cycle through again in a for loop using the arrays $sel[]  and ($crv + ".cv[]").  The translate of the object ($sel[$index] + ".t") gets connected into the CV $index.


There is no script checking to make sure user input is a string and not a vector array. To do so a validate string function would be useful to test if the input is a string. If true, do your work, if false, error out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home