Skip to content

Navigation & pathfinding

AI navigation in vgai is built on recast-navigation (the Recast/Detour toolkit, via WASM). The NavMeshManager (packages/engine/src/ai/navigation.ts) bakes a navmesh from level geometry and answers pathfinding and crowd queries.

Walkable meshes are baked into a navmesh used for pathfinding and crowd steering
Meshes → navmesh → paths & crowds.

Recast runs in WebAssembly, so call initNavigation() once per app before building a navmesh.

  • buildFromMeshes(meshes, params?) — bake a navmesh from Three.js meshes (grounds, obstacles). Bake params tune cell size, walkable slope/height/climb/radius, edge length, simplification, and region area.
  • findPath(start, end) — a straight path between world positions (returns points).
  • createCrowd(maxAgents) / updateCrowd(dt) — a crowd simulation; step it each frame.
  • getDebugMesh(scene) — a wireframe visualization of the navmesh.
  • exportData() / loadFromData() — serialize / restore a baked navmesh.
  • dispose(scene) — free the recast WASM handles.

The editor bakes navmeshes from your scene: mark geometry with walkable / obstacle roles (packages/editor/src/navmesh-handler.ts) and bake. The bake parameters live in the scene’s environment settings (cell size/height, slope, height, climb, radius, edge length, simplification error, region area) — see the Scene Schema reference.