-
Notifications
You must be signed in to change notification settings - Fork 0
/
constraintUI_micro_lib.py
312 lines (298 loc) · 20.7 KB
/
constraintUI_micro_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
import json
import os
import maya.cmds as cmds
import maya.mel as mel
def message( what = '' ):
mel.eval( 'print \"' + '-- ' + what + ' --' + '\";' )
# print "\n"
class Action( object ):
# builds row of buttons for bottom of window
def __init__( self, name, parent = None, h = 15, w = 80, cmdAction = '', label = '' ):
self.parent = parent
self.prefs = {}
self.illegalChar = ['.', '*']
self.form = name + '_form'
self.column = name + '_column'
self.opt = name + '_opt'
self.actionButton1 = name + '_actionButton1'
self.actionButton2 = name + '_actionButton2'
self.actionButton3 = name + '_actionButton3'
self.actionButton4 = name + '_actionButton4'
self.actionButton5 = name + '_actionButton5'
self.actionButton6 = name + '_actionButton6'
self.actionField1 = name + '_actionField1'
self.actionButton7 = name + '_actionButton7'
self.actionButton8 = name + '_actionButton8'
self.actionButton9 = name + '_actionButton9'
self.actionButton10 = name + '_actionButton10'
self.actionButton11 = name + '_actionButton11'
self.actionButton12 = name + '_actionButton12'
self.actionButton13 = name + '_actionButton13'
self.actionButton14 = name + '_actionButton14'
self.actionButton15 = name + '_actionButton15'
self.actionButton16 = name + '_actionButton16'
self.actionButton17 = name + '_actionButton17'
self.actionButton18 = name + '_actionButton18'
self.floatGroup1 = name + '_floatGrp1'
self.c1 = ''
self.c2 = ''
self.c3 = ''
self.c4 = ''
self.c5 = ''
# self.c6 = ''
self.c7 = ''
self.c8 = ''
self.c9 = ''
self.c10 = ''
self.c11 = ''
self.c12 = ''
self.c13 = ''
self.c14 = ''
self.c15 = ''
self.c16 = ''
self.c17 = ''
self.c18 = ''
self.c19 = ''
self.c20 = ''
self.c21 = ''
self.c22 = ''
self.s0 = ''
self.s1 = ''
self.s2 = ''
self.s3 = ''
self.s4 = ''
self.s5 = ''
self.s6 = ''
self.s7 = ''
self.opt1 = ''
self.sl1 = ''
# self.col1 = ''
# self.r1 = ''
# self.r2 = ''
self.conGrp = ''
self.aimGrp = ''
self.upGrp = ''
self.label = label
self.cmdAction = cmdAction
#
self.h = h
self.w = w
self.heightForm = 30
self.sepH = 15
self.sepStl = 'in'
self.buildColumn()
self.buildAction()
def prefPath( self, *args ):
varPath = cmds.internalVar( userAppDir = True )
path = os.path.join( varPath, 'scripts' )
path = os.path.join( path, 'HelpersPrefs.json' )
return path
def prefSave( self, *args ):
# save
fileObjectJSON = open( self.prefPath(), 'wt' )
json.dump( self.prefs, fileObjectJSON, indent = 1 )
fileObjectJSON.close()
def prefLoad( self, *args ):
# load
if os.path.isfile( self.prefPath() ):
try:
fileObjectJSON = open( self.prefPath(), 'r' )
self.prefs = json.load( fileObjectJSON )
fileObjectJSON.close()
self.prefPut()
except:
os.remove( self.prefPath() )
message( 'Pref file not compatible, DELETING.' )
def prefGet( self, *args ):
self.prefs['BkRmvCon'] = cmds.checkBox( self.c2, q = True, v = True )
self.prefs['BkTmRng'] = cmds.checkBox( self.c3, q = True, v = True )
self.prefs['BkAllFrms'] = cmds.checkBox( self.c4, q = True, v = True )
self.prefs['LocTrns'] = cmds.checkBox( self.c7, q = True, v = True )
self.prefs['LocRot'] = cmds.checkBox( self.c8, q = True, v = True )
self.prefs['LocAllFrms'] = cmds.checkBox( self.c12, q = True, v = True )
self.prefs['PrntRgPosOnly'] = cmds.checkBox( self.c17, q = True, v = True )
self.prefs['AimRgNegAim'] = cmds.checkBox( self.c15, q = True, v = True )
self.prefs['AimRgAim'] = cmds.radioButtonGrp( self.aimGrp, q = True, select = True )
self.prefs['AimRgNegUp'] = cmds.checkBox( self.c16, q = True, v = True )
self.prefs['AimRgUp'] = cmds.radioButtonGrp( self.upGrp, q = True, select = True )
self.prefs['PvtRgNegAim'] = cmds.checkBox( self.c18, q = True, v = True )
self.prefs['PvtRgAim'] = cmds.radioButtonGrp( self.aimPivotGrp, q = True, select = True )
self.prefs['PvtRgNegUp'] = cmds.checkBox( self.c19, q = True, v = True )
self.prefs['PvtRgUp'] = cmds.radioButtonGrp( self.upPivotGrp, q = True, select = True )
self.prefs['PvtRgMstr'] = cmds.checkBox( self.c21, q = True, v = True )
self.prefs['PvtRgMstrSl'] = cmds.radioButtonGrp( self.masterGrp, q = True, select = True )
self.prefs['PvtRgMstrEnbl'] = cmds.radioButtonGrp( self.masterGrp, q = True, en = True )
self.prefs['PvtRgAutoDstnc'] = cmds.checkBox( self.c22, q = True, v = True )
self.prefs['PvtRgDstnc'] = cmds.floatSliderGrp( self.sl1, q = True, v = True )
self.prefs['PvtRgDstncEnbl'] = cmds.floatSliderGrp( self.sl1, q = True, en = True )
self.prefs['LcAllFrms'] = cmds.checkBox( self.c21, q = True, v = True )
self.prefs['PlcCon'] = cmds.checkBox( self.c5, q = True, v = True )
self.prefs['PlcConTo'] = cmds.radioButtonGrp( self.conGrp, q = True, select = True )
self.prefs['PlcConToEnbl'] = cmds.radioButtonGrp( self.conGrp, q = True, en = True )
self.prefs['PlcMtchKys'] = cmds.checkBox( self.c13, q = True, v = True )
self.prefs['ConOffst'] = cmds.checkBox( self.c9, q = True, v = True )
self.prefs['ConTrns'] = cmds.checkBox( self.c10, q = True, v = True )
self.prefs['ConRot'] = cmds.checkBox( self.c11, q = True, v = True )
self.prefs['DstKys'] = cmds.intField( self.actionField1, q = True, v = True )
self.prefs['DstKysDstrct'] = cmds.checkBox( self.c14, q = True, v = True )
# float x3, needs to be x4 for, import requires it
l = cmds.floatFieldGrp( self.floatGroup1, q = True, v = True )
l.append( 0.0 )
self.prefs['ObjctSpaceOffst'] = l
#
self.prefSave()
def prefPut( self ):
cmds.checkBox( self.c2, e = True, v = self.prefs['BkRmvCon'] )
cmds.checkBox( self.c3, e = True, v = self.prefs['BkTmRng'] )
cmds.checkBox( self.c4, e = True, v = self.prefs['BkAllFrms'] )
cmds.checkBox( self.c7, e = True, v = self.prefs['LocTrns'] )
cmds.checkBox( self.c8, e = True, v = self.prefs['LocRot'] )
cmds.checkBox( self.c12, e = True, v = self.prefs['LocAllFrms'] )
cmds.checkBox( self.c17, e = True, v = self.prefs['PrntRgPosOnly'] )
cmds.checkBox( self.c15, e = True, v = self.prefs['AimRgNegAim'] )
cmds.radioButtonGrp( self.aimGrp, e = True, select = self.prefs['AimRgAim'] )
cmds.checkBox( self.c16, e = True, v = self.prefs['AimRgNegUp'] )
cmds.radioButtonGrp( self.upGrp, e = True, select = self.prefs['AimRgUp'] )
cmds.checkBox( self.c18, e = True, v = self.prefs['PvtRgNegAim'] )
cmds.radioButtonGrp( self.aimPivotGrp, e = True, select = self.prefs['PvtRgAim'] )
cmds.checkBox( self.c19, e = True, v = self.prefs['PvtRgNegUp'] )
cmds.radioButtonGrp( self.upPivotGrp, e = True, select = self.prefs['PvtRgUp'] )
cmds.checkBox( self.c21, e = True, v = self.prefs['PvtRgMstr'] )
cmds.radioButtonGrp( self.masterGrp, e = True, select = self.prefs['PvtRgMstrSl'] )
cmds.radioButtonGrp( self.masterGrp, e = True, en = self.prefs['PvtRgMstrEnbl'] )
cmds.checkBox( self.c22, e = True, v = self.prefs['PvtRgAutoDstnc'] )
cmds.floatSliderGrp( self.sl1, e = True, v = self.prefs['PvtRgDstnc'] )
cmds.floatSliderGrp( self.sl1, e = True, en = self.prefs['PvtRgDstncEnbl'] )
cmds.checkBox( self.c21, e = True, v = self.prefs['LcAllFrms'] )
cmds.checkBox( self.c5, e = True, v = self.prefs['PlcCon'] )
cmds.radioButtonGrp( self.conGrp, e = True, select = self.prefs['PlcConTo'] )
cmds.radioButtonGrp( self.conGrp, e = True, en = self.prefs['PlcConToEnbl'] )
cmds.checkBox( self.c13, e = True, v = self.prefs['PlcMtchKys'] )
cmds.checkBox( self.c9, e = True, v = self.prefs['ConOffst'] )
cmds.checkBox( self.c10, e = True, v = self.prefs['ConTrns'] )
cmds.checkBox( self.c11, e = True, v = self.prefs['ConRot'] )
cmds.intField( self.actionField1, e = True, v = self.prefs['DstKys'] )
cmds.checkBox( self.c14, e = True, v = self.prefs['DstKysDstrct'] )
cmds.floatFieldGrp( self.floatGroup1, e = True, v = self.prefs['ObjctSpaceOffst'] )
def buildColumn( self ):
cmds.setParent( self.parent )
self.column = cmds.columnLayout( adjustableColumn = True )
def buildAction( self ):
self.neutral = [0.37, 0.37, 0.37]
self.grey = [0.5, 0.5, 0.5]
self.greyD = [0.2, 0.2, 0.2]
self.red = [0.5, 0.2, 0.2]
self.redD = [0.4, 0.2, 0.2]
self.blue = [0.2, 0.3, 0.5]
self.green = [0.2, 0.5, 0.0]
self.teal = [0.0, 0.5, 0.5]
self.purple = [0.35, 0.35, 0.5]
self.purple2 = [0.28, 0.28, 0.39]
self.orange = [0.5, 0.35, 0.0]
existing = 'Will only bake on existing frames.\nTurn off to get a key on every frame.'
time = 'Force timeline range to be baked.\nOtherwise range is gathered in this priority:\n-Use selected range\n-Use range from animation, if any\n-Use range from timeline.'
simu = 'Step through every frame.'
# self.s0 = cmds.separator( height=self.sepH, style=self.sepStl )
# bake
self.actionButton1 = cmds.button( self.actionButton1, label = 'Bake', c = self.cmdAction, bgc = self.red,
ann = 'Bake selected objects if they are connected to a pairBlend node or constraint.' )
self.c2 = cmds.checkBox( label = 'Keep Constraint Connected', v = True, cc = self.prefGet,
ann = 'Remove constraint after baking.\nIf off, anim curves are updated and the constraint remains connected.' )
self.c3 = cmds.checkBox( label = 'Timeline Range', cc = self.prefGet, ann = time )
self.c4 = cmds.checkBox( label = 'On All Frames', v = False, cc = self.prefGet, ann = simu )
self.s7 = cmds.separator( height = self.sepH, style = self.sepStl )
# bake to locator
self.actionButton3 = cmds.button( self.actionButton3, label = 'Bake To HELPER', c = self.cmdAction, bgc = self.red,
ann = 'Bake all selected objects to a locator in world space.' )
# self.c6 = cmds.checkBox( label='On Existing Frames', v=True, ann=existing )
self.c7 = cmds.checkBox( label = 'Translation', v = True, cc = self.prefGet, ann = 'Only bake translation attributes.\nRotation will be constrained to follow object.' )
self.c8 = cmds.checkBox( label = 'Rotation', v = True, cc = self.prefGet, ann = 'Only bake rotation attributes.\nTranslation will be constrained to follow object.' )
self.c12 = cmds.checkBox( label = 'On All Frames', v = False, cc = self.prefGet, ann = simu )
self.s2 = cmds.separator( height = self.sepH, style = self.sepStl )
# distribute keys
cmds.rowLayout( numberOfColumns = 2, ad2 = 1 )
self.actionButton16 = cmds.button( self.actionButton16, label = 'Distribute keys every nth frame:', c = self.cmdAction, bgc = self.grey )
self.actionField1 = cmds.intField( self.actionField1, cc = self.prefGet, v = 5, w = 50 )
cmds.setParent( '..' )
ann = 'Destructive Mode. Removes keys that dont fall on the same frame.'
self.c14 = cmds.checkBox( label = 'Destructive', v = True, cc = self.prefGet, ann = ann )
self.s1 = cmds.separator( height = self.sepH, style = self.sepStl )
# rotate order
cmds.rowLayout( numberOfColumns = 3, ad3 = 1 )
self.actionButton7 = cmds.button( self.actionButton7, label = 'Transform Rotate Order', c = self.cmdAction, bgc = self.grey, ann = 'Transform animation to different rotation order.' )
self.actionButton18 = cmds.button( self.actionButton18, label = 'Query', c = self.cmdAction, ann = 'Selects objects current Rotate Order' )
self.opt1 = cmds.optionMenuGrp( label = '', cw2 = [0, 40], cat = ( 1, 'left', 0 ), ann = 'Select rotate order to bake to.' )
self.ro = ['xyz', 'yzx', 'zxy', 'xzy', 'yxz', 'zyx']
for o in self.ro:
cmds.menuItem( o )
cmds.setParent( '..' )
self.s6 = cmds.separator( height = self.sepH, style = self.sepStl )
# space switcher
self.actionButton8 = cmds.button( self.actionButton8, label = '-- Store -- World Space Anim', c = self.cmdAction, bgc = self.purple,
ann = 'Space switch tool\n1. Store animation before making changes to attributes.\n2. Make changes to attributes\n3. Restore animation using restore button.' )
self.actionButton9 = cmds.button( self.actionButton9, label = 'Restore', c = self.cmdAction, bgc = self.purple,
ann = 'Space switch tool\n1. Store animation before making changes to attributes.\n2. Make changes to attributes\n3. Restore animation using restore button.' )
self.actionButton14 = cmds.button( self.actionButton14, label = 'Restore to Selected', c = self.cmdAction, bgc = self.purple2,
ann = 'Space switch tool\n1. Store animation before making changes to attributes.\n2. Make changes to attributes\n3. Override - Restore animation to selected object.' )
# object space rotate offset
self.floatGroup1 = cmds.floatFieldGrp( self.floatGroup1, numberOfFields = 3, label = 'Restore with offset', cc = self.prefGet, ad4 = 1, cw4 = [50, 40, 40, 40], cl4 = ['left', 'left', 'left', 'left'], value1 = 0.0, value2 = 0.0, value3 = 0.0, w = self.w,
ann = 'Add a relative object space rotation to the stored animation' )
self.s3 = cmds.separator( height = self.sepH, style = self.sepStl )
#
# match things
# self.actionButton4 = cmds.button( self.actionButton4, label = 'Match Keys', c = self.cmdAction, bgc = self.green,
# ann = 'Select 2 objects.\nSecond object will be keyed on same frames as the first.\nNo animation is added, the object is just keyed.' )
# self.actionButton6 = cmds.button( self.actionButton6, label = 'Match Transforms', c = self.cmdAction, bgc = self.green,
# ann = 'Match the position of first object to second object.' )
# self.s6 = cmds.separator( height = self.sepH, style = self.sepStl )
# stick
# self.actionButton10 = cmds.button( self.actionButton10, label = 'Stick', c = self.cmdAction, bgc = self.teal,
# ann = '1 object selected:\nA locator is created and the object is constrained to it on that position.\n\n2 objects selected:\nThe first is constrained to second with an offset.' )
# self.actionButton11 = cmds.button( self.actionButton11, label = 'UnStick', c = self.cmdAction, bgc = self.teal,
# ann = 'Selected object is baked.\nhighlight a frame range to use it instead of the full animation.\nExtra objects are deleted.' )
# self.c1 = cmds.checkBox( label = 'On All Frames', v = False, ann = existing )
# self.s4 = cmds.separator( height = self.sepH, style = self.sepStl )
#
#
# parent rig
self.actionButton12 = cmds.button( self.actionButton12, label = 'Parent Rig', c = self.cmdAction, bgc = self.greyD,
ann = 'A parent rig is created between 2 objects.\n Animation is preserved and transfered to a locator.\nSelect child first.\nROOT/SPIN/OFFSET' )
self.c17 = cmds.checkBox( label = 'Position Only', v = False, cc = self.prefGet, ann = 'Rotations in world space or in the space of third selection' )
# aim rig
self.actionButton13 = cmds.button( self.actionButton13, label = 'Aim Rig', c = self.cmdAction, bgc = self.greyD,
ann = 'An aim rig is created between 2 objects.\n Animation is preserved and transfered to locator.\nSelect target first.\nROOT/BASE\nROOT/AIM/OFFSET\nROOT/AIM/UP' )
self.c15 = cmds.checkBox( label = 'Negative Aim', v = False, cc = self.prefGet, ann = 'Specifies the AIM should be in the negative direction' )
self.aimGrp = cmds.radioButtonGrp( label = 'Aim:', cc = self.prefGet, labelArray3 = ['x', 'y', 'z'], select = 1, numberOfRadioButtons = 3, w = self.w, ad4 = 5, cw4 = [40, 35, 35, 35], cl4 = ['left', 'left', 'left', 'left'], ct4 = ['left', 'left', 'left', 'left'] )
self.c16 = cmds.checkBox( label = 'Negative Up', v = False, cc = self.prefGet, ann = 'Specifies the UP should be in the negative direction' )
self.upGrp = cmds.radioButtonGrp( label = 'Up:', cc = self.prefGet, labelArray3 = ['x', 'y', 'z'], select = 2, numberOfRadioButtons = 3, w = self.w, ad4 = 5, cw4 = [40, 35, 35, 35], cl4 = ['left', 'left', 'left', 'left'], ct4 = ['left', 'left', 'left', 'left'] )
# pivot rig
# aimPivotRig(size=0.3, aim=(0, 0, 1), u=(0, 1, 0), offset=20.0, masterControl=False, masterPosition=0)
self.actionButton17 = cmds.button( self.actionButton17, label = 'Pivot Rig', c = self.cmdAction, bgc = self.greyD )
# aim
self.c18 = cmds.checkBox( label = 'Negative Aim', v = False, cc = self.prefGet, ann = 'Specifies the AIM should be in the negative direction' )
self.aimPivotGrp = cmds.radioButtonGrp( label = 'Aim:', cc = self.prefGet, labelArray3 = ['x', 'y', 'z'], select = 1, numberOfRadioButtons = 3, w = self.w, ad4 = 5, cw4 = [40, 35, 35, 35], cl4 = ['left', 'left', 'left', 'left'], ct4 = ['left', 'left', 'left', 'left'] )
# up
self.c19 = cmds.checkBox( label = 'Negative Up', v = False, cc = self.prefGet, ann = 'Specifies the UP should be in the negative direction' )
self.upPivotGrp = cmds.radioButtonGrp( label = 'Up:', cc = self.prefGet, labelArray3 = ['x', 'y', 'z'], select = 2, numberOfRadioButtons = 3, w = self.w, ad4 = 5, cw4 = [40, 35, 35, 35], cl4 = ['left', 'left', 'left', 'left'], ct4 = ['left', 'left', 'left', 'left'] )
# master
self.c21 = cmds.checkBox( label = 'Master Control / Location', v = False, cc = self.prefGet, ann = 'Create master control at one of the 4 pivot points.' )
self.masterGrp = cmds.radioButtonGrp( label = '', cc = self.prefGet, en = False, labelArray4 = ['Core', 'Root', 'Aim', 'Up'], select = 1, numberOfRadioButtons = 4, w = self.w, ad5 = 5, cw5 = [0, 50, 50, 40, 35], cl5 = ['left', 'left', 'left', 'left', 'left'], ct5 = ['left', 'left', 'left', 'left', 'left'] )
# offset
cmds.rowLayout( numberOfColumns = 2, ad2 = 2 )
self.c22 = cmds.checkBox( label = 'Auto Radius', v = True, cc = self.prefGet, ann = 'Auto calculate radius.' )
self.sl1 = cmds.floatSliderGrp( label = '', en = False, cc = self.prefGet, cw3 = [0, 40, 30], cl3 = ['left', 'left', 'left'], field = True, minValue = 0.5, maxValue = 100.0, fieldMinValue = -0.0, fieldMaxValue = 1000.0, value = 20 )
cmds.setParent( '..' )
self.s5 = cmds.separator( height = self.sepH, style = self.sepStl )
# update constraint offset
self.actionButton15 = cmds.button( self.actionButton15, label = 'Constraint Offset Update', c = self.cmdAction, bgc = self.blue )
self.s2 = cmds.separator( height = self.sepH, style = self.sepStl )
# place loc, constain
self.actionButton2 = cmds.button( self.actionButton2, label = 'Place HELPER', c = self.cmdAction, bgc = self.blue )
self.c5 = cmds.checkBox( label = 'Constrain to:', v = True, cc = self.prefGet, ann = 'Use constraint option.' )
self.conGrp = cmds.radioButtonGrp( label = '', cc = self.prefGet, labelArray2 = ['selection', 'reverse'], select = 1, numberOfRadioButtons = 2, w = self.w, ad3 = 3, cw3 = [0, 70, 35], cl3 = ['both', 'left', 'left'], ct3 = ['left', 'left', 'left'] )
self.c13 = cmds.checkBox( label = 'Match Keys', v = True, cc = self.prefGet, ann = 'Will add keys on the same frames as source object.' )
# constrain
self.actionButton5 = cmds.button( self.actionButton5, label = 'Parent Constraint', c = self.cmdAction, bgc = self.blue )
self.c9 = cmds.checkBox( label = 'Offset', cc = self.prefGet, v = True )
self.c10 = cmds.checkBox( label = 'Translation', cc = self.prefGet, v = True )
self.c11 = cmds.checkBox( label = 'Rotation', cc = self.prefGet, v = True )