private void LoadANK1FromStream(EndianBinaryReader reader, long tagStart) { LoopMode = (LoopType)reader.ReadByte(); // 0 = Play Once. 2 = Loop byte angleMultiplier = reader.ReadByte(); // Multiply Angle Value by pow(2, angleMultiplier) AnimLengthInFrames = reader.ReadInt16(); short jointEntryCount = reader.ReadInt16(); short numScaleFloatEntries = reader.ReadInt16(); short numRotationShortEntries = reader.ReadInt16(); short numTranslateFloatEntries = reader.ReadInt16(); int jointDataOffset = reader.ReadInt32(); int scaleDataOffset = reader.ReadInt32(); int rotationDataOffset = reader.ReadInt32(); int translateDataOffset = reader.ReadInt32(); // Read array of scale data float[] scaleData = new float[numScaleFloatEntries]; reader.BaseStream.Position = tagStart + scaleDataOffset; for (int j = 0; j < numScaleFloatEntries; j++) { scaleData[j] = reader.ReadSingle(); } // Read array of rotation data (but don't convert it) float[] rotationData = new float[numRotationShortEntries]; reader.BaseStream.Position = tagStart + rotationDataOffset; for (int j = 0; j < numRotationShortEntries; j++) { rotationData[j] = reader.ReadInt16(); } // Read array of translation/position data float[] translationData = new float[numTranslateFloatEntries]; reader.BaseStream.Position = tagStart + translateDataOffset; for (int j = 0; j < numTranslateFloatEntries; j++) { translationData[j] = reader.ReadSingle(); } // Read the data for each joint that this animation. m_animationData = new List <JointAnim>(); float rotScale = (float)Math.Pow(2f, angleMultiplier) * (180 / 32768f); reader.BaseStream.Position = tagStart + jointDataOffset; for (int j = 0; j < jointEntryCount; j++) { AnimatedJoint animatedJoint = ReadAnimJoint(reader); JointAnim joint = new JointAnim(); joint.ScalesX = ReadComp(scaleData, animatedJoint.X.Scale); joint.ScalesY = ReadComp(scaleData, animatedJoint.Y.Scale); joint.ScalesZ = ReadComp(scaleData, animatedJoint.Z.Scale); joint.RotationsX = ReadComp(rotationData, animatedJoint.X.Rotation); joint.RotationsY = ReadComp(rotationData, animatedJoint.Y.Rotation); joint.RotationsZ = ReadComp(rotationData, animatedJoint.Z.Rotation); // Convert all of the rotations from compressed shorts back into -180, 180 ConvertRotation(joint.RotationsX, rotScale); ConvertRotation(joint.RotationsY, rotScale); ConvertRotation(joint.RotationsZ, rotScale); joint.TranslationsX = ReadComp(translationData, animatedJoint.X.Translation); joint.TranslationsY = ReadComp(translationData, animatedJoint.Y.Translation); joint.TranslationsZ = ReadComp(translationData, animatedJoint.Z.Translation); m_animationData.Add(joint); } }
JointAnim anim; // The animation which controls the joint public Joint(JointAnim anim) { this.anim = anim; }