diff --git a/packaging/triangulate.py b/packaging/triangulate.py index dbd479c..51d7b29 100644 --- a/packaging/triangulate.py +++ b/packaging/triangulate.py @@ -26,13 +26,14 @@ # --- import bpy -from .. lib.modifiers import new_modifier +from .. lib.modifiers import new_modifier, remove_modifiers_ending_with class ND_OT_triangulate(bpy.types.Operator): bl_idname = "nd.triangulate" bl_label = "Triangulate" bl_description = """Add a triangulate modifier to the selected objects +CTRL — Remove existing modifiers ALT — Do not preserve custom normals SHIFT — Only triangulate ngons (5+ vertices)""" bl_options = {'UNDO'} @@ -47,11 +48,15 @@ def poll(cls, context): def invoke(self, context, event): self.preserve_normals = not event.alt self.only_ngons = event.shift + self.remove_mods = event.ctrl - for obj in context.selected_objects: - if obj.type != 'MESH': - continue + mesh_objects = [obj for obj in context.selected_objects if obj.type == 'MESH'] + + if self.remove_mods: + remove_modifiers_ending_with(mesh_objects, 'Triangulate — ND', False) + return {'FINISHED'} + for obj in mesh_objects: triangulate = new_modifier(obj, 'Triangulate — ND', 'TRIANGULATE', rectify=False) triangulate.keep_custom_normals = self.preserve_normals triangulate.quad_method = 'FIXED' if self.preserve_normals else 'BEAUTY'