forked from lookbothways/vfxTools
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetupMayaLensDistortionOptions.py
More file actions
194 lines (132 loc) · 4.11 KB
/
Copy pathsetupMayaLensDistortionOptions.py
File metadata and controls
194 lines (132 loc) · 4.11 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import maya.cmds as cmds
import re
import string
import maya.mel as mel
import os
exists=False
distortionFilename=""
"""
#Example global being updated inside a def (proc)
moo2= 1
def make_moo():
global moo2
moo2=2222
make_moo()
print moo2
"""
def stMapPath(proj):
#Gets the correct filename
temp=string.split(proj,'/')
seq="sc"+temp[6]
shot="sh"+temp[7]
pubDir=('/mnt/projects/tt/publish/scenes/'+seq+'/'+shot+'/distortion/')
distortion=[]
distortion=str(cmds.getFileList(fld=pubDir,fs='*distorted.exr'))
distortion=distortion[3:-2]
print "Looking for {}".format(distortion)
dirList=str(pubDir)+str(distortion)
fileExists=os.path.exists(dirList)
global distortionFilename
distortionFilename = pubDir+"tt_{}_{}_distorted.exr".format(seq,shot)
if fileExists == True:
mapPath=dirList
print "File exists: {} ".format(dirList)
return mapPath
exists=True
else:
return
def getRes(camera):
# example name sh110_RENDERCAMERA_2128x1197Shape
myLen=len(camera);
print(myLen)
xres=camera[myLen-14:myLen-10]
yres=camera[myLen-9:myLen-5]
return [xres,yres]
def getCamera():
cameras=cmds.ls(typ='camera')
for x in cameras:
if re.search('rendercamera',x.lower()):
return x
break
def setResolution(camera,option):
res=[2048,1152]
if option=='overscan':
res=getRes(camera)
print('xres is '+res[0]+' yres is '+res[1])
if cmds.objExists('defaultResolution'):
cmds.setAttr('defaultResolution.width',float(res[0]))
cmds.setAttr('defaultResolution.height',float(res[1]))
def getOption():
option=cmds.confirmDialog(
title='Distortion Pipeline Options',
message='Choose Lens Options',
button=['Use ST Map','Use Overscan','Bypass','Cancel'],
defaultButton='Use ST Map',
cancelButton='Cancel',
dismissString='Cancel'
)
return option
def mkFileNode(myName):
return cmds.createNode('aiImage',name=myName)
def assignMap(node,path):
if re.search(".exr",path):
print "Connecting ST file: "+path
cmds.setAttr(node+'.filename',path,type='string')
else:
cmds.warning( "Distortion setup failed: ST map is not in the correct location / incorrectly named. File should be {}".format(distortionFilename) )
# Example:
#cmds.setAttr(node+'.filename',path,type='string')
cmds.setAttr(node+'.swrap',2) # clamp texture tiling - IMPORTANT
cmds.setAttr(node+'.twrap',2)
def checkForExistingFileNode(myMap):
fileNodes=cmds.ls(typ='aiImage')
for x in fileNodes:
test=cmds.getAttr(x+'.filename')
if re.search(myMap,test):
return x
return None
def makeUVMapConnection(camera,myMap):
test=checkForExistingFileNode(myMap)
if test is not None:
print('reconnecting existing aiImage node')
txFileNode=test
else:
txFileNode=mkFileNode('UV_lensDstortionMap')
print('made aiImage node '+txFileNode)
assignMap(txFileNode,myMap)
cmds.connectAttr(txFileNode+'.outColor',camera+'.aiUvRemap')
def connectUVMap(proj,camera):
uvMap=stMapPath(proj)
if stMapPath(proj):
print "Attempting to connect {}".format(stMapPath(proj))
if uvMap is not None:
#print(uvMap)
if not breakConnection(camera,'test'): # test for existing connection
makeUVMapConnection(camera,uvMap)
else:
cmds.warning( "There is already a map connected to aiUvRemap." )
else:
cmds.warning( "Map not found!" )
def breakConnection(camera,mode):
conn=cmds.listConnections(camera+'.aiUvRemap',d=False,s=True,p=True)
if conn is not None:
if mode=='break':
cmds.disconnectAttr(conn[0],camera+'.aiUvRemap')
if mode=='test':
return 1
def doSomething():
option=getOption()
#print('option was '+option)
if option=='Cancel':
return
proj=cmds.workspace(q=True,act=True)
camera=getCamera()
if option=='Use ST Map':
connectUVMap(proj,camera)
setResolution(camera,'default')
if option=='Use Overscan':
breakConnection(camera,'break')
setResolution(camera,'overscan')
if option=='Bypass':
breakConnection(camera,'break')
setResolution(camera,'default')