diff options
Diffstat (limited to 'NW4RTools/BrresReader.cs')
-rw-r--r-- | NW4RTools/BrresReader.cs | 104 |
1 files changed, 81 insertions, 23 deletions
diff --git a/NW4RTools/BrresReader.cs b/NW4RTools/BrresReader.cs index db5d7c2..e67581b 100644 --- a/NW4RTools/BrresReader.cs +++ b/NW4RTools/BrresReader.cs @@ -37,7 +37,7 @@ namespace NW4RTools { UInt16 headerSize = ins.ReadUInt16(); UInt16 blockCount = ins.ReadUInt16(); - File.version = version; + File.Version = version; // Read first block header byte[] blkMagic = ins.ReadBytes(4); @@ -67,8 +67,14 @@ namespace NW4RTools { case "Textures(NW4R)": File.Add(name, ReadAndConvertDict<Texture>(ins, ConvertTextureResource)); break; + case "AnmChr(NW4R)": + File.Add(name, ReadAndConvertDict<Models.Animation.CharacterAnim>(ins, ConvertAnmChrResource)); + break; + case "AnmClr(NW4R)": + File.Add(name, ReadAndConvertDict<Models.Animation.ColorAnim>(ins, ConvertAnmClrResource)); + break; case "AnmTexSrt(NW4R)": - File.Add(name, ReadAndConvertDict<Models.Animation.TextureSRT>(ins, ConvertAnmTexSRTResource)); + File.Add(name, ReadAndConvertDict<Models.Animation.TextureSRTAnim>(ins, ConvertAnmTexSRTResource)); break; default: Debug.Send("Not implemented"); @@ -125,16 +131,48 @@ namespace NW4RTools { - private Models.Animation.TextureSRT ConvertAnmTexSRTResource(string name, InputStream ins) { + private Models.Animation.CharacterAnim ConvertAnmChrResource(string name, InputStream ins) { using (var c = Debug.Push(name)) { - var anim = new Models.Animation.TextureSRT(); + var anim = new Models.Animation.CharacterAnim(); int startPos = ins.Position; - OffsetMap.Add(startPos, "Texture SRT Animation: " + name); + OffsetMap.Add(startPos, "Character Animation: " + name); // TODO + + return anim; + } + } + + + + private Models.Animation.ColorAnim ConvertAnmClrResource(string name, InputStream ins) { + using (var c = Debug.Push(name)) { + var anim = new Models.Animation.ColorAnim(); + int startPos = ins.Position; + + OffsetMap.Add(startPos, "Color Animation: " + name); + + // TODO + + return anim; + } + } + + + + private Models.Animation.TextureSRTAnim ConvertAnmTexSRTResource(string name, InputStream ins) { + using (var c = Debug.Push(name)) { + var anim = new Models.Animation.TextureSRTAnim(); + + int startPos = ins.Position; + + OffsetMap.Add(startPos, "Texture SRT Animation: " + name); + + // TODO + return anim; } } @@ -170,6 +208,10 @@ namespace NW4RTools { Int32 textureOffset = ins.ReadInt32(); Int32 paletteOffset = ins.ReadInt32(); Int32 unkOffset = ins.ReadInt32(); + if (unkOffset != 0) { + Debug.Send("WARNING: Model {0} has unhandled unknown data", name); + OffsetMap.Add(startPos + unkOffset, "Model Unknown Data: " + name); + } Int32 nameOffset = ins.ReadInt32(); int infoStructPos = ins.Position; @@ -180,10 +222,10 @@ namespace NW4RTools { Int32 mdlOffset = ins.ReadInt32(); mdl.ScaleMode = (Model.ScaleModeType)ins.ReadUInt32(); mdl.TexMatrixMode = (Model.TexMatrixModeType)ins.ReadUInt32(); - UInt32 vtxCount = ins.ReadUInt32(); - UInt32 triCount = ins.ReadUInt32(); + mdl.VertexCount = ins.ReadUInt32(); + mdl.TriangleCount = ins.ReadUInt32(); UInt32 unk = ins.ReadUInt32(); - UInt32 nodeCount = ins.ReadUInt32(); + UInt32 matrixCount = ins.ReadUInt32(); mdl.UsesNrmMtxArray = (bool)(ins.ReadByte() != 0); mdl.UsesTexMtxArray = (bool)(ins.ReadByte() != 0); ins.Skip(2); @@ -216,8 +258,6 @@ namespace NW4RTools { FinishNodeLoading(); // Load vertex data - // COMMENTED OUT TO MAKE DEUBG OUTPUT CLEARER FOR NOW - VtxPosIndexLookup = new Dictionary<int, VertexPosData>(); VtxNrmIndexLookup = new Dictionary<int, VertexNrmData>(); VtxClrIndexLookup = new Dictionary<int, VertexClrData>(); @@ -259,12 +299,12 @@ namespace NW4RTools { } } - //*/ - // Load materials and associated structs // Material classes refer to Shaders using an offset, so this is used to fix those up + // Also, Pairings refer to Texture Info ShaderOffsetRefs = new Dictionary<int, Shader>(); MaterialOffsetRefs = new Dictionary<int, Material>(); + TextureInfoRefs = new Dictionary<int, TextureInfo>(); using (var c2 = Debug.Push("Shaders")) mdl.Shaders = ReadAndConvertDict<Shader>(ins.At(startPos + shaderOffset), ConvertModelShader); @@ -403,6 +443,10 @@ namespace NW4RTools { NodeLoadData[startPos] = loadInfo; Int32 extraDataOffset = ins.ReadInt32(); + if (extraDataOffset != 0) { + Debug.Send("WARNING: Node {0} has unhandled extra data!", name); + OffsetMap.Add(startPos + extraDataOffset, "Node Extra Data: " + name); + } n.NodeMatrix = ins.ReadMatrix(); n.NodeInvMatrix = ins.ReadMatrix(); @@ -471,15 +515,10 @@ namespace NW4RTools { n.EntryCount = ins.ReadUInt16(); - int structEndPos = ins.Position; - - ins.Seek(startPos + dataOffset); - n.RawData = ins.ReadBytes(n.EntrySize * n.EntryCount); + n.RawData = ins.At(startPos + dataOffset).ReadBytes(n.EntrySize * n.EntryCount); n.Parse(); OffsetMap.Add(startPos + dataOffset, n.GetType().ToString() + " Data"); - - ins.Seek(structEndPos); } private Dictionary<int, Models.VertexPosData> VtxPosIndexLookup; @@ -544,6 +583,7 @@ namespace NW4RTools { private Dictionary<int, Models.Material> MaterialOffsetRefs; + private Dictionary<int, Models.TextureInfo> TextureInfoRefs; private Models.Material ConvertModelMaterial(string name, InputStream ins) { Debug.Send("Reading {0}...", name); @@ -611,10 +651,10 @@ namespace NW4RTools { int ResTlutObjPos = ins.Position; //OffsetMap.Add(ins.Position, "Material ResTlutObj: " + name); - UInt32 tlutFlag = ins.ReadUInt32(); - if ((tlutFlag & 0xFC) == 0) { + m.TlutFlag = ins.ReadUInt32(); + if ((m.TlutFlag & ~3) == 0) { m.TlutObj = ins.ReadBytes(0x20); - } else if ((tlutFlag & 0xE0) == 0) { + } else if ((m.TlutFlag & ~0x1F) == 0) { m.TlutObj = ins.ReadBytes(0x40); } else { m.TlutObj = ins.ReadBytes(0x60); @@ -678,7 +718,11 @@ namespace NW4RTools { for (int i = 0; i < texInfoCount; i++) { //Debug.Send("Reading {0} texture info at {1:X}", i, ins.Position); - m.TextureInfos.Add(ReadTextureInfo(ins)); + int texInfoPos = ins.Position; + var texInfo = ReadTextureInfo(ins); + + m.TextureInfos.Add(texInfo); + TextureInfoRefs[texInfoPos] = texInfo; } // Display Lists @@ -812,6 +856,16 @@ namespace NW4RTools { // 0x64 Int32 extraDataOffset = ins.ReadInt32(); + var ed = ins.At(startPos + extraDataOffset); + UInt32 edCount = ed.ReadUInt32(); + + s.ExtraData = new ushort[edCount]; + for (int i = 0; i < edCount; i++) { + s.ExtraData[i] = ed.ReadUInt16(); + } + + OffsetMap.Add(startPos + extraDataOffset, String.Format("Shape Extra Data: {0} [{1} entries]", name, edCount)); + return s; } @@ -827,7 +881,7 @@ namespace NW4RTools { for (int i = 0; i < count; i++) { var p = new TexMatPairing(); p.Material = MaterialOffsetRefs[startPos + ins.ReadInt32()]; - p.Texture = ReadTextureInfo(ins.At(startPos + ins.ReadInt32())); + p.Texture = TextureInfoRefs[startPos + ins.ReadInt32()]; list.Add(p); } @@ -840,11 +894,15 @@ namespace NW4RTools { int bPos = ins.Position; var bTex = new Models.TextureInfo(); + Debug.Send("Reading a texture info from {0:X}", bPos); + Int32 texOffs = ins.ReadInt32(); bTex.TextureName = texOffs == 0 ? null : ins.At(bPos + texOffs - 4).ReadName(); Int32 palOffs = ins.ReadInt32(); bTex.PaletteName = palOffs == 0 ? null : ins.At(bPos + palOffs - 4).ReadName(); + Debug.Send("Was {0}", bTex.TextureName); + // placeholder pointers, don't need these ins.Skip(8); |