/// <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"); }
/// <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); }
/// <summary> /// The find displayed pieces. /// </summary> /// <param name="lodlevel">The lodlevel.</param> /// <param name="pm">The pm.</param> /// <returns></returns> /// <remarks></remarks> public static DisplayedInfo FindDisplayedPieces(int lodlevel, ParsedModel pm) { DisplayedInfo di = new DisplayedInfo(); if (pm.hlmt == null || pm.hlmt.Permutations.Piece.Length == 0) { for (int x = 0; x < pm.LOD.Piece.Length; x++) { for (int y = 0; y < pm.LOD.Piece[x].Permutation.Length; y++) { if (pm.LOD.Piece[x].Permutation[y].name == pm.LOD.PermutationStrings[0]) { if (di.Chunk.IndexOf(pm.LOD.Piece[x].Permutation[y].pieceNumber[lodlevel]) == -1) { di.Chunk.Add(pm.LOD.Piece[x].Permutation[y].pieceNumber[lodlevel]); } } } } goto shadeshit; } int tempid = pm.hlmt.FindPermutation(pm.PermutationString); LODInfo.LODPieceInfo.LODPermutationInfo lodinfo = new LODInfo.LODPieceInfo.LODPermutationInfo(); for (int x = 0; x < pm.hlmt.Permutations.Piece.Length; x++) { string name1 = pm.hlmt.Permutations.Piece[x].PieceName; // if (pm.hlmt.Permutations[tempid].Piece[x].Permutation.Length for (int xx = 0; xx < pm.hlmt.Permutations.Piece[x].Permutation.Length; xx++) { string name2 = pm.hlmt.Permutations.Piece[x].Permutation[xx].PermutationNameX; lodinfo = pm.LOD.FindPermutationInfo(name1, name2); if (di.Chunk.IndexOf(lodinfo.pieceNumber[lodlevel]) == -1) { di.Chunk.Add(lodinfo.pieceNumber[lodlevel]); } } } shadeshit: int[] tempshade = new int[200]; int tempshadecount = 1; for (int x = 0; x < di.Chunk.Count; x++) { for (int y = 0; y < pm.RawDataMetaChunks[di.Chunk[x]].SubMeshInfo.Length; y++) { int r = pm.RawDataMetaChunks[di.Chunk[x]].SubMeshInfo[y].ShaderNumber; if (Array.IndexOf(tempshade, r) == -1) { tempshade[tempshadecount] = r; tempshadecount++; } } } di.ShaderIndex = new int[tempshadecount]; Array.Copy(tempshade, 0, di.ShaderIndex, 0, tempshadecount); return di; }
/// <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); } }
/// <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); }