public static void Save(STSkeletonAnimation anim, String Fname) { System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone(); customCulture.NumberFormat.NumberDecimalSeparator = "."; STSkeleton Skeleton = anim.GetActiveSkeleton(); using (System.IO.StreamWriter file = new System.IO.StreamWriter(@Fname)) { file.WriteLine("version 1"); file.WriteLine("nodes"); foreach (STBone b in Skeleton.bones) { file.WriteLine(Skeleton.bones.IndexOf(b) + " \"" + b.Text + "\" " + b.parentIndex); } file.WriteLine("end"); file.WriteLine("skeleton"); anim.SetFrame(0); for (int i = 0; i <= anim.FrameCount; i++) { anim.SetFrame(i); anim.NextFrame(); file.WriteLine($"time {i}"); foreach (var sb in anim.AnimGroups) { STBone b = Skeleton.GetBone(sb.Name); if (b == null) { continue; } Vector3 eul = STMath.ToEulerAngles(b.rot); Vector3 scale = b.GetScale(); Vector3 translate = b.GetPosition(); file.WriteLine($"{ Skeleton.bones.IndexOf(b)} {translate.X} {translate.Y} {translate.Z} {eul.X} {eul.Y} {eul.Z}"); } } file.WriteLine("end"); file.Close(); } }
public static void Save(Animation anim, STSkeleton Skeleton, String Fname) { System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; using (System.IO.StreamWriter file = new System.IO.StreamWriter(@Fname)) { file.WriteLine("version 1"); file.WriteLine("nodes"); foreach (STBone b in Skeleton.bones) { file.WriteLine(Skeleton.bones.IndexOf(b) + " \"" + b.Text + "\" " + b.parentIndex); } file.WriteLine("end"); file.WriteLine("skeleton"); anim.SetFrame(0); for (int i = 0; i <= anim.FrameCount; i++) { anim.NextFrame(Skeleton, false, true); file.WriteLine($"time {i}"); foreach (Animation.KeyNode sb in anim.Bones) { STBone b = Skeleton.GetBone(sb.Text); if (b == null) { continue; } Vector3 eul = STMath.ToEulerAngles(b.rot); Vector3 scale = b.GetScale(); Vector3 translate = b.GetPosition(); file.WriteLine($"{ Skeleton.bones.IndexOf(b)} {translate.X} {translate.Y} {translate.Z} {eul.X} {eul.Y} {eul.Z}"); } } file.WriteLine("end"); file.Close(); } }
public static Animation Read(string FileName, STSkeleton skeleton) { Animation anim = new Animation(); var seanim = SEAnim.Read(FileName); anim.FrameCount = seanim.FrameCount; anim.CanLoop = seanim.Looping; foreach (var bone in seanim.Bones) { STBone genericBone = skeleton.GetBone(bone); if (genericBone != null) { var boneAnim = new Animation.KeyNode(bone); boneAnim.RotType = Animation.RotationType.EULER; boneAnim.UseSegmentScaleCompensate = false; anim.Bones.Add(boneAnim); float PositionX = 0; float PositionY = 0; float PositionZ = 0; float RotationX = 0; float RotationY = 0; float RotationZ = 0; float ScaleX = 0; float ScaleY = 0; float ScaleZ = 0; if (seanim.AnimType == AnimationType.Relative) { PositionX = genericBone.position[0]; PositionY = genericBone.position[1]; PositionZ = genericBone.position[2]; RotationX = genericBone.rotation[0]; RotationY = genericBone.rotation[1]; RotationZ = genericBone.rotation[2]; ScaleX = genericBone.scale[0]; ScaleY = genericBone.scale[1]; ScaleZ = genericBone.scale[2]; } System.Console.WriteLine(bone); if (seanim.AnimationPositionKeys.ContainsKey(bone)) { var translationKeys = seanim.AnimationPositionKeys[bone]; foreach (SEAnimFrame animFrame in translationKeys) { System.Console.WriteLine(animFrame.Frame + " T " + ((SELib.Utilities.Vector3)animFrame.Data).X); System.Console.WriteLine(animFrame.Frame + " T " + ((SELib.Utilities.Vector3)animFrame.Data).Y); System.Console.WriteLine(animFrame.Frame + " T " + ((SELib.Utilities.Vector3)animFrame.Data).Z); boneAnim.XPOS.Keys.Add(new Animation.KeyFrame() { Value = (float)((SELib.Utilities.Vector3)animFrame.Data).X + PositionX, Frame = animFrame.Frame, }); boneAnim.YPOS.Keys.Add(new Animation.KeyFrame() { Value = (float)((SELib.Utilities.Vector3)animFrame.Data).Y + PositionY, Frame = animFrame.Frame, }); boneAnim.ZPOS.Keys.Add(new Animation.KeyFrame() { Value = (float)((SELib.Utilities.Vector3)animFrame.Data).Z + PositionZ, Frame = animFrame.Frame, }); } } if (seanim.AnimationRotationKeys.ContainsKey(bone)) { var rotationnKeys = seanim.AnimationRotationKeys[bone]; foreach (SEAnimFrame animFrame in rotationnKeys) { var quat = ((SELib.Utilities.Quaternion)animFrame.Data); var euler = STMath.ToEulerAngles(quat.X, quat.Y, quat.Z, quat.W); System.Console.WriteLine(animFrame.Frame + " R " + euler.X); System.Console.WriteLine(animFrame.Frame + " R " + euler.Y); System.Console.WriteLine(animFrame.Frame + " R " + euler.Z); boneAnim.XROT.Keys.Add(new Animation.KeyFrame() { Value = euler.X + RotationX, Frame = animFrame.Frame, }); boneAnim.YROT.Keys.Add(new Animation.KeyFrame() { Value = euler.Y + RotationY, Frame = animFrame.Frame, }); boneAnim.ZROT.Keys.Add(new Animation.KeyFrame() { Value = euler.Z + RotationZ, Frame = animFrame.Frame, }); } } if (seanim.AnimationScaleKeys.ContainsKey(bone)) { var scaleKeys = seanim.AnimationScaleKeys[bone]; foreach (SEAnimFrame animFrame in scaleKeys) { System.Console.WriteLine(animFrame.Frame + " S " + ((SELib.Utilities.Vector3)animFrame.Data).X); System.Console.WriteLine(animFrame.Frame + " S " + ((SELib.Utilities.Vector3)animFrame.Data).Y); System.Console.WriteLine(animFrame.Frame + " S " + ((SELib.Utilities.Vector3)animFrame.Data).Z); boneAnim.XSCA.Keys.Add(new Animation.KeyFrame() { Value = (float)((SELib.Utilities.Vector3)animFrame.Data).X + ScaleX, Frame = animFrame.Frame, }); boneAnim.YSCA.Keys.Add(new Animation.KeyFrame() { Value = (float)((SELib.Utilities.Vector3)animFrame.Data).Y + ScaleY, Frame = animFrame.Frame, }); boneAnim.ZSCA.Keys.Add(new Animation.KeyFrame() { Value = (float)((SELib.Utilities.Vector3)animFrame.Data).Z + ScaleZ, Frame = animFrame.Frame, }); } } else { boneAnim.XSCA.Keys.Add(new Animation.KeyFrame() { Value = 1, Frame = 0, }); boneAnim.YSCA.Keys.Add(new Animation.KeyFrame() { Value = 1, Frame = 0, }); boneAnim.ZSCA.Keys.Add(new Animation.KeyFrame() { Value = 1, Frame = 0, }); } } } return(anim); }