Build a walkable navigation mesh from glTF 2.0 or GLB geometry.
dotnet add package RecursiveAI.OnePathRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
The download includes floor.gltf.
using RecursiveAI.OnePath; var mesh = NavMesh.BuildGltf( File.ReadAllBytes("floor.gltf")); var path = mesh.FindPath( new(2, 0, 2), new(18, 0, 18)); Console.WriteLine($"Path: {path.Status}");
Path: FoundThe input contains a flat square at Y = 0, with corners (0, 0, 0), (0, 0, 20), (20, 0, 20) and (20, 0, 0). Its two triangles use indices 0,1,2, 0,2,3, wound counter-clockwise when viewed from above. The embedded buffer holds the positions followed by those indices. Its primitive is:
{"attributes":{"POSITION":0},"indices":1}Malformed or unsupported input throws GltfException, whose message identifies the JSON path that failed.
Unzip the example, then dotnet run.
Variations
Save the built mesh and load it without reading the glTF again. Append this to the program:
File.WriteAllBytes("floor.navmesh", mesh.Save()); var loaded = NavMesh.Load(File.ReadAllBytes("floor.navmesh")); Console.WriteLine(loaded.FindPath( new(2, 0, 2), new(18, 0, 18)).Status);
FoundSet the character’s dimensions and movement limits explicitly. Radius, height and climb are in world units; slope is in degrees. Append this to the program:
var settings = new NavSettings { AgentRadius = 0.4, AgentHeight = 1.8, AgentMaxSlopeDegrees = 40, WalkableClimb = 0.3 }; var tuned = NavMesh.BuildGltf( File.ReadAllBytes("floor.gltf"), settings); Console.WriteLine(tuned.FindPath( new(2, 0, 2), new(18, 0, 18)).Status);
FoundFor an external buffer, add using RecursiveAI.OnePath.Mesh.Build3D; and append the following. The download includes floor-external.gltf, which uses the same geometry but replaces its embedded buffer URI with "floor.bin", and that binary buffer. This resolver accepts only that known filename:
var options = new GltfOptions { ResolveBuffer = uri => uri == "floor.bin" ? File.ReadAllBytes(uri) : null }; var external = NavMesh.BuildGltf( File.ReadAllBytes("floor-external.gltf"), options: options); Console.WriteLine(external.FindPath( new(2, 0, 2), new(18, 0, 18)).Status);
FoundRelated recipes
The short answer
Use NavMesh.BuildGltf with the file’s bytes. OnePath reads its triangle geometry, applies scene-node transforms and sends the world-space triangles through the 3D builder. Query the resulting mesh with FindPath; the example prints Found because both endpoints lie on the connected floor.
The input is level geometry, not an already-baked navigation mesh. The builder determines walkability from slope, clearance, step height and character radius. This makes the same asset useful for builds with different character sizes. Keep the chosen build settings with the asset so the application can reproduce the mesh later.
How do you build a navmesh from a glTF file?
Read the file as bytes and pass those bytes to BuildGltf. It accepts glTF JSON and binary GLB, recognizing GLB by its magic header rather than its filename. The glTF input documentation describes the reader’s exact scope.
For a self-contained JSON sample, use an embedded base64 data URI as this download does. For a file whose JSON references separate buffers, supply GltfOptions.ResolveBuffer: the reader does not open external files on its own. An unresolved URI is an error naming that URI. Resolve paths relative to your asset directory, not an unrelated process working directory.
The reader uses the selected scene, or scene zero when none is selected. With no scene list, it starts from root nodes. Node matrices or translation, rotation and scale determine world-space positions. Instanced geometry is included at each instance’s transformed location. You do not need to flatten the scene yourself before building.
What glTF JSON geometry can become a navmesh?
The reader accepts floating-point POSITION accessors with finite VEC3 coordinates and optional unsigned indices. It reads triangles, triangle strips and triangle fans. Line and point primitives are skipped. Floor triangles should face upward: the builder uses counter-clockwise winding as seen from the walkable side, with Y as the vertical axis.
Materials, cameras, skins, animation and morph targets are not read. Sparse accessors and normalized or integer positions are errors. Required extensions must be absent. For an animated level, export the static collision geometry you actually want to navigate rather than expecting an animation pose to be baked.
A successfully parsed file does not guarantee a walkable result. A surface can be too steep, a passage too narrow after radius erosion, or a small region removed by build settings. Inspect the scale and winding first, then adjust the settings to the physical character rather than treating every triangle as walkable. The 3D build documentation explains those filters.
Save produces mesh bytes and NavMesh.Load reconstructs the mesh, as the variation shows. Build during asset preparation when the geometry is static, then ship the saved bytes with your application. This separates loading navigation data from reading and processing render geometry.
Saving the mesh is different from keeping a runtime tile cache. A saved mesh supports path queries; dynamic obstacle rebuilding also needs cached geometry stages. When doors or barricades must change walkability, build through the cached pipeline described in the related dynamic-obstacle recipe.