mirror of
https://github.com/Siccity/xNode.git
synced 2026-03-26 22:49:02 +08:00
Improved bezier tangents
This commit is contained in:
parent
29acbf6348
commit
72a80deb27
@ -431,11 +431,11 @@ namespace XNodeEditor {
|
|||||||
Vector2 to = Vector2.zero;
|
Vector2 to = Vector2.zero;
|
||||||
for (int i = 0; i < draggedOutputReroutes.Count; i++) {
|
for (int i = 0; i < draggedOutputReroutes.Count; i++) {
|
||||||
to = draggedOutputReroutes[i];
|
to = draggedOutputReroutes[i];
|
||||||
DrawConnection(from, to, col);
|
DrawNoodle(from, i == 0 ? draggedOutput : null, to, null, col);
|
||||||
from = to;
|
from = to;
|
||||||
}
|
}
|
||||||
to = draggedOutputTarget != null ? portConnectionPoints[draggedOutputTarget].center : WindowToGridPosition(Event.current.mousePosition);
|
to = draggedOutputTarget != null ? portConnectionPoints[draggedOutputTarget].center : WindowToGridPosition(Event.current.mousePosition);
|
||||||
DrawConnection(from, to, col);
|
DrawNoodle(from, draggedOutputReroutes.Any() ? null : draggedOutput, to, draggedOutputTarget, col);
|
||||||
|
|
||||||
Color bgcol = Color.black;
|
Color bgcol = Color.black;
|
||||||
Color frcol = col;
|
Color frcol = col;
|
||||||
|
|||||||
@ -117,20 +117,25 @@ namespace XNodeEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Draw a bezier from startpoint to endpoint, both in grid coordinates </summary>
|
/// <summary> Draw a bezier from startpoint to endpoint, both in grid coordinates </summary>
|
||||||
public void DrawConnection(Vector2 startPoint, Vector2 endPoint, Color col) {
|
public void DrawNoodle(Vector2 startPoint, XNode.NodePort startPort, Vector2 endPoint, XNode.NodePort endPort, Color col) {
|
||||||
startPoint = GridToWindowPosition(startPoint);
|
startPoint = GridToWindowPosition(startPoint);
|
||||||
endPoint = GridToWindowPosition(endPoint);
|
endPoint = GridToWindowPosition(endPoint);
|
||||||
|
|
||||||
switch (NodeEditorPreferences.GetSettings().noodleType) {
|
switch (NodeEditorPreferences.GetSettings().noodleType) {
|
||||||
case NodeEditorPreferences.NoodleType.Curve:
|
case NodeEditorPreferences.NoodleType.Curve:
|
||||||
Vector2 startTangent = startPoint;
|
float minTangent = Vector2.Distance(endPoint, startPoint)*0.5f;
|
||||||
if (startPoint.x < endPoint.x) startTangent.x = Mathf.LerpUnclamped(startPoint.x, endPoint.x, 0.7f);
|
|
||||||
else startTangent.x = Mathf.LerpUnclamped(startPoint.x, endPoint.x, -0.7f);
|
|
||||||
|
|
||||||
Vector2 endTangent = endPoint;
|
Vector2 startTangent = Vector2.zero;
|
||||||
if (startPoint.x > endPoint.x) endTangent.x = Mathf.LerpUnclamped(endPoint.x, startPoint.x, -0.7f);
|
startTangent.x = (endPoint.x - startPoint.x) * 0.7f;
|
||||||
else endTangent.x = Mathf.LerpUnclamped(endPoint.x, startPoint.x, 0.7f);
|
startTangent.x = Mathf.Sign(startTangent.x) * Mathf.Max(Mathf.Abs(startTangent.x), minTangent);
|
||||||
Handles.DrawBezier(startPoint, endPoint, startTangent, endTangent, col, null, 4);
|
if (startPort != null) startTangent.x = Mathf.Abs(startTangent.x);
|
||||||
|
|
||||||
|
Vector2 endTangent = Vector2.zero;
|
||||||
|
endTangent.x = (startPoint.x - endPoint.x) * 0.7f;
|
||||||
|
endTangent.x = Mathf.Sign(endTangent.x) * Mathf.Max(Mathf.Abs(endTangent.x), minTangent);
|
||||||
|
if (endPort != null) endTangent.x = -Mathf.Abs(endTangent.x);
|
||||||
|
|
||||||
|
Handles.DrawBezier(startPoint, endPoint, startPoint + startTangent, endPoint + endTangent, col, null, 4);
|
||||||
break;
|
break;
|
||||||
case NodeEditorPreferences.NoodleType.Line:
|
case NodeEditorPreferences.NoodleType.Line:
|
||||||
Handles.color = col;
|
Handles.color = col;
|
||||||
@ -201,12 +206,12 @@ namespace XNodeEditor {
|
|||||||
// Loop through reroute points and draw the path
|
// Loop through reroute points and draw the path
|
||||||
for (int i = 0; i < reroutePoints.Count; i++) {
|
for (int i = 0; i < reroutePoints.Count; i++) {
|
||||||
to = reroutePoints[i];
|
to = reroutePoints[i];
|
||||||
DrawConnection(from, to, connectionColor);
|
DrawNoodle(from, i == 0 ? output : null, to, null, connectionColor);
|
||||||
from = to;
|
from = to;
|
||||||
}
|
}
|
||||||
to = toRect.center;
|
to = toRect.center;
|
||||||
|
|
||||||
DrawConnection(from, to, connectionColor);
|
DrawNoodle(from, reroutePoints.Any() ? null : output, to, input, connectionColor);
|
||||||
|
|
||||||
// Loop through reroute points again and draw the points
|
// Loop through reroute points again and draw the points
|
||||||
for (int i = 0; i < reroutePoints.Count; i++) {
|
for (int i = 0; i < reroutePoints.Count; i++) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user