Exemple #1
0
 public void ClipTo(CsgNode bsp)
 {
     Polygons = bsp.ClipPolygons(Polygons);
     if (Front != null)
     {
         Front.ClipTo(bsp);
     }
     if (Back != null)
     {
         Back.ClipTo(bsp);
     }
 }
Exemple #2
0
        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()));
        }
Exemple #3
0
        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);
            }
        }
Exemple #4
0
        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;
        }
Exemple #5
0
 private CsgNode()
 {
     Polygons = new List <Polygon>();
     Front    = null;
     Back     = null;
 }