Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- def float_lerp(a, b, t):
- return (1.0 - t) * a + t * b
- def arrange_nodes(node_array, calc_priority, horiz_padding=0.125, vert_padding=0.125):
- # Create a dictionary where the key is the
- # depth and the value is an array of nodes.
- depth_nodes = {}
- for node in node_array:
- depth = calc_priority(node)
- if depth in depth_nodes:
- # Add the node to the node array at that depth.
- depth_nodes[depth].append(node)
- else:
- # Begin a new array.
- depth_nodes[depth] = [node]
- # Add padding to half the width.
- extents_w = (0.5 + horiz_padding) * sum_widths(depth_nodes)
- t_w_max = 0.5
- sz0 = len(depth_nodes)
- if sz0 > 1:
- t_w_max = 1.0 / (sz0 - 1)
- # List of dictionary KVPs.
- depths = sorted(depth_nodes.items())
- depths_range = range(0, sz0, 1)
- for i in depths_range:
- nodes_array = depths[i][1]
- t_w = i * t_w_max
- x = float_lerp(-extents_w, extents_w, t_w)
- extents_h = (0.5 + vert_padding) * sum_heights(nodes_array)
- t_h_max = 0.5
- sz1 = len(nodes_array)
- if sz1 > 1:
- t_h_max = 1.0 / (sz1 - 1)
- nodes_range = range(0, sz1, 1)
- for j in nodes_range:
- node = nodes_array[j]
- t_h = j * t_h_max
- y = float_lerp(-extents_h, extents_h, t_h)
- half_w = 0.5 * node.width
- half_h = 0.5 * node.height
- node.location.xy = (x - half_w, y - half_h)
Add Comment
Please, Sign In to add comment