Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

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

Select an option

Save berniebernie/944ee83580953a7624fd to your computer and use it in GitHub Desktop.
Grows your selection of faces up to a certain angle threshold. /!\ Slow as fuck http://i.imgur.com/ZTJDrXB.gif
global string $selectedFace;
string $selected[] = `ls -sl`;
$selectedFace = $selected[0];
string $window = `window -title "Select similar faces"`;
columnLayout;
floatSliderGrp -label "Angle threshold " -field true
-minValue 0 -maxValue 180
-cc "growSel"
-value 0 "slidAngle";
showWindow $window;
proc growSel(){
global string $selectedFace;
string $newSelection[] = `ls -sl`;
if(size($newSelection)==1){
$selectedFace = $newSelection[0];
}
float $threshold = `floatSliderGrp -q -v "slidAngle"`;
growByAngle($selectedFace,$threshold);
}
proc growByAngle(string $face, float $threshold){
vector $base = norm($face);
string $newSele[] = {};
float $olds = 0;
float $news = 1;
int $round = 0;
while($olds != $news || $round > 999){
$round++;
$olds = size(`ls -sl`);
if($olds == 0){
select -r $face;
}
GrowPolygonSelectionRegion;
string $grow[] = `ls -sl -fl`;
for($face in $grow){
vector $fAngle = norm($face);
float $result[] = `angleBetween -euler -v1 ($base.x) ($base.y) ($base.z) -v2 ($fAngle.x) ($fAngle.y) ($fAngle.z)`;
if((abs($result[0])+abs($result[1])+abs($result[2]))<$threshold){
$newSele[size($newSele)] = $face;
}
}
select -r $newSele;
$news = size(`ls -sl`);
}
}
proc vector norm( string $face )
{
//from Joseph A. Hansen (Beyond Games).
vector $normal;
float $x;
float $y;
float $z;
string $pins[] = `polyInfo -fn $face`;
string $pin = $pins[0];
string $tokens[];
int $numTokens = `tokenize $pin " " $tokens`;
if ( ( $numTokens > 3 ) && ( $tokens[0] == "FACE_NORMAL" ) )
{
$x = ($tokens[$numTokens-3]);
$y = ($tokens[$numTokens-2]);
$z = ($tokens[$numTokens-1]);
$normal = << $x, $y, $z >>;
$normal = `unit $normal`;
}
return $normal;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment