MetaFusion/Reference/SuperRiggingEditor/scripts/SGReorderBlendShapes.mel

81 lines
2.5 KiB
Plaintext
Raw Normal View History

2025-02-03 22:58:41 +08:00
//******************************************************************************
//
// <20><>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD>: <20><>Ϫʱ<CFAA><CAB1><EFBFBD>Ƽ<EFBFBD><C6BC><EFBFBD><EFBFBD>޹<EFBFBD>˾
// <20><>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD>: q.100@qq.com
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 2024/09/16
//
//******************************************************************************
global proc SGReorderBlendShapes (){
for($mesheIndex=0; $mesheIndex<50; $mesheIndex++){
string $meshe = `SGGetMeshes -m $mesheIndex`;
if(`objExists $meshe`){
string $blendShape = `SGGetBlendShape $meshe`;
if(`objExists $blendShape`){
string $attrWeight = $blendShape + ".weight";
int $nbInTgt = `getAttr -size $attrWeight`;
int $existingIndices[] = `getAttr -multiIndices $attrWeight`;
string $currentBlendShapeList[] = `listAttr -m $attrWeight`;
string $blendShapeList[] = `SGGetBlendShapes`;
int $assess = `areIndexesSorted $blendShapeList $currentBlendShapeList`;
if($nbInTgt-1 != $existingIndices[$nbInTgt-1] || !$assess){
string $targetList[];
for($j=0; $j<size($existingIndices); $j++){
string $target[] = `sculptTarget -e -regenerate true -target $existingIndices[$j] $blendShape`;
$targetList[size($targetList)] = $target[0];
}
delete $blendShape;
select -cl;
for($j=0; $j<size($blendShapeList); $j++){
if(stringArrayContains($blendShapeList[$j], $targetList)){
select -add $blendShapeList[$j];
}
}
select -add $meshe;
blendShape -automatic -n $blendShape;
delete $targetList;
}
}
}
}
}
global proc int areIndexesSorted(string $arrayA[], string $arrayB[]) {
// <20><EFBFBD><E6B4A2>ͬԪ<CDAC>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
int $commonIndicesA[] = {};
int $commonIndicesB[] = {};
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>A<EFBFBD><41><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>B<EFBFBD><42>Ҳ<EFBFBD><D2B2><EFBFBD>ڵ<EFBFBD>Ԫ<EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for ($i = 0; $i < size($arrayA); $i++) {
for ($j = 0; $j < size($arrayB); $j++) {
// <20><><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>
if ($arrayA[$i] == $arrayB[$j]) {
// <20><>¼A<C2BC><41>B<EFBFBD><42><EFBFBD><EFBFBD>ͬԪ<CDAC>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
$commonIndicesA[size($commonIndicesA)] = $i;
$commonIndicesB[size($commonIndicesB)] = $j;
// <20>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><CBB3>ڲ<EFBFBD>ѭ<EFBFBD><D1AD>
break;
}
}
}
// <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
return isSorted($commonIndicesA) && isSorted($commonIndicesB);
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
global proc int isSorted(int $array[]) {
for ($i = 1; $i < size($array); $i++) {
if ($array[$i] < $array[$i - 1]) {
return 0; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
}
return 1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}