Created
March 24, 2017 12:37
-
-
Save nobolu-ootsuka-unrealengine/a8fa70aea7a7fe5bdde982a55a8ad9c4 to your computer and use it in GitHub Desktop.
AriUVGridding.mel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //-------------------------------------------------------------------------------------------------------- | |
| // | |
| // ScriptName : AriUVGridding | |
| // Contents : UVを格子状に整列。 | |
| // Author : Ari | |
| // URL : http://cgjishu.net/ | |
| // Since : 2015/02 | |
| // LastUpdate : 2016/11/20 1UV選択時の処理を高速化。Escで中断機能追加。 | |
| // : 2016/01/17 1UV選択の判定を、シェルの中で1UVのときに変更。 | |
| // : 2015/12/06 1UV選択のループ範囲が50程度で止まってしまっていたので修正。 | |
| // : 2015/11/29 1UV選択で整列機能を追加。 | |
| // | |
| //-------------------------------------------------------------------------------------------------------- | |
| proc int AriUVFromVertexRatioClassic(){ | |
| int $mode=1; | |
| return $mode; | |
| } | |
| proc vector AriUVVecChokkaku(vector $vec){ | |
| if(abs($vec.x) < abs($vec.y)){ | |
| if($vec.y>0) $vec=<<0,1,0>>; | |
| else $vec=<<0,-1,0>>; | |
| } | |
| else{ | |
| if($vec.x>0) $vec=<<1,0,0>>; | |
| else $vec=<<-1,0,0>>; | |
| } | |
| return $vec; | |
| } | |
| proc int Ari_checkSideUv(string $uv0,string $uv1) | |
| { | |
| string $uvToEdge[]=`polyListComponentConversion -te $uv0`; | |
| string $edgeToUv[]=`polyListComponentConversion -tuv $uvToEdge`; | |
| $edgeToUv=`filterExpand -selectionMask 35 $edgeToUv`; | |
| string $uvToFace[]=`polyListComponentConversion -tf $uv0`; | |
| string $faceToUv[]=`polyListComponentConversion -tuv $uvToFace`; | |
| $faceToUv=`filterExpand -selectionMask 35 $faceToUv`; | |
| if(stringArrayContains($uv1,$edgeToUv) && stringArrayContains($uv1,$faceToUv)){ | |
| return 1; | |
| } | |
| else return 0; | |
| } | |
| proc float Ari_distanceUV(string $uv0,string $uv1) | |
| { | |
| float $dis; | |
| float $uvPos0[]=`polyEditUV -q $uv0`; | |
| float $uvPos1[]=`polyEditUV -q $uv1`; | |
| $dis= ($uvPos1[0]-$uvPos0[0])*($uvPos1[0]-$uvPos0[0]) | |
| +($uvPos1[1]-$uvPos0[1])*($uvPos1[1]-$uvPos0[1]); | |
| $dis=sqrt ($dis); | |
| return $dis; | |
| } | |
| proc float Ari_distanceVer(string $ver1,string $ver2) | |
| { | |
| float $dis; | |
| float $verPos0[]=`pointPosition $ver1`; | |
| float $verPos1[]=`pointPosition $ver2`; | |
| $dis= ($verPos1[0]-$verPos0[0])*($verPos1[0]-$verPos0[0]) | |
| +($verPos1[1]-$verPos0[1])*($verPos1[1]-$verPos0[1]) | |
| +($verPos1[2]-$verPos0[2])*($verPos1[2]-$verPos0[2]); | |
| $dis=sqrt ($dis); | |
| return $dis; | |
| } | |
| proc float [] Ari_VectorMove(float $basePos[], float $dis,vector $vect) | |
| { | |
| float $vec[]={$vect.x,$vect.y,$vect.z}; | |
| float $newPos[3]; | |
| int $x=0; | |
| int $y=1; | |
| int $z=2; | |
| if($vec[$x]==0){ | |
| $x=1; | |
| $y=2; | |
| $z=0; | |
| if($vec[$x]==0){ | |
| $x=2; | |
| $y=0; | |
| $z=1; | |
| if($vec[$x]==0) return $basePos; | |
| } | |
| } | |
| $newPos[$x]= sqrt(($dis*$dis) / ( 1 + ($vec[$y]/$vec[$x])*($vec[$y]/$vec[$x]) + ($vec[$z]/$vec[$x])*($vec[$z]/$vec[$x]))); | |
| $newPos[$x]=($vec[$x]<0) ? $newPos[$x]*-1 : $newPos[$x]; | |
| $newPos[$y]= $newPos[$x] * $vec[$y]/$vec[$x]; | |
| $newPos[$z]= $newPos[$x] * $vec[$z]/$vec[$x]; | |
| $newPos[$x] =($basePos[$x] + $newPos[$x]); | |
| $newPos[$y] =($basePos[$y] + $newPos[$y]); | |
| $newPos[$z] =($basePos[$z] + $newPos[$z]); | |
| return $newPos; | |
| } | |
| proc float[] AriUVRatioMove (string $groupUV1[], string $groupUV2[],string $onlyUV[],int $mode){ | |
| float $uvDis_verDis[2]; | |
| vector $onlyUV_pos[]; | |
| vector $onlyUV_vec[]; | |
| for($i=0;$i<size($onlyUV);$i++){ | |
| float $pos[] =`polyEditUV -q $onlyUV[$i]`; | |
| $onlyUV_pos[$i]=<<$pos[0],$pos[1],$pos[2]>>; | |
| } | |
| if($mode!=0){ | |
| $j=0; | |
| for($i=0;$i<(size($onlyUV));$i=$i+2){ | |
| vector $vec = $onlyUV_pos[$i+1]-$onlyUV_pos[$i]; | |
| $vec = AriUVVecChokkaku($vec); | |
| if($mode==2)$vec=<<1,0,0>>; | |
| if($mode==3)$vec=<<0,1,0>>; | |
| if($mode==4)$vec=<<-1,0,0>>; | |
| if($mode==5)$vec=<<0,-1,0>>; | |
| $onlyUV_vec[$j]=$vec; | |
| $j++; | |
| } | |
| } | |
| float $uvDis[]; | |
| float $verDis[]; | |
| vector $uvBasePos1[]; | |
| vector $uvBasePos2[]; | |
| vector $uvVector[]; | |
| $j=0; | |
| for($i=0;$i<size($groupUV1);$i++){ | |
| $uvDis[$i]=Ari_distanceUV($groupUV1[$i],$groupUV2[$i]); | |
| string $vers[]; | |
| $vers =`polyListComponentConversion -tv $groupUV1[$i]`; | |
| $vers =`filterExpand -selectionMask 31 $vers`; | |
| string $ver1=$vers[0]; | |
| $vers =`polyListComponentConversion -tv $groupUV2[$i]`; | |
| $vers =`filterExpand -selectionMask 31 $vers`; | |
| string $ver2=$vers[0]; | |
| $verDis[$i]=Ari_distanceVer($ver1,$ver2); | |
| if($mode==0){ | |
| float $pos[]; | |
| $pos =`polyEditUV -q $groupUV1[$i]`; | |
| $uvBasePos1[$i]=<< $pos[0],$pos[1],$pos[2] >>; | |
| $pos =`polyEditUV -q $groupUV2[$i]`; | |
| $uvBasePos2[$i]=<< $pos[0],$pos[1],$pos[2] >>; | |
| $uvVector[$i]=$uvBasePos2[$i]-$uvBasePos1[$i]; | |
| } | |
| else{ | |
| $uvVector[$i]=$onlyUV_vec[$j/2]; | |
| if($onlyUV[$j+1]==$groupUV2[$i]){ | |
| $j=$j+2; | |
| } | |
| } | |
| } | |
| float $verDisTotal; | |
| float $uvDisTotal; | |
| for($i=0;$i<size($groupUV1);$i++){ | |
| $verDisTotal=$verDisTotal+$verDis[$i]; | |
| $uvDisTotal=$uvDisTotal+$uvDis[$i]; | |
| } | |
| for($i=0;$i<size($groupUV1);$i++){ | |
| vector $posVec=$uvBasePos1[$i]; | |
| vector $vecVec=$uvVector[$i]; | |
| float $moveDis=$uvDisTotal*$verDis[$i]/$verDisTotal; | |
| float $pos[] =`polyEditUV -q $groupUV1[$i]`; | |
| float $movePos[]= Ari_VectorMove($pos, $moveDis, $uvVector[$i]); | |
| polyEditUV -u $movePos[0] -v $movePos[1] -r false $groupUV2[$i]; | |
| } | |
| $uvDis_verDis[0]=$uvDisTotal; | |
| $uvDis_verDis[1]=$verDisTotal; | |
| return $uvDis_verDis; | |
| } | |
| proc string[] surroundingsUV(string $inputUV){ | |
| string $uvToEdge[] = `polyListComponentConversion -te $inputUV`; | |
| $uvToEdge = `filterExpand -selectionMask 32 $uvToEdge`; | |
| string $edgeToUV[] = `polyListComponentConversion -tuv $uvToEdge`; | |
| $edgeToUV = `filterExpand -selectionMask 35 $edgeToUV`; | |
| string $uvToFace[] = `polyListComponentConversion -tf $inputUV`; | |
| $uvToFace = `filterExpand -selectionMask 34 $uvToFace`; | |
| string $faceToUV[] = `polyListComponentConversion -tuv $uvToFace`; | |
| $faceToUV = `filterExpand -selectionMask 35 $faceToUV`; | |
| string $surroundingsUvList[]; | |
| int $i=0; | |
| for($uv in $edgeToUV){ | |
| if($uv != $inputUV){ | |
| if(stringArrayContains($uv, $faceToUV)){ | |
| $surroundingsUvList[$i] = $uv; | |
| $i++; | |
| } | |
| } | |
| } | |
| return $surroundingsUvList; | |
| } | |
| proc string nextUV(string $uv_base,string $uv_before){ | |
| string $uv_after; | |
| string $surroundingsUvList[]=(surroundingsUV($uv_base)); | |
| if(!stringArrayContains($uv_before,$surroundingsUvList))return ""; | |
| if(size($surroundingsUvList)!=3 && size($surroundingsUvList)!=4)return ""; | |
| string $uvToFase[] = `polyListComponentConversion -tf $uv_base`; | |
| $uvToFase = `filterExpand -selectionMask 34 $uvToFase`; | |
| if(size($surroundingsUvList)==4 && size($uvToFase)!=4)return ""; | |
| string $removeUVList[]=$surroundingsUvList; | |
| for($face in $uvToFase){ | |
| string $faceToUV[] = `polyListComponentConversion -tuv $face`; | |
| $faceToUV = `filterExpand -selectionMask 35 $faceToUV`; | |
| if(stringArrayContains($uv_before,$faceToUV)){ | |
| $removeUVList=stringArrayRemove($faceToUV, $removeUVList); | |
| } | |
| } | |
| $uv_after=$removeUVList[0]; | |
| return $uv_after; | |
| } | |
| proc string[] AriGetLoopUV(string $uv1,string $uv2){ | |
| int $limmiter=100000; | |
| string $loopUVList[]; | |
| int $i=0; | |
| string $loopUVList1[]; | |
| string $baseUV = $uv1; | |
| string $beforeUV = $uv2; | |
| string $afterUV; | |
| int $infiniteLoop = 0; | |
| $loopUVList1[0]=$uv2; | |
| $loopUVList1[1]=$uv1; | |
| $i=2; | |
| while($i<$limmiter){ | |
| $afterUV = nextUV($baseUV,$beforeUV); | |
| if($afterUV=="")break; | |
| if($infiniteLoop==1){ | |
| if($afterUV==$uv1){ | |
| $infiniteLoop=2; | |
| stringArrayRemoveAtIndex(($i-1), $loopUVList1); | |
| break; | |
| } | |
| else{ | |
| $infiniteLoop=0; | |
| } | |
| } | |
| if($infiniteLoop==0){ | |
| if($afterUV==$uv2){ | |
| $infiniteLoop=1; | |
| } | |
| } | |
| $loopUVList1[$i]=$afterUV; | |
| $i++; | |
| $beforeUV = $baseUV; | |
| $baseUV = $afterUV; | |
| } | |
| string $loopUVList2[]; | |
| if($infiniteLoop==0){ | |
| $baseUV = $uv2; | |
| $beforeUV = $uv1; | |
| $afterUV = ""; | |
| $i=0; | |
| while($i<$limmiter){ | |
| $afterUV = nextUV($baseUV,$beforeUV); | |
| if($afterUV=="")break; | |
| if($afterUV==$loopUVList2[0])break; | |
| $loopUVList2[$i]=$afterUV; | |
| $i++; | |
| $beforeUV = $baseUV; | |
| $baseUV = $afterUV; | |
| } | |
| } | |
| for($i=0;$i<size($loopUVList2);$i++){ | |
| $loopUVList[$i]=$loopUVList2[size($loopUVList2)-1-$i]; | |
| } | |
| for($i=0;$i<size($loopUVList1);$i++){ | |
| $loopUVList[size($loopUVList2)+$i]=$loopUVList1[$i]; | |
| } | |
| return $loopUVList; | |
| } | |
| proc string[] AriGetLoopUV_Single(string $inputUV){ | |
| string $loopUVList[]; | |
| int $i=0; | |
| string $surroundingsUvList[]=(surroundingsUV($inputUV)); | |
| for($surroundingsUv in $surroundingsUvList){ | |
| if(!stringArrayContains($surroundingsUv,$loopUVList)){ | |
| string $workloopUVList[] = AriGetLoopUV($inputUV,$surroundingsUv); | |
| $loopUVList=stringArrayCatenate($loopUVList, $workloopUVList ); | |
| } | |
| } | |
| return $loopUVList; | |
| } | |
| proc string[] AriUVFromVertexRatio_AriSelectUVLoop(string $selectUVList[]){ | |
| string $loopUVList[]; | |
| if(size($selectUVList)==1){ | |
| $loopUVList = AriGetLoopUV_Single($selectUVList[0]); | |
| } | |
| if(size($selectUVList)==2){ | |
| string $surroundingsUvList[]=(surroundingsUV($selectUVList[0])); | |
| if(stringArrayContains($selectUVList[1],$surroundingsUvList)){ | |
| $loopUVList = AriGetLoopUV($selectUVList[0],$selectUVList[1]); | |
| } | |
| else{ | |
| for($surroundingsUv in $surroundingsUvList){ | |
| string $workloopUVList[] = AriGetLoopUV($selectUVList[0],$surroundingsUv); | |
| if(stringArrayContains($selectUVList[1],$workloopUVList)){ | |
| int $i=0; | |
| int $startTrue=false; | |
| int $endTrue=false; | |
| string $workloopUVList2[]; | |
| clear $workloopUVList2; | |
| for($loopUV in $workloopUVList){ | |
| if($loopUV==$selectUVList[0] || $loopUV==$selectUVList[1]){ | |
| if($startTrue){ | |
| $workloopUVList2[$i] = $loopUV; | |
| $startTrue=false; | |
| } | |
| else{ | |
| $startTrue=true; | |
| } | |
| } | |
| if($startTrue){ | |
| $workloopUVList2[$i] = $loopUV; | |
| $i++; | |
| } | |
| } | |
| if(size($loopUVList)==0 || size($loopUVList)>size($workloopUVList2)){ | |
| $loopUVList=$workloopUVList2; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| return $loopUVList; | |
| } | |
| proc string[] AriUVFromVertexRatio_twoSelects(string $uvs[],int $mode){ | |
| string $groupUV1[]; | |
| string $groupUV2[]; | |
| float $beforePos[]=`polyEditUV -q $uvs[0]`; | |
| string $loopList[]=(AriUVFromVertexRatio_AriSelectUVLoop($uvs)); | |
| if(size($loopList)==0)return $loopList; | |
| for($i=0; $i<(size($loopList)-1); $i++){ | |
| $groupUV1[$i] = $loopList[$i]; | |
| $groupUV2[$i] = $loopList[$i+1]; | |
| } | |
| $onlyUV[0]=$loopList[0]; | |
| $onlyUV[1]=$loopList[size($loopList)-1]; | |
| float $distanceSet[2] = AriUVRatioMove($groupUV1,$groupUV2,$onlyUV,$mode); | |
| string $uvDis_verDis[]=$loopList; | |
| $uvDis_verDis[size($uvDis_verDis)] = $distanceSet[0]; | |
| $uvDis_verDis[size($uvDis_verDis)] = $distanceSet[1]; | |
| float $afterPos[]=`polyEditUV -q $uvs[0]`; | |
| polyEditUV -u ($beforePos[0]-$afterPos[0]) -v ($beforePos[1]-$afterPos[1]) -r true $loopList; | |
| return $uvDis_verDis; | |
| } | |
| proc string[] AriUVFromVertexRatio_oneSelects(string $uvs){ | |
| string $baseUV=$uvs; | |
| string $nextUV[]; | |
| float $basePos[]=`polyEditUV -q $baseUV`; | |
| string $uvToFace[] = `polyListComponentConversion -tf $baseUV`; | |
| $uvToFace=`filterExpand -selectionMask 34 $uvToFace`; | |
| string $faceToUv[]=`polyListComponentConversion -tuv $uvToFace[0]`; | |
| $faceToUv=`filterExpand -selectionMask 35 $faceToUv`; | |
| string $uvToEdge[]=`polyListComponentConversion -te $baseUV`; | |
| string $edgeToUv[]=`polyListComponentConversion -tuv $uvToEdge`; | |
| $edgeToUv=`filterExpand -selectionMask 35 $edgeToUv`; | |
| int $i=0; | |
| for($uv in $faceToUv){ | |
| if(stringArrayContains($uv, $edgeToUv)){ | |
| if($uv != $baseUV){ | |
| $nextUV[$i]=$uv; | |
| $i++; | |
| } | |
| } | |
| } | |
| string $uvList[]; | |
| $uvList[0]=$baseUV; | |
| $uvList[1]=$nextUV[0]; | |
| vector $pos0; | |
| vector $pos1; | |
| $pos0 =`polyEditUV -q $uvList[0]`; | |
| $pos1 =`polyEditUV -q $uvList[1]`; | |
| vector $vec=$pos0-$pos1; | |
| $vec = AriUVVecChokkaku($vec); | |
| int $mode1=0; | |
| if($vec==<< 1,0,0>>)$mode1=2; | |
| if($vec==<< 0,1,0>>)$mode1=3; | |
| if($vec==<<-1,0,0>>)$mode1=4; | |
| if($vec==<<0,-1,0>>)$mode1=5; | |
| string $uvDis_verDis1[] = AriUVFromVertexRatio_twoSelects($uvList,$mode1); | |
| if(size($uvDis_verDis1)==0)return $uvDis_verDis1; | |
| $uvList[1]=$nextUV[1]; | |
| $pos1 =`polyEditUV -q $uvList[1]`; | |
| $vec=$pos0-$pos1; | |
| $vec = AriUVVecChokkaku($vec); | |
| int $mode2=0; | |
| if($vec==<< 1,0,0>>)$mode2=2; | |
| if($vec==<< 0,1,0>>)$mode2=3; | |
| if($vec==<<-1,0,0>>)$mode2=4; | |
| if($vec==<<0,-1,0>>)$mode2=5; | |
| if($mode1==$mode2 || $mode1==$mode2+2 || $mode1==$mode2-2){ | |
| $mode2++; | |
| if($mode2==6)$mode2=2; | |
| } | |
| string $uvDis_verDis2[] = AriUVFromVertexRatio_twoSelects($uvList,$mode2); | |
| if(size($uvDis_verDis2)==0)return $uvDis_verDis2; | |
| string $uvList1[]; | |
| string $uvList2[]; | |
| for($i=0; $i<size($uvDis_verDis1)-2; $i++){ | |
| $uvList1[$i]=$uvDis_verDis1[$i]; | |
| } | |
| for($i=0; $i<size($uvDis_verDis2)-2; $i++){ | |
| $uvList2[$i]=$uvDis_verDis2[$i]; | |
| } | |
| string $loopUVList[]=stringArrayCatenate($uvList1,$uvList2); | |
| float $ver1_dis = float($uvDis_verDis1[size($uvDis_verDis1)-2]); | |
| float $uv1_dis = float($uvDis_verDis1[size($uvDis_verDis1)-1]); | |
| float $ver2_dis = float($uvDis_verDis2[size($uvDis_verDis2)-2]); | |
| float $uv2_dis = float($uvDis_verDis2[size($uvDis_verDis2)-1]); | |
| float $scale1 = ($uv1_dis + $uv2_dis) * ($ver1_dis / ($ver1_dis+$ver2_dis)) / $uv1_dis; | |
| float $scale2 = ($uv1_dis + $uv2_dis) * ($ver2_dis / ($ver1_dis+$ver2_dis)) / $uv2_dis; | |
| if($mode2==2 || $mode2==4) polyEditUV -pu $basePos[0] -pv $basePos[1] -su $scale1 -sv $scale2 $loopUVList; | |
| else polyEditUV -pu $basePos[0] -pv $basePos[1] -su $scale2 -sv $scale1 $loopUVList; | |
| return $loopUVList; | |
| } | |
| proc string[] AriUVGridding_AmFaceToUv(string $faceOne){ | |
| string $obj[]; | |
| tokenize $faceOne "." $obj; | |
| string $verList[]=`polyInfo -faceToVertex $faceOne`; | |
| string $vers[]; | |
| tokenizeList $verList[0] $vers; | |
| string $uvs[]=`polyListComponentConversion -toUV $faceOne`; | |
| string $uv[]=`filterExpand -selectionMask 35 $uvs`; | |
| string $verToUv[]; | |
| for ($x=0;$x<size($uv);$x++){ | |
| string $uvToVer[]=`polyListComponentConversion -toUV ($obj[0]+".vtx["+$vers[$x+2]+"]")`; | |
| $uvToVer=`filterExpand -selectionMask 35 $uvToVer`; | |
| for($Loop in $uvToVer){ | |
| for($uvLoop in $uv){ | |
| if($Loop==$uvLoop){ | |
| $verToUv[$x]=$Loop; | |
| } | |
| } | |
| } | |
| } | |
| return $verToUv; | |
| } | |
| proc int AriUVGridding_nearEq (float $a,float $b,float $nearVal){ | |
| if($a>=$b-$nearVal && $a<=$b+$nearVal){ | |
| return 1; | |
| } | |
| return 0; | |
| } | |
| proc string AriUVGridding_GO(string $face,string $selectUvList[],int $mode) | |
| { | |
| int $oldMode=false; | |
| string $null=""; | |
| string $uvs[]=`polyListComponentConversion -toUV $face`; | |
| string $uv[]=`filterExpand -selectionMask 35 $uvs`; | |
| if(size($uv)!=4)return $null; | |
| string $uvList[] = AriUVGridding_AmFaceToUv($face); | |
| float $uvPos[]; | |
| for($i=0;$i<4;$i++){ | |
| float $posWork[]=`polyEditUV -q $uvList[$i]`; | |
| $uvPos[$i*2 ]=$posWork[0]; | |
| $uvPos[$i*2+1]=$posWork[1]; | |
| } | |
| string $selectUv[]; | |
| if($oldMode){ | |
| string $selectObj[] = `ls -sl`; | |
| $selectUv = `filterExpand -selectionMask 35 $selectObj`; | |
| } | |
| else $selectUv = $selectUvList; | |
| string $unFixUv=""; | |
| int $prev; | |
| int $next; | |
| int $diago; | |
| for($this=0;$this<4;$this++){ | |
| $prev=$this-1; | |
| if($prev<=-1)$prev=3; | |
| $next=$this+1; | |
| if($next>=4)$next=0; | |
| $diago=$next+1; | |
| if($diago>=4)$diago=0; | |
| float $prevPos[2]; | |
| float $thisPos[2]; | |
| float $nestPos[2]; | |
| float $diagoPos[2]; | |
| $prevPos[0]=$uvPos[$prev*2]; | |
| $prevPos[1]=$uvPos[$prev*2+1]; | |
| $thisPos[0]=$uvPos[$this*2]; | |
| $thisPos[1]=$uvPos[$this*2+1]; | |
| $nextPos[0]=$uvPos[$next*2]; | |
| $nextPos[1]=$uvPos[$next*2+1]; | |
| $diagoPos[0]=$uvPos[$diago*2]; | |
| $diagoPos[1]=$uvPos[$diago*2+1]; | |
| float $near=0.00001; | |
| int $fixPattern=0; | |
| if( AriUVGridding_nearEq($prevPos[0],$thisPos[0],$near) ){ | |
| if( AriUVGridding_nearEq($thisPos[1],$nextPos[1],$near) ){ | |
| $unFixUv=$uvList[$diago]; | |
| $fixPattern=1; | |
| } | |
| } | |
| if( AriUVGridding_nearEq($prevPos[1],$thisPos[1],$near) ){ | |
| if( AriUVGridding_nearEq($thisPos[0],$nextPos[0],$near) ){ | |
| $unFixUv=$uvList[$diago]; | |
| $fixPattern=2; | |
| } | |
| } | |
| float $movePos[4]; | |
| if($unFixUv!=""){ | |
| if($fixPattern==1){ | |
| $movePos[0]=$nextPos[0]; | |
| $movePos[1]=$prevPos[1]; | |
| } | |
| if($fixPattern==2){ | |
| $movePos[0]=$prevPos[0]; | |
| $movePos[1]=$nextPos[1]; | |
| } | |
| if($movePos[0]==$diagoPos[0] && $movePos[1]==$diagoPos[1]){ | |
| return $null; | |
| } | |
| else{ | |
| if($mode==1 || stringArrayContains($unFixUv,$selectUv))polyEditUV -u $movePos[0] -v $movePos[1] -r false $unFixUv; | |
| $uvList[4]=$unFixUv; | |
| return $unFixUv; | |
| } | |
| } | |
| } | |
| return $null; | |
| } | |
| proc string[] AriUVGridding_L(int $mode){ | |
| global string $gMainProgressBar; | |
| global int $AriUVGridding_breakTrue; | |
| int $j=0; | |
| int $k=0; | |
| int $l=0; | |
| string $selectObj[]=`ls -sl -fl`; | |
| string $selectUv[] = $selectObj; | |
| string $faceList[] = `polyListComponentConversion -tf $selectObj`; | |
| $faceList = `filterExpand -selectionMask 34 $faceList`; | |
| if($mode==0)progressBar -edit -beginProgress -isInterruptable true -status "..." -maxValue (size($faceList)) $gMainProgressBar; | |
| string $deleteFaceList[]; | |
| int $dellCount=0; | |
| int $faceCount=0; | |
| int $totalProcessedFace=-1; | |
| string $processedUVList[]; | |
| string $processedFaceList[]; | |
| clear($processedUVList); | |
| clear($processedFaceList); | |
| for($m=0;$m<100000;$m++){ | |
| if($AriUVGridding_breakTrue)break; | |
| if($mode==0){ | |
| if(`progressBar -q -ic $gMainProgressBar`){ | |
| print("中断\n"); | |
| $AriUVGridding_breakTrue = true; | |
| break; | |
| } | |
| progressBar -e -pr $totalProcessedFace $gMainProgressBar; | |
| } | |
| if($totalProcessedFace == size($processedFaceList))break; | |
| $totalProcessedFace = size($processedFaceList); | |
| string $moveList[]; | |
| clear($moveList); | |
| $k=0; | |
| for($j=0; $j<size($faceList);$j++){ | |
| if(stringArrayContains($faceList[$j],$processedFaceList))continue; | |
| string $moveUV = AriUVGridding_GO($faceList[$j],$selectUv,0); | |
| if($moveUV!=""){ | |
| $processedUVList[$dellCount] = $moveUV; | |
| $dellCount++; | |
| $processedFaceList[$faceCount] = $faceList[$j]; | |
| $faceCount++; | |
| } | |
| } | |
| } | |
| if($mode==0) progressBar -e -endProgress $gMainProgressBar; | |
| return $processedUVList; | |
| } | |
| proc string[] AriUVGriddingOneGo(string $baseUV){ | |
| global string $gMainProgressBar; | |
| global int $AriUVGridding_breakTrue; | |
| string $returnList[]; | |
| string $processedUV[]; | |
| string $processedFace[]; | |
| string $processedEdge[]; | |
| string $nowFaceList[] = `polyListComponentConversion -tf $baseUV`; | |
| $nowFaceList = `filterExpand -selectionMask 34 $nowFaceList`; | |
| $processedFace = $nowFaceList; | |
| if(size($nowFaceList)<=4){ | |
| string $crossUV[]=AriUVFromVertexRatio_oneSelects($baseUV); | |
| if(size($crossUV)==0)return $returnList; | |
| $processedUV = $crossUV; | |
| select $baseUV; | |
| polySelectBorderShell 0; | |
| string $shellList[]=`ls -sl`; | |
| string $allFaceList[] = `polyListComponentConversion -tf $shellList`; | |
| $allFaceList = `filterExpand -selectionMask 34 $allFaceList`; | |
| progressBar -edit -beginProgress -isInterruptable true -status "..." -maxValue (size($allFaceList)) $gMainProgressBar; | |
| string $allComplateList[]; | |
| int $faceCounter = size($processedFace); | |
| int $uvCounter = size($processedUV); | |
| for($i=0; $i<100000; $i++){ | |
| if($AriUVGridding_breakTrue)break; | |
| progressBar -e -pr (size($processedFace)) $gMainProgressBar; | |
| for($face in $nowFaceList){ | |
| string $dummyString[]; | |
| string $moveUV = AriUVGridding_GO($face,$dummyString,1); | |
| if($moveUV!=""){ | |
| $processedUV[$uvCounter] = $moveUV; | |
| $uvCounter++; | |
| } | |
| } | |
| string $nextEdges[] = `polyListComponentConversion -te $nowFaceList`; | |
| $nextEdges = `filterExpand -selectionMask 32 $nextEdges`; | |
| $nextEdges = stringArrayRemove ($processedEdge, $nextEdges); | |
| $processedEdge = stringArrayCatenate ($processedEdge, $nextEdges); | |
| int $k=0; | |
| string $nextFaces[]; | |
| clear $nextFaces; | |
| for($edge in $nextEdges){ | |
| string $nextUVs[] = `polyListComponentConversion -tuv $edge`; | |
| $nextUVs = `filterExpand -selectionMask 35 $nextUVs`; | |
| if(size($nextUVs)!=2)continue; | |
| string $toFaces[] = `polyListComponentConversion -tf $edge`; | |
| $toFaces = `filterExpand -selectionMask 34 $toFaces`; | |
| for($toFace in $toFaces){ | |
| if(!stringArrayContains($toFace, $processedFace)){ | |
| $nextFaces[$k] = $toFace; | |
| $k++; | |
| $processedFace[$faceCounter] = $toFace; | |
| $faceCounter++; | |
| } | |
| } | |
| } | |
| $nowFaceList = $nextFaces; | |
| if(size($nowFaceList)==0)break; | |
| select $nowFaceList; | |
| if(`progressBar -q -ic $gMainProgressBar`){ | |
| print("中断\n"); | |
| $AriUVGridding_breakTrue = true; | |
| break; | |
| } | |
| } | |
| select $shellList; | |
| select -d $processedUV; | |
| $returnList = `ls -sl`; | |
| print (size($processedUV)+" UV Move\n"); | |
| progressBar -e -endProgress $gMainProgressBar; | |
| return $returnList; | |
| } | |
| } | |
| global proc AriUVGridding(){ | |
| print("Proc_00100_AriUVGridding() \n"); | |
| global int $AriUVGridding_breakTrue; | |
| float $startTime=`timerX`; | |
| $AriUVGridding_breakTrue = false; | |
| string $selectList[]=`ls -sl`; | |
| string $noMoveList[]; | |
| string $uvList[] = `polyListComponentConversion -tuv $selectList`; | |
| $uvList = `filterExpand -selectionMask 35 $uvList`; | |
| if(size($uvList)==0)return; | |
| polyEditUV -pu 0 -pv 0 -a 5.0 $uvList; | |
| string $copleteList[]=AriUVGridding_L(0); | |
| $noMoveList = stringArrayRemove($copleteList,$uvList); | |
| if(size($noMoveList)>0)polyEditUV -pu 0 -pv 0 -a -5.0 $noMoveList; | |
| int $k; | |
| string $processedUvList[]; | |
| string $nowShellUVList[]; | |
| int $shellTotal=0; | |
| for($i=0; $i<size($uvList); $i++){ | |
| if($AriUVGridding_breakTrue)break; | |
| if(stringArrayContains($uvList[$i],$processedUvList)){ | |
| continue; | |
| } | |
| select $uvList[$i]; | |
| polySelectBorderShell 0; | |
| string $shells[]=`ls -sl`; | |
| $shells=`filterExpand -selectionMask 35 $shells`; | |
| int $towUVTrue=false; | |
| for($j=$i+1; $j<size($uvList); $j++){ | |
| if(stringArrayContains($uvList[$j],$shells)){ | |
| $towUVTrue=true; | |
| $processedUvList[$k]=$uvList[$j]; | |
| $k++; | |
| } | |
| } | |
| if($towUVTrue!=1){ | |
| string $workUV[] = AriUVGriddingOneGo($uvList[$i]); | |
| string $bases[]; | |
| $bases[0]=$uvList[$i]; | |
| $noMoveList = stringArrayRemove($bases, $noMoveList); | |
| $noMoveList = stringArrayCatenate($noMoveList, $workUV); | |
| } | |
| } | |
| select $noMoveList; | |
| print (`timerX -st $startTime`+"\n"); | |
| if($AriUVGridding_breakTrue){ | |
| confirmDialog -m "中断しました "; | |
| } | |
| } | |
| AriUVGridding(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment