Start a hosting plan from $3.92/mo and get a free year on Tuts+ (normally $180)
In Part 7 of the Game Character Creation Series we introduced facial animation to Kila using a joint base system. This opened up the possibility for her to talk and also show a wide range of emotions, something which is key to any character animation.
As you know, there is more than one way to approach facial animation for games, so in this tutorial we will focus again on adding a facial rig to Kila, but this time the focus will be on using morph targets, or as they are more commonly known - blend shapes.
1. Blend Shape Based Rig
Unlike with the joint based system, blendshapes don't rely on joint positions to influence the main model. Instead, what blendshapes offer is a more direct and accurate vertex based deformation, which can result in a much nicer, and more natural facial expression.
Rather than deforming the main model through external influence, you have full control over where each vertex is placed for each morph target. The main model then refers to these vertex positions and allows the user to blend to them, and even mix and combine then.
Although this may be a more precise and organic way to animate the face it can be more costly, as you will see. Each new morph target requires a new model, and if you require lots of facial movement this could mean introducing upwards of 30 or more new models into the scene. Increasing file sizes, and exported data.
Step 1 – Model Preparation
To add blend shapes to Kila will involve some adjustments to the current scene. To generate a morph target you must first create a duplicate of your model. This is then moulded into the shape you want to blend to, with the main model then referring to it as a reference.
At present Kila is a single mesh so to create a morph target you would need to duplicate her entire body. The problem is, if you are only working on the face area there will be a lot of wasted data coming from the rest of the model which also needs to be stored and exported.
To help reduce this data you can divide Kila, leaving you with only the head area to work on and influence.
Luckily the head of the model is a nice separate element contained in its own UV shell, with hard edges around the area where the upper body meets her shirt. This means you can safely detach the head without causing any issues to the model, or introducing unwanted breaks and creases.
- Begin by going to Modify > Evaluate Nodes > Ignore All. This will disable the IK, and other influences on the Kila rig.
- Select the model and then go to Skin > Go To Bind Pose. You are doing this to ensure the model is in the exact position it was when she was originally bound to the skeleton.
- With the model now reset, select it and press Control-D twice to create two copies.
- Rename these duplicates to Kila_Head and Kila_Body.
You should now have three versions of Kila in the scene. The first is the original which is still connected to the skeleton and has all the binding data intact, with the second and third being clean, detached versions ready to be worked with.
Note: You may have to unlock the attributes on the new models in order to move them as they will inherit their locked status from the original.
The idea is that you can split the new models and then reattach them to the skeleton, transferring the weighting information from the original, onto the new pieces. This means you don't have to worry about reworking the weighting again on the whole mesh.
First you need to separate Kila into the relevant pieces.
- Working on the Kila_Body model, select a polygon on her head.
- You can then quickly select the rest of the connected faces in the same UV shell by simply holding Control while Right Clicking and selecting To UV Shell from the marking menu.
- Continue this process now to ensure all the elements of the head are selected, including the inner mouth, teeth and tongue. Also ensure the eye lashes are included, but leave the eyes and hair separate.
- Once selected, delete this geometry, leaving you with just the body, hair and a pair of floating eyes.
Now repeat the process on the other duplicate you created earlier, but this time invert the selection, (hold Shift and drag over the model) before you delete the redundant geometry, leaving you with the just the head and chest area.
The models are now separated, which is ideal as the blend shapes can now be restricted to just the head geometry.
Before you move on, you can use this opportunity to make some final adjustments to the new models before they are rebound to the skeleton.
A good place to enhance the head would be between the eyebrows, so add just a little more geometry here to allow you to move each eyebrow more freely, without effecting the central vertices, or the opposite side.
All you need to do now is reattach these to the main skeleton and transfer the weighting information.
Ideally you want to bind the new models to the exact same joints as the original. It’s not essential, but it helps to keep things consistent and clean. A quick way to select the joints which directly influence the original is to use a little bit of MEL.
select –r `skinCluster –q –inf skinCluster`;
This is essentially two pieces of MEL in one command –
select –r will replace the current selection with something you specify.
skinCluster –q –inf skinCluster is asking with the –q (querey) flag which influences (-inf) are effecting the skincluster named skinCluster.
Once these are combined, as demonstrated above, the script will query which joints are connected to the skincluster on Kila, and select them for you.
- Once selected, you can then add the new Kila_Head and Kila_Body models to the selection and go to Skin > Bind Skin > Smooth Bind.
- Now that the models are all connected simply select the original model, and then the Kila_Body model and go to Skin > Edit Smooth Skin > Copy Skin Weights to transfer the weighting from the original to the new body.
- Repeat this again now, but copy the weights onto the Kila_Head model.
- Finally, go to Modify > Evaluate Nodes > Evaluate All to enable the rig controls, and test the weights have transferred successfully by moving Kila around, ensuring she deforms correctly.
- When you are happy to move on clean up the scene by deleting the old, single piece Kila.
This should be all you need to do at this stage. Kila has been split into two, making for a more economical blend shape setup.
Before you move on, quickly create a new copy of the head model and rename this to Neutral.
Once you enable the nodes again the head may move slightly as the rig is reactivated, having this copy now ensures you are always working with the base, neutral pose.
Step 2 – Your First Morph Targets
Kila is ready to go. She has been divided, reattached and you have your base neutral shape which means you can dive in and begin working on your morph targets.
When working on the joint based rig, this was the stage where you defined the dummy attributes which would then drive the joints. Pushing and pulling them to form the facial poses. This time around each new morph target will dictate a new pose, with the attributes coming later.
- Create a copy of the Neutral head model and call this Blink.
- All you need to do now is focus on working on the vertices to bring the left upper eye lid down over the eye ball, but not all the way down.
- Next raise the lower eye lid slightly to meet it.
For this stage make sure that symmetrical modeling is enabled, meaning you only need to work on one side of the head and the opposite side will be updated automatically.
You can activate symmetrical modeling, or Reflection Mode as it’s called in Maya, through the Manipulator tool options. Simply Double Click on the tool and scroll down the window to find Reflection and activate it.
When you’re done you will have a version of Kila's head with both her eyes closed. As you worked on the left side, the right should have updated automatically too, which is ideal as it saved you half the work.
Note: Don't worry too much at this point about having individual morph targets for the left and right sides, the key at this stage is to have a single shape with both sides edited.
That’s one morph target complete, so your job now is to work through the remaining shapes. The problem is if we look back at the poses created for the joint setup there is quite a list to work through, and these don't include the eye lids or eye brow variations.
- Jaw Open
- Jaw Slide
- Jaw Twist
Don't let this scare you though, because with some clever planning you can reduce the amount of work you need to do.
Before you begin, consider the resulting shape you are after. Some shapes can be generated, or at the very least be given a head start from others. As an example, once you have an open jaw morph target, this can be the basis for the O, Ahh or Ooo shapes.
For now focus on creating the following foundation shapes -
- Jaw Open
- Jaw Slide Left
- Jaw Slide Right
- Jaw Twist Left
- Jaw Twist Right
IMPORTANT: Do not Freeze the Transforms on any of your morph targets if you move them away from the original head location. Doing this will make the head model move away from its origin once the blend shape nodes are defined later.
Step 3 – Build Your Morph Target Library
With the foundation shapes created you can now think ahead to the next level of shapes, but before you do, you must connect these shapes to your initial Neutral morph target.
Doing this, and adding a blend shape node, it will allow you to combine and blend these foundation shapes to begin the creation of new ones.
- To begin, select all your current morph targets.
- Next add the Neutral shape to the selection.
- Now go to Create Deformer > Blend Shape. No need to open the options as this blend shape node is just temporary.
- If you now select the Neutral head model and look in the Channel Box you will notice a new blendshape1 node.
- Open this to reveal the morph targets attributes.
- Set Jaw Open to about 0.5. This will open the jaw, but not all the way.
- Now adjust the Ooo attribute to about 0.5 just to bring the mouth in slightly.
- Select the Neutral model now and duplicate it, renaming this new copy to O.
- All this model needs is a little bit of refinement and you have a new O morph target.
Each attribute represents a morph target, with 0 being no blend and 1 achieving the full shape.
The beauty of blend shapes is that even though the attribute is initially limited to between 0 and 1, you can go over this amount, and even into negative figures. All Maya does is continues the trajectory of the vertices so as you increase, (or decrease) the value, the vertices keep moving.
This can obviously have some hideous results, but can also be fun to experiment with.
Now set Jaw Open to 0.15, set Smile to 0.5 and Grit to 0.2.
By combining these three foundation shapes you have just produced what can essentially become the CDENSZ morph target.
With those simple examples I hope you get the idea of how a few key shapes, when combined, can give you the foundations for others and dramatically speed up your workflow.
Now it’s up to you to produce the remaining shapes needed on the list, along with some addition morph targets to help shape the eyebrows.
Note: If you are not sure what to produce, or how they should look, feel free to refer to the file Kila_Face_Blendshapes_Finish.ma (included with the project files.)
Remember not to worry about creating separate shapes for the left and right side of the face, once you have a single shape with both sides posed, we will look at a quick way to separate them.
Step 4 – Turn One into Two
By now you should have a great collection of morph targets in the scene, but what you don't have is the flexibility to animate each side of the face separately.
Luckily, splitting the targets you have, doesn’t mean repeating work, or spending an age recreating new morph targets.
- Select the Blink morph target and create a copy, renaming both to Blink_Left and Blink_Right.
- Select the Blink_Right model and then select the vertices which were edited to close the left eye. It doesn't need to be exact so a general selection will do.
- If you now look in your Channel Box, you will see under Blink_RightShape there is an entry called CVs (click to show). Click this now to open up the list of selected vertices.
- Select all these boxes now and set the value to 0.
- Repeat this now on the Blink_Left shape, selecting and resetting the vertices on the right eye.
What you should see are some, if not all of the boxes have values present. These represent the offset you created when you adjusted the vertices to create the initial blink shape.
The left eye should now open again, and be reset back to its default pose, leaving you with just the right eye closed.
It seems like quite a simple step, but rather than trying to generate two separate morph targets what we have done is turned one into two within a few seconds.
You can now repeat this on your other morph targets, dividing key shapes into two individual ones, as illustrated below.
What you should do however, is leave any which overlap the middle of the model, like the eyebrows for example. These will need to be divided in a slightly different way to help retain any movement you have added to the central vertices.
If you imagine you have the eyebrows raised, and then you divide these as shown above but leave the central vertices intact, once you then blend back to these targets the central vertices will move too far. This will be because they will move twice, and be offset once for each morph target.
What you need to do is ensure that the central vertices only move half way for each side, so when combined they will only ever move to the intended position.
As you can imagine, editing the CVs as shown previously could be a nightmare as rather than reset the central vertices to 0, you would need to work out what half each value should be. Luckily there is an easy way to do this, and you could also adopt this technique instead of manually editing the CVs if you prefer.
Note: Don't worry if this doesn't make any sense, It will become clear once you see this in action.
- If your Neutral model still has the temporary blendshape node connected you can delete this now by selecting the model and going to Edit > Delete By Type > History.
- You now need a new blendshape node created, so select all your morph targets and then add the Neutral model to the selection.
- Now go to Create Deformer > Blend Shape as you did before.
- Under the new blendShape1 node, set your Eyebrow Raised attribute to 1.
- At this stage both eyebrows will be raised on your model, with the central vertices also being effected.
2. Paint Blend Shape Weights Tool
There are two ways you can now remove the influence of one side of the target. One is to input the values directly in a similar way to how you did previously, and the other is to physically paint in the influence.
- With the Neutral head still selected go to Edit Deformer > Paint Blend Shape Weight Tool.
- Set Value to 0 and then paint over the left side of the head, leaving any vertices in the middle. What you will see is the morph targets influence gradually being removed. So in this example, the left eyebrow is back in its neutral pose.
- Now you can set Value to 0.5 and paint over the central vertices, ensuring they are only influenced by the morph target by 50%.
- You can now duplicate this head to store the pose and move it to one side.
- Focus back on the Neutral head now.
- Set Value back to 1 and click the Flood button. This will flush the head white, resetting the influence.
- Finally repeat the process, but this time focus on removing the influence from the right side.
This works in exactly the same way as the Paint Skin Weights tools. You effectively paint the influence the blend shape is having on the model. So white is the full influence, and black is no influence.
Using the Paint Blend Shape Weight Tool is just an easier and more intuitive way of adjusting each morph targets influence on the model. The main benefit for you is that your adjusting a percentage of the influence, not the absolute value, meaning you can quickly apply a 50% influence to the central vertices.
3. Component Editor
The second approach is to basically edit the blend shape influence values manually through the Component Editor.
- Undo any changes you made with the Paint Blend Shape Weight Tool so you are working from the beginning again.
- This time select the Neutral head and go to Window > General Editors > Component Editor.
- If you select the BlendShape Deformers tab you probably won't see much happening, that is until you select the vertices on one side of the head.
- You can now manually edit these values so one side of the head has full influence of 1 with the other having 0.
- Next select the vertices down the middle of the model and set these values to 0.5, so again 50%.
What you will see is a list of the selected vertices and the value of 1 next to them showing how much influence each morph target, or blend shape node has over it.
So here rather than painting the influence you physically adjusting the values numerically.
Those are just a few options available to help speed up your workflow. Whichever option you choose, you can now complete your library of morph targets safe in the knowledge that you won't end up with the middle, overlapping morph targets deforming unnaturally.
Step 1 – Connecting Your Morph Targets
Up to now you have been working on the Neutral model, but with your arsenal of morph targets at the ready it’s time to connect them to the main Kila head mesh.
You have been using blend shape nodes briefly already, but this time lets investigate the options a little further.
- First select all your morph targets.
- Now add the main Kila_Head model to the selection.
- Go to Create Deformer > Blend Shape as you did before, but this time open the Options window.
- Click Create and let’s see what the default settings do.
- Go back to before you created the blend shape node.
- This time, before you click Create, open the Advanced tab.
- Set Deformation Order to Front of Chain, meaning the blend shape will be evaluated before the actual body deformation.
- Now click Create.
- This time around, if you pose Kila and then attempt to make her smile, the deformation remains local and exactly what you need.
As you can see, the basic options are pretty self-explanatory. You can specify a name for the node, the origin and the basic target shape options. These, with the exception of the name, can be left at the default settings.
Initially things may look OK. If you select the blend shape node and adjust the sliders, Kila's head will move and deform to form the shapes you created. So everything worked, great!
What happens however, if you pose Kila and then try to give her a facial expression, like a smile? The head model deforms, but the whole mesh moves back to the default position.
This isn't ideal, but what’s happening is the blend shape deformer is being evaluated after the skin data. So the body deforms, but then the head ignores this and moves back to the target shapes origin.
In here you will notice that you can adjust the deformation order, so in effect telling Maya how and when the blend shape should activate in the models history.
Step 2 – Editing Morph Targets
This is just a short section, but one which is quite important.
Defining the blend shape node doesn't mean that the targets are then set in stone. You can continue to edit each target on a vertex level to tweak and adjust each shape or pose. You can even add a blend shape to the morph target to help shape it, and this will traverse through the hierarchy and to the main model.
The only time when editing becomes impossible is if the actual morph targets are deleted from the scene, which you are welcome to do once the blend shape node has been generated and you are happy with the shapes.
The blend shape node stores the vertex data, meaning the actual targets can be safely removed. Although I don't recommend doing this, as its always handy having the ability to come back and revisit morph targets if you need to.
Step 3 – Drive Your Poses
Once defined, Maya will automatically give you a nice neat window to help animate your blend shapes, all using helpful sliders.
You can open this window by going to Window > Animation Editors > Blend Shape.
The problem with this solution is it’s not as intuitive as the joint rig you created in the previous tutorial, mainly because, for example, you had a nice way to control the eyes through just one attribute. If you recall -10 was blink, 0 was open, 10 was wide open, all on a single slider.
If these are kept separate the result may be overlapping targets, so the eyes may try to be open and closed at the same time, which can give undesirable results.
The good news is you can generate the same rig as you did previously by using Set Driven Keys, except rather than driving joint positions you can directly drive the blend shape attributes. So in effect it’s a much simpler rig.
Now, I'm not going to cover Set Driven Keys or adding custom attributes again as we have already gone through these in depth in the previous tutorial, so if you are unsure please refer back to Part 7. You will however find that the HeadControls icon will already have all the attributes you need to get you started.
Step 4 – Body Shapes
That’s the face pretty much complete, but with blend shapes you can go so much further. As you added them to deform the face, you can also go on to build them into other areas of Kila's body.
This can be useful for allowing more customization of the character in game, so as an example, you could create morph targets to adjust her size, make her clothing tighter or baggier and also change the size of her breasts.
On a more serious note, these “corrective” blend shapes are really useful to help enhance the models shape as she deforms. This approach is used to help correct problem areas like the arms and shoulders, so as the elbow bends, the rotation of that joint then triggers a new blend shape which adjusts the shape of the elbow so it looks more natural. While doing this you can then also increase the size of her biceps to make them bulge.
You have now worked through two ways to generate facial expressions, the joint based approach and this, the morph target approach.
With morph targets you can see that you have much more flexibility, and can be more precise about how the final face shapes look. This can be handy if you are restricted on the number of joints you are allowed to use, but on the flip side the file size will begin to rise with each new shape you add. This means more data to export and be handled by the processor.
Another down side to blend shapes is that if the main model changes, the targets will all need to be recreated. Yes, you have the Bake Topology to Targets tool, but I wouldn't rely on it when making more complicated edits.
In short, there is no winner here. Both approaches have benefits and drawbacks, so what I would say is experiment with both and go with whichever you personally prefer.
The face rigged Kila can now move on and be fully animated, but there is one more area we will look at in Part 9 before we sign the rig of as finished, and that is her hair.