Created
December 2, 2015 10:05
-
-
Save ben-hearn-sb/cdde5e63286a8d38fc4c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def createReplacementCgfx(material='', texturePaths={}, cgfxChannels={}, cgfxShaderPath=''): | |
""" If we find a shaderFxShader type material we need to replace wiuth CGFX for export purposes """ | |
print 'Replacing shader with CGFX' | |
#mel.eval('cgfxShader -fx "%s" ' %cgfxShaderPath) | |
matName = str(material) | |
shader = pm.listConnections(material, type='shadingEngine')[0] | |
members = list(set(shader.members(flatten=True))) | |
pm.delete(matName) | |
print 'got members' | |
if 'diffuse_layer0_texture' in texturePaths: | |
newMat = pm.shadingNode('cgfxShader', asShader=True, name=matName) | |
mel.eval('cgfxShader -e -fx "%s" %s;' %(cgfxShaderPath,newMat)) | |
for key in texturePaths: | |
slot = cgfxChannels[key] | |
texture = texturePaths[key] | |
newFileNode = createFileNode() | |
pm.setAttr('%s.fileTextureName' %newFileNode, texture, type='string') | |
pm.connectAttr('%s.outColor'%newFileNode, '%s.%s'%(newMat,slot), force=True) | |
print 'connected', newMat | |
pm.select(members) | |
pm.hyperShade(assign=newMat) | |
print 'CGFX function complete' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment