Speed up FBX export of vertex cos with numpy #104448
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#104448
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "Mysteryem/blender-addons:fbx_numpy_vertex_cos_pr"
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 cos 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 does the casting to the 64 bit fbx type much faster with .astype when needed.
Replace use of vcos_transformed_gen mesh transform helper with numpy version.
~35 (1538 vertices) to 55 (best) (24578 vertices) to 20 (6M to 25M vertices) times faster when geom_mat_co is None
~21 (1538 vertices) to 50 (best) (24578 vertices) to 23 (6M to 25M vertices) times faster when geom_mat_co is set
Relative to the original implementation, the numpy implementation seems to perform increasingly faster the more vertices there are until about 25k vertices and then starts getting slower at a decreasing rate, to the point that there is pretty much no change in the relative speedup between 6M and 25M vertices.
This patch slightly changes the exported cos when geom_mat_co is set by skipping a cast from double to single precision before casting as float64 (usually double precision):
The original code would multiply mathutils.Matrix (single precision) and mathutils.Vector (single precision) together, which casts the Matrix elements to double precision, performs the multiplication, and then casts the result back to single precision. These single precision multiplied vectors would then be cast to float64 to be exported.
The new code performs the same cast of the matrix to double precision, but skips the step of casting back to single precision, instead casting directly to float64.
Even if the new code were to cast back to single precision float and then to float64 like the original code, there does tend to be a small difference in the result, presumably due to precision error.
mathutils column vector multiplication for reference, note the use of double precision math:
This patch depends on
#104447
I wasn't sure if I should include its commit in this PR, I have included it for now.
147df61eb6
to6315b3d566
LGTM.