Эх сурвалжийг харах

Socket Template proof-of-concept (LinkInherit)

this commit is the proof-of-concept example for the new socket template system.
the goal is to update all the nodes to use Socket Template, then maybe eventually
to have them all be generated by their respective Mantis Node classes on registration.
Joseph Brandenburg 7 сар өмнө
parent
commit
f70c5bb100
2 өөрчлөгдсөн 14 нэмэгдсэн , 11 устгасан
  1. 11 4
      link_containers.py
  2. 3 7
      link_definitions.py

+ 11 - 4
link_containers.py

@@ -1,6 +1,6 @@
 from .node_container_common import *
 from bpy.types import Bone
-from .base_definitions import MantisNode, NodeSocket, GraphError, FLOAT_EPSILON
+from .base_definitions import MantisNode, GraphError, MantisSocketTemplate, FLOAT_EPSILON
 
 def TellClasses():
     return [
@@ -64,14 +64,21 @@ def GetxForm(nc):
             return node
     raise GraphError("%s is not connected to a downstream xForm" % nc)
 
+LinkInheritSockets = [   # Name                   is_input         bl_idname                  
+    MantisSocketTemplate(name="Parent",           is_input=True,   bl_idname='xFormSocket',),
+    MantisSocketTemplate(name="Inherit Rotation", is_input=True,   bl_idname='BooleanSocket',),
+    MantisSocketTemplate(name="Inherit Scale",    is_input=True,   bl_idname='EnumInheritScale',),
+    MantisSocketTemplate(name="Connected",        is_input=True,   bl_idname='BooleanSocket',),
+    MantisSocketTemplate(name="Inheritance",      is_input=False,  bl_idname='RelationshipSocket',),
+]
+
 class LinkInherit(MantisLinkNode):
     '''A node representing inheritance'''
     
     def __init__(self, signature, base_tree):
         super().__init__(signature, base_tree)
-        inputs = ["Parent", "Inherit Rotation", "Inherit Scale", "Connected"]
-        self.inputs.init_sockets(inputs)
-        self.outputs.init_sockets(["Inheritance"])
+        self.inputs.init_sockets(LinkInheritSockets)
+        self.outputs.init_sockets(LinkInheritSockets)
         self.init_parameters()
         self.set_traverse([('Parent', 'Inheritance')])
         self.executed = True

+ 3 - 7
link_definitions.py

@@ -61,14 +61,10 @@ class LinkInheritNode(Node, LinkNode):
     # bone_next : bpy.props.BoolProperty(default=False)
 
     def init(self, context):
-        r = self.inputs.new('BooleanSocket', "Inherit Rotation")
-        s = self.inputs.new('EnumInheritScale', "Inherit Scale")
-        c = self.inputs.new('BooleanSocket', "Connected")
-        i = self.outputs.new('RelationshipSocket', "Inheritance")
-        p = self.inputs.new('xFormSocket', "Parent")
+        from .link_containers import LinkInheritSockets
+        self.init_sockets(LinkInheritSockets)
         # set default values...
         self.initialized = True
-        # color
         self.use_custom_color = True
         self.color = inheritColor
 
@@ -704,4 +700,4 @@ class LinkDrivenParameterNode(Node, LinkNode):
 
 # Set up the class property that ties the UI classes to the Mantis classes.
 for cls in TellClasses():
-    cls.set_mantis_class()
+    cls.set_mantis_class()