Professional Documents
Culture Documents
// Global Variables
global string $tmGroups[], $tmSets[], $tmButtonRGB[], $tmSelConArray;
global int $tmNumButtons, $tmSliderWidth, $tmShowButtons, $tmShowSliders,
$tmButtonRowPad, $mayaVers, $tmSpecTick;
global float $tmButtonVal[];
clear $tmGroups;
clear $tmSets;
$tmSliderWidth = 200;
$mayaVers = (int) startString(`about -v`,1);
$tmSpecTick = 0;
// Make Window
window -w 300 -h 5 -mnb 1 -mxb 0 -menuBar 1 -mbv 1 -rtf 1 -s 1 -t
"tweenMachine - 2.03" -in "tweenMachine" tweenMachineWin;
tmBuildAllGroups;
showWindow tweenMachineWin ;
}
// --------------------------------------------------------------------------
string $c = "Yes";
if (size($tmGroups) > 0) $c = `confirmDialog -t "Start over?" -m "Erase all
tweenMachine data?" -b "Yes" -b "No" -db "Yes" -cb "No" -ds "No"`;
if ($c != "No") {
delete tmXML1;
tweenMachine;
}
}
// --------------------------------------------------------------------------
// If data exists in scene, pull the options and interface data from it
// if not, build XML data using default values
setParent tweenMachineWin;
}
// --------------------------------------------------------------------------
clear $tmGroups;
clear $tmSets;
$tmNumButtons = 7;
$tmShowButtons = 1;
$tmShowSliders = 1;
clear $tmButtonVal;
$tmButtonVal[0] = -75;
$tmButtonVal[1] = -60;
$tmButtonVal[2] = -33;
$tmButtonVal[3] = 0;
$tmButtonVal[4] = 33;
$tmButtonVal[5] = 60;
$tmButtonVal[6] = 75;
int $i;
for ($i=0; $i<$tmNumButtons; $i++) $tmButtonRGB[$i] = "0.6 0.6 0.6";
// --------------------------------------------------------------------------
makeNode ("tmXML",1);
makeNode ("tmOptions",0);
makeNode ("tmSliderVis",0);
addContent ("1");
closeTag;
makeNode ("tmButtonVis",0);
addContent ("1");
closeTag;
makeNode ("tmButtons id=\"7\"",0);
for ($i=0; $i<$tmNumButtons; $i++) {
makeNode ("tmButton",0);
makeNode ("tmButtonRGB",0);
addContent ($tmButtonRGB[$i]);
closeTag;
makeNode ("tmButtonValue",0);
addContent ($tmButtonVal[$i]);
closeTag;
closeTag;
}
closeTag;
closeTag;
makeNode ("tmGroups",0);
closeTag;
closeTag;
select -cl;
}
// ************************************************************************
// ************************************************************************
// Ticks and Toggles
// ************************************************************************
// ************************************************************************
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
if ($objName == "tmMainSelectedSet") {
// swap selectionConnection
int $selChk = `checkBox -q -v tmMainSelectedSetTicks`;
if (!$selChk) {
timeControl -e -mlc tmMasterSC timeControl1;
} else {
timeControl -e -mlc animationList timeControl1;
}
}
}
}
// ************************************************************************
// ************************************************************************
// Manage sets and groups
// ************************************************************************
// ************************************************************************
formLayout -e
tmSGMFormLayout;
showWindow tmSGMWin;
tmSGMRebuildList;
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
clear $sgmArray;
if (!$mode) {
string $group = `optionMenu -q -v tmSGMGroups`;
$sgmArray = tmSetsInGroup($group,0);
} else {
$sgmArray = $tmGroups;
}
// ------------------------------------------------------------------------
if ($result == "OK") {
string $newName = `promptDialog -q -text`;
if (`isValidObjectName($newName)`) {
if (!$mode) {
$group = `optionMenu -q -v tmSGMGroups`;
string $oldNameLong = "tm" + $group + $oldName + "Set";
string $newNameLong = "tm" + $group + $newName + "Set";
if (`objExists $newNameLong`) {
confirmDialog -t "Set exists" -m "A set by that name
already exists. Please choose a new name.";
return;
}
tmSGMRebuildList;
} else {
for ($grp in $tmGroups) {
if ($grp == $newName) {
confirmDialog -t "Group exists" -m "A group by
that name already exists. Please choose a new name.";
return;
}
}
$group = $oldName;
string $oldPrefix = "tm" + $group;
string $newPrefix = "tm" + $newName;
// rename columnLayout
renameUI ($oldPrefix + "GroupCL") ($newPrefix + "GroupCL");
// rename group SC
renameUI ($oldPrefix + "GroupSC") ($newPrefix + "GroupSC");
tmSGMRebuildList;
}
} else {
confirmDialog -t "Invalid name" -m "The name entered is not
valid.\nSet and group names must be valid Maya object names.";
}
}
}
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
string $modeName[];
$modeName[0] = " set?";
$modeName[1] = " group?";
if ($c == "Yes") {
if (!$mode) {
// query group from UI
string $group = `optionMenu -q -v tmSGMGroups`;
// remove set
delete $setName;
tmSGMRebuildList;
} else {
// remove group from $tmGroups array
$tmGroups = stringArrayRemove ({$item},$tmGroups);
tmSGMRebuildList;
}
}
}
// ************************************************************************
// ************************************************************************
// Build sets and groups
// ************************************************************************
// ************************************************************************
$tmGroups[$order] = $groupName;
string $grpPrefix = "tm" + $groupName;
string $checkCommand = "tmTickToggle(\"" + $groupName + "\", \"Main\")";
setParent tmMainGroupCL;
setParent tweenMachineWin;
print ("done.\n");
// ------------------------------------------------------------------------
$setLabel = $setName;
tmBuildButtonRow ($setName);
setParent $groupCLName;
// ------------------------------------------------------------------------
int $i;
for ($i=1; $i<=$tmNumButtons; $i++)
$rowBuilder += " -cw " + ($i + 1) + " " + ($buttonWidth + 5);
$rowBuilder += " " + $rowLayoutName + ";";
eval $rowBuilder;
}
}
// ************************************************************************
// ************************************************************************
// Add Sets and Groups
// ************************************************************************
// ************************************************************************
formLayout -e
-af tmAddGrpLabel "top" 5
-af tmAddGrpLabel "left" 5
-af tmAddGrpLabel "right" 5
tmAddGrpFL;
showWindow tmGroupUIWin;
// ------------------------------------------------------------------------
if (`isValidObjectName($newGroup)`) {
if (`frameLayout -ex ("tm" + $newGroup + "Group")`) {
confirmDialog -t "Group exists" -m "A group by that name already
exists. Please choose a new name.";
} else {
$currParent = "tmGroups1";
int $order = size($tmGroups);
string $nodeString = "tmGroup id=\"" + $newGroup + "\" order=\""
+ $order + "\"";
makeNode ($nodeString,0);
select -cl;
}
} else {
confirmDialog -t "Invalid name" -m "The name entered is not
valid.\nGroup names must be valid Maya object names.";
}
// ------------------------------------------------------------------------
formLayout -e
tmSetUIFL;
showWindow tmSetUIWin;
// ------------------------------------------------------------------------
if (!size($nodes)) {
confirmDialog -t "Nothing Selected" -m "You must select one or more
objects to make a new set.";
return;
}
if (`isValidObjectName($newSet)`) {
string $set;
for ($set in tmSetsInGroup($groupName,0)) {
if ($newSet == $set) {
confirmDialog -t "Set exists in selected group" -m "A set
by that name already exists in the selected group.\nPlease choose a new set name,
or pick a different group.";
return;
}
}
string $groups[];
$groups = getByType("tmGroups1","tmGroup");
string $sets[];
$sets = getByType($currParent,"tmSet");
int $order = size($sets);
select -r $nodes;
}
// ************************************************************************
// ************************************************************************
// Character set utilities
// ************************************************************************
// ************************************************************************
// add group
$currParent = "tmGroups1";
int $order = size($tmGroups);
string $nodeString = "tmGroup id=\"CharacterSet\" order=\"" + $order + "\"";
makeNode ($nodeString,0);
makeNode ("tmObject",0);
addContent ("tmCustomCharacterSet");
closeTag;
$charSet = $curChar;
// if name has namespace, replace colon with underscore
if (`match ".*:.*" $curChar` != "") $curChar = `substitute ":" $curChar "_"`;
tmAddGroup ($char);
tmAddSet ({$charSet}, $char, $char);
select -cl;
$subChars = `character -q $charSet`;
}
}
}
// ************************************************************************
// ************************************************************************
// Read from XML data in scene
// ************************************************************************
// ************************************************************************
clear $tmGroups;
clear $tmSets;
clear $tmButtonVal;
clear $tmButtonRGB;
$tmSets[0] = "tmMainSelectedSet";
int $i;
for ($i=0; $i<$tmNumButtons; $i++) {
string $buttonVal = "tmButtonValue" + ($i+1);
$tmButtonVal[$i] = `getData ($buttonVal)`;
string $buttonRGB = "tmButtonRGB" + ($i+1);
$tmButtonRGB[$i] = `getData ($buttonRGB)`;
}
// read groups
string $groups[];
$groups = getByType ("tmGroups1","tmGroup");
string $tmpSet[];
clear $tmpSet;
string $obj[];
clear $obj;
int $makeSet = 1;
for ($o in $objects) {
string $objTmp = `getAttr ($o + ".data")`;
if (`objExists $objTmp`)
$obj[size($obj)] = $objTmp;
else if ($objTmp == "tmCustomCharacterSet")
$makeSet = 0;
else print ("Omitting \"" + $objTmp + "\" from set \"" +
$setName + "\". Object does not exist in scene.\n");
// ************************************************************************
// ************************************************************************
// Save and Load XML Data
// ************************************************************************
// ************************************************************************
global proc int tmSaveToFile (string $file, string $fileType) {
$fileType = ".xml";
int $chkAgain = 1;
if ($c != "No") {
int $i = 0;
for ($i=0; $i<$tmNumButtons; $i++) {
fprint $fileId " <tmButton>\n";
fprint $fileId (" <tmButtonRGB>" + $tmButtonRGB[$i] +
"</tmButtonRGB>\n");
fprint $fileId (" <tmButtonValue>" + $tmButtonVal[$i]
+ "</tmButtonValue>\n");
fprint $fileId " </tmButton>\n";
}
string $groups[];
$groups = getByType ("tmGroups1","tmGroup");
string $sets[];
$sets = getByType ($grp,"tmSet");
string $tmObjects[];
$tmObjects = getByType ($set,"tmObject");
} else {
fileBrowser tmSaveToFile "Save" "" 1;
return 0;
}
// --------------------------------------------------------------------------
string $c;
// if a set exists, confirm that user wants to load new data
if (size($tmSets) > 1) $c = `confirmDialog -t "Replace data?" -m "Replace
current data with data from file?" -b "Yes" -b "No" -db "Yes" -cb "No" -ds "No"`;
if ($c != "No") {
// ************************************************************************
// ************************************************************************
// Starters and main TM procedure
// ************************************************************************
// ************************************************************************
if (startsWith($name,"tmCharacterSet"))
$nodes = `currentCharacters`;
else if ($biasCtl == "tmMainSelectedSetBias")
$nodes = `ls -sl`;
else
$nodes = `sets -q $name`;
tween_Machine ($poseBias,$nodes);
// --------------------------------------------------------------------------
string $nodes[];
tween_Machine ($poseBias,$nodes);
// --------------------------------------------------------------------------
clear $curves;
clear $newCurves;
if (size($attrs) > 0) {
waitCursor -state on ;
// Set new in and out tangent types based on previous and next tangent
types
string $tanInC = $tanOutPs[0];
string $tanOutC = $tanInNs[0];
if ($tanInC != "step")
keyTangent -t $timeC -itt $tanInC $crv;
currentTime -e $timeC;
setFocus $pf;
// ************************************************************************
// ************************************************************************
// Misc. helper procedures
// ************************************************************************
// ************************************************************************
if ($type < 2) {
for ($set in $tmSets) {
string $setSW = "tm" + $group;
if (startsWith ($set, $setSW)) {
if ($type == 0) {
$set = `substitute $setSW $set ""`;
$set = `substitute "Set" $set ""`;
}
$setsInGroup[size($setsInGroup)] = $set;
}
}
} else {
for ($grp in getByType("tmGroups1","tmGroup")) {
if (`getAttr ($grp + ".id")` == $group) $setsInGroup =
getByType($grp,"tmSet");
}
}
return $setsInGroup;
}
// --------------------------------------------------------------------------
global proc string tmFindInXML (string $type, string $parent, string $att, string
$val) {
// find set or group in XML data with parent $parent where attribute $att =
value $val
// $type = 0 (set) or 1 (group)
string $foundObj;
string $obj;
for($obj in getByType($parent,$type)) {
string $v = `getAttr ($obj + $att)`;
if ($v == $val) $foundObj = $obj;
}
return $foundObj;
}
// --------------------------------------------------------------------------