From ed026796f34e034c3ac471173fb69b9d0bcbb2dc Mon Sep 17 00:00:00 2001 From: Tristan Strathearn Date: Sat, 21 May 2022 11:38:44 +1000 Subject: [PATCH] feat: add an option to custom default smoothing angle and update & add it across all relevant operators --- __init__.py | 54 ++++++++++++++++------------- lib/objects.py | 3 +- power_mods/bevel.py | 8 +++++ power_mods/edge_bevel.py | 10 ++++++ power_mods/screw.py | 2 +- power_mods/solidify.py | 2 +- power_mods/vertex_bevel.py | 10 ++++++ power_mods/weighted_normal_bevel.py | 2 +- utils/smooth.py | 4 +-- 9 files changed, 65 insertions(+), 30 deletions(-) diff --git a/__init__.py b/__init__.py index 76083a5..de8fc17 100644 --- a/__init__.py +++ b/__init__.py @@ -179,6 +179,16 @@ class NDPreferences(AddonPreferences): default="GENERAL", ) + default_smoothing_angle: EnumProperty( + name="Default Smooting Angle", + items=[ + ("30", "30°", ""), + ("45", "45°", ""), + ("60", "60°", ""), + ], + default="30", + ) + overlay_pause_key: EnumProperty( name="Pause Key", items=lib.overlay_keys.overlay_keys_enum, @@ -232,33 +242,29 @@ def draw(self, context): def draw_general(self, box): - column = box.column(align=True) - row = column.row() - row.prop(self, "utils_collection_name") + general_prefs = [ + "utils_collection_name", + "use_fast_booleans", + "recon_poly_solidify"] - column = box.column(align=True) - row = column.row() - row.prop(self, "use_fast_booleans") - - column = box.column(align=True) - row = column.row() - row.prop(self, "recon_poly_solidify") + for pref in general_prefs: + column = box.column(align=True) + row = column.row() + row.prop(self, pref) - box2 = box.box() - column = box2.column(align=True) - row = column.row() - row.label(text="Set a path for a custom screw heads .blend file") - column = box2.column(align=True) - row = column.row() - row.prop(self, "custom_screw_heads_path") + general_boxed_prefs = [ + ["The default angle to use for smoothing operations (eg. auto-smooth)", "default_smoothing_angle", True], + ["Set a path for a custom screw heads .blend file", "custom_screw_heads_path", False], + ["Enable deprecated features for short term backwards compatibility", "enable_deprecated_features", False]] - box3 = box.box() - column = box3.column(align=True) - row = column.row() - row.label(text="Enable deprecated features for short term backwards compatibility", icon="ERROR") - column = box3.column(align=True) - row = column.row() - row.prop(self, "enable_deprecated_features") + for label, prop, expanded in general_boxed_prefs: + pref_box = box.box() + column = pref_box.column(align=True) + row = column.row() + row.label(text=label) + column = pref_box.column(align=True) + row = column.row() + row.prop(self, prop, expand=expanded) def draw_ui(self, box): diff --git a/lib/objects.py b/lib/objects.py index 009912e..5f90c5b 100644 --- a/lib/objects.py +++ b/lib/objects.py @@ -21,6 +21,7 @@ import bpy import bmesh from math import radians +from . preferences import get_preferences def add_single_vertex_object(cls, context, name): @@ -40,7 +41,7 @@ def add_single_vertex_object(cls, context, name): bpy.ops.object.shade_smooth() obj.data.use_auto_smooth = True - obj.data.auto_smooth_angle = radians(30) + obj.data.auto_smooth_angle = radians(float(get_preferences().default_smoothing_angle)) cls.obj = obj diff --git a/power_mods/bevel.py b/power_mods/bevel.py index 67ee2ae..e338d37 100644 --- a/power_mods/bevel.py +++ b/power_mods/bevel.py @@ -20,6 +20,7 @@ import bpy import bmesh +from math import radians from .. lib.overlay import update_overlay, init_overlay, toggle_pin_overlay, toggle_operator_passthrough, register_draw_handler, unregister_draw_handler, draw_header, draw_property, draw_hint from .. lib.events import capture_modifier_keys, pressed from .. lib.preferences import get_preferences @@ -196,6 +197,7 @@ def poll(cls, context): def prepare_new_operator(self, context): self.summoned = False + self.add_smooth_shading(context) self.add_bevel_modifier(context) @@ -210,6 +212,12 @@ def summon_old_operator(self, context, mods): self.harden_normals_prev = self.harden_normals = self.bevel.harden_normals + def add_smooth_shading(self, context): + bpy.ops.object.shade_smooth() + context.object.data.use_auto_smooth = True + context.object.data.auto_smooth_angle = radians(float(get_preferences().default_smoothing_angle)) + + def add_bevel_modifier(self, context): bevel = context.object.modifiers.new(mod_bevel, 'BEVEL') bevel.offset_type = 'WIDTH' diff --git a/power_mods/edge_bevel.py b/power_mods/edge_bevel.py index f48c433..97e014e 100644 --- a/power_mods/edge_bevel.py +++ b/power_mods/edge_bevel.py @@ -20,6 +20,7 @@ import bpy import bmesh +from math import radians from .. lib.overlay import update_overlay, init_overlay, toggle_pin_overlay, toggle_operator_passthrough, register_draw_handler, unregister_draw_handler, draw_header, draw_property, draw_hint from .. lib.events import capture_modifier_keys, pressed from .. lib.preferences import get_preferences @@ -222,6 +223,7 @@ def poll(cls, context): def prepare_new_operator(self, context): self.summoned = False + self.add_smooth_shading(context) self.add_bevel_modifier(context) @@ -236,6 +238,14 @@ def summon_old_operator(self, context, mods): self.harden_normals_prev = self.harden_normals = self.bevel.harden_normals + def add_smooth_shading(self, context): + bpy.ops.object.mode_set(mode='OBJECT') + bpy.ops.object.shade_smooth() + context.object.data.use_auto_smooth = True + context.object.data.auto_smooth_angle = radians(float(get_preferences().default_smoothing_angle)) + bpy.ops.object.mode_set(mode='EDIT') + + def add_bevel_modifier(self, context): bevel = context.object.modifiers.new(mod_bevel, 'BEVEL') bevel.offset_type = 'WIDTH' diff --git a/power_mods/screw.py b/power_mods/screw.py index 569914a..0f3b46a 100644 --- a/power_mods/screw.py +++ b/power_mods/screw.py @@ -231,7 +231,7 @@ def summon_old_operator(self, context, mods): def add_smooth_shading(self, context): bpy.ops.object.shade_smooth() context.object.data.use_auto_smooth = True - context.object.data.auto_smooth_angle = radians(30) + context.object.data.auto_smooth_angle = radians(float(get_preferences().default_smoothing_angle)) def add_displace_modifier(self, context): diff --git a/power_mods/solidify.py b/power_mods/solidify.py index 82d4f13..3644fac 100644 --- a/power_mods/solidify.py +++ b/power_mods/solidify.py @@ -198,7 +198,7 @@ def summon_old_operator(self, context, mods): def add_smooth_shading(self, context): bpy.ops.object.shade_smooth() context.object.data.use_auto_smooth = True - context.object.data.auto_smooth_angle = radians(30) + context.object.data.auto_smooth_angle = radians(float(get_preferences().default_smoothing_angle)) def add_displace_modifier(self, context): diff --git a/power_mods/vertex_bevel.py b/power_mods/vertex_bevel.py index 389c94a..a851620 100644 --- a/power_mods/vertex_bevel.py +++ b/power_mods/vertex_bevel.py @@ -20,6 +20,7 @@ import bpy import bmesh +from math import radians from .. lib.overlay import update_overlay, init_overlay, toggle_pin_overlay, toggle_operator_passthrough, register_draw_handler, unregister_draw_handler, draw_header, draw_property, draw_hint from .. lib.events import capture_modifier_keys, pressed from .. lib.preferences import get_preferences @@ -234,10 +235,19 @@ def summon_old_operator(self, context): def prepare_new_operator(self, context): self.summoned = False + self.add_smooth_shading(context) self.add_vertex_group(context) self.add_bevel_modifier(context) + def add_smooth_shading(self, context): + bpy.ops.object.mode_set(mode='OBJECT') + bpy.ops.object.shade_smooth() + context.object.data.use_auto_smooth = True + context.object.data.auto_smooth_angle = radians(float(get_preferences().default_smoothing_angle)) + bpy.ops.object.mode_set(mode='EDIT') + + def add_vertex_group(self, context): vgroup = context.object.vertex_groups.new(name="ND — Bevel") bpy.ops.object.vertex_group_assign() diff --git a/power_mods/weighted_normal_bevel.py b/power_mods/weighted_normal_bevel.py index d44fb5b..21cf0c6 100644 --- a/power_mods/weighted_normal_bevel.py +++ b/power_mods/weighted_normal_bevel.py @@ -172,7 +172,7 @@ def summon_old_operator(self, context, mods): def add_smooth_shading(self, context): bpy.ops.object.shade_smooth() context.object.data.use_auto_smooth = True - context.object.data.auto_smooth_angle = radians(30) + context.object.data.auto_smooth_angle = radians(float(get_preferences().default_smoothing_angle)) def add_bevel_modifier(self, context): diff --git a/utils/smooth.py b/utils/smooth.py index 9626b0b..c21679d 100644 --- a/utils/smooth.py +++ b/utils/smooth.py @@ -64,7 +64,7 @@ def modal(self, context, event): elif self.key_reset: if self.key_no_modifiers: self.angle_input_stream = new_stream() - self.angle = 30 + self.angle = float(get_preferences().default_smoothing_angle) self.dirty = True elif self.key_step_up: @@ -101,7 +101,7 @@ def modal(self, context, event): def invoke(self, context, event): self.dirty = False self.base_angle_factor = 15 - self.angle = 30 + self.angle = float(get_preferences().default_smoothing_angle) self.angle_input_stream = new_stream()