Ok, so I got my procedures running and executing well now, only they take so long that the progress window I made won't even update until it is done (even with a "refresh" command thrown into my loop), and everything freezes up while it is going through all these commands. The procedure is to import text value skin weights, and this is it:
proc applyWeights(int $vertNumb, string $vertices[], string $INF[], string $skinClus, string $NoReturns[])
{
int $k;
string $sValue[];
float $fValue[];
string $tempString = $NoReturns[$vertNumb];
tokenize $tempString $sValue;
$k = 0;
while ($k < size $INF)
{
$fValue[$k] = $sValue[$k];
float $comparison[] = skinPercent -q -value $skinClus $vertices[$vertNumb];
if ($fValue[$k] != $comparison[$k])
{
skinPercent -nrm 0 -tv $INF[$k] $fValue[$k] $skinClus $vertices[$vertNumb];
}
$k++;
}
}
proc applyCheckWeights(int $vertNumb, string $vertices[], string $INF[], string $skinClus, string $NoReturns[])
{
float $fCheck[] = skinPercent -q -value $skinClus $vertices[$vertNumb];
string $sCheck[];
int $counter;
string $oneString;
while ($counter < size $INF)
{
$sCheck[$counter] = $fCheck[$counter];
$oneString = $oneString + " " + $sCheck[$counter];
$counter++;
}
if ($NoReturns[$vertNumb] != $oneString)
{
int $k;
string $sValue[];
float $fValue[];
string $tempString = $NoReturns[$vertNumb];
tokenize $tempString $sValue;
$k = 0;
while ($k < size $INF)
{
$fValue[$k] = $sValue[$k];
float $comparison[] = skinPercent -q -value $skinClus $vertices[$vertNumb];
if ($fValue[$k] != $comparison[$k])
{
skinPercent -nrm 0 -tv $INF[$k] $fValue[$k] $skinClus $vertices[$vertNumb];
}
$k++;
}
}
}
global proc importSkinWeights ()
{
// Declare Vars:
//Selection Vars:
string $selection[] = ls -sl;
if ($selection [0] == "")
error ("No object has been selected.");
if (size $selection > 1)
error ("More than one object has been selected.");
string $selShape[] = ls -dagObjects -sl -hd 1 -type mesh;
if ($selShape[0] == "")
error ("A shape could not be found for the geometry.");
if (size $selShape > 1)
error ("More than one shape was found for the geometry.");
string $objHistory[] = listHistory $selShape[0];
string $skinCluster[] = ls -typ skinCluster $objHistory;
if (size $skinCluster == 0)
error ("A skinCluster could not be found for the selected geometry.");
// File Vars:
string $fileName = ( internalVar -userWorkspaceDir + workspace -q -act + "/text/" + "*.txt");
string $importFile = fileDialog -dm $fileName;
int $fileRead = fopen $importFile "r";
// Skin Influences:
string $INFs[] = listConnections ($skinCluster[0] + ".matrix");
string $compactVerts[] = ls ($selShape[0] + ".vtx;
[*]")
string $verts[] = filterExpand -sm 31 $compactVerts;
// Commands:
// Read input file, and store in $read[]:
int $i = 0;
string $read[];
while ($i < `size $verts`)
{
$read[$i] = `fgetline $fileRead`;
$i++;
} // # of lines = 5393
// Remove "n" characters from $read[] strings and returns $noReturns Array of strings:
int $count = 0;
string $noReturns[];
string $tempArray[];
// Create a work in progress window:
if (window -exists inProgress)
deleteUI inProgress;
window
-title "Work in progress..."
-widthHeight 200 100
inProgress;
columnLayout -adjustableColumn true;
text -label "Sit tight while I compute n~~snortsnort~*~";
showWindow inProgress;
// Remove all "n" characters:
while ($count < `size $verts`)
{
string $input = $read[$count];
tokenize $input "n" $tempArray;
$noReturns[$count] = $tempArray[0];
$count++;
clear $tempArray;
}
fclose $fileRead;
// If normalization was on, turn it off:
int $normalWeights = getAttr ($skinCluster[0] + ".normalizeWeights");
if ($normalWeights == 1)
setAttr ($skinCluster[0] + ".normalizeWeights") false;
// Assign weights:
int $j = 0;
while ($j < `size $verts`)
{
applyWeights($j, $verts, $INFs, $skinCluster[0], $noReturns);
$j++;
refresh;
}
// Reset weight normalization:
if( $normalWeights == 1 )
setAttr( $skinCluster[0] + ".normalizeWeights" ) true;
deleteUI inProgress;
}
As you can see, I have two procedures to do the applying of skin weight values. The first one simply checks all the skin weight vlaues for a certain vertex, influence by influece, to make sure they aren't the same as the weight of the joint/influence that is being overwriten, one at a time.
The second procedure, applyCheckWeights, I tried to make it also check for all the skin weights of a vertex and if they are the same as those being overwritten, skip that vertex all together.
Anyways, is there anyway to make it so the screen doesn't freeze up? Also any tips on making it evaluate any faster would be appreciated, as it currently is taking a good 5-15 minutes to apply the weights for a character with 5393 vertexes, and 93 joints/influence objects.
Thanks for any help!