WIP: FBX IO: Speed up shape key access using pointers #105126
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#105126
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "Mysteryem:fbx_shape_key_pointer_access"
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?
Unlike Blender, FBX shape keys are sparse data, meaning that it's not a
problem for large FBX meshes to have many shape keys that affect only
very few vertices. In Blender, because each shape key has as many shape
key coordinates as there are vertices in the mesh, it can result in
reading/writing a lot of data when importing/exporting FBX.
Due to the current implementation of shape keys in Blender, accessing
their data with foreach_set/foreach_get is slower compared to properties
with raw array access, such as most mesh attribute properties.
This PR avoids the issue of slower access to shape keys by constructing
an array view of the internal shape key data memory and using that array
to access the data directly.
To try and make the access to the internal shape key data safer, this
patch does checks when attempting to get the data and does a more
in-depth check the first time it tries to get internal shape key data.
This PR provides an alternative to blender/blender#116637, where, instead of adding to the current Python API, FBX IO is updated to access shape key data directly using the pointer to the first data element.
The overall effect on import/export duration varies depending on the file, but for most of my rigged humanoid models that have a 'face' mesh, separated from the rest of the model, that has facial shape keys (oculus visemes, apple arkit blend shapes or similar) the export duration is about 1.07-1.09 times faster (original duration ~0.2s). For a much larger model I have which instead has a full humanoid body with facial shape keys as a single mesh, the export duration is about 1.45 times faster (original duration ~2.4s).
The effect on import duration was roughly the same as the effect on export duration in an earlier version of this patch which performed two extra copies of the shape key data array. These two extra copies have been removed now so imports should be slightly faster, but probably not by much.
I'm not sure what the general sentiment is of accessing Blender data directly through pointers in add-ons. Most other properties accessed with foreach_get/set by FBX IO have raw array access internally so are quite fast already.
The individual
fast_mesh_shape_key_co_foreach_get
calls scale much better thanforeach_get
:As stated in blender/blender!116637, I would much rather avoid such dark and dangerous magic in our python code. ;)
Nice proof of concept though!
Pull request closed