summaryrefslogtreecommitdiff
path: root/NW4RTools/BrresReader.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--NW4RTools/BrresReader.cs160
1 files changed, 160 insertions, 0 deletions
diff --git a/NW4RTools/BrresReader.cs b/NW4RTools/BrresReader.cs
index a157fe9..4c63926 100644
--- a/NW4RTools/BrresReader.cs
+++ b/NW4RTools/BrresReader.cs
@@ -145,6 +145,8 @@ namespace NW4RTools {
FinishNodeLoading();
// 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"))
@@ -153,6 +155,11 @@ 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);
return mdl;
}
@@ -371,6 +378,159 @@ namespace NW4RTools {
+ private Models.Material ConvertModelMaterial(string name, InputStream ins) {
+ Debug.Send("Reading {0}...", name);
+
+ var m = new Models.Material();
+
+ int startPos = ins.Position;
+ OffsetMap.Add(ins.Position, "Material: " + name);
+
+ UInt32 size = ins.ReadUInt32();
+ Int32 mdlOffset = ins.ReadInt32();
+ Int32 nameOffset = ins.ReadInt32();
+ m.Index = ins.ReadUInt32();
+ m.Flags = ins.ReadUInt32();
+
+ // ResGenMode
+ m.TexCoordGenCount = ins.ReadByte();
+ m.ChanCount = ins.ReadByte();
+ m.TevStageCount = ins.ReadByte();
+ m.IndStageCount = ins.ReadByte();
+ m.CullMode = ins.ReadUInt32();
+
+ // ResMatMisc
+ m.ZCompLoc = ins.ReadByte();
+ m.LightSetID = ins.ReadByte();
+ m.FogID = ins.ReadByte();
+
+ m.IndirectTexMtxCalcMethod1 = ins.ReadBytes(4);
+ m.IndirectTexMtxCalcMethod2 = ins.ReadBytes(4);
+ ins.Skip(1);
+
+ // Other stuff
+ Int32 shaderOffset = ins.ReadInt32();
+ UInt32 boundTexCount = ins.ReadUInt32();
+ Int32 boundTexOffset = ins.ReadInt32();
+ Int32 furOffset = ins.ReadInt32();
+ Int32 unkOffset = ins.ReadInt32();
+ Int32 dlOffset = ins.ReadInt32();
+
+ // ResTexObj
+ int ResTexObjPos = ins.Position;
+ OffsetMap.Add(ins.Position, "Material ResTexObj: " + name);
+
+ UInt32 textureFlag = ins.ReadUInt32();
+ m.TexObj = new byte[8][];
+
+ for (int i = 0; i < 8; i++) {
+ if ((textureFlag & (1 << i)) != 0) {
+ m.TexObj[i] = ins.ReadBytes(0x20);
+ }
+ }
+
+ ins.Seek(ResTexObjPos + 0x104);
+
+ // ResTlutObj
+ int ResTlutObjPos = ins.Position;
+ OffsetMap.Add(ins.Position, "Material ResTlutObj: " + name);
+
+ UInt32 tlutFlag = ins.ReadUInt32();
+ if ((tlutFlag & 0xFC) == 0) {
+ m.TlutObj = ins.ReadBytes(0x20);
+ } else if ((tlutFlag & 0xE0) == 0) {
+ m.TlutObj = ins.ReadBytes(0x40);
+ } else {
+ m.TlutObj = ins.ReadBytes(0x60);
+ }
+
+ ins.Seek(ResTlutObjPos + 0x64);
+
+ // ResTexSrt
+ int ResTexSrtPos = ins.Position;
+ OffsetMap.Add(ins.Position, "Material ResTexSrt: " + name);
+
+ UInt32 srtFlag = ins.ReadUInt32();
+ m.TexMatrixType = ins.ReadUInt32();
+
+ m.SRTSettings = new SRTSettingInfo[8];
+ InputStream texSrtStream = ins.At(ins.Position);
+ InputStream texSetStream = ins.At(ins.Position + (0x14 * 8));
+
+ for (int i = 0; i < 8; i++) {
+ if ((srtFlag & (0xF << (i * 4))) != 0) {
+ var srtInfo = m.SRTSettings[i] = new SRTSettingInfo();
+
+ srtInfo.ScaleX = texSrtStream.ReadFloat();
+ srtInfo.ScaleY = texSrtStream.ReadFloat();
+ srtInfo.Rotate = texSrtStream.ReadFloat();
+ srtInfo.TranslateX = texSrtStream.ReadFloat();
+ srtInfo.TranslateY = texSrtStream.ReadFloat();
+
+ srtInfo.CameraID = texSetStream.ReadByte();
+ srtInfo.LightID = texSetStream.ReadByte();
+ srtInfo.MapType = texSetStream.ReadByte();
+ srtInfo.Flags = texSetStream.ReadByte();
+ srtInfo.TexMatrix = texSetStream.ReadMatrix();
+ }
+ }
+
+ ins.Seek(ResTexSrtPos + 8 + (0x14 * 8) + (0x34 * 8));
+
+ // ResMatChan
+ OffsetMap.Add(ins.Position, "Material ResMatChan: " + name);
+
+ m.ChanCtrls = new ChanCtrl[2];
+
+ for (int i = 0; i < 2; i++) {
+ var chanInfo = m.ChanCtrls[i] = new ChanCtrl();
+
+ chanInfo.Flags = ins.ReadUInt32();
+ chanInfo.MatColor = ins.ReadColor();
+ chanInfo.AmbColor = ins.ReadColor();
+ chanInfo.FlagC = ins.ReadUInt32();
+ chanInfo.FlagA = ins.ReadUInt32();
+ }
+
+ // Bound Textures
+ ins.Seek(startPos + boundTexOffset);
+ m.BoundTextures = new List<BoundTextureInfo>((int)boundTexCount);
+
+ for (int i = 0; i < boundTexCount; i++) {
+ Debug.Send("Reading {0} bound texture at {1:X}", i, ins.Position);
+
+ int bPos = ins.Position;
+ var bTex = new BoundTextureInfo();
+ m.BoundTextures.Add(bTex);
+
+ 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("<{0}> <{1}>", bTex.TextureName, bTex.PaletteName);
+
+ // placeholder pointers, don't need these
+ ins.Skip(8);
+
+ bTex.TexMapID = ins.ReadUInt32();
+ bTex.TlutID = ins.ReadUInt32();
+ bTex.WrapS = ins.ReadUInt32();
+ bTex.WrapT = ins.ReadUInt32();
+ bTex.MinFilt = ins.ReadUInt32();
+ bTex.MagFilt = ins.ReadUInt32();
+ bTex.LODBias = ins.ReadFloat();
+ bTex.MaxAniso = ins.ReadUInt32();
+ bTex.BiasClamp = (ins.ReadByte() != 0);
+ bTex.DoEdgeLOD = (ins.ReadByte() != 0);
+ ins.Skip(2);
+ }
+
+ return m;
+ }
+
+
+
private RawStreamResDict ReadDict(InputStream ins) {
RawStreamResDict output = new RawStreamResDict();