2015年2月11日水曜日

ウエイトエディット1.0更新


インフルエンス除外やインフルエンス追加はなんとなく危険なのでやめました。
ステップボタン追加
スライダーをいじっているときだけハンドルとラベルを3Dビューに表示するようにしました。
もうちょっとスライダーのバランス配分計算をいい感じにしたいんですがルールが思いつけば更新します。

global proc yjp_weightedit_balance(int $num)
{
    global float $yjp_weightedit_float[];
    float $val[],$total;
    int $c = 0;
    float $holdfloat = 0.0;
    float $changeval[];
    float $a,$v;
    string $joint,$label;
    int $n,$count[];
    int $m =1;
    string $control[] = `rowColumnLayout -q -ca yjp_WeightEditQueueLayout`;
    //ホールド状態の処理
    for ($n=0;$n<size($control);$n += 5)
    {
        $count[$c] = 0;
        $val[$c] = `floatSliderGrp -q -v $control[$n+2]`;
     
        if(`checkBox -q -v $control[$n]`)
        {
            //ホールド
            $holdfloat += $val[$c];
        }
        else if($num == $c)
        {
            $joint = `floatSliderGrp -q -l $control[$n+2]`;
            setAttr ($joint + ".type") 18;
            setAttr ($joint + ".drawLabel") 1;
            setAttr ($joint + ".displayHandle") 1;
            //動かしたスライダ
            $holdfloat += $val[$c];
        }
        else
        {
            //変化させるスライダ
            $count[$c] = 1;
            if($val[$c] < 0.01)
            {
                $val[$c] = 0.1;
            }
            $v += $val[$c];
        }
        $c++;
    }
    $total = 1 - $holdfloat;
 
    //print ("total " + $total +"\n");
 
    $a = $total / $v;
 
    for ($c=0;$c<size($val);$c++)
    {
        if($count[$c])
        {
            $val[$c] = $val[$c]*$a;
        }
        //print ("val " + $val[$c] +"\n");
    }
    $c = 0;
    for ($n=0;$n<size($control);$n += 5)
    {
        if($num == $c || `checkBox -q -v $control[$n]`){}
        else
        {
            $yjp_weightedit_float[$c] = $val[$c];
            floatSliderGrp -e -fmx $total -v $val[$c] $control[$n+2];
        }
        $c++;
    }

    if(`checkBox -q -v yjp_weightedit_ac`)
    {
        yjp_weightedit_apply;
    }
}

global proc yjp_weightedit_apply()
{
    string $vtxArray[] = `ls -sl`;
    if(size($vtxArray) == 0)return ;
    string $node[];
    tokenize $vtxArray[0] "." $node;
    string $sc = `findRelatedSkinCluster $node[0]`;
    string $control[] = `rowColumnLayout -q -ca yjp_WeightEditQueueLayout`;
    string $SkinScript,$jointList_out;
    float $weight;
    int $n;
 
        for( $n=0 ; $n<size($control); $n += 5 )
        {
            $weight = `floatSliderGrp -q -v $control[$n+2]`;
            $jointList_out = `floatSliderGrp -q -l $control[$n+2]`;
            $SkinScript += ( "-tv " + $jointList_out + " " + $weight + " " );
        }
        if( $SkinScript != "" )
        {
         
            for ($n=0;$n<size($vtxArray);$n++)
            {
                undoInfo -swf off;
                $SkinScript = ("skinPercent " + $SkinScript + $sc + " " + $vtxArray[$n] );
                eval( $SkinScript );
                print ($SkinScript +"\n");
                undoInfo -swf on;
            }
         
        }
}

global proc yjp_weightedit_get()
{
    string $node[];
    string $sourcevtxArray[] = `ls -sl`;
    string $window[] = `rowColumnLayout -q -ca yjp_WeightEditQueueLayout`;
    if(size($window))deleteUI $window;
    if(size($sourcevtxArray) == 0)return ;
    if(!`gmatch $sourcevtxArray[0] "*.vtx*"`)return ;
 
    global float $yjp_weightedit_float[];
        tokenize $sourcevtxArray[0] "." $node;
        string $sourcobj = $node[0];
        string $scA = `findRelatedSkinCluster $sourcobj`;

        //print ($sourcobj + " sourcobj " + $scA + "\n") ;

        int $n,$i;
        float $weight[];
    string $jointList[];

        $weight = `skinPercent -ib 0.00001 -q -v $scA $sourcevtxArray[0]`;
        $jointList = `skinPercent -ib 0.00001 -q -t $scA $sourcevtxArray[0]`;
     
    int $bool;

    string $labeltxt = "";
    float $step = `floatField -q -v yjpWeigtEditStepField`;

    for ($n=0 ; $n < size($jointList) ; $n++)
    {
        getAttr ($jointList[$n] + ".objectColor");
        $yjp_weightedit_float[$n] = $weight[$n];
        $bool = `getAttr ($jointList[$n] + ".lockInfluenceWeights")`;
        $labeltxt = `getAttr ($jointList[$n] + ".otherType")`;
        checkBox -w 30 -l "" -v $bool -p yjp_WeightEditQueueLayout -cc ("yjp_weightedit_Hold " + $n);
        textField -w 80 -tx $labeltxt -p yjp_WeightEditQueueLayout -cc ("yjp_weightedit_JointLabel " + $n);
        floatSliderGrp -w 320 -p yjp_WeightEditQueueLayout -cw 1 70 -cw 2 40 -cw 3 200 -cw 4 200 -label $jointList[$n] -field true
        -minValue 0 -maxValue 1.0
        -fieldMinValue 0 -fieldMaxValue 1.0
        -s $step
        -ss $step
        -dc ("yjp_weightedit_balance " + $n)
        -cc ("yjp_weightedit_JointUnhilite " + $n)
        -value $weight[$n];
        button -w 20 -l "<" -p yjp_WeightEditQueueLayout -c ("yjp_weightedit_step -1 " + $n);
        button -w 20 -l ">" -p yjp_WeightEditQueueLayout -c ("yjp_weightedit_step 1 " + $n);
    }
}
global proc yjp_weightedit_step(int $di,int $num)
{
    string $control[] = `rowColumnLayout -q -ca yjp_WeightEditQueueLayout`;
    int $c =0;
    for ($n=0;$n<size($control);$n += 5)
    {
        if($c == $num)
        {
            float $val = `floatField -q -v  yjpWeigtEditStepField` ;
            $val = $val * $di;
            $val += `floatSliderGrp -q -v $control[$n+2]`;
            floatSliderGrp -e -v $val $control[$n+2];
        }
        $c++;
    }
    yjp_weightedit_balance $num;
}
global proc yjp_weightedit_Reset()
{
    global float $yjp_weightedit_float[];

    string $control[] = `rowColumnLayout -q -ca yjp_WeightEditQueueLayout`;
    int $n;
    int $c =0;

    for ($n=0;$n<size($control);$n += 5)
    {
        floatSliderGrp -e -v $yjp_weightedit_float[$c] $control[$n+2];
        $c++;
    }
    yjp_weightedit_apply;
}
global proc yjp_weightedit_Hold(int $num)
{
    string $control[] = `rowColumnLayout -q -ca yjp_WeightEditQueueLayout`;
    int $n;
    int $c =0;
    string $joint;
    for ($n=0;$n<size($control);$n += 5)
    {
         if($c == $num)
        {
            //ホールド
            $joint = `floatSliderGrp -q -l $control[$n+2]`;
            if(`getAttr ($joint + ".lockInfluenceWeights")` == 0)
            {
                checkBox -e -v 1 $control[$n];
                floatSliderGrp -e -en 0 $control[$n+2];
                button -e -en 0 $control[$n+3];
                button -e -en 0 $control[$n+4];
                setAttr ($joint + ".lockInfluenceWeights") 1;
            }
            else
            {
                checkBox -e -v 0 $control[$n];
                floatSliderGrp -e -en 1 $control[$n+2];
                button -e -en 1 $control[$n+3];
                button -e -en 1 $control[$n+4];
                setAttr ($joint + ".lockInfluenceWeights") 0;
            }
        }
        $c++;
    }
}
global proc yjp_weightedit_JointLabel(int $num)
{
    int $n;
    int $c = 0;
    string $control[] = `rowColumnLayout -q -ca yjp_WeightEditQueueLayout`;
    for ($n=0;$n<size($control);$n += 5)
    {
        if($c == $num)
        {
            string $label = `textField -q-tx $control[$n+1]`;
            string $joint = `floatSliderGrp -q -l $control[$n+2]`;
            setAttr ($joint + ".type") 18;
            $labeltxt = `setAttr -type "string" ($joint + ".otherType") $label`;
        }
        $c++;
    }
}
global proc yjp_weightedit_JointUnhilite(int $num)
{
    int $n;
    int $c = 0;
    string $control[] = `rowColumnLayout -q -ca yjp_WeightEditQueueLayout`;
    for ($n=0;$n<size($control);$n += 5)
    {
        string $joint = `floatSliderGrp -q -l $control[$n+2]`;
        setAttr ($joint + ".drawLabel") 0;
        setAttr ($joint + ".displayHandle") 0;
    }
}
global proc yjp_WeightEdit()
{
    if(`window -q -ex yjp_WeightEditwindow`) deleteUI yjp_WeightEditwindow;
    window -s 1 -t "WeightEdit" yjp_WeightEditwindow;
    string $no = "";
 
    columnLayout -adjustableColumn true;
        rowColumnLayout -nc 8 -cw 1 60 -cw 2 35 -cw 3 50 -cw 4 60 -cw 5 60 -cw 6 60 -cw 7 60 -cw 8 60;
            checkBox -w 40 -l "Auto" -v 0 yjp_weightedit_ac;
            text -l "snap";
            floatField -w 50 -v 0.01 yjpWeigtEditStepField ;
            button -h 25 -w 60 -l "Get_vtx" -c "yjp_weightedit_get";
            button -h 25 -w 60 -l "Reset" -c "yjp_weightedit_Reset";
            button -h 25 -w 60 -l "apply" -c "yjp_weightedit_apply" ;
            button -h 25 -w 60 -l "Close" -c ("deleteUI -window yjp_WeightEditwindow;");
        setParent ..;
        rowColumnLayout -nc 5 -cw 1 40 -cw 2 60 -cw 3 100 -cw 4 240 -cw 5 40 ;
            text -l "Hold";
            text -l "Label";
            text -l "Joint";
            text -l "Value";
            text -l "step";
        setParent ..;
    scrollLayout -horizontalScrollBarThickness 16 -verticalScrollBarThickness 16 -h 400 yjp_WeightEditscrollLayout;
        rowColumnLayout -nc 5 -cw 1 30 -cw 2 80 -cw 3 320 -cw 4 20 -cw 5 20 yjp_WeightEditQueueLayout;
        setParent ..;
        setParent ..;
    setParent ..;
    window -e -wh 485 180 yjp_WeightEditwindow;
    showWindow yjp_WeightEditwindow;
    yjp_weightedit_get;
}

0 件のコメント:

コメントを投稿