No announcement yet.

Max Influence script for Maya

  • Filter
  • Time
  • Show
Clear All
new posts

    [TOOL] Max Influence script for Maya

    I use ngSkinTools plug-in for Maya 2016 in order to skin my models, but usually when I'm done smoothing all the weights I found many vertices with up to 7-8 influences and Apex clothing tool complaining about it. So I looked for a way to set the max influence value on the fly but found none, and I end up learning a bit of MEL scripting and coding my own MaxInfluence script. I'm sharing it if anyone need it:

            /*SCRIPT PARAMETER*/
    	int $MaxInfluence = 4;
    	string $Selection[] = `ls -sl`;
    	string $Skin = `findRelatedSkinCluster $Selection[0]`;
    	int $VertsCount[] = `polyEvaluate -v $Selection[0]`;
    	int $i = 0;
    	for(; $i < ($VertsCount[0] + 1); $i++)    // Iterate over all mesh vertices
    		string $Vertex = $Selection[0] + ".vtx[" + $i + "]";    // Variable to store current vertex
    		float $Weights[] = `skinPercent -ignoreBelow 0.0001 -query -value $Skin $Vertex`;    // Array of all influences not null
    		if(size($Weights) > $MaxInfluence)       // If (number of influences > max number of influences)
    		    int $j;
    		    float $Max[]; for($j = 0; $j < size($Weights); $j++) $Max[$j] = 0.0;    // Init Max array
    			for($W in $Weights)    // Iterate over all positive influences
    				int $k;
    				for($j = size($Weights); $j >= 0 && $W > $Max[$j]; $j--); $j++;    // Move the target influence down until the bottom is reached (-1) or the next influence is greater
    				for($k = size($Weights); $k > $j; $k--)
    					$Max[$k] = $Max[$k - 1];
    				$Max[$k] = $W;
    			float $PruneValue = $Max[$MaxInfluence] + 0.0001;
    			print ($PruneValue + "\n");
    			skinPercent -pruneWeights $PruneValue $Skin $Vertex;
    Just make sure that the target mesh is selected and run the script. If you want you can change the max influence parameter at the beginning of the script (maybe for performance purpose). Hope this helps!
    Last edited by Sneppy; 04-07-2016, 01:08 PM.
    Main links:
    Turbosquid 3D models

    thanks that was useful I was to lazy to write it, and worked out of the box.


      Sorry to bump a year old thread. But just wanted to let you know this was super useful and thought that it was maybe worth bumping in case someone else runs into this issue. Didn't know there wasn't already a procedure in maya for this and it worked very well, thanks!


        Found this page as weighting was giving major headaches when I set max influence limit to 2 but was finding 3,4,5+ influences across the mesh! Thanks Sneppy