public void DebugLog(Log log) { // TODO: log.Write("Edge Data"); log.Write("---------"); for (int i = 0; i < triangles.Count; i++) { Triangle t = (Triangle)triangles[i]; log.Write("Triangle {0} = [indexSet={1}, vertexSet={2}, v0={3}, v1={4}, v2={5}]", i, t.indexSet, t.vertexSet, t.vertIndex[0], t.vertIndex[1], t.vertIndex[2]); } for (int i = 0; i < edgeGroups.Count; i++) { EdgeGroup group = (EdgeGroup)edgeGroups[i]; log.Write("Edge Group vertexSet={0}", group.vertexSet); for (int j = 0; j < group.edges.Count; j++) { Edge e = (Edge)group.edges[j]; log.Write("Edge {0} = [\ntri0={1}, \ntri1={2}, \nv0={3}, \nv1={4}, \n degenerate={5}\n]", j, e.triIndex[0], e.triIndex[1], e.vertIndex[0], e.vertIndex[1], e.isDegenerate); } } }
private WorkingMesh MakeFillHoleMesh(WorkingMesh source) { int totalTris = 0; List <int[]> newTris = new List <int[]>(); for (int si = 0; si < source.subMeshCount; ++si) { List <int> tris = source.GetTriangles(si).ToList(); List <Vector2Int> edgeList = GetEdgeList(tris); List <EdgeGroup> groups = new List <EdgeGroup>(); for (int i = 0; i < edgeList.Count; ++i) { EdgeGroup group = new EdgeGroup(); group.Begin = edgeList[i].x; group.End = edgeList[i].y; group.EdgeList.Add(edgeList[i]); groups.Add(group); } bool isFinish = false; while (isFinish == false) { isFinish = true; for (int gi1 = 0; gi1 < groups.Count; ++gi1) { for (int gi2 = gi1 + 1; gi2 < groups.Count; ++gi2) { EdgeGroup g1 = groups[gi1]; EdgeGroup g2 = groups[gi2]; if (g1.End == g2.Begin) { g1.End = g2.End; g1.EdgeList.AddRange(g2.EdgeList); groups[gi2] = groups[groups.Count - 1]; groups.RemoveAt(groups.Count - 1); gi2 -= 1; isFinish = false; } else if (g1.Begin == g2.End) { g2.End = g1.End; g2.EdgeList.AddRange(g1.EdgeList); groups[gi1] = groups[gi2]; groups[gi2] = groups[groups.Count - 1]; groups.RemoveAt(groups.Count - 1); gi2 -= 1; isFinish = false; } } } } for (int gi = 0; gi < groups.Count; ++gi) { EdgeGroup group = groups[gi]; for (int ei1 = 1; ei1 < group.EdgeList.Count - 1; ++ei1) { for (int ei2 = ei1 + 1; ei2 < group.EdgeList.Count; ++ei2) { if (group.EdgeList[ei1].x == group.EdgeList[ei2].y) { EdgeGroup ng = new EdgeGroup(); ng.Begin = group.EdgeList[ei1].x; ng.End = group.EdgeList[ei2].y; for (int i = ei1; i <= ei2; ++i) { ng.EdgeList.Add(group.EdgeList[i]); } for (int i = ei2; i >= ei1; --i) { group.EdgeList.RemoveAt(i); } groups.Add(ng); ei1 = 0; // goto first break; } } } } if (groups.Count == 0) { continue; } groups.Sort((g1, g2) => { return(g2.EdgeList.Count - g1.EdgeList.Count); }); //first group( longest group ) is outline. for (int i = 1; i < groups.Count; ++i) { EdgeGroup group = groups[i]; for (int ei = 1; ei < group.EdgeList.Count - 1; ++ei) { tris.Add(group.Begin); tris.Add(group.EdgeList[ei].y); tris.Add(group.EdgeList[ei].x); } } totalTris += tris.Count; newTris.Add(tris.ToArray()); } WorkingMesh mesh = new WorkingMesh(Allocator.Persistent, source.vertexCount, totalTris, source.subMeshCount, 0); mesh.name = source.name; mesh.vertices = source.vertices; mesh.normals = source.normals; mesh.uv = source.uv; for (int i = 0; i < newTris.Count; ++i) { mesh.SetTriangles(newTris[i], i); } return(mesh); }
public void Init() { instance = new EdgeGroup(); }