Speed up FBX export of vertex colors with numpy #104454
No reviewers
Labels
No Label
Interest
Animation & Rigging
Interest
Blender Cloud
Interest
Collada
Interest
Core
Interest
Documentation
Interest
Eevee & Viewport
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
Import and Export
Interest
Modeling
Interest
Modifiers
Interest
Nodes & Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds, Tests & Devices
Interest
Python API
Interest
Rendering & Cycles
Interest
Sculpt, Paint & Texture
Interest
Translations
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Meta
Good First Issue
Meta
Papercut
Module
Add-ons (BF-Blender)
Module
Add-ons (Community)
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender-addons#104454
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "Mysteryem/blender-addons:fbx_numpy_vertex_colors_pr_standalone"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Use buffer matching the single precision float type of the vertex color data in foreach_get to avoid having to iterate and cast every element in the C foreach_getset function when single precision float is not 64 bits (it's usually 32 bits). Numpy can do the casting to the 64 bit fbx type much faster with .astype when needed. The largest relative speedup from this occurs with getting the 'color' property of Color attributes because the 'color_srgb' property and Byte Color attributes appear to have additional costs, which are presumably the conversion to sRGB and/or the conversion from byte to single precision float.
Find unique colors and their indices using numpy.
Use numpy to expand 'POINT' domain vertex colors to "ByPolygonVertex" using the loop vertex indices.
'POINT' domain vertex colors at about 1000+ vertices of a subdivided default cube:
~12-14 times faster for Byte Color
~16-22 times faster for Color (~12-19 for 'color_srgb')
'CORNER' domain vertex colors at about 1000+ loops of a subdivided default cube:
~5-7 times faster for Byte Color
~7-9 times faster for Color (~6-7 for 'color_srgb')
This does change the exported fbx because the vertex colors are sorted (albeit not in order because they are viewed as a different type for sorting performance), causing the "Colors" array to be in a different order and the "ColorIndex" array to match the new ordering, but the full array of colors reconstructed by indexing the "Colors" array with each "ColorIndex" 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.
The
t_lvi
array is also data that is used by the export of polygon indices and edges/UVs, so the same array used by those patches could be re-used for exporting vertex colors. Any extra loops added tot_lvi
for loose edges should be excluded, so the expansion of 'POINT' domain vertex colors would becomecol_indices = col_indices[t_lvi[:len(me.loops)]]
.See #104451 and #104453
This patch benefits the most from using the
fast_first_axis_unique
helper function overnp.unique(..., axis=0)
because np.unique would have to sort the array 4 times since each color has 4 components.This patch depends on
#104447
I wasn't sure if I should include its commit in this PR, I have included it for now.
0b6a002392
toa07e1bc6ea
a07e1bc6ea
to5d7e53eeba
Merging this final one, thanks again for the extensive in-code documentation, and detailed commit messages!