Browse Source

generate interface nodes during tree parse

this commit makes the interface nodes generate a little earlier, during tree parse
instead of just after parsing during the group node relink stage
Joseph Brandenburg 1 week ago
parent
commit
361aeb7755
5 changed files with 43 additions and 28 deletions
  1. 1 2
      dev_helpers/visualize.py
  2. 31 9
      execution/readtree.py
  3. 4 3
      execution/schema_solve.py
  4. 6 12
      internal_nodes.py
  5. 1 2
      misc_nodes.py

+ 1 - 2
dev_helpers/visualize.py

@@ -237,8 +237,7 @@ class MantisVisualizeOutput(Operator):
 
     def execute(self, context):
         from time import time
-        from ..utilities.utilities import wrapGreen, prGreen
-
+        from ..utilities.utilities import prGreen
         tree=context.space_data.path[0].node_tree
         tree.update_tree(context)
         prGreen(f"Visualize Tree: {tree.name}")

+ 31 - 9
execution/readtree.py

@@ -49,8 +49,7 @@ def autogen_node(base_tree, ui_socket, signature, mContext):
     mantis_node.ui_signature = None # does not exist in the UI
     return mantis_node
 
-# TODO: investigate whether I can set the properties in the downstream nodes directly.
-#       I am doing this in Schema Solver and it seems to work quite efficiently.
+
 def make_connections_to_ng_dummy(base_tree, tree_path_names, local_mantis_nodes, all_mantis_nodes, to_mantis_node):
     from ..socket_definitions import no_default_value
     for inp in to_mantis_node.ui_node.inputs:
@@ -66,21 +65,22 @@ def make_connections_to_ng_dummy(base_tree, tree_path_names, local_mantis_nodes,
             #  using UUID signature leads to TERRIBLE CONFUSING BUGS.
             if from_mantis_node is None: 
                 from_mantis_node = autogen_node(base_tree, inp, signature, to_mantis_node.mContext)
+                local_mantis_nodes[signature]=from_mantis_node
+                all_mantis_nodes[signature]=from_mantis_node
             if from_mantis_node: # autogen can fail and we should catch it.
                 from mathutils import Matrix
-                from_mantis_node.parameters = {inp.name: 
+                from_mantis_node.parameters[inp.name] = \
                                                Matrix(( tuple(inp.default_value[0:4]), \
                                                         tuple(inp.default_value[4:8]), \
                                                         tuple(inp.default_value[8:12]), \
                                                         tuple(inp.default_value[12:16]) )) if inp.bl_idname == 'MatrixSocket' \
-                                                            else inp.default_value}
-                local_mantis_nodes[signature] = from_mantis_node; all_mantis_nodes[signature] = from_mantis_node
+                                                            else inp.default_value
                 from_mantis_node.outputs[inp.name].connect(node=to_mantis_node, socket=to_s, sort_id=0)
             else:
-                prRed("No available auto-generated class for input %s in %s" % (inp.name, np.name))
+                prRed("No available auto-generated class for input %s in %s" % (inp.name, to_mantis_node.ui_node.name))
 
 def gen_mantis_nodes(base_tree, current_tree, tree_path_names, mContext, all_mantis_nodes, local_mantis_nodes, dummy_nodes, group_nodes, schema_nodes, in_schema ):
-    from ..internal_nodes import DummyNode
+    from ..internal_nodes import DummyNode, GroupInterface
     for ui_node in current_tree.nodes:
         mantis_node = None
         if ui_node.bl_idname in ["NodeFrame", "NodeReroute"]:
@@ -93,16 +93,38 @@ def gen_mantis_nodes(base_tree, current_tree, tree_path_names, mContext, all_man
                 mantis_node = DummyNode( signature=sig , base_tree=base_tree, ui_node=ui_node, ui_signature=ui_sig )
                 local_mantis_nodes[sig] = mantis_node; all_mantis_nodes[sig] = mantis_node; dummy_nodes[sig] = mantis_node
                 if ui_node.bl_idname in {"NodeGroupOutput"}:
+                    # We need an interface node, let's make it now.
+                    items_tree = ui_node.id_data.interface.items_tree
+                    interface = GroupInterface(
+                        # we'll clip the 'NodeGroupOutput' from the signature
+                        ( *mantis_node.signature[:-1], "OutputInterface"),
+                        mantis_node.base_tree, 'OUTPUT', ui_node=mantis_node.ui_node,
+                        items_tree=items_tree,)
+                    interface.mContext = mContext
+                    all_mantis_nodes[interface.signature] = interface; local_mantis_nodes[interface.signature] = interface
                     mantis_node.reroute_links_type = 'out'
         elif ui_node.bl_idname in  ["MantisNodeGroup", "MantisSchemaGroup"]:
             mantis_node = DummyNode( signature= (sig := (None, *tree_path_names, ui_node.name) ), base_tree=base_tree, ui_node=ui_node )
+            mantis_node.mContext = mContext
             local_mantis_nodes[sig] = mantis_node; all_mantis_nodes[sig] = mantis_node; dummy_nodes[sig] = mantis_node
-            make_connections_to_ng_dummy(base_tree, tree_path_names, local_mantis_nodes, all_mantis_nodes, mantis_node)
-            group_nodes.append(mantis_node)
+            items_tree = ui_node.node_tree.interface.items_tree
             if ui_node.bl_idname == "MantisNodeGroup":
                 mantis_node.reroute_links_type = 'group'
+                name = 'InputInterface'
+                interface_in_out = 'INPUT'
             else:
                 schema_nodes[sig] = mantis_node
+                name = 'InputInterface.0000'
+                interface_in_out = 'SCHEMA_INPUT'
+            # let's make the interface node for this now
+            interface = GroupInterface(
+                ( *mantis_node.signature, name), mantis_node.base_tree,
+                   interface_in_out, mantis_node.ui_node, items_tree=items_tree )
+            interface.mContext = mContext
+            all_mantis_nodes[interface.signature] = interface; local_mantis_nodes[interface.signature] = interface
+            group_nodes.append(mantis_node)
+            # This function depends on generating the interface
+            make_connections_to_ng_dummy(base_tree, tree_path_names, local_mantis_nodes, all_mantis_nodes, mantis_node)
         # if it wasn't the types we ignore or the types we make a Dummy for, use this to catch all non-special cases.
         elif (mantis_class := ui_node.mantis_class):
             sig = (None, *tree_path_names, ui_node.name)

+ 4 - 3
execution/schema_solve.py

@@ -168,9 +168,10 @@ class SchemaSolver:
             if i == 0: in_out = 'SCHEMA_INPUT'
             else:      in_out = 'SCHEMA_BETWEEN'
             signature = (*self.autogen_path_names, name)
-            interface = GroupInterface(signature=signature, base_tree=self.tree, in_out=in_out, 
-                        ui_node=None, items_tree=items_tree)
-            interface.mContext = mContext
+            if not (interface := self.all_nodes.get( signature)):
+                interface = GroupInterface(signature=signature, base_tree=self.tree, in_out=in_out, 
+                            ui_node=None, items_tree=items_tree)
+                interface.mContext = mContext
             mContext.interface_nodes[interface.signature] = interface
             interface.generated_at_schema_index = self.node.generated_at_schema_index + [i]
             # add the index and length socket constants

+ 6 - 12
internal_nodes.py

@@ -49,11 +49,7 @@ def grp_node_reroute_common(in_node, out_node, interface):
             out_link.die()
 
 def reroute_links_grp(group, all_nodes):
-    items_tree = group.ui_node.node_tree.interface.items_tree
-    interface = GroupInterface(
-        ( *group.signature, "InputInterface"), group.base_tree,
-            'INPUT', group.ui_node, items_tree=items_tree )
-    all_nodes[interface.signature] = interface
+    interface = all_nodes.get( ( *group.signature, "InputInterface") )
     if group.inputs:
         if group_input := all_nodes.get(( *group.signature, "NodeGroupInput")):
             grp_node_reroute_common(group, group_input, interface)
@@ -62,12 +58,7 @@ def reroute_links_grp(group, all_nodes):
 
 def reroute_links_grpout(group_output, all_nodes):
     if (group_output_node := all_nodes.get( ( *group_output.signature[:-1],) )):
-        items_tree = group_output_node.ui_node.id_data.interface.items_tree
-        interface = GroupInterface(
-            ( *group_output_node.signature, "OutputInterface"),
-            group_output_node.base_tree, 'OUTPUT', ui_node=group_output_node.ui_node,
-            items_tree=items_tree,)
-        all_nodes[interface.signature] = interface
+        interface = all_nodes.get( ( *group_output_node.signature, "OutputInterface") )
         grp_node_reroute_common(group_output, group_output_node, interface)
     else:
         prOrange(f"WARN: unconnected outputs from a node group "
@@ -156,7 +147,10 @@ class GroupInterface(MantisNode):
         
         # the index and length are like constant inputs.
         if self.in_out == 'SCHEMA_INPUT':
-            self.outputs["Length"] = NodeSocket(is_input=False, node=self, name="Length")
+            # this one is here because the tree expects it when linking things together
+            self.outputs["Schema Length"] = NodeSocket(is_input=False, node=self, name="Schema Length")
+            # HACK this one here is just there for overlays, really, doesn't hurt
+            self.outputs["Length"] = self.outputs["Schema Length"]
         if 'SCHEMA' in self.in_out: 
             self.outputs["Index"]  = NodeSocket(is_input=False, node=self, name="Index")
                

+ 1 - 2
misc_nodes.py

@@ -623,8 +623,7 @@ class UtilityNumberOfCurveSegments(MantisMiscNode):
             self.parameters["Number of Segments"] = len(spline.bezier_points)-1
         else:
             self.parameters["Number of Segments"] = len(spline.points)-1
-        self.prepared = True
-        self.executed = True
+        self.prepared = True; self.executed = True
 
 class UtilityNumberOfSplines(MantisMiscNode):
     __slots__ = ()