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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
| if (`window -exists uvToolWindow`) deleteUI uvToolWindow;
window -title "UV集检查修改工具" -sizeable false uvToolWindow; columnLayout -columnAttach "both" 10 -rowSpacing 8 -columnWidth 250;
text -h 40 -label "UV集检查与修改工具";
rowLayout -nc 2 -cw2 120 120 -adjustableColumn 2; button -label "选中多个UV集模型" -bgc 0.7 0.8 1 -height 35 -command "selectMultipleUVSetsModels"; button -label "删除多余UV集" -bgc 1 0.6 0.6 -height 35 -command "deleteExtraUVSets"; setParent ..;
rowLayout -nc 2 -cw2 120 120 -adjustableColumn 2; button -label " 选中非map1模型 " -bgc 0.7 1 0.7 -height 35 -command "selectNonDefaultUVModels"; button -label "重命名为map1" -bgc 1 0.9 0.6 -height 35 -command "renameFirstUVSetToMap1"; setParent ..;
rowLayout -nc 2 -cw2 120 120 -adjustableColumn 2; iconTextButton -style "iconAndTextHorizontal" -image "polyUVSetEditor.png" -bgc 0.5 0.9 0.6 -label "UV 集编辑器" -height 35 -command "UVSetEditor;"; button -label "中文字符UV集" -bgc 0.6 0.9 1 -height 35 -command "selectChineseUVSetModels"; setParent ..;
text -h 5 -label ""; showWindow uvToolWindow;
global proc selectMultipleUVSetsModels() { select -cl; string $allModels[] = `ls -g -type mesh`; int $found = 0; string $skippedModels[]; int $skippedCount = 0;
for ($model in $allModels) { string $uvSets[] = `polyUVSet -q -allUVSets $model`; if (size($uvSets) > 1) { int $isSequential = 1; for ($i = 0; $i < size($uvSets); $i++) { string $expectedName = "map" + ($i + 1); if ($uvSets[$i] != $expectedName) { $isSequential = 0; break; } } if ($isSequential) { $skippedModels[$skippedCount] = $model; $skippedCount++; } else { select -add $model; $found++; } } }
string $message = ""; if ($found == 0 && $skippedCount == 0) { $message = "没有找到具有多个UV集的模型。"; } else { if ($found > 0) { $message = "已选中 " + $found + " 个具有多个UV集的模型。\n"; } if ($skippedCount > 0) { $message += "以下模型因UV集符合map1, map2, map3...命名规律未被选中:\n"; for ($skippedModel in $skippedModels) { $message += " - " + $skippedModel + "\n"; } } } confirmDialog -title "提示" -message $message -button "确定"; }
global proc selectNonDefaultUVModels() { select -cl; string $allModels[] = `ls -g -type mesh`; int $found = 0;
for ($model in $allModels) { string $uvSets[] = `polyUVSet -q -allUVSets $model`; if (size($uvSets) > 0) { int $isSequential = 1; for ($i = 0; $i < size($uvSets); $i++) { string $expectedName = "map" + ($i + 1); if ($uvSets[$i] != $expectedName) { $isSequential = 0; break; } } if ($isSequential) { continue; } string $currentUVSet[] = `polyUVSet -q -currentUVSet $model`; if (size($currentUVSet) > 0 && $currentUVSet[0] != "map1") { select -add $model; $found++; } } }
string $message = ($found == 0) ? "未找到默认UV集不是 map1 的模型。" : ("已选中 " + $found + " 个默认UV集不是 map1 的模型。"); confirmDialog -title "提示" -message $message -button "确定"; }
global proc deleteExtraUVSets() { string $meshes[] = `ls -sl -dag -ni -type mesh`; if (size($meshes) == 0) { confirmDialog -title "提示" -message "请选择至少一个多边形模型。" -button "确定"; return; }
for ($mesh in $meshes) { string $uvSets[] = `polyUVSet -q -allUVSets $mesh`; if (size($uvSets) <= 1) continue;
for ($uvSet in $uvSets) { if ($uvSet != $uvSets[0]) { polyUVSet -delete -uvSet $uvSet $mesh; print ("删除UV集: " + $uvSet + "(模型:" + $mesh + ")\n"); } } }
print "多余UV集删除完毕。\n"; }
global proc renameFirstUVSetToMap1() { string $meshes[] = `ls -sl -dag -ni -type mesh`; if (size($meshes) == 0) { confirmDialog -title "提示" -message "请选择至少一个多边形模型。" -button "确定"; return; }
for ($mesh in $meshes) { string $uvSets[] = `polyUVSet -q -allUVSets $mesh`; if (size($uvSets) == 0) continue;
string $firstSet = $uvSets[0]; if ($firstSet != "map1") { polyUVSet -rename -uvSet $firstSet -newUVSet "map1" $mesh; print ("将 " + $mesh + " 的第一个UV集重命名为 map1\n"); } }
print "重命名完成。\n"; }
global proc selectChineseUVSetModels() { select -cl; string $allModels[] = `ls -g -type mesh`; int $found = 0;
for ($model in $allModels) { string $uvSets[] = `polyUVSet -q -allUVSets $model`; for ($uvSet in $uvSets) { int $charCount = `size($uvSet)`; int $hasChinese = 0; for ($i = 0; $i < $charCount; $i++) { string $char = `substring $uvSet ($i + 1) ($i + 1)`; int $charCode = `python("ord('" + $char + "')")`; if ($charCode >= 0x4E00 && $charCode <= 0x9FA5) { $hasChinese = 1; break; } } if ($hasChinese) { select -add $model; $found++; break; } } }
string $message = ($found == 0) ? "未找到包含中文字符的UV集的模型。" : ("已选中 " + $found + " 个包含中文字符UV集的模型。"); confirmDialog -title "提示" -message $message -button "确定"; }
|