forked from lookbothways/vfxTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addNodeBetween
102 lines (67 loc) · 3.58 KB
/
addNodeBetween
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import maya.cmds as cmds
"""
For Shelf:
import addNodeBetween
reload(addNodeBetween)
selectedShaders = cmds.ls(sl=True)
for shader in selectedShaders:
addNodeBetween.addNodeBetween(shader)
"""
# Adds either a remapHSV of a gamma between diffuseColor and whatever is plugged into it.
# Updated for Arnold 5 mb120118
def addNodeBetween(shader):
isaiss = []
cmds.select(shader)
isaiss = cmds.ls(type='aiStandardSurface', sl=True)
if cmds.ls(type='aiStandardSurface', sl=True):
print "Shader is aiStandardSurface"
shaderType = "aiStandardSurface"
surfaceDiffuse = '%s.baseColor' % shader[0]
chooseNode = ""
chooseNode = cmds.confirmDialog( title='Insert node', message='Choose node type', button=['HSV','Gamma','Snow','Cancel'], defaultButton='Yes', cancelButton='Cancel', dismissString='No' )
if chooseNode != "Cancel":
diffuseUpstream = []
def findDiffuseUpstream(connections):
for i,x in enumerate(connections):
if x == surfaceDiffuse:
diffuseUpstream = connections[i+1]
return diffuseUpstream
print "Shader "+ str(shader)
# if alshader
surfaceDiffuse = '%s.baseColor' % shader
connections = cmds.listConnections(shader, connections=True, p=True)
#get position of diffuse colour
diffusePosition = [i for i,x in enumerate(connections) if x == surfaceDiffuse]
#get the name of the upstream node (if alshader '.diffuseColor' plug)
diffuseUpstream = findDiffuseUpstream(connections)
#nodename
if chooseNode == 'HSV':
nodeName = str(shader)+"_remapHSV"
newNode = cmds.shadingNode('remapHsv', asShader=True, n=nodeName)
if chooseNode == 'Gamma':
nodeName = str(shader)+"_gamma"
newNode = cmds.shadingNode('gammaCorrect', asShader=True, n=nodeName)
if chooseNode == 'Snow':
nodeName = str(shader)+"_snow"
newNode = cmds.shadingNode('snow', asShader=True, n=nodeName)
cmds.setAttr(newNode+".depthDecay", 2.545)
cmds.setAttr(newNode+".threshold", 0.312)
cmds.setAttr(newNode+".thickness", 0.088)
#disconnect attributes
print "Adding node between "+str(diffuseUpstream)+" and "+str(surfaceDiffuse)
cmds.disconnectAttr(diffuseUpstream, surfaceDiffuse)
# Diconnects and reconnects
if chooseNode == 'HSV':
cmds.connectAttr( diffuseUpstream, newNode+".color" )
cmds.connectAttr( newNode+".outColor", surfaceDiffuse )
if chooseNode == 'Gamma':
cmds.connectAttr( diffuseUpstream, newNode+".value" )
cmds.connectAttr( newNode+".outValue", surfaceDiffuse )
if chooseNode == 'Snow':
cmds.connectAttr( diffuseUpstream, newNode+".surfaceColor" )
cmds.connectAttr( newNode+".outColor", surfaceDiffuse )
else:
print "Add node between cancelled."
else:
cmds.warning( "Add node between only works on Arnold Standard Surface nodes" )
#end mb150118