UV集修复工具
功能简单,都写在按钮上了,不做介绍,如遇报错请联系我。
界面:
MEL源码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
| //UV集检查修改工具// // 作者:三岁豆 , 创建日期 2024.01.13 V 1.0//
// 创建窗口 判断UVToolWindow是否存在 if (`window -exists uvToolWindow`) deleteUI uvToolWindow; window -title "三岁豆Er" -sizeable false uvToolWindow;
// 窗口布局 columnLayout -columnAttach "both" 10 -rowSpacing 5 -columnWidth 230; int $buttonHeight = 30;
//窗口内容 text -h 50 -label "UV集检查修改工具"; button -label "选中具有多个UV集的模型" -height $buttonHeight -command "selectMultipleUVSetsModels"; button -label "选中UV集不为map1的模型" -height $buttonHeight -command "selectNonDefaultUVModels"; button -label "删除多余的UV集" -height $buttonHeight -command "deleteExtraUVSets"; button -label "重命名默认UV集为map1" -height $buttonHeight -command "renameFirstUVSetToMap1"; text -h 5 -label"";
//显示窗口 showWindow uvToolWindow;
// 选中具有多个UV集的对象 global proc selectMultipleUVSetsModels() { select -cl; string $allModels[] = `ls -g`; string $model; int $foundModels = 0;
for ($model in $allModels) { string $uvSets[] = `polyUVSet -q -allUVSets $model`; if (size($uvSets) > 1) { select -add $model; $foundModels++; } }
if ($foundModels == 0) { confirmDialog -title "提示" -message "\n在当前场景中未找到具有多个UV集的模型!\n" -button "确定" -defaultButton "确定"; } }
// 选中UV集不为map1的模型 global proc selectNonDefaultUVModels() { select -cl; string $allModels[] = `ls -g`; string $model; int $foundModels = 0;
for ($model in $allModels) { string $currentUVSets[] = `polyUVSet -q -currentUVSet $model`; if (size($currentUVSets) > 0 && $currentUVSets[0] != "map1") { select -add $model; $foundModels++; } }
if ($foundModels == 0) { confirmDialog -title "提示" -message "\n在当前场景中未找到默认UV集名称非 map1 的模型!\n" -button "确定" -defaultButton "确定"; } }
// 删除多余的UV集 global proc deleteExtraUVSets() { string $selectedModels[] = `ls -sl -dag -ni -type mesh`; if(size($selectedModels) == 0){ confirmDialog -title "提示" -message "\n您还没有选中模型或选中的不是多边形!\n" -button "确定" -defaultButton "确定"; return; }
string $model; for ($model in $selectedModels) { string $uvSets[] = `polyUVSet -q -allUVSets $model`;
if(size($uvSets) <= 1) { confirmDialog -title "提示" -message "\n您当前选中的模型仅有一个UV集\n" -button "确定" -defaultButton "确定"; continue; }
string $uvSet; for ($uvSet in $uvSets) { if ($uvSet != "map1") { print ("正在删除 " + $model + " 的UV集:" + $uvSet + "\n"); polyUVSet -delete -uvSet $uvSet $model; } } } print "三岁豆Er:删除多余UV集成功!\n"; }
// 重命名默认UV集为map1 global proc renameFirstUVSetToMap1() { string $selectedObjects[] = `ls -sl -dag -ni -type mesh`; if(size($selectedObjects) == 0){ confirmDialog -title "提示" -message "\n您还没有选中模型或选中的不是多边形!\n" -button "确定" -defaultButton "确定"; return; }
string $object; for ($object in $selectedObjects) { string $uvSets[] = `polyUVSet -q -allUVSets $object`; if (size($uvSets) > 0) { string $firstUVSet = $uvSets[0]; if ($firstUVSet != "map1") { polyUVSet -rename -newUVSet "map1" -uvSet $firstUVSet $object; print ("已将 " + $object + " 的默认UV集重命名为 'map1'\n"); } else { print ($object + " 的第一个 UV 集已经是 'map1'。\n"); } } else { print ($object + " 没有 UV 集。\n"); } } print "三岁豆Er!重命名默认UV集成功!\n"; }
|