public binBVHJoint readJoint(byte[] data, ref int i)
{
binBVHJointKey[] positions;
binBVHJointKey[] rotations;
binBVHJoint pJoint = new binBVHJoint();
/*
109
84
111
114
114
111
0 <--- Null terminator
*/
pJoint.Name = ReadBytesUntilNull(data, ref i); // Joint name
/*
2 <- Priority Revisited
0
0
0
*/
/*
5 <-- 5 keyframes
0
0
0
... 5 Keyframe data blocks
*/
/*
2 <-- 2 keyframes
0
0
0
.. 2 Keyframe data blocks
*/
if (!BitConverter.IsLittleEndian)
{
pJoint.Priority = Utils.BytesToInt(EndianSwap(data, i, 4)); i += 4; // Joint Priority override?
rotationkeys = Utils.BytesToInt(EndianSwap(data, i, 4)); i += 4; // How many rotation keyframes
}
else
{
pJoint.Priority = Utils.BytesToInt(data, i); i += 4; // Joint Priority override?
rotationkeys = Utils.BytesToInt(data, i); i += 4; // How many rotation keyframes
}
// Sanity check how many rotation keys there are
if (rotationkeys < 0 || rotationkeys > 10000)
{
rotationkeys = 0;
}
rotations = readKeys(data, ref i, rotationkeys, -1.0f, 1.0f);
if (!BitConverter.IsLittleEndian)
{
positionkeys = Utils.BytesToInt(EndianSwap(data, i, 4)); i += 4; // How many position keyframes
}
else
{
positionkeys = Utils.BytesToInt(data, i); i += 4; // How many position keyframes
}
// Sanity check how many positions keys there are
if (positionkeys < 0 || positionkeys > 10000)
{
positionkeys = 0;
}
// Read in position keyframes
positions = readKeys(data, ref i, positionkeys, -0.5f, 1.5f);
pJoint.rotationkeys = rotations;
pJoint.positionkeys = positions;
return pJoint;
}