Пример #1
0
        public static Clipnode Read(BinaryReader br)
        {
            Clipnode node = new Clipnode();

            node.planenum = br.ReadUInt32();
            node.front    = br.ReadInt16();
            node.back     = br.ReadInt16();
            return(node);
        }
Пример #2
0
        public static Bsp Read(byte[] buf)
        {
            using (var ms = new MemoryStream(buf))
                using (var br = new BinaryReader(ms)) {
                    Header header = Header.Read(br);

                    Bsp bsp = new Bsp();

                    bsp.entities = ReadItems(br, header.entities, (b) => Entity.Read(b));
                    bsp.planes   = ReadItems(br, header.planes, (b) => Plane.Read(b));

                    br.BaseStream.Seek(header.miptex.offset, SeekOrigin.Begin);
                    bsp.mipheader = Mipheader.Read(br);
                    bsp.miptexs   = new Miptex[bsp.mipheader.numtex];
                    for (int i = 0; i < bsp.miptexs.Length; i++)
                    {
                        if (bsp.mipheader.offset[i] == -1)
                        {
                            continue;
                        }
                        br.BaseStream.Seek(header.miptex.offset + bsp.mipheader.offset[i], SeekOrigin.Begin);
                        bsp.miptexs[i] = Miptex.Read(br);
                    }

                    bsp.vertices  = ReadItems(br, header.vertices, (b) => new Vector3D(b.ReadSingle(), b.ReadSingle(), b.ReadSingle()));
                    bsp.vislist   = ReadItems(br, header.visilist, (b) => b.ReadByte());
                    bsp.nodes     = ReadItems(br, header.nodes, (b) => Node.Read(b));
                    bsp.texinfo   = ReadItems(br, header.texinfo, (b) => TexInfo.Read(b));
                    bsp.faces     = ReadItems(br, header.faces, (b) => Face.Read(b));
                    bsp.lightmaps = ReadItems(br, header.lightmaps, (b) => b.ReadByte());
                    bsp.clipnodes = ReadItems(br, header.clipnodes, (b) => Clipnode.Read(b));
                    bsp.leafs     = ReadItems(br, header.leafs, (b) => Leaf.Read(b));
                    bsp.lface     = ReadItems(br, header.lface, (b) => b.ReadUInt16());
                    bsp.edges     = ReadItems(br, header.edges, (b) => Edge.Read(b));
                    bsp.ledges    = ReadItems(br, header.ledges, (b) => b.ReadInt32());
                    bsp.models    = ReadItems(br, header.models, (b) => Model.Read(b));

                    bsp.mipMaterials = bsp.miptexs.Select((mip) => GetMipMaterial(mip)).ToArray();
                    bsp.mipModels    = bsp.faces.Select((face) => bsp.GetMipModel(face)).ToArray();
                    bsp.lightModels  = bsp.faces.Select((face) => bsp.GetLightModel(face)).ToArray();

                    return(bsp);
                }
        }