1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Added interpolation nodes (#755)

Nodes - Added interpolation nodes
Nodes - Renamed Numeric Interpolation node to Numeric Translation
This commit is contained in:
Aytaç Kayadelen 2023-02-01 23:51:09 +03:00 committed by GitHub
parent b493e43c6e
commit 6240e42e74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 3 deletions

View File

@ -2,8 +2,8 @@
namespace Artemis.VisualScripting.Nodes.Easing; namespace Artemis.VisualScripting.Nodes.Easing;
[Node("Numeric Easing", "Outputs an eased numeric value", "Easing", InputType = typeof(Numeric), OutputType = typeof(Numeric))] [Node("Numeric Transition", "Outputs an eased numeric value", "Easing", InputType = typeof(Numeric), OutputType = typeof(Numeric))]
public class NumericEasingNode : Node public class NumericTransitionNode : Node
{ {
private float _currentValue; private float _currentValue;
private DateTime _lastEvaluate = DateTime.MinValue; private DateTime _lastEvaluate = DateTime.MinValue;
@ -11,7 +11,7 @@ public class NumericEasingNode : Node
private float _sourceValue; private float _sourceValue;
private float _targetValue; private float _targetValue;
public NumericEasingNode() public NumericTransitionNode()
{ {
Input = CreateInputPin<Numeric>(); Input = CreateInputPin<Numeric>();
EasingTime = CreateInputPin<Numeric>("delay"); EasingTime = CreateInputPin<Numeric>("delay");

View File

@ -0,0 +1,31 @@
using Artemis.Core;
namespace Artemis.VisualScripting.Nodes.Mathematics;
[Node("Normalize", "Normalizes the number into range between 0-1",
"Mathematics", InputType = typeof(Numeric), OutputType = typeof(Numeric))]
public class NormalizeNode : Node
{
public InputPin<Numeric> Input { get; }
public InputPin<Numeric> Start { get; }
public InputPin<Numeric> End { get; }
public OutputPin<Numeric> Result { get; }
public NormalizeNode()
{
Input = CreateInputPin<Numeric>("Input");
Start = CreateInputPin<Numeric>("Start");
End = CreateInputPin<Numeric>("End");
Result = CreateOutputPin<Numeric>();
}
public override void Evaluate()
{
double inputValue = Input.Value;
double startValue = Start.Value;
double endValue = End.Value;
Result.Value = (Math.Clamp(inputValue, startValue, endValue) - startValue) / (endValue - startValue);
}
}

View File

@ -0,0 +1,30 @@
using Artemis.Core;
namespace Artemis.VisualScripting.Nodes.Easing;
[Node("Numeric Easing", "Interpolates a value from 0-1 to 0-1 with the given function",
"Mathematics", InputType = typeof(Numeric), OutputType = typeof(Numeric))]
public class NumericEasingNode : Node
{
public InputPin<Numeric> Input { get; }
public InputPin<Easings.Functions> EasingFunction { get; }
public OutputPin<Numeric> Result { get; }
public NumericEasingNode()
{
Input = CreateInputPin<Numeric>("Input");
EasingFunction = CreateInputPin<Easings.Functions>("EasingFunction");
Result = CreateOutputPin<Numeric>();
}
public override void Evaluate()
{
double inputValue = Input.Value;
double progress = Math.Clamp(inputValue, 0, 1);
Result.Value = Easings.Interpolate(progress, EasingFunction.Value);
}
}