Skip to content

Commit

Permalink
feat: add outset mode to bool_inset operator
Browse files Browse the repository at this point in the history
  • Loading branch information
tristan-hm committed Apr 24, 2022
1 parent 3f29af5 commit cc8edd7
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions booleans/boolean_inset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class ND_OT_bool_inset(bpy.types.Operator):
bl_idname = "nd.bool_inset"
bl_label = "Inset"
bl_label = "Inset/Outset"
bl_description = "Perform a boolean operation on the selected objects"
bl_options = {'UNDO'}

Expand Down Expand Up @@ -46,12 +46,16 @@ def modal(self, context, event):
elif self.key_step_up:
if self.key_no_modifiers:
self.thickness += thickness_factor
elif self.key_alt:
self.outset = not self.outset

self.dirty = True

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

self.dirty = True

Expand Down Expand Up @@ -82,21 +86,22 @@ def invoke(self, context, event):
self.base_thickness_factor = 0.01

self.thickness = 0.02
self.outset = False

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

a, b = context.selected_objects
self.reference_obj = a if a.name != context.object.name else b

self.difference_obj = context.object
self.target_obj = context.object

self.intersecting_obj = context.object.copy()
self.intersecting_obj.data = context.object.data.copy()
self.intersecting_obj.animation_data_clear()
context.collection.objects.link(self.intersecting_obj)

self.boolean_diff = self.difference_obj.modifiers.new("Difference — ND Bool", 'BOOLEAN')
self.boolean_diff.operation = 'DIFFERENCE'
self.boolean_diff = self.target_obj.modifiers.new("Inset/Outset — ND Bool", 'BOOLEAN')
self.boolean_diff.operation = 'UNION' if self.outset else 'DIFFERENCE'
self.boolean_diff.object = self.intersecting_obj
self.boolean_diff.solver = solver

Expand Down Expand Up @@ -124,11 +129,13 @@ def invoke(self, context, event):
self.intersecting_obj.name = " — ".join(['Bool', self.intersecting_obj.name])
self.intersecting_obj.data.name = self.intersecting_obj.name

self.reference_obj.parent = self.difference_obj
self.intersecting_obj.parent = self.difference_obj
self.reference_obj.parent = self.target_obj
self.intersecting_obj.parent = self.target_obj

self.reference_obj.matrix_parent_inverse = self.difference_obj.matrix_world.inverted()
self.intersecting_obj.matrix_parent_inverse = self.difference_obj.matrix_world.inverted()
self.reference_obj.matrix_parent_inverse = self.target_obj.matrix_world.inverted()
self.intersecting_obj.matrix_parent_inverse = self.target_obj.matrix_world.inverted()

bpy.ops.object.select_all(action='DESELECT')

self.operate(context)

Expand All @@ -150,6 +157,7 @@ def poll(cls, context):

def operate(self, context):
self.solidify.thickness = self.thickness
self.boolean_diff.operation = 'UNION' if self.outset else 'DIFFERENCE'

self.dirty = False

Expand Down Expand Up @@ -177,6 +185,7 @@ def revert(self, context):
self.reference_obj.name = self.reference_obj_name_prev
self.reference_obj.data.name = self.reference_obj_name_prev
self.reference_obj.parent = None
self.reference_obj.hide_set(False)

unregister_draw_handler()

Expand All @@ -192,6 +201,13 @@ def draw_text_callback(self):
alt_mode=self.key_shift_no_modifiers,
mouse_value=True)

draw_property(
self,
"Mode: {0}".format('Outset' if self.outset else 'Inset'),
"(Inset, Outset)",
active=self.key_alt,
alt_mode=False)


def menu_func(self, context):
self.layout.operator(ND_OT_bool_inset.bl_idname, text=ND_OT_bool_inset.bl_label)
Expand Down

0 comments on commit cc8edd7

Please sign in to comment.