コード例 #1
0
        private Lump <TexInfo> ReadTexInfoLump(BSPLumpInfo lump, BinaryReader binaryReader)
        {
            var texInfoCount = lump.length / 4; // Edges are 4 bytes long (2 int16)
            var texInfoLump  = new Lump <TexInfo>();

            Logging.Log($"Edge lump size: {texInfoCount}");

            for (int i = 0; i < texInfoCount; ++i)
            {
                // Read vertex
                texInfoLump.Contents.Add(new TexInfo()
                {
                    textureVecs = new float[2, 4]
                    {
                        { binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle() },
                        { binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle() },
                    },
                    lightmapVecs = new float[4, 2]
                    {
                        { binaryReader.ReadSingle(), binaryReader.ReadSingle() },
                        { binaryReader.ReadSingle(), binaryReader.ReadSingle() },
                        { binaryReader.ReadSingle(), binaryReader.ReadSingle() },
                        { binaryReader.ReadSingle(), binaryReader.ReadSingle() }
                    },
                    flags   = binaryReader.ReadInt32(),
                    texData = binaryReader.ReadInt32()
                });
            }

            return(texInfoLump);
        }
コード例 #2
0
        private Lump <Vector3> ReadVertexesLump(BSPLumpInfo lump, BinaryReader binaryReader)
        {
            var vertexCount = lump.length / 12; // Vertices are 12 bytes long (3 float)
            var vertexLump  = new Lump <Vector3>();

            Logging.Log($"Vertex lump size: {vertexCount}");

            for (int i = 0; i < vertexCount; ++i)
            {
                // Read vertex
                vertexLump.Contents.Add(binaryReader.ReadVector3());
            }

            return(vertexLump);
        }
コード例 #3
0
        private Lump <int> ReadSurfEdgesLump(BSPLumpInfo lump, BinaryReader binaryReader)
        {
            var surfEdgeCount = lump.length / 4; // Edges are 4 bytes long (1 int32)
            var surfEdgeLump  = new Lump <int>();

            Logging.Log($"Surfedge lump size: {surfEdgeCount}");

            for (int i = 0; i < surfEdgeCount; ++i)
            {
                // Read vertex
                surfEdgeLump.Contents.Add(binaryReader.ReadInt32());
            }

            return(surfEdgeLump);
        }
コード例 #4
0
        private Lump <Edge> ReadEdgesLump(BSPLumpInfo lump, BinaryReader binaryReader)
        {
            var edgeCount = lump.length / 4; // Edges are 4 bytes long (2 int16)
            var edgeLump  = new Lump <Edge>();

            Logging.Log($"Edge lump size: {edgeCount}");

            for (int i = 0; i < edgeCount; ++i)
            {
                // Read vertex
                edgeLump.Contents.Add(new Edge
                {
                    vertexIndices = new[] { binaryReader.ReadUInt16(), binaryReader.ReadUInt16() }
                });
            }

            return(edgeLump);
        }
コード例 #5
0
        private Lump <Plane> ReadPlaneLump(BSPLumpInfo lump, BinaryReader binaryReader)
        {
            var planeCount = lump.length / 20; // Planes are 20 bytes long
            var planeLump  = new Lump <Plane>();

            Logging.Log($"Plane lump size: {planeCount}");

            for (int i = 0; i < planeCount; ++i)
            {
                // Read plane
                planeLump.Contents.Add(new Plane
                {
                    normal = binaryReader.ReadVector3(),
                    dist   = binaryReader.ReadSingle(),
                    type   = binaryReader.ReadInt32()
                });
            }

            return(planeLump);
        }
コード例 #6
0
        private void ReadLump(BinaryReader binaryReader, BSPLumpInfo lump, BspLumpType lumpType)
        {
            var startOffset = binaryReader.BaseStream.Position;

            binaryReader.BaseStream.Seek(lump.offset, SeekOrigin.Begin);

            // handle lump based on lumptype given
            switch (lumpType)
            {
            case BspLumpType.LumpPlanes:
                Lumps[(int)lumpType] = ReadPlaneLump(lump, binaryReader);
                break;

            case BspLumpType.LumpVertexes:
                Lumps[(int)lumpType] = ReadVertexesLump(lump, binaryReader);
                break;

            case BspLumpType.LumpEdges:
                Lumps[(int)lumpType] = ReadEdgesLump(lump, binaryReader);
                break;

            case BspLumpType.LumpSurfEdges:
                Lumps[(int)lumpType] = ReadSurfEdgesLump(lump, binaryReader);
                break;

            case BspLumpType.LumpFaces:
                Lumps[(int)lumpType] = ReadFacesLump(lump, binaryReader);
                break;

            case BspLumpType.LumpTexInfo:
                Lumps[(int)lumpType] = ReadTexInfoLump(lump, binaryReader);
                break;

            default:
                Logging.Log($"No lump reader for {lumpType}", Logging.Severity.Medium);
                break;
            }

            // seek back to original pos
            binaryReader.BaseStream.Seek(startOffset, SeekOrigin.Begin);
        }
コード例 #7
0
        private Lump <Face> ReadFacesLump(BSPLumpInfo lump, BinaryReader binaryReader)
        {
            var faceCount = lump.length / 56; // Faces are 56 bytes long
            var faceLump  = new Lump <Face>();

            Logging.Log($"Face lump size: {faceCount}");

            for (int i = 0; i < faceCount; ++i)
            {
                // Read face
                faceLump.Contents.Add(new Face
                {
                    planeNumber                 = binaryReader.ReadUInt16(),
                    side                        = binaryReader.ReadByte(),
                    onNode                      = binaryReader.ReadByte() == 1,
                    firstSurfEdge               = binaryReader.ReadInt32(),
                    numSurfEdges                = binaryReader.ReadInt16(),
                    texInfo                     = binaryReader.ReadInt16(),
                    dispInfo                    = binaryReader.ReadInt16(),
                    surfaceFogVolumeId          = binaryReader.ReadInt16(),
                    styles                      = binaryReader.ReadBytes(4),
                    lightmapOffset              = binaryReader.ReadInt32(),
                    area                        = binaryReader.ReadSingle(),
                    lightmapTextureMinsInLuxels = new[] {
                        binaryReader.ReadInt32(), binaryReader.ReadInt32()
                    },
                    lightmapTextureSizeInLuxels = new[] {
                        binaryReader.ReadInt32(), binaryReader.ReadInt32()
                    },
                    origFace        = binaryReader.ReadInt32(),
                    numPrims        = binaryReader.ReadUInt16(),
                    firstPrimId     = binaryReader.ReadUInt16(),
                    smoothingGroups = binaryReader.ReadUInt32()
                });
            }

            return(faceLump);
        }