Skip to content

Commit

Permalink
fix: ensure operate is only executed on interactive option mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
tristan-hm committed Apr 4, 2022
1 parent 8d6d20e commit 8fa29fc
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 45 deletions.
17 changes: 12 additions & 5 deletions generators/recon_poly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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'

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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')
Expand Down
14 changes: 12 additions & 2 deletions generators/screw_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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'

Expand All @@ -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]
Expand Down
13 changes: 11 additions & 2 deletions power_mods/circular_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)

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

Expand All @@ -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

Expand All @@ -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')
Expand Down
19 changes: 12 additions & 7 deletions power_mods/profile_extrude.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 8fa29fc

Please sign in to comment.