Thanks,
I'll definitely look into that script. Here's what I have so far for the full functionality of my script...maybe this'll clear up something:
CODE
/*This script takes the result from the sz_ReturnComponentSelectionInOrder script when two verts are selected and
and matches the skinweighting from the first vertex selected to the second vertex selected.
I also modified it, so that you can clear the vert selection in between iterations of running the script. So, it
will run directly after the vert selection is made, or after you clear a selection, then select the verts you want to affect.
Its convenient for gaming especially where swapping heads and other parts are necessary, and vert weight must be matched exactly.
This will work on verts from the same skinned mesh, or two separate skinned meshes.
Script by Sean Danyi http://animandmel.blogspot.com 11-07. */
global proc sdMatch2VertWeights()
{
$realVertSelection = sz\_ReturnComponentSelectionInOrder
;
$realVertSize = size $realVertSelection
;
//--Some Error Checking.-----------------------------------------------------
if ($realVertSize == 3)
stringArrayRemoveAtIndex(0, $realVertSelection); //--This eliminates the "select -cl" command from the list if it was used.--\
if ($realVertSize > 3)
error "Please select only Two vertices.";
if (gmatch $realVertSelection[0] "*.vtx*"
!= 1)
error "Please select only Two vertices.";
if (gmatch $realVertSelection[1] "*.vtx*"
!= 1)
error "Please select only Two vertices.";
//--Define the first and second vertices.-------------------------------------
string $firstVertex = $realVertSelection[0];
string $secondVertex = $realVertSelection[1];
//--Find the objects they belong to.-------------------------------------------
string $firstObjectBuffer[];
string $secondObjectBuffer[];
int $firstNumTokens = tokenize ($firstVertex) "." $firstObjectBuffer
;
int $secondNumTokens = tokenize ($secondVertex) "." $secondObjectBuffer
;
string $firstObject = $firstObjectBuffer[0];
string $secondObject = $secondObjectBuffer[0];
//--Find the skin clusters affecting the objects.-----------------------------
string $firstSkinCluster = findRelatedSkinCluster ($firstObject)
;
string $secondSkinCluster = findRelatedSkinCluster ($secondObject)
;
//--Find the joints affecting the components, and the size of their array.-----------------
$firstVertexJoints = skinPercent -ib 0.001 -q -t $firstSkinCluster $firstVertex
;
$firstJointsSize = size $firstVertexJoints
;
$secondVertexJoints = skinPercent -ib 0.001 -q -t $secondSkinCluster $secondVertex
;
$secondJointsSize = size $secondVertexJoints
;
$secondSkinClusterInf = skinCluster -q -inf $secondSkinCluster
;
//--Find the weight percent of each joint for each vertex.--------------------
$firstVertPercents = skinPercent -q -v $firstSkinCluster $firstVertex
;
$secondVertPercents = skinPercent -q -v $secondSkinCluster $secondVertex
;
//--Check to ensure that both verts are influenced by the same joints.
for ($eachJoint in $firstVertexJoints)
{
int $jointInfluence = stringArrayContains (($eachJoint), $secondSkinClusterInf);
if ($jointInfluence == 0)
skinCluster -e -ai ($eachJoint) $secondSkinCluster;
}
//--reset the second vert's percentages to all zeros----------------
skinPercent -prw 1 -nrm off $secondSkinCluster $secondVertex;
//--For each joint affecting the first object, set its weight to affect the second.---------------------
//for ($counter = 1; $counter <= 5; $counter++) //--This will run the weight matching 5 times, since Maya automatically maintains a value of 1, this ensures precision.--\
//{
for ($i = 0; $i < $firstJointsSize; $i++)
{
skinPercent -nrm off -tv $firstVertexJoints[$i] $firstVertPercents[$i] $secondSkinCluster $secondVertex;
}
//}
//--Final Touches.-------------
//select -r $firstVertex;
//select -tgl $secondVertex;
print "Vertex weights successfully matched.";
}
Note: this is how it stands as my WIP.