-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathoverlap_control.py
78 lines (66 loc) · 2.01 KB
/
overlap_control.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
import mathutils
import io
import os
import sys
file_dir = os.path.dirname(__file__)
sys.path.append(file_dir)
stdout = io.StringIO()
from blender_utils import *
from iou import Intersection
class OverlapController:
def __init__(self):
self.name = 'v0'
def make(self, m1, m2):
"""
Function that checks whether two objects overlap
:param m1: object to check the overlap of, mesh
:param m2: object to check the overlap of, mesh
:return: result, bool
"""
return self._make(m1, m2)
def _make(self, m1, m2):
"""
Function that checks whether two objects overlap
:param m1: object to check the overlap of, mesh
:param m2: object to check the overlap of, mesh
:return: result, bool
"""
# length = (m1.matrix_world.to_translation() - m2.matrix_world.to_translation()).length
length = (m1.location - m2.location).length
if length < 1.5:
# _result = intersection_check(m1, m2)
# if len(_result) > 0:
return True
_result = intersection_check(m1, m2)
if len(_result) > 0:
return True
class OverlapVolumeController:
def __init__(self):
self.controller = OverlapController()
def make(self, module):
return self._make(module)
def _make(self, module):
_children = []
for sub in [x.name for x in bpy.data.collections[module.volume.name].children]:
if module.name not in sub and sub not in module.name:
_children += bpy.data.collections[sub].objects
for _child in _children: # mesh
result = self.controller.make(module.mesh, _child)
if result:
deselect_all()
_child.select_set(True)
# with redirect_stdout(stdout), redirect_stderr(stdout):
bpy.ops.object.delete()
class OverlapOtherVolumeController:
def __init__(self):
self.controller = OverlapController()
def make(self, module):
return self._make(module)
def _make(self, module):
_volumes = [x for x in bpy.data.objects if 'volume' in x.name]
for v in _volumes: # mesh
if v.name != module.volume.mesh.name:
result = self.controller.make(module.mesh, v)
if result:
module.remove()