Skip to content

Commit

Permalink
feat: add the 3 core boolean operators, difference, union, and intersect
Browse files Browse the repository at this point in the history
  • Loading branch information
tristan-hm committed Mar 29, 2022
1 parent 53d7604 commit ca58b0b
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
2 changes: 2 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from bpy.types import AddonPreferences
from bpy.props import BoolProperty
from . import lib
from . import booleans
from . import interface
from . import sketching
from . import power_mods
Expand All @@ -23,6 +24,7 @@


registerables = (
booleans,
interface,
sketching,
power_mods,
Expand Down
14 changes: 14 additions & 0 deletions booleans/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import importlib
from . import vanilla


def reload():
importlib.reload(vanilla)


def register():
vanilla.register()


def unregister():
vanilla.unregister()
50 changes: 50 additions & 0 deletions booleans/vanilla.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import bpy


class ND_OT_bool_vanilla(bpy.types.Operator):
bl_idname = "nd.bool_vanilla"
bl_label = "Boolean"
bl_description = "Perform a boolean operation on the selected objects"
bl_options = {'UNDO'}


mode: bpy.props.EnumProperty(items=[
('DIFFERENCE', 'Difference', 'Perform a difference operation'),
('UNION', 'Union', 'Perform a union operation'),
('INTERSECT', 'Intersect', 'Perform an intersect operation'),
], name="Mode", default='DIFFERENCE')


@classmethod
def poll(cls, context):
if context.mode == 'OBJECT':
return len(context.selected_objects) == 2


def execute(self, context):
a, b = context.selected_objects
reference_obj = a if a.name != context.object.name else b

boolean = context.object.modifiers.new(" — ".join([self.mode.capitalize(), "ND Bool"]), 'BOOLEAN')
boolean.operation = self.mode
boolean.object = reference_obj
boolean.solver = 'EXACT'

reference_obj.display_type = 'WIRE'
reference_obj.hide_render = True

return {'FINISHED'}


def menu_func(self, context):
self.layout.operator(ND_OT_bool_vanilla.bl_idname, text=ND_OT_bool_vanilla.bl_label)


def register():
bpy.utils.register_class(ND_OT_bool_vanilla)
bpy.types.VIEW3D_MT_object.append(menu_func)


def unregister():
bpy.utils.unregister_class(ND_OT_bool_vanilla)
bpy.types.VIEW3D_MT_object.remove(menu_func)
3 changes: 3 additions & 0 deletions interface/main_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def draw(self, context):
layout.operator("nd.blank_sketch", icon='GREASEPENCIL')
layout.operator("nd.vertex_bevel", icon='MOD_BEVEL')
layout.separator()
layout.operator("nd.bool_vanilla", text="Difference", icon='MOD_BOOLEAN').mode = 'DIFFERENCE'
layout.operator("nd.bool_vanilla", text="Union", icon='MOD_BOOLEAN').mode = 'UNION'
layout.operator("nd.bool_vanilla", text="Intersect", icon='MOD_BOOLEAN').mode = 'INTERSECT'
layout.operator("nd.weighted_normal_bevel", icon='MOD_BEVEL')
layout.operator("nd.solidify", icon='MOD_SOLIDIFY')
layout.operator("nd.screw", icon='MOD_SCREW')
Expand Down
12 changes: 12 additions & 0 deletions interface/main_ui_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ def draw(self, context):
box.label(text="Power Mods", icon='MODIFIER')
column = box.column()

row = column.row(align=True)
row.scale_y = 1.2
row.operator("nd.bool_vanilla", text="Difference", icon='MOD_BOOLEAN').mode = 'DIFFERENCE'

row = column.row(align=True)
row.scale_y = 1.2
row.operator("nd.bool_vanilla", text="Union", icon='MOD_BOOLEAN').mode = 'UNION'

row = column.row(align=True)
row.scale_y = 1.2
row.operator("nd.bool_vanilla", text="Intersect", icon='MOD_BOOLEAN').mode = 'INTERSECT'

row = column.row(align=True)
row.scale_y = 1.2
row.operator("nd.weighted_normal_bevel", icon='MOD_BEVEL')
Expand Down

0 comments on commit ca58b0b

Please sign in to comment.