//For ColladaMaya_301 global proc string cgfxToColladafx() { if (`pluginInfo -query -loaded cgfxShader.mll` == 0) { print "The CgFx PlugIn is not Loaded\n"; return "uneventful"; } else { //TODO: split out and generalize functions to be shared by other scripts //TODO: make proc getNodesFromSelected (name/type, string) //delete cgfx camera nodes int $numBadCameraNodes = 0; select persp; string $perspNodes[] = `listConnections -connections 1`; for ($i = 0; $i < size($perspNodes); $i++) { if ((`match pos $perspNodes[$i]` != "") || (`match dir $perspNodes[$i]` != "")) { delete $perspNodes[$i]; $numBadCameraNodes++; } } string $oldMaterials[] = `ls -type cgfxShader`; if (`size($oldMaterials)` == 0) { print "There are no CgFx materials in this scene\n"; //test to see if cgfx plugin is loaded if (`pluginInfo -query -loaded cgfxShader.mll`) { if ($numBadCameraNodes > 0) { return "modifiedFile"; } else { return "cgfxPluginLoaded"; } } else { return "uneventful"; } } else { string $sharedFileNodes[] ={"ambient_sampler", "diffuse_sampler", "emissive_sampler", "env_sampler", "normal_sampler", "specular_sampler"}; string $sharedParams[] = {"shininess", "reflection", "hidden", "collidable"}; for ($i = 0; $i < size($oldMaterials); $i++) { //get .cgfx file //TODO: skip if no cgfx file is assigned string $cgfxFile = `getAttr ($oldMaterials[$i] + ".shader")`; //add full path if needed string $projPath = `workspace -fn`; //string $cgfxMatch = `match $projPath $cgfxFile`; if (`match $projPath $cgfxFile` == "") { $cgfxFile = ($projPath + $cgfxFile); } //make sure collada plugin is loaded if (`pluginInfo -query -loaded COLLADA.mll` == 0) { string $oldpath = `pwd`; chdir "/"; chdir "/Program Files/AliasWavefront/Maya7.0"; chdir "/Program Files/Alias/Maya7.0"; chdir "%MAYA_PATH70%"; string $mayapath = `pwd`; chdir "/"; chdir $oldpath; string $colladapath = $mayapath + "/bin/plug-ins/COLLADA.mll"; waitCursor -state on; $ignoreUpdateCallback = true; catch( `loadPlugin $colladapath`); $ignoreUpdateCallback = false; waitCursor -state off; } //create new shader name (changing cgfx to colladafx if applicable) string $newMaterial = `substitute "cgfx" $oldMaterials[$i] "colladafx"`; //rename old shader rename ($oldMaterials[$i]) ($oldMaterials[$i]+ "_old"); $oldMaterials[$i] = ($oldMaterials[$i]+ "_old"); //create new shader shadingNode -asShader colladafxShader -name $newMaterial; //assign .cgfx file setAttr -type "string" ($newMaterial + ".vertexProgram") $cgfxFile; setAttr -type "string" ($newMaterial + ".fragmentProgram") $cgfxFile; //reload collada shader eval ("colladafxShaderCmd -lfe \"" + $cgfxFile + "\" \"main\" \"main\" -shader " + $newMaterial); //refreshColladafxShader $newMaterial; //get technique string $currentTechnique = `getAttr ($oldMaterials[$i] + ".technique")`; //set technique (cgfx technique = string - collada usetech = int) switch ($currentTechnique) { case "opaque": setAttr ($newMaterial + ".useTech") 0; break; case "alpha_blend": setAttr ($newMaterial + ".useTech") 1; break; case "alpha_test": setAttr ($newMaterial + ".useTech") 2; break; case "sky_opaque": setAttr ($newMaterial + ".useTech") 3; break; case "sky_blend": setAttr ($newMaterial + ".useTech") 4; break; } //copy $sharedParams between $oldMaterials[$i] and $newMaterial for ($j = 0; $j < size($sharedParams); $j++) { //get and assign attr setAttr ($newMaterial + "." + $sharedParams[$j]) `getAttr ($oldMaterials[$i] + "." + $sharedParams[$j])`; } //set .light_dir to persp string $lightDir = ($newMaterial + ".light_dir"); defaultNavigation -ce -d $lightDir -source persp; //connectNodeToAttrOverride("persp", $lightDir); //get channelFilePairs select $oldMaterials[$i]; string $channelFilePairs[] = `listConnections -connections 1`; //check existing cgfx connections and create connections to file nodes on new colladafx material for ($j = 0; $j < size($channelFilePairs); $j+=2) { string $channel = $channelFilePairs[$j]; string $fileNode = $channelFilePairs[$j+1]; //check against $sharedFileNodes for ($k = 0; $k < size($sharedFileNodes); $k++) { if ($channel == ($oldMaterials[$i] + "." + $sharedFileNodes[$k])) { //assign file node to new shader connectAttr -force ($fileNode + ".outColor") ($newMaterial + "." + $sharedFileNodes[$k]); } } } //select objects with old material, assign new material hyperShade -objects $oldMaterials[$i]; hyperShade -assign $newMaterial; //delete old material delete $oldMaterials[$i]; } //the end select -cl; print "\nc'est finis"; } return "modifiedFile"; } }