Last active
May 13, 2018 10:15
-
-
Save deathponta/d50a17f341f35af2b7e6af8ffa70a33e to your computer and use it in GitHub Desktop.
ボックスコントローラーを作成し選択ノードに位置・回転を合わせる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
■ 機能 | |
・ボックスリグを追加する。 | |
・ボックスリグは2重構造になっており、制御するコントローラのトランスフォームは初期状態で移動回転Zeroとなる。 | |
・ボックスリグの位置・回転は、選択しているオブジェクトに合わせる。 | |
・複数選択で作成できる。 | |
・Pivotがズレている場合の対応はしていません。 | |
*/ | |
proc Exec(){ | |
global string $parentObjs[]; | |
$s = `floatField -q -v "ff_size"`; // リグサイズ変数縮小 | |
string $selObj[] = `ls -sl -type "transform"`; // 選択ノード配列取得 | |
// 何も選択されていない場合は処理中止 | |
if( size($selObj)==0){ | |
confirmDialog -m "なにか選択してください。"; | |
return; | |
} | |
for ($sel in $selObj){ | |
// boxカーブ作成 | |
$crv = `curve -d 1 | |
-p (0.5*$s) (0.5*$s) (0.5*$s) -p (0.5*$s) (0.5*$s) (-0.5*$s) -p (-0.5*$s) (0.5*$s) (-0.5*$s) | |
-p (-0.5*$s) (-0.5*$s) (-0.5*$s) -p (0.5*$s) (-0.5*$s) (-0.5*$s) -p (0.5*$s) (0.5*$s) (-0.5*$s) | |
-p (-0.5*$s) (0.5*$s) (-0.5*$s) -p (-0.5*$s) (0.5*$s) (0.5*$s) -p (0.5*$s) (0.5*$s) (0.5*$s) | |
-p (0.5*$s) (-0.5*$s) (0.5*$s) -p (0.5*$s) (-0.5*$s) (-0.5*$s) -p (-0.5*$s) (-0.5*$s) (-0.5*$s) | |
-p (-0.5*$s) (-0.5*$s) (0.5*$s) -p (0.5*$s) (-0.5*$s) (0.5*$s) -p (-0.5*$s) (-0.5*$s) (0.5*$s) | |
-p (-0.5*$s) (0.5*$s) (0.5*$s) | |
-k 0 -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9 -k 10 -k 11 -k 12 -k 13 -k 14 -k 15 | |
-n ("rig_"+$sel)`; | |
// リグ<オフセット<ベーストランス保持用の3重構造 | |
$base = `createNode "transform" -n ("rig_" + $sel + "_base")`; | |
$offs = `createNode "transform" -n ("rig_" + $sel + "_offs") -p $base`; | |
parent $crv $offs; | |
// base を選択オブジェクトの位置・回転へ合わせる | |
$t = `xform -q -ws -t $sel`; | |
$r = `xform -q -ws -ro $sel`; | |
xform -ws -t $t[0] $t[1] $t[2] $base; | |
xform -ws -ro $r[0] $r[1] $r[2] $base; | |
// 親ノードの指定があった場合は移動 | |
if( size($parentObjs) > 0 ){ | |
parent $base $parentObjs[0]; | |
} | |
} | |
} | |
// 親ノードを指定 | |
proc SetParentObj(){ | |
global string $parentObjs[]; | |
$parentObjs = `ls -sl -l -type "transform"`; | |
// ボタンに選択オブジェクト名を反映 | |
$shortName = `ls $parentObjs[0]`; | |
if(size($parentObjs) == 0){ | |
button -e -l "Pick" -ann "親ノードは選択されていません" "btn_pick" ; | |
}else{ | |
button -e -l $shortName -ann ($parentObjs[0] + " が親ノードとしてセットされています!") "btn_pick" ; | |
} | |
} | |
proc AddController(){ | |
global string $parentObjs[]; // リグ作成後の親となるオブジェクトの絶対パス | |
string $win = "win_addController"; | |
if(`window -exists $win`){deleteUI $win;} | |
window -title "Add Controller" -toolbox true $win; | |
columnLayout -adj true; | |
rowLayout -nc 2 -ad2 1; | |
columnLayout -adj true; | |
text -l "親ノードを指定 → " -al "right" -h 30; | |
text -l "コントローラーのサイズを指定 → " -al "right" -h 30; | |
setParent ".."; | |
columnLayout -adj true -w 100; | |
button -l "Pick" -h 30 -c "SetParentObj()" -ann "親ノードは選択されていません" "btn_pick"; | |
floatField -min 0 -max 100 -v 10 -precision 1 -step .01 -h 30 "ff_size"; | |
setParent ".."; | |
setParent ".."; | |
button -l "コントローラーを作成し、選択ノードにスナップ!" -c "Exec()"; | |
showWindow $win; | |
} | |
AddController(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment