Navmesh Editing Overview

Navmesh Editing Overview

Based on Info from Clivewil, edited by Dnamro

Tools: BF2Editor, Python, 3d modeling software (3ds Max 7 is used for examples in this tutorial)

Before we start...

This tutorial assumes you know the basics of how to use a 3d modeling software package that uses the common wavefront obj format such as Maya, 3ds Max or Blender. This tutorial also assumes that you have set up your editing environment have generated the initial navmesh:

Setting up the editor for adding Singleplayer

Getting Started with a Navmesh

Generating a Navmesh

 There are many 3d modelling tutorials for Blender, Max or whatever your preferred 3d modelling software of choice on the internet to get you started.

**This tutorial on Blender Navmeshing is good:**

Blender Battlefield Navmeshing Tips

It can also be helpful to understand the wavefront obj format for a navmesh file:

Understanding the Obj format of a Navmesh

Naming conventions used in this tutorial: disregard any quotes or parentheses unless instructed otherwise. If i have written 'example' then you just type example without the quotes. Simple stuff indeed.

 When I state a max tool or modifier name, I will usually capitalise it, i.e. "...select the edge and Divide it..." - this means to use the tool named Divide, which in this case will be available when you are in 'Edge' mode. Other modes may also have similar tools, i.e. Face mode also has a Divide tool - make sure you are in the correct mode before you start hacking things into bits. Dividing an edge and dividing a face give a very different result.

3DS Max Note for Older versions:

 Older version of 3ds Max (7, 8, 9) often runs like a lethargic slug when displaying large or complex objects in its viewports. To speed things up a little, set each viewport to show objects as Smooth + Highlights, Edged Faces off, and Grid off. The default keys keys are F3, F4, and G respectively.

***Always keep a backup version of ANYTHING you are about to change, before you change it.***

```
Index:

Part 1 - Preparation and Import

Part 2 - Know Your Enemy
    Multiple Islands

    Open Edges

    Folded Polys and Bad Joins

    Invisible Edges

    Over-optimisation

Part 3 - Exporting Your Navmesh

```

Part 1 - Preparation and Import

 Preparing the Max Materials:

When a navmesh is first imported into the 3d modeling application, it appears completely white and is difficult to make out what is what. I suggest creating a special material to apply to your navmesh to make it simpler to understand what you are looking at - and if you intend to do several navmeshes, then put the materials into your 3d model tool materials library for later use. These tutorials are going into the process in more detail:

Understanding Navmesh Materials

Blender Navmesh Materials

Setting Navmesh Materials in 3dsmax

**Importing your navmesh:**

After you have started your 3d Modeling software and setup materials as in the previous step, you can import your first part of the navmesh. On a good day there will be only two parts; Infantry and Vehicle. (On a bad day there will be additional parts which you must either import and attach, or create by hand)

The import procedure is the same for any navmesh object, which includes the preopt and debug objects too. For most 3d modelling tools, the obj files will need to be imported. You will need to user your import fuction To import the Infantry mesh, select the .obj file format, browse to the BF2\_Folder\NavMesh\work\YourMapName\GTSData\Output\Infantry.obj file

These tutorials explain the how to use the obj import function for specific 3d modeling software:

3dsMax Navmesh Import

Import a Navmesh with Blender

You will be prompted to name this object, so name it 'Infantry'

Repeat the process for the vehicle mesh, and name it 'Vehicle'

 Apply the 'Default' material to both meshes and confirm that the appropriate areas have the correct materials, i.e. a blue ocean is correct. A green ocean means your materials have gone AWOL. Re-check your settings and re-import. If either mesh is 'inverted' or 'flipped' i.e. the polys are facing downwards instead of up, simply select its element and Flip the faces. (See the Multiple Islands section for details on element-selecting.) An inverted mesh is often an indicator of folded or badly edged polys, so be prepared to look extra hard for those particular problems on these meshes.

Hide the Vehicle mesh so we can concentrate on the Infantry mesh alone. Later on you can hide Infantry and work on Vehicle. On some occasions you will want both visible simultaneously, but for general work it's better to keep max as lightly loaded and fast as possible. The pic below shows part of a typical Infantry mesh; this one is from Operation Harvest. Materials are correctly assigned but there was a bad bridge which needed attention (already partly repaired in this pic)

A typical infantry navmesh looks like so:

 Part 2 - Know Your Enemy

Here I will attempt to show the types of errors you are likely to encounter, and mention ways of fixing them. Due to the chaotic nature of navmeshes, your own mesh may have all, some, or none of these faults present. Likewise, there are usually several ways of doing the actual repairs and it is dependent on the navmesh itself and your 3d skill as to how you go about rectifying the problems. Feel free to use your own methods - but if you already know best, why are you wasting time here? Off you go, you little troubleshooter you...

--- MULTIPLE ISLANDS ---

 Our first task is to find out how many 'islands' (separate objects) the mesh contains - any more than one will cause a crashed game. If you are doing complex work on a navmesh, it is possible to introduce some of these yourself without realising it. If during your tests your mesh suddenly crashes the game, do another check for these and make sure none have crept in. Even a single stray face counts as an extra island.

\*It is up to you to exercise good judgement when determining what is 'significant'  with regard to extra islands in your meshes and whether to delete them or try to rejoin them back to the main mesh. There are several reasons why an island may be separate (or not even included at all) but the two main reasons are -

1. It is impractical. For example, sections of vehicle mesh may be removed if the navmesh generator (nav-gen) has determined that a vehicle could never reach that location due to obstructions blocking the path, or too steep an angle to climb etc. - However tempting it may be to simply link these sections back in, if they were legitimately excluded then you may effectively ruin the map by reinstating them. You may end up with traffic jams as bots all converge on an area that none of them can realistically enter. If you are determined to have access to that particular area, you may need to modify the map in some way, i.e. remove barriers, add a ramp, widen a road, etc. etc. and could result in a lot more extra effort. Consider the pros and cons and choose wisely.

2. Bad col3 meshes. Col3 meshes are special collision meshes contained in statics to enable them to be properly navmeshed. Many are badly made or even non-existent - if this happens, the nav-gen will use the object's bounding-box instead, and carve out a hole of similar dimensions. See the pic further up for an example of where a bridge left a bounding box hole, and where a navmesh link was subsequently added to make the bridge usable by bots. Many col3s are approximate and do not contain every feature of the parent model, or have walkable surfaces at a different height than where they are on the parent model. You must keep an eye open for these instances and be prepared to adjust your mesh where necessary.

 Make sure the mesh is selected,

**3ds Max**

go into Sub-object -> Element mode. Select the mesh element; all or most of its faces should highlight to show that they are active. If they do not highlight, push F2 to turn on highlighting.

(insert image 3ds max face select)

 Note in the sidebar the readout: 'xxxx Faces Selected' - Now, go Edit -> Select Invert to select everything BUT the main mesh. Ideally the readout will now say '0 Faces Selected' which means that there are no extra elements (islands) but if there are some AND THEY ARE SIGNIFICANT\*, i.e. large or necessary portions that will need to be attached to the main somehow, then Detach these objects and call the new object 'Inf\_Extras' - but if it is insignificant pieces like a building roof or other unnecessary item, then just delete them outright.

 --- OPEN EDGES ---

First, let me say that 'open edges' are perfectly normal for navmeshes - any boundary edge on a navmesh is open, and it is not these i refer to. The ones we are trying to nail are the ones that occur on the inside portion of the navmesh, or most commonly going from the inside to the outside edges, making a 'bad join' described below.

 Often your navmesh work will require you to cut out or transplant a piece of mesh into another, and that can also cause rogue open edges. Here is the simplest way to see them easily:

 Select your mesh. Go into 'Edge' sub-object mode. Click 'Select Open Edges' and then 'Create Shape From Edges' and it will make a spline from any open edges. The pic below shows how the open edges are now very visible, and has highlighted a couple of troublesome ones.

 The open edges are usually fixed easily just by collapsing/welding the offending vertices.

--- FOLDED POLYS AND BAD JOINS ---

The nav-gen is far from perfect and sometimes makes bad decisions about how to form certain edges or contours. On some occasions it will leave two open-edged polys overlapping. The bad join was visible before we added the spline, but this just makes it more obvious. The bad join's repair is similar to that for Open Edges, but in some cases you may need to Divide an edge in order to keep the correct shape, and snap-weld one of the open vertices to the new vertex. This will create a new invisible edge, which must be made Visible before you export the finished navmesh. It is much better to do that now rather than trust your memory. (See 'Invisible Edges' for the reasons why.)

 If you get something that looks like a bad join but adding a spline doesn't highlight the internal edges, you probably have a 'folded' poly. This means there is an extra poly between the overlapped edges but it is facing downwards and is therefore invisible. (Imagine looking from side on, the edges would look like a flattened 'Z') - a visual confirmation can be made by using the Bottom viewport

 You can fix these the same way as for Bad Joins described above: either snap the vertices together and weld, or if necessary Divide an edge to create a new vertex and snap-weld as appropriate BUT it is common to end up with an extra long thin face or two hidden in there. These can be so thin they actually have no visible area and are impossible to spot by merely looking for them.

 To check for these, try this method:

 Drag a selection box around the area where you have been working to select all those polys.

 Hold down Alt and click-deselect each of the polys that are obviously good, one by one.

 After you deselect the last good poly, check how many faces are still selected.

 If it is 0, you are good to go. Do a check for any open edges that may have been introduced and close them.
If it is 1 or more, study the face/s still selected - in most cases it is easier to delete them than try to repair them.

 After any deleting/repairing, do a check for any open edges that may have been introduced and close them.

--- INVISIBLE EDGES ---

I mentioned Invisible Edges previously as being a bad thing to have; here is the reason why. The nav-gen will disregard one face of a pair that is sharing a common invisible edge. If, in max, you have this arrangement:

 (invisible edge pic)

 ...then once it has been exported and put into a navmesh it will become this:

(invisible edge result pic)

 ...which is obviously going to cause major problems. The nav-gen can only understand triangles with all-visible edges. Quads will fail as shown above. More to the point, the nav-gen will only ever produce visible-edged triangles, so if any invisible edges exist, it is because you have created them yourself.

 I very much recommend at the end of \*every\* navmesh editing session before you export your completed mesh:

 Go into Edge mode.

 Select All edges.

 Click the Visible button.

 While you're there, click Remove Isolated Vertices too; they are also unwanted guests.

 Deselect all edges, and get out of edge mode. Proceed with saving/exporting.

--- OVER-OPTIMISATION ---

This occurs as a result of the nav-gen being too eager to keep file sizes down, and ends up over-simplifying curves so that they no longer conform to the terrain (because this particular error is usually only found on terrain areas and not around statics.)

 It is most common with gently curving terrain; these curves get replaced with flat polys that create spots in the map where the navmesh surface is either too high or low above the terrain. In such spots, the game engine determines that any soldier or vehicle there is 'off the navmesh' so if you find areas in your map where soldiers inexplicably die, or vehicles are abandoned, then chances are that this is the cause.

What you are seeing in the above picture is an Infantry mesh with the terrain mesh imported along with it. Max has a tool called Section, which draws a spline through whatever objects it is placed over, giving a visual representation of their cross-section. One of those has been created here and you can see the shape it has drawn, and also the resultant gap  between the navmesh and the terrain itself.

 I have added a light into the scene here to show up the terrain detail more, and also turned the navmesh material to Wire so you can see just how the nav-gen has grossly over-simplified the mesh there. Now let's look at a typical repair. In the picture below i have isolated a small section and indicated where I would add new vertices to refine the mesh along a terrain contour. Use the 'Snap > Vertex' feature and Move the new vertices directly up or down so that they snap to the corresponding vertex on the terrain mesh. (To enable Snap > Vertex, right-click the Snap button and check the Vertex box)

 You can also see the edges that are created as a result of this refinement. All of these new edges are invisible, and need to be made Visible. If a new edge is going against the contour, use Edge > Turn to rotate it to a new position. You will need to rely on your judgement as to exactly how finely to detail your navmesh, and how to best match the contour. There is no point in accurately following every little nuance; all we want to do is stop the soldiers dying. Every extra polygon adds to the load the game engine has to handle, so don't go overboard here.

(navmesh fix pic)

Part 3 - Exporting Your Navmesh

After you have completed all editing operations necessary for both navmeshes, you will want to Export them out again for final processing.

The export procedure is very straightforward. For example, to export your Infantry mesh, make sure your Infantry mesh is selected, then select File menu> Export Selected, choose .obj as your export file format, browse to the BF2\_Folder\NavMesh\work\YourMapName\GTSData\Output\Infantry.obj file and use the settings shown:

3dsMax Navmesh Export

You will be prompted to overwrite the original, and because you have heeded my advice about keeping a backup, select OK to overwrite the original Infantry.obj with the newly repaired one.

 (There will be a noticeable size discrepancy between the new obj and the original; do not be concerned about this. The FixNavmesh operation will strip out any unnecessary data from the obj files and return them to a smaller size.)

 This is the final step for 3ds Max for now.  . Now all that remains is to run FixNavmesh.bat in a cmd window, then LoadGTSData and SaveQuadTrees in the BF2 Editor as per usual, and create the AerialHeightMap.  Then do some testing and repeat if necessary.

If after following the instructions and the edited navmesh does not show up in the editor, then the problem is probably a bad edit. (That is why you keep the last known good backup). Go back to that last known good backup of the navmesh and re-apply the edits, maybe, just one at a time and test it out.