UV传递工具
Maya进行UV传递的方法有很多种,Maya自带的功能也能实现。我还是习惯使用插件实现传递。
第一种
来自小静的UV传递插件
作者主页:https://smilejing.cn/
进行了界面上的小优化,功能没动,使用更加方便。也是最简单的UV传递方法,选择正确UV的模型,加选需要传递给的模型,点击执行即可完成传递。
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
| ////////////批量传递UV工具/////////////
global proc callUvOneToN() { string $objSel[] = `ls -sl`; int $numSel = size($objSel); if ($numSel <= 1) { confirmDialog -title "Message" -message "至少选择两个物体" -button "OK" -defaultButton "OK"; return; } string $source = $objSel[$numSel-1]; string $str = ""; int $i; for ($i=0; $i<$numSel-1; $i++) { polyTransfer -vc 0 -uv 1 -v 0-ao $source $objSel[$i]; } }
if(`window -ex FY_tool_3UV`) deleteUI FY_tool_3UV;
window -title "批量传递UV工具" -sizeable 0 -tlb 0 FY_tool_3UV; columnLayout -columnAttach "both" 10 -rowSpacing 5 -columnWidth 300; text -h 30 -l ""; text -fn "boldLabelFont" -l "选择所有物体,UV将会以最后选择的物体为准"; text -h 30-l ""; button -l "传递" -h 30 -bgc 0.45 0.55 0.27 -c "callUvOneToN()"; text -h 20 -l ""; setParent ..; showWindow FY_tool_3UV;
|
第二种
插件来源:老船动画吧
第一种传递方法固然方便,但是功能比较单一,就需要这个进阶版的UV传递工具。我个人也是进行了一些界面上的小优化,功能没有改动。这个工具可以实现多个模型一块选定一次性传递多个模型的UV。
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 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
| global proc gtUVtransforWin(){ if(`window -ex gtUVtransforWin`) deleteUI -window gtUVtransforWin; if(`windowPref -ex gtUVtransforWin`) windowPref -r gtUVtransforWin; window -title "UV传递工具" -sizeable 0 gtUVtransforWin;
columnLayout -columnAttach "both" 10 -rowSpacing 5 -columnWidth 350; text -h 10 -label""; radioButtonGrp -cw3 100 100 100 -numberOfRadioButtons 2 -l "层级方式:" -la2 "选择的物体:" "所有子层级" -sl 1 gtUVRad; radioButtonGrp -cw3 100 100 100 -numberOfRadioButtons 2 -l "判断方式:" -la2 "顶点数量:" "当前位置" -sl 1 gtUVcondition;
rowColumnLayout -nc 2 -cw 1 240 -cw 2 100 ;
textFieldGrp -l "编辑好UV的模型:" -text "" -ed 0 -cw2 100 120 gtUVobj; button -l "载入模型" -c "gtUVtransforProcLoad" gtUVBut;
setParent..; separator -style double; rowColumnLayout -nc 3 -cw 1 168 -cw 2 4 -cw 3 168 ;;
button -l "等数量传递UV" -c "gtUVtransforProc" gtIntsecoundBnButA; text -l ""; button -l "一对N传递UV" -c "gtUVtransforProcA" gtIntsecoundBnButAA;
setParent..; separator -style double; text -l "可以载入全部编辑好UV的多变形模型,或者一个" -bgc 0.38 0.38 0.38 -h 50 gtVexSameNum; text -h 5 -label""; showWindow gtUVtransforWin; }
gtUVtransforWin;
global proc gtUVtransforProcLoad(){ int $condition=`radioButtonGrp -q -sl gtUVcondition`; string $sel[]=`ls -sl`; string $name=""; string $nameE=""; if($condition==1){ for($j=0;$j<size($sel);$j++){ select -r $sel; select -d $sel[$j]; int $tempvex[]=`polyEvaluate -v $sel[$j]`; string $tempSel[]=`ls -sl`; for($i=0;$i<size($tempSel);$i++){ int $tempvexa[]=`polyEvaluate -v $tempSel[$i]`; if($tempvexa[0]==$tempvex[0])$nameE+=$tempSel[$i]+" "; } }
string $mm[]; if($nameE!=""){ int $num=`tokenize $nameE " " $mm`; select -r $sel; select -d ($mm); text -e -bgc 0.3 0 0 -l ($nameE+":\n当前选择的这些模型顶点数量相同\n无法自动识别对应物体,请逐个传递UV数据") gtVexSameNum; }else{ select -r $sel; text -e -bgc 0.1 0.2 0 -l ("所有选择的模型全部载入到输入框中") gtVexSameNum; } string $nam[]=`ls -sl`; for($i=0;$i<size($nam);$i++){ $name+=$nam[$i]+" "; }
textFieldGrp -e -tx ($name) gtUVobj; if($nameE!=""){ select -r ($mm); }else{ select -r $nam; } }else{ string $nam[]=`ls -sl`; for($i=0;$i<size($nam);$i++){ $name+=$nam[$i]+" "; }
textFieldGrp -e -tx ($name) gtUVobj; text -e -bgc 0.1 0.2 0 -l ("所有选择的模型全部载入到输入框中") gtVexSameNum; } }
global proc gtUVtransforProcAA() { string $sel[]=`ls -sl -l`; string $unDoObj[]; string $targetO= `textFieldGrp -q -tx gtUVobj`; int $style=`radioButtonGrp -q -sl gtUVRad`; string $mm[]; int $tm=`tokenize $targetO " " $mm`; string $targetObj[]; for($i=0;$i<size($mm);$i++){ $targetObj[$i]=$mm[$i]; } if($style==2){ select -cl; for($i=0;$i<size($sel);$i++){ string $objMm[]=`listRelatives -c -ad -type "mesh" $sel[$i]`; select -add $objMm; } string $objMesh[]=`ls -sl -type "mesh"`; string $objAll[]; for($i=0;$i<size($objMesh);$i++){ string $temp[]=`listRelatives -p $objMesh[$i]`; $objAll[$i]=$temp[0];
} select -r $objAll; string $objM[]=`ls -type "transform" -sl`; select -r $objM; select -d $targetObj; } string $objMeshT[]=`ls -sl`; for($i=0;$i<size($objMeshT);$i++){ string $obj=$objMeshT[$i]; int $objV[]=`polyEvaluate -v $obj`; string $oldObj=""; for($j=0;$j<size($targetObj);$j++){ int $objVe[]=`polyEvaluate -v $targetObj[$j]`; if($objV[0]==$objVe[0]) $oldObj=$targetObj[$j]; } if($oldObj==""){ int $undoS=size($unDoObj); $unDoObj[$undoS] =$obj; }else{ string $inputs[]= `listHistory $obj`; int $skin=0; for($ii=3;$ii<size($inputs);$ii++){ string $type=`nodeType ($inputs[$ii])`; if($type=="tweak")$skin=1; } if($skin==1){ string $targetShape[]= `listRelatives -shapes $obj`; string $targetOrigin = ($targetShape[1]); select -r $targetOrigin ; setAttr ($targetOrigin +".intermediateObject") 0; select -r $oldObj; select -add $targetOrigin ; transferAttributes -transferPositions 0 -transferNormals 0 -transferUVs 2 -transferColors 0 -sampleSpace 5 -sourceUvSpace "map1" -targetUvSpace "map1" -searchMethod 3-flipUVs 0 -colorBorders 1 ; select -r $targetOrigin; DeleteHistory; setAttr ($targetOrigin +".intermediateObject") 1; select -d; } if($skin==0){ select -r $oldObj; select -add $obj ; transferAttributes -transferPositions 0 -transferNormals 0 -transferUVs 2 -transferColors 0 -sampleSpace 5 -sourceUvSpace "map1" -targetUvSpace "map1" -searchMethod 3 -flipUVs 0 -colorBorders 1 ; select -r $obj; DeleteHistory; } } } int $undoS=size($unDoObj); if($undoS>0){ string $unDoO=""; for($i=0;$i<$undoS;$i++){ $unDoO+=$unDoObj[$i]+"、"; } text -e -bgc 0.3 0 0 -l ($unDoO+":\n当前选择的模型没有对应目标模型\n请手动查找,并逐个传递UV数据") gtVexSameNum; select -r $unDoObj; clear $unDoObj; }else{ text -e -bgc 0.1 0.3 0 -l ("当前选择的模型全部完成传递UV数据操作") gtVexSameNum; select -r $objMeshT; } }
global proc gtUVtransforProcBB() { string $sel[]=`ls -sl -l`; string $unDoObj[]; string $targetO= `textFieldGrp -q -tx gtUVobj`; int $style=`radioButtonGrp -q -sl gtUVRad`; string $mm[]; int $tm=`tokenize $targetO " " $mm`; string $targetObj[]; for($i=0;$i<size($mm);$i++){ $targetObj[$i]=$mm[$i]; }
if($style==2){ select -cl; for($i=0;$i<size($sel);$i++){ string $objMm[]=`listRelatives -c -ad -type "mesh" $sel[$i]`; select -add $objMm; } string $objMesh[]=`ls -sl -type "mesh"`; string $objAll[]; for($i=0;$i<size($objMesh);$i++){ string $temp[]=`listRelatives -p $objMesh[$i]`; $objAll[$i]=$temp[0];
} select -r $objAll; string $objM[]=`ls -type "transform" -sl`; select -r $objM; select -d $targetObj; } string $objMeshT[]=`ls -sl`; for($i=0;$i<size($objMeshT);$i++){ string $obj=$objMeshT[$i]; float $posA[]=`xform -q -ws -t ($obj+".vtx[0]")`; string $oldObj=""; float $dis=1000000; for($j=0;$j<size($targetObj);$j++){ float $posB[]=`xform -q -ws -t ($targetObj[$j]+".vtx[0]")`; float $cdis=mag(<<$posA[0],$posA[1],$posA[2]>>-<<$posB[0],$posB[1],$posB[2]>>); if($cdis<$dis){ $dis=$cdis; $oldObj=$targetObj[$j]; } }
if($oldObj==""){ int $undoS=size($unDoObj); $unDoObj[$undoS] =$obj; }else{ string $inputs[]= `listHistory $obj`; int $skin=0; for($ii=3;$ii<size($inputs);$ii++){ string $type=`nodeType ($inputs[$ii])`; if($type=="tweak")$skin=1; } if($skin==1){ string $targetShape[]= `listRelatives -shapes $obj`; string $targetOrigin = ($targetShape[1]); select -r $targetOrigin ; setAttr ($targetOrigin +".intermediateObject") 0; select -r $oldObj; select -add $targetOrigin ; transferAttributes -transferPositions 0 -transferNormals 0 -transferUVs 2 -transferColors 0 -sampleSpace 5 -sourceUvSpace "map1" -targetUvSpace "map1" -searchMethod 3-flipUVs 0 -colorBorders 1 ; select -r $targetOrigin; DeleteHistory; setAttr ($targetOrigin +".intermediateObject") 1; select -d; } if($skin==0){ select -r $oldObj; select -add $obj ; transferAttributes -transferPositions 0 -transferNormals 0 -transferUVs 2 -transferColors 0 -sampleSpace 5 -sourceUvSpace "map1" -targetUvSpace "map1" -searchMethod 3 -flipUVs 0 -colorBorders 1 ; select -r $obj; DeleteHistory; } } } int $undoS=size($unDoObj); if($undoS>0){ string $unDoO=""; for($i=0;$i<$undoS;$i++){ $unDoO+=$unDoObj[$i]+"、"; } text -e -bgc 0.3 0 0 -l ($unDoO+":\n当前选择的模型没有对应目标模型\n请手动查找,并逐个传递UV数据") gtVexSameNum; select -r $unDoObj; clear $unDoObj; }else{ text -e -bgc 0.1 0.3 0 -l ("当前选择的模型全部完成传递UV数据操作") gtVexSameNum; select -r $objMeshT; } }
global proc gtUVtransforProc() { int $condition=`radioButtonGrp -q -sl gtUVcondition`; if($condition==1) gtUVtransforProcAA; else gtUVtransforProcBB; }
global proc gtUVtransforProcA(){ string $targetO= `textFieldGrp -q -tx gtUVobj`; int $ex=`objExists $targetO`; if($ex==0)error "请载入一个编辑好UV的多边形物体名称"; int $style=`radioButtonGrp -q -sl gtUVRad`; string $sel[]=`ls -sl`; if($style==2){ select -cl; for($i=0;$i<size($sel);$i++){ string $objMm[]=`listRelatives -c -ad -type "mesh" $sel[$i]`; select -add $objMm; } string $objMesh[]=`ls -sl -type "mesh"`; string $objAll[]; for($i=0;$i<size($objMesh);$i++){ string $temp[]=`listRelatives -p $objMesh[$i]`; $objAll[$i]=$temp[0]; } select -r $objAll; string $objM[]=`ls -type "transform" -sl`; select -r $objM; select -d $targetO; } string $objMeshT[]=`ls -sl`; int $numA=size($objMeshT); string $notMatchM[]; clear $notMatchM; for($i=0;$i<size($objMeshT);$i++){ string $obj=$objMeshT[$i]; string $shap[]=`listRelatives -s $obj`; $ex=`objExists $shap[0]`; string $type; if($ex!=0)$type=`nodeType $shap[0]`;
if($type!="mesh"){ print ($obj+":不是多边形物体!"); }else{ int $objV[]=`polyEvaluate -v $obj`; string $oldObj=$targetO; int $objVe[]=`polyEvaluate -v $oldObj`;
if($objV[0]!=$objVe[0]){ int $nsize=size($notMatchM); $notMatchM[$nsize]=$obj; }else{ string $inputs[]= `listHistory $obj`; int $skin=0; for($ii=0;$ii<size($inputs);$ii++){ string $type=`nodeType ($inputs[$ii])`; if($type=="tweak")$skin=1; } if($skin==1){ string $targetShape[]= `listRelatives -shapes $obj`; string $targetOrigin = ($targetShape[1]); select -r $targetOrigin ; setAttr ($targetOrigin +".intermediateObject") 0; select -r $oldObj; select -add $targetOrigin ; transferAttributes -transferPositions 0 -transferNormals 0 -transferUVs 2 -transferColors 0 -sampleSpace 5 -sourceUvSpace "map1" -targetUvSpace "map1" -searchMethod 3-flipUVs 0 -colorBorders 1 ; select -r $targetOrigin; DeleteHistory; setAttr ($targetOrigin +".intermediateObject") 1; select -d; } if($skin==0){ select -r $oldObj; select -add $obj ; transferAttributes -transferPositions 0 -transferNormals 0 -transferUVs 2 -transferColors 0 -sampleSpace 5 -sourceUvSpace "map1" -targetUvSpace "map1" -searchMethod 3 -flipUVs 0 -colorBorders 1 ; select -r $obj; DeleteHistory; } } int $nsize=size($notMatchM); if($nsize==0){ text -e -bgc 0.1 0.3 0 -l ("当前选择的模型全部完成传递UV数据操作") gtVexSameNum; select -r $objMeshT; }else{ string $noeOM=""; for($i=0;$i<$nsize;$i++) $noeOM+=($notMatchM[$i]+"、"); text -e -bgc 0.1 0.3 0 -l ("当前选择的模型中:"+$noeOM+"这些模型顶点不匹配,没有传递UV数据操作") gtVexSameNum; select -r $notMatchM; } } } }
|