From e07ae33040fafadc1a1597fd95b645eb71d9513e Mon Sep 17 00:00:00 2001 From: Nils Hausfeld Date: Fri, 6 Oct 2023 15:23:43 +0200 Subject: [PATCH 1/3] - Added input box to animation sample node to receive animation assets - AssetSelect not gets shown or hidden depending on if the box has a connection - Animation asset reference box now overrides asset picker --- Source/Editor/Surface/Archetypes/Animation.cs | 22 ++++++++++++++++++- .../Animations/Graph/AnimGroup.Animation.cpp | 14 +++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Source/Editor/Surface/Archetypes/Animation.cs b/Source/Editor/Surface/Archetypes/Animation.cs index 6364106e4..2e362ae79 100644 --- a/Source/Editor/Surface/Archetypes/Animation.cs +++ b/Source/Editor/Surface/Archetypes/Animation.cs @@ -34,6 +34,9 @@ namespace FlaxEditor.Surface.Archetypes /// public class Sample : SurfaceNode { + private AssetSelect _assetSelect; + private Box _assetBox; + /// public Sample(uint id, VisjectSurfaceContext context, NodeArchetype nodeArch, GroupArchetype groupArch) : base(id, context, nodeArch, groupArch) @@ -54,7 +57,12 @@ namespace FlaxEditor.Surface.Archetypes base.OnSurfaceLoaded(); if (Surface != null) + { + _assetSelect = GetChild(); + _assetBox = GetBox(8); + _assetSelect.Visible = !_assetBox.HasAnyConnection; UpdateTitle(); + } } private void UpdateTitle() @@ -64,6 +72,17 @@ namespace FlaxEditor.Surface.Archetypes var style = Style.Current; Resize(Mathf.Max(230, style.FontLarge.MeasureText(Title).X + 30), 160); } + + /// + public override void ConnectionTick(Box box) + { + base.ConnectionTick(box); + + if(box.ID != _assetBox.ID) + return; + + _assetSelect.Visible = !box.HasAnyConnection; + } } /// @@ -305,7 +324,8 @@ namespace FlaxEditor.Surface.Archetypes NodeElementArchetype.Factory.Input(0, "Speed", true, typeof(float), 5, 1), NodeElementArchetype.Factory.Input(1, "Loop", true, typeof(bool), 6, 2), NodeElementArchetype.Factory.Input(2, "Start Position", true, typeof(float), 7, 3), - NodeElementArchetype.Factory.Asset(0, Surface.Constants.LayoutOffsetY * 3, 0, typeof(FlaxEngine.Animation)), + NodeElementArchetype.Factory.Input(3, "Animation Asset", true, typeof(FlaxEngine.Animation), 8), + NodeElementArchetype.Factory.Asset(0, Surface.Constants.LayoutOffsetY * 4, 0, typeof(FlaxEngine.Animation)), } }, new NodeArchetype diff --git a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp index 73ddbc41c..088e11ed3 100644 --- a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp +++ b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp @@ -749,7 +749,7 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu // Animation case 2: { - const auto anim = node->Assets[0].As(); + auto anim = node->Assets[0].As(); auto& bucket = context.Data->State[node->BucketIndex].Animation; switch (box->ID) @@ -761,6 +761,18 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu const float speed = (float)tryGetValue(node->GetBox(5), node->Values[1]); const bool loop = (bool)tryGetValue(node->GetBox(6), node->Values[2]); const float startTimePos = (float)tryGetValue(node->GetBox(7), node->Values[3]); + + // Override animation when animation reference box is connected + auto animationAssetBox = node->GetBox(8); + if(animationAssetBox->HasConnection()) + { + const Value assetBoxValue = tryGetValue(animationAssetBox, Value::Null); + if(assetBoxValue != Value::Null) + anim = (Animation*)assetBoxValue.AsAsset; + else + anim = nullptr; + } + const float length = anim ? anim->GetLength() : 0.0f; // Calculate new time position From ea355dd560f5757e07d4e009d34ebdde61ce6eed Mon Sep 17 00:00:00 2001 From: Nils Hausfeld Date: Fri, 6 Oct 2023 15:30:52 +0200 Subject: [PATCH 2/3] - Title of Animation sample node gets updated when connection of animation reference box changes --- Source/Editor/Surface/Archetypes/Animation.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Editor/Surface/Archetypes/Animation.cs b/Source/Editor/Surface/Archetypes/Animation.cs index 2e362ae79..2155b014e 100644 --- a/Source/Editor/Surface/Archetypes/Animation.cs +++ b/Source/Editor/Surface/Archetypes/Animation.cs @@ -68,7 +68,7 @@ namespace FlaxEditor.Surface.Archetypes private void UpdateTitle() { var asset = Editor.Instance.ContentDatabase.Find((Guid)Values[0]); - Title = asset?.ShortName ?? "Animation"; + Title = _assetBox.HasAnyConnection || asset == null ? "Animation" : asset.ShortName; var style = Style.Current; Resize(Mathf.Max(230, style.FontLarge.MeasureText(Title).X + 30), 160); } @@ -82,6 +82,7 @@ namespace FlaxEditor.Surface.Archetypes return; _assetSelect.Visible = !box.HasAnyConnection; + UpdateTitle(); } } From 63d57151d0a91cdbd116c40de141103a6d54416d Mon Sep 17 00:00:00 2001 From: Nils Hausfeld Date: Fri, 6 Oct 2023 17:50:19 +0200 Subject: [PATCH 3/3] - Minor cleanup --- Source/Editor/Surface/Archetypes/Animation.cs | 4 ++-- Source/Engine/Animations/Graph/AnimGroup.Animation.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Editor/Surface/Archetypes/Animation.cs b/Source/Editor/Surface/Archetypes/Animation.cs index 2155b014e..1b9e212b2 100644 --- a/Source/Editor/Surface/Archetypes/Animation.cs +++ b/Source/Editor/Surface/Archetypes/Animation.cs @@ -36,7 +36,7 @@ namespace FlaxEditor.Surface.Archetypes { private AssetSelect _assetSelect; private Box _assetBox; - + /// public Sample(uint id, VisjectSurfaceContext context, NodeArchetype nodeArch, GroupArchetype groupArch) : base(id, context, nodeArch, groupArch) @@ -77,7 +77,7 @@ namespace FlaxEditor.Surface.Archetypes public override void ConnectionTick(Box box) { base.ConnectionTick(box); - + if(box.ID != _assetBox.ID) return; diff --git a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp index 088e11ed3..043c57b4d 100644 --- a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp +++ b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp @@ -772,7 +772,7 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu else anim = nullptr; } - + const float length = anim ? anim->GetLength() : 0.0f; // Calculate new time position