Skip to content

Commit

Permalink
feat: add profile option to vanilla bevel operator
Browse files Browse the repository at this point in the history
  • Loading branch information
tristan-hm committed Apr 18, 2022
1 parent 9f22e77 commit ca24b38
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions power_mods/bevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class ND_OT_bevel(bpy.types.Operator):
def modal(self, context, event):
capture_modifier_keys(self, event)

width_factor = (self.base_width_factor / 10.0) if event.shift else self.base_width_factor
width_factor = (self.base_width_factor / 10.0) if self.key_shift else self.base_width_factor
profile_factor = 0.01 if self.key_shift else 0.1
segment_factor = 1 if self.key_shift else 2

if self.key_toggle_operator_passthrough:
Expand All @@ -39,24 +40,30 @@ def modal(self, context, event):
return {'CANCELLED'}

elif self.key_increase_factor:
self.base_width_factor = min(1, self.base_width_factor * 10.0)
if self.key_no_modifiers:
self.base_width_factor = min(1, self.base_width_factor * 10.0)

elif self.key_decrease_factor:
self.base_width_factor = max(0.001, self.base_width_factor / 10.0)

if self.key_no_modifiers:
self.base_width_factor = max(0.001, self.base_width_factor / 10.0)

elif self.key_step_up:
if self.key_alt:
self.segments = 2 if self.segments == 1 else self.segments + segment_factor
elif self.key_ctrl:
self.profile = min(1, self.profile + profile_factor)
elif self.key_no_modifiers:
self.width += width_factor

self.dirty = True

self.dirty = True

elif self.key_step_down:
if self.key_alt:
self.segments = max(1, self.segments - segment_factor)
elif self.key_ctrl:
self.profile = max(0, self.profile - profile_factor)
elif self.key_no_modifiers:
self.width = max(0.0001, self.width - width_factor)
self.width = max(0, self.width - width_factor)

self.dirty = True

Expand All @@ -70,7 +77,9 @@ def modal(self, context, event):

if get_preferences().enable_mouse_values:
if self.key_no_modifiers:
self.width = max(0.0001, self.width + self.mouse_value)
self.width = max(0, self.width + self.mouse_value)
elif self.key_ctrl:
self.profile = max(0, min(1, self.profile + self.mouse_value))

self.dirty = True

Expand All @@ -84,8 +93,11 @@ def modal(self, context, event):

def invoke(self, context, event):
self.dirty = False
self.base_width_factor = 0.001
self.base_width_factor = 0.01

self.segments = 1
self.width = 0
self.profile = 0.5

mods = context.active_object.modifiers
mod_names = list(map(lambda x: x.name, mods))
Expand Down Expand Up @@ -141,6 +153,7 @@ def add_bevel_modifier(self, context):
def operate(self, context):
self.bevel.width = self.width
self.bevel.segments = self.segments
self.bevel.profile = self.profile

self.dirty = False

Expand Down Expand Up @@ -178,6 +191,14 @@ def draw_text_callback(self):
active=self.key_alt,
alt_mode=self.key_shift_alt)

draw_property(
self,
"Profile: {0:.2f}".format(self.profile),
"Ctrl (±0.1) | Shift + Ctrl (±0.01)",
active=self.key_ctrl,
alt_mode=self.key_shift_ctrl,
mouse_value=True)


def menu_func(self, context):
self.layout.operator(ND_OT_bevel.bl_idname, text=ND_OT_bevel.bl_label)
Expand Down

0 comments on commit ca24b38

Please sign in to comment.