소스 검색

Add node: Lattice Deformer

NOTE: there seems to be a bug when re-generating that causes
the lattice to apply its scale in some circumstances. I don't know
if this is caused by Mantis or by Blender.
Joseph Brandenburg 4 달 전
부모
커밋
d9228f4fe9
3개의 변경된 파일60개의 추가작업 그리고 3개의 파일을 삭제
  1. 35 1
      deformer_containers.py
  2. 13 0
      deformer_definitions.py
  3. 12 2
      deformer_socket_templates.py

+ 35 - 1
deformer_containers.py

@@ -19,6 +19,7 @@ def TellClasses():
              DeformerMorphTargetDeform,
              DeformerSurfaceDeform,
              DeformerMeshDeform,
+             DeformerLatticeDeform,
            ]
 
 # object instance probably can't use the deformer but it doesn't hurt to try.
@@ -639,4 +640,37 @@ class DeformerMeshDeform(MantisDeformerNode):
             
             # todo: add influence parameter and set it up with vertex group and geometry nodes
             # todo: make cage object display as wireframe if it is not being used for something else
-            #          or add the option in the Geometry Object node
+            #          or add the option in the Geometry Object node
+
+
+class DeformerLatticeDeform(MantisDeformerNode):
+    '''A node representing a lattice deform modifier'''
+
+    def __init__(self, signature, base_tree):
+        super().__init__(signature, base_tree, LatticeDeformSockets)
+        # 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 Mesh Deform Node")
+        mod_name = self.evaluate_input("Name")
+        for xf in self.GetxForm():
+            ob = xf.bGetObject()
+            d = ob.modifiers.new(mod_name, type='LATTICE')
+            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)

+ 13 - 0
deformer_definitions.py

@@ -16,6 +16,7 @@ def TellClasses():
              DeformerMorphTarget,
              DeformerSurfaceDeform,
              DeformerMeshDeform,
+             DeformerLatticeDeform,
            ]
 
 
@@ -240,6 +241,18 @@ class DeformerMeshDeform(Node, DeformerNode):
         self.init_sockets(MeshDeformSockets)
         self.initialized = True
 
+class DeformerLatticeDeform(Node, DeformerNode):
+    '''A node representing a Lattice Deformer'''
+    bl_idname = 'DeformerLatticeDeform'
+    bl_label = "Lattice Deform"
+    bl_icon = 'MOD_LATTICE'
+    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(LatticeDeformSockets)
+        self.initialized = True
 
 # Set up the class property that ties the UI classes to the Mantis classes.
 for cls in TellClasses():

+ 12 - 2
deformer_socket_templates.py

@@ -53,6 +53,16 @@ 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"),
-    DeformerOutput := SockTemplate(name="Deformer", bl_idname='DeformerSocket',
-        is_input=False,), 
+    DeformerOutput, 
+]
+
+LatticeDeformSockets = [
+    DeformerInput := SockTemplate(name="Deformer", bl_idname='DeformerSocket',
+        is_input=True,),
+    LatticeDeformTarget := replace(Target, name="Object",),
+    VertexGroup,
+    InvertVertexGroup,
+    Strength := replace(Strength, bl_idname='FloatFactorSocket',),
+    DeformerOutput,
+
 ]