Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Semihazah opened this issue Jul 30, 2023 · 0 comments
Open

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

Semihazah opened this issue Jul 30, 2023 · 0 comments

Comments

@Semihazah
Copy link

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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant