private static void InitVarDefs(SpriterAnimation animation)
        {
            if (animation.Meta == null || animation.Meta.Varlines == null || animation.Meta.Varlines.Length == 0)
            {
                return;
            }

            foreach (SpriterVarline varline in animation.Meta.Varlines)
            {
                SpriterVarDef varDefs = animation.Entity.Variables[varline.Def];
                Init(varDefs, varline);
            }

            foreach (SpriterTimeline timeline in animation.Timelines)
            {
                if (timeline.Meta == null || timeline.Meta.Varlines == null || timeline.Meta.Varlines.Length == 0)
                {
                    continue;
                }
                SpriterObjectInfo objInfo = animation.Entity.ObjectInfos.First(o => o.Name == timeline.Name);
                foreach (SpriterVarline varline in timeline.Meta.Varlines)
                {
                    SpriterVarDef varDef = objInfo.Variables[varline.Def];
                    Init(varDef, varline);
                }
            }
        }
        private static SpriterObjectInfo GetObjectInfo(SpriterAnimation animation, string name)
        {
            SpriterObjectInfo objInfo = null;

            foreach (SpriterObjectInfo info in animation.Entity.ObjectInfos)
            {
                if (info.Name == name)
                {
                    objInfo = info;
                    break;
                }
            }

            return(objInfo);
        }
        protected virtual SpriterObjectInfo GetObjectInfo(SpriterAnimation animation, string name)
        {
            SpriterObjectInfo objInfo = null;

            for (int i = 0; i < animation.Entity.ObjectInfos.Length; ++i)
            {
                SpriterObjectInfo info = animation.Entity.ObjectInfos[i];
                if (info.Name == name)
                {
                    objInfo = info;
                    break;
                }
            }

            return(objInfo);
        }
示例#4
0
        public static SpriterObjectInfo[] GetDrawData(SpriterAnimation animation, float targetTime)
        {
            SpriterMainLineKey[] keys = animation.MainlineKeys;
            SpriterMainLineKey keyA = keys.Last(k => k.Time <= targetTime);
            int nextKey = keyA.Id + 1;
            if (nextKey >= keys.Length) nextKey = 0;
            SpriterMainLineKey keyB = keys[nextKey];

            float nextTime = keyB.Time > keyA.Time ? keyB.Time : animation.Length;
            float factor = GetFactor(keyA, keyB, animation.Length, targetTime);
            float adjustedTime = Linear(keyA.Time, nextTime, factor);

            var boneInfos = new Dictionary<int, SpriterSpatialInfo>();

            if (keyA.BoneRefs != null)
            {
                for (int i = 0; i < keyA.BoneRefs.Length; ++i)
                {
                    SpriterRef boneRef = keyA.BoneRefs[i];
                    SpriterSpatialInfo interpolated = GetBoneInfo(boneRef, animation, adjustedTime);

                    if (boneRef.ParentId >= 0) ApplyParentTransform(interpolated, boneInfos[boneRef.ParentId]);
                    boneInfos[i] = interpolated;
                }
            }

            SpriterObjectInfo[] ret = new SpriterObjectInfo[keyA.ObjectRefs.Length];

            for (int i = 0; i < keyA.ObjectRefs.Length; ++i)
            {
                SpriterObjectRef objectRef = keyA.ObjectRefs[i];
                SpriterObjectInfo interpolated = GetObjectInfo(objectRef, animation, adjustedTime);

                if (objectRef.ParentId >= 0) ApplyParentTransform(interpolated, boneInfos[objectRef.ParentId]);
                ret[objectRef.Id] = interpolated;
            }

            return ret;
        }
        protected virtual void AddVariableAndTagData(SpriterAnimation animation, float targetTime)
        {
            if (animation.Meta == null)
            {
                return;
            }

            if (Config.VarsEnabled && animation.Meta.Varlines != null && animation.Meta.Varlines.Length > 0)
            {
                for (int i = 0; i < animation.Meta.Varlines.Length; ++i)
                {
                    SpriterVarline varline  = animation.Meta.Varlines[i];
                    SpriterVarDef  variable = animation.Entity.Variables[varline.Def];
                    FrameData.AnimationVars[variable.Name] = GetVariableValue(animation, variable, varline, targetTime);
                }
            }

            SpriterElement[] tags    = animation.Entity.Spriter.Tags;
            SpriterTagline   tagline = animation.Meta.Tagline;

            if (Config.TagsEnabled && tagline != null && tagline.Keys != null && tagline.Keys.Length > 0)
            {
                SpriterTaglineKey key = tagline.Keys.GetLastKey(targetTime);
                if (key != null && key.Tags != null)
                {
                    for (int i = 0; i < key.Tags.Length; ++i)
                    {
                        SpriterTag tag = key.Tags[i];
                        FrameData.AnimationTags.Add(tags[tag.TagId].Name);
                    }
                }
            }

            for (int i = 0; i < animation.Timelines.Length; ++i)
            {
                SpriterTimeline timeline = animation.Timelines[i];
                SpriterMeta     meta     = timeline.Meta;
                if (meta == null)
                {
                    continue;
                }

                SpriterObjectInfo objInfo = GetObjectInfo(animation, timeline.Name);

                if (Config.VarsEnabled && meta.Varlines != null && meta.Varlines.Length > 0)
                {
                    for (int j = 0; j < timeline.Meta.Varlines.Length; ++j)
                    {
                        SpriterVarline varline  = timeline.Meta.Varlines[j];
                        SpriterVarDef  variable = objInfo.Variables[varline.Def];
                        FrameData.AddObjectVar(objInfo.Name, variable.Name, GetVariableValue(animation, variable, varline, targetTime));
                    }
                }

                if (Config.TagsEnabled && meta.Tagline != null && meta.Tagline.Keys != null && meta.Tagline.Keys.Length > 0)
                {
                    SpriterTaglineKey key = tagline.Keys.GetLastKey(targetTime);
                    if (key != null && key.Tags != null)
                    {
                        for (int j = 0; j < key.Tags.Length; ++j)
                        {
                            SpriterTag tag = key.Tags[j];
                            FrameData.AddObjectTag(objInfo.Name, tags[tag.TagId].Name);
                        }
                    }
                }
            }
        }
示例#6
0
 /// <summary>
 /// Applies the transform for the given box.
 /// </summary>
 protected virtual void ApplyBoxTransform(SpriterObjectInfo objInfo, SpriterObject info)
 {
 }
示例#7
0
 private static SpriterObjectInfo Interpolate(SpriterObjectInfo a, SpriterObjectInfo b, float f, int spin)
 {
     return new SpriterObjectInfo
     {
         Angle = AngleLinear(a.Angle, b.Angle, spin, f),
         Alpha = Linear(a.Alpha, b.Alpha, f),
         X = Linear(a.X, b.X, f),
         Y = Linear(a.Y, b.Y, f),
         ScaleX = Linear(a.ScaleX, b.ScaleX, f),
         ScaleY = Linear(a.ScaleY, b.ScaleY, f),
         PivotX = a.PivotX,
         PivotY = a.PivotY,
         FileId = a.FileId,
         FolderId = a.FolderId
     };
 }
示例#8
0
        private static SpriterObjectInfo Copy(SpriterObjectInfo info)
        {
            SpriterObjectInfo copy = new SpriterObjectInfo
            {
                FileId = info.FileId,
                FolderId = info.FolderId,
                PivotX = info.PivotX,
                PivotY = info.PivotY
            };

            FillFrom(copy, info);
            return copy;
        }
        private static void AddVariableAndTagData(SpriterAnimation animation, float targetTime, FrameMetadata metadata)
        {
            if (animation.Meta == null)
            {
                return;
            }

            if (animation.Meta.Varlines != null && animation.Meta.Varlines.Length > 0)
            {
                foreach (SpriterVarline varline in animation.Meta.Varlines)
                {
                    SpriterVarDef variable = animation.Entity.Variables[varline.Def];
                    metadata.AnimationVars[variable.Name] = GetVariableValue(animation, variable, varline, targetTime);
                }
            }

            SpriterElement[] tags    = animation.Entity.Spriter.Tags;
            SpriterTagline   tagline = animation.Meta.Tagline;

            if (tagline != null && tagline.Keys != null && tagline.Keys.Length > 0)
            {
                SpriterTaglineKey key = LastKeyForTime <SpriterTaglineKey>(tagline.Keys, targetTime);
                if (key != null && key.Tags != null)
                {
                    foreach (SpriterTag tag in key.Tags)
                    {
                        metadata.AnimationTags.Add(tags[tag.TagId].Name);
                    }
                }
            }

            foreach (SpriterTimeline timeline in animation.Timelines)
            {
                SpriterMeta meta = timeline.Meta;
                if (meta == null)
                {
                    continue;
                }

                SpriterObjectInfo objInfo = GetObjectInfo(animation, timeline.Name);

                if (meta.Varlines != null && meta.Varlines.Length > 0)
                {
                    foreach (SpriterVarline varline in timeline.Meta.Varlines)
                    {
                        SpriterVarDef variable = objInfo.Variables[varline.Def];
                        metadata.AddObjectVar(objInfo.Name, variable.Name, GetVariableValue(animation, variable, varline, targetTime));
                    }
                }

                if (meta.Tagline != null && meta.Tagline.Keys != null && meta.Tagline.Keys.Length > 0)
                {
                    SpriterTaglineKey key = LastKeyForTime <SpriterTaglineKey>(tagline.Keys, targetTime);
                    if (key != null && key.Tags != null)
                    {
                        foreach (SpriterTag tag in key.Tags)
                        {
                            metadata.AddObjectTag(objInfo.Name, tags[tag.TagId].Name);
                        }
                    }
                }
            }
        }