Professional Documents
Culture Documents
10
11
Create a new null group by selecting Create > Empty Group. masterController. Note the channel box on right is blank.
In your outliner, you should notice that you now have
something called "null1." Rename the empty group
"masterController."
We're going to be creating our own attributes for our
masterController, and won't be needing any of the default
ones. In the channel box, click-drag over everything (from
TranslateX to Visibility), and with them selected, right click
and select "Hide Selected" from the drop down menu.
Now we'll create a new attribute. Right click in the empty
channel box and select "Attributes -> Add Attribute" from the
dropdown menu. In the window that appears, name the
attribute "twist," make sure that's it's data type is "float" and
set the minimum to 0, the maximum to 1, and the default to
1. Select "Add." Create another new attribute called
"separate" with the same settings, except have the default
value be 0.
12
Let's set up some more set driven keys to do this, but using MEL. If you take a look at your script editor, you
should notice that the command to create a set driven key is pretty simple:
setDrivenKeyframe -currentDriver masterController.twist pair20.rotateY;
The -currentDriver flag indicates the driver (the twist attribute of the masterController) and the last argument
(pair20.rotateY) determines what's being driven.
Type in the following into the script editor:
for ($i=1; $i<=19; $i++) {
setAttr "masterController.twist" 1;
setDrivenKeyframe -currentDriver masterController.twist ("pair" + $i + ".translateX");
setAttr "masterController.twist" 0;
setAttr ("pair" + $i + ".translateX") 0;
setDrivenKeyframe -currentDriver masterController.twist ("pair" + $i + ".translateX");
}
Run the script (highlight it and hit Ctrl-Enter) and try changing the twist value of the masterController to check if
it's working. You should see that now the translateX is moving to 0 when twist is 0, but translate Z hasn't been
fixed yet. Run the previous expression again (you can cut and paste it from the upper part of the script editor)
and replace all three instances of "translateX" with "translateZ."
Breaking down the script:
setAttr "masterController.twist" 1;
Tutorial 8 DNA: variations on a theme
Fall 08
13
"setAttr" is short for "set Attribute" and sets, in this case, the twist attribute of the masterController to 1. The
translateX (or Z) value should already be set to whatever we want it to be when twist is 1, so we can go ahead
and set the driven key:
setDrivenKeyframe -currentDriver masterController.twist ("pair" + $i + ".translateX");
In the 2nd half of the script, we're repeating the same thing
after setting twist to 0 and translateX of the pair to 0.
The last thing that we want the masterController to do is to
separate the two strands of DNA.
In the outliner, take a look at the hierarchy of your DNA.
Each pair is made up of a "baseL" and a "baseR." For our
strand separation, we'd like baseL and baseR to move in
opposite directions from the origin. Depending on how you
arranged your DNA, baseL may need to go in the +X, -X, +Z
or -Z direction, and baseR in the opposite direction along the
same axis. Figure this out before the next step!
Now we'll just write a little more MEL to have the
masterController's 'separate' attribute control strand
separation. We will be using the exact same setDriven
technique as we have before.
Type in the following script into the Script Editor (keeping in
mind that youll need to replace translateX and 5 with
whatever axis and +/- value for 5 works in your case)
14