소스 검색

New Node: Number of Splines

Joseph Brandenburg 5 달 전
부모
커밋
1727502d47
4개의 변경된 파일35개의 추가작업 그리고 2개의 파일을 삭제
  1. 1 0
      __init__.py
  2. 13 1
      misc_nodes.py
  3. 7 1
      misc_nodes_socket_templates.py
  4. 14 0
      misc_nodes_ui.py

+ 1 - 0
__init__.py

@@ -146,6 +146,7 @@ matrix_category = [
         NodeItem("UtilityMatrixFromCurveSegment"),
         NodeItem("UtilityPointFromCurve"),
         NodeItem("UtilityGetCurvePoint"),
+        NodeItem("UtilityNumberOfSplines"),
         NodeItem("UtilityPointFromBoneMatrix"),
         NodeItem("UtilitySetBoneLength"),
         NodeItem("UtilityGetBoneLength"),

+ 13 - 1
misc_nodes.py

@@ -24,6 +24,7 @@ def TellClasses():
              UtilityMatrixFromCurve,
              UtilityMatricesFromCurve,
              UtilityNumberOfCurveSegments,
+             UtilityNumberOfSplines,
              UtilityMatrixFromCurveSegment,
              UtilityGetCurvePoint,
              UtilityGetNearestFactorOnCurve,
@@ -471,7 +472,6 @@ class UtilityNumberOfCurveSegments(MantisNode):
         self.node_type = "UTILITY"
     
     def bPrepare(self, bContext = None,):
-        import bpy
         curve_name = self.evaluate_input("Curve")
         curve = bpy_object_get_guarded( curve_name, self)
         spline = curve.data.splines[self.evaluate_input("Spline Index")]
@@ -482,6 +482,18 @@ class UtilityNumberOfCurveSegments(MantisNode):
         self.prepared = True
         self.executed = True
 
+class UtilityNumberOfSplines(MantisNode):
+    def __init__(self, signature, base_tree):
+        super().__init__(signature, base_tree, NumberOfSplinesSockets)
+        self.init_parameters()
+        self.node_type = "UTILITY"
+    
+    def bPrepare(self, bContext = None,):
+        curve_name = self.evaluate_input("Curve")
+        curve = bpy_object_get_guarded( curve_name, self)
+        self.parameters["Number of Splines"] = len(curve.data.splines)
+        self.prepared, self.executed = True, True
+
 class UtilityMatrixFromCurveSegment(MantisNode):
     def __init__(self, signature, base_tree):
         super().__init__(signature, base_tree, MatrixFromCurveSegmentSockets)

+ 7 - 1
misc_nodes_socket_templates.py

@@ -94,4 +94,10 @@ CompareSockets = [
     WildcardBTemplate := replace(WildcardATemplate, name="B"),
     CompareOutputTemplate := SockTemplate(
         name="Result", is_input=False, bl_idname="BooleanSocket",),
-]
+]
+
+NumberOfSplinesSockets=[
+    CurveTemplate,
+    NumberOfSplinesOut := SockTemplate(name="Number of Splines",
+        bl_idname='UnsignedIntSocket', is_input=False),
+]

+ 14 - 0
misc_nodes_ui.py

@@ -29,6 +29,7 @@ def TellClasses():
              UtilityMatrixFromCurve,
              UtilityMatricesFromCurve,
              UtilityNumberOfCurveSegments,
+             UtilityNumberOfSplines,
              UtilityMatrixFromCurveSegment,
              UtilityGetCurvePoint,
              UtilityGetNearestFactorOnCurve,
@@ -289,6 +290,19 @@ class UtilityNumberOfCurveSegments(Node, MantisUINode):
         self.outputs.new("UnsignedIntSocket", "Number of Segments")
         self.initialized = True
     
+class UtilityNumberOfSplines(Node, MantisUINode):
+    """Tells the number of splines in a curve."""
+    bl_idname = "UtilityNumberOfSplines"
+    bl_label = "Number of Splines"
+    bl_icon = "NODE"
+    
+    initialized : bpy.props.BoolProperty(default = False)
+    mantis_node_class_name=bl_idname
+    
+    def init(self, context):
+        self.init_sockets(NumberOfSplinesSockets)
+        self.initialized = True
+
 class UtilityMatrixFromCurveSegment(Node, MantisUINode):
     """Gets a matrix from a curve segment."""
     bl_idname = "UtilityMatrixFromCurveSegment"