BF2.US bf2-rsdeveloper wiki Parity Discord bf2.us
On this page

Navigation meshes

Bots walk and drive on two maps per level, Infantry and Vehicle: the AIPathFinding/<map>.qtr polygons and .clb clusters the server loads after ai.init. This page says how the 2005 tools made them, how the bf2-rs editor makes them in a few seconds, which settings both use, and how close the editor's maps come to the shipped ones.

BF22142

The files#

FileWhat it holdsReader
AIPathFinding/<map>.qtrconvex polygons (vertices, neighbours, material, cluster) in a quadtree, one tree per islandbf2-ai qtr.rs QtrFile::parse
AIPathFinding/<map>.clbthe cluster graph: portals between clusters and the portal costs per cost vehiclebf2-ai clb.rs ClbFile::parse
AIPathFinding/AerialHeighMap.ahm16 m grid of obstacle heights for the aircraftbf2-ai ahm.rs

The server loads them in AIPathfinding::loadQuadTrees (AIDLL_w32ded.dll!0x100a4530) for every map that ai/AIPathfinding.ai creates. The format is in notes/formats/ai-navigation.md.

The map settings#

Each map has four settings, set by aiPathfinding.map.* lines in the mod's ai/AIPathfinding.ai and the level's AI/AI.ai. The server keeps them in its MapContainer (setMaxSlope AIDLL_w32ded.dll!0x1009bb00, setRadius 0x1009bb50, setHeadClearance 0x1009bb80; maxWaterDepth 0x1009bb30). The 2005 editor wrote them into the navmesh tool's config.dat, and NavMesh.exe built the map with them.

SettingBF2 InfantryBF2 VehicleKarkandCerbere Landing (2142)
maxSlope (degrees)3020Infantry 43 ("so that it includes the 3 steep stairs")Infantry 35, Vehicle 24
radius (m)0.253.5as BF2Infantry 0.25, Vehicle 2.3 ("only jeeps on this map")
headClearance (m)1.93.5as BF21.9 / 3.5
maxWaterDepth (m)0.70.7as BF20.7

How the 2005 tools made a map#

NavMesh/CreateNavmesh.bat in the BF2 editor ran three steps (GenerateNavmeshLocal.py):

  1. the editor exported the level's collision meshes, the terrain, the combat area and the key points as GTS meshes (aIPathFinding.exportGTSMeshes);
  2. NavMesh.exe (source in NavMesh/Navmesh_SDK, built on the GTS library) joined them into one walkable surface with boolean mesh operations (manifold, stitch), cut the combat area's border (cutoutCombatArea), then per map (commandOpt in navmesh.cpp): cut out the places with less than the head clearance (expand_height), removed the faces steeper than maxSlope unless they rise less than 0.35 m (remove_sloping_triangles), shrank the surface by the radius (shrink_surface) and kept what the key points reach;
  3. a modder cleaned the result up by hand in Maya and FixNavmesh.bat wrote the .qtr / .clb.

The boolean operations on full collision meshes took hours per level, and step 3 was manual.

How the editor makes a map#

The Navigation panel's Generate (crates/bf2-editor/src/navmesh.rs, generator crates/bf2-ai/src/navgen.rs) works on a grid instead of on meshes:

  1. it gathers the level's collision: the terrain, and every static's collision mesh (its AI navigation LOD, else its soldier LOD, as the 2005 export read it) with the editor's edits applied, but not the statics marked Object.notInAI 1, which no bot round has (the game destroys them when the AI runs or the mode is gpm_coop, Object::setNotInAI bf2_w32ded.exe!0x006dc1e0; the shipped maps run over them too);
  2. it samples the triangles into grid cells: a cell's floors are the terrain and the walkable faces (normal y 0.7 or more); a floor stands when no collision and no other floor lies within the head clearance over it;
  3. it links neighbouring floors within the step height, removes the floors steeper than maxSlope (a floor's slope over two links on each side; a rise under 0.35 m stays), shrinks the walk area by the radius from every hole, drops the cells outside the game mode layer's combat areas, and keeps the largest part the key points reach (the 2005 export's: the spawn points 1.25 m up for Infantry, the vehicle spawners for Vehicle);
  4. it merges the floors into plane-fitting rectangles (the polygons), builds the quadtree and the clusters, and runs the game's own polygon search for the portal costs.
Generator settingInfantryVehicle
Collisionthe AI navigation LOD of each static (else its soldier LOD), without the notInAI staticsthe same
Cell size0.5 m0.5 m (1 m before H2872)
Step between neighbouring floors0.45 m0.45 m
Head clearanceheadClearance (1.9 m)headClearance (3.5 m)
Slope limitmaxSlope (30 degrees; Karkand 43)maxSlope (20 degrees)
Erosionradius from each wall piece's hexagon (0.25 m: the blocked cells alone)radius from each wall piece's hexagon (3.5 m; box corners cut, H2932)
WatermaxWaterDepth (0.7 m)maxWaterDepth (0.7 m)
Combat areathe layer's areasthe layer's areas
Cluster block24 m (grows when the .clb's 16-bit offsets overflow)32 m

The erosion follows the shape shrink_surface cut (Navmesh_SDK shrink.cpp, subtractor, H2913): for each boundary edge, the edge widened by the radius on both sides and pointed by the radius beyond both ends. A straight wall of any direction loses the full radius, but a box's convex corner is cut about r / sqrt(2) from it instead of round. That is why the shipped Karkand map keeps 2.1 m in the pipestack street, between a BTR wreck's corner and the pipe stack, 8 m apart. Since H2932 the generator does the same per wall piece: each wall triangle's share of a blocked cell is a piece of edge in that wall's own direction, cut where the wall leaves the cell, and a floor leaves when it lies inside a piece's hexagon (its distance across plus its distance past the nearer end is under the radius). It measures from the wall itself, not from the middle of its cell, and a pole's many faces come out nearly round. Around a 1 m box that leaves the box plus a diamond: the sides lose the full 3.5 m, the corners only 2.5 m along the diagonal. The street went from 1.0 m (round) to 2.0 m (shipped 2.1 m), the street north of the town junction is 1.0 m (shipped 1.5 m), and Karkand's Vehicle map has 4.9 % of its ground within 3.5 m of a static (shipped 4.1 %). The shipped maps also cut out what the game mode layer's spawners place and leave standing (the artillery, the UAV tower, the radar, TOW launchers and bipods; the UAV tower at Karkand's gas station leaves a hole of about 13 by 10 m), while they run over the spawn points of tanks, jeeps and APCs. The editor now places those stationary objects too (anything a spawner places without mobile physics); bot tanks had been held against the UAV tower and the artillery. Since H3099 each such spawner is the box the 2005 export wrote for it rather than the object itself: the export took every team's spawned object's collision bounds, turned with the spawner, and wrote the box around them, lined up with the map's axes. On Karkand the editor's 17 boxes are the export's to 0.1 mm, and the market artillery's box, 1.8 m wider than the gun, closes a strip beside it that the shipped map does not have. The SDK that Connor shared on R-0080 is the same as the editor's NavMesh/Navmesh_SDK. It has no corridor-width setting and no neck pass.

After the shrink the tool tidies the edge of the mesh before it keeps only what the key points reach. It removes faces on the edge that have at most one neighbour and are smaller than 0.32 m², then again with half that area, for as long as a round removes something. It also collapses slivers with a corner of 10 degrees or less. Since H2961 the generator runs the first step on its 0.5 m cells: a cell is 0.25 m², so the first round removes every cell left with one neighbour or none (the tip of a dead end one cell wide), and the second round, at 0.16 m², removes nothing. The sliver step has nothing to do on square cells. The effect is small: Karkand's Vehicle map loses 49 m², and the cells near statics in strips up to 1.5 m wide that the shipped map does not have go from 179 to 160. The cleanup cannot remove a whole strip, since a strip's faces have two neighbours each. The strips the shipped maps lack come from the shrink and from the tool's ground faces: with the simplified ground below, the count is 129, and the other way round (such cells the shipped map has and ours lacks) it is 217.

Every shipped map is one connected piece: all 38 of BF2's (19 levels, Infantry and Vehicle). The tool keeps what its key points reach, and the export's key points are the spawn points (1.25 m up) for the Infantry map and the vehicle spawners for the Vehicle map; Road_To_Jalalabad still ships the export's config.dat, and the editor's key points match it point for point. Since H3075 the generator floods from those key points and keeps the largest piece they reach. Before, it also seeded from the control points: Karkand's hotel control point stands 2.4 m over the street, so its Vehicle map kept a small patch there, linked to nothing, and bot vehicles that took a goal on it waited up to 35 s for a route that could not exist. On Cerbere Landing and Road_To_Jalalabad the Infantry maps now leave out a few roofs and a plateau that the shipped maps join to the rest and the grid does not (recall 1.5 and 1.1 points lower); no route led there before either.

NavMesh.exe tested the slope limit on its own ground mesh: the editor exports the terrain at the heightmap's spacing (2 m on Karkand, Gulf of Oman and Cerbere Landing), and the tool first simplifies that mesh, merging triangles whose slopes differ by under 20 degrees, then stitches the objects in, and only then removes the steep faces. H2962 ported that step as an option (the request's "ground": "sdk"), with the removed triangles' edges eroded like walls; since H3064 it is the default on BF2 levels, and the ground floors lie on the simplified mesh's faces, 0.2 m up, as the tool's output does. Without it ("ground": "grid", still the default on 2142 levels) the limit is tested on a floor's slope over its neighbours, about 2 m.

H2985 checked that port against the tool itself: a copy of the 2005 editor's NavMesh.exe ran -cmd manifold on the ground file the export writes, for Karkand and Cerbere Landing. The tool does not repeat itself. When two edges are equally long it takes them in the order of their memory addresses, so two runs on the same Karkand file removed 83,532 and 82,316 m² of steep ground, 1.5 % apart, and disagreed at 3.7 % of the points. Six runs on Karkand spread over 82,286 to 83,972 m² (2 %); four runs on Cerbere Landing over 0.7 %. Our simplification removes 81,728 to 82,320 m² on Karkand, depending on its own tie order, at the low end of the tool's range, and its faces overlap the tool's as closely as the tool's runs overlap each other. On Cerbere Landing it lies within 0.2 % of the runs' average (53,242 m² against 53,175). At the bank by Karkand's olive trees the runs disagree by several metres: one removed the bank from x -134.5, one from x -131, two kept all of it and two cut different diagonal strips across it. The shipped map's edge there, 1.3 m past the foot, is one of those outcomes. tools/bfheroes/navmesh_exe.py writes the tool's input files and compares its output with ours.

The simplification also stops at each object's box, as the tool did: the export writes every collider's box next to its mesh, and the tool keeps the triangles that touch either one. Midnight_Sun ships the tool's own simplified ground from the original run, so this is checked against the real thing: with the boxes our steep faces differ from it at 4.2 % of the points (6.1 % without them). Road_To_Jalalabad ships the original export, and 502 of its 512 boxes sit within 5 cm of ours.

For a while the option stayed off, because with the floors still on the heightmap it lost ground the shipped maps keep: Karkand's Vehicle map gained (90.3 % against 84.5 %), but Karkand's Infantry map fell under its 96 % gate (95.9 %). The missing piece was the surface. The tool's output lies on its simplified faces, which leave rolling ground by 1 to 3 m, and the maps are compared within 1 m in height, so ours and the tool's missed each other on every hillside. With the ground floors on those faces (H3064) Karkand's Vehicle map reaches 93.7 % of the shipped map at 93.4 % precision and covers 92.1-93.9 % of each of the tool's four runs (84.5 % / 92.0 % and 83.7-85.4 % before; the runs cover each other at 92.4-96.4 %); its Infantry map 98.2 % / 97.1 %, and Gulf of Oman's maps 97.1 % / 96.2 % (Infantry) and 95.6 % / 93.6 % (Vehicle), from 89.7 / 88.4 and 85.1 / 84.0.

Cerbere Landing's Vehicle map still drops to 76.4 % with it (93.8 % without), so 2142 levels keep the grid's rule. The tool's own simplification of Cerbere's ground, run in a copy of the 2005 editor's NavMesh.exe, removes the same faces ours does at the three regions it loses, so BF2's tool would lose them too: Cerbere's shipped map was not made by BF2's tool with the level's 24 degrees (2142's editor and its tool never shipped). Cerbere loses three regions. The one west of the town hangs on a 2 m corridor at (-20, -36), and there the simplification merges the flat corridor into the steep bank beside it; the merged faces are too steep, and the 2.3 m cut along their edge closes the corridor. The tool merges across such folds as well (it moved a ramp's foot in three of four runs), so whether a corridor survives depends on the order it happens to take: four orders of ours give Cerbere 75.8 to 84.4 %. The south-east strip is cut where our faces match one of the tool's two runs and the other keeps the way open. The north-west region is joined to the rest of the shipped map only by a diagonal strip one sample wide, which the walk grid, linking cells along x and z, cannot carry.

The overgrowth on that bank is not an obstacle either. The export writes each object's AI navigation collision (else its soldier or vehicle collision), and the pine bushes there (me_pinebush01) have only the projectile collision, which the export writes only for water. So NavMesh.exe saw no obstacle at them, the same as the editor's collision world.

Before H2872 the generator used none of the level's settings: no slope limit (only the step), two rings of 1 m cells (2 m) of erosion on the Vehicle map instead of 3.5 m, 1.8 m / 3 m of head clearance, the soldier and vehicle LODs, and the combat areas' bounding box plus 15 m instead of the areas themselves. Heroes ships no bot maps and keeps those settings. The Vehicle map moved to 0.5 m cells because a 3.5 m erosion on 1 m cells (where a wall can sit anywhere in its cell) cut Karkand's Vehicle map in two at a street the shipped map drives through.

Why it is fast#

Most of the work is one pass over the collision triangles into grid cells and a few passes over the cells. There are no boolean operations on meshes, which were what made NavMesh.exe slow. Speed and accuracy are separate: the bots drove into walls because the Vehicle map kept only 2 m from walls and had no slope limit, not because the grid is fast. Karkand natively (bf2_editor --game bf2 --level Strike_at_Karkand --navmesh '{}', its default 64-player layer, collision, generator and files):

MapBefore H2872After
Infantry2.2 s (45,127 polygons)1.6 s (22,401 polygons)
Vehicle0.5 s (12,798 polygons)1.4 s (11,369 polygons, 0.5 m cells)
Both2.7 s3.0 s

Leaving out the notInAI statics (H2885, Karkand's 8 trestles) changed neither time: the accuracy test's gpm_coop 16 maps took 1.0 s each before and after.

With "ground": "sdk" the job also decimates the terrain's 2 m mesh as NavMesh.exe -cmd manifold did. That ran in one piece of work, so the page froze for its whole length: 25 s on Gulf of Oman's whole co-op area. H2987 runs it a slice at a time and makes it 4 to 6 times faster with the same rules (the faces keep their area, quality and normal between collapses, the neighbour tests read sorted lists, the object boxes sit in a grid). The maps come out byte for byte the same. The aerial height map that goes with the Vehicle map runs in slices as well (notes/editor/perf.md). Natively, with 16 ms slices (analysis/scratch/bfheroes/h13/h2987; under other builds' load the same jobs took about 1.5 times as long, Oman's Vehicle job 10.7-12.4 s with no slice over 93 ms):

Job (gpm_coop 16, ground sdk)BeforeAfter
Gulf of Oman Vehicle, all three combat areas29.6 s, longest slice 25.1 s7.8 s, longest slice 60 ms
Gulf of Oman Infantry, all three combat areas19.3 s, longest slice 17.0 s6.7 s, longest slice 61 ms
Karkand Vehicle3.3 s, longest slice 2.0 s1.6 s, longest slice 28 ms
Karkand Infantry2.9 s, longest slice 1.9 s1.2 s, longest slice 25 ms
Cerbere Landing Vehicle1.7 s, longest slice 0.7 s1.0 s, longest slice 22 ms

With H2946's rule the Oman jobs end at the layer's flagged combat area (the town). On that area the Vehicle job with ground sdk takes 1.9 s, and no slice runs over 18 ms.

H3076 timed every piece of work between two looks at the clock, with the thread's CPU cycles and the process's page faults beside each (the probe is analysis/scratch/bfheroes/h13/h3076). A few pieces were still whole: the end of the simplification (sorting the remaining triangles into the lookup's cells, then dropping the decimation's tables, 7 ms on the town and 10-15 ms on the whole co-op area), the slope test that starts the steep stage (7-10 ms), the heap's growth while the simplification queues its edges (10-15 ms, 46 MB of fresh pages), the corner table's rehashes while the polygons are made (9 and 18 ms: a rectangle's corners sit on its own plane, so few are shared, 5.4 to 5.5 per rectangle where 2 were reserved) and the frees of the grid's largest tables (8-20 ms each). Each is now a run of small units: the lookup is two flat arrays filled in slices, the slope test walks the triangles and then each vertex's neighbours (SlopeBuild), the heap and the corner table are sized once up front, and the big tables are freed one per look at the clock. The maps come out the same to the byte (Gulf of Oman's town both maps 10 of 10 runs, the whole co-op area 3 of 3). Ten runs of each Oman job on the town ("areas": false) at 16 ms slices: no slice over 50 ms, the longest 25 ms (the aerial map's), the generator's at most 19 ms. On the whole co-op area (the job's bounds before H2946) the longest went from 113 ms to 28 ms, leaving aside the slices where the thread waited. The long holds H2987 saw there (0.2 to 3.6 s, in the rectangles phase) were the thread waiting: one caught this time held 850 ms with 2 million cycles of work and 161 page faults, so the machine had taken the thread off its core or its memory out to disk (other builds were running), and no cut in the job's own work can shorten that.

H3098 did the same for the job's last phase, which writes the files. On Kubra Dam's 64-player Infantry map (385,000 polygons, a 57 MB .qtr) it held three slices: writing the files (67-94 ms, the buffer doubling as it grew), reading them back as the server does (15-21 ms) and the AI files (75-85 ms, half of it a second pass over the map's connected parts that the BF2 branch never used, the other half the order placement cloning the map to find its largest part again). The .qtr is now written a run of items at a time into one buffer of its final size, the largest part is found once in runs and handed to the AI files, and the encode phase's longest slice at 4 ms slices is 21.7 ms (the read-back), the files the same to the byte. The whole Kubra job at 4 ms slices: the longest slice 216 ms before H3076, 98 ms before H3098, 26.6 ms now.

Slicing found a bug in the job. When a slice ended while the radius erosion was still allocating its per-floor table, the erosion skipped the floors already allocated, and if the slice ended just as the table was complete it skipped every floor. Those maps lost the radius cut: with slices cut at random, Karkand's Vehicle map kept 310,358 floors instead of 195,610. The page's 6 ms slices and the command line's 50 ms ones could end there on any map. Twelve command-line runs of the co-op scenario's Vehicle map before the fix all gave the same map, so that scenario was not hit. Fixed in H2987: every map now comes out the same however its job is sliced (navmesh_jobs_bf2, bf2-ai stepped_radius_and_ground_make_the_one_shot_map).

In the browser#

The editor page runs the same generator, compiled to WebAssembly, with the settings in the table above (0.5 m cells for both maps, Karkand's default 64-player layer). Measured with python tools\web\editor_check.py --engine wasm --game bf2 --level strike_at_karkand --only shell,navmesh (H2886): three runs in headless Chrome on a Ryzen 9 9950X3D (16 cores, 32 threads) while other builds ran on the same machine (mean CPU load 27 %, 39 % and 43 % over the three runs). The times come from the page's navmesh: <map> generated in lines and the engine's per-phase lines:

MapNativePage, start to finish (median of 3)Generator work in the pageViewport frames
Infantry1.5 s6.1 s (5.9-6.3 s)2.0 s337
Vehicle, with AerialHeighMap.ahm1.4 s6.0 s (5.8-6.1 s)2.0 s327
AerialHeighMap.ahm alone (before H2947)under 0.1 s14 ms (one slice)1
Both2.9 s12.1 s (12.0-12.1 s)4.0 s662

The WebAssembly code does about 1.4 times the native work time: 4.0 s for both maps where the native build takes 2.9 s. The page took three times as long again while the job got 6 ms of each viewport frame (H2771, navmesh.rs FRAME_BUDGET_MS), and a frame took about 18 ms in these runs. Since H3082, once nobody has touched the view for about 5 s, the job takes the rest of each frame up to the display's next refresh after the view's draw, and the view draws every second frame (rebake.rs FrameFit, as Bake all does): Verdun's two maps take about 14 s in the page where they took 26 s. Since H3167, while someone moves the camera, each frame still ends within one refresh at 60 Hz, the frame after each camera move draws, and the frames between give the job the draw's time, so the camera answers as quickly as with 6 ms a frame while the maps come sooner: Verdun's take about 16 s with the camera moved every 1.5 s, where they took 26 to 28 s. The camera keeps moving and the level keeps drawing while the maps are made. Most of the time goes to the grid phase, which samples the collision triangles into cells: about 1.7 s of work and 5 s in the page for each map. Before H2771 the job held the page's thread until it was done, and Karkand took 6.7 s in the page for both maps (H2498, with the Vehicle map on 1 m cells and the settings from before H2872), with the viewport frozen meanwhile.

Since H2947 the aerial height map casts the 2005 editor's rays at the level's objects, 16 x 16 per 16 m cell, and it runs in the job's slices too (notes/editor/perf.md "Cut: the navmesh's aerial height map in slices"): on Karkand 0.8 s of work in 122 slices of at most 12.5 ms (2.3 s in the page), on Verdun 1.7 s in 284 slices; the file is the same to the byte as the map made in one call.

Measured accuracy#

cargo test -p bf2-editor --test navmesh_accuracy_bf2 generates both maps of a level on its gpm_coop 16 layer (the bots' layer, whose combat area the shipped maps cover) with the settings before H2872 and with today's, and measures each against the shipped map (bf2-ai navcompare). Both maps are sampled every 0.5 m:

  • in a footprint: walkable samples where a static's collision (the colliders the job read) reaches into the head clearance over the floor;
  • recall: the shipped walkable area the generated map covers (within 1 m in height);
  • precision: the generated walkable area the shipped map has too;
  • near statics: ground samples within the map's radius of a static;
  • steep: samples steeper than the map's maxSlope.
Level, mapIn a footprintRecallPrecisionNear staticsSteepArea (shipped)Clusters (shipped)
Karkand Infantry0.00 -> 0.01 % (0.13 %)91.9 -> 98.2 %52.1 -> 97.2 %0.3 -> 0.2 % (0.6 %)1.1 -> 0.0 % (0.0 %)198,945 -> 113,954 m² (112,765)709 -> 483 (568)
Karkand Vehicle0.00 -> 0.00 % (0.00 %)95.4 -> 93.7 %38.3 -> 93.6 %9.2 -> 3.2 % (4.2 %)12.7 -> 0.0 % (0.1 %)121,859 -> 48,930 m² (48,879)379 -> 225 (149)
Gulf of Oman Infantry0.00 -> 0.02 % (0.12 %)87.2 -> 97.1 %9.9 -> 96.3 %0.1 -> 0.1 % (0.2 %)0.2 -> 0.0 % (0.0 %)836,216 -> 96,072 m² (95,340)1,930 -> 286 (268)
Gulf of Oman Vehicle0.00 -> 0.00 % (0.01 %)87.3 -> 95.6 %7.6 -> 93.7 %1.9 -> 1.8 % (2.3 %)0.9 -> 0.0 % (0.0 %)771,458 -> 68,345 m² (66,998)1,242 -> 184 (282)
Cerbere Landing Infantry0.00 -> 0.04 % (0.93 %)86.9 -> 92.4 %52.3 -> 94.1 %0.4 -> 0.8 % (1.7 %)8.1 -> 0.1 % (0.3 %)78,219 -> 46,304 m² (47,138)453 -> 263 (1,115)
Cerbere Landing Vehicle0.02 -> 0.00 % (0.00 %)88.7 -> 93.8 %50.6 -> 89.7 %3.0 -> 3.4 % (3.7 %)3.6 -> 0.0 % (0.0 %)27,654 -> 16,516 m² (15,798)182 -> 135 (144)

The numbers in brackets are the shipped map's. What they mean:

  • Almost no generated walkable area lies inside a static's collision, before or after. The bots' trouble was the space around the statics: the Vehicle map's ground within 3.5 m of a static fell from 9.2 % to 3.2 % on Karkand (the shipped map has 4.1 %), and the slopes over 20 degrees from 12.7 % to none.
  • 90-97 % of the generated area now lies where the shipped map has walkable ground (38-53 % before), and the generated maps cover 92-98 % of the shipped ones. Since H3064 the BF2 maps judge slopes on the tool's merged ground mesh and lie on it; the missing parts are strips beside buildings and the merged mesh's own variation (two runs of the tool differ as much). Cerbere Landing (2142) still judges slopes on the grid.
  • The shipped Gulf of Oman maps cover only the town: the co-op layer has three combat areas, and the 2005 export took the one flagged CombatArea.usedByPathFinding 1 (the export stops unless exactly one is flagged; every shipped co-op layer flags one). Since H2946 the editor's maps end at that area too (before: all three, 595,467 m² over the desert and a precision of 14 %).
  • The shipped .qtr is the tool's last output (GTSData/Output/<map>.qti, shipped in every level's server.zip) imported as it is: every walkable sample of one lies on the other. Any hand edit in Maya went into that output.

Against NavMesh.exe itself#

NavMesh.exe does not repeat itself: its mesh library takes equal edge lengths in memory order, so two runs on one export give different maps. H2946 measured that spread and the editor's distance from it. The 2005 editor in a copy of the game exported Karkand's and Gulf of Oman's co-op layers as they are today (tools/bfheroes/edproxy/export.py), tools/bfheroes/navmesh_exe.py pipeline ran the tool's whole build four times on each (and on Road to Jalalabad's shipped export, the input of its shipped maps), and cargo test -p bf2-editor --test navmesh_tool_spread with NAVMESH_TOOL_RUNS=<level>|<run>;... measured every run like the editor's maps:

MapTool runs: recall / precisionEditor: recall / precisionTool run against tool runEditor against a tool run
Karkand Infantry97.8-98.9 / 98.0-98.8 %98.2 / 97.2 % (96.4 / 91.4 %)97.5-98.6 %96.1-98.2 % (91.2-97.2 %)
Karkand Vehicle94.2-95.9 / 93.9-95.7 %93.7 / 93.6 % (84.5 / 92.0 %)92.4-96.4 %92.1-94.5 % (83.7-92.9 %)
Gulf of Oman Infantry95.0-98.4 / 94.9-98.3 %97.1 / 96.3 % (89.7 / 88.4 %)94.6-97.7 %95.1-96.4 % (88.2-91.4 %)
Gulf of Oman Vehicle93.3-97.5 / 89.1-93.0 %95.6 / 93.7 % (85.1 / 84.0 %)93.0-96.7 %90.0-93.5 % (81.0-86.6 %)
Road to Jalalabad Infantry98.0-98.5 / 99.2-99.3 %96.5 / 98.0 % (97.6 / 97.3 %)99.1-99.8 %96.5-97.7 % (96.4-98.1 %)
Road to Jalalabad Vehicle96.9-97.5 / 99.5-99.6 %94.9 / 97.8 % (95.0 / 97.3 %)99.0-99.7 %96.9-97.8 % (96.5-97.4 %)

The editor's columns are H3064's with H3099's spawner boxes, the grid's slope rule before H3064 in brackets. The tool's runs land 0.5 to 4 points apart. Before H3064 the editor's maps were 1.5 to 10 points from them; now Karkand's and Oman's Infantry map lie inside that spread (Karkand's Vehicle map covers 92.1-93.9 % of each run's area, the runs each other's 92.4-96.4 %) and Oman's Vehicle map and Jalalabad's 2 to 3 points out. The tool's last step simplifies its surface until it lies up to 1-3 m off rolling ground, and it tests slopes on its merged mesh's faces; the editor now does both on BF2 levels (H3064). It still cuts the collision meshes into the ground where the editor samples them into 0.5 m cells. Road to Jalalabad's editor maps use today's layout, which has 190 objects more than its 2005 export.

The bot round#

The scenario bots_editor_navmesh_karkand_stuck regenerates Karkand's maps with the editor's code on the gpm_coop 16 layer, mounts them through an overlay and plays three minutes with 15 bots. bf2-server's bots_stuck.rs prints a bots: vehicle held by a static line whenever a bot that follows a path pushes for 3 s with a drive throttle that points with its vehicle's motion (or into what it stands against) while the vehicle moves under 0.3 m/s within 3 m of a static's collision sphere. The brake a bot applies while it waits and the braking of a roll stay out of the count.

MapsBot vehicles that droveDistance drivenHeld by a static
Before H28725about 1,400 m2: a tank beside me_olivebig01 at the US base, an APC beside refug_2 at the town junction (-210, 2)
H28728about 2,270 m2, one episode: a tank at the same junction (-205, -18), beside sidewalk_3_34m and refug_2
H2885 (without the notInAI statics)none at the junction in 4 runs; 3 runs without any event, 1 with 2 events of a tank at the US base gas station (-121, -276)

The H2872 maps held the tank because of the map, not the curb or the tank's controller. Karkand puts a trestle at (-211.0, -21.7) in the junction's west half with Object.notInAI 1; a bot round never has it, and the shipped maps run over it, but the generator kept it and its 3.5 m radius closed the west half. The planner's path then ran along the east curb, into the car wreck and the concrete barrier the street narrows to there, and the tank backed and turned for about 25 s before it found the way over the traffic island. The sidewalks and traffic islands the held lines named are 0.1 m slabs a tank drives over; bots_stuck.rs names the first static whose bounding sphere lies within 3 m, which for a 34 m slab is most of the street. Without the trestle the junction is as wide as on the shipped map and the bots' tanks, APCs and jeeps drive through it in under 15 s (one tank that backed up while it fought took 25 s).

The gas station is another case: there the tank's path cut the corner of the fuel-tank island, where neither the generated nor the shipped Vehicle map has polygons, so the map is not what holds it. The scenario stays known failing until that is fixed.

How it is tested#

  • Against the shipped maps (crates/bf2-editor/tests/navmesh_accuracy_bf2.rs): the generated infantry and vehicle maps of one level are measured against the level's own shipped navigation maps: what they leave out, where steering points lie, how wide the streets come out.
  • Generation end to end: a Heroes level that ships no navigation data gets one in under a minute, saved and read back (navmesh_bfheroes.rs); the sliced job gives the same files as the one call (navmesh_jobs_bf2.rs).

One of six addresses stands in a test. "Measured against" is a comparison of shapes with a stated tolerance, not equality: the original's generator was a separate tool and is not reproduced.

Code and notes#

crates/bf2-ai/src/navgen.rs (generator), crates/bf2-ai/src/navcompare.rs (measurement), crates/bf2-editor/src/navmesh.rs (the editor's job and settings), crates/bf2-editor/tests/navmesh_accuracy_bf2.rs (the numbers above), crates/bf2-editor/tests/navmesh_tool_spread.rs with tools/bfheroes/edproxy/export.py and tools/bfheroes/navmesh_exe.py pipeline (the tool's own runs), crates/bf2-server/src/bots_stuck.rs (the held-vehicle lines). Notes: notes/editor/api.md "Navigation mesh", notes/editor/parity.md "Navmesh and AIPathFinding". Tasks H2395, H2498, H2771, H2872, H2885, H2886, H2946. Who walks on these maps and how: bots.

Source: docs/dev/levels/navmesh.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.