Browse Source

Add: Name of xForm, Geometry of xForm nodes

Joseph Brandenburg 8 months ago
parent
commit
bb2edd6fea
2 changed files with 101 additions and 6 deletions
  1. 74 5
      misc_containers.py
  2. 27 1
      nodes_generic.py

+ 74 - 5
misc_containers.py

@@ -20,6 +20,8 @@ def TellClasses():
              InputMatrix,
              InputExistingGeometryObject,
              InputExistingGeometryData,
+             UtilityGeometryOfXForm,
+             UtilityNameOfXForm,
              UtilityPointFromCurve,
              UtilityMatrixFromCurve,
              UtilityMatricesFromCurve,
@@ -622,10 +624,11 @@ class UtilityDriverVariable:
         
     def evaluate_input(self, input_name):
         if input_name == 'Property':
-            if self.inputs['Property'].is_linked:
-            # get the name instead...
-                trace = trace_single_line(self, input_name)
-                return trace[1].name # the name of the socket
+            if self.inputs.get('Property'):
+                if self.inputs['Property'].is_linked:
+                # get the name instead...
+                    trace = trace_single_line(self, input_name)
+                    return trace[1].name # the name of the socket
             return self.parameters["Property"]
         return evaluate_input(self, input_name)
         
@@ -1170,7 +1173,73 @@ class InputExistingGeometryData:
         if bObject is None:
             raise RuntimeError(f"Could not find a mesh or curve datablock named \"{self.evaluate_input('Name')}\" for node {self}")
         return bObject
-        
+
+class UtilityGeometryOfXForm:
+    '''A node representing existing object data'''
+    def __init__(self, signature, base_tree):
+        self.base_tree=base_tree
+        self.executed = False
+        self.signature = signature
+        self.inputs = {
+          "xForm"   : NodeSocket(is_input = True, name = "xForm", node = self),
+        }
+        self.outputs = {
+          "Geometry" : NodeSocket(is_input = False, name = "Geometry", node=self),
+        }
+        self.parameters = {
+
+          "xForm":None, 
+          "Geometry":None, 
+        }
+        self.node_type = "UTILITY"
+        self.hierarchy_connections, self.connections = [], []
+        self.hierarchy_dependencies,self.dependencies = [], []
+        self.prepared, self.executed = True, True
+
+    # mode for interface consistency
+    def bGetObject(self, mode=''):
+        if not (self.inputs.get('xForm') and self.inputs['xForm'].links):
+            prOrange(f"WARN: Cannot retrieve data from {self}, there is no xForm node connected.")
+            return None
+        xf = self.inputs["xForm"].links[0].from_node
+        if xf.node_type == 'XFORM':
+            xf_ob = xf.bGetObject()
+            if xf_ob.type in ['MESH', 'CURVE']:
+                return xf_ob.data
+        prOrange(f"WARN: Cannot retrieve data from {self}, the connected xForm is not a mesh or curve.")
+        return None
+
+
+class UtilityNameOfXForm:
+    '''A node representing existing object data'''
+    def __init__(self, signature, base_tree):
+        self.base_tree=base_tree
+        self.executed = False
+        self.signature = signature
+        self.inputs = {
+          "xForm"   : NodeSocket(is_input = True, name = "xForm", node = self),
+        }
+        self.outputs = {
+          "Name" : NodeSocket(is_input = False, name = "Name", node=self),
+        }
+        self.parameters = {
+
+          "xForm":None, 
+          "Name":'', 
+        }
+        self.node_type = "UTILITY"
+        self.hierarchy_connections, self.connections = [], []
+        self.hierarchy_dependencies,self.dependencies = [], []
+        self.prepared, self.executed = False, False
+
+    # mode for interface consistency
+    def bPrepare(self, bContext = None,):
+        if not (self.inputs.get('xForm') and self.inputs['xForm'].links):
+            prOrange(f"WARN: Cannot retrieve data from {self}, there is no xForm node connected.")
+            return ''
+        xf = self.inputs["xForm"].links[0].from_node
+        self.parameters["Name"] = xf.evaluate_input('Name')
+        self.prepared, self.executed = True, True
 
 class UtilityGetBoneLength:
     '''A node to get the length of a bone matrix'''

+ 27 - 1
nodes_generic.py

@@ -24,7 +24,8 @@ def TellClasses():
              # InputGeometryNode,
              InputExistingGeometryObjectNode,
              InputExistingGeometryDataNode,
-             
+             UtilityGeometryOfXForm,
+             UtilityNameOfXForm,
             #  ComposeMatrixNode,
              MetaRigMatrixNode,
              UtilityMatrixFromCurve,
@@ -591,6 +592,31 @@ class InputExistingGeometryDataNode(Node, MantisNode):
         self.outputs.new("GeometrySocket", "Geometry")
         self.initialized = True
 
+class UtilityGeometryOfXForm(Node, MantisNode):
+    """Retrieves a mesh or curve datablock from an xForm."""
+    bl_idname = "UtilityGeometryOfXForm"
+    bl_label = "Geometry of xForm"
+    bl_icon = "NODE"
+    initialized : bpy.props.BoolProperty(default = False)
+    
+    def init(self, context):
+        self.inputs.new("xFormSocket", "xForm")
+        self.outputs.new("GeometrySocket", "Geometry")
+        self.initialized = True
+
+
+class UtilityNameOfXForm(Node, MantisNode):
+    """Retrieves the name of a xForm."""
+    bl_idname = "UtilityNameOfXForm"
+    bl_label = "Name of xForm"
+    bl_icon = "NODE"
+    initialized : bpy.props.BoolProperty(default = False)
+    
+    def init(self, context):
+        self.inputs.new("xFormSocket", "xForm")
+        self.outputs.new("StringSocket", "Name")
+        self.initialized = True
+
 class UtilityGetBoneLength(Node, MantisNode):
     """Returns the length of the bone from its matrix."""
     bl_idname = "UtilityGetBoneLength"