码迷,mamicode.com
首页 > 其他好文 > 详细

Maya批量传递UV插件

时间:2016-01-03 00:21:58      阅读:349      评论:0      收藏:0      [点我收藏+]

标签:

之前写的关于Maya批量传递UV的小插件。在传递大量模型的UV属性时可用,免得一个一个去Transfer Attribute。列表可编辑,便于多次分步进行模型选择和传递。

技术分享

英文界面版: http://pan.baidu.com/s/1o7fYgsU

中文界面版:http://pan.baidu.com/s/1gdUbgJp

附源码:

//The Plug-in of batch UVs Transfer 
//Script by @Mullin
//Date Dec, 14th, 2015

string $toSendList[];
clear $toSendList;
string $unfoldedOBJ;
$unfoldedOBJ = "";

//Function for the tip and attention windows
global proc wrong(int $WrongNum)
{
    string $TextSay = "";
    
    if($WrongNum==1)
        $TextSay = "Please select polygon objects.";
    
    if($WrongNum==2)
        $TextSay = "Please select one polygon object.";
    
    if($WrongNum==3)
        $TextSay = "You haven‘t selected an unfolded object.";
    
    if($WrongNum==4)
        $TextSay = "You haven‘t selected object(s) to transfer UVs.";
        
    if($WrongNum==5)
    $TextSay = "Don‘t transfer UVs to itself.";
    
    if($WrongNum==0)
        $TextSay = "Batch UVs transfer finished.";
    
    if(`window -ex wrong`)
        deleteUI wrong;

    window -title "Tips" wrong ;
        rowColumnLayout -rowAttach 1 "both" 18 -columnAttach 1 "both" 50;
        text -label $TextSay;
        setParent ..;
    showWindow wrong;

    window -edit -widthHeight 350 60 -s 0 wrong;
}
//The command function for the UV_unfolded_OBJ button  
global proc loadUVunfolded(){
    global string $unfoldedOBJ;
    
    string $selectList[] = `filterExpand -sm 12`;
    $numSelect = size ($selectList);
    if ($numSelect == 0){
        wrong(1);
        $unfoldedOBJ = "";
    }
       
    if ($numSelect >=2){
        wrong(2);
        $unfoldedOBJ = "";
    }
    
    if ($numSelect == 1){
        $unfoldedOBJ = $selectList[0];
    }
    
    textField -e -text $unfoldedOBJ loadUnfoldedOBJ;
}

//The command function for the plus("+") button
global proc listAdd(){
    global string $toSendList[];
    string $selectList[] = `filterExpand -sm 12`;
    $numSelect = size ($selectList);
    for($i=0; $i<$numSelect ; ++$i) {
        if (stringArrayContains($selectList[$i], $toSendList)==0 ){
            stringArrayInsertAtIndex(1, $toSendList, $selectList[$i]);
            textScrollList -e -append $selectList[$i] toSendScroll;
        }
    }

    textScrollList -e -deselectAll toSendScroll;
    $numToSend = size($toSendList);
    string $textInTotal = "objects to transfer UVs ( " + $numToSend + " in total ):";
    text -e -label $textInTotal textTotal;
    scriptJob -e "SelectionChanged" "highlightSelected";
}

//The command function for the remove("-") button
global proc listSub(){
    global string $toSendList[];

    //the selection from the list to the scene 
    select -r `textScrollList -query -selectItem toSendScroll`;
    string $selectList[] = `filterExpand -sm 12`;

    //remove the item from the list and the array 
    $toSendList = stringArrayRemove($selectList,$toSendList);
    $numSelect = size($selectList);
    for($i=0; $i<$numSelect ; ++$i) {
        textScrollList -e -removeItem $selectList[$i] toSendScroll;
    }
    $numToSend = size($toSendList);
    string $textInTotal = "objects to transfer UVs ( " + $numToSend + " in total ):";
    text -e -label $textInTotal textTotal;
}

//The "Clear" button function
global proc listClear(){
     global string $toSendList[];
     clear $toSendList;
     textScrollList -e -removeAll toSendScroll;
     text -e -label "objects to transfer UVs ( 0 in total ):" textTotal;
}

//Use the scriptJob to highlight the item selected from the scene,
//which makes you select the list item more obviously
global proc highlightSelected() {
    global string $toSendList[];
    string $selectList[] = `filterExpand -sm 12`;
    $numSelect = size($selectList);
    textScrollList -e -deselectAll toSendScroll;
    for ($i=0; $i<$numSelect ; ++$i){
        int $found = stringArrayContains($selectList[$i], $toSendList);
        if($found) {
            textScrollList -e -selectItem $selectList[$i] toSendScroll;
        }
    }
}

//The command function of the button "Transfer", the core proc of this plug-in
global proc transferCommand(){
    global string $unfoldedOBJ;
    global string $toSendList[];
    $numToSend = size($toSendList);
    if ($unfoldedOBJ == ""){
        wrong(3);
        return;
    }
    
    if ($numToSend == 0){
        wrong(4);
        return;
    }
    
    for ($i=0; $i<$numToSend; ++$i){
        //if you transfer attribute to the object itself,
        //Maya will report error and stop the procedure
        if ($unfoldedOBJ == $toSendList[$i]){
            wrong(5);
        }
        else {
            select -r $unfoldedOBJ ;
            select -tgl $toSendList[$i] ;
            transferAttributes 
                -transferPositions 0 
                -transferNormals 0 
                -transferUVs 2 
                -transferColors 2 
                -sampleSpace 4 
                -sourceUvSpace "map1" 
                -targetUvSpace "map1" 
                -searchMethod 3
                -flipUVs 0 
                -colorBorders 1 ;
            wrong(0);
        }
    }
}

//To kill the scriptJob SelectionChanged after the window closed
global proc closeWindow(){
    scriptJob -killAll;
}

//The main window 
global proc mainWindow_UV_Transfer(){
    
    if(`window -query -exists UV_Transfer`){
        deleteUI UV_Transfer;
    }

window -title "Batch UV Transfer" UV_Transfer;

rowColumnLayout
    -numberOfColumns 1
    -rowAttach 1 "top" 20
    -columnAttach 1 "both" 25
    -columnWidth 1 300;
    
          
    rowColumnLayout
        -columnWidth 1 150
        -columnWidth 2 100
        -numberOfColumns 2;
    
        textField
            -text ""
            -editable 0
            loadUnfoldedOBJ;
    
        button 
            -label "Load Unfolded"
            -c loadUVunfolded;
    
        setParent ..; 

    separator -height 10 -st "none";

    rowColumnLayout;
        
        text -label "Objects to transfer UVs ( 0 in total ):" textTotal;
    
        setParent ..;   
    
    textScrollList
        -height 270
        -allowMultiSelection true
        toSendScroll;
        
    rowColumnLayout
        -columnWidth 1 100
        -columnWidth 2 100
        -columnWidth 3 50
        -numberOfColumns 3;

        button
            -label "+"
            -c  listAdd;
            
        button 
            -label "-"
            -c listSub;
            
        button 
            -label "Clear"
            -c listClear;
       
        setParent ..;
    
    separator  -height 15 -st "none";
    
    button  
        -label "Transfer"
        -c transferCommand;
     
showWindow UV_Transfer;

window 
    -edit
    -widthHeight 300 440 
    -s 0 
    UV_Transfer;
    
scriptJob -uiDeleted UV_Transfer closeWindow -protected;
}

mainWindow_UV_Transfer;

 

Maya批量传递UV插件

标签:

原文地址:http://www.cnblogs.com/mullin/p/5095451.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!