-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathfc_bool_op.py
119 lines (88 loc) · 3.44 KB
/
fc_bool_op.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import bpy
from bpy.types import Operator
from .utils.fc_bool_util import execute_boolean_op, execute_slice_op, select_active
def check_cutter_selected(context):
result = len(context.selected_objects) > 0
result = result and not bpy.context.scene.carver_target is None
result = result and not (bpy.context.scene.carver_target == context.view_layer.objects.active)
return result
# Difference operator
class FC_BoolOperator_Diff(Operator):
bl_idname = "object.bool_diff"
bl_label = "Bool difference"
bl_description = "Difference for 2 selected objects"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return check_cutter_selected(context)
def execute(self, context):
try:
target_obj = bpy.context.scene.carver_target
current_mode = context.object.mode
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
execute_boolean_op(context, target_obj, 0)
select_active(target_obj)
bpy.ops.object.mode_set(mode=current_mode, toggle=False)
except RuntimeError:
pass
return {'FINISHED'}
class FC_BoolOperator_Union(Operator):
bl_idname = "object.bool_union"
bl_label = "Bool union"
bl_description = "Union for 2 selected objects"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return check_cutter_selected(context)
def execute(self, context):
try:
target_obj = bpy.context.scene.carver_target
current_mode = context.object.mode
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
execute_boolean_op(context, target_obj, 1)
select_active(target_obj)
bpy.ops.object.mode_set(mode=current_mode, toggle=False)
except RuntimeError:
pass
return {'FINISHED'}
class FC_BoolOperator_Intersect(Operator):
bl_idname = "object.bool_intersect"
bl_label = "Bool intersect"
bl_description = "Intersect for 2 selected objects"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return check_cutter_selected(context)
def execute(self, context):
try:
target_obj = bpy.context.scene.carver_target
execute_boolean_op(context, target_obj, 2)
except RuntimeError:
pass
return {'FINISHED'}
class FC_BoolOperator_Slice(Operator):
bl_idname = "object.bool_slice"
bl_label = "Bool slice"
bl_description = "Slice for 2 selected objects"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return check_cutter_selected(context)
def execute(self, context):
try:
target_obj = bpy.context.scene.carver_target
execute_slice_op(context, target_obj)
except RuntimeError:
pass
return {'FINISHED'}
class FC_TargetSelectOperator(Operator):
bl_idname = "object.bool_target"
bl_label = "Selected as Target"
bl_description = "Set selected to target"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return len(context.selected_objects) > 0
def execute(self, context):
bpy.context.scene.carver_target = context.view_layer.objects.active
return {'FINISHED'}