Speed up bone merge in export prep #75
No reviewers
Labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kkbp-dev/KKBP_Importer!75
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "sialim/KKBP_Importer:master"
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?
The "Prep for target application" merge gets extremely slow on high-bone-count models. On a 89-object model with ~600–1000 bones each it runs for hours, sometimes effectively days.
Cause: merge_weights calls mix_weights once per (mesh, bone) pair, and each call creates a VERTEX_WEIGHT_MIX modifier and runs bpy.ops.object.modifier_apply. Every modifier_apply forces a full depsgraph re-evaluation and an undo push, so the work scales with meshes × bones × per-apply overhead and is entirely main-thread bound (extra CPU cores don't help).
Fix: Do the same operation directly on vertex-group data. A VERTEX_WEIGHT_MIX in ADD mode is just target_weight += source_weight for vertices in the source group, followed by deleting the source group — so this rewrites the merge to accumulate weights with vertex_group.add(..., 'ADD') in a single pass per mesh. No modifiers, no operators, no per-bone depsgraph evaluation. Cost is now roughly proportional to total vertex count.
I verified the direct-add output is numerically identical to the modifier-based result.
Tested on this card (https://db.bepis.moe/koikatsu/view/392842), VRM + "very simple" preset: merge dropped from ~[3-4 hours] to ~[30 seconds]. Output weights unchanged.
This is smart! Waiting even two minutes for a few bones to merge was a pain, and like you said the runtime goes from a coffee break to an unbearable wait when the amount of objects and bones increase. Thanks for diagnosing and finding an improvement!