Struct navmesh::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();

Nav mesh identifier.

Nav mesh origin point.

Reference to list of nav mesh vertices points.

Reference to list of nav mesh triangles.

Reference to list of nav mesh area descriptors.

Set area cost by triangle index.

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

Old area cost value.

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.

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

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.

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.

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.

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.

Calculate path length.

Arguments
  • path - path points.
Returns

Path length.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Deserialize this value from the given Serde deserializer. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

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

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

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

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.