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.
Initialize once
Section titled “Initialize once”Recast runs in WebAssembly, so call initNavigation() once per app before building a
navmesh.
NavMeshManager
Section titled “NavMeshManager”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.
Baking in the editor
Section titled “Baking in the editor”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.
See also
Section titled “See also”- Capstone: RTS — navmesh crowd pathfinding in a build.
- Scene Schema reference — navmesh bake parameters.