class

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

TypeNameDescription
static constexpr const char*kCancelledErrorDefault "cancelled".

Public functions

ReturnsNameDescription
SnapshotSnapshotSceneMain-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.
boolNavBoundsVolumeExtentThe union of the level's Nav Mesh Bounds Volumes, false when it has none (the bake then covers every walkable triangle).
voidClampToNavBoundsVolumes
uint32_tTerrainNavResolutionSamples 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_tTerrainGeometryRevisionLive fold of every terrain's weightmap revision and build fingerprint.
boolIsTerrainStale
ResultBakeSynchronous bake (kept for tools / tests / scripts that don't need async).
std::future<AsyncResult>BakeAsyncAsync bake.
ResultRunRecastRun the Recast pipeline against a pre-captured Snapshot.
std::future<PartialResult>BakePartialAsyncRebake a sub-rectangle of tiles in an existing tiled NavMeshAsset.
NavMeshBakeSettingsSettingsForAgentThe bake settings for agent type agentIndex of base.agentTypes: its capsule over the shared voxel and region parameters.
std::future<AsyncResult>BakeAllAgentsAsyncBakes 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
PartialResultApplyTileBatch
boolTileRectForBoundsThe tiles of asset's grid a world-space box touches, padded by the agent radius.
dtNavMesh*NavMeshAssetMultiTileInitAllocate + init() a dtNavMesh sized for a tiled bake covering (tileCountX × tileCountY) tiles.
intTileCellsA tile edge in whole voxels, and the same edge in metres.
floatTileWorldSize

Function details

SnapshotScene

C++
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").

C++
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

C++
static void ClampToNavBoundsVolumes(Scene& scene, Snapshot& snap)

TerrainNavResolution

C++
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

C++
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

C++
static bool IsTerrainStale(Scene& scene, const Snapshot& snapshot)

Bake

C++
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

C++
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

C++
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

C++
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

C++
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

C++
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

C++
static std::future<std::shared_ptr<TileBatch>> BakeTilesAsync(Snapshot snapshot, NavMeshBakeSettings settings, TileRect tileRect, std::shared_ptr<BakeProgress> progress = nullptr)

ApplyTileBatch

C++
static PartialResult ApplyTileBatch(NavMeshAsset& asset, TileBatch& batch)

TileRectForBounds

C++
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.

C++
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

C++
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

C++
static float TileWorldSize(const NavMeshBakeSettings& settings)
Generated from AINavigation/NavMeshBuilder.h via ainavigation.json · Oct 27, 2026Version 1.0.0