Battlefield 2 Modding Tutorial 4 - Building the Bunker in Maya

**Battlefield 2 Modding Tutorial 4 - Building the Bunker with Maya (WIP)**

**By Lawrence Brown**

 Now that we’ve created our basic mod, it’s time to actually start making the assets to put in it.

 We’re going to start out with a simple building: the bunker. This will be an all-purpose building, the base providing cover from enemy fire with window slots allowing soldiers to shoot back, and also a small tower providing a better view of the battlefield, a vantage point for laying cover fire and sniping, and also a potential platform for mounting static weapons such as machine guns and TOW rockets.

## **Set Up:**

This tutorial is for Maya 6.0  and requires that you have installed all the Maya tools that shipped with the editor.

It appears that Free Maya Personal Learning Edition is no longer available.   Instead, Autodesk now offers a free trial with the software and students can continue using the free trial while in school.

To install:
 1. Copy the folder "Objects" to your "RawData" folder after downloading the zip file and extracting it into a folder on your desktop:  Maya\_Bunker\_files

 Note: If you already have an "Objects" folder in your RawData folder, please copy whatever files and folders are necessary to create the following path:

 C:Program Files\EA Games\Battlefield 2\bf2editor\RawData\Objects\StaticObjects\\_MyBase01\My\_Bunker. The folder "\_MyBase01" should also contain the folder "textures".

 The point here is to create the same exact directory structure from "Objects" on as that of your mod. This way when you import something into the editor, the resulting object and associated textures will get placed in the correct directories.

 2. Make sure that you have created the mod "MyMod" through the editor. If not, do so following the steps in "Battlefield 2 Modding Tutorial 3 - Custom Mod Set-Up" before proceeding.

==

**Modeling:** ==
We’re going to start with a simple sketch of the building. This could come from a designer on the team, or it may be something you draw up yourself. The point is, even if you are just modeling for yourself, it’s good to at least draw out a basic form on paper to help visualize what you’re trying to do. Here’s a sketch for the bunker:

<BunkerSketch.jpg>

Now that we’ve got a blueprint of sorts, we can begin modeling.

The first step is to create the main visible LOD (Level of Detail)

1. Launch maya and open up My\_Bunker\_01.mb. Here I’ve roughed out the shape of the bunker, creating the interior and exterior and a system of ramps to get to the top. Notice that I haven’t put in details like the windows or the crenalations at the top of the tower (the notches in the sides of the walls). At this point we just want the basic shape so that we can export and test the overall design. Since we will probably have to make changes, there is no sense wasting time on details that would have to be reworked later.

<MyBunker01.jpg>

1. Select the two pieces and combine them into one mesh by selecting “Polygons>Combine” from the menu bar.
2. Rename this piece “My\_Bunker”.

**Col0:**

The next step is to create the collision meshes. First is the projectile collision mesh, Col0.

1. Duplicate My\_Bunker and rename it “Col0”.

Since this is the projectile collision mesh, we want to optimize it by deleting any small details that we don’t need. If there were things like antennas or other small items attached to the building, we would delete these. We also want to simplify the meshes where possible. The less polygons the game has to test against collisions, the faster the server will run. This building is currently so simple that there isn’t much to optimize. Even so, we should still do the following.

1. Hide My\_Bunker so that we can clearly see Col0 and zoom in on the stairs. Remove all excess edges until the stairs become a ramp like the following:

Note: make sure you remove any extra vertices that may have been left behind.

1. Now select the edges highlighted in orange in the following screenshot and remove. The edges go all the way around the tower, so make sure you select all four:

<TowerEdges01>

When you’re done, the Bunker should look like this:

<BunkerCol0Opt01>

**Col1:**

We’ve completed the optimization of Col0. The next step is to create the soldier collision mesh, Col1.

1. Duplicate Col0. Rename the new object “Col1” if it doesn’t do so automatically. (Note: “Col1”, not “Col01”!)

Normally we would do further optimization on this mesh, but there is really nothing to remove since it’s so simple. More about this later.

**Col2:**

The last collision mesh to make is the vehicle collision mesh, Col2.

1. Following the same steps as earlier, duplicate Col1 and rename it “Col2” if it doesn’t do so automatically.

This mesh would also be optimized, but we’re not going to waste time on it now since it’s just for preliminary testing. Keep in mind that we will be going back and adding more detail to the visible LOD once we are satisfied that the overall design works. At that time we will also be deleting the current collision meshes and creating them again from the updated LOD. Reworking objects is just part of the modding process, so it’s best to get used to it now.

**Texturing:**

The next step is to texture the pieces we created. You may either continue your work or open “My\_Bunker\_02.mb” for this section.

1. Open the Hypershade and with the middle mouse button, drag a new Lambert shader to the materials window.
2. double-click on the new Lambert shader to open up the attribute editor and change the name to “concrete”:

<ConcreteShader.jpg>

Note: If you are using the Multilister instead of the Hypershade, make sure you are changing the name of the Lambert shader to “concrete”, not the Shader Group! If you use the Multilister, it should look like the following when you’re done:

<ConcreteShaderMulti.jpg>

You can change the color of the shader to anything you like. The color is just to make it easy for you to identify. All the importer is concerned about it the name.

1. Assign the concrete shader we just made to the three collision meshes.

Concrete is the name of one of the materials in the game, so what will happen is that the importer will read this name and apply the material to the collision meshes. This is why it’s so important that it is spelled right. For a complete list of materials, consult the Material Editor section of the BF2 Editor.

**The Visible Mesh:**

Now we have to texture the visible mesh. Since this is just a test and we know we are going to add more detail later, we are just going to apply a simple placeholder shader for now.

1. Hide everything but My\_Bunker so that it is easier to work on.
2. Enter “dnyUVPanel” in the command line and press enter (or click on the shelf button if you’ve made one) to open up the BF2 UV Editor:

<dnyUVcommand.jpg>

1. Make sure that My\_Bunker is selected, then in the UV window press the “Assign” button:

<UVassign.jpg>

What this does is creates a cgFX shader and assigns it to the selected object. It also should create a pointlight that is connected to the shader that you can move around to see how the lighting affects your normal maps. (Sometimes the light isn’t created. If it isn’t, don’t worry about it. It won’t affect anything.)

1. Open up the Hypergraph window and double-click on the cgFX shader you just created to open up the attribute editor:

<cgfxAttributeEd.jpg>

We need to assign some basic textures so that the bunker exports properly. There are a lot of options in this shader, but we’ll get more into that in a later tutorial. Right now we just want the basics.

1. In the “StaticMesh Parameters” section, click on the folder icon to the right of “diffuseTexture”. In the window that pops up, select “C:\Program Files\EA Games\Battlefield 2\bf2editor\RawData\Objects\StaticObjects\\_MyBase01\textures\MyBase01\_c.dds”:

<diffTexturePath.jpg>

1. Do the same for “detailTexture”, choosing “MyBase01\_de.dds” from the same folder.
2. Do this a third time for “normalDetailTexture”, choosing” “MyBase01\_deb.dds”. (“\_de” stands for detail and “\_deb” stands for detail bumpmap.)
3. Finally, click on the folder icon next to “colorLut” and select “C:\Program Files\EA Games\Battlefield 2\maya\CGFX6.0\cgfx\_textures\SpecularLUT\_pow36.dds”.

If you press “6” on your number pad to go into Textured-Shaded mode, your bunker should look something like the following screenshot. Don’t worry if the texture placement is different because we haven’t set up the UV’s yet:

<MyBunkerNoUVs.jpg>

1. The editor and the BF2 engine don’t like UV’s with zero surface area, so make sure My\_Bunker is selected, then choose “Edit Polygons>Texture>Automatic Mapping” from the menu bar. We don’t really care what the options are, but you may want to reset them to default if you’ve used this tool much. This is just a quick way to make sure that the UV’s of each polygon have some surface area:

<BunkerAutoMap.jpg>

Your UV’s should now look similar to this. Don’t worry if your texture looks strange or is all green. We’ll fix that in a minute. Just worry about the UV’s for now:

<MyBunkerUVs.jpg>

23. Unhide the collision meshes and do the same thing to each of them. Even though the collision meshes aren’t seen in the game, the engine doesn’t deal well with polygons with zero surface area when calculating collisions either. Automatic mapping will take care of this. It doesn’t matter what the actual coordinates of the UVs are, only that they have some surface area.

**Creating the Second UV Set:**

Now that we’ve laid out basic UV’s, the last thing we have to do texture-wise is create a second set for the visible mesh. More on this in a later tutorial. For now you just have to know that the diffuse texture in the shader needs one UV set and the detail texture needs a second one.

It’s important to note that only the visible mesh needs the second UV set. The collision meshes should only have one. If the collision meshes have more than one UV set, it could crash the game!

1. Hide the collision meshes again and reselect My\_Bunker. Select “Edit Polygons>Texture>Copy UVs to UV Set>Copy into New UV Set>Options” from the menu bar:

<BunkerCopyUVs.jpg>

1. In the window that pops up, enter “detail” in the text box and click “Apply and Close”:

<DetailTextBox.jpg>

It should now look something like this:

<MyBunker2UVs.jpg>

Again, if your textures look different, it doesn’t matter. When you do the automatic mapping, Maya may sort the polygons differently depending on the options chosen.

**Triangulation and Cleanup:**

We have finished the texturing, but there’s one more step we have to do before we can put everything together. The importer doesn’t read anything but 3-sided polygons on the collision meshes, so we have to fix this now.

1. Unhide the collision meshes if you can’t see them and select all three. (just the collision meshes, not the visible mesh)
2. From the menu, select “Polygons>Triangulate”. Maya will triangulate the mesh and switch to face selection mode.
3. Click somewhere off of any of the objects to deselect everything, then make sure that everything is visible and drag-select to select everything in the scene.
4. Delete history and freeze transforms if necessary to be sure we have clean geometry. You are now ready to put everything together.

**Setting up the hierarchy:**

The last step is to set up the hierarchy for the importer to read. It’s very important to follow these steps exactly because the importer reads certain information from the various names and expects things to be in a certain order. Make sure there are no spelling mistakes and to pay attention to where there are capitalized letters.

You may either continue with the scene you’ve been working on or open “My\_Bunker\_03.mb.

1. Unhide all parts. You also may wish to open the outliner to make it easier to organize things.
2. Select the three collision meshes and group them.
3. Rename the new node “nonvis\_”. Note the single underscore at the end of the name:

1. Create a locator and rename it “My\_Bunker\_\_Anchor”.

Notice that there is a double-underscore in the middle of the name. The text before the double-underscore is just the name of the object and can be anything you want. Anything after the double-Underscore is read by the importer and is used to create the appropriate code in the editor. In this case, “Anchor” is basically a pivot point, but can be moved around to tweak an object. For now just leave it at the origin.

1. Select the “My\_Bunker\_Anchor” locator and the “nonvis\_” node and parent them both under “My\_Bunker”.
2. Select “My\_Bunker” and group it to itself. Rename the new node “lod0”.

In a later tutorial we will be adding more LODs. For now we only need this one.

1. Now with “lod0” selected, group it to itself again and name it “geom0\_LightmapSize512”.

This is more info for the importer to use. In this case it tells the importer to create a lightmap texture sheet that is 512x512 pixels.

1. Create a second locator and rename it “root\_staticMesh”.

All static objects have one of these. There should only be one in each Maya scene because this is what the importer looks for first. If there is more than one, it will get confused.

1. Parent “geom0\_LightmapSize512” underneath “root\_staticMesh”.

Your hierarchy should now look like this:

1. Save your file as “My\_Bunker.mb”. (Not My\_Bunker\_04.mb! This is our “final” version, the one that we will import into the editor. You don’t want any numbers at the end of the file, or the object will end up being called My\_Bunker04 instead of My\_Bunker. Numbers at the end of a name may also confuse the game and cause strange results.)

You have now completed your first staticMesh. In a later tutorial we will import this into a custom level.

If you have any problems or want to compare your version to the finished version, open up “My\_Bunker\_Complete.mb”. You can use this file as reference for setting up basic staticMesh objects.

You are now ready to move on to “Battlefield 2 Modding Tutorial 5 – Importing the Bunker”.