From 58f30cf003a6b7b3686f70fa0539aa45d126b457 Mon Sep 17 00:00:00 2001 From: Treeki Date: Sun, 6 Feb 2011 04:02:38 +0100 Subject: shader reading support --- NW4RTools/BrresReader.cs | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'NW4RTools/BrresReader.cs') 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(ins.At(startPos + vtxPosOffset), ConvertVtxPosData); using (var c2 = Debug.Push("Vertex Normal Data")) @@ -155,15 +155,18 @@ namespace NW4RTools { mdl.VtxClrData = ReadAndConvertDict(ins.At(startPos + vtxClrOffset), ConvertVtxClrData); using (var c2 = Debug.Push("Vertex TexCoord Data")) mdl.VtxTexCoordData = ReadAndConvertDict(ins.At(startPos + texCoordOffset), ConvertVtxTexCoordData); - */ + //*/ - // Load materials - using (var c2 = Debug.Push("Materials")) - mdl.Materials = ReadAndConvertDict(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(); using (var c2 = Debug.Push("Shaders")) mdl.Shaders = ReadAndConvertDict(ins.At(startPos + shaderOffset), ConvertModelShader); + using (var c2 = Debug.Push("Materials")) + mdl.Materials = ReadAndConvertDict(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 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; } -- cgit v1.2.3