FBX Import: Speed up geometry with numpy #104482
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#104482
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "Mysteryem/blender-addons:fbx_import_polys_verts_edges_np_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 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.
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.
The changes to the two listed edge cases of malformed .fbx could be changed to raise errors similar to the original code if preferred.
I kept the numpy import within the function like the other external module imports, I wasn't sure how important that was.
c1f572ad6e
toc648645cfc
c648645cfc
to600d0d8888
FBX Import: Speed up verts/edges/polys with numpyto FBX Import: Speed up geometry with numpyI pushed some additional changes to setting smoothing and custom split normals, since they're fairly small changes and part of the same
blen_read_geom
function that this patch covers.I tried a lot of different ways to see if I could make the call to
Mesh.normals_split_custom_set
faster, but the best I could do was tie the original implementation. For anything faster I think the only way would be ifMesh.normals_split_custom_set
was updated to be able to take advantage of inputs that are buffers, similar to theforeach_get
/foreach_set
functions ofbpy_prop_array
andbpy_prop_collection
.I managed to make a custom Blender build with buffer support which then runs
Mesh.normals_split_custom_set
2-3 times faster, I'll see if I can get interest from one of the Python API devs, especially since I don't have much C experience.Patch look good, would rather have the 'utils' part of it (shared with some other patches) either put in a single one, or even in a separate PR to help with the merging process.
Also think that the
import
s 'where it's used' can be ignored here, this is supposed to be a startup time optimization (to avoid blender's python to import everything when starting Blender), but in practice doubt this is giving any real improvements here, since numpy is also imported infbx_utils
etc.600d0d8888
tobd2d2e1cd8
bd2d2e1cd8
to07d0491966
The imports and shared
parray_as_ndarray
utility function have been moved to a separate commit that has its own PR: #104499I removed the reference to adding the
parray_as_ndarray
function from the commit message for this patch.07d0491966
to2438ae5c27