From d8cfc017d4d1cc718db855d8ae2f80f3e64f5eb8 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 12 Dec 2024 15:39:44 +0500 Subject: [PATCH] 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). --- src/bonsai/bonsai/tool/loader.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/bonsai/bonsai/tool/loader.py b/src/bonsai/bonsai/tool/loader.py index 9b8cee1429..8372c34475 100644 --- a/src/bonsai/bonsai/tool/loader.py +++ b/src/bonsai/bonsai/tool/loader.py @@ -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