FBX Export: Base patch for numpy speedup
commit994c4d9175b07f86b82a3223b916c3872572b05b
authorThomas Barlow <github@mysterymayhem.co.uk>
Wed, 25 Jan 2023 03:40:32 +0000 (25 03:40 +0000)
committerGitea <gitea@fake.local>
Tue, 28 Feb 2023 17:03:13 +0000 (28 18:03 +0100)
tree9694a843a8b04969f2c63a935f6859c8afa31e22
parent38212cf0bdd9c1af3b3031f238230a006c03a8a0
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.

Pull Request #104447
io_scene_fbx/encode_bin.py
io_scene_fbx/export_fbx_bin.py
io_scene_fbx/fbx_utils.py