diff --git a/booleans/boolean_inset.py b/booleans/boolean_inset.py index 6dc1151..4482516 100644 --- a/booleans/boolean_inset.py +++ b/booleans/boolean_inset.py @@ -15,6 +15,7 @@ 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 +from .. lib.bools import move_bool_under_bevels, remove_problematic_bevels class ND_OT_bool_inset(bpy.types.Operator): @@ -126,6 +127,8 @@ def invoke(self, context, event): self.boolean_diff.object = self.intersecting_obj self.boolean_diff.solver = solver + move_bool_under_bevels(self.target_obj, self.boolean_diff.name) + self.solidify = self.intersecting_obj.modifiers.new("Thickness — ND Bool", 'SOLIDIFY') self.solidify.use_even_offset = True self.solidify.offset = 0 @@ -135,6 +138,8 @@ def invoke(self, context, event): self.boolean_isect.object = self.reference_obj self.boolean_isect.solver = solver + remove_problematic_bevels(self.intersecting_obj) + self.reference_obj_display_type_prev = self.reference_obj.display_type self.reference_obj_hide_render_prev = self.reference_obj.hide_render self.reference_obj_name_prev = self.reference_obj.name diff --git a/booleans/boolean_slice.py b/booleans/boolean_slice.py index 0b5fe4d..1176e8d 100644 --- a/booleans/boolean_slice.py +++ b/booleans/boolean_slice.py @@ -10,6 +10,7 @@ import bpy from .. lib.collections import move_to_utils_collection, isolate_in_utils_collection from .. lib.preferences import get_preferences +from .. lib.bools import move_bool_under_bevels class ND_OT_bool_slice(bpy.types.Operator): @@ -43,10 +44,14 @@ def execute(self, context): boolean_diff.object = reference_obj boolean_diff.solver = solver + move_bool_under_bevels(difference_obj, boolean_diff.name) + boolean_isect = intersecting_obj.modifiers.new("Intersection — ND Bool", 'BOOLEAN') boolean_isect.operation = 'INTERSECT' boolean_isect.object = reference_obj boolean_isect.solver = solver + + move_bool_under_bevels(intersecting_obj, boolean_isect.name) reference_obj.display_type = 'WIRE' reference_obj.hide_render = True diff --git a/booleans/vanilla.py b/booleans/vanilla.py index caa6c02..d33e74f 100644 --- a/booleans/vanilla.py +++ b/booleans/vanilla.py @@ -10,6 +10,7 @@ import bpy from .. lib.collections import move_to_utils_collection, isolate_in_utils_collection from .. lib.preferences import get_preferences +from .. lib.bools import move_bool_under_bevels class ND_OT_bool_vanilla(bpy.types.Operator): @@ -44,6 +45,8 @@ def execute(self, context): boolean.object = reference_obj boolean.solver = solver + move_bool_under_bevels(context.object, boolean.name) + if not self.protect_reference_obj: reference_obj.display_type = 'WIRE' reference_obj.hide_render = True diff --git a/lib/__init__.py b/lib/__init__.py index b305809..9efb88b 100644 --- a/lib/__init__.py +++ b/lib/__init__.py @@ -19,6 +19,7 @@ from . import updates from . import preferences from . import collections +from . import bools from . import numeric_input from . import overlay_keys @@ -35,6 +36,7 @@ updates, preferences, collections, + bools, numeric_input, overlay_keys ) diff --git a/lib/bools.py b/lib/bools.py new file mode 100644 index 0000000..914fd0c --- /dev/null +++ b/lib/bools.py @@ -0,0 +1,40 @@ +# “Commons Clause” License Condition v1.0 +# +# See LICENSE for license details. If you did not receive a copy of the license, +# it may be obtained at https://github.com/hugemenace/nd/blob/main/LICENSE. +# +# Software: ND Blender Addon +# License: MIT +# Licensor: T.S. & I.J. (HugeMenace) + +import bpy + + +def move_bool_under_bevels(object, bool_name): + mods = [mod for mod in object.modifiers] + if len(mods) >= 3: + second_last = len(mods) - 2 + third_last = len(mods) - 3 + if "— ND WNB" in mods[second_last].name and "— ND WNB" in mods[third_last].name: + bpy.ops.object.modifier_move_up({'object': object}, modifier=bool_name) + bpy.ops.object.modifier_move_up({'object': object}, modifier=bool_name) + elif mods[second_last].type == 'BEVEL' and mods[second_last].segments == 1 and mods[second_last].harden_normals: + bpy.ops.object.modifier_move_up({'object': object}, modifier=bool_name) + bpy.ops.object.modifier_move_up({'object': object}, modifier=bool_name) + elif mods[third_last].type == 'BEVEL' and mods[third_last].segments == 1 and mods[third_last].harden_normals: + bpy.ops.object.modifier_move_up({'object': object}, modifier=bool_name) + bpy.ops.object.modifier_move_up({'object': object}, modifier=bool_name) + + +def remove_problematic_bevels(object): + mods = [mod for mod in object.modifiers] + remove_mods = [] + + for mod in mods: + if mod.type == 'BEVEL' and mod.segments == 1 and mod.harden_normals: + remove_mods.append(mod) + elif "— ND WNB" in mod.name: + remove_mods.append(mod) + + for mod in remove_mods: + object.modifiers.remove(mod)