Before we continue, some info.
Required: Python 2.7
Navmesh - or navigation mesh; it's what you'll primarily be creating. Navmesh is used by the game to tell bots what areas they can move to. Navmesh will create holes where bots cannot move to, mainly objects but also slopes.
Navmesh comes in three different versions, which are found in AIPathFinding folder of a map:
- Infantry - tells bots where they can move on foot.
- Vehicle - tells bots where they can move in ground vehicles.
- AerialHeighMap - tells bots in aircraft where they can fly.
Nav statics - are clones of existing static objects in PR that feature a col3 - collision mesh used by navmesh.exe to generate the navmesh. If an object doesn't have a col3, the editor will use the object's bounding box as col3 instead when exporting the info for navmesh.exe. Original BF2 statics all come with this, but some PR statics do not. These clones are only temporarily used to export the necessary info for navmesh.exe. Simple objects do not require them.
IMPORTANT: Backup your entire map, as some files will get overwritten and some will be changed for the purposes of navmeshing.
It is advisable that you only do this when your map layout is final. Any major terrain or object placement change will mean the navmesh will be misaligned and will have to be redone. However, you can get away with small changes and also manually edit the navmesh to avoid this.
With that in mind, lets continue.
For this tutorial you'll need default editor install, the necessary files come with it as mentioned and the nav statics.
Nav Statics Download
Unzip this file to mods/pr_edit/objects. All of the _nav versions can then be found at mods/pr_edit/objects/staticobjects/_stuff. If your static doesn't have a _nav there then it's probably already got one as part of its original file.
You'll need to to copy two files - exportGTS.con and saveQuadNoP4.con from the Navmesh folder to the main Battlefield folder.
![Image](http://i.imgur.com/ybc8t.jpg)
AI folder
Before you load up your map in editor, copypaste the "AI" folder out of another PR map with coop support.
Inside it is another file called AI. Open it with Notepad.
We're only interested in the maxSlope strings as those control the maximum angle the navmesh will reach (slopes above that angle do not get navmeshed).rem ************** LEVEL SPECIFIC AI SETTINGS ***************************
rem aiSettings.setViewDistance 300
rem *** Init AI using current settings ****
ai.init 2
rem *** Set custom angle to avoid cracks in a road ***
aiPathfinding.setActiveMap Vehicle
aiPathfinding.map.maxSlope 35
aiPathfinding.map.addVehicleForClusterCost Tank
aiPathfinding.map.addVehicleForClusterCost ArmedCar
aiPathfinding.setActiveMap Infantry
aiPathfinding.map.maxSlope 45
aiPathfinding.map.addVehicleForClusterCost Infantery
rem ----------------------------------------------------------------------------
You can keep the default values most of the time, however if your map is hilly/mountainous, you might want to slightly up the values. If your map is urban and mostly flat, but has enterable buildings with upper floors, the angle of staircases leading to those floors also counts in. It's preferable to keep the infantry angle high, so the said staircases do not cut off upper floors.
Setting up the navmesh area
As much as you'd like to see the entire map being used, unfortunately navmesh comes with some limitations in size. Do not expect much if your map is a.) 4km in size b.) overgrowth or static objects heavy.
For this tutorial I'll be using Silent Eagle as an example map.
To begin, make sure SinglePlayerEditor plugin is loaded into editor. Go under Tools>Add-in Manager.
![Image](http://i.imgur.com/0tTLj.jpg)
To pick the area that will be navmeshed, use the Combat area under Level editor and create a combat area as you normally would, but only around the area intended for navmeshing.
Make sure you place it counter-clockwise and check UsedByPathFinding in Tweakerbar.
![Image](http://i.imgur.com/NJgLC.jpg)
As I've said, navmesh is limited in size, so on 4km maps it is advisable to only do the 'bare bone' layout; several interest points and a route between them as seen here.
![Image](http://i.imgur.com/ZUBmw.jpg)
Replacing your statics with nav statics
To replace a static, select the static.
In the right side menu at the very top click "Select all of the same type". This will select all of the objects identical to the one you've selected across the map. Then click "Replace object(s)" below the previous button. A list will pop up, navigate to the nav statics and find the one that corresponds with the original name, but with a _nav suffix.
![Image](http://i.imgur.com/xxNBk.jpg)
Note: not all objects have a _nav version and identical models use the same _nav (ie. blue_tarp and white_tarp objects use blue_tarp_nav)
![Image](http://i.imgur.com/xaf2L.jpg)
Continue replacing other objects the same way.
IMPORTANT: If your map uses _nl (no ladder) versions of BF2 statics (mostly MiddleEast urban maps), replace all those with the original ones, otherwise they will not navmesh. If your map uses _roofwalls statics which are placed on top of existing buildings, delete them as they will interfere and also cause the buildings not to navmesh.
"Snap" statics
An issue with open areas is that navmesh will get oversimplified there, causing it to float and miss terrain completely. To avoid this, use a simple object, like a lightpole and place it around to snap the navmesh to ground.
Best areas to place these are near or on roads or paths between areas. You can later weld together the holes created when editing the navmesh in 3ds Max.
![Image](http://i.imgur.com/AfEZr.jpg)
Making sure
Before we export, it is good to check if we missed any object or any area that might need a snap static. Do this by clicking on Render > Toggle Draw Collision Meshes > AI Mesh. Your statics should now have colored shapes around them, like this:
![Image](http://i.imgur.com/2sADY.jpg)
Look for objects that don't. Again, simple objects like walls do not need a col3/_nav clone, however beware of wall sections that feature doors - the door won't be recognized when exporting the info and the object will be exported as a box.
Another issue can be corner wall objects like this, which will again be turned into a box and cut off the entire corner area with it unless replaced.
![Image](http://i.imgur.com/k0Khg.jpg)
Before you go to the next step, save your map.
Exporting files necceseary for navmesh.exe
Switch to SinglePlayerEditor from LevelEditor, then on the right-side menu, click "Generate PathFinding". Wait a few minutes for data to export.
![Image](http://i.imgur.com/IlT6x.jpg)
You can now close the editor, but DO NOT SAVE.
Much like lightmapping, exporting the files will turn overgrowth into static objects, however while saving after lightmapping rarely saves the overgrowth as static objects, saving after this will do so every time.
Creating the navmesh
The exported files can be found in your map's folder as GTSData folder. Copy it, then go to C:\Program Files\EA GAMES\Battlefield 2\NavMesh\.
There create a new folder called 'work' (if it doesn't exist already) and inside create a new folder with the map's exact name. Paste the GTSData into that folder.
![Image](http://i.imgur.com/dU1h1.jpg)
Now go to the main folder (\Battlefield 2\NavMesh\). Before you start, there's two Python files that can be tweaked.
Open GenerateNavmeshLocal with Notepad. Tweak this line (self-explanatory)
# Change the line below to the mod you are working on
mod = "pr_edit"
THIS IS OPTIONAL - Open navmeshControl and search for this.
This line controls what navmeshes will get generated (AerialHeighMap is generated by default). For example, if you want an infantry only coop and thus only the Inf mesh, then remove the Vehicle bracket.# Perform opt-steps
modes = [ "Infantry", "Vehicle"];
modes = [ "Infantry"];
Now, run the CreateNavmesh.bat file. It will ask you for the mod and map name, type them in exactly. bfeditor will run, prompting you to select the mod you just typed in. Do so and that's it.
Depending on your CPU power, come back in a few days or two weeks. You can still play PR/run BFeditor in the mean time or run other stuff, but check the Task Manager for resource usage, navmesh.exe will probably hog 40-50% of your CPU.
Once the process is complete, navmesh.exe will run bfeditor by itself to export the navmesh to your map, so it's a good idea not to have it open already or run BF2/PR during that time.
Now you can move onto the next step - editing the navmesh.