Advertisement
Piptrosia

Branching Coral MEL

Nov 22nd, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.84 KB | None | 0 0
  1. // MEL script for generating plants in Maya
  2. // The first part is for the UI, and will be saved as a button in the shelf
  3. // Then the part that will be saved in a .mel file in the script folder
  4.  
  5. // UI for basicBranchingCoral
  6.  
  7. if (`window -exists bbcWindowZW`)
  8. deleteUI -window bbcWindowZW;
  9.  
  10. window -rtf true -title "Branching Coral" bbcWindowZW;
  11.  
  12. columnLayout;
  13.  
  14. text " Create a Branching Coral";
  15. text " ";
  16. intSliderGrp -minValue 5 -maxValue 2000 -value 50 -label "Number of loops" -field true loopRoundsSlider;
  17. intSliderGrp -minValue 5 -maxValue 40 -value 15 -label "Angle" -field true angleSlider;
  18. text " ";
  19.  
  20. gridLayout -numberOfRowsColumns 1 3 -cellWidthHeight 130 40;
  21.  
  22. button -c "Call_basicBranchingCoralAndClose" -label "Create And Close";
  23. button -c "Call_basicBranchingCoral" -label "Apply";
  24. button -c "Call_Close" -label "Close";
  25.  
  26. ////
  27.  
  28. proc Call_basicBranchingCoral()
  29. {
  30. source basicBranchingCoral;
  31. int $loopRounds = `intSliderGrp -q -value "loopRoundsSlider"`;
  32. int $rotationAng = `intSliderGrp -q -value "angleSlider"`;
  33. basicBranchingCoral($loopRounds, $rotationAng);
  34. }
  35. proc Call_basicBranchingCoralAndClose()
  36. {
  37. source basicBranchingCoral;
  38. int $loopRounds = `intSliderGrp -q -value "loopRoundsSlider"`;
  39. int $rotationAng = `intSliderGrp -q -value "angleSlider"`;
  40. basicBranchingCoral($loopRounds, $rotationAng);
  41. deleteUI -window bbcWindowZW;
  42. }
  43. proc Call_Close()
  44. {
  45. deleteUI -window bbcWindowZW;
  46. }
  47.  
  48. //// Window shows:
  49. showWindow bbcWindowZW;
  50.  
  51. /////////////////////////////////////////////////////////////// UI stored in button
  52. ///////////////////////////////////////////////////////////////////////////////////
  53. ///////////////////////////////////////////////////////////////////////////////////
  54. ///////////////////////////////////////////////////////////////////////////////////
  55. ///////////////////////////////////////////////////// Main proc stored in .mel file
  56.  
  57. global proc basicBranchingCoral (int $loopRounds,int $rotationAng)
  58. {
  59.  
  60. int $namesNum = 0;
  61. int $loopCounter = 0;
  62.  
  63.  
  64. // ------------------------------------------------------------------------------------------------------------------------------------| Make first fucking shape:
  65. polySphere -r .3 -sx 20 -sy 20 -ax 0 1 0 -cuv 2 -ch 1;
  66. string $currentObj[] = `ls -sl`;
  67.  
  68.  
  69. select -r ($currentObj[0] + ".f[140:219]") ;
  70. scale -r -p -2.98023e-008cm 0cm -4.47035e-008cm 1 2.999999 1 ;
  71.  
  72. select -r ($currentObj[0] + ".f[240:359]") ($currentObj[0] + ".f[380:399]") ;
  73. move -r -os -wd 0 1.86 0 ;
  74. select -r ($currentObj[0] + ".f[0:119]") ($currentObj[0] + ".f[360:379]") ;
  75. move -r -os -wd 0 -1.863831 0 ;
  76.  
  77. select -r $currentObj[0] ;
  78.  
  79. move -r 0 -2 0 ($currentObj[0] + ".scalePivot") ($currentObj[0] + ".rotatePivot") ;
  80.  
  81. // ------------------------------------------------------------------------------------------------------------------------------------|
  82.  
  83.  
  84. //////////////////////////////////////////////////////////////////////////////////////////////////
  85. $createShader = 1;
  86. // check for shader
  87. string $shads[] = `ls -mat`;
  88. for ($myNode in $shads)
  89. {
  90. if($myNode == "coralColor")
  91. $createShader = 0;
  92.  
  93. }
  94.  
  95. switch ($createShader)
  96. {
  97. case 0:
  98. //apply shade
  99. break;
  100. case 1:
  101. //make shader
  102. shadingNode -asShader aiStandard -n "coralColor";
  103. sets -renderable true -noSurfaceShader true
  104. -empty -n coralColorSG;
  105. connectAttr -f coralColor.outColor coralColorSG.surfaceShader;
  106. setAttr "coralColor.color" -type double3 0 0 0 ;
  107. setAttr "coralColor.color" -type double3 1 0.1069 0 ;
  108.  
  109.  
  110. break;
  111. }
  112.  
  113.  
  114. ///////// --- connect to shader
  115. // connects to the shader network
  116. select $currentObj[0];
  117. sets -edit -forceElement coralColorSG $currentObj[0];
  118. //////////////////////////////////////////////////////////////////////////////////////////////////
  119.  
  120.  
  121. string $allBranches[] = `ls -sl`;
  122. int $branchSaveIndex = 1;
  123.  
  124.  
  125. // the first shape is duplicated and changed, then the duplicates are duplicated...:
  126. for ($loopCounter; $loopCounter < $loopRounds; $loopCounter++)
  127. {
  128. select $allBranches[$loopCounter];
  129. duplicate;
  130. string $currentObj1[] = `ls -sl`;
  131. move -r -os -wd 0 4 0;
  132. rotate -r -os -fo (rand(-$rotationAng, $rotationAng)) 0 (rand(-$rotationAng, $rotationAng));
  133. $allBranches[$branchSaveIndex] = $currentObj1[0];
  134. $branchSaveIndex++;
  135.  
  136. select $allBranches[$loopCounter];
  137. duplicate;
  138. string $currentObj2[] = `ls -sl`;
  139. move -r -os -wd 0 4 0;
  140. rotate -r -os -fo (rand(-$rotationAng, $rotationAng)) 0 (rand(-$rotationAng, $rotationAng));
  141. $allBranches[$branchSaveIndex] = $currentObj2[0];
  142. $branchSaveIndex++;
  143. }
  144.  
  145.  
  146. // Now all elements are selected:
  147. select -cl;
  148. int $i = ($loopRounds*2);
  149. for ($i; $i >= 0; $i--)
  150. {
  151. select -tgl $allBranches[$i];
  152. }
  153. // and put in a group:
  154. group -n "coral";
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement