void Buildsegments() { segments.Clear(); for (int i = 0; i < ObsTriangles.Length; i++) { NavmeshTriangle node = ObsTriangles [i]; for (int j = 0; j < node.shared.Count; ++j) { if (node.shared[j] == false) { segments.Add(node.GetSegment(j)); } } ShowProgress("构建单边列表", (float)i / (ObsTriangles.Length)); } DefineIDforSegments(segments); }
void TriangleCheck(List <NavmeshTriangle> testtriangles, Dictionary <KInt2, HashSet <Segment> > IntersectCache, List <Segment> removeList, Segment TestSegment) { HashSet <Segment> hitCache = null; if (IntersectCache.ContainsKey(TestSegment.start)) { hitCache = IntersectCache [TestSegment.start]; } if (IntersectCache.ContainsKey(TestSegment.end)) { HashSet <Segment> cache = IntersectCache [TestSegment.end]; if (cache != null) { if (hitCache == null) { hitCache = cache; } else { var en = cache.GetEnumerator(); while (en.MoveNext()) { hitCache.Add(en.Current); } } } } for (int PassedTricnt = 0; PassedTricnt < testtriangles.Count; ++PassedTricnt) { NavmeshTriangle targettriangle = testtriangles [PassedTricnt]; int insidecnt = 0; int hitcnt = 0; int concnt = 0; KInt2 result; for (int j = 0; j < 3; ++j) { Segment side = targettriangle.GetSegment(j); bool h1 = hitCache != null && hitCache.Contains(side); bool h2 = Segment.Intersect(TestSegment.start, TestSegment.end, side.start, side.end, out result); if (h1 || h2) { hitcnt++; } if (side.ContainsSegment(TestSegment)) { insidecnt++; } if (TestSegment.isConnect(side)) { concnt++; } } if (insidecnt == 0 && concnt == 0) { int b1 = isInside(targettriangle.v03xz, targettriangle.v13xz, targettriangle.v23xz, TestSegment.start, ErrorRadius); int b2 = isInside(targettriangle.v03xz, targettriangle.v13xz, targettriangle.v23xz, TestSegment.end, ErrorRadius); if (b1 == 2 && b2 == 2) { removeList.Add(TestSegment); break; } else if ((b1 == 1 && b2 == 2) || (b1 == 2 && b2 == 1)) { removeList.Add(TestSegment); break; } else if ((b1 <= 1 && b2 <= 1) && hitcnt == 2) { removeList.Add(TestSegment); break; } else if ((b1 == 2 || b2 == 2) && hitcnt > 0) { removeList.Add(TestSegment); break; } } ShowProgress("三角相交检测 移除相交线段", (float)PassedTricnt / testtriangles.Count); } }