Optimize loading index map #5848

Use dict of face sets so we can get face data in O(1) instead of going through all of O(n).
This commit is contained in:
Andrej730
2024-12-12 15:39:44 +05:00
parent 4e0a813eb4
commit d8cfc017d4
+8 -7
View File
@@ -592,22 +592,23 @@ class Loader(bonsai.core.tool.Loader):
opacity = opacity if opacity is not None else 1.0
data_list = [d + (opacity,) for d in data_list]
faces_tex_coord_data = {}
for tex_coord_index, face_remap in zip(texture_map, faces_remap, strict=True):
faces_tex_coord_data[frozenset(face_remap)] = (tex_coord_index, face_remap)
# Apply attribute to each face
for bface in bm.faces:
face = [loop.vert.index for loop in bface.loops]
face = frozenset(loop.vert.index for loop in bface.loops)
# Find the corresponding index in data list by matching ifc faceset with blender face.
data_index = None
for tex_coord_index, face_remap in zip(texture_map, faces_remap, strict=True):
if not all(i in face_remap for i in face):
continue
if tex_coord_data := faces_tex_coord_data.get(face):
tex_coord_index, face_remap = tex_coord_data
# Subtract 1 as tex_coord_index starts with 1.
if map_type == "UV":
data_index = [tex_coord_index[face_remap.index(i)] - 1 for i in face]
else:
data_index = [tex_coord_index - 1 for i in face]
break
if data_index is None:
else:
# This face may be part of another representation item
# Or we couldn't match it due to georeferencing.
continue