//////////////////////////////////////////////////////////////////////////////////////// // Auto UV Building Facades // written by: Kenny Lammers // Surreal Software, 2008 // // /////////////////////////////////////////////////////////////////////////////////////// // Script Start /////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////// // Auto Map Walls And Trim Proc /////////////////////////////////////////////////////////////////////////////////////// global proc setClipping() { setAttr "perspShape.farClipPlane" 10000000; setAttr "perspShape.nearClipPlane" 0.1; } proc float[] getNormalVec(string $faceNam) { //go through each face and find out its normal direction //if it is facing in a direction other than the y direction //then map it //select -cl; //find the direction of the face string $normals[] = `polyInfo -fn $faceNam`; float $normalV[]; string $temp; $temp = match("\-*[0-9]+\.[0-9]+ \-*[0-9]+\.[0-9]+ \-*[0-9]+\.[0-9]+", $normals[0]); //place the individual vector directions into the $normalV array 0 = x, 1 = y, 2 = z. $normalV[0] = match("\-*[0-9]+\.[0-9]+", $temp); $normalV[1] = match(" \-*[0-9]+\.[0-9]+",$temp); $normalV[2] = match("\-*[0-9]+\.[0-9]+$", $temp); //select -cl; return $normalV; } global proc mapGeo() { //select only the faces facing in a horizontal direction setClipping; string $sel[] = `ls -sl`; int $faceN[] = `polyEvaluate -f $sel[0]`; int $faceIndex = $faceN[0] - 1; select -cl; for($i = 0; $i <= $faceIndex; $i++) { string $curNam = ($sel[0] + ".f[" + $i + "]"); //print($curNam + "\n"); float $normalV[] = `getNormalVec($curNam)`; //print($normalV[2] + "\n"); /* if($normalV[0] == 1) { select -add $curNam; } */ /* if($normalV[0] == 1 || $normalV[0] == -1) { select -add $curNam; } else if($normalV[2] == 1 || $normalV[2] == -1) { select -tgl $curNam; } else if($normalV[1] < 0) { select -tgl $curNam; } else { print("Face: " + $curNam + " is a vertical face" + "\n"); } */ //find out which radio button is selected int $radioVal = `radioButtonGrp -q -sl "selectRGB"`; if($normalV[1] < 0.5 && $radioVal == 1) { select -tgl $curNam; } else if($normalV[1] > 0.5 || $normalV[1] == 1.0) { if($radioVal == 2) { select -tgl $curNam; } } } //store all the selected faces string $faceSel[] = `ls -sl`; polyAutoProjection -lm 0 -pb 0 -ibd 1 -cm 0 -l 2 -sc 1 -o 1 -p 3 -ps 0.2 -ws 1 $faceSel; } /////////////////////////////////////////////////////////////////////////////////////////////// // End auto Map Procs /////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// // Start sewing Scripts /////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// /// Indput: string and array /// /// Output: returns 1 if string occurs in array, 0 if not /// /////////////////////////////////////////////////////////////////////////////////// proc int OM_inArray( string $string , string $array[]) { int $int; int $return = 0; for ($int = 0 ; $int < size($array) ; $int++) { if ( $string == $array[$int] ) {$return = 1;} } return $return; } /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// /// Indput: 2 arrays /// /// Output: adds the second array at the end of the first /// /////////////////////////////////////////////////////////////////////////////////// proc string[] OM_addStringArray(string $origArray[] , string $addArray[]) { int $int; for ($int = 0 ; $int < size($addArray) ; $int++) { $origArray[ size($origArray) ] = $addArray[$int]; } return $origArray; } /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// /// Indput: Indput selection /// /// Output: String: Object name /// /////////////////////////////////////////////////////////////////////////////////// proc string OM_objectName(string $objSelection) { string $name[]; tokenize $objSelection "." $name; return $name[0]; } /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// /// Indput: a component name /// /// Output: returns 1 if the indput name has a number and 0 if /// /// it hasn't /// /////////////////////////////////////////////////////////////////////////////////// proc int OM_haveNumber(string $indput) { string $dump[]; int $size = `tokenize $indput "[]" $dump`; int $return = 0; if ($size == 2) { $return = 1; } return $return; } /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// /// Indput: a face /// /// Output: returns 1 if the face's a quad and 0 if it isn't /// /////////////////////////////////////////////////////////////////////////////////// proc int OM_isFaceQuad(string $face ) { string $token[]; string $dump[]; int $result = 0; if( OM_haveNumber($face) == 1 ) { $token = `polyInfo -fe $face`; tokenize ($token[0], $dump); if (size($dump) == 6 ) { $result = 1; } } return $result; } /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// /// Indput: Edge /// /// Output: returns a string Array with the two faces adjacent /// /// to the input edge /// /////////////////////////////////////////////////////////////////////////////////// proc string[] OM_edge2face(string $edge) { string $dump[]; string $token[]; string $object = `OM_objectName($edge)`; string $return[]; $token = `polyInfo -ef $edge`; tokenize ($token[0], $dump); $return[0] = $object + ".f[" + $dump[2] + "]"; $return[1] = $object + ".f[" + $dump[3] + "]"; return $return; } /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// /// Indput: 2 arrays /// /// Output: returns an array with the first array turned backwards /// /// and combined with the second /// /////////////////////////////////////////////////////////////////////////////////// proc string[] OM_combineStringArray(string $backwardArray[] , string $forwardArray[]) { int $int; string $return[]; for ($int = (size($backwardArray)-1) ; $int >= 0 ; $int--) { $return[(size($return))] = $backwardArray[$int]; } for ($int = 1 ; $int <= (size($forwardArray)-1) ; $int++) { $return[(size($return))] = $forwardArray[$int]; } return $return; } ////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// /// Indput: Edge plus a quad face adjacent to the edge. /// /// Output: string array, where [0] is the edge on the opposite side/// /// of the face and [1] is the new face adjacent to the new /// /// edge, where the face isn't similar to the input face /// /////////////////////////////////////////////////////////////////////////////////// global proc string[] OM_OppEdgeOnFace(string $edge, string $quadFace) { string $token[]; string $dump[]; string $return[]; string $object = `OM_objectName($edge)`; $token = `polyInfo -fe $quadFace`; tokenize ($token[0], $dump); for ($int = 2 ; $int <= 5 ; $int++) { if( (OM_objectName($edge) + ".e[" + $dump[$int] + "]") == $edge) { if ($int == 2 || $int == 3) { $return[0] = ($object + ".e[" + $dump[($int+2)] + "]"); } else $return[0] = ($object + ".e[" + $dump[($int-2)] + "]"); } } $token = `polyInfo -ef $return[0]`; tokenize ($token[0], $dump); if (($object + ".f[" + $dump[2] + "]") == $quadFace) { $return[1] = $object + ".f[" + $dump[3] + "]"; } else { $return[1] = $object + ".f[" + $dump[2] + "]"; } return $return; } /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// /// Indput: Edge and edge array /// /// Output: String array with ringedges. /// /// If only one edge appear on the ring it returns a whole /// /// ringloop. /// /// If a element in $selection is detected on the ring it /// /// only selects a partial ring between input and the /// /// $selection element /// /////////////////////////////////////////////////////////////////////////////////// proc string[] OM_listRing(string $edge1, string $selection[]) { global string $partials[]; string $dump[]; string $token[]; string $split1[]; string $split2[]; string $faces[]; string $return[]; int $stop; int $int; int $stoppedRing; int $partialBool = 0; $split1[0] = $edge1; $split2[0] = $edge1; $faces = OM_edge2face($edge1); $int = OM_isFaceQuad($faces[0]); switch ( $int ) { case 1: $edgeNface[1] = $faces[0]; $stoppedRing = 1; do { $stop = 0; $edgeNface = (OM_OppEdgeOnFace( $split1[ (size($split1)-1) ] , $edgeNface[1] )); $split1[ size($split1) ] = $edgeNface[0]; if ($edgeNface[0] == $edge1) { $stop = 1; } else if (OM_inArray($edgeNface[0], $selection) == 1) { $stoppedRing = 0; $partialBool = 1; $partials[size($partials)] = $edgeNface[0]; $stop = 1; } } while (OM_isFaceQuad($edgeNface[1]) == 1 && $stop == 0); if ($edgeNface[0] == $edge1) break; case 0: if (OM_isFaceQuad($faces[1])) { $edgeNface[1] = $faces[1]; $stoppedRing = ($stoppedRing + 2); do { $stop = 0; $edgeNface = OM_OppEdgeOnFace($split2[(size($split2) -1)], $edgeNface[1]); $split2[size($split2)] = $edgeNface[0]; if ($edgeNface[0] == $edge1) { $stop = 1; } else if (OM_inArray($edgeNface[0] , $selection) == 1) { $stoppedRing = ($stoppedRing - 2); $partialBool = 1; $partials[size($partials)] = $edgeNface[0]; $stop = 1; } } while (OM_isFaceQuad($edgeNface[1]) == 1 && $stop == 0); } } if ($partialBool == 1) { if (size($split1) == 1) $return = $split2; else if (size($split2)== 1) $return = $split1; else if (size($split1) < size($split2) && $stoppedRing != 1) $return = $split1; else if (size($split1) < size($split2) && $stoppedRing == 1) $return = $split2; else if (size($split1) > size($split2) && $stoppedRing != 2) $return = $split2; else if (size($split1) > size($split2) && $stoppedRing == 2) $return = $split1; else if (size($split1) == size($split2) && $stoppedRing != 1) $return = $split1; else if (size($split1) == size($split2) && $stoppedRing != 2) $return = $split2; } else $return = OM_combineStringArray($split1 , $split2); return $return; } /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// /// TOOL /// /// Indput: Edge Selection /// /// Function: Ring selection from every selected edge /// /////////////////////////////////////////////////////////////////////////////////// global proc OMT_to_selectRing() { global string $partials[]; clear $partials; string $selection[] = `filterExpand -sm 32`; string $select[]; if (size($selection) == 0) error "You need to select at least one poly edge"; else { undoInfo -swf 0; // Switches undo off for ( $sel in $selection ) { if (OM_inArray($sel, $partials) == 1) continue; $select = (OM_addStringArray($select, ( OM_listRing($sel,$selection) ) )); } undoInfo -swf 1; // Switches undo on select -r $select; } } global proc sewUV() { print("Sewing UVs" + "\n"); //store the selected edges string $selEdge[] = `filterExpand -ex 1 -sm 32`; int $sizeEdge = size($selEdge); int $index = $sizeEdge - 1; //print($index + "\n"); //call the edge ring select OMT_to_selectRing; //sew uvs except for the orginally selectetd edges string $newSel[] = `filterExpand -ex 1 -sm 32`; int $selSize = size($newSel) - 1; //print($selSize + "\n"); //Clear the Edge array string $sewEdges[]; clear $sewEdges; //remove the orignally selected edges from the group string $diff[] = stringArrayRemove($selEdge, $newSel); //sew together the selected edges select -cl; select -r $diff; polyMapSewMove -nf 10 -lps 0 $diff; //select the shell so the user can move it select -cl; select -r $diff; PolySelectConvert 4; SelectUVShell; polySelectBorderShell 0; //Switch to the move tool moveTool; } global proc moveTool() { TranslateToolWithSnapMarkingMenuPopDown; TranslateToolWithSnapMarkingMenu; MarkingMenuPopDown; if (`popupMenu -exists tempMM`) { deleteUI tempMM; }if (`popupMenu -exists tempMM2`) { deleteUI tempMM2; }; } //////////////////////////////////////////////////////////////////////////////////////////////// // End Sewing Scripts // //////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////// // build the GUI here //////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////// /* if(`window -exists autoUVWin`) { deleteUI autoUVWin; } string $win = `window -t "Auto UV BLDG" -wh 200 160 -tlb 1 -s 0 autoUVWin`; windowPref -w 200 -h 250 autoUVWin; string $form = `formLayout`; radioButtonGrp -numberOfRadioButtons 2 -columnWidth2 50 50 -select 1 -labelArray2 "Walls" "Roofs" "selectRGB"; string $mapBut = `symbolButton -w 100 -h 50 -i "Sew_ButIMG.bmp" -c "mapGeo"`; string $sewBut = `symbolButton -w 100 -h 50 -i "Sew2_ButIMG.bmp" -c "sewUV"`; floatFieldGrp -numberOfFields 3 -label "Tolerance" -value1 1.0 -value2 1.5 -value3 1.0 -columnWidth4 70 40 40 40 "tolFG"; string $spacer = `separator -w 190 -st "double"`; formLayout -edit //radio button group -attachForm "selectRGB" "top" 5 -attachForm "selectRGB" "left" 40 //buttons -attachForm $mapBut "top" 30 -attachForm $mapBut "left" 40 //floatFieldGrp -attachForm "tolFG" "top" 90 -attachForm "tolFG" "left" 0 //separator -attachForm $spacer "top" 120 -attachForm $spacer "left" 2 //Sew button -attachForm $sewBut "top" 140 -attachForm $sewBut "left" 40 $form; showWindow $win; //radioButtonGrp -q -sl "selectRGB"; //floatFieldGrp -q -v2 "tolFG"; */