2015年3月22日日曜日

ポーズコピーペースト

ボーナスツールの改造版
ノードの種類を指定してコピーできます。
ビジビリティもコピーするか設定できます。
UVスクロールはシーン内の全てをコピーします。
シェルフはそのままペーストしますが、
PosePasteはペーストされるノードを調べてからペーストします。

//GetTextStringLine.melつかってます
global proc yjp_PosePaste()
{
    string $PExportPath = `internalVar -usd`;
    int $n;
    string $cmd[] = `GetTextStringLine ($PExportPath + "/pose.txt")`;
    for ($n=0;$n<size($cmd);$n++)
    {
        string $buffer[];
        int $c = 0;
        tokenize $cmd[$n] " .;" $buffer;
        print ("cmd " + $cmd[$n] + "\n") ;
        if(`objExists $buffer[2]`)
        {
            string $atlist[] = `listAttr -keyable -connectable -unlocked -scalar -write -hd  $buffer[2]`;
                if(stringArrayCount($buffer[3], $atlist) > 0)
            {
            eval $cmd[$n];
            }
        }
        else
        {
            print ("no obj " +  $buffer[1] + "\n") ;
        }
     
    }

    print ("ポーズペースト終了" + "\n") ;
 
}
global proc yjp_PoseCopy(int $mode)
{
    string $node[];
    if(`radioButtonGrp -q -sl PoseCopyRBG` == 1)
    {
    if(`checkBox -q -v UseUVanimCB`)
    {
    $node =`ls -type "transform" -type "place2dTexture"`;
    }
    else
    {
    $node =`ls -type "transform"`;
    }
    }
    else if(`radioButtonGrp -q -sl PoseCopyRBG` == 2)
    {
    if(`checkBox -q -v UseUVanimCB`)
    {
        $node =`ls -type "transform" -type "place2dTexture" -sl`;
    }
    else
    {
    $node =`ls -type "transform" -sl`;
    }
    }
    else if(`radioButtonGrp -q -sl PoseCopyRBG` == 3)
    {
    select -hi;
        $node =`ls -type "transform" -sl`;
    if(`checkBox -q -v UseUVanimCB`)
    {
    $pt =`ls -type "place2dTexture" `;
    $node = stringArrayCatenate($node, $pt);
    }
    }
    int $n;
global string $gShelfTopLevel;
    string $script,$text;
int $writable;
string $command = "";

    int $ti = `currentTime -q`;

for ($item in $node)
{
string $attlist[] ;
clear $attlist;
if(`nodeType $item` == "transform")
{
//print ("mseh " + $item +"\n");
string $cnode[] = `listRelatives -c -s -f $item`;
if(size($cnode) > 0)
{
if(`nodeType $cnode[0]` == "mesh" && `checkBox -q -v MeshOnlyCB`)
{
//print ("mseh " + $item +"\n");
if(`checkBox -q -v UseVisibilityCB`)
{
$attlist = `listAttr -keyable -connectable -unlocked -scalar -write -hd -st "translate?" -st "rotate?" -st "scale?" -st "visibility" $item`;
}
else
{
$attlist = `listAttr -keyable -connectable -unlocked -scalar -write -hd -st "translate?" -st "rotate?" -st "scale?" $item`;
}

}
else if(`nodeType $cnode[0]` == "mesh" && !`checkBox -q -v MeshOnlyCB` && `checkBox -q -v UseVisibilityCB`)
{
$attlist = `listAttr -keyable -connectable -unlocked -scalar -write -hd -st "visibility" $item`;
}
else if(`nodeType $cnode[0]` == "locator" && `checkBox -q -v locatorOnlyCB`)
{
if(`checkBox -q -v UseVisibilityCB`)
{
$attlist = `listAttr -keyable -connectable -unlocked -scalar -write -hd -st "translate?" -st "rotate?" -st "scale?" -st "visibility" $item`;
}
else
{
$attlist = `listAttr -keyable -connectable -unlocked -scalar -write -hd -st "translate?" -st "rotate?" -st "scale?" $item`;
}
}
}
else if(`checkBox -q -v groupOnlyCB` && `checkBox -q -v UseVisibilityCB`)
{
$attlist = `listAttr -keyable -connectable -unlocked -scalar -write -hd -st "visibility" $item`;
}
}
else if(`nodeType $item` == "joint" && `checkBox -q -v JointOnlyCB`)
{
//print ("joint " + $item +"\n");
$attlist = `listAttr -keyable -connectable -unlocked -scalar -write -hd -st "translate?" -st "rotate?" -st "scale?" $item`;
}
else if(`nodeType $item` == "place2dTexture" && `checkBox -q -v UseUVanimCB`)
{
//print ("UV " + $item +"\n");
$attlist = `listAttr -keyable -connectable -unlocked -scalar -write -hd -st "offset?" -st "translateFrame?" $item`;
}
//Step through list of appropriate attributes for each object
if (size($attlist)>0){
for ($att in $attlist)
{
$match = ("match \"\\\\.\"  " + $att);
//print $match;


if ( `eval $match` != "." )   //if not a compound
{
                //
// Check for input connections to current attr
$input = `listConnections -source 1 ($item + "." + $att)`;
if (`size $input` == 0)
{
$writable = 1;  //if no connections
}
else
{
if (`nodeType $input[0]` == "character")
{
$writable = 1;  //if connected to character set
}
else
{
$writable = `isAnimCurve $input[0]`;  //check for anim curves
}
}


if ($writable)
{
// add to command list for shelf button and print to script editor
float $val = `getAttr ($item + "." + $att)`;
$text = ("setAttr -clamp " + $item + "." + $att + " " + $val + ";\n");
print ($text);
$command = ($command+$text);
}

else

{
// if locked by connection only print warning to script editor
$text = ($item + "." + $att + " : locked by input connection");
warning ($text);
}
}
}
}
}

    if($mode == 1)
    {
//make shelf button containing list of setAttrs
$buttonName = $ti;
if (`tabLayout -exists $gShelfTopLevel`)
{
shelfButton
-parent ($gShelfTopLevel + "|" + `tabLayout -q -st $gShelfTopLevel`)
-command ($command)
-image "createPose.png"
-iol $buttonName
-label $buttonName
-annotation $buttonName ;
}
else
error ("Must have active shelf to create shelf button");
       //textToShelf ($ti, $text);
}
    if($mode == 0)
    {
        string $PExportPath = `internalVar -usd`;
        int $PFile;
        $PFile =`fopen ($PExportPath + "/pose.txt") "w"`;
        fprint ($PFile, "//\r\n");
        fprint ($PFile, $command);
        fclose ($PFile);
    }
    print ("ポーズコピー終了" + "\n") ;
    return ;
}

global proc yjp_PoseCopyPaste()
{
    if(`window -q -ex yjp_PoseCopyPaste`)
    {
        deleteUI yjp_PoseCopyPaste ;
    }
    window -wh 210 200 -tb 1 -tlb 0 -t "PoseCopyPaste" yjp_PoseCopyPaste ;
    columnLayout -w 130;
    radioButtonGrp
        -nrb 3
        -la3 "All" "Select" "Hierarchy"
        -sl 1
        -cw3 40 50 60 PoseCopyRBG;
    rowColumnLayout -nc 4;

        checkBox -label "mesh" -value true MeshOnlyCB;

        checkBox -label "Joint" -value true JointOnlyCB;

checkBox -label "group" -value true groupOnlyCB;
checkBox -label "locator" -value true locatorOnlyCB;

        checkBox -label "Visibility" -value true UseVisibilityCB;
        checkBox -label "UVanim" -value true UseUVanimCB;
     setParent ..;
    rowColumnLayout -nc 4;
        button -w 80 -h 25 -l "PoseCopyShelf" -c "yjp_PoseCopy 1" ;
        button -w 60 -h 25 -l "PoseCopy" -c "yjp_PoseCopy 0";
        button -w 60 -h 25 -l "PosePaste" -c "yjp_PosePaste" ;

    setParent ..;
    showWindow yjp_PoseCopyPaste ;
    window -e -wh 230 90 yjp_PoseCopyPaste ;
}

0 件のコメント:

コメントを投稿