Navigation Meshes

From Valve Developer Community
Revision as of 05:39, 29 June 2005 by MikeBooth (talk | contribs) (Basic Mesh Editing Commands)

Jump to: navigation, search


Introduction

A Navigation Mesh represents the "walkable areas" of a map. This data is required by Bots and Hostages in Counter-Strike:Source, allowing them to "know" how to move around in the environment.

Navigation Mesh data is stored in a .nav file corresponding to the map file (.bsp) for which it is used. For example, the nav mesh for cstrike\maps\de_dust.bsp is stored in cstrike\maps\de_dust.nav.

Automatic Navigation Mesh Generation

To support the many community-created maps, Counter-Strike:Source includes an automatic mesh generation system. The first time you attempt to play a custom map with bots, the generation system will build a .nav file for that map. Depending on the size and complexity of the map, this may take a few minutes to a few hours. Most maps take about 5 minutes to auto-generate a .nav file. Once the generation is complete, a .nav file is saved to your hard drive for future use.

What is Computed During Generation

The following steps occur during Navigation Mesh generation:

  • Starting at a player spawn point, walkable space is sampled by "flood-filling" outwards from that spot, searching for adjacent walkable points
  • Rectangular Navigation Areas are constructed from the sampled data
  • Hiding and Sniper spots are computed
  • Encounter Spots and Approach Points are computed (this can take awhile)
  • Initial Encounter areas are computed

Manually Starting the Generation Process

To start the generation process manually, type nav_generate from the console.

Viewing the Navigation Mesh

To see the resulting Navigation Mesh, type nav_edit 1. To turn the mesh editor off, type nav_edit 0.

Explicity Marking Walkable Areas (ie: "There's no mesh upstairs")

Some maps that have very steep stairs, ramps, or hills may confuse the generation system, resulting in the Navigation Mesh not covering the entire map. To solve this, you can manually place additional walkable markers that tell the generator to search outwards from that point during its sampling phase.

To add one or more walkable markers, first aim your view towards a known walkable spot in your map, then type nav_mark_walkable in the console. When you are finished placing markers, type nav_generate to re-generate the mesh.

Quickly Generating Meshes for Testing

The analysis phase of the generator can be quite time consuming. To skip it, type nav_quicksave 1 in the console.

NOTE: "Quicksaving" skips the analysis phase, and the resultant nav mesh will be missing important data required by the CS Bots and Hostages higher-level planning and attention systems. While useful for testing, editing, and tuning a nav mesh, be sure to do a full analyze (ie: with nav_quicksave 0) before publishing your nav file to others.

Editing the Navigation Mesh

The automated Navigation Mesh generator does a reasonable job of constructing a mesh, allowing you to start using Bots and Hostages on custom maps easily.

However, careful hand-tuning of the Navigation Mesh can markedly improve the performance of Bots. In addition, manually decorating the mesh with Place Names allows the Bots to tell others where events occur, enhances the Counter-Strike radar and includes Place Names in all radio messages.

Enabling the Navigation Mesh editor in de_dust

The Navigation Mesh Editor

To enable the editor, type nav_edit 1 in the console (type nav_edit 0 to disable it).

  • The white cross in the center of your view is the cursor.
  • The Navigation Area you are pointing at is the selected area and is shown with a yellow outline.
  • Navigation Areas that can be reached from the selected area are shown in red.
  • The white line in the selected area denotes where the area will be split if the nav_split command is executed.

Using Mesh Editing Commands

Although all of the mesh editing commands can be typed in the console, in practise it is far easier to bind these commands to keys. For example, bind del nav_delete binds the delete key to the command nav_delete. After this binding, pressing the delete key will delete the nav area under your cursor (if you are nav editing mode).

Basic Mesh Editing Commands

Split

To split an area into two adjacent, inter-connected areas, aim your cursor at an area and execute the nav_split command. Before split After split

Merge

To merge two adjacent areas:

  1. Aim your cursor at the first area and execute nav_mark
  2. Aim your cursor at the second area and execute nav_merge

Note that both areas must be the same size along the edge to be merged.

Marked first area Aim at second area Merged

The resulting area will retain all of the connections of the original two areas, and inherit properties (ie: Place Names, etc) from the marked area.

Splice

Splicing creates a new area between two existing areas.

Marked first area Aim at second area New area spliced between

Delete

To delete an area, aim your cursor at it and execute nav_delete

Creating a New Area

To manually create a new area:

  1. Place your cursor at where a corner of the new area should be
  2. Execute nav_begin_area
  3. Move your cursor to drag out the area's extent
  4. Execute nav_end_area

Start dragging area at first corner Drag area extent Area created


Adding and Removing Connections Between Areas

The connections between areas define whether an agent can move from one area to another. Usually these connections are bidirectional, meaning agents can move back and forth between two areas at will. However, sometimes the connection is one way, as in the case of high ledges that can be jumped down, but not back up.

To make a one-way connection from area A to area B (meaning you can move from A to B):

  1. Place your cursor on area A
  2. Mark area A with nav_mark
  3. Aim your cursor at area B
  4. Execute nav_connect

To make a bidirectional connection, repeat the above steps reversing the roles of A and B.

To remove all connections from areas A and B:

  1. Aim at area A
  2. Mark area A with nav_mark
  3. Aim at area B
  4. Execute nav_disconnect



Addition information can be found here.