Add minor improvement to anim graph editing

This commit is contained in:
Wojtek Figat
2025-03-29 22:33:31 +01:00
parent 5bee99cb93
commit 4c133fb6ff
5 changed files with 37 additions and 3 deletions

View File

@@ -570,7 +570,7 @@ namespace FlaxEditor.Surface.Archetypes
var icon = Editor.Instance.Icons.VisjectBoxOpen32;
var size = BlendPoint.DefaultSize * _debugScale;
var debugPos = BlendSpacePosToBlendPointPos(_debugPos);
var debugRect = new Rectangle(debugPos + new Float2(size * -0.5f) + size * 0.5f, new Float2(size));
var debugRect = new Rectangle(debugPos + new Float2(size * -0.5f), new Float2(size));
var outline = Color.Black; // Shadow
Render2D.DrawSprite(icon, debugRect.MakeExpanded(2.0f), outline);
Render2D.DrawSprite(icon, debugRect, style.ProgressNormal);

View File

@@ -228,6 +228,13 @@ namespace FlaxEditor.Surface
/// </summary>
protected virtual void OnContextChanged()
{
// Cache viewport of the context (used to restore when leaving it)
if (_context != null)
{
_context._cachedViewCenterPosition = ViewCenterPosition;
_context._cachedViewScale = ViewScale;
}
var context = ContextStack.Count > 0 ? ContextStack.Peek() : null;
_context = context;
if (ContextStack.Count == 0)
@@ -249,6 +256,18 @@ namespace FlaxEditor.Surface
}
ContextChanged?.Invoke(_context);
// Restore viewport in the context
if (_context?._cachedViewScale > 0.0f)
{
ViewScale = _context._cachedViewScale;
ViewCenterPosition = _context._cachedViewCenterPosition;
}
else
{
// Show whole surface on load
ShowWholeGraph();
}
}
}
}

View File

@@ -29,6 +29,8 @@ namespace FlaxEditor.Surface
private bool _isModified;
private VisjectSurface _surface;
private SurfaceMeta _meta = new SurfaceMeta();
internal Float2 _cachedViewCenterPosition;
internal float _cachedViewScale = -1; // Negative scale to indicate missing data (will show whole surface on start)
/// <summary>
/// The parent context. Defines the higher key surface graph context. May be null for the top-level context.

View File

@@ -371,6 +371,9 @@ namespace FlaxEditor.Windows.Assets
// Update navbar
_surface.UpdateNavigationBar(_navigationBar, _toolstrip);
// Show whole model
_preview.ResetCamera();
return false;
}
@@ -437,6 +440,16 @@ namespace FlaxEditor.Windows.Assets
_debugFlows.Clear();
}
// Update preview values when debugging specific instance
if (debugActor != null && debugActor != _preview.PreviewActor)
{
var parameters = debugActor.Parameters;
foreach (var p in parameters)
{
_preview.PreviewActor.SetParameterValue(p.Identifier, p.Value);
}
}
_showNodesButton.Checked = _preview.ShowNodes;
}

View File

@@ -67,7 +67,7 @@ public:
/// <param name="predicate">The prediction function. Should return true for the target element to find.</param>
/// <returns>The first found item or default value if nothing found.</returns>
template<typename T, typename AllocationType>
static T First(const Array<T, AllocationType>& obj, const Function<bool(const T&)> predicate)
static T First(const Array<T, AllocationType>& obj, const Function<bool(const T&)>& predicate)
{
for (int32 i = 0; i < obj.Count(); i++)
{
@@ -84,7 +84,7 @@ public:
/// <param name="predicate">The prediction function. Should return true for the target element to find.</param>
/// <returns>The first found item or default value if nothing found.</returns>
template<typename T, typename AllocationType>
static T* First(const Array<T*, AllocationType>& obj, const Function<bool(const T*)> predicate)
static T* First(const Array<T*, AllocationType>& obj, const Function<bool(const T*)>& predicate)
{
for (int32 i = 0; i < obj.Count(); i++)
{