Эх сурвалжийг харах

GroupInterfaceNodes at group in/out

This commit fixes and finishes the last commit.
All I forgot was to add the nodes to the parsed tree,
and deal with a little bit of hardcoded foolishness
that assumed there would be no intervening nodes
using socket traversal.

There will be more fixing for this behaviour in the near
future, no doubt. But this works, and it opens up
a whole lot of doors.
Joseph Brandenburg 2 долоо хоног өмнө
parent
commit
587aaef964
4 өөрчлөгдсөн 31 нэмэгдсэн , 59 устгасан
  1. 0 2
      base_definitions.py
  2. 7 8
      readtree.py
  3. 16 37
      visualize.py
  4. 8 12
      xForm_nodes.py

+ 0 - 2
base_definitions.py

@@ -136,8 +136,6 @@ class MantisTree(NodeTree):
                 scene = bpy.context.scene
                 scene.render.use_lock_interface = True
                 self.parsed_tree = readtree.parse_tree(self, error_popups)
-                from .visualize import visualize_tree
-                visualize_tree(self.parsed_tree, self, context)
                 if context:
                     self.display_update(context)
                 self.tree_valid = True

+ 7 - 8
readtree.py

@@ -14,7 +14,7 @@ def grp_node_reroute_common(in_node, out_node, interface):
             # the inputs/outputs on the group and in/out nodes are IDs
             from_node.outputs[from_socket].connect(
                 interface,in_node_input.name, sort_id = in_link.multi_input_sort_id)
-            # in_link.die()
+            in_link.die()
             init_connections(from_node)
     for out_node_output in out_node.outputs:
         while (out_node_output.links):
@@ -23,7 +23,7 @@ def grp_node_reroute_common(in_node, out_node, interface):
             for l in interface.inputs[out_node_output.name].links:
                 interface.outputs[out_node_output.name].connect(
                     to_node, to_socket, sort_id = l.multi_input_sort_id)
-            # out_link.die()
+            out_link.die()
             init_dependencies(to_node)
     init_dependencies(interface); init_connections(interface)
 
@@ -32,6 +32,7 @@ def reroute_links_grp(group, all_nodes):
     interface = GroupInterface(
         ( *group.signature, "InputInterface"),
         group.base_tree, group.prototype, 'INPUT',)
+    all_nodes[interface.signature] = interface
     if group.inputs:
         if group_input := all_nodes.get(( *group.signature, "NodeGroupInput")):
             grp_node_reroute_common(group, group_input, interface)
@@ -44,6 +45,7 @@ def reroute_links_grpout(group_output, all_nodes):
         interface = GroupInterface(
             ( *group.signature, "OutputInterface"),
             group.base_tree, group.prototype, 'OUTPUT',)
+        all_nodes[interface.signature] = interface
         grp_node_reroute_common(group_output, group, interface)
     else:
         prOrange(f"WARN: unconnected outputs from a node group "
@@ -56,7 +58,6 @@ def insert_lazy_parents(nc):
     inherit_nc = None
     if nc.inputs["Relationship"].is_connected:
         link = nc.inputs["Relationship"].links[0]
-        # print(nc)
         from_nc = link.from_node
         if from_nc.node_type in ["XFORM"] and link.from_socket in ["xForm Out"]:
             inherit_nc = LinkInherit(("MANTIS_AUTOGENERATED", *nc.signature[1:], "LAZY_INHERIT"), nc.base_tree)
@@ -413,7 +414,6 @@ def parse_tree(base_tree, error_popups=False):
             init_schema_dependencies(schema, all_mantis_nodes)
             solve_only_these.extend(get_schema_length_dependencies(schema, all_mantis_nodes))
             unsolved_schema.append(schema)
-    print (solve_only_these)
     for array in array_nodes:
         if array not in solve_only_these: continue
         solve_only_these.extend(get_schema_length_dependencies(array))
@@ -486,7 +486,8 @@ def parse_tree(base_tree, error_popups=False):
         if nc.signature[0] == "MANTIS_AUTOGENERATED" and len(nc.inputs) == 0 and len(nc.outputs) == 1:
             from .base_definitions import can_remove_socket_for_autogen
             output=list(nc.outputs.values())[0]
-            value=list(nc.parameters.values())[0]   # IDEA modify the dependecy get function to exclude these nodes completely
+            value=list(nc.parameters.values())[0]
+            # We can remove this node if it is safe to push it into the other node's socket.
             keep_me = False
             for l in output.links:
                 to_node = l.to_node; to_socket = l.to_socket
@@ -622,9 +623,8 @@ def execute_tree(nodes, base_tree, context, error_popups = False):
         check_and_add_root(nc, xForm_pass)
     mContext.execution_failed = False
 
-    switch_me = [] # switch the mode on these objects
+    select_me, switch_me = [], [] # switch the mode on these objects
     active = None # only need it for switching modes
-    select_me = []
     try:
         sorted_nodes, execution_failed = sort_execution(nodes, xForm_pass)
         for n in sorted_nodes:
@@ -666,7 +666,6 @@ def execute_tree(nodes, base_tree, context, error_popups = False):
         # switch to pose mode here so that the nodes can use the final pose data
         # this will require them to update the depsgraph.
 
-
         for ob in switch_me:
             ob.data.pose_position = 'POSE'
 

+ 16 - 37
visualize.py

@@ -112,7 +112,7 @@ class MantisVisualizeNode(Node):
 def gen_vis_node( mantis_node,
                   vis_tree,
                   links,
-                  omit_simple=True,
+                  omit_simple=False,
                  ):
     from .base_definitions import array_output_types
     # if mantis_node.node_type == 'UTILITY' and \
@@ -141,12 +141,11 @@ def visualize_tree(m_nodes, base_tree, context):
     import cProfile
     import pstats, io
     from pstats import SortKey
+    cull_no_links = False
     with cProfile.Profile() as pr:
         try:
-            trace_from_roots = False
-            all_links = set()
-            mantis_nodes=set()
-            nodes={}
+            trace_from_roots = True
+            all_links = set(); mantis_nodes=set(); nodes={}
             if trace_from_roots:
                 roots=[]
                 for n in m_nodes.values():
@@ -157,12 +156,13 @@ def visualize_tree(m_nodes, base_tree, context):
                     print ("No nodes to visualize")
                     return
             else:
+                mantis_keys  = list(base_tree.parsed_tree.keys())
                 mantis_nodes = list(base_tree.parsed_tree.values())
 
             vis_tree = bpy.data.node_groups.new(base_tree.name+'_visualized', type='MantisVisualizeTree')
 
-            for m in mantis_nodes:
-                nodes[m.signature]=gen_vis_node(m, vis_tree,all_links)
+            for i, m in enumerate(mantis_nodes):
+                nodes[m.signature]=gen_vis_node(m, vis_tree, all_links)
                 # useful for debugging: check the connections for nodes that are
                 # not in the parsed tree or available from trace_all_nodes_from_root.
 
@@ -170,8 +170,8 @@ def visualize_tree(m_nodes, base_tree, context):
                 # if l.to_node.node_type in ['DUMMY_SCHEMA', 'DUMMY'] or \
                 # l.from_node.node_type in ['DUMMY_SCHEMA', 'DUMMY']:
                 #     pass
-                from_node=nodes.get(l.from_node.signature)
-                to_node=nodes.get(l.to_node.signature)
+                from_node = nodes.get(l.from_node.signature)
+                to_node   = nodes.get(l.to_node.signature)
                 from_socket, to_socket = None, None
                 if from_node and to_node:
                     from_socket = from_node.outputs.get(l.from_socket)
@@ -197,35 +197,14 @@ def visualize_tree(m_nodes, base_tree, context):
                 return False
 
             no_links=[]
+            if cull_no_links == True:
+                for n in vis_tree.nodes:
+                    if not has_links(n):
+                        no_links.append(n)
+                while (no_links):
+                    n = no_links.pop()
+                    vis_tree.nodes.remove(n)
 
-            for n in vis_tree.nodes:
-                if not has_links(n):
-                    no_links.append(n)
-
-            while (no_links):
-                n = no_links.pop()
-                vis_tree.nodes.remove(n)
-
-            # def side_len(n):
-            #     from math import floor
-            #     side = floor(n**(1/2)) + 1
-            #     return side
-            # side=side_len(len(no_links))
-            # break_me = True
-            # for i in range(side):
-            #     for j in range(side):
-            #         index = side*i+j
-            #         try:
-            #             n = no_links[index]
-            #             n.location.x = i*200
-            #             n.location.y = j*200
-            #         except IndexError:
-            #             break_me = True # it's too big, that's OK the square is definitely bigger
-            #             break
-            #     if break_me:
-            #         break
-            # from .utilities import SugiyamaGraph
-            # SugiyamaGraph(vis_tree, 1) # this can take a really long time
         finally:
             s = io.StringIO()
             sortby = SortKey.TIME

+ 8 - 12
xForm_nodes.py

@@ -267,23 +267,19 @@ class xFormBone(xFormNode):
         #should do the trick...
 
     def bSetParent(self, eb):
-        # print (self.bObject)
         from bpy.types import EditBone
         parent_nc = get_parent_node(self, type='LINK')
-        # print (self, parent_nc.inputs['Parent'].from_node)
-        parent=None
-        if parent_nc.inputs['Parent'].links[0].from_node.node_type == 'XFORM':
-            parent = parent_nc.inputs['Parent'].links[0].from_node.bGetObject(mode = 'EDIT')
+        node_lines, _last_socket = trace_single_line(parent_nc, 'Parent')
+        if node_lines[-1].node_type == 'XFORM':
+            parent = node_lines[-1].bGetObject(mode = 'EDIT')
+            if isinstance(parent, EditBone): # otherwise, no need to do anything.
+                eb.parent = parent
+                eb.use_connect = parent_nc.evaluate_input("Connected")
+                eb.use_inherit_rotation = parent_nc.evaluate_input("Inherit Rotation")
+                eb.inherit_scale = parent_nc.evaluate_input("Inherit Scale")
         else:
             raise RuntimeError(wrapRed(f"Cannot set parent for node {self}"))
 
-        if isinstance(parent, EditBone):
-            eb.parent = parent
-
-        eb.use_connect = parent_nc.evaluate_input("Connected")
-        eb.use_inherit_rotation = parent_nc.evaluate_input("Inherit Rotation")
-        eb.inherit_scale = parent_nc.evaluate_input("Inherit Scale")
-        # otherwise, no need to do anything.
 
     def bPrepare(self, bContext=None):
         self.parameters['Matrix'] = get_matrix(self)