Skip to content
Snippets Groups Projects
mesh_looptools.py 186 KiB
Newer Older
  • Learn to ignore specific revisions
  •         name="Max Vertices",
    
            description="Maximum number of vertices strokes will "
    
                        "have, when they are converted to geomtery",
            default=32,
            min=3,
            soft_max=500,
            update=gstretch_update_min
            )
    
    florianfelix's avatar
    florianfelix committed
        gstretch_conversion_min: IntProperty(
    
            name="Min Vertices",
    
            description="Minimum number of vertices strokes will "
    
                        "have, when they are converted to geomtery",
            default=8,
            min=3,
            soft_max=500,
            update=gstretch_update_max
            )
    
    florianfelix's avatar
    florianfelix committed
        gstretch_conversion_vertices: IntProperty(
    
            name="Vertices",
    
            description="Number of vertices strokes will "
    
                        "have, when they are converted to geometry. If strokes have less "
                        "points than required, the 'Spread evenly' method is used",
            default=32,
            min=3,
            soft_max=500
            )
    
    florianfelix's avatar
    florianfelix committed
        gstretch_delete_strokes: BoolProperty(
    
            name="Delete strokes",
            description="Remove Grease Pencil strokes if they have been used "
                        "for Gstretch. WARNING: DOES NOT SUPPORT UNDO",
            default=False
            )
    
    florianfelix's avatar
    florianfelix committed
        gstretch_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
        gstretch_lock_x: BoolProperty(
    
            name="Lock X",
            description="Lock editing of the x-coordinate",
            default=False
            )
    
    florianfelix's avatar
    florianfelix committed
        gstretch_lock_y: BoolProperty(
    
            name="Lock Y",
            description="Lock editing of the y-coordinate",
            default=False
            )
    
    florianfelix's avatar
    florianfelix committed
        gstretch_lock_z: BoolProperty(
    
            name="Lock Z",
            description="Lock editing of the z-coordinate",
            default=False
            )
    
    florianfelix's avatar
    florianfelix committed
        gstretch_method: EnumProperty(
    
            name="Method",
            items=(("project", "Project", "Project vertices onto the stroke, "
                    "using vertex normals and connected edges"),
                    ("irregular", "Spread", "Distribute vertices along the full "
                    "stroke, retaining relative distances between the vertices"),
                    ("regular", "Spread evenly", "Distribute vertices at regular "
                    "distances along the full stroke")),
            description="Method of distributing the vertices over the Grease "
                        "Pencil stroke",
            default='regular'
            )
    
        gstretch_use_guide: EnumProperty(
            name="Use guides",
            items=(("None", "None", "None"),
                    ("Annotation", "Annotation", "Annotation"),
                    ("GPencil", "GPencil", "GPencil")),
            default="None"
            )
        gstretch_guide: PointerProperty(
            name="GPencil object",
            description="Set GPencil object",
            type=bpy.types.Object
    
    florianfelix's avatar
    florianfelix committed
        relax_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 relaxed",
            default='selected'
            )
    
    florianfelix's avatar
    florianfelix committed
        relax_interpolation: EnumProperty(
    
            name="Interpolation",
            items=(("cubic", "Cubic", "Natural cubic spline, smooth results"),
                    ("linear", "Linear", "Simple and fast linear algorithm")),
            description="Algorithm used for interpolation",
            default='cubic'
            )
    
    florianfelix's avatar
    florianfelix committed
        relax_iterations: EnumProperty(name="Iterations",
    
            items=(("1", "1", "One"),
                    ("3", "3", "Three"),
                    ("5", "5", "Five"),
                    ("10", "10", "Ten"),
                    ("25", "25", "Twenty-five")),
            description="Number of times the loop is relaxed",
            default="1"
            )
    
    florianfelix's avatar
    florianfelix committed
        relax_regular: BoolProperty(
    
            name="Regular",
            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,
    
    
    
    # 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()