Skip to main content

Crate repame_nav

Crate repame_nav 

Source
Expand description

Spatial navigation for Repame: a heightfield navmesh you bake from the engine’s own collision input, A* path queries over the region graph, funnel (string-pull) corridors, and path-following agents with reciprocal velocity obstacle avoidance. Both 2D (glam::Vec2) and 3D (glam::Vec3) meshes share one implementation.

§Pipeline

  1. Implement Source2d or Source3d (any repame_physics::VoxelQuery is a Source3d) and call bake_2d or bake_3d to get a NavMesh.
  2. Query with NavMesh::find_path, or wrap the mesh in a NavMap to layer dynamic NavObstacles and off-mesh NavLinks on top.
  3. Drive a NavigationAgent with the returned path.

§Determinism

Bakes emit regions in row-major cell order and deduplicate shared corners, so vertex numbering is fixed. Adjacency and path results never iterate a hash map; A* breaks cost ties by polygon index and the funnel is order-stable. Obstacles and links are read in insertion order, and the avoidance resolver samples a fixed fan around sorted neighbours. Within one binary, the same inputs give bit-identical output. Cross-target float equality (native libm vs wasm, notably sqrt/sin_cos) is not claimed, the same caveat as [repame_sim]: hash a trace and diff to prove it.

use repame_nav::{bake_2d, Bake2d, Source2d};
use glam::Vec2;

struct Open;
impl Source2d for Open {
    fn is_solid(&self, _cell: [i32; 2]) -> bool { false }
}

let mesh = bake_2d(&Open, &Bake2d { min: [0, 0], max: [4, 4], cell_size: 1.0, agent_radius: 0.0 })
    .expect("open field bakes");
let path = mesh.find_path(Vec2::new(0.5, 0.5), Vec2::new(3.5, 3.5)).expect("connected");
assert_eq!(path.len(), 2);

Structs§

AgentNeighbor
Another agent seen by the avoidance resolver.
AvoidanceConfig
Tuning for resolve.
Bake2d
2D bake parameters. min is inclusive, max exclusive.
Bake3d
3D bake parameters. min is inclusive, max exclusive; a voxel is one world unit.
NavLink
A one-way or bidirectional off-mesh connection between two world points.
NavMap
A baked mesh plus the dynamic data layered on top of it for queries.
NavMesh
A navigation mesh: vertices plus convex polygon regions plus adjacency.
NavObstacle
A dynamic carved region, in navigation-plane coordinates.
NavigationAgent
Follows a path returned by NavMesh::find_path or NavMap::find_path.
Neighbor
The region across one directed edge of a polygon.
Neighbor2
A neighbour in the navigation plane.
Polygon
One convex region, stored as indices into the mesh vertex buffer.

Enums§

NavError
A navigation setup or query refused to build.

Constants§

VOXEL
Unit horizontal size of one voxel column, in world units.

Traits§

NavVec
A point or vector a navmesh can be built from: glam::Vec2 for flat 2D navigation, glam::Vec3 for a 3D heightfield.
Source2d
2D solidity sampler: a cell is either solid or free.
Source3d
3D collision sampler: solidity plus the top surface height behind a cell (ramps live behind Source3d::surface_top).

Functions§

bake_2d
Bake a flat 2D navmesh of unit squares from a solidity sampler.
bake_3d
Bake a heightfield 3D navmesh from a collision sampler.
funnel
Pull a straight path through an ordered list of portal segments.
resolve
Resolve desired against nearby agents. Returns the chosen velocity.