XGen is an arbitrary primitive generator used by Walt Disney Animation Studios
for films such as Tangled™ and Bolt™, and by Pixar Animation in Toy Story 3™.
It allows you to generate complex sets of primitives or objects
using guide or groom techniques, and is ideal for intricate character details
like hair and stubble, or set dressing forests, quarries,
and other scenes with randomized natural elements.
In this series, we'll look at how to use the Maya integration of XGen
to generate a number of hairstyles for both male and female characters.
Open the file "01-XGen_hair_part1_start.mb".
Before we start, it's important to set your project to the provided scene folder,
as XGen creates a lot of local files that need to be referenced.
To use XGen, we need to turn on its plug-ins from the Plug-in Manager.
“xgenToolkit.mll” loads the toolkit itself along with the menu and shelf,
while “xgenMR.mll” enables mental ray rendering of XGen primitives.
To add hair to our character, we first have to create a description.
The description will define one set of primitives, in this case our hair strands,
that all share the same properties, such as their length, style, and density.
Go to XGen > Open the XGen Window.
The XGen window hosts all the tools needed to create and edit our XGen objects.
Select the head geometry and click Create New Description...
Name the description "XGen_male_basic",
and add it to a new collection named "XGen_male_basic_collection".
Collections allow you to group multiple descriptions together,
which is useful when you want multiple hair styles (possibly on different parts of the geometry
such as the scalp and face) to always be used together.
Think of each collection as a grouping that represents a specific hair style for that character.
Next, we need to decide on the type of primitives we want XGen to generate
for this particular description.
Splines are simple curves ideal for hair and can be controlled easily
using guides or expressions as points of reference for how they should look.
Groomable splines are similar to splines, but you can shape them using brush tools
that emulate a sculpting workflow, much like Autodesk Mudbox.
Custom geometry, spheres, and cards allow you to substitute more regularly shaped geometry.
The former two are useful for set dressing while the latter is useful for sprite-based hair.
In this case though, we're going to use regular Splines to generate 3D hair.
We'll also generate them randomly across the surface,
and control them via Guides that we'll manually place on the character's scalp.
A number of new XGen nodes appear in the Outliner
representing both the collection and description we created.
Notice that in your project folder, Maya creates XGen-specific files and folders.
Maya also creates markers on the geometry's faces, to mark areas set for primitive generation.
Now we need to place a few guides around the scalp
so that Maya knows how to shape the hair strand primitives we're about to generate.
We can do this using the XGen window,
which has updated to include a vast array of tools and modifiers
to customize the primitive generation.
In this case, we'll use the Add or Move Guides Tool.
Place a few guides around the scalp. These mark where our primitives will be generated.
Notice that they also appear in the Outliner as children of the description.
When you're ready, click the Preview button to generate some primitives.
Maya creates a number of short hair primitives scattered randomly across the head geometry.
It doesn't look like much now, because our guides are so short and all identical.
You'll also notice our first problem: Maya is generating hair all over the head,
including over the eyes and cheeks.
This is because, while the guides control the shape and density of primitives close to them,
they don't have fine control over the placement of these primitives.
To avoid this problem, we actually need to work with just the scalp portion of the head,
not the entire head.
In the Outliner, select the collection and delete it.
You'll also need to display non DAG objects and remove expression1, xgmRefreshPreview,
xgen_hair_phong, xgmr:xgen_geo1, and xgen_hair_phen.
Now in the Layer Editor, switch on the visibility of the scalp_GEO_LYR.
This gives us access to a duplicated version of the scalp geometry.
Notice that it's parent constrained to the head so as to follow its movements.
Select it, and recreate the same description and collection as you did before,
overwriting the old one.
Set both the head_GEO_LYR and scalp_GEO_LYR to Reference mode
so we don't accidentally select them.
If you place a set of guides again and preview them,
this time you'll notice that the hair appears only on the scalp.
However, it doesn't have much body to it.
We can give the hair primitives more volume by increasing the Density value to 30
in the Generator Attributes section.
This gives our character a nice little afro.
Next, let's change the style a bit.
First, clear the XGen preview to make the guides easier to see.
To modify a spline, select it then hold the right mouse button over it
and select "Guide Control Points".
Now, similar to a NURBS curve, you can adjust the spline via its control vertices.
Update the preview. Notice that the hairs around the guide follow it,
while interpolating back towards the short hair of the other guides.
Now style the other guides similarly.
Once you've finished with one side, you can use the Mirror Guides Tool
to mirror your modified guides across to the other side of the head.
In object mode, select the guide you want to mirror and then click the "Mirror Guides" button.
Delete the old manually-created guides while you're at it.
Once you're finished, you'll notice a few things with our hair style.
First, notice how the hairs don't follow the guides exactly.
The top is flatter than it should be, which is causing some of the primitives to clip the scalp.
This is because the primitives don't have enough control vertices to follow the guides.
In the Primitive Attributes section, increase the Modifier CV Count value to 20.
You'll also notice that there's some hair, particularly in the front,
that seems to be overgrowing the bounds we want.
This is because the guide provides shape for all hairs around it, including those underneath.
However, we can mask out these hairs that are causing us problems.
Turn off the preview to get a better look at the scalp.
In the Generator Attributes section,
click the arrow next to the Mask field's Expression button and select "Create Map".
Name the mask "harline_mask" and increase the Map Resolution to a value of 10,
then click Create.
Maya floods the scalp white, indicating that the entire scalp will generate hair.
This is stored in a UV-less PTex file denoted by the file path here.
Double-click the 3D Paint Tool and change the Artisan brush to solid, and Color to black.
Now color the area below the front guides to create a hairline.
Save the PTex map by clicking the save button.
This is important, as Maya refers to the map file to draw primitives.
As you can see, it no longer grows over his face.
If you'd like to readjust the hairline,
click the Paintable Texture Map button to recall the paint map.
Just be sure to save any changes you make back out to the map file.
At this point we'll also hide the scalp geometry
since we only needed it here to define the region to populate with hair.
As the simplest of hairstyles, this is a good start.
The only remaining problem is that the hair doesn't really look like hair,
so much as it does grey tubes.
Let's adjust a few settings to at least get it looking a little more realistic.
First, in the XGen window’s Primitive Attributes section, set Taper to 0.7, and Taper Start to 0.3,
to scale down the tip of each primitive starting about a third of the way, just like real hair.
Decrease the width to 0.08 to thin the primitives out.
Next, let's color our hair.
When you create an XGen description, Maya automatically assigns it an XGen hair shader,
which you can find in the Hypershade.
Using the Attribute Editor, change the default grey diffuse color of the attached custom phen shader
to a dark brown.
You'll notice the hair in the workspace doesn't update to the new color.
In order to see the generated primitives' color, we need to change to Viewport 2.0.
To clear up our display,
return to the XGen window and turn off Tube Shade in the Primitive Attributes section.
We'll also need to adjust both Specular Colors of our shader a bit,
and set their respective Cosine Powers to 50 and 70 to give the hair a more subtle sheen.
We'll cover rendering more in-depth in a later movie,
but if you'd like to do a quick render of the scene,
you must first go to the Output Settings section of the Preview/Output tab
and click the Primitive Bound’s Auto Set button to display the full length of hair at rendering.
Also make sure to render using the mental ray renderer, with the Image Format set to EXR.
In the next movie, we'll show you how to create a slightly more complicated punk hairstyle
using a clumping map, as well as how to use groomable splines to create some stubble.