diff options
Diffstat (limited to '')
-rw-r--r-- | NW4RTools/BrresReader.cs | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/NW4RTools/BrresReader.cs b/NW4RTools/BrresReader.cs index 36634d0..cd9452d 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<VertexPosData>(ins.At(startPos + vtxPosOffset), ConvertVtxPosData); using (var c2 = Debug.Push("Vertex Normal Data")) @@ -155,15 +155,18 @@ namespace NW4RTools { mdl.VtxClrData = ReadAndConvertDict<VertexClrData>(ins.At(startPos + vtxClrOffset), ConvertVtxClrData); using (var c2 = Debug.Push("Vertex TexCoord Data")) mdl.VtxTexCoordData = ReadAndConvertDict<VertexTexCoordData>(ins.At(startPos + texCoordOffset), ConvertVtxTexCoordData); - */ + //*/ - // Load materials - using (var c2 = Debug.Push("Materials")) - mdl.Materials = ReadAndConvertDict<Material>(ins.At(startPos + materialOffset), ConvertModelMaterial); + // Load materials and associated structs + // Material classes refer to Shaders using an offset, so this is used to fix those up + ShaderOffsetRefs = new Dictionary<int, Shader>(); using (var c2 = Debug.Push("Shaders")) mdl.Shaders = ReadAndConvertDict<Shader>(ins.At(startPos + shaderOffset), ConvertModelShader); + using (var c2 = Debug.Push("Materials")) + mdl.Materials = ReadAndConvertDict<Material>(ins.At(startPos + materialOffset), ConvertModelMaterial); + return mdl; } } @@ -412,9 +415,8 @@ 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(); + m.ShaderRef = ShaderOffsetRefs[startPos + shaderOffset]; //Debug.Send("Shader offset for {0}: {1:X} [dest {2:X}]", name, shaderOffset, startPos + shaderOffset); UInt32 boundTexCount = ins.ReadUInt32(); @@ -556,6 +558,8 @@ namespace NW4RTools { + private Dictionary<int, Models.Shader> ShaderOffsetRefs; + private Models.Shader ConvertModelShader(string name, InputStream ins) { var s = new Models.Shader(); @@ -569,6 +573,21 @@ namespace NW4RTools { // if I'm making sense or not. Too tired to look it up, it's 4:51am... OffsetMap[ins.Position] = "Shader: " + name; + UInt32 size = ins.ReadUInt32(); + Int32 mdlOffset = ins.ReadInt32(); + + s.Index = ins.ReadUInt32(); + s.TevStageCount = ins.ReadByte(); + ins.Skip(3); + + s.Unk1 = ins.ReadUInt32(); + s.Unk2 = ins.ReadUInt32(); + ins.Skip(8); + + s.DisplayList = ins.ReadBytes(0x1E0); + + ShaderOffsetRefs[startPos] = s; + return s; } |