Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import maya.cmds as cmds
- def connectTex(image,material,input):
- # if a file texture is already connected to this input, update it
- # otherwise, delete it
- conn = cmds.listConnections(material+'.'+input,type='file')
- if conn:
- # there is a file texture connected. replace it
- cmds.setAttr(conn[0]+'.fileTextureName',image,type='string')
- else:
- # no connected file texture, so make a new one
- newFile = cmds.shadingNode('file',asTexture=1)
- newPlacer = cmds.shadingNode('place2dTexture',asUtility=1)
- # make common connections between place2dTexture and file texture
- connections = ['rotateUV','offset','noiseUV','vertexCameraOne','vertexUvThree','vertexUvTwo','vertexUvOne','repeatUV','wrapV','wrapU','stagger','mirrorU','mirrorV','rotateFrame','translateFrame','coverage']
- cmds.connectAttr(newPlacer+'.outUV',newFile+'.uvCoord')
- cmds.connectAttr(newPlacer+'.outUvFilterSize',newFile+'.uvFilterSize')
- for i in connections:
- cmds.connectAttr(newPlacer+'.'+i,newFile+'.'+i)
- # now connect the file texture output to the material input
- cmds.connectAttr(newFile+'.outColor',material+'.'+input,f=1)
- # now set attributes on the file node.
- cmds.setAttr(newFile+'.fileTextureName',image,type='string')
- cmds.setAttr(newFile+'.filterType',0)
- #line vis stuff
- LVchannel = 'sMaterialTexture87b579ec018fbd4d_texture'
- detailChannel = 'sMaterialTexture4930b970a7fd511f_texture'
- #find the texture folder for the current maya file
- folders = cmds.file(q=True, sn=True)
- textureFolder = os.path.dirname(folders)+ '/Textures/'
- print os.listdir(textureFolder)
- gmFolder = 'C:/Telltale/ArtData/Characters/Sk61/BatmanGM/Textures/'
- print os.listdir(textureFolder)
- #grab all dx11 shaders
- sel = cmds.ls(type='dx11Shader')
- missing_detail =[]
- for item in sel:
- #shaders "use visibility toggle"
- #generate a filename for the visibility map.
- visMapName = item[:-2] + '_Visibility.tga'
- visMapPath = textureFolder + visMapName
- #map slot connections for detaiil and visibility
- detailSlot = cmds.listConnections('%s.sMaterialTexture4930b970a7fd511f_texture'%item, type='file',s=True)
- try:
- visSlot = cmds.listConnections('%s.sMaterialTexture87b579ec018fbd4d_texture'%item,type='file',s=True)
- except:
- pass
- #if the connection for the detail map returns none, no map is plugged in
- if detailSlot is None:
- print item + ' has no map in its detail slot'
- #generate a file name na dpath off of the shader
- detailMapName = item[:-2] + '_detail.tga'
- detailMapPath = textureFolder + detailMapName
- #if we find a map plug it in, if the shader has "head' in the name, search in the GM folder
- if detailMapName in os.listdir(textureFolder) or detailMapName in os.listdir(gmFolder):
- if 'head' in item:
- detailMapPath = gmFolder + detailMapName
- connectTex(detailMapPath, item, detailChannel)
- #otherwise plug in the detail map we found
- else:
- print 'found a detail map for ' + item + ' plugging it in'
- detailMapPath = gmFolder + detailMapName
- connectTex(detailMapPath, item, detailChannel)
- elif detailMapName not in os.listdir(textureFolder):
- print 'no detail map was found for ' + item + ' in the texture folder'
- missing_detail.append(item)
- #if the
- if visMapName in os.listdir(textureFolder):
- print item + ' has a visibility map in the textures folder, attaching it now.'
- #toggle use vis map to true
- bULVString = (item + '.sMaterialStatic81a2c141682d2846_Value')
- cmds.setAttr(bULVString, 2)
- #plug in the map
- connectTex(visMapPath, item, LVchannel)
- else:
- print 'no visibility map found'
- print '\n \n \n ----------list of missing maps-----------'
- for m in missing_detail:
- print m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement