Friday, July 24, 2015

maya MEL: select texture border edges

Maya can visualize texture borders, but offers no way to quickly select them. Here a small script that converts any selection to border edges. After converting a selection to edges, it: tests for single connected faces (yields the same results as maya's 'convert to shell border') and tests for more than 2 uv's (indicating an edge is shared by multiple shells, and thus a texture border).

string $sel[];
$sel = `polyListComponentConversion -toEdge`;

$sel = `ls -sl -flatten`;
string $borderEdges[] = {};

for ($edge in $sel)
{
       int $count;
       string $list[];
       
       // test on uvs > 2
        $list = `polyListComponentConversion -toUV $edge`;
        $list = `ls -flatten $list`;
       
        $count = `size $list`;
        if ($count>2)
        {
              $borderEdges = stringArrayCatenate($borderEdges,{$edge});
        }
       
        // test on faces == 1
        $list = `polyListComponentConversion -toFace $edge`;
        $list = `ls -flatten $list`;
       
        $count = `size $list`;
        if ($count==1)
        {
              $borderEdges = stringArrayCatenate($borderEdges,{$edge});
        }
}

//cleanup
$borderEdges = `stringArrayRemoveDuplicates $borderEdges`;
select $borderEdges;

2 comments: