From 5da3d41c275d90bcde1b43aa566d7d0e26e42910 Mon Sep 17 00:00:00 2001 From: Thomas Barlow Date: Sat, 18 Mar 2023 03:13:33 +0000 Subject: [PATCH] FBX Import: Speed up cycles decal workaround with numpy Replace iteration with foreach_get/set and numpy vectorized operations An issue introduced in Blender 3.3 makes the original code very slow: https://projects.blender.org/blender/blender/issues/105909 So this results in about a 1500 times speedup at 6000 vertices and 3500 times at 25000 vertices. In Blender 3.2 the new code would run about 40-60 times faster for 1000-25000+ vertices. --- io_scene_fbx/import_fbx.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/io_scene_fbx/import_fbx.py b/io_scene_fbx/import_fbx.py index 67152205d..6e8cbd76f 100644 --- a/io_scene_fbx/import_fbx.py +++ b/io_scene_fbx/import_fbx.py @@ -3231,8 +3231,16 @@ def load(operator, context, filepath="", if decal_offset != 0.0: for material in mesh.materials: if material in material_decals: - for v in mesh.vertices: - v.co += v.normal * decal_offset + num_verts = len(mesh.vertices) + blen_cos_dtype = blen_norm_dtype = np.single + vcos = np.empty(num_verts * 3, dtype=blen_cos_dtype) + vnorm = np.empty(num_verts * 3, dtype=blen_norm_dtype) + mesh.vertices.foreach_get("co", vcos) + mesh.vertices.foreach_get("normal", vnorm) + + vcos += vnorm * decal_offset + + mesh.vertices.foreach_set("co", vcos) break for obj in (obj for obj in bpy.data.objects if obj.data == mesh): -- 2.30.2