Saturday, 19 March 2016

Autodesk Maya Tutorial: Mastering Set Driven Key for Advanced Rigging

Autodesk Maya Tutorial: Mastering Set Driven Key for Advanced Rigging


Welcome back, animators and riggers! I'm Prof. Dr. Zeeshan Bhatti, and today on Zeeshan Academy, we're diving into one of the most powerful and versatile tools in the Maya rigging artist's toolkit: Set Driven Key (SDK).

If you've ever wanted to create complex, intuitive relationships between attributes—like having a character's brow furrow automatically when they raise their eyelids, or building a clean control panel for facial expressions—then this tutorial is for you. We'll not only learn how to use SDKs to build a simple facial rig but also how to create a custom GUI to control it all, using the very MEL scripts you provided.

What is a Set Driven Key?

Forget the traditional concept of keyframing animation over time. A Set Driven Key establishes a relationship where the value of one attribute (the "Driver") directly controls the value of another attribute (the "Driven").

Think of it like a gear system:

  • Driver: The gear you turn.

  • Driven: The gear that turns as a result.

In our case, we'll create a slider that drives the rotation of a character's jaw bone. This allows for non-linear, customizable control that is essential for sophisticated character rigs.

Part 1: Building a Jaw Rig with Set Driven Key

Let's start with a practical example: opening and closing a character's mouth.

Step 1: Create the Control and the Geometry

  1. Create a simple polygon cube. Scale it to resemble a head. This is our "Head_Geo".

  2. Create a NURBS circle (Create > NURBS Primitives > Circle). This will be our control. Name it "Jaw_CTRL".

  3. Place the Jaw_CTRL in front of the face. Freeze its transformations (Modify > Freeze Transformations).

Step 2: Create the Jaw Joint

  1. Switch to the Rigging menu set.

  2. Create a joint (Skeleton > Create Joints). Click once for the root (at the pivot of the head) and again near the bottom of the "mouth" for the jaw tip. Press Enter. Name it "Jaw_Joint".

  3. Parent the Jaw_Joint to the Jaw_CTRL (Select Jaw_Joint, then Shift-select Jaw_CTRL, press p).

Step 3: Skin the Geometry

  1. Select the Jaw_Joint, then Shift-select the Head_Geo.

  2. Go to Skin > Bind Skin > Smooth Bind. Now, when you rotate the joint, the geometry should deform.

Step 4: The Magic - Setting the Driven Key
Now, we'll make the control's translate Y drive the jaw's rotation.

  1. Open the Set Driven Key window: Animate > Set Driven Key > Set...

  2. Load the Driver:

    • Select the Jaw_CTRL.

    • In the SDK window, click Load Driver.

    • On the right, you'll see its attributes. Select translateY.

  3. Load the Driven:

    • Select the Jaw_Joint.

    • In the SDK window, click Load Driven.

    • On the right, select the rotateX attribute (assuming this is the axis that opens the mouth).

  4. Set the First Key (Mouth Closed):

    • Ensure the Jaw_CTRL is at its original position (translateY = 0).

    • Ensure the Jaw_Joint is not rotated (rotateX = 0). This is the closed mouth state.

    • In the SDK window, click Key. You've set the first relationship: translateY 0 drives rotateX 0.

  5. Set the Second Key (Mouth Open):

    • Move the Jaw_CTRL upward on the Y-axis (e.g., translateY = 5).

    • Rotate the Jaw_Joint on the X-axis to open the mouth (e.g., rotateX = 45).

    • Click Key again.

Step 5: Test Your Rig!
Now, slowly move the Jaw_CTRL up and down. The jaw should open and close smoothly. You've just created your first Set Driven Key rig!

Part 2: Building a Custom Control GUI with MEL

Manipulating controls in the viewport is great, but for a clean, professional rig, a custom GUI is unbeatable. Let's use your scripts to build one.

Step 1: Create the Main Window
We'll start by creating the window and its basic layout.

mel
// Create the main window for our facial rig
window -title "Zeeshan Academy - Facial Rig" -widthHeight 300 400;
// Define a simple column layout to stack our controls
columnLayout -adjustableColumn true;

// Add a title text
text -label "Facial Control Panel" -font "boldLabelFont";

Step 2: Add Control Sliders
Let's add a slider for our jaw control. The attrFieldSliderGrp command is perfect as it gives us a slider, a field, and a label.

mel
// Create a slider for the Jaw control
attrFieldSliderGrp -min 0 -max 10
                   -columnWidth3 20 70 100
                   -attribute "Jaw_CTRL.translateY"
                   -label "Jaw Open"
                   jawSlider;
  • -min/-max: Defines the slider's range.

  • -columnWidth3: Sets the width for the number, slider, and field.

  • -attribute: This directly links the GUI element to our control's attribute in the scene! This is the most powerful part.

Step 3: Add Functional Buttons
Now, let's add buttons to select controls quickly.

mel
// Add some space
text -label "";

// A regular button to select the jaw control
button -width 130 -height 25 -label "Select Jaw CTRL" -annotation "Selects the Jaw Control" -command "select -r Jaw_CTRL";

// A symbol button for a hand control (using a placeholder image)
symbolButton -image "sphere.xpm" -command "select -r Hand_CTRL" -annotation "Select Hand CTRL";
  • The -command flag runs a MEL command when pressed. Here, it's a simple select command.

Step 4: Add a Checkbox for System Switching
For more complex rigs (like IK/FK switching), a checkbox is ideal.

mel
// Add more space
text -label "";

// A checkbox for an IK/FK switch
checkBox -label "IK / FK Switch" -width 130 -height 19 -annotation "Switch between IK and FK controls"
         -onCommand "setAttr IK_FK_CTRL.switch 1" // Command when checked
         -ofc "setAttr IK_FK_CTRL.switch 0";      // Command when unchecked

Step 5: Show the Window
Finally, we need to display the window we've built.

mel
// Show the completed window
showWindow;

Putting It All Together: Your Final MEL Script

Here is the complete script you can paste into the Maya Script Editor (make sure to be in the MEL tab) and execute.

mel
// Check if window exists and delete it to avoid errors
if (`window -exists facialRigWindow`) deleteUI facialRigWindow;

// Create the main window for our facial rig
window -title "Zeeshan Academy - Facial Rig" -widthHeight 300 400 facialRigWindow;
// Define a simple column layout to stack our controls
columnLayout -adjustableColumn true;

// Add a title text
text -label "Facial Control Panel" -font "boldLabelFont";

// Create a slider for the Jaw control
attrFieldSliderGrp -min 0 -max 10 -columnWidth3 20 70 100 -at "Jaw_CTRL.translateY" -l "Jaw Open" jawSlider;

// Add some space
text -label "";

// A regular button to select the jaw control
button -w 130 -h 25 -label "Select Jaw CTRL" -ann "Selects the Jaw Control" -c "select -r Jaw_CTRL";

// A symbol button for a hand control
symbolButton -image "sphere.xpm" -c "select -r Hand_CTRL" -ann "Select Hand CTRL";

// Add more space
text -label "";

// A checkbox for an IK/FK switch
checkBox -label "IK / FK Switch" -w 130 -h 19 -ann "Switch between IK and FK controls" -onc "setAttr IK_FK_CTRL.switch 1" -ofc "setAttr IK_FK_CTRL.switch 0";

// Show the completed window
showWindow;

Conclusion: You Are Now a Driver Master!

Congratulations! You've not only learned how to create intuitive rigging relationships with Set Driven Key but also how to build a professional-looking control panel using MEL. This combination is the foundation of creating robust, user-friendly character rigs that animators will love.

The principles you've learned here can be expanded to rig entire faces—where one slider could control the corners of the mouth, the cheeks, and even create nose wrinkles all at once.

For a visual walkthrough of this entire process, don't forget to check out the detailed video tutorial on the Zeeshan Academy YouTube channel!

Now, go forth and drive some keys!

Prof. Dr. Zeeshan Bhatti
Zeeshan Academy - https://www.youtube.com/@ZeeshanAcademy

Following are few quick scipts to create MEL GUI components:


create a window
 window;

  // define the layout of controls added 
  // to the window.
  columnLayout;

   // create some text
   text -label "hello world";

 // show the window we last created
 showWindow;

Slider:
attrFieldSliderGrp -min -10 -max 10 -cw 1 20 -cw 2 1 -cw 3 70
                              -at RightLeg_CTRL.AnkelRotate
                              -l aud AFD1;

Button:
button -w 70 -h 20 -label "Select All" -ann "Select all Controls" -c selAll

Symbol Button

// create window
window;
columnLayout;
   
  // create three symbol buttons with related mel command
  symbolButton -image "circle.xpm" -command "circle";
  symbolButton -image "sphere.xpm" -command "sphere";
  symbolButton -image "cube.xpm" -command "polyCube";
showWindow;


Checkbox:
checkBox -label "IK_FK" -w 30 -h 19 -ann "Switch IK FK control"
                 -onc "l_showIKFK(\"1\")"
                 -ofc "l_showIKFK(\"0\")"
                 ik_fk_switch;

example:
// create a checkbox
$c = `checkBox -label "thingy" -onCommand "on_func" -offCommand "off_func"`;
// to get the current value of the checkBox, use the -query flag
$value = `checkBox -query -value $c`;
print("check_box value = "+ $value +"\n");


Button with IMAGE:
iconTextButton -style "iconOnly" -mw 0 -mh 0 -ann "Select Hand CTRL"
                          -image1 "bbutton.bmp" -w 20 -h 20
                          -command "SelectHandCTRL(\"Left\")" 
                           selHand_Ctrl;

               

1 comment:

  1. sir i am using maya 2014. but there is no property editor. how can i find it? plz help me.

    ReplyDelete

Featured post

👉 🔥 Master Full Stack Web Development | Week-1 Lecture-1 - HTML & Frontend vs Backend, Dr. Zeeshan Bhatti

  Hey there, future coders! Welcome to the most exciting journey of your life. I'm  Dr. Zeeshan Bhatti  from  Zeeshan Academy , and you...