private static void MeshEdges(Mesh mesh, Tile tile, HashSet <Vector3D> completed, Polygon boundary) { for (int i = 0; i < tile.Boundary.Segments.Count; i++) { Segment boundarySeg = tile.Boundary.Segments[i]; Segment d1 = tile.Drawn.Segments[i]; if (completed.Contains(boundarySeg.Midpoint)) { continue; } // Find the incident segment. Segment seg2 = null, d2 = null; foreach (Tile incident in tile.EdgeIncidences) { for (int j = 0; j < incident.Boundary.Segments.Count; j++) { if (boundarySeg.Midpoint == incident.Boundary.Segments[j].Midpoint) { seg2 = incident.Boundary.Segments[j]; d2 = incident.Drawn.Segments[j]; break; } } if (seg2 != null) { break; } } // Found our incident edge? bool foundIncident = seg2 != null; if (!foundIncident) { seg2 = d2 = boundarySeg; } // Do the endpoints mismatch? if (boundarySeg.P1 != seg2.P1) { Segment clone = d2.Clone(); clone.Reverse(); d2 = clone; } // Add the two vertices (careful of orientation). if (foundIncident) { CheckAndAdd(mesh, new Mesh.Triangle(boundarySeg.P1, d1.P1, d2.P1), boundary); CheckAndAdd(mesh, new Mesh.Triangle(boundarySeg.P2, d2.P2, d1.P2), boundary); } int num = 1 + (int)(d1.Length * m_divisions); Vector3D[] list1 = d1.Subdivide(num); Vector3D[] list2 = d2.Subdivide(num); for (int j = 0; j < num; j++) { CheckAndAdd(mesh, new Mesh.Triangle(list1[j], list1[j + 1], list2[j + 1]), boundary); CheckAndAdd(mesh, new Mesh.Triangle(list2[j], list1[j], list2[j + 1]), boundary); } completed.Add(boundarySeg.Midpoint); } }