Skip to content

Commit

Permalink
feat: add option to remove triangulate modifiers via the CTRL alt-mod…
Browse files Browse the repository at this point in the history
…e convention
  • Loading branch information
tristan-hm authored Jun 28, 2024
1 parent 045eeaf commit e6aa830
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packaging/triangulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
Expand All @@ -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'
Expand Down

0 comments on commit e6aa830

Please sign in to comment.