VeAnimation.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #region License information
  2. // ----------------------------------------------------------------------------
  3. //
  4. // libeq2 - A library for analyzing the Everquest II File Format
  5. // Blaz (blaz@blazlabs.com)
  6. //
  7. // This program is free software; you can redistribute it and/or
  8. // modify it under the terms of the GNU General Public License
  9. // as published by the Free Software Foundation; either version 2
  10. // of the License, or (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License
  18. // along with this program; if not, write to the Free Software
  19. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  20. //
  21. // ( The full text of the license can be found in the License.txt file )
  22. //
  23. // ----------------------------------------------------------------------------
  24. #endregion
  25. #region Using directives
  26. using System;
  27. using System.IO;
  28. using System.Diagnostics;
  29. using Everquest2.Util;
  30. #endregion
  31. namespace Everquest2.Visualization
  32. {
  33. public class VeAnimation : VeBase
  34. {
  35. public struct TrackInfo<T>
  36. {
  37. public T Translation;
  38. public T Rotation;
  39. public T Scaling;
  40. }
  41. public VeAnimation()
  42. {
  43. }
  44. /// <summary>
  45. /// Special constructor used when deserializing the instance of the class.
  46. /// </summary>
  47. /// <param name="reader">Reader used to read the instance data.</param>
  48. protected VeAnimation(Util.Eq2Reader reader, Util.StreamingContext context) : base(reader, context)
  49. {
  50. byte classVersion = context.ClassVersions[typeof(VeAnimation)];
  51. Debug.Assert(classVersion >= 2 && classVersion <= 4, "VeAnimation class version " + classVersion + " not supported");
  52. uint trackCount = reader.ReadUInt32();
  53. boneNames = new string[trackCount];
  54. curveDegrees = new TrackInfo<uint>[trackCount];
  55. curveKnots = new TrackInfo<float[]>[trackCount];
  56. curveKeys = new TrackInfo<float[][]>[trackCount];
  57. for (uint i = 0; i < trackCount; ++i)
  58. {
  59. boneNames[i] = reader.ReadString(2);
  60. ReadTrackInfo(reader, ref curveDegrees[i].Translation, ref curveKnots[i].Translation, ref curveKeys[i].Translation);
  61. ReadTrackInfo(reader, ref curveDegrees[i].Rotation, ref curveKnots[i].Rotation, ref curveKeys[i].Rotation);
  62. ReadTrackInfo(reader, ref curveDegrees[i].Scaling, ref curveKnots[i].Scaling, ref curveKeys[i].Scaling);
  63. }
  64. length = reader.ReadSingle();
  65. if (classVersion > 2) skeletonName = reader.ReadString(2);
  66. }
  67. private void ReadTrackInfo(Util.Eq2Reader reader, ref uint degree, ref float[] knots, ref float[][] keys)
  68. {
  69. degree = reader.ReadUInt32();
  70. uint curveKnotCount = reader.ReadUInt32();
  71. knots = new float[curveKnotCount];
  72. for (uint i = 0; i < curveKnotCount; ++i) knots[i] = reader.ReadSingle();
  73. uint curveKeyCount = reader.ReadUInt32();
  74. uint componentCount = curveKeyCount / curveKnotCount;
  75. keys = new float[curveKnotCount][];
  76. for (uint i = 0; i < curveKnotCount; ++i)
  77. {
  78. keys[i] = new float[componentCount];
  79. for (uint j = 0; j < componentCount; ++j) keys[i][j] = reader.ReadSingle();
  80. }
  81. }
  82. public string[] boneNames;
  83. public TrackInfo<uint>[] curveDegrees;
  84. public TrackInfo<float[]>[] curveKnots;
  85. public TrackInfo<float[][]>[] curveKeys;
  86. public float length;
  87. public string skeletonName;
  88. }
  89. }