private static SpriterSpatial[] GetBoneInfos(SpriterMainlineKey key, SpriterAnimation animation, float targetTime, SpriterSpatial parentInfo = null)
        {
            if (key.BoneRefs == null)
            {
                return(null);
            }
            SpriterSpatial[] ret = SpriterObjectPool.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)
                {
                    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);
        }
        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 void Clear()
        {
            var varE = ObjectVars.GetEnumerator();

            while (varE.MoveNext())
            {
                SpriterObjectPool.ReturnStructDict(varE.Current.Value);
            }
            ObjectVars.Clear();

            var tagE = ObjectTags.GetEnumerator();

            while (tagE.MoveNext())
            {
                var list = tagE.Current.Value;
                list.Clear();
                SpriterObjectPool.ReturnObject(list);
            }
            ObjectTags.Clear();

            Sounds.Clear();
            AnimationVars.Clear();
            AnimationTags.Clear();
            Events.Clear();
        }
        public void AddObjectTag(string objectName, string tag)
        {
            List <string> tags;

            if (!ObjectTags.TryGetValue(objectName, out tags))
            {
                tags = SpriterObjectPool.GetObject <List <string> >();
                ObjectTags[objectName] = tags;
            }
            tags.Add(tag);
        }
        public void AddObjectVar(string objectName, string varName, SpriterVarValue value)
        {
            Dictionary <string, SpriterVarValue> values;

            if (!ObjectVars.TryGetValue(objectName, out values))
            {
                values = SpriterObjectPool.GetObject <Dictionary <string, SpriterVarValue> >();
                ObjectVars[objectName] = values;
            }
            values[varName] = value;
        }
        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 SpriterObject Copy(SpriterObject info)
        {
            SpriterObject so = SpriterObjectPool.GetObject <SpriterObject>();

            so.AnimationId = info.AnimationId;
            so.EntityId    = info.EntityId;
            so.FileId      = info.FileId;
            so.FolderId    = info.FolderId;
            so.PivotX      = info.PivotX;
            so.PivotY      = info.PivotY;
            so.T           = info.T;

            FillFrom(so, info);
            return(so);
        }
        private static SpriterObject Interpolate(SpriterObject a, SpriterObject b, float f, int spin)
        {
            SpriterObject so = SpriterObjectPool.GetObject <SpriterObject>();

            so.Angle       = MathHelper.AngleLinear(a.Angle, b.Angle, spin, f);
            so.Alpha       = MathHelper.Linear(a.Alpha, b.Alpha, f);
            so.X           = MathHelper.Linear(a.X, b.X, f);
            so.Y           = MathHelper.Linear(a.Y, b.Y, f);
            so.ScaleX      = MathHelper.Linear(a.ScaleX, b.ScaleX, f);
            so.ScaleY      = MathHelper.Linear(a.ScaleY, b.ScaleY, f);
            so.PivotX      = a.PivotX;
            so.PivotY      = a.PivotY;
            so.FileId      = a.FileId;
            so.FolderId    = a.FolderId;
            so.EntityId    = a.EntityId;
            so.AnimationId = a.AnimationId;
            so.T           = MathHelper.Linear(a.T, b.T, f);

            return(so);
        }
Example #10
0
 public void Clear()
 {
     SpriterObjectPool.ReturnChildren(SpriteData);
     SpriterObjectPool.ReturnChildren(PointData);
     SpriterObjectPool.ReturnChildren(BoxData);
 }
        public static void UpdateFrameData(FrameData frameData, SpriterAnimation first, SpriterAnimation second, float targetTime, float factor)
        {
            if (first == second)
            {
                UpdateFrameData(frameData, first, targetTime);
                return;
            }

            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 (!WillItBlend(firstKeyA, secondKeyA) || !WillItBlend(firstKeyB, secondKeyB))
            {
                UpdateFrameData(frameData, first, targetTime);
                return;
            }

            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 = SpriterObjectPool.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)
                {
                    ApplyParentTransform(info, boneInfos[objectRefFirst.ParentId]);
                }

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

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

            SpriterObjectPool.ReturnObject(boneInfosA);
            SpriterObjectPool.ReturnObject(boneInfosB);
            SpriterObjectPool.ReturnObject(boneInfos);
        }