首页 > 代码库 > 【mel】ea

【mel】ea

proc changeOtherList(){
textScrollList -e -da weightList;
textScrollList -e -da weightList;
textScrollList -e -da weightList;
textScrollList -e -da weightList;
int $index[]=`textScrollList -q -sii selectList`;
for ($obj in $index){
textScrollList -e -sii $obj weightList;
}
}

proc changeOtherListB(){
textScrollList -e -da selectList;
textScrollList -e -da selectList;
textScrollList -e -da selectList;
textScrollList -e -da selectList;
int $index[]=`textScrollList -q -sii weightList`;
for ($obj in $index){
textScrollList -e -sii $obj selectList;
}
}


//4T5
proc float countNew(float $a,int $n)
{
//float $a=0.2546523758;int $n=4;
float $N=pow(10,($n));
float $b=$a%(1/$N)*$N;
float $C;
if($b>0.5){
$C=ceil($a*$N)/$N;}
else{
$C=floor($a*$N)/$N;
}
return $C;
}

//get rid of
proc getRidOf(){
string $vesLists[]=`textScrollList -q -si selectList`;
string $skiLists[]=`textScrollList -q -si weightList`;
int $numOfSel[]=`textScrollList -q -sii weightList`;
int $gu=`intField -q -value gugezhi`;
string $buffer[];
string $shapeList[]=`ls -o $vesLists[0] `;
string $skinCluster= `findRelatedSkinCluster $shapeList[0]`;
for($h=0;$h<`size $vesLists`;$h++){
int $numbers = `tokenize $skiLists[$h] "[ * ]" $buffer`;
string $jointList[];string $jointLists;
float $weightLists[];
int $n=0;
//getlist
for($i=0;$i<$numbers;$i+=2){
$jointList[$n]=$buffer[$i];
$weightLists[$n]=$buffer[$i+1];
$n++;
}
//get min
if ($n>$gu){
float $b=2;
int $index=0;
for($i=0;$i<$n;$i++){
float $a=$weightLists[$i];
if($a<$b){
$b=$a;
$index=$i;
}else{
$b=$b;
$index=$index;
}
}
//get rid of
$b=$b/($n-1);
for ($i=0;$i<$n;$i++){
$weightLists[$i]+=$b;
if($i==$index){
$weightLists[$i]=0;
}
skinPercent -tv $jointList[$i] $weightLists[$i] $skinCluster $vesLists[$h];
setAttr ($jointList[$i]+".liw") 1;
if($weightLists[$i]>0){
$jointLists+=($jointList[$i]+" [ "+$weightLists[$i]+" ] ");
}
}
//update list
textScrollList -e -rii $numOfSel[$h] weightList;
textScrollList -e -ap $numOfSel[$h] $jointLists weightList;
//condistion
textScrollList -e -sii $numOfSel[$h] selectList;
textScrollList -e -sii $numOfSel[$h] weightList;
}
if (($n-1)==$gu){
textScrollList -e -dii $numOfSel[$h] selectList;
textScrollList -e -dii $numOfSel[$h] weightList;
}
for ($obj in $jointList){
setAttr ($obj+".liw") 0;
}
clear $weightLists;
$jointLists="";
}
}

proc loadOtherList(int $catch){
textScrollList -e -ra selectList;
textScrollList -e -ra weightList;
string $vList[]=`ls -fl -sl`;
string $shapeList[]=`ls -o -sl`;
if($vList[0]==$shapeList[0]){
int $nums[]=`polyEvaluate -v $shapeList[0]`;
for ($i=0;$i<$nums[0];$i++){
$vList[$i]=$shapeList[0]+".vtx["+$i+"]";
}
}
string $skinCluster= `findRelatedSkinCluster $shapeList[0]`;
string $jointLists;
for($obj in $vList){
int $i=1;int $numTokens;
textScrollList -e -ap $i $obj selectList;
string $jointList[]=`skinPercent -ib 0.00000000000000001 -q -t $skinCluster $obj`;
int $num=`size $jointList`;
float $weight[];
for($h=0;$h<$num;$h++){
$weight[$h]=`skinPercent -transform $jointList[$h] -query $skinCluster $obj`;
if($catch==1){
int $jin=`intField -q -value jinquezhi`;
$weight[$h]=countNew($weight[$h],$jin);
skinPercent -tv $jointList[$h] $weight[$h] $skinCluster $obj;
setAttr ($jointList[$h]+".liw") 1;
}
if($weight[$h]>0){
$jointLists+=($jointList[$h]+" [ "+$weight[$h]+" ] ");
string $buffers[];
$numTokens = `tokenize $jointLists "[" $buffers`;
}
}
for($obj in $jointList){
setAttr ($obj+".liw") 0;
}
textScrollList -e -ap $i $jointLists weightList;
int $gu=`intField -q -value gugezhi`;
if ($num>$gu){
textScrollList -e -sii $i selectList;
textScrollList -e -sii $i weightList;
}
if (!(($numTokens-1)>$gu)){
textScrollList -e -dii $i selectList;
textScrollList -e -dii $i weightList;
}
$i++;
$jointLists="";;
clear $weight;
}
updateTip;
}


proc updateTip(){
int $numOfSel=`textScrollList -q -nsi selectList`;
if($numOfSel){
text -e -l ($numOfSel+" selected!") selTip;
}else{
text -e -l "" selTip;
}
}
proc selectedOtherList(){
string $vesLists[]=`textScrollList -q -si selectList`;
select $vesLists;
}

//weight list
proc SkinWrite()
{
string $tempFileName =`internalVar -utd`+"tempSkin.skin";
$fileId=`fopen $tempFileName "w"`;
//fwrite $fileId "SmoothSkinList";
string $selList[]=`ls -fl -sl`;
string $shapeList[]=`ls -o -sl`;
int $nums[]=`polyEvaluate -v $shapeList[0]`;
string $vList[];
for ($i=0;$i<$nums[0];$i++){
//$vList[$i]=$shapeList[0]+".vtx["+$i+"]";
$vList[$i]=".vtx["+$i+"]";
}
string $skinCluster= `findRelatedSkinCluster $shapeList[0]`;
string $jointLists;
for($obj in $vList){
float $weight[];
fprint $fileId ($obj+" ");
string $jointList[]=`skinPercent -ib 0.00000000000000001 -q -t $skinCluster $obj`;
int $num=`size $jointList`;
for($h=0;$h<$num;$h++){
$weight[$h]=`skinPercent -transform $jointList[$h] -query $skinCluster $obj`;
fprint $fileId ($jointList[$h]+" "+$weight[$h]+" ");
}
fprint $fileId "\n";
}
fclose $fileId;
print "ok";
}

proc SkinActive()
{
string $tempFileName =`internalVar -utd`+"tempSkin.skin";
string $selList[]=`ls -fl -sl`;
string $shapeList[]=`ls -o -sl`;
string $skinCluster= `findRelatedSkinCluster $shapeList[0]`;
$fileId=`fopen $tempFileName "r"`;
string $nextLine = `fgetline $fileId`;
while ( size( $nextLine) > 0 ) {
string $buffer[];
//print $nextLine;
int $num=`tokenize $nextLine $buffer`;
string $vertex=$shapeList[0]+$buffer[0];
string $com;
for($i=1;$i<$num;$i+=2){
$com+="-tv "+$buffer[$i]+" "+$buffer[$i+1]+" ";
}
int $call=`eval ("skinPercent "+$com+$skinCluster+" "+$vertex)`;
//print ("skinPercent "+$com+$skinCluster+" "+$vertex);
$com="";
$nextLine = `fgetline $fileId`;
}
fclose $fileId;
}

//UI
proc skinTestWin(){
if(`window -ex skinTestWin`)deleteUI skinTestWin;
window -t "skinTest" -s 1 -tlb 1 -ret skinTestWin;
string $form=`formLayout`;
string $selectList=`textScrollList -ams 1
-sc "changeOtherList"
-dcc "selectedOtherList" selectList`;
string $weightList=`textScrollList -ams 1
-sc "changeOtherListB"
-dcc "selectedOtherList"
weightList`;
string $LayoutCollection1=`columnLayout `;
string $button0=`button -l "load" -w 95 -c "loadOtherList(0)"`;
string $button1=`button -l "clean" -w 95 -c "loadOtherList(1)"`;
string $button2=`button -l "removeMin" -w 95 -c "getRidOf;loadOtherList(1)"`;
string $button3=`button -l "select" -w 95 -c "selectedOtherList"`;
text -l "decimal";
string $intField1=`intField -min 1 -max 3 -step 1 -value 2 jinquezhi`;
text -l "influenced";
string $intField2=`intField -min 1 -max 5 -step 1 -value 2 gugezhi`;
string $button4=`button -l "record" -w 95 -c "SkinWrite"`;
string $button5=`button -l "active" -w 95 -c "SkinActive"`;

string $text=`text -label "" selTip`;
setParent ..;
setParent ..;
formLayout -e
-af $selectList"top" 5 -af $selectList"left" 0 -ap $selectList "right" 0 30 -af $selectList"bottom" 5
-af $weightList "top" 5 -ap $weightList "left" 0 30 -ap weightList "right" 0 80 -af $weightList "bottom" 5
-af $LayoutCollection1 "top" 5 -af $LayoutCollection1 "right" 2
$form;

window -e -wh 800 400 skinTestWin;
showWindow skinTestWin;
}
skinTestWin;