Monday, August 29, 2016

My favourite piece of code (Animator Buddy)



It is written in MEL (maya embedded language)THIS IS A PIECE OF CODE THAT I CREATED IN 2014 (NOT FULLY JUST PARTS OF IT ,)( See images and UI in following posts)
I named it  - Animator Buddy

It brings up a window named animator buddy.I modeled it  based on  a digital calculator program I did long time back using Visual basic
The window has buttons like
 
Buttons                    Explanation

 animation curves ,     opens the window in maya software showing the animation curves
set animation key       sets a animated key in maya software
playblast                     creates a video of the animated keys

create face camera      creates a camera automatically facing  the face of a 3d model

show only polygon     this shows only polygons in maya , (so no round or nurbs , or rigs are shown)


All these are already in maya menus , but the animator has to go through various menus each time and click various options , or some had to be done manually , like face camera
(my logic in automatically setting the face camera was , just automatically setup a camera facing the bone which has face as its name)
The codes were not written just like that . there is a editor in maya called MEL editor, I used go and click a particular option , or menu and look up the corresponding code
To be honest I just put together ,and tweaked all the codes the code editor , produced by itself.I had the help of my mentor  Jonathan Mafi  jono@podlance.co.nz.
many parts of the code , I dont know what it does
but I am sending the whole script so that if you would run in a mel script editor it would show the entire output.

But it is still a brilliant piece of code and if developed a bit more could be used professionally in animation companies even WETA  ,with adjustments to speed up the process of animation. Even now animators might find it useful.

It is  the application and  the idea more of "me" than the code  itself. This is my favorite piece of code  because it helped me do my animation project  , though many ideas are copied .I feel ,it is marketable  if tweaked and made more  professional.

the project I did with this tool  link is

https://www.youtube.com/watch?v=UETTjlJEy3U


if(`window -exists AnimatorBuddy`)
{
  deleteUI AnimatorBuddy; 
}
global proc nurbsselect ()
{
  setObjectPickMask "Marker" false;
updateObjectSelectionMasks;
updateComponentSelectionMasks;
setObjectPickMask "Joint" false;
updateObjectSelectionMasks;
updateComponentSelectionMasks;
setObjectPickMask "Surface" false;
updateObjectSelectionMasks;
updateComponentSelectionMasks;
setObjectPickMask "Deformer" false;
updateObjectSelectionMasks;
updateComponentSelectionMasks;
setObjectPickMask "Dynamic" false;
updateObjectSelectionMasks;
updateComponentSelectionMasks;
setObjectPickMask "Rendering" false;
updateObjectSelectionMasks;
updateComponentSelectionMasks;
setObjectPickMask "Other" false;
updateObjectSelectionMasks;
updateComponentSelectionMasks;
 
}
//shoes a graph editor and a cam and hypergraph
global proc interface ()
{
    setNamedPanelLayout "Persp/Graph/Hypergraph"; updateToolbox();
   findNewCurrentModelView;
   // Result: 1 //
  findNewCurrentModelView;
  // Result: 1 //
  updateModelPanelBar MayaWindow|formLayout1|viewPanes|modelPanel4|modelPanel4|modelPanel4;
}

  // keys a selected control 
global proc keyselected ()
{
   
  SetKey; 
}

//keys all selected controls
global proc keyall ()
  // Result: 1 //
  //updateModelPanelBar MayaWindow|formLayout1|viewPanes|modelPanel4|modelPanel4|modelPanel4;
{
    string $curves[] = `ls -type "nurbsCurve"`;
  
  // loop through each curve
  for( $shape in $curves )
  {
     
          pickWalk -d up $shape;
    SetKey;
  }
}

// locks a control named Global
global proc globallock ()
{
    string $gcurve[] = `ls -type "nurbsCurve" "*Global*"`;   
    for( $gshape in $gcurve )
    {
     
       string $pw[] = `pickWalk -d up $gshape`;
       
  setAttr -lock true ($pw[0] + ".tx");
        setAttr -lock true ($pw[0] + ".ty");
        setAttr -lock true ($pw[0] + ".tz");
        setAttr -lock true ($pw[0] + ".rx");
        setAttr -lock true ($pw[0] + ".ry");
        setAttr -lock true ($pw[0] + ".rz");
        setAttr -lock true ($pw[0] + ".sx");
        setAttr -lock true ($pw[0] + ".sy");
        setAttr -lock true ($pw[0] + ".sz");
        setAttr -lock true ($pw[0] + ".v");
 }
}

// shows only polygon
global proc showpolygon ()
{
    // Result: scriptEditorPanel1Window|TearOffPane|scriptEditorPanel1|formLayout49|formLayout51|paneLayout4|cmdScrollFieldReporter2 //
updateShowMenu MayaWindow|formLayout1|viewPanes|modelPanel4|menu30 modelPanel4 "modelPanel4" "Playblast Display";
modelEditor -e -allObjects 0 modelPanel4;updateShowMenu MayaWindow|formLayout1|viewPanes|modelPanel4|menu30|menuItem531 modelPanel4 "modelPanel4" "Playblast Display";
updateModelPanelBar MayaWindow|formLayout1|viewPanes|modelPanel4|modelPanel4|modelPanel4;
updateShowMenu MayaWindow|formLayout1|viewPanes|modelPanel4|menu30 modelPanel4 "modelPanel4" "Playblast Display";
modelEditor -e -polymeshes true modelPanel4;
// Result: modelPanel4 //
updateModelPanelBar MayaWindow|formLayout1|viewPanes|modelPanel4|modelPanel4|modelPanel4;
}

// clears the keyframes
global proc clearkeys ()
{
     cutKey -clear;
}

//global proc playblast ()
//{
   
//}
// image plane ,to which a brrowser window is loaded
global proc refpicture ()
{
       importImagePlane { "perspShape" };
        np_getPrimaryProjectFileRules 0;
}

// looks through a camera called facecamera(this is such a simple piece technically , but practically it is a leap for the animator doing the work.
global proc facecam ()
{
  if(`objExists "*facecamera*"`)
 {
    

 select -r" *facecamera*" ;
 lookThroughSelected 0 modelPanel4; 
 }
else
    {
       CreateCameraOnly;;

    
    
      lookThroughSelected 0 modelPanel4;
      }
 
}

// zeros all controls
global proc zerocontrols ()
{
  //generateChannelMenu MayaWindow|MainChannelsLayersLayout|ChannelsLayersPaneLayout|ChannelBoxForm|menuBarLayout1|frameLayout1|mainChannelBox|popupMenu1 1;
//channelBoxCommand -freezeAll;
//refreshAE;
  string $acurve[] = `ls -type "nurbsCurve" `;   
    for( $ashape in $acurve )
    {
     
       string $zw[] = `pickWalk -d up $ashape`;
       
  setAttr  ($zw[0] + ".translateX") 0 ;
  setAttr  ($zw[0] + ".translateY") 0 ; 
  setAttr  ($zw[0] + ".translateZ") 0 ;
  setAttr  ($zw[0] + ".rotateX") 0 ;  
  setAttr  ($zw[0] + ".rotateY") 0 ;
  setAttr  ($zw[0] + ".rotateZ") 0 ;
  setAttr  ($zw[0] + ".scaleX") 1 ; 
  setAttr  ($zw[0] + ".scaleY") 1 ; 
  setAttr  ($zw[0] + ".scaleZ") 1 ;       
       
}
}



//create the window (but keep invisible)
window AnimatorBuddy;
    //create the columnLayout
      columnLayout -rowSpacing 10 AbCol;
      
        button  -c nurbsselect -w 250 -h 35 -bgc 0 .0 .5  
                -l "NURBS ONLY SELECTABLE" -p AbCol buttonA;
               
                button -c interface -w 250 -h 35 -bgc 0 .0 .5
                -l "ANIMATION INTERFACE" -p AbCol buttonB;
              button -c keyselected -w 250 -h 35 -bgc 0 .0 .5
                -l "KEY SELECTED" -p AbCol buttonC;
                button -c keyall -w 250 -h 35 -bgc 0 .0 .5 
                -l "KEY ALL CONTROLS" -p AbCol buttonC1;
                button -c globallock -w 250 -h 35 -bgc 0 .0 .5
                -l "GLOBAL CONTOL LOCK" -p AbCol buttonD; 
                button -c showpolygon -w 250 -h 35 -bgc 0 .0 .5
                -l "SHOW POLYGONS ONLY" -p AbCol buttonE;
               
                button -c clearkeys -w 250 -h 35 -bgc 0 .0 .5
                
                -l "CLEAR ALL KEYS" -p AbCol buttonF;
               
                button -c playblast -w 250 -h 35 -bgc 0 .0 .5
                -l "PLAYBLAST" -p AbCol buttonG;
                button -c refpicture -w 250 -h 35 -bgc 0 .0 .5
                -l "REFERENCE PICTURE" -p AbCol buttonH;
                button -c facecam -w 250 -h 35 -bgc 0 .0 .5
                -l "FACE Cam" -p AbCol buttonI;
                button -c zerocontrols -w 250 -h 35 -bgc 0 .0 .5
                -l "ZERO ALL CONTROLS" -p AbCol buttonJ;
               
       
               
        rowLayout -w 250 -h 35 -nc 3 -p AbCol AbRow;
           
//show the window
showWindow AnimatorBuddy;
//edit the window size
//window -e -wh 1000 500 AnimatorBuddy;