Exemple #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");
        }
Exemple #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");
        }
Exemple #3
0
 public Chunk(int chunkPos)
 {
     if (Dungeon.getDeserializing()) return;
     this.chunkPos = chunkPos;
     this.color = Color.Orange;
     this.sColor = new SerializedColor(color);
     boundingBoxes = new BoundingBoxContainer();
 }
Exemple #4
0
        /// <summary>
        /// The dispose.
        /// </summary>
        /// <remarks></remarks>
        public void Dispose()
        {
            this.BoundingBox = null;
            this.Display = null;
            this.hlmt = null;
            this.LOD = null;
            this.RawDataMetaChunks = null;
            for (int i = 0; i < this.Shaders.Shader.Length; i++)
            {
                this.Shaders.Shader[i].Bitmaps.Clear();
                this.Shaders.Shader[i].BitmapNames.Clear();
            }

            this.Shaders = null;
            GC.SuppressFinalize(this);
        }
Exemple #5
0
            /// <summary>
            /// Initializes a new instance of the <see cref="RawDataMetaChunk"/> class.
            /// </summary>
            /// <param name="offset">The offset.</param>
            /// <param name="chunknumber">The chunknumber.</param>
            /// <param name="bb">The bb.</param>
            /// <param name="meta">The meta.</param>
            /// <remarks></remarks>
            public RawDataMetaChunk(int offset, int chunknumber, BoundingBoxContainer bb, ref Meta meta)
            {
                BinaryReader BR = new BinaryReader(meta.MS);
                BR.BaseStream.Position = offset + 4;
                VerticeCount = BR.ReadUInt16();
                FaceCount = BR.ReadUInt16();
                BR.BaseStream.Position = offset + 20;
                type = BR.ReadByte();
                BR.BaseStream.Position = offset + 68;
                HeaderSize = meta.raw.rawChunks[chunknumber].size - BR.ReadInt32() - 4;
                int tempc = BR.ReadInt32();
                int tempr = BR.ReadInt32() - meta.magic - meta.offset;
                RawDataChunkInfo = new RawDataOffsetChunk[tempc];
                for (int x = 0; x < tempc; x++)
                {
                    RawDataChunkInfo[x] = new RawDataOffsetChunk();
                    BR.BaseStream.Position = tempr + (x * 16) + 6;
                    RawDataChunkInfo[x].ChunkSize = BR.ReadUInt16();
                    RawDataChunkInfo[x].Size = BR.ReadInt32();
                    if (RawDataChunkInfo[x].ChunkSize == 0)
                    {
                        RawDataChunkInfo[x].ChunkSize = RawDataChunkInfo[x].Size;
                    }

                    RawDataChunkInfo[x].Offset = BR.ReadInt32();
                    RawDataChunkInfo[x].ChunkCount = RawDataChunkInfo[x].Size / RawDataChunkInfo[x].ChunkSize;
                }

                BR = new BinaryReader(meta.raw.rawChunks[chunknumber].MS);
                SubMeshInfo = new ModelSubMeshInfo[RawDataChunkInfo[0].ChunkCount];
                for (int x = 0; x < RawDataChunkInfo[0].ChunkCount; x++)
                {
                    SubMeshInfo[x] = new ModelSubMeshInfo();
                    BR.BaseStream.Position = HeaderSize + RawDataChunkInfo[0].Offset + (x * 72) + 4;
                    SubMeshInfo[x].ShaderNumber = BR.ReadUInt16();
                    SubMeshInfo[x].IndiceStart = BR.ReadUInt16();
                    SubMeshInfo[x].IndiceCount = BR.ReadUInt16();
                }

                BR.BaseStream.Position = 40;
                IndiceCount = BR.ReadUInt16();

                int indicechunk = 0;
                int verticechunk = 0;
                int uvchunk = 0;

                for (int x = 0; x < RawDataChunkInfo.Length; x++)
                {
                    if (RawDataChunkInfo[x].ChunkSize == 2)
                    {
                        indicechunk = x;
                        verticechunk = x + 2;
                        uvchunk = x + 3;
                        break;
                    }
                }

                int bonemapchunk = 0;
                BR.BaseStream.Position = 108;
                int tempbonemapcount = BR.ReadUInt16();
                if (tempbonemapcount > 0)
                {
                    for (int x = uvchunk + 1; x < RawDataChunkInfo.Length; x++)
                    {
                        if (RawDataChunkInfo[x].ChunkSize == 1)
                        {
                            bonemapchunk = x;
                            break;
                        }
                    }

                    BR.BaseStream.Position = HeaderSize + RawDataChunkInfo[bonemapchunk].Offset;
                    for (int x = 0; x < tempbonemapcount; x++)
                    {
                        BoneMap.Add(BR.ReadByte());
                    }
                }
                else
                {
                    BoneMap.Add(0);
                }

                RawDataChunkInfo[verticechunk].ChunkSize = RawDataChunkInfo[verticechunk].Size / VerticeCount;
                for (int x = 0; x < VerticeCount; x++)
                {
                    Vector3 vec = new Vector3();
                    BR.BaseStream.Position = HeaderSize + RawDataChunkInfo[verticechunk].Offset +
                                             (RawDataChunkInfo[verticechunk].ChunkSize * x);
                    vec.X = DecompressVertice(BR.ReadInt16(), bb.MinX, bb.MaxX);
                    vec.Y = DecompressVertice(BR.ReadInt16(), bb.MinY, bb.MaxY);
                    vec.Z = DecompressVertice(BR.ReadInt16(), bb.MinZ, bb.MaxZ);
                    Vertices.Add(vec);

                    // if (tempbonemapcount == 0) { continue; }

                    switch (RawDataChunkInfo[verticechunk].ChunkSize)
                    {
                        case 6:
                            BoneInfo b = new BoneInfo();
                            b.BoneIndex.Add(0);
                            b.Weight.Add(1.0f);
                            VerticeBones.Add(b);

                            break;
                        case 8:
                            BoneInfo c = new BoneInfo();
                            c.BoneIndex.Add(BR.ReadByte());
                            c.Weight.Add(1.0f);
                            byte tempb = BR.ReadByte();
                            if (tempb == 0)
                            {
                                VerticeBones.Add(c);
                                break;
                            }

                            BoneInfo c2 = new BoneInfo();
                            c2.BoneIndex.Add(tempb);
                            c2.Weight.Add(1.0f);
                            VerticeBones.Add(c2);
                            c.Weight[0] = 1.0f;
                            VerticeBones.Add(c);
                            break;
                        case 12:
                            BoneInfo bbb = new BoneInfo();
                            bbb.BoneIndex.Add(BR.ReadByte());
                            bbb.Weight.Add(0.99f);
                            VerticeBones.Add(bbb);
                            break;
                    }
                }

                RawDataChunkInfo[uvchunk].ChunkSize = 4;
                for (int x = 0; x < VerticeCount; x++)
                {
                    Vector2 tempuv = new Vector2();
                    BR.BaseStream.Position = HeaderSize + RawDataChunkInfo[uvchunk].Offset +
                                             (RawDataChunkInfo[uvchunk].ChunkSize * x);
                    tempuv.X = DecompressVertice(BR.ReadInt16(), bb.MinU, bb.MaxU) % 1;
                    tempuv.Y = DecompressVertice(BR.ReadInt16(), bb.MinV, bb.MaxV) % 1;

                    // if (tempuv.X > 1) { tempuv.X = tempuv.X - 1; }
                    // else
                    if (tempuv.X < 0)
                    {
                        tempuv.X = 1 - tempuv.X;
                    }

                    // if (tempuv.Y > 1) { tempuv.Y = tempuv.Y - 1; }
                    // else
                    if (tempuv.Y < 0)
                    {
                        tempuv.Y = 1 - tempuv.Y;
                    }

                    UVs.Add(tempuv);
                }

                RawDataChunkInfo[uvchunk + 1].ChunkSize = 12;
                for (int x = 0; x < VerticeCount; x++)
                {
                    BR.BaseStream.Position = HeaderSize + RawDataChunkInfo[uvchunk + 1].Offset +
                                             (RawDataChunkInfo[uvchunk + 1].ChunkSize * x);

                    int dword = BR.ReadInt32();

                    Vector3 tempnormal = DecompressNormal(dword);

                    int converto = CompressNormal(tempnormal);
                    Vector3 tempnormal2 = DecompressNormal(converto);
                    Normals.Add(tempnormal);
                }

                BR.BaseStream.Position = HeaderSize + RawDataChunkInfo[indicechunk].Offset;
                this.Indices = new short[IndiceCount];
                for (int x = 0; x < IndiceCount; x++)
                {
                    Indices[x] = (short)BR.ReadUInt16();
                }
            }
Exemple #6
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);
            }
        }
Exemple #7
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);
        }