PDA

View Full Version : Vector trouble



phillipwyllie
02-24-2008, 08:58 PM
Here's a little script that selects one half of a mesh(faces) along the x-axis. It works by finding the face-centrers of each face of a mesh and selects that face if it's x-coordinate of it's center is less than 0. It's a pain to try and get all those faces when modelling/mirroring. :)


global proc selectHalf()
{
vector $coords;
PolySelectConvert 1;
string $faces[]=`ls -sl -fl`;
select -cl;

for ($eachFace in $faces)
{
vector $coords = faceCenter ($eachFace);
if (($coords.x)<0)
{
select -add $eachFace;
}
}
}

global proc vector faceCenter(string $sFace)
{
string $szFilter[] = `filterExpand -sm 34 $sFace`;

if (size($szFilter) != 1)
error "faceCenter only accepts one polygon face.";
vector $vz[] = getVtxCoords($szFilter[0]);
return average3D($vz);
}

global proc vector[] getVtxCoords(string $sComp)
{
vector $vzReturn[];
float $fzCoords[] = `xform -q -ws -t $sComp`;
int $iSize = size($fzCoords);
for ($iCoords = 0, $iReturn = 0; $iCoords < $iSize; $iCoords+=3, $iReturn++)
{
$vzReturn[$iReturn] = <<
$fzCoords[$iCoords],
$fzCoords[$iCoords+1],
$fzCoords[$iCoords+2]
>>;
}

return $vzReturn;
}

global proc vector average3D(vector $vz[])
{
vector $vReturn;

for ($each in $vz)
$vReturn += $each;

return $vReturn / size($vz);
}

I'd like to have the script take in what axis you want to "mirror" over, with the x in the line "if (($coords.x)<0)" being a variable, but Maya gives an error about not being able to a logic operation on a string. So how do you do it, if possible?
Thanks