Fix anim graph debugging to handle nested graph connections highlights properly

This commit is contained in:
Wojtek Figat
2024-02-07 19:22:07 +01:00
parent a38d1ad7cc
commit cfb8350c65
7 changed files with 67 additions and 20 deletions

View File

@@ -134,12 +134,7 @@ namespace FlaxEditor.Surface
// Follow input node contexts path to verify if it matches with the path in the event
var c = node.Context;
for (int i = nodePathSize - 1; i >= 0 && c != null; i--)
{
if (c.OwnerNodeID != nodePath[i])
c = null;
else
c = c.Parent;
}
c = c.OwnerNodeID == nodePath[i] ? c.Parent : null;
if (c != null)
{
traceEvent = e;

View File

@@ -33,6 +33,30 @@ namespace FlaxEditor.Surface
/// </summary>
public event Action<VisjectSurfaceContext> ContextChanged;
/// <summary>
/// Finds the surface context with the given owning nodes IDs path.
/// </summary>
/// <param name="nodePath">The node ids path.</param>
/// <returns>Found context or null if cannot.</returns>
public VisjectSurfaceContext FindContext(Span<uint> nodePath)
{
// Get size of the path
int nodePathSize = 0;
while (nodePathSize < nodePath.Length && nodePath[nodePathSize] != 0)
nodePathSize++;
// Follow each context path to verify if it matches with the path in the input path
foreach (var e in _contextCache)
{
var c = e.Value;
for (int i = nodePathSize - 1; i >= 0 && c != null; i--)
c = c.OwnerNodeID == nodePath[i] ? c.Parent : null;
if (c != null)
return e.Value;
}
return null;
}
/// <summary>
/// Creates the Visject surface context for the given surface data source context.
/// </summary>

View File

@@ -154,10 +154,11 @@ namespace FlaxEditor.Windows.Assets
}
[StructLayout(LayoutKind.Sequential)]
private struct AnimGraphDebugFlowInfo
private unsafe struct AnimGraphDebugFlowInfo
{
public uint NodeId;
public int BoxId;
public fixed uint NodePath[8];
}
private FlaxObjectRefPickerControl _debugPicker;
@@ -252,25 +253,26 @@ namespace FlaxEditor.Windows.Assets
return obj is AnimatedModel player && player.AnimationGraph == OriginalAsset;
}
private void OnDebugFlow(Asset asset, Object obj, uint nodeId, uint boxId)
private unsafe void OnDebugFlow(Animations.DebugFlowInfo flowInfo)
{
// Filter the flow
if (_debugPicker.Value != null)
{
if (asset != OriginalAsset || _debugPicker.Value != obj)
if (flowInfo.Asset != OriginalAsset || _debugPicker.Value != flowInfo.Instance)
return;
}
else
{
if (asset != Asset || _preview.PreviewActor != obj)
if (flowInfo.Asset != Asset || _preview.PreviewActor != flowInfo.Instance)
return;
}
// Register flow to show it in UI on a surface
var flowInfo = new AnimGraphDebugFlowInfo { NodeId = nodeId, BoxId = (int)boxId };
var flow = new AnimGraphDebugFlowInfo { NodeId = flowInfo.NodeId, BoxId = (int)flowInfo.BoxId };
Utils.MemoryCopy(new IntPtr(flow.NodePath), new IntPtr(flowInfo.NodePath0), sizeof(uint) * 8ul);
lock (_debugFlows)
{
_debugFlows.Add(flowInfo);
_debugFlows.Add(flow);
}
}
@@ -394,7 +396,7 @@ namespace FlaxEditor.Windows.Assets
}
/// <inheritdoc />
public override void OnUpdate()
public override unsafe void OnUpdate()
{
// Extract animations playback state from the events tracing
var debugActor = _debugPicker.Value as AnimatedModel;
@@ -413,7 +415,8 @@ namespace FlaxEditor.Windows.Assets
{
foreach (var debugFlow in _debugFlows)
{
var node = Surface.Context.FindNode(debugFlow.NodeId);
var context = Surface.FindContext(new Span<uint>(debugFlow.NodePath, 8));
var node = context?.FindNode(debugFlow.NodeId);
var box = node?.GetBox(debugFlow.BoxId);
box?.HighlightConnections();
}