mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 21:38:38 +00:00
Added interpolation nodes (#755)
Nodes - Added interpolation nodes Nodes - Renamed Numeric Interpolation node to Numeric Translation
This commit is contained in:
parent
b493e43c6e
commit
6240e42e74
@ -2,8 +2,8 @@
|
||||
|
||||
namespace Artemis.VisualScripting.Nodes.Easing;
|
||||
|
||||
[Node("Numeric Easing", "Outputs an eased numeric value", "Easing", InputType = typeof(Numeric), OutputType = typeof(Numeric))]
|
||||
public class NumericEasingNode : Node
|
||||
[Node("Numeric Transition", "Outputs an eased numeric value", "Easing", InputType = typeof(Numeric), OutputType = typeof(Numeric))]
|
||||
public class NumericTransitionNode : Node
|
||||
{
|
||||
private float _currentValue;
|
||||
private DateTime _lastEvaluate = DateTime.MinValue;
|
||||
@ -11,7 +11,7 @@ public class NumericEasingNode : Node
|
||||
private float _sourceValue;
|
||||
private float _targetValue;
|
||||
|
||||
public NumericEasingNode()
|
||||
public NumericTransitionNode()
|
||||
{
|
||||
Input = CreateInputPin<Numeric>();
|
||||
EasingTime = CreateInputPin<Numeric>("delay");
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user