Quellcode durchsuchen

New Node: Point from Curve

Joseph Brandenburg vor 9 Monaten
Ursprung
Commit
68fc1badd6
3 geänderte Dateien mit 86 neuen und 8 gelöschten Zeilen
  1. 1 1
      __init__.py
  2. 68 6
      misc_containers.py
  3. 17 1
      nodes_generic.py

+ 1 - 1
__init__.py

@@ -156,12 +156,12 @@ matrix_category = [
         NodeItem("UtilityMetaRig"),
         NodeItem("UtilityMatrixFromCurve"),
         NodeItem("UtilityMatricesFromCurve"),
+        NodeItem("UtilityPointFromCurve"),
         NodeItem("UtilityPointFromBoneMatrix"),
         NodeItem("UtilitySetBoneLength"),
         NodeItem("UtilityGetBoneLength"),
         NodeItem("UtilityBoneMatrixHeadTailFlip"),
         NodeItem("UtilityMatrixSetLocation"),
-        NodeItem("UtilityMatrixGetLocation"),
         NodeItem("UtilityMatrixFromXForm"),
         NodeItem("UtilityAxesFromMatrix"),
         NodeItem("UtilityMatrixTransform"),

+ 68 - 6
misc_containers.py

@@ -24,6 +24,7 @@ def TellClasses():
              # InputGeometry,
              InputExistingGeometryObject,
              InputExistingGeometryData,
+             UtilityPointFromCurve,
              UtilityMatrixFromCurve,
              UtilityMatricesFromCurve,
              UtilityMetaRig,
@@ -335,12 +336,9 @@ class UtilityMatrixFromCurve:
           "Matrix"           : None,
         }
         self.node_type = "UTILITY"
-        self.hierarchy_connections = []
-        self.connections = []
-        self.hierarchy_dependencies = []
-        self.dependencies = []
-        self.prepared = False
-        self.executed = False
+        self.hierarchy_connections, self.connections = [], []
+        self.hierarchy_dependencies, self.dependencies = [], []
+        self.prepared, self.executed = False, False
 
     def bPrepare(self, bContext = None,):
         from mathutils import Matrix
@@ -385,6 +383,67 @@ class UtilityMatrixFromCurve:
     def fill_parameters(self):
         fill_parameters(self)
 
+
+class UtilityPointFromCurve:
+    '''Get a point from a curve'''
+
+    def __init__(self, signature, base_tree):
+        self.base_tree=base_tree
+        self.executed = False
+        self.signature = signature
+        self.inputs = {
+          "Curve"             : NodeSocket(is_input = True, name = "Curve", node=self),
+          "Factor"            : NodeSocket(is_input = True, name = "Factor", node=self),
+        }
+        self.outputs = {
+          "Point" : NodeSocket(name = "Point", node=self),
+        }
+        self.parameters = {
+          "Curve"       : None,
+          "Factor"      : None,
+          "Point"       : None,
+        }
+        self.node_type = "UTILITY"
+        self.hierarchy_connections, self.connections = [], []
+        self.hierarchy_dependencies, self.dependencies = [], []
+        self.prepared, self.executed = False, False
+
+    def bPrepare(self, bContext = None,):
+        from mathutils import Matrix
+        import bpy
+        curve = bpy.data.objects.get(self.evaluate_input("Curve"))
+        if not curve:
+            raise RuntimeError(f"No curve found for {self}.")
+        else:
+            from .utilities import mesh_from_curve, data_from_ribbon_mesh
+            if not bContext:
+                # TODO find out if this is bad or a HACK or if it is OK
+                bContext = bpy.context
+            # IMPORTANT TODO: I need to be able to reuse this m
+            # First, try to get the one we made before
+            m_name = curve.name+'.'+self.base_tree.execution_id
+            if not (m := bpy.data.meshes.get(m_name)):
+                m = mesh_from_curve(curve, bContext)
+                m.name = m_name
+            #
+            num_divisions = 1
+            factors = [self.evaluate_input("Factor")]
+            data = data_from_ribbon_mesh(m, [factors], curve.matrix_world)
+            p = data[0][0][0]
+        self.parameters["Point"] = p
+        self.prepared, self.executed = True, True
+    
+    def bFinalize(self, bContext=None):
+        import bpy
+        curve_name = self.evaluate_input("Curve")
+        curve = bpy.data.objects.get(curve_name)
+        m_name = curve.name+'.'+self.base_tree.execution_id
+        if (mesh := bpy.data.meshes.get(m_name)):
+            bpy.data.meshes.remove(mesh)
+
+    def fill_parameters(self):
+        fill_parameters(self)
+
 class UtilityMatricesFromCurve:
     '''Get matrices from a curve'''
 
@@ -1586,6 +1645,9 @@ class UtilityArrayGet:
 
     def bPrepare(self, bContext = None,):
       if self.prepared == False:
+        # sort the array entries
+        for inp in self.inputs.values():
+            inp.links.sort(key=lambda a : -a.multi_input_sort_id)
         oob   = self.evaluate_input("OoB Behaviour")
         index = self.evaluate_input("Index")
 

+ 17 - 1
nodes_generic.py

@@ -28,6 +28,7 @@ def TellClasses():
             #  ComposeMatrixNode,
              MetaRigMatrixNode,
              UtilityMatrixFromCurve,
+             UtilityPointFromCurve,
              UtilityMatricesFromCurve,
             #  ScaleBoneLengthNode,
              UtilityMetaRigNode,
@@ -325,10 +326,25 @@ class UtilityMatrixFromCurve(Node, MantisNode):
         curv = self.inputs.new("EnumCurveSocket", "Curve")
         curv.icon = "OUTLINER_OB_CURVE"
         self.inputs.new('IntSocket', 'Total Divisions')
-        self.inputs.new('IntSocket', 'Matrix Index')
         self.outputs.new("MatrixSocket", "Matrix")
         self.initialized = True
 
+
+class UtilityPointFromCurve(Node, MantisNode):
+    """Gets a point from a curve."""
+    bl_idname = "UtilityPointFromCurve"
+    bl_label = "Point from Curve"
+    bl_icon = "NODE"
+    
+    initialized : bpy.props.BoolProperty(default = False)
+    
+    def init(self, context):
+        curv = self.inputs.new("EnumCurveSocket", "Curve")
+        curv.icon = "OUTLINER_OB_CURVE"
+        self.inputs.new('FloatFactorSocket', 'Factor')
+        self.outputs.new("VectorSocket", "Point")
+        self.initialized = True
+
 class UtilityMatricesFromCurve(Node, MantisNode):
     """Gets a matrix from a curve."""
     bl_idname = "UtilityMatricesFromCurve"