Pārlūkot izejas kodu

Update: Improve Socket Definitions and UI for Deformers

 - adds Viewport/Render toggles
 - fixes Smooth Deform somewhat
 - UI for Smooth Deform to show/hide Scale parameter
 - new Inverted Boolean to simplify UI of Smooth deformer

still to do: add viewport/render toggles to other deformers
add "Length-weighted" smoothing option to smooth deformer
Joseph Brandenburg 4 mēneši atpakaļ
vecāks
revīzija
c40ff9041d

+ 1 - 1
deformer_containers.py

@@ -706,6 +706,6 @@ class DeformerSmoothCorrectiveDeform(MantisDeformerNode):
             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")
+            # self.get_target_and_subtarget(d, input_name="Object")
             props_sockets = self.gen_property_socket_map()
             evaluate_sockets(self, d, props_sockets)

+ 9 - 0
deformer_definitions.py

@@ -268,6 +268,15 @@ class DeformerSmoothCorrectiveDeform(Node, DeformerNode):
         self.init_sockets(SmoothDeformSockets)
         self.initialized = True
 
+    def display_update(self, parsed_tree, context):
+        use_corrective_smooth = self.inputs["Use Corrective Smooth"]
+        if ( use_corrective_smooth.is_linked or 
+             use_corrective_smooth.default_value == False): # this is inverted
+                    self.inputs['Corrective Smooth Scale'].hide = False
+        else:
+                    self.inputs['Corrective Smooth Scale'].hide = True
+
+
 # Set up the class property that ties the UI classes to the Mantis classes.
 for cls in TellClasses():
     cls.set_mantis_class()

+ 16 - 3
deformer_socket_templates.py

@@ -40,6 +40,12 @@ SurfaceDeformSockets= [
         is_input=True, default_value=False, blender_property="invert_vertex_group"),
     SparseBind := SockTemplate(name="Sparse Bind", bl_idname='BooleanSocket',
         is_input=True, default_value=False, blender_property="use_sparse_bind"),
+    EnableViewportTemplate := SockTemplate(
+        name="Enable in Viewport", is_input=True,  bl_idname='EnableSocket',
+        default_value=True, blender_property='show_viewport'),
+    EnableRenderTemplate := SockTemplate(
+        name="Enable in Render", is_input=True,  bl_idname='BooleanSocket',
+        default_value=True, blender_property='show_render'),
     DeformerOutput,
 ]
 
@@ -53,6 +59,8 @@ MeshDeformSockets= [
         is_input=True, default_value=4, blender_property="precision"),
     DynamicBind := SockTemplate(name="Dynamic Bind", bl_idname='BooleanSocket',
         is_input=True, default_value=False, blender_property="use_dynamic_bind"),
+    EnableViewportTemplate,
+    EnableRenderTemplate,
     DeformerOutput, 
 ]
 
@@ -63,6 +71,8 @@ LatticeDeformSockets = [
     VertexGroup,
     InvertVertexGroup,
     Strength := replace(Strength, bl_idname='FloatFactorSocket',),
+    EnableViewportTemplate,
+    EnableRenderTemplate,
     DeformerOutput,
 ]
 
@@ -73,13 +83,16 @@ SmoothDeformSockets = [
     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=False, blender_property="smooth_type" ),
+    OnlySmooth := SockTemplate(name="Use Corrective Smooth", bl_idname="InvertedBooleanSocket",
             is_input=True, default_value=True, blender_property="use_only_smooth"),
+    DeltaMushScale := SockTemplate(name="Corrective Smooth Scale", bl_idname="FloatSocket",
+            is_input=True, default_value=1.0, blender_property="scale" ),
     PinBoundary := SockTemplate(name="Pin Boundary", bl_idname="BooleanSocket",
             is_input=True, default_value=False, blender_property="use_pin_boundary"),
     VertexGroup,
     InvertVertexGroup,
+    EnableViewportTemplate,
+    EnableRenderTemplate,
     DeformerOutput,
 ]

+ 24 - 2
socket_definitions.py

@@ -133,6 +133,7 @@ def TellClasses() -> List[MantisSocket]:
              
              TransformSpaceSocket,
              BooleanSocket,
+             InvertedBooleanSocket,
              BooleanThreeTupleSocket,
              RotationOrderSocket,
              QuaternionSocket,
@@ -350,7 +351,9 @@ def update_metarig_posebone(self, context,):
 
 
 def ChooseDraw(self, context, layout, node, text, icon = "NONE", use_enum=True, nice_bool=True, icon_only=False):
-    # return
+    invert_checkbox = False
+    if hasattr(self, "invert") and self.invert == True:
+        invert_checkbox=True
     # TEXT ONLY
     if self.node.bl_idname in ["NodeGroupInput", "NodeGroupOutput"]:
         layout.label(text=text)
@@ -373,7 +376,8 @@ def ChooseDraw(self, context, layout, node, text, icon = "NONE", use_enum=True,
             #   and set them for each socket.
             if icon == 'NONE': icon_only = False
             elif icon_only == True : text = "" # "real" icon-only looks bad for strings, need to check other props types.
-            layout.prop(self, "default_value", text=text, toggle=nice_bool, slider=True, icon=icon,)
+            layout.prop(self, "default_value", text=text, toggle=nice_bool, slider=True, icon=icon,
+                        invert_checkbox=invert_checkbox)
         # CONNECTED sockets and outputs without input fields
         else:
             layout.label(text=text)
@@ -658,6 +662,24 @@ class BooleanSocket(MantisSocket):
     @classmethod
     def draw_color_simple(self):
         return self.color_simple
+    
+class InvertedBooleanSocket(MantisSocket):
+    '''Custom node socket type'''
+    bl_idname = 'InvertedBooleanSocket'
+    bl_label = "Inverted Boolean"
+    default_value: bpy.props.BoolProperty(update = update_socket,)
+    color_simple = cBool
+    color : bpy.props.FloatVectorProperty(default=cBool, size=4)
+    input : bpy.props.BoolProperty(default =False,)
+    invert : bpy.props.BoolProperty(default=True,)
+    is_valid_interface_type=False
+    def draw(self, context, layout, node, text):
+        ChooseDraw(self, context, layout, node, text)
+    def draw_color(self, context, node):
+        return self.color
+    @classmethod
+    def draw_color_simple(self):
+        return self.color_simple
 
 class BooleanThreeTupleSocket(MantisSocket):
     # Description string