skip to content

How is a navmesh generated from level geometry by voxelization, and why is the walkable area eroded by the agent's radius?

level: middleimportance: should knowfreq 45%

answer

  1. rasterize triangles into columns
  2. slope, headroom, step height
  3. shrink walkable cells inward
  4. regions, contours, polygons
  5. agent becomes a point

basics

~20 s

Level triangles are rasterized into a voxel heightfield, filtered by slope, headroom and step height, shrunk by the agent radius, and split into regions whose outlines become convex polygons. Erosion lets search treat the agent as a point.

solid answer

~50 s

Rasterize every collision triangle into a heightfield of vertical voxel columns at a chosen cell size and cell height. Mark a surface walkable if its slope is under the maximum walkable angle, then drop spans without headroom for the agent's height and ledges that fall to a neighbour by more than the climb height. **Erode** the walkable area inward by the agent radius, partition what remains into regions, trace and simplify each region's outline, and split it into convex polygons, often with a detail mesh for accurate height. Erosion is a configuration-space trick: once every walkable point is at least one radius from a wall, the agent's centre can go anywhere on the mesh, so search and the funnel treat the agent as a point and paths never clip walls. The cost is one mesh per agent radius.

go deeper

for a junior

Recall the broad steps: voxelize the geometry, keep walkable floor, shrink it by the agent radius, turn what is left into polygons.

for a middle

Explain each filter, slope, headroom, climb and ledge, why erosion turns the agent into a point, and why openings narrower than twice the radius vanish.

for a senior

Diagnose a missing doorway, agents on furniture or floating paths from the build parameters, and plan tile rebuilds for a changing world.

for a principal

Own the build pipeline: how many agent size classes, the tile size, build time inside content iteration, and the memory the meshes take.

## Why voxelize at all Level geometry is messy: overlapping props, stairs built from dozens of boxes, decorative meshes poking through floors, gaps between modules. Building polygons straight from those triangles would inherit every crack and overlap. Voxelization sidesteps the mess by **resampling** the world onto a regular 3D grid, where questions such as "is there floor here, and room to stand above it?" have simple answers. The output is a clean set of convex polygons that a search can use, produced automatically every time the level changes. ## The pipeline, step by step 1. **Rasterize.** Each triangle of the collision geometry is rasterized into a **heightfield**: a 2D grid of columns, where each column holds **spans**, vertical runs of solid space. The horizontal resolution is the **cell size** and the vertical one the **cell height**. 2. **Mark walkable surfaces.** A span's top is walkable if the triangle that produced it is flatter than the maximum walkable slope, by comparing its normal with the up axis. 3. **Filter.** Remove walkable tops without enough **headroom** for the agent's height before the next span above; allow stepping up onto low obstacles up to the **climb height**; drop **ledge** spans where a neighbour falls away by more than the climb height. 4. **Erode.** Shrink the walkable area inward by the **agent radius**, measured in cells, using a distance-to-boundary field. 5. **Partition into regions.** Split the remaining walkable cells into connected regions with simple outlines, for example by a watershed over the distance field, which tends to produce compact, well-shaped regions at some extra build cost. 6. **Trace and simplify contours.** Walk each region's border to get its outline, then simplify it so edges stay within a maximum error of the voxel border. 7. **Build polygons.** Triangulate each outline and merge triangles into convex polygons up to a vertex limit, then connect polygons that share sides. 8. **Detail mesh (optional).** Sample heights from the heightfield so that polygon surfaces follow stairs and bumpy ground closely enough for height queries. ## Erosion and the point-agent trick An agent is not a point: it has a radius. Planning for a disc of radius `r` among walls is equivalent to planning for a point among walls grown by `r`; that geometric idea is the **configuration space**. Eroding the walkable area by `r` builds exactly that grown-wall world into the mesh. Afterwards: - Any point on the mesh is at least `r` from a wall, so the agent's centre may stand anywhere on it. - The polygon search and the funnel step that straightens the route can treat the agent as a point; path corners land on mesh vertices that already sit a radius away from wall corners. - Openings narrower than `2r` vanish, because both sides are eroded by `r`. A 1.0 m doorway disappears for agents of radius 0.6 m, since `0.6 + 0.6 = 1.2`. The price is that **one mesh fits one radius**. Agents of different sizes need a mesh per size class, or a compromise in which small agents use a mesh eroded for a larger radius and lose some narrow gaps. ## Parameters and their trade-offs | Parameter | Too small | Too large | |---|---|---| | Cell size | Slow builds, more memory | Narrow gaps close; edges snap to the grid | | Cell height | Slow builds | Steps and headroom judged wrongly | | Agent radius | Agents clip walls | Real doorways close | | Climb height | Agents stuck at kerbs | Agents climb onto crates | | Max slope | Ramps become unwalkable | Steep cliffs become walkable | Because erosion works in whole cells, the radius is effectively rounded to a multiple of the cell size, so the radius should span a few cells. The right values depend on the game's scale and agents; no single default is correct. ## Tiles and runtime rebuilds Large levels are usually generated in **tiles**: square pieces of the world voxelized independently, with matching borders so neighbouring tiles connect. Tiles let the build run in parallel, let navigation data stream with the world, and let a runtime change, such as a collapsed wall, rebuild only the tiles it touched. ## Common failure modes - A doorway or corridor missing from the mesh: usually erosion against a radius too large for the opening, or a cell size too coarse. - Agents walking onto furniture: the climb height is larger than the furniture's top. - Floating or sunken paths on stairs: a missing or coarse detail mesh. - Tiny islands of navmesh on tabletops: remove regions below a minimum area.

  • How do you support agents of several sizes?
    Erosion bakes one radius into the mesh, so each size class gets its own mesh, or its own build of each tile, and each agent searches the mesh for its class. Memory and build time scale with the class count, so teams keep it small; the alternative is eroding for a larger radius and accepting that small agents lose narrow gaps.
  • Why generate the navmesh in tiles?
    A tile is an independent square of the world with its own voxelization, stitched to neighbours at shared borders. Tiles build in parallel, stream in and out with the world, and a local change, such as a placed building or a collapsed bridge, rebuilds only the touched tiles within a background budget.
  • What is the detail mesh for if the polygons already cover the floor?
    The polygons are simplified outlines with coarse heights, so on stairs or uneven ground their surface can float above or sink below the real floor. A detail mesh samples the heightfield to follow the surface closely; it is used for height queries and foot placement, while search still runs on the coarse polygons.

  • The navmesh is just the level's floor triangles copied directly.
  • One navmesh can serve agents of every size.
  • Smaller cells are always better because build time does not matter.
  • Agent radius only matters for local avoidance, not for the mesh.
  • A 1.0 m doorway stays open for agents of radius 0.6 m.