Sfoglia il codice sorgente

New Node: Floor Constraint

Joseph Brandenburg 4 mesi fa
parent
commit
5d23f68135
5 ha cambiato i file con 88 aggiunte e 2 eliminazioni
  1. 1 0
      __init__.py
  2. 27 1
      link_containers.py
  3. 15 1
      link_definitions.py
  4. 15 0
      link_socket_templates.py
  5. 30 0
      socket_definitions.py

+ 1 - 0
__init__.py

@@ -84,6 +84,7 @@ link_transform_category = [
         NodeItem("LinkLimitRotation"),
         NodeItem("LinkLimitDistance"),
         NodeItem("LinkTransformation"),
+        NodeItem("LinkFloor"),
     ]
 link_tracking_category = [
         NodeItem("LinkInverseKinematics"),

+ 27 - 1
link_containers.py

@@ -29,6 +29,7 @@ def TellClasses():
              # IK
              LinkInverseKinematics,
              LinkSplineIK,
+             LinkFloor,
              # Drivers
              LinkDrivenParameter,
             ]
@@ -838,4 +839,29 @@ class LinkSplineIK(MantisLinkNode):
             self.bObject.append(c)
             props_sockets = self.gen_property_socket_map()
             evaluate_sockets(self, c, props_sockets)
-        self.executed = True
+        self.executed = True
+    
+
+class LinkFloor(MantisLinkNode):
+    '''A node representing an armature object'''
+
+    def __init__(self, signature, base_tree,):
+        super().__init__(signature, base_tree, LinkFloorSockets)
+        self.init_parameters(additional_parameters={"Name":None })
+        self.set_traverse([("Input Relationship", "Output Relationship")])
+        setup_custom_props(self) # <-- this takes care of the runtime-added sockets
+
+    def bExecute(self, bContext = None,):
+        prepare_parameters(self)
+        for xf in self.GetxForm():
+            print(wrapGreen("Creating ")+wrapOrange("Floor")+
+                wrapGreen(" Constraint for bone: ") +
+                wrapOrange(xf.bGetObject().name))
+            c = xf.bGetObject().constraints.new('FLOOR')
+            self.get_target_and_subtarget(c)
+            if constraint_name := self.evaluate_input("Name"):
+                c.name = constraint_name
+            self.bObject.append(c)
+            props_sockets = self.gen_property_socket_map()
+            evaluate_sockets(self, c, props_sockets)
+        self.executed = True

+ 15 - 1
link_definitions.py

@@ -28,6 +28,7 @@ def TellClasses():
              LinkDrivenParameterNode,
              LinkArmatureNode,
              LinkSplineIKNode,
+             LinkFloorNode,
              LinkTransformationNode,
            ]
 
@@ -374,8 +375,21 @@ class LinkSplineIKNode(Node, LinkNode):
         self.color = ikColor
         self.initialized = True
         
-# DRIVERS!!
+class LinkFloorNode(Node, LinkNode):
+    """A node representing Blender's Floor Constraint"""
+    bl_idname = "LinkFloor"
+    bl_label = "Floor"
+    bl_icon = "CON_FLOOR"
+    initialized : bpy.props.BoolProperty(default = False)
+    mantis_node_class_name=bl_idname
+    
+    def init(self, context):
+        self.init_sockets(LinkFloorSockets)
+        self.use_custom_color = True
+        self.color = linkColor
+        self.initialized = True
 
+# DRIVERS!!
 class LinkDrivenParameterNode(Node, LinkNode):
     """Represents a driven parameter in the downstream xForm node."""
     bl_idname = "LinkDrivenParameter"

+ 15 - 0
link_socket_templates.py

@@ -407,6 +407,21 @@ LinkSplineIKSockets = [
     OutputRelationshipTemplate,
 ]
 
+LinkFloorSockets = [
+    InputRelationshipTemplate,
+    TargetTemplate,
+    FloorOffsetTemplate := SockTemplate(name="Offset", bl_idname="BooleanSocket",
+            is_input=True, default_value=False, blender_property='offset'),
+    FloorAxisTemplate := SockTemplate(name='Min/Max', bl_idname='EnumFloorAxis',
+            is_input = True, default_value="FLOOR_X", blender_property="floor_location"),
+    FloorUseRotation := SockTemplate(name="Rotation", bl_idname='BooleanSocket',
+            is_input=True, default_value=False, blender_property='use_rotation',),
+    TargetSpaceTemplate,
+    OwnerSpaceTemplate,
+    EnableTemplate,
+    OutputRelationshipTemplate,
+]
+
 # Remove this socket because of Blender changes.
 if (app.version >= (4, 5, 0)):
     LinkSplineIKSockets.pop(9)

+ 30 - 0
socket_definitions.py

@@ -155,6 +155,7 @@ def TellClasses() -> List[MantisSocket]:
              EnumTrackAxis,
              EnumUpAxis,
              EnumFollowPathForwardAxis,
+             EnumFloorAxis,
              EnumLockAxis,
              EnumLimitMode,
              EnumYScaleMode,
@@ -1431,6 +1432,35 @@ class EnumFollowPathForwardAxis(MantisSocket):
     def draw_color_simple(self):
         return self.color_simple
 
+# Follow Track Forward axis
+eFloorAxis =   (('FLOOR_X',        "X",  "X",  0),
+                ('FLOOR_Y',        "Y",  "Y",  1),
+                ('FLOOR_Z',        "Z",  "Z",  2),
+                ('FLOOR_NEGATIVE_X', "-X", "-X", 3),
+                ('FLOOR_NEGATIVE_Y', "-Y", "-Y", 4),
+                ('FLOOR_NEGATIVE_Z', "-Z", "-Z", 5),)
+
+class EnumFloorAxis(MantisSocket):
+    '''Floor Constraint Axis'''
+    bl_idname = 'EnumFloorAxis'
+    bl_label = "Floor Axis"
+    
+    default_value: bpy.props.EnumProperty(
+        items=eFloorAxis,
+        name="Floor Axis",
+        description="Floor Axis",
+        default = 'FLOOR_X',
+        update = update_socket,)
+    color_simple = cString
+    color : bpy.props.FloatVectorProperty(default=cString, size=4)
+    input : bpy.props.BoolProperty(default =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
 # Locked Track
 
 eLockAxis = (('LOCK_X', "X", "X", 1),