From cc166e30397d6f53306800be0601374ff821a530 Mon Sep 17 00:00:00 2001 From: Thomas Barlow Date: Fri, 29 Sep 2023 00:57:33 +0100 Subject: [PATCH 1/2] FBX IO: Speed up cluster export: Remove unused sorting Sorting the weights and vertex group indices on each vertex was added in a47e870349 as part of an option to limit the maximum number of exported weights per vertex. This feature was later removed, but the extra code that added the sorting was not. This patch removes the sorting because it is not needed and is quite expensive. Setting all the weights and indices into `vgroups` now runs in about 40% of the original time. The overall speedup from this patch depends very much on what data other than the clusters needs exporting, but I get a reduction in total export time between 7.5% and 15% for non-animated humanoid character models. --- io_scene_fbx/export_fbx_bin.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/io_scene_fbx/export_fbx_bin.py b/io_scene_fbx/export_fbx_bin.py index 2ff5210a1..702e0798f 100644 --- a/io_scene_fbx/export_fbx_bin.py +++ b/io_scene_fbx/export_fbx_bin.py @@ -1810,18 +1810,16 @@ def fbx_data_armature_elements(root, arm_obj, scene_data): elem_data_single_int32(fbx_skin, b"Version", FBX_DEFORMER_SKIN_VERSION) elem_data_single_float64(fbx_skin, b"Link_DeformAcuracy", 50.0) # Only vague idea what it is... - # Pre-process vertex weights (also to check vertices assigned to more than four bones). + # Pre-process vertex weights so that the vertices only need to be iterated once. ob = ob_obj.bdata bo_vg_idx = {bo_obj.bdata.name: ob.vertex_groups[bo_obj.bdata.name].index for bo_obj in clusters.keys() if bo_obj.bdata.name in ob.vertex_groups} valid_idxs = set(bo_vg_idx.values()) vgroups = {vg.index: {} for vg in ob.vertex_groups} - verts_vgroups = (sorted(((vg.group, vg.weight) for vg in v.groups if vg.weight and vg.group in valid_idxs), - key=lambda e: e[1], reverse=True) - for v in me.vertices) - for idx, vgs in enumerate(verts_vgroups): - for vg_idx, w in vgs: - vgroups[vg_idx][idx] = w + for idx, v in enumerate(me.vertices): + for vg in v.groups: + if (w := vg.weight) and (vg_idx := vg.group) in valid_idxs: + vgroups[vg_idx][idx] = w for bo_obj, clstr_key in clusters.items(): bo = bo_obj.bdata -- 2.30.2 From 844b22d7f0b85d455bf50309f8579f468ff0444b Mon Sep 17 00:00:00 2001 From: Thomas Barlow Date: Fri, 6 Oct 2023 03:16:49 +0100 Subject: [PATCH 2/2] Increase FBX IO Version --- io_scene_fbx/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io_scene_fbx/__init__.py b/io_scene_fbx/__init__.py index 5aaf9f92e..222a9652a 100644 --- a/io_scene_fbx/__init__.py +++ b/io_scene_fbx/__init__.py @@ -5,7 +5,7 @@ bl_info = { "name": "FBX format", "author": "Campbell Barton, Bastien Montagne, Jens Restemeier, @Mysteryem", - "version": (5, 8, 4), + "version": (5, 8, 5), "blender": (3, 6, 0), "location": "File > Import-Export", "description": "FBX IO meshes, UVs, vertex colors, materials, textures, cameras, lamps and actions", -- 2.30.2