Add highlighting active state in anim graph

This commit is contained in:
2024-02-07 19:31:34 +01:00
parent cfb8350c65
commit eed780a0b0
3 changed files with 37 additions and 5 deletions
@@ -653,6 +653,7 @@ namespace FlaxEditor.Surface.Archetypes
protected Rectangle _renameButtonRect;
private bool _cursorChanged = false;
private bool _textRectHovered = false;
private bool _debugActive;
/// <summary>
/// The transitions list from this state to the others.
@@ -1090,6 +1091,16 @@ namespace FlaxEditor.Surface.Archetypes
// TODO: maybe update only on actual transitions change?
UpdateTransitions();
// Debug current state
if (((AnimGraphSurface)Surface).TryGetTraceEvent(this, out var traceEvent))
{
_debugActive = true;
}
else
{
_debugActive = false;
}
}
/// <inheritdoc />
@@ -1130,6 +1141,10 @@ namespace FlaxEditor.Surface.Archetypes
// Close button
Render2D.DrawSprite(style.Cross, _closeButtonRect, _closeButtonRect.Contains(_mousePosition) ? style.Foreground : style.ForegroundGrey);
// Debug outline
if (_debugActive)
Render2D.DrawRectangle(_textRect.MakeExpanded(1.0f), style.ProgressNormal);
}
/// <inheritdoc />
@@ -803,6 +803,8 @@ struct AnimGraphContext
ChunkedArray<AnimGraphImpulse, 256> PoseCache;
int32 PoseCacheSize;
Dictionary<VisjectExecutor::Box*, Variant> ValueCache;
AnimGraphTraceEvent& AddTraceEvent(const AnimGraphNode* node);
};
/// <summary>
@@ -52,6 +52,17 @@ void RetargetSkeletonNode(const SkeletonData& sourceSkeleton, const SkeletonData
node = value;
}
AnimGraphTraceEvent& AnimGraphContext::AddTraceEvent(const AnimGraphNode* node)
{
auto& trace = Data->TraceEvents.AddOne();
trace.Value = 0.0f;
trace.NodeId = node->ID;
const auto* nodePath = NodePath.Get();
for (int32 i = 0; i < NodePath.Count(); i++)
trace.NodePath[i] = nodePath[i];
return trace;
}
int32 AnimGraphExecutor::GetRootNodeIndex(Animation* anim)
{
// TODO: cache the root node index (use dictionary with Animation* -> int32 for fast lookups)
@@ -223,13 +234,9 @@ void AnimGraphExecutor::ProcessAnimation(AnimGraphImpulse* nodes, AnimGraphNode*
auto& context = Context.Get();
if (context.Data->EnableTracing)
{
auto& trace = context.Data->TraceEvents.AddOne();
auto& trace = context.AddTraceEvent(node);
trace.Asset = anim;
trace.Value = animPos;
trace.NodeId = node->ID;
const auto* nodePath = context.NodePath.Get();
for (int32 i = 0; i < context.NodePath.Count(); i++)
trace.NodePath[i] = nodePath[i];
}
// Evaluate nested animations
@@ -502,11 +509,19 @@ Variant AnimGraphExecutor::SampleState(AnimGraphContext& context, const AnimGrap
auto& data = state->Data.State;
if (data.Graph == nullptr || data.Graph->GetRootNode() == nullptr)
return Value::Null;
// Add to trace
if (context.Data->EnableTracing)
{
auto& trace = context.AddTraceEvent(state);
}
ANIM_GRAPH_PROFILE_EVENT("Evaluate State");
context.NodePath.Add(state->ID);
auto rootNode = data.Graph->GetRootNode();
auto result = eatBox((Node*)rootNode, &rootNode->Boxes[0]);
context.NodePath.Pop();
return result;
}