Пример #1
0
        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();
            }
        }
Пример #2
0
        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);
        }