Tutorial: Using Colliders in StretchMesh
When setting up a character, it's often very difficult to preserve volume and create a
sense of skin moving over underlying anatomy. Using StretchMesh colliders, this problem
can be quickly and easily addressed.
For this tutorial, we'll look at a simple character model with very large shoulders. Shoulders
can be particularly challenging because the shoulder joint has three degrees of freedom, which results
in severe deformations.
First, We'll pull up our model. The character has been skinned to a basic rig using Smooth Bind and then StretchMesh has been applied.
To create the illusion of underlying anatomy, we will use StretchMesh colliders to represent the deltoid and preserve volume as the shoulder
undergoes deformation. In this case, we will use Curve Colliders. Curve Colliders are faster to calculate than equivalent Mesh Colliders,
so they should be used instead of Mesh Colliders whenever possible.
Just to recap, here's a list of the things that we are beginning this scene with:
- Polygonal model
- Simple joint skeletal structure
- Smooth bind model to the joints
- StretchMesh applied to the model
THE CURVE COLLIDER
A good starting point is the anatomy of an actual human arm, as this will inform what the
shoulder looks like as it moves. We will be creating a simplified version of the musculature, so a
good grounding in anatomy will help us as we rig our arm using StretchMesh.
The basis for a Curve Collider is a nurbs curve. The Curve Collider has radius
attributes corresponding to each edit point of the nurbs curve. Using the radius
attributes, we can reshape the Curve Collider to get a shape similar to a muscle.
The Curve Collider maintains a connection to the nurbs curve, so changes to the nurbs curve are
reflected in the Curve Collider. By attaching the nurbs curve to the joints, we can deform the
Curve Collider much like the deltoid deforms.
- Begin by creating several curves that will roughly cover the area that you'd like to keep "inflated." In this case, we've made four.
- Once the curves are positioned properly, we'll need to smooth bind them to the skeleton through Maya's normal Smooth Bind option.
- Now we will turn our curve into a Curve Collider so it will affect the mesh.
- Select the mesh with the StretchMesh applied to it, and then shift-select the curve.
- Go to your Kickstand menu, and select Add Curve Collider in the Colliders sub-menu.
The Curve Collider appears as a blue tube surrounding the nurbs curve. The vertices of the mesh will be pushed
away from the curve until they are outside of the Curve Collider. It is important to note that the Curve Collider appears to be
intersecting the mesh, this is because collisions are calculated on the vertices of the character mesh, so while
the vertices of the mesh are outside the Collider, the edges and faces in between might intersect with the Curve
Collider. The radius of the Curve Collider can be modified to get the desired results.
The Curve Collider itself is not renderable, and only exists as a visual representation of the effect it
will have on the mesh. For the next step, I will turn off the display of the character mesh.
- Upon selection of the Curve Collider, we can see a set of radius attributes in the Channel Box. By changing the radius
attributes, we can change the shape of the Curve Collider to approximate the deltoid.
- We will repeat this process for each of the four curves in our shoulder.
The vertices of the mesh will now slide over the Curve Colliders, helping to maintain
volume and give a sense of underlying anatomy.
We can also modify the influence of the Curve Colliders by selecting
the character model and then selecting Paint -> Paint Collider Influence in the Kickstand menu. Vertices painted
white are fully affected by the Curve Collider, vertices painted black are not affected at all, and vertices painted
gray will be partially affected. As an optimization, you can paint the Collider influence to black for parts of the mesh
that will never be affected by the Collider (legs and head, for example). Collision calculations will not be performed on
vertices painted black which will improve performance.
THE MESH COLLIDER
When the desired collision shape is too complex to be represented by Curve Colliders, Mesh Colliders can be
used. A Mesh Collider can be any arbitrary shape (watertight meshes are best), but they are more computationally
expensive than Curve Colliders or Sphere Colliders, so they should be used sparingly.
To demonstrate Mesh Colliders, we will add a bicep to the character's arm which will flex when the forearm is
rotated. We will accomplish this by adding a blendshape to the bicep which will be driven by the rotation of the forearm.
- First, let's make an approximate muscle shape.
- Next, we'll make a blendshape for the bicep that represents the flexed shape of the muscle.
- We need to set up our BlendShape using Maya's Create Deformers menu.
- Now we're going to make a Set Driven Key expression that will flex the bicep when the character rotates his forearm.
- The only thing left to do is make the bicep itself a Mesh Collider that will affect the body's geometry.
- Select the character body, then shift-select the mesh you want to make a Mesh Collider... in this case, the bicep.
- Go to the Kickstand Menu and select Add Mesh Collider.
Hide the actual geometry of the Mesh Collider and flex the arm a little bit. You will notice the arm bulging as a result of
the Mesh Collider. For additional control, there is a StretchMesh attribute called "mshColliderPad" which can
be used to inflate the Mesh Collider. For example, if mshColliderPad is set to 0.1, the vertices of the Mesh Collider
will be moved out along their normals by 0.1 units (the actual Mesh Collider geometry is not affected, just
the geometry used in the collision calculation).
The influence of a Mesh Collider can be modified per-vertex according to the as described above in the Curve Collider section.