以前作ったyjp_DuplicateMeshSkinで
バインドされたメッシュを加工し、ヒストリーを消す時にyjp_DuplicateMeshSkinを使う事で
ウエイトが崩れずに済むと聞いて試したら本当に大丈夫だった。
でも中間オブジェクトが複数出来てしまうと・・
見てみると複数できている。
yjp_DetachBindShelfで再バインドしてみると中間オブジェクトを消す処理でエラーが発生している
ちょっと調べてみよう。
2015年2月28日土曜日
2015年2月23日月曜日
yjp_WeightSymmetry1.2更新
yjp_WeightSymmetryのコピー方向が安定していなかったので修正
YZのミラーコピーは実装していないが記述では少し残っています。
/*
yjp_WeightSymmetry1.2
ウエイトミラーです。
重なっているジョイントのみアトリビュートでラベル名をつけてください。
対称ジョイントが同じラベル名になるようにしてください。
バインドフレームはデフォルト0ですがバインド時のポーズがあるフレームを指定してください
ノーマルマッチは左右対称頂点を検索する時に法線が似ている頂点を探します。
アナザーメッシュ欄は何もなければ選択した頂点のメッシュ内で対称にします
対称のオブジェゲットをすればそのメッシュから対称の頂点を探します。
左右半分のどちらかの頂点を選んでから←→どちらかのボタンを選びます。
*/
yjp_WeightSymmetryが使用しているプロシージャ
//yjp_pMatchSwapArray.mel
//yjp_WeightTransfer.mel
//yjp_jontMirrorArray.mel
global proc yjp_doWeightSymmetry(int $dir)
{
string $vetx[] = `ls -sl -fl`;
if(size($vetx) < 1 )return;
int $t = `currentTime -q` ;
int $nmc = `checkBox -q -v wsNormalMatcheCheck`;
int $wsbf = `intFieldGrp -q -value1 wsBindFrameField`;
int $oo = 0;
currentTime $wsbf ;
string $node[];
tokenize $vetx[0] "." $node;
//選択した頂点のオブジェクト
string $sourcobj = $node[0];
//参照オブジェクト
string $Allvtx[];
$obj = `textFieldGrp -q -tx yjp_wsAnothermeshField`;
if(`objExists $obj`)
{
$Allvtx = `ls -fl ($obj + ".vtx[*]")`;
}
else
{
$Allvtx = `ls -fl ($sourcobj + ".vtx[*]")`;
}
//中心を指定
float $center[] = {0,0,0};
int $ax;
int $d[] = {1,1,1};
int $dirax;
/*
$center[0] = `floatFieldGrp -q -value1 WeightSymmetryCenterField`;
$center[1] = `floatFieldGrp -q -value2 WeightSymmetryCenterField`;
$center[2] = `floatFieldGrp -q -value3 WeightSymmetryCenterField`;
*/
//選択した頂点の位置を中心からどちらか調べる
float $Vertex[] = `pointPosition $vetx[0]`;
switch ($dir)
{
case 0:
case 1:
$ax = 0;
$dirax = 1;
if($Vertex[0] > $center[0])
{
$d[0] = -1;
}
else
{
if($dir == 1)
{
$dir = 0;
}
else
{
$dir = 1;
}
}
break;
case 2:
case 3:
if($Vertex[1] > $center[1])$d[1] = -1;
$ax = 1;
$dirax = 2;
break;
case 4:
case 5:
if($Vertex[2] > $center[2])$d[2] = -1;
$ax = 2;
$dirax = 3;
break;
}
//print ("d " + $d[0] + $d[1] + $d[2] + "\n") ;
//print ("ax " + $ax + "\n") ;
//print ("dirax "+ $dirax + "\n") ;
float $VertexValueA[];
float $VertexValueB[];
string $Swapvtx[];
//対称の頂点のみのグループにする
for ($n=0;$n<size($Allvtx);$n++)
{
$VertexValueA = `pointPosition $Allvtx[$n]`;
if ($d[$ax] == 1)
{
if($VertexValueA[$ax] > $center[$ax])
{
$Swapvtx[size($Swapvtx)] = $Allvtx[$n];
//print ($VertexValueA[$ax] + " " + $Allvtx[$n] +"\n");
}
}
else if ($d[$ax] == -1)
{
//print ("VertexValueA "+ $dirax + "\n") ;
if($VertexValueA[$ax] < $center[$ax])
{
$Swapvtx[size($Swapvtx)] = $Allvtx[$n];
//print ($VertexValueA[$ax] + " " + $Allvtx[$n] +"\n");
}
}
}
if(size($Swapvtx)==0)
{
print ("対称の頂点がありません" +"\n");
return ;
}
$Swapvtx = `yjp_pMatchSwapArray $Swapvtx $vetx $dirax 1 $nmc`;
string $vtxGrA[] = $vetx;
string $vtxGrB[] = $Swapvtx;
if ($dir == 0)
{
//print ("X<<"+$vtxGrA[0] +" "+$vtxGrB[0] +"\n\n");
yjp_WeightTransfer $vtxGrB $vtxGrA 1;
select -r $vtxGrB;
//print ($vtxGrB[0] +"\n");
}
else
{
//print ("X>>"+$vtxGrB[0] +" "+$vtxGrA[0] +"\n\n");
yjp_WeightTransfer $vtxGrA $vtxGrB 1;
select -r $vtxGrA;
//print ($vtxGrA[0] +"\n");
}
currentTime $t ;
return ;
}
global proc yjp_WeightSymmetryObjGet(int $input)
{
if($input == 1)
{
string $sel[] = `ls -sl`;
if(size($sel)==1)
{
textFieldGrp -e -tx $sel[0] yjp_wsAnothermeshField;
}
}
else if($input == 0)
{
textFieldGrp -e -tx "" yjp_wsAnothermeshField;
}
}
/*
global proc yjp_WeightSymmetryCenter()
{
string $selobj[] = `ls -sl`;
if(`size$selobj` == 0){return ;}
float $vc[] = `xform -q -a -ws -t $selobj[0]`;
floatFieldGrp -e -value1 $vc[0] -value2 $vc[1] -value3 $vc[2] WeightSymmetryCenterField;
}
*/
global proc yjp_WeightSymmetry()
{
if(`window -q -ex yjp_WeightSymmetryWindow`)
{
deleteUI yjp_WeightSymmetryWindow ;
}
window -tb 1 -tlb 0 -t "WeightSymmetry1.2" yjp_WeightSymmetryWindow ;
columnLayout ;
rowColumnLayout -nc 2 -cw 1 220 -cw 2 96;
/*
floatFieldGrp -numberOfFields 3
-label "center"
-cw3 60 60 60
-value1 0.0 -value2 0.0 -value3 0.0 WeightSymmetryCenterField;
button -w 50 -label "center" -ann "選択した頂点から対称座標を入力" -command "yjp_WeightSymmetryCenter";
*/
intFieldGrp -numberOfFields 1
-label "BindFrame"
-cw 1 70
-value1 0 wsBindFrameField;
checkBox -l "NormalMatche" -ann "法線が似ている頂点を探す" -v 0 wsNormalMatcheCheck;
setParent..;
rowColumnLayout -nc 3 -cw 1 220 -cw 2 48 -cw 3 48;
textFieldGrp -label "Another mesh" -cw2 70 140 yjp_wsAnothermeshField;
button -label "ObjGet" -ann "別のメッシュとシンメトリする" -command "yjp_WeightSymmetryObjGet 1";
button -label "CLEAR" -ann "Another mesh欄を消す" -command "yjp_WeightSymmetryObjGet 0";
setParent..;
rowColumnLayout -nc 2 -cw 1 158 -cw 2 158;
button -h 30 -l "X←" -c "yjp_doWeightSymmetry 0";
button -h 30 -l "X→" -c "yjp_doWeightSymmetry 1";
setParent..;
//button -w 130 -h 25 -l "Close" -c ("deleteUI -window WeightSymmetryWindow") ;
setParent..;
showWindow yjp_WeightSymmetryWindow ;
window -e -wh 320 82 yjp_WeightSymmetryWindow ;
}
YZのミラーコピーは実装していないが記述では少し残っています。
/*
yjp_WeightSymmetry1.2
ウエイトミラーです。
重なっているジョイントのみアトリビュートでラベル名をつけてください。
対称ジョイントが同じラベル名になるようにしてください。
バインドフレームはデフォルト0ですがバインド時のポーズがあるフレームを指定してください
ノーマルマッチは左右対称頂点を検索する時に法線が似ている頂点を探します。
アナザーメッシュ欄は何もなければ選択した頂点のメッシュ内で対称にします
対称のオブジェゲットをすればそのメッシュから対称の頂点を探します。
左右半分のどちらかの頂点を選んでから←→どちらかのボタンを選びます。
*/
yjp_WeightSymmetryが使用しているプロシージャ
//yjp_pMatchSwapArray.mel
//yjp_WeightTransfer.mel
//yjp_jontMirrorArray.mel
global proc yjp_doWeightSymmetry(int $dir)
{
string $vetx[] = `ls -sl -fl`;
if(size($vetx) < 1 )return;
int $t = `currentTime -q` ;
int $nmc = `checkBox -q -v wsNormalMatcheCheck`;
int $wsbf = `intFieldGrp -q -value1 wsBindFrameField`;
int $oo = 0;
currentTime $wsbf ;
string $node[];
tokenize $vetx[0] "." $node;
//選択した頂点のオブジェクト
string $sourcobj = $node[0];
//参照オブジェクト
string $Allvtx[];
$obj = `textFieldGrp -q -tx yjp_wsAnothermeshField`;
if(`objExists $obj`)
{
$Allvtx = `ls -fl ($obj + ".vtx[*]")`;
}
else
{
$Allvtx = `ls -fl ($sourcobj + ".vtx[*]")`;
}
//中心を指定
float $center[] = {0,0,0};
int $ax;
int $d[] = {1,1,1};
int $dirax;
/*
$center[0] = `floatFieldGrp -q -value1 WeightSymmetryCenterField`;
$center[1] = `floatFieldGrp -q -value2 WeightSymmetryCenterField`;
$center[2] = `floatFieldGrp -q -value3 WeightSymmetryCenterField`;
*/
//選択した頂点の位置を中心からどちらか調べる
float $Vertex[] = `pointPosition $vetx[0]`;
switch ($dir)
{
case 0:
case 1:
$ax = 0;
$dirax = 1;
if($Vertex[0] > $center[0])
{
$d[0] = -1;
}
else
{
if($dir == 1)
{
$dir = 0;
}
else
{
$dir = 1;
}
}
break;
case 2:
case 3:
if($Vertex[1] > $center[1])$d[1] = -1;
$ax = 1;
$dirax = 2;
break;
case 4:
case 5:
if($Vertex[2] > $center[2])$d[2] = -1;
$ax = 2;
$dirax = 3;
break;
}
//print ("d " + $d[0] + $d[1] + $d[2] + "\n") ;
//print ("ax " + $ax + "\n") ;
//print ("dirax "+ $dirax + "\n") ;
float $VertexValueA[];
float $VertexValueB[];
string $Swapvtx[];
//対称の頂点のみのグループにする
for ($n=0;$n<size($Allvtx);$n++)
{
$VertexValueA = `pointPosition $Allvtx[$n]`;
if ($d[$ax] == 1)
{
if($VertexValueA[$ax] > $center[$ax])
{
$Swapvtx[size($Swapvtx)] = $Allvtx[$n];
//print ($VertexValueA[$ax] + " " + $Allvtx[$n] +"\n");
}
}
else if ($d[$ax] == -1)
{
//print ("VertexValueA "+ $dirax + "\n") ;
if($VertexValueA[$ax] < $center[$ax])
{
$Swapvtx[size($Swapvtx)] = $Allvtx[$n];
//print ($VertexValueA[$ax] + " " + $Allvtx[$n] +"\n");
}
}
}
if(size($Swapvtx)==0)
{
print ("対称の頂点がありません" +"\n");
return ;
}
$Swapvtx = `yjp_pMatchSwapArray $Swapvtx $vetx $dirax 1 $nmc`;
string $vtxGrA[] = $vetx;
string $vtxGrB[] = $Swapvtx;
if ($dir == 0)
{
//print ("X<<"+$vtxGrA[0] +" "+$vtxGrB[0] +"\n\n");
yjp_WeightTransfer $vtxGrB $vtxGrA 1;
select -r $vtxGrB;
//print ($vtxGrB[0] +"\n");
}
else
{
//print ("X>>"+$vtxGrB[0] +" "+$vtxGrA[0] +"\n\n");
yjp_WeightTransfer $vtxGrA $vtxGrB 1;
select -r $vtxGrA;
//print ($vtxGrA[0] +"\n");
}
currentTime $t ;
return ;
}
global proc yjp_WeightSymmetryObjGet(int $input)
{
if($input == 1)
{
string $sel[] = `ls -sl`;
if(size($sel)==1)
{
textFieldGrp -e -tx $sel[0] yjp_wsAnothermeshField;
}
}
else if($input == 0)
{
textFieldGrp -e -tx "" yjp_wsAnothermeshField;
}
}
/*
global proc yjp_WeightSymmetryCenter()
{
string $selobj[] = `ls -sl`;
if(`size$selobj` == 0){return ;}
float $vc[] = `xform -q -a -ws -t $selobj[0]`;
floatFieldGrp -e -value1 $vc[0] -value2 $vc[1] -value3 $vc[2] WeightSymmetryCenterField;
}
*/
global proc yjp_WeightSymmetry()
{
if(`window -q -ex yjp_WeightSymmetryWindow`)
{
deleteUI yjp_WeightSymmetryWindow ;
}
window -tb 1 -tlb 0 -t "WeightSymmetry1.2" yjp_WeightSymmetryWindow ;
columnLayout ;
rowColumnLayout -nc 2 -cw 1 220 -cw 2 96;
/*
floatFieldGrp -numberOfFields 3
-label "center"
-cw3 60 60 60
-value1 0.0 -value2 0.0 -value3 0.0 WeightSymmetryCenterField;
button -w 50 -label "center" -ann "選択した頂点から対称座標を入力" -command "yjp_WeightSymmetryCenter";
*/
intFieldGrp -numberOfFields 1
-label "BindFrame"
-cw 1 70
-value1 0 wsBindFrameField;
checkBox -l "NormalMatche" -ann "法線が似ている頂点を探す" -v 0 wsNormalMatcheCheck;
setParent..;
rowColumnLayout -nc 3 -cw 1 220 -cw 2 48 -cw 3 48;
textFieldGrp -label "Another mesh" -cw2 70 140 yjp_wsAnothermeshField;
button -label "ObjGet" -ann "別のメッシュとシンメトリする" -command "yjp_WeightSymmetryObjGet 1";
button -label "CLEAR" -ann "Another mesh欄を消す" -command "yjp_WeightSymmetryObjGet 0";
setParent..;
rowColumnLayout -nc 2 -cw 1 158 -cw 2 158;
button -h 30 -l "X←" -c "yjp_doWeightSymmetry 0";
button -h 30 -l "X→" -c "yjp_doWeightSymmetry 1";
setParent..;
//button -w 130 -h 25 -l "Close" -c ("deleteUI -window WeightSymmetryWindow") ;
setParent..;
showWindow yjp_WeightSymmetryWindow ;
window -e -wh 320 82 yjp_WeightSymmetryWindow ;
}
2015年2月22日日曜日
ウエイトエディット1.5 更新
yjp_weightedit1.5更新
1頂点だけですがウエイト調整がリアルタイムで出来ます。
同じインフルエンスと値であれば複数頂点も調整できます。
今回は合計が1になっていないバグを調整。
スライダーが入力時に適切な最大値に変動するようにしました。
1つのスライダを1にすることが出来なくなってしまうが、
他のスライダを0にすることで1に出来ます。
スライダーの最大値を変動するときの挙動が気になりますが、
なんとなくバランス配分固定できている気がしています。
ホールド変更やニューバランスボタンでスライダーバランスが再設定されます。(たぶん)
このMELはMayaLTでも動くのでしょうかねー。
2015年2月15日日曜日
yjp_WeightEdit 1.4
表示関係バグを修正。
取得してくるジョイントが変な事があったので修正。
ゼロウエイトをリストに入れるか入れないかのチェックボックス追加
スクロールレイアウトを調整
また使いながら調整していく。
コンポーネントエディターのウエイト調整よりだいぶ楽になった。
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`;
float $step = `floatField -q -v yjpWeigtEditStepField`;
//ホールド状態の処理
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;
float $w[],$all;
for ($c=0;$c<size($val);$c++)
{
if($count[$c])
{
$val[$c] = $val[$c]*$a;
$w[$c] = $val[$c];
$all = $val[$c];
}
//print ("val " + $val[$c] +"\n");
}
$w = `sort $w`;
$w[size($w)-1] = $w[size($w)-1] + ($total - $all);
$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`;
float $step = `floatField -q -v yjpWeigtEditStepField`;
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++)
{
$SkinScript = ("skinPercent " + $SkinScript + $sc + " " + $vtxArray[$n] );
undoInfo -swf off;
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[];
if(`checkBox -q -v yjp_weightedit_hz`)
{
$weight = `skinPercent -ib 0.0001 -q -v $scA $sourcevtxArray[0]`;
$jointList = `skinPercent -ib 0.0001 -q -t $scA $sourcevtxArray[0]`;
}
else
{
$weight = `skinPercent -ib 0.0000 -q -v $scA $sourcevtxArray[0]`;
$jointList = `skinPercent -ib 0.0000 -q -t $scA $sourcevtxArray[0]`;
}
string $labeltxt = "";
float $step = `floatField -q -v yjpWeigtEditStepField`;
$h = 60;
window -e -h $h yjp_WeightEditwindow;
for ($n=0 ; $n < size($jointList) ; $n++)
{
int $bool = 0;
int $hid = 1;
//getAttr ($jointList[$n] + ".objectColor");
setAttr ($jointList[$n] + ".lockInfluenceWeights") 0;
$yjp_weightedit_float[$n] = $weight[$n];
if($weight[$n] == 0)
{
$bool = 1;
$hid = 0;
}
$labeltxt = `getAttr ($jointList[$n] + ".otherType")`;
string $hcb = `checkBox -w 30 -l "" -v $bool -p yjp_WeightEditQueueLayout -onc ("yjp_weightedit_Hold 1 " + $n) -ofc ("yjp_weightedit_Hold 0 " + $n)`;
textField -w 80 -tx $labeltxt -p yjp_WeightEditQueueLayout -cc ("yjp_weightedit_JointLabel " + $n);
floatSliderGrp -en $hid -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 -en $hid -w 20 -l "<" -p yjp_WeightEditQueueLayout -c ("yjp_weightedit_step -1 " + $n);
button -en $hid -w 20 -l ">" -p yjp_WeightEditQueueLayout -c ("yjp_weightedit_step 1 " + $n);
$h += 23;
}
window -e -h $h yjp_WeightEditwindow;
}
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 $bool ,int $num)
{
string $control[] = `rowColumnLayout -q -ca yjp_WeightEditQueueLayout`;
int $n;
int $c =0;
string $joint;
int $en = 1;
if($bool)
{
$en = 0;
}
for ($n=0;$n<size($control);$n += 5)
{
if($c == $num)
{
//ホールド
$joint = `floatSliderGrp -q -l $control[$n+2]`;
checkBox -e -v $bool $control[$n];
floatSliderGrp -e -en $en $control[$n+2];
button -e -en $en $control[$n+3];
button -e -en $en $control[$n+4];
setAttr ($joint + ".lockInfluenceWeights") $bool;
}
$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_autoget()
{
global int $yjp_WeightEditJob;
if (`checkBox -q -v yjp_weightedit_ag`)
{
if (`scriptJob -ex $yjp_WeightEditJob`)scriptJob -force -kill $yjp_WeightEditJob;
$yjp_WeightEditJob =`scriptJob -p "yjp_WeightEditwindow" -e "SelectionChanged" "yjp_weightedit_get"`;
print ("yjp_WeightEditJob " + $yjp_WeightEditJob+ "\n") ;
}
else
{
scriptJob -kill $yjp_WeightEditJob -force;
print ("yjp_WeightEditJobkill " + $yjp_WeightEditJob+ "\n") ;
}
}
global proc yjp_weightedit_paint()
{
checkBox -e -v 0 yjp_weightedit_ag;
checkBox -e -v 0 yjp_weightedit_ac;
artUserPaintCtx artUserPaintCtx;
artUserPaintCtx -e -pm 1 -ic "yjp_weightedit_apply" artUserPaintCtx;
}
global proc yjp_WeightEdit()
{
if(`window -q -ex yjp_WeightEditwindow`) deleteUI yjp_WeightEditwindow;
window -s 1 -t "WeightEdit 1.4" -rtf true yjp_WeightEditwindow;
string $no = "";
global int $yjp_WeightEditJob;
string $form = `formLayout`;
string $Buttton = `columnLayout -adjustableColumn true`;
rowColumnLayout -nc 9 -cw 1 70 -cw 2 60 -cw 3 50 -cw 4 70 -cw 5 60 -cw 6 30 -cw 8 40 -cw 8 50 -cw 9 50;
//button -h 25 -w 60 -l "Reset" -c "yjp_weightedit_Reset";
checkBox -w 70 -l "HideZero" -v 1 -cc "yjp_weightedit_get" yjp_weightedit_hz;
checkBox -w 60 -l "AutoGet" -v 1 -cc "yjp_weightedit_autoget" yjp_weightedit_ag;
button -h 25 -w 50 -l "Get_vtx" -c "yjp_weightedit_get";
checkBox -w 60 -l "AutoApply" -v 0 yjp_weightedit_ac;
button -h 25 -w 50 -l "Apply" -c "yjp_weightedit_apply" ;
text -l "snap";
floatField -w 40 -v 0.01 -pre 3 yjpWeigtEditStepField ;
button -h 25 -w 50 -l "Paint" -c ("yjp_weightedit_paint;");
button -h 25 -w 50 -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 ..;
setParent ..;
string $WES = `scrollLayout -horizontalScrollBarThickness 16 -verticalScrollBarThickness 16 yjp_WeightEditscrollLayout`;
rowColumnLayout -nc 5 -cw 1 30 -cw 2 80 -cw 3 320 -cw 4 20 -cw 5 20 yjp_WeightEditQueueLayout;
setParent ..;
setParent ..;
formLayout -edit
-attachForm $Buttton "top" 0
-attachNone $Buttton "bottom"
-attachForm $Buttton "left" 5
-attachForm $Buttton "right" 5
-attachForm $WES "top" 50
-attachForm $WES "bottom" 0
-attachForm $WES "left" 0
-attachForm $WES "right" 0
$form;
window -e -wh 500 180 yjp_WeightEditwindow;
showWindow yjp_WeightEditwindow;
$yjp_WeightEditJob =`scriptJob -p "yjp_WeightEditwindow" -e "SelectionChanged" "yjp_weightedit_get"`;
}
取得してくるジョイントが変な事があったので修正。
ゼロウエイトをリストに入れるか入れないかのチェックボックス追加
スクロールレイアウトを調整
また使いながら調整していく。
コンポーネントエディターのウエイト調整よりだいぶ楽になった。
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`;
float $step = `floatField -q -v yjpWeigtEditStepField`;
//ホールド状態の処理
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;
float $w[],$all;
for ($c=0;$c<size($val);$c++)
{
if($count[$c])
{
$val[$c] = $val[$c]*$a;
$w[$c] = $val[$c];
$all = $val[$c];
}
//print ("val " + $val[$c] +"\n");
}
$w = `sort $w`;
$w[size($w)-1] = $w[size($w)-1] + ($total - $all);
$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`;
float $step = `floatField -q -v yjpWeigtEditStepField`;
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++)
{
$SkinScript = ("skinPercent " + $SkinScript + $sc + " " + $vtxArray[$n] );
undoInfo -swf off;
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[];
if(`checkBox -q -v yjp_weightedit_hz`)
{
$weight = `skinPercent -ib 0.0001 -q -v $scA $sourcevtxArray[0]`;
$jointList = `skinPercent -ib 0.0001 -q -t $scA $sourcevtxArray[0]`;
}
else
{
$weight = `skinPercent -ib 0.0000 -q -v $scA $sourcevtxArray[0]`;
$jointList = `skinPercent -ib 0.0000 -q -t $scA $sourcevtxArray[0]`;
}
string $labeltxt = "";
float $step = `floatField -q -v yjpWeigtEditStepField`;
$h = 60;
window -e -h $h yjp_WeightEditwindow;
for ($n=0 ; $n < size($jointList) ; $n++)
{
int $bool = 0;
int $hid = 1;
//getAttr ($jointList[$n] + ".objectColor");
setAttr ($jointList[$n] + ".lockInfluenceWeights") 0;
$yjp_weightedit_float[$n] = $weight[$n];
if($weight[$n] == 0)
{
$bool = 1;
$hid = 0;
}
$labeltxt = `getAttr ($jointList[$n] + ".otherType")`;
string $hcb = `checkBox -w 30 -l "" -v $bool -p yjp_WeightEditQueueLayout -onc ("yjp_weightedit_Hold 1 " + $n) -ofc ("yjp_weightedit_Hold 0 " + $n)`;
textField -w 80 -tx $labeltxt -p yjp_WeightEditQueueLayout -cc ("yjp_weightedit_JointLabel " + $n);
floatSliderGrp -en $hid -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 -en $hid -w 20 -l "<" -p yjp_WeightEditQueueLayout -c ("yjp_weightedit_step -1 " + $n);
button -en $hid -w 20 -l ">" -p yjp_WeightEditQueueLayout -c ("yjp_weightedit_step 1 " + $n);
$h += 23;
}
window -e -h $h yjp_WeightEditwindow;
}
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 $bool ,int $num)
{
string $control[] = `rowColumnLayout -q -ca yjp_WeightEditQueueLayout`;
int $n;
int $c =0;
string $joint;
int $en = 1;
if($bool)
{
$en = 0;
}
for ($n=0;$n<size($control);$n += 5)
{
if($c == $num)
{
//ホールド
$joint = `floatSliderGrp -q -l $control[$n+2]`;
checkBox -e -v $bool $control[$n];
floatSliderGrp -e -en $en $control[$n+2];
button -e -en $en $control[$n+3];
button -e -en $en $control[$n+4];
setAttr ($joint + ".lockInfluenceWeights") $bool;
}
$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_autoget()
{
global int $yjp_WeightEditJob;
if (`checkBox -q -v yjp_weightedit_ag`)
{
if (`scriptJob -ex $yjp_WeightEditJob`)scriptJob -force -kill $yjp_WeightEditJob;
$yjp_WeightEditJob =`scriptJob -p "yjp_WeightEditwindow" -e "SelectionChanged" "yjp_weightedit_get"`;
print ("yjp_WeightEditJob " + $yjp_WeightEditJob+ "\n") ;
}
else
{
scriptJob -kill $yjp_WeightEditJob -force;
print ("yjp_WeightEditJobkill " + $yjp_WeightEditJob+ "\n") ;
}
}
global proc yjp_weightedit_paint()
{
checkBox -e -v 0 yjp_weightedit_ag;
checkBox -e -v 0 yjp_weightedit_ac;
artUserPaintCtx artUserPaintCtx;
artUserPaintCtx -e -pm 1 -ic "yjp_weightedit_apply" artUserPaintCtx;
}
global proc yjp_WeightEdit()
{
if(`window -q -ex yjp_WeightEditwindow`) deleteUI yjp_WeightEditwindow;
window -s 1 -t "WeightEdit 1.4" -rtf true yjp_WeightEditwindow;
string $no = "";
global int $yjp_WeightEditJob;
string $form = `formLayout`;
string $Buttton = `columnLayout -adjustableColumn true`;
rowColumnLayout -nc 9 -cw 1 70 -cw 2 60 -cw 3 50 -cw 4 70 -cw 5 60 -cw 6 30 -cw 8 40 -cw 8 50 -cw 9 50;
//button -h 25 -w 60 -l "Reset" -c "yjp_weightedit_Reset";
checkBox -w 70 -l "HideZero" -v 1 -cc "yjp_weightedit_get" yjp_weightedit_hz;
checkBox -w 60 -l "AutoGet" -v 1 -cc "yjp_weightedit_autoget" yjp_weightedit_ag;
button -h 25 -w 50 -l "Get_vtx" -c "yjp_weightedit_get";
checkBox -w 60 -l "AutoApply" -v 0 yjp_weightedit_ac;
button -h 25 -w 50 -l "Apply" -c "yjp_weightedit_apply" ;
text -l "snap";
floatField -w 40 -v 0.01 -pre 3 yjpWeigtEditStepField ;
button -h 25 -w 50 -l "Paint" -c ("yjp_weightedit_paint;");
button -h 25 -w 50 -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 ..;
setParent ..;
string $WES = `scrollLayout -horizontalScrollBarThickness 16 -verticalScrollBarThickness 16 yjp_WeightEditscrollLayout`;
rowColumnLayout -nc 5 -cw 1 30 -cw 2 80 -cw 3 320 -cw 4 20 -cw 5 20 yjp_WeightEditQueueLayout;
setParent ..;
setParent ..;
formLayout -edit
-attachForm $Buttton "top" 0
-attachNone $Buttton "bottom"
-attachForm $Buttton "left" 5
-attachForm $Buttton "right" 5
-attachForm $WES "top" 50
-attachForm $WES "bottom" 0
-attachForm $WES "left" 0
-attachForm $WES "right" 0
$form;
window -e -wh 500 180 yjp_WeightEditwindow;
showWindow yjp_WeightEditwindow;
$yjp_WeightEditJob =`scriptJob -p "yjp_WeightEditwindow" -e "SelectionChanged" "yjp_weightedit_get"`;
}
2015年2月14日土曜日
yjp_WeightEdit 1.3
今回の更新はスクリプトジョブで頂点選択を変更する事でインフルエンスリストを更新。
オートゲットチェックを外せば頂点複数選択後Applyできます。
インフルエンスに含まれているけど非表示にしていたジョイント。
追加したい事よくあるので0ウエイトもリストに表示してホールドしています。
割合計算で多少問題がある。
1を超えたり少なかったりしているので、また今度考える。
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]`;
$weight = `skinPercent -q -v $scA $sourcevtxArray[0]`;
$jointList = `skinPercent -q -t $scA $sourcevtxArray[0]`;
string $labeltxt = "";
float $step = `floatField -q -v yjpWeigtEditStepField`;
$h = 60;
window -e -wh 485 $h yjp_WeightEditwindow;
for ($n=0 ; $n < size($jointList) ; $n++)
{
int $bool = 0;
int $hid = 1;
//getAttr ($jointList[$n] + ".objectColor");
setAttr ($jointList[$n] + ".lockInfluenceWeights") 0;
$yjp_weightedit_float[$n] = $weight[$n];
if($weight[$n] == 0)
{
$bool = 1;
$hid = 0;
}
$labeltxt = `getAttr ($jointList[$n] + ".otherType")`;
string $hcb = `checkBox -w 30 -l "" -v $bool -p yjp_WeightEditQueueLayout -onc ("yjp_weightedit_Hold 1 " + $n) -ofc ("yjp_weightedit_Hold 0 " + $n)`;
textField -w 80 -tx $labeltxt -p yjp_WeightEditQueueLayout -cc ("yjp_weightedit_JointLabel " + $n);
floatSliderGrp -en $hid -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);
$h += 23;
}
window -e -wh 485 $h yjp_WeightEditwindow;
}
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 $bool ,int $num)
{
string $control[] = `rowColumnLayout -q -ca yjp_WeightEditQueueLayout`;
int $n;
int $c =0;
string $joint;
int $en = 1;
if($bool)
{
$en = 0;
}
for ($n=0;$n<size($control);$n += 5)
{
if($c == $num)
{
//ホールド
$joint = `floatSliderGrp -q -l $control[$n+2]`;
checkBox -e -v $bool $control[$n];
floatSliderGrp -e -en $en $control[$n+2];
button -e -en $en $control[$n+3];
button -e -en $en $control[$n+4];
setAttr ($joint + ".lockInfluenceWeights") $bool;
}
$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_autoget()
{
global int $yjp_WeightEditJob;
if (`checkBox -q -v yjp_weightedit_ag`)
{
if (`scriptJob -ex $yjp_WeightEditJob`)scriptJob -force -kill $yjp_WeightEditJob;
$yjp_WeightEditJob =`scriptJob -p "yjp_WeightEditwindow" -e "SelectionChanged" "yjp_weightedit_get"`;
}
else
{
scriptJob -kill $yjp_WeightEditJob -force;
}
print ("yjp_WeightEditJob " + $yjp_WeightEditJob+ "\n") ;
}
global proc yjp_WeightEdit()
{
if(`window -q -ex yjp_WeightEditwindow`) deleteUI yjp_WeightEditwindow;
window -s 1 -t "WeightEdit 1.3" yjp_WeightEditwindow;
string $no = "";
global int $yjp_WeightEditJob;
columnLayout -adjustableColumn true;
rowColumnLayout -nc 8 -cw 1 70 -cw 2 70 -cw 3 70 -cw 4 70 -cw 5 70 -cw 6 30 -cw 8 40 -cw 8 50;
button -h 25 -w 60 -l "Reset" -c "yjp_weightedit_Reset";
checkBox -w 60 -l "AutoGet" -v 1 -cc "yjp_weightedit_autoget" yjp_weightedit_ag;
button -h 25 -w 60 -l "Get_vtx" -c "yjp_weightedit_get";
checkBox -w 70 -l "AutoApply" -v 0 yjp_weightedit_ac;
button -h 25 -w 60 -l "Apply" -c "yjp_weightedit_apply" ;
text -l "snap";
floatField -w 40 -v 0.01 yjpWeigtEditStepField ;
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_WeightEditJob =`scriptJob -p "yjp_WeightEditwindow" -e "SelectionChanged" "yjp_weightedit_get"`;
}
オートゲットチェックを外せば頂点複数選択後Applyできます。
インフルエンスに含まれているけど非表示にしていたジョイント。
追加したい事よくあるので0ウエイトもリストに表示してホールドしています。
割合計算で多少問題がある。
1を超えたり少なかったりしているので、また今度考える。
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]`;
$weight = `skinPercent -q -v $scA $sourcevtxArray[0]`;
$jointList = `skinPercent -q -t $scA $sourcevtxArray[0]`;
string $labeltxt = "";
float $step = `floatField -q -v yjpWeigtEditStepField`;
$h = 60;
window -e -wh 485 $h yjp_WeightEditwindow;
for ($n=0 ; $n < size($jointList) ; $n++)
{
int $bool = 0;
int $hid = 1;
//getAttr ($jointList[$n] + ".objectColor");
setAttr ($jointList[$n] + ".lockInfluenceWeights") 0;
$yjp_weightedit_float[$n] = $weight[$n];
if($weight[$n] == 0)
{
$bool = 1;
$hid = 0;
}
$labeltxt = `getAttr ($jointList[$n] + ".otherType")`;
string $hcb = `checkBox -w 30 -l "" -v $bool -p yjp_WeightEditQueueLayout -onc ("yjp_weightedit_Hold 1 " + $n) -ofc ("yjp_weightedit_Hold 0 " + $n)`;
textField -w 80 -tx $labeltxt -p yjp_WeightEditQueueLayout -cc ("yjp_weightedit_JointLabel " + $n);
floatSliderGrp -en $hid -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);
$h += 23;
}
window -e -wh 485 $h yjp_WeightEditwindow;
}
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 $bool ,int $num)
{
string $control[] = `rowColumnLayout -q -ca yjp_WeightEditQueueLayout`;
int $n;
int $c =0;
string $joint;
int $en = 1;
if($bool)
{
$en = 0;
}
for ($n=0;$n<size($control);$n += 5)
{
if($c == $num)
{
//ホールド
$joint = `floatSliderGrp -q -l $control[$n+2]`;
checkBox -e -v $bool $control[$n];
floatSliderGrp -e -en $en $control[$n+2];
button -e -en $en $control[$n+3];
button -e -en $en $control[$n+4];
setAttr ($joint + ".lockInfluenceWeights") $bool;
}
$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_autoget()
{
global int $yjp_WeightEditJob;
if (`checkBox -q -v yjp_weightedit_ag`)
{
if (`scriptJob -ex $yjp_WeightEditJob`)scriptJob -force -kill $yjp_WeightEditJob;
$yjp_WeightEditJob =`scriptJob -p "yjp_WeightEditwindow" -e "SelectionChanged" "yjp_weightedit_get"`;
}
else
{
scriptJob -kill $yjp_WeightEditJob -force;
}
print ("yjp_WeightEditJob " + $yjp_WeightEditJob+ "\n") ;
}
global proc yjp_WeightEdit()
{
if(`window -q -ex yjp_WeightEditwindow`) deleteUI yjp_WeightEditwindow;
window -s 1 -t "WeightEdit 1.3" yjp_WeightEditwindow;
string $no = "";
global int $yjp_WeightEditJob;
columnLayout -adjustableColumn true;
rowColumnLayout -nc 8 -cw 1 70 -cw 2 70 -cw 3 70 -cw 4 70 -cw 5 70 -cw 6 30 -cw 8 40 -cw 8 50;
button -h 25 -w 60 -l "Reset" -c "yjp_weightedit_Reset";
checkBox -w 60 -l "AutoGet" -v 1 -cc "yjp_weightedit_autoget" yjp_weightedit_ag;
button -h 25 -w 60 -l "Get_vtx" -c "yjp_weightedit_get";
checkBox -w 70 -l "AutoApply" -v 0 yjp_weightedit_ac;
button -h 25 -w 60 -l "Apply" -c "yjp_weightedit_apply" ;
text -l "snap";
floatField -w 40 -v 0.01 yjpWeigtEditStepField ;
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_WeightEditJob =`scriptJob -p "yjp_WeightEditwindow" -e "SelectionChanged" "yjp_weightedit_get"`;
}
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;
}
昨日アップしたウエイト調整MEL
リアルタイムでウエイトの変化を見れるのは便利なんですがアンドゥの履歴がこのMELですぐ埋まってしまうので気をつけてください。
いまはそのアンドゥ関係の処理と
複数選択で適用する
スライダーの横にステップ単位で増減できるようにボタンを付けようとしています。
あとはジョイントがどれか分かるようにしたいが、ジョイントカラーの取得が不明
明日考える。
他に何を作ろうかなー。
いまはそのアンドゥ関係の処理と
複数選択で適用する
スライダーの横にステップ単位で増減できるようにボタンを付けようとしています。
あとはジョイントがどれか分かるようにしたいが、ジョイントカラーの取得が不明
明日考える。
他に何を作ろうかなー。
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;
}
やっと出来ました。
一応テキトウに値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;
}
2015年2月9日月曜日
コンポーネントでウエイト編集が数値入力なのはなぜ
まだちゃんと動かない
とりあえずメモ
計画の機能はほとんど入れたが肝心なところの
UI内で1になるようにスライダーを動かそうとしているがいい方法がまだ見つからない
yjp_weightedit_balanceこれがダメです。使わないでください。
簡単に出来そうなものだけど、なぜか動かない。
今回、思いついた新しい処理は
フライダーUIを毎回新しく置き換えている。
追加するとUIの名前が自動で付くので触ったコントロールがどれか取得しにくいが
なんとかできました。
まだ使い物にならないけど
global proc yjp_weightedit_balance(int $num)
{
global float $yjp_weightedit_float[];
float $val[],$total;
int $c = 0;
int $f = 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]`;
$joint = `floatSliderGrp -q -l $control[$n+2]`;
$label = `textField -q-tx $control[$n+1]`;
$labeltxt = `setAttr -type "string" ($joint + ".otherType") $label`;
if(`checkBox -q -v $control[$n]`)
{
setAttr ($joint + ".lockInfluenceWeights") 1;
$holdfloat += $val[$c];
}
else if($num == $c)
{
setAttr ($joint + ".lockInfluenceWeights") 0;
$holdfloat += $val[$c];
if($yjp_weightedit_float[$c] < $val[$c])
{
$m = -1;
}
}
else
{
$count[$c] = 1;
$changeval[$f] = $val[$c];
$v += $changeval[$f];
$total = 1 - $val[$c];
}
$c++;
$f++;
}
$a = $total / $v;
for ($c=0;$c<size($val);$c++)
{
if($count[$c])
{
$val[$c] = $val[$c]*$a;
}
}
print ("total " + $total +"\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 -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;
textField -w 80 -tx $labeltxt -p yjp_WeightEditQueueLayout;
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()
{
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_weight" -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;
}
とりあえずメモ
計画の機能はほとんど入れたが肝心なところの
UI内で1になるようにスライダーを動かそうとしているがいい方法がまだ見つからない
yjp_weightedit_balanceこれがダメです。使わないでください。
簡単に出来そうなものだけど、なぜか動かない。
今回、思いついた新しい処理は
フライダーUIを毎回新しく置き換えている。
追加するとUIの名前が自動で付くので触ったコントロールがどれか取得しにくいが
なんとかできました。
まだ使い物にならないけど
global proc yjp_weightedit_balance(int $num)
{
global float $yjp_weightedit_float[];
float $val[],$total;
int $c = 0;
int $f = 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]`;
$joint = `floatSliderGrp -q -l $control[$n+2]`;
$label = `textField -q-tx $control[$n+1]`;
$labeltxt = `setAttr -type "string" ($joint + ".otherType") $label`;
if(`checkBox -q -v $control[$n]`)
{
setAttr ($joint + ".lockInfluenceWeights") 1;
$holdfloat += $val[$c];
}
else if($num == $c)
{
setAttr ($joint + ".lockInfluenceWeights") 0;
$holdfloat += $val[$c];
if($yjp_weightedit_float[$c] < $val[$c])
{
$m = -1;
}
}
else
{
$count[$c] = 1;
$changeval[$f] = $val[$c];
$v += $changeval[$f];
$total = 1 - $val[$c];
}
$c++;
$f++;
}
$a = $total / $v;
for ($c=0;$c<size($val);$c++)
{
if($count[$c])
{
$val[$c] = $val[$c]*$a;
}
}
print ("total " + $total +"\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 -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;
textField -w 80 -tx $labeltxt -p yjp_WeightEditQueueLayout;
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()
{
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_weight" -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;
}
2015年1月20日火曜日
WeightSymmetryに問題があるかも
yjp_WeightSymmetry思いのほか動いてるなーと使っていたら
変なミラーコピーをしだしました。
yjp_WeightTransferプロシージャに問題がありそう
skinPercent -ib 0.0001 -q -vとskinPercent -ib 0.0001 -q -tで
0.0001以上のウエイトしかコピペしてないから0で上書きされてないのかもしれない。
明日見てみよう。
次はなにを作ろうか考えていた。
そこでAIを考えてみようと思う。
全然知識は無いけど、MELでAIを使ったツールができないものか
変なミラーコピーをしだしました。
yjp_WeightTransferプロシージャに問題がありそう
skinPercent -ib 0.0001 -q -vとskinPercent -ib 0.0001 -q -tで
0.0001以上のウエイトしかコピペしてないから0で上書きされてないのかもしれない。
明日見てみよう。
次はなにを作ろうか考えていた。
そこでAIを考えてみようと思う。
全然知識は無いけど、MELでAIを使ったツールができないものか
2015年1月19日月曜日
yjp_WeightSymmetry追加
s_MayaScriptsを更新しました。
yjp_WeightSymmetry追加
ウエイトミラーです。
標準機能でミラーで着ない事が合ったので作ってみました
使い方
yjp_WeightSymmetry追加
ウエイトミラーです。
標準機能でミラーで着ない事が合ったので作ってみました
使い方
- 重なっているジョイントのみアトリビュートでラベル名をつけてください。
- 対称ジョイントが同じラベル名になるようにしてください。
- バインドフレームはデフォルト0ですがバインド時のポーズがあるフレームを指定してください
- ノーマルマッチは左右対称頂点を検索する時に法線が似ている頂点を探します。
- アナザーメッシュ欄は何もなければ選択した頂点のメッシュから対称を探します。
- 対称の別オブジェをゲットすればそのメッシュから対称の頂点を探します。
X方向のミラーしかできません。
左右どちらかを選択してください。左右選択すると誤作動するかもしれません。
今後は左右選択に対応するかもしれません。
非対称メッシュでもある程度シンメトリのウエイトになると思います。
ちょっと処理が重いです。
プログレスバーが早すぎて点滅します。課題です。
2014年11月17日月曜日
バインドメッシュを複製するやつ
前に作ったImitateBindを他の処理で使いやすくしました
global proc yjp_doImitateBind(string $sourceobj , string $targetobj )
{
string $scs = `findRelatedSkinCluster $sourceobj`;
string $sct = `findRelatedSkinCluster $targetobj`;
if( size($scs) == 0 )return;
if( size($sct))return;
string $jointlistname[] = `listConnections -type "joint" ($scs +".matrix")`;
int $maxInf = `getAttr ($scs + ".maxInfluences")`;
select $targetobj;
//アトリビュートをアンロック
yjp_meshUnlook $targetobj;
//フリーズ
FreezeTransformations ;
string $scnext[] = `skinCluster -mi $maxInf -omi true -dr 4 -rui 0 -tsb $jointlistname $targetobj`;
//copySkinWeights -ss $scs -ds $scnext[0] -ia "closestJoint" -ia "oneToOne";
select $sourceobj $targetobj;
copySkinWeights -noMirror -surfaceAssociation closestPoint -influenceAssociation closestJoint -influenceAssociation oneToOne;
select $targetobj;
return ;
}
以下はyjp_doImitateBindを使ってバインドを保持したままメッシュを複製します
思いのほか簡単。
global proc string yjp_DuplicateMeshSkin()
{
string $objs[] = `ls -sl`;
if( size($objs) == 0)return(0);
//メッシュ複製
string $newmeshA[] = `duplicate -n ($objs[0] + "_dup") -rr $objs[0]`;
yjp_doImitateBind $objs[0] $newmeshA[0];
return ($newmeshA[0]);
}
バインドメッシュ同士のコンバインとセパレートもyjp_doImitateBindをつかってます
一応アトリビュートのアンロックプロシージャ
global proc yjp_meshUnlook(string $selectName)
{
setAttr -lock 0 ($selectName + ".tx");
setAttr -lock 0 ($selectName + ".ty");
setAttr -lock 0 ($selectName + ".tz");
setAttr -lock 0 ($selectName + ".rx");
setAttr -lock 0 ($selectName + ".ry");
setAttr -lock 0 ($selectName + ".rz");
setAttr -lock 0 ($selectName + ".sx");
setAttr -lock 0 ($selectName + ".sy");
setAttr -lock 0 ($selectName + ".sz");
}
global proc yjp_doImitateBind(string $sourceobj , string $targetobj )
{
string $scs = `findRelatedSkinCluster $sourceobj`;
string $sct = `findRelatedSkinCluster $targetobj`;
if( size($scs) == 0 )return;
if( size($sct))return;
string $jointlistname[] = `listConnections -type "joint" ($scs +".matrix")`;
int $maxInf = `getAttr ($scs + ".maxInfluences")`;
select $targetobj;
//アトリビュートをアンロック
yjp_meshUnlook $targetobj;
//フリーズ
FreezeTransformations ;
string $scnext[] = `skinCluster -mi $maxInf -omi true -dr 4 -rui 0 -tsb $jointlistname $targetobj`;
//copySkinWeights -ss $scs -ds $scnext[0] -ia "closestJoint" -ia "oneToOne";
select $sourceobj $targetobj;
copySkinWeights -noMirror -surfaceAssociation closestPoint -influenceAssociation closestJoint -influenceAssociation oneToOne;
select $targetobj;
return ;
}
以下はyjp_doImitateBindを使ってバインドを保持したままメッシュを複製します
思いのほか簡単。
global proc string yjp_DuplicateMeshSkin()
{
string $objs[] = `ls -sl`;
if( size($objs) == 0)return(0);
//メッシュ複製
string $newmeshA[] = `duplicate -n ($objs[0] + "_dup") -rr $objs[0]`;
yjp_doImitateBind $objs[0] $newmeshA[0];
return ($newmeshA[0]);
}
バインドメッシュ同士のコンバインとセパレートもyjp_doImitateBindをつかってます
一応アトリビュートのアンロックプロシージャ
global proc yjp_meshUnlook(string $selectName)
{
setAttr -lock 0 ($selectName + ".tx");
setAttr -lock 0 ($selectName + ".ty");
setAttr -lock 0 ($selectName + ".tz");
setAttr -lock 0 ($selectName + ".rx");
setAttr -lock 0 ($selectName + ".ry");
setAttr -lock 0 ($selectName + ".rz");
setAttr -lock 0 ($selectName + ".sx");
setAttr -lock 0 ($selectName + ".sy");
setAttr -lock 0 ($selectName + ".sz");
}
2014年9月9日火曜日
ウエイト塗るときに値を入力するのが面倒
ウエイト塗るときに値を入力するのが面倒なのでボタンを作りました。
もしかするとMaya内部を直接書き換えたほうがUIがまとまってよさそうな気がしてきました。
スポイトが欲しいと言う声もあるので調べてみます。
global proc YPSWB_Replace(int $type ,float $val)
{
if($type == 0)
{
artAttrPaintOperation artAttrSkinPaintCtx Replace;
}
else if($type == 1)
{
artAttrPaintOperation artAttrSkinPaintCtx Add;
}
else if($type == 2)
{
artAttrPaintOperation artAttrSkinPaintCtx Smooth;
}
artAttrSkinPaintCtx -e -value $val `currentCtx`;
}
global proc yjp_PaintSikinWeightButton()
{
if(`window -q -ex yjp_WeightButtonWindow`)
{
deleteUI yjp_WeightButtonWindow ;
}
window -tb 1 -tlb 0 -t "PaintWeightButton" yjp_WeightButtonWindow ;
columnLayout ;
rowColumnLayout -nc 12 -cw 1 50 -cw 2 30 -cw 3 30 -cw 4 30 -cw 5 30 -cw 6 30 -cw 7 30 -cw 8 30 -cw 9 30 -cw 10 30 -cw 11 30 -cw 12 30;
text -w 50 -label "Replace";
button -w 30 -h 25 -l "0.0" -c "YPSWB_Replace 0 0.0" ;
button -w 30 -h 25 -l "0.1" -c "YPSWB_Replace 0 0.1" ;
button -w 30 -h 25 -l "0.2" -c "YPSWB_Replace 0 0.2" ;
button -w 30 -h 25 -l "0.3" -c "YPSWB_Replace 0 0.3" ;
button -w 30 -h 25 -l "0.4" -c "YPSWB_Replace 0 0.4" ;
button -w 30 -h 25 -l "0.5" -c "YPSWB_Replace 0 0.5" ;
button -w 30 -h 25 -l "0.6" -c "YPSWB_Replace 0 0.6" ;
button -w 30 -h 25 -l "0.7" -c "YPSWB_Replace 0 0.7" ;
button -w 30 -h 25 -l "0.8" -c "YPSWB_Replace 0 0.8" ;
button -w 30 -h 25 -l "0.9" -c "YPSWB_Replace 0 0.9" ;
button -w 30 -h 25 -l "1.0" -c "YPSWB_Replace 0 1.0" ;
setParent..;
rowColumnLayout -nc 7 -cw 1 50 -cw 2 30 -cw 3 30 -cw 4 50 -cw 5 60 -cw 6 60 -cw 7 60;
text -label "Add";
button -w 30 -h 25 -l "0.05" -c "YPSWB_Replace 1 0.05" ;
button -w 30 -h 25 -l "0.10" -c "YPSWB_Replace 1 0.1" ;
text -label " ";
button -w 60 -h 25 -label "Smooth" -c "YPSWB_Replace 2 0.0";
button -w 60 -h 25 -label "Isolate" -c "getActiveModelPanel";
button -w 60 -h 25 -l "Close" -c ("deleteUI -window yjp_WeightButtonWindow") ;
setParent..;
showWindow yjp_WeightButtonWindow ;
window -e -wh 390 60 yjp_WeightButtonWindow ;
ArtPaintSkinWeightsTool;
}
もしかするとMaya内部を直接書き換えたほうがUIがまとまってよさそうな気がしてきました。
スポイトが欲しいと言う声もあるので調べてみます。
global proc YPSWB_Replace(int $type ,float $val)
{
if($type == 0)
{
artAttrPaintOperation artAttrSkinPaintCtx Replace;
}
else if($type == 1)
{
artAttrPaintOperation artAttrSkinPaintCtx Add;
}
else if($type == 2)
{
artAttrPaintOperation artAttrSkinPaintCtx Smooth;
}
artAttrSkinPaintCtx -e -value $val `currentCtx`;
}
global proc yjp_PaintSikinWeightButton()
{
if(`window -q -ex yjp_WeightButtonWindow`)
{
deleteUI yjp_WeightButtonWindow ;
}
window -tb 1 -tlb 0 -t "PaintWeightButton" yjp_WeightButtonWindow ;
columnLayout ;
rowColumnLayout -nc 12 -cw 1 50 -cw 2 30 -cw 3 30 -cw 4 30 -cw 5 30 -cw 6 30 -cw 7 30 -cw 8 30 -cw 9 30 -cw 10 30 -cw 11 30 -cw 12 30;
text -w 50 -label "Replace";
button -w 30 -h 25 -l "0.0" -c "YPSWB_Replace 0 0.0" ;
button -w 30 -h 25 -l "0.1" -c "YPSWB_Replace 0 0.1" ;
button -w 30 -h 25 -l "0.2" -c "YPSWB_Replace 0 0.2" ;
button -w 30 -h 25 -l "0.3" -c "YPSWB_Replace 0 0.3" ;
button -w 30 -h 25 -l "0.4" -c "YPSWB_Replace 0 0.4" ;
button -w 30 -h 25 -l "0.5" -c "YPSWB_Replace 0 0.5" ;
button -w 30 -h 25 -l "0.6" -c "YPSWB_Replace 0 0.6" ;
button -w 30 -h 25 -l "0.7" -c "YPSWB_Replace 0 0.7" ;
button -w 30 -h 25 -l "0.8" -c "YPSWB_Replace 0 0.8" ;
button -w 30 -h 25 -l "0.9" -c "YPSWB_Replace 0 0.9" ;
button -w 30 -h 25 -l "1.0" -c "YPSWB_Replace 0 1.0" ;
setParent..;
rowColumnLayout -nc 7 -cw 1 50 -cw 2 30 -cw 3 30 -cw 4 50 -cw 5 60 -cw 6 60 -cw 7 60;
text -label "Add";
button -w 30 -h 25 -l "0.05" -c "YPSWB_Replace 1 0.05" ;
button -w 30 -h 25 -l "0.10" -c "YPSWB_Replace 1 0.1" ;
text -label " ";
button -w 60 -h 25 -label "Smooth" -c "YPSWB_Replace 2 0.0";
button -w 60 -h 25 -label "Isolate" -c "getActiveModelPanel";
button -w 60 -h 25 -l "Close" -c ("deleteUI -window yjp_WeightButtonWindow") ;
setParent..;
showWindow yjp_WeightButtonWindow ;
window -e -wh 390 60 yjp_WeightButtonWindow ;
ArtPaintSkinWeightsTool;
}
登録:
投稿 (Atom)