Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save berniebernie/a9f5adaeab0bedacefea to your computer and use it in GitHub Desktop.

Select an option

Save berniebernie/a9f5adaeab0bedacefea to your computer and use it in GitHub Desktop.
Methods of non-standard selection of objects and poly faces. Mileage may vary on complex meshes. http://i.imgur.com/ma38hQc.jpg http://i.imgur.com/rfskawS.jpg
//not tested on really heavy meshes
//
//selects shells with same number of faces
//expects 1 shell to be selected in face mode
//change numberOfTests according to mesh density
int $numberOfTests = 5000; //change according to mesh density and distribution, this took approx 10s on a 25k poly object
int $useMoreThanFacesCount = 1; //change to 1 if you want to match using UVs/edge, can be nice if you have same poly count but different UVs/edges count
int $debug = 0;
string $selectionList[] = {};
string $sele[] = `ls -sl -fl`;
string $obj = `match "^[^\.]*" $sele[0]`;
float $matchCount = size($sele);
string $extra[] = `polyListComponentConversion -fv -fe -ff -fvf -te`; //uvs, change -tuv to -te to compare with edges instead of UVs
select -r $extra;
float $matchCountExtra = size(`ls -fl -sl`);
print($debug?("faces: "+$matchCount+" uvs: "+$matchCountExtra+"\n-------------------------------------------------\n"):"");
string $faces[] = `ls -fl ($obj+".f[*]")`;
$s = size($faces);
for($i=0;$i<=$s;$i+=($s/$numberOfTests)){
$shl = `polySelect -asSelectString -ets $i $obj`;
string $shell[] = `ls -sl -fl`;
float $shellSize = size($shell);
float $shellUVs = 0;
if($useMoreThanFacesCount){
string $extraCount[] = `polyListComponentConversion -fv -fe -ff -fvf -te`; //uvs, change -tuv to -te to compare with edges instead of UVs
select -r $extraCount;
$shellUVs = size(`ls -sl -fl`);
print($debug?("faces: "+$shellSize+" uvs: "+$shellUVs+"\n"):"");
}
if($shellSize ==$matchCount && ($shellUVs== $matchCountExtra || $useMoreThanFacesCount==0 ) ){
for($j = 0;$j<size($shl);$j++){
$selectionList[size($selectionList)] = $shl[$j];
}
}
}
select -r $selectionList;
// Selects the objects that are similar to the last of the current
// selection, in the current selection, based on face counts
// (useful when cleaning up geo)
string $selection[] = `ls -sl`;
string $newSelection[];
int $faces[] = `polyEvaluate -f $selection[size($selection)-1]`;
for($obj in $selection){
int $pe[] = `polyEvaluate -f $obj`;
if($pe[0] == $faces[0]){
$newSelection[size($newSelection)] = $obj;
}
}
select -r $newSelection;
//////////////////////////////////////////////////////////////////////////////////
// select objects that have a similar wire color
string $os[] = `ls -dag -s -sl`;
$last = $os[size($os)-1];
int $color = `getAttr ($last+".overrideColor")`;
string $lists[] = {};
for($obj in $os){
if(`getAttr ($obj+".overrideColor")` == $color){
$lists[size($lists)] = $obj;
}
}
select -r $lists;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment