Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import maya.cmds as cmds
- def createAndConnectTex(nodeName, path, fileAttr, matAttr, isRaw=False, isAlphaAsLum=False):
- baseColFile = cmds.shadingNode('file', asTexture=True, isColorManaged=True, n=nodeName)#create file node
- cmds.setAttr(baseColFile + '.fileTextureName', path, type='string')#set file path
- if isRaw:
- gammaNode = cmds.shadingNode('gammaCorrect', n='%s_gammaCorrect' % nodeName, asUtility=True)
- cmds.setAttr(gammaNode + '.gamma', 2.2, 2.2, 2.2, type='double3')
- cmds.connectAttr(baseColFile + '.outColor', gammaNode + '.value', force=True)
- cmds.connectAttr(gammaNode + '.outValueX', matAttr, force=True)
- cmds.setAttr(baseColFile + '.colorSpace', 'Raw', type='string')
- else:
- cmds.connectAttr(baseColFile + fileAttr, matAttr, force=True)#connect file to material
- if isAlphaAsLum:
- cmds.setAttr(baseColFile + '.alphaIsLuminance', True)
- def getMapPath(diffPath, newMap):
- splitFile = diffPath.split('_')
- baseFile = '_'.join(splitFile[:-1])#get path without end
- mapTyp = splitFile[len(splitFile)-1]
- mapTypSplit = mapTyp.split('.')
- fileTyp = mapTypSplit[len(mapTypSplit)-1]#get file type
- newFile = baseFile+'_'+newMap+'.'+fileTyp#combine parts
- return newFile
- def setupMaterial(mat, baseFile):
- selMat = cmds.optionMenu(mat, query=True, value=True)#get material name
- selFile = cmds.textField(baseFile, query=True, text=True)#get selected file
- if selMat and selFile:
- createAndConnectTex('%s_Diffuse_file' % selMat, selFile, '.outColor', selMat + '.color')
- createAndConnectTex('%s_Specular_file' % selMat, getMapPath(selFile, 'Specular'), '.outColor', selMat + '.KsColor')
- createAndConnectTex('%s_Roughness_file' % selMat, getMapPath(selFile, 'Roughness'), '.outAlpha', selMat + '.specularRoughness', True, True)
- createAndConnectTex('%s_f0_file' % selMat, getMapPath(selFile, 'f0'), '.outAlpha', selMat + '.Ksn', True, True)
- nmlNode = cmds.shadingNode('bump2d', n='%s_Normal_B2D' % selMat, asUtility=True)
- nmlFileNode = cmds.shadingNode('file', asTexture=True, isColorManaged=True, n='%s_Normal_file' % selMat)#create file node
- cmds.setAttr(nmlFileNode + '.fileTextureName', getMapPath(selFile, 'Normal'), type='string')#set file path
- cmds.setAttr(nmlFileNode + '.colorSpace', 'Raw', type='string')
- cmds.connectAttr(nmlNode + '.outNormal', selMat + '.normalCamera', force=True)
- cmds.connectAttr(nmlFileNode + '.outAlpha', nmlNode + '.bumpValue', force=True)
- cmds.setAttr(nmlNode + '.bumpInterp', 1)#Set Tangent Space Normals
- cmds.select(selMat)
- def browseForFile(baseFile):
- selFile = cmds.fileDialog2(ds=2, fileMode=1, fileFilter='Image file (*.*)')
- if selFile:
- cmds.textField(baseFile, edit=True, text=selFile[0])
- winID = 'SubToRedUI'
- if cmds.window(winID, exists=True, resizeToFitChildren=True):
- cmds.deleteUI(winID)
- cmds.window( winID, title='Substance -> Arnold')
- cmds.columnLayout()
- matOption = cmds.optionMenu( label='Materials' )
- for mat in cmds.ls(type='aiStandard', long=True):
- cmds.menuItem(label=mat)
- cmds.separator(height=16)
- cmds.text(label='BaseColour texture:')
- cmds.rowLayout(numberOfColumns=2)
- baseFile = cmds.textField(width=256)
- cmds.button(label='Browse', command='browseForFile(baseFile)')
- cmds.setParent('..')
- cmds.separator(height=16)
- cmds.button(label='Go!', command='setupMaterial(matOption, baseFile)')
- cmds.showWindow( winID )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement