public Poly CopyList() { Poly p = CopyPoly(); if (!IsLast) { p.AddPoly(Next.CopyList()); } return(p); }
public void ClipToBrush(Brush brush, bool clipOnPlane) { Poly polyList = null; Poly p = Polys; for (int i = 0; i < GetNumberOfPolys; i++) { Poly clippedPoly = brush.Polys.ClipToList(p, clipOnPlane); if (polyList == null) { polyList = clippedPoly; } else { polyList.AddPoly(clippedPoly); } p = p.Next; } Polys = polyList; }
public Poly MergeList() { Brush clippedList = CopyList(); Brush clip = clippedList; Brush brush = null; Poly polyList = null; bool clipOnPlane = false; for (int i = 0; i < GetNumberOfBrushes; i++) { brush = this; clipOnPlane = false; for (int j = 0; j < GetNumberOfBrushes; j++) { if (i == j) { clipOnPlane = true; } else { if (clip.AABBIntersect(brush)) { clip.ClipToBrush(brush, clipOnPlane); } } brush = brush.Next; } clip = clip.Next; } clip = clippedList; while (clip != null) { if (clip.GetNumberOfPolys != 0) { // Extract brushes left over polygons and add them to the list Poly p = clip.Polys.CopyList(); if (polyList == null) { polyList = p; } else { polyList.AddPoly(p); } clip = clip.Next; } else { // Brush has no polygons and should be deleted if (clip == clippedList) { clip = clippedList.Next; clippedList.SetNext(null); clippedList = clip; } else { Brush temp = clippedList; while (temp != null) { if (temp.Next == clip) break; temp = temp.Next; } temp.Next = clip.Next; clip.SetNext(null); clip = temp.Next; } } } return polyList; }
public Poly ClipToList(Poly poly, bool clipOnPlane) { switch (ClassifyPoly(poly)) { case eCP.FRONT: return(poly.CopyPoly()); case eCP.BACK: if (IsLast) { return(null); } return(Next.ClipToList(poly, clipOnPlane)); case eCP.ONPLANE: float angle = Vector3.Dot(plane.n, poly.plane.n) - 1; if (angle < Mathf.EPSILON && angle > -Mathf.EPSILON) { if (!clipOnPlane) { return(poly.CopyPoly()); } } if (IsLast) { return(null); } return(Next.ClipToList(poly, clipOnPlane)); case eCP.SPLIT: Poly front = null; Poly back = null; SplitPoly(poly, ref front, ref back); if (IsLast) { return(front); } Poly backFrags = Next.ClipToList(back, clipOnPlane); if (backFrags == null) { return(front); } if (backFrags == back) { return(poly.CopyPoly()); } front.AddPoly(backFrags); return(front); } return(null); }