81 lines
2.5 KiB
Plaintext
81 lines
2.5 KiB
Plaintext
//******************************************************************************
|
||
//
|
||
// 版权所有: 玉溪时光科技有限公司
|
||
// 联系邮箱: q.100@qq.com
|
||
// 开发日期: 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[]) {
|
||
// 存储相同元素的索引
|
||
int $commonIndicesA[] = {};
|
||
int $commonIndicesB[] = {};
|
||
|
||
// 遍历数组A,找到在B中也存在的元素及其索引
|
||
for ($i = 0; $i < size($arrayA); $i++) {
|
||
for ($j = 0; $j < size($arrayB); $j++) {
|
||
// 如果元素相同,记录索引
|
||
if ($arrayA[$i] == $arrayB[$j]) {
|
||
// 记录A和B中相同元素的索引
|
||
$commonIndicesA[size($commonIndicesA)] = $i;
|
||
$commonIndicesB[size($commonIndicesB)] = $j;
|
||
// 找到后就退出内层循环
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 判断索引是否从小到大排序
|
||
return isSorted($commonIndicesA) && isSorted($commonIndicesB);
|
||
}
|
||
|
||
// 辅助函数:检查数组是否已排序
|
||
global proc int isSorted(int $array[]) {
|
||
for ($i = 1; $i < size($array); $i++) {
|
||
if ($array[$i] < $array[$i - 1]) {
|
||
return 0; // 不是升序
|
||
}
|
||
}
|
||
return 1; // 是升序
|
||
} |