internal CommonEdge(int _x, int _y, int _cx, int _cy) { this.edge = new PolyEdge(_x, _y); this.common = new PolyEdge(_cx, _cy); }
/// <summary> /// Returns a dictionary where each PolyEdge is mapped to a list of triangle indices that share that edge. /// To translate triangle list to vertex indices, multiply by 3 and take those indices (ex, triangles[index+{0,1,2}]) /// </summary> /// <param name="mesh">mesh to use</param> /// <returns>see summary</returns> internal static Dictionary <PolyEdge, List <int> > GetAdjacentTriangles(PolyMesh mesh) { //null checks if (mesh == null) { return(null); } int len = mesh.GetTriangles().Length; if (len % 3 != 0 || len / 3 == mesh.vertexCount) { return(new Dictionary <PolyEdge, List <int> >()); } Dictionary <PolyEdge, List <int> > lookup = null; // @todo - should add some checks to make sure triangle structure hasn't changed if (adjacentTrianglesCache.TryGetValue(mesh, out lookup) && lookup.Count == mesh.vertexCount) { return(lookup); } if (adjacentTrianglesCache.ContainsKey(mesh)) { adjacentTrianglesCache.Remove(mesh); } int subMeshCount = mesh.subMeshCount; lookup = new Dictionary <PolyEdge, List <int> >(); List <int> connections; for (int n = 0; n < subMeshCount; n++) { int[] tris = mesh.subMeshes[n].indexes; for (int i = 0; i < tris.Length; i += 3) { int index = i / 3; PolyEdge a = new PolyEdge(tris[i], tris[i + 1]); PolyEdge b = new PolyEdge(tris[i + 1], tris[i + 2]); PolyEdge c = new PolyEdge(tris[i + 2], tris[i]); if (lookup.TryGetValue(a, out connections)) { connections.Add(index); } else { lookup.Add(a, new List <int>() { index }); } if (lookup.TryGetValue(b, out connections)) { connections.Add(index); } else { lookup.Add(b, new List <int>() { index }); } if (lookup.TryGetValue(c, out connections)) { connections.Add(index); } else { lookup.Add(c, new List <int>() { index }); } } } adjacentTrianglesCache.Add(mesh, lookup); return(lookup); }