Exemplo n.º 1
0
            /// <summary>
            /// The h 1 bsp raw data meta chunk.
            /// </summary>
            /// <param name="offset">The offset.</param>
            /// <param name="chunknumber">The chunknumber.</param>
            /// <param name="meta">The meta.</param>
            /// <param name="faces">The faces.</param>
            /// <remarks></remarks>
            public void H1BSPRawDataMetaChunk(int offset, int chunknumber, ref Meta meta, Face[] faces)
            {
                BinaryReader BR = new BinaryReader(meta.MS);
                BR.BaseStream.Position = offset + 12;
                this.shadertagnumber = meta.Map.Functions.ForMeta.FindMetaByID(BR.ReadInt32());
                this.RawDataChunkInfo = new RawDataOffsetChunk[1];
                BR.BaseStream.Position = offset + 20;
                int surfacestart = BR.ReadInt32();
                this.FaceCount = BR.ReadInt32();
                this.SubMeshInfo = new ModelSubMeshInfo[1];
                this.SubMeshInfo[0] = new ModelSubMeshInfo();
                this.SubMeshInfo[0].IndiceCount = this.FaceCount * 3;
                this.SubMeshInfo[0].ShaderNumber = chunknumber;
                this.IndiceCount = this.SubMeshInfo[0].IndiceCount;
                this.Indices = new short[this.IndiceCount];
                for (int x = 0; x < this.FaceCount; x++)
                {
                    this.Indices[(x * 3) + 0] = (short)faces[surfacestart + x].vertex0Index;
                    this.Indices[(x * 3) + 1] = (short)faces[surfacestart + x].vertex1Index;
                    this.Indices[(x * 3) + 2] = (short)faces[surfacestart + x].vertex2Index;
                }

                BR.BaseStream.Position = offset + 180;
                this.VerticeCount = BR.ReadInt32();
                BR.BaseStream.Position = offset + 248;
                int vertstranslation = BR.ReadInt32() - meta.magic - meta.offset;
                BR.BaseStream.Position = vertstranslation;
                BSPRawDataMetaChunk tempchunk = new BSPRawDataMetaChunk();
                for (int x = 0; x < this.VerticeCount; x++)
                {
                    AddCompressedVertice(ref BR, ref tempchunk);
                }

                this.Vertices = tempchunk.Vertices;
                this.Normals = tempchunk.Normals;
                this.Binormals = tempchunk.Binormals;
                this.Tangents = tempchunk.Tangents;
                this.UVs = tempchunk.UVs;
                this.LightMapUVs = tempchunk.LightMapUVs;
            }
Exemplo n.º 2
0
        /// <summary>
        /// The add compressed vertice.
        /// </summary>
        /// <param name="BR">The br.</param>
        /// <param name="chunk">The chunk.</param>
        /// <remarks></remarks>
        public static void AddCompressedVertice(ref BinaryReader BR, ref BSPRawDataMetaChunk chunk)
        {
            // vertexes
            Vector3 vertice = new Vector3(BR.ReadSingle(), BR.ReadSingle(), BR.ReadSingle());
            chunk.Vertices.Add(vertice);
            // normals
            int test = BR.ReadInt32();
            Vector3 normal2 = ParsedModel.DecompressNormal(test);
            chunk.Normals.Add(normal2);
            test = BR.ReadInt32();
            Vector3 binormal2 = ParsedModel.DecompressNormal(test);
            chunk.Binormals.Add(binormal2);
            test = BR.ReadInt32();
            Vector3 tangent2 = ParsedModel.DecompressNormal(test);
            chunk.Tangents.Add(tangent2);
            // basemap uvs

            // short testx = BR.ReadInt16();
            float u = BR.ReadSingle(); // chunk.DecompressVertice(Convert.ToSingle(testx), -1, 1);
            // testx = BR.ReadInt16();
            float v = BR.ReadSingle(); // chunk.DecompressVertice(Convert.ToSingle(testx), -1, 1);// % 1;
            Vector2 uv2 = new Vector2(u, v);
            chunk.UVs.Add(uv2);

            // lightmap uvs
            // testx = BR.ReadInt16();
            // float ux = chunk.DecompressVertice(Convert.ToSingle(testx), -1, 1);// %1 ;
            // testx = BR.ReadInt16();
            // float vx =chunk.DecompressVertice(Convert.ToSingle(testx), -1, 1);// % 1;
            // Vector2 uv2x = new Vector2(ux, vx);
            // chunk.LightMapUVs.Add(uv2);
        }
Exemplo n.º 3
0
        /// <summary>
        /// The add uncompressed vertice.
        /// </summary>
        /// <param name="BR">The br.</param>
        /// <param name="chunk">The chunk.</param>
        /// <remarks></remarks>
        public static void AddUncompressedVertice(ref BinaryReader BR, ref BSPRawDataMetaChunk chunk)
        {
            Vector3 vertice = new Vector3(BR.ReadSingle(), BR.ReadSingle(), BR.ReadSingle());
            chunk.Vertices.Add(vertice);
            Vector3 normal = new Vector3(BR.ReadSingle(), BR.ReadSingle(), BR.ReadSingle());
            chunk.Normals.Add(normal);
            Vector3 binormal = new Vector3(BR.ReadSingle(), BR.ReadSingle(), BR.ReadSingle());
            chunk.Binormals.Add(binormal);
            Vector3 tangent = new Vector3(BR.ReadSingle(), BR.ReadSingle(), BR.ReadSingle());
            chunk.Tangents.Add(tangent);
            Vector2 uv = new Vector2(BR.ReadSingle(), BR.ReadSingle());

            chunk.UVs.Add(uv);
        }
Exemplo n.º 4
0
        /// <summary>
        /// The load model structure.
        /// </summary>
        /// <param name="meta">The meta.</param>
        /// <remarks></remarks>
        public void LoadModelStructure(ref Meta meta)
        {
            map.OpenMap(MapTypes.Internal);
            BinaryReader BR = new BinaryReader(meta.MS);
            switch (map.HaloVersion)
            {
                case HaloVersionEnum.Halo2:

                    // Loads the maps min & max boundries
                    float x1, x2, y1, y2, z1, z2;
                    // 68 = offset to World Boundries
                    BR.BaseStream.Position = 68;
                    x1 = BR.ReadSingle();
                    x2 = BR.ReadSingle();
                    y1 = BR.ReadSingle();
                    y2 = BR.ReadSingle();
                    z1 = BR.ReadSingle();
                    z2 = BR.ReadSingle();
                    minBoundries = new Vector3(x1, y1, z1);
                    maxBoundries = new Vector3(x2, y2, z2);


                    BR.BaseStream.Position = 172;
                    int tempc = BR.ReadInt32();
                    int tempr = BR.ReadInt32() - meta.magic - meta.offset;
                    BSPRawDataMetaChunks = new BSPRawDataMetaChunk[tempc];
                    BSPRawDataMetaChunksOffset = tempr;
                    for (int x = 0; x < tempc; x++)
                    {
                        BSPRawDataMetaChunks[x] = new BSPRawDataMetaChunk(tempr + (x * 176), x, ref meta, null);
                    }

                    

                    break;
                case HaloVersionEnum.HaloCE:
                case HaloVersionEnum.Halo1:
                    List<BSPRawDataMetaChunk> tempchunks = new List<BSPRawDataMetaChunk>();

                    BR.BaseStream.Position = map.BSP.sbsp[BspNumber].lightmapoffset + 248;
                    int facescount = BR.ReadInt32();
                    int facestranslation = BR.ReadInt32() - meta.magic - meta.offset;
                    Face[] faces = new Face[facescount];

                    BR.BaseStream.Position = facestranslation;
                    for (int x = 0; x < facescount; x++)
                    {
                        faces[x] = new Face();
                        faces[x].vertex0Index = BR.ReadInt16();
                        faces[x].vertex1Index = BR.ReadInt16();
                        faces[x].vertex2Index = BR.ReadInt16();
                    }

                    BR.BaseStream.Position = map.BSP.sbsp[BspNumber].lightmapoffset + 260;
                    int tempc2 = BR.ReadInt32();
                    int tempr2 = BR.ReadInt32() - meta.magic - meta.offset;

                    List<ShaderInfo> tempshad = new List<ShaderInfo>();
                    BSPRawDataMetaChunksOffset = tempr2;
                    for (int x = 0; x < tempc2; x++)
                    {
                        BR.BaseStream.Position = tempr2 + (32 * x) + 20;
                        int tempc22 = BR.ReadInt32();
                        int tempr22 = BR.ReadInt32() - meta.magic - meta.offset;
                        for (int xx = 0; xx < tempc22; xx++)
                        {
                            BSPRawDataMetaChunk tempraw = new BSPRawDataMetaChunk(
                                tempr22 + (256 * xx), tempchunks.Count, ref meta, faces);
                            tempchunks.Add(tempraw);
                            tempshad.Add(new ShaderInfo(tempraw.shadertagnumber, map));
                        }
                    }

                    this.Shaders.Shader = tempshad.ToArray();
                    this.BSPRawDataMetaChunks = tempchunks.ToArray();

                    break;
            }

            map.CloseMap();
        }