Guest User

Untitled

a guest
May 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. import bpy
  2.  
  3.  
  4. def float_lerp(a, b, t):
  5. return (1.0 - t) * a + t * b
  6.  
  7.  
  8. def arrange_nodes(node_array, calc_priority, horiz_padding=0.125, vert_padding=0.125):
  9.  
  10. # Create a dictionary where the key is the
  11. # depth and the value is an array of nodes.
  12. depth_nodes = {}
  13. for node in node_array:
  14.  
  15. depth = calc_priority(node)
  16. if depth in depth_nodes:
  17.  
  18. # Add the node to the node array at that depth.
  19. depth_nodes[depth].append(node)
  20. else:
  21.  
  22. # Begin a new array.
  23. depth_nodes[depth] = [node]
  24.  
  25. # Add padding to half the width.
  26. extents_w = (0.5 + horiz_padding) * sum_widths(depth_nodes)
  27. t_w_max = 0.5
  28. sz0 = len(depth_nodes)
  29. if sz0 > 1:
  30. t_w_max = 1.0 / (sz0 - 1)
  31.  
  32. # List of dictionary KVPs.
  33. depths = sorted(depth_nodes.items())
  34. depths_range = range(0, sz0, 1)
  35. for i in depths_range:
  36. nodes_array = depths[i][1]
  37. t_w = i * t_w_max
  38. x = float_lerp(-extents_w, extents_w, t_w)
  39.  
  40. extents_h = (0.5 + vert_padding) * sum_heights(nodes_array)
  41. t_h_max = 0.5
  42. sz1 = len(nodes_array)
  43. if sz1 > 1:
  44. t_h_max = 1.0 / (sz1 - 1)
  45.  
  46. nodes_range = range(0, sz1, 1)
  47. for j in nodes_range:
  48. node = nodes_array[j]
  49. t_h = j * t_h_max
  50. y = float_lerp(-extents_h, extents_h, t_h)
  51. half_w = 0.5 * node.width
  52. half_h = 0.5 * node.height
  53. node.location.xy = (x - half_w, y - half_h)
Add Comment
Please, Sign In to add comment