Forráskód Böngészése

Add Node: Smooth Deformer

NOTE: currently this only implements Corrective Smooth
this is not the final version of the node!
this is missing some features! (smooth type, bind type)
Joseph Brandenburg 10 hónapja
szülő
commit
187c2d2c99
3 módosított fájl, 66 hozzáadás és 2 törlés
  1. 34 1
      deformer_containers.py
  2. 14 0
      deformer_definitions.py
  3. 18 1
      deformer_socket_templates.py

+ 34 - 1
deformer_containers.py

@@ -20,6 +20,7 @@ def TellClasses():
              DeformerSurfaceDeform,
              DeformerMeshDeform,
              DeformerLatticeDeform,
+             DeformerSmoothCorrectiveDeform,
            ]
 
 # object instance probably can't use the deformer but it doesn't hurt to try.
@@ -665,7 +666,7 @@ class DeformerLatticeDeform(MantisDeformerNode):
         self.executed = True
          
     def bFinalize(self, bContext=None):
-        prGreen("Executing Mesh Deform Node")
+        prGreen("Executing Lattice Deform Node")
         mod_name = self.evaluate_input("Name")
         for xf in self.GetxForm():
             ob = xf.bGetObject()
@@ -675,4 +676,36 @@ class DeformerLatticeDeform(MantisDeformerNode):
             self.bObject.append(d)
             self.get_target_and_subtarget(d, input_name="Object")
             props_sockets = self.gen_property_socket_map()
+            evaluate_sockets(self, d, props_sockets)
+
+class DeformerSmoothCorrectiveDeform(MantisDeformerNode):
+    '''A node representing a corrective smooth deform modifier'''
+
+    def __init__(self, signature, base_tree):
+        super().__init__(signature, base_tree, SmoothDeformSockets)
+        # now set up the traverse target...
+        self.init_parameters(additional_parameters={"Name":None})
+        self.set_traverse([("Deformer", "Deformer")])
+        self.prepared = True
+
+    def GetxForm(self, socket="Deformer"):
+        if socket == "Deformer":
+            return super().GetxForm()
+        else:
+            trace_xForm_back(self, socket)
+    
+    def bExecute(self, bContext = None,):
+        self.executed = True
+         
+    def bFinalize(self, bContext=None):
+        prGreen("Executing Smooth Deform Node")
+        mod_name = self.evaluate_input("Name")
+        for xf in self.GetxForm():
+            ob = xf.bGetObject()
+            d = ob.modifiers.new(mod_name, type='CORRECTIVE_SMOOTH')
+            if d is None:
+                raise RuntimeError(f"Modifier was not created in node {self} -- the object is invalid.")
+            self.bObject.append(d)
+            self.get_target_and_subtarget(d, input_name="Object")
+            props_sockets = self.gen_property_socket_map()
             evaluate_sockets(self, d, props_sockets)

+ 14 - 0
deformer_definitions.py

@@ -17,6 +17,7 @@ def TellClasses():
              DeformerSurfaceDeform,
              DeformerMeshDeform,
              DeformerLatticeDeform,
+             DeformerSmoothCorrectiveDeform,
            ]
 
 
@@ -254,6 +255,19 @@ class DeformerLatticeDeform(Node, DeformerNode):
         self.init_sockets(LatticeDeformSockets)
         self.initialized = True
 
+class DeformerSmoothCorrectiveDeform(Node, DeformerNode):
+    '''A node representing a Corrective Smooth Deformer'''
+    bl_idname = 'DeformerSmoothCorrectiveDeform'
+    bl_label = "Smooth Deform"
+    bl_icon = 'MOD_SMOOTH'
+    initialized : bpy.props.BoolProperty(default = False)
+    num_targets : bpy.props.IntProperty(default = 0)
+    mantis_node_class_name=bl_idname
+
+    def init(self, context):
+        self.init_sockets(SmoothDeformSockets)
+        self.initialized = True
+
 # Set up the class property that ties the UI classes to the Mantis classes.
 for cls in TellClasses():
     cls.set_mantis_class()

+ 18 - 1
deformer_socket_templates.py

@@ -64,5 +64,22 @@ LatticeDeformSockets = [
     InvertVertexGroup,
     Strength := replace(Strength, bl_idname='FloatFactorSocket',),
     DeformerOutput,
+]
 
-]
+SmoothDeformSockets = [
+    DeformerInput,
+    Factor := replace(Influence, name="Factor", bl_idname='FloatSocket',
+                        default_value=1.0, blender_property='factor'),
+    iterations := SockTemplate(name='Iterations', bl_idname="UnsignedIntSocket",
+            is_input=True, default_value=5, blender_property='iterations'),
+    # SmoothType :=SockTemplate(name="Length Weighted Smoothing", bl_idname="BooleanSocket",
+    #         is_input=True, default_value=False, ),
+            # TODO: should be possible to drive this property by an int...
+    OnlySmooth := SockTemplate(name="Only Smooth", bl_idname="BooleanSocket",
+            is_input=True, default_value=True, blender_property="use_only_smooth"),
+    PinBoundary := SockTemplate(name="Pin Boundary", bl_idname="BooleanSocket",
+            is_input=True, default_value=False, blender_property="use_pin_boundary"),
+    VertexGroup,
+    InvertVertexGroup,
+    DeformerOutput,
+]