I downloaded a RS Material to Phong script from a forum but it doesn’t have RedshiftIncandescent support so I decided to add it I got to a point where I recreated the same structure but for some reason its not detecting the “illumination color” input from RedshiftIncandescent. It says “illumination_color” is invalid.
import maya.cmds as cmds
import collections
#### OPTIONS ####
bumpVal = 0.15 # all bump maps will be set to this value, change if wanted
def scanNodeAttribute(node, attr):
# get the node attribute mode, and retrieve the value or connected node
plug = '%s.%s' % (node, attr)
# attribute mode
attrMode = cmds.listConnections(plug)
# dig deeper
if not attrMode:
try:
attrMode = cmds.listConnections('%sX' % plug)
except:
pass
if not attrMode:
try:
attrMode = cmds.listConnections('%sR' % plug)
except:
pass
if attrMode:
attrValue = attrMode[0]
attrMode = 'node'
else:
attrValue = cmds.getAttr(plug)
attrMode = 'value'
return (attrMode, attrValue)
####
def readRedshiftMaterial(node):
### readRedshiftMaterial ###
# node category
nodeCategory = 'RedshiftMaterial'
# shader values
diffuse_color = scanNodeAttribute(node, 'diffuse_color')
diffuse_weight = scanNodeAttribute(node, 'diffuse_weight')
diffuse_roughness = scanNodeAttribute(node, 'diffuse_roughness')
transl_color = scanNodeAttribute(node, 'transl_color')
transl_weight = scanNodeAttribute(node, 'transl_weight')
refl_color = scanNodeAttribute(node, 'refl_color')
refl_weight = scanNodeAttribute(node, 'refl_weight')
refl_roughness = scanNodeAttribute(node, 'refl_roughness')
refl_aniso = scanNodeAttribute(node, 'refl_aniso')
refl_aniso_rotation = scanNodeAttribute(node, 'refl_aniso_rotation')
refl_ior = scanNodeAttribute(node, 'refl_ior')
coat_color = scanNodeAttribute(node, 'coat_color')
coat_weight = scanNodeAttribute(node, 'coat_weight')
coat_roughness = scanNodeAttribute(node, 'coat_roughness')
refr_ior = scanNodeAttribute(node, 'refr_ior')
coat_ior = scanNodeAttribute(node, 'coat_ior')
refr_color = scanNodeAttribute(node, 'refr_color')
refr_weight = scanNodeAttribute(node, 'refr_weight')
refr_use_base_IOR = scanNodeAttribute(node, 'refr_use_base_IOR')
refr_ior = scanNodeAttribute(node, 'refr_ior')
refr_roughness = scanNodeAttribute(node, 'refr_roughness')
# unsupported atm
refr_thin_walled = scanNodeAttribute(node, 'refr_thin_walled')
refr_abbe = scanNodeAttribute(node, 'refr_abbe')
opacity_color = scanNodeAttribute(node, 'opacity_color')
emission_color = scanNodeAttribute(node, 'emission_color')
emission_weight = scanNodeAttribute(node, 'emission_weight')
bump_input = scanNodeAttribute(node, 'bump_input')
# build dictionary
nodeDict = collections.OrderedDict([('nodeCategory', nodeCategory),
('diffuse_color', diffuse_color),
('diffuse_weight', diffuse_weight),
('diffuse_roughness', diffuse_roughness),
('transl_color', transl_color),
('transl_weight', transl_weight),
('refl_color', refl_color),
('refl_weight', refl_weight),
('refl_roughness', refl_roughness),
('refl_aniso', refl_aniso),
('refl_aniso_rotation', refl_aniso_rotation),
('refl_ior', refl_ior),
('coat_color', coat_color),
('coat_weight', coat_weight),
('coat_roughness', coat_roughness),
('refr_ior', refr_ior),
('coat_ior', coat_ior),
('refr_color', refr_color),
('refr_weight', refr_weight),
('refr_use_base_IOR', refr_use_base_IOR),
('refr_ior', refr_ior),
('refr_roughness', refr_roughness),
('refr_thin_walled', refr_thin_walled),
('refr_abbe', refr_abbe),
('opacity_color', opacity_color),
('emission_color', emission_color),
('emission_weight', emission_weight),
('bump_input', bump_input)])
return nodeDict
def readRedshiftIncandescent(node):
### readRedshiftIncandescent ###
# node category
nodeCategory = 'RedshiftIncandescent'
# shader values
illumination_color = scanNodeAttribute(node, 'illumination_color')
# build dictionary
nodeDict = collections.OrderedDict([('nodeCategory', nodeCategory),
('illumination_color', illumination_color)])
return nodeDict
def goGetFile(node):
# if the plug on the left is not a file node, fbx will not plug anything, so we retrieve the first file node found
h = cmds.listHistory(node)
for i in h:
if cmds.nodeType(i) == 'file':
return i
###############################################################
nodes = cmds.ls(type='RedshiftMaterial')
Incandescent_nodes = cmds.ls(type='RedshiftIncandescent')
for node in nodes:
# convert all RedshiftMaterials to Phong
shaderDict = readRedshiftMaterial(node)
phong = cmds.shadingNode('phong', n='M_%s' % (node), asShader=True)
try:
sg = cmds.listConnections('%s.outColor' % node)[0]
cmds.connectAttr('%s.outColor' % phong, '%s.surfaceShader' % sg, f=1)
except:
# unplugged shader, get out
continue
##############################
# connect supported channels #
##############################
# diffuse_color
try:
if shaderDict['diffuse_color'][0] == 'value':
cmds.setAttr('%s.color' % phong, shaderDict['diffuse_color'][1][0][0], shaderDict['diffuse_color'][1][0][1],
shaderDict['diffuse_color'][1][0][2])
else:
fileTex = goGetFile(shaderDict['diffuse_color'][1])
cmds.connectAttr('%s.outColor' % fileTex, '%s.color' % phong, f=1)
except:
pass
# diffuse_weight
try:
if shaderDict['diffuse_weight'][0] == 'value':
cmds.setAttr('%s.diffuse' % phong, shaderDict['diffuse_weight'][1])
else:
fileTex = goGetFile(shaderDict['diffuse_weight'][1])
cmds.connectAttr('%s.outColor' % fileTex, '%s.diffuse' % phong, f=1)
except:
pass
# emission_color
try:
if shaderDict['emission_color'][0] == 'value':
cmds.setAttr('%s.incandescence' % phong, shaderDict['emission_color'][1][0][0],
shaderDict['emission_color'][1][0][1], shaderDict['emission_color'][1][0][2])
else:
fileTex = goGetFile(shaderDict['emission_color'][1])
cmds.connectAttr('%s.outColor' % fileTex, '%s.incandescence' % phong, f=1)
except:
pass
# refl_roughness
try:
if shaderDict['refl_roughness'][0] == 'value':
# cosinePower remap
rs_refl_roughness = shaderDict['refl_roughness'][1]
refl_roughness = ((float(rs_refl_roughness) * (2.0 - 98.0))) + 98.0
cmds.setAttr('%s.cosinePower' % phong, refl_roughness)
else:
fileTex = goGetFile(shaderDict['refl_roughness'][1])
cmds.connectAttr('%s.outColor' % fileTex, '%s.cosinePower' % phong, f=1)
except:
pass
# refl_color
try:
if shaderDict['refl_color'][0] == 'value':
cmds.setAttr('%s.specularColor' % phong, shaderDict['refl_color'][1][0][0],
shaderDict['refl_color'][1][0][1], shaderDict['refl_color'][1][0][2])
else:
fileTex = goGetFile(shaderDict['refl_color'][1])
cmds.connectAttr('%s.outColor' % fileTex, '%s.specularColor' % phong, f=1)
cmds.setAttr('%s.reflectedColor' % phong, 0.5, 0.5, 0.5)
except:
pass
# refl_weight
try:
if shaderDict['refl_weight'][0] == 'value':
cmds.setAttr('%s.reflectivity' % phong, shaderDict['refl_weight'][1])
else:
fileTex = goGetFile(shaderDict['refl_weight'][1])
cmds.connectAttr('%s.outColor' % fileTex, '%s.reflectivity' % phong, f=1)
except:
pass
# bump
try:
if shaderDict['bump_input'][0] == 'value':
pass
else:
# plug a random file in a bump
rsBump = shaderDict['bump_input'][1]
fileTex = goGetFile(shaderDict['bump_input'][1])
bmp2d = cmds.shadingNode('bump2d', n='bmp', asTexture=True)
cmds.setAttr('%s.bumpDepth' % bmp2d, bumpVal)
cmds.connectAttr('%s.outAlpha' % fileTex, '%s.bumpValue' % bmp2d, f=1)
cmds.setAttr('%s.alphaIsLuminance' % fileTex, 1)
cmds.connectAttr('%s.outNormal' % bmp2d, '%s.normalCamera' % phong, f=1)
except:
pass
# opacity_color
try:
if shaderDict['opacity_color'][0] == 'value':
cmds.setAttr('%s.transparency' % phong, 1 - shaderDict['opacity_color'][1][0][0],
1 - shaderDict['opacity_color'][1][0][1], 1 - shaderDict['opacity_color'][1][0][2])
else:
fileTex = goGetFile(shaderDict['opacity_color'][1])
cmds.connectAttr('%s.outColor' % fileTex, '%s.transparency' % phong, f=1)
except:
pass
for node in Incandescent_nodes:
# convert all RedshiftMaterials to Phong
shaderDict = readRedshiftIncandescent(node)
phong = cmds.shadingNode('phong', n='M_%s' % (node), asShader=True)
try:
sg = cmds.listConnections('%s.outColor' % node)[0]
cmds.connectAttr('%s.outColor' % phong, '%s.surfaceShader' % sg, f=1)
except:
# unplugged shader, get out
continue
##############################
# connect supported channels #
##############################
# Illumination_Color
try:
if shaderDict['Illumination_Color'][0] == 'value':
cmds.setAttr('%s.color' % phong, shaderDict['Color'][1][0][0], shaderDict['Color'][1][0][1],
shaderDict['Color'][1][0][2])
else:
fileTex = goGetFile(shaderDict['Color'][1])
cmds.connectAttr('%s.outColor' % fileTex, '%s.color' % phong, f=1)
except:
passe