FBX Import: Speed up geometry with numpy #104482

Merged
Bastien Montagne merged 1 commits from Mysteryem/blender-addons:fbx_import_polys_verts_edges_np_pr into main 2023-04-03 15:07:49 +02:00

1 Commits

Author SHA1 Message Date
Thomas Barlow 2438ae5c27 FBX Import: Speed up geometry with numpy
Use buffers matching the C data types with foreach_set to avoid iterating and casting each element in foreach_set's C code.
Use numpy vectorized operations.
Replace _vcos_transformed_gen with numpy version, vcos_transformed.

Testing with verts/edges/polys arrays created from subdivided default cubes:
~8-45 times faster for about 1000 to 100_000 loops (len(fbx_polys)) then starts reducing at a reducing rate down to about 35 times faster after 6 million loops.
The speedup for setting smoothing is small, within the range of about 1-1.4 times.
The speedup for setting split normals is negligible since most of the time is spent on Mesh.normals_split_custom_set which runs in the same time as before.

Changes made to the import of malformed .fbx files:
.fbx that have edges, but no polygon-vertex-indices will now ignore the edges, print an error and continue the import, resulting in a mesh containing only vertices. Beforehand, an IndexError would be raised when an attempt would be made to index the empty fbx_polys array.
.fbx that have a verts array with a number of elements that isn't divisible by 3 will now have the remainder stripped from the end and an error will be printed. Beforehand, a RuntimeError would be raised by mesh.vertices.foreach_set("co", fbx_verts) because fbx_verts would not contain the number of elements exactly 3 times the number of vertices.
2023-04-03 14:55:09 +02:00