In the previous movie, we created long hair for our female character and styled it using modifiers.
In this movie, we'll explore animating the XGen hair using nDynamics.
Make sure you set your project folder to the provided scene folder,
then open the file "01-XGen_hair_part4_start.mb", or use your own file from the previous lesson.
While this makes for a nice static hairstyle,
it wouldn't be very useful in animation scenarios where you would want it to react to animation,
surrounding forces, or settle naturally with gravity.
Luckily, we can use Maya nDynamics to achieve these types of behaviors.
nDynamics uses a Maya nucleus solver to dynamically simulate complex scenarios,
such as hair, particles, and cloth.
We can leverage this system with XGen in two ways.
Using a top-down approach, an nHair system controls the motion of the XGen guides
through dynamic curves. This is quick to set up, but offers only coarse controls.
Using a bottom-up approach, special modifiers control the hair primitives directly.
This gives us greater customization by affording us more granular control
over the actual density and dispersal of curves.
In this movie, we'll focus on the former.
In the Guide Animation section of the XGen window, turn on "Use Animation".
This enables "Live Mode" as well as the Hair System buttons.
Next, click the "Create Hair System" button.
Maya gives us the option to connect the resulting hair system's follicles to NURBS curves,
Paint Effects strokes, or a combination of the two.
In this case, we'll create a system of NURBS curves based on our XGen guides.
Click the "Make Curves Dynamic" button.
Maya creates an nHair system derived from the guide curves of our description.
Maya also generates a collection of follicles under the xgGroom node
with associated NURBS curves and an nDynamics nucleus node.
Before playing the scene, go to the Time Slider section of the Preferences.
We'll adjust these settings based on the kind of performance your computer is capable of.
Set Playback Speed to "Play Every Frame".
This tells Maya to evaluate every frame of the simulation, ensuring solver accuracy.
On less powerful machines, set Max Playback Speed to "Free".
This will ensure Maya can take all the time it needs to play through the animation.
On more powerful machines, you'll want to lock the Max Playback Speed to 24 fps,
to keep the frame rate consistent.
Now play the simulation.
Maya only simulates the hair NURBS curves derived from the XGen guides.
For a better view, let's turn off the XGen preview for now.
Notice that some of the hairs burst out in all directions.
This is due to the initial settings of our hair system and nucleus solver.
Select the nucleus solver and in the Scale Attributes section, set Space Scale to 0.01.
This will better match our simulation's unit scale (meters),
relative to Maya's working unit scale (centimeters).
We'll also increase Substeps to 8 and Max Collision Iterations to 10.
This will increase the number of calculations performed per frame of animation,
as well as allow more collision iterations, thus increasing the accuracy of our hair simulation.
This time the hair doesn't burst out but rather falls down into the character's head.
Naturally we don't want the hair falling into the geometry,
so select the bust and in the nDynamics menu set, go to nMesh > Create Passive Collider.
This adds the bust to the nucleus solver's calculations as a nRigid node.
The hair now impacts the head, though it's falling over the face like a mop.
In order for the hair to maintain its shape,
we'll need to adjust some of its dynamic properties found in the hairSystemShape.
First, set both Stretch and Compression Resistance to 100.
This strengthens the curves to fight deformation, such as the pull of gravity.
In the Forces section, set Mass to 0.05 to make the hair substantially lighter.
Play the simulation again. The hair now swings less violently and settles more quickly.
Next, in the Start Curve Attract section, set the Start Curve Attract value to 0.05.
Similar to how hairspray holds hair in place, this tweaks the curves' tendency
towards maintaining their initial shape.
Finally, back in the Forces section, set the Damp attribute to 0.5.
This dampens the energy contained in each curve over time,
meaning the hair will lose speed much more quickly than before,
which helps remove the "swinging" effect we were getting previously.
Rewind the simulation and play it back.
The curves now settle a bit, but for the most part retain the shape of our initial hairstyle.
To double-check that it's still dynamic, let's gradually generate some wind in the scene.
Go back to the nucleus node and, in the Gravity and Wind section,
set a key on Wind Speed and Wind Noise on the first frame.
Now at frame 48, set Wind Speed to 200 and Wind Noise to 10.
Set another key on both attributes.
Combined with the Wind Axis value here, this will ramp up a sustained gust from left to right.
The hair is barely pushed across the face as the wind ramps up.
This is because our settings are tuned specifically with the objective of keeping the hairstyle's shape.
To make the hair really blow in the wind, select the hairSystemShape again.
On frame 1, set a keyframe on both the Damp and Start Curve Attract attributes.
On frame 48, reduce both attributes to 0 and set another key.
Rewind and play the simulation again.
This time, as the wind ramps up, the hair blows more dramatically.
Now that we know the curves driving the hair are acting the way we want,
we just need to see how the hair primitives will look.
Go back to the XGen window and update the preview again.
The primitives still appear in the hair's default configuration.
This is because we haven't attached them to this new dynamic hair system yet.
Select all the nHair NURBS curves.
Then in the Guide Animation section, click the "Attach Hair System" button.
Regenerate the primitives.
Now they properly interpolate based on the nHair curves.
This dynamic hair system now reacts to the body's movements and forces around it.
However, what happens once we've finalized our simulation?
As with most dynamic systems, Maya requires playback of the frame before it
to dynamically calculate how the hair should move in its current frame.
This means you can't jump around to specific frames of the timeline
and expect an accurate solve, which can be frustrating.
Furthermore, in a typical pipeline,
you'd prefer to strip out as many components as possible to keep our scene lean and quick.
In animation, both these issues are typically addressed by caching, or baking,
animation directly onto geometry, joints, and simulated objects.
For XGen, the process of caching basically records the movements and deformations
of guides and stores them in external files that Maya can reference,
rather than having to calculate in-real-time.
This lets Maya focus on other tasks, like rendering, and thus improves performance.
There are two types of caches we can consider when working with hair:
nCache or Alembic cache.
We could use an nCache to pre-record the movements of the nHair curves themselves.
This is useful if you're doing iterative simulations on the dynamic hair curves only.
Or use an Alembic cache to pre-record the movements of the hair guides.
Since our simulation is finalized, we won't really need the nHair system anymore,
so we're going to go with the latter solution and just cache the XGen hair .
Select all the nHair NURBS curves again.
Then go to Pipeline Cache > Alembic Cache > Export Selection to Alembic.
Save your alembic cache to the cache directory of your project,
and make sure that you set Cache time range to cover your simulation.
Maya plays through the animation as it caches the hair guides.
When complete, turn off Live Mode.
Maya now looks for an external Alembic cache in order to drive the hair guides.
Click the folder button and select your alembic cache.
Additionally, select the nucleus node and disable it.
Maya plays back the hair guides' movement.
You can also jump to specific frames in the animation,
and Maya is still able to show you the hair primitives' state at that frame.
Your scene is now ready for rendering or playblasting.
As you can see, breathing life into your XGen hair through nDynamics is relatively quick and simple.
However, you'll notice some of the hair penetrating the bust
despite the fact that it's a passive collision object.
Fixing a problem like this can require more granular control over the nhair generation process,
as well the simulated collision steps, than this top-down approach can give us.
In the next movie, we'll animate the XGen hair using a bottom-up method
that will afford us this greater degree of control.