-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathfc_bool_util.py
78 lines (53 loc) · 2.07 KB
/
fc_bool_util.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
import bpy
from bpy.props import *
def select_active(obj):
bpy.ops.object.select_all(action='DESELECT')
obj.select = True
bpy.context.scene.objects.active = obj
def is_apply_immediate():
return (bpy.context.scene.apply_bool == True)
def bool_mod_and_apply(obj, bool_method):
active_obj = bpy.context.scene.objects.active
bool_mod = active_obj.modifiers.new(type="BOOLEAN", name="FC_BOOL")
method = 'DIFFERENCE'
if bool_method == 1:
method = 'UNION'
elif bool_method == 2:
method = 'INTERSECT'
bool_mod.operation = method
#bool_mod.solver = 'CARVE'
bool_mod.object = obj
if is_apply_immediate() == True:
bpy.ops.object.modifier_apply(modifier=bool_mod.name)
else:
if bool_method == 0 or bool_method == 2:
obj.draw_type = 'WIRE'
def execute_slice_op(context, target_obj):
# store active object
current_obj = context.object
bpy.ops.object.transform_apply(scale=True)
# clone target
clone_target = target_obj.copy()
context.scene.objects.link(clone_target)
# Intersect for clone
select_active(clone_target)
bpy.ops.object.make_single_user(object=True, obdata=True)
bool_mod_and_apply(current_obj, 2)
# Difference for target
select_active(target_obj)
bpy.ops.object.make_single_user(object=False, obdata=True)
bool_mod_and_apply(current_obj, 0)
select_active(current_obj)
def execute_boolean_op(context, target_obj, bool_method = 0):
'''
function for bool operation
@target_obj : target object of the bool operation
@bool_method : 0 = difference, 1 = union, 2 = intersect
'''
# store active object
current_obj = context.object
bpy.ops.object.transform_apply(scale=True)
# make target the active object
select_active(target_obj)
bool_mod_and_apply(current_obj, bool_method)
select_active(current_obj)