cwisbg

toMia_1

Sep 21st, 2012
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.80 KB | None | 0 0
  1. # toMIA_converter  v1
  2. # cwisbg.com
  3. # Convert to MIA material
  4. from pymel.core import *
  5. sl = selected()
  6. attrList = ("color","normalCamera","specularColor")
  7. miaList = ("diffuse", "overall_bump","refl_gloss")
  8. def getCons(s):# Get Connections, retuns array of connections
  9.     connections = listConnections(s,c=1)
  10.     x = 0  
  11.     connectionsArray = []
  12.     connectionsArray2 = []
  13.     connectionsArray3= []
  14.     for a in connections:
  15.         sgCheck = nodeType(a[1])
  16.         if sgCheck == "shadingEngine":  
  17.             matSG = a
  18.         c = connectionInfo(a[0], sfd=1)        
  19.         if c:
  20.             connectionsArray.append(a[0])
  21.             connectionsArray2.append(a[1])
  22.             connectionsArray3.append(c)
  23.         x+=1
  24.     return connectionsArray,connectionsArray2, connectionsArray3, matSG[1]
  25. for s in sl:
  26.     con,con1, con2, matSG = getCons(s)# Connect blinn to Newly created MIA
  27.     nwMatCheck = ls('{0}_mia'.format(s))
  28.     if not nwMatCheck: # Check if theres a material already
  29.         nwMat = shadingNode('mia_material_x_passes',asShader=1,n='{0}_mia'.format(s))
  30.     else:
  31.         nwMat = nwMatCheck
  32.     i = 0
  33.     for c in con:
  34.         testCon = connectionInfo("{0}.{1}".format(nwMat,miaList[i]),sfd=1)
  35.         if not testCon:
  36.             if i == 2:
  37.                 connectAttr("{0}.outAlpha".format(con1[i]),"{0}.{1}".format(nwMat,miaList[i]))
  38.             else:
  39.                 connectAttr(con2[i],"{0}.{1}".format(nwMat,miaList[i]))
  40.         i+=1
  41.     # Connect material to current materials Mental Ray Shading Engine  
  42.     connectAttr("{0}.message".format(nwMat), "{0}.miMaterialShader".format(matSG), f=1)
  43.     connectAttr("{0}.message".format(nwMat), "{0}.miShadowShader".format(matSG), f=1)
  44.     connectAttr("{0}.message".format(nwMat), "{0}.miPhotonShader".format(matSG), f=1)
  45. print "done"
Advertisement
Add Comment
Please, Sign In to add comment