diff --git a/generators/recon_poly.py b/generators/recon_poly.py index d6c797e..2366db3 100644 --- a/generators/recon_poly.py +++ b/generators/recon_poly.py @@ -63,6 +63,8 @@ def modal(self, context, event): elif self.key_no_modifiers: self.segments = 4 if self.segments == 3 else self.segments + segment_factor + self.dirty = True + elif self.key_step_down: if self.key_alt: self.inner_radius = max(0, self.inner_radius - inner_radius_factor) @@ -72,6 +74,8 @@ def modal(self, context, event): elif self.key_no_modifiers: self.segments = max(3, self.segments - segment_factor) + self.dirty = True + elif self.key_confirm: self.finish(context) @@ -80,13 +84,16 @@ def modal(self, context, event): elif self.key_movement_passthrough: return {'PASS_THROUGH'} - self.operate(context) + if self.dirty: + self.operate(context) + update_overlay(self, context, event) return {'RUNNING_MODAL'} def invoke(self, context, event): + self.dirty = False self.base_inner_radius_factor = 0.001 self.base_width_factor = 0.001 @@ -102,6 +109,8 @@ def invoke(self, context, event): else: self.prepare_new_operator(context) + self.operate(context) + capture_modifier_keys(self) init_overlay(self, event) @@ -153,7 +162,6 @@ def poll(cls, context): def add_displace_modifier(self): displace = self.obj.modifiers.new(mod_displace, 'DISPLACE') displace.mid_level = 0.5 - displace.strength = self.inner_radius displace.direction = 'X' displace.space = 'LOCAL' @@ -164,7 +172,6 @@ def add_screw_x_modifier(self): screwX = self.obj.modifiers.new(mod_screw_1, 'SCREW') screwX.axis = 'X' screwX.angle = 0 - screwX.screw_offset = self.width screwX.steps = 1 screwX.render_steps = 1 screwX.use_merge_vertices = True @@ -176,8 +183,6 @@ def add_screw_x_modifier(self): def add_screw_z_modifer(self): screwZ = self.obj.modifiers.new(mod_screw_2, 'SCREW') screwZ.axis = 'Z' - screwZ.steps = self.segments - screwZ.render_steps = self.segments screwZ.use_merge_vertices = True screwZ.merge_threshold = 0.0001 screwZ.use_normal_calculate = True @@ -216,6 +221,8 @@ def operate(self, context): self.screwZ.render_steps = self.segments self.displace.strength = self.inner_radius + self.dirty = False + def select_recon_poly(self, context): bpy.ops.object.select_all(action='DESELECT') diff --git a/generators/screw_head.py b/generators/screw_head.py index a5927a5..99a8547 100644 --- a/generators/screw_head.py +++ b/generators/screw_head.py @@ -62,6 +62,8 @@ def modal(self, context, event): elif self.key_ctrl: self.scale += scale_factor + self.dirty = True + elif self.key_step_down: if self.key_no_modifiers: self.head_type_index = (self.head_type_index - 1) % len(self.objects) @@ -70,6 +72,8 @@ def modal(self, context, event): self.offset -= offset_factor elif self.key_ctrl: self.scale -= scale_factor + + self.dirty = True elif self.key_confirm: self.finish(context) @@ -79,13 +83,16 @@ def modal(self, context, event): elif self.key_movement_passthrough: return {'PASS_THROUGH'} - self.operate(context) + if self.dirty: + self.operate(context) + update_overlay(self, context, event) return {'RUNNING_MODAL'} def invoke(self, context, event): + self.dirty = False self.base_offset_factor = 0.01 self.base_scale_factor = 0.01 @@ -104,6 +111,8 @@ def invoke(self, context, event): self.update_head_type(context) + self.operate(context) + capture_modifier_keys(self) init_overlay(self, event) @@ -144,7 +153,6 @@ def update_head_type(self, context): def add_displace_modifier(self, context): displace = self.obj.modifiers.new(mod_displace, 'DISPLACE') - displace.strength = self.offset displace.direction = 'Z' displace.space = 'LOCAL' @@ -155,6 +163,8 @@ def operate(self, context): self.displace.strength = self.offset self.obj.scale = Vector((self.scale, self.scale, self.scale)) + self.dirty = False + def finish(self, context): objects_to_remove = [obj for obj in self.objects if obj.name != self.obj.name] diff --git a/power_mods/circular_array.py b/power_mods/circular_array.py index 213107d..983ce62 100644 --- a/power_mods/circular_array.py +++ b/power_mods/circular_array.py @@ -41,6 +41,8 @@ def modal(self, context, event): self.angle = min(360, self.angle + angle_factor) else: self.axis = (self.axis + 1) % 3 + + self.dirty = True elif self.key_step_down: if self.key_alt: @@ -49,6 +51,8 @@ def modal(self, context, event): self.angle = max(0, self.angle - angle_factor) else: self.axis = (self.axis - 1) % 3 + + self.dirty = True elif self.key_confirm: self.finish(context) @@ -57,14 +61,17 @@ def modal(self, context, event): elif self.key_movement_passthrough: return {'PASS_THROUGH'} + + if self.dirty: + self.operate(context) - self.operate(context) update_overlay(self, context, event) return {'RUNNING_MODAL'} def invoke(self, context, event): + self.dirty = False self.axis = 2 self.count = 2 self.angle = 360 @@ -75,6 +82,7 @@ def invoke(self, context, event): self.rotation_snapshot = self.rotator_obj.rotation_euler.copy() self.add_array_modifier() + self.operate(context) capture_modifier_keys(self) @@ -94,7 +102,6 @@ def poll(cls, context): def add_array_modifier(self): array = self.reference_obj.modifiers.new('Circular Array — ND', 'ARRAY') - array.count = self.count array.use_relative_offset = False array.use_object_offset = True array.offset_object = self.rotator_obj @@ -112,6 +119,8 @@ def operate(self, context): self.array.count = self.count + self.dirty = False + def select_reference_obj(self, context): bpy.ops.object.select_all(action='DESELECT') diff --git a/power_mods/mirror.py b/power_mods/mirror.py index c981bb3..ae7d579 100644 --- a/power_mods/mirror.py +++ b/power_mods/mirror.py @@ -36,12 +36,16 @@ def modal(self, context, event): self.flip = not self.flip else: self.axis = (self.axis + 1) % 3 + + self.dirty = True elif self.key_step_down: if self.key_alt: self.flip = not self.flip else: self.axis = (self.axis - 1) % 3 + + self.dirty = True elif self.key_confirm: self.finish(context) @@ -51,13 +55,16 @@ def modal(self, context, event): elif self.key_movement_passthrough: return {'PASS_THROUGH'} - self.operate(context) + if self.dirty: + self.operate(context) + update_overlay(self, context, event) return {'RUNNING_MODAL'} def invoke(self, context, event): + self.dirty = False self.axis = 0 self.flip = False self.reference_obj = context.active_object @@ -69,6 +76,7 @@ def invoke(self, context, event): self.mirror_obj = context.active_object self.add_mirror_modifier() + self.operate(context) capture_modifier_keys(self) @@ -91,12 +99,6 @@ def add_mirror_modifier(self): mirror.use_clip = True mirror.merge_threshold = 0.0001 - for i in range(3): - active = self.axis == i - mirror.use_axis[i] = active - mirror.use_bisect_axis[i] = active - mirror.use_bisect_flip_axis[i] = self.flip and active - if self.mirror_obj != None: mirror.mirror_object = self.mirror_obj @@ -110,6 +112,8 @@ def operate(self, context): self.mirror.use_bisect_axis[i] = active self.mirror.use_bisect_flip_axis[i] = self.flip and active + self.dirty = False + def select_reference_obj(self, context): bpy.ops.object.select_all(action='DESELECT') diff --git a/power_mods/profile_extrude.py b/power_mods/profile_extrude.py index 3018ed3..b1ed2c1 100644 --- a/power_mods/profile_extrude.py +++ b/power_mods/profile_extrude.py @@ -50,6 +50,8 @@ def modal(self, context, event): self.axis = (self.axis + 1) % 3 elif self.key_no_modifiers: self.extrusion_length += extrude_factor + + self.dirty = True elif self.key_step_down: if self.key_alt: @@ -58,6 +60,8 @@ def modal(self, context, event): self.axis = (self.axis - 1) % 3 elif self.key_no_modifiers: self.extrusion_length = max(0, self.extrusion_length - extrude_factor) + + self.dirty = True elif self.key_confirm: self.finish(context) @@ -67,13 +71,16 @@ def modal(self, context, event): elif self.key_movement_passthrough: return {'PASS_THROUGH'} - self.operate(context) + if self.dirty: + self.operate(context) + update_overlay(self, context, event) return {'RUNNING_MODAL'} def invoke(self, context, event): + self.dirty = False self.base_extrude_factor = 0.01 if len(context.selected_objects) == 1: @@ -88,6 +95,8 @@ def invoke(self, context, event): else: self.prepare_new_operator(context) + self.operate(context) + capture_modifier_keys(self) init_overlay(self, event) @@ -147,16 +156,12 @@ def add_offset_modifier(self, context): offset = context.object.modifiers.new(mod_offset, 'DISPLACE') offset.space = 'LOCAL' offset.mid_level = 0.5 - offset.direction = ['X', 'Y', 'Z'][self.axis] - offset.strength = self.calculate_offset_strength() self.offset = offset def add_screw_modifier(self, context): screw = context.object.modifiers.new(mod_screw, 'SCREW') - screw.axis = ['X', 'Y', 'Z'][self.axis] - screw.screw_offset = self.extrusion_length screw.steps = 0 screw.render_steps = 0 screw.angle = 0 @@ -173,6 +178,8 @@ def operate(self, context): self.offset.direction = axis self.offset.strength = self.calculate_offset_strength() + self.dirty = False + def finish(self, context): unregister_draw_handler() @@ -218,8 +225,6 @@ def draw_text_callback(self): active=self.key_ctrl, alt_mode=False) - - def menu_func(self, context): self.layout.operator(ND_OT_profile_extrude.bl_idname, text=ND_OT_profile_extrude.bl_label) diff --git a/power_mods/screw.py b/power_mods/screw.py index 992bff9..19cd7d9 100644 --- a/power_mods/screw.py +++ b/power_mods/screw.py @@ -60,6 +60,8 @@ def modal(self, context, event): self.angle = min(360, self.angle + angle_factor) else: self.segments = 4 if self.segments == 3 else self.segments + segment_factor + + self.dirty = True elif self.key_step_down: if self.key_ctrl_alt: @@ -73,6 +75,8 @@ def modal(self, context, event): self.angle = max(0, self.angle - angle_factor) else: self.segments = max(3, self.segments - segment_factor) + + self.dirty = True elif self.key_confirm: self.finish(context) @@ -82,13 +86,16 @@ def modal(self, context, event): elif self.key_movement_passthrough: return {'PASS_THROUGH'} - self.operate(context) + if self.dirty: + self.operate(context) + update_overlay(self, context, event) return {'RUNNING_MODAL'} def invoke(self, context, event): + self.dirty = False self.base_offset_factor = 0.01 if len(context.selected_objects) == 1: @@ -103,6 +110,8 @@ def invoke(self, context, event): else: self.prepare_new_operator(context) + self.operate(context) + capture_modifier_keys(self) init_overlay(self, event) @@ -156,20 +165,14 @@ def add_smooth_shading(self, context): def add_displace_modifier(self, context): displace = context.object.modifiers.new(mod_displace, 'DISPLACE') displace.mid_level = 0.5 - displace.strength = self.offset displace.space = 'LOCAL' - displace.direction = ['X', 'Y', 'Z'][self.offset_axis] self.displace = displace def add_screw_modifier(self, context): screw = context.object.modifiers.new(mod_screw, 'SCREW') - screw.angle = radians(self.angle) screw.screw_offset = 0 - screw.axis = ['X', 'Y', 'Z'][self.screw_axis] - screw.steps = self.segments - screw.render_steps = self.segments screw.use_merge_vertices = True screw.merge_threshold = 0.0001 screw.use_normal_calculate = True @@ -185,6 +188,8 @@ def operate(self, context): self.screw.render_steps = self.segments self.screw.angle = radians(self.angle) + self.dirty = False + def finish(self, context): unregister_draw_handler() diff --git a/power_mods/solidify.py b/power_mods/solidify.py index 73a3781..f892745 100644 --- a/power_mods/solidify.py +++ b/power_mods/solidify.py @@ -58,6 +58,8 @@ def modal(self, context, event): self.offset += offset_factor elif self.key_no_modifiers: self.thickness += thickness_factor + + self.dirty = True elif self.key_step_down: if self.key_alt: @@ -66,6 +68,8 @@ def modal(self, context, event): self.offset -= offset_factor elif self.key_no_modifiers: self.thickness = max(0, self.thickness - thickness_factor) + + self.dirty = True elif self.key_confirm: self.finish(context) @@ -75,13 +79,16 @@ def modal(self, context, event): elif self.key_movement_passthrough: return {'PASS_THROUGH'} - self.operate(context) + if self.dirty: + self.operate(context) + update_overlay(self, context, event) return {'RUNNING_MODAL'} def invoke(self, context, event): + self.dirty = False self.base_thickness_factor = 0.01 self.base_offset_factor = 0.001 @@ -97,6 +104,8 @@ def invoke(self, context, event): else: self.prepare_new_operator(context) + self.operate(context) + capture_modifier_keys(self) init_overlay(self, event) @@ -144,15 +153,12 @@ def add_smooth_shading(self, context): def add_displace_modifier(self, context): displace = context.object.modifiers.new(mod_displace, 'DISPLACE') - displace.strength = self.offset self.displace = displace def add_solidify_modifier(self, context): solidify = context.object.modifiers.new(mod_solidify, 'SOLIDIFY') - solidify.thickness = self.thickness - solidify.offset = self.weighting solidify.use_even_offset = True self.solidify = solidify @@ -163,6 +169,8 @@ def operate(self, context): self.solidify.offset = self.weighting self.displace.strength = self.offset + self.dirty = False + def finish(self, context): unregister_draw_handler() diff --git a/power_mods/vertex_bevel.py b/power_mods/vertex_bevel.py index d4d72dd..9c8fdf3 100644 --- a/power_mods/vertex_bevel.py +++ b/power_mods/vertex_bevel.py @@ -58,6 +58,8 @@ def modal(self, context, event): self.profile = min(1, self.profile + profile_factor) elif self.key_no_modifiers: self.segments = 2 if self.segments == 1 else self.segments + segment_factor + + self.dirty = True elif self.key_step_down: if self.key_alt: @@ -67,6 +69,8 @@ def modal(self, context, event): elif self.key_no_modifiers: self.segments = max(1, self.segments - segment_factor) + self.dirty = True + elif self.key_confirm: self.finish(context) @@ -75,13 +79,16 @@ def modal(self, context, event): elif self.key_movement_passthrough: return {'PASS_THROUGH'} - self.operate(context) + if self.dirty: + self.operate(context) + update_overlay(self, context, event) return {'RUNNING_MODAL'} def invoke(self, context, event): + self.dirty = False self.base_width_factor = 0.01 self.base_profile_factor = 0.1 @@ -92,6 +99,8 @@ def invoke(self, context, event): self.add_vertex_group(context) self.add_bevel_modifier(context) + self.operate(context) + capture_modifier_keys(self) init_overlay(self, event) @@ -122,9 +131,6 @@ def add_bevel_modifier(self, context): bevel.limit_method = 'VGROUP' bevel.offset_type = 'WIDTH' bevel.vertex_group = self.vgroup.name - bevel.segments = self.segments - bevel.width = self.width - bevel.profile = self.profile self.bevel = bevel @@ -152,6 +158,8 @@ def operate(self, context): self.bevel.segments = self.segments self.bevel.profile = self.profile + self.dirty = False + def finish(self, context): self.add_weld_modifier(context) diff --git a/power_mods/weighted_normal_bevel.py b/power_mods/weighted_normal_bevel.py index 982722e..9fdb238 100644 --- a/power_mods/weighted_normal_bevel.py +++ b/power_mods/weighted_normal_bevel.py @@ -46,9 +46,13 @@ def modal(self, context, event): elif self.key_step_up: self.width += width_factor + + self.dirty = True elif self.key_step_down: self.width = max(0.0001, self.width - width_factor) + + self.dirty = True elif self.key_confirm: self.finish(context) @@ -58,13 +62,16 @@ def modal(self, context, event): elif self.key_movement_passthrough: return {'PASS_THROUGH'} - self.operate(context) + if self.dirty: + self.operate(context) + update_overlay(self, context, event) return {'RUNNING_MODAL'} def invoke(self, context, event): + self.dirty = False self.base_width_factor = 0.001 if len(context.selected_objects) == 1: @@ -79,6 +86,8 @@ def invoke(self, context, event): else: self.prepare_new_operator(context) + self.operate(context) + capture_modifier_keys(self) init_overlay(self, event) @@ -124,7 +133,6 @@ def add_bevel_modifier(self, context): bevel = context.object.modifiers.new(mod_bevel, 'BEVEL') bevel.segments = 1 bevel.offset_type = 'WIDTH' - bevel.width = self.width self.bevel = bevel @@ -139,6 +147,8 @@ def add_weighted_normal_modifer(self, context): def operate(self, context): self.bevel.width = self.width + self.dirty = False + def finish(self, context): unregister_draw_handler() diff --git a/utils/seams.py b/utils/seams.py index 3df86de..b45ce76 100644 --- a/utils/seams.py +++ b/utils/seams.py @@ -38,12 +38,16 @@ def modal(self, context, event): self.commit_auto_smooth = not self.commit_auto_smooth else: self.angle = min(180, self.angle + angle_factor) + + self.dirty = True elif self.key_step_down: if self.key_alt: self.commit_auto_smooth = not self.commit_auto_smooth else: self.angle = max(0, self.angle - angle_factor) + + self.dirty = True elif self.key_confirm: self.finish(context) @@ -53,13 +57,16 @@ def modal(self, context, event): elif self.key_movement_passthrough: return {'PASS_THROUGH'} - self.operate(context) + if self.dirty: + self.operate(context) + update_overlay(self, context, event) return {'RUNNING_MODAL'} def invoke(self, context, event): + self.dirty = False self.base_angle_factor = 15 self.angle = degrees(context.object.data.auto_smooth_angle) self.commit_auto_smooth = False @@ -67,6 +74,8 @@ def invoke(self, context, event): bpy.ops.object.mode_set_with_submode(mode='EDIT', mesh_select_mode={'EDGE'}) bpy.ops.mesh.select_all(action='DESELECT') + self.operate(context) + capture_modifier_keys(self) init_overlay(self, event) @@ -84,8 +93,6 @@ def poll(cls, context): def operate(self, context): - print('fuck it') - self.clear_edges(context) bpy.ops.mesh.edges_select_sharp(sharpness=radians(self.angle)) @@ -95,6 +102,8 @@ def operate(self, context): bpy.ops.mesh.select_all(action='DESELECT') + self.dirty = False + def clear_edges(self, context): bpy.ops.mesh.select_all(action='SELECT') diff --git a/utils/smooth.py b/utils/smooth.py index f34b427..f2548c4 100644 --- a/utils/smooth.py +++ b/utils/smooth.py @@ -35,9 +35,13 @@ def modal(self, context, event): elif self.key_step_up: self.angle = min(180, self.angle + angle_factor) + + self.dirty = True elif self.key_step_down: self.angle = max(0, self.angle - angle_factor) + + self.dirty = True elif self.key_confirm: self.finish(context) @@ -47,18 +51,23 @@ def modal(self, context, event): elif self.key_movement_passthrough: return {'PASS_THROUGH'} - self.operate(context) + if self.dirty: + self.operate(context) + update_overlay(self, context, event) return {'RUNNING_MODAL'} def invoke(self, context, event): + self.dirty = False self.base_angle_factor = 15 self.angle = 30 self.add_smooth_shading(context) + self.operate(context) + capture_modifier_keys(self) init_overlay(self, event) @@ -78,12 +87,13 @@ def poll(cls, context): 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(self.angle) def operate(self, context): context.object.data.auto_smooth_angle = radians(self.angle) + self.dirty = False + def finish(self, context): unregister_draw_handler()