Skip to content
This repository was archived by the owner on Nov 14, 2025. It is now read-only.

Request: Add ability to check walkability of particular point. #15

@Semihazah

Description

@Semihazah

Hi, I'm trying to make a 3d TTRPG and would like to be able to place tiles based on the nav-mesh. Would it be possible to add a function to test if a particular point lies on or near a walkable point? I've been trying to use find_closest_polygon_in_box but it seems to return very inconsistent results.
Here's sample of what I have.
image

And the code for check_point and point_in_triangle:

fn check_point(point: Vec3, tile_coord: UVec2, poly_index: u16, tiles: &NavMeshTiles) -> bool {
    let tile = tiles.get_tiles().get(&tile_coord).unwrap();
    let poly = &tile.polygons[poly_index as usize];
    let indices = &poly.indices;
    for i in (0..indices.len()).step_by(3) {
        let a = tile.vertices[indices[i] as usize];
        let b = tile.vertices[indices[(i + 1) % indices.len()] as usize];
        let c = tile.vertices[indices[(i + 2) % indices.len()] as usize];
        if point_in_triangle(point, [a, b, c]) {
            return true
        }
    }
    return false
}

pub fn point_in_triangle(point: Vec3, triangle: [Vec3; 3]) -> bool{
    let mut a = triangle[0];
    let mut b = triangle[1];
    let mut c = triangle[2];
    let p = point;
    a -= p;
    b -= p;
    c -= p;

    let u = b.cross(c);
    let v = c.cross(a);
    let w = a.cross(b);

    if u.dot(v) < 0f32 {
        return false
    }
    if u.dot(w) < 0f32 {
        return false;
    }

    true
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions