-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.py
204 lines (186 loc) · 7.72 KB
/
database.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import bpy
from mathutils import *
from . import utils
def is_overlapping(point1: Vector, point2: Vector, direction: str, threshold=0.001) -> bool:
point1 = point1.copy()
point2 = point2.copy()
if direction == 'x':
point1.x = 0
point2.x = 0
elif direction == 'y':
point1.y = 0
point2.y = 0
elif direction == 'z':
point1.z = 0
point2.z = 0
distance = (point1 - point2).length
if distance <= threshold:
# print(f'{point1.x},{point1.y},{point1.z} overlapping with {point2.x},{point2.y},{point2.z}')
return True
else:
return False
# check if the vertices of an object can be connected to another object
def is_mesh_compatible(object1: object, object2: object, direction: str, threshold=0.001) -> bool:
object1Vertices = []
object2Vertices = []
if direction == 'x+':
for verts in object1.data.vertices:
if verts.co.x == 1:
object1Vertices.append(verts.co)
for verts in object2.data.vertices:
if verts.co.x == -1:
object2Vertices.append(verts.co)
if len(object1Vertices) != len(object2Vertices):
return False
elif len(object1Vertices) == 0 and len(object2Vertices) == 0:
return True
overlappingVerts = 0
for source in object1Vertices:
for target in object2Vertices:
if is_overlapping(source, target, 'x'):
overlappingVerts += 1
if overlappingVerts == len(object1Vertices) == len(object2Vertices):
return True
else:
return False
elif direction == 'x-':
for verts in object1.data.vertices:
if verts.co.x == -1:
object1Vertices.append(verts.co)
for verts in object2.data.vertices:
if verts.co.x == 1:
object2Vertices.append(verts.co)
if len(object1Vertices) != len(object2Vertices):
return False
elif len(object1Vertices) == 0 and len(object2Vertices) == 0:
return True
overlappingVerts = 0
for source in object1Vertices:
for target in object2Vertices:
if is_overlapping(source, target, 'x'):
overlappingVerts += 1
if overlappingVerts == len(object1Vertices) == len(object2Vertices):
return True
else:
return False
elif direction == 'y+':
for verts in object1.data.vertices:
if verts.co.y == 1:
object1Vertices.append(verts.co)
for verts in object2.data.vertices:
if verts.co.y == -1:
object2Vertices.append(verts.co)
if len(object1Vertices) != len(object2Vertices):
return False
elif len(object1Vertices) == 0 and len(object2Vertices) == 0:
return True
overlappingVerts = 0
for source in object1Vertices:
for target in object2Vertices:
if is_overlapping(source, target, 'y'):
overlappingVerts += 1
if overlappingVerts == len(object1Vertices) == len(object2Vertices):
return True
else:
return False
elif direction == 'y-':
for verts in object1.data.vertices:
if verts.co.y == -1:
object1Vertices.append(verts.co)
for verts in object2.data.vertices:
if verts.co.y == 1:
object2Vertices.append(verts.co)
if len(object1Vertices) != len(object2Vertices):
return False
elif len(object1Vertices) == 0 and len(object2Vertices) == 0:
return True
overlappingVerts = 0
for source in object1Vertices:
for target in object2Vertices:
if is_overlapping(source, target, 'y'):
overlappingVerts += 1
if overlappingVerts == len(object1Vertices) == len(object2Vertices):
return True
else:
return False
elif direction == 'z+':
for verts in object1.data.vertices:
if verts.co.z == 1:
object1Vertices.append(verts.co)
for verts in object2.data.vertices:
if verts.co.z == -1:
object2Vertices.append(verts.co)
if len(object1Vertices) != len(object2Vertices):
return False
elif len(object1Vertices) == 0 and len(object2Vertices) == 0:
return True
overlappingVerts = 0
for source in object1Vertices:
for target in object2Vertices:
if is_overlapping(source, target, 'z'):
overlappingVerts += 1
if overlappingVerts == len(object1Vertices) == len(object2Vertices):
return True
else:
return False
elif direction == 'z-':
for verts in object1.data.vertices:
if verts.co.z == -1:
object1Vertices.append(verts.co)
for verts in object2.data.vertices:
if verts.co.z == 1:
object2Vertices.append(verts.co)
if len(object1Vertices) != len(object2Vertices):
return False
elif len(object1Vertices) == 0 and len(object2Vertices) == 0:
return True
overlappingVerts = 0
for source in object1Vertices:
for target in object2Vertices:
if is_overlapping(source, target, 'z'):
overlappingVerts += 1
if overlappingVerts == len(object1Vertices) == len(object2Vertices):
return True
else:
return False
else:
print("An error occurred during mesh compatibility checking")
return False
class databaseMaker:
def __init__(self):
pass
def create_database(self, threshold=0.001):
database = {}
for object in bpy.context.selected_objects:
if object.type == 'MESH':
object.wfc_object.tile_type = 'DBTILE'
database[object.name] = {}
database[object.name]['x+'] = []
database[object.name]['x-'] = []
database[object.name]['y+'] = []
database[object.name]['y-'] = []
database[object.name]['z+'] = []
database[object.name]['z-'] = []
for target in bpy.context.selected_objects:
if target.type == 'MESH':
#print(f'Source : {object.name} | Destination : {target.name}')
if is_mesh_compatible(object, target, 'x+', threshold):
#print(f'{color.BOLD}{color.GREEN}{object.name} compatible on the X+ with {target.name}{color.END}')
database[object.name]['x+'].append(target.name)
if is_mesh_compatible(object, target, 'x-', threshold):
database[object.name]['x-'].append(target.name)
if is_mesh_compatible(object, target, 'y+', threshold):
database[object.name]['y+'].append(target.name)
if is_mesh_compatible(object, target, 'y-', threshold):
database[object.name]['y-'].append(target.name)
if is_mesh_compatible(object, target, 'z+', threshold):
database[object.name]['z+'].append(target.name)
if is_mesh_compatible(object, target, 'z-', threshold):
database[object.name]['z-'].append(target.name)
return database
def sortDatabaseKeys(self, database):
sortedKeys = sorted(database)
sortedDatabase = {}
for key in sortedKeys:
sortedDatabase[key] = database[key]
return sortedDatabase