Navigation mesh conversion to ArrayMesh

Godot Version

4.3

Question

Hello, I am working on some extended navigation features, and at the moment I am investigating the replication of Unity’s AI.Navmesh.Raycast (some sort of 2D raycast detecting intersections with a navmesh’s edges).

By doing so, I realised NavigationMesh is directly inheriting from Resource, and it seems there is nothing existing to easily convert one to some Mesh.
Ideally I would have used MeshDataTool to manipulate polygons and edges, which would have needed an ArrayMesh, but from what I found I would have to design the solution to convert a NavigationMesh to an ArrayMesh myself.

So I would just like to know if I missed something or if there is a way to do so that I have not thought about ?

There is no direct conversion. The polygons of a navigation mesh are not necessarily rendering triangles or have the correct winding for rendering as a navigation mesh has convex polygons that can have many edges and the winding does not matter.

So you would need to account for that. If you have a very simple, baked mesh you can create a procedural ArrayMesh and set the Mesh.ARRAY_VERTEX with the NavigationMesh.vertices PackedVector3Array.

For the Mesh.ARRAY_INDEX you need to create a new PackedVectorInt32Array and loop over all the polygons of the NavigationMesh and add the indices for each polygon. If a polygon is not just a triangle but a convex polygon with more edges youl will need to split that up manually.

1 Like