pub struct NavMesh { /* private fields */ }Expand description
Nav mesh object used to find shortest path between two points.
Implementations§
Sourcepub fn new(
vertices: Vec<NavVec3>,
triangles: Vec<NavTriangle>,
) -> NavResult<Self>
pub fn new( vertices: Vec<NavVec3>, triangles: Vec<NavTriangle>, ) -> NavResult<Self>
Create new nav mesh object from vertices and triangles.
§Arguments
vertices- list of vertices points.triangles- list of vertices indices that produces triangles.
§Returns
Ok with nav mesh object or Err with Error::TriangleVerticeIndexOutOfBounds if input
data is invalid.
§Example
use navmesh::*;
let vertices = vec![
(0.0, 0.0, 0.0).into(), // 0
(1.0, 0.0, 0.0).into(), // 1
(2.0, 0.0, 1.0).into(), // 2
(0.0, 1.0, 0.0).into(), // 3
(1.0, 1.0, 0.0).into(), // 4
(2.0, 1.0, 1.0).into(), // 5
];
let triangles = vec![
(0, 1, 4).into(), // 0
(4, 3, 0).into(), // 1
(1, 2, 5).into(), // 2
(5, 4, 1).into(), // 3
];
let mesh = NavMesh::new(vertices, triangles).unwrap();pub fn thicken(&self, value: Scalar) -> NavResult<Self>
pub fn scale(&self, value: NavVec3, origin: Option<NavVec3>) -> NavResult<Self>
Sourcepub fn triangles(&self) -> &[NavTriangle]
pub fn triangles(&self) -> &[NavTriangle]
Reference to list of nav mesh triangles.
Sourcepub fn set_area_cost(&mut self, index: usize, cost: Scalar) -> Scalar
pub fn set_area_cost(&mut self, index: usize, cost: Scalar) -> Scalar
Sourcepub fn find_path(
&self,
from: NavVec3,
to: NavVec3,
query: NavQuery,
mode: NavPathMode,
) -> Option<Vec<NavVec3>>
pub fn find_path( &self, from: NavVec3, to: NavVec3, query: NavQuery, mode: NavPathMode, ) -> Option<Vec<NavVec3>>
Find shortest path on nav mesh between two points.
§Arguments
from- query point from.to- query point to.query- query quality.mode- path finding quality.
§Returns
Some with path points on nav mesh if found or None otherwise.
§Example
use navmesh::*;
let vertices = vec![
(0.0, 0.0, 0.0).into(), // 0
(1.0, 0.0, 0.0).into(), // 1
(2.0, 0.0, 1.0).into(), // 2
(0.0, 1.0, 0.0).into(), // 3
(1.0, 1.0, 0.0).into(), // 4
(2.0, 1.0, 1.0).into(), // 5
];
let triangles = vec![
(0, 1, 4).into(), // 0
(4, 3, 0).into(), // 1
(1, 2, 5).into(), // 2
(5, 4, 1).into(), // 3
];
let mesh = NavMesh::new(vertices, triangles).unwrap();
let path = mesh
.find_path(
(0.0, 1.0, 0.0).into(),
(1.5, 0.25, 0.5).into(),
NavQuery::Accuracy,
NavPathMode::MidPoints,
)
.unwrap();
assert_eq!(
path.into_iter()
.map(|v| (
(v.x * 10.0) as i32,
(v.y * 10.0) as i32,
(v.z * 10.0) as i32,
))
.collect::<Vec<_>>(),
vec![(0, 10, 0), (10, 5, 0), (15, 2, 5),]
);Sourcepub fn find_path_custom<F>(
&self,
from: NavVec3,
to: NavVec3,
query: NavQuery,
mode: NavPathMode,
filter: F,
) -> Option<Vec<NavVec3>>
pub fn find_path_custom<F>( &self, from: NavVec3, to: NavVec3, query: NavQuery, mode: NavPathMode, filter: F, ) -> Option<Vec<NavVec3>>
Find shortest path on nav mesh between two points, providing custom filtering function.
§Arguments
from- query point from.to- query point to.query- query quality.mode- path finding quality.filter- closure that gives you a connection distance squared, first triangle index and second triangle index.
§Returns
Some with path points on nav mesh if found or None otherwise.
§Example
use navmesh::*;
let vertices = vec![
(0.0, 0.0, 0.0).into(), // 0
(1.0, 0.0, 0.0).into(), // 1
(2.0, 0.0, 1.0).into(), // 2
(0.0, 1.0, 0.0).into(), // 3
(1.0, 1.0, 0.0).into(), // 4
(2.0, 1.0, 1.0).into(), // 5
];
let triangles = vec![
(0, 1, 4).into(), // 0
(4, 3, 0).into(), // 1
(1, 2, 5).into(), // 2
(5, 4, 1).into(), // 3
];
let mesh = NavMesh::new(vertices, triangles).unwrap();
let path = mesh
.find_path_custom(
(0.0, 1.0, 0.0).into(),
(1.5, 0.25, 0.5).into(),
NavQuery::Accuracy,
NavPathMode::MidPoints,
|_dist_sqr, _first_idx, _second_idx| true,
)
.unwrap();
assert_eq!(
path.into_iter()
.map(|v| (
(v.x * 10.0) as i32,
(v.y * 10.0) as i32,
(v.z * 10.0) as i32,
))
.collect::<Vec<_>>(),
vec![(0, 10, 0), (10, 5, 0), (15, 2, 5),]
);Sourcepub fn find_path_triangles(
&self,
from: usize,
to: usize,
) -> Option<(Vec<usize>, Scalar)>
pub fn find_path_triangles( &self, from: usize, to: usize, ) -> Option<(Vec<usize>, Scalar)>
Find shortest path on nav mesh between two points.
§Arguments
from- query point from.to- query point to.query- query quality.mode- path finding quality.
§Returns
Some with path points on nav mesh and path length if found or None otherwise.
§Example
use navmesh::*;
let vertices = vec![
(0.0, 0.0, 0.0).into(), // 0
(1.0, 0.0, 0.0).into(), // 1
(2.0, 0.0, 1.0).into(), // 2
(0.0, 1.0, 0.0).into(), // 3
(1.0, 1.0, 0.0).into(), // 4
(2.0, 1.0, 1.0).into(), // 5
];
let triangles = vec![
(0, 1, 4).into(), // 0
(4, 3, 0).into(), // 1
(1, 2, 5).into(), // 2
(5, 4, 1).into(), // 3
];
let mesh = NavMesh::new(vertices, triangles).unwrap();
let path = mesh.find_path_triangles(1, 2).unwrap().0;
assert_eq!(path, vec![1, 0, 3, 2]);Sourcepub fn find_path_triangles_custom<F>(
&self,
from: usize,
to: usize,
filter: F,
) -> Option<(Vec<usize>, Scalar)>
pub fn find_path_triangles_custom<F>( &self, from: usize, to: usize, filter: F, ) -> Option<(Vec<usize>, Scalar)>
Find shortest path on nav mesh between two points, providing custom filtering function.
§Arguments
from- query point from.to- query point to.query- query quality.mode- path finding quality.filter- closure that gives you a connection distance squared, first triangle index and second triangle index.
§Returns
Some with path points on nav mesh and path length if found or None otherwise.
§Example
use navmesh::*;
let vertices = vec![
(0.0, 0.0, 0.0).into(), // 0
(1.0, 0.0, 0.0).into(), // 1
(2.0, 0.0, 1.0).into(), // 2
(0.0, 1.0, 0.0).into(), // 3
(1.0, 1.0, 0.0).into(), // 4
(2.0, 1.0, 1.0).into(), // 5
];
let triangles = vec![
(0, 1, 4).into(), // 0
(4, 3, 0).into(), // 1
(1, 2, 5).into(), // 2
(5, 4, 1).into(), // 3
];
let mesh = NavMesh::new(vertices, triangles).unwrap();
let path = mesh.find_path_triangles_custom(
1,
2,
|_dist_sqr, _first_idx, _second_idx| true
).unwrap().0;
assert_eq!(path, vec![1, 0, 3, 2]);pub fn find_triangle_islands(&self) -> Vec<Vec<usize>>
Sourcepub fn path_target_point(
path: &[NavVec3],
point: NavVec3,
offset: Scalar,
) -> Option<(NavVec3, Scalar)>
pub fn path_target_point( path: &[NavVec3], point: NavVec3, offset: Scalar, ) -> Option<(NavVec3, Scalar)>
Trait Implementations§
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.