Ver Fonte

Bugfix: When adding a new keyframe, don't add duplicate keyframes at the same time as existing ones
- Instead just update existing keyframe values

BearishSun há 7 anos atrás
pai
commit
59d952db8a

+ 24 - 0
Source/Scripting/MBansheeEditor/Utility/EdAnimationCurve.cs

@@ -150,6 +150,30 @@ namespace BansheeEditor
             return native.Evaluate(time, loop);
             return native.Evaluate(time, loop);
         }
         }
 
 
+        /// <summary>
+        /// Adds a new keyframe to the animation curve, unless a keyframe with the same time already exists in which case
+        /// the existing keyframe is updated with the new value. Newly added keyframe will use the automatic tangent mode.
+        /// </summary>
+        /// <param name="time">Time at which to add/update the keyframe.</param>
+        /// <param name="value">Value of the keyframe.</param>
+        internal void AddOrUpdateKeyframe(float time, float value)
+        {
+            int keyframeIdx = -1;
+            for (int i = 0; i < keyFrames.Length; i++)
+            {
+                if (MathEx.ApproxEquals(keyFrames[i].time, time))
+                {
+                    keyframeIdx = i;
+                    break;
+                }
+            }
+
+            if (keyframeIdx != -1)
+                UpdateKeyframe(keyframeIdx, time, value);
+            else
+                AddKeyframe(time, value);
+        }
+
         /// <summary>
         /// <summary>
         /// Adds a new keyframe to the animation curve. Keyframe will use the automatic tangent mode.
         /// Adds a new keyframe to the animation curve. Keyframe will use the automatic tangent mode.
         /// </summary>
         /// </summary>

+ 2 - 2
Source/Scripting/MBansheeEditor/Windows/Animation/GUICurveEditor.cs

@@ -757,7 +757,7 @@ namespace BansheeEditor
                     float t = guiCurveDrawing.GetTimeForFrame(markedFrameIdx);
                     float t = guiCurveDrawing.GetTimeForFrame(markedFrameIdx);
                     float value = curveInfo.curve.Evaluate(t);
                     float value = curveInfo.curve.Evaluate(t);
 
 
-                    curveInfo.curve.AddKeyframe(t, value);
+                    curveInfo.curve.AddOrUpdateKeyframe(t, value);
                     curveInfo.curve.Apply();
                     curveInfo.curve.Apply();
                 }
                 }
             }
             }
@@ -894,7 +894,7 @@ namespace BansheeEditor
                         float t = curveCoord.x;
                         float t = curveCoord.x;
                         float value = curveCoord.y;
                         float value = curveCoord.y;
 
 
-                        curveInfo.curve.AddKeyframe(t, value);
+                        curveInfo.curve.AddOrUpdateKeyframe(t, value);
                         curveInfo.curve.Apply();
                         curveInfo.curve.Apply();
                     }
                     }
                 }
                 }

+ 2 - 16
Source/Scripting/MBansheeEditor/Windows/AnimationWindow.cs

@@ -1182,23 +1182,9 @@ namespace BansheeEditor
                 float curveVal = curve.Evaluate(time);
                 float curveVal = curve.Evaluate(time);
                 if (!MathEx.ApproxEquals(value, curveVal, 0.001f))
                 if (!MathEx.ApproxEquals(value, curveVal, 0.001f))
                 {
                 {
-                    KeyFrame[] keyframes = curve.KeyFrames;
-                    int keyframeIdx = -1;
-                    for (int i = 0; i < keyframes.Length; i++)
-                    {
-                        if (MathEx.ApproxEquals(keyframes[i].time, time))
-                        {
-                            keyframeIdx = i;
-                            break;
-                        }
-                    }
-
-                    if (keyframeIdx != -1)
-                        curve.UpdateKeyframe(keyframeIdx, time, value);
-                    else
-                        curve.AddKeyframe(time, value);
-
+                    curve.AddOrUpdateKeyframe(time, value);
                     curve.Apply();
                     curve.Apply();
+
                     changesMade = true;
                     changesMade = true;
                 }
                 }
             }
             }