FBX Export: Base patch for numpy speedup #104447

Merged
Bastien Montagne merged 1 commits from Mysteryem/blender-addons:fbx_numpy_base_patch_pr into main 2023-02-28 18:03:14 +01:00

1 Commits

Author SHA1 Message Date
Thomas Barlow 388f48cb09 FBX Export: Base patch for numpy speedup
This is a base patch that all other separate numpy patches to the FBX exporter rely on.

Add support for writing bytes from numpy arrays like the already supported Python arrays.

Add numpy and helper function imports to fbx_utils.py and export_fbx_bin.py to simplify subsequent patches.

Add astype_view_signedness utility function for viewing unsigned integer data as signed only when the itemsizes match, to avoid copying arrays unnecessarily with `numpy.ndarray.astype(new_type, copy=False)`.

Add numpy versions of the vcos_transformed_gen and nors_transformed_gen mesh transform helpers. 4d output is supported following comments in nors_transformed_gen, though remains unused.
Given tests of 1000 to 200000 vectors:
The most common use case is where the matrix is None (when the bake_space_transform option of the exporter is disabled, which is the default), which is ~44-105 times faster.
When bake_space_transform is enabled geom_mat_co is usually a matrix containing only scaling, which is ~14-65 times faster.
When bake_space_transform is enabled geom_mat_no is usually the identity matrix, which is ~18-170 times faster.

Add helper functions for performing faster uniqueness along the first axis when a sorted result is not needed. The sorting part of numpy.unique is often what takes the most time in the subsequent patches and this helper function can run numpy.unique many times faster when the second axis of an array has more than one element because it treats each row as a single element of a larger dtype meaning it only has to sort once.

This patch on its own makes no change to exported files.
2023-02-28 18:02:33 +01:00