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
- Implement
Source2dorSource3d(anyrepame_physics::VoxelQueryis aSource3d) and callbake_2dorbake_3dto get aNavMesh. - Query with
NavMesh::find_path, or wrap the mesh in aNavMapto layer dynamicNavObstacles and off-meshNavLinks on top. - Drive a
NavigationAgentwith 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§
- Agent
Neighbor - Another agent seen by the avoidance resolver.
- Avoidance
Config - Tuning for
resolve. - Bake2d
- 2D bake parameters.
minis inclusive,maxexclusive. - Bake3d
- 3D bake parameters.
minis inclusive,maxexclusive; 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.
- Navigation
Agent - Follows a path returned by
NavMesh::find_pathorNavMap::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::Vec2for flat 2D navigation,glam::Vec3for 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).