MEL: Get face vertices coordinates, Sorted
Use this function to get the vertices of a face with any number of vertices. It also sorts the vertex array based on their connection to each other:
/*
Procedure Name: getPolyVtxCoords
Description: Gets the world space coordinates for the vertices that make up a given component.
Input Arguments: $sComp: The name of the component as a string
Return value: A vector array which contains the positions of the vertices that make up the component.
Usage: ein_getPolyVtxCoords( "pCube1.f[0]" );
*/
global proc vector[] fnUtils_getPolyVtxCoords(string $sComp)
{
vector $vzReturn[];
float $fzCoords[];
string $szVerticesTmp[] = `polyListComponentConversion -tv $sComp`;
string $szVertices[] = `ls -flatten $szVerticesTmp`;
for($i=0; $i < size($szVertices)-1; $i++){
for($j=size($szVertices)-1; $j > $i ; $j--){
string $sTmp[] = `polyListComponentConversion -internal -te $szVertices[$i] $szVertices[$j]`;
if($sTmp[0] == "") continue;
else {
$sTmp[0] = $szVertices[$i+1];
$szVertices[$i+1] = $szVertices[$j];
$szVertices[$j] = $sTmp[0];
break;
}
}
}
// Get the coordinates of the vertices that make up the component using xform, in groups of three.
for($i=0,$j=0; $i < size($szVertices); $i++,$j+=3) {
float $fzTmpCoords[] = `xform -q -ws -t $szVertices[$i]`;
$fzCoords[$j] = $fzTmpCoords[0];
$fzCoords[$j+1] = $fzTmpCoords[1];
$fzCoords[$j+2] = $fzTmpCoords[2];
}
int $iSize = size($fzCoords);
// Place the vertex coordinates into a vector array, three at a time.
for ($iCoords = 0, $iReturn = 0; $iCoords < $iSize; $iCoords+=3, $iReturn++)
{
$vzReturn[$iReturn] = <<
$fzCoords[$iCoords],
$fzCoords[$iCoords+1],
$fzCoords[$iCoords+2]
>>;
}
return $vzReturn;
}
Discuss - No Comments