public void Build(List<Polygon> polygons) { if (polygons.Count == 0) return; if (Plane == null) Plane = polygons[0].Plane.Clone(); var front = new List<Polygon>(); var back = new List<Polygon>(); foreach (var polygon in polygons) { Polygon f, b, cf, cb; polygon.Split(Plane, out b, out f, out cb, out cf); if (f != null) front.Add(f); if (b != null) back.Add(b); if (cf != null) Polygons.Add(cf); if (cb != null) Polygons.Add(cb); } if (front.Count > 0) { if (Front == null) Front = new CsgNode(); Front.Build(front); } if (back.Count > 0) { if (Back == null) Back = new CsgNode(); Back.Build(back); } }
public CsgSolid Union(CsgSolid solid) { var a = new CsgNode(this); var b = new CsgNode(solid); a.ClipTo(b); b.ClipTo(a); b.Invert(); b.ClipTo(a); b.Invert(); a.Build(b.AllPolygons()); return new CsgSolid(a.AllPolygons()); }
public void ClipTo(CsgNode bsp) { Polygons = bsp.ClipPolygons(Polygons); if (Front != null) { Front.ClipTo(bsp); } if (Back != null) { Back.ClipTo(bsp); } }
public CsgSolid Union(CsgSolid solid) { var a = new CsgNode(this); var b = new CsgNode(solid); a.ClipTo(b); b.ClipTo(a); b.Invert(); b.ClipTo(a); b.Invert(); a.Build(b.AllPolygons()); return(new CsgSolid(a.AllPolygons())); }
public void Build(List <Polygon> polygons) { if (polygons.Count == 0) { return; } if (Plane == null) { Plane = polygons[0].Plane.Clone(); } var pp = Plane.ToPrecisionPlane(); var front = new List <Polygon>(); var back = new List <Polygon>(); foreach (var polygon in polygons.Select(x => x.ToPrecisionPolygon())) { polygon.Split(pp, out var b, out var f, out var cb, out var cf); if (f != null) { front.Add(f.ToStandardPolygon()); } if (b != null) { back.Add(b.ToStandardPolygon()); } if (cf != null) { front.Add(cf.ToStandardPolygon()); } if (cb != null) { back.Add(cb.ToStandardPolygon()); } } if (front.Count > 0) { if (Front == null) { Front = new CsgNode(); } Front.Build(front); } if (back.Count > 0) { if (Back == null) { Back = new CsgNode(); } Back.Build(back); } }
public void Build(List <Polygon> polygons) { if (polygons.Count == 0) { return; } if (Plane == null) { Plane = polygons[0].Plane.Clone(); } var front = new List <Polygon>(); var back = new List <Polygon>(); foreach (var polygon in polygons) { Polygon f, b, cf, cb; polygon.Split(Plane, out b, out f, out cb, out cf); if (f != null) { front.Add(f); } if (b != null) { back.Add(b); } if (cf != null) { Polygons.Add(cf); } if (cb != null) { Polygons.Add(cb); } } if (front.Count > 0) { if (Front == null) { Front = new CsgNode(); } Front.Build(front); } if (back.Count > 0) { if (Back == null) { Back = new CsgNode(); } Back.Build(back); } }
public void Invert() { Polygons = Polygons.Select(x => x.Flip()).ToList(); Plane = new Plane(-Plane.Normal, Plane.PointOnPlane); if (Front != null) { Front.Invert(); } if (Back != null) { Back.Invert(); } var temp = Front; Front = Back; Back = temp; }
public void Invert() { foreach (var polygon in Polygons) { polygon.Flip(); } Plane = new Plane(-Plane.Normal, Plane.PointOnPlane); if (Front != null) { Front.Invert(); } if (Back != null) { Back.Invert(); } var temp = Front; Front = Back; Back = temp; }
private CsgNode() { Polygons = new List <Polygon>(); Front = null; Back = null; }
public void ClipTo(CsgNode bsp) { Polygons = bsp.ClipPolygons(Polygons); if (Front != null) Front.ClipTo(bsp); if (Back != null) Back.ClipTo(bsp); }