aboutsummaryrefslogtreecommitdiff
path: root/scripts/shaveShelf.mel
blob: 66d1048bb2f2a04d6305999d20f94a6e9dcdd35e (plain) (blame)
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
// Shave and a Haircut
// (c) 2019 Epic Games
// US Patent 6720962

global string $shaveShelf_fileVersion = "$Revision$";

global int $gShaveShelf_version = 7;


proc string[] getSelectModeButtonInfo(string $button)
{
	string	$result[];
	string	$label = `shelfButton -q -label $button`;

	switch ($label)
	{
		case "Guides":
			$result[0] = "guide";
			$result[1] = "shaveSQSelectStrand.xpm";
			$result[2] = "shaveSelectStrand.xpm";
		break;

		case "Verts":
			$result[0] = "vert";
			$result[1] = "shaveSQSelectVert.xpm";
			$result[2] = "shaveSelectVert.xpm";
		break;

		case "Tips":
			$result[0] = "tip";
			$result[1] = "shaveSQSelectTip.xpm";
			$result[2] = "shaveSelectTip.xpm";
		break;

		case "Roots":
			$result[0] = "root";
			$result[1] = "shaveSQSelectRoot.xpm";
			$result[2] = "shaveSelectRoot.xpm";
		break;
	}

	return $result;
}


global proc shaveShelf()
{
	//
	// If Maya's shelf layout doesn't exist, then there's nothing for us to
	// do.
	//
	global string	$gShelfTopLevel;

	if (($gShelfTopLevel == "") || !`shelfTabLayout -exists $gShelfTopLevel`)
		return;

	//
	// Has this user ever had the Shave shelf before?
	//
	global int	$gShaveShelf_version;
	int			$oldVersion = 0;

	if (`optionVar -exists shaveShelf_version`)
		$oldVersion = `optionVar -q shaveShelf_version`;

	optionVar -iv shaveShelf_version $gShaveShelf_version;

	//
	// %%%	Right now we just blow away the shelf and recreate it if its
	//		version is out of date.  Before we release this should be
	//		changed to do a more thoughtful upgrade of the existing shelf.
	//
	if ($oldVersion != $gShaveShelf_version) shaveShelf_create;
}


global proc shaveShelf_create()
{
	//
	// If Maya's shelf layout doesn't exist, then there's nothing for us to
	// do.
	//
	global string	$gShelfTopLevel;

	if (($gShelfTopLevel == "") || !`shelfTabLayout -exists $gShelfTopLevel`)
		return;

	//
	// Does the Shave shelf already exist?
	//
	int	$shelfNum;
	int	$numShelves = `optionVar -q numShelves`;

	for ($shelfNum = 1; $shelfNum <= $numShelves; $shelfNum++)
	{
		string	$name = `optionVar -q ("shelfName" + $shelfNum)`;

		if ($name == "Shave")
		{
			//
			// If the shelf bar is not being displayed, then it's possible
			// that while the optionVar for our shelf exists, the shelf
			// itself has not yet been created.  In that case we'll
			// silently return without doing anything: the fact that the
			// optionVar exists means that Maya will almost certainly
			// create the shelf for us the next time the shelf bar is
			// displayed.
			//
			if (!`shelfLayout -exists Shave`) return;

			break;
		}
	}

	//
	// If the shelf already exists, clear it, otherwise create it.
	//
	if ($shelfNum <= $numShelves)
	{
		string	$children[] = `shelfLayout -q -ca Shave`;
		string	$child;

		for ($child in $children) deleteUI $child;
	}
	else
	{
		optionVar -iv numShelves $shelfNum;
		optionVar -sv ("shelfName" + $shelfNum) "Shave";
		optionVar -sv ("shelfFile" + $shelfNum) "shelf_Shave";
		optionVar -iv ("shelfLoad" + $shelfNum) true;

		setParent $gShelfTopLevel;

		shelfLayout Shave;
	}

	//
	// Populate the shelf.
	//
	// We create a named command for each shelf button.  If we don't do
	// that then when the user saves out the shelf (or Maya does it for
	// them) the underlying command will be saved out as well, making it
	// difficult for us to later changed the command.  With named commands
	// only the named command will be saved out and we can still change the
	// underlying command that it represents.
	//
	setParent Shave;

	//	Component selection types.
	shelfButton
		-label "Guides"
		-image "shaveSelectStrand.xpm"
		-command shaveSelectGuides;

	shelfButton
		-label "Verts"
		-image "shaveSelectVert.xpm"
		-command shaveSelectVerts;

	shelfButton
		-label "Roots"
		-image "shaveSelectRoot.xpm"
		-command shaveSelectByRoots;

	shelfButton
		-label "Tips"
		-image "shaveSelectTip.xpm"
		-command shaveSelectByTips;

	shelfButton
		-annotation "Shave: Separator"
		-enable false;

	// Selection utilities
	shelfButton
		-label "Grow Selection"
		-image "shaveSelectGrow.xpm"
		-command shaveSelectGrow;

	shelfButton
		-label "Invert Selection"
		-image "shaveSelectInverse.xpm"
		-command shaveSelectInverse;

	shelfButton
		-label "Rotate Selection Up"
		-image "shaveSelectRotateUp.xpm"
		-command shaveSelectRotateUp;

	shelfButton
		-label "Select Hide"
		-image "shaveSelectHide.xpm"
		-command shaveSelectHide;

	shelfButton
		-label "Select Unhide"
		-image "shaveSelectUnHide.xpm"
		-command shaveSelectUnhide;

	shelfButton
		-annotation "separator"
		-enable false;

	//	Tools
	shelfButton
		-label "Brush"
		-image1 "shaveBrush.xpm"
		-command shaveBrushTool
		-doubleClickCommand shaveBrushToolOptions;

	shelfButton
		-label "Cut"
		-image1 "shaveCut.xpm"
		-command shaveCutTool
		-doubleClickCommand shaveCutTool;

	shelfButton
		-annotation "separator"
		-enable false;

	//	Utilities
	shelfButton
		-label "Attenuate"
		-image1 "shaveAttenuate.xpm"
		-command shaveAttenuate;

	shelfButton
		-label "Pop Selected"
		-image1 "shavePopSelect.xpm"
		-command shavePopSelected;

	shelfButton
		-label "Pop Zero-Sized"
		-image1 "shavePopZeroSized.xpm"
		-command shavePopZeroSized;

	shelfButton
		-label "Recomb"
		-image1 "shaveRecomb.xpm"
		-command shaveRecomb;

	shelfButton
		-label "Replace Rest"
		-image1 "shaveReplaceRest.xpm"
		-command shaveReplaceRest;

	shelfButton
		-label "Toggle Collision"
		-image1 "shaveToggleCollision.xpm"
		-command shaveTglCollision;

	shelfButton
		-label "Toggle Hairs"
		-image1 "shaveToggleHairs.xpm"
		-command shaveTglHairs;

	shelfButton
		-label "Toggle Preview"
		-image1 "shaveToggleFallback.xpm"
		-command shaveTglFallback;

	shelfButton
		-label "Lock"
		-image1 "shaveLock.xpm"
		-command shaveLockHair;

	shelfButton
		-label "Unlock"
		-image1 "shaveUnlock.xpm"
		-command shaveUnlockHair;

	shelfButton
		-label "Undo Style"
		-image1 "shaveUndo.xpm"
		-command shaveUndo;

	// Additional selection utilities
	shelfButton
		-annotation "separator"
		-enable false;

	shelfButton
		-label "Split Selection"
		-image "shaveSplit.xpm"
		-command shaveSplitSelection;

	shelfButton
		-label "Merge Selection"
		-image "shaveMerge.xpm"
		-command shaveMergeSelection;
		
	shelfButton
		-annotation "separator"
		-enable false;
		
	shelfButton
		-label "Update Textures"
		-image "textureRefresh.xpm"
		-command shaveUpdateTexturesN;

	//
	// To avoid duplicating annotation strings and possibly getting out of
	// synch, set each button's annotation string to be the same as its
	// runTimeCommand.
	//
	string	$buttons[] = `shelfLayout -q -ca Shave`;
	string	$button;

	for ($button in $buttons)
	{
		string	$cmd = `shelfButton -q -command $button`;

		if (($cmd != "") && `runTimeCommand -exists $cmd`)
		{
			string	$ann = `runTimeCommand -q -ann $cmd`;
			shelfButton -e -annotation $ann $button;
		}
	}

	shelfStyle("nochange", "nochange", "Shave");

	shaveShelf_updateSelectModeButtons(`optionVar -q shaveBrushSelectMode`);
}


global proc shaveShelf_notImplemented(string $op)
{
	warning("The '" + $op + "' operation is not yet implemented.");
}


global proc shaveShelf_updateSelectModeButtons(string $mode)
{
	if (`shelfLayout -q -exists Shave`)
	{
		string	$buttons[] = `shelfLayout -q -ca Shave`;
		string	$button;

		for ($button in $buttons)
		{
			string	$buttonInfo[] = getSelectModeButtonInfo($button);

			if (size($buttonInfo) > 0)
			{
				if ($buttonInfo[0] == $mode)
					shelfButton -e -image $buttonInfo[1] $button;
				else
					shelfButton -e -image $buttonInfo[2] $button;
			}
		}
	}
}