Skip to content

Commit

Permalink
feat: automatically move booleans under WN bevels and single segment …
Browse files Browse the repository at this point in the history
…HN bevels
  • Loading branch information
tristan-hm committed May 20, 2022
1 parent 624a0c0 commit 1170f08
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
5 changes: 5 additions & 0 deletions booleans/boolean_inset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions booleans/boolean_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions booleans/vanilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from . import updates
from . import preferences
from . import collections
from . import bools
from . import numeric_input
from . import overlay_keys

Expand All @@ -35,6 +36,7 @@
updates,
preferences,
collections,
bools,
numeric_input,
overlay_keys
)
Expand Down
40 changes: 40 additions & 0 deletions lib/bools.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 1170f08

Please sign in to comment.