Просмотр исходного кода

Animation editor: - Ability to drag and freely modify keyframe tangents

BearishSun 9 лет назад
Родитель
Сommit
ea7306e729

+ 1 - 1
Source/MBansheeEditor/Utility/EdAnimationCurve.cs

@@ -221,7 +221,7 @@ namespace BansheeEditor
             float length = 1/normal.x;
 
             // Use length to deduce the tangent (y coordinate)
-            return MathEx.Sqrt(length*length - 1);
+            return MathEx.Sqrt(length*length - 1) * MathEx.Sign(normal.y);
         }
 
         internal void Apply()

+ 34 - 4
Source/MBansheeEditor/Windows/Animation/GUICurveEditor.cs

@@ -127,8 +127,6 @@ namespace BansheeEditor
                     KeyframeRef keyframeRef;
                     if (!guiCurveDrawing.FindKeyFrame(drawingPos, out keyframeRef))
                     {
-                        ClearSelection();
-
                         TangentRef tangentRef;
                         if (guiCurveDrawing.FindTangent(drawingPos, out tangentRef))
                         {
@@ -136,6 +134,8 @@ namespace BansheeEditor
                             dragStart = drawingPos;
                             draggedTangent = tangentRef;
                         }
+                        else
+                            ClearSelection();
                     }
                     else
                     {
@@ -287,9 +287,39 @@ namespace BansheeEditor
                         }
                         else if (isMousePressedOverTangent)
                         {
-                            // TODO - Update tangent
+                            EdAnimationCurve curve = curves[draggedTangent.keyframeRef.curveIdx];
+                            KeyFrame keyframe = curve.KeyFrames[draggedTangent.keyframeRef.keyIdx];
 
-                            guiCurveDrawing.Rebuild();
+                            Vector2 keyframeCurveCoords = new Vector2(keyframe.time, keyframe.value);
+
+                            Vector2 currentPosCurve;
+                            if (guiCurveDrawing.PixelToCurveSpace(drawingPos, out currentPosCurve))
+                            {
+                                Vector2 normal = currentPosCurve - keyframeCurveCoords;
+                                normal = normal.Normalized;
+
+                                float tangent = EdAnimationCurve.NormalToTangent(normal);
+
+                                if (draggedTangent.type == TangentType.In)
+                                {
+                                    if (normal.x > 0.0f)
+                                        tangent = float.PositiveInfinity;
+
+                                    keyframe.inTangent = tangent;
+                                }
+                                else
+                                {
+                                    if (normal.x < 0.0f)
+                                        tangent = float.PositiveInfinity;
+
+                                    keyframe.outTangent = tangent;
+                                }
+
+                                curve.KeyFrames[draggedTangent.keyframeRef.keyIdx] = keyframe;
+                                curve.Apply();
+
+                                guiCurveDrawing.Rebuild();
+                            }
                         }
                     }
                 }