Browse Source

Feature: Nodes show names

this is a first hack at making the node graph show xForm's names and the result of Cat String nodes
in future I will be looking to make this sort of interactive feedback more pervasive and reliable.
This commit also fixes some problems with the xFormBone display update code that may have interfered with the previous commit
finally there is a tiny bit of cleanup in the Matrix nodes' code.
Joseph Brandenburg 8 months ago
parent
commit
a479d918cc
4 changed files with 85 additions and 41 deletions
  1. 25 7
      nodes_generic.py
  2. 4 2
      socket_definitions.py
  3. 2 0
      xForm_containers.py
  4. 54 32
      xForm_definitions.py

+ 25 - 7
nodes_generic.py

@@ -200,9 +200,6 @@ class InputMatrixNode(Node, MantisNode):
     def init(self, context):
     def init(self, context):
         self.outputs.new('MatrixSocket', "Matrix")
         self.outputs.new('MatrixSocket', "Matrix")
         self.initialized = True
         self.initialized = True
-        
-    def update_node(self, context):
-        self.outputs["Matrix"].default_value = self.set_matrix()
 
 
     def draw_buttons(self, context, layout):
     def draw_buttons(self, context, layout):
         # return
         # return
@@ -254,16 +251,13 @@ class MetaRigMatrixNode(Node, MantisNode):
         self.initialized = True
         self.initialized = True
     
     
     def traverse(self, context):
     def traverse(self, context):
-        from mathutils import Matrix
+        # from mathutils import Matrix
         v = self.outputs[0].default_value
         v = self.outputs[0].default_value
         # print( Matrix( ( ( v[ 0], v[ 1], v[ 2], v[ 3],),
         # print( Matrix( ( ( v[ 0], v[ 1], v[ 2], v[ 3],),
         #                  ( v[ 4], v[ 5], v[ 6], v[ 7],),
         #                  ( v[ 4], v[ 5], v[ 6], v[ 7],),
         #                  ( v[ 8], v[ 9], v[10], v[11],),
         #                  ( v[ 8], v[ 9], v[10], v[11],),
         #                  ( v[12], v[13], v[14], v[15],), ) ) )
         #                  ( v[12], v[13], v[14], v[15],), ) ) )
         return None
         return None
-    
-    def update_node(self, context):
-        self.outputs["Matrix"].default_value = self.set_matrix()
 
 
     def update(self):
     def update(self):
         mat_sock = self.outputs[0]
         mat_sock = self.outputs[0]
@@ -559,6 +553,30 @@ class UtilityCatStringsNode(Node, MantisNode):
         self.inputs.new("StringSocket", "String_2")
         self.inputs.new("StringSocket", "String_2")
         self.outputs.new("StringSocket", "OutputString")
         self.outputs.new("StringSocket", "OutputString")
         self.initialized = True
         self.initialized = True
+
+    def draw_label(self): # this will prefer a user-set label, or return the evaluated name
+        if self.label:
+            return self.label
+        if self.outputs['OutputString'].display_text:
+            return self.outputs['OutputString'].display_text
+        return self.name
+        
+    def display_update(self, parsed_tree, context):
+        from .base_definitions import get_signature_from_edited_tree
+        if context.space_data:
+            nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
+            self.inputs['String_1'].display_text = ""
+            self.inputs['String_2'].display_text = ""
+            self.outputs['OutputString'].display_text = ""
+            if nc:
+                try:
+                    self.inputs['String_1'].display_text = a = nc.evaluate_input("String_1")
+                    self.inputs['String_2'].display_text = b = nc.evaluate_input("String_2")
+                    # cat the strings here, since the node may not have run yet.
+                    self.outputs['OutputString'].display_text = a+b
+                except KeyError:
+                    return # the tree isn't ready yet.
+                
     
     
 class InputLayerMaskNode(Node, MantisNode):
 class InputLayerMaskNode(Node, MantisNode):
     """Represents a layer mask for a bone."""
     """Represents a layer mask for a bone."""

+ 4 - 2
socket_definitions.py

@@ -307,6 +307,8 @@ def ChooseDraw(self, context, layout, node, text, icon = "NONE", use_enum=True,
     # TEXT ONLY
     # TEXT ONLY
     if self.node.bl_idname in ["NodeGroupInput", "NodeGroupOutput"]:
     if self.node.bl_idname in ["NodeGroupInput", "NodeGroupOutput"]:
         layout.label(text=text)
         layout.label(text=text)
+    elif hasattr(self, "display_text") and self.display_text:
+            layout.label(text=self.display_text)
     else:
     else:
         if ( (hasattr(self, "text_only")) and (getattr(self, "text_only") ) ):
         if ( (hasattr(self, "text_only")) and (getattr(self, "text_only") ) ):
             layout.label(text=text)
             layout.label(text=text)
@@ -706,11 +708,12 @@ class StringSocket(bpy.types.NodeSocketString):
     color : bpy.props.FloatVectorProperty(default=cString, size=4)
     color : bpy.props.FloatVectorProperty(default=cString, size=4)
     icon : bpy.props.StringProperty(default = "NONE",)
     icon : bpy.props.StringProperty(default = "NONE",)
     input : bpy.props.BoolProperty(default =False,)
     input : bpy.props.BoolProperty(default =False,)
+    display_text : bpy.props.StringProperty(default="")
     # def init(self):
     # def init(self):
         # if self.node.bl_idname == 'UtilityBoneProperties':
         # if self.node.bl_idname == 'UtilityBoneProperties':
             # self.display_shape='CIRCLE_DOT'
             # self.display_shape='CIRCLE_DOT'
     def draw(self, context, layout, node, text):
     def draw(self, context, layout, node, text):
-        ChooseDraw(self, context, layout, node, text, icon=self.icon, icon_only=True)
+        ChooseDraw(self, context, layout, node, text, icon=self.icon, icon_only=True,)
     def draw_color(self, context, node):
     def draw_color(self, context, node):
         return self.color
         return self.color
     @classmethod
     @classmethod
@@ -982,7 +985,6 @@ class EnumMetaRigSocket(NodeSocket):
         else:
         else:
             layout.label(text=self.name)
             layout.label(text=self.name)
         
         
-        
     def draw_color(self, context, node):
     def draw_color(self, context, node):
         return self.color
         return self.color
     @classmethod
     @classmethod

+ 2 - 0
xForm_containers.py

@@ -364,6 +364,7 @@ class xFormBone:
         self.prepared = True
         self.prepared = True
         self.executed = False
         self.executed = False
         self.input_length = len(self.inputs) # HACK HACK HACK 
         self.input_length = len(self.inputs) # HACK HACK HACK 
+        self.bObject=None
     
     
     def bGetParentArmature(self):
     def bGetParentArmature(self):
         finished = False
         finished = False
@@ -715,6 +716,7 @@ class xFormBone:
                 pb.custom_shape = ob 
                 pb.custom_shape = ob 
 
 
     def bGetObject(self, mode = 'POSE'):
     def bGetObject(self, mode = 'POSE'):
+        if self.bObject is None: return None
         if mode in ["POSE", "OBJECT"] and self.bGetParentArmature().mode == "EDIT":
         if mode in ["POSE", "OBJECT"] and self.bGetParentArmature().mode == "EDIT":
             raise RuntimeError("Cannot get Bone or PoseBone in Edit mode.")
             raise RuntimeError("Cannot get Bone or PoseBone in Edit mode.")
         elif mode == "EDIT" and self.bGetParentArmature().mode != "EDIT":
         elif mode == "EDIT" and self.bGetParentArmature().mode != "EDIT":

+ 54 - 32
xForm_definitions.py

@@ -57,6 +57,14 @@ def check_if_connected(start, end, line):
     return True
     return True
 
 
 
 
+def main_draw_label(self): # this will prefer a user-set label, or return the evaluated name
+    if self.label:
+        return self.label
+    if self.inputs['Name'].display_text:
+        return self.inputs['Name'].display_text
+    return self.name
+
+
 # I had chat gpt flip these so they may be a little innacurate
 # I had chat gpt flip these so they may be a little innacurate
 # always visible
 # always visible
 main_names = {
 main_names = {
@@ -218,43 +226,27 @@ class xFormBoneNode(Node, xFormNode):
             layout.operator("mantis.remove_custom_property", text='-Remove Custom Parameter')
             layout.operator("mantis.remove_custom_property", text='-Remove Custom Parameter')
         else:
         else:
             layout.label(text="")
             layout.label(text="")
+    
+    def draw_label(self): # this will prefer a user-set label, or return the evaluated name
+        return main_draw_label(self)
+
         
         
     def display_update(self, parsed_tree, context):
     def display_update(self, parsed_tree, context):
         if context.space_data:
         if context.space_data:
             nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
             nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
-            other_nc = None
-            if len(self.inputs.get("Relationship").links)>0:
-                prev_node = self.inputs.get("Relationship").links[0].from_node
-                if prev_node:
-                    other_nc = parsed_tree.get(get_signature_from_edited_tree(prev_node, context))
-            
+            self.display_ik_settings = False
             if nc and (pb := nc.bGetObject(mode='POSE')):
             if nc and (pb := nc.bGetObject(mode='POSE')):
                 self.display_ik_settings = pb.is_in_ik_chain
                 self.display_ik_settings = pb.is_in_ik_chain
-                
-            if nc and other_nc:
-                self.display_vp_settings = nc.inputs["Custom Object"].is_connected
-                self.display_def_settings = nc.evaluate_input("Deform")
-                self.display_bb_settings = nc.evaluate_input("BBone Segments") > 1
-                self.display_ik_settings = False
-                #
-
-                inp = nc.inputs["Relationship"]
-                link = None
-                if inp.is_connected:
-                    link = inp.links[0]
-                while(link):
-                    if link.from_node.__class__.__name__ in ["LinkInverseKinematics"]:
-                        self.display_ik_settings = link.from_node.evaluate_input("Use Tail")
-                        break
-                    inp = link.from_node.outputs[link.from_socket]
-                    inp = inp.traverse_target
-                    if not inp:
-                        break
-                    if inp.links:
-                        link = inp.links[0]
-                    else:
-                        link = None
-        
+            
+            self.inputs['Name'].display_text = ""
+            if nc:
+                try:
+                    self.inputs['Name'].display_text = nc.evaluate_input("Name")
+                    self.display_vp_settings = nc.inputs["Custom Object"].is_connected
+                    self.display_def_settings = nc.evaluate_input("Deform")
+                    self.display_bb_settings = nc.evaluate_input("BBone Segments") > 1
+                except KeyError:
+                    return # the tree isn't ready yet.
             
             
             for name in ik_names.keys():
             for name in ik_names.keys():
                 self.inputs[name].hide = not self.display_ik_settings
                 self.inputs[name].hide = not self.display_ik_settings
@@ -262,7 +254,7 @@ class xFormBoneNode(Node, xFormNode):
             for name in display_names.keys():
             for name in display_names.keys():
                 if name in ['Custom Object', 'Bone Collection']: continue
                 if name in ['Custom Object', 'Bone Collection']: continue
                 self.inputs[name].hide = not self.display_vp_settings
                 self.inputs[name].hide = not self.display_vp_settings
-
+            
             for name in deform_names.keys():
             for name in deform_names.keys():
                 if name in ['Deform']: continue
                 if name in ['Deform']: continue
                 self.inputs[name].hide = not self.display_def_settings
                 self.inputs[name].hide = not self.display_def_settings
@@ -292,6 +284,16 @@ class xFormArmatureNode(Node, xFormNode):
 
 
         self.initialized=True
         self.initialized=True
 
 
+    def draw_label(self): # this will prefer a user-set label, or return the evaluated name
+        return main_draw_label(self)
+    
+    def display_update(self, parsed_tree, context):
+        if context.space_data:
+            nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
+            self.inputs['Name'].display_text = ""
+            if nc:
+                self.inputs['Name'].display_text = nc.evaluate_input("Name")
+
 
 
 class xFormGeometryObjectNode(Node, xFormNode):
 class xFormGeometryObjectNode(Node, xFormNode):
     """Represents a curve or mesh object."""
     """Represents a curve or mesh object."""
@@ -316,6 +318,16 @@ class xFormGeometryObjectNode(Node, xFormNode):
 
 
         self.initialized=True
         self.initialized=True
 
 
+    def draw_label(self): # this will prefer a user-set label, or return the evaluated name
+        return main_draw_label(self)
+    
+    def display_update(self, parsed_tree, context):
+        if context.space_data:
+            nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
+            self.inputs['Name'].display_text = ""
+            if nc:
+                self.inputs['Name'].display_text = nc.evaluate_input("Name")
+
 class xFormObjectInstance(Node, xFormNode):
 class xFormObjectInstance(Node, xFormNode):
     """Represents an instance of an existing geometry object."""
     """Represents an instance of an existing geometry object."""
     bl_idname = "xFormObjectInstance"
     bl_idname = "xFormObjectInstance"
@@ -339,3 +351,13 @@ class xFormObjectInstance(Node, xFormNode):
         self.color = xFormColor
         self.color = xFormColor
 
 
         self.initialized=True
         self.initialized=True
+
+    def draw_label(self): # this will prefer a user-set label, or return the evaluated name
+        return main_draw_label(self)
+    
+    def display_update(self, parsed_tree, context):
+        if context.space_data:
+            nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
+            self.inputs['Name'].display_text = ""
+            if nc:
+                self.inputs['Name'].display_text = nc.evaluate_input("Name")