Add model material parsing

This commit is contained in:
Jarrod Doyle 2024-08-18 10:23:31 +01:00
parent b5d3a3c275
commit 2c9958a64a
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 25 additions and 0 deletions

View File

@ -136,12 +136,31 @@ public class ModelFile
}
}
public struct Material
{
public string Name;
public byte Type;
public byte Slot;
public uint Handle;
public float Uv;
public Material(BinaryReader reader)
{
Name = Encoding.UTF8.GetString(reader.ReadBytes(16)).Replace("\0", string.Empty);
Type = reader.ReadByte();
Slot = reader.ReadByte();
Handle = reader.ReadUInt32();
Uv = reader.ReadSingle();
}
}
public BHeader BinHeader { get; set; }
public MHeader Header { get; set; }
public Vector3[] Vertices { get; }
public Vector2[] Uvs { get; }
public Vector3[] Normals { get; }
public Polygon[] Polygons { get; }
public Material[] Materials { get; }
public ModelFile(string filename)
{
@ -178,5 +197,11 @@ public class ModelFile
{
Polygons[i] = new Polygon(reader, BinHeader.Version);
}
stream.Seek(Header.MaterialOffset, SeekOrigin.Begin);
Materials = new Material[Header.MaterialCount];
for (var i = 0; i < Materials.Length; i++)
{
Materials[i] = new Material(reader);
}
}
}