forked from lookbothways/vfxTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
easyBump
80 lines (54 loc) · 2.27 KB
/
easyBump
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
"""
easyBump
Gets the diffuse of the selected shader, creates a bump node and connects the green channel (Y) to bump value
For shelf:
import easyBump
reload(easyBump)
easyBump.easyBump()
Now supports Arnold 5 Standard Surface
"""
# Determine what type of shader (alShader, aiStandard)
import maya.cmds as cmds
def easyBump():
shaderType = []
diffuseUpstream = []
def findDiffuseUpstream(connections):
for i,x in enumerate(connections):
if x == surfaceDiffuse:
diffuseUpstream = connections[i+1]
return diffuseUpstream
for i,x in enumerate(connections):
if x == "color":
diffuseUpstream = connections[i+1]
return diffuseUpstream
shader = cmds.ls(sl=True)
selected = cmds.select(shader)
# get selected nodeType
if cmds.ls(type='aiStandard', sl=True):
print "Shader is aiStandard"
shaderType = "aiStandard"
surfaceDiffuse = '%s.color' % shader[0]
if cmds.ls(type='aiStandardSurface', sl=True):
print "Shader is aiStandardSurface"
shaderType = "aiStandardSurface"
surfaceDiffuse = '%s.baseColor' % shader[0]
if cmds.ls(type='alSurface', sl=True):
print "Shader is alSurface"
shaderType = "alSurface"
surfaceDiffuse = '%s.diffuseColor' % shader[0]
# Hooks up all the bits:
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
diffuseUpstream = findDiffuseUpstream(connections)
#disconnect attributes
print "Adding bump to "+str(diffuseUpstream)+" using "+str(surfaceDiffuse)
nodeName = str(shader[0])+"_bump2d"
newBumpNode = cmds.shadingNode('bump2d', asShader=True, n=nodeName)
# Hooks them all up - maybe it's a gamma, so tries outValueY also
try:
cmds.connectAttr( diffuseUpstream+".outValueY", newBumpNode+".bumpValue")
except RuntimeError:
cmds.connectAttr( diffuseUpstream+".outColorG", newBumpNode+".bumpValue" )
cmds.connectAttr( newBumpNode+".outNormal", shader[0]+".normalCamera" )