Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string $add = "print(\"Checkin for ambient occlusion node...\\n\");"+
- "string $textures[] = `ls -tex`;"+
- "string $amb = \"\";"+
- "for($s in $textures){"+
- " if(`nodeType $s` == \"mib_amb_occlusion\"){"+
- " if(`attributeExists \"AO\" $s`){"+
- " $amb = $s;"+
- " break;"+
- " }"+
- " }"+
- "}"+
- "if($amb == \"\"){"+
- " print(\"Couldn't find ambient occlusion node! Please run the script again to create it! \" "+
- " + \"This could be a result of optimizing scene size!\\n\");"+
- "}else{"+
- " print(\"Found ambient occlusion node: \" + $amb + \"\\n\");"+
- " print(\"Applying to materials\\n\");"+
- " string $materials[] = `ls -mat`;"+
- " for($m in $materials){"+
- " if(`attributeExists \"ambientColor\" $m` && `nodeType $m` != \"fluidShape\"){"+
- " vector $ac = `getAttr ($m + \".ambientColor\")`;"+
- " int $acR = $ac.x;"+
- " int $acG = $ac.y;"+
- " int $acB = $ac.z;"+
- " string $oTex = \"\";"+
- " string $connections[] = `listConnections -c true $m`;"+
- " int $amc = 0;"+
- " for($con in $connections){"+
- " if($amc == 1){"+
- " $oTex = $con;"+
- " break;"+
- " }"+
- " if($con == ($m + \".ambientColor\")){"+
- " $amc = 1;"+
- " }"+
- " }"+
- " if($oTex != \"\"){"+
- " string $oAttr = \"\";"+
- " string $cons[] = `listConnections -c true $oTex`;"+
- " int $indexSize = size($cons);"+
- " for($i = 0; $i < $indexSize; $i++){"+
- " string $conT = $cons[$i];"+
- " if($conT == $m){"+
- " $oAttr = $cons[$i - 1];"+
- " }"+
- " }"+
- " string $s = `shadingNode -asUtility plusMinusAverage`;"+
- " catchQuiet ( `connectAttr -force ($amb + \".outValue\") ($s + \".input3D[0]\")` );"+
- " catchQuiet ( `connectAttr -force ($amb + \".outValue\") ($s + \".input3D[1]\")` );"+
- " catchQuiet ( `disconnectAttr ($amb + \".outValue\") ($s + \".input3D[1]\")` );"+
- " catchQuiet ( `connectAttr -force $oAttr ($s + \".input3D[1]\")` );"+
- " catchQuiet ( `connectAttr -force ($s + \".output3D\") ($m + \".ambientColor\")` );"+
- " }else{"+
- " if($acR == 0 && $acG == 0 && $acB == 0){"+
- " catchQuiet ( `connectAttr -force ($amb + \".outValue\") ($m + \".ambientColor\")` );"+
- " }else{"+
- " string $s = `shadingNode -asUtility plusMinusAverage`;"+
- " catchQuiet ( `connectAttr -force ($amb + \".outValue\") ($s + \".input3D[0]\")` );"+
- " catchQuiet ( `connectAttr -force ($amb + \".outValue\") ($s + \".input3D[1]\")` );"+
- " catchQuiet ( `disconnectAttr ($amb + \".outValue\") ($s + \".input3D[1]\")` );"+
- " setAttr ($s + \".input3D[1]\") ($acR) ($acG) ($acB);"+
- " catchQuiet ( `connectAttr -force ($s + \".output3D\") ($m + \".ambientColor\")` );"+
- " }"+
- " }"+
- " }"+
- " }"+
- "}";
- string $remove = "print(\"Checkin for ambient occlusion node...\\n\");"+
- "string $textures[] = `ls -tex`;"+
- "string $amb = \"\";"+
- "for($s in $textures){"+
- " if(`nodeType $s` == \"mib_amb_occlusion\"){"+
- " if(`attributeExists \"AO\" $s`){"+
- " $amb = $s;"+
- " break;"+
- " }"+
- " }"+
- "}"+
- "if($amb == \"\"){"+
- " print(\"Couldn't find ambient occlusion node! Please run the script again to create it! \" "+
- " + \"This could be a result of optimizing scene size!\\n\");"+
- "}else{"+
- " print(\"Found ambient occlusion node: \" + $amb + \"\\n\");"+
- " print(\"Removing from materials\\n\");"+
- " string $materials[] = `ls -mat`;"+
- " for($m in $materials){"+
- " if(`attributeExists \"ambientColor\" $m` && `nodeType $m` != \"fluidShape\"){"+
- " vector $ac = `getAttr ($m + \".ambientColor\")`;"+
- " int $acR = $ac.x;"+
- " int $acG = $ac.y;"+
- " int $acB = $ac.z;"+
- " string $oTex = \"\";"+
- " string $connections[] = `listConnections -c true $m`;"+
- " int $amc = 0;"+
- " for($con in $connections){"+
- " if($amc == 1){"+
- " $oTex = $con;"+
- " break;"+
- " }"+
- " if($con == ($m + \".ambientColor\")){"+
- " $amc = 1;"+
- " }"+
- " }"+
- "print($oTex + \"\\n\");"+
- " if($oTex != \"\" && (`nodeType $oTex` == \"mib_amb_occlusion\" || `nodeType $oTex` == \"plusMinusAverage\")){"+
- " string $oAttr = \"\";"+
- " string $cons[] = `listConnections -c true $oTex`;"+
- " int $indexSize = size($cons);"+
- " for($i = 0; $i < $indexSize; $i++){"+
- " string $conT = $cons[$i];"+
- " if($conT == $m){"+
- " $oAttr = $cons[$i - 1];"+
- " }"+
- " }"+
- " "+
- " catchQuiet ( `disconnectAttr $oAttr ($m + \".ambientColor\")` );"+
- " "+
- " if($oTex != $amb){"+
- " "+
- " string $oTex2 = \"\";"+
- " string $connections2[] = `listConnections -c true $oTex`;"+
- " int $amc2 = 0;"+
- " for($con2 in $connections2){"+
- " if($amc2 == 1){"+
- " $oTex2 = $con2; "+
- " break;"+
- " } "+
- " if($con2 == ($oTex + \".input3D[1]\")){"+
- " $amc2 = 1;"+
- " }"+
- " }"+
- " "+
- " if($oTex2 != \"\"){"+
- " string $oAttr2 = \"\";"+
- " string $cons2[] = `listConnections -c true $oTex2`;"+
- " int $indexSize2 = size($cons2);"+
- " for($i2 = 0; $i2 < $indexSize2; $i2++){"+
- " string $conT2 = $cons2[$i2];"+
- " if($conT2 == $oTex){"+
- " $oAttr2 = $cons2[$i2 - 1]; "+
- " }"+
- " }"+
- " if($oAttr2 != \"\"){"+
- " catchQuiet ( `connectAttr -force $oAttr2 ($m + \".ambientColor\")` );"+
- " }"+
- " }"+
- " delete $oTex;"+
- " }else{"+
- " setAttr ($m + \".ambientColor\") ($acR) ($acG) ($acB);"+
- " }"+
- " }"+
- " }"+
- " }"+
- "}";
- setAttr -type "string" defaultRenderGlobals.preMel $add;
- setAttr -type "string" defaultRenderGlobals.postMel $remove;
- print("Checkin for ambient occlusion node...\n");
- string $textures[] = `ls -tex`;
- string $amb = "";
- for($s in $textures){
- if(`nodeType $s` == "mib_amb_occlusion"){
- if(`attributeExists "AO" $s`){
- $amb = $s;
- break;
- }
- }
- }
- if($amb == ""){
- print("Ambient Occlusion node not found, creating node!\n.");
- string $amb = `mrCreateCustomNode -asTexture "" mib_amb_occlusion`;
- setAttr ($amb + ".max_distance") 0.5;
- setAttr ($amb + ".dark") -type double3 -0.25 -0.25 -0.25 ;
- setAttr ($amb + ".bright") -type double3 0 0 0 ;
- addAttr -ln "AO" -dt "string" $amb;
- addAttr -ln "Intensity" -at double -min 0 $amb;
- setAttr -e-keyable true ($amb + ".Intensity");
- setAttr ($amb + ".Intensity") 0.5;
- string $sl = `shadingNode -asUtility surfaceLuminance`;
- string $md = `shadingNode -asUtility multiplyDivide`;
- catch(`connectAttr -f ($sl + ".outValue") ($md + ".input1X")`);
- catch(`connectAttr -f ($sl + ".outValue") ($md + ".input1Y")`);
- catch(`connectAttr -f ($sl + ".outValue") ($md + ".input1Z")`);
- catch(`connectAttr -f ($amb + ".Intensity") ($md + ".input2X")`);
- catch(`connectAttr -f ($amb + ".Intensity") ($md + ".input2Y")`);
- catch(`connectAttr -f ($amb + ".Intensity") ($md + ".input2Z")`);
- string $pma = `shadingNode -asUtility plusMinusAverage`;
- setAttr ($pma + ".operation") 2;
- catch(`connectAttr -force ($md + ".output") ($pma + ".input3D[0]")`);
- catch(`disconnectAttr ($md + ".output") ($pma + ".input3D[0]")`);
- catch(`connectAttr -force ($md + ".output") ($pma + ".input3D[1]")`);
- catch(`connectAttr -f ($pma + ".output3D") ($amb + ".dark")`);
- select -r $amb;
- }else{
- select -r $amb;
- }
- 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