Skip to content

Commit a49da07

Browse files
committed
Add RecalculateCurveDirections node
1 parent a4dde2b commit a49da07

File tree

4 files changed

+122
-4
lines changed

4 files changed

+122
-4
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using GeometryGraph.Runtime.Graph;
2+
using Newtonsoft.Json.Linq;
3+
using UnityEditor.Experimental.GraphView;
4+
using UnityEngine.UIElements;
5+
6+
namespace GeometryGraph.Editor {
7+
[Title("Curve", "Recalculate Directions")]
8+
public class RecalculateCurveDirectionsNode : AbstractNode<GeometryGraph.Runtime.Graph.RecalculateCurveDirectionsNode> {
9+
protected override string Title => "Recalculate Directions";
10+
protected override NodeCategory Category => NodeCategory.Curve;
11+
12+
private GraphFrameworkPort curvePort;
13+
private GraphFrameworkPort resultPort;
14+
15+
private bool flipTangents;
16+
private bool flipNormals;
17+
private bool flipBinormals;
18+
19+
private BooleanToggle flipTangentsToggle;
20+
private BooleanToggle flipNormalsToggle;
21+
private BooleanToggle flipBinormalsToggle;
22+
23+
protected override void CreateNode() {
24+
curvePort = GraphFrameworkPort.Create("Curve", Direction.Input, Port.Capacity.Single, PortType.Curve, this);
25+
resultPort = GraphFrameworkPort.Create("Curve", Direction.Output, Port.Capacity.Multi, PortType.Curve, this);
26+
27+
flipTangentsToggle = new BooleanToggle(false, "Flip Tangents (Yes)", "Flip Tangents (No)");
28+
flipNormalsToggle = new BooleanToggle(false, "Flip Normals (Yes)", "Flip Normals (No)");
29+
flipBinormalsToggle = new BooleanToggle(false, "Flip Binormals (Yes)", "Flip Binormals (No)");
30+
31+
flipTangentsToggle.RegisterValueChangedCallback(evt => {
32+
if (evt.newValue == flipTangents) return;
33+
34+
Owner.EditorView.GraphObject.RegisterCompleteObjectUndo("Change Flip Tangents");
35+
flipTangents = evt.newValue;
36+
RuntimeNode.UpdateFlipTangents(flipTangents);
37+
});
38+
39+
flipNormalsToggle.RegisterValueChangedCallback(evt => {
40+
if (evt.newValue == flipNormals) return;
41+
42+
Owner.EditorView.GraphObject.RegisterCompleteObjectUndo("Change Flip Normals");
43+
flipNormals = evt.newValue;
44+
RuntimeNode.UpdateFlipNormals(flipNormals);
45+
});
46+
47+
flipBinormalsToggle.RegisterValueChangedCallback(evt => {
48+
if (evt.newValue == flipBinormals) return;
49+
50+
Owner.EditorView.GraphObject.RegisterCompleteObjectUndo("Change Flip Binormals");
51+
flipBinormals = evt.newValue;
52+
RuntimeNode.UpdateFlipBinormals(flipBinormals);
53+
});
54+
55+
inputContainer.Add(flipTangentsToggle);
56+
inputContainer.Add(flipNormalsToggle);
57+
inputContainer.Add(flipBinormalsToggle);
58+
AddPort(curvePort);
59+
AddPort(resultPort);
60+
}
61+
62+
protected override void BindPorts() {
63+
BindPort(curvePort, RuntimeNode.CurvePort);
64+
BindPort(resultPort, RuntimeNode.ResultPort);
65+
}
66+
67+
protected internal override JObject Serialize() {
68+
JObject root = base.Serialize();
69+
JArray data = new() {
70+
flipTangents ? 1 : 0,
71+
flipNormals ? 1 : 0,
72+
flipBinormals ? 1 : 0
73+
};
74+
75+
root["d"] = data;
76+
return root;
77+
}
78+
79+
protected internal override void Deserialize(JObject data) {
80+
JArray array = data["d"] as JArray;
81+
82+
flipTangents = array!.Value<int>(0) == 1;
83+
flipNormals = array.Value<int>(1) == 1;
84+
flipBinormals = array.Value<int>(2) == 1;
85+
86+
flipTangentsToggle.SetValueWithoutNotify(flipTangents);
87+
flipNormalsToggle.SetValueWithoutNotify(flipNormals);
88+
flipBinormalsToggle.SetValueWithoutNotify(flipBinormals);
89+
90+
RuntimeNode.UpdateFlipTangents(flipTangents);
91+
RuntimeNode.UpdateFlipNormals(flipNormals);
92+
RuntimeNode.UpdateFlipBinormals(flipBinormals);
93+
94+
base.Deserialize(data);
95+
}
96+
}
97+
}

UnityGeometryGraph/Assets/GeometryGraph/Editor/Graph/Nodes/Curve/RecalculateCurveDirectionsNode.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnityGeometryGraph/Assets/GeometryGraph/Runtime/Graph/Node/Curve/RecalculateCurveDirectionsNode.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,36 @@
22
using GeometryGraph.Runtime.Curve;
33

44
namespace GeometryGraph.Runtime.Graph {
5+
[GenerateRuntimeNode]
56
public partial class RecalculateCurveDirectionsNode {
67
[In(
7-
DefaultValue = "(CurveData)null",
8+
DefaultValue = "CurveData.Empty",
89
GetValueCode = "{self} = GetValue(connection, {default})",
910
UpdateValueCode = ""
1011
)]
1112
public CurveData Curve { get; private set; }
13+
1214
[Out] public CurveData Result { get; private set; }
1315

16+
[Setting] public bool FlipTangents { get; private set; }
17+
[Setting] public bool FlipNormals { get; private set; }
18+
[Setting] public bool FlipBinormals { get; private set; }
19+
20+
protected override void OnConnectionRemoved(Connection connection, RuntimePort port) {
21+
if (port == CurvePort) {
22+
Curve = CurveData.Empty;
23+
Result = CurveData.Empty;
24+
}
25+
}
26+
1427
[CalculatesProperty(nameof(Result))]
1528
private void CalculateResult() {
16-
// TODO: Implement
29+
if (Curve == null) {
30+
Result = CurveData.Empty;
31+
return;
32+
}
33+
34+
Result = CurveOperations.RecalculateDirectionVectors(Curve, new RecalculateCurveDirectionsSettings(FlipTangents, FlipNormals, FlipBinormals));
1735
}
1836
}
1937
}

UnityGeometryGraph/Assets/GeometryGraph/Runtime/Graph/Node/Curve/TransformCurveNode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ public partial class TransformCurveNode {
4040

4141
protected override void OnConnectionRemoved(Connection connection, RuntimePort port) {
4242
if (port != InputPort) return;
43-
Result = null;
43+
Result = CurveData.Empty;
4444
}
4545

4646
[CalculatesProperty(nameof(Result))]
4747
private void CalculateResult() {
4848
if (Input == null) {
49-
Result = null;
49+
Result = CurveData.Empty;
5050
return;
5151
}
5252

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy