Skip to content
Snippets Groups Projects
mesh_looptools.py 182 KiB
Newer Older
  • Learn to ignore specific revisions
  •         description="Distribute vertices at constant distances along the loop",
            default=True
            )
    
    florianfelix's avatar
    florianfelix committed
        space_influence: FloatProperty(
    
            name="Influence",
            description="Force of the tool",
            default=100.0,
            min=0.0,
            max=100.0,
            precision=1,
            subtype='PERCENTAGE'
            )
    
    florianfelix's avatar
    florianfelix committed
        space_input: EnumProperty(
    
            name="Input",
            items=(("all", "Parallel (all)", "Also use non-selected "
    
                    "parallel loops as input"),
    
                ("selected", "Selection", "Only use selected vertices as input")),
            description="Loops that are spaced",
            default='selected'
            )
    
    florianfelix's avatar
    florianfelix committed
        space_interpolation: EnumProperty(
    
            name="Interpolation",
            items=(("cubic", "Cubic", "Natural cubic spline, smooth results"),
    
                ("linear", "Linear", "Vertices are projected on existing edges")),
    
            description="Algorithm used for interpolation",
            default='cubic'
            )
    
    florianfelix's avatar
    florianfelix committed
        space_lock_x: BoolProperty(
    
            name="Lock X",
            description="Lock editing of the x-coordinate",
            default=False
            )
    
    florianfelix's avatar
    florianfelix committed
        space_lock_y: BoolProperty(
    
            name="Lock Y",
            description="Lock editing of the y-coordinate",
            default=False
            )
    
    florianfelix's avatar
    florianfelix committed
        space_lock_z: BoolProperty(
    
            name="Lock Z",
            description="Lock editing of the z-coordinate",
            default=False
            )
    
    
    # draw function for integration in menus
    def menu_func(self, context):
        self.layout.menu("VIEW3D_MT_edit_mesh_looptools")
        self.layout.separator()
    
    
    
    # Add-ons Preferences Update Panel
    
    # Define Panel classes for updating
    panels = (
            VIEW3D_PT_tools_looptools,
            )
    
    
    
    def update_panel(self, context):
    
        message = "LoopTools: Updating Panel locations has failed"
    
            for panel in panels:
                if "bl_rna" in panel.__dict__:
                    bpy.utils.unregister_class(panel)
    
            for panel in panels:
    
                panel.bl_category = context.preferences.addons[__name__].preferences.category
    
                bpy.utils.register_class(panel)
    
        except Exception as e:
            print("\n[{}]\n{}\n\nError:\n{}".format(__name__, message, e))
    
    
    class LoopPreferences(AddonPreferences):
    
        # this must match the addon name, use '__package__'
        # when defining this in a submodule of a python package.
        bl_idname = __name__
    
    
    florianfelix's avatar
    florianfelix committed
        category: StringProperty(
    
                name="Tab Category",
                description="Choose a name for the category of the panel",
    
                update=update_panel
                )
    
    
        def draw(self, context):
            layout = self.layout
    
            row = layout.row()
            col = row.column()
            col.label(text="Tab Category:")
            col.prop(self, "category", text="")
    
    # define classes for registration
    
        VIEW3D_MT_edit_mesh_looptools,
    
        VIEW3D_PT_tools_looptools,
        LoopToolsProps,
        Bridge,
        Circle,
        Curve,
        Flatten,
    
    Bart Crouch's avatar
    Bart Crouch committed
        GStretch,
    
        Space,
        LoopPreferences,
    
    meta-androcto's avatar
    meta-androcto committed
        RemoveGP,
    
    
    
    # registering and menu integration
    def register():
    
        for cls in classes:
            bpy.utils.register_class(cls)
    
        bpy.types.VIEW3D_MT_edit_mesh_context_menu.prepend(menu_func)
    
        bpy.types.WindowManager.looptools = PointerProperty(type=LoopToolsProps)
    
    # unregistering and removing menus
    def unregister():
    
    florianfelix's avatar
    florianfelix committed
        for cls in reversed(classes):
    
            bpy.utils.unregister_class(cls)
    
        bpy.types.VIEW3D_MT_edit_mesh_context_menu.remove(menu_func)
    
        try:
            del bpy.types.WindowManager.looptools
    
    florianfelix's avatar
    florianfelix committed
        except Exception as e:
            print('unregister fail:\n', e)
    
            pass
    
    
    if __name__ == "__main__":
        register()