Skip to content
Snippets Groups Projects
curve_assign_shapekey.py 38.4 KiB
Newer Older
  • Learn to ignore specific revisions
  •         description = 'Space that shape keys are evluated in')
    
        alignList : EnumProperty(name="Vertex Alignment", items = \
            [("-None-", 'Manual Alignment', "Align curve segments based on starting vertex"), \
             ('vertCo', 'Vertex Coordinates', 'Align curve segments based on vertex coordinates')], \
            description = 'Start aligning the vertices of target and shape keys from',
            default = '-None-')
    
        alignVal1 : EnumProperty(name="Value 1",
            items = matchList, default = 'minX', description='First align criterion')
    
        alignVal2 : EnumProperty(name="Value 2",
            items = matchList, default = 'maxY', description='Second align criterion')
    
        alignVal3 : EnumProperty(name="Value 3",
            items = matchList, default = 'minZ', description='Third align criterion')
    
        matchParts : EnumProperty(name="Match Parts", items = \
            [("-None-", 'None', "Don't match parts"), \
            ('default', 'Default', 'Use part (spline) order as in curve'), \
            ('custom', 'Custom', 'Use one of the custom criteria for part matching')], \
            description='Match disconnected parts', default = 'default')
    
        matchCri1 : EnumProperty(name="Value 1",
            items = matchList, default = 'minX', description='First match criterion')
    
        matchCri2 : EnumProperty(name="Value 2",
            items = matchList, default = 'maxY', description='Second match criterion')
    
        matchCri3 : EnumProperty(name="Value 3",
            items = matchList, default = 'minZ', description='Third match criterion')
    
        markVertex : BoolProperty(name="Mark Starting Vertices", \
            description='Mark first vertices in all splines of selected curves', \
                default = False, update = markVertHandler)
    
    
    
        bl_idname = "CURVE_PT_assign_shape_keys"
        bl_space_type = 'VIEW_3D'
        bl_region_type = 'UI'
    
        bl_options = {'DEFAULT_CLOSED'}
    
    
        @classmethod
        def poll(cls, context):
            return context.mode in {'OBJECT', 'EDIT_CURVE'}
    
        def draw(self, context):
    
            layout = self.layout
    
            col = layout.column()
            params = context.window_manager.AssignShapeKeyParams
    
            if(context.mode  == 'OBJECT'):
                row = col.row()
                row.prop(params, "removeOriginal")
    
                row = col.row()
                row.prop(params, "space")
    
                row = col.row()
                row.prop(params, "alignList")
    
                if(params.alignList == 'vertCo'):
                    row = col.row()
                    row.prop(params, "alignVal1")
                    row.prop(params, "alignVal2")
                    row.prop(params, "alignVal3")
    
                row = col.row()
                row.prop(params, "matchParts")
    
                if(params.matchParts == 'custom'):
                    row = col.row()
                    row.prop(params, "matchCri1")
                    row.prop(params, "matchCri2")
                    row.prop(params, "matchCri3")
    
                row = col.row()
                row.operator("object.assign_shape_keys")
            else:
                col.prop(params, "markVertex", \
                    toggle = True)
    
    
    
    def updatePanel(self, context):
        try:
            panel = AssignShapeKeysPanel
            if "bl_rna" in panel.__dict__:
                bpy.utils.unregister_class(panel)
    
            panel.bl_category = context.preferences.addons[__name__].preferences.category
            bpy.utils.register_class(panel)
    
        except Exception as e:
            print("Assign Shape Keys: Updating Panel locations has failed", e)
    
    class AssignShapeKeysPreferences(AddonPreferences):
        bl_idname = __name__
    
        category: StringProperty(
                name = "Tab Category",
                description = "Choose a name for the category of the panel",
    
                update = updatePanel
        )
    
        def draw(self, context):
            layout = self.layout
            row = layout.row()
            col = row.column()
            col.label(text="Tab Category:")
            col.prop(self, "category", text="")
    
    
    # registering and menu integration
    def register():
        bpy.utils.register_class(AssignShapeKeysPanel)
        bpy.utils.register_class(AssignShapeKeysOp)
        bpy.utils.register_class(AssignShapeKeyParams)
        bpy.types.WindowManager.AssignShapeKeyParams = \
            bpy.props.PointerProperty(type=AssignShapeKeyParams)
        bpy.utils.register_class(ModalMarkSegStartOp)
    
        bpy.utils.register_class(AssignShapeKeysPreferences)
        updatePanel(None, bpy.context)
    
    
    def unregister():
        bpy.utils.unregister_class(AssignShapeKeysOp)
        bpy.utils.unregister_class(AssignShapeKeysPanel)
        del bpy.types.WindowManager.AssignShapeKeyParams
        bpy.utils.unregister_class(AssignShapeKeyParams)
        bpy.utils.unregister_class(ModalMarkSegStartOp)
    
        bpy.utils.unregister_class(AssignShapeKeysPreferences)
    
    
    if __name__ == "__main__":
        register()