/ContentSystem/Rendering/Helpers/BoneData.cs
C# | 155 lines | 77 code | 15 blank | 63 comment | 4 complexity | cc8819d836c68146b784ce3262ca4dff MD5 | raw file
Possible License(s): Apache-2.0
- using System.IO;
- using Delta.Utilities;
- using Delta.Utilities.Datatypes;
-
- namespace Delta.ContentSystem.Rendering.Helpers
- {
- /// <summary>
- /// Helper class to store one bone entry for animated 3D models,
- /// this is not directly a content class, but used for MeshData and is
- /// also important for AnimationData, which keeps all the animated matrices.
- /// </summary>
- public class BoneData : ISaveLoadBinary
- {
- #region Constants
- /// <summary>
- /// Version number for this MeshData. If this goes above 1, we need
- /// to support loading older versions as well. Saving is always going
- /// to be the latest version (this one).
- /// </summary>
- private const int CurrentVersion = 1;
- #endregion
-
- #region Id (Public)
- /// <summary>
- /// Id
- /// </summary>
- public int Id;
- #endregion
-
- #region Name (Public)
- /// <summary>
- /// Name
- /// </summary>
- public string Name;
- #endregion
-
- #region InverseTransformMatrix (Public)
- /// <summary>
- /// The inverse bone skin matrix
- /// </summary>
- public Matrix InverseTransformMatrix;
- #endregion
-
- #region ParentId (Public)
- /// <summary>
- /// Parent id
- /// </summary>
- public int ParentId;
- #endregion
-
- #region ChildrenIds (Public)
- /// <summary>
- /// Children ids
- /// </summary>
- public int[] ChildrenIds = new int[0];
- #endregion
-
- #region Constructors
- /// <summary>
- /// Create bone data
- /// </summary>
- public BoneData()
- {
- }
-
- /// <summary>
- /// Create bone data
- /// </summary>
- /// <param name="dataReader">Data reader</param>
- public BoneData(BinaryReader dataReader)
- {
- Load(dataReader);
- }
- #endregion
-
- #region ISaveLoadBinary Members
- /// <summary>
- /// Load bone data (mostly all the matrices and their relationship).
- /// </summary>
- /// <param name="reader">Reader</param>
- public void Load(BinaryReader reader)
- {
- // We currently only support our version, if more versions are added,
- // we need to do different loading code depending on the version here.
- int version = reader.ReadInt32();
- if (version != CurrentVersion)
- {
- Log.InvalidVersionWarning(GetType().Name + ": " + Name,
- version, CurrentVersion);
- return;
- }
-
- // Load the bone id
- Id = reader.ReadInt32();
- // the name of the bone
- Name = reader.ReadString();
- //// the initial pose
- //InitialPoseMatrix.Load(reader);
- // the inverse bone matrix
- InverseTransformMatrix.Load(reader);
-
- // before we still save the hierarchy
- // with the parent
- ParentId = reader.ReadInt32();
- // and the children
- ChildrenIds = new int[reader.ReadInt32()];
- for (int index = 0; index < ChildrenIds.Length; index++)
- {
- ChildrenIds[index] = reader.ReadInt32();
- }
- }
-
- /// <summary>
- /// Save bone date (mostly all the matrices and their relationship).
- /// </summary>
- /// <param name="dataWriter">Data writer</param>
- public void Save(BinaryWriter dataWriter)
- {
- dataWriter.Write(CurrentVersion);
-
- // Save out the bone id
- dataWriter.Write(Id);
- // the name of the bone
- dataWriter.Write(Name);
- //// the initial pose
- //InitialPoseMatrix.Save(dataWriter);
- // the inverse bone matrix
- InverseTransformMatrix.Save(dataWriter);
-
- // before we still save the hierarchy
- // with the parent
- dataWriter.Write(ParentId);
- // and the children
- dataWriter.Write(ChildrenIds.Length);
- for (int index = 0; index < ChildrenIds.Length; index++)
- {
- dataWriter.Write(ChildrenIds[index]);
- }
- }
- #endregion
-
- #region ToString (Public)
- /// <summary>
- /// To string
- /// </summary>
- public override string ToString()
- {
- return GetType().Name + ": Name='" + Name +
- //"', FinalPosition='" + FinalTransform.Translation +
- //"', AnimationFrames='" + AnimationMatrices.Length +
- "'";
- }
- #endregion
- }
- }