Exemple #1
0
        public override void Unpack(BinaryReader reader, BSPType treeType)
        {
            Type = reader.ReadUInt32();

            SplittingPlane = new Plane();
            SplittingPlane.Unpack(reader);

            PosNode = BSPNode.ReadNode(reader, treeType);
            NegNode = BSPNode.ReadNode(reader, treeType);

            if (treeType == BSPType.Drawing)
            {
                Sphere = new Sphere();
                Sphere.Unpack(reader);

                var numPolys   = reader.ReadUInt32();
                var numPortals = reader.ReadUInt32();

                InPolys = new List <ushort>();
                for (uint i = 0; i < numPolys; i++)
                {
                    InPolys.Add(reader.ReadUInt16());
                }

                InPortals.Unpack(reader, numPortals);
            }
        }
Exemple #2
0
        public static BSPNode ReadNode(BinaryReader reader, BSPType treeType)
        {
            // We peek forward to get the type, then revert our position.
            var type = Encoding.ASCII.GetString(reader.ReadBytes(4)).Reverse();

            reader.BaseStream.Position -= 4;

            BSPNode node;

            switch (type)
            {
            case "PORT":
                node = new BSPPortal();
                break;

            case "LEAF":
                node = new BSPLeaf();
                break;

            case "BPnn":
            case "BPIn":
            case "BpIN":
            case "BpnN":
            case "BPIN":
            case "BPnN":
            default:
                node = new BSPNode();
                break;
            }

            node.Unpack(reader, treeType);

            return(node);
        }
Exemple #3
0
        public static BSPNode ReadNode(BinaryReader reader, BSPType treeType)
        {
            // We peek forward to get the type, then revert our position.
            var type = reader.ReadUInt32();

            reader.BaseStream.Position -= 4;

            BSPNode node;

            switch (type)
            {
            case PORT:
                node = new BSPPortal();
                break;

            case LEAF:
                node = new BSPLeaf();
                break;

            case BPnn:
            case BPIn:
            case BpIN:
            case BpnN:
            case BPIN:
            case BPnN:
            default:
                node = new BSPNode();
                break;
            }

            node.Unpack(reader, treeType);

            return(node);
        }
Exemple #4
0
        public static BSPTree Read(DatReader datReader, BSPType treeType)
        {
            BSPTree obj = new BSPTree();

            obj.RootNode = BSPNode.Read(datReader, treeType);
            return(obj);
        }
Exemple #5
0
        public static BSPPortal ReadPortal(DatReader datReader, BSPType treeType)
        {
            BSPPortal obj = new BSPPortal();

            obj.Type           = 0x504F5254; // PORT
            obj.SplittingPlane = Plane.Read(datReader);
            obj.PosNode        = BSPNode.Read(datReader, treeType);
            obj.NegNode        = BSPNode.Read(datReader, treeType);

            if (treeType == BSPType.Drawing)
            {
                obj.Sphere = CSphere.Read(datReader);

                uint numPolys   = datReader.ReadUInt32();
                uint numPortals = datReader.ReadUInt32();

                for (uint i = 0; i < numPolys; i++)
                {
                    obj.InPolys.Add(datReader.ReadUInt16());
                }

                for (uint i = 0; i < numPortals; i++)
                {
                    obj.InPortals.Add(PortalPoly.Read(datReader));
                }
            }

            return(obj);
        }
Exemple #6
0
        } = new List <ushort>();                                        // List of PolygonIds

        public static BSPNode Read(DatReader datReader, BSPType treeType)
        {
            BSPNode obj = new BSPNode();

            obj.Type = datReader.ReadUInt32();

            switch (obj.Type)
            {
            case PORT:
                return(BSPPortal.ReadPortal(datReader, treeType));

            case LEAF:
                return(BSPLeaf.ReadLeaf(datReader, treeType));
            }

            obj.SplittingPlane = Plane.Read(datReader);

            switch (obj.Type)
            {
            case BPnn:
            case BPIn:
                obj.PosNode = BSPNode.Read(datReader, treeType);
                break;

            case BpIN:
            case BpnN:
                obj.NegNode = BSPNode.Read(datReader, treeType);
                break;

            case BPIN:
            case BPnN:
                obj.PosNode = BSPNode.Read(datReader, treeType);
                obj.NegNode = BSPNode.Read(datReader, treeType);
                break;
            }

            if (treeType == BSPType.Cell)
            {
                return(obj);
            }

            obj.Sphere = CSphere.Read(datReader);

            if (treeType == BSPType.Physics)
            {
                return(obj);
            }

            uint numPolys = datReader.ReadUInt32();

            for (uint i = 0; i < numPolys; i++)
            {
                obj.InPolys.Add(datReader.ReadUInt16());
            }
            return(obj);
        }
Exemple #7
0
        public virtual void Unpack(BinaryReader reader, BSPType treeType)
        {
            Type = Encoding.ASCII.GetString(reader.ReadBytes(4)).Reverse();

            switch (Type)
            {
            // These types will unpack the data completely, in their own classes
            case "PORT":
            case "LEAF":
                throw new Exception();
            }

            SplittingPlane = new Plane();
            SplittingPlane.Unpack(reader);

            switch (Type)
            {
            case "BPnn":
            case "BPIn":
                PosNode = BSPNode.ReadNode(reader, treeType);
                break;

            case "BpIN":
            case "BpnN":
                NegNode = BSPNode.ReadNode(reader, treeType);
                break;

            case "BPIN":
            case "BPnN":
                PosNode = BSPNode.ReadNode(reader, treeType);
                NegNode = BSPNode.ReadNode(reader, treeType);
                break;
            }

            if (treeType == BSPType.Cell)
            {
                return;
            }

            Sphere = new Sphere();
            Sphere.Unpack(reader);

            if (treeType == BSPType.Physics)
            {
                return;
            }

            InPolys = new List <ushort>();
            uint numPolys = reader.ReadUInt32();

            for (uint i = 0; i < numPolys; i++)
            {
                InPolys.Add(reader.ReadUInt16());
            }
        }
Exemple #8
0
 public void Unpack(BinaryReader reader, BSPType treeType)
 {
     RootNode = BSPNode.ReadNode(reader, treeType);
 }