예제 #1
0
파일: BSPNode.cs 프로젝트: Kaydax/CSG
 public BSPNode(List <Polygon> list, Plane plane, BSPNode front, BSPNode back)
 {
     this.Polygons = list;
     this.Plane    = plane;
     this.Front    = front;
     this.Back     = back;
 }
예제 #2
0
파일: BSPNode.cs 프로젝트: Kaydax/CSG
        public void Build(List <Polygon> list)
        {
            if (list.Count < 1)
            {
                return;
            }

            if (this.Plane == null || !this.Plane.Valid())
            {
                this.Plane = new Plane
                {
                    Normal = list[0].Plane.Normal,
                    W      = list[0].Plane.W
                };
            }

            if (this.Polygons == null)
            {
                this.Polygons = new List <Polygon>();
            }

            // TODO: Optimize!
            var list_front = new List <Polygon>();
            var list_back  = new List <Polygon>();

            for (int i = 0; i < list.Count; i++)
            {
                this.Plane.SplitPolygon(list[i], this.Polygons, this.Polygons, list_front, list_back);
            }

            if (list_front.Count > 0)
            {
                if (this.Front == null)
                {
                    this.Front = new BSPNode {
                        Parent = this
                    };
                }
                this.Front.Build(list_front);
            }

            if (list_back.Count > 0)
            {
                if (this.Back == null)
                {
                    this.Back = new BSPNode {
                        Parent = this
                    };
                }
                this.Back.Build(list_back);
            }
        }
예제 #3
0
파일: BSPNode.cs 프로젝트: Kaydax/CSG
        public static BSPNode Union(BSPNode a1, BSPNode b1)
        {
            var a = a1.Clone();
            var b = b1.Clone();

            a.ClipTo(b);
            b.ClipTo(a);
            b.Invert();
            b.ClipTo(a);
            b.Invert();
            a.Build(b.AllPolygons());

            return(new BSPNode(a.AllPolygons()));
        }
예제 #4
0
파일: BSPNode.cs 프로젝트: Kaydax/CSG
        public void Invert()
        {
            for (int i = 0; i < this.Polygons.Count; i++)
            {
                this.Polygons[i].Flip();
            }

            this.Plane.Flip();
            this.Front?.Invert();
            this.Back?.Invert();

            var tmp = this.Front;

            this.Front = this.Back;
            this.Back  = tmp;
        }
예제 #5
0
파일: BSPNode.cs 프로젝트: Kaydax/CSG
 public void ClipTo(BSPNode other)
 {
     this.Polygons = other.ClipPolygons(this.Polygons);
     this.Front?.ClipTo(other);
     this.Back?.ClipTo(other);
 }
예제 #6
0
파일: BSPNode.cs 프로젝트: Kaydax/CSG
 public BSPNode()
 {
     this.Front = null;
     this.Back  = null;
 }