Ejemplo n.º 1
0
 public BSPNode(List <Polygon> list, Plane plane, BSPNode front, BSPNode back)
 {
     this.Polygons = list;
     this.Plane    = plane;
     this.Front    = front;
     this.Back     = back;
 }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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()));
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
 public void ClipTo(BSPNode other)
 {
     this.Polygons = other.ClipPolygons(this.Polygons);
     this.Front?.ClipTo(other);
     this.Back?.ClipTo(other);
 }
Ejemplo n.º 6
0
 public BSPNode()
 {
     this.Front = null;
     this.Back  = null;
 }