NavMeshBuilder
Runs the Recast bake pipeline against a scene. Walks every entity with TransformComponent + MeshRendererComponent, transforms the CPU-side mesh data to world space, feeds Recast, and produces a dtNavMesh ready to stuff into a NavMeshAsset.
- Module
- AINavigation
- Header
#include "AINavigation/NavMeshBuilder.h"- Namespace
Mowo
Solo (single-tile) mode is the default and stays fast for indoor / mid-size scenes. Set NavMeshBakeSettings::tiled to partition the scene bounds into a grid of tileSize² chunks and bake each independently — the composed dtNavMesh scales to open worlds and stays under Detour's per-tile poly cap. Both paths report the actual polygon and tile counts walked from the built mesh.
Properties
| Type | Name | Description |
|---|---|---|
static constexpr const char* | kCancelledError | Default "cancelled". |
Public functions
| Returns | Name | Description |
|---|---|---|
Snapshot | SnapshotScene | Main-thread: walk the scene, collect every MeshRenderer's CPU-side triangles in world space, plus every terrain's hole-aware triangle soup from TerrainSystem::BuildNavGeometry. |
bool | NavBoundsVolumeExtent | The union of the level's Nav Mesh Bounds Volumes, false when it has none (the bake then covers every walkable triangle). |
void | ClampToNavBoundsVolumes | |
uint32_t | TerrainNavResolution | Samples per side the terrain soup is built at, derived from the component's own chunk grid so a landscape authored at a finer resolution bakes a finer nav surface. |
uint64_t | TerrainGeometryRevision | Live fold of every terrain's weightmap revision and build fingerprint. |
bool | IsTerrainStale | |
Result | Bake | Synchronous bake (kept for tools / tests / scripts that don't need async). |
std::future<AsyncResult> | BakeAsync | Async bake. |
Result | RunRecast | Run the Recast pipeline against a pre-captured Snapshot. |
std::future<PartialResult> | BakePartialAsync | Rebake a sub-rectangle of tiles in an existing tiled NavMeshAsset. |
NavMeshBakeSettings | SettingsForAgent | The bake settings for agent type agentIndex of base.agentTypes: its capsule over the shared voxel and region parameters. |
std::future<AsyncResult> | BakeAllAgentsAsync | Bakes the active agent type as the primary asset and every other entry of settings.agentTypes as an agent variant on it, all from one snapshot. |
std::future<std::shared_ptr<TileBatch>> | BakeTilesAsync | |
PartialResult | ApplyTileBatch | |
bool | TileRectForBounds | The tiles of asset's grid a world-space box touches, padded by the agent radius. |
dtNavMesh* | NavMeshAssetMultiTileInit | Allocate + init() a dtNavMesh sized for a tiled bake covering (tileCountX × tileCountY) tiles. |
int | TileCells | A tile edge in whole voxels, and the same edge in metres. |
float | TileWorldSize |
Function details
SnapshotScene
static Snapshot SnapshotScene(Scene& scene)Main-thread: walk the scene, collect every MeshRenderer's CPU-side triangles in world space, plus every terrain's hole-aware triangle soup from TerrainSystem::BuildNavGeometry. Empty snapshot is valid (the bake will fail with "no walkable geometry").
NavBoundsVolumeExtent
static bool NavBoundsVolumeExtent(Scene& scene, Vec3& outMin, Vec3& outMax)The union of the level's Nav Mesh Bounds Volumes, false when it has none (the bake then covers every walkable triangle).
ClampToNavBoundsVolumes
static void ClampToNavBoundsVolumes(Scene& scene, Snapshot& snap)TerrainNavResolution
static uint32_t TerrainNavResolution(const TerrainComponent& terrain)Samples per side the terrain soup is built at, derived from the component's own chunk grid so a landscape authored at a finer resolution bakes a finer nav surface. Clamped: below the floor a hole is smaller than one square and vanishes, above the ceiling one terrain alone outruns Recast's per-tile budget.
TerrainGeometryRevision
static uint64_t TerrainGeometryRevision(Scene& scene)Live fold of every terrain's weightmap revision and build fingerprint. A bake whose snapshot carries a different value is stale — painting a visibility hole changes which squares exist, and nothing else in the snapshot can see it.
IsTerrainStale
static bool IsTerrainStale(Scene& scene, const Snapshot& snapshot)Bake
static Result Bake(Scene& scene, const NavMeshBakeSettings& settings, NavMeshAsset& outAsset)Synchronous bake (kept for tools / tests / scripts that don't need async). Wraps SnapshotScene + RunRecast.
BakeAsync
static std::future<AsyncResult> BakeAsync(Snapshot snapshot, NavMeshBakeSettings settings, std::shared_ptr<BakeProgress> progress = nullptr)Async bake. Hand off a Snapshot produced on the main thread — the returned future runs the Recast pipeline on a worker thread and yields an AsyncResult with a fresh NavMeshAsset on success. The optional progress block is updated by the worker thread; the caller polls it each frame to drive a progress bar. It must outlive the future (a shared_ptr handles that without thinking). Usage: auto snap = SnapshotScene(scene); auto progress = std::make_shared<BakeProgress>(); auto fut = BakeAsync(std::move(snap), settings, progress); // ... later, on main thread: if (fut.wait_for(0s) == ready) { auto r = fut.get(); if (r.info.success) scene.SetNavMesh(r.asset);
RunRecast
static Result RunRecast(const Snapshot& snapshot, const NavMeshBakeSettings& settings, NavMeshAsset& outAsset, BakeProgress* progress = nullptr)Run the Recast pipeline against a pre-captured Snapshot. Safe to call from any thread — outAsset will own the produced dtNavMesh. Exposed for tooling that wants synchronous behaviour without the scene-walking step.
BakePartialAsync
static std::future<PartialResult> BakePartialAsync( Snapshot snapshot, NavMeshBakeSettings settings, Ref<NavMeshAsset> existingAsset, TileRect tileRect, std::shared_ptr<BakeProgress> progress = nullptr)Rebake a sub-rectangle of tiles in an existing tiled NavMeshAsset. Used for incremental authoring: edit a few props, click "Rebuild Around Camera", get a refreshed nav mesh without paying for the unaffected tiles. Only works on tiled assets (settings.tiled + multi-tile dtNavMesh) — solo bakes return success=false with an error. Affected tiles get removed from the existing dtNavMesh and re-added with the latest bake settings. Unaffected tiles stay untouched. Off-mesh links inside the rebaked region are recreated from snapshot.links automatically.
SettingsForAgent
static NavMeshBakeSettings SettingsForAgent(const NavMeshBakeSettings& base, int32_t agentIndex)The bake settings for agent type agentIndex of base.agentTypes: its capsule over the shared voxel and region parameters.
BakeAllAgentsAsync
static std::future<AsyncResult> BakeAllAgentsAsync(Snapshot snapshot, NavMeshBakeSettings settings, std::shared_ptr<BakeProgress> progress = nullptr)Bakes the active agent type as the primary asset and every other entry of settings.agentTypes as an agent variant on it, all from one snapshot. A variant that fails is skipped with a warning.
BakeTilesAsync
static std::future<std::shared_ptr<TileBatch>> BakeTilesAsync(Snapshot snapshot, NavMeshBakeSettings settings, TileRect tileRect, std::shared_ptr<BakeProgress> progress = nullptr)ApplyTileBatch
static PartialResult ApplyTileBatch(NavMeshAsset& asset, TileBatch& batch)TileRectForBounds
static bool TileRectForBounds(const NavMeshAsset& asset, const Vec3& boundsMin, const Vec3& boundsMax, TileRect& out)The tiles of asset's grid a world-space box touches, padded by the agent radius. False for a solo mesh or a box outside the grid.
NavMeshAssetMultiTileInit
static dtNavMesh* NavMeshAssetMultiTileInit(const Snapshot& snap, const NavMeshBakeSettings& settings, int tileCountX, int tileCountY)Allocate + init() a dtNavMesh sized for a tiled bake covering (tileCountX × tileCountY) tiles. Used by the tiled path in RunRecast; exposed because the asset doesn't know about the grid layout it'll be populated with.
TileCells
static int TileCells(const NavMeshBakeSettings& settings)A tile edge in whole voxels, and the same edge in metres. Every tile grid (bake, tile cache, dtNavMesh params, load) must use these rather than settings.tileSize: a tileSize that is not a multiple of cellSize left each tile's polygons short of the boundary its neighbour starts at, so Detour found no portals and adjacent tiles never connected.
TileWorldSize
static float TileWorldSize(const NavMeshBakeSettings& settings)