Skip to content

Commit

Permalink
Added more Tween Nodes
Browse files Browse the repository at this point in the history
Added TweenPosition, TweenRotation, TweenScale. More to come soon.
  • Loading branch information
LeCloutPanda committed May 1, 2024
1 parent 3bca5b9 commit cca27f2
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 0 deletions.
61 changes: 61 additions & 0 deletions ProjectObsidian/ProtoFlux/Actions/TweenPosition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Threading.Tasks;
using Elements.Core;
using FrooxEngine;
using ProtoFlux.Core;
using ProtoFlux.Runtimes.Execution;

namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Actions
{
[NodeCategory("Obsidian/Actions")]
public class TweenPosition : AsyncActionNode<ExecutionContext>
{
public ValueInput<float3> To;
public ValueInput<float3> From;
[Core.DefaultValueAttribute(1f)]
public ValueInput<float> Duration;
[Core.DefaultValueAttribute(CurvePreset.Smooth)]
public ValueInput<CurvePreset> Curve;
public ValueInput<bool> ProportionalDuration;
public ObjectInput<Slot> Target;
public AsyncCall OnStarted;
public Continuation OnDone;

protected override async Task<IOperation> RunAsync(ExecutionContext context)
{
IField <float3> field = Target.Evaluate(context).Position_Field;
if (field == null)
{
return null;
}
float3 val = field.Value;
float3 val2 = field.Value;
if (To.Source != null)
{
val2 = To.Evaluate(context);
}
if (From.Source != null)
{
val = From.Evaluate(context);
}
float num = Duration.Evaluate(context, 1f);
bool num2 = ProportionalDuration.Evaluate(context, defaultValue: false);
CurvePreset curve = Curve.Evaluate(context, CurvePreset.Smooth);
if (num2 && Coder<float3>.SupportsDistance)
{
float num3 = Coder<float3>.Distance(val, val2);
if (num3.IsValid())
{
num *= num3;
}
}
TaskCompletionSource<bool> completion = new TaskCompletionSource<bool>();
field.TweenFromTo(val, val2, num, curve, null, delegate
{
completion.SetResult(result: true);
});
await OnStarted.ExecuteAsync(context);
await completion.Task;
return OnDone.Target;
}
}
}
61 changes: 61 additions & 0 deletions ProjectObsidian/ProtoFlux/Actions/TweenRotation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Threading.Tasks;
using Elements.Core;
using FrooxEngine;
using ProtoFlux.Core;
using ProtoFlux.Runtimes.Execution;

namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Actions
{
[NodeCategory("Obsidian/Actions")]
public class TweenRotation : AsyncActionNode<ExecutionContext>
{
public ValueInput<floatQ> To;
public ValueInput<floatQ> From;
[Core.DefaultValueAttribute(1f)]
public ValueInput<float> Duration;
[Core.DefaultValueAttribute(CurvePreset.Smooth)]
public ValueInput<CurvePreset> Curve;
public ValueInput<bool> ProportionalDuration;
public ObjectInput<Slot> Target;
public AsyncCall OnStarted;
public Continuation OnDone;

protected override async Task<IOperation> RunAsync(ExecutionContext context)
{
IField <floatQ> field = Target.Evaluate(context).Rotation_Field;
if (field == null)
{
return null;
}
floatQ val = field.Value;
floatQ val2 = field.Value;
if (To.Source != null)
{
val2 = To.Evaluate(context);
}
if (From.Source != null)
{
val = From.Evaluate(context);
}
float num = Duration.Evaluate(context, 1f);
bool num2 = ProportionalDuration.Evaluate(context, defaultValue: false);
CurvePreset curve = Curve.Evaluate(context, CurvePreset.Smooth);
if (num2 && Coder<floatQ>.SupportsDistance)
{
float num3 = Coder<floatQ>.Distance(val, val2);
if (num3.IsValid())
{
num *= num3;
}
}
TaskCompletionSource<bool> completion = new TaskCompletionSource<bool>();
field.TweenFromTo(val, val2, num, curve, null, delegate
{
completion.SetResult(result: true);
});
await OnStarted.ExecuteAsync(context);
await completion.Task;
return OnDone.Target;
}
}
}
61 changes: 61 additions & 0 deletions ProjectObsidian/ProtoFlux/Actions/TweenScale.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Threading.Tasks;
using Elements.Core;
using FrooxEngine;
using ProtoFlux.Core;
using ProtoFlux.Runtimes.Execution;

namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Actions
{
[NodeCategory("Obsidian/Actions")]
public class TweenScale: AsyncActionNode<ExecutionContext>
{
public ValueInput<float3> To;
public ValueInput<float3> From;
[Core.DefaultValueAttribute(1f)]
public ValueInput<float> Duration;
[Core.DefaultValueAttribute(CurvePreset.Smooth)]
public ValueInput<CurvePreset> Curve;
public ValueInput<bool> ProportionalDuration;
public ObjectInput<Slot> Target;
public AsyncCall OnStarted;
public Continuation OnDone;

protected override async Task<IOperation> RunAsync(ExecutionContext context)
{
IField<float3> field = Target.Evaluate(context).Scale_Field;
if (field == null)
{
return null;
}
float3 val = field.Value;
float3 val2 = field.Value;
if (To.Source != null)
{
val2 = To.Evaluate(context);
}
if (From.Source != null)
{
val = From.Evaluate(context);
}
float num = Duration.Evaluate(context, 1f);
bool num2 = ProportionalDuration.Evaluate(context, defaultValue: false);
CurvePreset curve = Curve.Evaluate(context, CurvePreset.Smooth);
if (num2 && Coder<float3>.SupportsDistance)
{
float num3 = Coder<float3>.Distance(val, val2);
if (num3.IsValid())
{
num *= num3;
}
}
TaskCompletionSource<bool> completion = new TaskCompletionSource<bool>();
field.TweenFromTo(val, val2, num, curve, null, delegate
{
completion.SetResult(result: true);
});
await OnStarted.ExecuteAsync(context);
await completion.Task;
return OnDone.Target;
}
}
}

0 comments on commit cca27f2

Please sign in to comment.