mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user