public static void SaveAnimation(string FileName, Animation anim, STSkeleton skeleton) { anim.SetFrame(anim.FrameCount - 1); //from last frame for (int f = 0; f < anim.FrameCount; ++f) //go through each frame with nextFrame { anim.NextFrame(skeleton); } anim.NextFrame(skeleton); //go on first frame SEAnim seAnim = new SEAnim(); seAnim.Looping = anim.CanLoop; seAnim.AnimType = AnimationType.Absolute; //Reset active animation to 0 anim.SetFrame(0); for (int frame = 0; frame < anim.FrameCount; frame++) { anim.NextFrame(skeleton, false, true); foreach (Animation.KeyNode boneAnim in anim.Bones) { if (boneAnim.HasKeyedFrames(frame)) { STBone bone = skeleton.GetBone(boneAnim.Text); if (bone == null) { continue; } Vector3 position = bone.GetPosition(); Quaternion rotation = bone.GetRotation(); Vector3 scale = bone.GetScale(); seAnim.AddTranslationKey(boneAnim.Text, frame, position.X, position.Y, position.Z); seAnim.AddRotationKey(boneAnim.Text, frame, rotation.X, rotation.Y, rotation.Z, rotation.W); seAnim.AddScaleKey(boneAnim.Text, frame, scale.X, scale.Y, scale.Z); } } } seAnim.Write(FileName); }
/// <summary> /// /// </summary> /// <param name="FileName"></param> /// <param name="animation"></param> /// <param name="skeleton"></param> public void ExportSBAnimation(string FileName, SBAnimation animation, SBSkeleton skeleton) { SEAnim seOut = new SEAnim(); //init new SEAnim foreach (var node in animation.TransformNodes) //iterate through each node { for (int i = 0; i < animation.FrameCount; i++) { SBBone temp = new SBBone(); temp.Transform = node.GetTransformAt(i, skeleton); seOut.AddTranslationKey(node.Name, i, temp.X, temp.Y, temp.Z); seOut.AddRotationKey(node.Name, i, temp.RotationQuaternion.X, temp.RotationQuaternion.Y, temp.RotationQuaternion.Z, temp.RotationQuaternion.W); seOut.AddScaleKey(node.Name, i, temp.SX, temp.SY, temp.SZ); } } seOut.Write(FileName); //write it! }
public static void ExportIOAnimation(string FileName, IOAnimation animData) { SEAnim seOut = new SEAnim(); //init new SEAnim foreach (IOAnimNode node in animData.Nodes) //iterate through each node { for (int i = 0; i < animData.FrameCount; i++) { OpenTK.Vector3 pos = node.GetPosition(i, OpenTK.Vector3.Zero); OpenTK.Quaternion rot = node.GetQuaternionRotation(i, new OpenTK.Quaternion(0, 0, 0, 0)); OpenTK.Vector3 sca = node.GetScaling(i, OpenTK.Vector3.Zero); seOut.AddTranslationKey(node.Name, i, pos.X, pos.Y, pos.Z); seOut.AddRotationKey(node.Name, i, rot.X, rot.Y, rot.Z, rot.W); seOut.AddScaleKey(node.Name, i, sca.X, sca.Y, sca.Z); } } seOut.Write(FileName); //write it! }
public static void SaveAnimation(string FileName, Animation anim, STSkeleton skeleton) { SEAnim seAnim = new SEAnim(); //Reset active animation to 0 anim.SetFrame(0); for (int frame = 0; frame < anim.FrameCount; frame++) { anim.NextFrame(skeleton); //Reset it when it reaches the total frame count if (anim.Frame >= anim.FrameCount) { anim.Frame = 0; } foreach (Animation.KeyNode boneAnim in anim.Bones) { STBone bone = skeleton.GetBone(boneAnim.Text); if (bone == null) { continue; } Vector3 position = bone.GetPosition(); Quaternion rotation = bone.GetRotation(); Vector3 scale = bone.GetScale(); seAnim.AddTranslationKey(boneAnim.Text, frame, position.X, position.Y, position.Z); seAnim.AddRotationKey(boneAnim.Text, frame, rotation.X, rotation.Y, rotation.Z, rotation.W); seAnim.AddScaleKey(boneAnim.Text, frame, scale.X, scale.Y, scale.Z); } //Add frames to the playing animation anim.Frame += 1f; } seAnim.Write(FileName); }
public static void Save(STSkeletonAnimation anim, string FileName) { STSkeleton skeleton = anim.GetActiveSkeleton(); SEAnim seAnim = new SEAnim(); seAnim.Looping = anim.Loop; seAnim.AnimType = AnimationType.Absolute; anim.SetFrame(0); for (int frame = 0; frame < anim.FrameCount; frame++) { anim.SetFrame(frame); anim.NextFrame(); foreach (STAnimGroup boneAnim in anim.AnimGroups) { if (boneAnim.GetTracks().Any(x => x.HasKeys)) { STBone bone = skeleton.GetBone(boneAnim.Name); if (bone == null) { continue; } Vector3 position = bone.GetPosition(); Quaternion rotation = bone.GetRotation(); Vector3 scale = bone.GetScale(); seAnim.AddTranslationKey(boneAnim.Name, frame, position.X, position.Y, position.Z); seAnim.AddRotationKey(boneAnim.Name, frame, rotation.X, rotation.Y, rotation.Z, rotation.W); seAnim.AddScaleKey(boneAnim.Name, frame, scale.X, scale.Y, scale.Z); } } } seAnim.Write(FileName); }
public void ExportSBAnimation(string FileName, SBAnimation animation, SBSkeleton skeleton) { SEAnim seOut = new SEAnim(); //init new SEAnim foreach (var node in animation.TransformNodes) //iterate through each node { for (int i = 0; i < animation.FrameCount; i++) { SBBone temp = new SBBone(); temp.Transform = node.Transform.GetValue(i); OpenTK.Vector3 pos = temp.Translation; OpenTK.Quaternion rot = temp.RotationQuaternion; OpenTK.Vector3 sca = temp.Scale; seOut.AddTranslationKey(node.Name, i, pos.X, pos.Y, pos.Z); seOut.AddRotationKey(node.Name, i, rot.X, rot.Y, rot.Z, rot.W); seOut.AddScaleKey(node.Name, i, sca.X, sca.Y, sca.Z); } } seOut.Write(FileName); //write it! }
public static void SaveAnimation(string FileName, Animation anim, STSkeleton skeleton) { anim.SetFrame(anim.FrameCount - 1); //from last frame for (int f = 0; f < anim.FrameCount; ++f) //go through each frame with nextFrame { anim.NextFrame(skeleton); } anim.NextFrame(skeleton); //go on first frame foreach (STBone b in skeleton.getBoneTreeOrder()) { if (anim.HasBone(b.Text)) { Animation.KeyNode n = anim.GetBone(b.Text); if (n.XPOS.HasAnimation()) { WriteKey(n.XPOS); } if (n.YPOS.HasAnimation()) { WriteKey(n.YPOS); } if (n.ZPOS.HasAnimation()) { WriteKey(n.ZPOS); } if (n.XROT.HasAnimation()) { WriteKey(n.XROT); } if (n.YROT.HasAnimation()) { WriteKey(n.YROT); } if (n.ZROT.HasAnimation()) { WriteKey(n.ZROT); } if (n.XSCA.HasAnimation()) { WriteKey(n.XSCA); } if (n.YSCA.HasAnimation()) { WriteKey(n.YSCA); } if (n.ZSCA.HasAnimation()) { WriteKey(n.ZSCA); } } } SEAnim seAnim = new SEAnim(); seAnim.Looping = anim.CanLoop; seAnim.AnimType = AnimationType.Absolute; //Reset active animation to 0 anim.SetFrame(0); for (int frame = 0; frame < anim.FrameCount; frame++) { anim.NextFrame(skeleton, false, true); foreach (Animation.KeyNode boneAnim in anim.Bones) { if (boneAnim.HasKeyedFrames(frame)) { STBone bone = skeleton.GetBone(boneAnim.Text); if (bone == null) { continue; } Vector3 position = bone.GetPosition(); Quaternion rotation = bone.GetRotation(); Vector3 scale = bone.GetScale(); //Exporting at specific keys doesn't work atm //Todo bool IsTranlationKeyed = (boneAnim.XPOS.GetKeyFrame(frame).IsKeyed || boneAnim.YPOS.GetKeyFrame(frame).IsKeyed || boneAnim.ZPOS.GetKeyFrame(frame).IsKeyed); bool IsRotationKeyed = (boneAnim.XROT.GetKeyFrame(frame).IsKeyed || boneAnim.YROT.GetKeyFrame(frame).IsKeyed || boneAnim.ZROT.GetKeyFrame(frame).IsKeyed); bool IsScaleKeyed = (boneAnim.XSCA.GetKeyFrame(frame).IsKeyed || boneAnim.YSCA.GetKeyFrame(frame).IsKeyed || boneAnim.ZSCA.GetKeyFrame(frame).IsKeyed); seAnim.AddTranslationKey(boneAnim.Text, frame, position.X, position.Y, position.Z); seAnim.AddRotationKey(boneAnim.Text, frame, rotation.X, rotation.Y, rotation.Z, rotation.W); seAnim.AddScaleKey(boneAnim.Text, frame, scale.X, scale.Y, scale.Z); } } } seAnim.Write(FileName); }
static void Main(string[] args) { // SELib Unit Test Console.Title = "SELib Unit Tests"; Console.WriteLine("SELib Unit Tests\n"); Console.WriteLine("- SEAnims\n"); #region SEAnim { // Log Console.Write("-- Test 1 "); // Make it var anim = new SEAnim(); // Add some keys anim.AddTranslationKey("shoulder", 0, 0, 0, 0); anim.AddTranslationKey("shoulder", 5, 1, 1, 1); anim.AddTranslationKey("shoulder", 10, 10, 10, 10); anim.AddTranslationKey("shoulder", 30, 20, 20, 20); anim.AddTranslationKey("shoulder", 40, 30, 30, 30); // Save it anim.Write("test1.seanim"); // Done Console.WriteLine("DONE!"); } { // Log Console.Write("-- Test 2 "); // Make it var anim = new SEAnim(); // Add some keys anim.AddTranslationKey("shoulder", 0, 0, 0, 0); anim.AddTranslationKey("shoulder", 5, 1, 1, 1); anim.AddTranslationKey("shoulder", 10, 10, 10, 10); anim.AddTranslationKey("shoulder", 30, 20, 20, 20); anim.AddTranslationKey("shoulder", 40, 30, 30, 30); // Add some scale anim.AddScaleKey("shoulder", 0, 1, 1, 1); anim.AddScaleKey("shoulder", 50, 3, 3, 3); // Save it anim.Write("test2.seanim"); // Done Console.WriteLine("DONE!"); } { // Log Console.Write("-- Test 3 "); // Make it var anim = new SEAnim(); // Add some keys anim.AddTranslationKey("shoulder", 0, 0, 0, 0); anim.AddTranslationKey("shoulder", 5, 1, 1, 1); anim.AddTranslationKey("shoulder", 10, 10, 10, 10); anim.AddTranslationKey("shoulder", 30, 20, 20, 20); anim.AddTranslationKey("shoulder", 40, 30, 30, 30); // Add some scale anim.AddScaleKey("shoulder", 0, 1, 1, 1); anim.AddScaleKey("shoulder", 50, 3, 3, 3); // Add some note anim.AddNoteTrack("hello_world", 3); anim.AddNoteTrack("bye", 50); // Save it anim.Write("test3.seanim"); // Done Console.WriteLine("DONE!"); } { // Log Console.Write("-- Test 4 "); // Make it var anim = new SEAnim(); // Add some keys anim.AddTranslationKey("shoulder", 0, 0, 0, 0); anim.AddTranslationKey("shoulder", 5, 1, 1, 1); anim.AddTranslationKey("shoulder", 10, 10, 10, 10); anim.AddTranslationKey("shoulder", 30, 20, 20, 20); anim.AddTranslationKey("shoulder", 40, 30, 30, 30); // Add some scale anim.AddScaleKey("shoulder", 0, 1, 1, 1); anim.AddScaleKey("shoulder", 50, 3, 3, 3); // Add some note anim.AddNoteTrack("hello_world", 3); anim.AddNoteTrack("bye", 50); // Save it (Really, we don't need doubles!!) anim.Write("test4.seanim", true); // Done Console.WriteLine("DONE!"); } { // Log Console.Write("-- Test 5 "); // Make it var anim = new SEAnim(); // Add some keys anim.AddTranslationKey("shoulder", 0, 0, 0, 0); anim.AddTranslationKey("shoulder", 5, 1, 1, 1); anim.AddTranslationKey("shoulder", 10, 10, 10, 10); anim.AddTranslationKey("shoulder", 30, 20, 20, 20); anim.AddTranslationKey("shoulder", 40, 30, 30, 30); // Add some scale anim.AddScaleKey("shoulder", 0, 1, 1, 1); anim.AddScaleKey("shoulder", 50, 3, 3, 3); // Add some rot anim.AddRotationKey("shoulder", 0, 0, 0, 0, 1); anim.AddRotationKey("shoulder", 50, 0.3, 0.2, 0.5, 1); // Random quat for test // Add some note anim.AddNoteTrack("hello_world", 3); anim.AddNoteTrack("bye", 50); // Save it anim.Write("test5.seanim"); // Done Console.WriteLine("DONE!"); } { // Log Console.Write("-- Test 6 "); // Read from test 5 var anim = SEAnim.Read("test5.seanim"); // Check data System.Diagnostics.Debug.Assert(anim.AnimationNotetracks.Count == 2); System.Diagnostics.Debug.Assert(anim.AnimationPositionKeys.Count == 1); System.Diagnostics.Debug.Assert(anim.AnimationRotationKeys.Count == 1); System.Diagnostics.Debug.Assert(anim.AnimationScaleKeys.Count == 1); System.Diagnostics.Debug.Assert(anim.BoneCount == 1); System.Diagnostics.Debug.Assert(anim.FrameCount == 51); System.Diagnostics.Debug.Assert(anim.FrameRate == 30.0); // Version System.Diagnostics.Debug.Assert(anim.APIVersion == "v1.0.1"); // Check functions System.Diagnostics.Debug.Assert(anim.RenameBone("shoulder", "shoulder") == false); System.Diagnostics.Debug.Assert(anim.RenameBone("shoulder", "new_shoulder") == true); // Done Console.WriteLine("DONE!"); } #endregion Console.WriteLine("\n- SEModels\n"); #region SEModel { // Log Console.Write("-- Test 1 "); // Make it var model = new SEModel(); // Add some bones model.AddBone("bone_0001", -1, Vector3.Zero, Quaternion.Identity, Vector3.Zero, Quaternion.Identity, Vector3.One); model.AddBone("bone_0002", 0, Vector3.Zero, Quaternion.Identity, Vector3.Zero, Quaternion.Identity, Vector3.One); model.AddBone("bone_0003", 0, Vector3.Zero, Quaternion.Identity, Vector3.Zero, Quaternion.Identity, Vector3.One); model.AddBone("bone_0004", 2, Vector3.Zero, Quaternion.Identity, new Vector3(22, 22, 22), Quaternion.Identity, Vector3.One); // Save it model.Write("test1.semodel"); // Done Console.WriteLine("DONE!"); } { // Log Console.Write("-- Test 2 "); // Make it var model = new SEModel(); // Allow globals too model.ModelBoneSupport = ModelBoneSupportTypes.SupportsBoth; // Add some bones model.AddBone("bone_0001", -1, Vector3.Zero, Quaternion.Identity, Vector3.Zero, Quaternion.Identity, Vector3.One); model.AddBone("bone_0002", 0, Vector3.Zero, Quaternion.Identity, Vector3.Zero, Quaternion.Identity, Vector3.One); model.AddBone("bone_0003", 0, Vector3.Zero, Quaternion.Identity, Vector3.Zero, Quaternion.Identity, Vector3.One); model.AddBone("bone_0004", 2, Vector3.Zero, Quaternion.Identity, new Vector3(22, 22, 22), Quaternion.Identity, Vector3.One); // Save it model.Write("test2.semodel"); // Done Console.WriteLine("DONE!"); } #endregion // Pause Console.Write("\nPress any key to continue..."); Console.ReadKey(); }