vleue / polyanya

Pathfinding using Polyanya
Apache License 2.0
266 stars 19 forks source link

Polyanya can't load mesh files it writes #42

Open MJohnson459 opened 9 months ago

MJohnson459 commented 9 months ago

When creating a mesh file using PolyanyaFile it creates the file mostly to spec but doesn't include the polygon neighbours as defined here.

Using the same example, instead of the expected

mesh
2
4 2
0.0 0.0 2 0 -1
1.5 0.0 3 0 1 -1
1.5 1.5 2 1 -1
0.0 1.5 3 -1 1 0
3 0 1 3 -1 -1 1
3 1 2 3 0 -1 -1

it writes

mesh
2
4 2
0.0 0.0 2 0 -1
1.5 0.0 3 0 1 -1
1.5 1.5 2 1 -1
0.0 1.5 3 -1 1 0
3 0 1 3
3 1 2 3

Loading this file then fails this assert

assert!(data.len() == nb * 2);

While removing this assert does allow the file to be loaded, the one-way flag is wrong as it defaults to true when there are no neighbours.

I saved the file with this code:

        let mut mesh = PolyanyaMesh::new(vertices, polygons);
        let file: PolyanyaFile = mesh.clone().into();
        file.to_file(&"nav_mesh.mesh");