Преглед изворни кода

UI improvements to sockets layout & cleanup

also fixed array inputs again because the solution
I tried before totally did not work.
Joseph Brandenburg пре 9 месеци
родитељ
комит
c43860e8b8
5 измењених фајлова са 45 додато и 50 уклоњено
  1. 2 10
      node_container_common.py
  2. 4 0
      nodes_generic.py
  3. 3 0
      readtree.py
  4. 34 38
      socket_definitions.py
  5. 2 2
      utilities.py

+ 2 - 10
node_container_common.py

@@ -631,10 +631,9 @@ class NodeLink:
         self.to_node = to_node
         self.to_socket = to_socket
         self.from_node.outputs[self.from_socket].links.append(self)
+        # it is the responsibility of the node that uses these links to sort them correctly based on the sort_id
         self.multi_input_sort_id = multi_input_sort_id
         self.to_node.inputs[self.to_socket].links.append(self)
-        if self.multi_input_sort_id>0:
-            self.to_node.inputs[self.to_socket].links.sort(key=lambda a : -1*a.multi_input_sort_id)
         self.is_hierarchy = detect_hierarchy_link(from_node, from_socket, to_node, to_socket,)
         self.is_alive = True
     
@@ -682,6 +681,7 @@ class NodeSocket:
             self.can_traverse = True
         
     def connect(self, node, socket, sort_id=0):
+        prOrange(sort_id)
         if  (self.is_input):
             to_node   = self.node; from_node = node
             to_socket = self.name; from_socket = socket
@@ -697,14 +697,6 @@ class NodeSocket:
                 to_node,
                 to_socket,
                 sort_id)
-        
-        # if (from_node.signature[-2] in ["Chiral Identifier"] and
-            # from_node.signature[-1] in ['Input_4']):
-                # print(wrapRed("Connecting %s" % new_link),)
-        # if (from_node.signature[-2] in ["Chiral Identifier"] and
-            # from_node.signature[-1] in ['Input_3',]):
-                # print(wrapRed("Connecting %s" % new_link),)
-        
         return new_link
     
     def set_traverse_target(self, traverse_target):

+ 4 - 0
nodes_generic.py

@@ -374,6 +374,10 @@ class UtilityMetaRigNode(Node, MantisNode):
             self.inputs["Meta-Bone"].hide=True
         else:
             self.inputs["Meta-Bone"].hide=False
+        if self.inputs["Meta-Armature"].is_connected:
+            self.inputs["Meta-Armature"].search_prop = None
+        if self.inputs["Meta-Bone"].is_connected:
+            self.inputs["Meta-Bone"].search_prop = None
 
 class UtilityBonePropertiesNode(Node, MantisNode):
     """Provides as sockets strings identifying bone transform properties."""

+ 3 - 0
readtree.py

@@ -257,6 +257,9 @@ def solve_schema_to_tree(nc, all_nc, roots=[]):
     tree = np.node_tree
     prOrange(f"Expanding schema {tree.name} in node {nc} with length {length}.")
 
+    for inp in nc.inputs.values():
+        inp.links.sort(key=lambda a : -a.multi_input_sort_id)
+
     solver = SchemaSolver(nc, all_nc, np)
     solved_nodes = solver.solve(length)
     # prGreen(f"Finished solving schema {tree.name} in node {nc}.")

+ 34 - 38
socket_definitions.py

@@ -99,7 +99,6 @@ def TellClasses():
             #  LayerMaskSocket,
             #  LayerMaskInputSocket,
              BoneCollectionSocket,
-             BoneCollectionInputSocket,
              EnumArrayGetOptions,
              
              xFormParameterSocket,
@@ -305,25 +304,28 @@ def update_metarig_posebone(self, context,):
 def ChooseDraw(self, context, layout, node, text, icon = "NONE", use_enum=True, nice_bool=True, icon_only=False):
     # return
     # TEXT ONLY
-    if ( (hasattr(self, "text_only")) and (getattr(self, "text_only") ) ):
+    if self.node.bl_idname in ["NodeGroupInput", "NodeGroupOutput"]:
         layout.label(text=text)
-    # ENUM VALUES (this is a HACK, fix it later)
-    elif ('Enum' in self.bl_idname) and (use_enum):
-        layout.prop_tabs_enum(self, "default_value",)
-    # for OUTPUT sockets that take INPUT (confusing name!)
-    elif ((hasattr(self, "default_value")) and hasattr(self, "input") and getattr(self, "input")):
-        # for simple input nodes
-        layout.prop(self, "default_value", text=text, toggle=nice_bool, slider=True)
-    # for INPUTS that are NOT CONNECTED
-    elif (hasattr(self, "default_value")) and not (self.is_output or self.is_linked):
-        # DO: expose these values as parameters for this function
-        #   and set them for each socket.
-        if icon == 'NONE': icon_only = False
-        elif icon_only == True : text = "" # "real" icon-only looks bad for strings, need to check other props types.
-        layout.prop(self, "default_value", text=text, toggle=nice_bool, slider=True, icon=icon,)
-    # CONNECTED sockets and outputs without input fields
     else:
-        layout.label(text=text)
+        if ( (hasattr(self, "text_only")) and (getattr(self, "text_only") ) ):
+            layout.label(text=text)
+        # ENUM VALUES (this is a HACK, fix it later)
+        elif ('Enum' in self.bl_idname) and (use_enum):
+            layout.prop_tabs_enum(self, "default_value",)
+        # for OUTPUT sockets that take INPUT (confusing name!)
+        elif ((hasattr(self, "default_value")) and hasattr(self, "input") and getattr(self, "input")):
+            # for simple input nodes
+            layout.prop(self, "default_value", text=text, toggle=nice_bool, slider=True)
+        # for INPUTS that are NOT CONNECTED
+        elif (hasattr(self, "default_value")) and not (self.is_output or self.is_linked):
+            # DO: expose these values as parameters for this function
+            #   and set them for each socket.
+            if icon == 'NONE': icon_only = False
+            elif icon_only == True : text = "" # "real" icon-only looks bad for strings, need to check other props types.
+            layout.prop(self, "default_value", text=text, toggle=nice_bool, slider=True, icon=icon,)
+        # CONNECTED sockets and outputs without input fields
+        else:
+            layout.label(text=text)
 
 class RelationshipSocket(NodeSocket):
     # Description string
@@ -753,22 +755,7 @@ class BoneCollectionSocket(bpy.types.NodeSocket):
     @classmethod
     def draw_color_simple(self):
         return self.color_simple
-        
-class BoneCollectionInputSocket(bpy.types.NodeSocket):
-    """Bone Collection Input Socket"""
-    bl_idname = 'BoneCollectionInputSocket'
-    bl_label = "Bone Collection"
-    default_value: bpy.props.StringProperty(default = "Collection", update = update_socket,)
-    input : bpy.props.BoolProperty(default =True,)
-    color_simple = cBoneCollection
-    color : bpy.props.FloatVectorProperty(default=cBoneCollection, size=4)
-    def draw(self, context, layout, node, text):
-        ChooseDraw(self, context, layout, node, text)
-    def draw_color(self, context, node):
-        return self.color
-    @classmethod
-    def draw_color_simple(self):
-        return self.color_simple
+
 
 
 eArrayGetOptions =(
@@ -980,10 +967,17 @@ class EnumMetaRigSocket(NodeSocket):
     color_simple = cString
     color : bpy.props.FloatVectorProperty(default=cString, size=4)
     def draw(self, context, layout, node, text):
-        if not (self.is_linked):
+        if self.is_output:
+            layout.label(text=self.name)
+        elif not (self.is_linked):
             layout.prop_search(data=self, property="search_prop", search_data=bpy.data, search_property="objects", text="", icon="OUTLINER_OB_ARMATURE", results_are_suggestions=True)
-        else:
+        elif hasattr(self.node, "armature"):
             layout.label(text=self.node.armature)
+            # TODO: we should actually use the parsed tree to query this info directly, since this socket may belong to a node group in/out
+            # which doesn't have this parameter. whatever.
+        else:
+            layout.label(text=self.name)
+        
         
     def draw_color(self, context, node):
         return self.color
@@ -1012,12 +1006,14 @@ class EnumCurveSocket(NodeSocket):
     color : bpy.props.FloatVectorProperty(default=cString, size=4)
     def draw(self, context, layout, node, text):
         if not (self.is_linked):
-            layout.prop_search(data=self, property="search_prop", search_data=bpy.data, search_property="objects", text="", icon="OUTLINER_OB_ARMATURE", results_are_suggestions=True)
+            layout.prop_search(data=self, property="search_prop", search_data=bpy.data, search_property="objects", text="", icon="CURVE_DATA", results_are_suggestions=True)
         else:
             try:
                 layout.label(text=self.search_prop.name)
             except AttributeError: # TODO make this show the graph's result
-                layout.label(text="")
+                layout.label(text=self.name)
+
+
         
     def draw_color(self, context, node):
         return self.color

+ 2 - 2
utilities.py

@@ -171,7 +171,7 @@ def clear_reroutes(links):
             kept_links.append(link)
     for start in rerouted_starts:
         from_socket = socket_seek(start, rerouted)
-        new_link = DummyLink(from_socket=from_socket, to_socket=start.to_socket, nc_from=None, nc_to=None, )
+        new_link = DummyLink(from_socket=from_socket, to_socket=start.to_socket, nc_from=None, nc_to=None, multi_input_sort_id=start.multi_input_sort_id )
         kept_links.append(new_link)
     return kept_links
 
@@ -799,7 +799,6 @@ def gen_nc_input_for_data(socket):
                         # "LayerMaskInputSocket"               : classes["InputLayerMask"],
                         # "LayerMaskSocket"                    : classes["InputLayerMask"],
                         "BoneCollectionSocket"                 : classes["InputString"],
-                        "BoneCollectionInputSocket"            : classes["InputString"],
                         #
                         "xFormParameterSocket"                 : None,
                         "ParameterBoolSocket"                  : classes["InputBoolean"],
@@ -831,6 +830,7 @@ def gen_nc_input_for_data(socket):
                         "EnumYScaleMode"                       : classes["InputString"],
                         "EnumXZScaleMode"                      : classes["InputString"],
                         "EnumCurveSocket"                      : classes["InputString"],
+                        "EnumMetaRigSocket"             : classes["InputString"],
                         # Deformers
                         "EnumSkinning"                         : classes["InputString"],
                         #