pub struct NavMesh {
pub vertices: Vec<NavVertex>,
pub triangles: Vec<NavTriangle>,
pub portals: Vec<Portal>,
/* private fields */
}Expand description
The main navigation mesh.
Fields§
§vertices: Vec<NavVertex>§triangles: Vec<NavTriangle>§portals: Vec<Portal>Implementations§
pub fn new() -> Self
Sourcepub fn add_vertex(&mut self, pos: Vec2) -> usize
pub fn add_vertex(&mut self, pos: Vec2) -> usize
Add a vertex and return its index.
Sourcepub fn add_triangle(&mut self, verts: [usize; 3]) -> usize
pub fn add_triangle(&mut self, verts: [usize; 3]) -> usize
Add a triangle (by vertex indices) and return its index.
Sourcepub fn build(&mut self)
pub fn build(&mut self)
Build adjacency, portals, and pre-compute geometry. Must be called after all triangles are added and before pathfinding.
Sourcepub fn point_in_triangle(&self, pt: Vec2, tri_idx: usize) -> bool
pub fn point_in_triangle(&self, pt: Vec2, tri_idx: usize) -> bool
Test whether a 2D point is inside a given triangle.
Sourcepub fn find_triangle(&self, pos: Vec2) -> Option<usize>
pub fn find_triangle(&self, pos: Vec2) -> Option<usize>
Find which triangle contains pos. Returns None if outside mesh.
Sourcepub fn find_path(&self, start: Vec2, end: Vec2) -> Option<Vec<Vec2>>
pub fn find_path(&self, start: Vec2, end: Vec2) -> Option<Vec<Vec2>>
Find a path from start to end using A* on the triangle graph,
then refine with the funnel (string-pulling) algorithm.
Sourcepub fn triangle_count(&self) -> usize
pub fn triangle_count(&self) -> usize
Returns the number of triangles.
Sourcepub fn portal_count(&self) -> usize
pub fn portal_count(&self) -> usize
Returns the number of portals.
Sourcepub fn contains(&self, pos: Vec2) -> bool
pub fn contains(&self, pos: Vec2) -> bool
Check whether a world position is inside the navmesh.
Sourcepub fn clamp_to_mesh(&self, pos: Vec2) -> Vec2
pub fn clamp_to_mesh(&self, pos: Vec2) -> Vec2
Clamp a position to the nearest point inside the navmesh.
Trait Implementations§
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.