Improvements for Visject Surface

This commit is contained in:
Wojtek Figat
2021-10-08 15:30:42 +02:00
parent aa3a6e2766
commit 78e093245d
4 changed files with 20 additions and 22 deletions

View File

@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FlaxEngine;
using FlaxEditor.Surface.Elements;
using FlaxEditor.Surface.Undo;
@@ -36,9 +34,10 @@ namespace FlaxEditor.Surface
/// Uses the Sugiyama method
/// </summary>
/// <param name="nodes">List of nodes</param>
protected void FormatGraph(List<SurfaceNode> nodes)
public void FormatGraph(List<SurfaceNode> nodes)
{
if (nodes.Count <= 1 || !CanEdit) return;
if (nodes.Count <= 1)
return;
var nodesToVisit = new HashSet<SurfaceNode>(nodes);
@@ -70,7 +69,6 @@ namespace FlaxEditor.Surface
queue.Enqueue(box.Connections[j].ParentNode);
}
}
}
}
}
@@ -85,7 +83,8 @@ namespace FlaxEditor.Surface
/// <param name="nodes">List of connected nodes</param>
protected void FormatConnectedGraph(List<SurfaceNode> nodes)
{
if (nodes.Count <= 1 || !CanEdit) return;
if (nodes.Count <= 1)
return;
var boundingBox = GetNodesBounds(nodes);
@@ -93,9 +92,9 @@ namespace FlaxEditor.Surface
// Rightmost nodes with none of our nodes to the right of them
var endNodes = nodes
.Where(n => !n.GetBoxes().Any(b => b.IsOutput && b.Connections.Any(c => nodeData.ContainsKey(c.ParentNode))))
.OrderBy(n => n.Top) // Keep their relative order
.ToList();
.Where(n => !n.GetBoxes().Any(b => b.IsOutput && b.Connections.Any(c => nodeData.ContainsKey(c.ParentNode))))
.OrderBy(n => n.Top) // Keep their relative order
.ToList();
// Longest path layering
int maxLayer = SetLayers(nodeData, endNodes);
@@ -219,7 +218,8 @@ namespace FlaxEditor.Surface
void SetOffsets(SurfaceNode node, NodeFormattingData straightParentData)
{
if (!nodeData.TryGetValue(node, out var data)) return;
if (!nodeData.TryGetValue(node, out var data))
return;
// If we realize that the current node would collide with an already existing node in this layer
if (data.Layer >= 0 && offsets[data.Layer] > data.Offset)
@@ -282,6 +282,5 @@ namespace FlaxEditor.Surface
return maxOffset;
}
}
}