summaryrefslogtreecommitdiff
path: root/NW4RTools/BrresReader.cs
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2011-02-11 01:10:44 +0100
committerTreeki <treeki@gmail.com>2011-02-11 01:10:44 +0100
commit0d017deb24e7f6f8e049616a71691f1401c50b6a (patch)
tree8b107dcb3d51163831ffcce96010367f3779585e /NW4RTools/BrresReader.cs
parent58dead7b909861732011325f5d4844eae21a9bc2 (diff)
downloadnw4rtools-0d017deb24e7f6f8e049616a71691f1401c50b6a.tar.gz
nw4rtools-0d017deb24e7f6f8e049616a71691f1401c50b6a.zip
tons of stuff: more work on shapes, unfinished OBJ exporter, ...
Diffstat (limited to 'NW4RTools/BrresReader.cs')
-rw-r--r--NW4RTools/BrresReader.cs46
1 files changed, 36 insertions, 10 deletions
diff --git a/NW4RTools/BrresReader.cs b/NW4RTools/BrresReader.cs
index eeccd94..49f2edb 100644
--- a/NW4RTools/BrresReader.cs
+++ b/NW4RTools/BrresReader.cs
@@ -147,6 +147,11 @@ namespace NW4RTools {
// 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>();
+ VtxTexCoordIndexLookup = new Dictionary<int, VertexTexCoordData>();
+
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"))
@@ -341,9 +346,11 @@ namespace NW4RTools {
Int32 dataOffset = ins.ReadInt32();
Int32 nameOffset = ins.ReadInt32();
+ // Note: we're relying on this value to be correct, for Shape mappings
n.Index = ins.ReadUInt32();
- n.ComponentCount = ins.ReadUInt32();
- n.ComponentType = ins.ReadUInt32();
+
+ n.ComponentCount = (CompCount)ins.ReadUInt32();
+ n.ComponentType = (CompType)ins.ReadUInt32();
n.Fraction = ins.ReadByte();
n.EntrySize = ins.ReadByte();
n.EntryCount = ins.ReadUInt16();
@@ -351,6 +358,11 @@ namespace NW4RTools {
n.Data = ins.ReadBytes(n.EntrySize * n.EntryCount);
}
+ private Dictionary<int, Models.VertexPosData> VtxPosIndexLookup;
+ private Dictionary<int, Models.VertexNrmData> VtxNrmIndexLookup;
+ private Dictionary<int, Models.VertexClrData> VtxClrIndexLookup;
+ private Dictionary<int, Models.VertexTexCoordData> VtxTexCoordIndexLookup;
+
private Models.VertexPosData ConvertVtxPosData(string name, InputStream ins) {
var n = new Models.VertexPosData();
@@ -361,6 +373,8 @@ namespace NW4RTools {
n.Minimum = ins.ReadVec3();
n.Maximum = ins.ReadVec3();
+ VtxPosIndexLookup[(int)n.Index] = n;
+
return n;
}
@@ -370,6 +384,8 @@ namespace NW4RTools {
OffsetMap.Add(ins.Position, "VertexNrmData: " + name);
LoadVertexDataBase(ins, n);
+
+ VtxNrmIndexLookup[(int)n.Index] = n;
return n;
}
@@ -380,6 +396,8 @@ namespace NW4RTools {
OffsetMap.Add(ins.Position, "VertexClrData: " + name);
LoadVertexDataBase(ins, n);
+
+ VtxClrIndexLookup[(int)n.Index] = n;
return n;
}
@@ -394,6 +412,8 @@ namespace NW4RTools {
n.Minimum = ins.ReadVec2();
n.Maximum = ins.ReadVec2();
+ VtxTexCoordIndexLookup[(int)n.Index] = n;
+
return n;
}
@@ -638,19 +658,25 @@ namespace NW4RTools {
s.PolygonCount = ins.ReadUInt32();
// 0x48
- s.PosDataIndex = ins.ReadInt16();
+ s.PosData = VtxPosIndexLookup[ins.ReadInt16()];
+
// 0x4A
- s.NrmDataIndex = ins.ReadInt16();
+ short nrmIndex = ins.ReadInt16();
+ s.NrmData = nrmIndex == -1 ? null : VtxNrmIndexLookup[nrmIndex];
// 0x4C
- s.ClrDataIndex = new short[2];
- for (int i = 0; i < 2; i++)
- s.ClrDataIndex[i] = ins.ReadInt16();
+ s.ClrData = new VertexClrData[2];
+ for (int i = 0; i < 2; i++) {
+ short clrIndex = ins.ReadInt16();
+ s.ClrData[i] = clrIndex == -1 ? null : VtxClrIndexLookup[clrIndex];
+ }
// 0x50
- s.TexCoordDataIndex = new short[8];
- for (int i = 0; i < 8; i++)
- s.TexCoordDataIndex[i] = ins.ReadInt16();
+ s.TexCoordData = new VertexTexCoordData[8];
+ for (int i = 0; i < 8; i++) {
+ short tcIndex = ins.ReadInt16();
+ s.TexCoordData[i] = tcIndex == -1 ? null : VtxTexCoordIndexLookup[tcIndex];
+ }
// 0x60
s.FurVecDataIndex = ins.ReadInt16();