Sorting through the triangles of a NavMesh to get a single triangle from a specific area?

Okay so I undertstand how I should be doing this:

  • NavMeshTriangulation.areas is an int, each element corresponds to a triangle on the Navesh, with
    each int indicating the area (NavMeshTriangulation.areas[16] could be part of area 5 for example).
  • NavMeshTriangulation.indices is an int, in groups of 3 they correspond to the indices of the
    vertices (NavMeshTriangulation.indices[0] through [5] would be { 0, 1, 2, 0, 2, 3 } for a square.
  • NavMeshTriangulation.vertices is a Vector3 containing the vectors of all the verts.

So to draw a ray for each vertex of an area I would:

  • Loop through the area to see if the index matches my area (5), store the index in a List or something.
  • Loop through the indices (using the stored area ints to make sure I’m looking at the right triangle),
    store the index in another List, plus the two indexes after (to make a triangle).
  • Finally use the stored values in the second list to Debug.DrawRay() the vertices.

However I’ve tried doing this and it keeps coming out wrong. I can draw a ray for every vertex on the NavMesh no problem, when I try and do it for a specific area it draws the rays on points other than that.

I’m probably just messing up a really silly calculation somewhere but if I do it by hand it all checks out.

Here’s a very broken down version of my code that I made to make sure everything looked good: hatebin

Thank you for any help!

Turns out that I was just getting confused and mixing up some of the vertex Vectors, here’s the basic code to put a ray on each point of a specific area (In this case area 5):

for (int i = 0; i < navMeshTriangulation.areas.Length; i++) { if (navMeshTriangulation.areas *== 5)* *{* _int j = i * 3;_ *for (int x = 0; x < 3; x++)* *{* *Debug.DrawRay(navMeshTriangulation.vertices[navMeshTriangulation.indices[j + x]],* *Vector3.up, Color.blue, 30.0f);* *}* *}* *}*
It would be really usefull if you could somehow see the triangles with their index in the editor, but this shall suffice.