/// <summary> /// Reads a *.anim file into this Anim instance. /// </summary> /// <param name="FileData">The filedata for the *.anim file.</param> public Anim(byte[] FileData) { MemoryStream MemStream = new MemoryStream(FileData); BinaryReader Reader = new BinaryReader(MemStream); m_Version = Endian.SwapUInt32(Reader.ReadUInt32()); m_Name = Encoding.ASCII.GetString(Reader.ReadBytes(Endian.SwapInt16(Reader.ReadInt16()))); m_Duration = Reader.ReadSingle() / 1000; //Why does this have to be divided by 1000? o_O m_Distance = Reader.ReadSingle(); m_IsMoving = Reader.ReadByte(); m_NumTranslations = Endian.SwapUInt32(Reader.ReadUInt32()); m_TranslationsTableOffset = Reader.BaseStream.Position; Reader.BaseStream.Seek(m_TranslationsTableOffset + 12 * m_NumTranslations, SeekOrigin.Begin); m_NumRotations = Endian.SwapUInt32(Reader.ReadUInt32()); m_RotationsTableOffset = Reader.BaseStream.Position; Reader.BaseStream.Seek(m_RotationsTableOffset + 16 * m_NumRotations, SeekOrigin.Begin); m_MotionCount = Endian.SwapUInt32(Reader.ReadUInt32()); for (int i = 0; i < m_MotionCount; i++) { m_Motions.Add(ReadMotion(Reader)); } }
public Binding(byte[] FileData) { MemoryStream MemStream = new MemoryStream(FileData); BinaryReader Reader = new BinaryReader(MemStream); m_Version = Endian.SwapUInt32(Reader.ReadUInt32()); byte StrLength = Reader.ReadByte(); string m_BoneName = Encoding.ASCII.GetString(Reader.ReadBytes(StrLength)); //Should be 8. uint MeshAssetIDSize = Endian.SwapUInt32(Reader.ReadUInt32()); //AssetID prefix, typical useless Maxis value... Reader.ReadUInt32(); m_MeshAssetID = Endian.SwapUInt64(Reader.ReadUInt64()); //Should be 8. uint TextureAssetIDSize = Endian.SwapUInt32(Reader.ReadUInt32()); //AssetID prefix, typical useless Maxis value... Reader.ReadUInt32(); m_TextureAssetID = Endian.SwapUInt64(Reader.ReadUInt64()); }
/// <summary> /// Reads all the property lists in a motion. /// </summary> /// <param name="Mot">The motion that the propertylists belong to.</param> /// <param name="Reader">The BinaryReader instance used to read the *.anim file.</param> private void ReadPropertyLists(ref Motion Mot, ref BinaryReader Reader) { uint Count = Endian.SwapUInt32(Reader.ReadUInt32()); for (int i = 0; i < Count; i++) { Mot.PropertyLists.Add(ReadPropList(Reader)); } }
public Binding(string Path) { BinaryReader Reader = new BinaryReader(File.Open(Path, FileMode.Open)); m_Version = Endian.SwapUInt32(Reader.ReadUInt32()); byte StrLength = Reader.ReadByte(); string m_BoneName = Encoding.ASCII.GetString(Reader.ReadBytes(StrLength)); }
public Appearance(byte[] FileData) { MemoryStream MemStream = new MemoryStream(FileData); BinaryReader Reader = new BinaryReader(MemStream); m_Version = Endian.SwapUInt32(Reader.ReadUInt32()); m_ThumbnailID = Endian.SwapUInt64(Reader.ReadUInt64()); uint Count = Endian.SwapUInt32(Reader.ReadUInt32()); for (int i = 0; i < Count; i++) { BindingIDs.Add(Endian.SwapUInt64(Reader.ReadUInt64())); } }
public Outfit(byte[] FileData) { MemoryStream MemStream = new MemoryStream(FileData); BinaryReader Reader = new BinaryReader(MemStream); m_Version = Endian.SwapUInt32(Reader.ReadUInt32()); Reader.ReadUInt32(); //Unknown. m_LightAppearanceID = Endian.SwapUInt64(Reader.ReadUInt64()); m_MediumAppearanceID = Endian.SwapUInt64(Reader.ReadUInt64()); m_DarkAppearanceID = Endian.SwapUInt64(Reader.ReadUInt64()); Reader.Close(); }
public PurchasableObject(byte[] FileData) { MemoryStream MemStream = new MemoryStream(FileData); BinaryReader Reader = new BinaryReader(MemStream); m_Version = Endian.SwapUInt32(Reader.ReadUInt32()); m_Gender = Endian.SwapUInt32(Reader.ReadUInt32()); m_AssetType = Endian.SwapUInt32(Reader.ReadUInt32()); Reader.ReadUInt32(); //GroupID m_OutfitAssetID = Convert.ToUInt64(Endian.SwapUInt64(Reader.ReadUInt64())); Reader.Close(); }
/// <summary> /// Reads all the timeproperty lists in a motion. /// </summary> /// <param name="Mot">The motion that the timeproperty lists belong to.</param> /// <param name="Reader">The BinaryReader instance used to read the *.anim file.</param> private void ReadTimePropertyLists(ref Motion Mot, ref BinaryReader Reader) { uint Count = Endian.SwapUInt32(Reader.ReadUInt32()); for (int i = 0; i < Count; i++) { TimePropertyList TList = new TimePropertyList(); TList.TimePropsCount = Endian.SwapUInt32(Reader.ReadUInt32()); for (int j = 0; j < TList.TimePropsCount; j++) { TimeProperty TProp = new TimeProperty(); TProp.TPropID = Endian.SwapUInt32(Reader.ReadUInt32()); TProp.PList = ReadPropList(Reader); } Mot.TimePropertyLists.Add(TList); } }
/// <summary> /// Reads a list of properties from the *.skel file. /// </summary> /// <param name="Reader">The BinaryReader instance used to read the *.skel file.</param> /// <returns>A PropertyList instance filled with properties.</returns> private PropertyList ReadPropList(BinaryReader Reader) { PropertyList PList = new PropertyList(); PList.PropsCount = Endian.SwapUInt32(Reader.ReadUInt32()); for (int j = 0; j < PList.PropsCount; j++) { Property Prop = new Property(); uint PairsCount = Endian.SwapUInt32(Reader.ReadUInt32()); for (int k = 0; k < PairsCount; k++) { Prop.Key = Encoding.ASCII.GetString(Reader.ReadBytes(Reader.ReadByte())); Prop.Value = Encoding.ASCII.GetString(Reader.ReadBytes(Reader.ReadByte())); } PList.PList.Add(Prop); } return(PList); }
public Skeleton(GraphicsDevice Device, byte[] Filedata, Matrix WorldMatrix) { MemoryStream MemStream = new MemoryStream(Filedata); BinaryReader Reader = new BinaryReader(MemStream); m_WorldMatrix = WorldMatrix; m_Version = Endian.SwapUInt32(Reader.ReadUInt32()); m_Name = Encoding.ASCII.GetString(Reader.ReadBytes(Reader.ReadByte())); m_BoneCount = Endian.SwapUInt16(Reader.ReadUInt16()); m_Bones = new Bone[m_BoneCount]; for (int i = 0; i < m_BoneCount; i++) { Endian.SwapUInt32(Reader.ReadUInt32()); //1 in hexadecimal... typical useless Maxis value... Bone Bne = new Bone(this); Bne.ID = i; Bne.BoneName = Encoding.ASCII.GetString(Reader.ReadBytes(Reader.ReadByte())); Log.LogThis("BoneName: " + Bne.BoneName, eloglevel.info); Bne.ParentName = Encoding.ASCII.GetString(Reader.ReadBytes(Reader.ReadByte())); Bne.HasPropertyList = Reader.ReadByte(); if (Bne.HasPropertyList == 1) { Bne.PList = ReadPropList(Reader); } //Little Endian Bne.Translations = new float[3]; Bne.Translations[0] = Reader.ReadSingle(); Bne.Translations[1] = Reader.ReadSingle(); Bne.Translations[2] = Reader.ReadSingle(); Bne.Versor = new float[4]; //These values are given in degrees... Bne.Versor[0] = MathHelper.ToRadians(Reader.ReadSingle()); Bne.Versor[1] = MathHelper.ToRadians(Reader.ReadSingle()); Bne.Versor[2] = MathHelper.ToRadians(Reader.ReadSingle()); Bne.Versor[3] = MathHelper.ToRadians(Reader.ReadSingle()); Bne.CanTranslate = Endian.SwapInt32(Reader.ReadInt32()); Bne.CanRotate = Endian.SwapInt32(Reader.ReadInt32()); Bne.CanUseBlending = Endian.SwapInt32(Reader.ReadInt32()); //Little endian. Bne.CanWiggle = Reader.ReadSingle(); Bne.WiggleAmount = Reader.ReadSingle(); Bne.BoneEffect = new BasicEffect(Device, null); Bne.Children = new int[m_BoneCount - i - 1]; int Parent = FindBone(Bne.ParentName, i); if (Parent != -1) { m_Bones[Parent].Children[m_Bones[Parent].NumChildren] = Bne.ID; m_Bones[Parent].NumChildren += 1; Bne.Parent = m_Bones[Parent]; Bne.ComputeAbsoluteTransform(m_WorldMatrix); } m_Bones[i] = Bne; /*Log.LogThis("Bone: " + Bne.BoneName, eloglevel.info); * if (Parent != -1) * { * Log.LogThis("Parent: " + Bne.Parent.BoneName, eloglevel.info); * * for (int j = 0; j < Bne.Parent.NumChildren; j++) * Log.LogThis("Child: " + Bne.Parent.Children[j].BoneName, eloglevel.info); * } * else * Log.LogThis("Parent: NULL", eloglevel.info);*/ } Reader.Close(); }
public Skeleton(GraphicsDevice Device, string Filepath, ref Matrix WorldMatrix) { BinaryReader Reader = new BinaryReader(File.Open(Filepath, FileMode.Open)); m_WorldMatrix = WorldMatrix; m_Version = Endian.SwapUInt32(Reader.ReadUInt32()); m_Name = Encoding.ASCII.GetString(Reader.ReadBytes(Reader.ReadByte())); m_BoneCount = Endian.SwapUInt16(Reader.ReadUInt16()); m_Bones = new Bone[m_BoneCount]; for (int i = 0; i < m_BoneCount; i++) { Endian.SwapUInt32(Reader.ReadUInt32()); //1 in hexadecimal... typical useless Maxis value... Bone Bne = new Bone(this); Bne.ID = i; Bne.BoneName = Encoding.ASCII.GetString(Reader.ReadBytes(Reader.ReadByte())); Bne.ParentName = Encoding.ASCII.GetString(Reader.ReadBytes(Reader.ReadByte())); Bne.HasPropertyList = Reader.ReadByte(); if (Bne.HasPropertyList == 1) { Bne.PList = ReadPropList(Reader); } //Little Endian Bne.Translations = new float[3]; Bne.Translations[0] = Reader.ReadSingle(); Bne.Translations[1] = Reader.ReadSingle(); Bne.Translations[2] = Reader.ReadSingle(); Bne.Versor = new float[4]; //These values are given in degrees... Bne.Versor[0] = MathHelper.ToRadians(Reader.ReadSingle()); Bne.Versor[1] = MathHelper.ToRadians(Reader.ReadSingle()); Bne.Versor[2] = MathHelper.ToRadians(Reader.ReadSingle()); Bne.Versor[3] = MathHelper.ToRadians(Reader.ReadSingle()); Bne.CanTranslate = Endian.SwapInt32(Reader.ReadInt32()); Bne.CanRotate = Endian.SwapInt32(Reader.ReadInt32()); Bne.CanUseBlending = Endian.SwapInt32(Reader.ReadInt32()); //Little endian. Bne.CanWiggle = Reader.ReadSingle(); Bne.WiggleAmount = Reader.ReadSingle(); Bne.BoneEffect = new BasicEffect(Device, null); Bne.Children = new int[m_BoneCount - i - 1]; int Parent = FindBone(Bne.ParentName, i); if (Parent != -1) { m_Bones[Parent].Children[m_Bones[Parent].NumChildren] = Bne.ID; m_Bones[Parent].NumChildren += 1; Bne.Parent = m_Bones[Parent]; Bne.ComputeAbsoluteTransform(m_WorldMatrix); } m_Bones[i] = Bne; } Reader.Close(); }
/// <summary> /// Reads a motion from a *.anim file. /// </summary> /// <param name="Reader">The BinaryReader instance used to read the *.anim file.</param> /// <returns>A Motion instance.</returns> private Motion ReadMotion(BinaryReader Reader) { Motion Mot = new Motion(); Mot.Unknown = Endian.SwapUInt32(Reader.ReadUInt32()); Mot.BoneName = Encoding.ASCII.GetString(Reader.ReadBytes(Reader.ReadByte())); Mot.NumFrames = Endian.SwapUInt32(Reader.ReadUInt32()); Mot.Duration = Reader.ReadSingle() / 1000; Mot.HasTranslation = Reader.ReadByte(); Mot.HasRotation = Reader.ReadByte(); Mot.TranslationsOffset = Endian.SwapUInt32(Reader.ReadUInt32()); Mot.RotationsOffset = Endian.SwapUInt32(Reader.ReadUInt32()); if (Mot.HasTranslation != 0) { Mot.Translations = new float[Mot.NumFrames, 3]; long CurrentOffset = Reader.BaseStream.Position; Reader.BaseStream.Seek(m_TranslationsTableOffset + 12 * Mot.TranslationsOffset, SeekOrigin.Begin); for (int i = 0; i < Mot.NumFrames; i++) { Mot.Translations[i, 0] = Reader.ReadSingle(); Mot.Translations[i, 1] = Reader.ReadSingle(); Mot.Translations[i, 2] = Reader.ReadSingle(); } Reader.BaseStream.Seek(CurrentOffset, SeekOrigin.Begin); } if (Mot.HasRotation != 0) { Mot.Rotations = new float[Mot.NumFrames, 4]; long CurrentOffset = Reader.BaseStream.Position; Reader.BaseStream.Seek(m_RotationsTableOffset + 16 * Mot.RotationsOffset, SeekOrigin.Begin); for (int i = 0; i < Mot.NumFrames; i++) { Mot.Rotations[i, 0] = Reader.ReadSingle(); Mot.Rotations[i, 1] = -Reader.ReadSingle(); Mot.Rotations[i, 2] = -Reader.ReadSingle(); Mot.Rotations[i, 3] = Reader.ReadSingle(); } Reader.BaseStream.Seek(CurrentOffset, SeekOrigin.Begin); } Mot.HasPropertyLists = Reader.ReadByte(); if (Mot.HasPropertyLists != 0) { ReadPropertyLists(ref Mot, ref Reader); } Mot.HasTimePropertyLists = Reader.ReadByte(); if (Mot.HasTimePropertyLists != 0) { ReadTimePropertyLists(ref Mot, ref Reader); } return(Mot); }