/************************************************************************************************************
The Blue Pill
Created Winter 2009
Ryan K Osteen

This version of the script is ment to transform all of your motion capture data from the MotionBuilder to
Massive using Maya's MEL Scripting.

First you will want to import your .fbx data from MotionBuilder and run this script form your script editor.
A new window will appear. Scroll down and click Use Defaults. I have provided names for all of the joints,
if you want to change any of the them feel free the script will work with your changes. Afterwords all you
need to do is click Transform and your done. Export your file and your off to do some sewwt massive with
your motion.

Disclaimer: This script works with Maya versions 2008 Ext1, Ext2, 2009. The fbx information also comes from
otionBuilder 7.5 Ext 2. With a change in software the script might break.

Special Thanks: Kenneth Huff

*************************************************************************************************************/

 

global proc useDefaults ()
{
string $miaJoints[] = lookupMiaJointsArray();
int $i;
for ($i = 0; $i < size($miaJoints); $i+=2)
{
textFieldGrp -edit -text $miaJoints[$i + 1] ("BluePill_UI_Text_" + $i) ;
}
}

/**************************************************************************************************************
This is the MEGA ARRAY! So for future changes and updates to joint names this is where you will need to go to
change them. I have made it pretty easy to read. The imported name is on the left and the new name is on the right.
**************************************************************************************************************/
global proc string[] lookupMiaJointsArray ()
{
return {
"Mia:Hips", "root",
"Mia:Spine_Dummy", "lowerSpine",
"Mia:Spine", "spine",
"Mia:Spine1", "midSpine",
"Mia:Spine2", "upperSpine",
"Mia:Neck", "neck",
"Mia:Head", "head",
"Mia:HeadEnd", "headEnd",
"Mia:RightShoulder_Dummy", "lowerRightShoulder",
"Mia:RightShoulder", "rightShoulder",
"Mia:RightArm_Dummy", "upperRightArm",
"Mia:RightArm", "rightArm",
"Mia:RightArmRoll:", "rightArmRoll",
"Mia:RightForeArm", "rightElbow",
"Mia:RightForeArmRoll", "rightForeArm",
"Mia:RightHand", "rightHand",
"Mia:RightHandThumb1", "rightHandThumb1",
"Mia:RightHandThumb2", "rightHandThumb2",
"Mia:RightHandThumb3", "rightHandThumb3",
"Mia:RightThumb_End", "rightThumbEnd",
"Mia:RightHandMiddle1", "rightHandMiddle1",
"Mia:RightHandMiddle2", "rightHandMiddle2",
"Mia:RightHandMiddle3", "rightHandMiddle3",
"Mia:RightMiddle_End", "rightMiddleEnd",
"Mia:RightHandRing1", "rightHandRing1",
"Mia:RightHandRing2", "rightHandRing2",
"Mia:RightHandRing3", "rightHandRing3",
"Mia:RightRing_End", "rightRingEnd",
"Mia:RightHandIndex1", "rightHandIndex1",
"Mia:RightHandIndex2", "rightHandIndex2",
"Mia:RightHandIndex3", "rightHandIndex3",
"Mia:RightIndex_End", "rightIndexEnd",
"Mia:RightHandPinky1", "rightHandPinky1",
"Mia:RightHandPinky2", "rightHandPinky2",
"Mia:RightHandPinky3", "rightHandPinky3",
"Mia:RightPinky_End", "rightPinkyEnd",
"Mia:LeftShoulder_Dummy", "lowerLeftShoulder",
"Mia:LeftShoulder", "leftShoulder",
"Mia:LeftArm_Dummy", "upperLeftArm",
"Mia:LeftArm", "leftArm",
"Mia:LeftArmRoll", "leftArmRoll",
"Mia:LeftForeArm", "leftElbow",
"Mia:LeftForeArmRoll", "leftForeArm",
"Mia:LeftHand", "leftHand",
"Mia:LeftHandThumb1", "leftHandThumb1",
"Mia:LeftHandThumb2", "leftHandThumb2",
"Mia:LeftHandThumb3", "leftHandThumb3",
"Mia:LeftThumb_End", "leftThumbEnd",
"Mia:LeftHandMiddle1", "leftHandMiddle1",
"Mia:LeftHandMiddle2", "leftHandMiddle2",
"Mia:LeftHandMiddle3", "leftHandMiddle3",
"Mia:LeftMiddle_End", "leftMiddleEnd",
"Mia:LeftHandRing1", "leftHandRing1",
"Mia:LeftHandRing2", "leftHandRing2",
"Mia:LeftHandRing3", "leftHandRing3",
"Mia:LeftRing_End", "leftRingEnd",
"Mia:LeftHandIndex1", "leftHandIndex1",
"Mia:LeftHandIndex2", "leftHandIndex2",
"Mia:LeftHandIndex3", "leftHandIndex3",
"Mia:LeftIndex_End", "leftIndexEnd",
"Mia:LeftHandPinky1", "leftHandPinky1",
"Mia:LeftHandPinky2", "leftHandPinky2",
"Mia:LeftHandPinky3", "leftHandPinky3",
"Mia:LeftPinky_End", "leftPinkyEnd",
"Mia:LeftHips_Dummy", "leftHips",
"Mia:LeftUpLeg", "leftUpperLeg",
"Mia:LeftUpLegRoll", "leftThigh",
"Mia:LeftLeg", "leftKnee",
"Mia:LeftLegRoll", "leftShin",
"Mia:LeftFoot", "leftAnkle",
"Mia:LeftToeBase", "leftHeel",
"Mia:LeftToes_End", "leftToe",
"Mia:RightHips_Dummy", "rightHips",
"Mia:RightUpLeg", "rightUpperLeg",
"Mia:RightUpLegRoll", "rightThigh",
"Mia:RightLeg", "rightKnee",
"Mia:RightLegRoll", "rightShin",
"Mia:RightFoot", "rightAnkle",
"Mia:RightToeBase", "righHeel",
"Mia:RightToes_End", "rightToe"
};

}

 

global proc finalStage()

{
string $miaJoints[] = lookupMiaJointsArray();
string $jointsForOptionVar[] = $miaJoints;


string $MiaRenameJoints = "demo_arraysInOptionVariables_optionVar";


if(`optionVar -exists $MiaRenameJoints`)
{
// print("// The optionVar called " + $MiaRenameJoints + " exists.\n");
// print("// It contains:\n");
// print (`optionVar -query $MiaRenameJoints`);
}
else
{
string $item;
for ($item in $jointsForOptionVar)
optionVar -stringValueAppend $MiaRenameJoints $item;
}
// print("// It now contains:\n");
// print (`optionVar -query $MiaRenameJoints`); // the result from the optionVar -query is a string array

delete
"Mia_Ctrl:HipsEffector" "Mia_Ctrl:LeftAnkleEffector" "Mia_Ctrl:RightAnkleEffector"
"Mia_Ctrl:LeftWristEffector" "Mia_Ctrl:RightWristEffector" "Mia_Ctrl:LeftKneeEffector"
"Mia_Ctrl:RightKneeEffector" "Mia_Ctrl:LeftElbowEffector" "Mia_Ctrl:RightElbowEffector"
"Mia_Ctrl:ChestOriginEffector" "Mia_Ctrl:ChestEndEffector" "Mia_Ctrl:LeftFootEffector"
"Mia_Ctrl:RightFootEffector" "Mia_Ctrl:LeftShoulderEffector" "Mia_Ctrl:RightShoulderEffector"
"Mia_Ctrl:HeadEffector" "Mia_Ctrl:LeftHipEffector" "Mia_Ctrl:RightHipEffector"
"Mia_Ctrl:LeftHandThumbEffector" "Mia_Ctrl:LeftHandIndexEffector" "Mia_Ctrl:LeftHandMiddleEffector"
"Mia_Ctrl:LeftHandRingEffector" "Mia_Ctrl:LeftHandPinkyEffector" "Mia_Ctrl:RightHandThumbEffector"
"Mia_Ctrl:RightHandIndexEffector" "Mia_Ctrl:RightHandMiddleEffector" "Mia_Ctrl:RightHandRingEffector"
"Mia_Ctrl:RightHandPinkyEffector" ;

select -replace Mia_Ctrl:Hips ;
delete ;

select -replace Mia:Root Mia:Master Mia:Reference ;
ungroup ;

select -replace Mia:Root Mia_Ctrl:Reference Mia:Master Mia:Reference Mia:Mia_body Mia:Mia_head Mia:Mia_left_leg
Mia:Mia_right_leg ;
delete ;

/********************************************************************************************************************
This marker array is specific to Maya 2008 and Maya 2008 Ext. 2.
********************************************************************************************************************/

string $markerArray[] =
{
"C3D:red_LElbow", "C3D:red_LForeArm", "C3D:red_LHand_A", "C3D:red_LShoulder", "C3D:red_LUpperArm",
"C3D:red_LWrist", "C3D:red_LHand_B", "C3D:red_TopSpine", "C3D:red_LBack", "C3D:red_MidBack",
"C3D:red_RBack", "C3D:red_Sternum", "C3D:red_RPelvis", "C3D:red_LowerBack", "C3D:red_Root",
"C3D:red_LBackWaist", "C3D:red_LFrontWaist", "C3D:red_LThigh", "3D:red_LKnee", "C3D:red_LShin",
"C3D:red_LAnkle", "C3D:red_LHeel", "C3D:red_LToe", "C3D:red_LMidFoot", "C3D:red_RHeel", "C3D:red_Rankle",
"C3D:red_RMidFoot", "C3D:red_RToe", "C3D:red_RShin", "C3D:red_RKnee", "C3D:red_RThigh",
"C3D:red_RBackWaist", "C3D:red_RFrontWaist", "C3D:red_Chest", "C3D:red_RShoulder", "C3D:red_RUpperArm",
"C3D:red_RElbow", "C3D:red_RForeArm", "C3D:red_RHand_B", "C3D:red_RWrist", "C3D:red_RHand_A",
"C3D:red_LFrontHead", "C3D:red_LBackHead", "C3D:red_RBackHead", "C3D:red_RFrontHeaf"
};
string $marker;
for ($marker in $markerArray)
if (objExists($marker))
delete $marker;

string $textFieldGrpArray[] = `columnLayout -query -childArray BluePill_container`;

//print("// The names of the textFieldGrp controls are:\n");
//print $textFieldGrpArray;

string $theTextFieldGrp;
for ($theTextFieldGrp in $textFieldGrpArray)
{
//print $theTextFieldGrp;
string $fieldName = `textFieldGrp -query -label $theTextFieldGrp`;
string $fieldValue = `textFieldGrp -query -text $theTextFieldGrp`;
{
if (`objExists $fieldName`)
rename $fieldName $fieldValue;
else
print "// Waring this joint does not exist." ;
}
}

delete Mia:Head_End;

//Since MAssive works in meters you are going to need to have this change
//so that your motion is not giantic within Massive.
currentUnit -linear "m";

}

global proc rkoBluePill ()

{
string $miaJoints[] = lookupMiaJointsArray();

if (`window -exists BluePill`)
{
deleteUI BluePill;
}

/*
if (`windowPref -exists demoWindow`) {
// remove the stored size of the window
windowPref -remove demoWindow ;
}
*/

if (`uiTemplate -exists BluePill_uiTemplate`)
{
deleteUI -uiTemplate BluePill_uiTemplate ;
}
uiTemplate BluePill_uiTemplate;

// if (`windowPref -exists BluePill`) windowPref -remove BluePill ;


int $buttonHeight = 60 ;
int $buttonWidth = 200 ;

button -defineTemplate BluePill_uiTemplate
-align "center"
-width $buttonWidth
-height $buttonHeight;

setUITemplate -pushTemplate BluePill_uiTemplate ;


window -title "Blue Pill" -resizeToFitChildren yes BluePill ;
scrollLayout ;
columnLayout;
columnLayout BluePill_container;
int $i;
for ($i = 0; $i < size($miaJoints); $i+=2)
{
textFieldGrp
-label $miaJoints[$i]
-text ""
-editable true

("BluePill_UI_Text_" + $i) ;
}

textFieldGrp -edit -editable false BluePill_UI_Text_0; // Within Massive it is very important to make sure that the main
//control joint in named the root joint otherwise Massive will not re
//conize any of your motions.
setParent .. ;
rowLayout -numberOfColumns 3 ;
button -label "Use Defaults" -command "useDefaults();" ;
button -label "Transform" -command "finalStage()" ;
button -label "Close" -command "deleteUI BluePill" ;

setUITemplate -popTemplate ;

showWindow BluePill ;

}

/****************************************************************************************************************
This Procedure sets up the OptionVar so that the joints within the field names are read and store so
that they can be applied later within the Transform procedure. An import note is this has to take
place after the Use Defaults command has been used so that the new joint names are stored and not the blank
fields that come up first.
*****************************************************************************************************************/

global proc optionVarSetup()
{
string $MiaRenameJoints = "demo_arraysInOptionVariables_optionVar";

if(`optionVar -exists $MiaRenameJoints`)
optionVar -clearArray $MiaRenameJoints;

string $textFieldGrpArray[] = `columnLayout -query -childArray BluePill_container`;

//print("// The names of the textFieldGrp controls are:\n");
//print $textFieldGrpArray;

string $theTextFieldGrp;
for ($theTextFieldGrp in $textFieldGrpArray)
{
//print $theTextFieldGrp;
string $fieldName = `textFieldGrp -query -label $theTextFieldGrp`;
string $fieldValue = `textFieldGrp -query -text $theTextFieldGrp`;

optionVar -stringValueAppend $MiaRenameJoints $fieldName;
optionVar -stringValueAppend $MiaRenameJoints $fieldValue;
}

// This is a great way to test what is being stored within the OptionVar system.
// print("// The optionVar " + $MiaRenameJoints + " contains:\n");
// print (`optionVar -query $MiaRenameJoints`);

}

rkoBluePill;