Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- proc vector translatePolyInfoNormal( string $pin )
- {
- vector $normal;
- float $x;
- float $y;
- float $z;
- string $tokens[];
- int $numTokens = `tokenize $pin " " $tokens`;
- // Make sure we're looking at polyInfo data:
- if ( ( $numTokens > 3 ) && ( $tokens[0] == "FACE_NORMAL" ) )
- {
- // Maya performs data-type conversion here.
- $x = ($tokens[$numTokens-3]);
- $y = ($tokens[$numTokens-2]);
- $z = ($tokens[$numTokens-1]);
- $normal = << $x, $y, $z >>;
- // Normalize it.
- $normal = `unit $normal`;
- }
- // Return it.
- return $normal;
- }
- global string $XintFieldName="";
- global string $YintFieldName="";
- global string $ZintFieldName="";
- MainWindowUVPlacer;
- global proc MainWindowUVPlacer()
- {
- // check first for another instance of this window..
- if((`window -exists "MC UV Fixer"`) == true) {
- // ..if there is, close it
- deleteUI MainWindow;
- }
- // create the window
- createMainWindow("MC UV Fixer");
- }
- proc createMainWindow(string $name) {
- global string $XintFieldName;
- global string $YintFieldName;
- global string $ZintFieldName;
- // set our window sizes
- $windowHeight = 256;
- $windowWidth = 450;
- string $windowName = `window -widthHeight 300 200 -title $name $name`;
- frameLayout -l "MC UV Fixer" -mh 5 -mw 5;
- columnLayout -adjustableColumn true -columnAttach "both" 10;
- text -label "\nMenu" -align "center";
- separator -height 10;
- text -label "X Center";
- $XintFieldName = `intField -value 1`;
- text -label "Y Center";
- $YintFieldName = `intField -value 1`;
- text -label "Z Center";
- $ZintFieldName = `intField -value 1`;
- button -label "Fix UVs" -command start;
- showWindow $windowName;
- }
- global proc start(){
- global string $XintFieldName;
- global string $YintFieldName;
- global string $ZintFieldName;
- int $xm = `intField -query -value $XintFieldName`;
- int $ym = `intField -query -value $YintFieldName`;
- int $zm = `intField -query -value $ZintFieldName`;
- string $selection[] = `ls -sl`;
- select -r $selection.f["*"];
- string $faceList[] = `filterExpand -sm 34`;
- $nof = (size($faceList));
- $nofLoop = $nof - 1;
- print ("\nNum of faces is: " + $nof + "\n");
- select -r $selection ;
- string $xFace[];
- int $xI = 0;
- string $yFace[];
- int $yI = 0;
- string $zFace[];
- int $zI = 0;
- string $nxFace[];
- int $nxI = 0;
- string $nyFace[];
- int $nyI = 0;
- string $nzFace[];
- int $nzI = 0;
- for ($i=0;$i<=$nofLoop;$i=$i+1)
- {
- string $polyInfo[] = `polyInfo -faceNormals $faceList[$i]`;
- vector $normal = translatePolyInfoNormal($polyInfo[0]);
- if($normal.x > 0.5){
- $xFace[$xI] = $faceList[$i];
- $xI = $xI + 1;
- }
- if($normal.y > 0.5){
- $yFace[$yI] = $faceList[$i];
- $yI = $yI + 1;
- }
- if($normal.z > 0.5){
- $zFace[$zI] = $faceList[$i];
- $zI = $zI + 1;
- }
- if($normal.x < -0.5){
- $nxFace[$nxI] = $faceList[$i];
- $nxI = $nxI + 1;
- }
- if($normal.y < -0.5){
- $nyFace[$nyI] = $faceList[$i];
- $nyI = $nyI + 1;
- }
- if($normal.z < -0.5){
- $nzFace[$nzI] = $faceList[$i];
- $nzI = $nzI + 1;
- }
- }
- if(size($xFace) > 0){
- select -r $xFace;
- string $xProjection[] = `polyProjection -ch 1 -type Planar -ibd off -md x -pcx 1 -pcy 1 -pcz 1`;
- $proj = $xProjection[0];
- setAttr ($proj + ".projectionCenterX") $xm;
- setAttr ($proj + ".projectionCenterY") $ym;
- setAttr ($proj + ".projectionCenterZ") $zm;
- setAttr ($proj + ".projectionWidth") 2;
- setAttr ($proj + ".projectionHeight") 2;
- }
- if(size($yFace) > 0){
- select -r $yFace;
- string $yProjection[] = `polyProjection -ch 1 -type Planar -ibd off -md y -pcx 1 -pcy 1 -pcz 1`;
- $proj = $yProjection[0];
- setAttr ($proj + ".projectionCenterX") $xm;
- setAttr ($proj + ".projectionCenterY") $ym;
- setAttr ($proj + ".projectionCenterZ") $zm;
- setAttr ($proj + ".projectionWidth") 2;
- setAttr ($proj + ".projectionHeight") 2;
- }
- if(size($zFace) > 0){
- select -r $zFace;
- string $zProjection[] = `polyProjection -ch 1 -type Planar -ibd off -md z -pcx 1 -pcy 1 -pcz 1`;
- $proj = $zProjection[0];
- setAttr ($proj + ".projectionCenterX") $xm;
- setAttr ($proj + ".projectionCenterY") $ym;
- setAttr ($proj + ".projectionCenterZ") $zm;
- setAttr ($proj + ".projectionWidth") 2;
- setAttr ($proj + ".projectionHeight") 2;
- }
- if(size($nxFace) > 0){
- select -r $nxFace;
- string $nxProjection[] = `polyProjection -ch 1 -type Planar -ibd off -md x -pcx 1 -pcy 1 -pcz 1`;
- $proj = $nxProjection[0];
- setAttr ($proj + ".projectionCenterX") $xm;
- setAttr ($proj + ".projectionCenterY") $ym;
- setAttr ($proj + ".projectionCenterZ") $zm;
- setAttr ($proj + ".projectionWidth") 2;
- setAttr ($proj + ".projectionHeight") 2;
- setAttr ($proj + ".imageScaleU") -1;
- }
- if(size($nyFace) > 0){
- select -r $nyFace;
- string $nyProjection[] = `polyProjection -ch 1 -type Planar -ibd off -md y -pcx 1 -pcy 1 -pcz 1`;
- $proj = $nyProjection[0];
- setAttr ($proj + ".projectionCenterX") $xm;
- setAttr ($proj + ".projectionCenterY") $ym;
- setAttr ($proj + ".projectionCenterZ") $zm;
- setAttr ($proj + ".projectionWidth") 2;
- setAttr ($proj + ".projectionHeight") 2;
- setAttr ($proj + ".imageScaleU") -1;
- }
- if(size($nzFace) > 0){
- select -r $nzFace;
- string $nzProjection[] = `polyProjection -ch 1 -type Planar -ibd off -md z -pcx 1 -pcy 1 -pcz 1`;
- $proj = $nzProjection[0];
- setAttr ($proj + ".projectionCenterX") $xm;
- setAttr ($proj + ".projectionCenterY") $ym;
- setAttr ($proj + ".projectionCenterZ") $zm;
- setAttr ($proj + ".projectionWidth") 2;
- setAttr ($proj + ".projectionHeight") 2;
- setAttr ($proj + ".imageScaleU") -1;
- }
- select -r $selection ;
- print("Done!\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement