Skip to content

Commit

Permalink
feat: add an option to custom default smoothing angle and update & ad…
Browse files Browse the repository at this point in the history
…d it across all relevant operators
  • Loading branch information
tristan-hm committed May 21, 2022
1 parent dc51574 commit ed02679
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 30 deletions.
54 changes: 30 additions & 24 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion lib/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

Expand Down
8 changes: 8 additions & 0 deletions power_mods/bevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)


Expand All @@ -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'
Expand Down
10 changes: 10 additions & 0 deletions power_mods/edge_bevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)


Expand All @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion power_mods/screw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion power_mods/solidify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 10 additions & 0 deletions power_mods/vertex_bevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion power_mods/weighted_normal_bevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions utils/smooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand 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()

Expand Down

0 comments on commit ed02679

Please sign in to comment.