From 52aada22e106b6fd36b6b94fb3064510ac3ee40c Mon Sep 17 00:00:00 2001 From: Treeki Date: Sun, 13 Feb 2011 04:03:59 +0100 Subject: it converts textures too, now! some formats missing, I'll add them later. --- NW4RTools/BrresReader.cs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'NW4RTools/BrresReader.cs') diff --git a/NW4RTools/BrresReader.cs b/NW4RTools/BrresReader.cs index 20d7739..71dacc3 100644 --- a/NW4RTools/BrresReader.cs +++ b/NW4RTools/BrresReader.cs @@ -64,6 +64,9 @@ namespace NW4RTools { case "3DModels(NW4R)": File.Add(name, ReadAndConvertDict(ins, ConvertModelResource)); break; + case "Textures(NW4R)": + File.Add(name, ReadAndConvertDict(ins, ConvertTextureResource)); + break; default: Debug.Send("Not implemented"); return; @@ -71,6 +74,47 @@ namespace NW4RTools { } } + + + private Texture ConvertTextureResource(string name, InputStream ins) { + using (var c = Debug.Push(name)) { + Texture tex = new Texture(); + + int startPos = ins.Position; + + OffsetMap.Add(startPos, "Texture: " + name); + + byte[] magic = ins.ReadBytes(4); + UInt32 size = ins.ReadUInt32(); + UInt32 version = ins.ReadUInt32(); + + Debug.Send("Offset: 0x{0:X}; Size: 0x{1:X}; Version: {2}", startPos, size, version); + + Int32 resFileOffset = ins.ReadInt32(); + Int32 dataOffset = ins.ReadInt32(); + Int32 nameOffset = ins.ReadInt32(); + + // Flags stores nothing interesting, just "is CI" flag (0x1) + UInt32 flags = ins.ReadUInt32(); + + Int16 width = ins.ReadInt16(); + Int16 height = ins.ReadInt16(); + TextureFormat format = (TextureFormat)ins.ReadUInt32(); + + tex.MipMapCount = ins.ReadUInt32(); + tex.MinLOD = ins.ReadFloat(); + tex.MaxLOD = ins.ReadFloat(); + + ins.Seek(startPos + dataOffset); + OffsetMap.Add(ins.Position, String.Format("Texture Data for: {0} [{1}, {2}x{3}]", name, format, width, height)); + tex.ImportData(ins.ReadBytes(Texture.GetDataSize(width, height, format)), width, height, format); + + return tex; + } + } + + + private Model ConvertModelResource(string name, InputStream ins) { using (var c = Debug.Push(name)) { Model mdl = new Model(); -- cgit v1.2.3