cwisbg

toMIA_converter v3

Apr 14th, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.29 KB | None | 0 0
  1. # toMIA_converter  v3
  2. # cwisbg.com
  3. # Convert to MIA material
  4. from pymel.core import *  
  5. sl = selected()
  6. for s in sl:
  7.     matList = []
  8.     matType = s.nodeType()
  9.     colorCon = s.color.listConnections()
  10.     bumpCon = s.normalCamera.listConnections()
  11.     if matType != "lambert":
  12.         specCon = s.specularColor.listConnections()
  13.     nwMatCheck = ls('{0}_mia'.format(s))
  14.     if not nwMatCheck: # Check if theres a material already
  15.         nwMat = shadingNode('mia_material_x_passes',asShader=1,n='{0}_mia'.format(s))
  16.         matList.append(nwMat)
  17.     else:
  18.         nwMat = nwMatCheck[0]
  19.         matList.append(nwMat)
  20.     if colorCon:
  21.         colorCon[0].outColor >> nwMat.diffuse
  22.     else:
  23.         currentColor = getAttr(s.color)
  24.         setAttr(nwMat.diffuse,currentColor)
  25.     if bumpCon:
  26.         bumpCon[0].outNormal >> nwMat.overall_bump
  27.     if specCon:
  28.         specCon[0].outAlpha >> nwMat.reflectivity
  29.    
  30.     matSG = s.listConnections(t="shadingEngine")[0]
  31.     nwMat.message >> matSG.miMaterialShader
  32.     nwMat.message >> matSG.miShadowShader
  33.     nwMat.message >> matSG.miPhotonShader
  34.     setAttr(nwMat.reflectivity, 0)
  35.     #setAttr(nwMat.refl_gloss, 0.15)
  36. # Simple add gamma correct
  37. nodeCheck = "gammaCorrect", "mip_gamma_gain"
  38. for s in matList:
  39.     colorGrab = listAttr(s,se=1)
  40.     for attr in colorGrab:      
  41.         if attr[-5:] == "color" or attr[-7:] == "diffuse":
  42.             currentCon = listConnections("{0}.{1}".format(s,attr), p=1)  
  43.             currentType = nodeType(currentCon)      
  44.             if currentType in nodeCheck:
  45.                 pass
  46.             else:
  47.                 nwGamma = shadingNode("gammaCorrect", asUtility=1, n= "{0}_{1}_gamma".format(s, attr))
  48.                 setAttr("{0}.gammaX".format(nwGamma), 0.454545)
  49.                 setAttr("{0}.gammaY".format(nwGamma), 0.454545)
  50.                 setAttr("{0}.gammaZ".format(nwGamma), 0.454545)
  51.                 if currentCon:
  52.                     currentCon[0] >> nwGamma.value
  53.                 else:
  54.                     colorCon = getAttr("{0}.{1}".format(s,attr))
  55.                     #print "{0}.{1}_gamma.value".format(s,attr)
  56.                     setAttr("{0}_{1}_gamma.value".format(s,attr),  colorCon,type= "double3")    
  57.                 nwGamma.outValue >> "{0}.{1}".format(s,attr)
  58. print "done"
Advertisement
Add Comment
Please, Sign In to add comment