From 27cd642d477e0c5647c61565af393f9dca8b6f66 Mon Sep 17 00:00:00 2001 From: Treeki Date: Sat, 5 Feb 2011 04:52:41 +0100 Subject: one final commit before I go to sleep, changed some debug messages, added empty (so far) code for loading shaders, will do more tomorrow --- NW4RTools/BrresReader.cs | 43 ++++++++++++++++++++++++++++++---- NW4RTools/Models/Model.cs | 1 + NW4RTools/Models/Shader.cs | 10 ++++++++ NW4RTools/NW4RTools.csproj | 1 + NW4RTools/bin/Debug/NW4RTools.dll | Bin 28160 -> 28672 bytes NW4RTools/bin/Debug/NW4RTools.dll.mdb | Bin 9806 -> 10083 bytes 6 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 NW4RTools/Models/Shader.cs (limited to 'NW4RTools') diff --git a/NW4RTools/BrresReader.cs b/NW4RTools/BrresReader.cs index 4c63926..70463d6 100644 --- a/NW4RTools/BrresReader.cs +++ b/NW4RTools/BrresReader.cs @@ -146,7 +146,7 @@ namespace NW4RTools { // Load vertex data // COMMENTED OUT TO MAKE DEUBG OUTPUT CLEARER FOR NOW - /* + /* using (var c2 = Debug.Push("Vertex Position Data")) mdl.VtxPosData = ReadAndConvertDict(ins.At(startPos + vtxPosOffset), ConvertVtxPosData); using (var c2 = Debug.Push("Vertex Normal Data")) @@ -158,9 +158,12 @@ namespace NW4RTools { */ // Load materials - using (var c2 = Debug.Push("Materials")) + using (var c2 = Debug.Push("Materials")) mdl.Materials = ReadAndConvertDict(ins.At(startPos + materialOffset), ConvertModelMaterial); + using (var c2 = Debug.Push("Shaders")) + mdl.Shaders = ReadAndConvertDict(ins.At(startPos + shaderOffset), ConvertModelShader); + return mdl; } } @@ -409,12 +412,23 @@ namespace NW4RTools { ins.Skip(1); // Other stuff + // Shader offset points to an entry in the Shaders group, must fix this up later + // like I did with Node classes Int32 shaderOffset = ins.ReadInt32(); + //Debug.Send("Shader offset for {0}: {1:X} [dest {2:X}]", name, shaderOffset, startPos + shaderOffset); + UInt32 boundTexCount = ins.ReadUInt32(); Int32 boundTexOffset = ins.ReadInt32(); + Int32 furOffset = ins.ReadInt32(); + Debug.Send("Fur offset for {0}: {1:X} [dest {2:X}]", name, furOffset, startPos + furOffset); + Int32 unkOffset = ins.ReadInt32(); + Debug.Send("Unknown offset for {0}: {1:X} [dest {2:X}]", name, unkOffset, startPos + unkOffset); + + // Need to implement DLs... Int32 dlOffset = ins.ReadInt32(); + Debug.Send("DL offset for {0}: {1:X} [dest {2:X}]", name, dlOffset, startPos + dlOffset); // ResTexObj int ResTexObjPos = ins.Position; @@ -493,11 +507,14 @@ namespace NW4RTools { } // Bound Textures + if (boundTexOffset != 0) + OffsetMap.Add(startPos + boundTexOffset, "Material Bound Textures: " + name); + ins.Seek(startPos + boundTexOffset); m.BoundTextures = new List((int)boundTexCount); for (int i = 0; i < boundTexCount; i++) { - Debug.Send("Reading {0} bound texture at {1:X}", i, ins.Position); + //Debug.Send("Reading {0} bound texture at {1:X}", i, ins.Position); int bPos = ins.Position; var bTex = new BoundTextureInfo(); @@ -508,7 +525,7 @@ namespace NW4RTools { Int32 palOffs = ins.ReadInt32(); bTex.PaletteName = palOffs == 0 ? null : ins.At(bPos + palOffs - 4).ReadName(); - Debug.Send("<{0}> <{1}>", bTex.TextureName, bTex.PaletteName); + //Debug.Send("<{0}> <{1}>", bTex.TextureName, bTex.PaletteName); // placeholder pointers, don't need these ins.Skip(8); @@ -531,6 +548,24 @@ namespace NW4RTools { + private Models.Shader ConvertModelShader(string name, InputStream ins) { + var s = new Models.Shader(); + + //Debug.Send("{0} @ {1:X}", name, ins.Position); + int startPos = ins.Position; + + // Note: duplicate shader entries seem to be common, so OffsetMap.Add can't be used + // Looks like Nintendo's converter checks for them when writing and optimises them + // into one entry. That'll sure be fun to implement here... probably requiring + // messing around with IEqualityComparer or whatever it's called. I don't even know + // if I'm making sense or not. Too tired to look it up, it's 4:51am... + OffsetMap[ins.Position] = "Shader: " + name; + + return s; + } + + + private RawStreamResDict ReadDict(InputStream ins) { RawStreamResDict output = new RawStreamResDict(); diff --git a/NW4RTools/Models/Model.cs b/NW4RTools/Models/Model.cs index 8fa576e..d1c170b 100644 --- a/NW4RTools/Models/Model.cs +++ b/NW4RTools/Models/Model.cs @@ -16,6 +16,7 @@ namespace NW4RTools.Models { public ResDict VtxClrData; public ResDict VtxTexCoordData; public ResDict Materials; + public ResDict Shaders; /*public ResDict Bytecode, Nodes, VtxPosData, VtsNrmData, VtxClrData, VtxTexCoordData; public ResDict VtxFurVecData, VtxFurPosData, Materials, Shaders, Shapes; diff --git a/NW4RTools/Models/Shader.cs b/NW4RTools/Models/Shader.cs new file mode 100644 index 0000000..42586da --- /dev/null +++ b/NW4RTools/Models/Shader.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; + +namespace NW4RTools.Models { + public class Shader { + public Shader() { + } + } +} + diff --git a/NW4RTools/NW4RTools.csproj b/NW4RTools/NW4RTools.csproj index f8f89e8..9050c94 100644 --- a/NW4RTools/NW4RTools.csproj +++ b/NW4RTools/NW4RTools.csproj @@ -47,6 +47,7 @@ + diff --git a/NW4RTools/bin/Debug/NW4RTools.dll b/NW4RTools/bin/Debug/NW4RTools.dll index 7e28e2a..1d9a2ad 100755 Binary files a/NW4RTools/bin/Debug/NW4RTools.dll and b/NW4RTools/bin/Debug/NW4RTools.dll differ diff --git a/NW4RTools/bin/Debug/NW4RTools.dll.mdb b/NW4RTools/bin/Debug/NW4RTools.dll.mdb index 8183184..e3698a2 100644 Binary files a/NW4RTools/bin/Debug/NW4RTools.dll.mdb and b/NW4RTools/bin/Debug/NW4RTools.dll.mdb differ -- cgit v1.2.3