MART Term 2, Lecture 2
Blend Shapes and the Dependency Graph

Blend Shapes

Most of the animation that we have done so far involves moving objects, whether it be bouncing a ball or moving joints around in a skeleton. Today we're going to look at blendshapes, which is essentially three-dimensional morphing: it lets us take the weighted average of the shape of two objects. Let's try it and see.

[screenshot: MART_T2L02_html_751bcb70]Take a polygon sphere. Duplicate it and move the duplicates apart (I used ctrl-d combined with shift-d). Leaving the original the same, change all of the duplicates to something more interesting than a sphere (only by moving points though: no extruding or splitting faces). Don't worry about making them very beautiful, but do make them different enough from the original and each other to be obvious.

[screenshot: MART_T2L02_html_4165d7ae]Now select all of the objects, selecting the base object (the sphere) last, and go to Create Deformer → Create Blend Shape ❐. There are quite a few interesting options here, but for now just name the node (I'm going to call mine sphereBlend), and click on Create.

[screenshot: MART_T2L02_html_m5b5b2519]This seems to do nothing to begin with, but click on the sphereBlend input of the sphere: you'll see that it has four attributes (well, five actually, but the fifth is the envelope attribute that we've seen in all the other deformers that we've looked at). These control the "amount" of each shape that is added to the sphere to give it its new shape. Try playing around with these values, and see what effect it has on the shape of the sphere. Even better, try animating them. The image on the right has maximum amount of all of the shapes I used.

Why did we duplicate our object to make the shapes? Because that is the best way to do it. Maya will compare the position of each point (or control vertex) in the two (or more) different shapes, so unless you've taken the same vertex and just moved it a bit, you are likely to get unexpected results. But let's try it anyway. Create a polygon cube, select it and the base shape, then go to Edit Deformer → Edit Blend Shape → Add (you may have to turn off Check topology in the option box). If you try playing around with the new parameter in the sphereBlend, you'll see that it gives very unpredictable results, because the objects have completely different numbers of points and connectivity between the points.

Rather than having to adjust the attributes individually in the channel box, there is an editor specifically designed for use with sets of blend shapes. Go to Window → Animation Editors → Blend Shape..., and you'll get a set of sliders which you can use to adjust your blend shape. Most of the buttons are fairly self-explanatory, so I won't bother to explain them here, except for one: the Delete button deletes the blend shape completely, and is very often not undo-able. So don't press it unless you mean it.

Extra Attributes

You may have noticed that all objects have an Extra Attributes section in the attribute editor. This is so that you can add any additional attributes to it, for whatever reason. I'm going to demonstrate this by creating a set of attributes that control my blend shapes.

What I'm going to do is make two pairs of blend shapes, and make them mutually exclusive: i.e., when one is on, the other is off. First I need to create an attribute. Select the sphere, and go to Modify → Add Attribute. Name your attribute (I called mine pairBlend1) and make sure that it's a float. As far as minimum and maximum go, it's up to you: usually, I set them to be -1 and 2 respectively. This may seem odd, but it is often the case that you want that little extra emphasis, so going beyond the normal range (0 - 1)is desirable.

Now go to the sphereBlend node, and set expressions on the two parameters. I set an expression on the nurbsSphere3 value of:

sphereBlend.nurbsSphere3 = nurbsSphere1.blendPair1

And another on nurbsSphere5 value of:

sphereBlend.nurbsSphere5 = 1 – nurbsSphere1.blendPair1

Thus when blendPair1 is zero, the value of nurbsSphere3 is zero and nurbsSphere5 is one. The opposite occurs when blendPair1 is one.

Now do the same for the other pair of shapes.

The Dependency Graph

Look now at the inputs of our sphere in the channel box: it should have several. But this list doesn't tell us how these things affect sphere, only that they do in some way. The dependency graph is how Maya remembers which inputs affect which objects, and how. In fact, the dependency graph is how Maya remembers the entire scene: everything in Maya is a node (or a combination of nodes) somewhere in the dependency graph.

Save this scene, we'll come back to it later. First let's looks at another scene that we used last term. Load:

You'll see that this is the spaceship that we made using polygon modelling last term. Zoom far out, and you'll see that it has a sphere round it, to give it a background. Click on the sphere (called stars), and then bring up the Hypergraph1 from the Window menu. The hypergraph is Maya's visualization of the dependency graph, and it is a very useful tool. Press a to frame all (below). What you should see is that every object in the scene has a box (node) in the hypergraph: spaceship, stars, each light, as well as some texture things that we're not going to worry about at this stage.

[screenshot: MART_T2L02_html_mfd715fb][screenshot: MART_T2L02_html_m16c1e9e6]Let's look a little more in depth at how Maya arranges the scene. In the menus on the hypergraph, go to Options → Display → Shape Nodes. This shows us that every object (for example, the star sphere) is composed of a hierarchy of two objects: stars and starsShape. These are known as the transform node and the shape node respectively. The shape node contains the geometry, so in this case it represents the shape of a sphere. The object is then moved using the transform node: this is the parent of the object; any transforms applied to it will also affect its children (starsShape). The stars transform node is essentially a group with only one member, which is starsShape.

There are more nodes which are not shown by default in the hypergraph: turn on hidden nodes (Options → Display → Hidden Nodes) and a few more nodes will pop up, namely the viewport cameras: like every other object that we can manipulate, they have their own (pair of) nodes.

[screenshot: MART_T2L02_html_m4ce8bc2f]Try parenting some things: for example, try (in the viewport) parenting the "engine light" to the spaceship. Look what happens in the hypergraph: the hierarchy is formed as shown on the right. The engineLight transform node is parented underneath the spaceship transform node. Note that both spaceshipShape and engineLight are children of the spaceship transform nodes: engineLight is not affected by spaceshipShape in any way, only by spaceship.

This may all seem very complicated: it is, and I'm afraid it's going to get worse. We're starting to investigate the intricacies of how Maya does what it does: with such a complicated piece of software, this subject is immense but also important. In order to determine how to best use Maya to do what you want, it is vital to have some idea of the methods that it uses internally.

Input and Output Connections

A node in the dependency graph can have two different types of connection: hierarchical connections (as we have already seen) and input / output connections. Unfortunately there is no way to view both at the same time, but instead there are two different methods for viewing the dependency graph in the hypergraph: we have been looking at the Scene Hierarchy view so far, but we can also view Input and Output Connections.

[screenshot: MART_T2L02_html_m1a556a3d]Select the stars sphere again, then click the appropriate button in the hypergraph window (right). The window will change, showing the input and output connections of the stars node. We can no longer see the hierarchical connection between them, instead we see the input / output connections of both.

[screenshot: MART_T2L02_html_m22bb174f]Each connection in the dependency graph indicates a dependency: the node at the end of the arrow depends upon the one at the start of it. Thus, in this example, the output of starsShape depends on polySphere1 (this can also be deduced from the fact that polySphere1 makes up the construction history of starsSphere). The final connection goes from the object's shape (starsShape) to surfaceShader1SG: this is related to the texture that the object has been given. We will go into texturing in more detail later in the term. It is worth noticing that we can delete an objects construction history in the hypergraph by simply selecting it and hitting delete.

Now let's look at the reason that you should regularly delete the construction history. Select the spaceship, and click Input and Output Connections again to refresh the window. You will now see the wonder that is our spaceship's construction history.

[screenshot: MART_T2L02_html_544836]As you can see, Maya has to cope with a huge list of dependencies regarding our spaceship. The longer this list gets, the slower Maya responds, as it spends all of its time calculating the dependencies. Thus, when you get to the stage that you know you will not need it again, delete the construction history. It is possible to delete individual items from the middle of the construction history: this will change the shape of the object, so watch it in the viewport as you do it. It can also make the system unstable: be sure to save your scene immediately before you try it.

Now open this scene:

[screenshot: MART_T2L02_html_52ef55ec]This is the scene that I got you to light last term. Open up the outliner to remind yourselves what is where, then open the hypergraph. The contents of the outliner and the hypergraph look very comparable at this stage. Now lets look at the shape nodes: Options → Display → Shape Nodes (you can see the shape nodes in the outliner too if you want: right-click and check Show Shapes). In the hypergraph, some of the shape nodes come out magenta, while some transform nodes don't have shape nodes. The reason for these two anomalies is indicated by the very faint (barely visible) line that connects the two. The middleShape node is instanced, so that the same shape appears twice in the scene, in two different places. Thus if we move around the points of one of them, both will change. Try this now: duplicate an object, but in the duplicate options, change from Copy to Instance. Now try editing the shape of the original (or the copy).

[screenshot: MART_T2L02_html_m441a6558]Go back now to the blend shapes that we made earlier, and see what the input and output connections of our base shape (the sphere) looks like. You will see that it is very complicated: much more complicated than we need to worry about. But it is useful to be able to pick out things that we do recognize: for example, we can see the four other shapes that we used in the blend shape, the original shape of the sphere, and the two expressions that we just set on the blend shape values (yes, expressions have their own node: EVERYTHING does!). Remember that we added two extra attributes to our sphere? Well, when we clicked on the sphere it selected the transform node and added the parameters to that. Thus, unusually, the transform node is actually connected to the inputs of the shape node, rather than just being connected hierarchically.

The concepts that we have looked at today are important, but they are difficult to grasp: you probably won't entirely get what I've been talking about until you have used Maya much more. If there were things in the lecture today that you didn't understand, try having a look around in the hypergraph every so often while you are using Maya. Try looking at scenes that have different things in them: maybe the crane scene that we put together, or the character rig with the tail. Also, every time you carry out an interesting or new procedure in Maya, have a quick look in the hypergraph and see what it did as regards the nodes themselves.

1Hypergraph Scene Hierarchy and Hypergraph Input and Output Connections give the same window but with slightly different options. Use Hypergraph Scene Hierarchy now.