-
Notifications
You must be signed in to change notification settings - Fork 1
/
mighty_world_head_switcher.mel
96 lines (67 loc) · 3.79 KB
/
mighty_world_head_switcher.mel
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
/*
// Mighty world head switcher
// mighty_world_head_switcher.mel
// by Olivier Ladeuix
//
// This script is to switch a control from local orient to world orient
// through baking. This script was tested successfully on Rosie's head.
/////////// Requirements //////////////////////
// 1. You need to have the full frame range visible
// 2. Select the control you want to mighty switch first. Only one at a time
////////////////////////////////
CHANGELOG:
2021 06 22 v1.0
2021 06 23 v1.1 Now a procedure rather than a simple script
2021 07 28 v1.2 Changed the name of the script from mighty_World_switcher to mighty_world_head_switcher
////////////// How to use /////////////////////////
Place the script in your scripts folder
Do a rehash or restart Maya for Maya to load the script
Select the object you want to switch to from local to world
Trigger the script from the shelf or command line with:
source "mighty_world_head_switcher"; mighty_world_head_switcher();
You could also use it as a Hotkey
////////////////////////////////////////////////////
*/
rehash;
global proc mighty_world_head_switcher() {
// Make a variable from the selection
string $mighty_world_head_switch_selection[] = `ls -sl`;
print ("Object selected is : " + $mighty_world_head_switch_selection[0]);
// Get the frame range and go to the start of the range
float $minTime = `playbackOptions -q -minTime`;
float $maxTime = `playbackOptions -q -maxTime`;
string $bakeRange = $minTime + ":" + $maxTime;
currentTime $minTime ;
// We could use this in the future to generate a shorter name
// referenceQuery -namespace `ls -sl`;
// Creation of the locator
spaceLocator -name mighty_world_head_switch_TEMP_locator ;
setAttr "mighty_world_head_switch_TEMP_locator.scaleX" 20 ;
setAttr "mighty_world_head_switch_TEMP_locator.scaleY" 20 ;
setAttr "mighty_world_head_switch_TEMP_locator.scaleZ" 20 ;
// Constraint the locator to the object selection for locator baking
parentConstraint -name mighty_constraint_TEMP_parentConstraint $mighty_world_head_switch_selection[0] mighty_world_head_switch_TEMP_locator ;
// Bake the locator and delete the constraint
print "\n////////// Baking Locator to Driver //////////";
bakeResults -simulation true -t ($bakeRange) -sampleBy 1 -oversamplingRate 1 -disableImplicitControl
true -preserveOutsideKeys true -sparseAnimCurveBake false -removeBakedAttributeFromLayer false -removeBakedAnimFromLayer
false -bakeOnOverrideLayer false -minimizeRotation true -controlPoints false -shape true;
print "\n////////// Locator baked to Driver //////////";
delete mighty_constraint_TEMP_parentConstraint;
// Constraint the object to the locator for object baking
parentConstraint -name mighty_constraint_TEMP_parentConstraint_B mighty_world_head_switch_TEMP_locator $mighty_world_head_switch_selection[0];
select $mighty_world_head_switch_selection[0];
// Switch the global attribute to Global (World orient)
cutKey -t ":" -f ":" -at "Global" $mighty_world_head_switch_selection[0];
setAttr ($mighty_world_head_switch_selection[0] + ".Global") 10 ;
setKeyframe ($mighty_world_head_switch_selection[0] + ".Global");
// setKeyframe -breakdown 0 -preserveCurveShape 0 -hierarchy none -at "blendParent1" Rosie:FKHead_M_CTRL;
print "\n////////// Baking driver to locator //////////";
bakeResults -simulation true -t ($bakeRange) -sampleBy 1 -oversamplingRate 1 -disableImplicitControl true -preserveOutsideKeys
true -sparseAnimCurveBake false -removeBakedAttributeFromLayer false -removeBakedAnimFromLayer false -bakeOnOverrideLayer false
-minimizeRotation true -controlPoints false -shape true ;
print "\n////////// Driver baked to locator //////////";
delete mighty_constraint_TEMP_parentConstraint_B;
delete mighty_world_head_switch_TEMP_locator ;
print "\n////////// Mighty World switch completed //////////\n";
};