NavMesh

Struct NavMesh 

Source
pub struct NavMesh { /* private fields */ }
Expand description

Nav mesh object used to find shortest path between two points.

Implementations§

Source§

impl NavMesh

Source

pub fn new( vertices: Vec<NavVec3>, triangles: Vec<NavTriangle>, ) -> Result<NavMesh, Error>

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 oxygengine_navigation::prelude::*;

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();
Source

pub fn id(&self) -> ID<NavMesh>

Nav mesh identifier.

Source

pub fn vertices(&self) -> &[NavVec3]

Reference to list of nav mesh vertices points.

Source

pub fn triangles(&self) -> &[NavTriangle]

Reference to list of nav mesh triangles.

Source

pub fn areas(&self) -> &[NavArea]

Reference to list of nav mesh area descriptors.

Source

pub fn set_area_cost(&mut self, index: usize, cost: f64) -> f64

Set area cost by triangle index.

§Arguments
  • index - triangle index.
  • cost - cost factor.
§Returns

Old area cost value.

Source

pub fn closest_point(&self, point: NavVec3, query: NavQuery) -> Option<NavVec3>

Find closest point on nav mesh.

§Arguments
  • point - query point.
  • query - query quality.
§Returns

Some with point on nav mesh if found or None otherwise.

Source

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 oxygengine_navigation::prelude::*;

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),]
);
Source

pub fn find_path_triangles( &self, from: usize, to: usize, ) -> Option<(Vec<usize>, f64)>

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 oxygengine_navigation::prelude::*;

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]);
Source

pub fn find_closest_triangle( &self, point: NavVec3, query: NavQuery, ) -> Option<usize>

Find closest triangle on nav mesh closest to given point.

§Arguments
  • point - query point.
  • query - query quality.
§Returns

Some with nav mesh triangle index if found or None otherwise.

Source

pub fn path_target_point( path: &[NavVec3], point: NavVec3, offset: f64, ) -> Option<(NavVec3, f64)>

Find target point on nav mesh path.

§Arguments
  • path - path points.
  • point - source point.
  • offset - target point offset from the source on path.
§Returns

Some with point and distance from path start point if found or None otherwise.

Source

pub fn project_on_path(path: &[NavVec3], point: NavVec3, offset: f64) -> f64

Project point on nav mesh path.

§Arguments
  • path - path points.
  • point - source point.
  • offset - target point offset from the source on path.
§Returns

Distance from path start point.

Source

pub fn point_on_path(path: &[NavVec3], s: f64) -> Option<NavVec3>

Find point on nav mesh path at given distance.

§Arguments
  • path - path points.
  • s - Distance from path start point.
§Returns

Some with point on path ot None otherwise.

Source

pub fn path_length(path: &[NavVec3]) -> f64

Calculate path length.

§Arguments
  • path - path points.
§Returns

Path length.

Trait Implementations§

Source§

impl Clone for NavMesh

Source§

fn clone(&self) -> NavMesh

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NavMesh

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for NavMesh

Source§

fn default() -> NavMesh

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Any for T
where T: Any,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

unsafe fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> TryDefault for T
where T: Default,

Source§

fn try_default() -> Result<T, String>

Tries to create the default.
Source§

fn unwrap_default() -> Self

Calls try_default and panics on an error case.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Erased for T

Source§

impl<T> Event for T
where T: Send + Sync + 'static,

Source§

impl<T> Resource for T
where T: Any + Send + Sync,