mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-31 17:06:29 +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
|
opacity = opacity if opacity is not None else 1.0
|
||||||
data_list = [d + (opacity,) for d in data_list]
|
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
|
# Apply attribute to each face
|
||||||
for bface in bm.faces:
|
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.
|
# Find the corresponding index in data list by matching ifc faceset with blender face.
|
||||||
data_index = None
|
data_index = None
|
||||||
for tex_coord_index, face_remap in zip(texture_map, faces_remap, strict=True):
|
if tex_coord_data := faces_tex_coord_data.get(face):
|
||||||
if not all(i in face_remap for i in face):
|
tex_coord_index, face_remap = tex_coord_data
|
||||||
continue
|
|
||||||
# Subtract 1 as tex_coord_index starts with 1.
|
# Subtract 1 as tex_coord_index starts with 1.
|
||||||
if map_type == "UV":
|
if map_type == "UV":
|
||||||
data_index = [tex_coord_index[face_remap.index(i)] - 1 for i in face]
|
data_index = [tex_coord_index[face_remap.index(i)] - 1 for i in face]
|
||||||
else:
|
else:
|
||||||
data_index = [tex_coord_index - 1 for i in face]
|
data_index = [tex_coord_index - 1 for i in face]
|
||||||
break
|
else:
|
||||||
|
|
||||||
if data_index is None:
|
|
||||||
# This face may be part of another representation item
|
# This face may be part of another representation item
|
||||||
# Or we couldn't match it due to georeferencing.
|
# Or we couldn't match it due to georeferencing.
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user