Building a graph from a mesh

So I’m building a graph out of the vertices and indices returned from NavMesh.CalculateTriangulation, which I’m using in a java based A* pathfinding library. But I think there is something I’m doing wrong. The paths being generated on the server basically have the x and z coordinates swapped.

Each node in my graph has a vertex, and an array of all other vertices it is connected to. I build it like so. Pseudo code.

// Build nodes first out of vertices
foreach vertex in vertices
    create node with position as vertex

foreach node
    foreach triangle in mesh
      if node vertex equals one of the triangle vertices, add the two triangle vertices that are not me as connected vertices

The graph is very simple, with a method that takes a node, and returns all connected nodes. This is used by the pathfinder. The heuristic is just a distance calculation between two nodes.

There is something I’m missing here but I’m just not seeing it.

I wasn’t completely accurate on the x and z coordinates being swapped. The path from my server code results in the end node being correct, but most of the middle coordinates look swapped. It feels like a rotation issue as best I can explain.

So once I exported the paths created by the server and displayed them in unity, the problem just turned out to be different paths taken around obstacles. The bigger issue as it turns out is that the data returned by NavMesh.CalculateTriangulation is not the actual navmesh. It’s clearly for visual display purposes only, as it is just not possible for the paths unity is generating to have come from what’s in NavMesh.CalculateTriangulation.