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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
|
// Shave and a Haircut
// (c) 2019 Epic Games
// US Patent 6720962
global string $shaveBrush_fileVersion = "$Revision$";
//
// Initialize brush handling.
//
global proc shaveBrush()
{
source shaveCursorCtxCommonProperties;
source shaveCursorCtxCommonValues;
//
// Create any properties which don't yet exist.
//
if (!`optionVar -exists shaveBrushSelectMode`)
optionVar -stringValue shaveBrushSelectMode "guide";
if (!`optionVar -exists shaveBrushMode`)
optionVar -intValue shaveBrushMode 0;
//
// Have the 'Other' component popup menu display hair components as
// well.
//
popupMenu -e -pmc shaveBrush_createComponentMenu compOtherPopup;
//
// Whenever the selection mode changes, convert selections.
//
global int $gShave_selectModeChangedJob;
$gShave_selectModeChangedJob = `scriptJob -e SelectModeChanged
"shaveUtil -convertComponentSelections"`;
}
global proc shaveBrush_cleanup()
{
if (`popupMenu -exists compOtherPopup`)
popupMenu -e -pmc "createMaskPopup \"compOther\"" compOtherPopup;
//
// Kill off the scriptJob we started up earlier.
//
global int $gShave_selectModeChangedJob;
shave_killJob($gShave_selectModeChangedJob);
$gShave_selectModeChangedJob = -1;
}
global proc shaveBrush_convertComponentSelections(int $forceToComponentMode)
{
//
// If we're not in component mode, and we're not forcing component
// mode, then there's nothing to do.
//
int $isComponentMode = `selectMode -q -co`;
if (!$forceToComponentMode && !$isComponentMode) return;
//
// Convert any existing selections to the current selection type. For
// example, if a guide has a vert selected and we're in guide selection
// mode, then select the guide.
//
int $foundComponents = false;
string $hairNode = "";
string $item;
string $mode = `optionVar -q shaveBrushSelectMode`;
string $newSel = "";
int $nodeIsHilited = false;
string $sel[] = `ls -sl`;
int $selectionChanged = false;
string $tmp[];
//
// If we're in component mode, give priority to the first hair node on
// the hilite list.
//
if ($isComponentMode)
{
$sel = `ls -hilite -dag -type shaveHair`;
if (size($sel) > 0) $hairNode = $sel[0];
}
$sel = `ls -sl`;
for ($item in $sel)
{
//
// We only care about the first hair node on the selection list
// (plus any components which might appear for that same node later
// in the list).
//
$tmp = `ls -o $item`;
$tmp = `ls -dag -s $tmp[0]`;
if (nodeType($tmp[0]) == "shaveHair")
{
if ($hairNode == "") $hairNode = $tmp[0];
if ($tmp[0] == $hairNode)
{
//
// Get the name of the component, if there is one.
//
tokenize $item "." $tmp;
if (size($tmp) == 2)
{
tokenize $tmp[1] "[]" $tmp;
if (($tmp[0] == "e")
|| ($tmp[0] == "gd")
|| ($tmp[0] == "guide"))
{
string $guideRange = $tmp[1];
switch ($mode)
{
case "guide":
case "root":
$newSel += " " + $item;
break;
case "tip":
$newSel += " " + $hairNode
+ ".cv[" + $guideRange + "][14]";
$selectionChanged = true;
break;
case "vert":
$newSel += " " + $hairNode
+ ".cv["+$guideRange+"][0:14]";
$selectionChanged = true;
break;
}
$foundComponents = true;
}
else if (($tmp[0] == "cv")
|| ($tmp[0] == "vtx")
|| ($tmp[0] == "vertex"))
{
string $guideRange = $tmp[1];
string $vtxRange = $tmp[2];
switch ($mode)
{
case "guide":
case "root":
$newSel += " " + $hairNode
+ ".e[" + $guideRange + "]";
$selectionChanged = true;
break;
case "tip":
$newSel += " " + $hairNode
+ ".cv[" + $guideRange + "][14]";
if ($vtxRange != "14")
{
$selectionChanged = true;
}
break;
case "vert":
$newSel += " " + $item;
break;
}
$foundComponents = true;
}
else
$selectionChanged = true;
}
else
$selectionChanged = true;
}
else
$selectionChanged = true;
}
}
//
// If we didn't find a hair node (or components thereof) on the
// selection list, then check the hilite list.
//
// If we did find a hair node, then see if it is already hilited.
//
$sel = `ls -hilite -dag -type shaveHair`;
if ($hairNode == "")
{
if (size($sel) > 0) $hairNode = $sel[0];
}
else
{
for ($item in $sel)
{
if ($item == $hairNode)
{
$nodeIsHilited = true;
break;
}
}
}
//
// If no hair node was selected then do nothing.
//
if ($hairNode == "") return;
//
// If we didn't end up with any hair components then select all of
// the hair node's components for the current component type.
//
if (!$foundComponents)
{
int $numGuides = getAttr($hairNode + ".totalGuides");
if ($numGuides > 0)
{
switch ($mode)
{
case "guide":
case "root":
$newSel = $hairNode + ".e[0:" + ($numGuides-1) + "]";
break;
case "tip":
$newSel = $hairNode + ".cv[0:" + ($numGuides-1) + "][14]";
break;
case "vert":
$newSel = $hairNode + ".cv[0:" + ($numGuides-1) + "][0:14]";
break;
}
$foundComponents = true;
$selectionChanged = true;
}
}
//
// At this point we have a hairNode and will definitely end up with
// some components selected, so it is now safe to force component mode,
// if we're not already there.
//
if (!$isComponentMode) selectMode -co;
//
// If the node is not already hilited, then do so now.
//
if (!$nodeIsHilited) hilite $hairNode;
//
// And finally, if we've changed the selections, then apply them now.
//
if ($selectionChanged && ($newSel != ""))
eval("select -r " + $newSel);
}
global proc shaveBrush_createComponentMenu()
{
string $selMode = `optionVar -q shaveBrushSelectMode`;
createMaskPopup "compOther";
setParent -m compOtherPopup;
menuItem -l "Shave Guides" -cb ($selMode == "guide")
-c "shaveSelectGuides" shaveGuideCompItem;
menuItem -l "Shave Roots" -cb ($selMode == "root")
-c "shaveSelectByRoots" shaveRootCompItem;
menuItem -l "Shave Tips" -cb ($selMode == "tip")
-c "shaveSelectByTips" shaveTipCompItem;
menuItem -l "Shave Verts" -cb ($selMode == "vert")
-c "shaveSelectVerts" shaveVertCompItem;
}
global proc shaveBrush_resize(int $enable)
{
string $ctx = `currentCtx`;
if (`contextInfo -class $ctx` == "shaveBrush")
shaveBrushCtx -e -interactiveResize $enable $ctx;
else if (`contextInfo -class $ctx` == "shaveCut")
shaveCutCtx -e -interactiveResize $enable $ctx;
}
global proc shaveBrush_setHotkeys(int $enable)
{
global string $gShaveBrushResizeOldKeyPressCmd;
global string $gShaveBrushResizeOldKeyReleaseCmd;
global string $gShaveBrush_origHotkeySet = "";
string $curHotkeySet = `hotkeySet -q -current`;
if ($enable)
{
// We should never get nested enables.
//
if ($curHotkeySet == "Shave_Hotkeys")
{
warning("Shave: Nested hotkey settings detected. Please contact [email protected]");
return;
}
$gShaveBrush_origHotkeySet = $curHotkeySet;
if (!`hotkeySet -q -exists Shave_Hotkeys`)
{
hotkeySet -current Shave_Hotkeys;
// Create named commands for resizing the brush and assign them to
// the key.
//
nameCommand -ann "Shave brush resize begin"
-c "shaveBrush_resize on" shaveBrushResizeBegin;
nameCommand -ann "Shave brush resize end"
-c "shaveBrush_resize off" shaveBrushResizeEnd;
hotkey -k b -n shaveBrushResizeBegin -rn shaveBrushResizeEnd;
}
else
{
hotkeySet -e -current Shave_Hotkeys;
}
}
else
{
// No one should have the Shave hotkey set as their default. That's
// probably due to Maya crashing while our brush was active. Use
// Maya's default hotkey set as the original instead.
//
if ($gShaveBrush_origHotkeySet == "Shave_Hotkeys")
{
hotkeySet -e -current "Maya_Default";
}
// Only reset the hotkey set if the current one is ours.
//
else if ($curHotkeySet == "Shave_Hotkeys")
{
// If we never recorded an original set, use Maya's
// default.
//
if ($gShaveBrush_origHotkeySet == "")
{
hotkeySet -e -current "Maya_Default";
}
else
{
hotkeySet -e -current $gShaveBrush_origHotkeySet;
}
}
$gShaveBrush_origHotkeySet = "";
}
}
global proc shaveBrush_setSelectMode(string $mode)
{
optionVar -sv shaveBrushSelectMode $mode;
if (`menuItem -q -exists shaveGuideCompItem`)
{
menuItem -e -cb ($mode == "guide") shaveGuideCompItem;
menuItem -e -cb ($mode == "root") shaveRootCompItem;
menuItem -e -cb ($mode == "tip") shaveTipCompItem;
menuItem -e -cb ($mode == "vert") shaveVertCompItem;
}
shaveShelf_updateSelectModeButtons($mode);
// Alas, Maya does not yet let us create own component types, so we
// must piggyback on top of those which already exist. That means that
// we must make sure that if the user sets one of our selection types,
// we select the corresponding Maya component type.
//
// Note that in 'root' mode we using vertices to make the selection, but it
// is guides which are being selected. Only in 'tip' and 'vert' modes do we
// actually select vertices.
//
if (($mode == "vert") || ($mode == "tip"))
{
selectType -cv on;
selectType -polymeshEdge off;
// For some reason VP2 won't let us do single-selection on our
// CVs unless the poly vert selection type is on.
//
selectType -polymeshVertex on;
}
else
{
selectType -polymeshEdge on;
selectType -cv off;
}
// If we're not currently in component selection mode, switch to it.
// Note that that will automatically force component selections to be
// updated.
//
if (!`selectMode -q -co`)
selectMode -co;
else
{
// Update component selection to match the new select mode.
//
shaveUtil -convertComponentSelections;
}
refresh -f;
}
|