// // このスクリプトをすべてコピーして、 // スクリプトエディターにペーストしてください。 // // 実行するとオプションウインドウが立ち上がります。 // // 最大ウェイト影響数を指定し、メッシュを選択して実行します。 // proc setSkinWeightMaxInfluences.setWeight( int $maxInfluences, string $vtx, string $cluster ) // // 引数のスキンクラスターと頂点を、maxInfluencesの数に制限。 // maxInfluencesの数分ウェイトが残るように、ウェイト値が低いものを捨てていきます。 // 同じ処理をするにも、いろいろな方法が考えられますので、改良してみてください。 // { // 今の頂点に割り当てられているジョイントのリストをいただきます! // string $joints[] = `skinPercent -q -transform $cluster $vtx`; string $jointsOrgList[] = $joints; // 既にスキンウェイト影響数がMaxより少ないのなら、処理しない。 // if ( `size $joints` == 0 || `size $joints` < $maxInfluences ){ return; } int $count = 0; int $same = 0; int $maxWeightIndex; // 検索中で最もウェイト値が大きいジョイントの番号を記録。 int $maxWeightIndices[]; float $weight = 0; // 検索中、対象になっているジョイントのウェイト値を記録。 float $maxWeight = 0; // 検索中で最大のウェイト値を記録。 string $item[]; int $length = `size $joints`; // 検索開始。 // while( $count < $maxInfluences ){ // バカバカしいのですが、まじめに処理するのもメンドウなので、 // ジョイントをすべてチェックして、最もウェイト値が大きいものから // 順々に抜き出していきます。 // 指定されたスキンウェイト数に達するまで繰り返します。 // for ( $i = 0; $i < $length; $i++ ){ // 既に立候補されていたらスキップ。 // for ( $j = 0; $j < $count; $j++ ){ if ( $i == $maxWeightIndices[$j] ) $same = 1; } if ( $same ){ $same = 0; continue; } // 現在対象となっているジョイントのウェイト値を調べる。 // $weight = `skinPercent -t $joints[$i] -q -v $cluster $vtx`; // もしこれまでのジョイントウェイト値で最大なら、 // 最大ウェイト値を更新して、最大ウェイトを持っているジョイント候補として // $maxWeightIndexに記録。 if ( $weight > $maxWeight ){ $maxWeight = $weight; $maxWeightIndex = $i; } } // 今回最大ウェイト値を持っているものを記録。 // $maxWeightIndices[ $count ] = $maxWeightIndex; $count++; $maxWeight = 0; } // 落第したジョイントをリストアップ。 // for ( $i = 0; $i < $maxInfluences; $i++ ){ $item[$i] = $joints[$maxWeightIndices[$i]]; } $joints = stringArrayRemove( $item, $joints ); // 落第ジョイントの影響力をゼロにする。 // for ( $joint in $joints ){ skinPercent -tv $joint 0.0 $cluster $vtx; } } global proc setSkinWeightMaxInfluences.doIt() // // オプションウインドウでSetを押したらこれを実行する。 // { // オプション設定をゲット! // int $maxInfluences = `intSliderGrp -q -v sswmi_max`; // 選択を頂点に変換して、頂点のリストをゲット! // ConvertSelectionToVertices; string $components[] = `ls -sl`; $components = `filterExpand -sm 31 $components`; // -sm 31 はポリゴン頂点の意味 if ( `size $components` == 0 ){ error "選択がなんかおかしいです。メッシュかフェースかエッジか、いい感じのものを選択してください。"; } // 選択しているメッシュに関連するスキンクラスターをゲット! // string $shape[] = `listRelatives -p -f`; string $groupIds[] = `listConnections -s true -d false -type "groupId" $shape[0]`; string $skinClusters[] = `listConnections -s false -d true -type "skinCluster" $groupIds`; // サービスとして、事前にプルーンウェイトしときます。 // for ( $cluster in $skinClusters ){ skinPercent -prw 0.0009 $cluster; } // スキンウェイトをセットしていきます。 // int $result; for ( $vtx in $components ){ for ( $cluster in $skinClusters ){ // 一頂点ずつスキンウェイトを制限していきます。 // setSkinWeightMaxInfluences.setWeight( $maxInfluences, $vtx, $cluster ); $result++; } } print ( "// Result : " + $result + " //\n" ); } global proc setSkinWeightMaxInfluences() // // オプションのウインドウを作ります。 // { // ウインドウの名前を決めます。 // 既にあるなら、それを表示します。 // string $win = "setSkinWeightMaxInfluencesWin"; if ( `window -q -ex $win` ){ showWindow $win; return; } // ウインドウを作ります。 // window $win; columnLayout; text -l ""; intSliderGrp -l "Max Influences" -field true -min 1 -max 4 -fmn 1 -v 2 sswmi_max; text -l ""; int $btnW = 200; rowLayout -nc 2 -cw2 $btnW $btnW -cl2 "center" "center"; button -l "Set" -w $btnW -c "setSkinWeightMaxInfluences.doIt()"; button -l "Close" -w $btnW -c ("deleteUI " + $win); setParent..; window -e -rtf true $win; showWindow $win; } // これでスクリプトを実行。 setSkinWeightMaxInfluences();