throw new IOException("Unrecognized mesh format");
// Populate base mesh variables
_hasWeights = (input.UnpackByte() != 0);
_hasDetailTexCoords = (input.UnpackByte() != 0);
_position = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
_rotationAngles = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
_rotationOrder = input.UnpackByte();
_scale = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
_numVertices = input.UnpackUShort();
// Populate the vertex array
_vertices = new Vertex[_numVertices];
for (int i = 0; i < _numVertices; i++)
_vertices[i].Coord = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
for (int i = 0; i < _numVertices; i++)
_vertices[i].Normal = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
for (int i = 0; i < _numVertices; i++)
_vertices[i].BiNormal = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
for (int i = 0; i < _numVertices; i++)
_vertices[i].TexCoord = new Vector2(input.UnpackFloat(), input.UnpackFloat());
if (_hasDetailTexCoords)
{
for (int i = 0; i < _numVertices; i++)
_vertices[i].DetailTexCoord = new Vector2(input.UnpackFloat(), input.UnpackFloat());
}
if (_hasWeights)
{
for (int i = 0; i < _numVertices; i++)
_vertices[i].Weight = input.UnpackFloat();
}
_numFaces = input.UnpackUShort();
_faces = new Face[_numFaces];
for (int i = 0; i < _numFaces; i++)
_faces[i].Indices = new short[] { input.UnpackShort(), input.UnpackShort(), input.UnpackShort() };
if (_hasWeights)
{
_numSkinJoints = input.UnpackUShort();
_skinJoints = new String[_numSkinJoints];
for (int i = 0; i < _numSkinJoints; i++)
{
_skinJoints[i] = Utils.TrimAt0(input.UnpackString(64));
}
}
else
{
_numSkinJoints = 0;
_skinJoints = new String[0];
}
// Grab morphs
List<Morph> morphs = new ArrayList<Morph>();
String morphName = Utils.TrimAt0(input.UnpackString(64));
while (!morphName.equalsIgnoreCase(MORPH_FOOTER))
{
if (input.getBytePos() + 48 >= input.Data.length) throw new IOException("Encountered end of file while parsing morphs");
Morph morph = new Morph();
morph.Name = morphName;
morph.NumVertices = input.UnpackInt();
morph.Vertices = new MorphVertex[morph.NumVertices];
for (int i = 0; i < morph.NumVertices; i++)
{
morph.Vertices[i].VertexIndex = input.UnpackUInt();
morph.Vertices[i].Coord = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
morph.Vertices[i].Normal = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
morph.Vertices[i].BiNormal = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
morph.Vertices[i].TexCoord = new Vector2(input.UnpackFloat(), input.UnpackFloat());
}
morphs.add(morph);