Explorar o código

Keyframes on the edge of the draw area can now be selected more easily
Scene object that doesn't already have an animation component will no longer be reset to a state without the component, if it was added within the editor
Ensure curve is evaluated properly when time is equal to the last keyframe

BearishSun %!s(int64=9) %!d(string=hai) anos
pai
achega
981f94b63f

+ 9 - 10
Source/BansheeCore/Source/BsAnimation.cpp

@@ -936,6 +936,15 @@ namespace BansheeEngine
 			if (clipInfo.clip == clip)
 			if (clipInfo.clip == clip)
 			{
 			{
 				state = clipInfo.state;
 				state = clipInfo.state;
+
+				// Internally we store unclamped time, so clamp/loop it
+				float clipLength = 0.0f;
+				if (clip.isLoaded())
+					clipLength = clip->getLength();
+
+				bool loop = clipInfo.state.wrapMode == AnimWrapMode::Loop;
+				AnimationUtility::wrapTime(clipInfo.state.time, 0.0f, clipLength, loop);
+
 				return true;
 				return true;
 			}
 			}
 		}
 		}
@@ -950,13 +959,6 @@ namespace BansheeEngine
 		if (clipInfo == nullptr)
 		if (clipInfo == nullptr)
 			return;
 			return;
 
 
-		float clipLength = 0.0f;
-		if (clip.isLoaded())
-			clipLength = clip->getLength();
-
-		bool loop = state.wrapMode == AnimWrapMode::Loop;
-		AnimationUtility::wrapTime(state.time, 0.0f, clipLength, loop);
-
 		clipInfo->state = state;
 		clipInfo->state = state;
 		mDirty |= AnimDirtyStateFlag::Value;
 		mDirty |= AnimDirtyStateFlag::Value;
 	}
 	}
@@ -1063,9 +1065,6 @@ namespace BansheeEngine
 				clipLength = clip->getLength();
 				clipLength = clip->getLength();
 			}
 			}
 
 
-			bool loop = clipInfo.state.wrapMode == AnimWrapMode::Loop;
-			AnimationUtility::wrapTime(clipInfo.state.time, 0.0f, clipLength, loop);
-
 			float fadeTime = clipInfo.fadeTime + scaledTimeDelta;
 			float fadeTime = clipInfo.fadeTime + scaledTimeDelta;
 			clipInfo.fadeTime = Math::clamp(fadeTime, 0.0f, clipInfo.fadeLength);
 			clipInfo.fadeTime = Math::clamp(fadeTime, 0.0f, clipInfo.fadeLength);
 		}
 		}

+ 2 - 2
Source/BansheeCore/Source/BsAnimationCurve.cpp

@@ -215,7 +215,7 @@ namespace BansheeEngine
 			return evaluateCache(time, cache);
 			return evaluateCache(time, cache);
 
 
 		// Clamp to start, cache constant of the first key and return
 		// Clamp to start, cache constant of the first key and return
-		if(time < mStart || mKeyframes.size() == 1)
+		if(time < mStart)
 		{
 		{
 			cache.cachedCurveStart = -std::numeric_limits<float>::infinity();
 			cache.cachedCurveStart = -std::numeric_limits<float>::infinity();
 			cache.cachedCurveEnd = mStart;
 			cache.cachedCurveEnd = mStart;
@@ -228,7 +228,7 @@ namespace BansheeEngine
 			return mKeyframes[0].value;
 			return mKeyframes[0].value;
 		}
 		}
 		
 		
-		if(time > mEnd) // Clamp to end, cache constant of the final key and return
+		if(time >= mEnd) // Clamp to end, cache constant of the final key and return
 		{
 		{
 			UINT32 lastKey = (UINT32)mKeyframes.size() - 1;
 			UINT32 lastKey = (UINT32)mKeyframes.size() - 1;
 
 

+ 9 - 3
Source/MBansheeEditor/Windows/Animation/GUICurveDrawing.cs

@@ -215,14 +215,20 @@ namespace BansheeEditor
         /// <param name="pixelCoords">Coordinates relative to this GUI element, in pixels.</param>
         /// <param name="pixelCoords">Coordinates relative to this GUI element, in pixels.</param>
         /// <param name="curveCoords">Curve coordinates within the range as specified by <see cref="SetRange"/>. Only
         /// <param name="curveCoords">Curve coordinates within the range as specified by <see cref="SetRange"/>. Only
         ///                           valid when function returns true.</param>
         ///                           valid when function returns true.</param>
+        /// <param name="padding">Determines should coordinates over padding be registered.</param>
         /// <returns>True if the coordinates are within the curve area, false otherwise.</returns>
         /// <returns>True if the coordinates are within the curve area, false otherwise.</returns>
-        public bool PixelToCurveSpace(Vector2I pixelCoords, out Vector2 curveCoords)
+        public bool PixelToCurveSpace(Vector2I pixelCoords, out Vector2 curveCoords, bool padding = false)
         {
         {
             Rect2I bounds = canvas.Bounds;
             Rect2I bounds = canvas.Bounds;
 
 
+            bool outsideHorizontal;
+            if (padding)
+                outsideHorizontal = pixelCoords.x < bounds.x || pixelCoords.x >= (bounds.x + bounds.width);
+            else
+                outsideHorizontal = pixelCoords.x < (bounds.x + PADDING) || pixelCoords.x >= (bounds.x + bounds.width - PADDING);
+
             // Check if outside of curve drawing bounds
             // Check if outside of curve drawing bounds
-            if (pixelCoords.x < (bounds.x + PADDING) || pixelCoords.x >= (bounds.x + bounds.width - PADDING) ||
-                pixelCoords.y < bounds.y || pixelCoords.y >= (bounds.y + bounds.height))
+            if (outsideHorizontal || pixelCoords.y < bounds.y || pixelCoords.y >= (bounds.y + bounds.height))
             {
             {
                 curveCoords = new Vector2();
                 curveCoords = new Vector2();
                 return false;
                 return false;

+ 6 - 18
Source/MBansheeEditor/Windows/Animation/GUICurveEditor.cs

@@ -303,18 +303,6 @@ namespace BansheeEditor
             guiSidebar.SetRange(-10.0f, 10.0f);
             guiSidebar.SetRange(-10.0f, 10.0f);
         }
         }
 
 
-        /// <summary>
-        /// Converts pixel coordinates relative to the curve drawing area into coordinates in curve space.
-        /// </summary>
-        /// <param name="pixelCoords">Coordinates relative to this GUI element, in pixels.</param>
-        /// <param name="curveCoords">Curve coordinates within the range as specified by <see cref="Range"/>. Only
-        ///                           valid when function returns true.</param>
-        /// <returns>True if the coordinates are within the curve area, false otherwise.</returns>
-        public bool PixelToCurveSpace(Vector2I pixelCoords, out Vector2 curveCoords)
-        {
-            return guiCurveDrawing.PixelToCurveSpace(pixelCoords, out curveCoords);
-        }
-
         /// <summary>
         /// <summary>
         /// Converts coordinate in curve space (time, value) into pixel coordinates relative to the curve drawing area
         /// Converts coordinate in curve space (time, value) into pixel coordinates relative to the curve drawing area
         /// origin.
         /// origin.
@@ -373,7 +361,7 @@ namespace BansheeEditor
             if (ev.Button == PointerButton.Left)
             if (ev.Button == PointerButton.Left)
             {
             {
                 Vector2 curveCoord;
                 Vector2 curveCoord;
-                if (guiCurveDrawing.PixelToCurveSpace(drawingPos, out curveCoord))
+                if (guiCurveDrawing.PixelToCurveSpace(drawingPos, out curveCoord, true))
                 {
                 {
                     KeyframeRef keyframeRef;
                     KeyframeRef keyframeRef;
                     if (!guiCurveDrawing.FindKeyFrame(drawingPos, out keyframeRef))
                     if (!guiCurveDrawing.FindKeyFrame(drawingPos, out keyframeRef))
@@ -439,7 +427,7 @@ namespace BansheeEditor
             else if (ev.Button == PointerButton.Right)
             else if (ev.Button == PointerButton.Right)
             {
             {
                 Vector2 curveCoord;
                 Vector2 curveCoord;
-                if (guiCurveDrawing.PixelToCurveSpace(drawingPos, out curveCoord))
+                if (guiCurveDrawing.PixelToCurveSpace(drawingPos, out curveCoord, true))
                 {
                 {
                     contextClickPosition = drawingPos;
                     contextClickPosition = drawingPos;
 
 
@@ -556,10 +544,10 @@ namespace BansheeEditor
                             Vector2 diff = Vector2.Zero;
                             Vector2 diff = Vector2.Zero;
 
 
                             Vector2 dragStartCurve;
                             Vector2 dragStartCurve;
-                            if (guiCurveDrawing.PixelToCurveSpace(dragStart, out dragStartCurve))
+                            if (guiCurveDrawing.PixelToCurveSpace(dragStart, out dragStartCurve, true))
                             {
                             {
                                 Vector2 currentPosCurve;
                                 Vector2 currentPosCurve;
-                                if (guiCurveDrawing.PixelToCurveSpace(drawingPos, out currentPosCurve))
+                                if (guiCurveDrawing.PixelToCurveSpace(drawingPos, out currentPosCurve, true))
                                     diff = currentPosCurve - dragStartCurve;
                                     diff = currentPosCurve - dragStartCurve;
                             }
                             }
 
 
@@ -571,7 +559,7 @@ namespace BansheeEditor
                                 {
                                 {
                                     DraggedKeyframe draggedKey = draggedEntry.keys[i];
                                     DraggedKeyframe draggedKey = draggedEntry.keys[i];
 
 
-                                    float newTime = draggedKey.original.time + diff.x;
+                                    float newTime = Math.Max(0.0f, draggedKey.original.time + diff.x);
                                     float newValue = draggedKey.original.value + diff.y;
                                     float newValue = draggedKey.original.value + diff.y;
 
 
                                     int newIndex = curve.UpdateKeyframe(draggedKey.index, newTime, newValue);
                                     int newIndex = curve.UpdateKeyframe(draggedKey.index, newTime, newValue);
@@ -606,7 +594,7 @@ namespace BansheeEditor
                             Vector2 keyframeCurveCoords = new Vector2(keyframe.time, keyframe.value);
                             Vector2 keyframeCurveCoords = new Vector2(keyframe.time, keyframe.value);
 
 
                             Vector2 currentPosCurve;
                             Vector2 currentPosCurve;
-                            if (guiCurveDrawing.PixelToCurveSpace(drawingPos, out currentPosCurve))
+                            if (guiCurveDrawing.PixelToCurveSpace(drawingPos, out currentPosCurve, true))
                             {
                             {
                                 Vector2 normal = currentPosCurve - keyframeCurveCoords;
                                 Vector2 normal = currentPosCurve - keyframeCurveCoords;
                                 normal = normal.Normalized;
                                 normal = normal.Normalized;

+ 5 - 4
Source/MBansheeEditor/Windows/AnimationWindow.cs

@@ -256,8 +256,6 @@ namespace BansheeEditor
                     fieldSelection.OnFieldSelected += OnFieldAdded;
                     fieldSelection.OnFieldSelected += OnFieldAdded;
                 };
                 };
 
 
-                SwitchState(State.Normal);
-
                 if (clipInfo.clip == null)
                 if (clipInfo.clip == null)
                 {
                 {
                     LocEdString title = new LocEdString("Warning");
                     LocEdString title = new LocEdString("Warning");
@@ -272,6 +270,7 @@ namespace BansheeEditor
                             string clipSavePath;
                             string clipSavePath;
                             if (BrowseDialog.SaveFile(ProjectLibrary.ResourceFolder, "*.asset", out clipSavePath))
                             if (BrowseDialog.SaveFile(ProjectLibrary.ResourceFolder, "*.asset", out clipSavePath))
                             {
                             {
+                                SwitchState(State.Empty);
                                 clipSavePath = Path.ChangeExtension(clipSavePath, ".asset");
                                 clipSavePath = Path.ChangeExtension(clipSavePath, ".asset");
 
 
                                 AnimationClip newClip = new AnimationClip();
                                 AnimationClip newClip = new AnimationClip();
@@ -286,8 +285,7 @@ namespace BansheeEditor
                                 animation.DefaultClip = newClip;
                                 animation.DefaultClip = newClip;
                                 EditorApplication.SetSceneDirty();
                                 EditorApplication.SetSceneDirty();
 
 
-                                soState = new SerializedSceneObject(selectedSO, true);
-
+                                SwitchState(State.Normal);
                                 openPropertyWindow();
                                 openPropertyWindow();
                             }
                             }
                         }
                         }
@@ -305,7 +303,10 @@ namespace BansheeEditor
                         DialogBox.Open(title, message, DialogBox.Type.OK);
                         DialogBox.Open(title, message, DialogBox.Type.OK);
                     }
                     }
                     else
                     else
+                    {
+                        SwitchState(State.Normal);
                         openPropertyWindow();
                         openPropertyWindow();
+                    }
                 }
                 }
             };
             };