internal_nodes.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. from .utilities.node_common import *
  2. from bpy.types import Node
  3. from .base_definitions import MantisNode, MantisSocketTemplate
  4. from uuid import uuid4
  5. # TODO: make node_type a class property like it is for everything else
  6. # I can't do this without making some changes to schema and anything that
  7. # checks for DUMMY SCHEMA
  8. class DummyNode(MantisNode):
  9. def __init__(self, signature, base_tree, ui_node = None, ui_signature=None):
  10. super().__init__(signature, base_tree)
  11. self.ui_node = ui_node
  12. self.prepared = True
  13. self.uuid = uuid4()
  14. self.solver = None
  15. self.node_type = 'DUMMY'
  16. if ui_node:
  17. if ui_node.bl_idname in ["MantisSchemaGroup"]:
  18. self.node_type = 'DUMMY_SCHEMA'
  19. self.prepared = False
  20. for sock in ui_node.inputs:
  21. if sock.identifier == "__extend__" or sock.name == "__extend__":
  22. continue
  23. self.inputs[sock.identifier] = NodeSocket(is_input = True, name = sock.identifier, node = self)
  24. for sock in ui_node.outputs:
  25. if sock.identifier == "__extend__" or sock.name == "__extend__":
  26. continue
  27. self.outputs[sock.identifier] = NodeSocket(is_input = False, name = sock.identifier, node = self)
  28. self.parameters[sock.identifier]=None
  29. # keep track of the "natural signature" of Schema nodes - so that they are unambiguous
  30. self.ui_signature=self.signature
  31. if ui_signature:
  32. self.ui_signature=ui_signature
  33. # This is necessary for Schema to work if there are multiple Schema nodes using the same Schema tree.
  34. # this is ugly and I hate it.
  35. self.execution_prepared=True # in case it gets left behind in the tree as a dependency
  36. class NoOpNode(MantisNode):
  37. node_type = 'UTILITY'
  38. def __init__(self, signature, base_tree):
  39. super().__init__(signature, base_tree)
  40. self.inputs.init_sockets(["Input"])
  41. self.outputs.init_sockets(["Output"])
  42. self.init_parameters()
  43. self.set_traverse([("Input", "Output")])
  44. self.prepared, self.executed = True, True
  45. self.execution_prepared=True
  46. # this node is useful for me to insert in the tree and use for debugging especially connections.
  47. class AutoGenNode(MantisNode):
  48. node_type = 'UTILITY'
  49. def __init__(self, signature, base_tree):
  50. super().__init__(signature, base_tree)
  51. self.prepared, self.executed = True, True
  52. self.execution_prepared=True
  53. def reset_execution(self):
  54. super().reset_execution()
  55. self.prepared, self.executed = True, True
  56. # The Group Interface node is responsible for gathering node connections
  57. # going in or out of the group and connecting back out the other side
  58. # this is also where caching and overlays live
  59. class GroupInterface(MantisNode):
  60. node_type = 'INTERFACE'
  61. def __init__(self, signature, base_tree, ui_node, in_out):
  62. super().__init__(signature, base_tree)
  63. self.prepared, self.executed = True, True; sockets = []
  64. self.in_out = in_out
  65. # init the sockets based on in/out, then set up traversal
  66. collection = ui_node.inputs if in_out == 'INPUT' else ui_node.outputs
  67. for socket in collection: sockets.append(socket.identifier)
  68. self.inputs.init_sockets(sockets); self.outputs.init_sockets(sockets)
  69. for socket in self.inputs.keys(): self.set_traverse( [(socket, socket)] )
  70. self.execution_prepared=True