public void Read(BinaryReader reader) { Offset = (uint)reader.BaseStream.Position; Identifier = reader.ReadUInt32(); HeaderSize = reader.ReadUInt32(); TextureCount = reader.ReadUInt32(); reader.BaseStream.Seek(Offset + HeaderSize, SeekOrigin.Begin); for (int i = 0; i < TextureCount; i++) { uint nodeOffset = (uint)reader.BaseStream.Position; uint NodeIdentifier = reader.ReadUInt32(); uint NodeSize = reader.ReadUInt32(); if (NodeIdentifier == 0x4E584554) //TEXN { Texture tex = new Texture(); tex.TextureID = new TextureID(reader); tex.Image = new PVRT(reader); Textures.Add(tex); } else if (NodeIdentifier == 0x454D414E) //NAME { for (i = 0; i < ((NodeSize - 8) / 8); i++) { Texture tex = new Texture(); tex.TextureID = new TextureID(reader); reader.BaseStream.Seek(-8, SeekOrigin.Current); UInt64 idName = reader.ReadUInt64(); if (MT5.SearchTexturesOneDirUp) { FileStream fileStream = (FileStream)reader.BaseStream; string dir = Path.GetDirectoryName(Path.GetDirectoryName(fileStream.Name)); TextureDatabase.SearchDirectory(dir); } if (MT5.UseTextureDatabase) { TEXN texture = TextureDatabase.FindTexture(idName); if (texture != null) { tex.Image = texture.Texture; Textures.Add(tex); } else { Textures.Add(tex); } } } } reader.BaseStream.Seek(nodeOffset + NodeSize, SeekOrigin.Begin); } while (reader.BaseStream.Position < reader.BaseStream.Length) { uint identifier = reader.ReadUInt32(); if (TEXL.IsValid(identifier)) { reader.BaseStream.Seek(-4, SeekOrigin.Current); TEXL = new TEXL(reader); } if (PTRL.IsValid(identifier)) { reader.BaseStream.Seek(-4, SeekOrigin.Current); PTRL = new PTRL(reader); } } }
protected override void _Read(BinaryReader reader) { Offset = (uint)reader.BaseStream.Position; Identifier = reader.ReadUInt32(); if (!IsValid(Identifier)) { return; } Size = reader.ReadUInt32(); FirstNodeOffset = reader.ReadUInt32(); TextureCount = reader.ReadUInt32(); //Read texture entries if there are any for (uint i = 0; i < TextureCount; i++) { TextureEntries.Add(new TextureEntry(reader)); } foreach (TextureEntry entry in TextureEntries) { entry.ReadTextureID(reader); } //If we are not at the first node yet, we still have an node offset table to read if (reader.BaseStream.Position != FirstNodeOffset) { NodeOffsetTableSize = reader.ReadUInt32(); for (int i = 0; i < NodeOffsetTableSize; i++) { NodeOffsetTable.Add(reader.ReadUInt32()); } } //Read first node and as an result create the whole node tree structure reader.BaseStream.Seek(Offset + FirstNodeOffset, SeekOrigin.Begin); RootNode = new MT7Node(reader, null); //Search for optional extra sections until EOF while (reader.BaseStream.Position < reader.BaseStream.Length - 4) { uint identifier = reader.ReadUInt32(); if (FACE.IsValid(identifier)) { reader.BaseStream.Seek(-4, SeekOrigin.Current); FACE = new FACE(reader); } else if (CLSG.IsValid(identifier)) { reader.BaseStream.Seek(-4, SeekOrigin.Current); CLSG = new CLSG(reader); } else if (TXT7.IsValid(identifier)) { reader.BaseStream.Seek(-4, SeekOrigin.Current); TXT7 = new TXT7(reader); } } //Filling the texture entries with the actual textures if (TXT7 != null) { foreach (TextureEntry entry in TextureEntries) { entry.Texture = TXT7.GetTexture(entry.TextureID); } } if (SearchTexturesOneDirUp) { FileStream fileStream = (FileStream)reader.BaseStream; string dir = Path.GetDirectoryName(Path.GetDirectoryName(fileStream.Name)); TextureDatabase.SearchDirectory(dir); } if (MT7.UseTextureDatabase) { foreach (TextureEntry entry in TextureEntries) { if (entry.Texture != null) { continue; } TEXN texture = TextureDatabase.FindTexture(entry.TextureID.Data); if (texture == null) { Console.WriteLine("Couldn't find texture: {0}", entry.TextureID.Name); continue; } entry.Texture = new Texture(); entry.Texture.TextureID = new TextureID(texture.TextureID); entry.Texture.Image = texture.Texture; } } //Populate base class textures foreach (TextureEntry entry in TextureEntries) { if (entry.Texture == null) { entry.Texture = new Texture(); entry.Texture.TextureID = entry.TextureID; } Textures.Add(entry.Texture); } //Resolve the textures in the faces RootNode.ResolveFaceTextures(Textures); }