Ver Fonte

Another fix: NodeGroupUpdate now correctly makes all new nodes

The changes here make it so that the links are made correctly from the Reroutes

also they make it so the Node Groups check to see if they need to make a new
socket, and if not, hold the socket and reorder it after finishing the socket updates.
Joseph Brandenburg há 6 meses atrás
pai
commit
80595b60d6
2 ficheiros alterados com 31 adições e 5 exclusões
  1. 29 3
      base_definitions.py
  2. 2 2
      utilities.py

+ 29 - 3
base_definitions.py

@@ -390,6 +390,8 @@ def node_group_update(node, force = False):
 
         from .utilities import relink_socket_map_add_socket
 
+        reorder_me_input = []; input_index = 0
+        reorder_me_output = []; output_index = 0
         for item in node.node_tree.interface.items_tree:
             if item.item_type != "SOCKET": continue
             if (item.in_out == 'INPUT' and update_input):
@@ -398,19 +400,43 @@ def node_group_update(node, force = False):
                         socket = relink_socket_map_add_socket(node, node.inputs, item)
                         do_relink(node, socket, socket_map_in)
                     else:
-                        prRed(item.identifier)
+                        for has_socket in node.inputs:
+                            if has_socket.bl_idname == item.socket_type and \
+                                has_socket.name == item.name:
+                                reorder_me_input.append((has_socket, input_index))
+                                break
+                        else:
+                            socket = relink_socket_map_add_socket(node, node.inputs, item)
                 else:
-                    prGreen(item.identifier)
                     socket = relink_socket_map_add_socket(node, node.inputs, item)
+                input_index += 1
 
             if (item.in_out == 'OUTPUT' and update_output):
                 if socket_map_out:
                     if item.identifier in socket_map_out.keys():
                         socket = relink_socket_map_add_socket(node, node.outputs, item)
                         do_relink(node, socket, socket_map_out)
+                    else:
+                        for has_socket in node.outputs:
+                            if has_socket.bl_idname == item.socket_type and \
+                                has_socket.name == item.name:
+                                reorder_me_output.append((has_socket, output_index))
+                                break
+                        else:
+                            socket = relink_socket_map_add_socket(node, node.outputs, item)
                 else:
                     socket = relink_socket_map_add_socket(node, node.outputs, item)
-                    
+                output_index += 1
+        
+        both_reorders = zip([reorder_me_input, reorder_me_output], [node.inputs, node.outputs])
+        for reorder_task, collection in both_reorders:
+            for socket, position in reorder_task:
+                for i, s  in enumerate(collection): # get the index
+                    if s.identifier == socket.identifier: break
+                else:
+                    prRed(f"WARN: could not reorder socket {socket.name}")
+                collection.move(i, position)
+
         # at this point there is no wildcard socket
         if socket_map_in and '__extend__' in socket_map_in.keys():
             do_relink(node, None, socket_map_in, in_out='INPUT', parent_name='Constant' )

+ 2 - 2
utilities.py

@@ -168,9 +168,9 @@ def do_relink(node, s, map, in_out='INPUT', parent_name = ''):
             elif isinstance(sub_val, Node):
                 # this happens when it is a NodeReroute
                 if in_out =='INPUT':
-                    node.id_data.links.new(input=sub_val, output=node.inputs[0])
+                    node.id_data.links.new(input=sub_val.outputs[0], output=s)
                 else:
-                    node.id_data.links.new(input=node.outputs[0], output=sub_val)
+                    node.id_data.links.new(input=s, output=sub_val.inputs[0])
             else:
                 raise RuntimeError("Unhandled case in do_relink()")
     elif get_string != "__extend__":