Add model material parsing
This commit is contained in:
parent
b5d3a3c275
commit
2c9958a64a
|
@ -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 BHeader BinHeader { get; set; }
|
||||||
public MHeader Header { get; set; }
|
public MHeader Header { get; set; }
|
||||||
public Vector3[] Vertices { get; }
|
public Vector3[] Vertices { get; }
|
||||||
public Vector2[] Uvs { get; }
|
public Vector2[] Uvs { get; }
|
||||||
public Vector3[] Normals { get; }
|
public Vector3[] Normals { get; }
|
||||||
public Polygon[] Polygons { get; }
|
public Polygon[] Polygons { get; }
|
||||||
|
public Material[] Materials { get; }
|
||||||
|
|
||||||
public ModelFile(string filename)
|
public ModelFile(string filename)
|
||||||
{
|
{
|
||||||
|
@ -178,5 +197,11 @@ public class ModelFile
|
||||||
{
|
{
|
||||||
Polygons[i] = new Polygon(reader, BinHeader.Version);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue