diff options
author | Treeki <treeki@gmail.com> | 2011-02-13 04:03:59 +0100 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2011-02-13 04:03:59 +0100 |
commit | 52aada22e106b6fd36b6b94fb3064510ac3ee40c (patch) | |
tree | 5cf5eb6866e33b023bfdaaf94ab1deb4b8ff71ab /NW4RTools/BrresReader.cs | |
parent | 8b48608d45c8266b765e8ee29e612fb18376aa65 (diff) | |
download | nw4rtools-52aada22e106b6fd36b6b94fb3064510ac3ee40c.tar.gz nw4rtools-52aada22e106b6fd36b6b94fb3064510ac3ee40c.zip |
it converts textures too, now! some formats missing, I'll add them later.
Diffstat (limited to 'NW4RTools/BrresReader.cs')
-rw-r--r-- | NW4RTools/BrresReader.cs | 44 |
1 files changed, 44 insertions, 0 deletions
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<Model>(ins, ConvertModelResource)); break; + case "Textures(NW4R)": + File.Add(name, ReadAndConvertDict<Texture>(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(); |