Advertisement
bram0101

MC UV Fixer

Feb 20th, 2017
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.65 KB | None | 0 0
  1. proc vector translatePolyInfoNormal( string $pin )
  2. {
  3. vector $normal;
  4. float $x;
  5. float $y;
  6. float $z;
  7.  
  8. string $tokens[];
  9. int $numTokens = `tokenize $pin " " $tokens`;
  10.  
  11. // Make sure we're looking at polyInfo data:
  12. if ( ( $numTokens > 3 ) && ( $tokens[0] == "FACE_NORMAL" ) )
  13. {
  14. // Maya performs data-type conversion here.
  15. $x = ($tokens[$numTokens-3]);
  16. $y = ($tokens[$numTokens-2]);
  17. $z = ($tokens[$numTokens-1]);
  18.  
  19. $normal = << $x, $y, $z >>;
  20.  
  21. // Normalize it.
  22. $normal = `unit $normal`;
  23. }
  24.  
  25. // Return it.
  26. return $normal;
  27. }
  28.  
  29. global string $XintFieldName="";
  30. global string $YintFieldName="";
  31. global string $ZintFieldName="";
  32.  
  33. MainWindowUVPlacer;
  34.  
  35. global proc MainWindowUVPlacer()
  36. {
  37. // check first for another instance of this window..
  38. if((`window -exists "MC UV Fixer"`) == true) {
  39. // ..if there is, close it
  40. deleteUI MainWindow;
  41. }
  42. // create the window
  43. createMainWindow("MC UV Fixer");
  44. }
  45.  
  46. proc createMainWindow(string $name) {
  47. global string $XintFieldName;
  48. global string $YintFieldName;
  49. global string $ZintFieldName;
  50.  
  51. // set our window sizes
  52. $windowHeight = 256;
  53. $windowWidth = 450;
  54.  
  55. string $windowName = `window -widthHeight 300 200 -title $name $name`;
  56.  
  57. frameLayout -l "MC UV Fixer" -mh 5 -mw 5;
  58.  
  59. columnLayout -adjustableColumn true -columnAttach "both" 10;
  60.  
  61. text -label "\nMenu" -align "center";
  62. separator -height 10;
  63. text -label "X Center";
  64. $XintFieldName = `intField -value 1`;
  65. text -label "Y Center";
  66. $YintFieldName = `intField -value 1`;
  67. text -label "Z Center";
  68. $ZintFieldName = `intField -value 1`;
  69.  
  70. button -label "Fix UVs" -command start;
  71.  
  72. showWindow $windowName;
  73. }
  74.  
  75.  
  76. global proc start(){
  77.  
  78. global string $XintFieldName;
  79. global string $YintFieldName;
  80. global string $ZintFieldName;
  81.  
  82. int $xm = `intField -query -value $XintFieldName`;
  83.  
  84. int $ym = `intField -query -value $YintFieldName`;
  85.  
  86. int $zm = `intField -query -value $ZintFieldName`;
  87.  
  88.  
  89. string $selection[] = `ls -sl`;
  90. select -r $selection.f["*"];
  91. string $faceList[] = `filterExpand -sm 34`;
  92. $nof = (size($faceList));
  93. $nofLoop = $nof - 1;
  94. print ("\nNum of faces is: " + $nof + "\n");
  95. select -r $selection ;
  96. string $xFace[];
  97. int $xI = 0;
  98. string $yFace[];
  99. int $yI = 0;
  100. string $zFace[];
  101. int $zI = 0;
  102.  
  103. string $nxFace[];
  104. int $nxI = 0;
  105. string $nyFace[];
  106. int $nyI = 0;
  107. string $nzFace[];
  108. int $nzI = 0;
  109.  
  110. for ($i=0;$i<=$nofLoop;$i=$i+1)
  111. {
  112. string $polyInfo[] = `polyInfo -faceNormals $faceList[$i]`;
  113. vector $normal = translatePolyInfoNormal($polyInfo[0]);
  114. if($normal.x > 0.5){
  115. $xFace[$xI] = $faceList[$i];
  116. $xI = $xI + 1;
  117. }
  118. if($normal.y > 0.5){
  119. $yFace[$yI] = $faceList[$i];
  120. $yI = $yI + 1;
  121. }
  122. if($normal.z > 0.5){
  123. $zFace[$zI] = $faceList[$i];
  124. $zI = $zI + 1;
  125. }
  126.  
  127. if($normal.x < -0.5){
  128. $nxFace[$nxI] = $faceList[$i];
  129. $nxI = $nxI + 1;
  130. }
  131. if($normal.y < -0.5){
  132. $nyFace[$nyI] = $faceList[$i];
  133. $nyI = $nyI + 1;
  134. }
  135. if($normal.z < -0.5){
  136. $nzFace[$nzI] = $faceList[$i];
  137. $nzI = $nzI + 1;
  138. }
  139. }
  140. if(size($xFace) > 0){
  141. select -r $xFace;
  142. string $xProjection[] = `polyProjection -ch 1 -type Planar -ibd off -md x -pcx 1 -pcy 1 -pcz 1`;
  143.  
  144. $proj = $xProjection[0];
  145. setAttr ($proj + ".projectionCenterX") $xm;
  146. setAttr ($proj + ".projectionCenterY") $ym;
  147. setAttr ($proj + ".projectionCenterZ") $zm;
  148. setAttr ($proj + ".projectionWidth") 2;
  149. setAttr ($proj + ".projectionHeight") 2;
  150. }
  151. if(size($yFace) > 0){
  152. select -r $yFace;
  153. string $yProjection[] = `polyProjection -ch 1 -type Planar -ibd off -md y -pcx 1 -pcy 1 -pcz 1`;
  154. $proj = $yProjection[0];
  155. setAttr ($proj + ".projectionCenterX") $xm;
  156. setAttr ($proj + ".projectionCenterY") $ym;
  157. setAttr ($proj + ".projectionCenterZ") $zm;
  158. setAttr ($proj + ".projectionWidth") 2;
  159. setAttr ($proj + ".projectionHeight") 2;
  160. }
  161. if(size($zFace) > 0){
  162. select -r $zFace;
  163. string $zProjection[] = `polyProjection -ch 1 -type Planar -ibd off -md z -pcx 1 -pcy 1 -pcz 1`;
  164. $proj = $zProjection[0];
  165. setAttr ($proj + ".projectionCenterX") $xm;
  166. setAttr ($proj + ".projectionCenterY") $ym;
  167. setAttr ($proj + ".projectionCenterZ") $zm;
  168. setAttr ($proj + ".projectionWidth") 2;
  169. setAttr ($proj + ".projectionHeight") 2;
  170.  
  171. }
  172.  
  173. if(size($nxFace) > 0){
  174. select -r $nxFace;
  175. string $nxProjection[] = `polyProjection -ch 1 -type Planar -ibd off -md x -pcx 1 -pcy 1 -pcz 1`;
  176.  
  177. $proj = $nxProjection[0];
  178. setAttr ($proj + ".projectionCenterX") $xm;
  179. setAttr ($proj + ".projectionCenterY") $ym;
  180. setAttr ($proj + ".projectionCenterZ") $zm;
  181. setAttr ($proj + ".projectionWidth") 2;
  182. setAttr ($proj + ".projectionHeight") 2;
  183. setAttr ($proj + ".imageScaleU") -1;
  184. }
  185. if(size($nyFace) > 0){
  186. select -r $nyFace;
  187. string $nyProjection[] = `polyProjection -ch 1 -type Planar -ibd off -md y -pcx 1 -pcy 1 -pcz 1`;
  188. $proj = $nyProjection[0];
  189. setAttr ($proj + ".projectionCenterX") $xm;
  190. setAttr ($proj + ".projectionCenterY") $ym;
  191. setAttr ($proj + ".projectionCenterZ") $zm;
  192. setAttr ($proj + ".projectionWidth") 2;
  193. setAttr ($proj + ".projectionHeight") 2;
  194. setAttr ($proj + ".imageScaleU") -1;
  195. }
  196. if(size($nzFace) > 0){
  197. select -r $nzFace;
  198. string $nzProjection[] = `polyProjection -ch 1 -type Planar -ibd off -md z -pcx 1 -pcy 1 -pcz 1`;
  199. $proj = $nzProjection[0];
  200. setAttr ($proj + ".projectionCenterX") $xm;
  201. setAttr ($proj + ".projectionCenterY") $ym;
  202. setAttr ($proj + ".projectionCenterZ") $zm;
  203. setAttr ($proj + ".projectionWidth") 2;
  204. setAttr ($proj + ".projectionHeight") 2;
  205. setAttr ($proj + ".imageScaleU") -1;
  206. }
  207.  
  208. select -r $selection ;
  209. print("Done!\n");
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement