public unsafe void Read(Stream stream)
{
using (var io = IoBuffer.FromStream(stream))
{
var version = io.ReadInt32();
var boneCount = io.ReadInt32();
var boneNames = new string[boneCount];
for (var i = 0; i < boneCount; i++){
boneNames[i] = io.ReadPascalString();
}
var faceCount = io.ReadInt32();
NumPrimitives = faceCount;
IndexBuffer = new short[faceCount * 3];
int offset = 0;
for (var i = 0; i < faceCount; i++){
IndexBuffer[offset++] = (short)io.ReadInt32();
IndexBuffer[offset++] = (short)io.ReadInt32();
IndexBuffer[offset++] = (short)io.ReadInt32();
}
/** Bone bindings **/
var bindingCount = io.ReadInt32();
BoneBindings = new BoneBinding[bindingCount];
for (var i = 0; i < bindingCount; i++)
{
BoneBindings[i] = new BoneBinding
{
BoneIndex = io.ReadInt32(),
FirstRealVertex = io.ReadInt32(),
RealVertexCount = io.ReadInt32(),
FirstBlendVertex = io.ReadInt32(),
BlendVertexCount = io.ReadInt32()
};
BoneBindings[i].BoneName = boneNames[BoneBindings[i].BoneIndex];
}
var realVertexCount = io.ReadInt32();
VertexBuffer = new VitaboyVertex[realVertexCount];
for (var i = 0; i < realVertexCount; i++){
VertexBuffer[i].TextureCoordinate.X = io.ReadFloat();
VertexBuffer[i].TextureCoordinate.Y = io.ReadFloat();
}
/** Blend data **/
var blendVertexCount = io.ReadInt32();
BlendData = new BlendData[blendVertexCount];
for (var i = 0; i < blendVertexCount; i++)
{
BlendData[i] = new BlendData
{
Weight = (float)io.ReadInt32() / 0x8000,
OtherVertex = io.ReadInt32()
};
}
var realVertexCount2 = io.ReadInt32();
for (int i = 0; i < realVertexCount; i++)
{
VertexBuffer[i].Position = new Microsoft.Xna.Framework.Vector3(
-io.ReadFloat(),
io.ReadFloat(),
io.ReadFloat()
);
VertexBuffer[i].Normal = new Microsoft.Xna.Framework.Vector3(
-io.ReadFloat(),
io.ReadFloat(),
io.ReadFloat()
);
}
BlendVerts = new Vector3[blendVertexCount];
for (int i = 0; i < blendVertexCount; i++)
{
BlendVerts[i] = new Vector3(
-io.ReadFloat(),
io.ReadFloat(),
io.ReadFloat()
);
var normal = new Vector3(
-io.ReadFloat(),
io.ReadFloat(),
io.ReadFloat()
); //todo: read this in somewhere and use it for lighting.
}
BlendVertBoneIndices = new int[blendVertexCount];
}
}