public SpriteAnimationCurve(SpriteAnimationCurve other)
        {
            this.name  = other.name;
            this.type  = other.type;
            this.curve = new AnimationCurve(other.curve.keys);

            this.interpolation = other.interpolation;
            this.length        = other.length;
            this.defaultValue  = other.defaultValue;
        }
예제 #2
0
        internal SpriteAnimationKeyFrame EvaluateAddtive(float time, SpriteTransform transform, float[] transformProperty)
        {
            int idx = (int)curves[0].curve.Evaluate(time);
            SpriteAnimationKeyFrame kf = keyFrames[idx];

            SpriteAnimationCurve curve = null;

            for (int i = 1, e = curves.Length; i < e; i++)
            {
                curve = curves[i];
                transformProperty[(int)curve.type] = curve.length == 0 ? 0f : (curve.curve.Evaluate(time) - curve.defaultValue);
            }
            return(kf);
        }
예제 #3
0
        private void AddKeyToCurve(SpriteAnimationCurve curve, float time, float value, bool copyTangent, int tangentMode, bool smoothTangent)
        {
            Keyframe kf = new Keyframe(time, value);

            kf.tangentMode = 0;

            foreach (SpriteAnimationCurve _curve in curves)
            {
                if (_curve.type == curve.type)
                {
                    foreach (Keyframe _kf in _curve.curve.keys)
                    {
                        if (_kf.time == time && copyTangent)
                        {
                            kf.inTangent   = _kf.inTangent;
                            kf.outTangent  = _kf.outTangent;
                            kf.tangentMode = _kf.tangentMode;
                            break;
                        }
                    }
                    break;
                }
            }


            curve.curve.AddKey(kf);
            curve.length = curve.curve.keys.Length;


            if (smoothTangent)
            {
                //int i = 0;

                //foreach (Keyframe _kf in curve.curve.keys)
                //{
                //    if (_kf.time == time && copyTangent)
                //    {
                //        curve.curve.SmoothTangents(i, 1f);
                //        break;
                //    }
                //    i++;
                //}
            }
        }
예제 #4
0
        internal SpriteAnimationKeyFrame EvaluateBlending(float time, SpriteTransform transform, float[] transformProperty)
        {
            int idx = (int)curves[0].curve.Evaluate(time);
            SpriteAnimationKeyFrame kf = keyFrames[idx];

            if (!transform.isSpriteValid)
            {
                transform.sprite = kf.sprite;
            }

            float v = 0f;
            SpriteAnimationCurve curve = null;

            for (int i = 1, e = curves.Length; i < e; i++)
            {
                curve = curves[i];
                transformProperty[(int)curve.type] = curve.length == 0 ? curve.defaultValue : curve.curve.Evaluate(time);
            }
            return(kf);
        }
예제 #5
0
        /// <summary>
        /// Calculate the curves of component.
        /// </summary>
        public void CalcCurve(SpriteAnimationKeyFrame newKf)
        {
            _maxIndex = GetMaxIndex();

            List <SpriteAnimationKeyFrame> tmp = new List <SpriteAnimationKeyFrame>(keyFrames);

            tmp.Sort(SpriteAnimationKeyFrameComparerByFrameIndex.comparer);
            keyFrames = tmp.ToArray();

            ApplyCurveChangeToKeyframe();

            List <SpriteAnimationCurve> tmpCurves = new List <SpriteAnimationCurve>();

            for (int i = (int)SpriteAnimationCurveType.KeyframeIndex, e = (int)SpriteAnimationCurveType.ShearY; i <= e; i++)
            {
                SpriteAnimationCurve curve = new SpriteAnimationCurve();

                curve.type  = (SpriteAnimationCurveType)i;
                curve.curve = new AnimationCurve();

                foreach (SpriteAnimationCurve _curve in curves)
                {
                    if (_curve.type == curve.type)
                    {
                        curve.interpolation = _curve.interpolation;
                    }
                }

                tmpCurves.Add(curve);
            }

            float tick = 1f / clip.frameRate;
            int   idx  = 0;

            tmpCurves[(int)SpriteAnimationCurveType.KeyframeIndex].curve         = new AnimationCurve();
            tmpCurves[(int)SpriteAnimationCurveType.KeyframeIndex].interpolation = true;

            foreach (SpriteAnimationKeyFrame kf in keyFrames)
            {
                float time = kf.frameIndex * tick;;
                kf.isSpriteValid = kf.sprite != null;

                bool needSmooth = kf == newKf;

                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.KeyframeIndex], time, idx + 0.005f, false, 0, false);

                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.PositionX], time, kf.position.x, true, 1, needSmooth);
                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.PositionY], time, kf.position.y, true, 0, needSmooth);

                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.Rotate], time, kf.rotation, true, 0, needSmooth);

                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.ScaleX], time, kf.scale.x, true, 0, needSmooth);
                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.ScaleY], time, kf.scale.y, true, 0, needSmooth);

                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.ShearX], time, kf.shear.x, true, 0, needSmooth);
                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.ShearY], time, kf.shear.y, true, 0, needSmooth);

                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.ColorR], time, kf.color.r, true, 0, needSmooth);
                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.ColorG], time, kf.color.g, true, 0, needSmooth);
                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.ColorB], time, kf.color.b, true, 0, needSmooth);
                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.ColorA], time, kf.color.a, true, 0, needSmooth);

                idx++;
            }


            //for (int i = 0, e = tmpCurves[(int)SpriteAnimationCurveType.KeyframeIndex].curve.keys.Length; i < e; i++)
            //    tmpCurves[(int)SpriteAnimationCurveType.KeyframeIndex].curve.SmoothTangents(i, 1f);


            //remove curves if values never change
            tmpCurves.RemoveAll(delegate(SpriteAnimationCurve curve)
            {
                if (curve.type == SpriteAnimationCurveType.KeyframeIndex)
                {
                    return(false);
                }

                bool ret = true;

                Keyframe fkf       = curve.curve.keys[0];
                curve.defaultValue = fkf.value;

                bool isFkDef = fkf.value == GetDefaultValue(curve.type);

                foreach (Keyframe kf in curve.curve.keys)
                {
                    if (fkf.value != kf.value)
                    {
                        return(false);
                    }
                }


                if (!isFkDef)
                {
                    curve.length = 0;
                    return(false);
                }

                return(ret);
            });


            foreach (SpriteAnimationCurve curve in tmpCurves)
            {
                if (curve.type == SpriteAnimationCurveType.KeyframeIndex)
                {
                    continue;
                }

                if (!curve.interpolation)
                {
                    Keyframe[] kfs = curve.curve.keys;
                    curve.curve = new AnimationCurve();

                    for (int i = 0, e = kfs.Length; i < e; i++)
                    {
                        Keyframe kf = kfs[i];
                        kf.inTangent  = float.PositiveInfinity;
                        kf.outTangent = float.NegativeInfinity;

                        curve.curve.AddKey(kf);
                    }
                }
            }

            curves = tmpCurves.ToArray();
        }
 public SpriteAnimationCurve(SpriteAnimationCurve other)
 {
     this.name  = name;
     this.type  = type;
     this.curve = new AnimationCurve(other.curve.keys);
 }
        private void AddKeyToCurve(SpriteAnimationCurve curve, float time, float value, bool copyTangent, int tangentMode, bool smoothTangent)
        {
            Keyframe kf = new Keyframe(time, value);
            kf.tangentMode = 0;

            foreach (SpriteAnimationCurve _curve in curves)
            {
                if (_curve.type == curve.type)
                {
                    foreach (Keyframe _kf in _curve.curve.keys)
                    {
                        if (_kf.time == time && copyTangent)
                        {
                            kf.inTangent = _kf.inTangent;
                            kf.outTangent = _kf.outTangent;
                            kf.tangentMode = _kf.tangentMode;
                            break;
                        }
                    }
                    break;
                }
            }


            curve.curve.AddKey(kf);
            curve.length = curve.curve.keys.Length;


            if (smoothTangent)
            {
                //int i = 0;

                //foreach (Keyframe _kf in curve.curve.keys)
                //{
                //    if (_kf.time == time && copyTangent)
                //    {
                //        curve.curve.SmoothTangents(i, 1f);
                //        break;
                //    }
                //    i++;
                //}
            }
        }
        /// <summary>
        /// Calculate the curves of component.
        /// </summary>
        public void CalcCurve(SpriteAnimationKeyFrame newKf)
        {
            _maxIndex = GetMaxIndex();

            List<SpriteAnimationKeyFrame> tmp = new List<SpriteAnimationKeyFrame>(keyFrames);
            tmp.Sort(SpriteAnimationKeyFrameComparerByFrameIndex.comparer);
            keyFrames = tmp.ToArray();

            ApplyCurveChangeToKeyframe();

            List<SpriteAnimationCurve> tmpCurves = new List<SpriteAnimationCurve>();
            for (int i = (int)SpriteAnimationCurveType.KeyframeIndex, e = (int)SpriteAnimationCurveType.ShearY; i <= e; i++)
            {
                SpriteAnimationCurve curve = new SpriteAnimationCurve();

                curve.type = (SpriteAnimationCurveType)i;
                curve.curve = new AnimationCurve();

                foreach (SpriteAnimationCurve _curve in curves)
                {
                    if (_curve.type == curve.type)
                        curve.interpolation = _curve.interpolation;
                }

                tmpCurves.Add(curve);
            }

            float tick = 1f / clip.frameRate;
            int idx = 0;

            tmpCurves[(int)SpriteAnimationCurveType.KeyframeIndex].curve = new AnimationCurve();
            tmpCurves[(int)SpriteAnimationCurveType.KeyframeIndex].interpolation = true;

            foreach (SpriteAnimationKeyFrame kf in keyFrames)
            {
                float time = kf.frameIndex * tick; ;
                kf.isSpriteValid = kf.sprite != null;

                bool needSmooth = kf == newKf;

                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.KeyframeIndex], time, idx + 0.005f, false, 0, false);

                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.PositionX], time, kf.position.x, true, 1, needSmooth);
                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.PositionY], time, kf.position.y, true, 0, needSmooth);

                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.Rotate], time, kf.rotation, true, 0, needSmooth);

                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.ScaleX], time, kf.scale.x, true, 0, needSmooth);
                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.ScaleY], time, kf.scale.y, true, 0, needSmooth);

                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.ShearX], time, kf.shear.x, true, 0, needSmooth);
                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.ShearY], time, kf.shear.y, true, 0, needSmooth);

                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.ColorR], time, kf.color.r, true, 0, needSmooth);
                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.ColorG], time, kf.color.g, true, 0, needSmooth);
                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.ColorB], time, kf.color.b, true, 0, needSmooth);
                AddKeyToCurve(tmpCurves[(int)SpriteAnimationCurveType.ColorA], time, kf.color.a, true, 0, needSmooth);

                idx++;
            }


            //for (int i = 0, e = tmpCurves[(int)SpriteAnimationCurveType.KeyframeIndex].curve.keys.Length; i < e; i++)
            //    tmpCurves[(int)SpriteAnimationCurveType.KeyframeIndex].curve.SmoothTangents(i, 1f);


            //remove curves if values never change
            tmpCurves.RemoveAll(delegate(SpriteAnimationCurve curve)
            {
                if (curve.type == SpriteAnimationCurveType.KeyframeIndex)
                    return false;

                bool ret = true;

                Keyframe fkf = curve.curve.keys[0];
                curve.defaultValue = fkf.value;

                bool isFkDef = fkf.value == GetDefaultValue(curve.type);

                foreach (Keyframe kf in curve.curve.keys)
                {
                    if (fkf.value != kf.value)
                        return false;
                }


                if (!isFkDef)
                {
                    curve.length = 0;
                    return false;
                }

                return ret;
            });


            foreach (SpriteAnimationCurve curve in tmpCurves)
            {
                if (curve.type == SpriteAnimationCurveType.KeyframeIndex)
                    continue;

                if (!curve.interpolation)
                {
                    Keyframe[] kfs = curve.curve.keys;
                    curve.curve = new AnimationCurve();

                    for (int i = 0, e = kfs.Length; i < e; i++)
                    {
                        Keyframe kf = kfs[i];
                        kf.inTangent = float.PositiveInfinity;
                        kf.outTangent = float.NegativeInfinity;

                        curve.curve.AddKey(kf);
                    }
                }
            }

            curves = tmpCurves.ToArray();
        }
 public SpriteAnimationCurve(SpriteAnimationCurve other)
 {
     this.name = name;
     this.type = type;
     this.curve = new AnimationCurve(other.curve.keys);
 }
        public SpriteAnimationCurve(SpriteAnimationCurve other)
        {
            this.name = other.name;
            this.type = other.type;
            this.curve = new AnimationCurve(other.curve.keys);

            this.interpolation = other.interpolation;
            this.length = other.length;
            this.defaultValue = other.defaultValue;
        }