SkinPercent Slowdown

Hi guys, I have a maya skinning tool where I want a user to select an inv and say ‘add X pct or weight’. Below is a small loop, this crawls on slightly large meshes (5-8k)

     def plusWeightFn(self):
		if self.currentInf:
			addVal = self.ui.setWeightSpin.value()
			for v in self.currentVerts:
				val = cmds.skinPercent(self.currentSkin, v, transform=self.currentInf, q=1)
				val += addVal
				cmds.skinPercent(self.currentSkin, v, tv=[str(self.currentInf), val])
			self.refreshUI()
		else: cmds.warning('[skinWrangler] No influences/joints selected')

If performance is becoming an issue, then it may be time to start using the python API objects.

For this you’d need: OpenMayaAnim.MFnSkinCluster

Stev

There are a lot of things you can do to speed up the query and set of weights, but you do have to delve into the API and deal with more complex code. The fastest way I know about is to use MPlug to query weights and setAttr to set weights. This might help, Dealing with skinCluster weights in Maya

If you aren’t comfortable with that, from your basic example, you could probably use the normal paintSkinWeights tool and let it deal with modifying the weights. For example, your script would select vertices to modify, start the paintSkinWeights tool, select the influence in the list, set operation to add, set opacity to 1.0, set value to the desired value, and run a flood. This also gives easy access to other operations (scale, smooth, etc). No ideal, but wouldn’t be slow.

Wow…

So the above was taking ~80 sec on a selection of verts, I have found an optimization in the manual that gets that down to 0.061 sec. The ‘relative’ flag:

def plusWeightFn2():
        if currentInf:
                val = 0.1
                cmds.skinPercent(currentSkin, sel, tv=[str(currentInf), val], r=1)
        else: cmds.warning('[skinWrangler] No influences/joints selected')

HUGE FACEPALM.

The difference being that here it can just offset all component selection by an additive amt in one go with no looping. There was another optimization if anyone is interested. I was polling a selection of verts for the amt each was weighted to an inf then avging that. There is a special way to query a component selection with skin pct, where based on the order you feed it the tv flag, it will return you an avg weight for all selected components.