1 unstable release

0.1.0 Dec 31, 2022

#1592 in Game dev

MIT license

5MB
20K SLoC

C++ 18K SLoC // 0.1% comments Rust 1.5K SLoC // 0.0% comments ReScript 10 SLoC C 4 SLoC

Contains (Windows DLL, 620KB) recast_src/x64/Debug/AiNav.dll, (ELF lib, 365KB) lib/libAiNav.so, (Windows DLL, 205KB) lib/AiNav.dll, (Windows DLL, 205KB) recast_src/x64/Release/AiNav.dll, (DOS exe, 110KB) CMakeCXXCompilerId.exe, (DOS exe, 110KB) CMakeCXXCompilerId.exe and 5 more.

recast_navigation

Rust wrappers for recast navigation

This is a wrapper over a higher level C++ wrapper for recast navigation. So the rust side is fairly high level. Supports recast, detour, and detour crowd to varying degrees. Some functionality like offmesh links are not supported.

Building from source

The C++ source is built with cmake and has VS cmake project configurations. Precompiled libraries for windows and linux are provided in lib. build.rs will copy them to the build output.

If you build from source you will want to copy the shared libs cmake creates into lib manually.

Navmesh building flow

  • Create a NavmeshBuilder.
  • Create a Navmesh.
  • NavmeshBuildUtils::get_overlapping_tiles_from_settings will give you a list of all tile coords within a bounds.
  • Take those tiles and call NavmeshBuildUtils::calculate_tile_bounding_box on each tile to get the tile bounds.
  • Create a TileInputBuilder for each tile.
  • Gather the geometry for the tile bounds and feed it to the TileInputBuilder.
  • NavmeshBuilder has a built_tile function that takes a TileInputBuilder. Single builder can build multiple tiles.
  • Add the tiles to the navmesh

Tile building is completely separate from the navmesh. So you can build tiles in the background at runtime, and then add/replace them into the navmesh which is fairly fast/cheap.

Navmesh Queries

Queries are done through a NavQuery instance. Queries have a pointer to the Navmesh, so cannot be used while adding/removing tiles from the navmesh.

We ensure this by queries being obtained from a query pool belonging to the navmesh, and some simple reference counting. If there are rented queries you won't be allowed to mutate the navmesh.

moving agents over the navmesh

The flow here is straight forward but it's important to understand that there is a navigation mesh and a separate detail mesh.

You pathfind over the navigation mesh, but it does not return a correct surface height. You call NavQuery.get_location with a position that is on the path, which returns the surface height.

Crowds

Detour crowd is decent but it's the one area of recast that people usually customize or just roll their own. Don't expect it's behavior to match what engines like UE or Unity provide, as they have heavily customized detour crowd over time.

Dependencies

~9.5MB
~200K SLoC