示例#1
0
文件: CsgNode.cs 项目: silky/sledge
 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);
     }
 }
示例#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());
 }
示例#3
0
 public void ClipTo(CsgNode bsp)
 {
     Polygons = bsp.ClipPolygons(Polygons);
     if (Front != null)
     {
         Front.ClipTo(bsp);
     }
     if (Back != null)
     {
         Back.ClipTo(bsp);
     }
 }
示例#4
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()));
        }
示例#5
0
        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);
            }
        }
示例#6
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);
            }
        }
示例#7
0
        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;
        }
示例#8
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;
        }
示例#9
0
 private CsgNode()
 {
     Polygons = new List <Polygon>();
     Front    = null;
     Back     = null;
 }
示例#10
0
文件: CsgNode.cs 项目: silky/sledge
 public void ClipTo(CsgNode bsp)
 {
     Polygons = bsp.ClipPolygons(Polygons);
     if (Front != null) Front.ClipTo(bsp);
     if (Back != null) Back.ClipTo(bsp);
 }