dna maya tutorial

Upload: aeteatpk

Post on 02-Jun-2018

228 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 Dna maya tutorial

    1/14

    Tutorial 8 DNA: variations on a themeGal McGill & Janet Iwasa Fall 08

    1

    TUTORIAL 8 DNA: variations on a theme

    In this tutorial, well explore different methods for modeling,rigging, and animating DNA. There are many ways toapproach this macromolecule in Maya and each has itsmerits depending on what the model will be used for in yourscene. Well start with a simple plank DNA model that isroughly based on what is known about the moleculesproportions, and then look at different ways to deform it.Next well import a PDB coordinate set for B-DNA andexperiment with different representations using particles.These first two methods assume that the helix does not needto unwind and melt. Finally, well go over a programmaticapproach to building DNA using PDB data for a single basepair this method will allow us to twist and unzip the doublehelix.

    Before we jump in, lets briefly review the structural features

    of B-DNA that are important for our modeling efforts:19 in diameter10.5 base pairs per helical turn (~34oper base pair)34 high per helical turn (~3.3 per base pair)

    For the purposes of our initial modeling efforts (i.e. plankDNA), we will round out these numbers to assume ~10 basepairs per helical turn and ~20 in diameter.

    Part 1 Plank DNA

    Modeling plank DNA

    In this first exercise, well create a stand-in model for B-DNAthat could be useful in schematic animations where atomicresolution is not required and melting of the double helix isnot necessary. Heres a quick overview of the process: 1)model a base pair with polygons, 2) animate its rotation andelevation to use the animated snapshot tool, 3) create 2NURBS curves slightly offset from the base pair, 4) use theanimated sweep tool to extrude those circles and create thebackbone and finally 5) duplicate special to createadditional helical turns to the model prior to rigging.

    Although weve reviewed B-DNAs characteristics above,lets also have a PDB-derived cartoon model in our scene to

    make sure we have the right proportions as we go throughthe modeling process. Go to the Learning section ofwww.molecularmovies.org and download supporting files.

    Open the ref_1helicalTurn.mafile its a simple model of asingle helical turn of DNA. This was generated in PyMOL(with the cartoon representation), exported as a vrml2 file,converted to an obj, and then imported into Maya. Observethe model in various orthographic views and notice that it is4 grid units wide and ~7 grid units high (from bottom base-

    One helical turn of reference B-DNA createdusing the cartoon representation in PyMOL

    The first base pair consists of 4 polygon cubes

  • 8/10/2019 Dna maya tutorial

    2/14

    Tutorial 8 DNA: variations on a themeGal McGill & Janet Iwasa Fall 08

    2

    pair to top base-pair). As expected, this is the correct ratiofor B-DNA (i.e. 7units/4units = 34/20 = ~1.7). Extendyour timeline to 800 framesand savethe file asplankDNA_01_modeling.ma.

    Lets begin by creating a single base-pair with simplegeometry. Using the polygon primitive cube tool, create aplank that is roughly 2 units long along the x axis, ~ 0.5 unitswide along the z with just a little thickness along the y axis.Duplicate the plank, scale it down slightly along the x axis,and move it on the other side of the origin along the x axis.

    Add a small plank angled at 45 degrees along the y to eachlarger plank (refer to the pictures on the right for placement).Select the 4 planks, group and name bp.

    This base pair would need to rotate 360 degrees and travel~7 grid units along the y axis to find itself one helical turnaway from where it is now. Lets animate that displacement:making sure you are on frame 1of the timeline, select thebp group and key its Translate y and Rotate yattributes in

    the Channel Box (they should both be 0 by default). Now goto frame 100, change Translate y to 7 and Rotate y to 360

    key those values and play the animation. The base pairrises along the y axis while rotating, as if were travelingthrough all of the intermediate positions where theintervening 8 base pairs would be. We will use thisanimation to sprinkle a copy of the base pair at eachappropriate location along the y to do this well use Mayas

    Animation Snapshot tool. With the bp group selected, go tothe Animation menu set and go to Animate -> CreateAnimation Snapshot | Options reset. With the Starttime set to 1, the End time set to 100 (i.e. the range ofyour base pair animation), and the Increment set to 10,

    click Snapshot. Maya plays through the specific range offrames and takes a snapshot of the geometry every 10frames (thats the increment setting). Notice that it actuallyleft out the last base pair this is fine in that we will beduplicating the entire helical turn later and therefore wouldnot want this overlap. If you did want to get all 10 base pairsin the animated snapshot, you would need to set the Endtime to 101 (instead of 100) with the same increment of 10.

    Although weve applied it in a very basic way here (we couldhave used the Duplicate Special tool here), the AnimatedSnapshot technique is a powerful method of using any kindof animation to create duplicated geometry.

    Now well use a similar to tool to create the backbone.Mayas Animated sweep tool, like the animated snapshot,places new copies of geometry based on an animation butwith 2 important differences: 1) it only works with curves and2) it creates a lofted NURBS surface from all of theseduplicated curves. Lets see how this works.

    Create a NURBS circle and scale/position it on the grid suchthat it overlaps one of the outer corners of your plank.

    Duplicated base pairs after the animated snapshot

    Placement of NURBS circles relative to the base pair

    Animation sweep settings for the backbone

    Duplicate Special settings to extend the DNA strand

  • 8/10/2019 Dna maya tutorial

    3/14

    Tutorial 8 DNA: variations on a themeGal McGill & Janet Iwasa Fall 08

    3

    Duplicate the circle and move/position it on the other side ofthe plank (see image on the right). Make sure they are bothoffset on the same side of the plank - this offset is what willcreate the major and minor grooving of your DNA model (i.e.the base pairs are centered on the helical axis, but thebackbone strands are not). Select both circles, group andname backbone circles. Similar to the process we used toset up the Animated Snapshot, well need to animate thecircles group on frame 1, key the Translate y and Rotatey values and the on frame 100, key Translate y to 7 andRotate y to 360. Back on frame 1 with the backbonecircles group selected in the Outliner, go to Animate ->Create Animated Sweep | Options (reset). Set the Starttime to 1, the End time to 101(well want the geometry toextend all the way up to 7 grid units this time) and By Timeto 10 leave all the rest to defaults and press AnimSweep.

    Notice the snapshot5 & snapshot6 groups in the Outliner, aswell as 2 loftedSurfaces. This shows you how the

    Animated Sweep works it first does an Animated Snapshotoperation and then lofts between the curves in the snapshotgroups. Compare your modeled DNA to the reference model

    they should be pretty much identical in terms ofproportions (except for the intentionally missing last basepair at the top of your model). You can now hide bpbackbone circles snapshot5Group andsnapshot6Groupbefore we proceed to growing the DNAstrand.

    Select snapshotGroups 1, 2, 3 and 4 (i.e. the base pairs)and the 2 lofted surfaces (i.e the backbone strands) andgroup them rename the group DNA. With this group

    selected in the Outliner, go to Edit -> Duplicate Special |Options (Reset). Use the following settings: Group under -World, Translate y to 7, Number of copies to 4. Youshould now have a DNA model that is 5 helical turns theOutliner shows every turn of the helix as a separate group.Save you file, and then Save Scene As:plankDNA_02_rigging.ma.

    Rigging your model

    There are many ways to deform this DNA model dependingon the animation goals in this tutorial, well explore atechnique where instead of creating a skeleton and skinningit to the geometry (which is typical), we first apply a lattice tothe model and then skin the lattice to a skeleton. This canyield faster and smoother deformations the skeletoncontrols the lattice, which in turn controls the model it iswrapped around.

    Select all the DNA groupsin the Outliner and group them rename it DNA_strand. With this new group selected, goto Create Defomers -> Lattice | Options (Reset). Well use

    The com leted lank DNA model

    Lattice settings

    Adding a skeleton to your DNA model

  • 8/10/2019 Dna maya tutorial

    4/14

    Tutorial 8 DNA: variations on a themeGal McGill & Janet Iwasa Fall 08

    4

    settings that give us plenty of deforming resolution alongthe y axis: Divisions 2 10 2(keep the rest as defaults).You can test to see if your lattice works by RMB-clickingover the latticeand selecting Lattice Point from the pop-up. Now drag-select some points and rotate or move themto deform the model.

    Switch to the front orthographic camera and, with yourmodel maximized/scaled in the viewport, go to Skeleton ->Joint Tooland create joints from bottom to top clicking ateach rung or division in the lattice. Press enter when youfinished creating your skeleton you should have 10 jointstotal and your joint chain should be centered inside thelattice by default. Return to the perspective viewport. Withthe root joint selected (i.e. joint 1 in the Outliner), shift-selectthe lattice in the viewport and go Skin -> Bind Skin ->Smooth Bind | Options (Reset). Use the following settings:Bind Method: Closest distance, Max influences: 3(rest atdefaults) click on Bind Skin. Now select a joint at thecenter of the chain and rotate it you should now see your

    DNA model bending around as you control the rotation of thejoints! Save your scene.

    Controlling your rig

    A common way to control a skeleton is through the use of IK(Inverse Kinematics): instead of rotating and keying theposition of every joint in a chain, IK allows you to key theposition of a single IK handle. We already explored thiswhen we rigged the sigma tentacle in the Animation tutorial

    for our model DNA, however, well look at another type ofIK called spline IK. The main difference is that in spline IK a

    curve is used to control the joint chain instead of an IKhandle.

    Save your scene as plankDNA_03_rigControl.ma. Tomake things easier to select and see as we add layers ofcontrol to this rig, hide the lattice and switch your viewport toX-Ray mode (shading -> X-Ray). To add a spline Ikcontroller to your skeleton, go to Skeleton -> IK SplineHandle Tool | Options (Reset). As per the instructions thatshow up in the lower left-hand corner of your scnreen, firstclick on the root joint of the skeleton (joint 1 at the bottom)and then on the top joint of the chain. Youll notice two newnodes in the Outliner: an IK handle (which, unlike regularIK, you will not be able to move) and a curve. In the Showdrop-down menu of your perspective viewport, toggle off thevisibility of Joints and IK Handles. What should be left atthe center of your DNA model is a blue curve. Select it and,in the Surfaces menu set, go to Edit Curves -> RebuildCurves | Options (Reset) set the Number of spans to10, make sure it is cubic/degree 3curve, and the Keeporiginal option is off click Rebuild. With the curveselected, switch to component mode (F8), select one orseveral CVs and move them the DNA model is now being

    Settings for binding the lattice to the skeleton

    Rotating individuals joints deforms the latticealong with the underlying DNA model

    Rebuildin the s line IK curve

  • 8/10/2019 Dna maya tutorial

    5/14

    Tutorial 8 DNA: variations on a themeGal McGill & Janet Iwasa Fall 08

    5

    deformed in response to the shape of the curve! Typically, ifyou want start keying the shape of the curve, you wouldselect the CVs and create clusters for each one and key theposition of the clusters. You could also apply any deformerto the curve anything that influences the shape of yourcurve over time will animate the DNA.

    To add some organic motion to the DNA, were going toconvert the spline IK curve into a softbody with goals andthen apply fields. Select the curve and, in the Dynamicsmenu set, go to Soft/Rigid Bodies -> Create Softbody |Options (Reset) use the following settings:

    Creation Options: Duplicate, make original soft(this is key since it is only the original curve that is the splineIK and controls your skeleton).Hide non-soft object is onMake non-soft a goal is onWeight: 0.3Click Create.

    As with any particles, well need to add a field to see anyeffect expand the curve1 node in the Outliner and selectthe particle object under it. Go to Fields -> Turbulence |Options (Reset) set the magnitude to10and theattenuation to 0, click Create. Select the field in theOutliner and, in the Channel Box, add an expression to thePhase X channel(select the channel, RMB-click over it andselect Editors -> Expressions):

    turbulenceField1.phaseX=time;turbulenceField1.phaseY=time;turbulenceField1.phaseZ=time;

    If you now play the animation you should see a wigglingDNA strand! You now have all the control that dynamicsaffords you in terms of how the DNA follows the goal curve(fields, springs, goalPP, etc). Instead of a softbody wecould also have turned the spline IK curve into Maya hair this option gives you even more attributes and control over agoal weight value for the softbody. If you want to add moredirected animation and motion to your DNA on top of thedynamic/organic wiggling, you still have the goal curve(hidden and called copyOfcurve1) to animate. You couldadd clusters to each of the CVs and then key their positionsand/or add non-linear deformers to the curve. For an

    example of both of these deformations, view theplankDNA.movexample movie associated with this tutorialon molecularmovies.org (and see the picture to the right).

    Moving the CVs on the spline IK deforms the DNA

    Adding a Turbulence field to affect the softbody curve

    Fully rigged DNA model (includes clusters & sinedeformer on spline IK goal curve)

  • 8/10/2019 Dna maya tutorial

    6/14

    Tutorial 8 DNA: variations on a themeGal McGill & Janet Iwasa Fall 08

    6

    Part 2 - Imported PDB DNA

    pdbReader & ballAndStick MEL scripts

    In this section of the tutorial well import a PDB file for anentire strand of B-DNA using Tom Doedens pdbReaderscript that creates NURBS spheres at every PDB coordinatepoint. The original script has been around for while and canbe downloaded form www.highend3d.com. We will actuallybe using a version of the script that was slightly modified byGeordie Martinez (www.negative13.com) so that it workswith his ballAndStick MEL script. The latter script will allowus to add bonds (NURBS cylinders) between atomsgenerated by the pdbReader script. Another approach willalso be to take the spheres generated by the pdbReaderscript and, instead of adding bonds, well use a MEL script tocreate a particle at every sphere (jPivToParticle created byJulian Mann) and then use the blobby sphere render type torender the DNA.

    An important note before we jump into this section this partof the tutorial is heavily influenced by THE original tutorial onthe use of these scripts: Eric Kellers now famous Workingwith Macromolecular Data in Maya: DNA which can befound on www.highend3d.com. Kudos to Eric(www.bloopatone.com) for initially putting this materialtogether into a tutorial it has been widely used since itsinitial print publication in Highend3D magazine. Thefollowing is just my reimplementation of the steps as theyrelate to an audience of scientists.

    Start with a new Maya scene and go to the script editor under File -> Source Script find the pdbReader.melscript. Nothing will happen when you click Open. To runthe script, type pdbReaderin the MEL command lineatthe bottom left of the Maya interface hit enter, and a smallpop-up window should appear. At the top click on Get PDBFile and search for the DNA.pdbfile that you downloadedalong with the other materials for this tutorial. Once loadedinto the window, you will notice that the Sample line of datafrom the file is now populated with typical PDB data thistakes a little experimenting as the columns may be slightlydifferent for different PDBs but the goal is to find the right xy z coordinate columns and specify them in the X Field, Y

    Field, Z Field in the script window. In the case of this PDB,enter 3 for the Atom Field, and 7, 8, 9, for the X, Y, ZField valuesrespectively. Now click on PRESS ME Create Molecule Structure.

    This may take a few moments you will know Maya is donewhen you see four new nodes in the Outliner calledPhosphorusGrp, OxygenGrp etc If you click in theperspective viewport to unselect any geometry and thenpress F, your camera should now zoom out to encompass

    Sourcin a MEL scri t from the scri t editor

    The pdbReader.mel script window

    Imported sphere model in the perspective viewport

    The ballAndStick.mel script window

  • 8/10/2019 Dna maya tutorial

    7/14

    Tutorial 8 DNA: variations on a themeGal McGill & Janet Iwasa Fall 08

    7

    the imported model. As is typical with imported PDB data,the model is large and far away from the grid. Press 5 toview the shaded model. Youll notice that the pdbReaderscript has assigned a different shader to each atom veryconvenient. Lets resist the urge to scale and center themodel until we have played with the ballAndStick script a bit.

    In the MEL command line, type ballAndStickand pressEnter a pop-up window appears. Read Geordiescomments he goes over the basics of how the script worksand provides default values that work well to create bonds.

    As suggested, lets begin by resizing all of the spheres in ourDNA model open each of the 4 atom groups in the Outlinerand select the long list of spheres within each group,scale each down to 0.5in the Channel Box. Now lets testthe script marquee-select a few spheres (~1 base pairequivalent) in the perspective viewport and run the script bypressing Generate Sticks. You should see light greycylinders appear between atoms in your selection. Repeatthe operation a few times by selecting different sets of

    atoms. To view the fully-shaded bonds, go to Renderer ->High Quality Renderingin your perspective viewport drop-down menu.

    Creating particles with jPivToParticle

    In the Outliner, delete the StickGroupthat was generatedas a result of running the ballAndStick script. Select theremaining 4 main groups (PhosphorusGrp, OxygenGrpetc) and group them name the group DNA. Now withthis new group selected, scale it down to 0.2 and centerpivot. Move the model to the center of the grid and switchbetween orthographic views to straighten the model. Freezetransformationson the master group DNA and the foursubgroups.

    If you inspect the model and expand the groups in theOutliner youll notice that the spheres are all very lowtessellation NURBS which is what makes this script so great.Indeed, a sphere model imported from any moleculargraphics program would yield polygonal spheres with hightessellation (with the exception of Jmol which now has anexport to the .ma file type and yields NURBS spheres thanks to Bob Hanson for that Jmol feature!). In any case,despite this lighter geometry, it is still almost unworkablewhen dealing with medium to large models of proteins for

    example. Converting the spheres to particles increasesperformance and, for some like Drew Berry, is also apreferred means of rendering molecules (using Hardwarerendering as opposed to Software rendering).

    To run the jPivToParticle script, begin by ungrouping allspheres in the Outliner: select the 4 main groups and goto Edit -> Ungroup. You should now have a long list ofNURBS objects with various atom names listed directly

    Sticks added to part of the DNA model

    The model scaled down and centered at the origin

  • 8/10/2019 Dna maya tutorial

    8/14

    Tutorial 8 DNA: variations on a themeGal McGill & Janet Iwasa Fall 08

    8

    under the DNA group. Select all the spheres in theOutlinerand, in the MEL command line, typejPivToParticleDNA_and press Enter. A new particle object shouldappear in the Outliner, all the names of the spheres nowstart with DNA_ and have a number. You can now selectthe DNA master group and hide it what should remain inthe viewport is a mist of grey particle points. Each spherehas been replaced with a single particle and all the particlesbelong to the same particle object. This last point is critical -its what will allow us to get a blobby look between the DNAatoms (this would not happen if each atom type was in itsown particle object i.e. blobbies dont form blobbiesbetweenparticle objects).

    Select the particle object and, in the Attribute Editor, switchthe render attributes to Blobby Surface [s/w] click onCurrent Render Typeand reduce the radius to 0.3. Takea render and click the Keep Image button (little open greybox with a black arrow pointing down into it). Now increasethe Threshold value to 0.45and take another render

    compare the two images.

    Now that your model is made of particles, there are anumber of ways to control it. Since Maya version 6, you canalso add non-linear deformers to particles. For an exampleof a bend-deformer applied to this model, view theblobbyDNA.movexample movie associated with thistutorial on molecularmovies.org

    After running the jPivToParticle script, particles arepositioned at each sphere location in the model.Points are switched to blobby surfaces for rendering.

    DNA rendered with blobby surfaces: Threshold=0.45DNA rendered with blobby surfaces: Threshold=0

  • 8/10/2019 Dna maya tutorial

    9/14

    Tutorial 8 DNA: variations on a themeGal McGill & Janet Iwasa Fall 08

    9

    Part 3 - Creating a DNA rig by JanetIwasa

    In this section of the tutorial, you will use PDB reader andsome rigging tricks to create a segment of DNA that can

    undergo strand twisting and untwisting as well as strandseparation.

    Importing nucleotides using PDB reader

    The primary building block that we're going to use to createour rig is two nucleotides base paired to one another. Icreated a PDB for you to use by taking a PDB of double-stranded DNA, and rather laboriously deleting everything buttwo paired bases (plus some extra atoms for alignment).

    If you haven't already sourced the PDB reader script, go tothe script editor, select File > Source Script and select the

    PDBreader plugin. In the MEL command line, type"pdbReader" and press Enter. Run pdbReader as you'vedone in the previous example, using "oneBP.pdb" as theinput pdb file.

    After you import the basepair, if you take a look at it (frameusing the 'f' key in the perspective view), you'll see that theatoms are sort of small. Draw a selection box around all ofthe atoms of the basepair and scale them up so that theyhave a more conventional space-filling look.

    In the perspective window, select the atoms of one of thenucleotides, press ctrl+g to create a new group, and name it

    "baseL" in the outliner (by double clicking on the name).Select the atoms of the other nucleotide, create a newgroup, and name it "baseR."

    Note that the atom type groups that were created byPDBreader ("NitrogenGrp," "CarbonGrp," etc) are now emptyand can be deleted.

    Select baseL and baseR in the outliner and group themtogether, naming the new group "pair0."

    Center the pivot of pair0 (Modify > Center Pivot) and movepair0 to the center of the grid using grid snapping (by

    keeping x depressed while moving). Rotate pair0 so that thebases are approximately flat along the x-z plane, and scaleto 0.5. Freeze the transformations of pair0 (Modify > FreezeTransformations).

    Creating a double stranded helix

    Scaling the atoms of the base pair to have a moreconventional spacefilling look.

    Create groups for the left and right nucleotides.

    Top orthogonal and side orthogonal views of thepair0 after adjusting rotation and scale.

  • 8/10/2019 Dna maya tutorial

    10/14

    Tutorial 8 DNA: variations on a themeGal McGill & Janet Iwasa Fall 08

    10

    Select pair0 in the outliner and duplicate it (ctrl+d). Thisduplicate should be named "pair1" by default. In the channelbox, change the rotation Y value to 36. Move pair1 aroundin X, Y and Z to align it so that pair 1 has overlappingoxygens with pair0 (refer to image on right). Do this withoutchanging any of the rotation values; only change thetranslate values! This might be tough depending on how youset up pair0, and don't worry if it isn't perfect. If the oxygensare impossibly far apart, delete pair1 and go back and adjustthe rotation of pair0, making sure to freeze transformationsafter you make your adjustments.

    Delete one of each of the overlapping oxygens (doesn'tmatter which one). Now select pair1 in the outliner and takea look at its translate coordinates in the channel box(remember, the rotations should all be 0 except rotate Y,which should be 36). With pair1 still selected, go to Edit >Duplicate Special and open the options box.

    In the Duplicate Special Options window, input the translate

    values for X, Y and Z of pair1 into the translate boxes.Change the rotate Y value to 36, and change number ofcopies to 19. Press 'Duplicate Special.'

    You should now have a nice helical model of DNA.

    Building a DNA untwister

    In order to unwind our DNA, we need to change the Yrotation coordinates for each of our pairs to 0. We could dothis manually, or better, brainstorming a bit and coming upwith some clever MEL tricks.

    One way that we can imagine how to rig the DNA twist is byimagining that the bottommost pair (pair0) is fixed, and thatthe topmost pair (pair20) is free to rotate in Y, and that itsrotation will determine the rotation of all the other basepairs.Imagine, for example, holding a rope ladder from the toprung and rotating that rung around, with the bottommost rungbeing tied down to the ground, and thus unable to rotate.

    To get started, we need to figure out what the rotation is forthe topmost pair. If you click on pair20 and check out its Yrotation, you'll see that it's 0. Each 10th base should returnto 0 since each base's Y rotation is offset by 36 degrees.This means that you can think of the Y rotation value ofpair10 as 360 and pair20 as 720. Change the Y rotationvalue of pair20 to 720.

    Since base0 will always be 0, all the basepairs in between(base2 through base19) will be a fraction of the Y rotation ofbase20, such that base20 would be the master rotationcontroller of all of the basepairs underneath it. For this, wewould want the Y rotation of base19 to be 19/20th the Yrotation of base20, base18 should be 18/20th, and so on.

    Top orthogonal and side orthogonal views of the pair1and pair0, with overlapping oxygens shown in green forclarity.

    Duplicate Special Options box for creating 19 duplicatesof pair1 with the correct translation and rotation values.

    The DNA after duplicating pair1. You should have 21base airs in all.

  • 8/10/2019 Dna maya tutorial

    11/14

    Tutorial 8 DNA: variations on a themeGal McGill & Janet Iwasa Fall 08

    11

    We could do this using expressions that control the Yrotation of each pair. To see how expressions are handledin MEL, let's go through one example.

    Select pair19, select "RotateY" in the channel box and right click. Select "expressions" from the drop down menu.Type in the following expression:

    rotateY = pair20.rotateY * 0.95;

    and press 'Create.' (note that 0.95 is 19/20). You shouldn't notice any difference since the rotation value shouldbe the same as it was before, but now if you rotate pair20, you should see that pair19 rotates with it (but alwaysslightly less). Take a look at the MEL that was used to create the expression by opening the script editor(Window > General Editors > Script Editor). You should see a line that looks something like this:

    expression -s "rotateY = pair20.rotateY * .95;" -o pair5 -ae 1 -uc all;

    We want to use MEL to create this expression for pairs2 through pair19. First, make sure that the expression isno longer controlling pair19's rotation by selecting 'RotateY' in the channel editor and selecting 'BreakConnections' from the drop-down menu.

    Now to implement the plan, type in the following in the script editor:

    for ($i=1; $i

  • 8/10/2019 Dna maya tutorial

    12/14

    Tutorial 8 DNA: variations on a themeGal McGill & Janet Iwasa Fall 08

    12

    Take a look at the Y rotation in the channel box for each ofthe pairs betwen 1 and 19. You should see that the box ispurple, and when you right click and select 'Expressions...,'you can view and edit the expression you made with thescript.

    Now if you change the value of pair20's Y rotation, youshould see that all of the pairs below follow.

    Creating a DNA Master Controller

    Next, we're going to build a master controller that's going tolet us control our DNA's movements a little more intuitively.

    Create a new null group by selecting Create > Empty Group.In your outliner, you should notice that you now havesomething called "null1." Rename the empty group

    "masterController."

    We're going to be creating our own attributes for ourmasterController, and won't be needing any of the defaultones. In the channel box, click-drag over everything (fromTranslateX to Visibility), and with them selected, right clickand select "Hide Selected" from the drop down menu.

    Now we'll create a new attribute. Right click in the emptychannel box and select "Attributes -> Add Attribute" from thedropdown menu. In the window that appears, name theattribute "twist," make sure that's it's data type is "float" andset 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 defaultvalue be 0.

    So what are we going to have this master controller do? Wewant the twist value of the master controller to control therotateY value of pair20, which will in turn control the rotationof the pairs below it. When twist is at 0, we want the rotateYof pair20 to also be at 0, but when twist is set to 1, we wantpair20 to be 720.

    To set up this relationship, we'll use the "setDriven"technique. Select pair20 in the outliner, then, in the

    Animation menu, go to Animate > Set Driven Key > Set... Anew window should appear, with pair20 appearing in thelower, "Driven" area. Now select the masterController in theoutliner, and in the Set Driven Key window, click on "LoadDriver." In the right section, next to "masterController," clickon "twist." In the bottom right, next to "pair20," click on"rotateY."

    What this sets up is a relationship where we can have themasterController's twist attribute controlling the rotateY of

    Creating a new attribute called 'twist' for themasterController. Note the channel box on right is blank.

    The channel box of the masterController now has twonew attributes.

    Setting up the driver and driven objects.

  • 8/10/2019 Dna maya tutorial

    13/14

    Tutorial 8 DNA: variations on a themeGal McGill & Janet Iwasa Fall 08

    13

    pair20. Now we need to set keys to determine the range ofcontrol.

    Make sure that the twist attribute of the masterController is set to 1, and the rotateY attribute of pair20 is set to720 in the channel box. Then click on "Key" in the Set Driven Key window.

    Now set the twist attribute of the masterController to 0, and set the rotateY of pair20 to 0 as well, and click on"Key" in the Set Driven Key window again.

    Now change the Twist value of the masterController. Itshould be controlling the twist of the DNA. A nice way to dothis is to click on "Twist" in the channel box (the text shouldhighlighted in black on a PC - as shown in the image on theright and blue on a Mac), and middle mouse drag in theperspective window. This should allow you to dynamicallychange the attribute.

    Set the Twist value to 0. You probably already noticed thatwhen all of the pairs Y rotation is set to 0, the DNA looksquite wavy. How can we fix this?

    The problem is due to the fact that when we originallycreated the helix, we moved the pairs in X and Z, and thesemovements were repeated along the length of the helix.Ideally, we'd like to keep the current values of translateX andtranslateZ when the helix is completely twisted, but havethem set to 0 for when twist is set to 0.

    Let's set up some more set driven keys to do this, but using MEL. If you take a look at your script editor, youshould 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

  • 8/10/2019 Dna maya tutorial

    14/14

    Tutorial 8 DNA: variations on a themeGal McGill & Janet Iwasa Fall 08

    14

    "setAttr" is short for "set Attribute" and sets, in this case, the twist attribute of the masterController to 1. ThetranslateX (or Z) value should already be set to whatever we want it to be when twist is 1, so we can go aheadand set the driven key:

    setDrivenKeyframe -currentDriver masterController.twist ("pair" + $i + ".translateX");

    In the 2nd half of the script, we're repeating the same thingafter setting twist to 0 and translateX of the pair to 0.

    The last thing that we want the masterController to do is toseparate 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 ourstrand separation, we'd like baseL and baseR to move inopposite directions from the origin. Depending on how youarranged your DNA, baseL may need to go in the +X, -X, +Zor -Z direction, and baseR in the opposite direction along thesame axis. Figure this out before the next step!

    Now we'll just write a little more MEL to have themasterController's 'separate' attribute control strandseparation. We will be using the exact same setDriventechnique as we have before.

    Type in the following script into the Script Editor (keeping inmind that youll need to replace translateX and 5 withwhatever axis and +/- value for 5 works in your case)

    for ($i=0; $i