f_nodegraph.py 4.0 KB

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