-
Notifications
You must be signed in to change notification settings - Fork 0
/
key_util_lib.py
355 lines (303 loc) · 11.2 KB
/
key_util_lib.py
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
from ctypes import *
import datetime
from pymel.core import *
import maya.OpenMaya as OpenMaya
import maya.cmds as cmds
class struct_timespec( Structure ):
_fields_ = [( 'tv_sec', c_long ), ( 'tv_nsec', c_long )]
class struct_stat64( Structure ):
_fields_ = [
( 'st_dev', c_int32 ),
( 'st_mode', c_uint16 ),
( 'st_nlink', c_uint16 ),
( 'st_ino', c_uint64 ),
( 'st_uid', c_uint32 ),
( 'st_gid', c_uint32 ),
( 'st_rdev', c_int32 ),
( 'st_atimespec', struct_timespec ),
( 'st_mtimespec', struct_timespec ),
( 'st_ctimespec', struct_timespec ),
( 'st_birthtimespec', struct_timespec ),
( 'dont_care', c_uint64 * 8 )
]
def get_creation_time( path ):
libc = CDLL( 'libc.dylib' )
stat64 = libc.stat64
stat64.argtypes = [c_char_p, POINTER( struct_stat64 )]
buf = struct_stat64()
rv = stat64( path, pointer( buf ) )
if rv != 0:
raise OSError( "Couldn't stat file %r" % path )
return buf.st_birthtimespec.tv_sec
def stripNamespaceFromReferenceImport( *args ):
objs = ls( fl = True )
for obj in objs:
colIdx = obj.rfind( ':' )
if colIdx > -1:
if cmds.objExists( obj ):
cmds.lockNode( obj, lock = False )
strName = str( obj )
name = strName[colIdx + 1:]
rename( obj, name )
def setPerspClippingPlane( *args ):
import math
perspCam = ls( 'perspShape' )[0]
pCamTransformNode = perspCam.getParent()
tran = pCamTransformNode.getTranslation()
camXun = math.sqrt( tran[0] * tran[0] )
camYun = math.sqrt( tran[1] * tran[1] )
camZun = math.sqrt( tran[2] * tran[2] )
clipPlaneFar = camXun + camYun + camZun
clipPlaneNear = ( camXun + camYun + camZun ) / 10000
perspCam.farClipPlane.set( clipPlaneFar )
perspCam.nearClipPlane.set( clipPlaneNear )
def distance2Pts( p1, p2 ):
error = 0
if len( p1 ) != 3:
OpenMaya.MGlobal.displayError( 'First argument list needs to have three elements...' )
error = 1
if len( p2 ) != 3:
OpenMaya.MGlobal.displayError( 'Second argument list needs to have three elements...' )
error = 1
if error != 1:
v = [0, 0, 0]
v[0] = p1[0] - p2[0]
v[1] = p1[1] - p2[1]
v[2] = p1[2] - p2[2]
distance = v[0] * v[0] + v[1] * v[1] + v[2] * v[2]
from math import sqrt
distance = sqrt( distance )
return distance
else:
return None
# some random shelf buttons for something I know little to nothing about
def FGC0( *args ):
sel = cmds.ls( sl = True, l = True )
shape = None
for item in sel:
shape = cmds.listRelatives( item, s = True, f = True )[0]
if shape != None:
cmds.setAttr( shape + '.miFinalGatherCast', 0 )
print ( shape )
def FGC1( *args ):
sel = cmds.ls( sl = True, l = True )
shape = None
for item in sel:
shape = cmds.listRelatives( item, s = True, f = True )[0]
if shape != None:
cmds.setAttr( shape + '.miFinalGatherCast', 1 )
print ( shape )
def FGR0( *args ):
sel = cmds.ls( sl = True, l = True )
shape = None
for item in sel:
shape = cmds.listRelatives( item, s = True, f = True )[0]
if shape != None:
cmds.setAttr( shape + '.miFinalGatherReceive', 0 )
print ( shape )
def FGR1( *args ):
sel = cmds.ls( sl = True, l = True )
shape = None
for item in sel:
shape = cmds.listRelatives( item, s = True, f = True )[0]
if shape != None:
cmds.setAttr( shape + '.miFinalGatherReceive', 1 )
print ( shape )
def shapeSize( mltp ):
'''\n
mltp = multiplier of shape nodes
'''
sel = cmds.ls( sl = True, l = True )
shape = None
for item in sel:
shape = cmds.listRelatives( item, s = True, f = True )
if shape != None:
for node in shape:
if 'SharedAttr' not in node:
cmds.scale( mltp, mltp, mltp, node + '.cv[*]' )
def transferPolySelectionSet( *args ):
'''
Name :trasferSelectionSet
Description :Usage, select a character set then the mesh you want to
create a newset from. This will create a new set from the currently
select set from the mesh selection. Transferring the set information
from oneobject to another.
Objects must have the same vertex index for predictable results.
'''
if len( cmds.ls( selection = True ) ) == 2:
master_set = cmds.ls( selection = True )[0]
target = cmds.ls( sl = True )[1]
sel_set = cmds.select( master_set )
sel_face = cmds.ls( sl = True, fl = True )
cmds.select( cl = True )
selList = []
for face in sel_face:
faceCheck = face.find( '.f' )
if faceCheck > -1:
addFace = '%s.f%s' % ( target, face.partition( '.f' )[2] )
selList.append( addFace )
cmds.select( selList )
target_set = cmds.sets( n = target + '_set' )
cmds.select( cl = True )
else:
print ( 'Need exactly two objects selected selection set, and a mesh' )
def cleanCacheNodes():
historySwitches = cmds.ls( type = 'historySwitch' )
for switch in historySwitches:
his = cmds.listHistory( switch )
for h in his:
if cmds.objExists( h ):
if cmds.nodeType( h ) != 'time':
cmds.delete( h )
OpenMaya.MGlobal.displayInfo( '== %s has been deleted ==' % h )
# begin the dumbest fucking hack ever
# maya will delete any sets that connected to the orig node. The connection
# only becomes visible when the Relationship Editor is open. Locking the nodes
# prevents their deletion
sets = cmds.ls( type = 'objectSet' )
for s in sets:
# lock-em up...dumb as shitty way of doing things
cmds.lockNode( s, l = True )
nodes = cmds.ls( type = 'mesh' )
for node in nodes:
if cmds.getAttr( node + '.intermediateObject' ):
cmds.delete( node )
OpenMaya.MGlobal.displayInfo( '== %s has been deleted ==' % node )
# end the dumbest fucking hack ever
for s in sets:
# unlock the nodes
cmds.lockNode( s, l = False )
class positionHud():
#
# First HUD for Cam Origin
#
def __init__( self, camStartObj = 'cam_StartPos', camOriginObj = 'cam_OriginPos', camAnimateObj = 'cam_AnimatePos', posCamStart = "CAM: pos from rail on 1st frame", posCamAnimate = "CAM: current pos (relative to 1st frame)" ):
namespace = 'Distance3Pnt:'
self.camOriginObj = namespace + camOriginObj
self.camStartObj = namespace + camStartObj
self.camAnimateObj = namespace + camAnimateObj
self.posCamStart = posCamStart
self.posCamAnimate = posCamAnimate
self.disCamOrigin = 'DISTANCE: cam from sleigh rail'
self.disCamAnimate = 'DISTANCE: cam traveled'
self.hud = None
def runHud( self ):
self.displayStartHud( self.posCamStart )
self.displayOrigDisHud( self.disCamOrigin )
self.displayAnimateHud( self.posCamAnimate )
self.displayAnimatedDisHud( self.disCamAnimate )
def cmToin( self, values ):
# values is expected to be made a tuple with 3 values
n = 'in'
if type( values ) == tuple:
conversion = []
axis = ['X', 'Y', 'Z']
i = 0
for value in values:
tmp = cmds.convertUnit( value, fromUnit = 'cm', toUnit = n )
flt = float( str( tmp ).rstrip( n ) )
tmp = str( round( flt, 1 ) )
conversion.append( axis[i] + ' = ' + tmp + n )
i = i + 1
return conversion
else:
tmp = cmds.convertUnit( values, fromUnit = 'cm', toUnit = n )
flt = float( str( tmp ).rstrip( n ) )
tmp = str( round( flt, 1 ) ) + n
return tmp
def posStart( self ):
try:
positionList = cmds.getAttr( '%s.translate' % self.camStartObj )[0]
positionList = self.cmToin( positionList )
return positionList
except:
return ( 0.0, 0.0, 0.0 )
def posAnimate( self ):
try:
positionList = cmds.getAttr( '%s.translate' % self.camAnimateObj )[0]
positionList = self.cmToin( positionList )
return positionList
except:
return ( 0.0, 0.0, 0.0 )
def disOrigin( self ):
try:
p1 = cmds.xform( self.camOriginObj, q = True, ws = True, t = True )
p2 = cmds.xform( self.camStartObj, q = True, ws = True, t = True )
distance = distance2Pts( p1, p2 )
distance = self.cmToin( distance )
return distance
except:
return 0
def disAnimate( self ):
try:
p1 = cmds.xform( self.camStartObj, q = True, ws = True, t = True )
p2 = cmds.xform( self.camAnimateObj, q = True, ws = True, t = True )
distance = distance2Pts( p1, p2 )
distance = self.cmToin( distance )
return distance
except:
return 0
def labelName( self, label = 'position' ):
sel = cmds.ls( sl = True )
string = ''
if len( sel ) == 0:
string = label + ' ---'
else:
string = label + ' ' + str( cmds.selectedNodes()[0].rsplit( '|' )[1] )
return string
def displayStartHud( self, hudName ):
self.hud = hudName
section = 4
cmds.headsUpDisplay( hudName, rem = True )
cmds.headsUpDisplay(
hudName,
section = section,
block = cmds.headsUpDisplay( nfb = section ),
attachToRefresh = True,
blockSize = 'medium',
label = hudName,
labelFontSize = 'small',
command = self.posStart
)
def displayAnimateHud( self, hudName ):
self.hud = hudName
section = 4
cmds.headsUpDisplay( hudName, rem = True )
cmds.headsUpDisplay(
hudName,
section = section,
block = cmds.headsUpDisplay( nfb = section ),
attachToRefresh = True,
blockSize = 'medium',
label = hudName,
labelFontSize = 'small',
command = self.posAnimate
)
def displayOrigDisHud( self, hudName ):
self.hud = hudName
section = 4
cmds.headsUpDisplay( hudName, rem = True )
cmds.headsUpDisplay(
hudName,
section = section,
block = cmds.headsUpDisplay( nfb = section ),
attachToRefresh = True,
blockSize = 'medium',
label = hudName,
labelFontSize = 'small',
command = self.disOrigin
)
def displayAnimatedDisHud( self, hudName ):
self.hud = hudName
section = 4
cmds.headsUpDisplay( hudName, rem = True )
cmds.headsUpDisplay(
hudName,
section = section,
block = cmds.headsUpDisplay( nfb = section ),
attachToRefresh = True,
blockSize = 'medium',
label = hudName,
labelFontSize = 'small',
command = self.disAnimate
)