-
-
Save cg-method/ea59bbbdc1c2a719b9c21cfa73eaff31 to your computer and use it in GitHub Desktop.
【Maya】ポーズの反転コピー
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
global proc MirrorPose() | |
{ | |
print( "\n------------ Start MirrorPose() ------------\n" ); | |
string $allObjects[]; | |
string $obj; | |
$allObjects = `ls -sl`; // 選択中のオブジェクトリスト | |
int $nAllObjects = size($allObjects); // 要素数 | |
// 退避テーブル | |
float $rotX[]; | |
float $transX[]; | |
float $rotY[]; | |
float $transY[]; | |
float $rotZ[]; | |
float $transZ[]; | |
// 選択対照の情報を退避 | |
if( $nAllObjects == 1 ) // 一つ | |
{ | |
$transX[0] = `getAttr $allObjects.translateX`; | |
$transY[0] = `getAttr $allObjects.translateY`; | |
$transZ[0] = `getAttr $allObjects.translateZ`; | |
$rotX[0] = `getAttr $allObjects.rotateX`; | |
$rotY[0] = `getAttr $allObjects.rotateY`; | |
$rotZ[0] = `getAttr $allObjects.rotateZ`; | |
} | |
else if( $nAllObjects > 1 ) // 複数 | |
{ | |
$transX = `getAttr $allObjects.translateX`; | |
$transY = `getAttr $allObjects.translateY`; | |
$transZ = `getAttr $allObjects.translateZ`; | |
$rotX = `getAttr $allObjects.rotateX`; | |
$rotY = `getAttr $allObjects.rotateY`; | |
$rotZ = `getAttr $allObjects.rotateZ`; | |
} | |
// ポーズ反転処理 | |
for ( $cnt = 0; $cnt < $nAllObjects; $cnt++ ) | |
{ | |
$obj = $allObjects[$nAllObjects - $cnt - 1]; // 逆順で入ってるみたい? | |
$isLR = false; | |
print ($obj + " -> "); | |
// 選択対象の名称置き換え | |
if( `gmatch $obj "*Left*"` ) | |
{ | |
$obj = substituteAllString( $obj, "Left", "Right" ); | |
$isLR = true; | |
} | |
else if( `gmatch $obj "*Right*"` ) | |
{ | |
$obj = substituteAllString( $obj, "Right", "Left" ); | |
$isLR = true; | |
} | |
else if( `gmatch $obj "*_L"` ) | |
{ | |
$obj = substituteAllString( $obj, "_L", "_R" ); | |
$isLR = true; | |
} | |
else if( `gmatch $obj "*_R"` ) | |
{ | |
$obj = substituteAllString( $obj, "_R", "_L" ); | |
$isLR = true; | |
} | |
else if( `gmatch $obj "*_l"` ) | |
{ | |
$obj = substituteAllString( $obj, "_l", "_r" ); | |
$isLR = true; | |
} | |
else if( `gmatch $obj "*_r"` ) | |
{ | |
$obj = substituteAllString( $obj, "_r", "_l" ); | |
$isLR = true; | |
} | |
print ($obj + "\n"); | |
// 選択反転 | |
select -r $obj ; | |
// 座標 | |
move ($transX[$cnt] * -1) $transY[$cnt] $transZ[$cnt]; | |
// 回転 | |
if( `gmatch $obj "*Effector"` ) // IK? | |
{ | |
// IK | |
rotate ($rotX[$cnt] * -1) ($rotY[$cnt] * -1) $rotZ[$cnt]; | |
} | |
else | |
{ | |
// FK | |
if( $isLR ) // 対照リグ? | |
{ | |
if( `gmatch $obj "*Arm"` ) | |
{ | |
// 腕 | |
rotate $rotX[$cnt] $rotY[$cnt] $rotZ[$cnt]; | |
} | |
else if( `gmatch $obj "*Shoulder"` ) | |
{ | |
// 肩 | |
rotate $rotX[$cnt] ($rotY[$cnt] * -1) ($rotZ[$cnt] * -1); | |
} | |
else | |
{ | |
// その他 | |
rotate ($rotX[$cnt] * -1) ($rotY[$cnt] * -1) $rotZ[$cnt]; | |
} | |
} | |
else | |
{ | |
// その他(胴体など) | |
rotate ($rotX[$cnt] * -1) ($rotY[$cnt] * -1) $rotZ[$cnt]; | |
} | |
} | |
}; | |
print( "------------ End MirrorPose() ------------\n" ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment