/// <summary> /// Builds a single polygon from the nav mesh /// </summary> /// <param name="navmesh">the entire navmesh which contains all polygon data</param> /// <param name="refId">id of the polygon that is to be drawn</param> /// <param name="color">Color to make the polygon</param> /// <param name="verts">List of Verts to add to</param> /// <param name="colors">List of colors for specific polygons</param> /// <param name="uvs">List of UVs for the polygons</param> /// <param name="tris">List of Triangles for the polygons</param> private void BuildNavMeshPoly(Detour.NavMesh navmesh, long refId, Color color, List<Vector3> verts, List<Color> colors, List<Vector2> uvs, List<int> tris) { MeshTile tile = null; Poly poly = null; if ((navmesh.GetTileAndPolyByRef(refId, ref tile, ref poly) & Status.Failure) != 0) return; long ip = 0; for (int i = 0; i < tile.Polys.Length; i++) { if (poly == tile.Polys[i]) ip = i; } if (poly.Type == Detour.AtavismNavTile.PolyTypeOffMeshConnection) { // do nothing for now } else { PolyDetail pd = tile.DetailMeshes[ip]; for (int i = 0; i < pd.TriCount; i++) { int t = ((int)pd.TriBase + i) * 4; for (int j = 0; j < 3; j++) { if (tile.DetailTris[t + j] < poly.VertCount) { verts.Add(new Vector3(tile.Verts[poly.Verts[tile.DetailTris[t + j]] * 3 + 0], tile.Verts[poly.Verts[tile.DetailTris[t + j]] * 3 + 1], tile.Verts[poly.Verts[tile.DetailTris[t + j]] * 3 + 2])); } else { verts.Add( new Vector3(tile.DetailVerts[(pd.VertBase + tile.DetailTris[t + j] - poly.VertCount) * 3 + 0], tile.DetailVerts[(pd.VertBase + tile.DetailTris[t + j] - poly.VertCount) * 3 + 1], tile.DetailVerts[(pd.VertBase + tile.DetailTris[t + j] - poly.VertCount) * 3 + 2])); } uvs.Add(new Vector2()); colors.Add(color); tris.Add(tris.Count); } } } }