Parcourir la source

Basic implementation of Interface nodes in Schema

Joseph Brandenburg il y a 2 semaines
Parent
commit
d987aeeef1
1 fichiers modifiés avec 40 ajouts et 0 suppressions
  1. 40 0
      schema_solve.py

+ 40 - 0
schema_solve.py

@@ -89,6 +89,35 @@ class SchemaSolver:
                 mantis_node = SchemaConstOutput(signature=signature, base_tree=self.node.base_tree, parent_schema_node=self.node)
                 self.schema_nodes[signature] = mantis_node
                 mantis_node.fill_parameters(ui_node)
+        interface = self.setup_interface_node(signature=( *self.signature, "InputInterface"))
+    
+    def setup_interface_node(self, signature):
+        from .internal_containers import GroupInterface
+        interface = GroupInterface(
+            signature,
+            self.node.base_tree, self.node.prototype, 'INPUT',)
+        # now we need to connect it up
+        # adapted from readtree.grp_node_reroute_common
+        from .base_definitions import links_sort_key
+        for in_node_input in self.node.inputs:
+            if in_node_input.name != 'Schema Length':
+                for interface_socket in self.tree.interface.items_tree:
+                    if interface_socket.item_type == 'PANEL': continue
+                    if interface_socket.identifier == in_node_input.name: break
+                if hasattr(interface_socket, "is_array") and interface_socket.is_array: continue
+                if hasattr(interface_socket, "is_connection") and interface_socket.is_connection: continue
+                # for now, do not try and connect to the array/connection inputs.
+            i = 0
+            if len(in_node_input.links)>1: # sort here to ensure correct sub_sort_id
+                in_node_input.links.sort(key=links_sort_key)
+            for in_link in in_node_input.links:
+                from_node = in_link.from_node; from_socket = in_link.from_socket
+                link = from_node.outputs[from_socket].connect(
+                    interface,in_node_input.name, sort_id = 2**16, sub_sort_id=i)
+                i += 1
+            in_node_input.links.sort(key=links_sort_key)
+        return interface # I want to be able to set this up elsewhere
+
 
     def set_index_strings(self):
         self.index_str = lambda : '.'+str(self.uuid)+'.'+str(self.index).zfill(4)
@@ -199,6 +228,11 @@ class SchemaSolver:
             mantis_node.fill_parameters(prototype_ui_node)
             # be sure to pass on the Mantis Context to them
             mantis_node.mContext=mContext
+        # set up an interface node at this point.
+        interface = self.setup_interface_node(signature=( *self.signature, "InputInterface"+self.index_str() ))
+        interface.mContext = mContext
+        frame_mantis_nodes[interface.signature] = interface
+        self.all_nodes[interface.signature] = interface
 
     def handle_link_from_index_input(self, index, frame_mantis_nodes, ui_link):
         from .base_definitions import can_remove_socket_for_autogen
@@ -243,6 +277,12 @@ class SchemaSolver:
         else:
             raise RuntimeError("247 I This code should be unreachable. Please report this as a bug!")
 
+    # TODO: link the incoming connection to the current Interface node
+    #       It is complicated because the Interface needs the identifier
+    #       but most of this stuff uses the name and I donno how to get the ID
+    #       this isn't very important. I'll add this feature when someone tries
+    #       to use it and complains.
+
     def handle_link_from_incoming_connection_input(self, frame_mantis_nodes, ui_link):
         incoming = self.incoming_connections[ui_link.from_socket.name]
         if incoming is not None: