Пример #1
0
        protected virtual SpriterSpatial Interpolate(SpriterSpatial a, SpriterSpatial b, float f, int spin)
        {
            SpriterSpatial ss = Pool.GetObject <SpriterSpatial>();

            ss.Interpolate(a, b, f, spin);
            return(ss);
        }
Пример #2
0
        protected virtual SpriterSpatial[] GetBoneInfos(SpriterMainlineKey key, SpriterAnimation animation, float targetTime, SpriterSpatial parentInfo = null)
        {
            if (key.BoneRefs == null)
            {
                return(null);
            }
            SpriterSpatial[] ret = Pool.GetArray <SpriterSpatial>(key.BoneRefs.Length);

            for (int i = 0; i < key.BoneRefs.Length; ++i)
            {
                SpriterRef     boneRef      = key.BoneRefs[i];
                SpriterSpatial interpolated = GetBoneInfo(boneRef, animation, targetTime);

                if (boneRef.ParentId >= 0)
                {
                    interpolated.ApplyParentTransform(ret[boneRef.ParentId]);
                }
                else if (parentInfo != null)
                {
                    interpolated.ApplyParentTransform(parentInfo);
                }
                ret[i] = interpolated;
            }

            return(ret);
        }
        private static SpriterSpatial Copy(SpriterSpatial info)
        {
            SpriterSpatial copy = new SpriterSpatial();

            FillFrom(copy, info);
            return(copy);
        }
        private static SpriterSpatial[] GetBoneInfos(SpriterMainlineKey key, SpriterAnimation animation, float targetTime, SpriterSpatial parentInfo = null)
        {
            if (key.BoneRefs == null)
            {
                return(null);
            }
            SpriterSpatial[] ret = new SpriterSpatial[key.BoneRefs.Length];

            for (int i = 0; i < key.BoneRefs.Length; ++i)
            {
                SpriterRef     boneRef      = key.BoneRefs[i];
                SpriterSpatial interpolated = GetBoneInfo(boneRef, animation, targetTime);

                if (boneRef.ParentId >= 0)
                {
                    ApplyParentTransform(interpolated, ret[boneRef.ParentId]);
                }
                else if (parentInfo != null)
                {
                    ApplyParentTransform(interpolated, parentInfo);
                }
                ret[i] = interpolated;
            }

            return(ret);
        }
        private static SpriterSpatial Copy(SpriterSpatial info)
        {
            SpriterSpatial copy = SpriterObjectPool.GetObject <SpriterSpatial>();

            FillFrom(copy, info);
            return(copy);
        }
Пример #6
0
        protected virtual SpriterSpatial Copy(SpriterSpatial info)
        {
            SpriterSpatial copy = Pool.GetObject <SpriterSpatial>();

            copy.FillFrom(info);
            return(copy);
        }
 private static void FillFrom(SpriterSpatial target, SpriterSpatial source)
 {
     target.Alpha  = source.Alpha;
     target.Angle  = source.Angle;
     target.ScaleX = source.ScaleX;
     target.ScaleY = source.ScaleY;
     target.X      = source.X;
     target.Y      = source.Y;
 }
 private static SpriterSpatial Interpolate(SpriterSpatial a, SpriterSpatial b, float f, int spin)
 {
     return(new SpriterSpatial
     {
         Angle = MathHelper.AngleLinear(a.Angle, b.Angle, spin, f),
         X = MathHelper.Linear(a.X, b.X, f),
         Y = MathHelper.Linear(a.Y, b.Y, f),
         ScaleX = MathHelper.Linear(a.ScaleX, b.ScaleX, f),
         ScaleY = MathHelper.Linear(a.ScaleY, b.ScaleY, f)
     });
 }
        private static SpriterSpatial Interpolate(SpriterSpatial a, SpriterSpatial b, float f, int spin)
        {
            SpriterSpatial ss = SpriterObjectPool.GetObject <SpriterSpatial>();

            ss.Angle  = MathHelper.AngleLinear(a.Angle, b.Angle, spin, f);
            ss.X      = MathHelper.Linear(a.X, b.X, f);
            ss.Y      = MathHelper.Linear(a.Y, b.Y, f);
            ss.ScaleX = MathHelper.Linear(a.ScaleX, b.ScaleX, f);
            ss.ScaleY = MathHelper.Linear(a.ScaleY, b.ScaleY, f);

            return(ss);
        }
        private static void ApplyParentTransform(SpriterSpatial child, SpriterSpatial parent)
        {
            float  px       = parent.ScaleX * child.X;
            float  py       = parent.ScaleY * child.Y;
            double angleRad = parent.Angle * Math.PI / 180;
            float  s        = (float)Math.Sin(angleRad);
            float  c        = (float)Math.Cos(angleRad);

            child.X       = px * c - py * s + parent.X;
            child.Y       = px * s + py * c + parent.Y;
            child.ScaleX *= parent.ScaleX;
            child.ScaleY *= parent.ScaleY;
            child.Angle   = parent.Angle + Math.Sign(parent.ScaleX * parent.ScaleY) * child.Angle;
            child.Angle  %= 360.0f;
        }
        public static FrameData GetFrameData(SpriterAnimation first, SpriterAnimation second, float targetTime, float factor)
        {
            if (first == second)
            {
                return(GetFrameData(first, targetTime));
            }

            float targetTimeSecond = targetTime / first.Length * second.Length;

            SpriterMainlineKey firstKeyA;
            SpriterMainlineKey firstKeyB;

            GetMainlineKeys(first.MainlineKeys, targetTime, out firstKeyA, out firstKeyB);

            SpriterMainlineKey secondKeyA;
            SpriterMainlineKey secondKeyB;

            GetMainlineKeys(second.MainlineKeys, targetTimeSecond, out secondKeyA, out secondKeyB);

            if (firstKeyA.BoneRefs.Length != secondKeyA.BoneRefs.Length ||
                firstKeyB.BoneRefs.Length != secondKeyB.BoneRefs.Length ||
                firstKeyA.ObjectRefs.Length != secondKeyA.ObjectRefs.Length ||
                firstKeyB.ObjectRefs.Length != secondKeyB.ObjectRefs.Length)
            {
                return(GetFrameData(first, targetTime));
            }

            float adjustedTimeFirst  = AdjustTime(firstKeyA, firstKeyB, first.Length, targetTime);
            float adjustedTimeSecond = AdjustTime(secondKeyA, secondKeyB, second.Length, targetTimeSecond);

            SpriterSpatial[] boneInfosA = GetBoneInfos(firstKeyA, first, adjustedTimeFirst);
            SpriterSpatial[] boneInfosB = GetBoneInfos(secondKeyA, second, adjustedTimeSecond);
            SpriterSpatial[] boneInfos  = null;
            if (boneInfosA != null && boneInfosB != null)
            {
                boneInfos = new SpriterSpatial[boneInfosA.Length];
                for (int i = 0; i < boneInfosA.Length; ++i)
                {
                    SpriterSpatial boneA        = boneInfosA[i];
                    SpriterSpatial boneB        = boneInfosB[i];
                    SpriterSpatial interpolated = Interpolate(boneA, boneB, factor, 1);
                    interpolated.Angle = MathHelper.CloserAngleLinear(boneA.Angle, boneB.Angle, factor);
                    boneInfos[i]       = interpolated;
                }
            }

            SpriterMainlineKey baseKey          = factor < 0.5f ? firstKeyA : firstKeyB;
            SpriterAnimation   currentAnimation = factor < 0.5f ? first : second;

            FrameData frameData = new FrameData();

            for (int i = 0; i < baseKey.ObjectRefs.Length; ++i)
            {
                SpriterObjectRef objectRefFirst    = baseKey.ObjectRefs[i];
                SpriterObject    interpolatedFirst = GetObjectInfo(objectRefFirst, first, adjustedTimeFirst);

                SpriterObjectRef objectRefSecond    = secondKeyA.ObjectRefs[i];
                SpriterObject    interpolatedSecond = GetObjectInfo(objectRefSecond, second, adjustedTimeSecond);

                SpriterObject info = Interpolate(interpolatedFirst, interpolatedSecond, factor, 1);
                info.Angle = MathHelper.CloserAngleLinear(interpolatedFirst.Angle, interpolatedSecond.Angle, factor);

                if (boneInfos != null && objectRefFirst.ParentId >= 0)
                {
                    ApplyParentTransform(info, boneInfos[objectRefFirst.ParentId]);
                }

                AddSpatialData(info, currentAnimation.Timelines[objectRefFirst.TimelineId], currentAnimation.Entity.Spriter, targetTime, frameData);
            }

            return(frameData);
        }
        public static void UpdateFrameData(FrameData frameData, SpriterAnimation animation, float targetTime, SpriterSpatial parentInfo = null)
        {
            SpriterMainlineKey keyA;
            SpriterMainlineKey keyB;

            GetMainlineKeys(animation.MainlineKeys, targetTime, out keyA, out keyB);

            float adjustedTime = AdjustTime(keyA, keyB, animation.Length, targetTime);

            SpriterSpatial[] boneInfos = GetBoneInfos(keyA, animation, targetTime, parentInfo);

            if (keyA.ObjectRefs == null)
            {
                SpriterObjectPool.ReturnObject(boneInfos);
                return;
            }

            for (int i = 0; i < keyA.ObjectRefs.Length; ++i)
            {
                SpriterObjectRef objectRef    = keyA.ObjectRefs[i];
                SpriterObject    interpolated = GetObjectInfo(objectRef, animation, adjustedTime);
                if (boneInfos != null && objectRef.ParentId >= 0)
                {
                    ApplyParentTransform(interpolated, boneInfos[objectRef.ParentId]);
                }
                else if (parentInfo != null)
                {
                    ApplyParentTransform(interpolated, parentInfo);
                }

                AddSpatialData(interpolated, animation.Timelines[objectRef.TimelineId], animation.Entity.Spriter, targetTime, frameData);
            }

            SpriterObjectPool.ReturnObject(boneInfos);
        }
        public static FrameData GetFrameData(SpriterAnimation animation, float targetTime, SpriterSpatial parentInfo = null)
        {
            SpriterMainlineKey keyA;
            SpriterMainlineKey keyB;

            GetMainlineKeys(animation.MainlineKeys, targetTime, out keyA, out keyB);

            float adjustedTime = AdjustTime(keyA, keyB, animation.Length, targetTime);

            SpriterSpatial[] boneInfos = GetBoneInfos(keyA, animation, targetTime, parentInfo);

            FrameData frameData = new FrameData();

            foreach (SpriterObjectRef objectRef in keyA.ObjectRefs)
            {
                SpriterObject interpolated = GetObjectInfo(objectRef, animation, adjustedTime);
                if (boneInfos != null && objectRef.ParentId >= 0)
                {
                    ApplyParentTransform(interpolated, boneInfos[objectRef.ParentId]);
                }

                AddSpatialData(interpolated, animation.Timelines[objectRef.TimelineId], animation.Entity.Spriter, targetTime, frameData);
            }

            return(frameData);
        }
Пример #14
0
        public virtual FrameData GetFrameData(SpriterAnimation first, SpriterAnimation second, float targetTime, float deltaTime, float factor)
        {
            FrameData.Clear();

            if (first == second)
            {
                GetFrameData(first, targetTime, deltaTime);
                return(FrameData);
            }

            float targetTimeSecond = targetTime / first.Length * second.Length;

            SpriterMainlineKey firstKeyA;
            SpriterMainlineKey firstKeyB;

            GetMainlineKeys(first.MainlineKeys, targetTime, out firstKeyA, out firstKeyB);

            SpriterMainlineKey secondKeyA;
            SpriterMainlineKey secondKeyB;

            GetMainlineKeys(second.MainlineKeys, targetTimeSecond, out secondKeyA, out secondKeyB);

            if (!SpriterHelper.WillItBlend(firstKeyA, secondKeyA) || !SpriterHelper.WillItBlend(firstKeyB, secondKeyB))
            {
                GetFrameData(first, targetTime, deltaTime);
                return(FrameData);
            }

            float adjustedTimeFirst  = SpriterHelper.AdjustTime(targetTime, firstKeyA, firstKeyB, first.Length);
            float adjustedTimeSecond = SpriterHelper.AdjustTime(targetTimeSecond, secondKeyA, secondKeyB, second.Length);

            SpriterSpatial[] boneInfosA = GetBoneInfos(firstKeyA, first, adjustedTimeFirst);
            SpriterSpatial[] boneInfosB = GetBoneInfos(secondKeyA, second, adjustedTimeSecond);
            SpriterSpatial[] boneInfos  = null;
            if (boneInfosA != null && boneInfosB != null)
            {
                boneInfos = Pool.GetArray <SpriterSpatial>(boneInfosA.Length);
                for (int i = 0; i < boneInfosA.Length; ++i)
                {
                    SpriterSpatial boneA        = boneInfosA[i];
                    SpriterSpatial boneB        = boneInfosB[i];
                    SpriterSpatial interpolated = Interpolate(boneA, boneB, factor, 1);
                    interpolated.Angle = MathHelper.CloserAngleLinear(boneA.Angle, boneB.Angle, factor);
                    boneInfos[i]       = interpolated;
                }
            }

            SpriterMainlineKey baseKey          = factor < 0.5f ? firstKeyA : firstKeyB;
            SpriterAnimation   currentAnimation = factor < 0.5f ? first : second;

            for (int i = 0; i < baseKey.ObjectRefs.Length; ++i)
            {
                SpriterObjectRef objectRefFirst    = baseKey.ObjectRefs[i];
                SpriterObject    interpolatedFirst = GetObjectInfo(objectRefFirst, first, adjustedTimeFirst);

                SpriterObjectRef objectRefSecond    = secondKeyA.ObjectRefs[i];
                SpriterObject    interpolatedSecond = GetObjectInfo(objectRefSecond, second, adjustedTimeSecond);

                SpriterObject info = Interpolate(interpolatedFirst, interpolatedSecond, factor, 1);
                info.Angle  = MathHelper.CloserAngleLinear(interpolatedFirst.Angle, interpolatedSecond.Angle, factor);
                info.PivotX = MathHelper.Linear(interpolatedFirst.PivotX, interpolatedSecond.PivotX, factor);
                info.PivotY = MathHelper.Linear(interpolatedFirst.PivotY, interpolatedSecond.PivotY, factor);

                if (boneInfos != null && objectRefFirst.ParentId >= 0)
                {
                    info.ApplyParentTransform(boneInfos[objectRefFirst.ParentId]);
                }

                AddSpatialData(info, currentAnimation.Timelines[objectRefFirst.TimelineId], currentAnimation.Entity.Spriter, deltaTime);

                Pool.ReturnObject(interpolatedFirst);
                Pool.ReturnObject(interpolatedSecond);
            }

            Pool.ReturnObject(boneInfosA);
            Pool.ReturnObject(boneInfosB);
            Pool.ReturnObject(boneInfos);

            if (Config.MetadataEnabled)
            {
                UpdateMetadata(currentAnimation, targetTime, deltaTime);
            }

            return(FrameData);
        }
Пример #15
0
 protected virtual void UpdateMetadata(SpriterAnimation animation, float targetTime, float deltaTime, SpriterSpatial parentInfo = null)
 {
     if (Config.VarsEnabled || Config.TagsEnabled)
     {
         AddVariableAndTagData(animation, targetTime);
     }
     if (Config.EventsEnabled)
     {
         AddEventData(animation, targetTime, deltaTime);
     }
     if (Config.SoundsEnabled)
     {
         AddSoundData(animation, targetTime, deltaTime);
     }
 }
Пример #16
0
        public virtual FrameData GetFrameData(SpriterAnimation animation, float targetTime, float deltaTime, SpriterSpatial parentInfo = null)
        {
            if (parentInfo == null)
            {
                FrameData.Clear();
            }

            SpriterMainlineKey keyA;
            SpriterMainlineKey keyB;

            GetMainlineKeys(animation.MainlineKeys, targetTime, out keyA, out keyB);

            float adjustedTime = SpriterHelper.AdjustTime(targetTime, keyA, keyB, animation.Length);

            SpriterSpatial[] boneInfos = GetBoneInfos(keyA, animation, adjustedTime, parentInfo);

            if (keyA.ObjectRefs == null)
            {
                Pool.ReturnObject(boneInfos);
                return(FrameData);
            }

            for (int i = 0; i < keyA.ObjectRefs.Length; ++i)
            {
                SpriterObjectRef objectRef    = keyA.ObjectRefs[i];
                SpriterObject    interpolated = GetObjectInfo(objectRef, animation, adjustedTime);
                if (boneInfos != null && objectRef.ParentId >= 0)
                {
                    interpolated.ApplyParentTransform(boneInfos[objectRef.ParentId]);
                }
                else if (parentInfo != null)
                {
                    interpolated.ApplyParentTransform(parentInfo);
                }

                AddSpatialData(interpolated, animation.Timelines[objectRef.TimelineId], animation.Entity.Spriter, deltaTime);
            }

            Pool.ReturnObject(boneInfos);

            if (Config.MetadataEnabled)
            {
                UpdateMetadata(animation, targetTime, deltaTime);
            }

            return(FrameData);
        }
 public static void UpdateFrameMetadata(FrameMetadata metadata, SpriterAnimation animation, float targetTime, float deltaTime, SpriterSpatial parentInfo = null)
 {
     if (SpriterConfig.VarsEnabled || SpriterConfig.TagsEnabled)
     {
         AddVariableAndTagData(animation, targetTime, metadata);
     }
     if (SpriterConfig.EventsEnabled)
     {
         AddEventData(animation, targetTime, deltaTime, metadata);
     }
     if (SpriterConfig.SoundsEnabled)
     {
         AddSoundData(animation, targetTime, deltaTime, metadata);
     }
 }
        public static FrameMetadata GetFrameMetadata(SpriterAnimation animation, float targetTime, float deltaTime, SpriterSpatial parentInfo = null)
        {
            FrameMetadata metadata = new FrameMetadata();

            AddVariableAndTagData(animation, targetTime, metadata);
            AddEventData(animation, targetTime, deltaTime, metadata);
            AddSoundData(animation, targetTime, deltaTime, metadata);
            return(metadata);
        }