Advertisement
bram0101

Maya Mel MC AmbientOcclusion

Feb 17th, 2016
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.83 KB | None | 0 0
  1. string $add = "print(\"Checkin for ambient occlusion node...\\n\");"+
  2. "string $textures[] = `ls -tex`;"+
  3. "string $amb = \"\";"+
  4. "for($s in $textures){"+
  5. " if(`nodeType $s` == \"mib_amb_occlusion\"){"+
  6. " if(`attributeExists \"AO\" $s`){"+
  7. " $amb = $s;"+
  8. " break;"+
  9. " }"+
  10. " }"+
  11. "}"+
  12. "if($amb == \"\"){"+
  13. " print(\"Couldn't find ambient occlusion node! Please run the script again to create it! \" "+
  14. " + \"This could be a result of optimizing scene size!\\n\");"+
  15. "}else{"+
  16. " print(\"Found ambient occlusion node: \" + $amb + \"\\n\");"+
  17. " print(\"Applying to materials\\n\");"+
  18. " string $materials[] = `ls -mat`;"+
  19. " for($m in $materials){"+
  20. " if(`attributeExists \"ambientColor\" $m` && `nodeType $m` != \"fluidShape\"){"+
  21. " vector $ac = `getAttr ($m + \".ambientColor\")`;"+
  22. " int $acR = $ac.x;"+
  23. " int $acG = $ac.y;"+
  24. " int $acB = $ac.z;"+
  25. " string $oTex = \"\";"+
  26. " string $connections[] = `listConnections -c true $m`;"+
  27. " int $amc = 0;"+
  28. " for($con in $connections){"+
  29. " if($amc == 1){"+
  30. " $oTex = $con;"+
  31. " break;"+
  32. " }"+
  33. " if($con == ($m + \".ambientColor\")){"+
  34. " $amc = 1;"+
  35. " }"+
  36. " }"+
  37. " if($oTex != \"\"){"+
  38. " string $oAttr = \"\";"+
  39. " string $cons[] = `listConnections -c true $oTex`;"+
  40. " int $indexSize = size($cons);"+
  41. " for($i = 0; $i < $indexSize; $i++){"+
  42. " string $conT = $cons[$i];"+
  43. " if($conT == $m){"+
  44. " $oAttr = $cons[$i - 1];"+
  45. " }"+
  46. " }"+
  47. " string $s = `shadingNode -asUtility plusMinusAverage`;"+
  48. " catchQuiet ( `connectAttr -force ($amb + \".outValue\") ($s + \".input3D[0]\")` );"+
  49. " catchQuiet ( `connectAttr -force ($amb + \".outValue\") ($s + \".input3D[1]\")` );"+
  50. " catchQuiet ( `disconnectAttr ($amb + \".outValue\") ($s + \".input3D[1]\")` );"+
  51. " catchQuiet ( `connectAttr -force $oAttr ($s + \".input3D[1]\")` );"+
  52. " catchQuiet ( `connectAttr -force ($s + \".output3D\") ($m + \".ambientColor\")` );"+
  53. " }else{"+
  54. " if($acR == 0 && $acG == 0 && $acB == 0){"+
  55. " catchQuiet ( `connectAttr -force ($amb + \".outValue\") ($m + \".ambientColor\")` );"+
  56. " }else{"+
  57. " string $s = `shadingNode -asUtility plusMinusAverage`;"+
  58. " catchQuiet ( `connectAttr -force ($amb + \".outValue\") ($s + \".input3D[0]\")` );"+
  59. " catchQuiet ( `connectAttr -force ($amb + \".outValue\") ($s + \".input3D[1]\")` );"+
  60. " catchQuiet ( `disconnectAttr ($amb + \".outValue\") ($s + \".input3D[1]\")` );"+
  61. " setAttr ($s + \".input3D[1]\") ($acR) ($acG) ($acB);"+
  62. " catchQuiet ( `connectAttr -force ($s + \".output3D\") ($m + \".ambientColor\")` );"+
  63. " }"+
  64. " }"+
  65. " }"+
  66. " }"+
  67. "}";
  68.  
  69. string $remove = "print(\"Checkin for ambient occlusion node...\\n\");"+
  70. "string $textures[] = `ls -tex`;"+
  71. "string $amb = \"\";"+
  72. "for($s in $textures){"+
  73. " if(`nodeType $s` == \"mib_amb_occlusion\"){"+
  74. " if(`attributeExists \"AO\" $s`){"+
  75. " $amb = $s;"+
  76. " break;"+
  77. " }"+
  78. " }"+
  79. "}"+
  80. "if($amb == \"\"){"+
  81. " print(\"Couldn't find ambient occlusion node! Please run the script again to create it! \" "+
  82. " + \"This could be a result of optimizing scene size!\\n\");"+
  83. "}else{"+
  84. " print(\"Found ambient occlusion node: \" + $amb + \"\\n\");"+
  85. " print(\"Removing from materials\\n\");"+
  86. " string $materials[] = `ls -mat`;"+
  87. " for($m in $materials){"+
  88. " if(`attributeExists \"ambientColor\" $m` && `nodeType $m` != \"fluidShape\"){"+
  89. " vector $ac = `getAttr ($m + \".ambientColor\")`;"+
  90. " int $acR = $ac.x;"+
  91. " int $acG = $ac.y;"+
  92. " int $acB = $ac.z;"+
  93. " string $oTex = \"\";"+
  94. " string $connections[] = `listConnections -c true $m`;"+
  95. " int $amc = 0;"+
  96. " for($con in $connections){"+
  97. " if($amc == 1){"+
  98. " $oTex = $con;"+
  99. " break;"+
  100. " }"+
  101. " if($con == ($m + \".ambientColor\")){"+
  102. " $amc = 1;"+
  103. " }"+
  104. " }"+
  105. "print($oTex + \"\\n\");"+
  106. " if($oTex != \"\" && (`nodeType $oTex` == \"mib_amb_occlusion\" || `nodeType $oTex` == \"plusMinusAverage\")){"+
  107. " string $oAttr = \"\";"+
  108. " string $cons[] = `listConnections -c true $oTex`;"+
  109. " int $indexSize = size($cons);"+
  110. " for($i = 0; $i < $indexSize; $i++){"+
  111. " string $conT = $cons[$i];"+
  112. " if($conT == $m){"+
  113. " $oAttr = $cons[$i - 1];"+
  114. " }"+
  115. " }"+
  116. " "+
  117. " catchQuiet ( `disconnectAttr $oAttr ($m + \".ambientColor\")` );"+
  118. " "+
  119. " if($oTex != $amb){"+
  120. " "+
  121. " string $oTex2 = \"\";"+
  122. " string $connections2[] = `listConnections -c true $oTex`;"+
  123. " int $amc2 = 0;"+
  124. " for($con2 in $connections2){"+
  125. " if($amc2 == 1){"+
  126. " $oTex2 = $con2; "+
  127. " break;"+
  128. " } "+
  129. " if($con2 == ($oTex + \".input3D[1]\")){"+
  130. " $amc2 = 1;"+
  131. " }"+
  132. " }"+
  133. " "+
  134. " if($oTex2 != \"\"){"+
  135. " string $oAttr2 = \"\";"+
  136. " string $cons2[] = `listConnections -c true $oTex2`;"+
  137. " int $indexSize2 = size($cons2);"+
  138. " for($i2 = 0; $i2 < $indexSize2; $i2++){"+
  139. " string $conT2 = $cons2[$i2];"+
  140. " if($conT2 == $oTex){"+
  141. " $oAttr2 = $cons2[$i2 - 1]; "+
  142. " }"+
  143. " }"+
  144. " if($oAttr2 != \"\"){"+
  145. " catchQuiet ( `connectAttr -force $oAttr2 ($m + \".ambientColor\")` );"+
  146. " }"+
  147. " }"+
  148. " delete $oTex;"+
  149. " }else{"+
  150. " setAttr ($m + \".ambientColor\") ($acR) ($acG) ($acB);"+
  151. " }"+
  152. " }"+
  153. " }"+
  154. " }"+
  155. "}";
  156.  
  157. setAttr -type "string" defaultRenderGlobals.preMel $add;
  158. setAttr -type "string" defaultRenderGlobals.postMel $remove;
  159. print("Checkin for ambient occlusion node...\n");
  160. string $textures[] = `ls -tex`;
  161. string $amb = "";
  162. for($s in $textures){
  163. if(`nodeType $s` == "mib_amb_occlusion"){
  164. if(`attributeExists "AO" $s`){
  165. $amb = $s;
  166. break;
  167. }
  168. }
  169. }
  170. if($amb == ""){
  171. print("Ambient Occlusion node not found, creating node!\n.");
  172. string $amb = `mrCreateCustomNode -asTexture "" mib_amb_occlusion`;
  173. setAttr ($amb + ".max_distance") 0.5;
  174. setAttr ($amb + ".dark") -type double3 -0.25 -0.25 -0.25 ;
  175. setAttr ($amb + ".bright") -type double3 0 0 0 ;
  176. addAttr -ln "AO" -dt "string" $amb;
  177. addAttr -ln "Intensity" -at double -min 0 $amb;
  178. setAttr -e-keyable true ($amb + ".Intensity");
  179. setAttr ($amb + ".Intensity") 0.5;
  180. string $sl = `shadingNode -asUtility surfaceLuminance`;
  181. string $md = `shadingNode -asUtility multiplyDivide`;
  182. catch(`connectAttr -f ($sl + ".outValue") ($md + ".input1X")`);
  183. catch(`connectAttr -f ($sl + ".outValue") ($md + ".input1Y")`);
  184. catch(`connectAttr -f ($sl + ".outValue") ($md + ".input1Z")`);
  185. catch(`connectAttr -f ($amb + ".Intensity") ($md + ".input2X")`);
  186. catch(`connectAttr -f ($amb + ".Intensity") ($md + ".input2Y")`);
  187. catch(`connectAttr -f ($amb + ".Intensity") ($md + ".input2Z")`);
  188. string $pma = `shadingNode -asUtility plusMinusAverage`;
  189. setAttr ($pma + ".operation") 2;
  190. catch(`connectAttr -force ($md + ".output") ($pma + ".input3D[0]")`);
  191. catch(`disconnectAttr ($md + ".output") ($pma + ".input3D[0]")`);
  192. catch(`connectAttr -force ($md + ".output") ($pma + ".input3D[1]")`);
  193. catch(`connectAttr -f ($pma + ".output3D") ($amb + ".dark")`);
  194. select -r $amb;
  195. }else{
  196. select -r $amb;
  197. }
  198. print("These are the ambient occlusion settings. Bright should be the way it is, and Dark needs to be negative!\n");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement