I want to copy skin weights from one human model to another. The two models have the same topology, so I tried to directly copy the weight index by index using following code.
for idx, p in enumerate(points):
# skinValues save first model's skinning
if idx in skinValues.keys():
ns = skinValues[str_idx]
mc.skinPercent(skinClusterIm, p, tv = ns,zri = True)
But it works so slowly (for models with 50000 vertices and 300 joints takes 15 minutes). Is there any way to speed up the process?
Yes, this will be painfully slow sadly, because Maya is generating an undo step for every single iteration sadly. That's 50000 * 300 undo steps, which is quite a lot of memory allocation!
You have two options to speed this up.
Option 1: disable the undo queue!
Option 2: Modify the skin cluster data directly.
The data on the skin cluster is addressed like so:
You can skip the need to skinPercent command entirely, by simply using setAttr to set the weights directly. I'm a bit old school, so generally use MEL, but in MEL you can set all weights for a single vertex in a single command, e.g.
Even with the undo stack enabled, this helps trim down the number of undo steps (However, even with this approach, I'd still disable the undo stack!!). By and large, I'd avoid using MFnSkinCluster in the Maya API, because it's stupidly slow. Sadly, the skinPercent command is clearly implemented using MFnSkinCluster :(
\edit
a little Mel script to extract the joint names from the skin cluster.