Skip to content

Commit

Permalink
feat: add optional late-invocation mode to vertex bevel operator (for…
Browse files Browse the repository at this point in the history
… post-sketch usage)
  • Loading branch information
tristan-hm committed Apr 11, 2022
1 parent d816aa8 commit ff0ffa4
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions power_mods/vertex_bevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

mod_bevel = "Bevel — ND VB"
mod_weld = "Weld — ND VB"
mod_weld_la = "Weld — ND VB LA" # For late-application of the modifier
mod_summon_list = [mod_bevel, mod_weld]


class ND_OT_vertex_bevel(bpy.types.Operator):
bl_idname = "nd.vertex_bevel"
bl_label = "Vertex Bevel"
bl_description = "Adds a vertex group bevel and weld modifier"
bl_description = """Adds a vertex group bevel and weld modifier
SHIFT — Place modifiers at the top of the stack (post-sketch)"""
bl_options = {'UNDO'}


Expand Down Expand Up @@ -88,6 +90,8 @@ def modal(self, context, event):


def invoke(self, context, event):
self.late_apply = event.shift

self.dirty = False
self.base_width_factor = 0.01
self.base_profile_factor = 0.1
Expand Down Expand Up @@ -134,23 +138,25 @@ def add_bevel_modifier(self, context):

self.bevel = bevel

while context.object.modifiers[0].name != self.bevel.name:
bpy.ops.object.modifier_move_up(modifier=self.bevel.name)
if not self.late_apply:
while context.object.modifiers[0].name != self.bevel.name:
bpy.ops.object.modifier_move_up(modifier=self.bevel.name)


def add_weld_modifier(self, context):
mods = context.active_object.modifiers
mod_names = list(map(lambda x: x.name, mods))
previous_op = all(m in mod_names for m in mod_summon_list)

if not previous_op:
weld = context.object.modifiers.new(mod_weld, type='WELD')
if self.late_apply or not previous_op:
weld = context.object.modifiers.new(mod_weld_la if self.late_apply else mod_weld, type='WELD')
weld.merge_threshold = 0.00001

self.weld = weld

while context.object.modifiers[1].name != self.weld.name:
bpy.ops.object.modifier_move_up(modifier=self.weld.name)
if not self.late_apply:
while context.object.modifiers[1].name != self.weld.name:
bpy.ops.object.modifier_move_up(modifier=self.weld.name)


def operate(self, context):
Expand Down

0 comments on commit ff0ffa4

Please sign in to comment.