Beispiel #1
0
 Vector3 SampleKeyByTime(float t, GOECurvKeyFrame left, GOECurvKeyFrame right, GOECurvInterpolationType interpMode, Vector3 val, Vector3 val2)
 {
     if (interpMode == GOECurvInterpolationType.Const || left.Time == right.Time)
     {
         return(val);
     }
     else if (interpMode == GOECurvInterpolationType.Linear)
     {
         float durance = right.Time - left.Time;
         if (0 == durance)
         {
             return(val);
         }
         else
         {
             float factor = (t - left.Time) / durance;
             return(val * (1 - factor) + val2 * factor);
         }
     }
     else if (interpMode == GOECurvInterpolationType.Bezier)
     {
         float x = SampleBezierByTime(t, left, right, val.x, val2.x);
         float y = SampleBezierByTime(t, left, right, val.y, val2.y);
         float z = SampleBezierByTime(t, left, right, val.z, val2.z);
     }
     return(val);
 }
Beispiel #2
0
        public void SampleByTime(float t, out Vector3 pos, out Quaternion q, out Vector3 s)
        {
            int left = 0, right = 0;

            pos = Vector3.zero;
            q   = Quaternion.identity;
            s   = Vector3.one;
            GOECurveFindIndexResults b = FindIndexByTime(t, out left, out right);

            if (b > GOECurveFindIndexResults.FailedNoKeyFrame)
            {
                GOECurvKeyFrame          l          = keyFrames[left];
                GOECurvKeyFrame          r          = keyFrames[right];
                GOECurvInterpolationType interpMode = l.PositionInterpolationType;
                pos = SampleKeyByTime(t, l, r, interpMode, l.Position, r.Position);

                interpMode = l.RotationInterpolationType;

                if (interpMode == GOECurvInterpolationType.Const || left == right)
                {
                    q = l.Rotation;
                }
                else if (interpMode == GOECurvInterpolationType.Linear)
                {
                    Quaternion ql, qr;
                    ql = l.Rotation;
                    qr = r.Rotation;
                    q  = Quaternion.Slerp(ql, qr, (t - l.Time) / (r.Time - l.Time));
                }

                interpMode = l.ScaleInterpolationType;
                s          = SampleKeyByTime(t, l, r, interpMode, l.Scale, r.Scale);
            }
        }
Beispiel #3
0
        public void AddKey(float time, ref Vector3 vp, ref Quaternion vr, ref Vector3 vs, GOECurvInterpolationType pt = GOECurvInterpolationType.Linear, GOECurvInterpolationType rt = GOECurvInterpolationType.Linear, GOECurvInterpolationType st = GOECurvInterpolationType.Linear)
        {
            GOECurvKeyFrame kf = new GOECurvKeyFrame();

            kf.Time     = time;
            kf.Position = vp;
            kf.Rotation = vr;
            kf.Scale    = vs;
            kf.PositionInterpolationType = pt;
            kf.RotationInterpolationType = rt;
            kf.ScaleInterpolationType    = st;

            int left, right;
            GOECurveFindIndexResults b = FindIndexByTime(time, out left, out right);

            if (b == GOECurveFindIndexResults.AfterAllKeyFrame || b == GOECurveFindIndexResults.FailedNoKeyFrame)
            {
                keyFrames.Add(kf);
            }
            else if (b == GOECurveFindIndexResults.BeforeAllKeyFrame)
            {
                KeyFrames.Insert(0, kf);
            }
            else
            {
                keyFrames.Insert(left + 1, kf);
            }

            if (EditorGameObject)
            {
                kf.EnsureEditorGO(EditorGameObject);
                UnityEditor.Selection.activeGameObject = kf.EditorGameObject;
            }
        }
Beispiel #4
0
        public void SampleByIndex(int idx, ref Vector3 pos, ref Quaternion q, ref Vector3 s)
        {
            GOECurvKeyFrame frame = keyFrames[idx];

            pos = frame.Position;
            q   = frame.Rotation;
            s   = frame.Scale;
        }
Beispiel #5
0
        public void SampleByIndex2(int idx, ref Vector3 pos, ref Quaternion q, ref Vector3 s,
                                   ref GOECurvInterpolationType posInterpMode, ref GOECurvInterpolationType rotInterpMode, ref GOECurvInterpolationType scaleInterpMode)
        {
            SampleByIndex(idx, ref pos, ref q, ref s);
            GOECurvKeyFrame frame = keyFrames[idx];

            posInterpMode   = frame.PositionInterpolationType;
            rotInterpMode   = frame.RotationInterpolationType;
            scaleInterpMode = frame.ScaleInterpolationType;
        }
Beispiel #6
0
        public void MoveKey(int keyIdx, float time)
        {
            GOECurvKeyFrame kf = keyFrames[keyIdx];

            kf.Time = time;
            keyFrames.RemoveAt(keyIdx);

            int left, right;
            GOECurveFindIndexResults b = FindIndexByTime(time, out left, out right);

            if (b == GOECurveFindIndexResults.AfterAllKeyFrame || b == GOECurveFindIndexResults.FailedNoKeyFrame)
            {
                keyFrames.Add(kf);
            }
            else
            {
                keyFrames.Insert(left + 1, kf);
            }
        }
Beispiel #7
0
        float SampleBezierByTime(float t, GOECurvKeyFrame left, GOECurvKeyFrame right, float val, float val2)
        {
            Vector2 v0      = new Vector2(left.Time, val);
            Vector2 v3      = new Vector2(right.Time, val2);
            float   durance = right.Time - left.Time;
            float   diff    = val2 - val;
            float   len     = Vector2.Distance(v0, v3);
            float   l       = len / 2;//使用1/4作为切线控制点长度//
            Vector2 v1      = new Vector2(1, left.OutTangent);

            v1 = v0 + v1.normalized * l;
            Vector2 v2 = new Vector2(1, right.InTangent);

            v2 = v3 - v2.normalized * l;
            float   a = (t - left.Time) / durance;
            float   b = 1 - a;
            Vector2 v = v0 * b * b * b + 3 * v1 * a * b * b + 3 * v2 * a * a * b + v3 * a * a * a;

            return(v.y);
        }