Advertisement
Guest User

maya reset rotation

a guest
Apr 22nd, 2016
1,002
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.73 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. //
  4. // Reset rotation of objects using 3 vertices
  5. //
  6. // Features:
  7. // # restores rotation of objects
  8. // # resets world space transforms
  9. //
  10. // Usage:
  11. // # select 3 vertices in a 90 degree optimal angle
  12. // point - center of orientation
  13. // y - orientation of where Y-axis should point
  14. // z - orientation of where Z-axis should point
  15. // # hit run
  16. //
  17. // Criteria to work:
  18. // # if many objects are selected, they need to have identical vertex IDs on respective vertex
  19. //
  20. //
  21. //
  22. // Ludvig Lindqvist 1/7-2010
  23. //
  24. //////////////////////////////////////////////////////////////////////////////////////////
  25.  
  26.  
  27. // create window with 5 buttons
  28. global proc ludo_resetRotation()
  29. {
  30. if (`window -exists VFXresetRotationWin`) deleteUI -window VFXresetRotationWin;
  31. string $window = `window -title "reset rotation" -widthHeight 160 155 -s 0 VFXresetRotationWin`;
  32. columnLayout -adjustableColumn true;
  33. rowColumnLayout -nc 2 -cw 1 50 -cw 2 100;
  34.  
  35. text -l "Origin" -al "center";
  36. $t = `button -label "vertex" -bgc 0.7 0.7 0.7 -c "getVert(1)" ludoVert1`;
  37. text -l "localY" -al "center";
  38. $t = `button -label "vertex" -bgc 0.7 0.7 0.7 -c "getVert(2)" -en 0 ludoVert2`;
  39. text -l "localZ" -al "center";
  40. $t = `button -label "vertex" -bgc 0.7 0.7 0.7 -c "getVert(3)" -en 0 ludoVert3`;
  41. text -l " " -al "center";
  42.  
  43. string $clearButton = `button -label "clear" -bgc 0.8 0.8 0.8`;
  44. button -e -c "ludo_resetRotation()" $clearButton;
  45.  
  46. setParent ..;
  47. separator;
  48.  
  49. $t = `button -label "run on selected objects" -bgc 0.8 0.8 0.8 -c "createVertArray()" -en 0 ludoRunIt`;
  50.  
  51. text -l "select 3 vertices" -en 0 -al "center";
  52.  
  53. showWindow $window;
  54. }
  55.  
  56. global proc getVert(int $id)
  57. {
  58. string $sel[] = `ls -sl -fl`;
  59. $sel = `filterExpand -sm 31`; // just verts please
  60.  
  61. if (size($sel) == 1 ) {
  62. string $component = `match "\\..*" $sel[0]`;
  63. switch ($id) {
  64. case 1:
  65. $t = `button -e -label $component ludoVert1`;
  66. $t = `button -e -en 1 ludoVert2`;
  67. break;
  68. case 2:
  69. $t = `button -e -label $component ludoVert2`;
  70. $t = `button -e -en 1 ludoVert3`;
  71. break;
  72. case 3:
  73. $t = `button -e -label $component ludoVert3`;
  74. $t = `button -e -en 1 ludoRunIt`;
  75. break;
  76. }
  77. }
  78. }
  79.  
  80. //////////////////////////////////////////////////////////////////////////////////////////
  81.  
  82. // get all button labels with stores vertex data
  83. // check if all buttons are set
  84.  
  85. global proc createVertArray(){
  86. string $selVert[];
  87. int $fail = 0;
  88.  
  89. $selVert[0] = `button -q -label ludoVert1`;
  90. $selVert[1] = `button -q -label ludoVert2`;
  91. $selVert[2] = `button -q -label ludoVert3`;
  92.  
  93. if($selVert[0] == "vertex") {
  94. $fail = 1;
  95. error("load vertex to all buttons");
  96. }
  97.  
  98. if($selVert[1] == "vertex") {
  99. $fail = 1;
  100. error("load vertex to all buttons");
  101. }
  102.  
  103. if($selVert[2] == "vertex") {
  104. $fail = 1;
  105. error("load vertex to all buttons");
  106. }
  107.  
  108. if($fail == 0) getObjNames($selVert);
  109.  
  110. }
  111.  
  112.  
  113. //////////////////////////////////////////////////////////////////////////////////////////
  114.  
  115. // loop objects in this procedure
  116. // rebuilds the button string with previously stripped components eg. object.vtx[n], was previously .vtx[n]
  117. // runs through rest of linked procedures within the loop for each object
  118. // applies world coordinates for every object
  119.  
  120. global proc getObjNames(string $selVert[]){
  121.  
  122. string $objSel[] = `ls -sl -fl`;
  123.  
  124. if(size($objSel)!=0){
  125. int $i;
  126.  
  127. string $nVert[];
  128. $nVert[0] = $selVert[0];
  129. $nVert[1] = $selVert[1];
  130. $nVert[2] = $selVert[2];
  131.  
  132. for($i = 0 ; $i<size($objSel) ; $i++){
  133.  
  134. select $objSel[$i];
  135. FreezeTransformations;
  136.  
  137. $selVert[0] = $objSel[$i] + $nVert[0];
  138. $selVert[1] = $objSel[$i] + $nVert[1];
  139. $selVert[2] = $objSel[$i] + $nVert[2];
  140.  
  141. createEmitter($selVert, $objSel[$i]);
  142. }
  143. worldPos($objSel);
  144. }
  145. else error("select items to reset");
  146. }
  147.  
  148.  
  149. //////////////////////////////////////////////////////////////////////////////////////////
  150.  
  151. // create emitters at specified vertices
  152. // call camera procedure for emitters
  153.  
  154. global proc createEmitter(string $verts[], string $obj){
  155.  
  156. string $emitterCollection[];
  157. string $tmp[];
  158.  
  159.  
  160. string $eName = $obj + "_emitter";
  161.  
  162. int $i;
  163.  
  164. for($i = 0 ; $i < 3 ; $i++){
  165. select $verts[$i];
  166.  
  167. $tmp = `emitter -n $eName`;
  168.  
  169. $emitterCollection[$i] = $tmp[1];
  170. }
  171. createCamera($emitterCollection, $obj);
  172. }
  173.  
  174.  
  175. //////////////////////////////////////////////////////////////////////////////////////////
  176.  
  177. // create a "Camera Aim and Up"
  178. // move camera to the emitters tied to vertices
  179. // move Aim and Up to emitters
  180. // delete emitters
  181.  
  182. global proc createCamera(string $emitterCollection[], string $obj){
  183. string $tmpCam[] = `camera`;
  184. cameraMakeNode 3 "";
  185.  
  186. string $cam = $tmpCam[0];
  187.  
  188. string $tmpStr;
  189. string $tmpCamera;
  190.  
  191. float $vPos[];
  192.  
  193.  
  194. $tmpStr = $emitterCollection[2] + ".translate";
  195. $vPos = `getAttr $tmpStr`;
  196. $tmpCamera = $cam + ".translate";
  197. setAttr $tmpCamera -type "double3" $vPos[0] $vPos[1] $vPos[2];
  198.  
  199. $tmpStr = $emitterCollection[0] + ".translate";
  200. $vPos = `getAttr $tmpStr`;
  201. $tmpCamera = $cam + "_aim.translate";
  202. setAttr $tmpCamera -type "double3" $vPos[0] $vPos[1] $vPos[2];
  203.  
  204. $tmpStr = $emitterCollection[1] + ".translate";
  205. $vPos = `getAttr $tmpStr`;
  206. $tmpCamera = $cam + "_up.translate";
  207. setAttr $tmpCamera -type "double3" $vPos[0] $vPos[1] $vPos[2];
  208.  
  209. for($i = 0 ; $i < 3 ; $i++){ select $emitterCollection[$i]; delete; }
  210.  
  211. sunParentWhatever($cam, $obj);
  212. }
  213.  
  214.  
  215. //////////////////////////////////////////////////////////////////////////////////////////
  216.  
  217. // parent object to camera then freeze object
  218. // unparent object to get relative rotations correct
  219. // delete camera
  220.  
  221. global proc sunParentWhatever(string $cam, string $obj){
  222. parent $obj $cam;
  223.  
  224. select $obj;
  225. FreezeTransformations;
  226.  
  227. parent -w $obj;
  228.  
  229. delete `listRelatives -p $cam`;
  230. }
  231.  
  232.  
  233. //////////////////////////////////////////////////////////////////////////////////////////
  234.  
  235. // apply world coordinates
  236.  
  237. global proc worldPos(string $sel[]){
  238. float $worldPos[];
  239.  
  240. for ($obj in $sel){
  241.  
  242. select $obj;
  243.  
  244. $worldPos = `xform -q -ws -piv`;
  245. makeIdentity -apply true -t 1 -r 0 -s 1 -n 0 $obj;
  246.  
  247. move -r -wd ($worldPos[0]*-1) ($worldPos[1]*-1) ($worldPos[2]*-1);
  248.  
  249. makeIdentity -apply true -t 1 -r 0 -s 1 -n 0 $obj;
  250.  
  251. move -r -wd $worldPos[0] $worldPos[1] $worldPos[2];
  252.  
  253. }
  254. select $sel;
  255. }
  256.  
  257.  
  258. //////////////////////////////////////////////////////////////////////////////////////////
  259.  
  260. ludo_resetRotation();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement