From 330049d732daf239eacdbc3a8655412944fafe22 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 10 Apr 2026 10:48:45 +0200 Subject: [PATCH] Cleanup anim graph nodes access to share code --- Source/Engine/Animations/Graph/AnimGraph.cpp | 17 ++++++ Source/Engine/Animations/Graph/AnimGraph.h | 10 +++- .../Animations/Graph/AnimGroup.Animation.cpp | 54 ++----------------- 3 files changed, 30 insertions(+), 51 deletions(-) diff --git a/Source/Engine/Animations/Graph/AnimGraph.cpp b/Source/Engine/Animations/Graph/AnimGraph.cpp index 3c2630b51..38f802ec8 100644 --- a/Source/Engine/Animations/Graph/AnimGraph.cpp +++ b/Source/Engine/Animations/Graph/AnimGraph.cpp @@ -142,6 +142,23 @@ AnimGraphImpulse* AnimGraphNode::GetNodes(AnimGraphExecutor* executor) return &nodes; } +AnimGraphImpulse* AnimGraphNode::GetNodes(AnimGraphExecutor* executor, Variant& input) +{ + const auto nodes = GetNodes(executor); + if (ANIM_GRAPH_IS_VALID_PTR(input)) + { + // Use input nodes + executor->CopyNodes(nodes, input); + } + else + { + // Use default nodes + executor->InitNodes(nodes); + input = nodes; + } + return nodes; +} + bool AnimGraph::Load(ReadStream* stream, bool loadMeta) { Version++; diff --git a/Source/Engine/Animations/Graph/AnimGraph.h b/Source/Engine/Animations/Graph/AnimGraph.h index 051f6613d..ac429bd36 100644 --- a/Source/Engine/Animations/Graph/AnimGraph.h +++ b/Source/Engine/Animations/Graph/AnimGraph.h @@ -555,11 +555,19 @@ public: public: /// - /// Gets the per-node node transformations cache (cached). + /// Gets the per-node node transformations (cached). /// /// The Graph execution context. /// Nodes data. AnimGraphImpulse* GetNodes(AnimGraphExecutor* executor); + + /// + /// Gets the per-node node transformations (cached) and initializes the nodes. + /// + /// The Graph execution context. + /// The input nodes to copy. If input is invalid then reference is used to initialize the nodes. + /// Nodes data. + AnimGraphImpulse* GetNodes(AnimGraphExecutor* executor, Variant& input); }; /// diff --git a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp index 7eb8d32d6..eb72d9788 100644 --- a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp +++ b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp @@ -1212,18 +1212,7 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu // [Deprecated on 13.05.2020, expires on 13.05.2021] // Get input auto input = tryGetValue(node->GetBox(1), Value::Null); - const auto nodes = node->GetNodes(this); - if (ANIM_GRAPH_IS_VALID_PTR(input)) - { - // Use input nodes - CopyNodes(nodes, input); - } - else - { - // Use default nodes - InitNodes(nodes); - input = nodes; - } + const auto nodes = node->GetNodes(this, input); // Fetch the settings const auto srcBoneIndex = (int32)node->Values[0]; @@ -2220,18 +2209,7 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu { // Get input auto input = tryGetValue(node->GetBox(1), Value::Null); - const auto nodes = node->GetNodes(this); - if (ANIM_GRAPH_IS_VALID_PTR(input)) - { - // Use input nodes - CopyNodes(nodes, input); - } - else - { - // Use default nodes - InitNodes(nodes); - input = nodes; - } + const auto nodes = node->GetNodes(this, input); // Fetch the settings const auto srcNodeIndex = node->Data.CopyNode.SrcNodeIndex; @@ -2285,22 +2263,10 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu float weight = (float)tryGetValue(node->GetBox(3), node->Values[1]); if (nodeIndex < 0 || nodeIndex >= _skeletonNodesCount || weight < ANIM_GRAPH_BLEND_THRESHOLD) { - // Pass through the input value = input; break; } - const auto nodes = node->GetNodes(this); - if (ANIM_GRAPH_IS_VALID_PTR(input)) - { - // Use input nodes - CopyNodes(nodes, input); - } - else - { - // Use default nodes - InitNodes(nodes); - input = nodes; - } + const auto nodes = node->GetNodes(this, input); const Vector3 target = (Vector3)tryGetValue(node->GetBox(2), Vector3::Zero); weight = Math::Saturate(weight); @@ -2342,22 +2308,10 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu float weight = (float)tryGetValue(node->GetBox(4), node->Values[1]); if (nodeIndex < 0 || nodeIndex >= _skeletonNodesCount || weight < ANIM_GRAPH_BLEND_THRESHOLD) { - // Pass through the input value = input; break; } - const auto nodes = node->GetNodes(this); - if (ANIM_GRAPH_IS_VALID_PTR(input)) - { - // Use input nodes - CopyNodes(nodes, input); - } - else - { - // Use default nodes - InitNodes(nodes); - input = nodes; - } + const auto nodes = node->GetNodes(this, input); const Vector3 target = (Vector3)tryGetValue(node->GetBox(2), Vector3::Zero); const Vector3 jointTarget = (Vector3)tryGetValue(node->GetBox(3), Vector3::Zero); const bool allowStretching = (bool)tryGetValue(node->GetBox(5), node->Values[2]);