f_nodegraph.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #Node Graph Functions
  2. def SeekNodePathUntil(node, input_name, nodeType, direction = 'BACK'):
  3. from .node_container_common import trace_single_line, trace_single_line_up
  4. if direction == 'BACK':
  5. return trace_single_line(node, input_name)
  6. else: # 'FORWARD'
  7. return trace_single_line_up(node, input_name)
  8. def get_node_container(node, context):
  9. from .utilities import parse_node_tree, print_lines
  10. base_tree = context.space_data.path[0].node_tree
  11. from .readtree import get_tree_data
  12. parsed_tree = parse_node_tree(base_tree)
  13. nodes = get_tree_data(parsed_tree, base_tree)
  14. node_container = None
  15. if (node.id_data != context.space_data.path[-1].node_tree):
  16. return None, None
  17. if (node.id_data == base_tree):
  18. try:
  19. #other_node = node.inputs['Parent'].links[0].from_node
  20. node_container = nodes.get( ('NONE', node.name) )
  21. except IndexError: # node just isn't connected'
  22. nodes = None
  23. return node_container, nodes
  24. else: # find it in Node-Groups
  25. # I am checking the active node, which should always
  26. # be the path of Group Nodes.
  27. # if not, then the user is doing something sp0oky
  28. for node_container in nodes.values():
  29. if len(node_container.signature) != len(context.space_data.path)+1:
  30. continue
  31. tree = base_tree; found = False
  32. for name in node_container.signature[0:]:
  33. g_node = tree.nodes.get(name)
  34. if not (g_node == tree.nodes.active): continue
  35. if (hasattr(g_node, 'node_tree')):
  36. tree = g_node.node_tree
  37. elif name == node.name: found = True; break
  38. else:
  39. found = False
  40. continue
  41. if found == True:
  42. return node_container, nodes
  43. else:
  44. return None, None
  45. return None, None
  46. def GetUpstreamXFormNodes(node_container, context):
  47. if (node_container):
  48. input_name=None
  49. if node_container.node_type == 'LINK':
  50. input_name = 'Input Relationship'
  51. if node_container.__class__.__name__ == 'LinkInherit':
  52. input_name = 'Parent'
  53. elif node_container.node_type == 'XFORM':
  54. input_name = 'Relationship'
  55. xF = SeekNodePathUntil(node_container, input_name, ['xFormArmature', 'xFormBone', 'xFormRoot'])
  56. return xF
  57. else:
  58. return None
  59. def GetDownstreamXFormNodes(node_container, context):
  60. if (node_container):
  61. output_name=None
  62. if node_container.node_type == 'LINK':
  63. output_name = 'Output Relationship'
  64. if node_container.__class__.__name__ == 'LinkInherit':
  65. output_name = 'Inheritance'
  66. elif node_container.node_type == 'XFORM':
  67. output_name = 'xForm Out'
  68. xF = SeekNodePathUntil(node_container, output_name, ['xFormArmature', 'xFormBone', 'xFormRoot'], direction = 'FORWARD')
  69. return xF
  70. else:
  71. return None
  72. # def get_parent(node_container):
  73. # node_line, socket = trace_single_line(node_container, "Relationship")
  74. # parent_nc = None
  75. # for i in range(len(node_line)):
  76. # print (node_line[i])
  77. # # check each of the possible parent types.
  78. # if ( (node_line[ i ].__class__.__name__ == 'LinkInherit') ):
  79. # try: # it's the next one
  80. # return node_line[ i + 1 ]
  81. # except IndexError: # if there is no next one...
  82. # return None # then there's no parent!
  83. # return None
  84. # # TO DO!
  85. # #
  86. # # make this do shorthand parenting - if no parent, then use World
  87. # # if the parent node is skipped, use the previous node (an xForm)
  88. # # with default settings.
  89. # # it is OK to generate a new, "fake" node container for this!
  90. # #my_sig = get_node_signature(node, tree)
  91. def FindIKNode():
  92. pass