/// <summary> /// Builds a Single polygon out of the NavMesh, called by BuildNavMeshGeometry /// </summary> /// <param name="refId"></param> /// <param name="color"></param> /// <param name="verts"></param> /// <param name="colors"></param> /// <param name="uvs"></param> /// <param name="tris"></param> private void BuildNavMeshPoly(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 == LunaNav.NavMeshBuilder.PolyTypeOffMeshConnection) { } 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);//duIntToCol((int)ip, 192)); tris.Add(tris.Count); } } } }
private static void AddMeshTile(MeshTile tile, List <Point3D> vertices, List <int> indices) { byte[] detailTris = tile.GetAllDetailIndices(); var verts = tile.GetAllVertices(); var detailVerts = tile.GetAllDetailVertices(); var vertMap = new Dictionary <uint, int>(); for (int i = 0; i < tile.Header.PolyCount; i++) { Poly p = tile.GetPoly(i); if (p.Type == 1) // DT_POLYTYPE_OFFMESH_CONNECTION { continue; } PolyDetail pd = tile.GetPolyDetail(i); for (int j = 0; j < pd.TriCount; j++) { for (int k = 0; k < 3; k++) { int index = detailTris[(pd.TriBase + j) * 4 + k]; uint vertIndex; if (index < p.VertCount) { vertIndex = p.GetVert(index); } else { var val = verts.Length + pd.VertBase + index - p.VertCount; Debug.Assert(val <= uint.MaxValue); vertIndex = (uint)val; } if (!vertMap.ContainsKey(vertIndex)) { var pos = vertIndex >= verts.Length ? detailVerts[vertIndex - verts.Length] : verts[vertIndex]; pos.Y += 0.03f; vertices.Add(new Point3D(pos.X, pos.Z, pos.Y + 0.5)); vertMap[vertIndex] = vertices.Count - 1; } indices.Add(vertMap[vertIndex]); } } } }
private PolyDetail[] readPolyDetails(ByteBuffer buf, MeshHeader header, bool cCompatibility) { PolyDetail[] polys = new PolyDetail[header.detailMeshCount]; for (int i = 0; i < polys.Length; i++) { polys[i] = new PolyDetail(); polys[i].vertBase = buf.Int; polys[i].triBase = buf.Int; polys[i].vertCount = buf.get() & 0xFF; polys[i].triCount = buf.get() & 0xFF; if (cCompatibility) { buf.Short; // C struct padding } } return(polys); }