Struct oxygengine_navigation::resource::NavMesh [−][src]
pub struct NavMesh { /* fields omitted */ }Expand description
Nav mesh object used to find shortest path between two points.
Implementations
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();
Reference to list of nav mesh triangles.
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),] );
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),] );
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]);
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]);
Trait Implementations
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<NavMesh, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>, [src]
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<NavMesh, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>, [src]Deserialize this value from the given Serde deserializer. Read more
pub fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer, [src]
pub fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer, [src]Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations
impl RefUnwindSafe for NavMeshimpl UnwindSafe for NavMeshBlanket Implementations
impl<T> Any for T where
T: Any,
impl<T> Any for T where
T: Any, pub fn get_type_id(&self) -> TypeIdMutably borrows from an owned value. Read more
type Output = T
type Output = TShould always be Self
The inverse inclusion map: attempts to construct self from the equivalent element of its
superset. Read more
pub fn is_in_subset(&self) -> bool
pub fn is_in_subset(&self) -> boolChecks if self is actually part of its subset T (and can be converted to it).
pub unsafe fn to_subset_unchecked(&self) -> SS
pub unsafe fn to_subset_unchecked(&self) -> SSUse with care! Same as self.to_subset but without any property checks. Always succeeds.
pub fn from_subset(element: &SS) -> SP
pub fn from_subset(element: &SS) -> SPThe inclusion map: converts self to the equivalent element of its superset.
impl<T> TryDefault for T where
T: Default,
impl<T> TryDefault for T where
T: Default, pub fn try_default() -> Result<T, String>
pub fn try_default() -> Result<T, String>Tries to create the default.
fn unwrap_default() -> Self
fn unwrap_default() -> SelfCalls try_default and panics on an error case.