Skip to content

Commit

Permalink
feat: allow for manual values to be supplied to overlay & optimise op…
Browse files Browse the repository at this point in the history
…erator overlay options
  • Loading branch information
tristan-hm authored May 20, 2022
1 parent a5260f5 commit bffaf72
Show file tree
Hide file tree
Showing 29 changed files with 1,122 additions and 619 deletions.
30 changes: 30 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,24 @@ class NDPreferences(AddonPreferences):
default="P",
)

overlay_reset_key: EnumProperty(
name="Reset Option Key",
items=lib.overlay_keys.overlay_keys_enum,
default="X",
)

overlay_increase_factor: EnumProperty(
name="Increase Option Factor",
items=lib.overlay_keys.overlay_keys_enum,
default="RIGHT_BRACKET",
)

overlay_decrease_factor: EnumProperty(
name="Decrease Option Factor",
items=lib.overlay_keys.overlay_keys_enum,
default="LEFT_BRACKET",
)

custom_screw_heads_path: StringProperty(
name="Custom Screw Heads",
subtype='FILE_PATH',
Expand Down Expand Up @@ -276,6 +294,18 @@ def draw_keymap(self, box):
column = box.column(align=True)
row = column.row()
row.prop(self, "overlay_pause_key")

column = box.column(align=True)
row = column.row()
row.prop(self, "overlay_reset_key")

column = box.column(align=True)
row = column.row()
row.prop(self, "overlay_increase_factor")

column = box.column(align=True)
row = column.row()
row.prop(self, "overlay_decrease_factor")

name = "ND v%s" % ('.'.join([str(v) for v in bl_info['version']]))
wm = bpy.context.window_manager
Expand Down
51 changes: 29 additions & 22 deletions booleans/boolean_inset.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
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
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
from .. lib.collections import move_to_utils_collection, isolate_in_utils_collection
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream


class ND_OT_bool_inset(bpy.types.Operator):
Expand Down Expand Up @@ -43,34 +44,40 @@ def modal(self, context, event):
self.revert(context)

return {'CANCELLED'}

elif self.key_numeric_input:
if self.key_no_modifiers:
self.thickness_input_stream = update_stream(self.thickness_input_stream, event.type)
self.thickness = get_stream_value(self.thickness_input_stream, 0.001)
self.dirty = True

elif self.key_reset:
if self.key_no_modifiers:
self.thickness_input_stream = new_stream()
self.thickness = 0
self.dirty = True

elif pressed(event, {'M'}):
self.outset = not self.outset
self.dirty = True

elif self.key_increase_factor:
if self.key_no_modifiers:
if no_stream(self.thickness_input_stream) and self.key_no_modifiers:
self.base_thickness_factor = min(1, self.base_thickness_factor * 10.0)

elif self.key_decrease_factor:
if self.key_no_modifiers:
if no_stream(self.thickness_input_stream) and self.key_no_modifiers:
self.base_thickness_factor = max(0.001, self.base_thickness_factor / 10.0)

elif self.key_step_up:
if self.key_no_modifiers:
if no_stream(self.thickness_input_stream) and self.key_no_modifiers:
self.thickness += thickness_factor
elif self.key_alt:
self.outset = not self.outset

self.dirty = True
self.dirty = True

elif self.key_step_down:
if self.key_no_modifiers:
if no_stream(self.thickness_input_stream) and self.key_no_modifiers:
self.thickness = max(0, self.thickness - thickness_factor)
elif self.key_alt:
self.outset = not self.outset

self.dirty = True
self.dirty = True

elif self.key_confirm:
self.finish(context)
Expand All @@ -81,10 +88,9 @@ def modal(self, context, event):
return {'PASS_THROUGH'}

if get_preferences().enable_mouse_values:
if self.key_no_modifiers:
if no_stream(self.thickness_input_stream) and self.key_no_modifiers:
self.thickness = max(0, self.thickness + self.mouse_value)

self.dirty = True
self.dirty = True

if self.dirty:
self.operate(context)
Expand All @@ -101,6 +107,8 @@ def invoke(self, context, event):
self.thickness = 0.02
self.outset = False

self.thickness_input_stream = new_stream()

solver = 'FAST' if get_preferences().use_fast_booleans else 'EXACT'

a, b = context.selected_objects
Expand Down Expand Up @@ -214,14 +222,13 @@ def draw_text_callback(self):
"(±{0:.1f}) | Shift + (±{1:.1f})".format(self.base_thickness_factor * 1000, (self.base_thickness_factor / 10) * 1000),
active=self.key_no_modifiers,
alt_mode=self.key_shift_no_modifiers,
mouse_value=True)
mouse_value=True,
input_stream=self.thickness_input_stream)

draw_property(
self,
draw_hint(
self,
"Mode [M]: {0}".format('Outset' if self.outset else 'Inset'),
"(Inset, Outset)",
active=self.key_alt,
alt_mode=False)
"Create an Inset or Outset")


def menu_func(self, context):
Expand Down
82 changes: 60 additions & 22 deletions generators/recon_poly.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .. lib.objects import add_single_vertex_object, align_object_to_3d_cursor
from .. lib.events import capture_modifier_keys
from .. lib.preferences import get_preferences
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream


mod_displace = "Radius — ND RCP"
Expand Down Expand Up @@ -53,38 +54,68 @@ def modal(self, context, event):

return {'CANCELLED'}

elif self.key_increase_factor:
elif self.key_numeric_input:
if self.key_no_modifiers:
self.base_width_factor = min(1, self.base_width_factor * 10.0)
self.width_input_stream = update_stream(self.width_input_stream, event.type)
self.width = get_stream_value(self.width_input_stream, 0.001)
self.dirty = True
elif self.key_ctrl:
self.inner_radius_input_stream = update_stream(self.inner_radius_input_stream, event.type)
self.inner_radius = get_stream_value(self.inner_radius_input_stream, 0.001)
self.dirty = True
elif self.key_alt:
self.segments_input_stream = update_stream(self.segments_input_stream, event.type)
self.segments = get_stream_value(self.segments_input_stream)
self.dirty = True

elif self.key_reset:
if self.key_no_modifiers:
self.width_input_stream = new_stream()
self.width = 0.05
self.dirty = True
elif self.key_ctrl:
self.inner_radius_input_stream = new_stream()
self.inner_radius = 0
self.dirty = True
elif self.key_alt:
self.segments_input_stream = new_stream()
self.segments = 3
self.dirty = True

elif self.key_increase_factor:
if no_stream(self.width_input_stream) and self.key_no_modifiers:
self.base_width_factor = min(1, self.base_width_factor * 10.0)
elif no_stream(self.inner_radius_input_stream) and self.key_ctrl:
self.base_inner_radius_factor = min(1, self.base_inner_radius_factor * 10.0)

elif self.key_decrease_factor:
if self.key_no_modifiers:
if no_stream(self.width_input_stream) and self.key_no_modifiers:
self.base_width_factor = max(0.001, self.base_width_factor / 10.0)
elif self.key_ctrl:
elif no_stream(self.inner_radius_input_stream) and self.key_ctrl:
self.base_inner_radius_factor = max(0.001, self.base_inner_radius_factor / 10.0)

elif self.key_step_up:
if self.key_alt:
if no_stream(self.segments_input_stream) and self.key_alt:
self.segments = 4 if self.segments == 3 else self.segments + segment_factor
elif self.key_ctrl:
self.dirty = True
elif no_stream(self.inner_radius_input_stream) and self.key_ctrl:
self.inner_radius += inner_radius_factor
elif self.key_no_modifiers:
self.dirty = True
elif no_stream(self.width_input_stream) and self.key_no_modifiers:
self.width += width_factor

self.dirty = True
self.dirty = True

elif self.key_step_down:
if self.key_alt:
if no_stream(self.segments_input_stream) and self.key_alt:
self.segments = max(3, self.segments - segment_factor)
elif self.key_ctrl:
self.dirty = True
elif no_stream(self.inner_radius_input_stream) and self.key_ctrl:
self.inner_radius = max(0, self.inner_radius - inner_radius_factor)
self.width = max(self.inner_radius * -0.5, self.width)
elif self.key_no_modifiers:
self.dirty = True
elif no_stream(self.width_input_stream) and self.key_no_modifiers:
self.width = max(self.inner_radius * -0.5, self.width - width_factor)

self.dirty = True
self.dirty = True

elif self.key_confirm:
self.finish(context)
Expand All @@ -95,13 +126,13 @@ def modal(self, context, event):
return {'PASS_THROUGH'}

if get_preferences().enable_mouse_values:
if self.key_no_modifiers:
if no_stream(self.width_input_stream) and self.key_no_modifiers:
self.width = max(self.inner_radius * -0.5, self.width + self.mouse_value)
elif self.key_ctrl:
self.dirty = True
elif no_stream(self.inner_radius_input_stream) and self.key_ctrl:
self.inner_radius = max(0, self.inner_radius + self.mouse_value)
self.width = max(self.inner_radius * -0.5, self.width)

self.dirty = True
self.dirty = True

if self.dirty:
self.operate(context)
Expand All @@ -116,6 +147,10 @@ def invoke(self, context, event):
self.base_inner_radius_factor = 0.001
self.base_width_factor = 0.001

self.segments_input_stream = new_stream()
self.inner_radius_input_stream = new_stream()
self.width_input_stream = new_stream()

if len(context.selected_objects) == 1:
mods = context.active_object.modifiers
mod_names = list(map(lambda x: x.name, mods))
Expand Down Expand Up @@ -180,7 +215,7 @@ def poll(cls, context):

def add_displace_modifier(self):
displace = self.obj.modifiers.new(mod_displace, 'DISPLACE')
displace.mid_level = 0.5
displace.mid_level = 0
displace.direction = 'X'
displace.space = 'LOCAL'

Expand Down Expand Up @@ -286,22 +321,25 @@ def draw_text_callback(self):
"(±{0:.1f}) | Shift (±{1:.1f})".format(self.base_width_factor * 1000, (self.base_width_factor / 10) * 1000),
active=self.key_no_modifiers,
alt_mode=self.key_shift_no_modifiers,
mouse_value=True)
mouse_value=True,
input_stream=self.width_input_stream)

draw_property(
self,
"Segments: {}".format(self.segments),
"Alt (±2) | Shift + Alt (±1)",
active=self.key_alt,
alt_mode=self.key_shift_alt)
alt_mode=self.key_shift_alt,
input_stream=self.segments_input_stream)

draw_property(
self,
"Inner Radius: {0:.1f}".format(self.inner_radius * 1000),
"Ctrl (±{0:.1f}) | Shift + Ctrl (±{1:.1f})".format(self.base_inner_radius_factor * 1000, (self.base_inner_radius_factor / 10) * 1000),
active=self.key_ctrl,
alt_mode=self.key_shift_ctrl,
mouse_value=True)
mouse_value=True,
input_stream=self.inner_radius_input_stream)


def menu_func(self, context):
Expand Down
Loading

0 comments on commit bffaf72

Please sign in to comment.