6

I'm attempting to write a plugin for Blender that automatically arranges a node-tree neatly, without overlaps or connections that flow to the left. I have access to the list of nodes, their positions, their dimensions and a list of connections/links. The graph runs from left to right and can multiple start and end nodes. The output of a node cannot connect to the input of a node before it, or it's own input (no cyclic dependencies.)

Does anyone know of a paper or article that focuses on coding something that can turn this: Messy nodes

Into this? Neat nodes

The method I originally came up with was: For all nodes that have no input connections, line them up on the left. For all nodes that are connected to these starting nodes, put them to the right of the connecting start node. Repeat this for each node until the end. If one node overlaps another, move it, and the chain of nodes to it's right, down.

This worked great for each isolated chain, but when a node of one chain connected to a node of another (a branch that connects back to the trunk for example), it would often have a backward connection: Backward connection

This method I've come up with seems to be quite... crude. I've read up a little about Spring Force-Directed layouts, but they seems to be more for graphs that flow in any/all directions, and I'm not entirely sure how I'd manually implement that here anyways, since I'm restricted to using core math alone with no other external libraries.

It's not exactly a common problem, but I'm far from the first to try to figure it out. I'm not asking for code examples exactly, just something to look at to help me work out a decent algorithm.

4

3 回答 3

4

拓扑排序的节点(如果存在)将为您提供正确的节点顺序以供显示。如果两个节点不相关但相邻排序,如果您愿意,可以将它们放置在相同的 X 坐标处。

一般来说,以适当的间距绘制树是 NP 完全的 [参见 Bill Mill 的Drawing Presentable Trees中的参考资料],并且绘制图形并不容易。

于 2013-06-15T16:00:07.217 回答
1

我没有尝试创建完美的系统,而是决定通过自己解决每个问题而不是阻止它的原因来强迫自己获得一个整洁的图表。它很粗糙,很慢,而且远非理想,但它确实有效: 示例 1 示例 2 示例 3

当它更完整时,我将在 GNU 下发布它,但现在这里是它的核心:http: //www.pasteall.org/43213/python

编辑:发布:http ://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Nodes/Node_Wrangler

于 2013-06-16T17:16:34.213 回答
1

我会为此使用 GraphViz:http: //www.graphviz.org/

  1. 将 Blender 图表读入内存
  2. 以 GraphViz 图形文件格式写出相同的图形
  3. 运行 GraphViz 可执行文件之一(我建议使用dot (link)
  4. 读取等效图,但节点位置由 GraphViz 创建
  5. 编写您的 Blender 图表,根据 GraphViz 结果修改位置

除非出于学术原因,否则不要重新发明轮子。这种方法应该很容易做到,并且不需要设计复杂的图形布局算法。

于 2013-06-15T20:58:01.900 回答