// MTUVPanel.mel // Written by Markus Tessmann, Rock Farm Animation // ------------------------------------------------------- // // This script creates a control panel with presets for fast and easy // scaling and rotation of UV coordinates on an object. // // Source this script, select your UV's, and start scaling and rotating. // // // Create the window. if(`window -ex UVPanelWindow`) deleteUI UVPanelWindow; window -title " UV Control Centre " -wh 500 500 UVPanelWindow; string $form = `formLayout`; string $frameAction = `frameLayout -labelVisible 0`; // *** Pivot Point *** string $setPivot = `columnLayout`; text -w 70 -label "UV Pivot" -font "boldLabelFont"; rowColumnLayout -numberOfColumns 3 -columnWidth 1 20 -columnWidth 2 20 -columnWidth 3 20 ; radioCollection; $rbUVpivot11 = `radioButton -label "" `; $rbUVpivot12 = `radioButton -label "" `; $rbUVpivot13 = `radioButton -label "" `; $rbUVpivot14 = `radioButton -label "" `; $rbUVpivot15 = `radioButton -label "" `; $rbUVpivot16 = `radioButton -label "" `; $rbUVpivot17 = `radioButton -label "" `; $rbUVpivot18 = `radioButton -label "" `; $rbUVpivot19 = `radioButton -label "" `; setParent ..; rowColumnLayout -numberOfColumns 2; radioCollection; $rbUVCentric = `radioButton -label "UV Centric"`; $rbNormalized = `radioButton -label "Normalized"`; setParent ..; // *** Action Buttons *** string $rowAction = `rowColumnLayout -numberOfColumns 3 -ann "Action"`; button -label "Scale" -command "doScale($pu,$pv,$su,$sv)" ; button -label "Rotate" -command "doRotate($pu,$pv,$angle)" ; button -label "Show Values" -command "doShowMe($pu,$pv,$su,$sv,$angle)" ; setParent ..; textField -text "Ready" -editable false -width 300 StatusLine; setParent ..; setParent ..; //parent to formLayout string $tabs = `tabLayout -innerMarginWidth 5 -innerMarginHeight 5`; // *** Scale *** string $tabScale = `columnLayout`; text -label "U Scale - Horizontal"; rowColumnLayout -numberOfColumns 4 ; radioCollection; $radioButton21 = `radioButton -label "0.25"`; $radioButton22 = `radioButton -label "0.33"`; $radioButton23 = `radioButton -label "0.5"`; $radioButton24 = `radioButton -label "1.0"`; $radioButton25 = `radioButton -label "4.0"`; $radioButton26 = `radioButton -label "3.0"`; $radioButton27 = `radioButton -label "2.0"`; setParent ..; text -label "Height (V) Scale"; rowColumnLayout -numberOfColumns 4 ; radioCollection; $radioButton31 = `radioButton -label "0.25"`; $radioButton32 = `radioButton -label "0.33"`; $radioButton33 = `radioButton -label "0.5"`; $radioButton34 = `radioButton -label "1.0"`; $radioButton35 = `radioButton -label "4.0"`; $radioButton36 = `radioButton -label "3.0"`; $radioButton37 = `radioButton -label "2.0"`; setParent ..; setParent ..; // *** Rotate *** string $tabRotate = `columnLayout`; text -label "Rotate"; radioCollection; $radioButton101 = `radioButton -label "CW 90" `; $radioButton102 = `radioButton -label "CCW 90" `; $radioButton103 = `radioButton -label "180" `; setParent ..; // Add functionality. // string $NewUVselected = "New UV's selected - UV pivot reset to Centre"; string $pivotCentered = "Pivot moved to center"; float $pu = $pv = 0.5; float $su = $sv = 1.0; float $angle = -90.0; int $PivotRef = 1; float $MinMidMax[5]; SetNewPivot($PivotRef, $MinMidMax); calcMinMax($MinMidMax); radioButton -edit -onCommand "SetNewPivot(1, $MinMidMax); $pu = $MinMidMax[1]; $pv = $MinMidMax[4]; radioButton -edit -select $rbUVpivot15" $rbNormalized; radioButton -edit -onCommand "SetNewPivot(0, $MinMidMax); $pu = $MinMidMax[1]; $pv = $MinMidMax[4]; radioButton -edit -select $rbUVpivot15" $rbUVCentric; radioButton -edit -onCommand "$pu = $MinMidMax[0]; $pv = $MinMidMax[5]" $rbUVpivot11; radioButton -edit -onCommand "$pu = $MinMidMax[1]; $pv = $MinMidMax[5]" $rbUVpivot12; radioButton -edit -onCommand "$pu = $MinMidMax[2]; $pv = $MinMidMax[5]" $rbUVpivot13; radioButton -edit -onCommand "$pu = $MinMidMax[0]; $pv = $MinMidMax[4]" $rbUVpivot14; radioButton -edit -onCommand "$pu = $MinMidMax[1]; $pv = $MinMidMax[4]" $rbUVpivot15; radioButton -edit -onCommand "$pu = $MinMidMax[2]; $pv = $MinMidMax[4]" $rbUVpivot16; radioButton -edit -onCommand "$pu = $MinMidMax[0]; $pv = $MinMidMax[3]" $rbUVpivot17; radioButton -edit -onCommand "$pu = $MinMidMax[1]; $pv = $MinMidMax[3]" $rbUVpivot18; radioButton -edit -onCommand "$pu = $MinMidMax[2]; $pv = $MinMidMax[3]" $rbUVpivot19; radioButton -edit -onCommand "$su = 0.25" $radioButton21; radioButton -edit -onCommand "$su = 0.333333" $radioButton22; radioButton -edit -onCommand "$su = 0.5" $radioButton23; radioButton -edit -onCommand "$su = 1.0" $radioButton24; radioButton -edit -onCommand "$su = 4.0" $radioButton25; radioButton -edit -onCommand "$su = 3.0" $radioButton26; radioButton -edit -onCommand "$su = 2.0" $radioButton27; radioButton -edit -onCommand "$sv = 0.25" $radioButton31; radioButton -edit -onCommand "$sv = 0.333333" $radioButton32; radioButton -edit -onCommand "$sv = 0.5" $radioButton33; radioButton -edit -onCommand "$sv = 1.0" $radioButton34; radioButton -edit -onCommand "$sv = 4.0" $radioButton35; radioButton -edit -onCommand "$sv = 3.0" $radioButton36; radioButton -edit -onCommand "$sv = 2.0" $radioButton37; radioButton -edit -onCommand "$angle = -90.0" $radioButton101; radioButton -edit -onCommand "$angle = 90.0" $radioButton102; radioButton -edit -onCommand "$angle = 180.0" $radioButton103; // Set initial state. // // pivot centricity radioButton -edit -select $rbNormalized; // UV Pivot radioButton -edit -select $rbUVpivot15; // UV Scale radioButton -edit -select $radioButton24; radioButton -edit -select $radioButton34; // Rotation radioButton -edit -select $radioButton101; tabLayout -edit -image "BuzzFace.BMP" -iv 1 -tabLabel $tabScale "Scale" -tabLabel $tabRotate "Rotate" $tabs; formLayout -edit -attachForm $frameAction "top" 5 -attachForm $frameAction "left" 5 -attachPosition $frameAction "bottom" 5 50 -attachForm $frameAction "right" 5 -attachControl $tabs "top" 5 $frameAction -attachForm $tabs "left" 5 -attachForm $tabs "bottom" 5 -attachForm $tabs "right" 5 $form; showWindow UVPanelWindow; scriptJob -parent UVPanelWindow -event "SelectionChanged" "SetNewPivot(1, $MinMidMax); showStatus($NewUVselected); radioButton -edit -select $rbNormalized; radioButton -edit -select $rbUVpivot15; $pu = $MinMidMax[1]; $pv = $MinMidMax[4]; "; // // Calculate the minimum, maximum and midpoint in U and V of selected verticies // proc calcMinMax(float $MinMidMax[]) { float $UVs[] = `polyEvaluate -bc2`; $MinMidMax[0] = $UVs[0]; $MinMidMax[1] = ($UVs[0] + $UVs[1])/2; $MinMidMax[2] = $UVs[1]; $MinMidMax[3] = $UVs[2]; $MinMidMax[4] = ($UVs[2] + $UVs[3])/2; $MinMidMax[5] = $UVs[3]; } proc SetNewPivot(int $PivotRef, float $MinMidMax[]) { if ($PivotRef) { showStatus("Normalized Pivot"); $MinMidMax[0] = 0.0; $MinMidMax[1] = 0.5; $MinMidMax[2] = 1.0; $MinMidMax[3] = 0.0; $MinMidMax[4] = 0.5; $MinMidMax[5] = 1.0; } else { showStatus("UV Centric Pivot"); calcMinMax($MinMidMax); } } // // Scale the UV's based on the selections from the UI window // proc doScale(float $pu, float $pv, float $su, float $sv) { string $pEUV = "polyEditUV -pu " + $pu +" -pv " + $pv + " -su " + $su + " -sv " + $sv + ";"; polyEditUV -pu $pu -pv $pv -su $su -sv $sv; showStatus($pEUV); } // // Rotate the UV's based on the selections from the UI window // proc doRotate(float $pu, float $pv, float $angle) { string $pEUV = "polyEditUV -pu " + $pu +" -pv " + $pv + " -a " + $angle + ";"; polyEditUV -pu $pu -pv $pv -a $angle; showStatus($pEUV); } // // Show the current values of the UV's based on the selections from the UI window // proc doShowMe(float $pu, float $pv, float $su, float $sv, float $angle) { string $pEUV = "polyEditUV " + " -pu " + $pu +" -pv " + $pv + " -su " + $su + " -sv " + $sv + " -a " + $angle + ";"; showStatus($pEUV); } // Update the status line. // proc showStatus (string $newStatus) { textField -edit -text $newStatus StatusLine; }