Beispiel #1
0
        public void UpdateProperty(float frame, ref MotionProps m, BodymovinAnimatedShapeProperties[] set)
        {
            /* ----- CHECK FOR COMPLETE ----- */

            if (m.keys <= 0)
            {
                //Debug.Log(">>> NO PROP KEYS TO ANIMATE!");
                m.completed = true;
                return;
            }

            if (frame >= m.endFrame)
            {
                if (set == null || m.key + 1 == set.Length - 1)
                {
                    m.completed = true;
                    //Debug.Log("****** Prop Animation done! ******");
                    return;
                }

                SetKeyframe(ref m, set, m.key + 1);
            }



            /* ----- PERCENT KEYFRAME COMPLETE ----- */

            m.percent = (frame - m.startFrame) / (m.endFrame - m.startFrame);


            /* ----- CUBIC BEZIER EASE ----- */

            float ease = Ease.CubicBezier(Vector2.zero, m.currentOutTangent, m.nextInTangent, Vector2.one, m.percent);


            /* ----- UPDATE POINTS ----- */

            for (int i = 0; i < points.Length; i++)
            {
                if (m.percent < 0)
                {
                    // BACK TO START OF KEYFRAME
                    points[i].p = startPoints[i].p;
                    points[i].i = startPoints[i].i;
                    points[i].o = startPoints[i].o;
                }
                else
                {
                    points[i].p = startPoints[i].p + ((endPoints[i].p - startPoints[i].p) * ease);
                    points[i].i = startPoints[i].i + ((endPoints[i].i - startPoints[i].i) * ease);
                    points[i].o = startPoints[i].o + ((endPoints[i].o - startPoints[i].o) * ease);
                }
            }

            //  Debug.Log("Shape anim fr:  " + frame + "    m.percent:  " + m.percent);

            /* ----- UPDATE MESH ----- */

            UpdateMesh(false);
        }
Beispiel #2
0
 public void MotionSetup(ref bool b, ref MotionProps prop, BodymovinAnimatedShapeProperties[] set)
 {
     b = set != null && set.Length > 0;
     if (b)
     {
         prop = new MotionProps {
             keys = set.Length
         };
         SetKeyframe(ref prop, set, 0);
     }
 }
Beispiel #3
0
        public void CreatePathKeyframe(ref MotionProps prop, float start, float end, Vector2[] ease, BodyPoint[] pts, int k = 0)
        {
            prop.completed = false;
            prop.keys      = 1;

            prop.key               = k;
            prop.startFrame        = start;
            prop.endFrame          = end;
            prop.currentOutTangent = ease[0];
            prop.nextInTangent     = ease[1];

            startPoints = points;
            endPoints   = pts;
        }
Beispiel #4
0
        public void CreateKeyframe(ref MotionProps prop, float start, float end,
                                   Vector2[] ease, Vector3 startValue, Vector3 endValue, int k = 0)
        {
            prop.completed = false;
            prop.keys      = 1;

            prop.key               = k;
            prop.startFrame        = start;
            prop.endFrame          = end;
            prop.currentOutTangent = ease[0];
            prop.nextInTangent     = ease[1];

            prop.startValue = startValue;
            prop.endValue   = endValue;
        }
Beispiel #5
0
        /* ----- KEYFRAME SETTERS ----- */

        public void SetKeyframe(ref MotionProps prop, BodymovinAnimatedProperties[] set, int k = 0)
        {
            prop.completed = false;
            if (prop.keys <= 0 || set == null)
            {
                return;
            }
            if (k >= prop.keys)
            {
                k = 0;
            }

            prop.key               = k;
            prop.startFrame        = set[k].t;
            prop.endFrame          = set.Length > k + 1 ? set[k + 1].t : prop.startFrame;
            prop.currentOutTangent = set[k].o;
            prop.nextInTangent     = set[k].i;

            prop.startValue = set[k].s;
            prop.endValue   = set[k].e;
        }
Beispiel #6
0
        public void SetKeyframe(ref MotionProps prop, BodymovinAnimatedProperties[] set, int k = 0)
        {
            prop.completed = false;
            if (prop.keys <= 0)
            {
                return;
            }
            if (k >= prop.keys)
            {
                k = 0;
            }

            prop.key               = k;
            prop.startFrame        = set[k].t;
            prop.endFrame          = set.Length > k + 1 ? set[k + 1].t : prop.startFrame;
            prop.currentOutTangent = set[k].o;
            prop.nextInTangent     = set[k].i;

            bool v3 = (set == content.positionSets || set == content.scaleSets || set == content.anchorSets);

            prop.startValue = v3 ? set[k].s : new Vector3(set[k].sf, 0, 0);
            prop.endValue   = v3 ? set[k].e : new Vector3(set[k].ef, 0, 0);
        }
Beispiel #7
0
        public void SetKeyframe(ref MotionProps prop, BodymovinAnimatedShapeProperties[] set, int k = 0)
        {
            prop.completed = false;
            if (prop.keys <= 0 || set == null)
            {
                return;
            }
            if (k >= prop.keys)
            {
                k = 0;
            }

            prop.key               = k;
            prop.startFrame        = set[k].t;
            prop.endFrame          = set.Length > k ? set[k + 1].t : prop.startFrame;
            prop.currentOutTangent = set[k].o;
            prop.nextInTangent     = set[k].i;

            if (set == motionSet)
            {
                startPoints = set[k].pts[0];
                endPoints   = set[k].pts[1];
            }
        }
Beispiel #8
0
 public Vector3 Value3(MotionProps m, float ease)
 {
     return((m.percent < 0 || m.percent > 1) ?
            m.startValue : m.startValue + ((m.endValue - m.startValue) * ease));
 }
Beispiel #9
0
        public void UpdateProperty(float frame, ref MotionProps m, BodymovinAnimatedProperties[] set)
        {
            /* ----- CHECK FOR COMPLETE ----- */

            if (m.keys <= 0)
            {
                //Debug.Log(">>> NO PROP KEYS TO ANIMATE!");
                m.completed = true;
                return;
            }

            if (frame >= m.endFrame)
            {
                if (m.key + 1 == set.Length - 1)
                {
                    m.completed = true;
                    //Debug.Log("****** Prop Animation done! ******");
                    return;
                }

                while (frame >= m.endFrame)
                {
                    // Debug.Log("fr > end, eq:  " + frame + " - " + m.startFrame + " / (" + m.endFrame + " - " + m.startFrame + ")   keyframe:  " + m.key );
                    SetKeyframe(ref m, set, m.key + 1);
                    if (m.key == 0)
                    {
                        break;
                    }
                }
            }


            /* ----- PERCENT KEYFRAME COMPLETE ----- */

            m.percent = (frame - m.startFrame) / (m.endFrame - m.startFrame);


            /* ----- CUBIC BEZIER EASE ----- */

            //Debug.Log("to:  " + m.currentOutTangent + "   ti:  " + m.nextInTangent);

            float ease = Ease.CubicBezier(Vector2.zero, m.currentOutTangent, m.nextInTangent, Vector2.one, m.percent);


            /* ----- UPDATE PROPERTY ----- */

            if (set == content.strokeColorSets)
            {
                Color   c = stroke.Color;
                Vector3 v = Value3(m, ease);
                currentStrokeColor = v;
                c.r = v.x;
                c.g = v.y;
                c.b = v.z;

                UpdateStrokeColor(c);
            }
            else if (set == content.fillColorSets)
            {
                //Debug.Log("diff:  " + (set[m.key].e.x - set[m.key].s.x).ToString("F4") + "   fnl:  " + (set[m.key].s + ((set[m.key].e - set[m.key].s) * ease)) + "   percent:  " + m.percent + "   ease:  " + ease);

                Color   c = fill.Color;
                Vector3 v = Value3(m, ease);
                currentFillColor = v;
                c.r = v.x;
                c.g = v.y;
                c.b = v.z;

                UpdateFillColor(c);
            }
        }
Beispiel #10
0
 public float Value1(MotionProps m, float ease)
 {
     return((m.percent < 0 || m.percent > 1) ?
            m.startValue.x : m.startValue.x + ((m.endValue.x - m.startValue.x) * ease));
 }
Beispiel #11
0
        public void UpdateProperty(float frame, ref MotionProps m, BodymovinAnimatedProperties[] set)
        {
            /* ----- CHECK FOR COMPLETE ----- */

            if (m.keys <= 0)
            {
                //Debug.Log(">>> NO PROP KEYS TO ANIMATE!");
                m.completed = true;
                return;
            }

            if (frame >= m.endFrame)
            {
                if (m.key + 1 == set.Length - 1)
                {
                    m.completed = true;
                    //Debug.Log("****** Prop Animation done! ******");
                    return;
                }

                while (frame >= m.endFrame)
                {
                    // Debug.Log("fr > end, eq:  " + frame + " - " + m.startFrame + " / (" + m.endFrame + " - " + m.startFrame + ")   keyframe:  " + m.key );
                    SetKeyframe(ref m, set, m.key + 1);
                    if (m.key == 0)
                    {
                        break;
                    }
                }
            }


            /* ----- PERCENT KEYFRAME COMPLETE ----- */

            m.percent = (frame - m.startFrame) / (m.endFrame - m.startFrame);


            /* ----- CUBIC BEZIER EASE ----- */

            float ease = Ease.CubicBezier(Vector2.zero, m.currentOutTangent, m.nextInTangent, Vector2.one, m.percent);


            /* ----- UPDATE PROPERTY ----- */

            if (set == content.positionSets)
            {
                transform.localPosition = Value3(m, ease) + positionOffset;
            }
            else if (set == content.anchorSets)
            {
                Vector3 v = Value3(m, ease);
                currentAnchor = v;

                for (int i = 0; i < shapes.Length; i++)
                {
                    shapes[i].UpdateAnchor(v);
                }
            }
            else if (set == content.scaleSets)
            {
                transform.localScale = Value3(m, ease);
            }
            else if (set == content.rotationXSets)
            {
                finalRotation.x = Value1(m, ease);
            }
            else if (set == content.rotationYSets)
            {
                finalRotation.y = Value1(m, ease);
            }
            else if (set == content.rotationZSets)
            {
                finalRotation.z = Value1(m, ease);
            }
            else if (set == content.opacitySets)
            {
                float v = Value1(m, ease);
                currentOpacity = v;

                for (int i = 0; i < shapes.Length; i++)
                {
                    shapes[i].UpdateOpacity(v);
                }
            }
        }