-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
116 additions
and
7 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
ProtoFlux/Bindings/Math/Physics/PotentialEnergyCalculationBinding.CS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using FrooxEngine.ProtoFlux; | ||
using ProtoFlux.Runtimes.Execution; | ||
using System; | ||
|
||
namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Math.Physics | ||
{ | ||
[Category("Obsidian/Math/Physics")] | ||
public class PotentialEnergyCalculationBinding : FrooxEngine.ProtoFlux.Runtimes.Execution.NodeBinding<PotentialEnergyCalculationNode> | ||
{ | ||
public readonly SyncRef<INodeValueOutput<float>> Mass; | ||
public readonly SyncRef<INodeValueOutput<float>> Height; | ||
|
||
public override Type NodeType => typeof(PotentialEnergyCalculationNode); | ||
|
||
public PotentialEnergyCalculationNode TypedNodeInstance { get; private set; } | ||
|
||
public override INode NodeInstance => TypedNodeInstance; | ||
|
||
public override int NodeInputCount => base.NodeInputCount + 2; | ||
|
||
public override TN Instantiate<TN>() | ||
{ | ||
try | ||
{ | ||
if (TypedNodeInstance != null) | ||
throw new InvalidOperationException("Node has already been instantiated"); | ||
|
||
var instance = (TypedNodeInstance = new PotentialEnergyCalculationNode()); | ||
return instance as TN; | ||
} | ||
catch (Exception ex) | ||
{ | ||
UniLog.Log($"Error in PotentialEnergyCalculationBinding.Instantiate: {ex.Message}"); | ||
throw; | ||
} | ||
} | ||
|
||
protected override void AssociateInstanceInternal(INode node) | ||
{ | ||
try | ||
{ | ||
if (node is not PotentialEnergyCalculationNode typedNodeInstance) | ||
throw new ArgumentException("Node instance is not of type " + typeof(PotentialEnergyCalculationNode)); | ||
|
||
TypedNodeInstance = typedNodeInstance; | ||
} | ||
catch (Exception ex) | ||
{ | ||
UniLog.Log($"Error in PotentialEnergyCalculationBinding.AssociateInstanceInternal: {ex.Message}"); | ||
throw; | ||
} | ||
} | ||
|
||
public override void ClearInstance() => TypedNodeInstance = null; | ||
|
||
protected override ISyncRef GetInputInternal(ref int index) | ||
{ | ||
var inputInternal = base.GetInputInternal(ref index); | ||
if (inputInternal != null) | ||
{ | ||
return inputInternal; | ||
} | ||
|
||
switch (index) | ||
{ | ||
case 0: | ||
return Mass; | ||
case 1: | ||
return Height; | ||
default: | ||
index -= 2; | ||
return null; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Elements.Core; | ||
using ProtoFlux.Core; | ||
using ProtoFlux.Runtimes.Execution; | ||
using System; | ||
|
||
namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Math.Physics | ||
{ | ||
[NodeCategory("Obsidian/Math/Physics")] | ||
public class PotentialEnergyCalculationNode : ValueFunctionNode<ExecutionContext, float> | ||
{ | ||
public ValueInput<float> Mass; | ||
public ValueInput<float> Height; | ||
|
||
protected override float Compute(ExecutionContext context) | ||
{ | ||
try | ||
{ | ||
float mass = Mass.Evaluate(context); | ||
float height = Height.Evaluate(context); | ||
|
||
float potentialEnergy = mass * Constants.G * height; | ||
|
||
return potentialEnergy; | ||
} | ||
catch (Exception ex) | ||
{ | ||
// Log any exceptions without throwing them | ||
UniLog.Log($"Error in PotentialEnergyCalculationNode.Compute: {ex.Message}"); | ||
} | ||
|
||
return 0.0f; // Return a default value in case of an error | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters