Example #1
0
        /// <summary>
        /// The h 2 parsed prtm.
        /// </summary>
        /// <param name="meta">The meta.</param>
        /// <remarks></remarks>
        public void H2ParsedPRTM(ref Meta meta)
        {
            string[] temps = meta.name.Split('\\');
            name = temps[temps.Length - 1];

            BoundingBox = new BoundingBoxContainer();

            BinaryReader BR = new BinaryReader(meta.MS);

            RawDataMetaChunks = new RawDataMetaChunk[1];
            RawDataMetaChunks[0] = new PRTMRawDataMetaChunk(ref meta);

            BR.BaseStream.Position = 28;
            int tempshad = BR.ReadInt32();
            int shadid = meta.Map.Functions.ForMeta.FindMetaByID(tempshad);
            Shaders = new ShaderContainer();
            Shaders.Shader = new ShaderInfo[1];
            Shaders.Shader[0] = new ShaderInfo(shadid, meta.Map);

            // LOD = new LODInfo(ref meta, meta.Map, ref RawDataMetaChunks);
            Display = new DisplayedInfo();
            Display.Chunk.Add(0);
            Display.ShaderIndex = new int[1];
            Display.ShaderIndex[0] = 0;

            // MessageBox.Show("test");
        }
Example #2
0
        /// <summary>
        /// The h 2 parsed prtm.
        /// </summary>
        /// <param name="meta">The meta.</param>
        /// <remarks></remarks>
        public void H2ParsedPRTM(ref Meta meta)
        {
            string[] temps = meta.name.Split('\\');
            name = temps[temps.Length - 1];

            BoundingBox = new BoundingBoxContainer();

            BinaryReader BR = new BinaryReader(meta.MS);

            RawDataMetaChunks    = new RawDataMetaChunk[1];
            RawDataMetaChunks[0] = new PRTMRawDataMetaChunk(ref meta);

            BR.BaseStream.Position = 28;
            int tempshad = BR.ReadInt32();
            int shadid   = meta.Map.Functions.ForMeta.FindMetaByID(tempshad);

            Shaders           = new ShaderContainer();
            Shaders.Shader    = new ShaderInfo[1];
            Shaders.Shader[0] = new ShaderInfo(shadid, meta.Map);

            // LOD = new LODInfo(ref meta, meta.Map, ref RawDataMetaChunks);
            Display = new DisplayedInfo();
            Display.Chunk.Add(0);
            Display.ShaderIndex    = new int[1];
            Display.ShaderIndex[0] = 0;

            // MessageBox.Show("test");
        }
Example #3
0
            /// <summary>
            /// Initializes a new instance of the <see cref="LODInfo"/> class.
            /// </summary>
            /// <param name="meta">The meta.</param>
            /// <param name="rd">The rd.</param>
            /// <remarks></remarks>
            public LODInfo(ref Meta meta, ref RawDataMetaChunk[] rd)
            {
                BinaryReader BR = new BinaryReader(meta.MS);
                BR.BaseStream.Position = 28;
                int tempc = BR.ReadInt32();
                int tempr = BR.ReadInt32() - meta.magic - meta.offset;
                Piece = new LODPieceInfo[tempc];

                for (int x = 0; x < tempc; x++)
                {
                    Piece[x] = new LODPieceInfo();
                    BR.BaseStream.Position = tempr + (x * 16);
                    Piece[x].Name = meta.Map.Strings.Name[BR.ReadInt16()];
                    BR.BaseStream.Position = tempr + (x * 16) + 8;
                    int tempc2 = BR.ReadInt32();
                    int tempr2 = BR.ReadInt32() - meta.magic - meta.offset;
                    Piece[x].Permutation = new LODPieceInfo.LODPermutationInfo[tempc2];
                    for (int xx = 0; xx < tempc2; xx++)
                    {
                        BR.BaseStream.Position = tempr2 + (xx * 16);
                        Piece[x].Permutation[xx] = new LODPieceInfo.LODPermutationInfo();
                        Piece[x].Permutation[xx].name = meta.Map.Strings.Name[BR.ReadInt16()];
                        if (PermutationStrings.IndexOf(Piece[x].Permutation[xx].name) == -1)
                        {
                            PermutationStrings.Add(Piece[x].Permutation[xx].name);
                        }

                        BR.ReadInt16();
                        Piece[x].Permutation[xx].pieceNumber = new int[5];
                        for (int w = 0; w < 5; w++)
                        {
                            Piece[x].Permutation[xx].pieceNumber[w] = BR.ReadInt16();
                            rd[Piece[x].Permutation[xx].pieceNumber[w]].piecename = Piece[x].Name;
                            rd[Piece[x].Permutation[xx].pieceNumber[w]].permutation = Piece[x].Permutation[xx].name;
                            rd[Piece[x].Permutation[xx].pieceNumber[w]].lod = w;
                        }
                    }
                }
            }
Example #4
0
        /// <summary>
        /// The ce parsed model.
        /// </summary>
        /// <param name="meta">The meta.</param>
        /// <remarks></remarks>
        public void CEParsedModel(ref Meta meta)
        {
            Display = new DisplayedInfo();
            string[] temps = meta.name.Split('\\');
            name = temps[temps.Length - 1];
            BoundingBox = new BoundingBoxContainer();
            BinaryReader BR = new BinaryReader(meta.MS);
            BR.BaseStream.Position = 208;
            int tempc = BR.ReadInt32();
            int tempr = BR.ReadInt32() - meta.magic - meta.offset;
            BR.BaseStream.Position = tempr + 36;
            tempc = BR.ReadInt32();
            RawDataMetaChunks = new RawDataMetaChunk[meta.raw.rawChunks.Count / 2];
            for (int x = 0; x < meta.raw.rawChunks.Count / 2; x++)
            {
                RawDataMetaChunks[x] = new RawDataMetaChunk();
                RawDataMetaChunks[x].IndiceCount = meta.raw.rawChunks[x * 2].size / 2;
                BinaryReader BRX = new BinaryReader(meta.raw.rawChunks[x * 2].MS);
                BRX.BaseStream.Position = 0;
                RawDataMetaChunks[x].Indices = new short[RawDataMetaChunks[x].IndiceCount];
                for (int y = 0; y < RawDataMetaChunks[x].IndiceCount; y++)
                {
                    RawDataMetaChunks[x].Indices[y] = BRX.ReadInt16();
                }

                RawDataMetaChunks[x].Indices = Renderer.DecompressIndices(
                    RawDataMetaChunks[x].Indices, 0, RawDataMetaChunks[x].Indices.Length);
                RawDataMetaChunks[x].IndiceCount = RawDataMetaChunks[x].Indices.Length;
                RawDataMetaChunks[x].FaceCount = RawDataMetaChunks[x].IndiceCount / 3;
                RawDataMetaChunks[x].SubMeshInfo = new RawDataMetaChunk.ModelSubMeshInfo[1];
                RawDataMetaChunks[x].SubMeshInfo[0] = new RawDataMetaChunk.ModelSubMeshInfo();
                RawDataMetaChunks[x].SubMeshInfo[0].IndiceCount = RawDataMetaChunks[x].IndiceCount;
                RawDataMetaChunks[x].SubMeshInfo[0].ShaderNumber = meta.raw.rawChunks[x * 2].shadernumber;
                RawDataMetaChunks[x].Vertices = new List<Vector3>();
                RawDataMetaChunks[x].UVs = new List<Vector2>();
                RawDataMetaChunks[x].Normals = new List<Vector3>();
                RawDataMetaChunks[x].Binormals = new List<Vector3>();
                RawDataMetaChunks[x].Tangents = new List<Vector3>();
                int chunksize = 68;
                if (meta.Map.HaloVersion == HaloVersionEnum.Halo1)
                {
                    chunksize = 32;
                }

                RawDataMetaChunks[x].VerticeCount = meta.raw.rawChunks[x * 2 + 1].size / chunksize;
                BRX = new BinaryReader(meta.raw.rawChunks[x * 2 + 1].MS);

                for (int y = 0; y < RawDataMetaChunks[x].VerticeCount; y++)
                {
                    BRX.BaseStream.Position = y * chunksize;
                    Vector3 vertice = new Vector3(BRX.ReadSingle(), BRX.ReadSingle(), BRX.ReadSingle());
                    RawDataMetaChunks[x].Vertices.Add(vertice);
                    switch (meta.Map.HaloVersion)
                    {
                        case HaloVersionEnum.HaloCE:
                            Vector3 normal = new Vector3(BRX.ReadSingle(), BRX.ReadSingle(), BRX.ReadSingle());
                            RawDataMetaChunks[x].Normals.Add(normal);
                            Vector3 binormal = new Vector3(BRX.ReadSingle(), BRX.ReadSingle(), BRX.ReadSingle());
                            RawDataMetaChunks[x].Binormals.Add(binormal);
                            Vector3 tangent = new Vector3(BRX.ReadSingle(), BRX.ReadSingle(), BRX.ReadSingle());
                            RawDataMetaChunks[x].Tangents.Add(tangent);
                            Vector2 uv = new Vector2(BRX.ReadSingle(), BRX.ReadSingle());

                            RawDataMetaChunks[x].UVs.Add(uv);
                            break;
                        case HaloVersionEnum.Halo1:
                            int test = BRX.ReadInt32();
                            Vector3 normal2 = DecompressNormal(test);
                            RawDataMetaChunks[x].Normals.Add(normal2);
                            test = BRX.ReadInt32();
                            Vector3 binormal2 = DecompressNormal(test);
                            RawDataMetaChunks[x].Binormals.Add(binormal2);
                            test = BRX.ReadInt32();
                            Vector3 tangent2 = DecompressNormal(test);
                            RawDataMetaChunks[x].Tangents.Add(tangent2);
                            short testx = BRX.ReadInt16();
                            float u = DecompressVertice(Convert.ToSingle(testx), -1, 1); // %1 ;
                            testx = BRX.ReadInt16();
                            float v = DecompressVertice(Convert.ToSingle(testx), -1, 1); // % 1;
                            Vector2 uv2 = new Vector2(u, v);

                            RawDataMetaChunks[x].UVs.Add(uv2);
                            break;
                    }
                }

                if (x < tempc)
                {
                    Display.Chunk.Add(x);
                }
            }

            Shaders = new ShaderContainer();

            BR.BaseStream.Position = 220;
            tempc = BR.ReadInt32();
            tempr = BR.ReadInt32() - meta.magic - meta.offset;
            Shaders.Shader = new ShaderInfo[tempc];
            Display.ShaderIndex = new int[tempc];
            for (int x = 0; x < tempc; x++)
            {
                Display.ShaderIndex[x] = x;
                BR.BaseStream.Position = tempr + (x * 32) + 12;
                int temptag = meta.Map.Functions.ForMeta.FindMetaByID(BR.ReadInt32());
                Shaders.Shader[x] = new ShaderInfo(temptag, meta.Map);
            }
        }
Example #5
0
        /// <summary>
        /// The write obj.
        /// </summary>
        /// <param name="SW">The sw.</param>
        /// <param name="mtllib">The mtllib.</param>
        /// <param name="chunk">The chunk.</param>
        /// <param name="names">The names.</param>
        /// <param name="pass">The pass.</param>
        /// <param name="startFace">The start face.</param>
        /// <remarks></remarks>
        public void writeOBJ(
            StreamWriter SW, string mtllib, RawDataMetaChunk chunk, List<string> names, ref int pass, ref int startFace)
        {
            SW.WriteLine("mtllib " + mtllib);

            for (int y = 0; y < chunk.VerticeCount; y++)
            {
                string temps = "v " + chunk.Vertices[y].X + " " + chunk.Vertices[y].Y + " " + chunk.Vertices[y].Z;
                SW.WriteLine(temps);
            }

            SW.WriteLine("# " + chunk.Vertices.Count + " vertices");

            for (int y = 0; y < chunk.VerticeCount; y++)
            {
                string temps = "vt " + chunk.UVs[y].X + " " + chunk.UVs[y].Y;

                SW.WriteLine(temps);
            }

            SW.WriteLine("# " + chunk.Vertices.Count + " texture vertices");
            for (int y = 0; y < chunk.VerticeCount; y++)
            {
                string temps = "vn " + chunk.Normals[y].X + " " + chunk.Normals[y].Y + " " + chunk.Normals[y].Z;
                SW.WriteLine(temps);
            }

            SW.WriteLine("# " + chunk.Vertices.Count + " normals");

            for (int y = 0; y < chunk.SubMeshInfo.Length; y++)
            {
                SW.WriteLine("g " + pass + "." + y);
                try
                {
                    SW.WriteLine("usemtl  " + names[chunk.SubMeshInfo[y].ShaderNumber]);
                }
                catch
                {
                }

                short[] s***e = new short[100000];
                int s = 0;
                if (chunk.FaceCount * 3 != chunk.IndiceCount)
                {
                    int m = chunk.SubMeshInfo[y].IndiceStart;

                    bool dir = false;
                    short tempx;
                    short tempy;
                    short tempz;

                    do
                    {
                        // if (mode.EndOfIndices[x][j]>m+2){break;}
                        tempx = chunk.Indices[m];
                        tempy = chunk.Indices[m + 1];
                        tempz = chunk.Indices[m + 2];

                        if (tempx != tempy && tempx != tempz && tempy != tempz)
                        {
                            if (dir == false)
                            {
                                s***e[s] = tempx;
                                s***e[s + 1] = tempy;
                                s***e[s + 2] = tempz;
                                s += 3;

                                dir = true;
                            }
                            else
                            {
                                s***e[s] = tempx;
                                s***e[s + 1] = tempz;
                                s***e[s + 2] = tempy;
                                s += 3;
                                dir = false;
                            }

                            m += 1;
                        }
                        else
                        {
                            if (dir)
                            {
                                dir = false;
                            }
                            else
                            {
                                dir = true;
                            }

                            m += 1;
                        }
                    }
                    while (m < chunk.SubMeshInfo[y].IndiceStart + chunk.SubMeshInfo[y].IndiceCount - 2);
                }
                else
                {
                    Array.Copy(
                        chunk.Indices, chunk.SubMeshInfo[y].IndiceStart, s***e, 0, chunk.SubMeshInfo[y].IndiceCount);
                    s = chunk.SubMeshInfo[y].IndiceCount; // chunk.IndiceCount;
                }

                for (int xx = 0; xx < s; xx += 3)
                {
                    string temps = "f " + (s***e[xx] + 1 + startFace) + "/" + (s***e[xx] + 1 + startFace) + "/" +
                                   (s***e[xx] + 1 + startFace) + " " + (s***e[xx + 1] + 1 + startFace) + "/" +
                                   (s***e[xx + 1] + 1 + startFace) + "/" + (s***e[xx + 1] + 1 + startFace) + " " +
                                   (s***e[xx + 2] + 1 + startFace) + "/" + (s***e[xx + 2] + 1 + startFace) + "/" +
                                   (s***e[xx + 2] + 1 + startFace);
                    SW.WriteLine(temps);
                }

                SW.WriteLine("# " + (s / 3) + " elements");
            }

            pass++;
            startFace += chunk.Vertices.Count;
        }
Example #6
0
        /// <summary>
        /// The h 2 parsed model.
        /// </summary>
        /// <param name="meta">The meta.</param>
        /// <remarks></remarks>
        public void H2ParsedModel(ref Meta meta)
        {
            if (meta.MS.Length == 0)
            {
                return;
            }

            string[] temps = meta.name.Split('\\');
            name = temps[temps.Length - 1];
            BoundingBox = new BoundingBoxContainer(ref meta);

            BinaryReader BR = new BinaryReader(meta.MS);
            BR.BaseStream.Position = 36;
            int tempc = BR.ReadInt32();
            int tempr = BR.ReadInt32() - meta.magic - meta.offset;
            RawDataMetaChunks = new RawDataMetaChunk[tempc];
            for (int x = 0; x < tempc; x++)
            {
                RawDataMetaChunks[x] = new RawDataMetaChunk(tempr + (x * 92), x, BoundingBox, ref meta);
            }

            Shaders = new ShaderContainer(ref meta);

            LOD = new LODInfo(ref meta, ref RawDataMetaChunks);

            int temphlmt = -1;
            for (int x = 0; x < meta.Map.IndexHeader.metaCount; x++)
            {
                if ("hlmt" == meta.Map.MetaInfo.TagType[x] && meta.Map.FileNames.Name[x] == meta.name)
                {
                    temphlmt = x;
                    break;
                }
            }

            if (temphlmt != -1)
            {
                hlmt = new hlmtContainer(temphlmt, meta.Map);
                PermutationString = hlmt.Permutations.Name;
            }

            // ** Length of Distance LOD
            Display = DisplayedInfo.FindDisplayedPieces(4, this);

            Frames = new FrameHierarchy();
            Frames.GetFramesFromHalo2Model(ref meta);
        }