Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. import maya.cmds as cmds
  2.  
  3. def connectTex(image,material,input):
  4. # if a file texture is already connected to this input, update it
  5. # otherwise, delete it
  6. conn = cmds.listConnections(material+'.'+input,type='file')
  7. if conn:
  8. # there is a file texture connected. replace it
  9. cmds.setAttr(conn[0]+'.fileTextureName',image,type='string')
  10. else:
  11. # no connected file texture, so make a new one
  12. newFile = cmds.shadingNode('file',asTexture=1)
  13. newPlacer = cmds.shadingNode('place2dTexture',asUtility=1)
  14. # make common connections between place2dTexture and file texture
  15. connections = ['rotateUV','offset','noiseUV','vertexCameraOne','vertexUvThree','vertexUvTwo','vertexUvOne','repeatUV','wrapV','wrapU','stagger','mirrorU','mirrorV','rotateFrame','translateFrame','coverage']
  16. cmds.connectAttr(newPlacer+'.outUV',newFile+'.uvCoord')
  17. cmds.connectAttr(newPlacer+'.outUvFilterSize',newFile+'.uvFilterSize')
  18. for i in connections:
  19. cmds.connectAttr(newPlacer+'.'+i,newFile+'.'+i)
  20. # now connect the file texture output to the material input
  21. cmds.connectAttr(newFile+'.outColor',material+'.'+input,f=1)
  22. # now set attributes on the file node.
  23. cmds.setAttr(newFile+'.fileTextureName',image,type='string')
  24. cmds.setAttr(newFile+'.filterType',0)
  25.  
  26. #line vis stuff
  27. LVchannel = 'sMaterialTexture87b579ec018fbd4d_texture'
  28. detailChannel = 'sMaterialTexture4930b970a7fd511f_texture'
  29.  
  30. #find the texture folder for the current maya file
  31. folders = cmds.file(q=True, sn=True)
  32. textureFolder = os.path.dirname(folders)+ '/Textures/'
  33. print os.listdir(textureFolder)
  34.  
  35. gmFolder = 'C:/Telltale/ArtData/Characters/Sk61/BatmanGM/Textures/'
  36. print os.listdir(textureFolder)
  37.  
  38. #grab all dx11 shaders
  39. sel = cmds.ls(type='dx11Shader')
  40.  
  41. missing_detail =[]
  42.  
  43. for item in sel:
  44.  
  45. #shaders "use visibility toggle"
  46. #generate a filename for the visibility map.
  47. visMapName = item[:-2] + '_Visibility.tga'
  48. visMapPath = textureFolder + visMapName
  49.  
  50. #map slot connections for detaiil and visibility
  51. detailSlot = cmds.listConnections('%s.sMaterialTexture4930b970a7fd511f_texture'%item, type='file',s=True)
  52. try:
  53. visSlot = cmds.listConnections('%s.sMaterialTexture87b579ec018fbd4d_texture'%item,type='file',s=True)
  54. except:
  55. pass
  56.  
  57. #if the connection for the detail map returns none, no map is plugged in
  58. if detailSlot is None:
  59. print item + ' has no map in its detail slot'
  60.  
  61. #generate a file name na dpath off of the shader
  62. detailMapName = item[:-2] + '_detail.tga'
  63. detailMapPath = textureFolder + detailMapName
  64.  
  65. #if we find a map plug it in, if the shader has "head' in the name, search in the GM folder
  66.  
  67. if detailMapName in os.listdir(textureFolder) or detailMapName in os.listdir(gmFolder):
  68. if 'head' in item:
  69. detailMapPath = gmFolder + detailMapName
  70. connectTex(detailMapPath, item, detailChannel)
  71. #otherwise plug in the detail map we found
  72. else:
  73. print 'found a detail map for ' + item + ' plugging it in'
  74. detailMapPath = gmFolder + detailMapName
  75. connectTex(detailMapPath, item, detailChannel)
  76.  
  77. elif detailMapName not in os.listdir(textureFolder):
  78. print 'no detail map was found for ' + item + ' in the texture folder'
  79. missing_detail.append(item)
  80.  
  81. #if the
  82. if visMapName in os.listdir(textureFolder):
  83. print item + ' has a visibility map in the textures folder, attaching it now.'
  84. #toggle use vis map to true
  85. bULVString = (item + '.sMaterialStatic81a2c141682d2846_Value')
  86. cmds.setAttr(bULVString, 2)
  87. #plug in the map
  88. connectTex(visMapPath, item, LVchannel)
  89.  
  90.  
  91. else:
  92. print 'no visibility map found'
  93.  
  94. print '\n \n \n ----------list of missing maps-----------'
  95.  
  96. for m in missing_detail:
  97. print m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement