| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021 | import bpyfrom bpy.types import Nodefrom .base_definitions import MantisNodefrom .utilities import (prRed, prGreen, prPurple, prWhite,                              prOrange,                              wrapRed, wrapGreen, wrapPurple, wrapWhite,                              wrapOrange,)def TellClasses():    return [ InputFloatNode,             InputIntNode,             InputVectorNode,             InputBooleanNode,             InputBooleanThreeTupleNode,             InputRotationOrderNode,             InputTransformSpaceNode,             InputStringNode,             InputQuaternionNode,             InputQuaternionNodeAA,             InputMatrixNode,             InputLayerMaskNode,             # InputGeometryNode,             InputExistingGeometryObjectNode,             InputExistingGeometryDataNode,                         #  ComposeMatrixNode,             MetaRigMatrixNode,             UtilityMatrixFromCurve,             UtilityPointFromCurve,             UtilityMatricesFromCurve,            #  ScaleBoneLengthNode,             UtilityMetaRigNode,             UtilityBonePropertiesNode,             UtilityDriverVariableNode,             UtilityFCurveNode,             UtilityDriverNode,             UtilitySwitchNode,             UtilityKeyframe,             UtilityCombineThreeBoolNode,             UtilityCombineVectorNode,             UtilityCatStringsNode,             UtilityGetBoneLength,             UtilityPointFromBoneMatrix,             UtilitySetBoneLength,             UtilityMatrixSetLocation,             UtilityMatrixGetLocation,             UtilityMatrixFromXForm,             UtilityAxesFromMatrix,             UtilityBoneMatrixHeadTailFlip,             UtilityMatrixTransform,             UtilityTransformationMatrix,             UtilitySetBoneMatrixTail,             UtilityIntToString,             UtilityArrayGet,             #             UtilityCompare,             UtilityChoose,             # for testing             UtilityPrint,            ]def default_traverse(self,socket):    return Noneclass InputFloatNode(Node, MantisNode):    '''A node representing inheritance'''    bl_idname = 'InputFloatNode'    bl_label = "Float"    bl_icon = 'NODE'    initialized : bpy.props.BoolProperty(default = False)    def init(self, context):        self.outputs.new('FloatSocket', "Float Input").input = True        self.initialized = Trueclass InputIntNode(Node, MantisNode):    '''A node representing inheritance'''    bl_idname = 'InputIntNode'    bl_label = "Integer"    bl_icon = 'NODE'    initialized : bpy.props.BoolProperty(default = False)    def init(self, context):        self.outputs.new('IntSocket', "Integer").input = True        self.initialized = True    class InputVectorNode(Node, MantisNode):    '''A node representing inheritance'''    bl_idname = 'InputVectorNode'    bl_label = "Vector"    bl_icon = 'NODE'    initialized : bpy.props.BoolProperty(default = False)    def init(self, context):        self.outputs.new('VectorSocket', "").input = True        self.initialized = Trueclass InputBooleanNode(Node, MantisNode):    '''A node representing inheritance'''    bl_idname = 'InputBooleanNode'    bl_label = "Boolean"    bl_icon = 'NODE'    initialized : bpy.props.BoolProperty(default = False)    def init(self, context):        self.outputs.new('BooleanSocket', "").input = True        self.initialized = Trueclass InputBooleanThreeTupleNode(Node, MantisNode):    '''A node representing inheritance'''    bl_idname = 'InputBooleanThreeTupleNode'    bl_label = "Boolean Vector"    bl_icon = 'NODE'    initialized : bpy.props.BoolProperty(default = False)    def init(self, context):        self.outputs.new('BooleanThreeTupleSocket', "")        self.initialized = Trueclass InputRotationOrderNode(Node, MantisNode):    '''A node representing inheritance'''    bl_idname = 'InputRotationOrderNode'    bl_label = "Rotation Order"    bl_icon = 'NODE'    initialized : bpy.props.BoolProperty(default = False)    def init(self, context):        self.outputs.new('RotationOrderSocket', "").input = True        self.initialized = Trueclass InputTransformSpaceNode(Node, MantisNode):    '''A node representing inheritance'''    bl_idname = 'InputTransformSpaceNode'    bl_label = "Transform Space"    bl_icon = 'NODE'    initialized : bpy.props.BoolProperty(default = False)    def init(self, context):        self.outputs.new('TransformSpaceSocket', "").input = True        self.initialized = Trueclass InputStringNode(Node, MantisNode):    '''A node representing inheritance'''    bl_idname = 'InputStringNode'    bl_label = "String"    bl_icon = 'NODE'    initialized : bpy.props.BoolProperty(default = False)    def init(self, context):        self.outputs.new('StringSocket', "").input = True        self.initialized = Trueclass InputQuaternionNode(Node, MantisNode):    '''A node representing inheritance'''    bl_idname = 'InputQuaternionNode'    bl_label = "Quaternion"    bl_icon = 'NODE'    initialized : bpy.props.BoolProperty(default = False)    def init(self, context):        self.outputs.new('QuaternionSocket', "").input = True        self.initialized = Trueclass InputQuaternionNodeAA(Node, MantisNode):    '''A node representing inheritance'''    bl_idname = 'InputQuaternionNodeAA'    bl_label = "Axis Angle"    bl_icon = 'NODE'    initialized : bpy.props.BoolProperty(default = False)    def init(self, context):        self.outputs.new('QuaternionSocketAA', "").input = True        self.initialized = Trueclass InputMatrixNode(Node, MantisNode):    '''A node representing inheritance'''    bl_idname = 'InputMatrixNode'    bl_label = "Matrix"    bl_icon = 'NODE'    first_row  : bpy.props.FloatVectorProperty(name="", size=4, default = (1.0, 0.0, 0.0, 0.0,))    second_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 1.0, 0.0, 0.0,))    third_row  : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 0.0, 1.0, 0.0,))    fourth_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 0.0, 0.0, 1.0,))    initialized : bpy.props.BoolProperty(default = False)    def set_matrix(self):        return (self.first_row[ 0], self.first_row[ 1], self.first_row[ 2], self.first_row[ 3],                self.second_row[0], self.second_row[1], self.second_row[2], self.second_row[3],                self.third_row[ 0], self.third_row[ 1], self.third_row[ 2], self.third_row[ 3],                self.fourth_row[0], self.fourth_row[1], self.fourth_row[2], self.fourth_row[3],)    def init(self, context):        self.outputs.new('MatrixSocket', "Matrix")        self.initialized = True            def update_node(self, context):        self.outputs["Matrix"].default_value = self.set_matrix()    def draw_buttons(self, context, layout):        # return        layout.prop(self, "first_row")        layout.prop(self, "second_row")        layout.prop(self, "third_row")        layout.prop(self, "fourth_row")    def update(self):        mat_sock = self.outputs[0]        mat_sock.default_value = self.set_matrix()# TODO: reimplement the nodes beneath here# from .utilities import QuerySocket, to_mathutils_value# class ComposeMatrixNode(Node, MantisNode):#     '''A utility node for composing a matrix'''#     bl_idname = 'ComposeMatrixNode'#     bl_label = "Compose Matrix"#     bl_icon = 'NODE'#     def init(self, context):#         self.inputs.new('VectorTranslationSocket', "Translation")#         self.inputs.new('GenericRotationSocket', "Rotation")#         self.inputs.new('VectorScaleSocket', "Scale")#         self.outputs.new('MatrixSocket', "Matrix")#     def update_node(self, context = None):#         from mathutils import Matrix, Euler, Quaternion, Vector#         mat_sock = self.outputs[0]#         rotation = Matrix.Identity(4)#         scale = Matrix.Identity(4)#         translation = Matrix.Identity(4)#         sock = QuerySocket(self.inputs["Rotation"])[0]#         val = to_mathutils_value(sock)#         if (val):#             if (isinstance(val, Vector)):#                 val = Euler((val[0], val[1], val[2]), 'XYZ')#             rotation = val.to_matrix().to_4x4()#         sock = QuerySocket(self.inputs["Scale"])[0]#         val = to_mathutils_value(sock)#         if (val):#             if (isinstance(val, Vector)):#                 scale = Matrix.Scale(val[0],4,(1.0,0.0,0.0)) @ Matrix.Scale(val[1],4,(0.0,1.0,0.0)) @ Matrix.Scale(val[2],4,(0.0,0.0,1.0))#         sock = QuerySocket(self.inputs["Translation"])[0]#         val = to_mathutils_value(sock)#         if (val):#             if (isinstance(val, Vector)):#                 translation = Matrix.Translation((val))        #         mat = translation @ rotation @ scale#         mat_sock.default_value = ( mat[0][0], mat[0][1], mat[0][2], mat[0][3],#                                    mat[1][0], mat[1][1], mat[1][2], mat[1][3],#                                    mat[2][0], mat[2][1], mat[2][2], mat[2][3],#                                    mat[3][0], mat[3][1], mat[3][2], mat[3][3], )class ScaleBoneLengthNode(Node, MantisNode):    '''Scale Bone Length'''    bl_idname = 'ScaleBoneLength'    bl_label = "Scale Bone Length"    bl_icon = 'NODE'    initialized : bpy.props.BoolProperty(default = False)    # === Optional Functions ===    def init(self, context):        self.inputs.new('MatrixSocket', "In Matrix")        self.inputs.new('FloatSocket', "Factor")        self.outputs.new('MatrixSocket', "Out Matrix")        self.initialized = Trueclass MetaRigMatrixNode(Node, MantisNode):    # Identical to the above, except    '''A node representing a bone's matrix'''    bl_idname = 'MetaRigMatrixNode'    bl_label = "Matrix"    bl_icon = 'NODE'    first_row  : bpy.props.FloatVectorProperty(name="", size=4, default = (1.0, 0.0, 0.0, 0.0,))    second_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 1.0, 0.0, 0.0,))    third_row  : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 0.0, 1.0, 0.0,))    fourth_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 0.0, 0.0, 1.0,))    initialized : bpy.props.BoolProperty(default = False)    def set_matrix(self):        return (self.first_row[ 0], self.first_row[ 1], self.first_row[ 2], self.first_row[ 3],                self.second_row[0], self.second_row[1], self.second_row[2], self.second_row[3],                self.third_row[ 0], self.third_row[ 1], self.third_row[ 2], self.third_row[ 3],                self.fourth_row[0], self.fourth_row[1], self.fourth_row[2], self.fourth_row[3],)    def init(self, context):        self.outputs.new('MatrixSocket', "Matrix")        self.initialized = True        def traverse(self, context):        from mathutils import Matrix        v = self.outputs[0].default_value        # print( Matrix( ( ( v[ 0], v[ 1], v[ 2], v[ 3],),        #                  ( v[ 4], v[ 5], v[ 6], v[ 7],),        #                  ( v[ 8], v[ 9], v[10], v[11],),        #                  ( v[12], v[13], v[14], v[15],), ) ) )        return None        def update_node(self, context):        self.outputs["Matrix"].default_value = self.set_matrix()    def update(self):        mat_sock = self.outputs[0]        mat_sock.default_value = self.set_matrix()class UtilityMatrixFromCurve(Node, MantisNode):    """Gets a matrix from a curve."""    bl_idname = "UtilityMatrixFromCurve"    bl_label = "Matrix from Curve"    bl_icon = "NODE"        initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        curv = self.inputs.new("EnumCurveSocket", "Curve")        curv.icon = "OUTLINER_OB_CURVE"        self.inputs.new('IntSocket', 'Total Divisions')        self.outputs.new("MatrixSocket", "Matrix")        self.initialized = Trueclass UtilityPointFromCurve(Node, MantisNode):    """Gets a point from a curve."""    bl_idname = "UtilityPointFromCurve"    bl_label = "Point from Curve"    bl_icon = "NODE"        initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        curv = self.inputs.new("EnumCurveSocket", "Curve")        curv.icon = "OUTLINER_OB_CURVE"        self.inputs.new('FloatFactorSocket', 'Factor')        self.outputs.new("VectorSocket", "Point")        self.initialized = Trueclass UtilityMatricesFromCurve(Node, MantisNode):    """Gets a matrix from a curve."""    bl_idname = "UtilityMatricesFromCurve"    bl_label = "Matrices from Curve"    bl_icon = "NODE"        initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        curv = self.inputs.new("EnumCurveSocket", "Curve")        curv.icon = "OUTLINER_OB_CURVE"        self.inputs.new('IntSocket', 'Total Divisions')        o = self.outputs.new("MatrixSocket", "Matrices")        o.display_shape = 'SQUARE_DOT'        self.initialized = Trueclass UtilityMetaRigNode(Node, MantisNode):    """Gets a matrix from a meta-rig bone."""    bl_idname = "UtilityMetaRig"    bl_label = "Meta-Rig"    bl_icon = "NODE"        armature:bpy.props.StringProperty()    pose_bone:bpy.props.StringProperty()    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        armt = self.inputs.new("EnumMetaRigSocket", "Meta-Armature")        bone = self.inputs.new("EnumMetaBoneSocket", "Meta-Bone")        armt.icon = "OUTLINER_OB_ARMATURE"        bone.icon = "BONE_DATA"        bone.hide=True        self.outputs.new("MatrixSocket", "Matrix")        self.initialized = True        def display_update(self, parsed_tree, context):        from .base_definitions import get_signature_from_edited_tree        nc = parsed_tree.get(get_signature_from_edited_tree(self, context))        if nc:            self.armature= nc.evaluate_input("Meta-Armature")            self.pose_bone= nc.evaluate_input("Meta-Bone")        if not self.armature:            self.inputs["Meta-Bone"].hide=True        else:            self.inputs["Meta-Bone"].hide=False        if self.inputs["Meta-Armature"].is_connected:            self.inputs["Meta-Armature"].search_prop = None        if self.inputs["Meta-Bone"].is_connected:            self.inputs["Meta-Bone"].search_prop = Noneclass UtilityBonePropertiesNode(Node, MantisNode):    """Provides as sockets strings identifying bone transform properties."""    bl_idname = "UtilityBoneProperties"    bl_label = "Bone Properties"    bl_icon = "NODE"    #bl_width_default = 250    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        self.outputs.new("ParameterStringSocket", "matrix")        self.outputs.new("ParameterStringSocket", "matrix_local")        self.outputs.new("ParameterStringSocket", "matrix_basis")        self.outputs.new("ParameterStringSocket", "head")        self.outputs.new("ParameterStringSocket", "tail")        self.outputs.new("ParameterStringSocket", "length")        self.outputs.new("ParameterStringSocket", "rotation")        self.outputs.new("ParameterStringSocket", "location")        self.outputs.new("ParameterStringSocket", "scale")        self.initialized = True                for o in self.outputs:            o.text_only = Trueclass UtilityDriverVariableNode(Node, MantisNode):    """Creates a variable for use in a driver."""    bl_idname = "UtilityDriverVariable"    bl_label = "Driver Variable"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)            def init(self, context):        self.inputs.new("EnumDriverVariableType", "Variable Type")                 # 0        self.inputs.new("ParameterStringSocket", "Property")                       # 1        self.inputs.new("IntSocket", "Property Index")                             # 2        self.inputs.new("EnumDriverVariableTransformChannel", "Transform Channel") # 3        self.inputs.new("EnumDriverVariableEvaluationSpace", "Evaluation Space")   # 4        self.inputs.new("EnumDriverRotationMode", "Rotation Mode")                 # 5        self.inputs.new("xFormSocket", "xForm 1")                                  # 6        self.inputs.new("xFormSocket", "xForm 2")                                  # 7        self.outputs.new("DriverVariableSocket", "Driver Variable")        self.inputs[3].hide = True        self.initialized = True            # def update_on_socket_change(self, context):    #     self.update()        def display_update(self, parsed_tree, context):        from .base_definitions import get_signature_from_edited_tree        if self.inputs["Variable Type"].is_linked:            if context.space_data:                node_tree = context.space_data.path[0].node_tree                nc = parsed_tree.get(get_signature_from_edited_tree(self, context))                if nc:                    driver_type = nc.evaluate_input("Variable Type")        else:            driver_type = self.inputs[0].default_value        if driver_type == 'SINGLE_PROP':            self.inputs[1].hide = False            self.inputs[2].hide = False            self.inputs[3].hide = True            self.inputs[4].hide = False            self.inputs[5].hide = False            self.inputs[6].hide = False            self.inputs[7].hide = True        elif driver_type == 'LOC_DIFF':            self.inputs[1].hide = True            self.inputs[2].hide = True            self.inputs[3].hide = True            self.inputs[4].hide = True            self.inputs[5].hide = True            self.inputs[6].hide = False            self.inputs[7].hide = False        elif driver_type == 'ROTATION_DIFF':            self.inputs[1].hide = True            self.inputs[2].hide = True            self.inputs[3].hide = True            self.inputs[4].hide = True            self.inputs[5].hide = False            self.inputs[6].hide = False            self.inputs[7].hide = False        elif driver_type == 'TRANSFORMS':            self.inputs[1].hide = True            self.inputs[2].hide = True            self.inputs[3].hide = False            self.inputs[4].hide = False            self.inputs[5].hide = False            self.inputs[6].hide = False            self.inputs[7].hide = True        self.inputs[3].hide = True    class UtilityFCurveNode(Node, MantisNode):    """Creates an fCurve for use with a driver."""    bl_idname = "UtilityFCurve"    bl_label = "fCurve"    bl_icon = "NODE"        use_kf_nodes   : bpy.props.BoolProperty(default=True)    # fake_fcurve_ob : bpy.props.PointerProperty(type=bpy.types.Object)    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        self.outputs.new("FCurveSocket", "fCurve")        # if not self.fake_fcurve_ob:        #     ob = bpy.data.objects.new("fake_ob_"+self.name, None)        #     self.fake_fcurve_ob = ob        #     ob.animation_data_create()        #     ob.animation_data.action = bpy.data.actions.new('fake_action_'+self.name)        #     fc = ob.animation_data.action.fcurves.new('location', index=0, action_group='location')        #     fc.keyframe_points.add(2)        #     kf0 = fc.keyframe_points[0]; kf0.co_ui = (0, 0)        #     kf1 = fc.keyframe_points[1]; kf1.co_ui = (1, 1)        #     #        #     kf0.interpolation = 'BEZIER'        #     kf0.handle_left_type  = 'AUTO_CLAMPED'        #     kf0.handle_right_type = 'AUTO_CLAMPED'        #     kf1.interpolation = 'BEZIER'        #     kf1.handle_left_type  = 'AUTO_CLAMPED'        #     kf1.handle_right_type = 'AUTO_CLAMPED'            #        self.initialized = True                def draw_buttons(self, context, layout):        # return        # if self.use_kf_nodes:            # layout.prop(self, "use_kf_nodes",  text="[ Use fCurve data ]", toggle=True, invert_checkbox=True)        layout.operator( 'mantis.fcurve_node_add_kf' )        if (len(self.inputs) > 0):            layout.operator( 'mantis.fcurve_node_remove_kf' )        # else:            # layout.prop(self, "use_kf_nodes",  text="[ Use Keyframe Nodes ]", toggle=True)            # layout.operator('mantis.edit_fcurve_node')                            # THE DIFFICULT part is getting it to show up in the graph editor    # TRY:    #       a modal operator that opens the Graph Editor    #       and then finishes when it is closed    #       it would reveal the object holding the fCurve before    #       showing the Graph Editor    #       And hide it after closing it.    #                                class UtilityDriverNode(Node, MantisNode):    """Represents a Driver relationship"""    bl_idname = "UtilityDriver"    bl_label = "Driver"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        self.inputs.new("EnumDriverType", "Driver Type")        self.inputs.new("FCurveSocket", "fCurve")        self.inputs.new("StringSocket", "Expression")        self.outputs.new("DriverSocket", "Driver")        self.initialized = True            def update(self):        return        context = bpy.context        try:            tree = context.space_data.path[0].node_tree            proceed = True        except AttributeError:            proceed = False        if proceed:            from .f_nodegraph import (GetDownstreamXFormNodes, get_node_container)            if (node_container := get_node_container(self, context)[0]):                dType = node_container.evaluate_input("Driver Type")            else:                dType = self.inputs[0].default_value                        if dType == 'SCRIPTED':                self.inputs["Expression"].hide = False            else:                self.inputs["Expression"].hide = True        def draw_buttons(self, context, layout):        # return        layout.operator( 'mantis.driver_node_add_variable' )        if (len(self.inputs) > 3):            layout.operator( 'mantis.driver_node_remove_variable' )class UtilitySwitchNode(Node, MantisNode):    """Represents a switch relationship between one driver property and one or more driven properties."""    bl_idname = "UtilitySwitch"    bl_label = "Switch"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        # self.inputs.new("xFormSocket", "xForm")        self.inputs.new("ParameterStringSocket", "Parameter")        self.inputs.new("IntSocket", "Parameter Index")        self.inputs.new("BooleanSocket", "Invert Switch")        self.outputs.new("DriverSocket", "Driver")        self.initialized = Trueclass UtilityCombineThreeBoolNode(Node, MantisNode):    """Combines three booleans into a three-bool."""    bl_idname = "UtilityCombineThreeBool"    bl_label = "CombineThreeBool"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        self.inputs.new("BooleanSocket", "X")        self.inputs.new("BooleanSocket", "Y")        self.inputs.new("BooleanSocket", "Z")        self.outputs.new("BooleanThreeTupleSocket", "Three-Bool")        # this node should eventually just be a Combine Boolean Three-Tuple node        # and the "Driver" output will need to be figured out some other way        self.initialized = Trueclass UtilityCombineVectorNode(Node, MantisNode):    """Combines three floats into a vector."""    bl_idname = "UtilityCombineVector"    bl_label = "CombineVector"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        self.inputs.new("FloatSocket", "X")        self.inputs.new("FloatSocket", "Y")        self.inputs.new("FloatSocket", "Z")        self.outputs.new("VectorSocket", "Vector")        # this node should eventually just be a Combine Boolean Three-Tuple node        # and the "Driver" output will need to be figured out some other way        self.initialized = True        class UtilityCatStringsNode(Node, MantisNode):    """Adds a suffix to a string"""    bl_idname = "UtilityCatStrings"    bl_label = "Concatenate Strings"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        self.inputs.new("StringSocket", "String_1")        self.inputs.new("StringSocket", "String_2")        self.outputs.new("StringSocket", "OutputString")        self.initialized = True    class InputLayerMaskNode(Node, MantisNode):    """Represents a layer mask for a bone."""    bl_idname = "InputLayerMaskNode"    bl_label = "Layer Mask"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        self.outputs.new("LayerMaskInputSocket", "Layer Mask")        self.initialized = Trueclass InputExistingGeometryObjectNode(Node, MantisNode):    """Represents an existing geometry object from within the scene."""    bl_idname = "InputExistingGeometryObject"    bl_label = "Existing Object"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)    # We want Mantis to import widgets and stuff, so we hold a reference to the object    object_reference : bpy.props.PointerProperty(type=bpy.types.Object,)         def init(self, context):        self.inputs.new("StringSocket", "Name")        self.outputs.new("xFormSocket", "Object")        self.initialized = True        def display_update(self, parsed_tree, context):        from .base_definitions import get_signature_from_edited_tree        nc = parsed_tree.get(get_signature_from_edited_tree(self, context))        if nc: # this is done here so I don't have to define yet another custom socket.            self.object_reference = bpy.data.objects.get(nc.evaluate_input("Name"))    # TODO: maybe I should hold a data reference here, too.#       but it is complicated by the fact that Mantis does not distinguish b/tw geo typesclass InputExistingGeometryDataNode(Node, MantisNode):    """Represents a mesh or curve datablock from the scene."""    bl_idname = "InputExistingGeometryData"    bl_label = "Existing Geometry"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        self.inputs.new("StringSocket", "Name")        self.outputs.new("GeometrySocket", "Geometry")        self.initialized = Trueclass UtilityGetBoneLength(Node, MantisNode):    """Returns the length of the bone from its matrix."""    bl_idname = "UtilityGetBoneLength"    bl_label = "Get Bone Length"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        self.inputs.new("MatrixSocket", "Bone Matrix")        self.outputs.new("FloatSocket", "Bone Length")        self.initialized = True# TODO: make it work with BBones!class UtilityPointFromBoneMatrix(Node, MantisNode):    """Returns a point representing the location along a bone, given a matrix representing that bone's shape."""    bl_idname = "UtilityPointFromBoneMatrix"    bl_label = "Point from Bone Matrix"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        self.inputs.new("MatrixSocket", "Bone Matrix")        self.inputs.new("FloatFactorSocket", "Head/Tail")        self.outputs.new("VectorSocket", "Point")        self.initialized = Trueclass UtilitySetBoneLength(Node, MantisNode):    """Sets the length of a bone matrix."""    bl_idname = "UtilitySetBoneLength"    bl_label = "Set Bone Matrix Length"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        self.inputs.new("MatrixSocket", "Bone Matrix")        self.inputs.new("FloatSocket", "Length")        self.outputs.new("MatrixSocket", "Bone Matrix")        self.initialized = Trueclass UtilityKeyframe(Node, MantisNode):    """A keyframe for a FCurve"""    bl_idname = "UtilityKeyframe"    bl_label = "KeyFrame"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        # x and y        # output is keyframe        # self.inputs.new("EnumKeyframeInterpolationTypeSocket", "Interpolation")        # self.inputs.new("EnumKeyframeBezierHandleType", "Left Handle Type")        # self.inputs.new("EnumKeyframeBezierHandleType", "Right Handle Type")        # self.inputs.new("FloatSocket", "Left Handle Distance")        # self.inputs.new("FloatSocket", "Left Handle Value")        # self.inputs.new("FloatSocket", "Right Handle Frame")        # self.inputs.new("FloatSocket", "Right Handle Value")        self.inputs.new("FloatSocket", "Frame")        self.inputs.new("FloatSocket", "Value")        self.outputs.new("KeyframeSocket", "Keyframe")        # there will eventually be inputs for e.g. key type, key handles, etc.        # right now I am gonna hardcode LINEAR keyframes so I don't have to deal with anything else        # TODO TODO TODO            # def display_update(self, parsed_tree, context):    #     if context.space_data:    #         nc = parsed_tree.get(get_signature_from_edited_tree(self, context))    #         if nc.evaluate_input("Interpolation") in ["CONSTANT", "LINEAR"]:    #             for inp in self.inputs[1:6]:    #                 inp.hide = True    #         else:    #             if nc.evaluate_input("Left Handle Type") in ["FREE", "ALIGNED"]:    #             for inp in self.inputs[1:6]:    #                 inp.hide = False        self.initialized = Trueclass UtilityBoneMatrixHeadTailFlip(Node, MantisNode):    """Flips a bone matrix so that the head is where the tail was and visa versa."""    bl_idname = "UtilityBoneMatrixHeadTailFlip"    bl_label = "Flip Head/Tail"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        self.inputs.new("MatrixSocket", "Bone Matrix")        self.outputs.new("MatrixSocket", "Bone Matrix")        self.initialized = Trueclass UtilityMatrixTransform(Node, MantisNode):    """Transforms a matrix by another."""    bl_idname = "UtilityMatrixTransform"    bl_label = "Matrix Transform"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        self.inputs.new("MatrixSocket", "Matrix 1")        self.inputs.new("MatrixSocket", "Matrix 2")        self.outputs.new("MatrixSocket", "Out Matrix")        self.initialized = Trueclass UtilityMatrixSetLocation(Node, MantisNode):    """Sets a matrix's location."""    bl_idname = "UtilityMatrixSetLocation"    bl_label = "Set Matrix Location"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        self.inputs.new("MatrixSocket", "Matrix")        self.inputs.new("VectorSocket", "Location")        self.outputs.new("MatrixSocket", "Matrix")        self.initialized = Trueclass UtilityMatrixGetLocation(Node, MantisNode):    """Gets a matrix's location."""    bl_idname = "UtilityMatrixGetLocation"    bl_label = "Get Matrix Location"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        self.inputs.new("MatrixSocket", "Matrix")        self.outputs.new("VectorSocket", "Location")        self.initialized = Trueclass UtilityTransformationMatrix(Node, MantisNode):    """Constructs a matrix representing a transformation"""    bl_idname = "UtilityTransformationMatrix"    bl_label = "Transformation Matrix"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        # first input is a transformation type - translation, rotation, or scale        #                         rotation is an especially annoying feature because it can take multiple types        #   so Euler, axis/angle, quaternion, matrix...        #   for now I am only going to implement axis-angle        # it should get an axis and a magnitude        # self.inputs.new("MatrixSocket", "Bone Matrix")                self.inputs.new("MatrixTransformOperation", "Operation")        self.inputs.new("VectorSocket", "Vector")        self.inputs.new("FloatSocket", "W")        self.outputs.new("MatrixSocket", "Matrix")        self.initialized = True# Blender calculates bone roll this way...# https://projects.blender.org/blender/blender/src/commit/dd209221675ac7b62ce47b7ea42f15cbe34a6035/source/blender/editors/armature/armature_edit.cc#L281# but this looks like it will be harder to re-implement than to re-use. Unfortunately, it doesn't apply directly to a matrix so I have to call a method# in the edit bone. Thus, this node currently does nothing and the xForm node has to handle it by reading back through the tree....# this will lead to bugs.# So instead, we need to avoid calculating the roll for now.# but I want to make that its own node and add roll-recalc to this node, too.class UtilitySetBoneMatrixTail(Node, MantisNode):    """Constructs a matrix representing a transformation"""    bl_idname = "UtilitySetBoneMatrixTail"    bl_label = "Set Bone Matrix Tail"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        self.inputs.new("MatrixSocket", "Matrix")        self.inputs.new("VectorSocket", "Tail Location")        self.outputs.new("MatrixSocket", "Result")        self.initialized = Trueclass UtilityMatrixFromXForm(Node, MantisNode):    """Returns the matrix of the given xForm node."""    bl_idname = "UtilityMatrixFromXForm"    bl_label = "Matrix of xForm"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        self.inputs.new("xFormSocket", "xForm")        self.outputs.new("MatrixSocket", "Matrix")        self.initialized = Trueclass UtilityAxesFromMatrix(Node, MantisNode):    """Returns the axes of the matrix."""    bl_idname = "UtilityAxesFromMatrix"    bl_label = "Axes of Matrix"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        self.inputs.new("MatrixSocket", "Matrix")        self.outputs.new("VectorSocket", "X Axis")        self.outputs.new("VectorSocket", "Y Axis")        self.outputs.new("VectorSocket", "Z Axis")        self.initialized = Trueclass UtilityIntToString(Node, MantisNode):    """Converts a number to a string"""    bl_idname = "UtilityIntToString"    bl_label = "Number String"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):                self.inputs.new("IntSocket", "Number")        self.inputs.new("IntSocket", "Zero Padding")        self.outputs.new("StringSocket", "String")        self.initialized = Trueclass UtilityArrayGet(Node, MantisNode):    """Gets a value from an array at a specified index."""    bl_idname = "UtilityArrayGet"    bl_label  = "Array Get"    bl_icon   = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        self.inputs.new('EnumArrayGetOptions', 'OoB Behaviour')        self.inputs.new("IntSocket", "Index")        s = self.inputs.new("WildcardSocket", "Array", use_multi_input=True)        s.display_shape = 'SQUARE_DOT'        self.outputs.new("WildcardSocket", "Output")        self.initialized = True        def update(self):        wildcard_color = (0.0,0.0,0.0,0.0)        if self.inputs['Array'].is_linked == False:            self.inputs['Array'].color = wildcard_color            self.outputs['Output'].color = wildcard_color    def insert_link(self, link):        prGreen(link.from_node.name, link.from_socket.identifier, link.to_node.name, link.to_socket.identifier)        if link.to_socket.identifier == self.inputs['Array'].identifier:            from_socket = link.from_socket            print (from_socket.color)            if hasattr(from_socket, "color"):                self.inputs['Array'].color = from_socket.color                self.outputs['Output'].color = from_socket.colorclass UtilityCompare(Node, MantisNode):    """Compares two inputs and produces a boolean output"""    bl_idname = "UtilityCompare"    bl_label = "Compare"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        self.inputs.new("WildcardSocket", "A")        self.inputs.new("WildcardSocket", "B")        self.outputs.new("BooleanSocket", "Result")        self.initialized = True        def update(self):        wildcard_color = (0.0,0.0,0.0,0.0)        if self.inputs['A'].is_linked == False:            self.inputs['A'].color = wildcard_color        if self.inputs['B'].is_linked == False:            self.inputs['B'].color = wildcard_color    def insert_link(self, link):        if link.to_socket.identifier == self.inputs['A'].identifier:            self.inputs['A'].color = from_socket.color_simple            if hasattr(from_socket, "color"):                self.inputs['A'].color = from_socket.color        if link.to_socket.identifier == self.inputs['B'].identifier:            self.inputs['B'].color = from_socket.color_simple            if hasattr(from_socket, "color"):                self.inputs['B'].color = from_socket.colorclass UtilityChoose(Node, MantisNode):    """Chooses an output"""    bl_idname = "UtilityChoose"    bl_label = "Choose"    bl_icon = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):                self.inputs.new("BooleanSocket", "Condition")        self.inputs.new("WildcardSocket", "A")        self.inputs.new("WildcardSocket", "B")        self.outputs.new("WildcardSocket", "Result")        self.initialized = True        def update(self):        wildcard_color = (0.0,0.0,0.0,0.0)        if self.inputs['A'].is_linked == False:            self.inputs['A'].color = wildcard_color            self.outputs['Result'].color = (1.0,0.0,0.0,0.0) # red for Error        if self.inputs['B'].is_linked == False:            self.inputs['B'].color = wildcard_color            self.outputs['Result'].color = (1.0,0.0,0.0,0.0)        # if both inputs are the same color, then use that color for the result        if self.inputs['A'].is_linked and self.inputs['A'].color == self.inputs['B'].color:            self.outputs['Result'].color = self.inputs['A'].color        #        if ((self.inputs['A'].is_linked and self.inputs['B'].is_linked) and            (self.inputs['A'].links[0].from_socket.bl_idname != self.inputs['B'].links[0].from_socket.bl_idname)):            self.inputs['A'].color = (1.0,0.0,0.0,0.0)            self.inputs['B'].color = (1.0,0.0,0.0,0.0)            self.outputs['Result'].color = (1.0,0.0,0.0,0.0)    def insert_link(self, link):        if link.to_socket.identifier == self.inputs['A'].identifier:            self.inputs['A'].color = from_socket.color_simple            if hasattr(from_socket, "color"):                self.inputs['A'].color = from_socket.color        if link.to_socket.identifier == self.inputs['B'].identifier:            self.inputs['B'].color = from_socket.color_simple            if hasattr(from_socket, "color"):                self.inputs['B'].color = from_socket.colorclass UtilityPrint(Node, MantisNode):    """A utility used to print arbitrary values."""    bl_idname = "UtilityPrint"    bl_label  = "Print"    bl_icon   = "NODE"    initialized : bpy.props.BoolProperty(default = False)        def init(self, context):        self.inputs.new("WildcardSocket", "Input")        self.initialized = True    
 |