Rust bindings for Recast from recastnavigation
.
Recast is essentially a toolbox for generating navigation meshes from geometry. A good starting point for generating navigation meshes is:
Heightfield
.Heightfield
. Consider marking triangles as
walkable.CompactHeightfield
from the Heightfield
.CompactHeightfield
.ContourSet
from the CompactHeightfield
(with regions).PolyMesh
from the ContourSet
.PolyMesh
data as a navigation mesh.As a simple example of this process:
```Rust use recast_rs::*;
fn generatenavmesh(
vertices: &[Vec3
let (minbounds, maxbounds) = util::calculate_bounds(vertices);
let mut heightfield = Heightfield::new( &mut context, minbounds, maxbounds, /* cellhorizontalsize / 1.0, / cell_height= */ 1.0, )?;
let mut areaids = vec![0; triangles.len()]; util::markwalkabletriangles( &mut context, /* walkableslopeangle= */ 45.0, vertices, triangles, &mut areaids, );
heightfield.rasterizeindexedtrianglesi32( &mut context, vertices, triangles, &areaids, /* flagmergethreshold= */ 1, )?;
let mut compactheightfield = CompactHeightfield::
compactheightfield .erodewalkable_area(&mut context, /* radius= */ 1)?;
let compactheightfield = compactheightfield.buildregions( &mut context, /* bordersize= / 0, / minregionarea= / 0, / mergeregionarea= */ 0, )?;
let contourset = ContourSet::new( &compactheightfield, &mut context, /* maxerror= */ 1.0, /* maxedgelen= */ 10, ContourBuildFlags { tessellatewalledges: true, tessellatearea_edges: false, }, )?;
let polymesh = PolyMesh::new( &contourset, &mut context, /* maxverticesper_polygon= */ 8, )?;
Ok( polymesh .polygonsiter() .map(|polygon| { polygon .validvertices() .iter() .map(|&vertexindex| polymesh.vertex(vertexindex as usize).as_f32()) .collect() }) .collect(), ) } ```
Note in this example we just create a Vec for each polygon filled with the vertices that make up that polygon. In practice, you likely want to extract the neighbour information for each polygon to use this as a navigation mesh.
Licensed under the MIT license.