Create an Army of Toy Soldiers

Login to Follow
Last modification: 5 Apr, 2018
  • Film & VFX
  • General
  • Scripting
  • Shaders
  • Maya
Skill Level
  • Intermediate

Tutorial by Lee Griggs Thanks to Pedro Fernando Gómez for his assistance with XGen.

Parts of this tutorial will not work with the current release of MtoA. It will be fully compatible with the next release. In this tutorial you are going to regress to a fun part of your childhood when you may have enjoyed playing with toy soldiers. Unlike your childhood, you will be using XGen to arrange the soldiers into interesting formations using expressions and texture maps as masks. We will also cover ways to add color to the individual soldiers using expressions and texture maps. For some real world inspiration you should also look at some of the work by this artist and also this artist. Both artists use toy soldiers, among other things, to create interesting works of art. The tutorial is broken up into the following chapters: Creating the Archive Files Creating the XGen Description Generator Attributes Assigning Random Colors to the Soldiers using an Expression Using an Expression as a Mask Using a Texture Map as a Mask Workflow issue - Primitive Bound

This video demonstrates IPR rendering of an XGen scene containing soldier primitive archives.

The toy soldier models are available to download at the end of this tutorial. Remember to always share your toy soldiers with your friends and not hog them to yourself.

Creating the Archive Files

Start off by opening the toy soldiers file in Maya. We need to convert the individual soldier models to XGen archives first, so that we can then play with them in XGen.

Select each soldier individually and go to XGen>Export Selection as Archive. Choose an archive name and destination folder and select Export.

Creating the XGen Description

Create a polygon plane and scale it to the size that you want the soldiers to fill. Increase the number of polygon plane subdivisions in Height and Width to at least 5. The number of XGen archive primitives is related to the number of subdivisions in the polygon plane. If you notice that your soldiers are not filling the entire size of the plane, then you will need to add more subdivisions to the polygon plane.

Polygon plane with only 1 subdivision. Soldiers do not fill the plane Polygon plane with 5 subdivisions. Soldiers fill the size of the plane

With the polygon plane selected, go to XGen>Create XGen Description. Choose Custom Geometry/Archives (use for any model you have created).

It is good practise to lower the Percent value in the Preview/Output tab before continuing. If the Percent value is too high you may find that your computer will stall due to the large number of primitives generated.

Under Archive Files, select Add and go to the location where you saved the soldier archives previously.

It is possible to change the color of the icon for each soldier and even add an image icon that represents each archive. To do this, right click on the red square for one of the archive files and choose Edit.

Click on the Thumbnail folder icon and choose a bitmap that represents each soldier. In the examples below, you can see that we have screen grabbed the Maya viewport for each soldier and saved those images to files. We can also change the color of the icon and increase its size by adjusting the slider above:

Density Increase the Density to around 500. This will increase the number of soldier primitives on the polygon plane.

Density 500 Density 1000

Positioning the Soldiers


Generator Attributes

When Generate Primitives is set to In uniform rows and columns the Spacing attribute replaces Density. Increasing the Spacing attribute increases the distance between the primitives.

Generate Primitives 'Randomly across the surface' Generate Primitives 'In uniform rows and columns'

Assigning Random Colors to the Soldiers using an Expression


More information on how to do this can be found in the Assigning Random Colors to Primitives tutorial. Create an Ai UserData Color node and connect it to the Color attribute of the Ai Standard shader that is assigned to the soldiers XGen description.

Ai UserData Color node connected to Color attribute of Ai Standard shader

Type color in the Color Attr Name of the Ai UserData color node. We will use the same 'Color' name in the XGen description.

Add the name 'color' to the Color Attr Name in the Ai UserData Color node

MtoA will not gamma correct the Ai UserData Color node, therefore you will need to add a Maya Gamma Correct node in-between the Ai UserData Color node and the Color attribute of the Ai Standard shader as shown below. Change the Gamma RGB values to 0.454.

Render the scene. The soldiers are black because the Ai UserData Color Default Value is black. We need to connect it to the XGen description using the Custom Shader Parameters in XGen. Click on the Preview/Output tab in XGen and open up Output Settings. Underneath you should see the Custom Shader Parameters. This is where we will add our expression.

Custom Shader Parameters

In the Name text field, type the same name that was used for the Color Attr Name with the Ai UserData Color node. In this case we used the word 'Color'. Click on float and change it to Color because this is the attribute that we want to change.

Custom Shader Parameters set to Color

Click on the XGen Expression Editor icon (below) to the right of our new 'color color' parameter and add the following text in the Expression Editor:

$factor = 0.1920; $a=[rand( 0.3, 0.65 ,$id)*$factor,rand( 0.4, 0.45 ,$id+1)*$factor,rand( 0.25, 0.55 ,$id+2)*$factor];#-1.0,1.0 $a

XGen Expression Editor for the custom color

Render the scene. You should now see that the colors of the soldiers are randomly created based on the rand values that we used above.

Working with Masks

Using an Expression as a Mask We can also use an expression to define how many soldiers appear on each polygon face. Click on the Expression icon (below) to the right of the mask slider control and type the following text in the XGen Expression Editor:

$border = 0.1150; $u > $border && $u $border && $v

With each face you can get the UV coordinates with $u and $v. With this expression, you only populate places where U is greater than 0.2 and less than 0.8 and V is greater than 0.2 and less than 0.8. This way we are getting a square in the middle of each face of the polygon plane.

$border = 0.1000 $border = 0.2000
Using a Texture Map as a Mask

We can also use a black and white grid texture to map out a formation for our army. Click on the downward pointing arrow (below) to the right of Length. Select Create Map... (it is important to note that this will only work if the plane has a Maya shader assigned to it).

The Map Name should say 'mask'. Increase the Map Resolution to around 200. This sets the resolution of the PTEX map in texels per-face. When using high resolution textures, use larger Map Resolution values. After you have done that, click on Create.

Grid texture map used as Density Mask Checker texture map used as Density Mask Checker texture map used as Density Mask

The example below shows another example when using a color texture to drive the density mask.

Circle map used just for color (primitives placed 'In uniform rows and columns') Circle map used for both color and density (primitives placed 'Randomly across the surface')

If we invert the map used for the mask we can get transparency in the white areas used for the color map.

The map used for the mask is inverted and therefore soldiers do not appear in the black areas.

Workflow issue - Primitive Bound

In the render below, you can see some 'clipping' in the top right corner. This is because the bounding box area is set too low and the soldiers are not being rendered outside of this area. Increasing the Primitive Bound resolves this problem. This can be found in Output Settings under the Preview/Output tab.

Primitive Bound has not been set to a large enough value for the XGen archive primitives

That concludes this tutorial on how to create masks and colorize primitive archive toy soldier models in XGen. I hope you had fun with this tutorial. However, its now time to put your toy soldiers away and clean up your bedroom!

Example Renders (1.4MB)


Posted By
  • Maya
  • General
  • Scripting
  • Shaders
1 Comment
To post a comment please login or register
| 3 years ago
How the hell do I download