2015年2月10日火曜日

ウエイトエディター

1頂点のウエイトのインフルエンスをスライダーでリスト表示

やっと出来ました。

一応テキトウに値1を保つようにスライダーが動きます
ホールドもポチポチできます
Autoにチェックしてスライダーを動かすとリアルタイムでウエイトの変化が見れて気持ちがいい。
インフルエンスの追加や削除ができればいいナーとボタンだけ用意してます。

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 += 4)
    {
        $count[$c] = 0;
        $val[$c] = `floatSliderGrp -q -v $control[$n+2]`;
        if(`checkBox -q -v $control[$n]`)
        {
            //ホールド
            $holdfloat += $val[$c];
        }
        else if($num == $c)
        {
            //動かしたスライダ
            $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 += 4)
    {
        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+=4 )
        {
            $weight = `floatSliderGrp -q -v $control[$n+2]`;
            $jointList_out = `floatSliderGrp -q -l $control[$n+2]`;
            $SkinScript += ( "-tv " + $jointList_out + " " + $weight + " " );
        }
        if( $SkinScript != "" )
        {
            $SkinScript = ("skinPercent " + $SkinScript + $sc + " " + $vtxArray[0] );
            eval( $SkinScript );
            print ($SkinScript +"\n");
        }
}

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++)
    {
        $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 220 -label $jointList[$n] -field true
        -minValue 0 -maxValue 1.0
        -fieldMinValue 0 -fieldMaxValue 1.0
        -s $step
        -dc ("yjp_weightedit_balance " + $n)
        -value $weight[$n];
        button -en 0 -w 30 -l "Del"     -p yjp_WeightEditQueueLayout  ;
    }
}

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 += 4)
    {
        floatSliderGrp -e -v $yjp_weightedit_float[$c] $control[$n+2];
        $c++;
    }
}
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 += 4)
    {
         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];
                setAttr ($joint + ".lockInfluenceWeights") 1;
            }
            else
            {
                checkBox -e -v 0 $control[$n];
                floatSliderGrp -e -en 1 $control[$n+2];
                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 += 4)
    {
        if($c == $num)
        {
            string $label = `textField -q-tx $control[$n+1]`;
            string $joint = `floatSliderGrp -q -l $control[$n+2]`;
            $labeltxt = `setAttr -type "string" ($joint + ".otherType") $label`;
        }
        $c++;
    }
}
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 -en 0-h 25 -w 60 -l "Add_joint" ;
            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 "Delete";
        setParent ..;
    scrollLayout -horizontalScrollBarThickness 16 -verticalScrollBarThickness 16 -h 400 yjp_WeightEditscrollLayout;
        rowColumnLayout -nc 4 -cw 1 30 -cw 2 80 -cw 3 320 -cw 4 30 yjp_WeightEditQueueLayout;
        setParent ..;
        setParent ..;
    setParent ..;
    window -e -wh 485 180 yjp_WeightEditwindow;
    showWindow yjp_WeightEditwindow;
    yjp_weightedit_get;
}

0 件のコメント:

コメントを投稿