Speed up FBX export of UVs with numpy #104453

Closed
Thomas Barlow wants to merge 1 commits from Mysteryem/blender-addons:fbx_numpy_uvs_pr_standalone into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

1 Commits

Author SHA1 Message Date
Thomas Barlow 65a1a580e9 Speed up FBX export of UVs with numpy
Use buffers matching the C types of the data in foreach_get to avoid having to iterate and cast every single element in the C foreach_getset function.

Uses sorting-based uniqueness in the same way as numpy.unique, but avoids creating an array of triplets by keeping the uvs and vertex indices arrays separate and splits up the work needed for both arrays, since the vertex indices are the same for every uv layer, so only need to be sorted once.

Adds a specific check and exception for NaN values since the original code would also raise an exception when NaN values were encountered in uvs.

About 10-20 times faster with 1 uv layer, with further speedup the more uv layers there are. It is possible to export uvs in a similar manner as the original code, but with only a single iteration rather than the original two iterations, in which case, this patch is about 6-12 times faster with 1 uv layer.

This does change the exported fbx because the uvs are sorted (albeit not in order because they are viewed as a different type for sorting performance), causing the "UV" array to be in a different order and the "UVIndex" array to match the new ordering, but the full array of uvs reconstructed by indexing the "UV" array with each "UVIndex" in sequence does remain the same, so while the exported file may be different, the result of importing the different file will still be the same.
2023-02-28 18:07:39 +01:00